aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/Kconfig2
-rw-r--r--drivers/acpi/glue.c112
-rw-r--r--drivers/ata/pata_of_platform.c2
-rw-r--r--drivers/ata/pata_pcmcia.c168
-rw-r--r--drivers/base/Kconfig2
-rw-r--r--drivers/base/bus.c54
-rw-r--r--drivers/base/core.c30
-rw-r--r--drivers/base/dd.c3
-rw-r--r--drivers/base/firmware_class.c24
-rw-r--r--drivers/base/platform.c80
-rw-r--r--drivers/base/power/main.c9
-rw-r--r--drivers/block/aoe/aoechr.c6
-rw-r--r--drivers/block/ataflop.c4
-rw-r--r--drivers/block/floppy.c2
-rw-r--r--drivers/block/paride/pg.c5
-rw-r--r--drivers/block/paride/pt.c10
-rw-r--r--drivers/block/pktcdvd.c5
-rw-r--r--drivers/block/viodasd.c3
-rw-r--r--drivers/bluetooth/bluecard_cs.c8
-rw-r--r--drivers/bluetooth/bt3c_cs.c125
-rw-r--r--drivers/bluetooth/btuart_cs.c126
-rw-r--r--drivers/bluetooth/dtl1_cs.c67
-rw-r--r--drivers/bluetooth/hci_ldisc.c2
-rw-r--r--drivers/char/Kconfig13
-rw-r--r--drivers/char/Makefile2
-rw-r--r--drivers/char/agp/amd-k7-agp.c38
-rw-r--r--drivers/char/agp/intel-agp.c18
-rw-r--r--drivers/char/agp/nvidia-agp.c22
-rw-r--r--drivers/char/amiserial.c6
-rw-r--r--drivers/char/applicom.c8
-rw-r--r--drivers/char/bsr.c5
-rw-r--r--drivers/char/cyclades.c21
-rw-r--r--drivers/char/ds1286.c4
-rw-r--r--drivers/char/dsp56k.c4
-rw-r--r--drivers/char/epca.c5
-rw-r--r--drivers/char/generic_serial.c21
-rw-r--r--drivers/char/hpet.c159
-rw-r--r--drivers/char/hvc_console.c14
-rw-r--r--drivers/char/hw_random/omap-rng.c33
-rw-r--r--drivers/char/ip2/Makefile2
-rw-r--r--drivers/char/ip2/i2ellis.c32
-rw-r--r--drivers/char/ip2/i2ellis.h2
-rw-r--r--drivers/char/ip2/ip2base.c108
-rw-r--r--drivers/char/ip2/ip2main.c550
-rw-r--r--drivers/char/ipmi/ipmi_devintf.c2
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c2
-rw-r--r--drivers/char/isicom.c61
-rw-r--r--drivers/char/istallion.c118
-rw-r--r--drivers/char/keyboard.c2
-rw-r--r--drivers/char/lp.c4
-rw-r--r--drivers/char/mem.c6
-rw-r--r--drivers/char/misc.c4
-rw-r--r--drivers/char/moxa.c63
-rw-r--r--drivers/char/mxser.c193
-rw-r--r--drivers/char/n_hdlc.c2
-rw-r--r--drivers/char/n_r3964.c8
-rw-r--r--drivers/char/n_tty.c125
-rw-r--r--drivers/char/nozomi.c5
-rw-r--r--drivers/char/pcmcia/cm4000_cs.c75
-rw-r--r--drivers/char/pcmcia/cm4040_cs.c83
-rw-r--r--drivers/char/pcmcia/ipwireless/main.c54
-rw-r--r--drivers/char/pcmcia/ipwireless/tty.c19
-rw-r--r--drivers/char/pcmcia/synclink_cs.c2
-rw-r--r--drivers/char/ppdev.c5
-rw-r--r--drivers/char/pty.c335
-rw-r--r--drivers/char/random.c2
-rw-r--r--drivers/char/raw.c7
-rw-r--r--drivers/char/rtc.c2
-rw-r--r--drivers/char/snsc.c4
-rw-r--r--drivers/char/stallion.c143
-rw-r--r--drivers/char/sx.c4
-rw-r--r--drivers/char/sysrq.c31
-rw-r--r--drivers/char/tpm/tpm.c132
-rw-r--r--drivers/char/tpm/tpm.h3
-rw-r--r--drivers/char/tpm/tpm_tis.c14
-rw-r--r--drivers/char/tty_audit.c2
-rw-r--r--drivers/char/tty_buffer.c511
-rw-r--r--drivers/char/tty_io.c1387
-rw-r--r--drivers/char/tty_ioctl.c212
-rw-r--r--drivers/char/tty_port.c96
-rw-r--r--drivers/char/vc_screen.c12
-rw-r--r--drivers/char/viotape.c8
-rw-r--r--drivers/char/vt.c91
-rw-r--r--drivers/char/vt_ioctl.c2
-rw-r--r--drivers/char/xilinx_hwicap/xilinx_hwicap.c3
-rw-r--r--drivers/dca/dca-sysfs.c8
-rw-r--r--drivers/edac/i5000_edac.c196
-rw-r--r--drivers/edac/i82443bxgx_edac.c63
-rw-r--r--drivers/edac/mpc85xx_edac.c33
-rw-r--r--drivers/firewire/fw-card.c56
-rw-r--r--drivers/firewire/fw-cdev.c6
-rw-r--r--drivers/firewire/fw-device.c37
-rw-r--r--drivers/firewire/fw-sbp2.c116
-rw-r--r--drivers/firewire/fw-transaction.c48
-rw-r--r--drivers/firewire/fw-transaction.h9
-rw-r--r--drivers/firmware/dmi_scan.c22
-rw-r--r--drivers/firmware/iscsi_ibft.c18
-rw-r--r--drivers/gpio/gpiolib.c111
-rw-r--r--drivers/gpio/max7301.c24
-rw-r--r--drivers/gpio/max732x.c5
-rw-r--r--drivers/gpio/mcp23s08.c5
-rw-r--r--drivers/gpio/pca953x.c5
-rw-r--r--drivers/gpio/pcf857x.c5
-rw-r--r--drivers/gpu/drm/i915/i915_dma.c4
-rw-r--r--drivers/hid/Kconfig197
-rw-r--r--drivers/hid/Makefile35
-rw-r--r--drivers/hid/hid-a4tech.c162
-rw-r--r--drivers/hid/hid-apple.c484
-rw-r--r--drivers/hid/hid-belkin.c105
-rw-r--r--drivers/hid/hid-bright.c71
-rw-r--r--drivers/hid/hid-cherry.c87
-rw-r--r--drivers/hid/hid-chicony.c80
-rw-r--r--drivers/hid/hid-core.c1183
-rw-r--r--drivers/hid/hid-cypress.c158
-rw-r--r--drivers/hid/hid-dell.c75
-rw-r--r--drivers/hid/hid-dummy.c72
-rw-r--r--drivers/hid/hid-ezkey.c95
-rw-r--r--drivers/hid/hid-gyration.c96
-rw-r--r--drivers/hid/hid-ids.h406
-rw-r--r--drivers/hid/hid-input-quirks.c484
-rw-r--r--drivers/hid/hid-input.c915
-rw-r--r--drivers/hid/hid-lg.c342
-rw-r--r--drivers/hid/hid-lg.h18
-rw-r--r--drivers/hid/hid-lg2ff.c (renamed from drivers/hid/usbhid/hid-lg2ff.c)14
-rw-r--r--drivers/hid/hid-lgff.c (renamed from drivers/hid/usbhid/hid-lgff.c)34
-rw-r--r--drivers/hid/hid-microsoft.c219
-rw-r--r--drivers/hid/hid-monterey.c82
-rw-r--r--drivers/hid/hid-petalynx.c122
-rw-r--r--drivers/hid/hid-pl.c (renamed from drivers/hid/usbhid/hid-plff.c)83
-rw-r--r--drivers/hid/hid-samsung.c100
-rw-r--r--drivers/hid/hid-sony.c110
-rw-r--r--drivers/hid/hid-sunplus.c82
-rw-r--r--drivers/hid/hid-tmff.c (renamed from drivers/hid/usbhid/hid-tmff.c)138
-rw-r--r--drivers/hid/hid-zpff.c (renamed from drivers/hid/usbhid/hid-zpff.c)71
-rw-r--r--drivers/hid/hidraw.c13
-rw-r--r--drivers/hid/usbhid/Kconfig75
-rw-r--r--drivers/hid/usbhid/Makefile18
-rw-r--r--drivers/hid/usbhid/hid-core.c463
-rw-r--r--drivers/hid/usbhid/hid-ff.c95
-rw-r--r--drivers/hid/usbhid/hid-pidff.c5
-rw-r--r--drivers/hid/usbhid/hid-quirks.c934
-rw-r--r--drivers/hid/usbhid/hiddev.c20
-rw-r--r--drivers/hid/usbhid/usbhid.h4
-rw-r--r--drivers/hid/usbhid/usbkbd.c12
-rw-r--r--drivers/hid/usbhid/usbmouse.c8
-rw-r--r--drivers/hwmon/ams/ams.h2
-rw-r--r--drivers/hwmon/dme1737.c320
-rw-r--r--drivers/hwmon/hwmon.c4
-rw-r--r--drivers/i2c/busses/Kconfig20
-rw-r--r--drivers/i2c/busses/Makefile1
-rw-r--r--drivers/i2c/busses/i2c-highlander.c498
-rw-r--r--drivers/i2c/busses/i2c-mpc.c1
-rw-r--r--drivers/i2c/busses/i2c-omap.c12
-rw-r--r--drivers/i2c/busses/i2c-parport-light.c39
-rw-r--r--drivers/i2c/busses/i2c-pca-isa.c22
-rw-r--r--drivers/i2c/busses/i2c-viapro.c17
-rw-r--r--drivers/i2c/chips/Kconfig11
-rw-r--r--drivers/i2c/chips/Makefile1
-rw-r--r--drivers/i2c/chips/isp1301_omap.c141
-rw-r--r--drivers/i2c/chips/mcu_mpc8349emitx.c209
-rw-r--r--drivers/i2c/chips/tps65010.c12
-rw-r--r--drivers/i2c/i2c-core.c35
-rw-r--r--drivers/i2c/i2c-dev.c6
-rw-r--r--drivers/ide/Kconfig40
-rw-r--r--drivers/ide/Makefile19
-rw-r--r--drivers/ide/arm/icside.c23
-rw-r--r--drivers/ide/h8300/ide-h8300.c2
-rw-r--r--drivers/ide/ide-acpi.c12
-rw-r--r--drivers/ide/ide-atapi.c183
-rw-r--r--drivers/ide/ide-cd.c261
-rw-r--r--drivers/ide/ide-cd.h1
-rw-r--r--drivers/ide/ide-disk.c357
-rw-r--r--drivers/ide/ide-disk.h32
-rw-r--r--drivers/ide/ide-disk_ioctl.c29
-rw-r--r--drivers/ide/ide-disk_proc.c129
-rw-r--r--drivers/ide/ide-dma-sff.c356
-rw-r--r--drivers/ide/ide-dma.c481
-rw-r--r--drivers/ide/ide-floppy.c392
-rw-r--r--drivers/ide/ide-floppy.h19
-rw-r--r--drivers/ide/ide-floppy_ioctl.c56
-rw-r--r--drivers/ide/ide-floppy_proc.c33
-rw-r--r--drivers/ide/ide-generic.c51
-rw-r--r--drivers/ide/ide-io.c237
-rw-r--r--drivers/ide/ide-ioctls.c21
-rw-r--r--drivers/ide/ide-iops.c95
-rw-r--r--drivers/ide/ide-lib.c2
-rw-r--r--drivers/ide/ide-park.c121
-rw-r--r--drivers/ide/ide-probe.c219
-rw-r--r--drivers/ide/ide-proc.c6
-rw-r--r--drivers/ide/ide-tape.c166
-rw-r--r--drivers/ide/ide-taskfile.c128
-rw-r--r--drivers/ide/ide.c135
-rw-r--r--drivers/ide/legacy/ali14xx.c2
-rw-r--r--drivers/ide/legacy/ht6560b.c9
-rw-r--r--drivers/ide/legacy/ide-4drives.c2
-rw-r--r--drivers/ide/legacy/ide-cs.c158
-rw-r--r--drivers/ide/legacy/qd65xx.c2
-rw-r--r--drivers/ide/mips/au1xxx-ide.c34
-rw-r--r--drivers/ide/pci/aec62xx.c8
-rw-r--r--drivers/ide/pci/alim15x3.c15
-rw-r--r--drivers/ide/pci/amd74xx.c8
-rw-r--r--drivers/ide/pci/atiixp.c6
-rw-r--r--drivers/ide/pci/cmd640.c18
-rw-r--r--drivers/ide/pci/cmd64x.c10
-rw-r--r--drivers/ide/pci/cs5520.c4
-rw-r--r--drivers/ide/pci/cs5530.c6
-rw-r--r--drivers/ide/pci/cs5535.c8
-rw-r--r--drivers/ide/pci/cy82c693.c124
-rw-r--r--drivers/ide/pci/delkin_cb.c6
-rw-r--r--drivers/ide/pci/generic.c6
-rw-r--r--drivers/ide/pci/hpt34x.c6
-rw-r--r--drivers/ide/pci/hpt366.c15
-rw-r--r--drivers/ide/pci/it8213.c6
-rw-r--r--drivers/ide/pci/it821x.c46
-rw-r--r--drivers/ide/pci/jmicron.c6
-rw-r--r--drivers/ide/pci/ns87415.c21
-rw-r--r--drivers/ide/pci/opti621.c8
-rw-r--r--drivers/ide/pci/pdc202xx_new.c6
-rw-r--r--drivers/ide/pci/pdc202xx_old.c14
-rw-r--r--drivers/ide/pci/piix.c46
-rw-r--r--drivers/ide/pci/rz1000.c6
-rw-r--r--drivers/ide/pci/sc1200.c12
-rw-r--r--drivers/ide/pci/scc_pata.c29
-rw-r--r--drivers/ide/pci/serverworks.c8
-rw-r--r--drivers/ide/pci/sgiioc4.c59
-rw-r--r--drivers/ide/pci/siimage.c17
-rw-r--r--drivers/ide/pci/sis5513.c6
-rw-r--r--drivers/ide/pci/sl82c105.c8
-rw-r--r--drivers/ide/pci/slc90e66.c6
-rw-r--r--drivers/ide/pci/tc86c001.c8
-rw-r--r--drivers/ide/pci/triflex.c15
-rw-r--r--drivers/ide/pci/trm290.c10
-rw-r--r--drivers/ide/pci/via82cxxx.c6
-rw-r--r--drivers/ide/ppc/pmac.c71
-rw-r--r--drivers/ieee1394/csr1212.c2
-rw-r--r--drivers/ieee1394/dv1394.c10
-rw-r--r--drivers/ieee1394/eth1394.c2
-rw-r--r--drivers/ieee1394/nodemgr.c279
-rw-r--r--drivers/ieee1394/nodemgr.h2
-rw-r--r--drivers/ieee1394/raw1394-private.h1
-rw-r--r--drivers/ieee1394/raw1394.c238
-rw-r--r--drivers/ieee1394/sbp2.c218
-rw-r--r--drivers/ieee1394/sbp2.h33
-rw-r--r--drivers/ieee1394/video1394.c13
-rw-r--r--drivers/infiniband/core/cm.c6
-rw-r--r--drivers/infiniband/core/user_mad.c12
-rw-r--r--drivers/infiniband/core/uverbs_main.c9
-rw-r--r--drivers/infiniband/hw/ipath/ipath_file_ops.c2
-rw-r--r--drivers/infiniband/ulp/srp/ib_srp.c2
-rw-r--r--drivers/input/gameport/gameport.c88
-rw-r--r--drivers/input/joystick/a3d.c3
-rw-r--r--drivers/input/joystick/adi.c3
-rw-r--r--drivers/input/joystick/analog.c4
-rw-r--r--drivers/input/joystick/cobra.c3
-rw-r--r--drivers/input/joystick/gf2k.c3
-rw-r--r--drivers/input/joystick/grip.c3
-rw-r--r--drivers/input/joystick/grip_mp.c3
-rw-r--r--drivers/input/joystick/guillemot.c3
-rw-r--r--drivers/input/joystick/interact.c3
-rw-r--r--drivers/input/joystick/joydump.c3
-rw-r--r--drivers/input/joystick/sidewinder.c3
-rw-r--r--drivers/input/joystick/tmdc.c3
-rw-r--r--drivers/input/joystick/xpad.c4
-rw-r--r--drivers/input/keyboard/atkbd.c30
-rw-r--r--drivers/input/keyboard/bf54x-keys.c13
-rw-r--r--drivers/input/keyboard/gpio_keys.c42
-rw-r--r--drivers/input/keyboard/omap-keypad.c29
-rw-r--r--drivers/input/misc/Kconfig13
-rw-r--r--drivers/input/misc/Makefile1
-rw-r--r--drivers/input/misc/ati_remote2.c263
-rw-r--r--drivers/input/misc/cm109.c882
-rw-r--r--drivers/input/misc/hp_sdc_rtc.c10
-rw-r--r--drivers/input/misc/map_to_7segment.h189
-rw-r--r--drivers/input/misc/wistron_btns.c19
-rw-r--r--drivers/input/misc/yealink.c2
-rw-r--r--drivers/input/mouse/Kconfig10
-rw-r--r--drivers/input/mouse/Makefile1
-rw-r--r--drivers/input/mouse/alps.c1
-rw-r--r--drivers/input/mouse/appletouch.c299
-rw-r--r--drivers/input/mouse/hgpk.c477
-rw-r--r--drivers/input/mouse/hgpk.h49
-rw-r--r--drivers/input/mouse/logips2pp.c4
-rw-r--r--drivers/input/mouse/psmouse-base.c81
-rw-r--r--drivers/input/mouse/psmouse.h14
-rw-r--r--drivers/input/mouse/trackpoint.c8
-rw-r--r--drivers/input/serio/hp_sdc.c2
-rw-r--r--drivers/input/serio/i8042-io.h2
-rw-r--r--drivers/input/serio/i8042-x86ia64io.h7
-rw-r--r--drivers/input/serio/serio_raw.c6
-rw-r--r--drivers/input/tablet/aiptek.c53
-rw-r--r--drivers/input/touchscreen/ads7846.c94
-rw-r--r--drivers/input/touchscreen/atmel_tsadcc.c37
-rw-r--r--drivers/input/touchscreen/mainstone-wm97xx.c5
-rw-r--r--drivers/input/touchscreen/wm9705.c5
-rw-r--r--drivers/input/touchscreen/wm9712.c5
-rw-r--r--drivers/input/touchscreen/wm9713.c5
-rw-r--r--drivers/input/touchscreen/wm97xx-core.c5
-rw-r--r--drivers/isdn/capi/capi.c5
-rw-r--r--drivers/isdn/gigaset/ser-gigaset.c27
-rw-r--r--drivers/isdn/hardware/avm/avm_cs.c85
-rw-r--r--drivers/isdn/hisax/avma1_cs.c81
-rw-r--r--drivers/isdn/hisax/elsa_cs.c79
-rw-r--r--drivers/isdn/hisax/sedlbauer_cs.c197
-rw-r--r--drivers/isdn/hisax/teles_cs.c79
-rw-r--r--drivers/isdn/mISDN/dsp_cmx.c4
-rw-r--r--drivers/isdn/mISDN/timerdev.c2
-rw-r--r--drivers/leds/led-class.c4
-rw-r--r--drivers/macintosh/adb.c3
-rw-r--r--drivers/md/Kconfig14
-rw-r--r--drivers/md/faulty.c2
-rw-r--r--drivers/md/linear.c133
-rw-r--r--drivers/md/md.c81
-rw-r--r--drivers/md/multipath.c9
-rw-r--r--drivers/md/raid0.c5
-rw-r--r--drivers/md/raid1.c1
-rw-r--r--drivers/md/raid10.c6
-rw-r--r--drivers/md/raid5.c42
-rw-r--r--drivers/md/raid6.h9
-rw-r--r--drivers/media/common/ir-keymaps.c280
-rw-r--r--drivers/media/common/saa7146_core.c2
-rw-r--r--drivers/media/common/saa7146_fops.c2
-rw-r--r--drivers/media/common/tuners/mt2060.c38
-rw-r--r--drivers/media/common/tuners/mxl5007t.c1
-rw-r--r--drivers/media/common/tuners/tda18271-fe.c1
-rw-r--r--drivers/media/common/tuners/tda827x.c12
-rw-r--r--drivers/media/common/tuners/tda827x.h1
-rw-r--r--drivers/media/common/tuners/tda8290.c4
-rw-r--r--drivers/media/common/tuners/tda8290.h1
-rw-r--r--drivers/media/common/tuners/tda9887.c1
-rw-r--r--drivers/media/common/tuners/tuner-simple.c3
-rw-r--r--drivers/media/common/tuners/tuner-types.c22
-rw-r--r--drivers/media/common/tuners/tuner-xc2028.c74
-rw-r--r--drivers/media/common/tuners/tuner-xc2028.h10
-rw-r--r--drivers/media/common/tuners/xc5000.c109
-rw-r--r--drivers/media/common/tuners/xc5000.h8
-rw-r--r--drivers/media/common/tuners/xc5000_priv.h37
-rw-r--r--drivers/media/dvb/Kconfig5
-rw-r--r--drivers/media/dvb/Makefile2
-rw-r--r--drivers/media/dvb/b2c2/flexcop-dma.c2
-rw-r--r--drivers/media/dvb/bt8xx/dvb-bt8xx.c2
-rw-r--r--drivers/media/dvb/cinergyT2/Kconfig85
-rw-r--r--drivers/media/dvb/cinergyT2/Makefile3
-rw-r--r--drivers/media/dvb/cinergyT2/cinergyT2.c1105
-rw-r--r--drivers/media/dvb/dm1105/Kconfig18
-rw-r--r--drivers/media/dvb/dm1105/Makefile3
-rw-r--r--drivers/media/dvb/dm1105/dm1105.c911
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c666
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.h32
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.c2
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig42
-rw-r--r--drivers/media/dvb/dvb-usb/Makefile10
-rw-r--r--drivers/media/dvb/dvb-usb/af9005-remote.c2
-rw-r--r--drivers/media/dvb/dvb-usb/af9005-script.h2
-rw-r--r--drivers/media/dvb/dvb-usb/af9005.c23
-rw-r--r--drivers/media/dvb/dvb-usb/af9015.c1474
-rw-r--r--drivers/media/dvb/dvb-usb/af9015.h524
-rw-r--r--drivers/media/dvb/dvb-usb/anysee.c30
-rw-r--r--drivers/media/dvb/dvb-usb/cinergyT2-core.c268
-rw-r--r--drivers/media/dvb/dvb-usb/cinergyT2-fe.c351
-rw-r--r--drivers/media/dvb/dvb-usb/cinergyT2.h95
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.c504
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700.h4
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_core.c115
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_devices.c195
-rw-r--r--drivers/media/dvb/dvb-usb/dtv5100.c240
-rw-r--r--drivers/media/dvb/dvb-usb/dtv5100.h51
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h29
-rw-r--r--drivers/media/dvb/dvb-usb/dw2102.c572
-rw-r--r--drivers/media/dvb/dvb-usb/dw2102.h1
-rw-r--r--drivers/media/dvb/frontends/Kconfig47
-rw-r--r--drivers/media/dvb/frontends/Makefile7
-rw-r--r--drivers/media/dvb/frontends/af9013.c1685
-rw-r--r--drivers/media/dvb/frontends/af9013.h107
-rw-r--r--drivers/media/dvb/frontends/af9013_priv.h869
-rw-r--r--drivers/media/dvb/frontends/au8522.c133
-rw-r--r--drivers/media/dvb/frontends/au8522.h17
-rw-r--r--drivers/media/dvb/frontends/cx24110.h15
-rw-r--r--drivers/media/dvb/frontends/cx24116.c1423
-rw-r--r--drivers/media/dvb/frontends/cx24116.h53
-rw-r--r--drivers/media/dvb/frontends/dib0070.h8
-rw-r--r--drivers/media/dvb/frontends/dib7000m.c6
-rw-r--r--drivers/media/dvb/frontends/dib7000p.c3
-rw-r--r--drivers/media/dvb/frontends/dib7000p.h41
-rw-r--r--drivers/media/dvb/frontends/drx397xD.c288
-rw-r--r--drivers/media/dvb/frontends/drx397xD.h6
-rw-r--r--drivers/media/dvb/frontends/dvb_dummy_fe.c11
-rw-r--r--drivers/media/dvb/frontends/eds1547.h133
-rw-r--r--drivers/media/dvb/frontends/lgs8gl5.c454
-rw-r--r--drivers/media/dvb/frontends/lgs8gl5.h45
-rw-r--r--drivers/media/dvb/frontends/nxt200x.c4
-rw-r--r--drivers/media/dvb/frontends/or51211.c2
-rw-r--r--drivers/media/dvb/frontends/si21xx.c974
-rw-r--r--drivers/media/dvb/frontends/si21xx.h37
-rw-r--r--drivers/media/dvb/frontends/sp887x.c3
-rw-r--r--drivers/media/dvb/frontends/stb6000.c255
-rw-r--r--drivers/media/dvb/frontends/stb6000.h51
-rw-r--r--drivers/media/dvb/frontends/stv0288.c618
-rw-r--r--drivers/media/dvb/frontends/stv0288.h67
-rw-r--r--drivers/media/dvb/frontends/stv0299.c2
-rw-r--r--drivers/media/dvb/frontends/stv0299.h13
-rw-r--r--drivers/media/dvb/frontends/tdhd1.h73
-rw-r--r--drivers/media/dvb/ttpci/Kconfig1
-rw-r--r--drivers/media/dvb/ttpci/av7110.c127
-rw-r--r--drivers/media/dvb/ttpci/av7110.h1
-rw-r--r--drivers/media/dvb/ttpci/av7110_av.c3
-rw-r--r--drivers/media/dvb/ttpci/budget-av.c8
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c7
-rw-r--r--drivers/media/dvb/ttpci/budget-core.c6
-rw-r--r--drivers/media/dvb/ttpci/budget-patch.c9
-rw-r--r--drivers/media/dvb/ttpci/budget.c25
-rw-r--r--drivers/media/dvb/ttpci/budget.h2
-rw-r--r--drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c2
-rw-r--r--drivers/media/dvb/ttusb-dec/ttusb_dec.c2
-rw-r--r--drivers/media/dvb/ttusb-dec/ttusbdecfe.c16
-rw-r--r--drivers/media/radio/Kconfig12
-rw-r--r--drivers/media/radio/Makefile1
-rw-r--r--drivers/media/radio/dsbr100.c28
-rw-r--r--drivers/media/radio/radio-aimslab.c34
-rw-r--r--drivers/media/radio/radio-aztech.c40
-rw-r--r--drivers/media/radio/radio-cadet.c1
-rw-r--r--drivers/media/radio/radio-gemtek-pci.c42
-rw-r--r--drivers/media/radio/radio-gemtek.c37
-rw-r--r--drivers/media/radio/radio-maestro.c34
-rw-r--r--drivers/media/radio/radio-maxiradio.c40
-rw-r--r--drivers/media/radio/radio-mr800.c628
-rw-r--r--drivers/media/radio/radio-rtrack2.c34
-rw-r--r--drivers/media/radio/radio-sf16fmi.c34
-rw-r--r--drivers/media/radio/radio-sf16fmr2.c34
-rw-r--r--drivers/media/radio/radio-si470x.c24
-rw-r--r--drivers/media/radio/radio-terratec.c34
-rw-r--r--drivers/media/radio/radio-trust.c17
-rw-r--r--drivers/media/radio/radio-typhoon.c35
-rw-r--r--drivers/media/radio/radio-zoltrix.c51
-rw-r--r--drivers/media/video/Kconfig235
-rw-r--r--drivers/media/video/Makefile9
-rw-r--r--drivers/media/video/arv.c29
-rw-r--r--drivers/media/video/au0828/au0828-cards.c2
-rw-r--r--drivers/media/video/au0828/au0828-dvb.c47
-rw-r--r--drivers/media/video/au0828/au0828.h3
-rw-r--r--drivers/media/video/bt856.c8
-rw-r--r--drivers/media/video/bt8xx/bttv-cards.c27
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c66
-rw-r--r--drivers/media/video/bt8xx/bttv-input.c62
-rw-r--r--drivers/media/video/bt8xx/bttv.h2
-rw-r--r--drivers/media/video/btcx-risc.c2
-rw-r--r--drivers/media/video/bw-qcam.c26
-rw-r--r--drivers/media/video/bw-qcam.h1
-rw-r--r--drivers/media/video/c-qcam.c23
-rw-r--r--drivers/media/video/cafe_ccic.c19
-rw-r--r--drivers/media/video/cpia.c19
-rw-r--r--drivers/media/video/cpia2/cpia2_core.c10
-rw-r--r--drivers/media/video/cpia2/cpia2_usb.c2
-rw-r--r--drivers/media/video/cpia2/cpia2_v4l.c16
-rw-r--r--drivers/media/video/cx18/Makefile2
-rw-r--r--drivers/media/video/cx18/cx18-audio.c5
-rw-r--r--drivers/media/video/cx18/cx18-av-core.c23
-rw-r--r--drivers/media/video/cx18/cx18-av-core.h2
-rw-r--r--drivers/media/video/cx18/cx18-av-firmware.c25
-rw-r--r--drivers/media/video/cx18/cx18-cards.c99
-rw-r--r--drivers/media/video/cx18/cx18-driver.c51
-rw-r--r--drivers/media/video/cx18/cx18-driver.h71
-rw-r--r--drivers/media/video/cx18/cx18-dvb.c5
-rw-r--r--drivers/media/video/cx18/cx18-fileops.c47
-rw-r--r--drivers/media/video/cx18/cx18-firmware.c140
-rw-r--r--drivers/media/video/cx18/cx18-gpio.c17
-rw-r--r--drivers/media/video/cx18/cx18-gpio.h2
-rw-r--r--drivers/media/video/cx18/cx18-i2c.c49
-rw-r--r--drivers/media/video/cx18/cx18-io.c254
-rw-r--r--drivers/media/video/cx18/cx18-io.h378
-rw-r--r--drivers/media/video/cx18/cx18-ioctl.c34
-rw-r--r--drivers/media/video/cx18/cx18-irq.c47
-rw-r--r--drivers/media/video/cx18/cx18-mailbox.c45
-rw-r--r--drivers/media/video/cx18/cx18-queue.c18
-rw-r--r--drivers/media/video/cx18/cx18-scb.c131
-rw-r--r--drivers/media/video/cx18/cx18-streams.c70
-rw-r--r--drivers/media/video/cx18/cx18-version.h2
-rw-r--r--drivers/media/video/cx18/cx23418.h2
-rw-r--r--drivers/media/video/cx2341x.c5
-rw-r--r--drivers/media/video/cx23885/Kconfig1
-rw-r--r--drivers/media/video/cx23885/cx23885-417.c13
-rw-r--r--drivers/media/video/cx23885/cx23885-cards.c86
-rw-r--r--drivers/media/video/cx23885/cx23885-core.c2
-rw-r--r--drivers/media/video/cx23885/cx23885-dvb.c105
-rw-r--r--drivers/media/video/cx23885/cx23885-vbi.c12
-rw-r--r--drivers/media/video/cx23885/cx23885-video.c39
-rw-r--r--drivers/media/video/cx23885/cx23885.h4
-rw-r--r--drivers/media/video/cx25840/cx25840-vbi.c5
-rw-r--r--drivers/media/video/cx88/Kconfig4
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c9
-rw-r--r--drivers/media/video/cx88/cx88-cards.c306
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c198
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c16
-rw-r--r--drivers/media/video/cx88/cx88-input.c33
-rw-r--r--drivers/media/video/cx88/cx88-video.c15
-rw-r--r--drivers/media/video/cx88/cx88.h11
-rw-r--r--drivers/media/video/dabusb.c3
-rw-r--r--drivers/media/video/dpc7146.c408
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c4
-rw-r--r--drivers/media/video/em28xx/em28xx-dvb.c25
-rw-r--r--drivers/media/video/em28xx/em28xx-i2c.c35
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c60
-rw-r--r--drivers/media/video/em28xx/em28xx.h6
-rw-r--r--drivers/media/video/et61x251/et61x251_core.c14
-rw-r--r--drivers/media/video/gspca/Kconfig215
-rw-r--r--drivers/media/video/gspca/Makefile75
-rw-r--r--drivers/media/video/gspca/conex.c3
-rw-r--r--drivers/media/video/gspca/etoms.c3
-rw-r--r--drivers/media/video/gspca/finepix.c466
-rw-r--r--drivers/media/video/gspca/gspca.c245
-rw-r--r--drivers/media/video/gspca/gspca.h21
-rw-r--r--drivers/media/video/gspca/m5602/Kconfig11
-rw-r--r--drivers/media/video/gspca/m5602/Makefile11
-rw-r--r--drivers/media/video/gspca/m5602/m5602_bridge.h170
-rw-r--r--drivers/media/video/gspca/m5602/m5602_core.c313
-rw-r--r--drivers/media/video/gspca/m5602/m5602_mt9m111.c345
-rw-r--r--drivers/media/video/gspca/m5602/m5602_mt9m111.h1020
-rw-r--r--drivers/media/video/gspca/m5602/m5602_ov9650.c546
-rw-r--r--drivers/media/video/gspca/m5602/m5602_ov9650.h503
-rw-r--r--drivers/media/video/gspca/m5602/m5602_po1030.c336
-rw-r--r--drivers/media/video/gspca/m5602/m5602_po1030.h478
-rw-r--r--drivers/media/video/gspca/m5602/m5602_s5k4aa.c463
-rw-r--r--drivers/media/video/gspca/m5602/m5602_s5k4aa.h370
-rw-r--r--drivers/media/video/gspca/m5602/m5602_s5k83a.c423
-rw-r--r--drivers/media/video/gspca/m5602/m5602_s5k83a.h484
-rw-r--r--drivers/media/video/gspca/m5602/m5602_sensor.h76
-rw-r--r--drivers/media/video/gspca/mars.c20
-rw-r--r--drivers/media/video/gspca/ov519.c5
-rw-r--r--drivers/media/video/gspca/pac207.c4
-rw-r--r--drivers/media/video/gspca/pac7311.c3
-rw-r--r--drivers/media/video/gspca/sonixb.c5
-rw-r--r--drivers/media/video/gspca/sonixj.c89
-rw-r--r--drivers/media/video/gspca/spca500.c3
-rw-r--r--drivers/media/video/gspca/spca501.c3
-rw-r--r--drivers/media/video/gspca/spca505.c3
-rw-r--r--drivers/media/video/gspca/spca506.c3
-rw-r--r--drivers/media/video/gspca/spca508.c3
-rw-r--r--drivers/media/video/gspca/spca561.c10
-rw-r--r--drivers/media/video/gspca/stk014.c5
-rw-r--r--drivers/media/video/gspca/sunplus.c3
-rw-r--r--drivers/media/video/gspca/t613.c591
-rw-r--r--drivers/media/video/gspca/tv8532.c3
-rw-r--r--drivers/media/video/gspca/vc032x.c6
-rw-r--r--drivers/media/video/gspca/zc3xx.c3
-rw-r--r--drivers/media/video/ir-kbd-i2c.c64
-rw-r--r--drivers/media/video/ivtv/ivtv-cards.h2
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c12
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.h9
-rw-r--r--drivers/media/video/ivtv/ivtv-fileops.c8
-rw-r--r--drivers/media/video/ivtv/ivtv-fileops.h5
-rw-r--r--drivers/media/video/ivtv/ivtv-gpio.c2
-rw-r--r--drivers/media/video/ivtv/ivtv-gpio.h2
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.c2
-rw-r--r--drivers/media/video/ivtv/ivtv-ioctl.c58
-rw-r--r--drivers/media/video/ivtv/ivtv-irq.c9
-rw-r--r--drivers/media/video/ivtv/ivtv-streams.c42
-rw-r--r--drivers/media/video/ivtv/ivtv-vbi.c2
-rw-r--r--drivers/media/video/ivtv/ivtv-yuv.c1
-rw-r--r--drivers/media/video/ivtv/ivtvfb.c78
-rw-r--r--drivers/media/video/meye.c13
-rw-r--r--drivers/media/video/meye.h1
-rw-r--r--drivers/media/video/mt9m001.c55
-rw-r--r--drivers/media/video/mt9m111.c973
-rw-r--r--drivers/media/video/mt9v022.c52
-rw-r--r--drivers/media/video/mxb.c469
-rw-r--r--drivers/media/video/ov511.c105
-rw-r--r--drivers/media/video/ov511.h3
-rw-r--r--drivers/media/video/ovcamchip/ovcamchip_core.c6
-rw-r--r--drivers/media/video/ovcamchip/ovcamchip_priv.h6
-rw-r--r--drivers/media/video/pms.c23
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-ctrl.c8
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-ctrl.h2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h9
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.c340
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.h13
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c7
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c46
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h1
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-core.c42
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-main.c8
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-sysfs.c23
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-v4l2.c94
-rw-r--r--drivers/media/video/pwc/pwc-ctrl.c1
-rw-r--r--drivers/media/video/pwc/pwc-if.c12
-rw-r--r--drivers/media/video/pwc/pwc-v4l.c2
-rw-r--r--drivers/media/video/pxa_camera.c48
-rw-r--r--drivers/media/video/s2255drv.c572
-rw-r--r--drivers/media/video/saa5246a.c556
-rw-r--r--drivers/media/video/saa5246a.h359
-rw-r--r--drivers/media/video/saa5249.c704
-rw-r--r--drivers/media/video/saa7115.c42
-rw-r--r--drivers/media/video/saa7134/saa6752hs.c440
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c261
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c62
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c52
-rw-r--r--drivers/media/video/saa7134/saa7134-empress.c63
-rw-r--r--drivers/media/video/saa7134/saa7134-i2c.c11
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c210
-rw-r--r--drivers/media/video/saa7134/saa7134-ts.c56
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c63
-rw-r--r--drivers/media/video/saa7134/saa7134.h19
-rw-r--r--drivers/media/video/se401.c44
-rw-r--r--drivers/media/video/sh_mobile_ceu_camera.c5
-rw-r--r--drivers/media/video/sn9c102/sn9c102_core.c34
-rw-r--r--drivers/media/video/sn9c102/sn9c102_devtable.h20
-rw-r--r--drivers/media/video/sn9c102/sn9c102_hv7131d.c1
-rw-r--r--drivers/media/video/sn9c102/sn9c102_hv7131r.c1
-rw-r--r--drivers/media/video/sn9c102/sn9c102_mi0343.c1
-rw-r--r--drivers/media/video/sn9c102/sn9c102_mi0360.c1
-rw-r--r--drivers/media/video/sn9c102/sn9c102_mt9v111.c1
-rw-r--r--drivers/media/video/sn9c102/sn9c102_ov7630.c1
-rw-r--r--drivers/media/video/sn9c102/sn9c102_ov7660.c1
-rw-r--r--drivers/media/video/sn9c102/sn9c102_pas106b.c1
-rw-r--r--drivers/media/video/sn9c102/sn9c102_pas202bcb.c1
-rw-r--r--drivers/media/video/sn9c102/sn9c102_tas5110c1b.c1
-rw-r--r--drivers/media/video/sn9c102/sn9c102_tas5110d.c1
-rw-r--r--drivers/media/video/sn9c102/sn9c102_tas5130d1b.c1
-rw-r--r--drivers/media/video/stk-webcam.c90
-rw-r--r--drivers/media/video/stk-webcam.h2
-rw-r--r--drivers/media/video/stradis.c7
-rw-r--r--drivers/media/video/stv680.c8
-rw-r--r--drivers/media/video/tda9840.c260
-rw-r--r--drivers/media/video/tda9840.h21
-rw-r--r--drivers/media/video/tea6415c.c131
-rw-r--r--drivers/media/video/tea6420.c147
-rw-r--r--drivers/media/video/tuner-3036.c214
-rw-r--r--drivers/media/video/tuner-core.c13
-rw-r--r--drivers/media/video/usbvideo/ibmcam.c78
-rw-r--r--drivers/media/video/usbvideo/konicawc.c17
-rw-r--r--drivers/media/video/usbvideo/quickcam_messenger.c3
-rw-r--r--drivers/media/video/usbvideo/ultracam.c29
-rw-r--r--drivers/media/video/usbvideo/usbvideo.c166
-rw-r--r--drivers/media/video/usbvideo/vicam.c17
-rw-r--r--drivers/media/video/usbvision/usbvision-core.c7
-rw-r--r--drivers/media/video/usbvision/usbvision-i2c.c3
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c131
-rw-r--r--drivers/media/video/uvc/uvc_ctrl.c185
-rw-r--r--drivers/media/video/uvc/uvc_driver.c51
-rw-r--r--drivers/media/video/uvc/uvc_status.c11
-rw-r--r--drivers/media/video/uvc/uvc_v4l2.c17
-rw-r--r--drivers/media/video/uvc/uvc_video.c12
-rw-r--r--drivers/media/video/uvc/uvcvideo.h4
-rw-r--r--drivers/media/video/v4l1-compat.c4
-rw-r--r--drivers/media/video/v4l2-common.c187
-rw-r--r--drivers/media/video/v4l2-dev.c300
-rw-r--r--drivers/media/video/v4l2-ioctl.c12
-rw-r--r--drivers/media/video/vino.c30
-rw-r--r--drivers/media/video/vivi.c7
-rw-r--r--drivers/media/video/vpx3220.c2
-rw-r--r--drivers/media/video/w9966.c29
-rw-r--r--drivers/media/video/w9968cf.c4
-rw-r--r--drivers/media/video/zc0301/zc0301_core.c14
-rw-r--r--drivers/media/video/zoran/Kconfig73
-rw-r--r--drivers/media/video/zoran/Makefile6
-rw-r--r--drivers/media/video/zoran/videocodec.c (renamed from drivers/media/video/videocodec.c)0
-rw-r--r--drivers/media/video/zoran/videocodec.h (renamed from drivers/media/video/videocodec.h)0
-rw-r--r--drivers/media/video/zoran/zoran.h (renamed from drivers/media/video/zoran.h)0
-rw-r--r--drivers/media/video/zoran/zoran_card.c (renamed from drivers/media/video/zoran_card.c)0
-rw-r--r--drivers/media/video/zoran/zoran_card.h (renamed from drivers/media/video/zoran_card.h)0
-rw-r--r--drivers/media/video/zoran/zoran_device.c (renamed from drivers/media/video/zoran_device.c)6
-rw-r--r--drivers/media/video/zoran/zoran_device.h (renamed from drivers/media/video/zoran_device.h)8
-rw-r--r--drivers/media/video/zoran/zoran_driver.c (renamed from drivers/media/video/zoran_driver.c)13
-rw-r--r--drivers/media/video/zoran/zoran_procfs.c (renamed from drivers/media/video/zoran_procfs.c)0
-rw-r--r--drivers/media/video/zoran/zoran_procfs.h (renamed from drivers/media/video/zoran_procfs.h)0
-rw-r--r--drivers/media/video/zoran/zr36016.c (renamed from drivers/media/video/zr36016.c)0
-rw-r--r--drivers/media/video/zoran/zr36016.h (renamed from drivers/media/video/zr36016.h)0
-rw-r--r--drivers/media/video/zoran/zr36050.c (renamed from drivers/media/video/zr36050.c)0
-rw-r--r--drivers/media/video/zoran/zr36050.h (renamed from drivers/media/video/zr36050.h)0
-rw-r--r--drivers/media/video/zoran/zr36057.h (renamed from drivers/media/video/zr36057.h)0
-rw-r--r--drivers/media/video/zoran/zr36060.c (renamed from drivers/media/video/zr36060.c)0
-rw-r--r--drivers/media/video/zoran/zr36060.h (renamed from drivers/media/video/zr36060.h)0
-rw-r--r--drivers/media/video/zr364xx.c87
-rw-r--r--drivers/message/i2o/Makefile2
-rw-r--r--drivers/message/i2o/device.c2
-rw-r--r--drivers/message/i2o/exec-osm.c4
-rw-r--r--drivers/message/i2o/i2o_config.c31
-rw-r--r--drivers/message/i2o/iop.c2
-rw-r--r--drivers/message/i2o/memory.c313
-rw-r--r--drivers/message/i2o/pci.c16
-rw-r--r--drivers/mfd/Kconfig38
-rw-r--r--drivers/mfd/Makefile5
-rw-r--r--drivers/mfd/wm8350-core.c1273
-rw-r--r--drivers/mfd/wm8350-gpio.c222
-rw-r--r--drivers/mfd/wm8350-i2c.c120
-rw-r--r--drivers/mfd/wm8350-regmap.c1347
-rw-r--r--drivers/mfd/wm8400-core.c455
-rw-r--r--drivers/misc/Kconfig3
-rw-r--r--drivers/misc/hp-wmi.c2
-rw-r--r--drivers/misc/phantom.c6
-rw-r--r--drivers/misc/sgi-gru/gru.h4
-rw-r--r--drivers/misc/sgi-gru/gru_instructions.h10
-rw-r--r--drivers/misc/sgi-gru/grufault.c11
-rw-r--r--drivers/misc/sgi-gru/grufile.c8
-rw-r--r--drivers/misc/sgi-gru/gruhandles.h5
-rw-r--r--drivers/misc/sgi-gru/grukservices.c3
-rw-r--r--drivers/misc/sgi-gru/grumain.c29
-rw-r--r--drivers/mmc/host/omap.c11
-rw-r--r--drivers/mmc/host/sdhci-pci.c2
-rw-r--r--drivers/mtd/maps/pcmciamtd.c34
-rw-r--r--drivers/mtd/mtdchar.c10
-rw-r--r--drivers/mtd/mtdpart.c2
-rw-r--r--drivers/mtd/nand/ams-delta.c4
-rw-r--r--drivers/mtd/nand/cafe_nand.c6
-rw-r--r--drivers/net/3c501.c12
-rw-r--r--drivers/net/3c509.c2
-rw-r--r--drivers/net/3c515.c2
-rw-r--r--drivers/net/Kconfig14
-rw-r--r--drivers/net/appletalk/cops.c2
-rw-r--r--drivers/net/au1000_eth.c27
-rw-r--r--drivers/net/bfin_mac.c26
-rw-r--r--drivers/net/cs89x0.c13
-rw-r--r--drivers/net/cxgb3/adapter.h2
-rw-r--r--drivers/net/cxgb3/ael1002.c2
-rw-r--r--drivers/net/cxgb3/common.h2
-rw-r--r--drivers/net/cxgb3/cxgb3_ctl_defs.h2
-rw-r--r--drivers/net/cxgb3/cxgb3_defs.h2
-rw-r--r--drivers/net/cxgb3/cxgb3_ioctl.h2
-rw-r--r--drivers/net/cxgb3/cxgb3_main.c2
-rw-r--r--drivers/net/cxgb3/cxgb3_offload.c2
-rw-r--r--drivers/net/cxgb3/cxgb3_offload.h2
-rw-r--r--drivers/net/cxgb3/firmware_exports.h2
-rw-r--r--drivers/net/cxgb3/l2t.c2
-rw-r--r--drivers/net/cxgb3/l2t.h2
-rw-r--r--drivers/net/cxgb3/mc5.c2
-rw-r--r--drivers/net/cxgb3/sge.c2
-rw-r--r--drivers/net/cxgb3/t3_cpl.h2
-rw-r--r--drivers/net/cxgb3/t3_hw.c2
-rw-r--r--drivers/net/cxgb3/t3cdev.h2
-rw-r--r--drivers/net/cxgb3/version.h4
-rw-r--r--drivers/net/cxgb3/vsc8211.c2
-rw-r--r--drivers/net/cxgb3/xgmac.c2
-rw-r--r--drivers/net/eexpress.c2
-rw-r--r--drivers/net/enic/enic_main.c1
-rw-r--r--drivers/net/ibm_newemac/Kconfig12
-rw-r--r--drivers/net/ibm_newemac/core.c42
-rw-r--r--drivers/net/ibm_newemac/core.h6
-rw-r--r--drivers/net/ibm_newemac/mal.c60
-rw-r--r--drivers/net/ibm_newemac/mal.h34
-rw-r--r--drivers/net/ibm_newemac/phy.c84
-rw-r--r--drivers/net/ibm_newemac/phy.h2
-rw-r--r--drivers/net/ibmlana.c2
-rw-r--r--drivers/net/irda/sir_dongle.c2
-rw-r--r--drivers/net/ixgbe/ixgbe.h4
-rw-r--r--drivers/net/ixgbe/ixgbe_main.c32
-rw-r--r--drivers/net/jme.c2
-rw-r--r--drivers/net/macmace.c2
-rw-r--r--drivers/net/myri10ge/myri10ge.c26
-rw-r--r--drivers/net/pcmcia/3c574_cs.c7
-rw-r--r--drivers/net/pcmcia/3c589_cs.c9
-rw-r--r--drivers/net/pcmcia/Kconfig2
-rw-r--r--drivers/net/pcmcia/axnet_cs.c80
-rw-r--r--drivers/net/pcmcia/com20020_cs.c8
-rw-r--r--drivers/net/pcmcia/fmvj18x_cs.c21
-rw-r--r--drivers/net/pcmcia/ibmtr_cs.c2
-rw-r--r--drivers/net/pcmcia/nmclan_cs.c4
-rw-r--r--drivers/net/pcmcia/pcnet_cs.c86
-rw-r--r--drivers/net/pcmcia/smc91c92_cs.c151
-rw-r--r--drivers/net/pcmcia/xirc2ps_cs.c79
-rw-r--r--drivers/net/phy/mdio_bus.c1
-rw-r--r--drivers/net/phy/phy_device.c9
-rw-r--r--drivers/net/ppp_generic.c14
-rw-r--r--drivers/net/pppox.c9
-rw-r--r--drivers/net/qlge/qlge.h2
-rw-r--r--drivers/net/qlge/qlge_ethtool.c1
-rw-r--r--drivers/net/qlge/qlge_main.c2
-rw-r--r--drivers/net/r8169.c3
-rw-r--r--drivers/net/sky2.c19
-rw-r--r--drivers/net/smc911x.c6
-rw-r--r--drivers/net/smc911x.h14
-rw-r--r--drivers/net/tc35815.c2
-rw-r--r--drivers/net/tlan.c3
-rw-r--r--drivers/net/tokenring/smctr.c2
-rw-r--r--drivers/net/tulip/de2104x.c1
-rw-r--r--drivers/net/tulip/dmfe.c4
-rw-r--r--drivers/net/via-velocity.c2
-rw-r--r--drivers/net/wan/Kconfig2
-rw-r--r--drivers/net/wan/cosa.c4
-rw-r--r--drivers/net/wan/lmc/lmc_main.c31
-rw-r--r--drivers/net/wan/z85230.c3
-rw-r--r--drivers/net/wan/z85230.h2
-rw-r--r--drivers/net/wireless/airo_cs.c222
-rw-r--r--drivers/net/wireless/ath9k/main.c8
-rw-r--r--drivers/net/wireless/atmel_cs.c119
-rw-r--r--drivers/net/wireless/b43/pcmcia.c16
-rw-r--r--drivers/net/wireless/hostap/hostap_cs.c237
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000.c6
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.c2
-rw-r--r--drivers/net/wireless/libertas/cmd.c2
-rw-r--r--drivers/net/wireless/libertas/if_cs.c2
-rw-r--r--drivers/net/wireless/mac80211_hwsim.c6
-rw-r--r--drivers/net/wireless/netwave_cs.c5
-rw-r--r--drivers/net/wireless/orinoco_cs.c170
-rw-r--r--drivers/net/wireless/p54/p54common.c1
-rw-r--r--drivers/net/wireless/p54/p54usb.c3
-rw-r--r--drivers/net/wireless/ray_cs.c4
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00queue.c9
-rw-r--r--drivers/net/wireless/rtl8187_dev.c3
-rw-r--r--drivers/net/wireless/spectrum_cs.c167
-rw-r--r--drivers/net/wireless/wavelan.c2
-rw-r--r--drivers/net/wireless/wavelan.p.h2
-rw-r--r--drivers/net/wireless/wavelan_cs.c16
-rw-r--r--drivers/net/wireless/wl3501_cs.c4
-rw-r--r--drivers/net/xen-netfront.c7
-rw-r--r--drivers/nubus/nubus.c2
-rw-r--r--drivers/of/base.c136
-rw-r--r--drivers/of/gpio.c81
-rw-r--r--drivers/oprofile/buffer_sync.c209
-rw-r--r--drivers/oprofile/cpu_buffer.c74
-rw-r--r--drivers/oprofile/cpu_buffer.h2
-rw-r--r--drivers/parport/ChangeLog2
-rw-r--r--drivers/parport/ieee1284.c2
-rw-r--r--drivers/parport/parport_cs.c70
-rw-r--r--drivers/parport/probe.c2
-rw-r--r--drivers/parport/share.c2
-rw-r--r--drivers/pci/dma_remapping.h157
-rw-r--r--drivers/pci/dmar.c4
-rw-r--r--drivers/pci/hotplug/ibmphp_ebda.c2
-rw-r--r--drivers/pci/hotplug/rpaphp_slot.c4
-rw-r--r--drivers/pci/intel-iommu.c116
-rw-r--r--drivers/pci/intel-iommu.h307
-rw-r--r--drivers/pci/intr_remapping.c2
-rw-r--r--drivers/pci/intr_remapping.h2
-rw-r--r--drivers/pci/iova.c2
-rw-r--r--drivers/pci/iova.h52
-rw-r--r--drivers/pci/probe.c50
-rw-r--r--drivers/pci/quirks.c3
-rw-r--r--drivers/pci/setup-bus.c9
-rw-r--r--drivers/pcmcia/Makefile7
-rw-r--r--drivers/pcmcia/au1000_generic.c2
-rw-r--r--drivers/pcmcia/au1000_generic.h2
-rw-r--r--drivers/pcmcia/au1000_pb1x00.c1
-rw-r--r--drivers/pcmcia/au1000_xxs1500.c1
-rw-r--r--drivers/pcmcia/cardbus.c2
-rw-r--r--drivers/pcmcia/cistpl.c297
-rw-r--r--drivers/pcmcia/cs.c78
-rw-r--r--drivers/pcmcia/cs_internal.h226
-rw-r--r--drivers/pcmcia/ds.c239
-rw-r--r--drivers/pcmcia/ds_internal.h23
-rw-r--r--drivers/pcmcia/hd64465_ss.c1
-rw-r--r--drivers/pcmcia/i82365.c2
-rw-r--r--drivers/pcmcia/m32r_cfc.c4
-rw-r--r--drivers/pcmcia/m32r_pcc.c4
-rw-r--r--drivers/pcmcia/m8xx_pcmcia.c4
-rw-r--r--drivers/pcmcia/o2micro.h10
-rw-r--r--drivers/pcmcia/pcmcia_ioctl.c120
-rw-r--r--drivers/pcmcia/pcmcia_resource.c381
-rw-r--r--drivers/pcmcia/pxa2xx_base.c1
-rw-r--r--drivers/pcmcia/rsrc_nonstatic.c67
-rw-r--r--drivers/pcmcia/soc_common.c2
-rw-r--r--drivers/pcmcia/soc_common.h3
-rw-r--r--drivers/pcmcia/socket_sysfs.c13
-rw-r--r--drivers/pcmcia/tcic.c2
-rw-r--r--drivers/pcmcia/ti113x.h78
-rw-r--r--drivers/pcmcia/yenta_socket.c86
-rw-r--r--drivers/pnp/base.h4
-rw-r--r--drivers/pnp/core.c11
-rw-r--r--drivers/pnp/driver.c1
-rw-r--r--drivers/pnp/interface.c37
-rw-r--r--drivers/pnp/isapnp/core.c2
-rw-r--r--drivers/pnp/pnpbios/core.c4
-rw-r--r--drivers/pnp/quirks.c5
-rw-r--r--drivers/pnp/resource.c4
-rw-r--r--drivers/power/olpc_battery.c20
-rw-r--r--drivers/power/power_supply_core.c4
-rw-r--r--drivers/regulator/Kconfig24
-rw-r--r--drivers/regulator/Makefile3
-rw-r--r--drivers/regulator/bq24022.c21
-rw-r--r--drivers/regulator/core.c508
-rw-r--r--drivers/regulator/da903x.c513
-rw-r--r--drivers/regulator/wm8350-regulator.c1431
-rw-r--r--drivers/regulator/wm8400-regulator.c368
-rw-r--r--drivers/rtc/Kconfig39
-rw-r--r--drivers/rtc/Makefile3
-rw-r--r--drivers/rtc/rtc-at91rm9200.c4
-rw-r--r--drivers/rtc/rtc-cmos.c122
-rw-r--r--drivers/rtc/rtc-dev.c12
-rw-r--r--drivers/rtc/rtc-ds1286.c410
-rw-r--r--drivers/rtc/rtc-ds1307.c308
-rw-r--r--drivers/rtc/rtc-ds1374.c21
-rw-r--r--drivers/rtc/rtc-ds1511.c13
-rw-r--r--drivers/rtc/rtc-ds1553.c12
-rw-r--r--drivers/rtc/rtc-ds1672.c114
-rw-r--r--drivers/rtc/rtc-ds3234.c290
-rw-r--r--drivers/rtc/rtc-m41t80.c43
-rw-r--r--drivers/rtc/rtc-m48t35.c235
-rw-r--r--drivers/rtc/rtc-max6900.c223
-rw-r--r--drivers/rtc/rtc-pcf8563.c58
-rw-r--r--drivers/rtc/rtc-pl030.c11
-rw-r--r--drivers/rtc/rtc-pl031.c14
-rw-r--r--drivers/rtc/rtc-rs5c372.c228
-rw-r--r--drivers/rtc/rtc-sh.c7
-rw-r--r--drivers/rtc/rtc-stk17ta8.c12
-rw-r--r--drivers/s390/char/fs3270.c17
-rw-r--r--drivers/s390/char/raw3270.c14
-rw-r--r--drivers/s390/char/tape_class.c6
-rw-r--r--drivers/s390/char/vmlogrdr.c8
-rw-r--r--drivers/s390/char/vmur.c5
-rw-r--r--drivers/s390/net/claw.c2
-rw-r--r--drivers/s390/net/ctcm_mpc.c2
-rw-r--r--drivers/scsi/Kconfig9
-rw-r--r--drivers/scsi/atari_dma_emul.c468
-rw-r--r--drivers/scsi/atari_scsi.c27
-rw-r--r--drivers/scsi/ch.c6
-rw-r--r--drivers/scsi/dpt_i2o.c2
-rw-r--r--drivers/scsi/ide-scsi.c102
-rw-r--r--drivers/scsi/osst.c3
-rw-r--r--drivers/scsi/pcmcia/aha152x_stub.c58
-rw-r--r--drivers/scsi/pcmcia/fdomain_stub.c37
-rw-r--r--drivers/scsi/pcmcia/nsp_cs.c194
-rw-r--r--drivers/scsi/pcmcia/qlogic_stub.c47
-rw-r--r--drivers/scsi/pcmcia/sym53c500_cs.c46
-rw-r--r--drivers/scsi/sg.c10
-rw-r--r--drivers/scsi/st.c11
-rw-r--r--drivers/serial/8250.c72
-rw-r--r--drivers/serial/8250_pci.c4
-rw-r--r--drivers/serial/Kconfig53
-rw-r--r--drivers/serial/Makefile16
-rw-r--r--drivers/serial/bfin_5xx.c123
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_core.c3
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_cpm1.c6
-rw-r--r--drivers/serial/cpm_uart/cpm_uart_cpm2.c6
-rw-r--r--drivers/serial/crisv10.c5
-rw-r--r--drivers/serial/mcfserial.c1965
-rw-r--r--drivers/serial/mcfserial.h74
-rw-r--r--drivers/serial/mpc52xx_uart.c181
-rw-r--r--drivers/serial/s3c2400.c2
-rw-r--r--drivers/serial/s3c2410.c2
-rw-r--r--drivers/serial/s3c2412.c2
-rw-r--r--drivers/serial/s3c2440.c2
-rw-r--r--drivers/serial/samsung.c2
-rw-r--r--drivers/serial/serial_core.c12
-rw-r--r--drivers/serial/serial_cs.c302
-rw-r--r--drivers/serial/ucc_uart.c4
-rw-r--r--drivers/spi/mpc52xx_psc_spi.c61
-rw-r--r--drivers/spi/omap2_mcspi.c18
-rw-r--r--drivers/spi/omap_uwire.c23
-rw-r--r--drivers/spi/orion_spi.c5
-rw-r--r--drivers/spi/pxa2xx_spi.c54
-rw-r--r--drivers/spi/spi.c24
-rw-r--r--drivers/spi/spi_s3c24xx.c6
-rw-r--r--drivers/spi/spidev.c7
-rw-r--r--drivers/ssb/pcmcia.c22
-rw-r--r--drivers/telephony/ixj.c2
-rw-r--r--drivers/telephony/ixj_pcmcia.c72
-rw-r--r--drivers/uio/Kconfig13
-rw-r--r--drivers/uio/Makefile1
-rw-r--r--drivers/uio/uio.c26
-rw-r--r--drivers/uio/uio_pdrv.c2
-rw-r--r--drivers/uio/uio_sercos3.c243
-rw-r--r--drivers/usb/core/devio.c6
-rw-r--r--drivers/usb/core/file.c6
-rw-r--r--drivers/usb/core/hcd.c5
-rw-r--r--drivers/usb/core/inode.c2
-rw-r--r--drivers/usb/gadget/Makefile23
-rw-r--r--drivers/usb/gadget/cdc2.c25
-rw-r--r--drivers/usb/gadget/ether.c28
-rw-r--r--drivers/usb/gadget/f_ecm.c108
-rw-r--r--drivers/usb/gadget/f_loopback.c34
-rw-r--r--drivers/usb/gadget/f_subset.c44
-rw-r--r--drivers/usb/gadget/file_storage.c12
-rw-r--r--drivers/usb/gadget/gmidi.c15
-rw-r--r--drivers/usb/gadget/printer.c18
-rw-r--r--drivers/usb/gadget/rndis.c115
-rw-r--r--drivers/usb/gadget/serial.c18
-rw-r--r--drivers/usb/gadget/u_ether.c4
-rw-r--r--drivers/usb/gadget/zero.c17
-rw-r--r--drivers/usb/host/ohci-omap.c14
-rw-r--r--drivers/usb/host/sl811_cs.c133
-rw-r--r--drivers/usb/host/uhci-q.c24
-rw-r--r--drivers/usb/misc/phidgetkit.c5
-rw-r--r--drivers/usb/misc/phidgetmotorcontrol.c5
-rw-r--r--drivers/usb/misc/phidgetservo.c5
-rw-r--r--drivers/usb/mon/mon_bin.c6
-rw-r--r--drivers/usb/serial/aircable.c15
-rw-r--r--drivers/usb/serial/belkin_sa.c3
-rw-r--r--drivers/usb/serial/console.c8
-rw-r--r--drivers/usb/serial/cyberjack.c3
-rw-r--r--drivers/usb/serial/cypress_m8.c5
-rw-r--r--drivers/usb/serial/digi_acceleport.c19
-rw-r--r--drivers/usb/serial/empeg.c8
-rw-r--r--drivers/usb/serial/ftdi_sio.c25
-rw-r--r--drivers/usb/serial/garmin_gps.c3
-rw-r--r--drivers/usb/serial/generic.c3
-rw-r--r--drivers/usb/serial/io_edgeport.c43
-rw-r--r--drivers/usb/serial/io_ti.c26
-rw-r--r--drivers/usb/serial/ipaq.c3
-rw-r--r--drivers/usb/serial/ipw.c3
-rw-r--r--drivers/usb/serial/ir-usb.c3
-rw-r--r--drivers/usb/serial/iuu_phoenix.c3
-rw-r--r--drivers/usb/serial/keyspan.c77
-rw-r--r--drivers/usb/serial/keyspan_pda.c16
-rw-r--r--drivers/usb/serial/kl5kusb105.c3
-rw-r--r--drivers/usb/serial/kobil_sct.c3
-rw-r--r--drivers/usb/serial/mct_u232.c6
-rw-r--r--drivers/usb/serial/mos7720.c36
-rw-r--r--drivers/usb/serial/mos7840.c7
-rw-r--r--drivers/usb/serial/navman.c3
-rw-r--r--drivers/usb/serial/omninet.c10
-rw-r--r--drivers/usb/serial/option.c18
-rw-r--r--drivers/usb/serial/oti6858.c7
-rw-r--r--drivers/usb/serial/pl2303.c15
-rw-r--r--drivers/usb/serial/safe_serial.c11
-rw-r--r--drivers/usb/serial/sierra.c16
-rw-r--r--drivers/usb/serial/spcp8x5.c3
-rw-r--r--drivers/usb/serial/ti_usb_3410_5052.c44
-rw-r--r--drivers/usb/serial/usb-serial.c24
-rw-r--r--drivers/usb/serial/visor.c18
-rw-r--r--drivers/usb/serial/whiteheat.c8
-rw-r--r--drivers/video/Kconfig109
-rw-r--r--drivers/video/Makefile3
-rw-r--r--drivers/video/atmel_lcdfb.c7
-rw-r--r--drivers/video/aty/radeon_accel.c313
-rw-r--r--drivers/video/aty/radeon_backlight.c2
-rw-r--r--drivers/video/aty/radeon_base.c35
-rw-r--r--drivers/video/aty/radeon_i2c.c4
-rw-r--r--drivers/video/aty/radeon_pm.c6
-rw-r--r--drivers/video/aty/radeonfb.h53
-rw-r--r--drivers/video/backlight/mbp_nvidia_bl.c4
-rw-r--r--drivers/video/carminefb.c2
-rw-r--r--drivers/video/cirrusfb.c577
-rw-r--r--drivers/video/console/fbcon.c47
-rw-r--r--drivers/video/console/mdacon.c2
-rw-r--r--drivers/video/console/sticon.c4
-rw-r--r--drivers/video/console/vgacon.c43
-rw-r--r--drivers/video/display/display-sysfs.c9
-rw-r--r--drivers/video/efifb.c191
-rw-r--r--drivers/video/fbmem.c22
-rw-r--r--drivers/video/fbmon.c8
-rw-r--r--drivers/video/imacfb.c376
-rw-r--r--drivers/video/intelfb/intelfb.h7
-rw-r--r--drivers/video/intelfb/intelfb_i2c.c1
-rw-r--r--drivers/video/intelfb/intelfbdrv.c7
-rw-r--r--drivers/video/intelfb/intelfbhw.c7
-rw-r--r--drivers/video/matrox/matroxfb_base.c9
-rw-r--r--drivers/video/metronomefb.c2
-rw-r--r--drivers/video/neofb.c60
-rw-r--r--drivers/video/omap/dispc.c21
-rw-r--r--drivers/video/omap/dispc.h2
-rw-r--r--drivers/video/omap/lcd_h4.c4
-rw-r--r--drivers/video/omap/lcd_inn1610.c22
-rw-r--r--drivers/video/omap/lcd_osk.c10
-rw-r--r--drivers/video/omap/lcd_sx1.c99
-rw-r--r--drivers/video/omap/lcdc.c2
-rw-r--r--drivers/video/omap/lcdc.h2
-rw-r--r--drivers/video/omap/omapfb_main.c15
-rw-r--r--drivers/video/omap/rfbi.c9
-rw-r--r--drivers/video/omap/sossi.c8
-rw-r--r--drivers/video/s1d13xxxfb.c23
-rw-r--r--drivers/video/tdfxfb.c48
-rw-r--r--drivers/video/tmiofb.c1050
-rw-r--r--drivers/video/uvesafb.c11
-rw-r--r--drivers/video/vga16fb.c11
-rw-r--r--drivers/video/via/Makefile7
-rw-r--r--drivers/video/via/accel.c279
-rw-r--r--drivers/video/via/accel.h169
-rw-r--r--drivers/video/via/chip.h190
-rw-r--r--drivers/video/via/debug.h41
-rw-r--r--drivers/video/via/dvi.c682
-rw-r--r--drivers/video/via/dvi.h64
-rw-r--r--drivers/video/via/global.c60
-rw-r--r--drivers/video/via/global.h90
-rw-r--r--drivers/video/via/hw.c2865
-rw-r--r--drivers/video/via/hw.h933
-rw-r--r--drivers/video/via/iface.c78
-rw-r--r--drivers/video/via/iface.h38
-rw-r--r--drivers/video/via/ioctl.c112
-rw-r--r--drivers/video/via/ioctl.h210
-rw-r--r--drivers/video/via/lcd.c1821
-rw-r--r--drivers/video/via/lcd.h94
-rw-r--r--drivers/video/via/lcdtbl.h591
-rw-r--r--drivers/video/via/share.h1105
-rw-r--r--drivers/video/via/tbl1636.c71
-rw-r--r--drivers/video/via/tbl1636.h34
-rw-r--r--drivers/video/via/tblDPASetting.c109
-rw-r--r--drivers/video/via/tblDPASetting.h47
-rw-r--r--drivers/video/via/via_i2c.c177
-rw-r--r--drivers/video/via/via_i2c.h46
-rw-r--r--drivers/video/via/via_utility.c253
-rw-r--r--drivers/video/via/via_utility.h35
-rw-r--r--drivers/video/via/viafbdev.c2571
-rw-r--r--drivers/video/via/viafbdev.h112
-rw-r--r--drivers/video/via/viamode.c1086
-rw-r--r--drivers/video/via/viamode.h177
-rw-r--r--drivers/video/via/vt1636.c306
-rw-r--r--drivers/video/via/vt1636.h44
-rw-r--r--drivers/w1/masters/ds1wm.c10
-rw-r--r--drivers/w1/masters/ds2490.c348
-rw-r--r--drivers/w1/slaves/w1_ds2431.c312
-rw-r--r--drivers/w1/slaves/w1_therm.c72
-rw-r--r--drivers/w1/w1.c423
-rw-r--r--drivers/w1/w1.h34
-rw-r--r--drivers/w1/w1_family.c13
-rw-r--r--drivers/w1/w1_family.h3
-rw-r--r--drivers/w1/w1_int.c88
-rw-r--r--drivers/w1/w1_io.c85
1094 files changed, 74133 insertions, 25698 deletions
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 12cf5d491f0d..da49b006bcc5 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -259,7 +259,7 @@ config ACPI_ASUS
259 259
260config ACPI_TOSHIBA 260config ACPI_TOSHIBA
261 tristate "Toshiba Laptop Extras" 261 tristate "Toshiba Laptop Extras"
262 depends on X86 262 depends on X86 && INPUT
263 select INPUT_POLLDEV 263 select INPUT_POLLDEV
264 select NET 264 select NET
265 select RFKILL 265 select RFKILL
diff --git a/drivers/acpi/glue.c b/drivers/acpi/glue.c
index 3c578ef78c48..24649ada08df 100644
--- a/drivers/acpi/glue.c
+++ b/drivers/acpi/glue.c
@@ -260,115 +260,3 @@ static int __init init_acpi_device_notify(void)
260} 260}
261 261
262arch_initcall(init_acpi_device_notify); 262arch_initcall(init_acpi_device_notify);
263
264
265#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE)
266
267#ifdef CONFIG_PM
268static u32 rtc_handler(void *context)
269{
270 acpi_clear_event(ACPI_EVENT_RTC);
271 acpi_disable_event(ACPI_EVENT_RTC, 0);
272 return ACPI_INTERRUPT_HANDLED;
273}
274
275static inline void rtc_wake_setup(void)
276{
277 acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL);
278 /*
279 * After the RTC handler is installed, the Fixed_RTC event should
280 * be disabled. Only when the RTC alarm is set will it be enabled.
281 */
282 acpi_clear_event(ACPI_EVENT_RTC);
283 acpi_disable_event(ACPI_EVENT_RTC, 0);
284}
285
286static void rtc_wake_on(struct device *dev)
287{
288 acpi_clear_event(ACPI_EVENT_RTC);
289 acpi_enable_event(ACPI_EVENT_RTC, 0);
290}
291
292static void rtc_wake_off(struct device *dev)
293{
294 acpi_disable_event(ACPI_EVENT_RTC, 0);
295}
296#else
297#define rtc_wake_setup() do{}while(0)
298#define rtc_wake_on NULL
299#define rtc_wake_off NULL
300#endif
301
302/* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find
303 * its device node and pass extra config data. This helps its driver use
304 * capabilities that the now-obsolete mc146818 didn't have, and informs it
305 * that this board's RTC is wakeup-capable (per ACPI spec).
306 */
307#include <linux/mc146818rtc.h>
308
309static struct cmos_rtc_board_info rtc_info;
310
311
312/* PNP devices are registered in a subsys_initcall();
313 * ACPI specifies the PNP IDs to use.
314 */
315#include <linux/pnp.h>
316
317static int __init pnp_match(struct device *dev, void *data)
318{
319 static const char *ids[] = { "PNP0b00", "PNP0b01", "PNP0b02", };
320 struct pnp_dev *pnp = to_pnp_dev(dev);
321 int i;
322
323 for (i = 0; i < ARRAY_SIZE(ids); i++) {
324 if (compare_pnp_id(pnp->id, ids[i]) != 0)
325 return 1;
326 }
327 return 0;
328}
329
330static struct device *__init get_rtc_dev(void)
331{
332 return bus_find_device(&pnp_bus_type, NULL, NULL, pnp_match);
333}
334
335static int __init acpi_rtc_init(void)
336{
337 struct device *dev = get_rtc_dev();
338
339 if (acpi_disabled)
340 return 0;
341
342 if (dev) {
343 rtc_wake_setup();
344 rtc_info.wake_on = rtc_wake_on;
345 rtc_info.wake_off = rtc_wake_off;
346
347 /* workaround bug in some ACPI tables */
348 if (acpi_gbl_FADT.month_alarm && !acpi_gbl_FADT.day_alarm) {
349 DBG("bogus FADT month_alarm\n");
350 acpi_gbl_FADT.month_alarm = 0;
351 }
352
353 rtc_info.rtc_day_alarm = acpi_gbl_FADT.day_alarm;
354 rtc_info.rtc_mon_alarm = acpi_gbl_FADT.month_alarm;
355 rtc_info.rtc_century = acpi_gbl_FADT.century;
356
357 /* NOTE: S4_RTC_WAKE is NOT currently useful to Linux */
358 if (acpi_gbl_FADT.flags & ACPI_FADT_S4_RTC_WAKE)
359 printk(PREFIX "RTC can wake from S4\n");
360
361
362 dev->platform_data = &rtc_info;
363
364 /* RTC always wakes from S1/S2/S3, and often S4/STD */
365 device_init_wakeup(dev, 1);
366
367 put_device(dev);
368 } else
369 DBG("RTC unavailable?\n");
370 return 0;
371}
372module_init(acpi_rtc_init);
373
374#endif
diff --git a/drivers/ata/pata_of_platform.c b/drivers/ata/pata_of_platform.c
index 408da30594c4..1f18ad9e4fe1 100644
--- a/drivers/ata/pata_of_platform.c
+++ b/drivers/ata/pata_of_platform.c
@@ -52,7 +52,7 @@ static int __devinit pata_of_platform_probe(struct of_device *ofdev,
52 52
53 ret = of_irq_to_resource(dn, 0, &irq_res); 53 ret = of_irq_to_resource(dn, 0, &irq_res);
54 if (ret == NO_IRQ) 54 if (ret == NO_IRQ)
55 irq_res.start = irq_res.end = -1; 55 irq_res.start = irq_res.end = 0;
56 else 56 else
57 irq_res.flags = 0; 57 irq_res.flags = 0;
58 58
diff --git a/drivers/ata/pata_pcmcia.c b/drivers/ata/pata_pcmcia.c
index 41b4361bbf6e..02b596b9cf6a 100644
--- a/drivers/ata/pata_pcmcia.c
+++ b/drivers/ata/pata_pcmcia.c
@@ -148,6 +148,64 @@ static struct ata_port_operations pcmcia_8bit_port_ops = {
148#define CS_CHECK(fn, ret) \ 148#define CS_CHECK(fn, ret) \
149do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 149do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
150 150
151
152struct pcmcia_config_check {
153 unsigned long ctl_base;
154 int skip_vcc;
155 int is_kme;
156};
157
158static int pcmcia_check_one_config(struct pcmcia_device *pdev,
159 cistpl_cftable_entry_t *cfg,
160 cistpl_cftable_entry_t *dflt,
161 unsigned int vcc,
162 void *priv_data)
163{
164 struct pcmcia_config_check *stk = priv_data;
165
166 /* Check for matching Vcc, unless we're desperate */
167 if (!stk->skip_vcc) {
168 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
169 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
170 return -ENODEV;
171 } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
172 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] / 10000)
173 return -ENODEV;
174 }
175 }
176
177 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
178 pdev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
179 else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
180 pdev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
181
182 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
183 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
184 pdev->io.BasePort1 = io->win[0].base;
185 pdev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
186 if (!(io->flags & CISTPL_IO_16BIT))
187 pdev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
188 if (io->nwin == 2) {
189 pdev->io.NumPorts1 = 8;
190 pdev->io.BasePort2 = io->win[1].base;
191 pdev->io.NumPorts2 = (stk->is_kme) ? 2 : 1;
192 if (pcmcia_request_io(pdev, &pdev->io) != 0)
193 return -ENODEV;
194 stk->ctl_base = pdev->io.BasePort2;
195 } else if ((io->nwin == 1) && (io->win[0].len >= 16)) {
196 pdev->io.NumPorts1 = io->win[0].len;
197 pdev->io.NumPorts2 = 0;
198 if (pcmcia_request_io(pdev, &pdev->io) != 0)
199 return -ENODEV;
200 stk->ctl_base = pdev->io.BasePort1 + 0x0e;
201 } else
202 return -ENODEV;
203 /* If we've got this far, we're done */
204 return 0;
205 }
206 return -ENODEV;
207}
208
151/** 209/**
152 * pcmcia_init_one - attach a PCMCIA interface 210 * pcmcia_init_one - attach a PCMCIA interface
153 * @pdev: pcmcia device 211 * @pdev: pcmcia device
@@ -161,19 +219,11 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
161 struct ata_host *host; 219 struct ata_host *host;
162 struct ata_port *ap; 220 struct ata_port *ap;
163 struct ata_pcmcia_info *info; 221 struct ata_pcmcia_info *info;
164 tuple_t tuple; 222 struct pcmcia_config_check *stk = NULL;
165 struct { 223 int last_ret = 0, last_fn = 0, is_kme = 0, ret = -ENOMEM, p;
166 unsigned short buf[128];
167 cisparse_t parse;
168 config_info_t conf;
169 cistpl_cftable_entry_t dflt;
170 } *stk = NULL;
171 cistpl_cftable_entry_t *cfg;
172 int pass, last_ret = 0, last_fn = 0, is_kme = 0, ret = -ENOMEM, p;
173 unsigned long io_base, ctl_base; 224 unsigned long io_base, ctl_base;
174 void __iomem *io_addr, *ctl_addr; 225 void __iomem *io_addr, *ctl_addr;
175 int n_ports = 1; 226 int n_ports = 1;
176
177 struct ata_port_operations *ops = &pcmcia_port_ops; 227 struct ata_port_operations *ops = &pcmcia_port_ops;
178 228
179 info = kzalloc(sizeof(*info), GFP_KERNEL); 229 info = kzalloc(sizeof(*info), GFP_KERNEL);
@@ -193,96 +243,27 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
193 pdev->conf.Attributes = CONF_ENABLE_IRQ; 243 pdev->conf.Attributes = CONF_ENABLE_IRQ;
194 pdev->conf.IntType = INT_MEMORY_AND_IO; 244 pdev->conf.IntType = INT_MEMORY_AND_IO;
195 245
196 /* Allocate resoure probing structures */
197
198 stk = kzalloc(sizeof(*stk), GFP_KERNEL);
199 if (!stk)
200 goto out1;
201
202 cfg = &stk->parse.cftable_entry;
203
204 /* Tuples we are walking */
205 tuple.TupleData = (cisdata_t *)&stk->buf;
206 tuple.TupleOffset = 0;
207 tuple.TupleDataMax = 255;
208 tuple.Attributes = 0;
209
210 /* See if we have a manufacturer identifier. Use it to set is_kme for 246 /* See if we have a manufacturer identifier. Use it to set is_kme for
211 vendor quirks */ 247 vendor quirks */
212 is_kme = ((pdev->manf_id == MANFID_KME) && 248 is_kme = ((pdev->manf_id == MANFID_KME) &&
213 ((pdev->card_id == PRODID_KME_KXLC005_A) || 249 ((pdev->card_id == PRODID_KME_KXLC005_A) ||
214 (pdev->card_id == PRODID_KME_KXLC005_B))); 250 (pdev->card_id == PRODID_KME_KXLC005_B)));
215 251
216 /* Not sure if this is right... look up the current Vcc */ 252 /* Allocate resoure probing structures */
217 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(pdev, &stk->conf));
218/* link->conf.Vcc = stk->conf.Vcc; */
219
220 pass = io_base = ctl_base = 0;
221 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
222 tuple.Attributes = 0;
223 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(pdev, &tuple));
224
225 /* Now munch the resources looking for a suitable set */
226 while (1) {
227 if (pcmcia_get_tuple_data(pdev, &tuple) != 0)
228 goto next_entry;
229 if (pcmcia_parse_tuple(pdev, &tuple, &stk->parse) != 0)
230 goto next_entry;
231 /* Check for matching Vcc, unless we're desperate */
232 if (!pass) {
233 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
234 if (stk->conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
235 goto next_entry;
236 } else if (stk->dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
237 if (stk->conf.Vcc != stk->dflt.vcc.param[CISTPL_POWER_VNOM] / 10000)
238 goto next_entry;
239 }
240 }
241 253
242 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) 254 stk = kzalloc(sizeof(*stk), GFP_KERNEL);
243 pdev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; 255 if (!stk)
244 else if (stk->dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) 256 goto out1;
245 pdev->conf.Vpp = stk->dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; 257 stk->is_kme = is_kme;
246 258 stk->skip_vcc = io_base = ctl_base = 0;
247 if ((cfg->io.nwin > 0) || (stk->dflt.io.nwin > 0)) {
248 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &stk->dflt.io;
249 pdev->conf.ConfigIndex = cfg->index;
250 pdev->io.BasePort1 = io->win[0].base;
251 pdev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
252 if (!(io->flags & CISTPL_IO_16BIT))
253 pdev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
254 if (io->nwin == 2) {
255 pdev->io.NumPorts1 = 8;
256 pdev->io.BasePort2 = io->win[1].base;
257 pdev->io.NumPorts2 = (is_kme) ? 2 : 1;
258 if (pcmcia_request_io(pdev, &pdev->io) != 0)
259 goto next_entry;
260 io_base = pdev->io.BasePort1;
261 ctl_base = pdev->io.BasePort2;
262 } else if ((io->nwin == 1) && (io->win[0].len >= 16)) {
263 pdev->io.NumPorts1 = io->win[0].len;
264 pdev->io.NumPorts2 = 0;
265 if (pcmcia_request_io(pdev, &pdev->io) != 0)
266 goto next_entry;
267 io_base = pdev->io.BasePort1;
268 ctl_base = pdev->io.BasePort1 + 0x0e;
269 } else
270 goto next_entry;
271 /* If we've got this far, we're done */
272 break;
273 }
274next_entry:
275 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
276 memcpy(&stk->dflt, cfg, sizeof(stk->dflt));
277 if (pass) {
278 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(pdev, &tuple));
279 } else if (pcmcia_get_next_tuple(pdev, &tuple) != 0) {
280 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(pdev, &tuple));
281 memset(&stk->dflt, 0, sizeof(stk->dflt));
282 pass++;
283 }
284 }
285 259
260 if (pcmcia_loop_config(pdev, pcmcia_check_one_config, stk)) {
261 stk->skip_vcc = 1;
262 if (pcmcia_loop_config(pdev, pcmcia_check_one_config, stk))
263 goto failed; /* No suitable config found */
264 }
265 io_base = pdev->io.BasePort1;
266 ctl_base = stk->ctl_base;
286 CS_CHECK(RequestIRQ, pcmcia_request_irq(pdev, &pdev->irq)); 267 CS_CHECK(RequestIRQ, pcmcia_request_irq(pdev, &pdev->irq));
287 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(pdev, &pdev->conf)); 268 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(pdev, &pdev->conf));
288 269
@@ -384,6 +365,7 @@ static struct pcmcia_device_id pcmcia_devices[] = {
384 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704), 365 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704),
385 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x2904), 366 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x2904),
386 PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401), /* SanDisk CFA */ 367 PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401), /* SanDisk CFA */
368 PCMCIA_DEVICE_MANF_CARD(0x004f, 0x0000), /* Kingston */
387 PCMCIA_DEVICE_MANF_CARD(0x0097, 0x1620), /* TI emulated */ 369 PCMCIA_DEVICE_MANF_CARD(0x0097, 0x1620), /* TI emulated */
388 PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000), /* Toshiba */ 370 PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000), /* Toshiba */
389 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d), 371 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d),
@@ -404,9 +386,9 @@ static struct pcmcia_device_id pcmcia_devices[] = {
404 PCMCIA_DEVICE_PROD_ID12("EXP ", "CD-ROM", 0x0a5c52fd, 0x66536591), 386 PCMCIA_DEVICE_PROD_ID12("EXP ", "CD-ROM", 0x0a5c52fd, 0x66536591),
405 PCMCIA_DEVICE_PROD_ID12("EXP ", "PnPIDE", 0x0a5c52fd, 0x0c694728), 387 PCMCIA_DEVICE_PROD_ID12("EXP ", "PnPIDE", 0x0a5c52fd, 0x0c694728),
406 PCMCIA_DEVICE_PROD_ID12("FREECOM", "PCCARD-IDE", 0x5714cbf7, 0x48e0ab8e), 388 PCMCIA_DEVICE_PROD_ID12("FREECOM", "PCCARD-IDE", 0x5714cbf7, 0x48e0ab8e),
407 PCMCIA_DEVICE_PROD_ID12("Hyperstone", "Model1", 0x3d5b9ef5, 0xca6ab420),
408 PCMCIA_DEVICE_PROD_ID12("HITACHI", "FLASH", 0xf4f43949, 0x9eb86aae), 389 PCMCIA_DEVICE_PROD_ID12("HITACHI", "FLASH", 0xf4f43949, 0x9eb86aae),
409 PCMCIA_DEVICE_PROD_ID12("HITACHI", "microdrive", 0xf4f43949, 0xa6d76178), 390 PCMCIA_DEVICE_PROD_ID12("HITACHI", "microdrive", 0xf4f43949, 0xa6d76178),
391 PCMCIA_DEVICE_PROD_ID12("Hyperstone", "Model1", 0x3d5b9ef5, 0xca6ab420),
410 PCMCIA_DEVICE_PROD_ID12("IBM", "microdrive", 0xb569a6e5, 0xa6d76178), 392 PCMCIA_DEVICE_PROD_ID12("IBM", "microdrive", 0xb569a6e5, 0xa6d76178),
411 PCMCIA_DEVICE_PROD_ID12("IBM", "IBM17JSSFP20", 0xb569a6e5, 0xf2508753), 393 PCMCIA_DEVICE_PROD_ID12("IBM", "IBM17JSSFP20", 0xb569a6e5, 0xf2508753),
412 PCMCIA_DEVICE_PROD_ID12("KINGSTON", "CF8GB", 0x2e6d1829, 0xacbe682e), 394 PCMCIA_DEVICE_PROD_ID12("KINGSTON", "CF8GB", 0x2e6d1829, 0xacbe682e),
diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig
index 6318f6b57360..d8e8c49c0cbd 100644
--- a/drivers/base/Kconfig
+++ b/drivers/base/Kconfig
@@ -54,7 +54,7 @@ config FIRMWARE_IN_KERNEL
54 such firmware, and do not wish to use an initrd. 54 such firmware, and do not wish to use an initrd.
55 55
56 This single option controls the inclusion of firmware for 56 This single option controls the inclusion of firmware for
57 every driver which usees request_firmare() and ships its 57 every driver which uses request_firmare() and ships its
58 firmware in the kernel source tree, to avoid a proliferation 58 firmware in the kernel source tree, to avoid a proliferation
59 of 'Include firmware for xxx device' options. 59 of 'Include firmware for xxx device' options.
60 60
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index ef522ae55480..5aee1c0169ea 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -333,9 +333,7 @@ static int match_name(struct device *dev, void *data)
333{ 333{
334 const char *name = data; 334 const char *name = data;
335 335
336 if (strcmp(name, dev->bus_id) == 0) 336 return sysfs_streq(name, dev->bus_id);
337 return 1;
338 return 0;
339} 337}
340 338
341/** 339/**
@@ -982,6 +980,56 @@ struct klist *bus_get_device_klist(struct bus_type *bus)
982} 980}
983EXPORT_SYMBOL_GPL(bus_get_device_klist); 981EXPORT_SYMBOL_GPL(bus_get_device_klist);
984 982
983/*
984 * Yes, this forcably breaks the klist abstraction temporarily. It
985 * just wants to sort the klist, not change reference counts and
986 * take/drop locks rapidly in the process. It does all this while
987 * holding the lock for the list, so objects can't otherwise be
988 * added/removed while we're swizzling.
989 */
990static void device_insertion_sort_klist(struct device *a, struct list_head *list,
991 int (*compare)(const struct device *a,
992 const struct device *b))
993{
994 struct list_head *pos;
995 struct klist_node *n;
996 struct device *b;
997
998 list_for_each(pos, list) {
999 n = container_of(pos, struct klist_node, n_node);
1000 b = container_of(n, struct device, knode_bus);
1001 if (compare(a, b) <= 0) {
1002 list_move_tail(&a->knode_bus.n_node,
1003 &b->knode_bus.n_node);
1004 return;
1005 }
1006 }
1007 list_move_tail(&a->knode_bus.n_node, list);
1008}
1009
1010void bus_sort_breadthfirst(struct bus_type *bus,
1011 int (*compare)(const struct device *a,
1012 const struct device *b))
1013{
1014 LIST_HEAD(sorted_devices);
1015 struct list_head *pos, *tmp;
1016 struct klist_node *n;
1017 struct device *dev;
1018 struct klist *device_klist;
1019
1020 device_klist = bus_get_device_klist(bus);
1021
1022 spin_lock(&device_klist->k_lock);
1023 list_for_each_safe(pos, tmp, &device_klist->k_list) {
1024 n = container_of(pos, struct klist_node, n_node);
1025 dev = container_of(n, struct device, knode_bus);
1026 device_insertion_sort_klist(dev, &sorted_devices, compare);
1027 }
1028 list_splice(&sorted_devices, &device_klist->k_list);
1029 spin_unlock(&device_klist->k_lock);
1030}
1031EXPORT_SYMBOL_GPL(bus_sort_breadthfirst);
1032
985int __init buses_init(void) 1033int __init buses_init(void)
986{ 1034{
987 bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL); 1035 bus_kset = kset_create_and_add("bus", &bus_uevent_ops, NULL);
diff --git a/drivers/base/core.c b/drivers/base/core.c
index b98cb1416a2d..8c2cc2648f5a 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -523,11 +523,16 @@ static void klist_children_put(struct klist_node *n)
523 * device_initialize - init device structure. 523 * device_initialize - init device structure.
524 * @dev: device. 524 * @dev: device.
525 * 525 *
526 * This prepares the device for use by other layers, 526 * This prepares the device for use by other layers by initializing
527 * including adding it to the device hierarchy. 527 * its fields.
528 * It is the first half of device_register(), if called by 528 * It is the first half of device_register(), if called by
529 * that, though it can also be called separately, so one 529 * that function, though it can also be called separately, so one
530 * may use @dev's fields (e.g. the refcount). 530 * may use @dev's fields. In particular, get_device()/put_device()
531 * may be used for reference counting of @dev after calling this
532 * function.
533 *
534 * NOTE: Use put_device() to give up your reference instead of freeing
535 * @dev directly once you have called this function.
531 */ 536 */
532void device_initialize(struct device *dev) 537void device_initialize(struct device *dev)
533{ 538{
@@ -835,9 +840,13 @@ static void device_remove_sys_dev_entry(struct device *dev)
835 * This is part 2 of device_register(), though may be called 840 * This is part 2 of device_register(), though may be called
836 * separately _iff_ device_initialize() has been called separately. 841 * separately _iff_ device_initialize() has been called separately.
837 * 842 *
838 * This adds it to the kobject hierarchy via kobject_add(), adds it 843 * This adds @dev to the kobject hierarchy via kobject_add(), adds it
839 * to the global and sibling lists for the device, then 844 * to the global and sibling lists for the device, then
840 * adds it to the other relevant subsystems of the driver model. 845 * adds it to the other relevant subsystems of the driver model.
846 *
847 * NOTE: _Never_ directly free @dev after calling this function, even
848 * if it returned an error! Always use put_device() to give up your
849 * reference instead.
841 */ 850 */
842int device_add(struct device *dev) 851int device_add(struct device *dev)
843{ 852{
@@ -965,6 +974,10 @@ done:
965 * I.e. you should only call the two helpers separately if 974 * I.e. you should only call the two helpers separately if
966 * have a clearly defined need to use and refcount the device 975 * have a clearly defined need to use and refcount the device
967 * before it is added to the hierarchy. 976 * before it is added to the hierarchy.
977 *
978 * NOTE: _Never_ directly free @dev after calling this function, even
979 * if it returned an error! Always use put_device() to give up the
980 * reference initialized in this function instead.
968 */ 981 */
969int device_register(struct device *dev) 982int device_register(struct device *dev)
970{ 983{
@@ -1243,7 +1256,7 @@ struct device *device_create_vargs(struct class *class, struct device *parent,
1243 return dev; 1256 return dev;
1244 1257
1245error: 1258error:
1246 kfree(dev); 1259 put_device(dev);
1247 return ERR_PTR(retval); 1260 return ERR_PTR(retval);
1248} 1261}
1249EXPORT_SYMBOL_GPL(device_create_vargs); 1262EXPORT_SYMBOL_GPL(device_create_vargs);
@@ -1314,6 +1327,11 @@ EXPORT_SYMBOL_GPL(device_destroy);
1314 * device_rename - renames a device 1327 * device_rename - renames a device
1315 * @dev: the pointer to the struct device to be renamed 1328 * @dev: the pointer to the struct device to be renamed
1316 * @new_name: the new name of the device 1329 * @new_name: the new name of the device
1330 *
1331 * It is the responsibility of the caller to provide mutual
1332 * exclusion between two different calls of device_rename
1333 * on the same device to ensure that new_name is valid and
1334 * won't conflict with other devices.
1317 */ 1335 */
1318int device_rename(struct device *dev, char *new_name) 1336int device_rename(struct device *dev, char *new_name)
1319{ 1337{
diff --git a/drivers/base/dd.c b/drivers/base/dd.c
index 3ac443b2ac08..20febc00a525 100644
--- a/drivers/base/dd.c
+++ b/drivers/base/dd.c
@@ -257,6 +257,9 @@ static int __driver_attach(struct device *dev, void *data)
257 * is an error. 257 * is an error.
258 */ 258 */
259 259
260 if (drv->bus->match && !drv->bus->match(dev, drv))
261 return 0;
262
260 if (dev->parent) /* Needed for USB */ 263 if (dev->parent) /* Needed for USB */
261 down(&dev->parent->sem); 264 down(&dev->parent->sem);
262 down(&dev->sem); 265 down(&dev->sem);
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index c9c92b00fd55..b7e571031ecd 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -164,8 +164,7 @@ static ssize_t firmware_loading_store(struct device *dev,
164 } 164 }
165 /* fallthrough */ 165 /* fallthrough */
166 default: 166 default:
167 printk(KERN_ERR "%s: unexpected value (%d)\n", __func__, 167 dev_err(dev, "%s: unexpected value (%d)\n", __func__, loading);
168 loading);
169 /* fallthrough */ 168 /* fallthrough */
170 case -1: 169 case -1:
171 fw_load_abort(fw_priv); 170 fw_load_abort(fw_priv);
@@ -309,7 +308,7 @@ static int fw_register_device(struct device **dev_p, const char *fw_name,
309 *dev_p = NULL; 308 *dev_p = NULL;
310 309
311 if (!fw_priv || !f_dev) { 310 if (!fw_priv || !f_dev) {
312 printk(KERN_ERR "%s: kmalloc failed\n", __func__); 311 dev_err(device, "%s: kmalloc failed\n", __func__);
313 retval = -ENOMEM; 312 retval = -ENOMEM;
314 goto error_kfree; 313 goto error_kfree;
315 } 314 }
@@ -329,8 +328,7 @@ static int fw_register_device(struct device **dev_p, const char *fw_name,
329 f_dev->uevent_suppress = 1; 328 f_dev->uevent_suppress = 1;
330 retval = device_register(f_dev); 329 retval = device_register(f_dev);
331 if (retval) { 330 if (retval) {
332 printk(KERN_ERR "%s: device_register failed\n", 331 dev_err(device, "%s: device_register failed\n", __func__);
333 __func__);
334 goto error_kfree; 332 goto error_kfree;
335 } 333 }
336 *dev_p = f_dev; 334 *dev_p = f_dev;
@@ -363,15 +361,13 @@ static int fw_setup_device(struct firmware *fw, struct device **dev_p,
363 fw_priv->fw = fw; 361 fw_priv->fw = fw;
364 retval = sysfs_create_bin_file(&f_dev->kobj, &fw_priv->attr_data); 362 retval = sysfs_create_bin_file(&f_dev->kobj, &fw_priv->attr_data);
365 if (retval) { 363 if (retval) {
366 printk(KERN_ERR "%s: sysfs_create_bin_file failed\n", 364 dev_err(device, "%s: sysfs_create_bin_file failed\n", __func__);
367 __func__);
368 goto error_unreg; 365 goto error_unreg;
369 } 366 }
370 367
371 retval = device_create_file(f_dev, &dev_attr_loading); 368 retval = device_create_file(f_dev, &dev_attr_loading);
372 if (retval) { 369 if (retval) {
373 printk(KERN_ERR "%s: device_create_file failed\n", 370 dev_err(device, "%s: device_create_file failed\n", __func__);
374 __func__);
375 goto error_unreg; 371 goto error_unreg;
376 } 372 }
377 373
@@ -401,8 +397,8 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
401 397
402 *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL); 398 *firmware_p = firmware = kzalloc(sizeof(*firmware), GFP_KERNEL);
403 if (!firmware) { 399 if (!firmware) {
404 printk(KERN_ERR "%s: kmalloc(struct firmware) failed\n", 400 dev_err(device, "%s: kmalloc(struct firmware) failed\n",
405 __func__); 401 __func__);
406 retval = -ENOMEM; 402 retval = -ENOMEM;
407 goto out; 403 goto out;
408 } 404 }
@@ -411,15 +407,15 @@ _request_firmware(const struct firmware **firmware_p, const char *name,
411 builtin++) { 407 builtin++) {
412 if (strcmp(name, builtin->name)) 408 if (strcmp(name, builtin->name))
413 continue; 409 continue;
414 printk(KERN_INFO "firmware: using built-in firmware %s\n", 410 dev_info(device, "firmware: using built-in firmware %s\n",
415 name); 411 name);
416 firmware->size = builtin->size; 412 firmware->size = builtin->size;
417 firmware->data = builtin->data; 413 firmware->data = builtin->data;
418 return 0; 414 return 0;
419 } 415 }
420 416
421 if (uevent) 417 if (uevent)
422 printk(KERN_INFO "firmware: requesting %s\n", name); 418 dev_info(device, "firmware: requesting %s\n", name);
423 419
424 retval = fw_setup_device(firmware, &f_dev, name, device, uevent); 420 retval = fw_setup_device(firmware, &f_dev, name, device, uevent);
425 if (retval) 421 if (retval)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 3f940393d6c7..dfcbfe504867 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -42,10 +42,8 @@ struct resource *platform_get_resource(struct platform_device *dev,
42 for (i = 0; i < dev->num_resources; i++) { 42 for (i = 0; i < dev->num_resources; i++) {
43 struct resource *r = &dev->resource[i]; 43 struct resource *r = &dev->resource[i];
44 44
45 if ((r->flags & (IORESOURCE_IO|IORESOURCE_MEM| 45 if (type == resource_type(r) && num-- == 0)
46 IORESOURCE_IRQ|IORESOURCE_DMA)) == type) 46 return r;
47 if (num-- == 0)
48 return r;
49 } 47 }
50 return NULL; 48 return NULL;
51} 49}
@@ -78,10 +76,8 @@ struct resource *platform_get_resource_byname(struct platform_device *dev,
78 for (i = 0; i < dev->num_resources; i++) { 76 for (i = 0; i < dev->num_resources; i++) {
79 struct resource *r = &dev->resource[i]; 77 struct resource *r = &dev->resource[i];
80 78
81 if ((r->flags & (IORESOURCE_IO|IORESOURCE_MEM| 79 if (type == resource_type(r) && !strcmp(r->name, name))
82 IORESOURCE_IRQ|IORESOURCE_DMA)) == type) 80 return r;
83 if (!strcmp(r->name, name))
84 return r;
85 } 81 }
86 return NULL; 82 return NULL;
87} 83}
@@ -259,9 +255,9 @@ int platform_device_add(struct platform_device *pdev)
259 255
260 p = r->parent; 256 p = r->parent;
261 if (!p) { 257 if (!p) {
262 if (r->flags & IORESOURCE_MEM) 258 if (resource_type(r) == IORESOURCE_MEM)
263 p = &iomem_resource; 259 p = &iomem_resource;
264 else if (r->flags & IORESOURCE_IO) 260 else if (resource_type(r) == IORESOURCE_IO)
265 p = &ioport_resource; 261 p = &ioport_resource;
266 } 262 }
267 263
@@ -282,9 +278,14 @@ int platform_device_add(struct platform_device *pdev)
282 return ret; 278 return ret;
283 279
284 failed: 280 failed:
285 while (--i >= 0) 281 while (--i >= 0) {
286 if (pdev->resource[i].flags & (IORESOURCE_MEM|IORESOURCE_IO)) 282 struct resource *r = &pdev->resource[i];
287 release_resource(&pdev->resource[i]); 283 unsigned long type = resource_type(r);
284
285 if (type == IORESOURCE_MEM || type == IORESOURCE_IO)
286 release_resource(r);
287 }
288
288 return ret; 289 return ret;
289} 290}
290EXPORT_SYMBOL_GPL(platform_device_add); 291EXPORT_SYMBOL_GPL(platform_device_add);
@@ -306,7 +307,9 @@ void platform_device_del(struct platform_device *pdev)
306 307
307 for (i = 0; i < pdev->num_resources; i++) { 308 for (i = 0; i < pdev->num_resources; i++) {
308 struct resource *r = &pdev->resource[i]; 309 struct resource *r = &pdev->resource[i];
309 if (r->flags & (IORESOURCE_MEM|IORESOURCE_IO)) 310 unsigned long type = resource_type(r);
311
312 if (type == IORESOURCE_MEM || type == IORESOURCE_IO)
310 release_resource(r); 313 release_resource(r);
311 } 314 }
312 } 315 }
@@ -391,6 +394,53 @@ error:
391} 394}
392EXPORT_SYMBOL_GPL(platform_device_register_simple); 395EXPORT_SYMBOL_GPL(platform_device_register_simple);
393 396
397/**
398 * platform_device_register_data
399 * @parent: parent device for the device we're adding
400 * @name: base name of the device we're adding
401 * @id: instance id
402 * @data: platform specific data for this platform device
403 * @size: size of platform specific data
404 *
405 * This function creates a simple platform device that requires minimal
406 * resource and memory management. Canned release function freeing memory
407 * allocated for the device allows drivers using such devices to be
408 * unloaded without waiting for the last reference to the device to be
409 * dropped.
410 */
411struct platform_device *platform_device_register_data(
412 struct device *parent,
413 const char *name, int id,
414 const void *data, size_t size)
415{
416 struct platform_device *pdev;
417 int retval;
418
419 pdev = platform_device_alloc(name, id);
420 if (!pdev) {
421 retval = -ENOMEM;
422 goto error;
423 }
424
425 pdev->dev.parent = parent;
426
427 if (size) {
428 retval = platform_device_add_data(pdev, data, size);
429 if (retval)
430 goto error;
431 }
432
433 retval = platform_device_add(pdev);
434 if (retval)
435 goto error;
436
437 return pdev;
438
439error:
440 platform_device_put(pdev);
441 return ERR_PTR(retval);
442}
443
394static int platform_drv_probe(struct device *_dev) 444static int platform_drv_probe(struct device *_dev)
395{ 445{
396 struct platform_driver *drv = to_platform_driver(_dev->driver); 446 struct platform_driver *drv = to_platform_driver(_dev->driver);
@@ -862,7 +912,7 @@ static int platform_pm_restore_noirq(struct device *dev)
862 912
863#endif /* !CONFIG_HIBERNATION */ 913#endif /* !CONFIG_HIBERNATION */
864 914
865struct pm_ext_ops platform_pm_ops = { 915static struct pm_ext_ops platform_pm_ops = {
866 .base = { 916 .base = {
867 .prepare = platform_pm_prepare, 917 .prepare = platform_pm_prepare,
868 .complete = platform_pm_complete, 918 .complete = platform_pm_complete,
diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c
index 273a944d4040..692c20ba5144 100644
--- a/drivers/base/power/main.c
+++ b/drivers/base/power/main.c
@@ -83,7 +83,7 @@ void device_pm_add(struct device *dev)
83 * transition is in progress in order to avoid leaving them 83 * transition is in progress in order to avoid leaving them
84 * unhandled down the road 84 * unhandled down the road
85 */ 85 */
86 WARN_ON(true); 86 dev_WARN(dev, "Parentless device registered during a PM transaction\n");
87 } 87 }
88 88
89 list_add_tail(&dev->power.entry, &dpm_list); 89 list_add_tail(&dev->power.entry, &dpm_list);
@@ -778,10 +778,7 @@ EXPORT_SYMBOL_GPL(device_suspend);
778 778
779void __suspend_report_result(const char *function, void *fn, int ret) 779void __suspend_report_result(const char *function, void *fn, int ret)
780{ 780{
781 if (ret) { 781 if (ret)
782 printk(KERN_ERR "%s(): ", function); 782 printk(KERN_ERR "%s(): %pF returns %d\n", function, fn, ret);
783 print_fn_descriptor_symbol("%s returns ", fn);
784 printk("%d\n", ret);
785 }
786} 783}
787EXPORT_SYMBOL_GPL(__suspend_report_result); 784EXPORT_SYMBOL_GPL(__suspend_report_result);
diff --git a/drivers/block/aoe/aoechr.c b/drivers/block/aoe/aoechr.c
index 1f56d2c5b7fc..200efc4d2c1e 100644
--- a/drivers/block/aoe/aoechr.c
+++ b/drivers/block/aoe/aoechr.c
@@ -284,9 +284,9 @@ aoechr_init(void)
284 return PTR_ERR(aoe_class); 284 return PTR_ERR(aoe_class);
285 } 285 }
286 for (i = 0; i < ARRAY_SIZE(chardevs); ++i) 286 for (i = 0; i < ARRAY_SIZE(chardevs); ++i)
287 device_create_drvdata(aoe_class, NULL, 287 device_create(aoe_class, NULL,
288 MKDEV(AOE_MAJOR, chardevs[i].minor), 288 MKDEV(AOE_MAJOR, chardevs[i].minor), NULL,
289 NULL, chardevs[i].name); 289 chardevs[i].name);
290 290
291 return 0; 291 return 0;
292} 292}
diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c
index 49f274197b16..432cf4018291 100644
--- a/drivers/block/ataflop.c
+++ b/drivers/block/ataflop.c
@@ -1882,10 +1882,6 @@ static int __init atari_floppy_init (void)
1882 /* Amiga, Mac, ... don't have Atari-compatible floppy :-) */ 1882 /* Amiga, Mac, ... don't have Atari-compatible floppy :-) */
1883 return -ENODEV; 1883 return -ENODEV;
1884 1884
1885 if (MACH_IS_HADES)
1886 /* Hades doesn't have Atari-compatible floppy */
1887 return -ENODEV;
1888
1889 if (register_blkdev(FLOPPY_MAJOR,"fd")) 1885 if (register_blkdev(FLOPPY_MAJOR,"fd"))
1890 return -EBUSY; 1886 return -EBUSY;
1891 1887
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index cf64ddf5d839..2cea27aba9a0 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -4172,7 +4172,7 @@ static int __init floppy_init(void)
4172 int i, unit, drive; 4172 int i, unit, drive;
4173 int err, dr; 4173 int err, dr;
4174 4174
4175#if defined(CONFIG_PPC_MERGE) 4175#if defined(CONFIG_PPC)
4176 if (check_legacy_ioport(FDC1)) 4176 if (check_legacy_ioport(FDC1))
4177 return -ENODEV; 4177 return -ENODEV;
4178#endif 4178#endif
diff --git a/drivers/block/paride/pg.c b/drivers/block/paride/pg.c
index d731ca42f802..9dfa27163001 100644
--- a/drivers/block/paride/pg.c
+++ b/drivers/block/paride/pg.c
@@ -686,9 +686,8 @@ static int __init pg_init(void)
686 for (unit = 0; unit < PG_UNITS; unit++) { 686 for (unit = 0; unit < PG_UNITS; unit++) {
687 struct pg *dev = &devices[unit]; 687 struct pg *dev = &devices[unit];
688 if (dev->present) 688 if (dev->present)
689 device_create_drvdata(pg_class, NULL, 689 device_create(pg_class, NULL, MKDEV(major, unit), NULL,
690 MKDEV(major, unit), NULL, 690 "pg%u", unit);
691 "pg%u", unit);
692 } 691 }
693 err = 0; 692 err = 0;
694 goto out; 693 goto out;
diff --git a/drivers/block/paride/pt.c b/drivers/block/paride/pt.c
index 673b8b2fd337..5ae229656eaa 100644
--- a/drivers/block/paride/pt.c
+++ b/drivers/block/paride/pt.c
@@ -979,12 +979,10 @@ static int __init pt_init(void)
979 979
980 for (unit = 0; unit < PT_UNITS; unit++) 980 for (unit = 0; unit < PT_UNITS; unit++)
981 if (pt[unit].present) { 981 if (pt[unit].present) {
982 device_create_drvdata(pt_class, NULL, 982 device_create(pt_class, NULL, MKDEV(major, unit), NULL,
983 MKDEV(major, unit), NULL, 983 "pt%d", unit);
984 "pt%d", unit); 984 device_create(pt_class, NULL, MKDEV(major, unit + 128),
985 device_create_drvdata(pt_class, NULL, 985 NULL, "pt%dn", unit);
986 MKDEV(major, unit + 128), NULL,
987 "pt%dn", unit);
988 } 986 }
989 goto out; 987 goto out;
990 988
diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
index 0e077150568b..195ca7c720f5 100644
--- a/drivers/block/pktcdvd.c
+++ b/drivers/block/pktcdvd.c
@@ -302,9 +302,8 @@ static struct kobj_type kobj_pkt_type_wqueue = {
302static void pkt_sysfs_dev_new(struct pktcdvd_device *pd) 302static void pkt_sysfs_dev_new(struct pktcdvd_device *pd)
303{ 303{
304 if (class_pktcdvd) { 304 if (class_pktcdvd) {
305 pd->dev = device_create_drvdata(class_pktcdvd, NULL, 305 pd->dev = device_create(class_pktcdvd, NULL, pd->pkt_dev, NULL,
306 pd->pkt_dev, NULL, 306 "%s", pd->name);
307 "%s", pd->name);
308 if (IS_ERR(pd->dev)) 307 if (IS_ERR(pd->dev))
309 pd->dev = NULL; 308 pd->dev = NULL;
310 } 309 }
diff --git a/drivers/block/viodasd.c b/drivers/block/viodasd.c
index f1c8feb5510b..1730d29e6044 100644
--- a/drivers/block/viodasd.c
+++ b/drivers/block/viodasd.c
@@ -249,7 +249,6 @@ static int send_request(struct request *req)
249 struct HvLpEvent *hev; 249 struct HvLpEvent *hev;
250 struct scatterlist sg[VIOMAXBLOCKDMA]; 250 struct scatterlist sg[VIOMAXBLOCKDMA];
251 int sgindex; 251 int sgindex;
252 int statindex;
253 struct viodasd_device *d; 252 struct viodasd_device *d;
254 unsigned long flags; 253 unsigned long flags;
255 254
@@ -258,11 +257,9 @@ static int send_request(struct request *req)
258 if (rq_data_dir(req) == READ) { 257 if (rq_data_dir(req) == READ) {
259 direction = DMA_FROM_DEVICE; 258 direction = DMA_FROM_DEVICE;
260 viocmd = viomajorsubtype_blockio | vioblockread; 259 viocmd = viomajorsubtype_blockio | vioblockread;
261 statindex = 0;
262 } else { 260 } else {
263 direction = DMA_TO_DEVICE; 261 direction = DMA_TO_DEVICE;
264 viocmd = viomajorsubtype_blockio | vioblockwrite; 262 viocmd = viomajorsubtype_blockio | vioblockwrite;
265 statindex = 1;
266 } 263 }
267 264
268 d = req->rq_disk->private_data; 265 d = req->rq_disk->private_data;
diff --git a/drivers/bluetooth/bluecard_cs.c b/drivers/bluetooth/bluecard_cs.c
index bcf57927b7a8..e6ee21d99d92 100644
--- a/drivers/bluetooth/bluecard_cs.c
+++ b/drivers/bluetooth/bluecard_cs.c
@@ -901,23 +901,23 @@ static int bluecard_config(struct pcmcia_device *link)
901 for (n = 0; n < 0x400; n += 0x40) { 901 for (n = 0; n < 0x400; n += 0x40) {
902 link->io.BasePort1 = n ^ 0x300; 902 link->io.BasePort1 = n ^ 0x300;
903 i = pcmcia_request_io(link, &link->io); 903 i = pcmcia_request_io(link, &link->io);
904 if (i == CS_SUCCESS) 904 if (i == 0)
905 break; 905 break;
906 } 906 }
907 907
908 if (i != CS_SUCCESS) { 908 if (i != 0) {
909 cs_error(link, RequestIO, i); 909 cs_error(link, RequestIO, i);
910 goto failed; 910 goto failed;
911 } 911 }
912 912
913 i = pcmcia_request_irq(link, &link->irq); 913 i = pcmcia_request_irq(link, &link->irq);
914 if (i != CS_SUCCESS) { 914 if (i != 0) {
915 cs_error(link, RequestIRQ, i); 915 cs_error(link, RequestIRQ, i);
916 link->irq.AssignedIRQ = 0; 916 link->irq.AssignedIRQ = 0;
917 } 917 }
918 918
919 i = pcmcia_request_configuration(link, &link->conf); 919 i = pcmcia_request_configuration(link, &link->conf);
920 if (i != CS_SUCCESS) { 920 if (i != 0) {
921 cs_error(link, RequestConfiguration, i); 921 cs_error(link, RequestConfiguration, i);
922 goto failed; 922 goto failed;
923 } 923 }
diff --git a/drivers/bluetooth/bt3c_cs.c b/drivers/bluetooth/bt3c_cs.c
index 27058477cc8b..2cbe70b66470 100644
--- a/drivers/bluetooth/bt3c_cs.c
+++ b/drivers/bluetooth/bt3c_cs.c
@@ -678,101 +678,78 @@ static void bt3c_detach(struct pcmcia_device *link)
678 kfree(info); 678 kfree(info);
679} 679}
680 680
681static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse) 681static int bt3c_check_config(struct pcmcia_device *p_dev,
682 cistpl_cftable_entry_t *cf,
683 cistpl_cftable_entry_t *dflt,
684 unsigned int vcc,
685 void *priv_data)
682{ 686{
683 int i; 687 unsigned long try = (unsigned long) priv_data;
684 688
685 i = pcmcia_get_tuple_data(handle, tuple); 689 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
686 if (i != CS_SUCCESS) 690 p_dev->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
687 return i; 691 if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) &&
688 692 (cf->io.win[0].base != 0)) {
689 return pcmcia_parse_tuple(handle, tuple, parse); 693 p_dev->io.BasePort1 = cf->io.win[0].base;
690} 694 p_dev->io.IOAddrLines = (try == 0) ? 16 :
691 695 cf->io.flags & CISTPL_IO_LINES_MASK;
692static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse) 696 if (!pcmcia_request_io(p_dev, &p_dev->io))
693{ 697 return 0;
694 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) 698 }
695 return CS_NO_MORE_ITEMS; 699 return -ENODEV;
696 return get_tuple(handle, tuple, parse);
697} 700}
698 701
699static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse) 702static int bt3c_check_config_notpicky(struct pcmcia_device *p_dev,
703 cistpl_cftable_entry_t *cf,
704 cistpl_cftable_entry_t *dflt,
705 unsigned int vcc,
706 void *priv_data)
700{ 707{
701 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS) 708 static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
702 return CS_NO_MORE_ITEMS; 709 int j;
703 return get_tuple(handle, tuple, parse); 710
711 if ((cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
712 for (j = 0; j < 5; j++) {
713 p_dev->io.BasePort1 = base[j];
714 p_dev->io.IOAddrLines = base[j] ? 16 : 3;
715 if (!pcmcia_request_io(p_dev, &p_dev->io))
716 return 0;
717 }
718 }
719 return -ENODEV;
704} 720}
705 721
706static int bt3c_config(struct pcmcia_device *link) 722static int bt3c_config(struct pcmcia_device *link)
707{ 723{
708 static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
709 bt3c_info_t *info = link->priv; 724 bt3c_info_t *info = link->priv;
710 tuple_t tuple; 725 int i;
711 u_short buf[256]; 726 unsigned long try;
712 cisparse_t parse; 727
713 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 728 /* First pass: look for a config entry that looks normal.
714 int i, j, try; 729 Two tries: without IO aliases, then with aliases */
715 730 for (try = 0; try < 2; try++)
716 /* First pass: look for a config entry that looks normal. */ 731 if (!pcmcia_loop_config(link, bt3c_check_config, (void *) try))
717 tuple.TupleData = (cisdata_t *)buf; 732 goto found_port;
718 tuple.TupleOffset = 0;
719 tuple.TupleDataMax = 255;
720 tuple.Attributes = 0;
721 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
722 /* Two tries: without IO aliases, then with aliases */
723 for (try = 0; try < 2; try++) {
724 i = first_tuple(link, &tuple, &parse);
725 while (i != CS_NO_MORE_ITEMS) {
726 if (i != CS_SUCCESS)
727 goto next_entry;
728 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
729 link->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
730 if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) {
731 link->conf.ConfigIndex = cf->index;
732 link->io.BasePort1 = cf->io.win[0].base;
733 link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK;
734 i = pcmcia_request_io(link, &link->io);
735 if (i == CS_SUCCESS)
736 goto found_port;
737 }
738next_entry:
739 i = next_tuple(link, &tuple, &parse);
740 }
741 }
742 733
743 /* Second pass: try to find an entry that isn't picky about 734 /* Second pass: try to find an entry that isn't picky about
744 its base address, then try to grab any standard serial port 735 its base address, then try to grab any standard serial port
745 address, and finally try to get any free port. */ 736 address, and finally try to get any free port. */
746 i = first_tuple(link, &tuple, &parse); 737 if (!pcmcia_loop_config(link, bt3c_check_config_notpicky, NULL))
747 while (i != CS_NO_MORE_ITEMS) { 738 goto found_port;
748 if ((i == CS_SUCCESS) && (cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
749 link->conf.ConfigIndex = cf->index;
750 for (j = 0; j < 5; j++) {
751 link->io.BasePort1 = base[j];
752 link->io.IOAddrLines = base[j] ? 16 : 3;
753 i = pcmcia_request_io(link, &link->io);
754 if (i == CS_SUCCESS)
755 goto found_port;
756 }
757 }
758 i = next_tuple(link, &tuple, &parse);
759 }
760 739
761found_port: 740 BT_ERR("No usable port range found");
762 if (i != CS_SUCCESS) { 741 cs_error(link, RequestIO, -ENODEV);
763 BT_ERR("No usable port range found"); 742 goto failed;
764 cs_error(link, RequestIO, i);
765 goto failed;
766 }
767 743
744found_port:
768 i = pcmcia_request_irq(link, &link->irq); 745 i = pcmcia_request_irq(link, &link->irq);
769 if (i != CS_SUCCESS) { 746 if (i != 0) {
770 cs_error(link, RequestIRQ, i); 747 cs_error(link, RequestIRQ, i);
771 link->irq.AssignedIRQ = 0; 748 link->irq.AssignedIRQ = 0;
772 } 749 }
773 750
774 i = pcmcia_request_configuration(link, &link->conf); 751 i = pcmcia_request_configuration(link, &link->conf);
775 if (i != CS_SUCCESS) { 752 if (i != 0) {
776 cs_error(link, RequestConfiguration, i); 753 cs_error(link, RequestConfiguration, i);
777 goto failed; 754 goto failed;
778 } 755 }
diff --git a/drivers/bluetooth/btuart_cs.c b/drivers/bluetooth/btuart_cs.c
index 68d1d258e6a4..8e556b7ff9f6 100644
--- a/drivers/bluetooth/btuart_cs.c
+++ b/drivers/bluetooth/btuart_cs.c
@@ -607,102 +607,78 @@ static void btuart_detach(struct pcmcia_device *link)
607 kfree(info); 607 kfree(info);
608} 608}
609 609
610static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse) 610static int btuart_check_config(struct pcmcia_device *p_dev,
611 cistpl_cftable_entry_t *cf,
612 cistpl_cftable_entry_t *dflt,
613 unsigned int vcc,
614 void *priv_data)
611{ 615{
612 int i; 616 int *try = priv_data;
613 617
614 i = pcmcia_get_tuple_data(handle, tuple); 618 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
615 if (i != CS_SUCCESS) 619 p_dev->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
616 return i; 620 if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) &&
617 621 (cf->io.win[0].base != 0)) {
618 return pcmcia_parse_tuple(handle, tuple, parse); 622 p_dev->io.BasePort1 = cf->io.win[0].base;
619} 623 p_dev->io.IOAddrLines = (*try == 0) ? 16 :
620 624 cf->io.flags & CISTPL_IO_LINES_MASK;
621static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse) 625 if (!pcmcia_request_io(p_dev, &p_dev->io))
622{ 626 return 0;
623 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS) 627 }
624 return CS_NO_MORE_ITEMS; 628 return -ENODEV;
625 return get_tuple(handle, tuple, parse);
626} 629}
627 630
628static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse) 631static int btuart_check_config_notpicky(struct pcmcia_device *p_dev,
632 cistpl_cftable_entry_t *cf,
633 cistpl_cftable_entry_t *dflt,
634 unsigned int vcc,
635 void *priv_data)
629{ 636{
630 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS) 637 static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
631 return CS_NO_MORE_ITEMS; 638 int j;
632 return get_tuple(handle, tuple, parse); 639
640 if ((cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
641 for (j = 0; j < 5; j++) {
642 p_dev->io.BasePort1 = base[j];
643 p_dev->io.IOAddrLines = base[j] ? 16 : 3;
644 if (!pcmcia_request_io(p_dev, &p_dev->io))
645 return 0;
646 }
647 }
648 return -ENODEV;
633} 649}
634 650
635static int btuart_config(struct pcmcia_device *link) 651static int btuart_config(struct pcmcia_device *link)
636{ 652{
637 static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
638 btuart_info_t *info = link->priv; 653 btuart_info_t *info = link->priv;
639 tuple_t tuple; 654 int i;
640 u_short buf[256]; 655 int try;
641 cisparse_t parse; 656
642 cistpl_cftable_entry_t *cf = &parse.cftable_entry; 657 /* First pass: look for a config entry that looks normal.
643 int i, j, try; 658 Two tries: without IO aliases, then with aliases */
644 659 for (try = 0; try < 2; try++)
645 /* First pass: look for a config entry that looks normal. */ 660 if (!pcmcia_loop_config(link, btuart_check_config, &try))
646 tuple.TupleData = (cisdata_t *) buf; 661 goto found_port;
647 tuple.TupleOffset = 0;
648 tuple.TupleDataMax = 255;
649 tuple.Attributes = 0;
650 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
651 /* Two tries: without IO aliases, then with aliases */
652 for (try = 0; try < 2; try++) {
653 i = first_tuple(link, &tuple, &parse);
654 while (i != CS_NO_MORE_ITEMS) {
655 if (i != CS_SUCCESS)
656 goto next_entry;
657 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
658 link->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
659 if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) {
660 link->conf.ConfigIndex = cf->index;
661 link->io.BasePort1 = cf->io.win[0].base;
662 link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK;
663 i = pcmcia_request_io(link, &link->io);
664 if (i == CS_SUCCESS)
665 goto found_port;
666 }
667next_entry:
668 i = next_tuple(link, &tuple, &parse);
669 }
670 }
671 662
672 /* Second pass: try to find an entry that isn't picky about 663 /* Second pass: try to find an entry that isn't picky about
673 its base address, then try to grab any standard serial port 664 its base address, then try to grab any standard serial port
674 address, and finally try to get any free port. */ 665 address, and finally try to get any free port. */
675 i = first_tuple(link, &tuple, &parse); 666 if (!pcmcia_loop_config(link, btuart_check_config_notpicky, NULL))
676 while (i != CS_NO_MORE_ITEMS) { 667 goto found_port;
677 if ((i == CS_SUCCESS) && (cf->io.nwin > 0)
678 && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
679 link->conf.ConfigIndex = cf->index;
680 for (j = 0; j < 5; j++) {
681 link->io.BasePort1 = base[j];
682 link->io.IOAddrLines = base[j] ? 16 : 3;
683 i = pcmcia_request_io(link, &link->io);
684 if (i == CS_SUCCESS)
685 goto found_port;
686 }
687 }
688 i = next_tuple(link, &tuple, &parse);
689 }
690 668
691found_port: 669 BT_ERR("No usable port range found");
692 if (i != CS_SUCCESS) { 670 cs_error(link, RequestIO, -ENODEV);
693 BT_ERR("No usable port range found"); 671 goto failed;
694 cs_error(link, RequestIO, i);
695 goto failed;
696 }
697 672
673found_port:
698 i = pcmcia_request_irq(link, &link->irq); 674 i = pcmcia_request_irq(link, &link->irq);
699 if (i != CS_SUCCESS) { 675 if (i != 0) {
700 cs_error(link, RequestIRQ, i); 676 cs_error(link, RequestIRQ, i);
701 link->irq.AssignedIRQ = 0; 677 link->irq.AssignedIRQ = 0;
702 } 678 }
703 679
704 i = pcmcia_request_configuration(link, &link->conf); 680 i = pcmcia_request_configuration(link, &link->conf);
705 if (i != CS_SUCCESS) { 681 if (i != 0) {
706 cs_error(link, RequestConfiguration, i); 682 cs_error(link, RequestConfiguration, i);
707 goto failed; 683 goto failed;
708 } 684 }
diff --git a/drivers/bluetooth/dtl1_cs.c b/drivers/bluetooth/dtl1_cs.c
index dae45cdf02b2..e6e6b037695a 100644
--- a/drivers/bluetooth/dtl1_cs.c
+++ b/drivers/bluetooth/dtl1_cs.c
@@ -590,75 +590,40 @@ static void dtl1_detach(struct pcmcia_device *link)
590 kfree(info); 590 kfree(info);
591} 591}
592 592
593static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse) 593static int dtl1_confcheck(struct pcmcia_device *p_dev,
594 cistpl_cftable_entry_t *cf,
595 cistpl_cftable_entry_t *dflt,
596 unsigned int vcc,
597 void *priv_data)
594{ 598{
595 int i; 599 if ((cf->io.nwin == 1) && (cf->io.win[0].len > 8)) {
596 600 p_dev->io.BasePort1 = cf->io.win[0].base;
597 i = pcmcia_get_tuple_data(handle, tuple); 601 p_dev->io.NumPorts1 = cf->io.win[0].len; /*yo */
598 if (i != CS_SUCCESS) 602 p_dev->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
599 return i; 603 if (!pcmcia_request_io(p_dev, &p_dev->io))
600 604 return 0;
601 return pcmcia_parse_tuple(handle, tuple, parse); 605 }
602} 606 return -ENODEV;
603
604static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
605{
606 if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS)
607 return CS_NO_MORE_ITEMS;
608 return get_tuple(handle, tuple, parse);
609}
610
611static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
612{
613 if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS)
614 return CS_NO_MORE_ITEMS;
615 return get_tuple(handle, tuple, parse);
616} 607}
617 608
618static int dtl1_config(struct pcmcia_device *link) 609static int dtl1_config(struct pcmcia_device *link)
619{ 610{
620 dtl1_info_t *info = link->priv; 611 dtl1_info_t *info = link->priv;
621 tuple_t tuple;
622 u_short buf[256];
623 cisparse_t parse;
624 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
625 int i; 612 int i;
626 613
627 tuple.TupleData = (cisdata_t *)buf;
628 tuple.TupleOffset = 0;
629 tuple.TupleDataMax = 255;
630 tuple.Attributes = 0;
631 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
632
633 /* Look for a generic full-sized window */ 614 /* Look for a generic full-sized window */
634 link->io.NumPorts1 = 8; 615 link->io.NumPorts1 = 8;
635 i = first_tuple(link, &tuple, &parse); 616 if (!pcmcia_loop_config(link, dtl1_confcheck, NULL))
636 while (i != CS_NO_MORE_ITEMS) {
637 if ((i == CS_SUCCESS) && (cf->io.nwin == 1) && (cf->io.win[0].len > 8)) {
638 link->conf.ConfigIndex = cf->index;
639 link->io.BasePort1 = cf->io.win[0].base;
640 link->io.NumPorts1 = cf->io.win[0].len; /*yo */
641 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
642 i = pcmcia_request_io(link, &link->io);
643 if (i == CS_SUCCESS)
644 break;
645 }
646 i = next_tuple(link, &tuple, &parse);
647 }
648
649 if (i != CS_SUCCESS) {
650 cs_error(link, RequestIO, i);
651 goto failed; 617 goto failed;
652 }
653 618
654 i = pcmcia_request_irq(link, &link->irq); 619 i = pcmcia_request_irq(link, &link->irq);
655 if (i != CS_SUCCESS) { 620 if (i != 0) {
656 cs_error(link, RequestIRQ, i); 621 cs_error(link, RequestIRQ, i);
657 link->irq.AssignedIRQ = 0; 622 link->irq.AssignedIRQ = 0;
658 } 623 }
659 624
660 i = pcmcia_request_configuration(link, &link->conf); 625 i = pcmcia_request_configuration(link, &link->conf);
661 if (i != CS_SUCCESS) { 626 if (i != 0) {
662 cs_error(link, RequestConfiguration, i); 627 cs_error(link, RequestConfiguration, i);
663 goto failed; 628 goto failed;
664 } 629 }
diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
index 8dfcf77cb717..4426bb552bd9 100644
--- a/drivers/bluetooth/hci_ldisc.c
+++ b/drivers/bluetooth/hci_ldisc.c
@@ -484,7 +484,7 @@ static int hci_uart_tty_ioctl(struct tty_struct *tty, struct file * file,
484 return -EUNATCH; 484 return -EUNATCH;
485 485
486 default: 486 default:
487 err = n_tty_ioctl(tty, file, cmd, arg); 487 err = n_tty_ioctl_helper(tty, file, cmd, arg);
488 break; 488 break;
489 }; 489 };
490 490
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index caff85149b9d..122254155ae1 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -350,7 +350,7 @@ config STALDRV
350 350
351config STALLION 351config STALLION
352 tristate "Stallion EasyIO or EC8/32 support" 352 tristate "Stallion EasyIO or EC8/32 support"
353 depends on STALDRV && BROKEN_ON_SMP && (ISA || EISA || PCI) 353 depends on STALDRV && (ISA || EISA || PCI)
354 help 354 help
355 If you have an EasyIO or EasyConnection 8/32 multiport Stallion 355 If you have an EasyIO or EasyConnection 8/32 multiport Stallion
356 card, then this is for you; say Y. Make sure to read 356 card, then this is for you; say Y. Make sure to read
@@ -361,7 +361,7 @@ config STALLION
361 361
362config ISTALLION 362config ISTALLION
363 tristate "Stallion EC8/64, ONboard, Brumby support" 363 tristate "Stallion EC8/64, ONboard, Brumby support"
364 depends on STALDRV && BROKEN_ON_SMP && (ISA || EISA || PCI) 364 depends on STALDRV && (ISA || EISA || PCI)
365 help 365 help
366 If you have an EasyConnection 8/64, ONboard, Brumby or Stallion 366 If you have an EasyConnection 8/64, ONboard, Brumby or Stallion
367 serial multiport card, say Y here. Make sure to read 367 serial multiport card, say Y here. Make sure to read
@@ -1043,15 +1043,6 @@ config HPET
1043 open selects one of the timers supported by the HPET. The timers are 1043 open selects one of the timers supported by the HPET. The timers are
1044 non-periodic and/or periodic. 1044 non-periodic and/or periodic.
1045 1045
1046config HPET_RTC_IRQ
1047 bool
1048 default HPET_EMULATE_RTC
1049 depends on RTC && HPET
1050 help
1051 If you say Y here, you will disable RTC_IRQ in drivers/char/rtc.c. It
1052 is assumed the platform called hpet_alloc with the RTC IRQ values for
1053 the HPET timers.
1054
1055config HPET_MMAP 1046config HPET_MMAP
1056 bool "Allow mmap of HPET" 1047 bool "Allow mmap of HPET"
1057 default y 1048 default y
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 6850f6da7576..1a4247dccac4 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -7,7 +7,7 @@
7# 7#
8FONTMAPFILE = cp437.uni 8FONTMAPFILE = cp437.uni
9 9
10obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o 10obj-y += mem.o random.o tty_io.o n_tty.o tty_ioctl.o tty_ldisc.o tty_buffer.o tty_port.o
11 11
12obj-$(CONFIG_LEGACY_PTYS) += pty.o 12obj-$(CONFIG_LEGACY_PTYS) += pty.o
13obj-$(CONFIG_UNIX98_PTYS) += pty.o 13obj-$(CONFIG_UNIX98_PTYS) += pty.o
diff --git a/drivers/char/agp/amd-k7-agp.c b/drivers/char/agp/amd-k7-agp.c
index 603a986e96af..3f98254b911f 100644
--- a/drivers/char/agp/amd-k7-agp.c
+++ b/drivers/char/agp/amd-k7-agp.c
@@ -223,12 +223,14 @@ static int amd_irongate_configure(void)
223 223
224 current_size = A_SIZE_LVL2(agp_bridge->current_size); 224 current_size = A_SIZE_LVL2(agp_bridge->current_size);
225 225
226 /* Get the memory mapped registers */ 226 if (!amd_irongate_private.registers) {
227 pci_read_config_dword(agp_bridge->dev, AMD_MMBASE, &temp); 227 /* Get the memory mapped registers */
228 temp = (temp & PCI_BASE_ADDRESS_MEM_MASK); 228 pci_read_config_dword(agp_bridge->dev, AMD_MMBASE, &temp);
229 amd_irongate_private.registers = (volatile u8 __iomem *) ioremap(temp, 4096); 229 temp = (temp & PCI_BASE_ADDRESS_MEM_MASK);
230 if (!amd_irongate_private.registers) 230 amd_irongate_private.registers = (volatile u8 __iomem *) ioremap(temp, 4096);
231 return -ENOMEM; 231 if (!amd_irongate_private.registers)
232 return -ENOMEM;
233 }
232 234
233 /* Write out the address of the gatt table */ 235 /* Write out the address of the gatt table */
234 writel(agp_bridge->gatt_bus_addr, amd_irongate_private.registers+AMD_ATTBASE); 236 writel(agp_bridge->gatt_bus_addr, amd_irongate_private.registers+AMD_ATTBASE);
@@ -492,6 +494,26 @@ static void __devexit agp_amdk7_remove(struct pci_dev *pdev)
492 agp_put_bridge(bridge); 494 agp_put_bridge(bridge);
493} 495}
494 496
497#ifdef CONFIG_PM
498
499static int agp_amdk7_suspend(struct pci_dev *pdev, pm_message_t state)
500{
501 pci_save_state(pdev);
502 pci_set_power_state(pdev, pci_choose_state(pdev, state));
503
504 return 0;
505}
506
507static int agp_amdk7_resume(struct pci_dev *pdev)
508{
509 pci_set_power_state(pdev, PCI_D0);
510 pci_restore_state(pdev);
511
512 return amd_irongate_driver.configure();
513}
514
515#endif /* CONFIG_PM */
516
495/* must be the same order as name table above */ 517/* must be the same order as name table above */
496static struct pci_device_id agp_amdk7_pci_table[] = { 518static struct pci_device_id agp_amdk7_pci_table[] = {
497 { 519 {
@@ -528,6 +550,10 @@ static struct pci_driver agp_amdk7_pci_driver = {
528 .id_table = agp_amdk7_pci_table, 550 .id_table = agp_amdk7_pci_table,
529 .probe = agp_amdk7_probe, 551 .probe = agp_amdk7_probe,
530 .remove = agp_amdk7_remove, 552 .remove = agp_amdk7_remove,
553#ifdef CONFIG_PM
554 .suspend = agp_amdk7_suspend,
555 .resume = agp_amdk7_resume,
556#endif
531}; 557};
532 558
533static int __init agp_amdk7_init(void) 559static int __init agp_amdk7_init(void)
diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c
index 043e36628d6d..1108665913e2 100644
--- a/drivers/char/agp/intel-agp.c
+++ b/drivers/char/agp/intel-agp.c
@@ -54,8 +54,7 @@
54 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965Q_HB || \ 54 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965Q_HB || \
55 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965G_HB || \ 55 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965G_HB || \
56 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GM_HB || \ 56 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GM_HB || \
57 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GME_HB || \ 57 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_82965GME_HB)
58 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_GM45_HB)
59 58
60#define IS_G33 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G33_HB || \ 59#define IS_G33 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G33_HB || \
61 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q35_HB || \ 60 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q35_HB || \
@@ -63,7 +62,8 @@
63 62
64#define IS_G4X (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGD_E_HB || \ 63#define IS_G4X (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IGD_E_HB || \
65 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q45_HB || \ 64 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q45_HB || \
66 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G45_HB) 65 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G45_HB || \
66 agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_GM45_HB)
67 67
68extern int agp_memory_reserved; 68extern int agp_memory_reserved;
69 69
@@ -214,8 +214,8 @@ static int intel_i810_configure(void)
214 if (agp_bridge->driver->needs_scratch_page) { 214 if (agp_bridge->driver->needs_scratch_page) {
215 for (i = 0; i < current_size->num_entries; i++) { 215 for (i = 0; i < current_size->num_entries; i++) {
216 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4)); 216 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
217 readl(intel_private.registers+I810_PTE_BASE+(i*4)); /* PCI posting. */
218 } 217 }
218 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4)); /* PCI posting. */
219 } 219 }
220 global_cache_flush(); 220 global_cache_flush();
221 return 0; 221 return 0;
@@ -525,8 +525,10 @@ static void intel_i830_init_gtt_entries(void)
525 size += 4; 525 size += 4;
526 } else if (IS_G4X) { 526 } else if (IS_G4X) {
527 /* On 4 series hardware, GTT stolen is separate from graphics 527 /* On 4 series hardware, GTT stolen is separate from graphics
528 * stolen, ignore it in stolen gtt entries counting */ 528 * stolen, ignore it in stolen gtt entries counting. However,
529 size = 0; 529 * 4KB of the stolen memory doesn't get mapped to the GTT.
530 */
531 size = 4;
530 } else { 532 } else {
531 /* On previous hardware, the GTT size was just what was 533 /* On previous hardware, the GTT size was just what was
532 * required to map the aperture. 534 * required to map the aperture.
@@ -773,8 +775,8 @@ static int intel_i830_configure(void)
773 if (agp_bridge->driver->needs_scratch_page) { 775 if (agp_bridge->driver->needs_scratch_page) {
774 for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) { 776 for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) {
775 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4)); 777 writel(agp_bridge->scratch_page, intel_private.registers+I810_PTE_BASE+(i*4));
776 readl(intel_private.registers+I810_PTE_BASE+(i*4)); /* PCI Posting. */
777 } 778 }
779 readl(intel_private.registers+I810_PTE_BASE+((i-1)*4)); /* PCI Posting. */
778 } 780 }
779 781
780 global_cache_flush(); 782 global_cache_flush();
@@ -989,8 +991,8 @@ static int intel_i915_configure(void)
989 if (agp_bridge->driver->needs_scratch_page) { 991 if (agp_bridge->driver->needs_scratch_page) {
990 for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) { 992 for (i = intel_private.gtt_entries; i < current_size->num_entries; i++) {
991 writel(agp_bridge->scratch_page, intel_private.gtt+i); 993 writel(agp_bridge->scratch_page, intel_private.gtt+i);
992 readl(intel_private.gtt+i); /* PCI Posting. */
993 } 994 }
995 readl(intel_private.gtt+i-1); /* PCI Posting. */
994 } 996 }
995 997
996 global_cache_flush(); 998 global_cache_flush();
diff --git a/drivers/char/agp/nvidia-agp.c b/drivers/char/agp/nvidia-agp.c
index dc70d3771811..5bbed3d79db9 100644
--- a/drivers/char/agp/nvidia-agp.c
+++ b/drivers/char/agp/nvidia-agp.c
@@ -201,10 +201,15 @@ extern int agp_memory_reserved;
201static int nvidia_insert_memory(struct agp_memory *mem, off_t pg_start, int type) 201static int nvidia_insert_memory(struct agp_memory *mem, off_t pg_start, int type)
202{ 202{
203 int i, j; 203 int i, j;
204 int mask_type;
204 205
205 if ((type != 0) || (mem->type != 0)) 206 mask_type = agp_generic_type_to_mask_type(mem->bridge, type);
207 if (mask_type != 0 || type != mem->type)
206 return -EINVAL; 208 return -EINVAL;
207 209
210 if (mem->page_count == 0)
211 return 0;
212
208 if ((pg_start + mem->page_count) > 213 if ((pg_start + mem->page_count) >
209 (nvidia_private.num_active_entries - agp_memory_reserved/PAGE_SIZE)) 214 (nvidia_private.num_active_entries - agp_memory_reserved/PAGE_SIZE))
210 return -EINVAL; 215 return -EINVAL;
@@ -220,10 +225,13 @@ static int nvidia_insert_memory(struct agp_memory *mem, off_t pg_start, int type
220 } 225 }
221 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { 226 for (i = 0, j = pg_start; i < mem->page_count; i++, j++) {
222 writel(agp_bridge->driver->mask_memory(agp_bridge, 227 writel(agp_bridge->driver->mask_memory(agp_bridge,
223 mem->memory[i], mem->type), 228 mem->memory[i], mask_type),
224 agp_bridge->gatt_table+nvidia_private.pg_offset+j); 229 agp_bridge->gatt_table+nvidia_private.pg_offset+j);
225 readl(agp_bridge->gatt_table+nvidia_private.pg_offset+j); /* PCI Posting. */
226 } 230 }
231
232 /* PCI Posting. */
233 readl(agp_bridge->gatt_table+nvidia_private.pg_offset+j - 1);
234
227 agp_bridge->driver->tlb_flush(mem); 235 agp_bridge->driver->tlb_flush(mem);
228 return 0; 236 return 0;
229} 237}
@@ -233,9 +241,15 @@ static int nvidia_remove_memory(struct agp_memory *mem, off_t pg_start, int type
233{ 241{
234 int i; 242 int i;
235 243
236 if ((type != 0) || (mem->type != 0)) 244 int mask_type;
245
246 mask_type = agp_generic_type_to_mask_type(mem->bridge, type);
247 if (mask_type != 0 || type != mem->type)
237 return -EINVAL; 248 return -EINVAL;
238 249
250 if (mem->page_count == 0)
251 return 0;
252
239 for (i = pg_start; i < (mem->page_count + pg_start); i++) 253 for (i = pg_start; i < (mem->page_count + pg_start); i++)
240 writel(agp_bridge->scratch_page, agp_bridge->gatt_table+nvidia_private.pg_offset+i); 254 writel(agp_bridge->scratch_page, agp_bridge->gatt_table+nvidia_private.pg_offset+i);
241 255
diff --git a/drivers/char/amiserial.c b/drivers/char/amiserial.c
index 6e763e3f5a81..98821f97583c 100644
--- a/drivers/char/amiserial.c
+++ b/drivers/char/amiserial.c
@@ -837,9 +837,6 @@ static int rs_put_char(struct tty_struct *tty, unsigned char ch)
837 struct async_struct *info; 837 struct async_struct *info;
838 unsigned long flags; 838 unsigned long flags;
839 839
840 if (!tty)
841 return 0;
842
843 info = tty->driver_data; 840 info = tty->driver_data;
844 841
845 if (serial_paranoia_check(info, tty->name, "rs_put_char")) 842 if (serial_paranoia_check(info, tty->name, "rs_put_char"))
@@ -892,9 +889,6 @@ static int rs_write(struct tty_struct * tty, const unsigned char *buf, int count
892 struct async_struct *info; 889 struct async_struct *info;
893 unsigned long flags; 890 unsigned long flags;
894 891
895 if (!tty)
896 return 0;
897
898 info = tty->driver_data; 892 info = tty->driver_data;
899 893
900 if (serial_paranoia_check(info, tty->name, "rs_write")) 894 if (serial_paranoia_check(info, tty->name, "rs_write"))
diff --git a/drivers/char/applicom.c b/drivers/char/applicom.c
index 31d08b641f5b..05674febb0c6 100644
--- a/drivers/char/applicom.c
+++ b/drivers/char/applicom.c
@@ -478,7 +478,7 @@ static int do_ac_read(int IndexCard, char __user *buf,
478 struct st_ram_io *st_loc, struct mailbox *mailbox) 478 struct st_ram_io *st_loc, struct mailbox *mailbox)
479{ 479{
480 void __iomem *from = apbs[IndexCard].RamIO + RAM_TO_PC; 480 void __iomem *from = apbs[IndexCard].RamIO + RAM_TO_PC;
481 unsigned char *to = (unsigned char *)&mailbox; 481 unsigned char *to = (unsigned char *)mailbox;
482#ifdef DEBUG 482#ifdef DEBUG
483 int c; 483 int c;
484#endif 484#endif
@@ -712,8 +712,7 @@ static int ac_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
712 712
713 IndexCard = adgl->num_card-1; 713 IndexCard = adgl->num_card-1;
714 714
715 if(cmd != 0 && cmd != 6 && 715 if(cmd != 6 && ((IndexCard >= MAX_BOARD) || !apbs[IndexCard].RamIO)) {
716 ((IndexCard >= MAX_BOARD) || !apbs[IndexCard].RamIO)) {
717 static int warncount = 10; 716 static int warncount = 10;
718 if (warncount) { 717 if (warncount) {
719 printk( KERN_WARNING "APPLICOM driver IOCTL, bad board number %d\n",(int)IndexCard+1); 718 printk( KERN_WARNING "APPLICOM driver IOCTL, bad board number %d\n",(int)IndexCard+1);
@@ -832,8 +831,7 @@ static int ac_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
832 } 831 }
833 break; 832 break;
834 default: 833 default:
835 printk(KERN_INFO "APPLICOM driver ioctl, unknown function code %d\n",cmd) ; 834 ret = -ENOTTY;
836 ret = -EINVAL;
837 break; 835 break;
838 } 836 }
839 Dummy = readb(apbs[IndexCard].RamIO + VERS); 837 Dummy = readb(apbs[IndexCard].RamIO + VERS);
diff --git a/drivers/char/bsr.c b/drivers/char/bsr.c
index b650b4e48e50..456f54db73e2 100644
--- a/drivers/char/bsr.c
+++ b/drivers/char/bsr.c
@@ -229,9 +229,8 @@ static int bsr_create_devs(struct device_node *bn)
229 if (result) 229 if (result)
230 goto out_err; 230 goto out_err;
231 231
232 cur->bsr_device = device_create_drvdata(bsr_class, NULL, 232 cur->bsr_device = device_create(bsr_class, NULL, cur->bsr_dev,
233 cur->bsr_dev, 233 cur, cur->bsr_name);
234 cur, cur->bsr_name);
235 if (!cur->bsr_device) { 234 if (!cur->bsr_device) {
236 printk(KERN_ERR "device_create failed for %s\n", 235 printk(KERN_ERR "device_create failed for %s\n",
237 cur->bsr_name); 236 cur->bsr_name);
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index fe6d774fe2e4..5e5b1dc1a0a7 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -4993,12 +4993,14 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
4993 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) { 4993 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) {
4994 card_name = "Cyclom-Y"; 4994 card_name = "Cyclom-Y";
4995 4995
4996 addr0 = pci_iomap(pdev, 0, CyPCI_Yctl); 4996 addr0 = ioremap_nocache(pci_resource_start(pdev, 0),
4997 CyPCI_Yctl);
4997 if (addr0 == NULL) { 4998 if (addr0 == NULL) {
4998 dev_err(&pdev->dev, "can't remap ctl region\n"); 4999 dev_err(&pdev->dev, "can't remap ctl region\n");
4999 goto err_reg; 5000 goto err_reg;
5000 } 5001 }
5001 addr2 = pci_iomap(pdev, 2, CyPCI_Ywin); 5002 addr2 = ioremap_nocache(pci_resource_start(pdev, 2),
5003 CyPCI_Ywin);
5002 if (addr2 == NULL) { 5004 if (addr2 == NULL) {
5003 dev_err(&pdev->dev, "can't remap base region\n"); 5005 dev_err(&pdev->dev, "can't remap base region\n");
5004 goto err_unmap; 5006 goto err_unmap;
@@ -5013,7 +5015,8 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
5013 } else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi) { 5015 } else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi) {
5014 struct RUNTIME_9060 __iomem *ctl_addr; 5016 struct RUNTIME_9060 __iomem *ctl_addr;
5015 5017
5016 ctl_addr = addr0 = pci_iomap(pdev, 0, CyPCI_Zctl); 5018 ctl_addr = addr0 = ioremap_nocache(pci_resource_start(pdev, 0),
5019 CyPCI_Zctl);
5017 if (addr0 == NULL) { 5020 if (addr0 == NULL) {
5018 dev_err(&pdev->dev, "can't remap ctl region\n"); 5021 dev_err(&pdev->dev, "can't remap ctl region\n");
5019 goto err_reg; 5022 goto err_reg;
@@ -5026,8 +5029,8 @@ static int __devinit cy_pci_probe(struct pci_dev *pdev,
5026 5029
5027 mailbox = (u32)readl(&ctl_addr->mail_box_0); 5030 mailbox = (u32)readl(&ctl_addr->mail_box_0);
5028 5031
5029 addr2 = pci_iomap(pdev, 2, mailbox == ZE_V1 ? 5032 addr2 = ioremap_nocache(pci_resource_start(pdev, 2),
5030 CyPCI_Ze_win : CyPCI_Zwin); 5033 mailbox == ZE_V1 ? CyPCI_Ze_win : CyPCI_Zwin);
5031 if (addr2 == NULL) { 5034 if (addr2 == NULL) {
5032 dev_err(&pdev->dev, "can't remap base region\n"); 5035 dev_err(&pdev->dev, "can't remap base region\n");
5033 goto err_unmap; 5036 goto err_unmap;
@@ -5159,9 +5162,9 @@ err_null:
5159 cy_card[card_no].base_addr = NULL; 5162 cy_card[card_no].base_addr = NULL;
5160 free_irq(irq, &cy_card[card_no]); 5163 free_irq(irq, &cy_card[card_no]);
5161err_unmap: 5164err_unmap:
5162 pci_iounmap(pdev, addr0); 5165 iounmap(addr0);
5163 if (addr2) 5166 if (addr2)
5164 pci_iounmap(pdev, addr2); 5167 iounmap(addr2);
5165err_reg: 5168err_reg:
5166 pci_release_regions(pdev); 5169 pci_release_regions(pdev);
5167err_dis: 5170err_dis:
@@ -5186,9 +5189,9 @@ static void __devexit cy_pci_remove(struct pci_dev *pdev)
5186 cy_writew(cinfo->ctl_addr + 0x68, 5189 cy_writew(cinfo->ctl_addr + 0x68,
5187 readw(cinfo->ctl_addr + 0x68) & ~0x0900); 5190 readw(cinfo->ctl_addr + 0x68) & ~0x0900);
5188 5191
5189 pci_iounmap(pdev, cinfo->base_addr); 5192 iounmap(cinfo->base_addr);
5190 if (cinfo->ctl_addr) 5193 if (cinfo->ctl_addr)
5191 pci_iounmap(pdev, cinfo->ctl_addr); 5194 iounmap(cinfo->ctl_addr);
5192 if (cinfo->irq 5195 if (cinfo->irq
5193#ifndef CONFIG_CYZ_INTR 5196#ifndef CONFIG_CYZ_INTR
5194 && !IS_CYC_Z(*cinfo) 5197 && !IS_CYC_Z(*cinfo)
diff --git a/drivers/char/ds1286.c b/drivers/char/ds1286.c
index fb584938c9c3..5329d482b582 100644
--- a/drivers/char/ds1286.c
+++ b/drivers/char/ds1286.c
@@ -443,7 +443,6 @@ static void ds1286_get_time(struct rtc_time *rtc_tm)
443{ 443{
444 unsigned char save_control; 444 unsigned char save_control;
445 unsigned long flags; 445 unsigned long flags;
446 unsigned long uip_watchdog = jiffies;
447 446
448 /* 447 /*
449 * read RTC once any update in progress is done. The update 448 * read RTC once any update in progress is done. The update
@@ -456,8 +455,7 @@ static void ds1286_get_time(struct rtc_time *rtc_tm)
456 */ 455 */
457 456
458 if (ds1286_is_updating() != 0) 457 if (ds1286_is_updating() != 0)
459 while (time_before(jiffies, uip_watchdog + 2*HZ/100)) 458 msleep(20);
460 barrier();
461 459
462 /* 460 /*
463 * Only the values that we read from the RTC are set. We leave 461 * Only the values that we read from the RTC are set. We leave
diff --git a/drivers/char/dsp56k.c b/drivers/char/dsp56k.c
index ca7c72a486b2..85832ab924e6 100644
--- a/drivers/char/dsp56k.c
+++ b/drivers/char/dsp56k.c
@@ -508,8 +508,8 @@ static int __init dsp56k_init_driver(void)
508 err = PTR_ERR(dsp56k_class); 508 err = PTR_ERR(dsp56k_class);
509 goto out_chrdev; 509 goto out_chrdev;
510 } 510 }
511 device_create_drvdata(dsp56k_class, NULL, MKDEV(DSP56K_MAJOR, 0), 511 device_create(dsp56k_class, NULL, MKDEV(DSP56K_MAJOR, 0), NULL,
512 NULL, "dsp56k"); 512 "dsp56k");
513 513
514 printk(banner); 514 printk(banner);
515 goto out; 515 goto out;
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index 456e4ede049f..4998b2761e8f 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -1376,6 +1376,7 @@ static void post_fep_init(unsigned int crd)
1376 unsigned long flags; 1376 unsigned long flags;
1377 u16 tseg, rseg; 1377 u16 tseg, rseg;
1378 1378
1379 tty_port_init(&ch->port);
1379 ch->brdchan = bc; 1380 ch->brdchan = bc;
1380 ch->mailbox = gd; 1381 ch->mailbox = gd;
1381 INIT_WORK(&ch->tqueue, do_softint); 1382 INIT_WORK(&ch->tqueue, do_softint);
@@ -1510,10 +1511,6 @@ static void post_fep_init(unsigned int crd)
1510 ch->fepstopca = 0; 1511 ch->fepstopca = 0;
1511 1512
1512 ch->close_delay = 50; 1513 ch->close_delay = 50;
1513 ch->port.count = 0;
1514 ch->port.blocked_open = 0;
1515 init_waitqueue_head(&ch->port.open_wait);
1516 init_waitqueue_head(&ch->port.close_wait);
1517 1514
1518 spin_unlock_irqrestore(&epca_lock, flags); 1515 spin_unlock_irqrestore(&epca_lock, flags);
1519 } 1516 }
diff --git a/drivers/char/generic_serial.c b/drivers/char/generic_serial.c
index 19d3afb0e50c..c6090f84a2e4 100644
--- a/drivers/char/generic_serial.c
+++ b/drivers/char/generic_serial.c
@@ -54,8 +54,6 @@ int gs_put_char(struct tty_struct * tty, unsigned char ch)
54 54
55 func_enter (); 55 func_enter ();
56 56
57 if (!tty) return 0;
58
59 port = tty->driver_data; 57 port = tty->driver_data;
60 58
61 if (!port) return 0; 59 if (!port) return 0;
@@ -97,8 +95,6 @@ int gs_write(struct tty_struct * tty,
97 95
98 func_enter (); 96 func_enter ();
99 97
100 if (!tty) return 0;
101
102 port = tty->driver_data; 98 port = tty->driver_data;
103 99
104 if (!port) return 0; 100 if (!port) return 0;
@@ -185,7 +181,6 @@ static int gs_real_chars_in_buffer(struct tty_struct *tty)
185 struct gs_port *port; 181 struct gs_port *port;
186 func_enter (); 182 func_enter ();
187 183
188 if (!tty) return 0;
189 port = tty->driver_data; 184 port = tty->driver_data;
190 185
191 if (!port->rd) return 0; 186 if (!port->rd) return 0;
@@ -274,8 +269,6 @@ void gs_flush_buffer(struct tty_struct *tty)
274 269
275 func_enter (); 270 func_enter ();
276 271
277 if (!tty) return;
278
279 port = tty->driver_data; 272 port = tty->driver_data;
280 273
281 if (!port) return; 274 if (!port) return;
@@ -296,8 +289,6 @@ void gs_flush_chars(struct tty_struct * tty)
296 289
297 func_enter (); 290 func_enter ();
298 291
299 if (!tty) return;
300
301 port = tty->driver_data; 292 port = tty->driver_data;
302 293
303 if (!port) return; 294 if (!port) return;
@@ -321,8 +312,6 @@ void gs_stop(struct tty_struct * tty)
321 312
322 func_enter (); 313 func_enter ();
323 314
324 if (!tty) return;
325
326 port = tty->driver_data; 315 port = tty->driver_data;
327 316
328 if (!port) return; 317 if (!port) return;
@@ -341,8 +330,6 @@ void gs_start(struct tty_struct * tty)
341{ 330{
342 struct gs_port *port; 331 struct gs_port *port;
343 332
344 if (!tty) return;
345
346 port = tty->driver_data; 333 port = tty->driver_data;
347 334
348 if (!port) return; 335 if (!port) return;
@@ -393,8 +380,6 @@ void gs_hangup(struct tty_struct *tty)
393 380
394 func_enter (); 381 func_enter ();
395 382
396 if (!tty) return;
397
398 port = tty->driver_data; 383 port = tty->driver_data;
399 tty = port->port.tty; 384 tty = port->port.tty;
400 if (!tty) 385 if (!tty)
@@ -426,8 +411,6 @@ int gs_block_til_ready(void *port_, struct file * filp)
426 411
427 tty = port->port.tty; 412 tty = port->port.tty;
428 413
429 if (!tty) return 0;
430
431 gs_dprintk (GS_DEBUG_BTR, "Entering gs_block_till_ready.\n"); 414 gs_dprintk (GS_DEBUG_BTR, "Entering gs_block_till_ready.\n");
432 /* 415 /*
433 * If the device is in the middle of being closed, then block 416 * If the device is in the middle of being closed, then block
@@ -523,8 +506,6 @@ void gs_close(struct tty_struct * tty, struct file * filp)
523 506
524 func_enter (); 507 func_enter ();
525 508
526 if (!tty) return;
527
528 port = (struct gs_port *) tty->driver_data; 509 port = (struct gs_port *) tty->driver_data;
529 510
530 if (!port) return; 511 if (!port) return;
@@ -621,8 +602,6 @@ void gs_set_termios (struct tty_struct * tty,
621 602
622 func_enter(); 603 func_enter();
623 604
624 if (!tty) return;
625
626 port = tty->driver_data; 605 port = tty->driver_data;
627 606
628 if (!port) return; 607 if (!port) return;
diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
index b3f5dbc6d880..f3cfb4c76125 100644
--- a/drivers/char/hpet.c
+++ b/drivers/char/hpet.c
@@ -53,6 +53,11 @@
53 53
54#define HPET_RANGE_SIZE 1024 /* from HPET spec */ 54#define HPET_RANGE_SIZE 1024 /* from HPET spec */
55 55
56
57/* WARNING -- don't get confused. These macros are never used
58 * to write the (single) counter, and rarely to read it.
59 * They're badly named; to fix, someday.
60 */
56#if BITS_PER_LONG == 64 61#if BITS_PER_LONG == 64
57#define write_counter(V, MC) writeq(V, MC) 62#define write_counter(V, MC) writeq(V, MC)
58#define read_counter(MC) readq(MC) 63#define read_counter(MC) readq(MC)
@@ -77,7 +82,7 @@ static struct clocksource clocksource_hpet = {
77 .rating = 250, 82 .rating = 250,
78 .read = read_hpet, 83 .read = read_hpet,
79 .mask = CLOCKSOURCE_MASK(64), 84 .mask = CLOCKSOURCE_MASK(64),
80 .mult = 0, /*to be caluclated*/ 85 .mult = 0, /* to be calculated */
81 .shift = 10, 86 .shift = 10,
82 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 87 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
83}; 88};
@@ -86,8 +91,6 @@ static struct clocksource *hpet_clocksource;
86 91
87/* A lock for concurrent access by app and isr hpet activity. */ 92/* A lock for concurrent access by app and isr hpet activity. */
88static DEFINE_SPINLOCK(hpet_lock); 93static DEFINE_SPINLOCK(hpet_lock);
89/* A lock for concurrent intermodule access to hpet and isr hpet activity. */
90static DEFINE_SPINLOCK(hpet_task_lock);
91 94
92#define HPET_DEV_NAME (7) 95#define HPET_DEV_NAME (7)
93 96
@@ -99,7 +102,6 @@ struct hpet_dev {
99 unsigned long hd_irqdata; 102 unsigned long hd_irqdata;
100 wait_queue_head_t hd_waitqueue; 103 wait_queue_head_t hd_waitqueue;
101 struct fasync_struct *hd_async_queue; 104 struct fasync_struct *hd_async_queue;
102 struct hpet_task *hd_task;
103 unsigned int hd_flags; 105 unsigned int hd_flags;
104 unsigned int hd_irq; 106 unsigned int hd_irq;
105 unsigned int hd_hdwirq; 107 unsigned int hd_hdwirq;
@@ -173,11 +175,6 @@ static irqreturn_t hpet_interrupt(int irq, void *data)
173 writel(isr, &devp->hd_hpet->hpet_isr); 175 writel(isr, &devp->hd_hpet->hpet_isr);
174 spin_unlock(&hpet_lock); 176 spin_unlock(&hpet_lock);
175 177
176 spin_lock(&hpet_task_lock);
177 if (devp->hd_task)
178 devp->hd_task->ht_func(devp->hd_task->ht_data);
179 spin_unlock(&hpet_task_lock);
180
181 wake_up_interruptible(&devp->hd_waitqueue); 178 wake_up_interruptible(&devp->hd_waitqueue);
182 179
183 kill_fasync(&devp->hd_async_queue, SIGIO, POLL_IN); 180 kill_fasync(&devp->hd_async_queue, SIGIO, POLL_IN);
@@ -185,6 +182,67 @@ static irqreturn_t hpet_interrupt(int irq, void *data)
185 return IRQ_HANDLED; 182 return IRQ_HANDLED;
186} 183}
187 184
185static void hpet_timer_set_irq(struct hpet_dev *devp)
186{
187 unsigned long v;
188 int irq, gsi;
189 struct hpet_timer __iomem *timer;
190
191 spin_lock_irq(&hpet_lock);
192 if (devp->hd_hdwirq) {
193 spin_unlock_irq(&hpet_lock);
194 return;
195 }
196
197 timer = devp->hd_timer;
198
199 /* we prefer level triggered mode */
200 v = readl(&timer->hpet_config);
201 if (!(v & Tn_INT_TYPE_CNF_MASK)) {
202 v |= Tn_INT_TYPE_CNF_MASK;
203 writel(v, &timer->hpet_config);
204 }
205 spin_unlock_irq(&hpet_lock);
206
207 v = (readq(&timer->hpet_config) & Tn_INT_ROUTE_CAP_MASK) >>
208 Tn_INT_ROUTE_CAP_SHIFT;
209
210 /*
211 * In PIC mode, skip IRQ0-4, IRQ6-9, IRQ12-15 which is always used by
212 * legacy device. In IO APIC mode, we skip all the legacy IRQS.
213 */
214 if (acpi_irq_model == ACPI_IRQ_MODEL_PIC)
215 v &= ~0xf3df;
216 else
217 v &= ~0xffff;
218
219 for (irq = find_first_bit(&v, HPET_MAX_IRQ); irq < HPET_MAX_IRQ;
220 irq = find_next_bit(&v, HPET_MAX_IRQ, 1 + irq)) {
221
222 if (irq >= NR_IRQS) {
223 irq = HPET_MAX_IRQ;
224 break;
225 }
226
227 gsi = acpi_register_gsi(irq, ACPI_LEVEL_SENSITIVE,
228 ACPI_ACTIVE_LOW);
229 if (gsi > 0)
230 break;
231
232 /* FIXME: Setup interrupt source table */
233 }
234
235 if (irq < HPET_MAX_IRQ) {
236 spin_lock_irq(&hpet_lock);
237 v = readl(&timer->hpet_config);
238 v |= irq << Tn_INT_ROUTE_CNF_SHIFT;
239 writel(v, &timer->hpet_config);
240 devp->hd_hdwirq = gsi;
241 spin_unlock_irq(&hpet_lock);
242 }
243 return;
244}
245
188static int hpet_open(struct inode *inode, struct file *file) 246static int hpet_open(struct inode *inode, struct file *file)
189{ 247{
190 struct hpet_dev *devp; 248 struct hpet_dev *devp;
@@ -199,8 +257,7 @@ static int hpet_open(struct inode *inode, struct file *file)
199 257
200 for (devp = NULL, hpetp = hpets; hpetp && !devp; hpetp = hpetp->hp_next) 258 for (devp = NULL, hpetp = hpets; hpetp && !devp; hpetp = hpetp->hp_next)
201 for (i = 0; i < hpetp->hp_ntimer; i++) 259 for (i = 0; i < hpetp->hp_ntimer; i++)
202 if (hpetp->hp_dev[i].hd_flags & HPET_OPEN 260 if (hpetp->hp_dev[i].hd_flags & HPET_OPEN)
203 || hpetp->hp_dev[i].hd_task)
204 continue; 261 continue;
205 else { 262 else {
206 devp = &hpetp->hp_dev[i]; 263 devp = &hpetp->hp_dev[i];
@@ -219,6 +276,8 @@ static int hpet_open(struct inode *inode, struct file *file)
219 spin_unlock_irq(&hpet_lock); 276 spin_unlock_irq(&hpet_lock);
220 unlock_kernel(); 277 unlock_kernel();
221 278
279 hpet_timer_set_irq(devp);
280
222 return 0; 281 return 0;
223} 282}
224 283
@@ -441,7 +500,11 @@ static int hpet_ioctl_ieon(struct hpet_dev *devp)
441 devp->hd_irq = irq; 500 devp->hd_irq = irq;
442 t = devp->hd_ireqfreq; 501 t = devp->hd_ireqfreq;
443 v = readq(&timer->hpet_config); 502 v = readq(&timer->hpet_config);
444 g = v | Tn_INT_ENB_CNF_MASK; 503
504 /* 64-bit comparators are not yet supported through the ioctls,
505 * so force this into 32-bit mode if it supports both modes
506 */
507 g = v | Tn_32MODE_CNF_MASK | Tn_INT_ENB_CNF_MASK;
445 508
446 if (devp->hd_flags & HPET_PERIODIC) { 509 if (devp->hd_flags & HPET_PERIODIC) {
447 write_counter(t, &timer->hpet_compare); 510 write_counter(t, &timer->hpet_compare);
@@ -451,6 +514,12 @@ static int hpet_ioctl_ieon(struct hpet_dev *devp)
451 v |= Tn_VAL_SET_CNF_MASK; 514 v |= Tn_VAL_SET_CNF_MASK;
452 writeq(v, &timer->hpet_config); 515 writeq(v, &timer->hpet_config);
453 local_irq_save(flags); 516 local_irq_save(flags);
517
518 /* NOTE: what we modify here is a hidden accumulator
519 * register supported by periodic-capable comparators.
520 * We never want to modify the (single) counter; that
521 * would affect all the comparators.
522 */
454 m = read_counter(&hpet->hpet_mc); 523 m = read_counter(&hpet->hpet_mc);
455 write_counter(t + m + hpetp->hp_delta, &timer->hpet_compare); 524 write_counter(t + m + hpetp->hp_delta, &timer->hpet_compare);
456 } else { 525 } else {
@@ -604,57 +673,6 @@ static int hpet_is_known(struct hpet_data *hdp)
604 return 0; 673 return 0;
605} 674}
606 675
607static inline int hpet_tpcheck(struct hpet_task *tp)
608{
609 struct hpet_dev *devp;
610 struct hpets *hpetp;
611
612 devp = tp->ht_opaque;
613
614 if (!devp)
615 return -ENXIO;
616
617 for (hpetp = hpets; hpetp; hpetp = hpetp->hp_next)
618 if (devp >= hpetp->hp_dev
619 && devp < (hpetp->hp_dev + hpetp->hp_ntimer)
620 && devp->hd_hpet == hpetp->hp_hpet)
621 return 0;
622
623 return -ENXIO;
624}
625
626#if 0
627int hpet_unregister(struct hpet_task *tp)
628{
629 struct hpet_dev *devp;
630 struct hpet_timer __iomem *timer;
631 int err;
632
633 if ((err = hpet_tpcheck(tp)))
634 return err;
635
636 spin_lock_irq(&hpet_task_lock);
637 spin_lock(&hpet_lock);
638
639 devp = tp->ht_opaque;
640 if (devp->hd_task != tp) {
641 spin_unlock(&hpet_lock);
642 spin_unlock_irq(&hpet_task_lock);
643 return -ENXIO;
644 }
645
646 timer = devp->hd_timer;
647 writeq((readq(&timer->hpet_config) & ~Tn_INT_ENB_CNF_MASK),
648 &timer->hpet_config);
649 devp->hd_flags &= ~(HPET_IE | HPET_PERIODIC);
650 devp->hd_task = NULL;
651 spin_unlock(&hpet_lock);
652 spin_unlock_irq(&hpet_task_lock);
653
654 return 0;
655}
656#endif /* 0 */
657
658static ctl_table hpet_table[] = { 676static ctl_table hpet_table[] = {
659 { 677 {
660 .ctl_name = CTL_UNNUMBERED, 678 .ctl_name = CTL_UNNUMBERED,
@@ -746,6 +764,7 @@ int hpet_alloc(struct hpet_data *hdp)
746 static struct hpets *last = NULL; 764 static struct hpets *last = NULL;
747 unsigned long period; 765 unsigned long period;
748 unsigned long long temp; 766 unsigned long long temp;
767 u32 remainder;
749 768
750 /* 769 /*
751 * hpet_alloc can be called by platform dependent code. 770 * hpet_alloc can be called by platform dependent code.
@@ -809,9 +828,13 @@ int hpet_alloc(struct hpet_data *hdp)
809 printk("%s %d", i > 0 ? "," : "", hdp->hd_irq[i]); 828 printk("%s %d", i > 0 ? "," : "", hdp->hd_irq[i]);
810 printk("\n"); 829 printk("\n");
811 830
812 printk(KERN_INFO "hpet%u: %u %d-bit timers, %Lu Hz\n", 831 temp = hpetp->hp_tick_freq;
813 hpetp->hp_which, hpetp->hp_ntimer, 832 remainder = do_div(temp, 1000000);
814 cap & HPET_COUNTER_SIZE_MASK ? 64 : 32, hpetp->hp_tick_freq); 833 printk(KERN_INFO
834 "hpet%u: %u comparators, %d-bit %u.%06u MHz counter\n",
835 hpetp->hp_which, hpetp->hp_ntimer,
836 cap & HPET_COUNTER_SIZE_MASK ? 64 : 32,
837 (unsigned) temp, remainder);
815 838
816 mcfg = readq(&hpet->hpet_config); 839 mcfg = readq(&hpet->hpet_config);
817 if ((mcfg & HPET_ENABLE_CNF_MASK) == 0) { 840 if ((mcfg & HPET_ENABLE_CNF_MASK) == 0) {
@@ -874,8 +897,6 @@ static acpi_status hpet_resources(struct acpi_resource *res, void *data)
874 hdp->hd_address = ioremap(addr.minimum, addr.address_length); 897 hdp->hd_address = ioremap(addr.minimum, addr.address_length);
875 898
876 if (hpet_is_known(hdp)) { 899 if (hpet_is_known(hdp)) {
877 printk(KERN_DEBUG "%s: 0x%lx is busy\n",
878 __func__, hdp->hd_phys_address);
879 iounmap(hdp->hd_address); 900 iounmap(hdp->hd_address);
880 return AE_ALREADY_EXISTS; 901 return AE_ALREADY_EXISTS;
881 } 902 }
@@ -891,8 +912,6 @@ static acpi_status hpet_resources(struct acpi_resource *res, void *data)
891 HPET_RANGE_SIZE); 912 HPET_RANGE_SIZE);
892 913
893 if (hpet_is_known(hdp)) { 914 if (hpet_is_known(hdp)) {
894 printk(KERN_DEBUG "%s: 0x%lx is busy\n",
895 __func__, hdp->hd_phys_address);
896 iounmap(hdp->hd_address); 915 iounmap(hdp->hd_address);
897 return AE_ALREADY_EXISTS; 916 return AE_ALREADY_EXISTS;
898 } 917 }
diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c
index fd64137b1ab9..bf70450a49cc 100644
--- a/drivers/char/hvc_console.c
+++ b/drivers/char/hvc_console.c
@@ -367,13 +367,13 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
367 spin_lock_irqsave(&hp->lock, flags); 367 spin_lock_irqsave(&hp->lock, flags);
368 368
369 if (--hp->count == 0) { 369 if (--hp->count == 0) {
370 if (hp->ops->notifier_del)
371 hp->ops->notifier_del(hp, hp->data);
372
373 /* We are done with the tty pointer now. */ 370 /* We are done with the tty pointer now. */
374 hp->tty = NULL; 371 hp->tty = NULL;
375 spin_unlock_irqrestore(&hp->lock, flags); 372 spin_unlock_irqrestore(&hp->lock, flags);
376 373
374 if (hp->ops->notifier_del)
375 hp->ops->notifier_del(hp, hp->data);
376
377 /* 377 /*
378 * Chain calls chars_in_buffer() and returns immediately if 378 * Chain calls chars_in_buffer() and returns immediately if
379 * there is no buffered data otherwise sleeps on a wait queue 379 * there is no buffered data otherwise sleeps on a wait queue
@@ -416,11 +416,11 @@ static void hvc_hangup(struct tty_struct *tty)
416 hp->n_outbuf = 0; 416 hp->n_outbuf = 0;
417 hp->tty = NULL; 417 hp->tty = NULL;
418 418
419 spin_unlock_irqrestore(&hp->lock, flags);
420
419 if (hp->ops->notifier_del) 421 if (hp->ops->notifier_del)
420 hp->ops->notifier_del(hp, hp->data); 422 hp->ops->notifier_del(hp, hp->data);
421 423
422 spin_unlock_irqrestore(&hp->lock, flags);
423
424 while(temp_open_count) { 424 while(temp_open_count) {
425 --temp_open_count; 425 --temp_open_count;
426 kref_put(&hp->kref, destroy_hvc_struct); 426 kref_put(&hp->kref, destroy_hvc_struct);
@@ -819,11 +819,11 @@ static int hvc_init(void)
819 hvc_driver = drv; 819 hvc_driver = drv;
820 return 0; 820 return 0;
821 821
822put_tty:
823 put_tty_driver(hvc_driver);
824stop_thread: 822stop_thread:
825 kthread_stop(hvc_task); 823 kthread_stop(hvc_task);
826 hvc_task = NULL; 824 hvc_task = NULL;
825put_tty:
826 put_tty_driver(drv);
827out: 827out:
828 return err; 828 return err;
829} 829}
diff --git a/drivers/char/hw_random/omap-rng.c b/drivers/char/hw_random/omap-rng.c
index 51738bdd834e..d4e7dca06e4f 100644
--- a/drivers/char/hw_random/omap-rng.c
+++ b/drivers/char/hw_random/omap-rng.c
@@ -118,18 +118,21 @@ static int __init omap_rng_probe(struct platform_device *pdev)
118 118
119 mem = request_mem_region(res->start, res->end - res->start + 1, 119 mem = request_mem_region(res->start, res->end - res->start + 1,
120 pdev->name); 120 pdev->name);
121 if (mem == NULL) 121 if (mem == NULL) {
122 return -EBUSY; 122 ret = -EBUSY;
123 goto err_region;
124 }
123 125
124 dev_set_drvdata(&pdev->dev, mem); 126 dev_set_drvdata(&pdev->dev, mem);
125 rng_base = (u32 __force __iomem *)io_p2v(res->start); 127 rng_base = ioremap(res->start, res->end - res->start + 1);
128 if (!rng_base) {
129 ret = -ENOMEM;
130 goto err_ioremap;
131 }
126 132
127 ret = hwrng_register(&omap_rng_ops); 133 ret = hwrng_register(&omap_rng_ops);
128 if (ret) { 134 if (ret)
129 release_resource(mem); 135 goto err_register;
130 rng_base = NULL;
131 return ret;
132 }
133 136
134 dev_info(&pdev->dev, "OMAP Random Number Generator ver. %02x\n", 137 dev_info(&pdev->dev, "OMAP Random Number Generator ver. %02x\n",
135 omap_rng_read_reg(RNG_REV_REG)); 138 omap_rng_read_reg(RNG_REV_REG));
@@ -138,6 +141,18 @@ static int __init omap_rng_probe(struct platform_device *pdev)
138 rng_dev = pdev; 141 rng_dev = pdev;
139 142
140 return 0; 143 return 0;
144
145err_register:
146 iounmap(rng_base);
147 rng_base = NULL;
148err_ioremap:
149 release_resource(mem);
150err_region:
151 if (cpu_is_omap24xx()) {
152 clk_disable(rng_ick);
153 clk_put(rng_ick);
154 }
155 return ret;
141} 156}
142 157
143static int __exit omap_rng_remove(struct platform_device *pdev) 158static int __exit omap_rng_remove(struct platform_device *pdev)
@@ -148,6 +163,8 @@ static int __exit omap_rng_remove(struct platform_device *pdev)
148 163
149 omap_rng_write_reg(RNG_MASK_REG, 0x0); 164 omap_rng_write_reg(RNG_MASK_REG, 0x0);
150 165
166 iounmap(rng_base);
167
151 if (cpu_is_omap24xx()) { 168 if (cpu_is_omap24xx()) {
152 clk_disable(rng_ick); 169 clk_disable(rng_ick);
153 clk_put(rng_ick); 170 clk_put(rng_ick);
diff --git a/drivers/char/ip2/Makefile b/drivers/char/ip2/Makefile
index 939618f62fe1..bc397d92b499 100644
--- a/drivers/char/ip2/Makefile
+++ b/drivers/char/ip2/Makefile
@@ -4,5 +4,5 @@
4 4
5obj-$(CONFIG_COMPUTONE) += ip2.o 5obj-$(CONFIG_COMPUTONE) += ip2.o
6 6
7ip2-objs := ip2base.o ip2main.o 7ip2-objs := ip2main.o
8 8
diff --git a/drivers/char/ip2/i2ellis.c b/drivers/char/ip2/i2ellis.c
index 3601017f58cf..29db44de399f 100644
--- a/drivers/char/ip2/i2ellis.c
+++ b/drivers/char/ip2/i2ellis.c
@@ -69,38 +69,6 @@ static DEFINE_RWLOCK(Dl_spinlock);
69//======================================================= 69//=======================================================
70 70
71//****************************************************************************** 71//******************************************************************************
72// Function: iiEllisInit()
73// Parameters: None
74//
75// Returns: Nothing
76//
77// Description:
78//
79// This routine performs any required initialization of the iiEllis subsystem.
80//
81//******************************************************************************
82static void
83iiEllisInit(void)
84{
85}
86
87//******************************************************************************
88// Function: iiEllisCleanup()
89// Parameters: None
90//
91// Returns: Nothing
92//
93// Description:
94//
95// This routine performs any required cleanup of the iiEllis subsystem.
96//
97//******************************************************************************
98static void
99iiEllisCleanup(void)
100{
101}
102
103//******************************************************************************
104// Function: iiSetAddress(pB, address, delay) 72// Function: iiSetAddress(pB, address, delay)
105// Parameters: pB - pointer to the board structure 73// Parameters: pB - pointer to the board structure
106// address - the purported I/O address of the board 74// address - the purported I/O address of the board
diff --git a/drivers/char/ip2/i2ellis.h b/drivers/char/ip2/i2ellis.h
index c88a64e527aa..fb6df2456018 100644
--- a/drivers/char/ip2/i2ellis.h
+++ b/drivers/char/ip2/i2ellis.h
@@ -511,7 +511,6 @@ typedef void (*delayFunc_t)(unsigned int);
511// 511//
512// Initialization of a board & structure is in four (five!) parts: 512// Initialization of a board & structure is in four (five!) parts:
513// 513//
514// 0) iiEllisInit() - Initialize iiEllis subsystem.
515// 1) iiSetAddress() - Define the board address & delay function for a board. 514// 1) iiSetAddress() - Define the board address & delay function for a board.
516// 2) iiReset() - Reset the board (provided it exists) 515// 2) iiReset() - Reset the board (provided it exists)
517// -- Note you may do this to several boards -- 516// -- Note you may do this to several boards --
@@ -523,7 +522,6 @@ typedef void (*delayFunc_t)(unsigned int);
523// loadware. To change loadware, you must begin again with step 2, resetting 522// loadware. To change loadware, you must begin again with step 2, resetting
524// the board again (step 1 not needed). 523// the board again (step 1 not needed).
525 524
526static void iiEllisInit(void);
527static int iiSetAddress(i2eBordStrPtr, int, delayFunc_t ); 525static int iiSetAddress(i2eBordStrPtr, int, delayFunc_t );
528static int iiReset(i2eBordStrPtr); 526static int iiReset(i2eBordStrPtr);
529static int iiResetDelay(i2eBordStrPtr); 527static int iiResetDelay(i2eBordStrPtr);
diff --git a/drivers/char/ip2/ip2base.c b/drivers/char/ip2/ip2base.c
deleted file mode 100644
index 8155e247c04b..000000000000
--- a/drivers/char/ip2/ip2base.c
+++ /dev/null
@@ -1,108 +0,0 @@
1// ip2.c
2// This is a dummy module to make the firmware available when needed
3// and allows it to be unloaded when not. Rumor is the __initdata
4// macro doesn't always works on all platforms so we use this kludge.
5// If not compiled as a module it just makes fip_firm avaliable then
6// __initdata should work as advertized
7//
8
9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/wait.h>
12
13#ifndef __init
14#define __init
15#endif
16#ifndef __initfunc
17#define __initfunc(a) a
18#endif
19#ifndef __initdata
20#define __initdata
21#endif
22
23#include "ip2types.h"
24
25int
26ip2_loadmain(int *, int *); // ref into ip2main.c
27
28/* Note: Add compiled in defaults to these arrays, not to the structure
29 in ip2.h any longer. That structure WILL get overridden
30 by these values, or command line values, or insmod values!!! =mhw=
31*/
32static int io[IP2_MAX_BOARDS]= { 0, 0, 0, 0 };
33static int irq[IP2_MAX_BOARDS] = { -1, -1, -1, -1 };
34
35static int poll_only = 0;
36
37MODULE_AUTHOR("Doug McNash");
38MODULE_DESCRIPTION("Computone IntelliPort Plus Driver");
39module_param_array(irq, int, NULL, 0);
40MODULE_PARM_DESC(irq,"Interrupts for IntelliPort Cards");
41module_param_array(io, int, NULL, 0);
42MODULE_PARM_DESC(io,"I/O ports for IntelliPort Cards");
43module_param(poll_only, bool, 0);
44MODULE_PARM_DESC(poll_only,"Do not use card interrupts");
45
46
47static int __init ip2_init(void)
48{
49 if( poll_only ) {
50 /* Hard lock the interrupts to zero */
51 irq[0] = irq[1] = irq[2] = irq[3] = 0;
52 }
53
54 return ip2_loadmain(io, irq);
55}
56module_init(ip2_init);
57
58MODULE_LICENSE("GPL");
59
60#ifndef MODULE
61/******************************************************************************
62 * ip2_setup:
63 * str: kernel command line string
64 *
65 * Can't autoprobe the boards so user must specify configuration on
66 * kernel command line. Sane people build it modular but the others
67 * come here.
68 *
69 * Alternating pairs of io,irq for up to 4 boards.
70 * ip2=io0,irq0,io1,irq1,io2,irq2,io3,irq3
71 *
72 * io=0 => No board
73 * io=1 => PCI
74 * io=2 => EISA
75 * else => ISA I/O address
76 *
77 * irq=0 or invalid for ISA will revert to polling mode
78 *
79 * Any value = -1, do not overwrite compiled in value.
80 *
81 ******************************************************************************/
82static int __init ip2_setup(char *str)
83{
84 int ints[10]; /* 4 boards, 2 parameters + 2 */
85 int i, j;
86
87 str = get_options (str, ARRAY_SIZE(ints), ints);
88
89 for( i = 0, j = 1; i < 4; i++ ) {
90 if( j > ints[0] ) {
91 break;
92 }
93 if( ints[j] >= 0 ) {
94 io[i] = ints[j];
95 }
96 j++;
97 if( j > ints[0] ) {
98 break;
99 }
100 if( ints[j] >= 0 ) {
101 irq[i] = ints[j];
102 }
103 j++;
104 }
105 return 1;
106}
107__setup("ip2=", ip2_setup);
108#endif /* !MODULE */
diff --git a/drivers/char/ip2/ip2main.c b/drivers/char/ip2/ip2main.c
index 689f9dcd3b86..70e0ebc30bd0 100644
--- a/drivers/char/ip2/ip2main.c
+++ b/drivers/char/ip2/ip2main.c
@@ -150,15 +150,12 @@ static int ip2_read_proc(char *, char **, off_t, int, int *, void * );
150/*************/ 150/*************/
151 151
152/* String constants to identify ourselves */ 152/* String constants to identify ourselves */
153static char *pcName = "Computone IntelliPort Plus multiport driver"; 153static const char pcName[] = "Computone IntelliPort Plus multiport driver";
154static char *pcVersion = "1.2.14"; 154static const char pcVersion[] = "1.2.14";
155 155
156/* String constants for port names */ 156/* String constants for port names */
157static char *pcDriver_name = "ip2"; 157static const char pcDriver_name[] = "ip2";
158static char *pcIpl = "ip2ipl"; 158static const char pcIpl[] = "ip2ipl";
159
160// cheezy kludge or genius - you decide?
161int ip2_loadmain(int *, int *);
162 159
163/***********************/ 160/***********************/
164/* Function Prototypes */ 161/* Function Prototypes */
@@ -240,8 +237,8 @@ static const struct file_operations ip2_ipl = {
240 .open = ip2_ipl_open, 237 .open = ip2_ipl_open,
241}; 238};
242 239
243static unsigned long irq_counter = 0; 240static unsigned long irq_counter;
244static unsigned long bh_counter = 0; 241static unsigned long bh_counter;
245 242
246// Use immediate queue to service interrupts 243// Use immediate queue to service interrupts
247#define USE_IQI 244#define USE_IQI
@@ -252,7 +249,6 @@ static unsigned long bh_counter = 0;
252 */ 249 */
253#define POLL_TIMEOUT (jiffies + 1) 250#define POLL_TIMEOUT (jiffies + 1)
254static DEFINE_TIMER(PollTimer, ip2_poll, 0, 0); 251static DEFINE_TIMER(PollTimer, ip2_poll, 0, 0);
255static char TimerOn;
256 252
257#ifdef IP2DEBUG_TRACE 253#ifdef IP2DEBUG_TRACE
258/* Trace (debug) buffer data */ 254/* Trace (debug) buffer data */
@@ -268,8 +264,8 @@ static int tracewrap;
268/**********/ 264/**********/
269 265
270#if defined(MODULE) && defined(IP2DEBUG_OPEN) 266#if defined(MODULE) && defined(IP2DEBUG_OPEN)
271#define DBG_CNT(s) printk(KERN_DEBUG "(%s): [%x] refc=%d, ttyc=%d, modc=%x -> %s\n", \ 267#define DBG_CNT(s) printk(KERN_DEBUG "(%s): [%x] ttyc=%d, modc=%x -> %s\n", \
272 tty->name,(pCh->flags),ip2_tty_driver->refcount, \ 268 tty->name,(pCh->flags), \
273 tty->count,/*GET_USE_COUNT(module)*/0,s) 269 tty->count,/*GET_USE_COUNT(module)*/0,s)
274#else 270#else
275#define DBG_CNT(s) 271#define DBG_CNT(s)
@@ -287,8 +283,9 @@ static int tracewrap;
287 283
288MODULE_AUTHOR("Doug McNash"); 284MODULE_AUTHOR("Doug McNash");
289MODULE_DESCRIPTION("Computone IntelliPort Plus Driver"); 285MODULE_DESCRIPTION("Computone IntelliPort Plus Driver");
286MODULE_LICENSE("GPL");
290 287
291static int poll_only = 0; 288static int poll_only;
292 289
293static int Eisa_irq; 290static int Eisa_irq;
294static int Eisa_slot; 291static int Eisa_slot;
@@ -297,34 +294,46 @@ static int iindx;
297static char rirqs[IP2_MAX_BOARDS]; 294static char rirqs[IP2_MAX_BOARDS];
298static int Valid_Irqs[] = { 3, 4, 5, 7, 10, 11, 12, 15, 0}; 295static int Valid_Irqs[] = { 3, 4, 5, 7, 10, 11, 12, 15, 0};
299 296
297/* Note: Add compiled in defaults to these arrays, not to the structure
298 in ip2.h any longer. That structure WILL get overridden
299 by these values, or command line values, or insmod values!!! =mhw=
300*/
301static int io[IP2_MAX_BOARDS];
302static int irq[IP2_MAX_BOARDS] = { -1, -1, -1, -1 };
303
304MODULE_AUTHOR("Doug McNash");
305MODULE_DESCRIPTION("Computone IntelliPort Plus Driver");
306module_param_array(irq, int, NULL, 0);
307MODULE_PARM_DESC(irq, "Interrupts for IntelliPort Cards");
308module_param_array(io, int, NULL, 0);
309MODULE_PARM_DESC(io, "I/O ports for IntelliPort Cards");
310module_param(poll_only, bool, 0);
311MODULE_PARM_DESC(poll_only, "Do not use card interrupts");
312
300/* for sysfs class support */ 313/* for sysfs class support */
301static struct class *ip2_class; 314static struct class *ip2_class;
302 315
303// Some functions to keep track of what irq's we have 316/* Some functions to keep track of what irqs we have */
304 317
305static int 318static int __init is_valid_irq(int irq)
306is_valid_irq(int irq)
307{ 319{
308 int *i = Valid_Irqs; 320 int *i = Valid_Irqs;
309 321
310 while ((*i != 0) && (*i != irq)) { 322 while (*i != 0 && *i != irq)
311 i++; 323 i++;
312 } 324
313 return (*i); 325 return *i;
314} 326}
315 327
316static void 328static void __init mark_requested_irq(char irq)
317mark_requested_irq( char irq )
318{ 329{
319 rirqs[iindx++] = irq; 330 rirqs[iindx++] = irq;
320} 331}
321 332
322#ifdef MODULE 333static int __exit clear_requested_irq(char irq)
323static int
324clear_requested_irq( char irq )
325{ 334{
326 int i; 335 int i;
327 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) { 336 for (i = 0; i < IP2_MAX_BOARDS; ++i) {
328 if (rirqs[i] == irq) { 337 if (rirqs[i] == irq) {
329 rirqs[i] = 0; 338 rirqs[i] = 0;
330 return 1; 339 return 1;
@@ -332,17 +341,15 @@ clear_requested_irq( char irq )
332 } 341 }
333 return 0; 342 return 0;
334} 343}
335#endif
336 344
337static int 345static int have_requested_irq(char irq)
338have_requested_irq( char irq )
339{ 346{
340 // array init to zeros so 0 irq will not be requested as a side effect 347 /* array init to zeros so 0 irq will not be requested as a side
348 * effect */
341 int i; 349 int i;
342 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) { 350 for (i = 0; i < IP2_MAX_BOARDS; ++i)
343 if (rirqs[i] == irq) 351 if (rirqs[i] == irq)
344 return 1; 352 return 1;
345 }
346 return 0; 353 return 0;
347} 354}
348 355
@@ -361,53 +368,45 @@ have_requested_irq( char irq )
361/* handle subsequent installations of the driver. All memory allocated by the */ 368/* handle subsequent installations of the driver. All memory allocated by the */
362/* driver should be returned since it may be unloaded from memory. */ 369/* driver should be returned since it may be unloaded from memory. */
363/******************************************************************************/ 370/******************************************************************************/
364#ifdef MODULE 371static void __exit ip2_cleanup_module(void)
365void __exit
366ip2_cleanup_module(void)
367{ 372{
368 int err; 373 int err;
369 int i; 374 int i;
370 375
371#ifdef IP2DEBUG_INIT 376 del_timer_sync(&PollTimer);
372 printk (KERN_DEBUG "Unloading %s: version %s\n", pcName, pcVersion );
373#endif
374 /* Stop poll timer if we had one. */
375 if ( TimerOn ) {
376 del_timer ( &PollTimer );
377 TimerOn = 0;
378 }
379 377
380 /* Reset the boards we have. */ 378 /* Reset the boards we have. */
381 for( i = 0; i < IP2_MAX_BOARDS; ++i ) { 379 for (i = 0; i < IP2_MAX_BOARDS; i++)
382 if ( i2BoardPtrTable[i] ) { 380 if (i2BoardPtrTable[i])
383 iiReset( i2BoardPtrTable[i] ); 381 iiReset(i2BoardPtrTable[i]);
384 }
385 }
386 382
387 /* The following is done at most once, if any boards were installed. */ 383 /* The following is done at most once, if any boards were installed. */
388 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) { 384 for (i = 0; i < IP2_MAX_BOARDS; i++) {
389 if ( i2BoardPtrTable[i] ) { 385 if (i2BoardPtrTable[i]) {
390 iiResetDelay( i2BoardPtrTable[i] ); 386 iiResetDelay(i2BoardPtrTable[i]);
391 /* free io addresses and Tibet */ 387 /* free io addresses and Tibet */
392 release_region( ip2config.addr[i], 8 ); 388 release_region(ip2config.addr[i], 8);
393 device_destroy(ip2_class, MKDEV(IP2_IPL_MAJOR, 4 * i)); 389 device_destroy(ip2_class, MKDEV(IP2_IPL_MAJOR, 4 * i));
394 device_destroy(ip2_class, MKDEV(IP2_IPL_MAJOR, 4 * i + 1)); 390 device_destroy(ip2_class, MKDEV(IP2_IPL_MAJOR,
391 4 * i + 1));
395 } 392 }
396 /* Disable and remove interrupt handler. */ 393 /* Disable and remove interrupt handler. */
397 if ( (ip2config.irq[i] > 0) && have_requested_irq(ip2config.irq[i]) ) { 394 if (ip2config.irq[i] > 0 &&
398 free_irq ( ip2config.irq[i], (void *)&pcName); 395 have_requested_irq(ip2config.irq[i])) {
399 clear_requested_irq( ip2config.irq[i]); 396 free_irq(ip2config.irq[i], (void *)&pcName);
397 clear_requested_irq(ip2config.irq[i]);
400 } 398 }
401 } 399 }
402 class_destroy(ip2_class); 400 class_destroy(ip2_class);
403 if ( ( err = tty_unregister_driver ( ip2_tty_driver ) ) ) { 401 err = tty_unregister_driver(ip2_tty_driver);
404 printk(KERN_ERR "IP2: failed to unregister tty driver (%d)\n", err); 402 if (err)
405 } 403 printk(KERN_ERR "IP2: failed to unregister tty driver (%d)\n",
404 err);
406 put_tty_driver(ip2_tty_driver); 405 put_tty_driver(ip2_tty_driver);
407 unregister_chrdev(IP2_IPL_MAJOR, pcIpl); 406 unregister_chrdev(IP2_IPL_MAJOR, pcIpl);
408 remove_proc_entry("ip2mem", NULL); 407 remove_proc_entry("ip2mem", NULL);
409 408
410 // free memory 409 /* free memory */
411 for (i = 0; i < IP2_MAX_BOARDS; i++) { 410 for (i = 0; i < IP2_MAX_BOARDS; i++) {
412 void *pB; 411 void *pB;
413#ifdef CONFIG_PCI 412#ifdef CONFIG_PCI
@@ -417,24 +416,18 @@ ip2_cleanup_module(void)
417 ip2config.pci_dev[i] = NULL; 416 ip2config.pci_dev[i] = NULL;
418 } 417 }
419#endif 418#endif
420 if ((pB = i2BoardPtrTable[i]) != 0 ) { 419 pB = i2BoardPtrTable[i];
421 kfree ( pB ); 420 if (pB != NULL) {
421 kfree(pB);
422 i2BoardPtrTable[i] = NULL; 422 i2BoardPtrTable[i] = NULL;
423 } 423 }
424 if ((DevTableMem[i]) != NULL ) { 424 if (DevTableMem[i] != NULL) {
425 kfree ( DevTableMem[i] ); 425 kfree(DevTableMem[i]);
426 DevTableMem[i] = NULL; 426 DevTableMem[i] = NULL;
427 } 427 }
428 } 428 }
429
430 /* Cleanup the iiEllis subsystem. */
431 iiEllisCleanup();
432#ifdef IP2DEBUG_INIT
433 printk (KERN_DEBUG "IP2 Unloaded\n" );
434#endif
435} 429}
436module_exit(ip2_cleanup_module); 430module_exit(ip2_cleanup_module);
437#endif /* MODULE */
438 431
439static const struct tty_operations ip2_ops = { 432static const struct tty_operations ip2_ops = {
440 .open = ip2_open, 433 .open = ip2_open,
@@ -494,139 +487,168 @@ static const struct firmware *ip2_request_firmware(void)
494 return fw; 487 return fw;
495} 488}
496 489
497int 490#ifndef MODULE
498ip2_loadmain(int *iop, int *irqp) 491/******************************************************************************
492 * ip2_setup:
493 * str: kernel command line string
494 *
495 * Can't autoprobe the boards so user must specify configuration on
496 * kernel command line. Sane people build it modular but the others
497 * come here.
498 *
499 * Alternating pairs of io,irq for up to 4 boards.
500 * ip2=io0,irq0,io1,irq1,io2,irq2,io3,irq3
501 *
502 * io=0 => No board
503 * io=1 => PCI
504 * io=2 => EISA
505 * else => ISA I/O address
506 *
507 * irq=0 or invalid for ISA will revert to polling mode
508 *
509 * Any value = -1, do not overwrite compiled in value.
510 *
511 ******************************************************************************/
512static int __init ip2_setup(char *str)
513{
514 int j, ints[10]; /* 4 boards, 2 parameters + 2 */
515 unsigned int i;
516
517 str = get_options(str, ARRAY_SIZE(ints), ints);
518
519 for (i = 0, j = 1; i < 4; i++) {
520 if (j > ints[0])
521 break;
522 if (ints[j] >= 0)
523 io[i] = ints[j];
524 j++;
525 if (j > ints[0])
526 break;
527 if (ints[j] >= 0)
528 irq[i] = ints[j];
529 j++;
530 }
531 return 1;
532}
533__setup("ip2=", ip2_setup);
534#endif /* !MODULE */
535
536static int __init ip2_loadmain(void)
499{ 537{
500 int i, j, box; 538 int i, j, box;
501 int err = 0; 539 int err = 0;
502 static int loaded;
503 i2eBordStrPtr pB = NULL; 540 i2eBordStrPtr pB = NULL;
504 int rc = -1; 541 int rc = -1;
505 static struct pci_dev *pci_dev_i = NULL; 542 struct pci_dev *pdev = NULL;
506 const struct firmware *fw = NULL; 543 const struct firmware *fw = NULL;
507 544
508 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_ENTER, 0 ); 545 if (poll_only) {
546 /* Hard lock the interrupts to zero */
547 irq[0] = irq[1] = irq[2] = irq[3] = poll_only = 0;
548 }
549
550 ip2trace(ITRC_NO_PORT, ITRC_INIT, ITRC_ENTER, 0);
509 551
510 /* process command line arguments to modprobe or 552 /* process command line arguments to modprobe or
511 insmod i.e. iop & irqp */ 553 insmod i.e. iop & irqp */
512 /* irqp and iop should ALWAYS be specified now... But we check 554 /* irqp and iop should ALWAYS be specified now... But we check
513 them individually just to be sure, anyways... */ 555 them individually just to be sure, anyways... */
514 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) { 556 for (i = 0; i < IP2_MAX_BOARDS; ++i) {
515 if (iop) { 557 ip2config.addr[i] = io[i];
516 ip2config.addr[i] = iop[i]; 558 if (irq[i] >= 0)
517 if (irqp) { 559 ip2config.irq[i] = irq[i];
518 if( irqp[i] >= 0 ) { 560 else
519 ip2config.irq[i] = irqp[i]; 561 ip2config.irq[i] = 0;
520 } else { 562 /* This is a little bit of a hack. If poll_only=1 on command
521 ip2config.irq[i] = 0; 563 line back in ip2.c OR all IRQs on all specified boards are
522 } 564 explicitly set to 0, then drop to poll only mode and override
523 // This is a little bit of a hack. If poll_only=1 on command 565 PCI or EISA interrupts. This superceeds the old hack of
524 // line back in ip2.c OR all IRQs on all specified boards are 566 triggering if all interrupts were zero (like da default).
525 // explicitly set to 0, then drop to poll only mode and override 567 Still a hack but less prone to random acts of terrorism.
526 // PCI or EISA interrupts. This superceeds the old hack of 568
527 // triggering if all interrupts were zero (like da default). 569 What we really should do, now that the IRQ default is set
528 // Still a hack but less prone to random acts of terrorism. 570 to -1, is to use 0 as a hard coded, do not probe.
529 // 571
530 // What we really should do, now that the IRQ default is set 572 /\/\|=mhw=|\/\/
531 // to -1, is to use 0 as a hard coded, do not probe. 573 */
532 // 574 poll_only |= irq[i];
533 // /\/\|=mhw=|\/\/
534 poll_only |= irqp[i];
535 }
536 }
537 } 575 }
538 poll_only = !poll_only; 576 poll_only = !poll_only;
539 577
540 /* Announce our presence */ 578 /* Announce our presence */
541 printk( KERN_INFO "%s version %s\n", pcName, pcVersion ); 579 printk(KERN_INFO "%s version %s\n", pcName, pcVersion);
542
543 // ip2 can be unloaded and reloaded for no good reason
544 // we can't let that happen here or bad things happen
545 // second load hoses board but not system - fixme later
546 if (loaded) {
547 printk( KERN_INFO "Still loaded\n" );
548 return 0;
549 }
550 loaded++;
551 580
552 ip2_tty_driver = alloc_tty_driver(IP2_MAX_PORTS); 581 ip2_tty_driver = alloc_tty_driver(IP2_MAX_PORTS);
553 if (!ip2_tty_driver) 582 if (!ip2_tty_driver)
554 return -ENOMEM; 583 return -ENOMEM;
555 584
556 /* Initialise the iiEllis subsystem. */
557 iiEllisInit();
558
559 /* Initialize arrays. */
560 memset( i2BoardPtrTable, 0, sizeof i2BoardPtrTable );
561 memset( DevTable, 0, sizeof DevTable );
562
563 /* Initialise all the boards we can find (up to the maximum). */ 585 /* Initialise all the boards we can find (up to the maximum). */
564 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) { 586 for (i = 0; i < IP2_MAX_BOARDS; ++i) {
565 switch ( ip2config.addr[i] ) { 587 switch (ip2config.addr[i]) {
566 case 0: /* skip this slot even if card is present */ 588 case 0: /* skip this slot even if card is present */
567 break; 589 break;
568 default: /* ISA */ 590 default: /* ISA */
569 /* ISA address must be specified */ 591 /* ISA address must be specified */
570 if ( (ip2config.addr[i] < 0x100) || (ip2config.addr[i] > 0x3f8) ) { 592 if (ip2config.addr[i] < 0x100 ||
571 printk ( KERN_ERR "IP2: Bad ISA board %d address %x\n", 593 ip2config.addr[i] > 0x3f8) {
572 i, ip2config.addr[i] ); 594 printk(KERN_ERR "IP2: Bad ISA board %d "
595 "address %x\n", i,
596 ip2config.addr[i]);
573 ip2config.addr[i] = 0; 597 ip2config.addr[i] = 0;
574 } else { 598 break;
575 ip2config.type[i] = ISA; 599 }
576 600 ip2config.type[i] = ISA;
577 /* Check for valid irq argument, set for polling if invalid */ 601
578 if (ip2config.irq[i] && !is_valid_irq(ip2config.irq[i])) { 602 /* Check for valid irq argument, set for polling if
579 printk(KERN_ERR "IP2: Bad IRQ(%d) specified\n",ip2config.irq[i]); 603 * invalid */
580 ip2config.irq[i] = 0;// 0 is polling and is valid in that sense 604 if (ip2config.irq[i] &&
581 } 605 !is_valid_irq(ip2config.irq[i])) {
606 printk(KERN_ERR "IP2: Bad IRQ(%d) specified\n",
607 ip2config.irq[i]);
608 /* 0 is polling and is valid in that sense */
609 ip2config.irq[i] = 0;
582 } 610 }
583 break; 611 break;
584 case PCI: 612 case PCI:
585#ifdef CONFIG_PCI 613#ifdef CONFIG_PCI
586 { 614 {
587 int status; 615 u32 addr;
616 int status;
588 617
589 pci_dev_i = pci_get_device(PCI_VENDOR_ID_COMPUTONE, 618 pdev = pci_get_device(PCI_VENDOR_ID_COMPUTONE,
590 PCI_DEVICE_ID_COMPUTONE_IP2EX, pci_dev_i); 619 PCI_DEVICE_ID_COMPUTONE_IP2EX, pdev);
591 if (pci_dev_i != NULL) { 620 if (pdev == NULL) {
592 unsigned int addr; 621 ip2config.addr[i] = 0;
593 622 printk(KERN_ERR "IP2: PCI board %d not "
594 if (pci_enable_device(pci_dev_i)) { 623 "found\n", i);
595 printk( KERN_ERR "IP2: can't enable PCI device at %s\n", 624 break;
596 pci_name(pci_dev_i)); 625 }
597 break;
598 }
599 ip2config.type[i] = PCI;
600 ip2config.pci_dev[i] = pci_dev_get(pci_dev_i);
601 status =
602 pci_read_config_dword(pci_dev_i, PCI_BASE_ADDRESS_1, &addr);
603 if ( addr & 1 ) {
604 ip2config.addr[i]=(USHORT)(addr&0xfffe);
605 } else {
606 printk( KERN_ERR "IP2: PCI I/O address error\n");
607 }
608 626
609// If the PCI BIOS assigned it, lets try and use it. If we 627 if (pci_enable_device(pdev)) {
610// can't acquire it or it screws up, deal with it then. 628 dev_err(&pdev->dev, "can't enable device\n");
611 629 break;
612// if (!is_valid_irq(pci_irq)) {
613// printk( KERN_ERR "IP2: Bad PCI BIOS IRQ(%d)\n",pci_irq);
614// pci_irq = 0;
615// }
616 ip2config.irq[i] = pci_dev_i->irq;
617 } else { // ann error
618 ip2config.addr[i] = 0;
619 printk(KERN_ERR "IP2: PCI board %d not found\n", i);
620 }
621 } 630 }
631 ip2config.type[i] = PCI;
632 ip2config.pci_dev[i] = pci_dev_get(pdev);
633 status = pci_read_config_dword(pdev, PCI_BASE_ADDRESS_1,
634 &addr);
635 if (addr & 1)
636 ip2config.addr[i] = (USHORT)(addr & 0xfffe);
637 else
638 dev_err(&pdev->dev, "I/O address error\n");
639
640 ip2config.irq[i] = pdev->irq;
641 }
622#else 642#else
623 printk( KERN_ERR "IP2: PCI card specified but PCI support not\n"); 643 printk(KERN_ERR "IP2: PCI card specified but PCI "
624 printk( KERN_ERR "IP2: configured in this kernel.\n"); 644 "support not enabled.\n");
625 printk( KERN_ERR "IP2: Recompile kernel with CONFIG_PCI defined!\n"); 645 printk(KERN_ERR "IP2: Recompile kernel with CONFIG_PCI "
646 "defined!\n");
626#endif /* CONFIG_PCI */ 647#endif /* CONFIG_PCI */
627 break; 648 break;
628 case EISA: 649 case EISA:
629 if ( (ip2config.addr[i] = find_eisa_board( Eisa_slot + 1 )) != 0) { 650 ip2config.addr[i] = find_eisa_board(Eisa_slot + 1);
651 if (ip2config.addr[i] != 0) {
630 /* Eisa_irq set as side effect, boo */ 652 /* Eisa_irq set as side effect, boo */
631 ip2config.type[i] = EISA; 653 ip2config.type[i] = EISA;
632 } 654 }
@@ -634,31 +656,32 @@ ip2_loadmain(int *iop, int *irqp)
634 break; 656 break;
635 } /* switch */ 657 } /* switch */
636 } /* for */ 658 } /* for */
637 if (pci_dev_i) 659 pci_dev_put(pdev);
638 pci_dev_put(pci_dev_i);
639 660
640 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) { 661 for (i = 0; i < IP2_MAX_BOARDS; ++i) {
641 if ( ip2config.addr[i] ) { 662 if (ip2config.addr[i]) {
642 pB = kzalloc(sizeof(i2eBordStr), GFP_KERNEL); 663 pB = kzalloc(sizeof(i2eBordStr), GFP_KERNEL);
643 if (pB) { 664 if (pB) {
644 i2BoardPtrTable[i] = pB; 665 i2BoardPtrTable[i] = pB;
645 iiSetAddress( pB, ip2config.addr[i], ii2DelayTimer ); 666 iiSetAddress(pB, ip2config.addr[i],
646 iiReset( pB ); 667 ii2DelayTimer);
647 } else { 668 iiReset(pB);
648 printk(KERN_ERR "IP2: board memory allocation error\n"); 669 } else
649 } 670 printk(KERN_ERR "IP2: board memory allocation "
671 "error\n");
650 } 672 }
651 } 673 }
652 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) { 674 for (i = 0; i < IP2_MAX_BOARDS; ++i) {
653 if ( ( pB = i2BoardPtrTable[i] ) != NULL ) { 675 pB = i2BoardPtrTable[i];
654 iiResetDelay( pB ); 676 if (pB != NULL) {
677 iiResetDelay(pB);
655 break; 678 break;
656 } 679 }
657 } 680 }
658 for ( i = 0; i < IP2_MAX_BOARDS; ++i ) { 681 for (i = 0; i < IP2_MAX_BOARDS; ++i) {
659 /* We don't want to request the firmware unless we have at 682 /* We don't want to request the firmware unless we have at
660 least one board */ 683 least one board */
661 if ( i2BoardPtrTable[i] != NULL ) { 684 if (i2BoardPtrTable[i] != NULL) {
662 if (!fw) 685 if (!fw)
663 fw = ip2_request_firmware(); 686 fw = ip2_request_firmware();
664 if (!fw) 687 if (!fw)
@@ -669,7 +692,7 @@ ip2_loadmain(int *iop, int *irqp)
669 if (fw) 692 if (fw)
670 release_firmware(fw); 693 release_firmware(fw);
671 694
672 ip2trace (ITRC_NO_PORT, ITRC_INIT, 2, 0 ); 695 ip2trace(ITRC_NO_PORT, ITRC_INIT, 2, 0);
673 696
674 ip2_tty_driver->owner = THIS_MODULE; 697 ip2_tty_driver->owner = THIS_MODULE;
675 ip2_tty_driver->name = "ttyF"; 698 ip2_tty_driver->name = "ttyF";
@@ -680,20 +703,23 @@ ip2_loadmain(int *iop, int *irqp)
680 ip2_tty_driver->subtype = SERIAL_TYPE_NORMAL; 703 ip2_tty_driver->subtype = SERIAL_TYPE_NORMAL;
681 ip2_tty_driver->init_termios = tty_std_termios; 704 ip2_tty_driver->init_termios = tty_std_termios;
682 ip2_tty_driver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL; 705 ip2_tty_driver->init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
683 ip2_tty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 706 ip2_tty_driver->flags = TTY_DRIVER_REAL_RAW |
707 TTY_DRIVER_DYNAMIC_DEV;
684 tty_set_operations(ip2_tty_driver, &ip2_ops); 708 tty_set_operations(ip2_tty_driver, &ip2_ops);
685 709
686 ip2trace (ITRC_NO_PORT, ITRC_INIT, 3, 0 ); 710 ip2trace(ITRC_NO_PORT, ITRC_INIT, 3, 0);
687 711
688 /* Register the tty devices. */ 712 err = tty_register_driver(ip2_tty_driver);
689 if ( ( err = tty_register_driver ( ip2_tty_driver ) ) ) { 713 if (err) {
690 printk(KERN_ERR "IP2: failed to register tty driver (%d)\n", err); 714 printk(KERN_ERR "IP2: failed to register tty driver\n");
691 put_tty_driver(ip2_tty_driver); 715 put_tty_driver(ip2_tty_driver);
692 return -EINVAL; 716 return err; /* leaking resources */
693 } else 717 }
694 /* Register the IPL driver. */ 718
695 if ( ( err = register_chrdev ( IP2_IPL_MAJOR, pcIpl, &ip2_ipl ) ) ) { 719 err = register_chrdev(IP2_IPL_MAJOR, pcIpl, &ip2_ipl);
696 printk(KERN_ERR "IP2: failed to register IPL device (%d)\n", err ); 720 if (err) {
721 printk(KERN_ERR "IP2: failed to register IPL device (%d)\n",
722 err);
697 } else { 723 } else {
698 /* create the sysfs class */ 724 /* create the sysfs class */
699 ip2_class = class_create(THIS_MODULE, "ip2"); 725 ip2_class = class_create(THIS_MODULE, "ip2");
@@ -705,84 +731,86 @@ ip2_loadmain(int *iop, int *irqp)
705 /* Register the read_procmem thing */ 731 /* Register the read_procmem thing */
706 if (!proc_create("ip2mem",0,NULL,&ip2mem_proc_fops)) { 732 if (!proc_create("ip2mem",0,NULL,&ip2mem_proc_fops)) {
707 printk(KERN_ERR "IP2: failed to register read_procmem\n"); 733 printk(KERN_ERR "IP2: failed to register read_procmem\n");
708 } else { 734 return -EIO; /* leaking resources */
735 }
709 736
710 ip2trace (ITRC_NO_PORT, ITRC_INIT, 4, 0 ); 737 ip2trace(ITRC_NO_PORT, ITRC_INIT, 4, 0);
711 /* Register the interrupt handler or poll handler, depending upon the 738 /* Register the interrupt handler or poll handler, depending upon the
712 * specified interrupt. 739 * specified interrupt.
713 */ 740 */
714 741
715 for( i = 0; i < IP2_MAX_BOARDS; ++i ) { 742 for (i = 0; i < IP2_MAX_BOARDS; ++i) {
716 if ( 0 == ip2config.addr[i] ) { 743 if (ip2config.addr[i] == 0)
717 continue; 744 continue;
718 }
719 745
720 if ( NULL != ( pB = i2BoardPtrTable[i] ) ) { 746 pB = i2BoardPtrTable[i];
721 device_create_drvdata(ip2_class, NULL, 747 if (pB != NULL) {
722 MKDEV(IP2_IPL_MAJOR, 4 * i), 748 device_create(ip2_class, NULL,
723 NULL, "ipl%d", i); 749 MKDEV(IP2_IPL_MAJOR, 4 * i),
724 device_create_drvdata(ip2_class, NULL, 750 NULL, "ipl%d", i);
725 MKDEV(IP2_IPL_MAJOR, 4 * i + 1), 751 device_create(ip2_class, NULL,
726 NULL, "stat%d", i); 752 MKDEV(IP2_IPL_MAJOR, 4 * i + 1),
727 753 NULL, "stat%d", i);
728 for ( box = 0; box < ABS_MAX_BOXES; ++box ) 754
729 { 755 for (box = 0; box < ABS_MAX_BOXES; box++)
730 for ( j = 0; j < ABS_BIGGEST_BOX; ++j ) 756 for (j = 0; j < ABS_BIGGEST_BOX; j++)
731 { 757 if (pB->i2eChannelMap[box] & (1 << j))
732 if ( pB->i2eChannelMap[box] & (1 << j) ) 758 tty_register_device(
733 { 759 ip2_tty_driver,
734 tty_register_device(ip2_tty_driver, 760 j + ABS_BIGGEST_BOX *
735 j + ABS_BIGGEST_BOX * 761 (box+i*ABS_MAX_BOXES),
736 (box+i*ABS_MAX_BOXES), NULL); 762 NULL);
737 } 763 }
738 }
739 }
740 }
741 764
742 if (poll_only) { 765 if (poll_only) {
743// Poll only forces driver to only use polling and 766 /* Poll only forces driver to only use polling and
744// to ignore the probed PCI or EISA interrupts. 767 to ignore the probed PCI or EISA interrupts. */
745 ip2config.irq[i] = CIR_POLL; 768 ip2config.irq[i] = CIR_POLL;
746 } 769 }
747 if ( ip2config.irq[i] == CIR_POLL ) { 770 if (ip2config.irq[i] == CIR_POLL) {
748retry: 771retry:
749 if (!TimerOn) { 772 if (!timer_pending(&PollTimer)) {
750 PollTimer.expires = POLL_TIMEOUT; 773 mod_timer(&PollTimer, POLL_TIMEOUT);
751 add_timer ( &PollTimer ); 774 printk(KERN_INFO "IP2: polling\n");
752 TimerOn = 1;
753 printk( KERN_INFO "IP2: polling\n");
754 }
755 } else {
756 if (have_requested_irq(ip2config.irq[i]))
757 continue;
758 rc = request_irq( ip2config.irq[i], ip2_interrupt,
759 IP2_SA_FLAGS | (ip2config.type[i] == PCI ? IRQF_SHARED : 0),
760 pcName, i2BoardPtrTable[i]);
761 if (rc) {
762 printk(KERN_ERR "IP2: an request_irq failed: error %d\n",rc);
763 ip2config.irq[i] = CIR_POLL;
764 printk( KERN_INFO "IP2: Polling %ld/sec.\n",
765 (POLL_TIMEOUT - jiffies));
766 goto retry;
767 }
768 mark_requested_irq(ip2config.irq[i]);
769 /* Initialise the interrupt handler bottom half (aka slih). */
770 } 775 }
771 } 776 } else {
772 for( i = 0; i < IP2_MAX_BOARDS; ++i ) { 777 if (have_requested_irq(ip2config.irq[i]))
773 if ( i2BoardPtrTable[i] ) { 778 continue;
774 set_irq( i, ip2config.irq[i] ); /* set and enable board interrupt */ 779 rc = request_irq(ip2config.irq[i], ip2_interrupt,
780 IP2_SA_FLAGS |
781 (ip2config.type[i] == PCI ? IRQF_SHARED : 0),
782 pcName, i2BoardPtrTable[i]);
783 if (rc) {
784 printk(KERN_ERR "IP2: request_irq failed: "
785 "error %d\n", rc);
786 ip2config.irq[i] = CIR_POLL;
787 printk(KERN_INFO "IP2: Polling %ld/sec.\n",
788 (POLL_TIMEOUT - jiffies));
789 goto retry;
775 } 790 }
791 mark_requested_irq(ip2config.irq[i]);
792 /* Initialise the interrupt handler bottom half
793 * (aka slih). */
776 } 794 }
777 } 795 }
778 ip2trace (ITRC_NO_PORT, ITRC_INIT, ITRC_RETURN, 0 ); 796
779 goto out; 797 for (i = 0; i < IP2_MAX_BOARDS; ++i) {
798 if (i2BoardPtrTable[i]) {
799 /* set and enable board interrupt */
800 set_irq(i, ip2config.irq[i]);
801 }
802 }
803
804 ip2trace(ITRC_NO_PORT, ITRC_INIT, ITRC_RETURN, 0);
805
806 return 0;
780 807
781out_chrdev: 808out_chrdev:
782 unregister_chrdev(IP2_IPL_MAJOR, "ip2"); 809 unregister_chrdev(IP2_IPL_MAJOR, "ip2");
783out: 810 /* unregister and put tty here */
784 return err; 811 return err;
785} 812}
813module_init(ip2_loadmain);
786 814
787/******************************************************************************/ 815/******************************************************************************/
788/* Function: ip2_init_board() */ 816/* Function: ip2_init_board() */
@@ -1199,9 +1227,8 @@ ip2_polled_interrupt(void)
1199{ 1227{
1200 int i; 1228 int i;
1201 i2eBordStrPtr pB; 1229 i2eBordStrPtr pB;
1202 const int irq = 0;
1203 1230
1204 ip2trace (ITRC_NO_PORT, ITRC_INTR, 99, 1, irq ); 1231 ip2trace(ITRC_NO_PORT, ITRC_INTR, 99, 1, 0);
1205 1232
1206 /* Service just the boards on the list using this irq */ 1233 /* Service just the boards on the list using this irq */
1207 for( i = 0; i < i2nBoards; ++i ) { 1234 for( i = 0; i < i2nBoards; ++i ) {
@@ -1210,9 +1237,8 @@ ip2_polled_interrupt(void)
1210// Only process those boards which match our IRQ. 1237// Only process those boards which match our IRQ.
1211// IRQ = 0 for polled boards, we won't poll "IRQ" boards 1238// IRQ = 0 for polled boards, we won't poll "IRQ" boards
1212 1239
1213 if ( pB && (pB->i2eUsingIrq == irq) ) { 1240 if (pB && pB->i2eUsingIrq == 0)
1214 ip2_irq_work(pB); 1241 ip2_irq_work(pB);
1215 }
1216 } 1242 }
1217 1243
1218 ++irq_counter; 1244 ++irq_counter;
@@ -1250,16 +1276,12 @@ ip2_poll(unsigned long arg)
1250{ 1276{
1251 ip2trace (ITRC_NO_PORT, ITRC_INTR, 100, 0 ); 1277 ip2trace (ITRC_NO_PORT, ITRC_INTR, 100, 0 );
1252 1278
1253 TimerOn = 0; // it's the truth but not checked in service
1254
1255 // Just polled boards, IRQ = 0 will hit all non-interrupt boards. 1279 // Just polled boards, IRQ = 0 will hit all non-interrupt boards.
1256 // It will NOT poll boards handled by hard interrupts. 1280 // It will NOT poll boards handled by hard interrupts.
1257 // The issue of queued BH interrupts is handled in ip2_interrupt(). 1281 // The issue of queued BH interrupts is handled in ip2_interrupt().
1258 ip2_polled_interrupt(); 1282 ip2_polled_interrupt();
1259 1283
1260 PollTimer.expires = POLL_TIMEOUT; 1284 mod_timer(&PollTimer, POLL_TIMEOUT);
1261 add_timer( &PollTimer );
1262 TimerOn = 1;
1263 1285
1264 ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 ); 1286 ip2trace (ITRC_NO_PORT, ITRC_INTR, ITRC_RETURN, 0 );
1265} 1287}
@@ -2871,7 +2893,7 @@ ip2_ipl_ioctl (struct file *pFile, UINT cmd, ULONG arg )
2871 case 13: 2893 case 13:
2872 switch ( cmd ) { 2894 switch ( cmd ) {
2873 case 64: /* Driver - ip2stat */ 2895 case 64: /* Driver - ip2stat */
2874 rc = put_user(ip2_tty_driver->refcount, pIndex++ ); 2896 rc = put_user(-1, pIndex++ );
2875 rc = put_user(irq_counter, pIndex++ ); 2897 rc = put_user(irq_counter, pIndex++ );
2876 rc = put_user(bh_counter, pIndex++ ); 2898 rc = put_user(bh_counter, pIndex++ );
2877 break; 2899 break;
diff --git a/drivers/char/ipmi/ipmi_devintf.c b/drivers/char/ipmi/ipmi_devintf.c
index 64e1c169e826..835a33c8d5f5 100644
--- a/drivers/char/ipmi/ipmi_devintf.c
+++ b/drivers/char/ipmi/ipmi_devintf.c
@@ -871,7 +871,7 @@ static void ipmi_new_smi(int if_num, struct device *device)
871 entry->dev = dev; 871 entry->dev = dev;
872 872
873 mutex_lock(&reg_list_mutex); 873 mutex_lock(&reg_list_mutex);
874 device_create_drvdata(ipmi_class, device, dev, NULL, "ipmi%d", if_num); 874 device_create(ipmi_class, device, dev, NULL, "ipmi%d", if_num);
875 list_add(&entry->link, &reg_list); 875 list_add(&entry->link, &reg_list);
876 mutex_unlock(&reg_list_mutex); 876 mutex_unlock(&reg_list_mutex);
877} 877}
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 8e8afb6141f9..3123bf57ad91 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -2695,7 +2695,7 @@ static __devinit void default_find_bmc(void)
2695 for (i = 0; ; i++) { 2695 for (i = 0; ; i++) {
2696 if (!ipmi_defaults[i].port) 2696 if (!ipmi_defaults[i].port)
2697 break; 2697 break;
2698#ifdef CONFIG_PPC_MERGE 2698#ifdef CONFIG_PPC
2699 if (check_legacy_ioport(ipmi_defaults[i].port)) 2699 if (check_legacy_ioport(ipmi_defaults[i].port))
2700 continue; 2700 continue;
2701#endif 2701#endif
diff --git a/drivers/char/isicom.c b/drivers/char/isicom.c
index 8f7cc190b62d..7d30ee1d3fca 100644
--- a/drivers/char/isicom.c
+++ b/drivers/char/isicom.c
@@ -421,17 +421,16 @@ static void isicom_tx(unsigned long _data)
421 if (retries >= 100) 421 if (retries >= 100)
422 goto unlock; 422 goto unlock;
423 423
424 tty = tty_port_tty_get(&port->port);
425 if (tty == NULL)
426 goto put_unlock;
427
424 for (; count > 0; count--, port++) { 428 for (; count > 0; count--, port++) {
425 /* port not active or tx disabled to force flow control */ 429 /* port not active or tx disabled to force flow control */
426 if (!(port->port.flags & ASYNC_INITIALIZED) || 430 if (!(port->port.flags & ASYNC_INITIALIZED) ||
427 !(port->status & ISI_TXOK)) 431 !(port->status & ISI_TXOK))
428 continue; 432 continue;
429 433
430 tty = port->port.tty;
431
432 if (tty == NULL)
433 continue;
434
435 txcount = min_t(short, TX_SIZE, port->xmit_cnt); 434 txcount = min_t(short, TX_SIZE, port->xmit_cnt);
436 if (txcount <= 0 || tty->stopped || tty->hw_stopped) 435 if (txcount <= 0 || tty->stopped || tty->hw_stopped)
437 continue; 436 continue;
@@ -489,6 +488,8 @@ static void isicom_tx(unsigned long _data)
489 tty_wakeup(tty); 488 tty_wakeup(tty);
490 } 489 }
491 490
491put_unlock:
492 tty_kref_put(tty);
492unlock: 493unlock:
493 spin_unlock_irqrestore(&isi_card[card].card_lock, flags); 494 spin_unlock_irqrestore(&isi_card[card].card_lock, flags);
494 /* schedule another tx for hopefully in about 10ms */ 495 /* schedule another tx for hopefully in about 10ms */
@@ -547,7 +548,7 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
547 return IRQ_HANDLED; 548 return IRQ_HANDLED;
548 } 549 }
549 550
550 tty = port->port.tty; 551 tty = tty_port_tty_get(&port->port);
551 if (tty == NULL) { 552 if (tty == NULL) {
552 word_count = byte_count >> 1; 553 word_count = byte_count >> 1;
553 while (byte_count > 1) { 554 while (byte_count > 1) {
@@ -588,7 +589,7 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
588 } 589 }
589 590
590 if (port->port.flags & ASYNC_CTS_FLOW) { 591 if (port->port.flags & ASYNC_CTS_FLOW) {
591 if (port->port.tty->hw_stopped) { 592 if (tty->hw_stopped) {
592 if (header & ISI_CTS) { 593 if (header & ISI_CTS) {
593 port->port.tty->hw_stopped = 0; 594 port->port.tty->hw_stopped = 0;
594 /* start tx ing */ 595 /* start tx ing */
@@ -597,7 +598,7 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
597 tty_wakeup(tty); 598 tty_wakeup(tty);
598 } 599 }
599 } else if (!(header & ISI_CTS)) { 600 } else if (!(header & ISI_CTS)) {
600 port->port.tty->hw_stopped = 1; 601 tty->hw_stopped = 1;
601 /* stop tx ing */ 602 /* stop tx ing */
602 port->status &= ~(ISI_TXOK | ISI_CTS); 603 port->status &= ~(ISI_TXOK | ISI_CTS);
603 } 604 }
@@ -660,24 +661,21 @@ static irqreturn_t isicom_interrupt(int irq, void *dev_id)
660 } 661 }
661 outw(0x0000, base+0x04); /* enable interrupts */ 662 outw(0x0000, base+0x04); /* enable interrupts */
662 spin_unlock(&card->card_lock); 663 spin_unlock(&card->card_lock);
664 tty_kref_put(tty);
663 665
664 return IRQ_HANDLED; 666 return IRQ_HANDLED;
665} 667}
666 668
667static void isicom_config_port(struct isi_port *port) 669static void isicom_config_port(struct tty_struct *tty)
668{ 670{
671 struct isi_port *port = tty->driver_data;
669 struct isi_board *card = port->card; 672 struct isi_board *card = port->card;
670 struct tty_struct *tty;
671 unsigned long baud; 673 unsigned long baud;
672 unsigned long base = card->base; 674 unsigned long base = card->base;
673 u16 channel_setup, channel = port->channel, 675 u16 channel_setup, channel = port->channel,
674 shift_count = card->shift_count; 676 shift_count = card->shift_count;
675 unsigned char flow_ctrl; 677 unsigned char flow_ctrl;
676 678
677 tty = port->port.tty;
678
679 if (tty == NULL)
680 return;
681 /* FIXME: Switch to new tty baud API */ 679 /* FIXME: Switch to new tty baud API */
682 baud = C_BAUD(tty); 680 baud = C_BAUD(tty);
683 if (baud & CBAUDEX) { 681 if (baud & CBAUDEX) {
@@ -690,7 +688,7 @@ static void isicom_config_port(struct isi_port *port)
690 688
691 /* 1,2,3,4 => 57.6, 115.2, 230, 460 kbps resp. */ 689 /* 1,2,3,4 => 57.6, 115.2, 230, 460 kbps resp. */
692 if (baud < 1 || baud > 4) 690 if (baud < 1 || baud > 4)
693 port->port.tty->termios->c_cflag &= ~CBAUDEX; 691 tty->termios->c_cflag &= ~CBAUDEX;
694 else 692 else
695 baud += 15; 693 baud += 15;
696 } 694 }
@@ -797,8 +795,9 @@ static inline void isicom_setup_board(struct isi_board *bp)
797 spin_unlock_irqrestore(&bp->card_lock, flags); 795 spin_unlock_irqrestore(&bp->card_lock, flags);
798} 796}
799 797
800static int isicom_setup_port(struct isi_port *port) 798static int isicom_setup_port(struct tty_struct *tty)
801{ 799{
800 struct isi_port *port = tty->driver_data;
802 struct isi_board *card = port->card; 801 struct isi_board *card = port->card;
803 unsigned long flags; 802 unsigned long flags;
804 803
@@ -808,8 +807,7 @@ static int isicom_setup_port(struct isi_port *port)
808 return -ENOMEM; 807 return -ENOMEM;
809 808
810 spin_lock_irqsave(&card->card_lock, flags); 809 spin_lock_irqsave(&card->card_lock, flags);
811 if (port->port.tty) 810 clear_bit(TTY_IO_ERROR, &tty->flags);
812 clear_bit(TTY_IO_ERROR, &port->port.tty->flags);
813 if (port->port.count == 1) 811 if (port->port.count == 1)
814 card->count++; 812 card->count++;
815 813
@@ -823,7 +821,7 @@ static int isicom_setup_port(struct isi_port *port)
823 InterruptTheCard(card->base); 821 InterruptTheCard(card->base);
824 } 822 }
825 823
826 isicom_config_port(port); 824 isicom_config_port(tty);
827 port->port.flags |= ASYNC_INITIALIZED; 825 port->port.flags |= ASYNC_INITIALIZED;
828 spin_unlock_irqrestore(&card->card_lock, flags); 826 spin_unlock_irqrestore(&card->card_lock, flags);
829 827
@@ -934,8 +932,8 @@ static int isicom_open(struct tty_struct *tty, struct file *filp)
934 932
935 port->port.count++; 933 port->port.count++;
936 tty->driver_data = port; 934 tty->driver_data = port;
937 port->port.tty = tty; 935 tty_port_tty_set(&port->port, tty);
938 error = isicom_setup_port(port); 936 error = isicom_setup_port(tty);
939 if (error == 0) 937 if (error == 0)
940 error = block_til_ready(tty, filp, port); 938 error = block_til_ready(tty, filp, port);
941 return error; 939 return error;
@@ -955,15 +953,17 @@ static void isicom_shutdown_port(struct isi_port *port)
955 struct isi_board *card = port->card; 953 struct isi_board *card = port->card;
956 struct tty_struct *tty; 954 struct tty_struct *tty;
957 955
958 tty = port->port.tty; 956 tty = tty_port_tty_get(&port->port);
959 957
960 if (!(port->port.flags & ASYNC_INITIALIZED)) 958 if (!(port->port.flags & ASYNC_INITIALIZED)) {
959 tty_kref_put(tty);
961 return; 960 return;
961 }
962 962
963 tty_port_free_xmit_buf(&port->port); 963 tty_port_free_xmit_buf(&port->port);
964 port->port.flags &= ~ASYNC_INITIALIZED; 964 port->port.flags &= ~ASYNC_INITIALIZED;
965 /* 3rd October 2000 : Vinayak P Risbud */ 965 /* 3rd October 2000 : Vinayak P Risbud */
966 port->port.tty = NULL; 966 tty_port_tty_set(&port->port, NULL);
967 967
968 /*Fix done by Anil .S on 30-04-2001 968 /*Fix done by Anil .S on 30-04-2001
969 remote login through isi port has dtr toggle problem 969 remote login through isi port has dtr toggle problem
@@ -1243,9 +1243,10 @@ static int isicom_tiocmset(struct tty_struct *tty, struct file *file,
1243 return 0; 1243 return 0;
1244} 1244}
1245 1245
1246static int isicom_set_serial_info(struct isi_port *port, 1246static int isicom_set_serial_info(struct tty_struct *tty,
1247 struct serial_struct __user *info) 1247 struct serial_struct __user *info)
1248{ 1248{
1249 struct isi_port *port = tty->driver_data;
1249 struct serial_struct newinfo; 1250 struct serial_struct newinfo;
1250 int reconfig_port; 1251 int reconfig_port;
1251 1252
@@ -1276,7 +1277,7 @@ static int isicom_set_serial_info(struct isi_port *port,
1276 if (reconfig_port) { 1277 if (reconfig_port) {
1277 unsigned long flags; 1278 unsigned long flags;
1278 spin_lock_irqsave(&port->card->card_lock, flags); 1279 spin_lock_irqsave(&port->card->card_lock, flags);
1279 isicom_config_port(port); 1280 isicom_config_port(tty);
1280 spin_unlock_irqrestore(&port->card->card_lock, flags); 1281 spin_unlock_irqrestore(&port->card->card_lock, flags);
1281 } 1282 }
1282 unlock_kernel(); 1283 unlock_kernel();
@@ -1318,7 +1319,7 @@ static int isicom_ioctl(struct tty_struct *tty, struct file *filp,
1318 return isicom_get_serial_info(port, argp); 1319 return isicom_get_serial_info(port, argp);
1319 1320
1320 case TIOCSSERIAL: 1321 case TIOCSSERIAL:
1321 return isicom_set_serial_info(port, argp); 1322 return isicom_set_serial_info(tty, argp);
1322 1323
1323 default: 1324 default:
1324 return -ENOIOCTLCMD; 1325 return -ENOIOCTLCMD;
@@ -1341,7 +1342,7 @@ static void isicom_set_termios(struct tty_struct *tty,
1341 return; 1342 return;
1342 1343
1343 spin_lock_irqsave(&port->card->card_lock, flags); 1344 spin_lock_irqsave(&port->card->card_lock, flags);
1344 isicom_config_port(port); 1345 isicom_config_port(tty);
1345 spin_unlock_irqrestore(&port->card->card_lock, flags); 1346 spin_unlock_irqrestore(&port->card->card_lock, flags);
1346 1347
1347 if ((old_termios->c_cflag & CRTSCTS) && 1348 if ((old_termios->c_cflag & CRTSCTS) &&
@@ -1419,7 +1420,7 @@ static void isicom_hangup(struct tty_struct *tty)
1419 1420
1420 port->port.count = 0; 1421 port->port.count = 0;
1421 port->port.flags &= ~ASYNC_NORMAL_ACTIVE; 1422 port->port.flags &= ~ASYNC_NORMAL_ACTIVE;
1422 port->port.tty = NULL; 1423 tty_port_tty_set(&port->port, NULL);
1423 wake_up_interruptible(&port->port.open_wait); 1424 wake_up_interruptible(&port->port.open_wait);
1424} 1425}
1425 1426
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index 843a2afaf204..44e5d60f517e 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -623,24 +623,25 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
623static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp); 623static void stli_brdpoll(struct stlibrd *brdp, cdkhdr_t __iomem *hdrp);
624static void stli_poll(unsigned long arg); 624static void stli_poll(unsigned long arg);
625static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp); 625static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp);
626static int stli_initopen(struct stlibrd *brdp, struct stliport *portp); 626static int stli_initopen(struct tty_struct *tty, struct stlibrd *brdp, struct stliport *portp);
627static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait); 627static int stli_rawopen(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
628static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait); 628static int stli_rawclose(struct stlibrd *brdp, struct stliport *portp, unsigned long arg, int wait);
629static int stli_waitcarrier(struct stlibrd *brdp, struct stliport *portp, struct file *filp); 629static int stli_waitcarrier(struct tty_struct *tty, struct stlibrd *brdp,
630static int stli_setport(struct stliport *portp); 630 struct stliport *portp, struct file *filp);
631static int stli_setport(struct tty_struct *tty);
631static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback); 632static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
632static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback); 633static void stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
633static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback); 634static void __stli_sendcmd(struct stlibrd *brdp, struct stliport *portp, unsigned long cmd, void *arg, int size, int copyback);
634static void stli_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp); 635static void stli_dodelaycmd(struct stliport *portp, cdkctrl_t __iomem *cp);
635static void stli_mkasyport(struct stliport *portp, asyport_t *pp, struct ktermios *tiosp); 636static void stli_mkasyport(struct tty_struct *tty, struct stliport *portp, asyport_t *pp, struct ktermios *tiosp);
636static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts); 637static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
637static long stli_mktiocm(unsigned long sigvalue); 638static long stli_mktiocm(unsigned long sigvalue);
638static void stli_read(struct stlibrd *brdp, struct stliport *portp); 639static void stli_read(struct stlibrd *brdp, struct stliport *portp);
639static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp); 640static int stli_getserial(struct stliport *portp, struct serial_struct __user *sp);
640static int stli_setserial(struct stliport *portp, struct serial_struct __user *sp); 641static int stli_setserial(struct tty_struct *tty, struct serial_struct __user *sp);
641static int stli_getbrdstats(combrd_t __user *bp); 642static int stli_getbrdstats(combrd_t __user *bp);
642static int stli_getportstats(struct stliport *portp, comstats_t __user *cp); 643static int stli_getportstats(struct tty_struct *tty, struct stliport *portp, comstats_t __user *cp);
643static int stli_portcmdstats(struct stliport *portp); 644static int stli_portcmdstats(struct tty_struct *tty, struct stliport *portp);
644static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp); 645static int stli_clrportstats(struct stliport *portp, comstats_t __user *cp);
645static int stli_getportstruct(struct stliport __user *arg); 646static int stli_getportstruct(struct stliport __user *arg);
646static int stli_getbrdstruct(struct stlibrd __user *arg); 647static int stli_getbrdstruct(struct stlibrd __user *arg);
@@ -731,12 +732,16 @@ static void stli_cleanup_ports(struct stlibrd *brdp)
731{ 732{
732 struct stliport *portp; 733 struct stliport *portp;
733 unsigned int j; 734 unsigned int j;
735 struct tty_struct *tty;
734 736
735 for (j = 0; j < STL_MAXPORTS; j++) { 737 for (j = 0; j < STL_MAXPORTS; j++) {
736 portp = brdp->ports[j]; 738 portp = brdp->ports[j];
737 if (portp != NULL) { 739 if (portp != NULL) {
738 if (portp->port.tty != NULL) 740 tty = tty_port_tty_get(&portp->port);
739 tty_hangup(portp->port.tty); 741 if (tty != NULL) {
742 tty_hangup(tty);
743 tty_kref_put(tty);
744 }
740 kfree(portp); 745 kfree(portp);
741 } 746 }
742 } 747 }
@@ -824,7 +829,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
824 * requires several commands to the board we will need to wait for any 829 * requires several commands to the board we will need to wait for any
825 * other open that is already initializing the port. 830 * other open that is already initializing the port.
826 */ 831 */
827 portp->port.tty = tty; 832 tty_port_tty_set(&portp->port, tty);
828 tty->driver_data = portp; 833 tty->driver_data = portp;
829 portp->port.count++; 834 portp->port.count++;
830 835
@@ -835,7 +840,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
835 840
836 if ((portp->port.flags & ASYNC_INITIALIZED) == 0) { 841 if ((portp->port.flags & ASYNC_INITIALIZED) == 0) {
837 set_bit(ST_INITIALIZING, &portp->state); 842 set_bit(ST_INITIALIZING, &portp->state);
838 if ((rc = stli_initopen(brdp, portp)) >= 0) { 843 if ((rc = stli_initopen(tty, brdp, portp)) >= 0) {
839 portp->port.flags |= ASYNC_INITIALIZED; 844 portp->port.flags |= ASYNC_INITIALIZED;
840 clear_bit(TTY_IO_ERROR, &tty->flags); 845 clear_bit(TTY_IO_ERROR, &tty->flags);
841 } 846 }
@@ -864,7 +869,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
864 * then also we might have to wait for carrier. 869 * then also we might have to wait for carrier.
865 */ 870 */
866 if (!(filp->f_flags & O_NONBLOCK)) { 871 if (!(filp->f_flags & O_NONBLOCK)) {
867 if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0) 872 if ((rc = stli_waitcarrier(tty, brdp, portp, filp)) != 0)
868 return rc; 873 return rc;
869 } 874 }
870 portp->port.flags |= ASYNC_NORMAL_ACTIVE; 875 portp->port.flags |= ASYNC_NORMAL_ACTIVE;
@@ -930,7 +935,7 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
930 stli_flushbuffer(tty); 935 stli_flushbuffer(tty);
931 936
932 tty->closing = 0; 937 tty->closing = 0;
933 portp->port.tty = NULL; 938 tty_port_tty_set(&portp->port, NULL);
934 939
935 if (portp->openwaitcnt) { 940 if (portp->openwaitcnt) {
936 if (portp->close_delay) 941 if (portp->close_delay)
@@ -952,9 +957,9 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
952 * this still all happens pretty quickly. 957 * this still all happens pretty quickly.
953 */ 958 */
954 959
955static int stli_initopen(struct stlibrd *brdp, struct stliport *portp) 960static int stli_initopen(struct tty_struct *tty,
961 struct stlibrd *brdp, struct stliport *portp)
956{ 962{
957 struct tty_struct *tty;
958 asynotify_t nt; 963 asynotify_t nt;
959 asyport_t aport; 964 asyport_t aport;
960 int rc; 965 int rc;
@@ -969,10 +974,7 @@ static int stli_initopen(struct stlibrd *brdp, struct stliport *portp)
969 sizeof(asynotify_t), 0)) < 0) 974 sizeof(asynotify_t), 0)) < 0)
970 return rc; 975 return rc;
971 976
972 tty = portp->port.tty; 977 stli_mkasyport(tty, portp, &aport, tty->termios);
973 if (tty == NULL)
974 return -ENODEV;
975 stli_mkasyport(portp, &aport, tty->termios);
976 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport, 978 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
977 sizeof(asyport_t), 0)) < 0) 979 sizeof(asyport_t), 0)) < 0)
978 return rc; 980 return rc;
@@ -1161,22 +1163,21 @@ static int stli_cmdwait(struct stlibrd *brdp, struct stliport *portp, unsigned l
1161 * waiting for the command to complete - so must have user context. 1163 * waiting for the command to complete - so must have user context.
1162 */ 1164 */
1163 1165
1164static int stli_setport(struct stliport *portp) 1166static int stli_setport(struct tty_struct *tty)
1165{ 1167{
1168 struct stliport *portp = tty->driver_data;
1166 struct stlibrd *brdp; 1169 struct stlibrd *brdp;
1167 asyport_t aport; 1170 asyport_t aport;
1168 1171
1169 if (portp == NULL) 1172 if (portp == NULL)
1170 return -ENODEV; 1173 return -ENODEV;
1171 if (portp->port.tty == NULL)
1172 return -ENODEV;
1173 if (portp->brdnr >= stli_nrbrds) 1174 if (portp->brdnr >= stli_nrbrds)
1174 return -ENODEV; 1175 return -ENODEV;
1175 brdp = stli_brds[portp->brdnr]; 1176 brdp = stli_brds[portp->brdnr];
1176 if (brdp == NULL) 1177 if (brdp == NULL)
1177 return -ENODEV; 1178 return -ENODEV;
1178 1179
1179 stli_mkasyport(portp, &aport, portp->port.tty->termios); 1180 stli_mkasyport(tty, portp, &aport, tty->termios);
1180 return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0)); 1181 return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
1181} 1182}
1182 1183
@@ -1187,7 +1188,8 @@ static int stli_setport(struct stliport *portp)
1187 * maybe because if we are clocal then we don't need to wait... 1188 * maybe because if we are clocal then we don't need to wait...
1188 */ 1189 */
1189 1190
1190static int stli_waitcarrier(struct stlibrd *brdp, struct stliport *portp, struct file *filp) 1191static int stli_waitcarrier(struct tty_struct *tty, struct stlibrd *brdp,
1192 struct stliport *portp, struct file *filp)
1191{ 1193{
1192 unsigned long flags; 1194 unsigned long flags;
1193 int rc, doclocal; 1195 int rc, doclocal;
@@ -1195,7 +1197,7 @@ static int stli_waitcarrier(struct stlibrd *brdp, struct stliport *portp, struct
1195 rc = 0; 1197 rc = 0;
1196 doclocal = 0; 1198 doclocal = 0;
1197 1199
1198 if (portp->port.tty->termios->c_cflag & CLOCAL) 1200 if (tty->termios->c_cflag & CLOCAL)
1199 doclocal++; 1201 doclocal++;
1200 1202
1201 spin_lock_irqsave(&stli_lock, flags); 1203 spin_lock_irqsave(&stli_lock, flags);
@@ -1373,8 +1375,6 @@ static void stli_flushchars(struct tty_struct *tty)
1373 stli_txcookrealsize = 0; 1375 stli_txcookrealsize = 0;
1374 stli_txcooktty = NULL; 1376 stli_txcooktty = NULL;
1375 1377
1376 if (tty == NULL)
1377 return;
1378 if (cooktty == NULL) 1378 if (cooktty == NULL)
1379 return; 1379 return;
1380 if (tty != cooktty) 1380 if (tty != cooktty)
@@ -1572,10 +1572,11 @@ static int stli_getserial(struct stliport *portp, struct serial_struct __user *s
1572 * just quietly ignore any requests to change irq, etc. 1572 * just quietly ignore any requests to change irq, etc.
1573 */ 1573 */
1574 1574
1575static int stli_setserial(struct stliport *portp, struct serial_struct __user *sp) 1575static int stli_setserial(struct tty_struct *tty, struct serial_struct __user *sp)
1576{ 1576{
1577 struct serial_struct sio; 1577 struct serial_struct sio;
1578 int rc; 1578 int rc;
1579 struct stliport *portp = tty->driver_data;
1579 1580
1580 if (copy_from_user(&sio, sp, sizeof(struct serial_struct))) 1581 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1581 return -EFAULT; 1582 return -EFAULT;
@@ -1594,7 +1595,7 @@ static int stli_setserial(struct stliport *portp, struct serial_struct __user *s
1594 portp->closing_wait = sio.closing_wait; 1595 portp->closing_wait = sio.closing_wait;
1595 portp->custom_divisor = sio.custom_divisor; 1596 portp->custom_divisor = sio.custom_divisor;
1596 1597
1597 if ((rc = stli_setport(portp)) < 0) 1598 if ((rc = stli_setport(tty)) < 0)
1598 return rc; 1599 return rc;
1599 return 0; 1600 return 0;
1600} 1601}
@@ -1685,17 +1686,17 @@ static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm
1685 rc = stli_getserial(portp, argp); 1686 rc = stli_getserial(portp, argp);
1686 break; 1687 break;
1687 case TIOCSSERIAL: 1688 case TIOCSSERIAL:
1688 rc = stli_setserial(portp, argp); 1689 rc = stli_setserial(tty, argp);
1689 break; 1690 break;
1690 case STL_GETPFLAG: 1691 case STL_GETPFLAG:
1691 rc = put_user(portp->pflag, (unsigned __user *)argp); 1692 rc = put_user(portp->pflag, (unsigned __user *)argp);
1692 break; 1693 break;
1693 case STL_SETPFLAG: 1694 case STL_SETPFLAG:
1694 if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0) 1695 if ((rc = get_user(portp->pflag, (unsigned __user *)argp)) == 0)
1695 stli_setport(portp); 1696 stli_setport(tty);
1696 break; 1697 break;
1697 case COM_GETPORTSTATS: 1698 case COM_GETPORTSTATS:
1698 rc = stli_getportstats(portp, argp); 1699 rc = stli_getportstats(tty, portp, argp);
1699 break; 1700 break;
1700 case COM_CLRPORTSTATS: 1701 case COM_CLRPORTSTATS:
1701 rc = stli_clrportstats(portp, argp); 1702 rc = stli_clrportstats(portp, argp);
@@ -1729,8 +1730,6 @@ static void stli_settermios(struct tty_struct *tty, struct ktermios *old)
1729 struct ktermios *tiosp; 1730 struct ktermios *tiosp;
1730 asyport_t aport; 1731 asyport_t aport;
1731 1732
1732 if (tty == NULL)
1733 return;
1734 portp = tty->driver_data; 1733 portp = tty->driver_data;
1735 if (portp == NULL) 1734 if (portp == NULL)
1736 return; 1735 return;
@@ -1742,7 +1741,7 @@ static void stli_settermios(struct tty_struct *tty, struct ktermios *old)
1742 1741
1743 tiosp = tty->termios; 1742 tiosp = tty->termios;
1744 1743
1745 stli_mkasyport(portp, &aport, tiosp); 1744 stli_mkasyport(tty, portp, &aport, tiosp);
1746 stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0); 1745 stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0);
1747 stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1); 1746 stli_mkasysigs(&portp->asig, ((tiosp->c_cflag & CBAUD) ? 1 : 0), -1);
1748 stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, 1747 stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
@@ -1854,7 +1853,7 @@ static void stli_hangup(struct tty_struct *tty)
1854 clear_bit(ST_TXBUSY, &portp->state); 1853 clear_bit(ST_TXBUSY, &portp->state);
1855 clear_bit(ST_RXSTOP, &portp->state); 1854 clear_bit(ST_RXSTOP, &portp->state);
1856 set_bit(TTY_IO_ERROR, &tty->flags); 1855 set_bit(TTY_IO_ERROR, &tty->flags);
1857 portp->port.tty = NULL; 1856 tty_port_tty_set(&portp->port, NULL);
1858 portp->port.flags &= ~ASYNC_NORMAL_ACTIVE; 1857 portp->port.flags &= ~ASYNC_NORMAL_ACTIVE;
1859 portp->port.count = 0; 1858 portp->port.count = 0;
1860 spin_unlock_irqrestore(&stli_lock, flags); 1859 spin_unlock_irqrestore(&stli_lock, flags);
@@ -1935,8 +1934,6 @@ static void stli_waituntilsent(struct tty_struct *tty, int timeout)
1935 struct stliport *portp; 1934 struct stliport *portp;
1936 unsigned long tend; 1935 unsigned long tend;
1937 1936
1938 if (tty == NULL)
1939 return;
1940 portp = tty->driver_data; 1937 portp = tty->driver_data;
1941 if (portp == NULL) 1938 if (portp == NULL)
1942 return; 1939 return;
@@ -1998,7 +1995,7 @@ static int stli_portinfo(struct stlibrd *brdp, struct stliport *portp, int portn
1998 char *sp, *uart; 1995 char *sp, *uart;
1999 int rc, cnt; 1996 int rc, cnt;
2000 1997
2001 rc = stli_portcmdstats(portp); 1998 rc = stli_portcmdstats(NULL, portp);
2002 1999
2003 uart = "UNKNOWN"; 2000 uart = "UNKNOWN";
2004 if (brdp->state & BST_STARTED) { 2001 if (brdp->state & BST_STARTED) {
@@ -2188,7 +2185,7 @@ static void stli_read(struct stlibrd *brdp, struct stliport *portp)
2188 2185
2189 if (test_bit(ST_RXSTOP, &portp->state)) 2186 if (test_bit(ST_RXSTOP, &portp->state))
2190 return; 2187 return;
2191 tty = portp->port.tty; 2188 tty = tty_port_tty_get(&portp->port);
2192 if (tty == NULL) 2189 if (tty == NULL)
2193 return; 2190 return;
2194 2191
@@ -2230,6 +2227,7 @@ static void stli_read(struct stlibrd *brdp, struct stliport *portp)
2230 set_bit(ST_RXING, &portp->state); 2227 set_bit(ST_RXING, &portp->state);
2231 2228
2232 tty_schedule_flip(tty); 2229 tty_schedule_flip(tty);
2230 tty_kref_put(tty);
2233} 2231}
2234 2232
2235/*****************************************************************************/ 2233/*****************************************************************************/
@@ -2362,7 +2360,7 @@ static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp)
2362 if (ap->notify) { 2360 if (ap->notify) {
2363 nt = ap->changed; 2361 nt = ap->changed;
2364 ap->notify = 0; 2362 ap->notify = 0;
2365 tty = portp->port.tty; 2363 tty = tty_port_tty_get(&portp->port);
2366 2364
2367 if (nt.signal & SG_DCD) { 2365 if (nt.signal & SG_DCD) {
2368 oldsigs = portp->sigs; 2366 oldsigs = portp->sigs;
@@ -2399,6 +2397,7 @@ static int stli_hostcmd(struct stlibrd *brdp, struct stliport *portp)
2399 tty_schedule_flip(tty); 2397 tty_schedule_flip(tty);
2400 } 2398 }
2401 } 2399 }
2400 tty_kref_put(tty);
2402 2401
2403 if (nt.data & DT_RXBUSY) { 2402 if (nt.data & DT_RXBUSY) {
2404 donerx++; 2403 donerx++;
@@ -2535,14 +2534,15 @@ static void stli_poll(unsigned long arg)
2535 * the slave. 2534 * the slave.
2536 */ 2535 */
2537 2536
2538static void stli_mkasyport(struct stliport *portp, asyport_t *pp, struct ktermios *tiosp) 2537static void stli_mkasyport(struct tty_struct *tty, struct stliport *portp,
2538 asyport_t *pp, struct ktermios *tiosp)
2539{ 2539{
2540 memset(pp, 0, sizeof(asyport_t)); 2540 memset(pp, 0, sizeof(asyport_t));
2541 2541
2542/* 2542/*
2543 * Start of by setting the baud, char size, parity and stop bit info. 2543 * Start of by setting the baud, char size, parity and stop bit info.
2544 */ 2544 */
2545 pp->baudout = tty_get_baud_rate(portp->port.tty); 2545 pp->baudout = tty_get_baud_rate(tty);
2546 if ((tiosp->c_cflag & CBAUD) == B38400) { 2546 if ((tiosp->c_cflag & CBAUD) == B38400) {
2547 if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI) 2547 if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2548 pp->baudout = 57600; 2548 pp->baudout = 57600;
@@ -2695,7 +2695,7 @@ static int stli_initports(struct stlibrd *brdp)
2695 printk("STALLION: failed to allocate port structure\n"); 2695 printk("STALLION: failed to allocate port structure\n");
2696 continue; 2696 continue;
2697 } 2697 }
2698 2698 tty_port_init(&portp->port);
2699 portp->magic = STLI_PORTMAGIC; 2699 portp->magic = STLI_PORTMAGIC;
2700 portp->portnr = i; 2700 portp->portnr = i;
2701 portp->brdnr = brdp->brdnr; 2701 portp->brdnr = brdp->brdnr;
@@ -4220,7 +4220,7 @@ static struct stliport *stli_getport(unsigned int brdnr, unsigned int panelnr,
4220 * what port to get stats for (used through board control device). 4220 * what port to get stats for (used through board control device).
4221 */ 4221 */
4222 4222
4223static int stli_portcmdstats(struct stliport *portp) 4223static int stli_portcmdstats(struct tty_struct *tty, struct stliport *portp)
4224{ 4224{
4225 unsigned long flags; 4225 unsigned long flags;
4226 struct stlibrd *brdp; 4226 struct stlibrd *brdp;
@@ -4249,15 +4249,15 @@ static int stli_portcmdstats(struct stliport *portp)
4249 stli_comstats.flags = portp->port.flags; 4249 stli_comstats.flags = portp->port.flags;
4250 4250
4251 spin_lock_irqsave(&brd_lock, flags); 4251 spin_lock_irqsave(&brd_lock, flags);
4252 if (portp->port.tty != NULL) { 4252 if (tty != NULL) {
4253 if (portp->port.tty->driver_data == portp) { 4253 if (portp->port.tty == tty) {
4254 stli_comstats.ttystate = portp->port.tty->flags; 4254 stli_comstats.ttystate = tty->flags;
4255 stli_comstats.rxbuffered = -1; 4255 stli_comstats.rxbuffered = -1;
4256 if (portp->port.tty->termios != NULL) { 4256 if (tty->termios != NULL) {
4257 stli_comstats.cflags = portp->port.tty->termios->c_cflag; 4257 stli_comstats.cflags = tty->termios->c_cflag;
4258 stli_comstats.iflags = portp->port.tty->termios->c_iflag; 4258 stli_comstats.iflags = tty->termios->c_iflag;
4259 stli_comstats.oflags = portp->port.tty->termios->c_oflag; 4259 stli_comstats.oflags = tty->termios->c_oflag;
4260 stli_comstats.lflags = portp->port.tty->termios->c_lflag; 4260 stli_comstats.lflags = tty->termios->c_lflag;
4261 } 4261 }
4262 } 4262 }
4263 } 4263 }
@@ -4294,7 +4294,8 @@ static int stli_portcmdstats(struct stliport *portp)
4294 * what port to get stats for (used through board control device). 4294 * what port to get stats for (used through board control device).
4295 */ 4295 */
4296 4296
4297static int stli_getportstats(struct stliport *portp, comstats_t __user *cp) 4297static int stli_getportstats(struct tty_struct *tty, struct stliport *portp,
4298 comstats_t __user *cp)
4298{ 4299{
4299 struct stlibrd *brdp; 4300 struct stlibrd *brdp;
4300 int rc; 4301 int rc;
@@ -4312,7 +4313,7 @@ static int stli_getportstats(struct stliport *portp, comstats_t __user *cp)
4312 if (!brdp) 4313 if (!brdp)
4313 return -ENODEV; 4314 return -ENODEV;
4314 4315
4315 if ((rc = stli_portcmdstats(portp)) < 0) 4316 if ((rc = stli_portcmdstats(tty, portp)) < 0)
4316 return rc; 4317 return rc;
4317 4318
4318 return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ? 4319 return copy_to_user(cp, &stli_comstats, sizeof(comstats_t)) ?
@@ -4427,7 +4428,7 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
4427 4428
4428 switch (cmd) { 4429 switch (cmd) {
4429 case COM_GETPORTSTATS: 4430 case COM_GETPORTSTATS:
4430 rc = stli_getportstats(NULL, argp); 4431 rc = stli_getportstats(NULL, NULL, argp);
4431 done++; 4432 done++;
4432 break; 4433 break;
4433 case COM_CLRPORTSTATS: 4434 case COM_CLRPORTSTATS:
@@ -4599,9 +4600,8 @@ static int __init istallion_module_init(void)
4599 4600
4600 istallion_class = class_create(THIS_MODULE, "staliomem"); 4601 istallion_class = class_create(THIS_MODULE, "staliomem");
4601 for (i = 0; i < 4; i++) 4602 for (i = 0; i < 4; i++)
4602 device_create_drvdata(istallion_class, NULL, 4603 device_create(istallion_class, NULL, MKDEV(STL_SIOMEMMAJOR, i),
4603 MKDEV(STL_SIOMEMMAJOR, i), 4604 NULL, "staliomem%d", i);
4604 NULL, "staliomem%d", i);
4605 4605
4606 return 0; 4606 return 0;
4607err_deinit: 4607err_deinit:
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index 7b3a212c86b1..de26a978fbdd 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -1249,7 +1249,7 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)
1249 return; 1249 return;
1250 } 1250 }
1251 1251
1252 if (keycode > NR_KEYS) 1252 if (keycode >= NR_KEYS)
1253 if (keycode >= KEY_BRL_DOT1 && keycode <= KEY_BRL_DOT8) 1253 if (keycode >= KEY_BRL_DOT1 && keycode <= KEY_BRL_DOT8)
1254 keysym = K(KT_BRL, keycode - KEY_BRL_DOT1 + 1); 1254 keysym = K(KT_BRL, keycode - KEY_BRL_DOT1 + 1);
1255 else 1255 else
diff --git a/drivers/char/lp.c b/drivers/char/lp.c
index 3f2719b9f77b..e444c2dba160 100644
--- a/drivers/char/lp.c
+++ b/drivers/char/lp.c
@@ -813,8 +813,8 @@ static int lp_register(int nr, struct parport *port)
813 if (reset) 813 if (reset)
814 lp_reset(nr); 814 lp_reset(nr);
815 815
816 device_create_drvdata(lp_class, port->dev, MKDEV(LP_MAJOR, nr), NULL, 816 device_create(lp_class, port->dev, MKDEV(LP_MAJOR, nr), NULL,
817 "lp%d", nr); 817 "lp%d", nr);
818 818
819 printk(KERN_INFO "lp%d: using %s (%s).\n", nr, port->name, 819 printk(KERN_INFO "lp%d: using %s (%s).\n", nr, port->name,
820 (port->irq == PARPORT_IRQ_NONE)?"polling":"interrupt-driven"); 820 (port->irq == PARPORT_IRQ_NONE)?"polling":"interrupt-driven");
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 672b08e694d0..6431f6921a67 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -992,9 +992,9 @@ static int __init chr_dev_init(void)
992 992
993 mem_class = class_create(THIS_MODULE, "mem"); 993 mem_class = class_create(THIS_MODULE, "mem");
994 for (i = 0; i < ARRAY_SIZE(devlist); i++) 994 for (i = 0; i < ARRAY_SIZE(devlist); i++)
995 device_create_drvdata(mem_class, NULL, 995 device_create(mem_class, NULL,
996 MKDEV(MEM_MAJOR, devlist[i].minor), 996 MKDEV(MEM_MAJOR, devlist[i].minor), NULL,
997 NULL, devlist[i].name); 997 devlist[i].name);
998 998
999 return 0; 999 return 0;
1000} 1000}
diff --git a/drivers/char/misc.c b/drivers/char/misc.c
index 999aa779c08a..a5e0db9d7662 100644
--- a/drivers/char/misc.c
+++ b/drivers/char/misc.c
@@ -217,8 +217,8 @@ int misc_register(struct miscdevice * misc)
217 misc_minors[misc->minor >> 3] |= 1 << (misc->minor & 7); 217 misc_minors[misc->minor >> 3] |= 1 << (misc->minor & 7);
218 dev = MKDEV(MISC_MAJOR, misc->minor); 218 dev = MKDEV(MISC_MAJOR, misc->minor);
219 219
220 misc->this_device = device_create_drvdata(misc_class, misc->parent, 220 misc->this_device = device_create(misc_class, misc->parent, dev, NULL,
221 dev, NULL, "%s", misc->name); 221 "%s", misc->name);
222 if (IS_ERR(misc->this_device)) { 222 if (IS_ERR(misc->this_device)) {
223 err = PTR_ERR(misc->this_device); 223 err = PTR_ERR(misc->this_device);
224 goto out; 224 goto out;
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index d3d7864e0c1e..12d327a2c9ba 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -205,7 +205,7 @@ static int moxa_tiocmset(struct tty_struct *tty, struct file *file,
205static void moxa_poll(unsigned long); 205static void moxa_poll(unsigned long);
206static void moxa_set_tty_param(struct tty_struct *, struct ktermios *); 206static void moxa_set_tty_param(struct tty_struct *, struct ktermios *);
207static void moxa_setup_empty_event(struct tty_struct *); 207static void moxa_setup_empty_event(struct tty_struct *);
208static void moxa_shut_down(struct moxa_port *); 208static void moxa_shut_down(struct tty_struct *);
209/* 209/*
210 * moxa board interface functions: 210 * moxa board interface functions:
211 */ 211 */
@@ -217,7 +217,7 @@ static void MoxaPortLineCtrl(struct moxa_port *, int, int);
217static void MoxaPortFlowCtrl(struct moxa_port *, int, int, int, int, int); 217static void MoxaPortFlowCtrl(struct moxa_port *, int, int, int, int, int);
218static int MoxaPortLineStatus(struct moxa_port *); 218static int MoxaPortLineStatus(struct moxa_port *);
219static void MoxaPortFlushData(struct moxa_port *, int); 219static void MoxaPortFlushData(struct moxa_port *, int);
220static int MoxaPortWriteData(struct moxa_port *, const unsigned char *, int); 220static int MoxaPortWriteData(struct tty_struct *, const unsigned char *, int);
221static int MoxaPortReadData(struct moxa_port *); 221static int MoxaPortReadData(struct moxa_port *);
222static int MoxaPortTxQueue(struct moxa_port *); 222static int MoxaPortTxQueue(struct moxa_port *);
223static int MoxaPortRxQueue(struct moxa_port *); 223static int MoxaPortRxQueue(struct moxa_port *);
@@ -332,6 +332,7 @@ static int moxa_ioctl(struct tty_struct *tty, struct file *file,
332 for (i = 0; i < MAX_BOARDS; i++) { 332 for (i = 0; i < MAX_BOARDS; i++) {
333 p = moxa_boards[i].ports; 333 p = moxa_boards[i].ports;
334 for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) { 334 for (j = 0; j < MAX_PORTS_PER_BOARD; j++, p++, argm++) {
335 struct tty_struct *ttyp;
335 memset(&tmp, 0, sizeof(tmp)); 336 memset(&tmp, 0, sizeof(tmp));
336 if (!moxa_boards[i].ready) 337 if (!moxa_boards[i].ready)
337 goto copy; 338 goto copy;
@@ -344,10 +345,12 @@ static int moxa_ioctl(struct tty_struct *tty, struct file *file,
344 if (status & 4) 345 if (status & 4)
345 tmp.dcd = 1; 346 tmp.dcd = 1;
346 347
347 if (!p->port.tty || !p->port.tty->termios) 348 ttyp = tty_port_tty_get(&p->port);
349 if (!ttyp || !ttyp->termios)
348 tmp.cflag = p->cflag; 350 tmp.cflag = p->cflag;
349 else 351 else
350 tmp.cflag = p->port.tty->termios->c_cflag; 352 tmp.cflag = ttyp->termios->c_cflag;
353 tty_kref_put(tty);
351copy: 354copy:
352 if (copy_to_user(argm, &tmp, sizeof(tmp))) { 355 if (copy_to_user(argm, &tmp, sizeof(tmp))) {
353 mutex_unlock(&moxa_openlock); 356 mutex_unlock(&moxa_openlock);
@@ -510,7 +513,7 @@ static int moxa_real_load_code(struct moxa_board_conf *brd, const void *ptr,
510 size_t len) 513 size_t len)
511{ 514{
512 void __iomem *baseAddr = brd->basemem; 515 void __iomem *baseAddr = brd->basemem;
513 const u16 *uptr = ptr; 516 const __le16 *uptr = ptr;
514 size_t wlen, len2, j; 517 size_t wlen, len2, j;
515 unsigned long key, loadbuf, loadlen, checksum, checksum_ok; 518 unsigned long key, loadbuf, loadlen, checksum, checksum_ok;
516 unsigned int i, retry; 519 unsigned int i, retry;
@@ -880,8 +883,14 @@ static void moxa_board_deinit(struct moxa_board_conf *brd)
880 883
881 /* pci hot-un-plug support */ 884 /* pci hot-un-plug support */
882 for (a = 0; a < brd->numPorts; a++) 885 for (a = 0; a < brd->numPorts; a++)
883 if (brd->ports[a].port.flags & ASYNC_INITIALIZED) 886 if (brd->ports[a].port.flags & ASYNC_INITIALIZED) {
884 tty_hangup(brd->ports[a].port.tty); 887 struct tty_struct *tty = tty_port_tty_get(
888 &brd->ports[a].port);
889 if (tty) {
890 tty_hangup(tty);
891 tty_kref_put(tty);
892 }
893 }
885 while (1) { 894 while (1) {
886 opened = 0; 895 opened = 0;
887 for (a = 0; a < brd->numPorts; a++) 896 for (a = 0; a < brd->numPorts; a++)
@@ -1096,13 +1105,14 @@ static void __exit moxa_exit(void)
1096module_init(moxa_init); 1105module_init(moxa_init);
1097module_exit(moxa_exit); 1106module_exit(moxa_exit);
1098 1107
1099static void moxa_close_port(struct moxa_port *ch) 1108static void moxa_close_port(struct tty_struct *tty)
1100{ 1109{
1101 moxa_shut_down(ch); 1110 struct moxa_port *ch = tty->driver_data;
1111 moxa_shut_down(tty);
1102 MoxaPortFlushData(ch, 2); 1112 MoxaPortFlushData(ch, 2);
1103 ch->port.flags &= ~ASYNC_NORMAL_ACTIVE; 1113 ch->port.flags &= ~ASYNC_NORMAL_ACTIVE;
1104 ch->port.tty->driver_data = NULL; 1114 tty->driver_data = NULL;
1105 ch->port.tty = NULL; 1115 tty_port_tty_set(&ch->port, NULL);
1106} 1116}
1107 1117
1108static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp, 1118static int moxa_block_till_ready(struct tty_struct *tty, struct file *filp,
@@ -1161,7 +1171,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
1161 ch = &brd->ports[port % MAX_PORTS_PER_BOARD]; 1171 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
1162 ch->port.count++; 1172 ch->port.count++;
1163 tty->driver_data = ch; 1173 tty->driver_data = ch;
1164 ch->port.tty = tty; 1174 tty_port_tty_set(&ch->port, tty);
1165 if (!(ch->port.flags & ASYNC_INITIALIZED)) { 1175 if (!(ch->port.flags & ASYNC_INITIALIZED)) {
1166 ch->statusflags = 0; 1176 ch->statusflags = 0;
1167 moxa_set_tty_param(tty, tty->termios); 1177 moxa_set_tty_param(tty, tty->termios);
@@ -1179,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
1179 if (retval) { 1189 if (retval) {
1180 if (ch->port.count) /* 0 means already hung up... */ 1190 if (ch->port.count) /* 0 means already hung up... */
1181 if (--ch->port.count == 0) 1191 if (--ch->port.count == 0)
1182 moxa_close_port(ch); 1192 moxa_close_port(tty);
1183 } else 1193 } else
1184 ch->port.flags |= ASYNC_NORMAL_ACTIVE; 1194 ch->port.flags |= ASYNC_NORMAL_ACTIVE;
1185 mutex_unlock(&moxa_openlock); 1195 mutex_unlock(&moxa_openlock);
@@ -1219,7 +1229,7 @@ static void moxa_close(struct tty_struct *tty, struct file *filp)
1219 tty_wait_until_sent(tty, 30 * HZ); /* 30 seconds timeout */ 1229 tty_wait_until_sent(tty, 30 * HZ); /* 30 seconds timeout */
1220 } 1230 }
1221 1231
1222 moxa_close_port(ch); 1232 moxa_close_port(tty);
1223unlock: 1233unlock:
1224 mutex_unlock(&moxa_openlock); 1234 mutex_unlock(&moxa_openlock);
1225} 1235}
@@ -1234,7 +1244,7 @@ static int moxa_write(struct tty_struct *tty,
1234 return 0; 1244 return 0;
1235 1245
1236 spin_lock_bh(&moxa_lock); 1246 spin_lock_bh(&moxa_lock);
1237 len = MoxaPortWriteData(ch, buf, count); 1247 len = MoxaPortWriteData(tty, buf, count);
1238 spin_unlock_bh(&moxa_lock); 1248 spin_unlock_bh(&moxa_lock);
1239 1249
1240 ch->statusflags |= LOWWAIT; 1250 ch->statusflags |= LOWWAIT;
@@ -1409,7 +1419,7 @@ static void moxa_hangup(struct tty_struct *tty)
1409 return; 1419 return;
1410 } 1420 }
1411 ch->port.count = 0; 1421 ch->port.count = 0;
1412 moxa_close_port(ch); 1422 moxa_close_port(tty);
1413 mutex_unlock(&moxa_openlock); 1423 mutex_unlock(&moxa_openlock);
1414 1424
1415 wake_up_interruptible(&ch->port.open_wait); 1425 wake_up_interruptible(&ch->port.open_wait);
@@ -1417,11 +1427,14 @@ static void moxa_hangup(struct tty_struct *tty)
1417 1427
1418static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd) 1428static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
1419{ 1429{
1430 struct tty_struct *tty;
1420 dcd = !!dcd; 1431 dcd = !!dcd;
1421 1432
1422 if (dcd != p->DCDState && p->port.tty && C_CLOCAL(p->port.tty)) { 1433 if (dcd != p->DCDState) {
1423 if (!dcd) 1434 tty = tty_port_tty_get(&p->port);
1424 tty_hangup(p->port.tty); 1435 if (tty && C_CLOCAL(tty) && !dcd)
1436 tty_hangup(tty);
1437 tty_kref_put(tty);
1425 } 1438 }
1426 p->DCDState = dcd; 1439 p->DCDState = dcd;
1427} 1440}
@@ -1429,7 +1442,7 @@ static void moxa_new_dcdstate(struct moxa_port *p, u8 dcd)
1429static int moxa_poll_port(struct moxa_port *p, unsigned int handle, 1442static int moxa_poll_port(struct moxa_port *p, unsigned int handle,
1430 u16 __iomem *ip) 1443 u16 __iomem *ip)
1431{ 1444{
1432 struct tty_struct *tty = p->port.tty; 1445 struct tty_struct *tty = tty_port_tty_get(&p->port);
1433 void __iomem *ofsAddr; 1446 void __iomem *ofsAddr;
1434 unsigned int inited = p->port.flags & ASYNC_INITIALIZED; 1447 unsigned int inited = p->port.flags & ASYNC_INITIALIZED;
1435 u16 intr; 1448 u16 intr;
@@ -1476,6 +1489,7 @@ static int moxa_poll_port(struct moxa_port *p, unsigned int handle,
1476 tty_insert_flip_char(tty, 0, TTY_BREAK); 1489 tty_insert_flip_char(tty, 0, TTY_BREAK);
1477 tty_schedule_flip(tty); 1490 tty_schedule_flip(tty);
1478 } 1491 }
1492 tty_kref_put(tty);
1479 1493
1480 if (intr & IntrLine) 1494 if (intr & IntrLine)
1481 moxa_new_dcdstate(p, readb(ofsAddr + FlagStat) & DCD_state); 1495 moxa_new_dcdstate(p, readb(ofsAddr + FlagStat) & DCD_state);
@@ -1560,9 +1574,9 @@ static void moxa_setup_empty_event(struct tty_struct *tty)
1560 spin_unlock_bh(&moxa_lock); 1574 spin_unlock_bh(&moxa_lock);
1561} 1575}
1562 1576
1563static void moxa_shut_down(struct moxa_port *ch) 1577static void moxa_shut_down(struct tty_struct *tty)
1564{ 1578{
1565 struct tty_struct *tp = ch->port.tty; 1579 struct moxa_port *ch = tty->driver_data;
1566 1580
1567 if (!(ch->port.flags & ASYNC_INITIALIZED)) 1581 if (!(ch->port.flags & ASYNC_INITIALIZED))
1568 return; 1582 return;
@@ -1572,7 +1586,7 @@ static void moxa_shut_down(struct moxa_port *ch)
1572 /* 1586 /*
1573 * If we're a modem control device and HUPCL is on, drop RTS & DTR. 1587 * If we're a modem control device and HUPCL is on, drop RTS & DTR.
1574 */ 1588 */
1575 if (C_HUPCL(tp)) 1589 if (C_HUPCL(tty))
1576 MoxaPortLineCtrl(ch, 0, 0); 1590 MoxaPortLineCtrl(ch, 0, 0);
1577 1591
1578 spin_lock_bh(&moxa_lock); 1592 spin_lock_bh(&moxa_lock);
@@ -1953,9 +1967,10 @@ static int MoxaPortLineStatus(struct moxa_port *port)
1953 return val; 1967 return val;
1954} 1968}
1955 1969
1956static int MoxaPortWriteData(struct moxa_port *port, 1970static int MoxaPortWriteData(struct tty_struct *tty,
1957 const unsigned char *buffer, int len) 1971 const unsigned char *buffer, int len)
1958{ 1972{
1973 struct moxa_port *port = tty->driver_data;
1959 void __iomem *baseAddr, *ofsAddr, *ofs; 1974 void __iomem *baseAddr, *ofsAddr, *ofs;
1960 unsigned int c, total; 1975 unsigned int c, total;
1961 u16 head, tail, tx_mask, spage, epage; 1976 u16 head, tail, tx_mask, spage, epage;
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index b638403e8e9c..8beef50f95a0 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -610,15 +610,13 @@ static int mxser_block_til_ready(struct tty_struct *tty, struct file *filp,
610 return 0; 610 return 0;
611} 611}
612 612
613static int mxser_set_baud(struct mxser_port *info, long newspd) 613static int mxser_set_baud(struct tty_struct *tty, long newspd)
614{ 614{
615 struct mxser_port *info = tty->driver_data;
615 int quot = 0, baud; 616 int quot = 0, baud;
616 unsigned char cval; 617 unsigned char cval;
617 618
618 if (!info->port.tty || !info->port.tty->termios) 619 if (!info->ioaddr)
619 return -1;
620
621 if (!(info->ioaddr))
622 return -1; 620 return -1;
623 621
624 if (newspd > info->max_baud) 622 if (newspd > info->max_baud)
@@ -626,13 +624,13 @@ static int mxser_set_baud(struct mxser_port *info, long newspd)
626 624
627 if (newspd == 134) { 625 if (newspd == 134) {
628 quot = 2 * info->baud_base / 269; 626 quot = 2 * info->baud_base / 269;
629 tty_encode_baud_rate(info->port.tty, 134, 134); 627 tty_encode_baud_rate(tty, 134, 134);
630 } else if (newspd) { 628 } else if (newspd) {
631 quot = info->baud_base / newspd; 629 quot = info->baud_base / newspd;
632 if (quot == 0) 630 if (quot == 0)
633 quot = 1; 631 quot = 1;
634 baud = info->baud_base/quot; 632 baud = info->baud_base/quot;
635 tty_encode_baud_rate(info->port.tty, baud, baud); 633 tty_encode_baud_rate(tty, baud, baud);
636 } else { 634 } else {
637 quot = 0; 635 quot = 0;
638 } 636 }
@@ -658,7 +656,7 @@ static int mxser_set_baud(struct mxser_port *info, long newspd)
658 outb(cval, info->ioaddr + UART_LCR); /* reset DLAB */ 656 outb(cval, info->ioaddr + UART_LCR); /* reset DLAB */
659 657
660#ifdef BOTHER 658#ifdef BOTHER
661 if (C_BAUD(info->port.tty) == BOTHER) { 659 if (C_BAUD(tty) == BOTHER) {
662 quot = info->baud_base % newspd; 660 quot = info->baud_base % newspd;
663 quot *= 8; 661 quot *= 8;
664 if (quot % newspd > newspd / 2) { 662 if (quot % newspd > newspd / 2) {
@@ -679,21 +677,20 @@ static int mxser_set_baud(struct mxser_port *info, long newspd)
679 * This routine is called to set the UART divisor registers to match 677 * This routine is called to set the UART divisor registers to match
680 * the specified baud rate for a serial port. 678 * the specified baud rate for a serial port.
681 */ 679 */
682static int mxser_change_speed(struct mxser_port *info, 680static int mxser_change_speed(struct tty_struct *tty,
683 struct ktermios *old_termios) 681 struct ktermios *old_termios)
684{ 682{
683 struct mxser_port *info = tty->driver_data;
685 unsigned cflag, cval, fcr; 684 unsigned cflag, cval, fcr;
686 int ret = 0; 685 int ret = 0;
687 unsigned char status; 686 unsigned char status;
688 687
689 if (!info->port.tty || !info->port.tty->termios) 688 cflag = tty->termios->c_cflag;
690 return ret; 689 if (!info->ioaddr)
691 cflag = info->port.tty->termios->c_cflag;
692 if (!(info->ioaddr))
693 return ret; 690 return ret;
694 691
695 if (mxser_set_baud_method[info->port.tty->index] == 0) 692 if (mxser_set_baud_method[tty->index] == 0)
696 mxser_set_baud(info, tty_get_baud_rate(info->port.tty)); 693 mxser_set_baud(tty, tty_get_baud_rate(tty));
697 694
698 /* byte size and parity */ 695 /* byte size and parity */
699 switch (cflag & CSIZE) { 696 switch (cflag & CSIZE) {
@@ -762,9 +759,9 @@ static int mxser_change_speed(struct mxser_port *info,
762 info->MCR |= UART_MCR_AFE; 759 info->MCR |= UART_MCR_AFE;
763 } else { 760 } else {
764 status = inb(info->ioaddr + UART_MSR); 761 status = inb(info->ioaddr + UART_MSR);
765 if (info->port.tty->hw_stopped) { 762 if (tty->hw_stopped) {
766 if (status & UART_MSR_CTS) { 763 if (status & UART_MSR_CTS) {
767 info->port.tty->hw_stopped = 0; 764 tty->hw_stopped = 0;
768 if (info->type != PORT_16550A && 765 if (info->type != PORT_16550A &&
769 !info->board->chip_flag) { 766 !info->board->chip_flag) {
770 outb(info->IER & ~UART_IER_THRI, 767 outb(info->IER & ~UART_IER_THRI,
@@ -774,11 +771,11 @@ static int mxser_change_speed(struct mxser_port *info,
774 outb(info->IER, info->ioaddr + 771 outb(info->IER, info->ioaddr +
775 UART_IER); 772 UART_IER);
776 } 773 }
777 tty_wakeup(info->port.tty); 774 tty_wakeup(tty);
778 } 775 }
779 } else { 776 } else {
780 if (!(status & UART_MSR_CTS)) { 777 if (!(status & UART_MSR_CTS)) {
781 info->port.tty->hw_stopped = 1; 778 tty->hw_stopped = 1;
782 if ((info->type != PORT_16550A) && 779 if ((info->type != PORT_16550A) &&
783 (!info->board->chip_flag)) { 780 (!info->board->chip_flag)) {
784 info->IER &= ~UART_IER_THRI; 781 info->IER &= ~UART_IER_THRI;
@@ -804,21 +801,21 @@ static int mxser_change_speed(struct mxser_port *info,
804 * Set up parity check flag 801 * Set up parity check flag
805 */ 802 */
806 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR; 803 info->read_status_mask = UART_LSR_OE | UART_LSR_THRE | UART_LSR_DR;
807 if (I_INPCK(info->port.tty)) 804 if (I_INPCK(tty))
808 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE; 805 info->read_status_mask |= UART_LSR_FE | UART_LSR_PE;
809 if (I_BRKINT(info->port.tty) || I_PARMRK(info->port.tty)) 806 if (I_BRKINT(tty) || I_PARMRK(tty))
810 info->read_status_mask |= UART_LSR_BI; 807 info->read_status_mask |= UART_LSR_BI;
811 808
812 info->ignore_status_mask = 0; 809 info->ignore_status_mask = 0;
813 810
814 if (I_IGNBRK(info->port.tty)) { 811 if (I_IGNBRK(tty)) {
815 info->ignore_status_mask |= UART_LSR_BI; 812 info->ignore_status_mask |= UART_LSR_BI;
816 info->read_status_mask |= UART_LSR_BI; 813 info->read_status_mask |= UART_LSR_BI;
817 /* 814 /*
818 * If we're ignore parity and break indicators, ignore 815 * If we're ignore parity and break indicators, ignore
819 * overruns too. (For real raw support). 816 * overruns too. (For real raw support).
820 */ 817 */
821 if (I_IGNPAR(info->port.tty)) { 818 if (I_IGNPAR(tty)) {
822 info->ignore_status_mask |= 819 info->ignore_status_mask |=
823 UART_LSR_OE | 820 UART_LSR_OE |
824 UART_LSR_PE | 821 UART_LSR_PE |
@@ -830,16 +827,16 @@ static int mxser_change_speed(struct mxser_port *info,
830 } 827 }
831 } 828 }
832 if (info->board->chip_flag) { 829 if (info->board->chip_flag) {
833 mxser_set_must_xon1_value(info->ioaddr, START_CHAR(info->port.tty)); 830 mxser_set_must_xon1_value(info->ioaddr, START_CHAR(tty));
834 mxser_set_must_xoff1_value(info->ioaddr, STOP_CHAR(info->port.tty)); 831 mxser_set_must_xoff1_value(info->ioaddr, STOP_CHAR(tty));
835 if (I_IXON(info->port.tty)) { 832 if (I_IXON(tty)) {
836 mxser_enable_must_rx_software_flow_control( 833 mxser_enable_must_rx_software_flow_control(
837 info->ioaddr); 834 info->ioaddr);
838 } else { 835 } else {
839 mxser_disable_must_rx_software_flow_control( 836 mxser_disable_must_rx_software_flow_control(
840 info->ioaddr); 837 info->ioaddr);
841 } 838 }
842 if (I_IXOFF(info->port.tty)) { 839 if (I_IXOFF(tty)) {
843 mxser_enable_must_tx_software_flow_control( 840 mxser_enable_must_tx_software_flow_control(
844 info->ioaddr); 841 info->ioaddr);
845 } else { 842 } else {
@@ -855,7 +852,8 @@ static int mxser_change_speed(struct mxser_port *info,
855 return ret; 852 return ret;
856} 853}
857 854
858static void mxser_check_modem_status(struct mxser_port *port, int status) 855static void mxser_check_modem_status(struct tty_struct *tty,
856 struct mxser_port *port, int status)
859{ 857{
860 /* update input line counters */ 858 /* update input line counters */
861 if (status & UART_MSR_TERI) 859 if (status & UART_MSR_TERI)
@@ -874,10 +872,11 @@ static void mxser_check_modem_status(struct mxser_port *port, int status)
874 wake_up_interruptible(&port->port.open_wait); 872 wake_up_interruptible(&port->port.open_wait);
875 } 873 }
876 874
875 tty = tty_port_tty_get(&port->port);
877 if (port->port.flags & ASYNC_CTS_FLOW) { 876 if (port->port.flags & ASYNC_CTS_FLOW) {
878 if (port->port.tty->hw_stopped) { 877 if (tty->hw_stopped) {
879 if (status & UART_MSR_CTS) { 878 if (status & UART_MSR_CTS) {
880 port->port.tty->hw_stopped = 0; 879 tty->hw_stopped = 0;
881 880
882 if ((port->type != PORT_16550A) && 881 if ((port->type != PORT_16550A) &&
883 (!port->board->chip_flag)) { 882 (!port->board->chip_flag)) {
@@ -887,11 +886,11 @@ static void mxser_check_modem_status(struct mxser_port *port, int status)
887 outb(port->IER, port->ioaddr + 886 outb(port->IER, port->ioaddr +
888 UART_IER); 887 UART_IER);
889 } 888 }
890 tty_wakeup(port->port.tty); 889 tty_wakeup(tty);
891 } 890 }
892 } else { 891 } else {
893 if (!(status & UART_MSR_CTS)) { 892 if (!(status & UART_MSR_CTS)) {
894 port->port.tty->hw_stopped = 1; 893 tty->hw_stopped = 1;
895 if (port->type != PORT_16550A && 894 if (port->type != PORT_16550A &&
896 !port->board->chip_flag) { 895 !port->board->chip_flag) {
897 port->IER &= ~UART_IER_THRI; 896 port->IER &= ~UART_IER_THRI;
@@ -903,8 +902,9 @@ static void mxser_check_modem_status(struct mxser_port *port, int status)
903 } 902 }
904} 903}
905 904
906static int mxser_startup(struct mxser_port *info) 905static int mxser_startup(struct tty_struct *tty)
907{ 906{
907 struct mxser_port *info = tty->driver_data;
908 unsigned long page; 908 unsigned long page;
909 unsigned long flags; 909 unsigned long flags;
910 910
@@ -921,8 +921,7 @@ static int mxser_startup(struct mxser_port *info)
921 } 921 }
922 922
923 if (!info->ioaddr || !info->type) { 923 if (!info->ioaddr || !info->type) {
924 if (info->port.tty) 924 set_bit(TTY_IO_ERROR, &tty->flags);
925 set_bit(TTY_IO_ERROR, &info->port.tty->flags);
926 free_page(page); 925 free_page(page);
927 spin_unlock_irqrestore(&info->slock, flags); 926 spin_unlock_irqrestore(&info->slock, flags);
928 return 0; 927 return 0;
@@ -952,8 +951,8 @@ static int mxser_startup(struct mxser_port *info)
952 if (inb(info->ioaddr + UART_LSR) == 0xff) { 951 if (inb(info->ioaddr + UART_LSR) == 0xff) {
953 spin_unlock_irqrestore(&info->slock, flags); 952 spin_unlock_irqrestore(&info->slock, flags);
954 if (capable(CAP_SYS_ADMIN)) { 953 if (capable(CAP_SYS_ADMIN)) {
955 if (info->port.tty) 954 if (tty)
956 set_bit(TTY_IO_ERROR, &info->port.tty->flags); 955 set_bit(TTY_IO_ERROR, &tty->flags);
957 return 0; 956 return 0;
958 } else 957 } else
959 return -ENODEV; 958 return -ENODEV;
@@ -991,14 +990,13 @@ static int mxser_startup(struct mxser_port *info)
991 (void) inb(info->ioaddr + UART_IIR); 990 (void) inb(info->ioaddr + UART_IIR);
992 (void) inb(info->ioaddr + UART_MSR); 991 (void) inb(info->ioaddr + UART_MSR);
993 992
994 if (info->port.tty) 993 clear_bit(TTY_IO_ERROR, &tty->flags);
995 clear_bit(TTY_IO_ERROR, &info->port.tty->flags);
996 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 994 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
997 995
998 /* 996 /*
999 * and set the speed of the serial port 997 * and set the speed of the serial port
1000 */ 998 */
1001 mxser_change_speed(info, NULL); 999 mxser_change_speed(tty, NULL);
1002 info->port.flags |= ASYNC_INITIALIZED; 1000 info->port.flags |= ASYNC_INITIALIZED;
1003 spin_unlock_irqrestore(&info->slock, flags); 1001 spin_unlock_irqrestore(&info->slock, flags);
1004 1002
@@ -1009,8 +1007,9 @@ static int mxser_startup(struct mxser_port *info)
1009 * This routine will shutdown a serial port; interrupts maybe disabled, and 1007 * This routine will shutdown a serial port; interrupts maybe disabled, and
1010 * DTR is dropped if the hangup on close termio flag is on. 1008 * DTR is dropped if the hangup on close termio flag is on.
1011 */ 1009 */
1012static void mxser_shutdown(struct mxser_port *info) 1010static void mxser_shutdown(struct tty_struct *tty)
1013{ 1011{
1012 struct mxser_port *info = tty->driver_data;
1014 unsigned long flags; 1013 unsigned long flags;
1015 1014
1016 if (!(info->port.flags & ASYNC_INITIALIZED)) 1015 if (!(info->port.flags & ASYNC_INITIALIZED))
@@ -1035,7 +1034,7 @@ static void mxser_shutdown(struct mxser_port *info)
1035 info->IER = 0; 1034 info->IER = 0;
1036 outb(0x00, info->ioaddr + UART_IER); 1035 outb(0x00, info->ioaddr + UART_IER);
1037 1036
1038 if (!info->port.tty || (info->port.tty->termios->c_cflag & HUPCL)) 1037 if (tty->termios->c_cflag & HUPCL)
1039 info->MCR &= ~(UART_MCR_DTR | UART_MCR_RTS); 1038 info->MCR &= ~(UART_MCR_DTR | UART_MCR_RTS);
1040 outb(info->MCR, info->ioaddr + UART_MCR); 1039 outb(info->MCR, info->ioaddr + UART_MCR);
1041 1040
@@ -1051,8 +1050,7 @@ static void mxser_shutdown(struct mxser_port *info)
1051 /* read data port to reset things */ 1050 /* read data port to reset things */
1052 (void) inb(info->ioaddr + UART_RX); 1051 (void) inb(info->ioaddr + UART_RX);
1053 1052
1054 if (info->port.tty) 1053 set_bit(TTY_IO_ERROR, &tty->flags);
1055 set_bit(TTY_IO_ERROR, &info->port.tty->flags);
1056 1054
1057 info->port.flags &= ~ASYNC_INITIALIZED; 1055 info->port.flags &= ~ASYNC_INITIALIZED;
1058 1056
@@ -1084,14 +1082,14 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
1084 return -ENODEV; 1082 return -ENODEV;
1085 1083
1086 tty->driver_data = info; 1084 tty->driver_data = info;
1087 info->port.tty = tty; 1085 tty_port_tty_set(&info->port, tty);
1088 /* 1086 /*
1089 * Start up serial port 1087 * Start up serial port
1090 */ 1088 */
1091 spin_lock_irqsave(&info->slock, flags); 1089 spin_lock_irqsave(&info->slock, flags);
1092 info->port.count++; 1090 info->port.count++;
1093 spin_unlock_irqrestore(&info->slock, flags); 1091 spin_unlock_irqrestore(&info->slock, flags);
1094 retval = mxser_startup(info); 1092 retval = mxser_startup(tty);
1095 if (retval) 1093 if (retval)
1096 return retval; 1094 return retval;
1097 1095
@@ -1209,13 +1207,13 @@ static void mxser_close(struct tty_struct *tty, struct file *filp)
1209 break; 1207 break;
1210 } 1208 }
1211 } 1209 }
1212 mxser_shutdown(info); 1210 mxser_shutdown(tty);
1213 1211
1214 mxser_flush_buffer(tty); 1212 mxser_flush_buffer(tty);
1215 tty_ldisc_flush(tty); 1213 tty_ldisc_flush(tty);
1216 1214
1217 tty->closing = 0; 1215 tty->closing = 0;
1218 info->port.tty = NULL; 1216 tty_port_tty_set(&info->port, NULL);
1219 if (info->port.blocked_open) { 1217 if (info->port.blocked_open) {
1220 if (info->port.close_delay) 1218 if (info->port.close_delay)
1221 schedule_timeout_interruptible(info->port.close_delay); 1219 schedule_timeout_interruptible(info->port.close_delay);
@@ -1337,12 +1335,13 @@ static int mxser_chars_in_buffer(struct tty_struct *tty)
1337 * friends of mxser_ioctl() 1335 * friends of mxser_ioctl()
1338 * ------------------------------------------------------------ 1336 * ------------------------------------------------------------
1339 */ 1337 */
1340static int mxser_get_serial_info(struct mxser_port *info, 1338static int mxser_get_serial_info(struct tty_struct *tty,
1341 struct serial_struct __user *retinfo) 1339 struct serial_struct __user *retinfo)
1342{ 1340{
1341 struct mxser_port *info = tty->driver_data;
1343 struct serial_struct tmp = { 1342 struct serial_struct tmp = {
1344 .type = info->type, 1343 .type = info->type,
1345 .line = info->port.tty->index, 1344 .line = tty->index,
1346 .port = info->ioaddr, 1345 .port = info->ioaddr,
1347 .irq = info->board->irq, 1346 .irq = info->board->irq,
1348 .flags = info->port.flags, 1347 .flags = info->port.flags,
@@ -1357,9 +1356,10 @@ static int mxser_get_serial_info(struct mxser_port *info,
1357 return 0; 1356 return 0;
1358} 1357}
1359 1358
1360static int mxser_set_serial_info(struct mxser_port *info, 1359static int mxser_set_serial_info(struct tty_struct *tty,
1361 struct serial_struct __user *new_info) 1360 struct serial_struct __user *new_info)
1362{ 1361{
1362 struct mxser_port *info = tty->driver_data;
1363 struct serial_struct new_serial; 1363 struct serial_struct new_serial;
1364 speed_t baud; 1364 speed_t baud;
1365 unsigned long sl_flags; 1365 unsigned long sl_flags;
@@ -1393,14 +1393,14 @@ static int mxser_set_serial_info(struct mxser_port *info,
1393 (new_serial.flags & ASYNC_FLAGS)); 1393 (new_serial.flags & ASYNC_FLAGS));
1394 info->port.close_delay = new_serial.close_delay * HZ / 100; 1394 info->port.close_delay = new_serial.close_delay * HZ / 100;
1395 info->port.closing_wait = new_serial.closing_wait * HZ / 100; 1395 info->port.closing_wait = new_serial.closing_wait * HZ / 100;
1396 info->port.tty->low_latency = 1396 tty->low_latency = (info->port.flags & ASYNC_LOW_LATENCY)
1397 (info->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0; 1397 ? 1 : 0;
1398 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST && 1398 if ((info->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST &&
1399 (new_serial.baud_base != info->baud_base || 1399 (new_serial.baud_base != info->baud_base ||
1400 new_serial.custom_divisor != 1400 new_serial.custom_divisor !=
1401 info->custom_divisor)) { 1401 info->custom_divisor)) {
1402 baud = new_serial.baud_base / new_serial.custom_divisor; 1402 baud = new_serial.baud_base / new_serial.custom_divisor;
1403 tty_encode_baud_rate(info->port.tty, baud, baud); 1403 tty_encode_baud_rate(tty, baud, baud);
1404 } 1404 }
1405 } 1405 }
1406 1406
@@ -1411,11 +1411,11 @@ static int mxser_set_serial_info(struct mxser_port *info,
1411 if (info->port.flags & ASYNC_INITIALIZED) { 1411 if (info->port.flags & ASYNC_INITIALIZED) {
1412 if (flags != (info->port.flags & ASYNC_SPD_MASK)) { 1412 if (flags != (info->port.flags & ASYNC_SPD_MASK)) {
1413 spin_lock_irqsave(&info->slock, sl_flags); 1413 spin_lock_irqsave(&info->slock, sl_flags);
1414 mxser_change_speed(info, NULL); 1414 mxser_change_speed(tty, NULL);
1415 spin_unlock_irqrestore(&info->slock, sl_flags); 1415 spin_unlock_irqrestore(&info->slock, sl_flags);
1416 } 1416 }
1417 } else 1417 } else
1418 retval = mxser_startup(info); 1418 retval = mxser_startup(tty);
1419 1419
1420 return retval; 1420 return retval;
1421} 1421}
@@ -1461,7 +1461,7 @@ static int mxser_tiocmget(struct tty_struct *tty, struct file *file)
1461 spin_lock_irqsave(&info->slock, flags); 1461 spin_lock_irqsave(&info->slock, flags);
1462 status = inb(info->ioaddr + UART_MSR); 1462 status = inb(info->ioaddr + UART_MSR);
1463 if (status & UART_MSR_ANY_DELTA) 1463 if (status & UART_MSR_ANY_DELTA)
1464 mxser_check_modem_status(info, status); 1464 mxser_check_modem_status(tty, info, status);
1465 spin_unlock_irqrestore(&info->slock, flags); 1465 spin_unlock_irqrestore(&info->slock, flags);
1466 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) | 1466 return ((control & UART_MCR_RTS) ? TIOCM_RTS : 0) |
1467 ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) | 1467 ((control & UART_MCR_DTR) ? TIOCM_DTR : 0) |
@@ -1606,6 +1606,7 @@ static int __init mxser_read_register(int port, unsigned short *regs)
1606static int mxser_ioctl_special(unsigned int cmd, void __user *argp) 1606static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1607{ 1607{
1608 struct mxser_port *port; 1608 struct mxser_port *port;
1609 struct tty_struct *tty;
1609 int result, status; 1610 int result, status;
1610 unsigned int i, j; 1611 unsigned int i, j;
1611 int ret = 0; 1612 int ret = 0;
@@ -1643,12 +1644,14 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1643 1644
1644 if (!port->ioaddr) 1645 if (!port->ioaddr)
1645 goto copy; 1646 goto copy;
1647
1648 tty = tty_port_tty_get(&port->port);
1646 1649
1647 if (!port->port.tty || !port->port.tty->termios) 1650 if (!tty || !tty->termios)
1648 ms.cflag = port->normal_termios.c_cflag; 1651 ms.cflag = port->normal_termios.c_cflag;
1649 else 1652 else
1650 ms.cflag = port->port.tty->termios->c_cflag; 1653 ms.cflag = tty->termios->c_cflag;
1651 1654 tty_kref_put(tty);
1652 status = inb(port->ioaddr + UART_MSR); 1655 status = inb(port->ioaddr + UART_MSR);
1653 if (status & UART_MSR_DCD) 1656 if (status & UART_MSR_DCD)
1654 ms.dcd = 1; 1657 ms.dcd = 1;
@@ -1704,15 +1707,18 @@ static int mxser_ioctl_special(unsigned int cmd, void __user *argp)
1704 me->up_txcnt[p] = port->mon_data.up_txcnt; 1707 me->up_txcnt[p] = port->mon_data.up_txcnt;
1705 me->modem_status[p] = 1708 me->modem_status[p] =
1706 port->mon_data.modem_status; 1709 port->mon_data.modem_status;
1707 me->baudrate[p] = tty_get_baud_rate(port->port.tty); 1710 tty = tty_port_tty_get(&port->port);
1708 1711
1709 if (!port->port.tty || !port->port.tty->termios) { 1712 if (!tty || !tty->termios) {
1710 cflag = port->normal_termios.c_cflag; 1713 cflag = port->normal_termios.c_cflag;
1711 iflag = port->normal_termios.c_iflag; 1714 iflag = port->normal_termios.c_iflag;
1715 me->baudrate[p] = tty_termios_baud_rate(&port->normal_termios);
1712 } else { 1716 } else {
1713 cflag = port->port.tty->termios->c_cflag; 1717 cflag = tty->termios->c_cflag;
1714 iflag = port->port.tty->termios->c_iflag; 1718 iflag = tty->termios->c_iflag;
1719 me->baudrate[p] = tty_get_baud_rate(tty);
1715 } 1720 }
1721 tty_kref_put(tty);
1716 1722
1717 me->databits[p] = cflag & CSIZE; 1723 me->databits[p] = cflag & CSIZE;
1718 me->stopbits[p] = cflag & CSTOPB; 1724 me->stopbits[p] = cflag & CSTOPB;
@@ -1822,12 +1828,12 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1822 switch (cmd) { 1828 switch (cmd) {
1823 case TIOCGSERIAL: 1829 case TIOCGSERIAL:
1824 lock_kernel(); 1830 lock_kernel();
1825 retval = mxser_get_serial_info(info, argp); 1831 retval = mxser_get_serial_info(tty, argp);
1826 unlock_kernel(); 1832 unlock_kernel();
1827 return retval; 1833 return retval;
1828 case TIOCSSERIAL: 1834 case TIOCSSERIAL:
1829 lock_kernel(); 1835 lock_kernel();
1830 retval = mxser_set_serial_info(info, argp); 1836 retval = mxser_set_serial_info(tty, argp);
1831 unlock_kernel(); 1837 unlock_kernel();
1832 return retval; 1838 return retval;
1833 case TIOCSERGETLSR: /* Get line status register */ 1839 case TIOCSERGETLSR: /* Get line status register */
@@ -1896,7 +1902,7 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1896 1902
1897 lock_kernel(); 1903 lock_kernel();
1898 status = mxser_get_msr(info->ioaddr, 1, tty->index); 1904 status = mxser_get_msr(info->ioaddr, 1, tty->index);
1899 mxser_check_modem_status(info, status); 1905 mxser_check_modem_status(tty, info, status);
1900 1906
1901 mcr = inb(info->ioaddr + UART_MCR); 1907 mcr = inb(info->ioaddr + UART_MCR);
1902 if (mcr & MOXA_MUST_MCR_XON_FLAG) 1908 if (mcr & MOXA_MUST_MCR_XON_FLAG)
@@ -1909,7 +1915,7 @@ static int mxser_ioctl(struct tty_struct *tty, struct file *file,
1909 else 1915 else
1910 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFXENT; 1916 info->mon_data.hold_reason |= NPPI_NOTIFY_XOFFXENT;
1911 1917
1912 if (info->port.tty->hw_stopped) 1918 if (tty->hw_stopped)
1913 info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD; 1919 info->mon_data.hold_reason |= NPPI_NOTIFY_CTSHOLD;
1914 else 1920 else
1915 info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD; 1921 info->mon_data.hold_reason &= ~NPPI_NOTIFY_CTSHOLD;
@@ -1958,7 +1964,7 @@ static void mxser_stoprx(struct tty_struct *tty)
1958 } 1964 }
1959 } 1965 }
1960 1966
1961 if (info->port.tty->termios->c_cflag & CRTSCTS) { 1967 if (tty->termios->c_cflag & CRTSCTS) {
1962 info->MCR &= ~UART_MCR_RTS; 1968 info->MCR &= ~UART_MCR_RTS;
1963 outb(info->MCR, info->ioaddr + UART_MCR); 1969 outb(info->MCR, info->ioaddr + UART_MCR);
1964 } 1970 }
@@ -1995,7 +2001,7 @@ static void mxser_unthrottle(struct tty_struct *tty)
1995 } 2001 }
1996 } 2002 }
1997 2003
1998 if (info->port.tty->termios->c_cflag & CRTSCTS) { 2004 if (tty->termios->c_cflag & CRTSCTS) {
1999 info->MCR |= UART_MCR_RTS; 2005 info->MCR |= UART_MCR_RTS;
2000 outb(info->MCR, info->ioaddr + UART_MCR); 2006 outb(info->MCR, info->ioaddr + UART_MCR);
2001 } 2007 }
@@ -2040,7 +2046,7 @@ static void mxser_set_termios(struct tty_struct *tty, struct ktermios *old_termi
2040 unsigned long flags; 2046 unsigned long flags;
2041 2047
2042 spin_lock_irqsave(&info->slock, flags); 2048 spin_lock_irqsave(&info->slock, flags);
2043 mxser_change_speed(info, old_termios); 2049 mxser_change_speed(tty, old_termios);
2044 spin_unlock_irqrestore(&info->slock, flags); 2050 spin_unlock_irqrestore(&info->slock, flags);
2045 2051
2046 if ((old_termios->c_cflag & CRTSCTS) && 2052 if ((old_termios->c_cflag & CRTSCTS) &&
@@ -2138,10 +2144,10 @@ static void mxser_hangup(struct tty_struct *tty)
2138 struct mxser_port *info = tty->driver_data; 2144 struct mxser_port *info = tty->driver_data;
2139 2145
2140 mxser_flush_buffer(tty); 2146 mxser_flush_buffer(tty);
2141 mxser_shutdown(info); 2147 mxser_shutdown(tty);
2142 info->port.count = 0; 2148 info->port.count = 0;
2143 info->port.flags &= ~ASYNC_NORMAL_ACTIVE; 2149 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
2144 info->port.tty = NULL; 2150 tty_port_tty_set(&info->port, NULL);
2145 wake_up_interruptible(&info->port.open_wait); 2151 wake_up_interruptible(&info->port.open_wait);
2146} 2152}
2147 2153
@@ -2164,9 +2170,9 @@ static int mxser_rs_break(struct tty_struct *tty, int break_state)
2164 return 0; 2170 return 0;
2165} 2171}
2166 2172
2167static void mxser_receive_chars(struct mxser_port *port, int *status) 2173static void mxser_receive_chars(struct tty_struct *tty,
2174 struct mxser_port *port, int *status)
2168{ 2175{
2169 struct tty_struct *tty = port->port.tty;
2170 unsigned char ch, gdl; 2176 unsigned char ch, gdl;
2171 int ignored = 0; 2177 int ignored = 0;
2172 int cnt = 0; 2178 int cnt = 0;
@@ -2174,9 +2180,8 @@ static void mxser_receive_chars(struct mxser_port *port, int *status)
2174 int max = 256; 2180 int max = 256;
2175 2181
2176 recv_room = tty->receive_room; 2182 recv_room = tty->receive_room;
2177 if ((recv_room == 0) && (!port->ldisc_stop_rx)) 2183 if (recv_room == 0 && !port->ldisc_stop_rx)
2178 mxser_stoprx(tty); 2184 mxser_stoprx(tty);
2179
2180 if (port->board->chip_flag != MOXA_OTHER_UART) { 2185 if (port->board->chip_flag != MOXA_OTHER_UART) {
2181 2186
2182 if (*status & UART_LSR_SPECIAL) 2187 if (*status & UART_LSR_SPECIAL)
@@ -2253,7 +2258,7 @@ intr_old:
2253 } while (*status & UART_LSR_DR); 2258 } while (*status & UART_LSR_DR);
2254 2259
2255end_intr: 2260end_intr:
2256 mxvar_log.rxcnt[port->port.tty->index] += cnt; 2261 mxvar_log.rxcnt[tty->index] += cnt;
2257 port->mon_data.rxcnt += cnt; 2262 port->mon_data.rxcnt += cnt;
2258 port->mon_data.up_rxcnt += cnt; 2263 port->mon_data.up_rxcnt += cnt;
2259 2264
@@ -2267,14 +2272,14 @@ end_intr:
2267 spin_lock(&port->slock); 2272 spin_lock(&port->slock);
2268} 2273}
2269 2274
2270static void mxser_transmit_chars(struct mxser_port *port) 2275static void mxser_transmit_chars(struct tty_struct *tty, struct mxser_port *port)
2271{ 2276{
2272 int count, cnt; 2277 int count, cnt;
2273 2278
2274 if (port->x_char) { 2279 if (port->x_char) {
2275 outb(port->x_char, port->ioaddr + UART_TX); 2280 outb(port->x_char, port->ioaddr + UART_TX);
2276 port->x_char = 0; 2281 port->x_char = 0;
2277 mxvar_log.txcnt[port->port.tty->index]++; 2282 mxvar_log.txcnt[tty->index]++;
2278 port->mon_data.txcnt++; 2283 port->mon_data.txcnt++;
2279 port->mon_data.up_txcnt++; 2284 port->mon_data.up_txcnt++;
2280 port->icount.tx++; 2285 port->icount.tx++;
@@ -2284,8 +2289,8 @@ static void mxser_transmit_chars(struct mxser_port *port)
2284 if (port->port.xmit_buf == NULL) 2289 if (port->port.xmit_buf == NULL)
2285 return; 2290 return;
2286 2291
2287 if ((port->xmit_cnt <= 0) || port->port.tty->stopped || 2292 if (port->xmit_cnt <= 0 || tty->stopped ||
2288 (port->port.tty->hw_stopped && 2293 (tty->hw_stopped &&
2289 (port->type != PORT_16550A) && 2294 (port->type != PORT_16550A) &&
2290 (!port->board->chip_flag))) { 2295 (!port->board->chip_flag))) {
2291 port->IER &= ~UART_IER_THRI; 2296 port->IER &= ~UART_IER_THRI;
@@ -2302,14 +2307,14 @@ static void mxser_transmit_chars(struct mxser_port *port)
2302 if (--port->xmit_cnt <= 0) 2307 if (--port->xmit_cnt <= 0)
2303 break; 2308 break;
2304 } while (--count > 0); 2309 } while (--count > 0);
2305 mxvar_log.txcnt[port->port.tty->index] += (cnt - port->xmit_cnt); 2310 mxvar_log.txcnt[tty->index] += (cnt - port->xmit_cnt);
2306 2311
2307 port->mon_data.txcnt += (cnt - port->xmit_cnt); 2312 port->mon_data.txcnt += (cnt - port->xmit_cnt);
2308 port->mon_data.up_txcnt += (cnt - port->xmit_cnt); 2313 port->mon_data.up_txcnt += (cnt - port->xmit_cnt);
2309 port->icount.tx += (cnt - port->xmit_cnt); 2314 port->icount.tx += (cnt - port->xmit_cnt);
2310 2315
2311 if (port->xmit_cnt < WAKEUP_CHARS) 2316 if (port->xmit_cnt < WAKEUP_CHARS && tty)
2312 tty_wakeup(port->port.tty); 2317 tty_wakeup(tty);
2313 2318
2314 if (port->xmit_cnt <= 0) { 2319 if (port->xmit_cnt <= 0) {
2315 port->IER &= ~UART_IER_THRI; 2320 port->IER &= ~UART_IER_THRI;
@@ -2328,6 +2333,7 @@ static irqreturn_t mxser_interrupt(int irq, void *dev_id)
2328 int max, irqbits, bits, msr; 2333 int max, irqbits, bits, msr;
2329 unsigned int int_cnt, pass_counter = 0; 2334 unsigned int int_cnt, pass_counter = 0;
2330 int handled = IRQ_NONE; 2335 int handled = IRQ_NONE;
2336 struct tty_struct *tty;
2331 2337
2332 for (i = 0; i < MXSER_BOARDS; i++) 2338 for (i = 0; i < MXSER_BOARDS; i++)
2333 if (dev_id == &mxser_boards[i]) { 2339 if (dev_id == &mxser_boards[i]) {
@@ -2360,13 +2366,15 @@ static irqreturn_t mxser_interrupt(int irq, void *dev_id)
2360 if (iir & UART_IIR_NO_INT) 2366 if (iir & UART_IIR_NO_INT)
2361 break; 2367 break;
2362 iir &= MOXA_MUST_IIR_MASK; 2368 iir &= MOXA_MUST_IIR_MASK;
2363 if (!port->port.tty || 2369 tty = tty_port_tty_get(&port->port);
2370 if (!tty ||
2364 (port->port.flags & ASYNC_CLOSING) || 2371 (port->port.flags & ASYNC_CLOSING) ||
2365 !(port->port.flags & 2372 !(port->port.flags &
2366 ASYNC_INITIALIZED)) { 2373 ASYNC_INITIALIZED)) {
2367 status = inb(port->ioaddr + UART_LSR); 2374 status = inb(port->ioaddr + UART_LSR);
2368 outb(0x27, port->ioaddr + UART_FCR); 2375 outb(0x27, port->ioaddr + UART_FCR);
2369 inb(port->ioaddr + UART_MSR); 2376 inb(port->ioaddr + UART_MSR);
2377 tty_kref_put(tty);
2370 break; 2378 break;
2371 } 2379 }
2372 2380
@@ -2387,27 +2395,28 @@ static irqreturn_t mxser_interrupt(int irq, void *dev_id)
2387 iir == MOXA_MUST_IIR_RDA || 2395 iir == MOXA_MUST_IIR_RDA ||
2388 iir == MOXA_MUST_IIR_RTO || 2396 iir == MOXA_MUST_IIR_RTO ||
2389 iir == MOXA_MUST_IIR_LSR) 2397 iir == MOXA_MUST_IIR_LSR)
2390 mxser_receive_chars(port, 2398 mxser_receive_chars(tty, port,
2391 &status); 2399 &status);
2392 2400
2393 } else { 2401 } else {
2394 status &= port->read_status_mask; 2402 status &= port->read_status_mask;
2395 if (status & UART_LSR_DR) 2403 if (status & UART_LSR_DR)
2396 mxser_receive_chars(port, 2404 mxser_receive_chars(tty, port,
2397 &status); 2405 &status);
2398 } 2406 }
2399 msr = inb(port->ioaddr + UART_MSR); 2407 msr = inb(port->ioaddr + UART_MSR);
2400 if (msr & UART_MSR_ANY_DELTA) 2408 if (msr & UART_MSR_ANY_DELTA)
2401 mxser_check_modem_status(port, msr); 2409 mxser_check_modem_status(tty, port, msr);
2402 2410
2403 if (port->board->chip_flag) { 2411 if (port->board->chip_flag) {
2404 if (iir == 0x02 && (status & 2412 if (iir == 0x02 && (status &
2405 UART_LSR_THRE)) 2413 UART_LSR_THRE))
2406 mxser_transmit_chars(port); 2414 mxser_transmit_chars(tty, port);
2407 } else { 2415 } else {
2408 if (status & UART_LSR_THRE) 2416 if (status & UART_LSR_THRE)
2409 mxser_transmit_chars(port); 2417 mxser_transmit_chars(tty, port);
2410 } 2418 }
2419 tty_kref_put(tty);
2411 } while (int_cnt++ < MXSER_ISR_PASS_LIMIT); 2420 } while (int_cnt++ < MXSER_ISR_PASS_LIMIT);
2412 spin_unlock(&port->slock); 2421 spin_unlock(&port->slock);
2413 } 2422 }
diff --git a/drivers/char/n_hdlc.c b/drivers/char/n_hdlc.c
index 69ec6399c714..bacb3e2872ae 100644
--- a/drivers/char/n_hdlc.c
+++ b/drivers/char/n_hdlc.c
@@ -764,7 +764,7 @@ static int n_hdlc_tty_ioctl(struct tty_struct *tty, struct file *file,
764 break; 764 break;
765 765
766 default: 766 default:
767 error = n_tty_ioctl (tty, file, cmd, arg); 767 error = n_tty_ioctl_helper(tty, file, cmd, arg);
768 break; 768 break;
769 } 769 }
770 return error; 770 return error;
diff --git a/drivers/char/n_r3964.c b/drivers/char/n_r3964.c
index ae377aa473ba..4a8215a89ad3 100644
--- a/drivers/char/n_r3964.c
+++ b/drivers/char/n_r3964.c
@@ -372,14 +372,8 @@ static void remove_from_rx_queue(struct r3964_info *pInfo,
372static void put_char(struct r3964_info *pInfo, unsigned char ch) 372static void put_char(struct r3964_info *pInfo, unsigned char ch)
373{ 373{
374 struct tty_struct *tty = pInfo->tty; 374 struct tty_struct *tty = pInfo->tty;
375
376 if (tty == NULL)
377 return;
378
379 /* FIXME: put_char should not be called from an IRQ */ 375 /* FIXME: put_char should not be called from an IRQ */
380 if (tty->ops->put_char) { 376 tty_put_char(tty, ch);
381 tty->ops->put_char(tty, ch);
382 }
383 pInfo->bcc ^= ch; 377 pInfo->bcc ^= ch;
384} 378}
385 379
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index 708c2b1dbe51..efbfe9612658 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -26,7 +26,7 @@
26 * 26 *
27 * 2002/03/18 Implemented n_tty_wakeup to send SIGIO POLL_OUTs to 27 * 2002/03/18 Implemented n_tty_wakeup to send SIGIO POLL_OUTs to
28 * waiting writing processes-Sapan Bhatia <sapan@corewars.org>. 28 * waiting writing processes-Sapan Bhatia <sapan@corewars.org>.
29 * Also fixed a bug in BLOCKING mode where write_chan returns 29 * Also fixed a bug in BLOCKING mode where n_tty_write returns
30 * EAGAIN 30 * EAGAIN
31 */ 31 */
32 32
@@ -99,6 +99,7 @@ static inline int tty_put_user(struct tty_struct *tty, unsigned char x,
99 99
100static void n_tty_set_room(struct tty_struct *tty) 100static void n_tty_set_room(struct tty_struct *tty)
101{ 101{
102 /* tty->read_cnt is not read locked ? */
102 int left = N_TTY_BUF_SIZE - tty->read_cnt - 1; 103 int left = N_TTY_BUF_SIZE - tty->read_cnt - 1;
103 104
104 /* 105 /*
@@ -121,6 +122,16 @@ static void put_tty_queue_nolock(unsigned char c, struct tty_struct *tty)
121 } 122 }
122} 123}
123 124
125/**
126 * put_tty_queue - add character to tty
127 * @c: character
128 * @tty: tty device
129 *
130 * Add a character to the tty read_buf queue. This is done under the
131 * read_lock to serialize character addition and also to protect us
132 * against parallel reads or flushes
133 */
134
124static void put_tty_queue(unsigned char c, struct tty_struct *tty) 135static void put_tty_queue(unsigned char c, struct tty_struct *tty)
125{ 136{
126 unsigned long flags; 137 unsigned long flags;
@@ -137,14 +148,11 @@ static void put_tty_queue(unsigned char c, struct tty_struct *tty)
137 * check_unthrottle - allow new receive data 148 * check_unthrottle - allow new receive data
138 * @tty; tty device 149 * @tty; tty device
139 * 150 *
140 * Check whether to call the driver.unthrottle function. 151 * Check whether to call the driver unthrottle functions
141 * We test the TTY_THROTTLED bit first so that it always 152 *
142 * indicates the current state. The decision about whether
143 * it is worth allowing more input has been taken by the caller.
144 * Can sleep, may be called under the atomic_read_lock mutex but 153 * Can sleep, may be called under the atomic_read_lock mutex but
145 * this is not guaranteed. 154 * this is not guaranteed.
146 */ 155 */
147
148static void check_unthrottle(struct tty_struct *tty) 156static void check_unthrottle(struct tty_struct *tty)
149{ 157{
150 if (tty->count) 158 if (tty->count)
@@ -158,6 +166,8 @@ static void check_unthrottle(struct tty_struct *tty)
158 * Reset the read buffer counters, clear the flags, 166 * Reset the read buffer counters, clear the flags,
159 * and make sure the driver is unthrottled. Called 167 * and make sure the driver is unthrottled. Called
160 * from n_tty_open() and n_tty_flush_buffer(). 168 * from n_tty_open() and n_tty_flush_buffer().
169 *
170 * Locking: tty_read_lock for read fields.
161 */ 171 */
162static void reset_buffer_flags(struct tty_struct *tty) 172static void reset_buffer_flags(struct tty_struct *tty)
163{ 173{
@@ -181,7 +191,7 @@ static void reset_buffer_flags(struct tty_struct *tty)
181 * at hangup) or when the N_TTY line discipline internally has to 191 * at hangup) or when the N_TTY line discipline internally has to
182 * clean the pending queue (for example some signals). 192 * clean the pending queue (for example some signals).
183 * 193 *
184 * Locking: ctrl_lock 194 * Locking: ctrl_lock, read_lock.
185 */ 195 */
186 196
187static void n_tty_flush_buffer(struct tty_struct *tty) 197static void n_tty_flush_buffer(struct tty_struct *tty)
@@ -207,6 +217,8 @@ static void n_tty_flush_buffer(struct tty_struct *tty)
207 * 217 *
208 * Report the number of characters buffered to be delivered to user 218 * Report the number of characters buffered to be delivered to user
209 * at this instant in time. 219 * at this instant in time.
220 *
221 * Locking: read_lock
210 */ 222 */
211 223
212static ssize_t n_tty_chars_in_buffer(struct tty_struct *tty) 224static ssize_t n_tty_chars_in_buffer(struct tty_struct *tty)
@@ -346,7 +358,7 @@ static int opost(unsigned char c, struct tty_struct *tty)
346 * the simple cases normally found and helps to generate blocks of 358 * the simple cases normally found and helps to generate blocks of
347 * symbols for the console driver and thus improve performance. 359 * symbols for the console driver and thus improve performance.
348 * 360 *
349 * Called from write_chan under the tty layer write lock. Relies 361 * Called from n_tty_write under the tty layer write lock. Relies
350 * on lock_kernel for the tty->column state. 362 * on lock_kernel for the tty->column state.
351 */ 363 */
352 364
@@ -410,6 +422,8 @@ break_out:
410 * 422 *
411 * Echo user input back onto the screen. This must be called only when 423 * Echo user input back onto the screen. This must be called only when
412 * L_ECHO(tty) is true. Called from the driver receive_buf path. 424 * L_ECHO(tty) is true. Called from the driver receive_buf path.
425 *
426 * Relies on BKL for tty column locking
413 */ 427 */
414 428
415static void echo_char(unsigned char c, struct tty_struct *tty) 429static void echo_char(unsigned char c, struct tty_struct *tty)
@@ -422,6 +436,12 @@ static void echo_char(unsigned char c, struct tty_struct *tty)
422 opost(c, tty); 436 opost(c, tty);
423} 437}
424 438
439/**
440 * finsh_erasing - complete erase
441 * @tty: tty doing the erase
442 *
443 * Relies on BKL for tty column locking
444 */
425static inline void finish_erasing(struct tty_struct *tty) 445static inline void finish_erasing(struct tty_struct *tty)
426{ 446{
427 if (tty->erasing) { 447 if (tty->erasing) {
@@ -439,6 +459,8 @@ static inline void finish_erasing(struct tty_struct *tty)
439 * Perform erase and necessary output when an erase character is 459 * Perform erase and necessary output when an erase character is
440 * present in the stream from the driver layer. Handles the complexities 460 * present in the stream from the driver layer. Handles the complexities
441 * of UTF-8 multibyte symbols. 461 * of UTF-8 multibyte symbols.
462 *
463 * Locking: read_lock for tty buffers, BKL for column/erasing state
442 */ 464 */
443 465
444static void eraser(unsigned char c, struct tty_struct *tty) 466static void eraser(unsigned char c, struct tty_struct *tty)
@@ -447,6 +469,7 @@ static void eraser(unsigned char c, struct tty_struct *tty)
447 int head, seen_alnums, cnt; 469 int head, seen_alnums, cnt;
448 unsigned long flags; 470 unsigned long flags;
449 471
472 /* FIXME: locking needed ? */
450 if (tty->read_head == tty->canon_head) { 473 if (tty->read_head == tty->canon_head) {
451 /* opost('\a', tty); */ /* what do you think? */ 474 /* opost('\a', tty); */ /* what do you think? */
452 return; 475 return;
@@ -481,6 +504,7 @@ static void eraser(unsigned char c, struct tty_struct *tty)
481 } 504 }
482 505
483 seen_alnums = 0; 506 seen_alnums = 0;
507 /* FIXME: Locking ?? */
484 while (tty->read_head != tty->canon_head) { 508 while (tty->read_head != tty->canon_head) {
485 head = tty->read_head; 509 head = tty->read_head;
486 510
@@ -583,6 +607,8 @@ static void eraser(unsigned char c, struct tty_struct *tty)
583 * may caus terminal flushing to take place according to the termios 607 * may caus terminal flushing to take place according to the termios
584 * settings and character used. Called from the driver receive_buf 608 * settings and character used. Called from the driver receive_buf
585 * path so serialized. 609 * path so serialized.
610 *
611 * Locking: ctrl_lock, read_lock (both via flush buffer)
586 */ 612 */
587 613
588static inline void isig(int sig, struct tty_struct *tty, int flush) 614static inline void isig(int sig, struct tty_struct *tty, int flush)
@@ -1007,12 +1033,26 @@ int is_ignored(int sig)
1007 * and is protected from re-entry by the tty layer. The user is 1033 * and is protected from re-entry by the tty layer. The user is
1008 * guaranteed that this function will not be re-entered or in progress 1034 * guaranteed that this function will not be re-entered or in progress
1009 * when the ldisc is closed. 1035 * when the ldisc is closed.
1036 *
1037 * Locking: Caller holds tty->termios_mutex
1010 */ 1038 */
1011 1039
1012static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old) 1040static void n_tty_set_termios(struct tty_struct *tty, struct ktermios *old)
1013{ 1041{
1014 if (!tty) 1042 int canon_change = 1;
1015 return; 1043 BUG_ON(!tty);
1044
1045 if (old)
1046 canon_change = (old->c_lflag ^ tty->termios->c_lflag) & ICANON;
1047 if (canon_change) {
1048 memset(&tty->read_flags, 0, sizeof tty->read_flags);
1049 tty->canon_head = tty->read_tail;
1050 tty->canon_data = 0;
1051 tty->erasing = 0;
1052 }
1053
1054 if (canon_change && !L_ICANON(tty) && tty->read_cnt)
1055 wake_up_interruptible(&tty->read_wait);
1016 1056
1017 tty->icanon = (L_ICANON(tty) != 0); 1057 tty->icanon = (L_ICANON(tty) != 0);
1018 if (test_bit(TTY_HW_COOK_IN, &tty->flags)) { 1058 if (test_bit(TTY_HW_COOK_IN, &tty->flags)) {
@@ -1143,7 +1183,7 @@ static inline int input_available_p(struct tty_struct *tty, int amt)
1143 * @b: user data 1183 * @b: user data
1144 * @nr: size of data 1184 * @nr: size of data
1145 * 1185 *
1146 * Helper function to speed up read_chan. It is only called when 1186 * Helper function to speed up n_tty_read. It is only called when
1147 * ICANON is off; it copies characters straight from the tty queue to 1187 * ICANON is off; it copies characters straight from the tty queue to
1148 * user space directly. It can be profitably called twice; once to 1188 * user space directly. It can be profitably called twice; once to
1149 * drain the space from the tail pointer to the (physical) end of the 1189 * drain the space from the tail pointer to the (physical) end of the
@@ -1210,7 +1250,7 @@ static int job_control(struct tty_struct *tty, struct file *file)
1210 if (file->f_op->write != redirected_tty_write && 1250 if (file->f_op->write != redirected_tty_write &&
1211 current->signal->tty == tty) { 1251 current->signal->tty == tty) {
1212 if (!tty->pgrp) 1252 if (!tty->pgrp)
1213 printk(KERN_ERR "read_chan: no tty->pgrp!\n"); 1253 printk(KERN_ERR "n_tty_read: no tty->pgrp!\n");
1214 else if (task_pgrp(current) != tty->pgrp) { 1254 else if (task_pgrp(current) != tty->pgrp) {
1215 if (is_ignored(SIGTTIN) || 1255 if (is_ignored(SIGTTIN) ||
1216 is_current_pgrp_orphaned()) 1256 is_current_pgrp_orphaned())
@@ -1225,7 +1265,7 @@ static int job_control(struct tty_struct *tty, struct file *file)
1225 1265
1226 1266
1227/** 1267/**
1228 * read_chan - read function for tty 1268 * n_tty_read - read function for tty
1229 * @tty: tty device 1269 * @tty: tty device
1230 * @file: file object 1270 * @file: file object
1231 * @buf: userspace buffer pointer 1271 * @buf: userspace buffer pointer
@@ -1239,7 +1279,7 @@ static int job_control(struct tty_struct *tty, struct file *file)
1239 * This code must be sure never to sleep through a hangup. 1279 * This code must be sure never to sleep through a hangup.
1240 */ 1280 */
1241 1281
1242static ssize_t read_chan(struct tty_struct *tty, struct file *file, 1282static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
1243 unsigned char __user *buf, size_t nr) 1283 unsigned char __user *buf, size_t nr)
1244{ 1284{
1245 unsigned char __user *b = buf; 1285 unsigned char __user *b = buf;
@@ -1254,10 +1294,7 @@ static ssize_t read_chan(struct tty_struct *tty, struct file *file,
1254 1294
1255do_it_again: 1295do_it_again:
1256 1296
1257 if (!tty->read_buf) { 1297 BUG_ON(!tty->read_buf);
1258 printk(KERN_ERR "n_tty_read_chan: read_buf == NULL?!?\n");
1259 return -EIO;
1260 }
1261 1298
1262 c = job_control(tty, file); 1299 c = job_control(tty, file);
1263 if (c < 0) 1300 if (c < 0)
@@ -1444,7 +1481,7 @@ do_it_again:
1444} 1481}
1445 1482
1446/** 1483/**
1447 * write_chan - write function for tty 1484 * n_tty_write - write function for tty
1448 * @tty: tty device 1485 * @tty: tty device
1449 * @file: file object 1486 * @file: file object
1450 * @buf: userspace buffer pointer 1487 * @buf: userspace buffer pointer
@@ -1458,7 +1495,7 @@ do_it_again:
1458 * This code must be sure never to sleep through a hangup. 1495 * This code must be sure never to sleep through a hangup.
1459 */ 1496 */
1460 1497
1461static ssize_t write_chan(struct tty_struct *tty, struct file *file, 1498static ssize_t n_tty_write(struct tty_struct *tty, struct file *file,
1462 const unsigned char *buf, size_t nr) 1499 const unsigned char *buf, size_t nr)
1463{ 1500{
1464 const unsigned char *b = buf; 1501 const unsigned char *b = buf;
@@ -1532,7 +1569,7 @@ break_out:
1532} 1569}
1533 1570
1534/** 1571/**
1535 * normal_poll - poll method for N_TTY 1572 * n_tty_poll - poll method for N_TTY
1536 * @tty: terminal device 1573 * @tty: terminal device
1537 * @file: file accessing it 1574 * @file: file accessing it
1538 * @wait: poll table 1575 * @wait: poll table
@@ -1545,7 +1582,7 @@ break_out:
1545 * Called without the kernel lock held - fine 1582 * Called without the kernel lock held - fine
1546 */ 1583 */
1547 1584
1548static unsigned int normal_poll(struct tty_struct *tty, struct file *file, 1585static unsigned int n_tty_poll(struct tty_struct *tty, struct file *file,
1549 poll_table *wait) 1586 poll_table *wait)
1550{ 1587{
1551 unsigned int mask = 0; 1588 unsigned int mask = 0;
@@ -1573,6 +1610,44 @@ static unsigned int normal_poll(struct tty_struct *tty, struct file *file,
1573 return mask; 1610 return mask;
1574} 1611}
1575 1612
1613static unsigned long inq_canon(struct tty_struct *tty)
1614{
1615 int nr, head, tail;
1616
1617 if (!tty->canon_data)
1618 return 0;
1619 head = tty->canon_head;
1620 tail = tty->read_tail;
1621 nr = (head - tail) & (N_TTY_BUF_SIZE-1);
1622 /* Skip EOF-chars.. */
1623 while (head != tail) {
1624 if (test_bit(tail, tty->read_flags) &&
1625 tty->read_buf[tail] == __DISABLED_CHAR)
1626 nr--;
1627 tail = (tail+1) & (N_TTY_BUF_SIZE-1);
1628 }
1629 return nr;
1630}
1631
1632static int n_tty_ioctl(struct tty_struct *tty, struct file *file,
1633 unsigned int cmd, unsigned long arg)
1634{
1635 int retval;
1636
1637 switch (cmd) {
1638 case TIOCOUTQ:
1639 return put_user(tty_chars_in_buffer(tty), (int __user *) arg);
1640 case TIOCINQ:
1641 /* FIXME: Locking */
1642 retval = tty->read_cnt;
1643 if (L_ICANON(tty))
1644 retval = inq_canon(tty);
1645 return put_user(retval, (unsigned int __user *) arg);
1646 default:
1647 return n_tty_ioctl_helper(tty, file, cmd, arg);
1648 }
1649}
1650
1576struct tty_ldisc_ops tty_ldisc_N_TTY = { 1651struct tty_ldisc_ops tty_ldisc_N_TTY = {
1577 .magic = TTY_LDISC_MAGIC, 1652 .magic = TTY_LDISC_MAGIC,
1578 .name = "n_tty", 1653 .name = "n_tty",
@@ -1580,11 +1655,11 @@ struct tty_ldisc_ops tty_ldisc_N_TTY = {
1580 .close = n_tty_close, 1655 .close = n_tty_close,
1581 .flush_buffer = n_tty_flush_buffer, 1656 .flush_buffer = n_tty_flush_buffer,
1582 .chars_in_buffer = n_tty_chars_in_buffer, 1657 .chars_in_buffer = n_tty_chars_in_buffer,
1583 .read = read_chan, 1658 .read = n_tty_read,
1584 .write = write_chan, 1659 .write = n_tty_write,
1585 .ioctl = n_tty_ioctl, 1660 .ioctl = n_tty_ioctl,
1586 .set_termios = n_tty_set_termios, 1661 .set_termios = n_tty_set_termios,
1587 .poll = normal_poll, 1662 .poll = n_tty_poll,
1588 .receive_buf = n_tty_receive_buf, 1663 .receive_buf = n_tty_receive_buf,
1589 .write_wakeup = n_tty_write_wakeup 1664 .write_wakeup = n_tty_write_wakeup
1590}; 1665};
diff --git a/drivers/char/nozomi.c b/drivers/char/nozomi.c
index 66a0f931c66c..9a34a1935283 100644
--- a/drivers/char/nozomi.c
+++ b/drivers/char/nozomi.c
@@ -1599,7 +1599,10 @@ static int ntty_open(struct tty_struct *tty, struct file *file)
1599 return 0; 1599 return 0;
1600} 1600}
1601 1601
1602/* Called when the userspace process close the tty, /dev/noz*. */ 1602/* Called when the userspace process close the tty, /dev/noz*. Also
1603 called immediately if ntty_open fails in which case tty->driver_data
1604 will be NULL an we exit by the first return */
1605
1603static void ntty_close(struct tty_struct *tty, struct file *file) 1606static void ntty_close(struct tty_struct *tty, struct file *file)
1604{ 1607{
1605 struct nozomi *dc = get_dc_by_tty(tty); 1608 struct nozomi *dc = get_dc_by_tty(tty);
diff --git a/drivers/char/pcmcia/cm4000_cs.c b/drivers/char/pcmcia/cm4000_cs.c
index f070ae7bd91a..dbb912574569 100644
--- a/drivers/char/pcmcia/cm4000_cs.c
+++ b/drivers/char/pcmcia/cm4000_cs.c
@@ -1759,65 +1759,40 @@ static void cmm_cm4000_release(struct pcmcia_device * link)
1759 1759
1760/*==== Interface to PCMCIA Layer =======================================*/ 1760/*==== Interface to PCMCIA Layer =======================================*/
1761 1761
1762static int cm4000_config_check(struct pcmcia_device *p_dev,
1763 cistpl_cftable_entry_t *cfg,
1764 cistpl_cftable_entry_t *dflt,
1765 unsigned int vcc,
1766 void *priv_data)
1767{
1768 if (!cfg->io.nwin)
1769 return -ENODEV;
1770
1771 /* Get the IOaddr */
1772 p_dev->io.BasePort1 = cfg->io.win[0].base;
1773 p_dev->io.NumPorts1 = cfg->io.win[0].len;
1774 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
1775 if (!(cfg->io.flags & CISTPL_IO_8BIT))
1776 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
1777 if (!(cfg->io.flags & CISTPL_IO_16BIT))
1778 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
1779 p_dev->io.IOAddrLines = cfg->io.flags & CISTPL_IO_LINES_MASK;
1780
1781 return pcmcia_request_io(p_dev, &p_dev->io);
1782}
1783
1762static int cm4000_config(struct pcmcia_device * link, int devno) 1784static int cm4000_config(struct pcmcia_device * link, int devno)
1763{ 1785{
1764 struct cm4000_dev *dev; 1786 struct cm4000_dev *dev;
1765 tuple_t tuple;
1766 cisparse_t parse;
1767 u_char buf[64];
1768 int fail_fn, fail_rc;
1769 int rc;
1770 1787
1771 /* read the config-tuples */ 1788 /* read the config-tuples */
1772 tuple.Attributes = 0; 1789 if (pcmcia_loop_config(link, cm4000_config_check, NULL))
1773 tuple.TupleData = buf;
1774 tuple.TupleDataMax = sizeof(buf);
1775 tuple.TupleOffset = 0;
1776
1777 link->io.BasePort2 = 0;
1778 link->io.NumPorts2 = 0;
1779 link->io.Attributes2 = 0;
1780 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
1781 for (rc = pcmcia_get_first_tuple(link, &tuple);
1782 rc == CS_SUCCESS; rc = pcmcia_get_next_tuple(link, &tuple)) {
1783
1784 rc = pcmcia_get_tuple_data(link, &tuple);
1785 if (rc != CS_SUCCESS)
1786 continue;
1787 rc = pcmcia_parse_tuple(link, &tuple, &parse);
1788 if (rc != CS_SUCCESS)
1789 continue;
1790
1791 link->conf.ConfigIndex = parse.cftable_entry.index;
1792
1793 if (!parse.cftable_entry.io.nwin)
1794 continue;
1795
1796 /* Get the IOaddr */
1797 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
1798 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
1799 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
1800 if (!(parse.cftable_entry.io.flags & CISTPL_IO_8BIT))
1801 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
1802 if (!(parse.cftable_entry.io.flags & CISTPL_IO_16BIT))
1803 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
1804 link->io.IOAddrLines = parse.cftable_entry.io.flags
1805 & CISTPL_IO_LINES_MASK;
1806
1807 rc = pcmcia_request_io(link, &link->io);
1808 if (rc == CS_SUCCESS)
1809 break; /* we are done */
1810 }
1811 if (rc != CS_SUCCESS)
1812 goto cs_release; 1790 goto cs_release;
1813 1791
1814 link->conf.IntType = 00000002; 1792 link->conf.IntType = 00000002;
1815 1793
1816 if ((fail_rc = 1794 if (pcmcia_request_configuration(link, &link->conf))
1817 pcmcia_request_configuration(link, &link->conf)) != CS_SUCCESS) {
1818 fail_fn = RequestConfiguration;
1819 goto cs_release; 1795 goto cs_release;
1820 }
1821 1796
1822 dev = link->priv; 1797 dev = link->priv;
1823 sprintf(dev->node.dev_name, DEVICE_NAME "%d", devno); 1798 sprintf(dev->node.dev_name, DEVICE_NAME "%d", devno);
@@ -1896,7 +1871,7 @@ static int cm4000_probe(struct pcmcia_device *link)
1896 return ret; 1871 return ret;
1897 } 1872 }
1898 1873
1899 device_create_drvdata(cmm_class, NULL, MKDEV(major, i), NULL, "cmm%d", i); 1874 device_create(cmm_class, NULL, MKDEV(major, i), NULL, "cmm%d", i);
1900 1875
1901 return 0; 1876 return 0;
1902} 1877}
diff --git a/drivers/char/pcmcia/cm4040_cs.c b/drivers/char/pcmcia/cm4040_cs.c
index 0b5934bef7a4..4f0723b07974 100644
--- a/drivers/char/pcmcia/cm4040_cs.c
+++ b/drivers/char/pcmcia/cm4040_cs.c
@@ -526,65 +526,49 @@ static void cm4040_reader_release(struct pcmcia_device *link)
526 return; 526 return;
527} 527}
528 528
529static int reader_config(struct pcmcia_device *link, int devno) 529static int cm4040_config_check(struct pcmcia_device *p_dev,
530 cistpl_cftable_entry_t *cfg,
531 cistpl_cftable_entry_t *dflt,
532 unsigned int vcc,
533 void *priv_data)
530{ 534{
531 struct reader_dev *dev;
532 tuple_t tuple;
533 cisparse_t parse;
534 u_char buf[64];
535 int fail_fn, fail_rc;
536 int rc; 535 int rc;
536 if (!cfg->io.nwin)
537 return -ENODEV;
538
539 /* Get the IOaddr */
540 p_dev->io.BasePort1 = cfg->io.win[0].base;
541 p_dev->io.NumPorts1 = cfg->io.win[0].len;
542 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
543 if (!(cfg->io.flags & CISTPL_IO_8BIT))
544 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
545 if (!(cfg->io.flags & CISTPL_IO_16BIT))
546 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
547 p_dev->io.IOAddrLines = cfg->io.flags & CISTPL_IO_LINES_MASK;
548
549 rc = pcmcia_request_io(p_dev, &p_dev->io);
550 dev_printk(KERN_INFO, &handle_to_dev(p_dev),
551 "pcmcia_request_io returned 0x%x\n", rc);
552 return rc;
553}
554
537 555
538 tuple.Attributes = 0; 556static int reader_config(struct pcmcia_device *link, int devno)
539 tuple.TupleData = buf; 557{
540 tuple.TupleDataMax = sizeof(buf); 558 struct reader_dev *dev;
541 tuple.TupleOffset = 0; 559 int fail_rc;
542 560
543 link->io.BasePort2 = 0; 561 link->io.BasePort2 = 0;
544 link->io.NumPorts2 = 0; 562 link->io.NumPorts2 = 0;
545 link->io.Attributes2 = 0; 563 link->io.Attributes2 = 0;
546 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 564
547 for (rc = pcmcia_get_first_tuple(link, &tuple); 565 if (pcmcia_loop_config(link, cm4040_config_check, NULL))
548 rc == CS_SUCCESS;
549 rc = pcmcia_get_next_tuple(link, &tuple)) {
550 rc = pcmcia_get_tuple_data(link, &tuple);
551 if (rc != CS_SUCCESS)
552 continue;
553 rc = pcmcia_parse_tuple(link, &tuple, &parse);
554 if (rc != CS_SUCCESS)
555 continue;
556
557 link->conf.ConfigIndex = parse.cftable_entry.index;
558
559 if (!parse.cftable_entry.io.nwin)
560 continue;
561
562 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
563 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
564 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
565 if (!(parse.cftable_entry.io.flags & CISTPL_IO_8BIT))
566 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
567 if (!(parse.cftable_entry.io.flags & CISTPL_IO_16BIT))
568 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
569 link->io.IOAddrLines = parse.cftable_entry.io.flags
570 & CISTPL_IO_LINES_MASK;
571 rc = pcmcia_request_io(link, &link->io);
572
573 dev_printk(KERN_INFO, &handle_to_dev(link), "foo");
574 if (rc == CS_SUCCESS)
575 break;
576 else
577 dev_printk(KERN_INFO, &handle_to_dev(link),
578 "pcmcia_request_io failed 0x%x\n", rc);
579 }
580 if (rc != CS_SUCCESS)
581 goto cs_release; 566 goto cs_release;
582 567
583 link->conf.IntType = 00000002; 568 link->conf.IntType = 00000002;
584 569
585 if ((fail_rc = pcmcia_request_configuration(link,&link->conf)) 570 fail_rc = pcmcia_request_configuration(link, &link->conf);
586 !=CS_SUCCESS) { 571 if (fail_rc != 0) {
587 fail_fn = RequestConfiguration;
588 dev_printk(KERN_INFO, &handle_to_dev(link), 572 dev_printk(KERN_INFO, &handle_to_dev(link),
589 "pcmcia_request_configuration failed 0x%x\n", 573 "pcmcia_request_configuration failed 0x%x\n",
590 fail_rc); 574 fail_rc);
@@ -653,8 +637,7 @@ static int reader_probe(struct pcmcia_device *link)
653 return ret; 637 return ret;
654 } 638 }
655 639
656 device_create_drvdata(cmx_class, NULL, MKDEV(major, i), NULL, 640 device_create(cmx_class, NULL, MKDEV(major, i), NULL, "cmx%d", i);
657 "cmx%d", i);
658 641
659 return 0; 642 return 0;
660} 643}
diff --git a/drivers/char/pcmcia/ipwireless/main.c b/drivers/char/pcmcia/ipwireless/main.c
index 5eca7a99afe6..5216fce0c62d 100644
--- a/drivers/char/pcmcia/ipwireless/main.c
+++ b/drivers/char/pcmcia/ipwireless/main.c
@@ -65,9 +65,9 @@ static void signalled_reboot_work(struct work_struct *work_reboot)
65 struct ipw_dev *ipw = container_of(work_reboot, struct ipw_dev, 65 struct ipw_dev *ipw = container_of(work_reboot, struct ipw_dev,
66 work_reboot); 66 work_reboot);
67 struct pcmcia_device *link = ipw->link; 67 struct pcmcia_device *link = ipw->link;
68 int ret = pccard_reset_card(link->socket); 68 int ret = pcmcia_reset_card(link->socket);
69 69
70 if (ret != CS_SUCCESS) 70 if (ret != 0)
71 cs_error(link, ResetCard, ret); 71 cs_error(link, ResetCard, ret);
72} 72}
73 73
@@ -83,7 +83,6 @@ static int config_ipwireless(struct ipw_dev *ipw)
83{ 83{
84 struct pcmcia_device *link = ipw->link; 84 struct pcmcia_device *link = ipw->link;
85 int ret; 85 int ret;
86 config_info_t conf;
87 tuple_t tuple; 86 tuple_t tuple;
88 unsigned short buf[64]; 87 unsigned short buf[64];
89 cisparse_t parse; 88 cisparse_t parse;
@@ -105,7 +104,7 @@ static int config_ipwireless(struct ipw_dev *ipw)
105 while (ret == 0) { 104 while (ret == 0) {
106 ret = pcmcia_get_tuple_data(link, &tuple); 105 ret = pcmcia_get_tuple_data(link, &tuple);
107 106
108 if (ret != CS_SUCCESS) { 107 if (ret != 0) {
109 cs_error(link, GetTupleData, ret); 108 cs_error(link, GetTupleData, ret);
110 goto exit0; 109 goto exit0;
111 } 110 }
@@ -116,21 +115,21 @@ static int config_ipwireless(struct ipw_dev *ipw)
116 115
117 ret = pcmcia_get_first_tuple(link, &tuple); 116 ret = pcmcia_get_first_tuple(link, &tuple);
118 117
119 if (ret != CS_SUCCESS) { 118 if (ret != 0) {
120 cs_error(link, GetFirstTuple, ret); 119 cs_error(link, GetFirstTuple, ret);
121 goto exit0; 120 goto exit0;
122 } 121 }
123 122
124 ret = pcmcia_get_tuple_data(link, &tuple); 123 ret = pcmcia_get_tuple_data(link, &tuple);
125 124
126 if (ret != CS_SUCCESS) { 125 if (ret != 0) {
127 cs_error(link, GetTupleData, ret); 126 cs_error(link, GetTupleData, ret);
128 goto exit0; 127 goto exit0;
129 } 128 }
130 129
131 ret = pcmcia_parse_tuple(link, &tuple, &parse); 130 ret = pcmcia_parse_tuple(&tuple, &parse);
132 131
133 if (ret != CS_SUCCESS) { 132 if (ret != 0) {
134 cs_error(link, ParseTuple, ret); 133 cs_error(link, ParseTuple, ret);
135 goto exit0; 134 goto exit0;
136 } 135 }
@@ -152,21 +151,21 @@ static int config_ipwireless(struct ipw_dev *ipw)
152 151
153 ret = pcmcia_get_first_tuple(link, &tuple); 152 ret = pcmcia_get_first_tuple(link, &tuple);
154 153
155 if (ret != CS_SUCCESS) { 154 if (ret != 0) {
156 cs_error(link, GetFirstTuple, ret); 155 cs_error(link, GetFirstTuple, ret);
157 goto exit0; 156 goto exit0;
158 } 157 }
159 158
160 ret = pcmcia_get_tuple_data(link, &tuple); 159 ret = pcmcia_get_tuple_data(link, &tuple);
161 160
162 if (ret != CS_SUCCESS) { 161 if (ret != 0) {
163 cs_error(link, GetTupleData, ret); 162 cs_error(link, GetTupleData, ret);
164 goto exit0; 163 goto exit0;
165 } 164 }
166 165
167 ret = pcmcia_parse_tuple(link, &tuple, &parse); 166 ret = pcmcia_parse_tuple(&tuple, &parse);
168 167
169 if (ret != CS_SUCCESS) { 168 if (ret != 0) {
170 cs_error(link, GetTupleData, ret); 169 cs_error(link, GetTupleData, ret);
171 goto exit0; 170 goto exit0;
172 } 171 }
@@ -181,7 +180,7 @@ static int config_ipwireless(struct ipw_dev *ipw)
181 180
182 ret = pcmcia_request_io(link, &link->io); 181 ret = pcmcia_request_io(link, &link->io);
183 182
184 if (ret != CS_SUCCESS) { 183 if (ret != 0) {
185 cs_error(link, RequestIO, ret); 184 cs_error(link, RequestIO, ret);
186 goto exit0; 185 goto exit0;
187 } 186 }
@@ -195,21 +194,21 @@ static int config_ipwireless(struct ipw_dev *ipw)
195 194
196 ret = pcmcia_get_first_tuple(link, &tuple); 195 ret = pcmcia_get_first_tuple(link, &tuple);
197 196
198 if (ret != CS_SUCCESS) { 197 if (ret != 0) {
199 cs_error(link, GetFirstTuple, ret); 198 cs_error(link, GetFirstTuple, ret);
200 goto exit1; 199 goto exit1;
201 } 200 }
202 201
203 ret = pcmcia_get_tuple_data(link, &tuple); 202 ret = pcmcia_get_tuple_data(link, &tuple);
204 203
205 if (ret != CS_SUCCESS) { 204 if (ret != 0) {
206 cs_error(link, GetTupleData, ret); 205 cs_error(link, GetTupleData, ret);
207 goto exit1; 206 goto exit1;
208 } 207 }
209 208
210 ret = pcmcia_parse_tuple(link, &tuple, &parse); 209 ret = pcmcia_parse_tuple(&tuple, &parse);
211 210
212 if (ret != CS_SUCCESS) { 211 if (ret != 0) {
213 cs_error(link, ParseTuple, ret); 212 cs_error(link, ParseTuple, ret);
214 goto exit1; 213 goto exit1;
215 } 214 }
@@ -227,7 +226,7 @@ static int config_ipwireless(struct ipw_dev *ipw)
227 ret = pcmcia_request_window(&link, &ipw->request_common_memory, 226 ret = pcmcia_request_window(&link, &ipw->request_common_memory,
228 &ipw->handle_common_memory); 227 &ipw->handle_common_memory);
229 228
230 if (ret != CS_SUCCESS) { 229 if (ret != 0) {
231 cs_error(link, RequestWindow, ret); 230 cs_error(link, RequestWindow, ret);
232 goto exit1; 231 goto exit1;
233 } 232 }
@@ -239,7 +238,7 @@ static int config_ipwireless(struct ipw_dev *ipw)
239 ret = pcmcia_map_mem_page(ipw->handle_common_memory, 238 ret = pcmcia_map_mem_page(ipw->handle_common_memory,
240 &memreq_common_memory); 239 &memreq_common_memory);
241 240
242 if (ret != CS_SUCCESS) { 241 if (ret != 0) {
243 cs_error(link, MapMemPage, ret); 242 cs_error(link, MapMemPage, ret);
244 goto exit1; 243 goto exit1;
245 } 244 }
@@ -261,7 +260,7 @@ static int config_ipwireless(struct ipw_dev *ipw)
261 ret = pcmcia_request_window(&link, &ipw->request_attr_memory, 260 ret = pcmcia_request_window(&link, &ipw->request_attr_memory,
262 &ipw->handle_attr_memory); 261 &ipw->handle_attr_memory);
263 262
264 if (ret != CS_SUCCESS) { 263 if (ret != 0) {
265 cs_error(link, RequestWindow, ret); 264 cs_error(link, RequestWindow, ret);
266 goto exit2; 265 goto exit2;
267 } 266 }
@@ -272,7 +271,7 @@ static int config_ipwireless(struct ipw_dev *ipw)
272 ret = pcmcia_map_mem_page(ipw->handle_attr_memory, 271 ret = pcmcia_map_mem_page(ipw->handle_attr_memory,
273 &memreq_attr_memory); 272 &memreq_attr_memory);
274 273
275 if (ret != CS_SUCCESS) { 274 if (ret != 0) {
276 cs_error(link, MapMemPage, ret); 275 cs_error(link, MapMemPage, ret);
277 goto exit2; 276 goto exit2;
278 } 277 }
@@ -292,20 +291,11 @@ static int config_ipwireless(struct ipw_dev *ipw)
292 291
293 ret = pcmcia_request_irq(link, &link->irq); 292 ret = pcmcia_request_irq(link, &link->irq);
294 293
295 if (ret != CS_SUCCESS) { 294 if (ret != 0) {
296 cs_error(link, RequestIRQ, ret); 295 cs_error(link, RequestIRQ, ret);
297 goto exit3; 296 goto exit3;
298 } 297 }
299 298
300 /* Look up current Vcc */
301
302 ret = pcmcia_get_configuration_info(link, &conf);
303
304 if (ret != CS_SUCCESS) {
305 cs_error(link, GetConfigurationInfo, ret);
306 goto exit4;
307 }
308
309 printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": Card type %s\n", 299 printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": Card type %s\n",
310 ipw->is_v2_card ? "V2/V3" : "V1"); 300 ipw->is_v2_card ? "V2/V3" : "V1");
311 printk(KERN_INFO IPWIRELESS_PCCARD_NAME 301 printk(KERN_INFO IPWIRELESS_PCCARD_NAME
@@ -341,7 +331,7 @@ static int config_ipwireless(struct ipw_dev *ipw)
341 */ 331 */
342 ret = pcmcia_request_configuration(link, &link->conf); 332 ret = pcmcia_request_configuration(link, &link->conf);
343 333
344 if (ret != CS_SUCCESS) { 334 if (ret != 0) {
345 cs_error(link, RequestConfiguration, ret); 335 cs_error(link, RequestConfiguration, ret);
346 goto exit4; 336 goto exit4;
347 } 337 }
diff --git a/drivers/char/pcmcia/ipwireless/tty.c b/drivers/char/pcmcia/ipwireless/tty.c
index 3a23e7694d55..569f2f7743a7 100644
--- a/drivers/char/pcmcia/ipwireless/tty.c
+++ b/drivers/char/pcmcia/ipwireless/tty.c
@@ -276,6 +276,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
276 struct ipw_tty *tty = linux_tty->driver_data; 276 struct ipw_tty *tty = linux_tty->driver_data;
277 int room; 277 int room;
278 278
279 /* FIXME: Exactly how is the tty object locked here .. */
279 if (!tty) 280 if (!tty)
280 return -ENODEV; 281 return -ENODEV;
281 282
@@ -397,6 +398,7 @@ static int set_control_lines(struct ipw_tty *tty, unsigned int set,
397static int ipw_tiocmget(struct tty_struct *linux_tty, struct file *file) 398static int ipw_tiocmget(struct tty_struct *linux_tty, struct file *file)
398{ 399{
399 struct ipw_tty *tty = linux_tty->driver_data; 400 struct ipw_tty *tty = linux_tty->driver_data;
401 /* FIXME: Exactly how is the tty object locked here .. */
400 402
401 if (!tty) 403 if (!tty)
402 return -ENODEV; 404 return -ENODEV;
@@ -412,6 +414,7 @@ ipw_tiocmset(struct tty_struct *linux_tty, struct file *file,
412 unsigned int set, unsigned int clear) 414 unsigned int set, unsigned int clear)
413{ 415{
414 struct ipw_tty *tty = linux_tty->driver_data; 416 struct ipw_tty *tty = linux_tty->driver_data;
417 /* FIXME: Exactly how is the tty object locked here .. */
415 418
416 if (!tty) 419 if (!tty)
417 return -ENODEV; 420 return -ENODEV;
@@ -433,6 +436,8 @@ static int ipw_ioctl(struct tty_struct *linux_tty, struct file *file,
433 if (!tty->open_count) 436 if (!tty->open_count)
434 return -EINVAL; 437 return -EINVAL;
435 438
439 /* FIXME: Exactly how is the tty object locked here .. */
440
436 switch (cmd) { 441 switch (cmd) {
437 case TIOCGSERIAL: 442 case TIOCGSERIAL:
438 return ipwireless_get_serial_info(tty, (void __user *) arg); 443 return ipwireless_get_serial_info(tty, (void __user *) arg);
@@ -467,13 +472,6 @@ static int ipw_ioctl(struct tty_struct *linux_tty, struct file *file,
467 } 472 }
468 return 0; 473 return 0;
469 474
470 case TCGETS:
471 case TCGETA:
472 return n_tty_ioctl(linux_tty, file, cmd, arg);
473
474 case TCFLSH:
475 return n_tty_ioctl(linux_tty, file, cmd, arg);
476
477 case FIONREAD: 475 case FIONREAD:
478 { 476 {
479 int val = 0; 477 int val = 0;
@@ -482,10 +480,11 @@ static int ipw_ioctl(struct tty_struct *linux_tty, struct file *file,
482 return -EFAULT; 480 return -EFAULT;
483 } 481 }
484 return 0; 482 return 0;
483 case TCFLSH:
484 return tty_perform_flush(linux_tty, arg);
485 } 485 }
486 } 486 }
487 487 return tty_mode_ioctl(linux_tty, file, cmd , arg);
488 return -ENOIOCTLCMD;
489} 488}
490 489
491static int add_tty(dev_node_t *nodesp, int j, 490static int add_tty(dev_node_t *nodesp, int j,
@@ -588,6 +587,8 @@ void ipwireless_tty_free(struct ipw_tty *tty)
588 tty_hangup(ttyj->linux_tty); 587 tty_hangup(ttyj->linux_tty);
589 /* Wait till the tty_hangup has completed */ 588 /* Wait till the tty_hangup has completed */
590 flush_scheduled_work(); 589 flush_scheduled_work();
590 /* FIXME: Exactly how is the tty object locked here
591 against a parallel ioctl etc */
591 mutex_lock(&ttyj->ipw_tty_mutex); 592 mutex_lock(&ttyj->ipw_tty_mutex);
592 } 593 }
593 while (ttyj->open_count) 594 while (ttyj->open_count)
diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
index c240562c218b..9a626e50b793 100644
--- a/drivers/char/pcmcia/synclink_cs.c
+++ b/drivers/char/pcmcia/synclink_cs.c
@@ -601,7 +601,7 @@ static int mgslpc_config(struct pcmcia_device *link)
601 601
602 cfg = &(parse.cftable_entry); 602 cfg = &(parse.cftable_entry);
603 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple)); 603 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
604 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse)); 604 CS_CHECK(ParseTuple, pcmcia_parse_tuple(&tuple, &parse));
605 605
606 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; 606 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
607 if (cfg->index == 0) 607 if (cfg->index == 0)
diff --git a/drivers/char/ppdev.c b/drivers/char/ppdev.c
index bee39fdfba73..c84c34fb1231 100644
--- a/drivers/char/ppdev.c
+++ b/drivers/char/ppdev.c
@@ -760,9 +760,8 @@ static const struct file_operations pp_fops = {
760 760
761static void pp_attach(struct parport *port) 761static void pp_attach(struct parport *port)
762{ 762{
763 device_create_drvdata(ppdev_class, port->dev, 763 device_create(ppdev_class, port->dev, MKDEV(PP_MAJOR, port->number),
764 MKDEV(PP_MAJOR, port->number), 764 NULL, "parport%d", port->number);
765 NULL, "parport%d", port->number);
766} 765}
767 766
768static void pp_detach(struct parport *port) 767static void pp_detach(struct parport *port)
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index 76b27932d229..6d4582712b1f 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -8,10 +8,12 @@
8 * Added TTY_DO_WRITE_WAKEUP to enable n_tty to send POLL_OUT to 8 * Added TTY_DO_WRITE_WAKEUP to enable n_tty to send POLL_OUT to
9 * waiting writers -- Sapan Bhatia <sapan@corewars.org> 9 * waiting writers -- Sapan Bhatia <sapan@corewars.org>
10 * 10 *
11 * 11 * When reading this code see also fs/devpts. In particular note that the
12 * driver_data field is used by the devpts side as a binding to the devpts
13 * inode.
12 */ 14 */
13 15
14#include <linux/module.h> /* For EXPORT_SYMBOL */ 16#include <linux/module.h>
15 17
16#include <linux/errno.h> 18#include <linux/errno.h>
17#include <linux/interrupt.h> 19#include <linux/interrupt.h>
@@ -23,26 +25,25 @@
23#include <linux/mm.h> 25#include <linux/mm.h>
24#include <linux/init.h> 26#include <linux/init.h>
25#include <linux/sysctl.h> 27#include <linux/sysctl.h>
26 28#include <linux/device.h>
27#include <asm/uaccess.h> 29#include <linux/uaccess.h>
28#include <asm/system.h>
29#include <linux/bitops.h> 30#include <linux/bitops.h>
30#include <linux/devpts_fs.h> 31#include <linux/devpts_fs.h>
31 32
33#include <asm/system.h>
34
32/* These are global because they are accessed in tty_io.c */ 35/* These are global because they are accessed in tty_io.c */
33#ifdef CONFIG_UNIX98_PTYS 36#ifdef CONFIG_UNIX98_PTYS
34struct tty_driver *ptm_driver; 37struct tty_driver *ptm_driver;
35static struct tty_driver *pts_driver; 38static struct tty_driver *pts_driver;
36#endif 39#endif
37 40
38static void pty_close(struct tty_struct * tty, struct file * filp) 41static void pty_close(struct tty_struct *tty, struct file *filp)
39{ 42{
40 if (!tty) 43 BUG_ON(!tty);
41 return; 44 if (tty->driver->subtype == PTY_TYPE_MASTER)
42 if (tty->driver->subtype == PTY_TYPE_MASTER) { 45 WARN_ON(tty->count > 1);
43 if (tty->count > 1) 46 else {
44 printk("master pty_close: count = %d!!\n", tty->count);
45 } else {
46 if (tty->count > 2) 47 if (tty->count > 2)
47 return; 48 return;
48 } 49 }
@@ -59,7 +60,7 @@ static void pty_close(struct tty_struct * tty, struct file * filp)
59 set_bit(TTY_OTHER_CLOSED, &tty->flags); 60 set_bit(TTY_OTHER_CLOSED, &tty->flags);
60#ifdef CONFIG_UNIX98_PTYS 61#ifdef CONFIG_UNIX98_PTYS
61 if (tty->driver == ptm_driver) 62 if (tty->driver == ptm_driver)
62 devpts_pty_kill(tty->index); 63 devpts_pty_kill(tty->link);
63#endif 64#endif
64 tty_vhangup(tty->link); 65 tty_vhangup(tty->link);
65 } 66 }
@@ -69,13 +70,13 @@ static void pty_close(struct tty_struct * tty, struct file * filp)
69 * The unthrottle routine is called by the line discipline to signal 70 * The unthrottle routine is called by the line discipline to signal
70 * that it can receive more characters. For PTY's, the TTY_THROTTLED 71 * that it can receive more characters. For PTY's, the TTY_THROTTLED
71 * flag is always set, to force the line discipline to always call the 72 * flag is always set, to force the line discipline to always call the
72 * unthrottle routine when there are fewer than TTY_THRESHOLD_UNTHROTTLE 73 * unthrottle routine when there are fewer than TTY_THRESHOLD_UNTHROTTLE
73 * characters in the queue. This is necessary since each time this 74 * characters in the queue. This is necessary since each time this
74 * happens, we need to wake up any sleeping processes that could be 75 * happens, we need to wake up any sleeping processes that could be
75 * (1) trying to send data to the pty, or (2) waiting in wait_until_sent() 76 * (1) trying to send data to the pty, or (2) waiting in wait_until_sent()
76 * for the pty buffer to be drained. 77 * for the pty buffer to be drained.
77 */ 78 */
78static void pty_unthrottle(struct tty_struct * tty) 79static void pty_unthrottle(struct tty_struct *tty)
79{ 80{
80 struct tty_struct *o_tty = tty->link; 81 struct tty_struct *o_tty = tty->link;
81 82
@@ -87,7 +88,7 @@ static void pty_unthrottle(struct tty_struct * tty)
87} 88}
88 89
89/* 90/*
90 * WSH 05/24/97: modified to 91 * WSH 05/24/97: modified to
91 * (1) use space in tty->flip instead of a shared temp buffer 92 * (1) use space in tty->flip instead of a shared temp buffer
92 * The flip buffers aren't being used for a pty, so there's lots 93 * The flip buffers aren't being used for a pty, so there's lots
93 * of space available. The buffer is protected by a per-pty 94 * of space available. The buffer is protected by a per-pty
@@ -100,7 +101,8 @@ static void pty_unthrottle(struct tty_struct * tty)
100 * not our partners. We can't just take the other one blindly without 101 * not our partners. We can't just take the other one blindly without
101 * risking deadlocks. 102 * risking deadlocks.
102 */ 103 */
103static int pty_write(struct tty_struct * tty, const unsigned char *buf, int count) 104static int pty_write(struct tty_struct *tty, const unsigned char *buf,
105 int count)
104{ 106{
105 struct tty_struct *to = tty->link; 107 struct tty_struct *to = tty->link;
106 int c; 108 int c;
@@ -112,7 +114,7 @@ static int pty_write(struct tty_struct * tty, const unsigned char *buf, int coun
112 if (c > count) 114 if (c > count)
113 c = count; 115 c = count;
114 to->ldisc.ops->receive_buf(to, buf, NULL, c); 116 to->ldisc.ops->receive_buf(to, buf, NULL, c);
115 117
116 return c; 118 return c;
117} 119}
118 120
@@ -128,17 +130,17 @@ static int pty_write_room(struct tty_struct *tty)
128 130
129/* 131/*
130 * WSH 05/24/97: Modified for asymmetric MASTER/SLAVE behavior 132 * WSH 05/24/97: Modified for asymmetric MASTER/SLAVE behavior
131 * The chars_in_buffer() value is used by the ldisc select() function 133 * The chars_in_buffer() value is used by the ldisc select() function
132 * to hold off writing when chars_in_buffer > WAKEUP_CHARS (== 256). 134 * to hold off writing when chars_in_buffer > WAKEUP_CHARS (== 256).
133 * The pty driver chars_in_buffer() Master/Slave must behave differently: 135 * The pty driver chars_in_buffer() Master/Slave must behave differently:
134 * 136 *
135 * The Master side needs to allow typed-ahead commands to accumulate 137 * The Master side needs to allow typed-ahead commands to accumulate
136 * while being canonicalized, so we report "our buffer" as empty until 138 * while being canonicalized, so we report "our buffer" as empty until
137 * some threshold is reached, and then report the count. (Any count > 139 * some threshold is reached, and then report the count. (Any count >
138 * WAKEUP_CHARS is regarded by select() as "full".) To avoid deadlock 140 * WAKEUP_CHARS is regarded by select() as "full".) To avoid deadlock
139 * the count returned must be 0 if no canonical data is available to be 141 * the count returned must be 0 if no canonical data is available to be
140 * read. (The N_TTY ldisc.chars_in_buffer now knows this.) 142 * read. (The N_TTY ldisc.chars_in_buffer now knows this.)
141 * 143 *
142 * The Slave side passes all characters in raw mode to the Master side's 144 * The Slave side passes all characters in raw mode to the Master side's
143 * buffer where they can be read immediately, so in this case we can 145 * buffer where they can be read immediately, so in this case we can
144 * return the true count in the buffer. 146 * return the true count in the buffer.
@@ -155,21 +157,22 @@ static int pty_chars_in_buffer(struct tty_struct *tty)
155 /* The ldisc must report 0 if no characters available to be read */ 157 /* The ldisc must report 0 if no characters available to be read */
156 count = to->ldisc.ops->chars_in_buffer(to); 158 count = to->ldisc.ops->chars_in_buffer(to);
157 159
158 if (tty->driver->subtype == PTY_TYPE_SLAVE) return count; 160 if (tty->driver->subtype == PTY_TYPE_SLAVE)
161 return count;
159 162
160 /* Master side driver ... if the other side's read buffer is less than 163 /* Master side driver ... if the other side's read buffer is less than
161 * half full, return 0 to allow writers to proceed; otherwise return 164 * half full, return 0 to allow writers to proceed; otherwise return
162 * the count. This leaves a comfortable margin to avoid overflow, 165 * the count. This leaves a comfortable margin to avoid overflow,
163 * and still allows half a buffer's worth of typed-ahead commands. 166 * and still allows half a buffer's worth of typed-ahead commands.
164 */ 167 */
165 return ((count < N_TTY_BUF_SIZE/2) ? 0 : count); 168 return (count < N_TTY_BUF_SIZE/2) ? 0 : count;
166} 169}
167 170
168/* Set the lock flag on a pty */ 171/* Set the lock flag on a pty */
169static int pty_set_lock(struct tty_struct *tty, int __user * arg) 172static int pty_set_lock(struct tty_struct *tty, int __user *arg)
170{ 173{
171 int val; 174 int val;
172 if (get_user(val,arg)) 175 if (get_user(val, arg))
173 return -EFAULT; 176 return -EFAULT;
174 if (val) 177 if (val)
175 set_bit(TTY_PTY_LOCK, &tty->flags); 178 set_bit(TTY_PTY_LOCK, &tty->flags);
@@ -182,13 +185,13 @@ static void pty_flush_buffer(struct tty_struct *tty)
182{ 185{
183 struct tty_struct *to = tty->link; 186 struct tty_struct *to = tty->link;
184 unsigned long flags; 187 unsigned long flags;
185 188
186 if (!to) 189 if (!to)
187 return; 190 return;
188 191
189 if (to->ldisc.ops->flush_buffer) 192 if (to->ldisc.ops->flush_buffer)
190 to->ldisc.ops->flush_buffer(to); 193 to->ldisc.ops->flush_buffer(to);
191 194
192 if (to->packet) { 195 if (to->packet) {
193 spin_lock_irqsave(&tty->ctrl_lock, flags); 196 spin_lock_irqsave(&tty->ctrl_lock, flags);
194 tty->ctrl_status |= TIOCPKT_FLUSHWRITE; 197 tty->ctrl_status |= TIOCPKT_FLUSHWRITE;
@@ -197,7 +200,7 @@ static void pty_flush_buffer(struct tty_struct *tty)
197 } 200 }
198} 201}
199 202
200static int pty_open(struct tty_struct *tty, struct file * filp) 203static int pty_open(struct tty_struct *tty, struct file *filp)
201{ 204{
202 int retval = -ENODEV; 205 int retval = -ENODEV;
203 206
@@ -220,13 +223,65 @@ out:
220 return retval; 223 return retval;
221} 224}
222 225
223static void pty_set_termios(struct tty_struct *tty, struct ktermios *old_termios) 226static void pty_set_termios(struct tty_struct *tty,
227 struct ktermios *old_termios)
228{
229 tty->termios->c_cflag &= ~(CSIZE | PARENB);
230 tty->termios->c_cflag |= (CS8 | CREAD);
231}
232
233static int pty_install(struct tty_driver *driver, struct tty_struct *tty)
224{ 234{
225 tty->termios->c_cflag &= ~(CSIZE | PARENB); 235 struct tty_struct *o_tty;
226 tty->termios->c_cflag |= (CS8 | CREAD); 236 int idx = tty->index;
237 int retval;
238
239 o_tty = alloc_tty_struct();
240 if (!o_tty)
241 return -ENOMEM;
242 if (!try_module_get(driver->other->owner)) {
243 /* This cannot in fact currently happen */
244 free_tty_struct(o_tty);
245 return -ENOMEM;
246 }
247 initialize_tty_struct(o_tty, driver->other, idx);
248
249 /* We always use new tty termios data so we can do this
250 the easy way .. */
251 retval = tty_init_termios(tty);
252 if (retval)
253 goto free_mem_out;
254
255 retval = tty_init_termios(o_tty);
256 if (retval) {
257 tty_free_termios(tty);
258 goto free_mem_out;
259 }
260
261 /*
262 * Everything allocated ... set up the o_tty structure.
263 */
264 driver->other->ttys[idx] = o_tty;
265 tty_driver_kref_get(driver->other);
266 if (driver->subtype == PTY_TYPE_MASTER)
267 o_tty->count++;
268 /* Establish the links in both directions */
269 tty->link = o_tty;
270 o_tty->link = tty;
271
272 tty_driver_kref_get(driver);
273 tty->count++;
274 driver->ttys[idx] = tty;
275 return 0;
276free_mem_out:
277 module_put(o_tty->driver->owner);
278 free_tty_struct(o_tty);
279 return -ENOMEM;
227} 280}
228 281
282
229static const struct tty_operations pty_ops = { 283static const struct tty_operations pty_ops = {
284 .install = pty_install,
230 .open = pty_open, 285 .open = pty_open,
231 .close = pty_close, 286 .close = pty_close,
232 .write = pty_write, 287 .write = pty_write,
@@ -329,8 +384,11 @@ static inline void legacy_pty_init(void) { }
329 * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly. 384 * Otherwise one can eat up all kernel memory by opening /dev/ptmx repeatedly.
330 */ 385 */
331int pty_limit = NR_UNIX98_PTY_DEFAULT; 386int pty_limit = NR_UNIX98_PTY_DEFAULT;
332static int pty_limit_min = 0; 387static int pty_limit_min;
333static int pty_limit_max = NR_UNIX98_PTY_MAX; 388static int pty_limit_max = NR_UNIX98_PTY_MAX;
389static int pty_count;
390
391static struct cdev ptmx_cdev;
334 392
335static struct ctl_table pty_table[] = { 393static struct ctl_table pty_table[] = {
336 { 394 {
@@ -348,6 +406,7 @@ static struct ctl_table pty_table[] = {
348 .procname = "nr", 406 .procname = "nr",
349 .maxlen = sizeof(int), 407 .maxlen = sizeof(int),
350 .mode = 0444, 408 .mode = 0444,
409 .data = &pty_count,
351 .proc_handler = &proc_dointvec, 410 .proc_handler = &proc_dointvec,
352 }, { 411 }, {
353 .ctl_name = 0 412 .ctl_name = 0
@@ -388,7 +447,127 @@ static int pty_unix98_ioctl(struct tty_struct *tty, struct file *file,
388 return -ENOIOCTLCMD; 447 return -ENOIOCTLCMD;
389} 448}
390 449
450/**
451 * ptm_unix98_lookup - find a pty master
452 * @driver: ptm driver
453 * @idx: tty index
454 *
455 * Look up a pty master device. Called under the tty_mutex for now.
456 * This provides our locking.
457 */
458
459static struct tty_struct *ptm_unix98_lookup(struct tty_driver *driver,
460 struct inode *ptm_inode, int idx)
461{
462 struct tty_struct *tty = devpts_get_tty(ptm_inode, idx);
463 if (tty)
464 tty = tty->link;
465 return tty;
466}
467
468/**
469 * pts_unix98_lookup - find a pty slave
470 * @driver: pts driver
471 * @idx: tty index
472 *
473 * Look up a pty master device. Called under the tty_mutex for now.
474 * This provides our locking.
475 */
476
477static struct tty_struct *pts_unix98_lookup(struct tty_driver *driver,
478 struct inode *pts_inode, int idx)
479{
480 struct tty_struct *tty = devpts_get_tty(pts_inode, idx);
481 /* Master must be open before slave */
482 if (!tty)
483 return ERR_PTR(-EIO);
484 return tty;
485}
486
487static void pty_unix98_shutdown(struct tty_struct *tty)
488{
489 /* We have our own method as we don't use the tty index */
490 kfree(tty->termios);
491}
492
493/* We have no need to install and remove our tty objects as devpts does all
494 the work for us */
495
496static int pty_unix98_install(struct tty_driver *driver, struct tty_struct *tty)
497{
498 struct tty_struct *o_tty;
499 int idx = tty->index;
500
501 o_tty = alloc_tty_struct();
502 if (!o_tty)
503 return -ENOMEM;
504 if (!try_module_get(driver->other->owner)) {
505 /* This cannot in fact currently happen */
506 free_tty_struct(o_tty);
507 return -ENOMEM;
508 }
509 initialize_tty_struct(o_tty, driver->other, idx);
510
511 tty->termios = kzalloc(sizeof(struct ktermios[2]), GFP_KERNEL);
512 if (tty->termios == NULL)
513 goto free_mem_out;
514 *tty->termios = driver->init_termios;
515 tty->termios_locked = tty->termios + 1;
516
517 o_tty->termios = kzalloc(sizeof(struct ktermios[2]), GFP_KERNEL);
518 if (o_tty->termios == NULL)
519 goto free_mem_out;
520 *o_tty->termios = driver->other->init_termios;
521 o_tty->termios_locked = o_tty->termios + 1;
522
523 tty_driver_kref_get(driver->other);
524 if (driver->subtype == PTY_TYPE_MASTER)
525 o_tty->count++;
526 /* Establish the links in both directions */
527 tty->link = o_tty;
528 o_tty->link = tty;
529 /*
530 * All structures have been allocated, so now we install them.
531 * Failures after this point use release_tty to clean up, so
532 * there's no need to null out the local pointers.
533 */
534 tty_driver_kref_get(driver);
535 tty->count++;
536 pty_count++;
537 return 0;
538free_mem_out:
539 kfree(o_tty->termios);
540 module_put(o_tty->driver->owner);
541 free_tty_struct(o_tty);
542 kfree(tty->termios);
543 return -ENOMEM;
544}
545
546static void pty_unix98_remove(struct tty_driver *driver, struct tty_struct *tty)
547{
548 pty_count--;
549}
550
551static const struct tty_operations ptm_unix98_ops = {
552 .lookup = ptm_unix98_lookup,
553 .install = pty_unix98_install,
554 .remove = pty_unix98_remove,
555 .open = pty_open,
556 .close = pty_close,
557 .write = pty_write,
558 .write_room = pty_write_room,
559 .flush_buffer = pty_flush_buffer,
560 .chars_in_buffer = pty_chars_in_buffer,
561 .unthrottle = pty_unthrottle,
562 .set_termios = pty_set_termios,
563 .ioctl = pty_unix98_ioctl,
564 .shutdown = pty_unix98_shutdown
565};
566
391static const struct tty_operations pty_unix98_ops = { 567static const struct tty_operations pty_unix98_ops = {
568 .lookup = pts_unix98_lookup,
569 .install = pty_unix98_install,
570 .remove = pty_unix98_remove,
392 .open = pty_open, 571 .open = pty_open,
393 .close = pty_close, 572 .close = pty_close,
394 .write = pty_write, 573 .write = pty_write,
@@ -397,9 +576,73 @@ static const struct tty_operations pty_unix98_ops = {
397 .chars_in_buffer = pty_chars_in_buffer, 576 .chars_in_buffer = pty_chars_in_buffer,
398 .unthrottle = pty_unthrottle, 577 .unthrottle = pty_unthrottle,
399 .set_termios = pty_set_termios, 578 .set_termios = pty_set_termios,
400 .ioctl = pty_unix98_ioctl 579 .shutdown = pty_unix98_shutdown
401}; 580};
402 581
582/**
583 * ptmx_open - open a unix 98 pty master
584 * @inode: inode of device file
585 * @filp: file pointer to tty
586 *
587 * Allocate a unix98 pty master device from the ptmx driver.
588 *
589 * Locking: tty_mutex protects the init_dev work. tty->count should
590 * protect the rest.
591 * allocated_ptys_lock handles the list of free pty numbers
592 */
593
594static int __ptmx_open(struct inode *inode, struct file *filp)
595{
596 struct tty_struct *tty;
597 int retval;
598 int index;
599
600 nonseekable_open(inode, filp);
601
602 /* find a device that is not in use. */
603 index = devpts_new_index(inode);
604 if (index < 0)
605 return index;
606
607 mutex_lock(&tty_mutex);
608 tty = tty_init_dev(ptm_driver, index, 1);
609 mutex_unlock(&tty_mutex);
610
611 if (IS_ERR(tty)) {
612 retval = PTR_ERR(tty);
613 goto out;
614 }
615
616 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
617 filp->private_data = tty;
618 file_move(filp, &tty->tty_files);
619
620 retval = devpts_pty_new(inode, tty->link);
621 if (retval)
622 goto out1;
623
624 retval = ptm_driver->ops->open(tty, filp);
625 if (!retval)
626 return 0;
627out1:
628 tty_release_dev(filp);
629 return retval;
630out:
631 devpts_kill_index(inode, index);
632 return retval;
633}
634
635static int ptmx_open(struct inode *inode, struct file *filp)
636{
637 int ret;
638
639 lock_kernel();
640 ret = __ptmx_open(inode, filp);
641 unlock_kernel();
642 return ret;
643}
644
645static struct file_operations ptmx_fops;
403 646
404static void __init unix98_pty_init(void) 647static void __init unix98_pty_init(void)
405{ 648{
@@ -427,7 +670,7 @@ static void __init unix98_pty_init(void)
427 ptm_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW | 670 ptm_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW |
428 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM; 671 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM;
429 ptm_driver->other = pts_driver; 672 ptm_driver->other = pts_driver;
430 tty_set_operations(ptm_driver, &pty_unix98_ops); 673 tty_set_operations(ptm_driver, &ptm_unix98_ops);
431 674
432 pts_driver->owner = THIS_MODULE; 675 pts_driver->owner = THIS_MODULE;
433 pts_driver->driver_name = "pty_slave"; 676 pts_driver->driver_name = "pty_slave";
@@ -443,16 +686,26 @@ static void __init unix98_pty_init(void)
443 pts_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW | 686 pts_driver->flags = TTY_DRIVER_RESET_TERMIOS | TTY_DRIVER_REAL_RAW |
444 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM; 687 TTY_DRIVER_DYNAMIC_DEV | TTY_DRIVER_DEVPTS_MEM;
445 pts_driver->other = ptm_driver; 688 pts_driver->other = ptm_driver;
446 tty_set_operations(pts_driver, &pty_ops); 689 tty_set_operations(pts_driver, &pty_unix98_ops);
447 690
448 if (tty_register_driver(ptm_driver)) 691 if (tty_register_driver(ptm_driver))
449 panic("Couldn't register Unix98 ptm driver"); 692 panic("Couldn't register Unix98 ptm driver");
450 if (tty_register_driver(pts_driver)) 693 if (tty_register_driver(pts_driver))
451 panic("Couldn't register Unix98 pts driver"); 694 panic("Couldn't register Unix98 pts driver");
452 695
453 pty_table[1].data = &ptm_driver->refcount;
454 register_sysctl_table(pty_root_table); 696 register_sysctl_table(pty_root_table);
697
698 /* Now create the /dev/ptmx special device */
699 tty_default_fops(&ptmx_fops);
700 ptmx_fops.open = ptmx_open;
701
702 cdev_init(&ptmx_cdev, &ptmx_fops);
703 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
704 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
705 panic("Couldn't register /dev/ptmx driver\n");
706 device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx");
455} 707}
708
456#else 709#else
457static inline void unix98_pty_init(void) { } 710static inline void unix98_pty_init(void) { }
458#endif 711#endif
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 6af435b89867..c8752eaad483 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1205,7 +1205,7 @@ static int proc_do_uuid(ctl_table *table, int write, struct file *filp,
1205 return proc_dostring(&fake_table, write, filp, buffer, lenp, ppos); 1205 return proc_dostring(&fake_table, write, filp, buffer, lenp, ppos);
1206} 1206}
1207 1207
1208static int uuid_strategy(ctl_table *table, int __user *name, int nlen, 1208static int uuid_strategy(ctl_table *table,
1209 void __user *oldval, size_t __user *oldlenp, 1209 void __user *oldval, size_t __user *oldlenp,
1210 void __user *newval, size_t newlen) 1210 void __user *newval, size_t newlen)
1211{ 1211{
diff --git a/drivers/char/raw.c b/drivers/char/raw.c
index 47b8cf281d4a..e139372d0e69 100644
--- a/drivers/char/raw.c
+++ b/drivers/char/raw.c
@@ -131,8 +131,8 @@ raw_ioctl(struct inode *inode, struct file *filp,
131static void bind_device(struct raw_config_request *rq) 131static void bind_device(struct raw_config_request *rq)
132{ 132{
133 device_destroy(raw_class, MKDEV(RAW_MAJOR, rq->raw_minor)); 133 device_destroy(raw_class, MKDEV(RAW_MAJOR, rq->raw_minor));
134 device_create_drvdata(raw_class, NULL, MKDEV(RAW_MAJOR, rq->raw_minor), 134 device_create(raw_class, NULL, MKDEV(RAW_MAJOR, rq->raw_minor), NULL,
135 NULL, "raw%d", rq->raw_minor); 135 "raw%d", rq->raw_minor);
136} 136}
137 137
138/* 138/*
@@ -283,8 +283,7 @@ static int __init raw_init(void)
283 ret = PTR_ERR(raw_class); 283 ret = PTR_ERR(raw_class);
284 goto error_region; 284 goto error_region;
285 } 285 }
286 device_create_drvdata(raw_class, NULL, MKDEV(RAW_MAJOR, 0), NULL, 286 device_create(raw_class, NULL, MKDEV(RAW_MAJOR, 0), NULL, "rawctl");
287 "rawctl");
288 287
289 return 0; 288 return 0;
290 289
diff --git a/drivers/char/rtc.c b/drivers/char/rtc.c
index b47710c17885..17683de95717 100644
--- a/drivers/char/rtc.c
+++ b/drivers/char/rtc.c
@@ -96,7 +96,7 @@ static unsigned long rtc_port;
96static int rtc_irq; 96static int rtc_irq;
97#endif 97#endif
98 98
99#ifdef CONFIG_HPET_RTC_IRQ 99#ifdef CONFIG_HPET_EMULATE_RTC
100#undef RTC_IRQ 100#undef RTC_IRQ
101#endif 101#endif
102 102
diff --git a/drivers/char/snsc.c b/drivers/char/snsc.c
index 3ce60df14c0a..32b74de18f5f 100644
--- a/drivers/char/snsc.c
+++ b/drivers/char/snsc.c
@@ -444,8 +444,8 @@ scdrv_init(void)
444 continue; 444 continue;
445 } 445 }
446 446
447 device_create_drvdata(snsc_class, NULL, dev, NULL, 447 device_create(snsc_class, NULL, dev, NULL,
448 "%s", devname); 448 "%s", devname);
449 449
450 ia64_sn_irtr_intr_enable(scd->scd_nasid, 450 ia64_sn_irtr_intr_enable(scd->scd_nasid,
451 0 /*ignored */ , 451 0 /*ignored */ ,
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index 19db1eb87c26..963b03fb29e5 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -405,9 +405,9 @@ static unsigned int stl_baudrates[] = {
405 405
406static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg); 406static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
407static int stl_brdinit(struct stlbrd *brdp); 407static int stl_brdinit(struct stlbrd *brdp);
408static int stl_getportstats(struct stlport *portp, comstats_t __user *cp); 408static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comstats_t __user *cp);
409static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp); 409static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp);
410static int stl_waitcarrier(struct stlport *portp, struct file *filp); 410static int stl_waitcarrier(struct tty_struct *tty, struct stlport *portp, struct file *filp);
411 411
412/* 412/*
413 * CD1400 uart specific handling functions. 413 * CD1400 uart specific handling functions.
@@ -612,8 +612,9 @@ static struct class *stallion_class;
612static void stl_cd_change(struct stlport *portp) 612static void stl_cd_change(struct stlport *portp)
613{ 613{
614 unsigned int oldsigs = portp->sigs; 614 unsigned int oldsigs = portp->sigs;
615 struct tty_struct *tty = tty_port_tty_get(&portp->port);
615 616
616 if (!portp->port.tty) 617 if (!tty)
617 return; 618 return;
618 619
619 portp->sigs = stl_getsignals(portp); 620 portp->sigs = stl_getsignals(portp);
@@ -623,7 +624,8 @@ static void stl_cd_change(struct stlport *portp)
623 624
624 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) 625 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0))
625 if (portp->port.flags & ASYNC_CHECK_CD) 626 if (portp->port.flags & ASYNC_CHECK_CD)
626 tty_hangup(portp->port.tty); 627 tty_hangup(tty);
628 tty_kref_put(tty);
627} 629}
628 630
629/* 631/*
@@ -734,7 +736,7 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
734 * On the first open of the device setup the port hardware, and 736 * On the first open of the device setup the port hardware, and
735 * initialize the per port data structure. 737 * initialize the per port data structure.
736 */ 738 */
737 portp->port.tty = tty; 739 tty_port_tty_set(&portp->port, tty);
738 tty->driver_data = portp; 740 tty->driver_data = portp;
739 portp->port.count++; 741 portp->port.count++;
740 742
@@ -774,7 +776,7 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
774 * then also we might have to wait for carrier. 776 * then also we might have to wait for carrier.
775 */ 777 */
776 if (!(filp->f_flags & O_NONBLOCK)) 778 if (!(filp->f_flags & O_NONBLOCK))
777 if ((rc = stl_waitcarrier(portp, filp)) != 0) 779 if ((rc = stl_waitcarrier(tty, portp, filp)) != 0)
778 return rc; 780 return rc;
779 781
780 portp->port.flags |= ASYNC_NORMAL_ACTIVE; 782 portp->port.flags |= ASYNC_NORMAL_ACTIVE;
@@ -789,7 +791,8 @@ static int stl_open(struct tty_struct *tty, struct file *filp)
789 * maybe because if we are clocal then we don't need to wait... 791 * maybe because if we are clocal then we don't need to wait...
790 */ 792 */
791 793
792static int stl_waitcarrier(struct stlport *portp, struct file *filp) 794static int stl_waitcarrier(struct tty_struct *tty, struct stlport *portp,
795 struct file *filp)
793{ 796{
794 unsigned long flags; 797 unsigned long flags;
795 int rc, doclocal; 798 int rc, doclocal;
@@ -801,7 +804,7 @@ static int stl_waitcarrier(struct stlport *portp, struct file *filp)
801 804
802 spin_lock_irqsave(&stallion_lock, flags); 805 spin_lock_irqsave(&stallion_lock, flags);
803 806
804 if (portp->port.tty->termios->c_cflag & CLOCAL) 807 if (tty->termios->c_cflag & CLOCAL)
805 doclocal++; 808 doclocal++;
806 809
807 portp->openwaitcnt++; 810 portp->openwaitcnt++;
@@ -846,8 +849,6 @@ static void stl_flushbuffer(struct tty_struct *tty)
846 849
847 pr_debug("stl_flushbuffer(tty=%p)\n", tty); 850 pr_debug("stl_flushbuffer(tty=%p)\n", tty);
848 851
849 if (tty == NULL)
850 return;
851 portp = tty->driver_data; 852 portp = tty->driver_data;
852 if (portp == NULL) 853 if (portp == NULL)
853 return; 854 return;
@@ -865,8 +866,6 @@ static void stl_waituntilsent(struct tty_struct *tty, int timeout)
865 866
866 pr_debug("stl_waituntilsent(tty=%p,timeout=%d)\n", tty, timeout); 867 pr_debug("stl_waituntilsent(tty=%p,timeout=%d)\n", tty, timeout);
867 868
868 if (tty == NULL)
869 return;
870 portp = tty->driver_data; 869 portp = tty->driver_data;
871 if (portp == NULL) 870 if (portp == NULL)
872 return; 871 return;
@@ -949,7 +948,7 @@ static void stl_close(struct tty_struct *tty, struct file *filp)
949 tty_ldisc_flush(tty); 948 tty_ldisc_flush(tty);
950 949
951 tty->closing = 0; 950 tty->closing = 0;
952 portp->port.tty = NULL; 951 tty_port_tty_set(&portp->port, NULL);
953 952
954 if (portp->openwaitcnt) { 953 if (portp->openwaitcnt) {
955 if (portp->close_delay) 954 if (portp->close_delay)
@@ -1033,8 +1032,6 @@ static int stl_putchar(struct tty_struct *tty, unsigned char ch)
1033 1032
1034 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch); 1033 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch);
1035 1034
1036 if (tty == NULL)
1037 return -EINVAL;
1038 portp = tty->driver_data; 1035 portp = tty->driver_data;
1039 if (portp == NULL) 1036 if (portp == NULL)
1040 return -EINVAL; 1037 return -EINVAL;
@@ -1070,8 +1067,6 @@ static void stl_flushchars(struct tty_struct *tty)
1070 1067
1071 pr_debug("stl_flushchars(tty=%p)\n", tty); 1068 pr_debug("stl_flushchars(tty=%p)\n", tty);
1072 1069
1073 if (tty == NULL)
1074 return;
1075 portp = tty->driver_data; 1070 portp = tty->driver_data;
1076 if (portp == NULL) 1071 if (portp == NULL)
1077 return; 1072 return;
@@ -1090,8 +1085,6 @@ static int stl_writeroom(struct tty_struct *tty)
1090 1085
1091 pr_debug("stl_writeroom(tty=%p)\n", tty); 1086 pr_debug("stl_writeroom(tty=%p)\n", tty);
1092 1087
1093 if (tty == NULL)
1094 return 0;
1095 portp = tty->driver_data; 1088 portp = tty->driver_data;
1096 if (portp == NULL) 1089 if (portp == NULL)
1097 return 0; 1090 return 0;
@@ -1122,8 +1115,6 @@ static int stl_charsinbuffer(struct tty_struct *tty)
1122 1115
1123 pr_debug("stl_charsinbuffer(tty=%p)\n", tty); 1116 pr_debug("stl_charsinbuffer(tty=%p)\n", tty);
1124 1117
1125 if (tty == NULL)
1126 return 0;
1127 portp = tty->driver_data; 1118 portp = tty->driver_data;
1128 if (portp == NULL) 1119 if (portp == NULL)
1129 return 0; 1120 return 0;
@@ -1183,8 +1174,9 @@ static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp)
1183 * just quietly ignore any requests to change irq, etc. 1174 * just quietly ignore any requests to change irq, etc.
1184 */ 1175 */
1185 1176
1186static int stl_setserial(struct stlport *portp, struct serial_struct __user *sp) 1177static int stl_setserial(struct tty_struct *tty, struct serial_struct __user *sp)
1187{ 1178{
1179 struct stlport * portp = tty->driver_data;
1188 struct serial_struct sio; 1180 struct serial_struct sio;
1189 1181
1190 pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp, sp); 1182 pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp, sp);
@@ -1205,7 +1197,7 @@ static int stl_setserial(struct stlport *portp, struct serial_struct __user *sp)
1205 portp->close_delay = sio.close_delay; 1197 portp->close_delay = sio.close_delay;
1206 portp->closing_wait = sio.closing_wait; 1198 portp->closing_wait = sio.closing_wait;
1207 portp->custom_divisor = sio.custom_divisor; 1199 portp->custom_divisor = sio.custom_divisor;
1208 stl_setport(portp, portp->port.tty->termios); 1200 stl_setport(portp, tty->termios);
1209 return 0; 1201 return 0;
1210} 1202}
1211 1203
@@ -1215,8 +1207,6 @@ static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1215{ 1207{
1216 struct stlport *portp; 1208 struct stlport *portp;
1217 1209
1218 if (tty == NULL)
1219 return -ENODEV;
1220 portp = tty->driver_data; 1210 portp = tty->driver_data;
1221 if (portp == NULL) 1211 if (portp == NULL)
1222 return -ENODEV; 1212 return -ENODEV;
@@ -1232,8 +1222,6 @@ static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1232 struct stlport *portp; 1222 struct stlport *portp;
1233 int rts = -1, dtr = -1; 1223 int rts = -1, dtr = -1;
1234 1224
1235 if (tty == NULL)
1236 return -ENODEV;
1237 portp = tty->driver_data; 1225 portp = tty->driver_data;
1238 if (portp == NULL) 1226 if (portp == NULL)
1239 return -ENODEV; 1227 return -ENODEV;
@@ -1262,8 +1250,6 @@ static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd
1262 pr_debug("stl_ioctl(tty=%p,file=%p,cmd=%x,arg=%lx)\n", tty, file, cmd, 1250 pr_debug("stl_ioctl(tty=%p,file=%p,cmd=%x,arg=%lx)\n", tty, file, cmd,
1263 arg); 1251 arg);
1264 1252
1265 if (tty == NULL)
1266 return -ENODEV;
1267 portp = tty->driver_data; 1253 portp = tty->driver_data;
1268 if (portp == NULL) 1254 if (portp == NULL)
1269 return -ENODEV; 1255 return -ENODEV;
@@ -1282,10 +1268,10 @@ static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd
1282 rc = stl_getserial(portp, argp); 1268 rc = stl_getserial(portp, argp);
1283 break; 1269 break;
1284 case TIOCSSERIAL: 1270 case TIOCSSERIAL:
1285 rc = stl_setserial(portp, argp); 1271 rc = stl_setserial(tty, argp);
1286 break; 1272 break;
1287 case COM_GETPORTSTATS: 1273 case COM_GETPORTSTATS:
1288 rc = stl_getportstats(portp, argp); 1274 rc = stl_getportstats(tty, portp, argp);
1289 break; 1275 break;
1290 case COM_CLRPORTSTATS: 1276 case COM_CLRPORTSTATS:
1291 rc = stl_clrportstats(portp, argp); 1277 rc = stl_clrportstats(portp, argp);
@@ -1317,8 +1303,6 @@ static void stl_start(struct tty_struct *tty)
1317 1303
1318 pr_debug("stl_start(tty=%p)\n", tty); 1304 pr_debug("stl_start(tty=%p)\n", tty);
1319 1305
1320 if (tty == NULL)
1321 return;
1322 portp = tty->driver_data; 1306 portp = tty->driver_data;
1323 if (portp == NULL) 1307 if (portp == NULL)
1324 return; 1308 return;
@@ -1334,8 +1318,6 @@ static void stl_settermios(struct tty_struct *tty, struct ktermios *old)
1334 1318
1335 pr_debug("stl_settermios(tty=%p,old=%p)\n", tty, old); 1319 pr_debug("stl_settermios(tty=%p,old=%p)\n", tty, old);
1336 1320
1337 if (tty == NULL)
1338 return;
1339 portp = tty->driver_data; 1321 portp = tty->driver_data;
1340 if (portp == NULL) 1322 if (portp == NULL)
1341 return; 1323 return;
@@ -1369,8 +1351,6 @@ static void stl_throttle(struct tty_struct *tty)
1369 1351
1370 pr_debug("stl_throttle(tty=%p)\n", tty); 1352 pr_debug("stl_throttle(tty=%p)\n", tty);
1371 1353
1372 if (tty == NULL)
1373 return;
1374 portp = tty->driver_data; 1354 portp = tty->driver_data;
1375 if (portp == NULL) 1355 if (portp == NULL)
1376 return; 1356 return;
@@ -1389,8 +1369,6 @@ static void stl_unthrottle(struct tty_struct *tty)
1389 1369
1390 pr_debug("stl_unthrottle(tty=%p)\n", tty); 1370 pr_debug("stl_unthrottle(tty=%p)\n", tty);
1391 1371
1392 if (tty == NULL)
1393 return;
1394 portp = tty->driver_data; 1372 portp = tty->driver_data;
1395 if (portp == NULL) 1373 if (portp == NULL)
1396 return; 1374 return;
@@ -1410,8 +1388,6 @@ static void stl_stop(struct tty_struct *tty)
1410 1388
1411 pr_debug("stl_stop(tty=%p)\n", tty); 1389 pr_debug("stl_stop(tty=%p)\n", tty);
1412 1390
1413 if (tty == NULL)
1414 return;
1415 portp = tty->driver_data; 1391 portp = tty->driver_data;
1416 if (portp == NULL) 1392 if (portp == NULL)
1417 return; 1393 return;
@@ -1432,8 +1408,6 @@ static void stl_hangup(struct tty_struct *tty)
1432 1408
1433 pr_debug("stl_hangup(tty=%p)\n", tty); 1409 pr_debug("stl_hangup(tty=%p)\n", tty);
1434 1410
1435 if (tty == NULL)
1436 return;
1437 portp = tty->driver_data; 1411 portp = tty->driver_data;
1438 if (portp == NULL) 1412 if (portp == NULL)
1439 return; 1413 return;
@@ -1452,7 +1426,7 @@ static void stl_hangup(struct tty_struct *tty)
1452 portp->tx.head = NULL; 1426 portp->tx.head = NULL;
1453 portp->tx.tail = NULL; 1427 portp->tx.tail = NULL;
1454 } 1428 }
1455 portp->port.tty = NULL; 1429 tty_port_tty_set(&portp->port, NULL);
1456 portp->port.flags &= ~ASYNC_NORMAL_ACTIVE; 1430 portp->port.flags &= ~ASYNC_NORMAL_ACTIVE;
1457 portp->port.count = 0; 1431 portp->port.count = 0;
1458 wake_up_interruptible(&portp->port.open_wait); 1432 wake_up_interruptible(&portp->port.open_wait);
@@ -1466,8 +1440,6 @@ static int stl_breakctl(struct tty_struct *tty, int state)
1466 1440
1467 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state); 1441 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state);
1468 1442
1469 if (tty == NULL)
1470 return -EINVAL;
1471 portp = tty->driver_data; 1443 portp = tty->driver_data;
1472 if (portp == NULL) 1444 if (portp == NULL)
1473 return -EINVAL; 1445 return -EINVAL;
@@ -1484,8 +1456,6 @@ static void stl_sendxchar(struct tty_struct *tty, char ch)
1484 1456
1485 pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty, ch); 1457 pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty, ch);
1486 1458
1487 if (tty == NULL)
1488 return;
1489 portp = tty->driver_data; 1459 portp = tty->driver_data;
1490 if (portp == NULL) 1460 if (portp == NULL)
1491 return; 1461 return;
@@ -1805,7 +1775,7 @@ static int __devinit stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
1805 "(size=%Zd)\n", sizeof(struct stlport)); 1775 "(size=%Zd)\n", sizeof(struct stlport));
1806 break; 1776 break;
1807 } 1777 }
1808 1778 tty_port_init(&portp->port);
1809 portp->magic = STL_PORTMAGIC; 1779 portp->magic = STL_PORTMAGIC;
1810 portp->portnr = i; 1780 portp->portnr = i;
1811 portp->brdnr = panelp->brdnr; 1781 portp->brdnr = panelp->brdnr;
@@ -1832,6 +1802,7 @@ static void stl_cleanup_panels(struct stlbrd *brdp)
1832 struct stlpanel *panelp; 1802 struct stlpanel *panelp;
1833 struct stlport *portp; 1803 struct stlport *portp;
1834 unsigned int j, k; 1804 unsigned int j, k;
1805 struct tty_struct *tty;
1835 1806
1836 for (j = 0; j < STL_MAXPANELS; j++) { 1807 for (j = 0; j < STL_MAXPANELS; j++) {
1837 panelp = brdp->panels[j]; 1808 panelp = brdp->panels[j];
@@ -1841,8 +1812,11 @@ static void stl_cleanup_panels(struct stlbrd *brdp)
1841 portp = panelp->ports[k]; 1812 portp = panelp->ports[k];
1842 if (portp == NULL) 1813 if (portp == NULL)
1843 continue; 1814 continue;
1844 if (portp->port.tty != NULL) 1815 tty = tty_port_tty_get(&portp->port);
1845 stl_hangup(portp->port.tty); 1816 if (tty != NULL) {
1817 stl_hangup(tty);
1818 tty_kref_put(tty);
1819 }
1846 kfree(portp->tx.buf); 1820 kfree(portp->tx.buf);
1847 kfree(portp); 1821 kfree(portp);
1848 } 1822 }
@@ -2498,7 +2472,7 @@ static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
2498 * what port to get stats for (used through board control device). 2472 * what port to get stats for (used through board control device).
2499 */ 2473 */
2500 2474
2501static int stl_getportstats(struct stlport *portp, comstats_t __user *cp) 2475static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comstats_t __user *cp)
2502{ 2476{
2503 comstats_t stl_comstats; 2477 comstats_t stl_comstats;
2504 unsigned char *head, *tail; 2478 unsigned char *head, *tail;
@@ -2525,18 +2499,17 @@ static int stl_getportstats(struct stlport *portp, comstats_t __user *cp)
2525 portp->stats.rxbuffered = 0; 2499 portp->stats.rxbuffered = 0;
2526 2500
2527 spin_lock_irqsave(&stallion_lock, flags); 2501 spin_lock_irqsave(&stallion_lock, flags);
2528 if (portp->port.tty != NULL) 2502 if (tty != NULL && portp->port.tty == tty) {
2529 if (portp->port.tty->driver_data == portp) { 2503 portp->stats.ttystate = tty->flags;
2530 portp->stats.ttystate = portp->port.tty->flags; 2504 /* No longer available as a statistic */
2531 /* No longer available as a statistic */ 2505 portp->stats.rxbuffered = 1; /*tty->flip.count; */
2532 portp->stats.rxbuffered = 1; /*portp->port.tty->flip.count; */ 2506 if (tty->termios != NULL) {
2533 if (portp->port.tty->termios != NULL) { 2507 portp->stats.cflags = tty->termios->c_cflag;
2534 portp->stats.cflags = portp->port.tty->termios->c_cflag; 2508 portp->stats.iflags = tty->termios->c_iflag;
2535 portp->stats.iflags = portp->port.tty->termios->c_iflag; 2509 portp->stats.oflags = tty->termios->c_oflag;
2536 portp->stats.oflags = portp->port.tty->termios->c_oflag; 2510 portp->stats.lflags = tty->termios->c_lflag;
2537 portp->stats.lflags = portp->port.tty->termios->c_lflag;
2538 }
2539 } 2511 }
2512 }
2540 spin_unlock_irqrestore(&stallion_lock, flags); 2513 spin_unlock_irqrestore(&stallion_lock, flags);
2541 2514
2542 head = portp->tx.head; 2515 head = portp->tx.head;
@@ -2640,7 +2613,7 @@ static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, uns
2640 2613
2641 switch (cmd) { 2614 switch (cmd) {
2642 case COM_GETPORTSTATS: 2615 case COM_GETPORTSTATS:
2643 rc = stl_getportstats(NULL, argp); 2616 rc = stl_getportstats(NULL, NULL, argp);
2644 break; 2617 break;
2645 case COM_CLRPORTSTATS: 2618 case COM_CLRPORTSTATS:
2646 rc = stl_clrportstats(NULL, argp); 2619 rc = stl_clrportstats(NULL, argp);
@@ -3243,7 +3216,7 @@ static void stl_cd1400flowctrl(struct stlport *portp, int state)
3243 3216
3244 if (portp == NULL) 3217 if (portp == NULL)
3245 return; 3218 return;
3246 tty = portp->port.tty; 3219 tty = tty_port_tty_get(&portp->port);
3247 if (tty == NULL) 3220 if (tty == NULL)
3248 return; 3221 return;
3249 3222
@@ -3288,6 +3261,7 @@ static void stl_cd1400flowctrl(struct stlport *portp, int state)
3288 3261
3289 BRDDISABLE(portp->brdnr); 3262 BRDDISABLE(portp->brdnr);
3290 spin_unlock_irqrestore(&brd_lock, flags); 3263 spin_unlock_irqrestore(&brd_lock, flags);
3264 tty_kref_put(tty);
3291} 3265}
3292 3266
3293/*****************************************************************************/ 3267/*****************************************************************************/
@@ -3305,7 +3279,7 @@ static void stl_cd1400sendflow(struct stlport *portp, int state)
3305 3279
3306 if (portp == NULL) 3280 if (portp == NULL)
3307 return; 3281 return;
3308 tty = portp->port.tty; 3282 tty = tty_port_tty_get(&portp->port);
3309 if (tty == NULL) 3283 if (tty == NULL)
3310 return; 3284 return;
3311 3285
@@ -3325,6 +3299,7 @@ static void stl_cd1400sendflow(struct stlport *portp, int state)
3325 } 3299 }
3326 BRDDISABLE(portp->brdnr); 3300 BRDDISABLE(portp->brdnr);
3327 spin_unlock_irqrestore(&brd_lock, flags); 3301 spin_unlock_irqrestore(&brd_lock, flags);
3302 tty_kref_put(tty);
3328} 3303}
3329 3304
3330/*****************************************************************************/ 3305/*****************************************************************************/
@@ -3478,6 +3453,7 @@ static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr)
3478 int len, stlen; 3453 int len, stlen;
3479 char *head, *tail; 3454 char *head, *tail;
3480 unsigned char ioack, srer; 3455 unsigned char ioack, srer;
3456 struct tty_struct *tty;
3481 3457
3482 pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr); 3458 pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3483 3459
@@ -3504,8 +3480,11 @@ static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr)
3504 if ((len == 0) || ((len < STL_TXBUFLOW) && 3480 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3505 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) { 3481 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3506 set_bit(ASYI_TXLOW, &portp->istate); 3482 set_bit(ASYI_TXLOW, &portp->istate);
3507 if (portp->port.tty) 3483 tty = tty_port_tty_get(&portp->port);
3508 tty_wakeup(portp->port.tty); 3484 if (tty) {
3485 tty_wakeup(tty);
3486 tty_kref_put(tty);
3487 }
3509 } 3488 }
3510 3489
3511 if (len == 0) { 3490 if (len == 0) {
@@ -3569,7 +3548,7 @@ static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
3569 return; 3548 return;
3570 } 3549 }
3571 portp = panelp->ports[(ioack >> 3)]; 3550 portp = panelp->ports[(ioack >> 3)];
3572 tty = portp->port.tty; 3551 tty = tty_port_tty_get(&portp->port);
3573 3552
3574 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) { 3553 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
3575 outb((RDCR + portp->uartaddr), ioaddr); 3554 outb((RDCR + portp->uartaddr), ioaddr);
@@ -3633,10 +3612,12 @@ static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
3633 } 3612 }
3634 } else { 3613 } else {
3635 printk("STALLION: bad RX interrupt ack value=%x\n", ioack); 3614 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3615 tty_kref_put(tty);
3636 return; 3616 return;
3637 } 3617 }
3638 3618
3639stl_rxalldone: 3619stl_rxalldone:
3620 tty_kref_put(tty);
3640 outb((EOSRR + portp->uartaddr), ioaddr); 3621 outb((EOSRR + portp->uartaddr), ioaddr);
3641 outb(0, (ioaddr + EREG_DATA)); 3622 outb(0, (ioaddr + EREG_DATA));
3642} 3623}
@@ -4175,7 +4156,7 @@ static void stl_sc26198flowctrl(struct stlport *portp, int state)
4175 4156
4176 if (portp == NULL) 4157 if (portp == NULL)
4177 return; 4158 return;
4178 tty = portp->port.tty; 4159 tty = tty_port_tty_get(&portp->port);
4179 if (tty == NULL) 4160 if (tty == NULL)
4180 return; 4161 return;
4181 4162
@@ -4226,6 +4207,7 @@ static void stl_sc26198flowctrl(struct stlport *portp, int state)
4226 4207
4227 BRDDISABLE(portp->brdnr); 4208 BRDDISABLE(portp->brdnr);
4228 spin_unlock_irqrestore(&brd_lock, flags); 4209 spin_unlock_irqrestore(&brd_lock, flags);
4210 tty_kref_put(tty);
4229} 4211}
4230 4212
4231/*****************************************************************************/ 4213/*****************************************************************************/
@@ -4244,7 +4226,7 @@ static void stl_sc26198sendflow(struct stlport *portp, int state)
4244 4226
4245 if (portp == NULL) 4227 if (portp == NULL)
4246 return; 4228 return;
4247 tty = portp->port.tty; 4229 tty = tty_port_tty_get(&portp->port);
4248 if (tty == NULL) 4230 if (tty == NULL)
4249 return; 4231 return;
4250 4232
@@ -4269,6 +4251,7 @@ static void stl_sc26198sendflow(struct stlport *portp, int state)
4269 } 4251 }
4270 BRDDISABLE(portp->brdnr); 4252 BRDDISABLE(portp->brdnr);
4271 spin_unlock_irqrestore(&brd_lock, flags); 4253 spin_unlock_irqrestore(&brd_lock, flags);
4254 tty_kref_put(tty);
4272} 4255}
4273 4256
4274/*****************************************************************************/ 4257/*****************************************************************************/
@@ -4408,6 +4391,7 @@ static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase)
4408 4391
4409static void stl_sc26198txisr(struct stlport *portp) 4392static void stl_sc26198txisr(struct stlport *portp)
4410{ 4393{
4394 struct tty_struct *tty;
4411 unsigned int ioaddr; 4395 unsigned int ioaddr;
4412 unsigned char mr0; 4396 unsigned char mr0;
4413 int len, stlen; 4397 int len, stlen;
@@ -4422,8 +4406,11 @@ static void stl_sc26198txisr(struct stlport *portp)
4422 if ((len == 0) || ((len < STL_TXBUFLOW) && 4406 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4423 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) { 4407 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4424 set_bit(ASYI_TXLOW, &portp->istate); 4408 set_bit(ASYI_TXLOW, &portp->istate);
4425 if (portp->port.tty) 4409 tty = tty_port_tty_get(&portp->port);
4426 tty_wakeup(portp->port.tty); 4410 if (tty) {
4411 tty_wakeup(tty);
4412 tty_kref_put(tty);
4413 }
4427 } 4414 }
4428 4415
4429 if (len == 0) { 4416 if (len == 0) {
@@ -4476,7 +4463,7 @@ static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack)
4476 4463
4477 pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack); 4464 pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack);
4478 4465
4479 tty = portp->port.tty; 4466 tty = tty_port_tty_get(&portp->port);
4480 ioaddr = portp->ioaddr; 4467 ioaddr = portp->ioaddr;
4481 outb(GIBCR, (ioaddr + XP_ADDR)); 4468 outb(GIBCR, (ioaddr + XP_ADDR));
4482 len = inb(ioaddr + XP_DATA) + 1; 4469 len = inb(ioaddr + XP_DATA) + 1;
@@ -4515,6 +4502,7 @@ static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack)
4515 stl_sc26198txunflow(portp, tty); 4502 stl_sc26198txunflow(portp, tty);
4516 } 4503 }
4517 } 4504 }
4505 tty_kref_put(tty);
4518} 4506}
4519 4507
4520/*****************************************************************************/ 4508/*****************************************************************************/
@@ -4528,7 +4516,7 @@ static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char
4528 struct tty_struct *tty; 4516 struct tty_struct *tty;
4529 unsigned int ioaddr; 4517 unsigned int ioaddr;
4530 4518
4531 tty = portp->port.tty; 4519 tty = tty_port_tty_get(&portp->port);
4532 ioaddr = portp->ioaddr; 4520 ioaddr = portp->ioaddr;
4533 4521
4534 if (status & SR_RXPARITY) 4522 if (status & SR_RXPARITY)
@@ -4566,6 +4554,7 @@ static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char
4566 if (status == 0) 4554 if (status == 0)
4567 portp->stats.rxtotal++; 4555 portp->stats.rxtotal++;
4568 } 4556 }
4557 tty_kref_put(tty);
4569} 4558}
4570 4559
4571/*****************************************************************************/ 4560/*****************************************************************************/
@@ -4754,8 +4743,8 @@ static int __init stallion_module_init(void)
4754 if (IS_ERR(stallion_class)) 4743 if (IS_ERR(stallion_class))
4755 printk("STALLION: failed to create class\n"); 4744 printk("STALLION: failed to create class\n");
4756 for (i = 0; i < 4; i++) 4745 for (i = 0; i < 4; i++)
4757 device_create_drvdata(stallion_class, NULL, MKDEV(STL_SIOMEMMAJOR, i), 4746 device_create(stallion_class, NULL, MKDEV(STL_SIOMEMMAJOR, i),
4758 NULL, "staliomem%d", i); 4747 NULL, "staliomem%d", i);
4759 4748
4760 return 0; 4749 return 0;
4761err_unrtty: 4750err_unrtty:
diff --git a/drivers/char/sx.c b/drivers/char/sx.c
index c385206f9db5..5b8d7a1aa3e6 100644
--- a/drivers/char/sx.c
+++ b/drivers/char/sx.c
@@ -2504,7 +2504,7 @@ static void __devexit sx_remove_card(struct sx_board *board,
2504 del_timer(&board->timer); 2504 del_timer(&board->timer);
2505 if (pdev) { 2505 if (pdev) {
2506#ifdef CONFIG_PCI 2506#ifdef CONFIG_PCI
2507 pci_iounmap(pdev, board->base); 2507 pci_iounmap(pdev, board->base2);
2508 pci_release_region(pdev, IS_CF_BOARD(board) ? 3 : 2); 2508 pci_release_region(pdev, IS_CF_BOARD(board) ? 3 : 2);
2509#endif 2509#endif
2510 } else { 2510 } else {
@@ -2703,7 +2703,7 @@ static int __devinit sx_pci_probe(struct pci_dev *pdev,
2703 2703
2704 return 0; 2704 return 0;
2705err_unmap: 2705err_unmap:
2706 pci_iounmap(pdev, board->base); 2706 pci_iounmap(pdev, board->base2);
2707err_reg: 2707err_reg:
2708 pci_release_region(pdev, reg); 2708 pci_release_region(pdev, reg);
2709err_flag: 2709err_flag:
diff --git a/drivers/char/sysrq.c b/drivers/char/sysrq.c
index 8fdfe9c871e3..dce4cc0e6953 100644
--- a/drivers/char/sysrq.c
+++ b/drivers/char/sysrq.c
@@ -23,6 +23,7 @@
23#include <linux/reboot.h> 23#include <linux/reboot.h>
24#include <linux/sysrq.h> 24#include <linux/sysrq.h>
25#include <linux/kbd_kern.h> 25#include <linux/kbd_kern.h>
26#include <linux/proc_fs.h>
26#include <linux/quotaops.h> 27#include <linux/quotaops.h>
27#include <linux/kernel.h> 28#include <linux/kernel.h>
28#include <linux/module.h> 29#include <linux/module.h>
@@ -326,6 +327,7 @@ static struct sysrq_key_op sysrq_moom_op = {
326 .handler = sysrq_handle_moom, 327 .handler = sysrq_handle_moom,
327 .help_msg = "Full", 328 .help_msg = "Full",
328 .action_msg = "Manual OOM execution", 329 .action_msg = "Manual OOM execution",
330 .enable_mask = SYSRQ_ENABLE_SIGNAL,
329}; 331};
330 332
331static void sysrq_handle_kill(int key, struct tty_struct *tty) 333static void sysrq_handle_kill(int key, struct tty_struct *tty)
@@ -533,3 +535,32 @@ int unregister_sysrq_key(int key, struct sysrq_key_op *op_p)
533 return __sysrq_swap_key_ops(key, NULL, op_p); 535 return __sysrq_swap_key_ops(key, NULL, op_p);
534} 536}
535EXPORT_SYMBOL(unregister_sysrq_key); 537EXPORT_SYMBOL(unregister_sysrq_key);
538
539#ifdef CONFIG_PROC_FS
540/*
541 * writing 'C' to /proc/sysrq-trigger is like sysrq-C
542 */
543static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
544 size_t count, loff_t *ppos)
545{
546 if (count) {
547 char c;
548
549 if (get_user(c, buf))
550 return -EFAULT;
551 __handle_sysrq(c, NULL, 0);
552 }
553 return count;
554}
555
556static const struct file_operations proc_sysrq_trigger_operations = {
557 .write = write_sysrq_trigger,
558};
559
560static int __init sysrq_init(void)
561{
562 proc_create("sysrq-trigger", S_IWUSR, NULL, &proc_sysrq_trigger_operations);
563 return 0;
564}
565module_init(sysrq_init);
566#endif
diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
index ae766d868454..e70d13defde4 100644
--- a/drivers/char/tpm/tpm.c
+++ b/drivers/char/tpm/tpm.c
@@ -525,19 +525,19 @@ void tpm_get_timeouts(struct tpm_chip *chip)
525 timeout = 525 timeout =
526 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX))); 526 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_1_IDX)));
527 if (timeout) 527 if (timeout)
528 chip->vendor.timeout_a = msecs_to_jiffies(timeout); 528 chip->vendor.timeout_a = usecs_to_jiffies(timeout);
529 timeout = 529 timeout =
530 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_2_IDX))); 530 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_2_IDX)));
531 if (timeout) 531 if (timeout)
532 chip->vendor.timeout_b = msecs_to_jiffies(timeout); 532 chip->vendor.timeout_b = usecs_to_jiffies(timeout);
533 timeout = 533 timeout =
534 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_3_IDX))); 534 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_3_IDX)));
535 if (timeout) 535 if (timeout)
536 chip->vendor.timeout_c = msecs_to_jiffies(timeout); 536 chip->vendor.timeout_c = usecs_to_jiffies(timeout);
537 timeout = 537 timeout =
538 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_4_IDX))); 538 be32_to_cpu(*((__be32 *) (data + TPM_GET_CAP_RET_UINT32_4_IDX)));
539 if (timeout) 539 if (timeout)
540 chip->vendor.timeout_d = msecs_to_jiffies(timeout); 540 chip->vendor.timeout_d = usecs_to_jiffies(timeout);
541 541
542duration: 542duration:
543 memcpy(data, tpm_cap, sizeof(tpm_cap)); 543 memcpy(data, tpm_cap, sizeof(tpm_cap));
@@ -554,15 +554,22 @@ duration:
554 return; 554 return;
555 555
556 chip->vendor.duration[TPM_SHORT] = 556 chip->vendor.duration[TPM_SHORT] =
557 msecs_to_jiffies(be32_to_cpu 557 usecs_to_jiffies(be32_to_cpu
558 (*((__be32 *) (data + 558 (*((__be32 *) (data +
559 TPM_GET_CAP_RET_UINT32_1_IDX)))); 559 TPM_GET_CAP_RET_UINT32_1_IDX))));
560 /* The Broadcom BCM0102 chipset in a Dell Latitude D820 gets the above
561 * value wrong and apparently reports msecs rather than usecs. So we
562 * fix up the resulting too-small TPM_SHORT value to make things work.
563 */
564 if (chip->vendor.duration[TPM_SHORT] < (HZ/100))
565 chip->vendor.duration[TPM_SHORT] = HZ;
566
560 chip->vendor.duration[TPM_MEDIUM] = 567 chip->vendor.duration[TPM_MEDIUM] =
561 msecs_to_jiffies(be32_to_cpu 568 usecs_to_jiffies(be32_to_cpu
562 (*((__be32 *) (data + 569 (*((__be32 *) (data +
563 TPM_GET_CAP_RET_UINT32_2_IDX)))); 570 TPM_GET_CAP_RET_UINT32_2_IDX))));
564 chip->vendor.duration[TPM_LONG] = 571 chip->vendor.duration[TPM_LONG] =
565 msecs_to_jiffies(be32_to_cpu 572 usecs_to_jiffies(be32_to_cpu
566 (*((__be32 *) (data + 573 (*((__be32 *) (data +
567 TPM_GET_CAP_RET_UINT32_3_IDX)))); 574 TPM_GET_CAP_RET_UINT32_3_IDX))));
568} 575}
@@ -954,72 +961,63 @@ EXPORT_SYMBOL_GPL(tpm_store_cancel);
954 961
955/* 962/*
956 * Device file system interface to the TPM 963 * Device file system interface to the TPM
964 *
965 * It's assured that the chip will be opened just once,
966 * by the check of is_open variable, which is protected
967 * by driver_lock.
957 */ 968 */
958int tpm_open(struct inode *inode, struct file *file) 969int tpm_open(struct inode *inode, struct file *file)
959{ 970{
960 int rc = 0, minor = iminor(inode); 971 int minor = iminor(inode);
961 struct tpm_chip *chip = NULL, *pos; 972 struct tpm_chip *chip = NULL, *pos;
962 973
963 lock_kernel(); 974 rcu_read_lock();
964 spin_lock(&driver_lock); 975 list_for_each_entry_rcu(pos, &tpm_chip_list, list) {
965
966 list_for_each_entry(pos, &tpm_chip_list, list) {
967 if (pos->vendor.miscdev.minor == minor) { 976 if (pos->vendor.miscdev.minor == minor) {
968 chip = pos; 977 chip = pos;
978 get_device(chip->dev);
969 break; 979 break;
970 } 980 }
971 } 981 }
982 rcu_read_unlock();
972 983
973 if (chip == NULL) { 984 if (!chip)
974 rc = -ENODEV; 985 return -ENODEV;
975 goto err_out;
976 }
977 986
978 if (chip->num_opens) { 987 if (test_and_set_bit(0, &chip->is_open)) {
979 dev_dbg(chip->dev, "Another process owns this TPM\n"); 988 dev_dbg(chip->dev, "Another process owns this TPM\n");
980 rc = -EBUSY; 989 put_device(chip->dev);
981 goto err_out; 990 return -EBUSY;
982 } 991 }
983 992
984 chip->num_opens++;
985 get_device(chip->dev);
986
987 spin_unlock(&driver_lock);
988
989 chip->data_buffer = kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL); 993 chip->data_buffer = kmalloc(TPM_BUFSIZE * sizeof(u8), GFP_KERNEL);
990 if (chip->data_buffer == NULL) { 994 if (chip->data_buffer == NULL) {
991 chip->num_opens--; 995 clear_bit(0, &chip->is_open);
992 put_device(chip->dev); 996 put_device(chip->dev);
993 unlock_kernel();
994 return -ENOMEM; 997 return -ENOMEM;
995 } 998 }
996 999
997 atomic_set(&chip->data_pending, 0); 1000 atomic_set(&chip->data_pending, 0);
998 1001
999 file->private_data = chip; 1002 file->private_data = chip;
1000 unlock_kernel();
1001 return 0; 1003 return 0;
1002
1003err_out:
1004 spin_unlock(&driver_lock);
1005 unlock_kernel();
1006 return rc;
1007} 1004}
1008EXPORT_SYMBOL_GPL(tpm_open); 1005EXPORT_SYMBOL_GPL(tpm_open);
1009 1006
1007/*
1008 * Called on file close
1009 */
1010int tpm_release(struct inode *inode, struct file *file) 1010int tpm_release(struct inode *inode, struct file *file)
1011{ 1011{
1012 struct tpm_chip *chip = file->private_data; 1012 struct tpm_chip *chip = file->private_data;
1013 1013
1014 del_singleshot_timer_sync(&chip->user_read_timer);
1014 flush_scheduled_work(); 1015 flush_scheduled_work();
1015 spin_lock(&driver_lock);
1016 file->private_data = NULL; 1016 file->private_data = NULL;
1017 del_singleshot_timer_sync(&chip->user_read_timer);
1018 atomic_set(&chip->data_pending, 0); 1017 atomic_set(&chip->data_pending, 0);
1019 chip->num_opens--;
1020 put_device(chip->dev);
1021 kfree(chip->data_buffer); 1018 kfree(chip->data_buffer);
1022 spin_unlock(&driver_lock); 1019 clear_bit(0, &chip->is_open);
1020 put_device(chip->dev);
1023 return 0; 1021 return 0;
1024} 1022}
1025EXPORT_SYMBOL_GPL(tpm_release); 1023EXPORT_SYMBOL_GPL(tpm_release);
@@ -1093,13 +1091,11 @@ void tpm_remove_hardware(struct device *dev)
1093 } 1091 }
1094 1092
1095 spin_lock(&driver_lock); 1093 spin_lock(&driver_lock);
1096 1094 list_del_rcu(&chip->list);
1097 list_del(&chip->list);
1098
1099 spin_unlock(&driver_lock); 1095 spin_unlock(&driver_lock);
1096 synchronize_rcu();
1100 1097
1101 misc_deregister(&chip->vendor.miscdev); 1098 misc_deregister(&chip->vendor.miscdev);
1102
1103 sysfs_remove_group(&dev->kobj, chip->vendor.attr_group); 1099 sysfs_remove_group(&dev->kobj, chip->vendor.attr_group);
1104 tpm_bios_log_teardown(chip->bios_dir); 1100 tpm_bios_log_teardown(chip->bios_dir);
1105 1101
@@ -1144,25 +1140,33 @@ int tpm_pm_resume(struct device *dev)
1144} 1140}
1145EXPORT_SYMBOL_GPL(tpm_pm_resume); 1141EXPORT_SYMBOL_GPL(tpm_pm_resume);
1146 1142
1143/* In case vendor provided release function, call it too.*/
1144
1145void tpm_dev_vendor_release(struct tpm_chip *chip)
1146{
1147 if (chip->vendor.release)
1148 chip->vendor.release(chip->dev);
1149
1150 clear_bit(chip->dev_num, dev_mask);
1151 kfree(chip->vendor.miscdev.name);
1152}
1153EXPORT_SYMBOL_GPL(tpm_dev_vendor_release);
1154
1155
1147/* 1156/*
1148 * Once all references to platform device are down to 0, 1157 * Once all references to platform device are down to 0,
1149 * release all allocated structures. 1158 * release all allocated structures.
1150 * In case vendor provided release function,
1151 * call it too.
1152 */ 1159 */
1153static void tpm_dev_release(struct device *dev) 1160static void tpm_dev_release(struct device *dev)
1154{ 1161{
1155 struct tpm_chip *chip = dev_get_drvdata(dev); 1162 struct tpm_chip *chip = dev_get_drvdata(dev);
1156 1163
1157 if (chip->vendor.release) 1164 tpm_dev_vendor_release(chip);
1158 chip->vendor.release(dev);
1159 1165
1160 chip->release(dev); 1166 chip->release(dev);
1161
1162 clear_bit(chip->dev_num, dev_mask);
1163 kfree(chip->vendor.miscdev.name);
1164 kfree(chip); 1167 kfree(chip);
1165} 1168}
1169EXPORT_SYMBOL_GPL(tpm_dev_release);
1166 1170
1167/* 1171/*
1168 * Called from tpm_<specific>.c probe function only for devices 1172 * Called from tpm_<specific>.c probe function only for devices
@@ -1171,8 +1175,8 @@ static void tpm_dev_release(struct device *dev)
1171 * upon errant exit from this function specific probe function should call 1175 * upon errant exit from this function specific probe function should call
1172 * pci_disable_device 1176 * pci_disable_device
1173 */ 1177 */
1174struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vendor_specific 1178struct tpm_chip *tpm_register_hardware(struct device *dev,
1175 *entry) 1179 const struct tpm_vendor_specific *entry)
1176{ 1180{
1177#define DEVNAME_SIZE 7 1181#define DEVNAME_SIZE 7
1178 1182
@@ -1183,11 +1187,8 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
1183 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 1187 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1184 devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL); 1188 devname = kmalloc(DEVNAME_SIZE, GFP_KERNEL);
1185 1189
1186 if (chip == NULL || devname == NULL) { 1190 if (chip == NULL || devname == NULL)
1187 kfree(chip); 1191 goto out_free;
1188 kfree(devname);
1189 return NULL;
1190 }
1191 1192
1192 mutex_init(&chip->buffer_mutex); 1193 mutex_init(&chip->buffer_mutex);
1193 mutex_init(&chip->tpm_mutex); 1194 mutex_init(&chip->tpm_mutex);
@@ -1204,8 +1205,7 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
1204 1205
1205 if (chip->dev_num >= TPM_NUM_DEVICES) { 1206 if (chip->dev_num >= TPM_NUM_DEVICES) {
1206 dev_err(dev, "No available tpm device numbers\n"); 1207 dev_err(dev, "No available tpm device numbers\n");
1207 kfree(chip); 1208 goto out_free;
1208 return NULL;
1209 } else if (chip->dev_num == 0) 1209 } else if (chip->dev_num == 0)
1210 chip->vendor.miscdev.minor = TPM_MINOR; 1210 chip->vendor.miscdev.minor = TPM_MINOR;
1211 else 1211 else
@@ -1231,22 +1231,26 @@ struct tpm_chip *tpm_register_hardware(struct device *dev, const struct tpm_vend
1231 return NULL; 1231 return NULL;
1232 } 1232 }
1233 1233
1234 spin_lock(&driver_lock);
1235
1236 list_add(&chip->list, &tpm_chip_list);
1237
1238 spin_unlock(&driver_lock);
1239
1240 if (sysfs_create_group(&dev->kobj, chip->vendor.attr_group)) { 1234 if (sysfs_create_group(&dev->kobj, chip->vendor.attr_group)) {
1241 list_del(&chip->list);
1242 misc_deregister(&chip->vendor.miscdev); 1235 misc_deregister(&chip->vendor.miscdev);
1243 put_device(chip->dev); 1236 put_device(chip->dev);
1237
1244 return NULL; 1238 return NULL;
1245 } 1239 }
1246 1240
1247 chip->bios_dir = tpm_bios_log_setup(devname); 1241 chip->bios_dir = tpm_bios_log_setup(devname);
1248 1242
1243 /* Make chip available */
1244 spin_lock(&driver_lock);
1245 list_add_rcu(&chip->list, &tpm_chip_list);
1246 spin_unlock(&driver_lock);
1247
1249 return chip; 1248 return chip;
1249
1250out_free:
1251 kfree(chip);
1252 kfree(devname);
1253 return NULL;
1250} 1254}
1251EXPORT_SYMBOL_GPL(tpm_register_hardware); 1255EXPORT_SYMBOL_GPL(tpm_register_hardware);
1252 1256
diff --git a/drivers/char/tpm/tpm.h b/drivers/char/tpm/tpm.h
index e885148b4cfb..8e30df4a4388 100644
--- a/drivers/char/tpm/tpm.h
+++ b/drivers/char/tpm/tpm.h
@@ -90,7 +90,7 @@ struct tpm_chip {
90 struct device *dev; /* Device stuff */ 90 struct device *dev; /* Device stuff */
91 91
92 int dev_num; /* /dev/tpm# */ 92 int dev_num; /* /dev/tpm# */
93 int num_opens; /* only one allowed */ 93 unsigned long is_open; /* only one allowed */
94 int time_expired; 94 int time_expired;
95 95
96 /* Data passed to and from the tpm via the read/write calls */ 96 /* Data passed to and from the tpm via the read/write calls */
@@ -132,6 +132,7 @@ extern struct tpm_chip* tpm_register_hardware(struct device *,
132 const struct tpm_vendor_specific *); 132 const struct tpm_vendor_specific *);
133extern int tpm_open(struct inode *, struct file *); 133extern int tpm_open(struct inode *, struct file *);
134extern int tpm_release(struct inode *, struct file *); 134extern int tpm_release(struct inode *, struct file *);
135extern void tpm_dev_vendor_release(struct tpm_chip *);
135extern ssize_t tpm_write(struct file *, const char __user *, size_t, 136extern ssize_t tpm_write(struct file *, const char __user *, size_t,
136 loff_t *); 137 loff_t *);
137extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *); 138extern ssize_t tpm_read(struct file *, char __user *, size_t, loff_t *);
diff --git a/drivers/char/tpm/tpm_tis.c b/drivers/char/tpm/tpm_tis.c
index ed1879c0dd8d..717af7ad1bdf 100644
--- a/drivers/char/tpm/tpm_tis.c
+++ b/drivers/char/tpm/tpm_tis.c
@@ -630,12 +630,23 @@ static struct pnp_device_id tpm_pnp_tbl[] __devinitdata = {
630 {"", 0} /* Terminator */ 630 {"", 0} /* Terminator */
631}; 631};
632 632
633static __devexit void tpm_tis_pnp_remove(struct pnp_dev *dev)
634{
635 struct tpm_chip *chip = pnp_get_drvdata(dev);
636
637 tpm_dev_vendor_release(chip);
638
639 kfree(chip);
640}
641
642
633static struct pnp_driver tis_pnp_driver = { 643static struct pnp_driver tis_pnp_driver = {
634 .name = "tpm_tis", 644 .name = "tpm_tis",
635 .id_table = tpm_pnp_tbl, 645 .id_table = tpm_pnp_tbl,
636 .probe = tpm_tis_pnp_init, 646 .probe = tpm_tis_pnp_init,
637 .suspend = tpm_tis_pnp_suspend, 647 .suspend = tpm_tis_pnp_suspend,
638 .resume = tpm_tis_pnp_resume, 648 .resume = tpm_tis_pnp_resume,
649 .remove = tpm_tis_pnp_remove,
639}; 650};
640 651
641#define TIS_HID_USR_IDX sizeof(tpm_pnp_tbl)/sizeof(struct pnp_device_id) -2 652#define TIS_HID_USR_IDX sizeof(tpm_pnp_tbl)/sizeof(struct pnp_device_id) -2
@@ -683,6 +694,7 @@ static void __exit cleanup_tis(void)
683 spin_lock(&tis_lock); 694 spin_lock(&tis_lock);
684 list_for_each_entry_safe(i, j, &tis_chips, list) { 695 list_for_each_entry_safe(i, j, &tis_chips, list) {
685 chip = to_tpm_chip(i); 696 chip = to_tpm_chip(i);
697 tpm_remove_hardware(chip->dev);
686 iowrite32(~TPM_GLOBAL_INT_ENABLE & 698 iowrite32(~TPM_GLOBAL_INT_ENABLE &
687 ioread32(chip->vendor.iobase + 699 ioread32(chip->vendor.iobase +
688 TPM_INT_ENABLE(chip->vendor. 700 TPM_INT_ENABLE(chip->vendor.
@@ -694,9 +706,9 @@ static void __exit cleanup_tis(void)
694 free_irq(chip->vendor.irq, chip); 706 free_irq(chip->vendor.irq, chip);
695 iounmap(i->iobase); 707 iounmap(i->iobase);
696 list_del(&i->list); 708 list_del(&i->list);
697 tpm_remove_hardware(chip->dev);
698 } 709 }
699 spin_unlock(&tis_lock); 710 spin_unlock(&tis_lock);
711
700 if (force) { 712 if (force) {
701 platform_device_unregister(pdev); 713 platform_device_unregister(pdev);
702 driver_unregister(&tis_drv); 714 driver_unregister(&tis_drv);
diff --git a/drivers/char/tty_audit.c b/drivers/char/tty_audit.c
index 3582f43345a8..5787249934c8 100644
--- a/drivers/char/tty_audit.c
+++ b/drivers/char/tty_audit.c
@@ -93,7 +93,7 @@ static void tty_audit_buf_push(struct task_struct *tsk, uid_t loginuid,
93 get_task_comm(name, tsk); 93 get_task_comm(name, tsk);
94 audit_log_untrustedstring(ab, name); 94 audit_log_untrustedstring(ab, name);
95 audit_log_format(ab, " data="); 95 audit_log_format(ab, " data=");
96 audit_log_n_untrustedstring(ab, buf->data, buf->valid); 96 audit_log_n_hex(ab, buf->data, buf->valid);
97 audit_log_end(ab); 97 audit_log_end(ab);
98 } 98 }
99 buf->valid = 0; 99 buf->valid = 0;
diff --git a/drivers/char/tty_buffer.c b/drivers/char/tty_buffer.c
new file mode 100644
index 000000000000..810ee25d66a4
--- /dev/null
+++ b/drivers/char/tty_buffer.c
@@ -0,0 +1,511 @@
1/*
2 * Tty buffer allocation management
3 */
4
5#include <linux/types.h>
6#include <linux/errno.h>
7#include <linux/tty.h>
8#include <linux/tty_driver.h>
9#include <linux/tty_flip.h>
10#include <linux/timer.h>
11#include <linux/string.h>
12#include <linux/slab.h>
13#include <linux/sched.h>
14#include <linux/init.h>
15#include <linux/wait.h>
16#include <linux/bitops.h>
17#include <linux/delay.h>
18#include <linux/module.h>
19
20/**
21 * tty_buffer_free_all - free buffers used by a tty
22 * @tty: tty to free from
23 *
24 * Remove all the buffers pending on a tty whether queued with data
25 * or in the free ring. Must be called when the tty is no longer in use
26 *
27 * Locking: none
28 */
29
30void tty_buffer_free_all(struct tty_struct *tty)
31{
32 struct tty_buffer *thead;
33 while ((thead = tty->buf.head) != NULL) {
34 tty->buf.head = thead->next;
35 kfree(thead);
36 }
37 while ((thead = tty->buf.free) != NULL) {
38 tty->buf.free = thead->next;
39 kfree(thead);
40 }
41 tty->buf.tail = NULL;
42 tty->buf.memory_used = 0;
43}
44
45/**
46 * tty_buffer_alloc - allocate a tty buffer
47 * @tty: tty device
48 * @size: desired size (characters)
49 *
50 * Allocate a new tty buffer to hold the desired number of characters.
51 * Return NULL if out of memory or the allocation would exceed the
52 * per device queue
53 *
54 * Locking: Caller must hold tty->buf.lock
55 */
56
57static struct tty_buffer *tty_buffer_alloc(struct tty_struct *tty, size_t size)
58{
59 struct tty_buffer *p;
60
61 if (tty->buf.memory_used + size > 65536)
62 return NULL;
63 p = kmalloc(sizeof(struct tty_buffer) + 2 * size, GFP_ATOMIC);
64 if (p == NULL)
65 return NULL;
66 p->used = 0;
67 p->size = size;
68 p->next = NULL;
69 p->commit = 0;
70 p->read = 0;
71 p->char_buf_ptr = (char *)(p->data);
72 p->flag_buf_ptr = (unsigned char *)p->char_buf_ptr + size;
73 tty->buf.memory_used += size;
74 return p;
75}
76
77/**
78 * tty_buffer_free - free a tty buffer
79 * @tty: tty owning the buffer
80 * @b: the buffer to free
81 *
82 * Free a tty buffer, or add it to the free list according to our
83 * internal strategy
84 *
85 * Locking: Caller must hold tty->buf.lock
86 */
87
88static void tty_buffer_free(struct tty_struct *tty, struct tty_buffer *b)
89{
90 /* Dumb strategy for now - should keep some stats */
91 tty->buf.memory_used -= b->size;
92 WARN_ON(tty->buf.memory_used < 0);
93
94 if (b->size >= 512)
95 kfree(b);
96 else {
97 b->next = tty->buf.free;
98 tty->buf.free = b;
99 }
100}
101
102/**
103 * __tty_buffer_flush - flush full tty buffers
104 * @tty: tty to flush
105 *
106 * flush all the buffers containing receive data. Caller must
107 * hold the buffer lock and must have ensured no parallel flush to
108 * ldisc is running.
109 *
110 * Locking: Caller must hold tty->buf.lock
111 */
112
113static void __tty_buffer_flush(struct tty_struct *tty)
114{
115 struct tty_buffer *thead;
116
117 while ((thead = tty->buf.head) != NULL) {
118 tty->buf.head = thead->next;
119 tty_buffer_free(tty, thead);
120 }
121 tty->buf.tail = NULL;
122}
123
124/**
125 * tty_buffer_flush - flush full tty buffers
126 * @tty: tty to flush
127 *
128 * flush all the buffers containing receive data. If the buffer is
129 * being processed by flush_to_ldisc then we defer the processing
130 * to that function
131 *
132 * Locking: none
133 */
134
135void tty_buffer_flush(struct tty_struct *tty)
136{
137 unsigned long flags;
138 spin_lock_irqsave(&tty->buf.lock, flags);
139
140 /* If the data is being pushed to the tty layer then we can't
141 process it here. Instead set a flag and the flush_to_ldisc
142 path will process the flush request before it exits */
143 if (test_bit(TTY_FLUSHING, &tty->flags)) {
144 set_bit(TTY_FLUSHPENDING, &tty->flags);
145 spin_unlock_irqrestore(&tty->buf.lock, flags);
146 wait_event(tty->read_wait,
147 test_bit(TTY_FLUSHPENDING, &tty->flags) == 0);
148 return;
149 } else
150 __tty_buffer_flush(tty);
151 spin_unlock_irqrestore(&tty->buf.lock, flags);
152}
153
154/**
155 * tty_buffer_find - find a free tty buffer
156 * @tty: tty owning the buffer
157 * @size: characters wanted
158 *
159 * Locate an existing suitable tty buffer or if we are lacking one then
160 * allocate a new one. We round our buffers off in 256 character chunks
161 * to get better allocation behaviour.
162 *
163 * Locking: Caller must hold tty->buf.lock
164 */
165
166static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size)
167{
168 struct tty_buffer **tbh = &tty->buf.free;
169 while ((*tbh) != NULL) {
170 struct tty_buffer *t = *tbh;
171 if (t->size >= size) {
172 *tbh = t->next;
173 t->next = NULL;
174 t->used = 0;
175 t->commit = 0;
176 t->read = 0;
177 tty->buf.memory_used += t->size;
178 return t;
179 }
180 tbh = &((*tbh)->next);
181 }
182 /* Round the buffer size out */
183 size = (size + 0xFF) & ~0xFF;
184 return tty_buffer_alloc(tty, size);
185 /* Should possibly check if this fails for the largest buffer we
186 have queued and recycle that ? */
187}
188
189/**
190 * tty_buffer_request_room - grow tty buffer if needed
191 * @tty: tty structure
192 * @size: size desired
193 *
194 * Make at least size bytes of linear space available for the tty
195 * buffer. If we fail return the size we managed to find.
196 *
197 * Locking: Takes tty->buf.lock
198 */
199int tty_buffer_request_room(struct tty_struct *tty, size_t size)
200{
201 struct tty_buffer *b, *n;
202 int left;
203 unsigned long flags;
204
205 spin_lock_irqsave(&tty->buf.lock, flags);
206
207 /* OPTIMISATION: We could keep a per tty "zero" sized buffer to
208 remove this conditional if its worth it. This would be invisible
209 to the callers */
210 if ((b = tty->buf.tail) != NULL)
211 left = b->size - b->used;
212 else
213 left = 0;
214
215 if (left < size) {
216 /* This is the slow path - looking for new buffers to use */
217 if ((n = tty_buffer_find(tty, size)) != NULL) {
218 if (b != NULL) {
219 b->next = n;
220 b->commit = b->used;
221 } else
222 tty->buf.head = n;
223 tty->buf.tail = n;
224 } else
225 size = left;
226 }
227
228 spin_unlock_irqrestore(&tty->buf.lock, flags);
229 return size;
230}
231EXPORT_SYMBOL_GPL(tty_buffer_request_room);
232
233/**
234 * tty_insert_flip_string - Add characters to the tty buffer
235 * @tty: tty structure
236 * @chars: characters
237 * @size: size
238 *
239 * Queue a series of bytes to the tty buffering. All the characters
240 * passed are marked as without error. Returns the number added.
241 *
242 * Locking: Called functions may take tty->buf.lock
243 */
244
245int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars,
246 size_t size)
247{
248 int copied = 0;
249 do {
250 int space = tty_buffer_request_room(tty, size - copied);
251 struct tty_buffer *tb = tty->buf.tail;
252 /* If there is no space then tb may be NULL */
253 if (unlikely(space == 0))
254 break;
255 memcpy(tb->char_buf_ptr + tb->used, chars, space);
256 memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space);
257 tb->used += space;
258 copied += space;
259 chars += space;
260 /* There is a small chance that we need to split the data over
261 several buffers. If this is the case we must loop */
262 } while (unlikely(size > copied));
263 return copied;
264}
265EXPORT_SYMBOL(tty_insert_flip_string);
266
267/**
268 * tty_insert_flip_string_flags - Add characters to the tty buffer
269 * @tty: tty structure
270 * @chars: characters
271 * @flags: flag bytes
272 * @size: size
273 *
274 * Queue a series of bytes to the tty buffering. For each character
275 * the flags array indicates the status of the character. Returns the
276 * number added.
277 *
278 * Locking: Called functions may take tty->buf.lock
279 */
280
281int tty_insert_flip_string_flags(struct tty_struct *tty,
282 const unsigned char *chars, const char *flags, size_t size)
283{
284 int copied = 0;
285 do {
286 int space = tty_buffer_request_room(tty, size - copied);
287 struct tty_buffer *tb = tty->buf.tail;
288 /* If there is no space then tb may be NULL */
289 if (unlikely(space == 0))
290 break;
291 memcpy(tb->char_buf_ptr + tb->used, chars, space);
292 memcpy(tb->flag_buf_ptr + tb->used, flags, space);
293 tb->used += space;
294 copied += space;
295 chars += space;
296 flags += space;
297 /* There is a small chance that we need to split the data over
298 several buffers. If this is the case we must loop */
299 } while (unlikely(size > copied));
300 return copied;
301}
302EXPORT_SYMBOL(tty_insert_flip_string_flags);
303
304/**
305 * tty_schedule_flip - push characters to ldisc
306 * @tty: tty to push from
307 *
308 * Takes any pending buffers and transfers their ownership to the
309 * ldisc side of the queue. It then schedules those characters for
310 * processing by the line discipline.
311 *
312 * Locking: Takes tty->buf.lock
313 */
314
315void tty_schedule_flip(struct tty_struct *tty)
316{
317 unsigned long flags;
318 spin_lock_irqsave(&tty->buf.lock, flags);
319 if (tty->buf.tail != NULL)
320 tty->buf.tail->commit = tty->buf.tail->used;
321 spin_unlock_irqrestore(&tty->buf.lock, flags);
322 schedule_delayed_work(&tty->buf.work, 1);
323}
324EXPORT_SYMBOL(tty_schedule_flip);
325
326/**
327 * tty_prepare_flip_string - make room for characters
328 * @tty: tty
329 * @chars: return pointer for character write area
330 * @size: desired size
331 *
332 * Prepare a block of space in the buffer for data. Returns the length
333 * available and buffer pointer to the space which is now allocated and
334 * accounted for as ready for normal characters. This is used for drivers
335 * that need their own block copy routines into the buffer. There is no
336 * guarantee the buffer is a DMA target!
337 *
338 * Locking: May call functions taking tty->buf.lock
339 */
340
341int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars,
342 size_t size)
343{
344 int space = tty_buffer_request_room(tty, size);
345 if (likely(space)) {
346 struct tty_buffer *tb = tty->buf.tail;
347 *chars = tb->char_buf_ptr + tb->used;
348 memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space);
349 tb->used += space;
350 }
351 return space;
352}
353EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
354
355/**
356 * tty_prepare_flip_string_flags - make room for characters
357 * @tty: tty
358 * @chars: return pointer for character write area
359 * @flags: return pointer for status flag write area
360 * @size: desired size
361 *
362 * Prepare a block of space in the buffer for data. Returns the length
363 * available and buffer pointer to the space which is now allocated and
364 * accounted for as ready for characters. This is used for drivers
365 * that need their own block copy routines into the buffer. There is no
366 * guarantee the buffer is a DMA target!
367 *
368 * Locking: May call functions taking tty->buf.lock
369 */
370
371int tty_prepare_flip_string_flags(struct tty_struct *tty,
372 unsigned char **chars, char **flags, size_t size)
373{
374 int space = tty_buffer_request_room(tty, size);
375 if (likely(space)) {
376 struct tty_buffer *tb = tty->buf.tail;
377 *chars = tb->char_buf_ptr + tb->used;
378 *flags = tb->flag_buf_ptr + tb->used;
379 tb->used += space;
380 }
381 return space;
382}
383EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
384
385
386
387/**
388 * flush_to_ldisc
389 * @work: tty structure passed from work queue.
390 *
391 * This routine is called out of the software interrupt to flush data
392 * from the buffer chain to the line discipline.
393 *
394 * Locking: holds tty->buf.lock to guard buffer list. Drops the lock
395 * while invoking the line discipline receive_buf method. The
396 * receive_buf method is single threaded for each tty instance.
397 */
398
399static void flush_to_ldisc(struct work_struct *work)
400{
401 struct tty_struct *tty =
402 container_of(work, struct tty_struct, buf.work.work);
403 unsigned long flags;
404 struct tty_ldisc *disc;
405 struct tty_buffer *tbuf, *head;
406 char *char_buf;
407 unsigned char *flag_buf;
408
409 disc = tty_ldisc_ref(tty);
410 if (disc == NULL) /* !TTY_LDISC */
411 return;
412
413 spin_lock_irqsave(&tty->buf.lock, flags);
414 /* So we know a flush is running */
415 set_bit(TTY_FLUSHING, &tty->flags);
416 head = tty->buf.head;
417 if (head != NULL) {
418 tty->buf.head = NULL;
419 for (;;) {
420 int count = head->commit - head->read;
421 if (!count) {
422 if (head->next == NULL)
423 break;
424 tbuf = head;
425 head = head->next;
426 tty_buffer_free(tty, tbuf);
427 continue;
428 }
429 /* Ldisc or user is trying to flush the buffers
430 we are feeding to the ldisc, stop feeding the
431 line discipline as we want to empty the queue */
432 if (test_bit(TTY_FLUSHPENDING, &tty->flags))
433 break;
434 if (!tty->receive_room) {
435 schedule_delayed_work(&tty->buf.work, 1);
436 break;
437 }
438 if (count > tty->receive_room)
439 count = tty->receive_room;
440 char_buf = head->char_buf_ptr + head->read;
441 flag_buf = head->flag_buf_ptr + head->read;
442 head->read += count;
443 spin_unlock_irqrestore(&tty->buf.lock, flags);
444 disc->ops->receive_buf(tty, char_buf,
445 flag_buf, count);
446 spin_lock_irqsave(&tty->buf.lock, flags);
447 }
448 /* Restore the queue head */
449 tty->buf.head = head;
450 }
451 /* We may have a deferred request to flush the input buffer,
452 if so pull the chain under the lock and empty the queue */
453 if (test_bit(TTY_FLUSHPENDING, &tty->flags)) {
454 __tty_buffer_flush(tty);
455 clear_bit(TTY_FLUSHPENDING, &tty->flags);
456 wake_up(&tty->read_wait);
457 }
458 clear_bit(TTY_FLUSHING, &tty->flags);
459 spin_unlock_irqrestore(&tty->buf.lock, flags);
460
461 tty_ldisc_deref(disc);
462}
463
464/**
465 * tty_flip_buffer_push - terminal
466 * @tty: tty to push
467 *
468 * Queue a push of the terminal flip buffers to the line discipline. This
469 * function must not be called from IRQ context if tty->low_latency is set.
470 *
471 * In the event of the queue being busy for flipping the work will be
472 * held off and retried later.
473 *
474 * Locking: tty buffer lock. Driver locks in low latency mode.
475 */
476
477void tty_flip_buffer_push(struct tty_struct *tty)
478{
479 unsigned long flags;
480 spin_lock_irqsave(&tty->buf.lock, flags);
481 if (tty->buf.tail != NULL)
482 tty->buf.tail->commit = tty->buf.tail->used;
483 spin_unlock_irqrestore(&tty->buf.lock, flags);
484
485 if (tty->low_latency)
486 flush_to_ldisc(&tty->buf.work.work);
487 else
488 schedule_delayed_work(&tty->buf.work, 1);
489}
490EXPORT_SYMBOL(tty_flip_buffer_push);
491
492/**
493 * tty_buffer_init - prepare a tty buffer structure
494 * @tty: tty to initialise
495 *
496 * Set up the initial state of the buffer management for a tty device.
497 * Must be called before the other tty buffer functions are used.
498 *
499 * Locking: none
500 */
501
502void tty_buffer_init(struct tty_struct *tty)
503{
504 spin_lock_init(&tty->buf.lock);
505 tty->buf.head = NULL;
506 tty->buf.tail = NULL;
507 tty->buf.free = NULL;
508 tty->buf.memory_used = 0;
509 INIT_DELAYED_WORK(&tty->buf.work, flush_to_ldisc);
510}
511
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index e4dce8709541..59f472143f08 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -49,7 +49,7 @@
49 * implement CONFIG_VT and generalize console device interface. 49 * implement CONFIG_VT and generalize console device interface.
50 * -- Marko Kohtala <Marko.Kohtala@hut.fi>, March 97 50 * -- Marko Kohtala <Marko.Kohtala@hut.fi>, March 97
51 * 51 *
52 * Rewrote init_dev and release_dev to eliminate races. 52 * Rewrote tty_init_dev and tty_release_dev to eliminate races.
53 * -- Bill Hawes <whawes@star.net>, June 97 53 * -- Bill Hawes <whawes@star.net>, June 97
54 * 54 *
55 * Added devfs support. 55 * Added devfs support.
@@ -136,13 +136,6 @@ LIST_HEAD(tty_drivers); /* linked list of tty drivers */
136DEFINE_MUTEX(tty_mutex); 136DEFINE_MUTEX(tty_mutex);
137EXPORT_SYMBOL(tty_mutex); 137EXPORT_SYMBOL(tty_mutex);
138 138
139#ifdef CONFIG_UNIX98_PTYS
140extern struct tty_driver *ptm_driver; /* Unix98 pty masters; for /dev/ptmx */
141static int ptmx_open(struct inode *, struct file *);
142#endif
143
144static void initialize_tty_struct(struct tty_struct *tty);
145
146static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *); 139static ssize_t tty_read(struct file *, char __user *, size_t, loff_t *);
147static ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *); 140static ssize_t tty_write(struct file *, const char __user *, size_t, loff_t *);
148ssize_t redirected_tty_write(struct file *, const char __user *, 141ssize_t redirected_tty_write(struct file *, const char __user *,
@@ -171,13 +164,11 @@ static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty);
171 * Locking: none 164 * Locking: none
172 */ 165 */
173 166
174static struct tty_struct *alloc_tty_struct(void) 167struct tty_struct *alloc_tty_struct(void)
175{ 168{
176 return kzalloc(sizeof(struct tty_struct), GFP_KERNEL); 169 return kzalloc(sizeof(struct tty_struct), GFP_KERNEL);
177} 170}
178 171
179static void tty_buffer_free_all(struct tty_struct *);
180
181/** 172/**
182 * free_tty_struct - free a disused tty 173 * free_tty_struct - free a disused tty
183 * @tty: tty struct to free 174 * @tty: tty struct to free
@@ -187,7 +178,7 @@ static void tty_buffer_free_all(struct tty_struct *);
187 * Locking: none. Must be called after tty is definitely unused 178 * Locking: none. Must be called after tty is definitely unused
188 */ 179 */
189 180
190static inline void free_tty_struct(struct tty_struct *tty) 181void free_tty_struct(struct tty_struct *tty)
191{ 182{
192 kfree(tty->write_buf); 183 kfree(tty->write_buf);
193 tty_buffer_free_all(tty); 184 tty_buffer_free_all(tty);
@@ -263,398 +254,6 @@ static int check_tty_count(struct tty_struct *tty, const char *routine)
263 return 0; 254 return 0;
264} 255}
265 256
266/*
267 * Tty buffer allocation management
268 */
269
270/**
271 * tty_buffer_free_all - free buffers used by a tty
272 * @tty: tty to free from
273 *
274 * Remove all the buffers pending on a tty whether queued with data
275 * or in the free ring. Must be called when the tty is no longer in use
276 *
277 * Locking: none
278 */
279
280static void tty_buffer_free_all(struct tty_struct *tty)
281{
282 struct tty_buffer *thead;
283 while ((thead = tty->buf.head) != NULL) {
284 tty->buf.head = thead->next;
285 kfree(thead);
286 }
287 while ((thead = tty->buf.free) != NULL) {
288 tty->buf.free = thead->next;
289 kfree(thead);
290 }
291 tty->buf.tail = NULL;
292 tty->buf.memory_used = 0;
293}
294
295/**
296 * tty_buffer_init - prepare a tty buffer structure
297 * @tty: tty to initialise
298 *
299 * Set up the initial state of the buffer management for a tty device.
300 * Must be called before the other tty buffer functions are used.
301 *
302 * Locking: none
303 */
304
305static void tty_buffer_init(struct tty_struct *tty)
306{
307 spin_lock_init(&tty->buf.lock);
308 tty->buf.head = NULL;
309 tty->buf.tail = NULL;
310 tty->buf.free = NULL;
311 tty->buf.memory_used = 0;
312}
313
314/**
315 * tty_buffer_alloc - allocate a tty buffer
316 * @tty: tty device
317 * @size: desired size (characters)
318 *
319 * Allocate a new tty buffer to hold the desired number of characters.
320 * Return NULL if out of memory or the allocation would exceed the
321 * per device queue
322 *
323 * Locking: Caller must hold tty->buf.lock
324 */
325
326static struct tty_buffer *tty_buffer_alloc(struct tty_struct *tty, size_t size)
327{
328 struct tty_buffer *p;
329
330 if (tty->buf.memory_used + size > 65536)
331 return NULL;
332 p = kmalloc(sizeof(struct tty_buffer) + 2 * size, GFP_ATOMIC);
333 if (p == NULL)
334 return NULL;
335 p->used = 0;
336 p->size = size;
337 p->next = NULL;
338 p->commit = 0;
339 p->read = 0;
340 p->char_buf_ptr = (char *)(p->data);
341 p->flag_buf_ptr = (unsigned char *)p->char_buf_ptr + size;
342 tty->buf.memory_used += size;
343 return p;
344}
345
346/**
347 * tty_buffer_free - free a tty buffer
348 * @tty: tty owning the buffer
349 * @b: the buffer to free
350 *
351 * Free a tty buffer, or add it to the free list according to our
352 * internal strategy
353 *
354 * Locking: Caller must hold tty->buf.lock
355 */
356
357static void tty_buffer_free(struct tty_struct *tty, struct tty_buffer *b)
358{
359 /* Dumb strategy for now - should keep some stats */
360 tty->buf.memory_used -= b->size;
361 WARN_ON(tty->buf.memory_used < 0);
362
363 if (b->size >= 512)
364 kfree(b);
365 else {
366 b->next = tty->buf.free;
367 tty->buf.free = b;
368 }
369}
370
371/**
372 * __tty_buffer_flush - flush full tty buffers
373 * @tty: tty to flush
374 *
375 * flush all the buffers containing receive data. Caller must
376 * hold the buffer lock and must have ensured no parallel flush to
377 * ldisc is running.
378 *
379 * Locking: Caller must hold tty->buf.lock
380 */
381
382static void __tty_buffer_flush(struct tty_struct *tty)
383{
384 struct tty_buffer *thead;
385
386 while ((thead = tty->buf.head) != NULL) {
387 tty->buf.head = thead->next;
388 tty_buffer_free(tty, thead);
389 }
390 tty->buf.tail = NULL;
391}
392
393/**
394 * tty_buffer_flush - flush full tty buffers
395 * @tty: tty to flush
396 *
397 * flush all the buffers containing receive data. If the buffer is
398 * being processed by flush_to_ldisc then we defer the processing
399 * to that function
400 *
401 * Locking: none
402 */
403
404static void tty_buffer_flush(struct tty_struct *tty)
405{
406 unsigned long flags;
407 spin_lock_irqsave(&tty->buf.lock, flags);
408
409 /* If the data is being pushed to the tty layer then we can't
410 process it here. Instead set a flag and the flush_to_ldisc
411 path will process the flush request before it exits */
412 if (test_bit(TTY_FLUSHING, &tty->flags)) {
413 set_bit(TTY_FLUSHPENDING, &tty->flags);
414 spin_unlock_irqrestore(&tty->buf.lock, flags);
415 wait_event(tty->read_wait,
416 test_bit(TTY_FLUSHPENDING, &tty->flags) == 0);
417 return;
418 } else
419 __tty_buffer_flush(tty);
420 spin_unlock_irqrestore(&tty->buf.lock, flags);
421}
422
423/**
424 * tty_buffer_find - find a free tty buffer
425 * @tty: tty owning the buffer
426 * @size: characters wanted
427 *
428 * Locate an existing suitable tty buffer or if we are lacking one then
429 * allocate a new one. We round our buffers off in 256 character chunks
430 * to get better allocation behaviour.
431 *
432 * Locking: Caller must hold tty->buf.lock
433 */
434
435static struct tty_buffer *tty_buffer_find(struct tty_struct *tty, size_t size)
436{
437 struct tty_buffer **tbh = &tty->buf.free;
438 while ((*tbh) != NULL) {
439 struct tty_buffer *t = *tbh;
440 if (t->size >= size) {
441 *tbh = t->next;
442 t->next = NULL;
443 t->used = 0;
444 t->commit = 0;
445 t->read = 0;
446 tty->buf.memory_used += t->size;
447 return t;
448 }
449 tbh = &((*tbh)->next);
450 }
451 /* Round the buffer size out */
452 size = (size + 0xFF) & ~0xFF;
453 return tty_buffer_alloc(tty, size);
454 /* Should possibly check if this fails for the largest buffer we
455 have queued and recycle that ? */
456}
457
458/**
459 * tty_buffer_request_room - grow tty buffer if needed
460 * @tty: tty structure
461 * @size: size desired
462 *
463 * Make at least size bytes of linear space available for the tty
464 * buffer. If we fail return the size we managed to find.
465 *
466 * Locking: Takes tty->buf.lock
467 */
468int tty_buffer_request_room(struct tty_struct *tty, size_t size)
469{
470 struct tty_buffer *b, *n;
471 int left;
472 unsigned long flags;
473
474 spin_lock_irqsave(&tty->buf.lock, flags);
475
476 /* OPTIMISATION: We could keep a per tty "zero" sized buffer to
477 remove this conditional if its worth it. This would be invisible
478 to the callers */
479 if ((b = tty->buf.tail) != NULL)
480 left = b->size - b->used;
481 else
482 left = 0;
483
484 if (left < size) {
485 /* This is the slow path - looking for new buffers to use */
486 if ((n = tty_buffer_find(tty, size)) != NULL) {
487 if (b != NULL) {
488 b->next = n;
489 b->commit = b->used;
490 } else
491 tty->buf.head = n;
492 tty->buf.tail = n;
493 } else
494 size = left;
495 }
496
497 spin_unlock_irqrestore(&tty->buf.lock, flags);
498 return size;
499}
500EXPORT_SYMBOL_GPL(tty_buffer_request_room);
501
502/**
503 * tty_insert_flip_string - Add characters to the tty buffer
504 * @tty: tty structure
505 * @chars: characters
506 * @size: size
507 *
508 * Queue a series of bytes to the tty buffering. All the characters
509 * passed are marked as without error. Returns the number added.
510 *
511 * Locking: Called functions may take tty->buf.lock
512 */
513
514int tty_insert_flip_string(struct tty_struct *tty, const unsigned char *chars,
515 size_t size)
516{
517 int copied = 0;
518 do {
519 int space = tty_buffer_request_room(tty, size - copied);
520 struct tty_buffer *tb = tty->buf.tail;
521 /* If there is no space then tb may be NULL */
522 if (unlikely(space == 0))
523 break;
524 memcpy(tb->char_buf_ptr + tb->used, chars, space);
525 memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space);
526 tb->used += space;
527 copied += space;
528 chars += space;
529 /* There is a small chance that we need to split the data over
530 several buffers. If this is the case we must loop */
531 } while (unlikely(size > copied));
532 return copied;
533}
534EXPORT_SYMBOL(tty_insert_flip_string);
535
536/**
537 * tty_insert_flip_string_flags - Add characters to the tty buffer
538 * @tty: tty structure
539 * @chars: characters
540 * @flags: flag bytes
541 * @size: size
542 *
543 * Queue a series of bytes to the tty buffering. For each character
544 * the flags array indicates the status of the character. Returns the
545 * number added.
546 *
547 * Locking: Called functions may take tty->buf.lock
548 */
549
550int tty_insert_flip_string_flags(struct tty_struct *tty,
551 const unsigned char *chars, const char *flags, size_t size)
552{
553 int copied = 0;
554 do {
555 int space = tty_buffer_request_room(tty, size - copied);
556 struct tty_buffer *tb = tty->buf.tail;
557 /* If there is no space then tb may be NULL */
558 if (unlikely(space == 0))
559 break;
560 memcpy(tb->char_buf_ptr + tb->used, chars, space);
561 memcpy(tb->flag_buf_ptr + tb->used, flags, space);
562 tb->used += space;
563 copied += space;
564 chars += space;
565 flags += space;
566 /* There is a small chance that we need to split the data over
567 several buffers. If this is the case we must loop */
568 } while (unlikely(size > copied));
569 return copied;
570}
571EXPORT_SYMBOL(tty_insert_flip_string_flags);
572
573/**
574 * tty_schedule_flip - push characters to ldisc
575 * @tty: tty to push from
576 *
577 * Takes any pending buffers and transfers their ownership to the
578 * ldisc side of the queue. It then schedules those characters for
579 * processing by the line discipline.
580 *
581 * Locking: Takes tty->buf.lock
582 */
583
584void tty_schedule_flip(struct tty_struct *tty)
585{
586 unsigned long flags;
587 spin_lock_irqsave(&tty->buf.lock, flags);
588 if (tty->buf.tail != NULL)
589 tty->buf.tail->commit = tty->buf.tail->used;
590 spin_unlock_irqrestore(&tty->buf.lock, flags);
591 schedule_delayed_work(&tty->buf.work, 1);
592}
593EXPORT_SYMBOL(tty_schedule_flip);
594
595/**
596 * tty_prepare_flip_string - make room for characters
597 * @tty: tty
598 * @chars: return pointer for character write area
599 * @size: desired size
600 *
601 * Prepare a block of space in the buffer for data. Returns the length
602 * available and buffer pointer to the space which is now allocated and
603 * accounted for as ready for normal characters. This is used for drivers
604 * that need their own block copy routines into the buffer. There is no
605 * guarantee the buffer is a DMA target!
606 *
607 * Locking: May call functions taking tty->buf.lock
608 */
609
610int tty_prepare_flip_string(struct tty_struct *tty, unsigned char **chars,
611 size_t size)
612{
613 int space = tty_buffer_request_room(tty, size);
614 if (likely(space)) {
615 struct tty_buffer *tb = tty->buf.tail;
616 *chars = tb->char_buf_ptr + tb->used;
617 memset(tb->flag_buf_ptr + tb->used, TTY_NORMAL, space);
618 tb->used += space;
619 }
620 return space;
621}
622
623EXPORT_SYMBOL_GPL(tty_prepare_flip_string);
624
625/**
626 * tty_prepare_flip_string_flags - make room for characters
627 * @tty: tty
628 * @chars: return pointer for character write area
629 * @flags: return pointer for status flag write area
630 * @size: desired size
631 *
632 * Prepare a block of space in the buffer for data. Returns the length
633 * available and buffer pointer to the space which is now allocated and
634 * accounted for as ready for characters. This is used for drivers
635 * that need their own block copy routines into the buffer. There is no
636 * guarantee the buffer is a DMA target!
637 *
638 * Locking: May call functions taking tty->buf.lock
639 */
640
641int tty_prepare_flip_string_flags(struct tty_struct *tty,
642 unsigned char **chars, char **flags, size_t size)
643{
644 int space = tty_buffer_request_room(tty, size);
645 if (likely(space)) {
646 struct tty_buffer *tb = tty->buf.tail;
647 *chars = tb->char_buf_ptr + tb->used;
648 *flags = tb->flag_buf_ptr + tb->used;
649 tb->used += space;
650 }
651 return space;
652}
653
654EXPORT_SYMBOL_GPL(tty_prepare_flip_string_flags);
655
656
657
658/** 257/**
659 * get_tty_driver - find device of a tty 258 * get_tty_driver - find device of a tty
660 * @dev_t: device identifier 259 * @dev_t: device identifier
@@ -675,7 +274,7 @@ static struct tty_driver *get_tty_driver(dev_t device, int *index)
675 if (device < base || device >= base + p->num) 274 if (device < base || device >= base + p->num)
676 continue; 275 continue;
677 *index = device - base; 276 *index = device - base;
678 return p; 277 return tty_driver_kref_get(p);
679 } 278 }
680 return NULL; 279 return NULL;
681} 280}
@@ -719,7 +318,7 @@ struct tty_driver *tty_find_polling_driver(char *name, int *line)
719 318
720 if (tty_line >= 0 && tty_line <= p->num && p->ops && 319 if (tty_line >= 0 && tty_line <= p->num && p->ops &&
721 p->ops->poll_init && !p->ops->poll_init(p, tty_line, str)) { 320 p->ops->poll_init && !p->ops->poll_init(p, tty_line, str)) {
722 res = p; 321 res = tty_driver_kref_get(p);
723 *line = tty_line; 322 *line = tty_line;
724 break; 323 break;
725 } 324 }
@@ -819,20 +418,6 @@ static const struct file_operations tty_fops = {
819 .fasync = tty_fasync, 418 .fasync = tty_fasync,
820}; 419};
821 420
822#ifdef CONFIG_UNIX98_PTYS
823static const struct file_operations ptmx_fops = {
824 .llseek = no_llseek,
825 .read = tty_read,
826 .write = tty_write,
827 .poll = tty_poll,
828 .unlocked_ioctl = tty_ioctl,
829 .compat_ioctl = tty_compat_ioctl,
830 .open = ptmx_open,
831 .release = tty_release,
832 .fasync = tty_fasync,
833};
834#endif
835
836static const struct file_operations console_fops = { 421static const struct file_operations console_fops = {
837 .llseek = no_llseek, 422 .llseek = no_llseek,
838 .read = tty_read, 423 .read = tty_read,
@@ -953,6 +538,7 @@ static void do_tty_hangup(struct work_struct *work)
953 struct tty_ldisc *ld; 538 struct tty_ldisc *ld;
954 int closecount = 0, n; 539 int closecount = 0, n;
955 unsigned long flags; 540 unsigned long flags;
541 int refs = 0;
956 542
957 if (!tty) 543 if (!tty)
958 return; 544 return;
@@ -1019,8 +605,12 @@ static void do_tty_hangup(struct work_struct *work)
1019 if (tty->session) { 605 if (tty->session) {
1020 do_each_pid_task(tty->session, PIDTYPE_SID, p) { 606 do_each_pid_task(tty->session, PIDTYPE_SID, p) {
1021 spin_lock_irq(&p->sighand->siglock); 607 spin_lock_irq(&p->sighand->siglock);
1022 if (p->signal->tty == tty) 608 if (p->signal->tty == tty) {
1023 p->signal->tty = NULL; 609 p->signal->tty = NULL;
610 /* We defer the dereferences outside fo
611 the tasklist lock */
612 refs++;
613 }
1024 if (!p->signal->leader) { 614 if (!p->signal->leader) {
1025 spin_unlock_irq(&p->sighand->siglock); 615 spin_unlock_irq(&p->sighand->siglock);
1026 continue; 616 continue;
@@ -1046,6 +636,10 @@ static void do_tty_hangup(struct work_struct *work)
1046 tty->ctrl_status = 0; 636 tty->ctrl_status = 0;
1047 spin_unlock_irqrestore(&tty->ctrl_lock, flags); 637 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
1048 638
639 /* Account for the p->signal references we killed */
640 while (refs--)
641 tty_kref_put(tty);
642
1049 /* 643 /*
1050 * If one of the devices matches a console pointer, we 644 * If one of the devices matches a console pointer, we
1051 * cannot just call hangup() because that will cause 645 * cannot just call hangup() because that will cause
@@ -1115,6 +709,23 @@ void tty_vhangup(struct tty_struct *tty)
1115EXPORT_SYMBOL(tty_vhangup); 709EXPORT_SYMBOL(tty_vhangup);
1116 710
1117/** 711/**
712 * tty_vhangup_self - process vhangup for own ctty
713 *
714 * Perform a vhangup on the current controlling tty
715 */
716
717void tty_vhangup_self(void)
718{
719 struct tty_struct *tty;
720
721 tty = get_current_tty();
722 if (tty) {
723 tty_vhangup(tty);
724 tty_kref_put(tty);
725 }
726}
727
728/**
1118 * tty_hung_up_p - was tty hung up 729 * tty_hung_up_p - was tty hung up
1119 * @filp: file pointer of tty 730 * @filp: file pointer of tty
1120 * 731 *
@@ -1167,16 +778,14 @@ void disassociate_ctty(int on_exit)
1167 struct pid *tty_pgrp = NULL; 778 struct pid *tty_pgrp = NULL;
1168 779
1169 780
1170 mutex_lock(&tty_mutex);
1171 tty = get_current_tty(); 781 tty = get_current_tty();
1172 if (tty) { 782 if (tty) {
1173 tty_pgrp = get_pid(tty->pgrp); 783 tty_pgrp = get_pid(tty->pgrp);
1174 lock_kernel(); 784 lock_kernel();
1175 mutex_unlock(&tty_mutex);
1176 /* XXX: here we race, there is nothing protecting tty */
1177 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY) 785 if (on_exit && tty->driver->type != TTY_DRIVER_TYPE_PTY)
1178 tty_vhangup(tty); 786 tty_vhangup(tty);
1179 unlock_kernel(); 787 unlock_kernel();
788 tty_kref_put(tty);
1180 } else if (on_exit) { 789 } else if (on_exit) {
1181 struct pid *old_pgrp; 790 struct pid *old_pgrp;
1182 spin_lock_irq(&current->sighand->siglock); 791 spin_lock_irq(&current->sighand->siglock);
@@ -1188,7 +797,6 @@ void disassociate_ctty(int on_exit)
1188 kill_pgrp(old_pgrp, SIGCONT, on_exit); 797 kill_pgrp(old_pgrp, SIGCONT, on_exit);
1189 put_pid(old_pgrp); 798 put_pid(old_pgrp);
1190 } 799 }
1191 mutex_unlock(&tty_mutex);
1192 return; 800 return;
1193 } 801 }
1194 if (tty_pgrp) { 802 if (tty_pgrp) {
@@ -1203,8 +811,6 @@ void disassociate_ctty(int on_exit)
1203 current->signal->tty_old_pgrp = NULL; 811 current->signal->tty_old_pgrp = NULL;
1204 spin_unlock_irq(&current->sighand->siglock); 812 spin_unlock_irq(&current->sighand->siglock);
1205 813
1206 mutex_lock(&tty_mutex);
1207 /* It is possible that do_tty_hangup has free'd this tty */
1208 tty = get_current_tty(); 814 tty = get_current_tty();
1209 if (tty) { 815 if (tty) {
1210 unsigned long flags; 816 unsigned long flags;
@@ -1214,13 +820,13 @@ void disassociate_ctty(int on_exit)
1214 tty->session = NULL; 820 tty->session = NULL;
1215 tty->pgrp = NULL; 821 tty->pgrp = NULL;
1216 spin_unlock_irqrestore(&tty->ctrl_lock, flags); 822 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
823 tty_kref_put(tty);
1217 } else { 824 } else {
1218#ifdef TTY_DEBUG_HANGUP 825#ifdef TTY_DEBUG_HANGUP
1219 printk(KERN_DEBUG "error attempted to write to tty [0x%p]" 826 printk(KERN_DEBUG "error attempted to write to tty [0x%p]"
1220 " = NULL", tty); 827 " = NULL", tty);
1221#endif 828#endif
1222 } 829 }
1223 mutex_unlock(&tty_mutex);
1224 830
1225 /* Now clear signal->tty under the lock */ 831 /* Now clear signal->tty under the lock */
1226 read_lock(&tasklist_lock); 832 read_lock(&tasklist_lock);
@@ -1420,19 +1026,19 @@ static inline ssize_t do_tty_write(
1420 1026
1421 /* write_buf/write_cnt is protected by the atomic_write_lock mutex */ 1027 /* write_buf/write_cnt is protected by the atomic_write_lock mutex */
1422 if (tty->write_cnt < chunk) { 1028 if (tty->write_cnt < chunk) {
1423 unsigned char *buf; 1029 unsigned char *buf_chunk;
1424 1030
1425 if (chunk < 1024) 1031 if (chunk < 1024)
1426 chunk = 1024; 1032 chunk = 1024;
1427 1033
1428 buf = kmalloc(chunk, GFP_KERNEL); 1034 buf_chunk = kmalloc(chunk, GFP_KERNEL);
1429 if (!buf) { 1035 if (!buf_chunk) {
1430 ret = -ENOMEM; 1036 ret = -ENOMEM;
1431 goto out; 1037 goto out;
1432 } 1038 }
1433 kfree(tty->write_buf); 1039 kfree(tty->write_buf);
1434 tty->write_cnt = chunk; 1040 tty->write_cnt = chunk;
1435 tty->write_buf = buf; 1041 tty->write_buf = buf_chunk;
1436 } 1042 }
1437 1043
1438 /* Do the write .. */ 1044 /* Do the write .. */
@@ -1466,6 +1072,31 @@ out:
1466 return ret; 1072 return ret;
1467} 1073}
1468 1074
1075/**
1076 * tty_write_message - write a message to a certain tty, not just the console.
1077 * @tty: the destination tty_struct
1078 * @msg: the message to write
1079 *
1080 * This is used for messages that need to be redirected to a specific tty.
1081 * We don't put it into the syslog queue right now maybe in the future if
1082 * really needed.
1083 *
1084 * We must still hold the BKL and test the CLOSING flag for the moment.
1085 */
1086
1087void tty_write_message(struct tty_struct *tty, char *msg)
1088{
1089 lock_kernel();
1090 if (tty) {
1091 mutex_lock(&tty->atomic_write_lock);
1092 if (tty->ops->write && !test_bit(TTY_CLOSING, &tty->flags))
1093 tty->ops->write(tty, msg, strlen(msg));
1094 tty_write_unlock(tty);
1095 }
1096 unlock_kernel();
1097 return;
1098}
1099
1469 1100
1470/** 1101/**
1471 * tty_write - write method for tty device file 1102 * tty_write - write method for tty device file
@@ -1533,42 +1164,6 @@ ssize_t redirected_tty_write(struct file *file, const char __user *buf,
1533 return tty_write(file, buf, count, ppos); 1164 return tty_write(file, buf, count, ppos);
1534} 1165}
1535 1166
1536void tty_port_init(struct tty_port *port)
1537{
1538 memset(port, 0, sizeof(*port));
1539 init_waitqueue_head(&port->open_wait);
1540 init_waitqueue_head(&port->close_wait);
1541 mutex_init(&port->mutex);
1542 port->close_delay = (50 * HZ) / 100;
1543 port->closing_wait = (3000 * HZ) / 100;
1544}
1545EXPORT_SYMBOL(tty_port_init);
1546
1547int tty_port_alloc_xmit_buf(struct tty_port *port)
1548{
1549 /* We may sleep in get_zeroed_page() */
1550 mutex_lock(&port->mutex);
1551 if (port->xmit_buf == NULL)
1552 port->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL);
1553 mutex_unlock(&port->mutex);
1554 if (port->xmit_buf == NULL)
1555 return -ENOMEM;
1556 return 0;
1557}
1558EXPORT_SYMBOL(tty_port_alloc_xmit_buf);
1559
1560void tty_port_free_xmit_buf(struct tty_port *port)
1561{
1562 mutex_lock(&port->mutex);
1563 if (port->xmit_buf != NULL) {
1564 free_page((unsigned long)port->xmit_buf);
1565 port->xmit_buf = NULL;
1566 }
1567 mutex_unlock(&port->mutex);
1568}
1569EXPORT_SYMBOL(tty_port_free_xmit_buf);
1570
1571
1572static char ptychar[] = "pqrstuvwxyzabcde"; 1167static char ptychar[] = "pqrstuvwxyzabcde";
1573 1168
1574/** 1169/**
@@ -1592,7 +1187,7 @@ static void pty_line_name(struct tty_driver *driver, int index, char *p)
1592} 1187}
1593 1188
1594/** 1189/**
1595 * pty_line_name - generate name for a tty 1190 * tty_line_name - generate name for a tty
1596 * @driver: the tty driver in use 1191 * @driver: the tty driver in use
1597 * @index: the minor number 1192 * @index: the minor number
1598 * @p: output buffer of at least 7 bytes 1193 * @p: output buffer of at least 7 bytes
@@ -1608,10 +1203,148 @@ static void tty_line_name(struct tty_driver *driver, int index, char *p)
1608} 1203}
1609 1204
1610/** 1205/**
1611 * init_dev - initialise a tty device 1206 * tty_driver_lookup_tty() - find an existing tty, if any
1207 * @driver: the driver for the tty
1208 * @idx: the minor number
1209 *
1210 * Return the tty, if found or ERR_PTR() otherwise.
1211 *
1212 * Locking: tty_mutex must be held. If tty is found, the mutex must
1213 * be held until the 'fast-open' is also done. Will change once we
1214 * have refcounting in the driver and per driver locking
1215 */
1216struct tty_struct *tty_driver_lookup_tty(struct tty_driver *driver,
1217 struct inode *inode, int idx)
1218{
1219 struct tty_struct *tty;
1220
1221 if (driver->ops->lookup)
1222 return driver->ops->lookup(driver, inode, idx);
1223
1224 tty = driver->ttys[idx];
1225 return tty;
1226}
1227
1228/**
1229 * tty_init_termios - helper for termios setup
1230 * @tty: the tty to set up
1231 *
1232 * Initialise the termios structures for this tty. Thus runs under
1233 * the tty_mutex currently so we can be relaxed about ordering.
1234 */
1235
1236int tty_init_termios(struct tty_struct *tty)
1237{
1238 struct ktermios *tp;
1239 int idx = tty->index;
1240
1241 tp = tty->driver->termios[idx];
1242 if (tp == NULL) {
1243 tp = kzalloc(sizeof(struct ktermios[2]), GFP_KERNEL);
1244 if (tp == NULL)
1245 return -ENOMEM;
1246 memcpy(tp, &tty->driver->init_termios,
1247 sizeof(struct ktermios));
1248 tty->driver->termios[idx] = tp;
1249 }
1250 tty->termios = tp;
1251 tty->termios_locked = tp + 1;
1252
1253 /* Compatibility until drivers always set this */
1254 tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios);
1255 tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
1256 return 0;
1257}
1258
1259/**
1260 * tty_driver_install_tty() - install a tty entry in the driver
1261 * @driver: the driver for the tty
1262 * @tty: the tty
1263 *
1264 * Install a tty object into the driver tables. The tty->index field
1265 * will be set by the time this is called. This method is responsible
1266 * for ensuring any need additional structures are allocated and
1267 * configured.
1268 *
1269 * Locking: tty_mutex for now
1270 */
1271static int tty_driver_install_tty(struct tty_driver *driver,
1272 struct tty_struct *tty)
1273{
1274 int idx = tty->index;
1275
1276 if (driver->ops->install)
1277 return driver->ops->install(driver, tty);
1278
1279 if (tty_init_termios(tty) == 0) {
1280 tty_driver_kref_get(driver);
1281 tty->count++;
1282 driver->ttys[idx] = tty;
1283 return 0;
1284 }
1285 return -ENOMEM;
1286}
1287
1288/**
1289 * tty_driver_remove_tty() - remove a tty from the driver tables
1290 * @driver: the driver for the tty
1291 * @idx: the minor number
1292 *
1293 * Remvoe a tty object from the driver tables. The tty->index field
1294 * will be set by the time this is called.
1295 *
1296 * Locking: tty_mutex for now
1297 */
1298static void tty_driver_remove_tty(struct tty_driver *driver,
1299 struct tty_struct *tty)
1300{
1301 if (driver->ops->remove)
1302 driver->ops->remove(driver, tty);
1303 else
1304 driver->ttys[tty->index] = NULL;
1305}
1306
1307/*
1308 * tty_reopen() - fast re-open of an open tty
1309 * @tty - the tty to open
1310 *
1311 * Return 0 on success, -errno on error.
1312 *
1313 * Locking: tty_mutex must be held from the time the tty was found
1314 * till this open completes.
1315 */
1316static int tty_reopen(struct tty_struct *tty)
1317{
1318 struct tty_driver *driver = tty->driver;
1319
1320 if (test_bit(TTY_CLOSING, &tty->flags))
1321 return -EIO;
1322
1323 if (driver->type == TTY_DRIVER_TYPE_PTY &&
1324 driver->subtype == PTY_TYPE_MASTER) {
1325 /*
1326 * special case for PTY masters: only one open permitted,
1327 * and the slave side open count is incremented as well.
1328 */
1329 if (tty->count)
1330 return -EIO;
1331
1332 tty->link->count++;
1333 }
1334 tty->count++;
1335 tty->driver = driver; /* N.B. why do this every time?? */
1336
1337 WARN_ON(!test_bit(TTY_LDISC, &tty->flags));
1338
1339 return 0;
1340}
1341
1342/**
1343 * tty_init_dev - initialise a tty device
1612 * @driver: tty driver we are opening a device on 1344 * @driver: tty driver we are opening a device on
1613 * @idx: device index 1345 * @idx: device index
1614 * @tty: returned tty structure 1346 * @ret_tty: returned tty structure
1347 * @first_ok: ok to open a new device (used by ptmx)
1615 * 1348 *
1616 * Prepare a tty device. This may not be a "new" clean device but 1349 * Prepare a tty device. This may not be a "new" clean device but
1617 * could also be an active device. The pty drivers require special 1350 * could also be an active device. The pty drivers require special
@@ -1631,37 +1364,16 @@ static void tty_line_name(struct tty_driver *driver, int index, char *p)
1631 * relaxed for the (most common) case of reopening a tty. 1364 * relaxed for the (most common) case of reopening a tty.
1632 */ 1365 */
1633 1366
1634static int init_dev(struct tty_driver *driver, int idx, 1367struct tty_struct *tty_init_dev(struct tty_driver *driver, int idx,
1635 struct tty_struct **ret_tty) 1368 int first_ok)
1636{ 1369{
1637 struct tty_struct *tty, *o_tty; 1370 struct tty_struct *tty;
1638 struct ktermios *tp, **tp_loc, *o_tp, **o_tp_loc; 1371 int retval;
1639 struct ktermios *ltp, **ltp_loc, *o_ltp, **o_ltp_loc;
1640 int retval = 0;
1641 1372
1642 /* check whether we're reopening an existing tty */ 1373 /* Check if pty master is being opened multiple times */
1643 if (driver->flags & TTY_DRIVER_DEVPTS_MEM) { 1374 if (driver->subtype == PTY_TYPE_MASTER &&
1644 tty = devpts_get_tty(idx); 1375 (driver->flags & TTY_DRIVER_DEVPTS_MEM) && !first_ok)
1645 /* 1376 return ERR_PTR(-EIO);
1646 * If we don't have a tty here on a slave open, it's because
1647 * the master already started the close process and there's
1648 * no relation between devpts file and tty anymore.
1649 */
1650 if (!tty && driver->subtype == PTY_TYPE_SLAVE) {
1651 retval = -EIO;
1652 goto end_init;
1653 }
1654 /*
1655 * It's safe from now on because init_dev() is called with
1656 * tty_mutex held and release_dev() won't change tty->count
1657 * or tty->flags without having to grab tty_mutex
1658 */
1659 if (tty && driver->subtype == PTY_TYPE_MASTER)
1660 tty = tty->link;
1661 } else {
1662 tty = driver->ttys[idx];
1663 }
1664 if (tty) goto fast_track;
1665 1377
1666 /* 1378 /*
1667 * First time open is complex, especially for PTY devices. 1379 * First time open is complex, especially for PTY devices.
@@ -1671,189 +1383,69 @@ static int init_dev(struct tty_driver *driver, int idx,
1671 * and locked termios may be retained.) 1383 * and locked termios may be retained.)
1672 */ 1384 */
1673 1385
1674 if (!try_module_get(driver->owner)) { 1386 if (!try_module_get(driver->owner))
1675 retval = -ENODEV; 1387 return ERR_PTR(-ENODEV);
1676 goto end_init;
1677 }
1678
1679 o_tty = NULL;
1680 tp = o_tp = NULL;
1681 ltp = o_ltp = NULL;
1682 1388
1683 tty = alloc_tty_struct(); 1389 tty = alloc_tty_struct();
1684 if (!tty) 1390 if (!tty)
1685 goto fail_no_mem; 1391 goto fail_no_mem;
1686 initialize_tty_struct(tty); 1392 initialize_tty_struct(tty, driver, idx);
1687 tty->driver = driver;
1688 tty->ops = driver->ops;
1689 tty->index = idx;
1690 tty_line_name(driver, idx, tty->name);
1691
1692 if (driver->flags & TTY_DRIVER_DEVPTS_MEM) {
1693 tp_loc = &tty->termios;
1694 ltp_loc = &tty->termios_locked;
1695 } else {
1696 tp_loc = &driver->termios[idx];
1697 ltp_loc = &driver->termios_locked[idx];
1698 }
1699
1700 if (!*tp_loc) {
1701 tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL);
1702 if (!tp)
1703 goto free_mem_out;
1704 *tp = driver->init_termios;
1705 }
1706
1707 if (!*ltp_loc) {
1708 ltp = kzalloc(sizeof(struct ktermios), GFP_KERNEL);
1709 if (!ltp)
1710 goto free_mem_out;
1711 }
1712
1713 if (driver->type == TTY_DRIVER_TYPE_PTY) {
1714 o_tty = alloc_tty_struct();
1715 if (!o_tty)
1716 goto free_mem_out;
1717 initialize_tty_struct(o_tty);
1718 o_tty->driver = driver->other;
1719 o_tty->ops = driver->ops;
1720 o_tty->index = idx;
1721 tty_line_name(driver->other, idx, o_tty->name);
1722
1723 if (driver->flags & TTY_DRIVER_DEVPTS_MEM) {
1724 o_tp_loc = &o_tty->termios;
1725 o_ltp_loc = &o_tty->termios_locked;
1726 } else {
1727 o_tp_loc = &driver->other->termios[idx];
1728 o_ltp_loc = &driver->other->termios_locked[idx];
1729 }
1730 1393
1731 if (!*o_tp_loc) { 1394 retval = tty_driver_install_tty(driver, tty);
1732 o_tp = kmalloc(sizeof(struct ktermios), GFP_KERNEL); 1395 if (retval < 0) {
1733 if (!o_tp) 1396 free_tty_struct(tty);
1734 goto free_mem_out; 1397 module_put(driver->owner);
1735 *o_tp = driver->other->init_termios; 1398 return ERR_PTR(retval);
1736 }
1737
1738 if (!*o_ltp_loc) {
1739 o_ltp = kzalloc(sizeof(struct ktermios), GFP_KERNEL);
1740 if (!o_ltp)
1741 goto free_mem_out;
1742 }
1743
1744 /*
1745 * Everything allocated ... set up the o_tty structure.
1746 */
1747 if (!(driver->other->flags & TTY_DRIVER_DEVPTS_MEM))
1748 driver->other->ttys[idx] = o_tty;
1749 if (!*o_tp_loc)
1750 *o_tp_loc = o_tp;
1751 if (!*o_ltp_loc)
1752 *o_ltp_loc = o_ltp;
1753 o_tty->termios = *o_tp_loc;
1754 o_tty->termios_locked = *o_ltp_loc;
1755 driver->other->refcount++;
1756 if (driver->subtype == PTY_TYPE_MASTER)
1757 o_tty->count++;
1758
1759 /* Establish the links in both directions */
1760 tty->link = o_tty;
1761 o_tty->link = tty;
1762 } 1399 }
1763 1400
1764 /* 1401 /*
1765 * All structures have been allocated, so now we install them.
1766 * Failures after this point use release_tty to clean up, so
1767 * there's no need to null out the local pointers.
1768 */
1769 if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM))
1770 driver->ttys[idx] = tty;
1771
1772 if (!*tp_loc)
1773 *tp_loc = tp;
1774 if (!*ltp_loc)
1775 *ltp_loc = ltp;
1776 tty->termios = *tp_loc;
1777 tty->termios_locked = *ltp_loc;
1778 /* Compatibility until drivers always set this */
1779 tty->termios->c_ispeed = tty_termios_input_baud_rate(tty->termios);
1780 tty->termios->c_ospeed = tty_termios_baud_rate(tty->termios);
1781 driver->refcount++;
1782 tty->count++;
1783
1784 /*
1785 * Structures all installed ... call the ldisc open routines. 1402 * Structures all installed ... call the ldisc open routines.
1786 * If we fail here just call release_tty to clean up. No need 1403 * If we fail here just call release_tty to clean up. No need
1787 * to decrement the use counts, as release_tty doesn't care. 1404 * to decrement the use counts, as release_tty doesn't care.
1788 */ 1405 */
1789 1406
1790 retval = tty_ldisc_setup(tty, o_tty); 1407 retval = tty_ldisc_setup(tty, tty->link);
1791
1792 if (retval) 1408 if (retval)
1793 goto release_mem_out; 1409 goto release_mem_out;
1794 goto success; 1410 return tty;
1795
1796 /*
1797 * This fast open can be used if the tty is already open.
1798 * No memory is allocated, and the only failures are from
1799 * attempting to open a closing tty or attempting multiple
1800 * opens on a pty master.
1801 */
1802fast_track:
1803 if (test_bit(TTY_CLOSING, &tty->flags)) {
1804 retval = -EIO;
1805 goto end_init;
1806 }
1807 if (driver->type == TTY_DRIVER_TYPE_PTY &&
1808 driver->subtype == PTY_TYPE_MASTER) {
1809 /*
1810 * special case for PTY masters: only one open permitted,
1811 * and the slave side open count is incremented as well.
1812 */
1813 if (tty->count) {
1814 retval = -EIO;
1815 goto end_init;
1816 }
1817 tty->link->count++;
1818 }
1819 tty->count++;
1820 tty->driver = driver; /* N.B. why do this every time?? */
1821
1822 /* FIXME */
1823 if (!test_bit(TTY_LDISC, &tty->flags))
1824 printk(KERN_ERR "init_dev but no ldisc\n");
1825success:
1826 *ret_tty = tty;
1827
1828 /* All paths come through here to release the mutex */
1829end_init:
1830 return retval;
1831
1832 /* Release locally allocated memory ... nothing placed in slots */
1833free_mem_out:
1834 kfree(o_tp);
1835 if (o_tty)
1836 free_tty_struct(o_tty);
1837 kfree(ltp);
1838 kfree(tp);
1839 free_tty_struct(tty);
1840 1411
1841fail_no_mem: 1412fail_no_mem:
1842 module_put(driver->owner); 1413 module_put(driver->owner);
1843 retval = -ENOMEM; 1414 return ERR_PTR(-ENOMEM);
1844 goto end_init;
1845 1415
1846 /* call the tty release_tty routine to clean out this slot */ 1416 /* call the tty release_tty routine to clean out this slot */
1847release_mem_out: 1417release_mem_out:
1848 if (printk_ratelimit()) 1418 if (printk_ratelimit())
1849 printk(KERN_INFO "init_dev: ldisc open failed, " 1419 printk(KERN_INFO "tty_init_dev: ldisc open failed, "
1850 "clearing slot %d\n", idx); 1420 "clearing slot %d\n", idx);
1851 release_tty(tty, idx); 1421 release_tty(tty, idx);
1852 goto end_init; 1422 return ERR_PTR(retval);
1853} 1423}
1854 1424
1425void tty_free_termios(struct tty_struct *tty)
1426{
1427 struct ktermios *tp;
1428 int idx = tty->index;
1429 /* Kill this flag and push into drivers for locking etc */
1430 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) {
1431 /* FIXME: Locking on ->termios array */
1432 tp = tty->termios;
1433 tty->driver->termios[idx] = NULL;
1434 kfree(tp);
1435 }
1436}
1437EXPORT_SYMBOL(tty_free_termios);
1438
1439void tty_shutdown(struct tty_struct *tty)
1440{
1441 tty_driver_remove_tty(tty->driver, tty);
1442 tty_free_termios(tty);
1443}
1444EXPORT_SYMBOL(tty_shutdown);
1445
1855/** 1446/**
1856 * release_one_tty - release tty structure memory 1447 * release_one_tty - release tty structure memory
1448 * @kref: kref of tty we are obliterating
1857 * 1449 *
1858 * Releases memory associated with a tty structure, and clears out the 1450 * Releases memory associated with a tty structure, and clears out the
1859 * driver table slots. This function is called when a device is no longer 1451 * driver table slots. This function is called when a device is no longer
@@ -1863,31 +1455,19 @@ release_mem_out:
1863 * tty_mutex - sometimes only 1455 * tty_mutex - sometimes only
1864 * takes the file list lock internally when working on the list 1456 * takes the file list lock internally when working on the list
1865 * of ttys that the driver keeps. 1457 * of ttys that the driver keeps.
1866 * FIXME: should we require tty_mutex is held here ??
1867 */ 1458 */
1868static void release_one_tty(struct tty_struct *tty, int idx) 1459static void release_one_tty(struct kref *kref)
1869{ 1460{
1870 int devpts = tty->driver->flags & TTY_DRIVER_DEVPTS_MEM; 1461 struct tty_struct *tty = container_of(kref, struct tty_struct, kref);
1871 struct ktermios *tp; 1462 struct tty_driver *driver = tty->driver;
1872
1873 if (!devpts)
1874 tty->driver->ttys[idx] = NULL;
1875
1876 if (tty->driver->flags & TTY_DRIVER_RESET_TERMIOS) {
1877 tp = tty->termios;
1878 if (!devpts)
1879 tty->driver->termios[idx] = NULL;
1880 kfree(tp);
1881
1882 tp = tty->termios_locked;
1883 if (!devpts)
1884 tty->driver->termios_locked[idx] = NULL;
1885 kfree(tp);
1886 }
1887
1888 1463
1464 if (tty->ops->shutdown)
1465 tty->ops->shutdown(tty);
1466 else
1467 tty_shutdown(tty);
1889 tty->magic = 0; 1468 tty->magic = 0;
1890 tty->driver->refcount--; 1469 tty_driver_kref_put(driver);
1470 module_put(driver->owner);
1891 1471
1892 file_list_lock(); 1472 file_list_lock();
1893 list_del_init(&tty->tty_files); 1473 list_del_init(&tty->tty_files);
@@ -1897,6 +1477,21 @@ static void release_one_tty(struct tty_struct *tty, int idx)
1897} 1477}
1898 1478
1899/** 1479/**
1480 * tty_kref_put - release a tty kref
1481 * @tty: tty device
1482 *
1483 * Release a reference to a tty device and if need be let the kref
1484 * layer destruct the object for us
1485 */
1486
1487void tty_kref_put(struct tty_struct *tty)
1488{
1489 if (tty)
1490 kref_put(&tty->kref, release_one_tty);
1491}
1492EXPORT_SYMBOL(tty_kref_put);
1493
1494/**
1900 * release_tty - release tty structure memory 1495 * release_tty - release tty structure memory
1901 * 1496 *
1902 * Release both @tty and a possible linked partner (think pty pair), 1497 * Release both @tty and a possible linked partner (think pty pair),
@@ -1907,15 +1502,16 @@ static void release_one_tty(struct tty_struct *tty, int idx)
1907 * takes the file list lock internally when working on the list 1502 * takes the file list lock internally when working on the list
1908 * of ttys that the driver keeps. 1503 * of ttys that the driver keeps.
1909 * FIXME: should we require tty_mutex is held here ?? 1504 * FIXME: should we require tty_mutex is held here ??
1505 *
1910 */ 1506 */
1911static void release_tty(struct tty_struct *tty, int idx) 1507static void release_tty(struct tty_struct *tty, int idx)
1912{ 1508{
1913 struct tty_driver *driver = tty->driver; 1509 /* This should always be true but check for the moment */
1510 WARN_ON(tty->index != idx);
1914 1511
1915 if (tty->link) 1512 if (tty->link)
1916 release_one_tty(tty->link, idx); 1513 tty_kref_put(tty->link);
1917 release_one_tty(tty, idx); 1514 tty_kref_put(tty);
1918 module_put(driver->owner);
1919} 1515}
1920 1516
1921/* 1517/*
@@ -1926,20 +1522,21 @@ static void release_tty(struct tty_struct *tty, int idx)
1926 * WSH 09/09/97: rewritten to avoid some nasty race conditions that could 1522 * WSH 09/09/97: rewritten to avoid some nasty race conditions that could
1927 * lead to double frees or releasing memory still in use. 1523 * lead to double frees or releasing memory still in use.
1928 */ 1524 */
1929static void release_dev(struct file *filp) 1525void tty_release_dev(struct file *filp)
1930{ 1526{
1931 struct tty_struct *tty, *o_tty; 1527 struct tty_struct *tty, *o_tty;
1932 int pty_master, tty_closing, o_tty_closing, do_sleep; 1528 int pty_master, tty_closing, o_tty_closing, do_sleep;
1933 int devpts; 1529 int devpts;
1934 int idx; 1530 int idx;
1935 char buf[64]; 1531 char buf[64];
1532 struct inode *inode;
1936 1533
1534 inode = filp->f_path.dentry->d_inode;
1937 tty = (struct tty_struct *)filp->private_data; 1535 tty = (struct tty_struct *)filp->private_data;
1938 if (tty_paranoia_check(tty, filp->f_path.dentry->d_inode, 1536 if (tty_paranoia_check(tty, inode, "tty_release_dev"))
1939 "release_dev"))
1940 return; 1537 return;
1941 1538
1942 check_tty_count(tty, "release_dev"); 1539 check_tty_count(tty, "tty_release_dev");
1943 1540
1944 tty_fasync(-1, filp, 0); 1541 tty_fasync(-1, filp, 0);
1945 1542
@@ -1951,33 +1548,27 @@ static void release_dev(struct file *filp)
1951 1548
1952#ifdef TTY_PARANOIA_CHECK 1549#ifdef TTY_PARANOIA_CHECK
1953 if (idx < 0 || idx >= tty->driver->num) { 1550 if (idx < 0 || idx >= tty->driver->num) {
1954 printk(KERN_DEBUG "release_dev: bad idx when trying to " 1551 printk(KERN_DEBUG "tty_release_dev: bad idx when trying to "
1955 "free (%s)\n", tty->name); 1552 "free (%s)\n", tty->name);
1956 return; 1553 return;
1957 } 1554 }
1958 if (!(tty->driver->flags & TTY_DRIVER_DEVPTS_MEM)) { 1555 if (!devpts) {
1959 if (tty != tty->driver->ttys[idx]) { 1556 if (tty != tty->driver->ttys[idx]) {
1960 printk(KERN_DEBUG "release_dev: driver.table[%d] not tty " 1557 printk(KERN_DEBUG "tty_release_dev: driver.table[%d] not tty "
1961 "for (%s)\n", idx, tty->name); 1558 "for (%s)\n", idx, tty->name);
1962 return; 1559 return;
1963 } 1560 }
1964 if (tty->termios != tty->driver->termios[idx]) { 1561 if (tty->termios != tty->driver->termios[idx]) {
1965 printk(KERN_DEBUG "release_dev: driver.termios[%d] not termios " 1562 printk(KERN_DEBUG "tty_release_dev: driver.termios[%d] not termios "
1966 "for (%s)\n", 1563 "for (%s)\n",
1967 idx, tty->name); 1564 idx, tty->name);
1968 return; 1565 return;
1969 } 1566 }
1970 if (tty->termios_locked != tty->driver->termios_locked[idx]) {
1971 printk(KERN_DEBUG "release_dev: driver.termios_locked[%d] not "
1972 "termios_locked for (%s)\n",
1973 idx, tty->name);
1974 return;
1975 }
1976 } 1567 }
1977#endif 1568#endif
1978 1569
1979#ifdef TTY_DEBUG_HANGUP 1570#ifdef TTY_DEBUG_HANGUP
1980 printk(KERN_DEBUG "release_dev of %s (tty count=%d)...", 1571 printk(KERN_DEBUG "tty_release_dev of %s (tty count=%d)...",
1981 tty_name(tty, buf), tty->count); 1572 tty_name(tty, buf), tty->count);
1982#endif 1573#endif
1983 1574
@@ -1985,26 +1576,19 @@ static void release_dev(struct file *filp)
1985 if (tty->driver->other && 1576 if (tty->driver->other &&
1986 !(tty->driver->flags & TTY_DRIVER_DEVPTS_MEM)) { 1577 !(tty->driver->flags & TTY_DRIVER_DEVPTS_MEM)) {
1987 if (o_tty != tty->driver->other->ttys[idx]) { 1578 if (o_tty != tty->driver->other->ttys[idx]) {
1988 printk(KERN_DEBUG "release_dev: other->table[%d] " 1579 printk(KERN_DEBUG "tty_release_dev: other->table[%d] "
1989 "not o_tty for (%s)\n", 1580 "not o_tty for (%s)\n",
1990 idx, tty->name); 1581 idx, tty->name);
1991 return; 1582 return;
1992 } 1583 }
1993 if (o_tty->termios != tty->driver->other->termios[idx]) { 1584 if (o_tty->termios != tty->driver->other->termios[idx]) {
1994 printk(KERN_DEBUG "release_dev: other->termios[%d] " 1585 printk(KERN_DEBUG "tty_release_dev: other->termios[%d] "
1995 "not o_termios for (%s)\n", 1586 "not o_termios for (%s)\n",
1996 idx, tty->name); 1587 idx, tty->name);
1997 return; 1588 return;
1998 } 1589 }
1999 if (o_tty->termios_locked !=
2000 tty->driver->other->termios_locked[idx]) {
2001 printk(KERN_DEBUG "release_dev: other->termios_locked["
2002 "%d] not o_termios_locked for (%s)\n",
2003 idx, tty->name);
2004 return;
2005 }
2006 if (o_tty->link != tty) { 1590 if (o_tty->link != tty) {
2007 printk(KERN_DEBUG "release_dev: bad pty pointers\n"); 1591 printk(KERN_DEBUG "tty_release_dev: bad pty pointers\n");
2008 return; 1592 return;
2009 } 1593 }
2010 } 1594 }
@@ -2062,7 +1646,7 @@ static void release_dev(struct file *filp)
2062 if (!do_sleep) 1646 if (!do_sleep)
2063 break; 1647 break;
2064 1648
2065 printk(KERN_WARNING "release_dev: %s: read/write wait queue " 1649 printk(KERN_WARNING "tty_release_dev: %s: read/write wait queue "
2066 "active!\n", tty_name(tty, buf)); 1650 "active!\n", tty_name(tty, buf));
2067 mutex_unlock(&tty_mutex); 1651 mutex_unlock(&tty_mutex);
2068 schedule(); 1652 schedule();
@@ -2075,14 +1659,14 @@ static void release_dev(struct file *filp)
2075 */ 1659 */
2076 if (pty_master) { 1660 if (pty_master) {
2077 if (--o_tty->count < 0) { 1661 if (--o_tty->count < 0) {
2078 printk(KERN_WARNING "release_dev: bad pty slave count " 1662 printk(KERN_WARNING "tty_release_dev: bad pty slave count "
2079 "(%d) for %s\n", 1663 "(%d) for %s\n",
2080 o_tty->count, tty_name(o_tty, buf)); 1664 o_tty->count, tty_name(o_tty, buf));
2081 o_tty->count = 0; 1665 o_tty->count = 0;
2082 } 1666 }
2083 } 1667 }
2084 if (--tty->count < 0) { 1668 if (--tty->count < 0) {
2085 printk(KERN_WARNING "release_dev: bad tty->count (%d) for %s\n", 1669 printk(KERN_WARNING "tty_release_dev: bad tty->count (%d) for %s\n",
2086 tty->count, tty_name(tty, buf)); 1670 tty->count, tty_name(tty, buf));
2087 tty->count = 0; 1671 tty->count = 0;
2088 } 1672 }
@@ -2145,11 +1729,11 @@ static void release_dev(struct file *filp)
2145 1729
2146 /* Make this pty number available for reallocation */ 1730 /* Make this pty number available for reallocation */
2147 if (devpts) 1731 if (devpts)
2148 devpts_kill_index(idx); 1732 devpts_kill_index(inode, idx);
2149} 1733}
2150 1734
2151/** 1735/**
2152 * tty_open - open a tty device 1736 * __tty_open - open a tty device
2153 * @inode: inode of device file 1737 * @inode: inode of device file
2154 * @filp: file pointer to tty 1738 * @filp: file pointer to tty
2155 * 1739 *
@@ -2164,14 +1748,14 @@ static void release_dev(struct file *filp)
2164 * The termios state of a pty is reset on first open so that 1748 * The termios state of a pty is reset on first open so that
2165 * settings don't persist across reuse. 1749 * settings don't persist across reuse.
2166 * 1750 *
2167 * Locking: tty_mutex protects tty, get_tty_driver and init_dev work. 1751 * Locking: tty_mutex protects tty, get_tty_driver and tty_init_dev work.
2168 * tty->count should protect the rest. 1752 * tty->count should protect the rest.
2169 * ->siglock protects ->signal/->sighand 1753 * ->siglock protects ->signal/->sighand
2170 */ 1754 */
2171 1755
2172static int __tty_open(struct inode *inode, struct file *filp) 1756static int __tty_open(struct inode *inode, struct file *filp)
2173{ 1757{
2174 struct tty_struct *tty; 1758 struct tty_struct *tty = NULL;
2175 int noctty, retval; 1759 int noctty, retval;
2176 struct tty_driver *driver; 1760 struct tty_driver *driver;
2177 int index; 1761 int index;
@@ -2193,23 +1777,25 @@ retry_open:
2193 mutex_unlock(&tty_mutex); 1777 mutex_unlock(&tty_mutex);
2194 return -ENXIO; 1778 return -ENXIO;
2195 } 1779 }
2196 driver = tty->driver; 1780 driver = tty_driver_kref_get(tty->driver);
2197 index = tty->index; 1781 index = tty->index;
2198 filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */ 1782 filp->f_flags |= O_NONBLOCK; /* Don't let /dev/tty block */
2199 /* noctty = 1; */ 1783 /* noctty = 1; */
1784 /* FIXME: Should we take a driver reference ? */
1785 tty_kref_put(tty);
2200 goto got_driver; 1786 goto got_driver;
2201 } 1787 }
2202#ifdef CONFIG_VT 1788#ifdef CONFIG_VT
2203 if (device == MKDEV(TTY_MAJOR, 0)) { 1789 if (device == MKDEV(TTY_MAJOR, 0)) {
2204 extern struct tty_driver *console_driver; 1790 extern struct tty_driver *console_driver;
2205 driver = console_driver; 1791 driver = tty_driver_kref_get(console_driver);
2206 index = fg_console; 1792 index = fg_console;
2207 noctty = 1; 1793 noctty = 1;
2208 goto got_driver; 1794 goto got_driver;
2209 } 1795 }
2210#endif 1796#endif
2211 if (device == MKDEV(TTYAUX_MAJOR, 1)) { 1797 if (device == MKDEV(TTYAUX_MAJOR, 1)) {
2212 driver = console_device(&index); 1798 driver = tty_driver_kref_get(console_device(&index));
2213 if (driver) { 1799 if (driver) {
2214 /* Don't let /dev/console block */ 1800 /* Don't let /dev/console block */
2215 filp->f_flags |= O_NONBLOCK; 1801 filp->f_flags |= O_NONBLOCK;
@@ -2226,10 +1812,25 @@ retry_open:
2226 return -ENODEV; 1812 return -ENODEV;
2227 } 1813 }
2228got_driver: 1814got_driver:
2229 retval = init_dev(driver, index, &tty); 1815 if (!tty) {
1816 /* check whether we're reopening an existing tty */
1817 tty = tty_driver_lookup_tty(driver, inode, index);
1818
1819 if (IS_ERR(tty))
1820 return PTR_ERR(tty);
1821 }
1822
1823 if (tty) {
1824 retval = tty_reopen(tty);
1825 if (retval)
1826 tty = ERR_PTR(retval);
1827 } else
1828 tty = tty_init_dev(driver, index, 0);
1829
2230 mutex_unlock(&tty_mutex); 1830 mutex_unlock(&tty_mutex);
2231 if (retval) 1831 tty_driver_kref_put(driver);
2232 return retval; 1832 if (IS_ERR(tty))
1833 return PTR_ERR(tty);
2233 1834
2234 filp->private_data = tty; 1835 filp->private_data = tty;
2235 file_move(filp, &tty->tty_files); 1836 file_move(filp, &tty->tty_files);
@@ -2257,7 +1858,7 @@ got_driver:
2257 printk(KERN_DEBUG "error %d in opening %s...", retval, 1858 printk(KERN_DEBUG "error %d in opening %s...", retval,
2258 tty->name); 1859 tty->name);
2259#endif 1860#endif
2260 release_dev(filp); 1861 tty_release_dev(filp);
2261 if (retval != -ERESTARTSYS) 1862 if (retval != -ERESTARTSYS)
2262 return retval; 1863 return retval;
2263 if (signal_pending(current)) 1864 if (signal_pending(current))
@@ -2296,69 +1897,6 @@ static int tty_open(struct inode *inode, struct file *filp)
2296 1897
2297 1898
2298 1899
2299#ifdef CONFIG_UNIX98_PTYS
2300/**
2301 * ptmx_open - open a unix 98 pty master
2302 * @inode: inode of device file
2303 * @filp: file pointer to tty
2304 *
2305 * Allocate a unix98 pty master device from the ptmx driver.
2306 *
2307 * Locking: tty_mutex protects theinit_dev work. tty->count should
2308 * protect the rest.
2309 * allocated_ptys_lock handles the list of free pty numbers
2310 */
2311
2312static int __ptmx_open(struct inode *inode, struct file *filp)
2313{
2314 struct tty_struct *tty;
2315 int retval;
2316 int index;
2317
2318 nonseekable_open(inode, filp);
2319
2320 /* find a device that is not in use. */
2321 index = devpts_new_index();
2322 if (index < 0)
2323 return index;
2324
2325 mutex_lock(&tty_mutex);
2326 retval = init_dev(ptm_driver, index, &tty);
2327 mutex_unlock(&tty_mutex);
2328
2329 if (retval)
2330 goto out;
2331
2332 set_bit(TTY_PTY_LOCK, &tty->flags); /* LOCK THE SLAVE */
2333 filp->private_data = tty;
2334 file_move(filp, &tty->tty_files);
2335
2336 retval = devpts_pty_new(tty->link);
2337 if (retval)
2338 goto out1;
2339
2340 check_tty_count(tty, "ptmx_open");
2341 retval = ptm_driver->ops->open(tty, filp);
2342 if (!retval)
2343 return 0;
2344out1:
2345 release_dev(filp);
2346 return retval;
2347out:
2348 devpts_kill_index(index);
2349 return retval;
2350}
2351
2352static int ptmx_open(struct inode *inode, struct file *filp)
2353{
2354 int ret;
2355
2356 lock_kernel();
2357 ret = __ptmx_open(inode, filp);
2358 unlock_kernel();
2359 return ret;
2360}
2361#endif
2362 1900
2363/** 1901/**
2364 * tty_release - vfs callback for close 1902 * tty_release - vfs callback for close
@@ -2369,13 +1907,13 @@ static int ptmx_open(struct inode *inode, struct file *filp)
2369 * this tty. There may however be several such references. 1907 * this tty. There may however be several such references.
2370 * 1908 *
2371 * Locking: 1909 * Locking:
2372 * Takes bkl. See release_dev 1910 * Takes bkl. See tty_release_dev
2373 */ 1911 */
2374 1912
2375static int tty_release(struct inode *inode, struct file *filp) 1913static int tty_release(struct inode *inode, struct file *filp)
2376{ 1914{
2377 lock_kernel(); 1915 lock_kernel();
2378 release_dev(filp); 1916 tty_release_dev(filp);
2379 unlock_kernel(); 1917 unlock_kernel();
2380 return 0; 1918 return 0;
2381} 1919}
@@ -2524,7 +2062,7 @@ int tty_do_resize(struct tty_struct *tty, struct tty_struct *real_tty,
2524 2062
2525 /* For a PTY we need to lock the tty side */ 2063 /* For a PTY we need to lock the tty side */
2526 mutex_lock(&real_tty->termios_mutex); 2064 mutex_lock(&real_tty->termios_mutex);
2527 if (!memcmp(ws, &tty->winsize, sizeof(*ws))) 2065 if (!memcmp(ws, &real_tty->winsize, sizeof(*ws)))
2528 goto done; 2066 goto done;
2529 /* Get the PID values and reference them so we can 2067 /* Get the PID values and reference them so we can
2530 avoid holding the tty ctrl lock while sending signals */ 2068 avoid holding the tty ctrl lock while sending signals */
@@ -2996,7 +2534,7 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2996 case TIOCSTI: 2534 case TIOCSTI:
2997 return tiocsti(tty, p); 2535 return tiocsti(tty, p);
2998 case TIOCGWINSZ: 2536 case TIOCGWINSZ:
2999 return tiocgwinsz(tty, p); 2537 return tiocgwinsz(real_tty, p);
3000 case TIOCSWINSZ: 2538 case TIOCSWINSZ:
3001 return tiocswinsz(tty, real_tty, p); 2539 return tiocswinsz(tty, real_tty, p);
3002 case TIOCCONS: 2540 case TIOCCONS:
@@ -3026,10 +2564,6 @@ long tty_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
3026 return put_user(tty->ldisc.ops->num, (int __user *)p); 2564 return put_user(tty->ldisc.ops->num, (int __user *)p);
3027 case TIOCSETD: 2565 case TIOCSETD:
3028 return tiocsetd(tty, p); 2566 return tiocsetd(tty, p);
3029#ifdef CONFIG_VT
3030 case TIOCLINUX:
3031 return tioclinux(tty, arg);
3032#endif
3033 /* 2567 /*
3034 * Break handling 2568 * Break handling
3035 */ 2569 */
@@ -3220,113 +2754,6 @@ void do_SAK(struct tty_struct *tty)
3220EXPORT_SYMBOL(do_SAK); 2754EXPORT_SYMBOL(do_SAK);
3221 2755
3222/** 2756/**
3223 * flush_to_ldisc
3224 * @work: tty structure passed from work queue.
3225 *
3226 * This routine is called out of the software interrupt to flush data
3227 * from the buffer chain to the line discipline.
3228 *
3229 * Locking: holds tty->buf.lock to guard buffer list. Drops the lock
3230 * while invoking the line discipline receive_buf method. The
3231 * receive_buf method is single threaded for each tty instance.
3232 */
3233
3234static void flush_to_ldisc(struct work_struct *work)
3235{
3236 struct tty_struct *tty =
3237 container_of(work, struct tty_struct, buf.work.work);
3238 unsigned long flags;
3239 struct tty_ldisc *disc;
3240 struct tty_buffer *tbuf, *head;
3241 char *char_buf;
3242 unsigned char *flag_buf;
3243
3244 disc = tty_ldisc_ref(tty);
3245 if (disc == NULL) /* !TTY_LDISC */
3246 return;
3247
3248 spin_lock_irqsave(&tty->buf.lock, flags);
3249 /* So we know a flush is running */
3250 set_bit(TTY_FLUSHING, &tty->flags);
3251 head = tty->buf.head;
3252 if (head != NULL) {
3253 tty->buf.head = NULL;
3254 for (;;) {
3255 int count = head->commit - head->read;
3256 if (!count) {
3257 if (head->next == NULL)
3258 break;
3259 tbuf = head;
3260 head = head->next;
3261 tty_buffer_free(tty, tbuf);
3262 continue;
3263 }
3264 /* Ldisc or user is trying to flush the buffers
3265 we are feeding to the ldisc, stop feeding the
3266 line discipline as we want to empty the queue */
3267 if (test_bit(TTY_FLUSHPENDING, &tty->flags))
3268 break;
3269 if (!tty->receive_room) {
3270 schedule_delayed_work(&tty->buf.work, 1);
3271 break;
3272 }
3273 if (count > tty->receive_room)
3274 count = tty->receive_room;
3275 char_buf = head->char_buf_ptr + head->read;
3276 flag_buf = head->flag_buf_ptr + head->read;
3277 head->read += count;
3278 spin_unlock_irqrestore(&tty->buf.lock, flags);
3279 disc->ops->receive_buf(tty, char_buf,
3280 flag_buf, count);
3281 spin_lock_irqsave(&tty->buf.lock, flags);
3282 }
3283 /* Restore the queue head */
3284 tty->buf.head = head;
3285 }
3286 /* We may have a deferred request to flush the input buffer,
3287 if so pull the chain under the lock and empty the queue */
3288 if (test_bit(TTY_FLUSHPENDING, &tty->flags)) {
3289 __tty_buffer_flush(tty);
3290 clear_bit(TTY_FLUSHPENDING, &tty->flags);
3291 wake_up(&tty->read_wait);
3292 }
3293 clear_bit(TTY_FLUSHING, &tty->flags);
3294 spin_unlock_irqrestore(&tty->buf.lock, flags);
3295
3296 tty_ldisc_deref(disc);
3297}
3298
3299/**
3300 * tty_flip_buffer_push - terminal
3301 * @tty: tty to push
3302 *
3303 * Queue a push of the terminal flip buffers to the line discipline. This
3304 * function must not be called from IRQ context if tty->low_latency is set.
3305 *
3306 * In the event of the queue being busy for flipping the work will be
3307 * held off and retried later.
3308 *
3309 * Locking: tty buffer lock. Driver locks in low latency mode.
3310 */
3311
3312void tty_flip_buffer_push(struct tty_struct *tty)
3313{
3314 unsigned long flags;
3315 spin_lock_irqsave(&tty->buf.lock, flags);
3316 if (tty->buf.tail != NULL)
3317 tty->buf.tail->commit = tty->buf.tail->used;
3318 spin_unlock_irqrestore(&tty->buf.lock, flags);
3319
3320 if (tty->low_latency)
3321 flush_to_ldisc(&tty->buf.work.work);
3322 else
3323 schedule_delayed_work(&tty->buf.work, 1);
3324}
3325
3326EXPORT_SYMBOL(tty_flip_buffer_push);
3327
3328
3329/**
3330 * initialize_tty_struct 2757 * initialize_tty_struct
3331 * @tty: tty to initialize 2758 * @tty: tty to initialize
3332 * 2759 *
@@ -3336,9 +2763,11 @@ EXPORT_SYMBOL(tty_flip_buffer_push);
3336 * Locking: none - tty in question must not be exposed at this point 2763 * Locking: none - tty in question must not be exposed at this point
3337 */ 2764 */
3338 2765
3339static void initialize_tty_struct(struct tty_struct *tty) 2766void initialize_tty_struct(struct tty_struct *tty,
2767 struct tty_driver *driver, int idx)
3340{ 2768{
3341 memset(tty, 0, sizeof(struct tty_struct)); 2769 memset(tty, 0, sizeof(struct tty_struct));
2770 kref_init(&tty->kref);
3342 tty->magic = TTY_MAGIC; 2771 tty->magic = TTY_MAGIC;
3343 tty_ldisc_init(tty); 2772 tty_ldisc_init(tty);
3344 tty->session = NULL; 2773 tty->session = NULL;
@@ -3346,7 +2775,6 @@ static void initialize_tty_struct(struct tty_struct *tty)
3346 tty->overrun_time = jiffies; 2775 tty->overrun_time = jiffies;
3347 tty->buf.head = tty->buf.tail = NULL; 2776 tty->buf.head = tty->buf.tail = NULL;
3348 tty_buffer_init(tty); 2777 tty_buffer_init(tty);
3349 INIT_DELAYED_WORK(&tty->buf.work, flush_to_ldisc);
3350 mutex_init(&tty->termios_mutex); 2778 mutex_init(&tty->termios_mutex);
3351 init_waitqueue_head(&tty->write_wait); 2779 init_waitqueue_head(&tty->write_wait);
3352 init_waitqueue_head(&tty->read_wait); 2780 init_waitqueue_head(&tty->read_wait);
@@ -3357,6 +2785,11 @@ static void initialize_tty_struct(struct tty_struct *tty)
3357 spin_lock_init(&tty->ctrl_lock); 2785 spin_lock_init(&tty->ctrl_lock);
3358 INIT_LIST_HEAD(&tty->tty_files); 2786 INIT_LIST_HEAD(&tty->tty_files);
3359 INIT_WORK(&tty->SAK_work, do_SAK_work); 2787 INIT_WORK(&tty->SAK_work, do_SAK_work);
2788
2789 tty->driver = driver;
2790 tty->ops = driver->ops;
2791 tty->index = idx;
2792 tty_line_name(driver, idx, tty->name);
3360} 2793}
3361 2794
3362/** 2795/**
@@ -3377,10 +2810,9 @@ int tty_put_char(struct tty_struct *tty, unsigned char ch)
3377 return tty->ops->put_char(tty, ch); 2810 return tty->ops->put_char(tty, ch);
3378 return tty->ops->write(tty, &ch, 1); 2811 return tty->ops->write(tty, &ch, 1);
3379} 2812}
3380
3381EXPORT_SYMBOL_GPL(tty_put_char); 2813EXPORT_SYMBOL_GPL(tty_put_char);
3382 2814
3383static struct class *tty_class; 2815struct class *tty_class;
3384 2816
3385/** 2817/**
3386 * tty_register_device - register a tty device 2818 * tty_register_device - register a tty device
@@ -3418,8 +2850,9 @@ struct device *tty_register_device(struct tty_driver *driver, unsigned index,
3418 else 2850 else
3419 tty_line_name(driver, index, name); 2851 tty_line_name(driver, index, name);
3420 2852
3421 return device_create_drvdata(tty_class, device, dev, NULL, name); 2853 return device_create(tty_class, device, dev, NULL, name);
3422} 2854}
2855EXPORT_SYMBOL(tty_register_device);
3423 2856
3424/** 2857/**
3425 * tty_unregister_device - unregister a tty device 2858 * tty_unregister_device - unregister a tty device
@@ -3437,8 +2870,6 @@ void tty_unregister_device(struct tty_driver *driver, unsigned index)
3437 device_destroy(tty_class, 2870 device_destroy(tty_class,
3438 MKDEV(driver->major, driver->minor_start) + index); 2871 MKDEV(driver->major, driver->minor_start) + index);
3439} 2872}
3440
3441EXPORT_SYMBOL(tty_register_device);
3442EXPORT_SYMBOL(tty_unregister_device); 2873EXPORT_SYMBOL(tty_unregister_device);
3443 2874
3444struct tty_driver *alloc_tty_driver(int lines) 2875struct tty_driver *alloc_tty_driver(int lines)
@@ -3447,27 +2878,65 @@ struct tty_driver *alloc_tty_driver(int lines)
3447 2878
3448 driver = kzalloc(sizeof(struct tty_driver), GFP_KERNEL); 2879 driver = kzalloc(sizeof(struct tty_driver), GFP_KERNEL);
3449 if (driver) { 2880 if (driver) {
2881 kref_init(&driver->kref);
3450 driver->magic = TTY_DRIVER_MAGIC; 2882 driver->magic = TTY_DRIVER_MAGIC;
3451 driver->num = lines; 2883 driver->num = lines;
3452 /* later we'll move allocation of tables here */ 2884 /* later we'll move allocation of tables here */
3453 } 2885 }
3454 return driver; 2886 return driver;
3455} 2887}
2888EXPORT_SYMBOL(alloc_tty_driver);
3456 2889
3457void put_tty_driver(struct tty_driver *driver) 2890static void destruct_tty_driver(struct kref *kref)
3458{ 2891{
2892 struct tty_driver *driver = container_of(kref, struct tty_driver, kref);
2893 int i;
2894 struct ktermios *tp;
2895 void *p;
2896
2897 if (driver->flags & TTY_DRIVER_INSTALLED) {
2898 /*
2899 * Free the termios and termios_locked structures because
2900 * we don't want to get memory leaks when modular tty
2901 * drivers are removed from the kernel.
2902 */
2903 for (i = 0; i < driver->num; i++) {
2904 tp = driver->termios[i];
2905 if (tp) {
2906 driver->termios[i] = NULL;
2907 kfree(tp);
2908 }
2909 if (!(driver->flags & TTY_DRIVER_DYNAMIC_DEV))
2910 tty_unregister_device(driver, i);
2911 }
2912 p = driver->ttys;
2913 proc_tty_unregister_driver(driver);
2914 driver->ttys = NULL;
2915 driver->termios = NULL;
2916 kfree(p);
2917 cdev_del(&driver->cdev);
2918 }
3459 kfree(driver); 2919 kfree(driver);
3460} 2920}
3461 2921
2922void tty_driver_kref_put(struct tty_driver *driver)
2923{
2924 kref_put(&driver->kref, destruct_tty_driver);
2925}
2926EXPORT_SYMBOL(tty_driver_kref_put);
2927
3462void tty_set_operations(struct tty_driver *driver, 2928void tty_set_operations(struct tty_driver *driver,
3463 const struct tty_operations *op) 2929 const struct tty_operations *op)
3464{ 2930{
3465 driver->ops = op; 2931 driver->ops = op;
3466}; 2932};
2933EXPORT_SYMBOL(tty_set_operations);
3467 2934
3468EXPORT_SYMBOL(alloc_tty_driver); 2935void put_tty_driver(struct tty_driver *d)
2936{
2937 tty_driver_kref_put(d);
2938}
3469EXPORT_SYMBOL(put_tty_driver); 2939EXPORT_SYMBOL(put_tty_driver);
3470EXPORT_SYMBOL(tty_set_operations);
3471 2940
3472/* 2941/*
3473 * Called by a tty driver to register itself. 2942 * Called by a tty driver to register itself.
@@ -3479,11 +2948,8 @@ int tty_register_driver(struct tty_driver *driver)
3479 dev_t dev; 2948 dev_t dev;
3480 void **p = NULL; 2949 void **p = NULL;
3481 2950
3482 if (driver->flags & TTY_DRIVER_INSTALLED)
3483 return 0;
3484
3485 if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM) && driver->num) { 2951 if (!(driver->flags & TTY_DRIVER_DEVPTS_MEM) && driver->num) {
3486 p = kzalloc(driver->num * 3 * sizeof(void *), GFP_KERNEL); 2952 p = kzalloc(driver->num * 2 * sizeof(void *), GFP_KERNEL);
3487 if (!p) 2953 if (!p)
3488 return -ENOMEM; 2954 return -ENOMEM;
3489 } 2955 }
@@ -3507,12 +2973,9 @@ int tty_register_driver(struct tty_driver *driver)
3507 if (p) { 2973 if (p) {
3508 driver->ttys = (struct tty_struct **)p; 2974 driver->ttys = (struct tty_struct **)p;
3509 driver->termios = (struct ktermios **)(p + driver->num); 2975 driver->termios = (struct ktermios **)(p + driver->num);
3510 driver->termios_locked = (struct ktermios **)
3511 (p + driver->num * 2);
3512 } else { 2976 } else {
3513 driver->ttys = NULL; 2977 driver->ttys = NULL;
3514 driver->termios = NULL; 2978 driver->termios = NULL;
3515 driver->termios_locked = NULL;
3516 } 2979 }
3517 2980
3518 cdev_init(&driver->cdev, &tty_fops); 2981 cdev_init(&driver->cdev, &tty_fops);
@@ -3521,7 +2984,7 @@ int tty_register_driver(struct tty_driver *driver)
3521 if (error) { 2984 if (error) {
3522 unregister_chrdev_region(dev, driver->num); 2985 unregister_chrdev_region(dev, driver->num);
3523 driver->ttys = NULL; 2986 driver->ttys = NULL;
3524 driver->termios = driver->termios_locked = NULL; 2987 driver->termios = NULL;
3525 kfree(p); 2988 kfree(p);
3526 return error; 2989 return error;
3527 } 2990 }
@@ -3535,6 +2998,7 @@ int tty_register_driver(struct tty_driver *driver)
3535 tty_register_device(driver, i, NULL); 2998 tty_register_device(driver, i, NULL);
3536 } 2999 }
3537 proc_tty_register_driver(driver); 3000 proc_tty_register_driver(driver);
3001 driver->flags |= TTY_DRIVER_INSTALLED;
3538 return 0; 3002 return 0;
3539} 3003}
3540 3004
@@ -3545,46 +3009,19 @@ EXPORT_SYMBOL(tty_register_driver);
3545 */ 3009 */
3546int tty_unregister_driver(struct tty_driver *driver) 3010int tty_unregister_driver(struct tty_driver *driver)
3547{ 3011{
3548 int i; 3012#if 0
3549 struct ktermios *tp; 3013 /* FIXME */
3550 void *p;
3551
3552 if (driver->refcount) 3014 if (driver->refcount)
3553 return -EBUSY; 3015 return -EBUSY;
3554 3016#endif
3555 unregister_chrdev_region(MKDEV(driver->major, driver->minor_start), 3017 unregister_chrdev_region(MKDEV(driver->major, driver->minor_start),
3556 driver->num); 3018 driver->num);
3557 mutex_lock(&tty_mutex); 3019 mutex_lock(&tty_mutex);
3558 list_del(&driver->tty_drivers); 3020 list_del(&driver->tty_drivers);
3559 mutex_unlock(&tty_mutex); 3021 mutex_unlock(&tty_mutex);
3560
3561 /*
3562 * Free the termios and termios_locked structures because
3563 * we don't want to get memory leaks when modular tty
3564 * drivers are removed from the kernel.
3565 */
3566 for (i = 0; i < driver->num; i++) {
3567 tp = driver->termios[i];
3568 if (tp) {
3569 driver->termios[i] = NULL;
3570 kfree(tp);
3571 }
3572 tp = driver->termios_locked[i];
3573 if (tp) {
3574 driver->termios_locked[i] = NULL;
3575 kfree(tp);
3576 }
3577 if (!(driver->flags & TTY_DRIVER_DYNAMIC_DEV))
3578 tty_unregister_device(driver, i);
3579 }
3580 p = driver->ttys;
3581 proc_tty_unregister_driver(driver);
3582 driver->ttys = NULL;
3583 driver->termios = driver->termios_locked = NULL;
3584 kfree(p);
3585 cdev_del(&driver->cdev);
3586 return 0; 3022 return 0;
3587} 3023}
3024
3588EXPORT_SYMBOL(tty_unregister_driver); 3025EXPORT_SYMBOL(tty_unregister_driver);
3589 3026
3590dev_t tty_devnum(struct tty_struct *tty) 3027dev_t tty_devnum(struct tty_struct *tty)
@@ -3595,9 +3032,13 @@ EXPORT_SYMBOL(tty_devnum);
3595 3032
3596void proc_clear_tty(struct task_struct *p) 3033void proc_clear_tty(struct task_struct *p)
3597{ 3034{
3598 spin_lock_irq(&p->sighand->siglock); 3035 unsigned long flags;
3036 struct tty_struct *tty;
3037 spin_lock_irqsave(&p->sighand->siglock, flags);
3038 tty = p->signal->tty;
3599 p->signal->tty = NULL; 3039 p->signal->tty = NULL;
3600 spin_unlock_irq(&p->sighand->siglock); 3040 spin_unlock_irqrestore(&p->sighand->siglock, flags);
3041 tty_kref_put(tty);
3601} 3042}
3602 3043
3603/* Called under the sighand lock */ 3044/* Called under the sighand lock */
@@ -3613,9 +3054,13 @@ static void __proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
3613 tty->pgrp = get_pid(task_pgrp(tsk)); 3054 tty->pgrp = get_pid(task_pgrp(tsk));
3614 spin_unlock_irqrestore(&tty->ctrl_lock, flags); 3055 spin_unlock_irqrestore(&tty->ctrl_lock, flags);
3615 tty->session = get_pid(task_session(tsk)); 3056 tty->session = get_pid(task_session(tsk));
3057 if (tsk->signal->tty) {
3058 printk(KERN_DEBUG "tty not NULL!!\n");
3059 tty_kref_put(tsk->signal->tty);
3060 }
3616 } 3061 }
3617 put_pid(tsk->signal->tty_old_pgrp); 3062 put_pid(tsk->signal->tty_old_pgrp);
3618 tsk->signal->tty = tty; 3063 tsk->signal->tty = tty_kref_get(tty);
3619 tsk->signal->tty_old_pgrp = NULL; 3064 tsk->signal->tty_old_pgrp = NULL;
3620} 3065}
3621 3066
@@ -3629,18 +3074,20 @@ static void proc_set_tty(struct task_struct *tsk, struct tty_struct *tty)
3629struct tty_struct *get_current_tty(void) 3074struct tty_struct *get_current_tty(void)
3630{ 3075{
3631 struct tty_struct *tty; 3076 struct tty_struct *tty;
3632 WARN_ON_ONCE(!mutex_is_locked(&tty_mutex)); 3077 unsigned long flags;
3633 tty = current->signal->tty; 3078
3634 /* 3079 spin_lock_irqsave(&current->sighand->siglock, flags);
3635 * session->tty can be changed/cleared from under us, make sure we 3080 tty = tty_kref_get(current->signal->tty);
3636 * issue the load. The obtained pointer, when not NULL, is valid as 3081 spin_unlock_irqrestore(&current->sighand->siglock, flags);
3637 * long as we hold tty_mutex.
3638 */
3639 barrier();
3640 return tty; 3082 return tty;
3641} 3083}
3642EXPORT_SYMBOL_GPL(get_current_tty); 3084EXPORT_SYMBOL_GPL(get_current_tty);
3643 3085
3086void tty_default_fops(struct file_operations *fops)
3087{
3088 *fops = tty_fops;
3089}
3090
3644/* 3091/*
3645 * Initialize the console device. This is called *early*, so 3092 * Initialize the console device. This is called *early*, so
3646 * we can't necessarily depend on lots of kernel help here. 3093 * we can't necessarily depend on lots of kernel help here.
@@ -3678,12 +3125,6 @@ postcore_initcall(tty_class_init);
3678/* 3/2004 jmc: why do these devices exist? */ 3125/* 3/2004 jmc: why do these devices exist? */
3679 3126
3680static struct cdev tty_cdev, console_cdev; 3127static struct cdev tty_cdev, console_cdev;
3681#ifdef CONFIG_UNIX98_PTYS
3682static struct cdev ptmx_cdev;
3683#endif
3684#ifdef CONFIG_VT
3685static struct cdev vc0_cdev;
3686#endif
3687 3128
3688/* 3129/*
3689 * Ok, now we can initialize the rest of the tty devices and can count 3130 * Ok, now we can initialize the rest of the tty devices and can count
@@ -3695,32 +3136,18 @@ static int __init tty_init(void)
3695 if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) || 3136 if (cdev_add(&tty_cdev, MKDEV(TTYAUX_MAJOR, 0), 1) ||
3696 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0) 3137 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0)
3697 panic("Couldn't register /dev/tty driver\n"); 3138 panic("Couldn't register /dev/tty driver\n");
3698 device_create_drvdata(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL, 3139 device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 0), NULL,
3699 "tty"); 3140 "tty");
3700 3141
3701 cdev_init(&console_cdev, &console_fops); 3142 cdev_init(&console_cdev, &console_fops);
3702 if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) || 3143 if (cdev_add(&console_cdev, MKDEV(TTYAUX_MAJOR, 1), 1) ||
3703 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0) 3144 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0)
3704 panic("Couldn't register /dev/console driver\n"); 3145 panic("Couldn't register /dev/console driver\n");
3705 device_create_drvdata(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 1), NULL, 3146 device_create(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 1), NULL,
3706 "console"); 3147 "console");
3707 3148
3708#ifdef CONFIG_UNIX98_PTYS
3709 cdev_init(&ptmx_cdev, &ptmx_fops);
3710 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
3711 register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
3712 panic("Couldn't register /dev/ptmx driver\n");
3713 device_create_drvdata(tty_class, NULL, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx");
3714#endif
3715
3716#ifdef CONFIG_VT 3149#ifdef CONFIG_VT
3717 cdev_init(&vc0_cdev, &console_fops); 3150 vty_init(&console_fops);
3718 if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) ||
3719 register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0)
3720 panic("Couldn't register /dev/tty0 driver\n");
3721 device_create_drvdata(tty_class, NULL, MKDEV(TTY_MAJOR, 0), NULL, "tty0");
3722
3723 vty_init();
3724#endif 3151#endif
3725 return 0; 3152 return 0;
3726} 3153}
diff --git a/drivers/char/tty_ioctl.c b/drivers/char/tty_ioctl.c
index bf34e4597421..a408c8e487ec 100644
--- a/drivers/char/tty_ioctl.c
+++ b/drivers/char/tty_ioctl.c
@@ -40,6 +40,15 @@
40#define TERMIOS_OLD 8 40#define TERMIOS_OLD 8
41 41
42 42
43/**
44 * tty_chars_in_buffer - characters pending
45 * @tty: terminal
46 *
47 * Return the number of bytes of data in the device private
48 * output queue. If no private method is supplied there is assumed
49 * to be no queue on the device.
50 */
51
43int tty_chars_in_buffer(struct tty_struct *tty) 52int tty_chars_in_buffer(struct tty_struct *tty)
44{ 53{
45 if (tty->ops->chars_in_buffer) 54 if (tty->ops->chars_in_buffer)
@@ -47,26 +56,49 @@ int tty_chars_in_buffer(struct tty_struct *tty)
47 else 56 else
48 return 0; 57 return 0;
49} 58}
50
51EXPORT_SYMBOL(tty_chars_in_buffer); 59EXPORT_SYMBOL(tty_chars_in_buffer);
52 60
61/**
62 * tty_write_room - write queue space
63 * @tty: terminal
64 *
65 * Return the number of bytes that can be queued to this device
66 * at the present time. The result should be treated as a guarantee
67 * and the driver cannot offer a value it later shrinks by more than
68 * the number of bytes written. If no method is provided 2K is always
69 * returned and data may be lost as there will be no flow control.
70 */
71
53int tty_write_room(struct tty_struct *tty) 72int tty_write_room(struct tty_struct *tty)
54{ 73{
55 if (tty->ops->write_room) 74 if (tty->ops->write_room)
56 return tty->ops->write_room(tty); 75 return tty->ops->write_room(tty);
57 return 2048; 76 return 2048;
58} 77}
59
60EXPORT_SYMBOL(tty_write_room); 78EXPORT_SYMBOL(tty_write_room);
61 79
80/**
81 * tty_driver_flush_buffer - discard internal buffer
82 * @tty: terminal
83 *
84 * Discard the internal output buffer for this device. If no method
85 * is provided then either the buffer cannot be hardware flushed or
86 * there is no buffer driver side.
87 */
62void tty_driver_flush_buffer(struct tty_struct *tty) 88void tty_driver_flush_buffer(struct tty_struct *tty)
63{ 89{
64 if (tty->ops->flush_buffer) 90 if (tty->ops->flush_buffer)
65 tty->ops->flush_buffer(tty); 91 tty->ops->flush_buffer(tty);
66} 92}
67
68EXPORT_SYMBOL(tty_driver_flush_buffer); 93EXPORT_SYMBOL(tty_driver_flush_buffer);
69 94
95/**
96 * tty_throttle - flow control
97 * @tty: terminal
98 *
99 * Indicate that a tty should stop transmitting data down the stack.
100 */
101
70void tty_throttle(struct tty_struct *tty) 102void tty_throttle(struct tty_struct *tty)
71{ 103{
72 /* check TTY_THROTTLED first so it indicates our state */ 104 /* check TTY_THROTTLED first so it indicates our state */
@@ -76,6 +108,13 @@ void tty_throttle(struct tty_struct *tty)
76} 108}
77EXPORT_SYMBOL(tty_throttle); 109EXPORT_SYMBOL(tty_throttle);
78 110
111/**
112 * tty_unthrottle - flow control
113 * @tty: terminal
114 *
115 * Indicate that a tty may continue transmitting data down the stack.
116 */
117
79void tty_unthrottle(struct tty_struct *tty) 118void tty_unthrottle(struct tty_struct *tty)
80{ 119{
81 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) && 120 if (test_and_clear_bit(TTY_THROTTLED, &tty->flags) &&
@@ -112,6 +151,11 @@ void tty_wait_until_sent(struct tty_struct *tty, long timeout)
112} 151}
113EXPORT_SYMBOL(tty_wait_until_sent); 152EXPORT_SYMBOL(tty_wait_until_sent);
114 153
154
155/*
156 * Termios Helper Methods
157 */
158
115static void unset_locked_termios(struct ktermios *termios, 159static void unset_locked_termios(struct ktermios *termios,
116 struct ktermios *old, 160 struct ktermios *old,
117 struct ktermios *locked) 161 struct ktermios *locked)
@@ -346,6 +390,16 @@ void tty_termios_encode_baud_rate(struct ktermios *termios,
346} 390}
347EXPORT_SYMBOL_GPL(tty_termios_encode_baud_rate); 391EXPORT_SYMBOL_GPL(tty_termios_encode_baud_rate);
348 392
393/**
394 * tty_encode_baud_rate - set baud rate of the tty
395 * @ibaud: input baud rate
396 * @obad: output baud rate
397 *
398 * Update the current termios data for the tty with the new speed
399 * settings. The caller must hold the termios_mutex for the tty in
400 * question.
401 */
402
349void tty_encode_baud_rate(struct tty_struct *tty, speed_t ibaud, speed_t obaud) 403void tty_encode_baud_rate(struct tty_struct *tty, speed_t ibaud, speed_t obaud)
350{ 404{
351 tty_termios_encode_baud_rate(tty->termios, ibaud, obaud); 405 tty_termios_encode_baud_rate(tty->termios, ibaud, obaud);
@@ -430,12 +484,11 @@ EXPORT_SYMBOL(tty_termios_hw_change);
430 * is a bit of layering violation here with n_tty in terms of the 484 * is a bit of layering violation here with n_tty in terms of the
431 * internal knowledge of this function. 485 * internal knowledge of this function.
432 * 486 *
433 * Locking: termios_sem 487 * Locking: termios_mutex
434 */ 488 */
435 489
436static void change_termios(struct tty_struct *tty, struct ktermios *new_termios) 490static void change_termios(struct tty_struct *tty, struct ktermios *new_termios)
437{ 491{
438 int canon_change;
439 struct ktermios old_termios; 492 struct ktermios old_termios;
440 struct tty_ldisc *ld; 493 struct tty_ldisc *ld;
441 unsigned long flags; 494 unsigned long flags;
@@ -451,18 +504,6 @@ static void change_termios(struct tty_struct *tty, struct ktermios *new_termios)
451 old_termios = *tty->termios; 504 old_termios = *tty->termios;
452 *tty->termios = *new_termios; 505 *tty->termios = *new_termios;
453 unset_locked_termios(tty->termios, &old_termios, tty->termios_locked); 506 unset_locked_termios(tty->termios, &old_termios, tty->termios_locked);
454 canon_change = (old_termios.c_lflag ^ tty->termios->c_lflag) & ICANON;
455 if (canon_change) {
456 memset(&tty->read_flags, 0, sizeof tty->read_flags);
457 tty->canon_head = tty->read_tail;
458 tty->canon_data = 0;
459 tty->erasing = 0;
460 }
461
462 /* This bit should be in the ldisc code */
463 if (canon_change && !L_ICANON(tty) && tty->read_cnt)
464 /* Get characters left over from canonical mode. */
465 wake_up_interruptible(&tty->read_wait);
466 507
467 /* See if packet mode change of state. */ 508 /* See if packet mode change of state. */
468 if (tty->link && tty->link->packet) { 509 if (tty->link && tty->link->packet) {
@@ -508,7 +549,7 @@ static void change_termios(struct tty_struct *tty, struct ktermios *new_termios)
508 * functions before using change_termios to do the actual changes. 549 * functions before using change_termios to do the actual changes.
509 * 550 *
510 * Locking: 551 * Locking:
511 * Called functions take ldisc and termios_sem locks 552 * Called functions take ldisc and termios_mutex locks
512 */ 553 */
513 554
514static int set_termios(struct tty_struct *tty, void __user *arg, int opt) 555static int set_termios(struct tty_struct *tty, void __user *arg, int opt)
@@ -579,25 +620,51 @@ static int get_termio(struct tty_struct *tty, struct termio __user *termio)
579 return 0; 620 return 0;
580} 621}
581 622
582static unsigned long inq_canon(struct tty_struct *tty) 623
624#ifdef TCGETX
625
626/**
627 * set_termiox - set termiox fields if possible
628 * @tty: terminal
629 * @arg: termiox structure from user
630 * @opt: option flags for ioctl type
631 *
632 * Implement the device calling points for the SYS5 termiox ioctl
633 * interface in Linux
634 */
635
636static int set_termiox(struct tty_struct *tty, void __user *arg, int opt)
583{ 637{
584 int nr, head, tail; 638 struct termiox tnew;
639 struct tty_ldisc *ld;
585 640
586 if (!tty->canon_data || !tty->read_buf) 641 if (tty->termiox == NULL)
587 return 0; 642 return -EINVAL;
588 head = tty->canon_head; 643 if (copy_from_user(&tnew, arg, sizeof(struct termiox)))
589 tail = tty->read_tail; 644 return -EFAULT;
590 nr = (head - tail) & (N_TTY_BUF_SIZE-1); 645
591 /* Skip EOF-chars.. */ 646 ld = tty_ldisc_ref(tty);
592 while (head != tail) { 647 if (ld != NULL) {
593 if (test_bit(tail, tty->read_flags) && 648 if ((opt & TERMIOS_FLUSH) && ld->ops->flush_buffer)
594 tty->read_buf[tail] == __DISABLED_CHAR) 649 ld->ops->flush_buffer(tty);
595 nr--; 650 tty_ldisc_deref(ld);
596 tail = (tail+1) & (N_TTY_BUF_SIZE-1);
597 } 651 }
598 return nr; 652 if (opt & TERMIOS_WAIT) {
653 tty_wait_until_sent(tty, 0);
654 if (signal_pending(current))
655 return -EINTR;
656 }
657
658 mutex_lock(&tty->termios_mutex);
659 if (tty->ops->set_termiox)
660 tty->ops->set_termiox(tty, &tnew);
661 mutex_unlock(&tty->termios_mutex);
662 return 0;
599} 663}
600 664
665#endif
666
667
601#ifdef TIOCGETP 668#ifdef TIOCGETP
602/* 669/*
603 * These are deprecated, but there is limited support.. 670 * These are deprecated, but there is limited support..
@@ -671,7 +738,7 @@ static void set_sgflags(struct ktermios *termios, int flags)
671 * Updates a terminal from the legacy BSD style terminal information 738 * Updates a terminal from the legacy BSD style terminal information
672 * structure. 739 * structure.
673 * 740 *
674 * Locking: termios_sem 741 * Locking: termios_mutex
675 */ 742 */
676 743
677static int set_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb) 744static int set_sgttyb(struct tty_struct *tty, struct sgttyb __user *sgttyb)
@@ -849,6 +916,7 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
849{ 916{
850 struct tty_struct *real_tty; 917 struct tty_struct *real_tty;
851 void __user *p = (void __user *)arg; 918 void __user *p = (void __user *)arg;
919 int ret = 0;
852 920
853 if (tty->driver->type == TTY_DRIVER_TYPE_PTY && 921 if (tty->driver->type == TTY_DRIVER_TYPE_PTY &&
854 tty->driver->subtype == PTY_TYPE_MASTER) 922 tty->driver->subtype == PTY_TYPE_MASTER)
@@ -884,18 +952,24 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
884 return set_termios(real_tty, p, TERMIOS_OLD); 952 return set_termios(real_tty, p, TERMIOS_OLD);
885#ifndef TCGETS2 953#ifndef TCGETS2
886 case TCGETS: 954 case TCGETS:
955 mutex_lock(&real_tty->termios_mutex);
887 if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios)) 956 if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios))
888 return -EFAULT; 957 ret = -EFAULT;
889 return 0; 958 mutex_unlock(&real_tty->termios_mutex);
959 return ret;
890#else 960#else
891 case TCGETS: 961 case TCGETS:
962 mutex_lock(&real_tty->termios_mutex);
892 if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios)) 963 if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios))
893 return -EFAULT; 964 ret = -EFAULT;
894 return 0; 965 mutex_unlock(&real_tty->termios_mutex);
966 return ret;
895 case TCGETS2: 967 case TCGETS2:
968 mutex_lock(&real_tty->termios_mutex);
896 if (kernel_termios_to_user_termios((struct termios2 __user *)arg, real_tty->termios)) 969 if (kernel_termios_to_user_termios((struct termios2 __user *)arg, real_tty->termios))
897 return -EFAULT; 970 ret = -EFAULT;
898 return 0; 971 mutex_unlock(&real_tty->termios_mutex);
972 return ret;
899 case TCSETSF2: 973 case TCSETSF2:
900 return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT); 974 return set_termios(real_tty, p, TERMIOS_FLUSH | TERMIOS_WAIT);
901 case TCSETSW2: 975 case TCSETSW2:
@@ -913,34 +987,59 @@ int tty_mode_ioctl(struct tty_struct *tty, struct file *file,
913 return set_termios(real_tty, p, TERMIOS_TERMIO); 987 return set_termios(real_tty, p, TERMIOS_TERMIO);
914#ifndef TCGETS2 988#ifndef TCGETS2
915 case TIOCGLCKTRMIOS: 989 case TIOCGLCKTRMIOS:
990 mutex_lock(&real_tty->termios_mutex);
916 if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios_locked)) 991 if (kernel_termios_to_user_termios((struct termios __user *)arg, real_tty->termios_locked))
917 return -EFAULT; 992 ret = -EFAULT;
918 return 0; 993 mutex_unlock(&real_tty->termios_mutex);
994 return ret;
919 case TIOCSLCKTRMIOS: 995 case TIOCSLCKTRMIOS:
920 if (!capable(CAP_SYS_ADMIN)) 996 if (!capable(CAP_SYS_ADMIN))
921 return -EPERM; 997 return -EPERM;
998 mutex_lock(&real_tty->termios_mutex);
922 if (user_termios_to_kernel_termios(real_tty->termios_locked, 999 if (user_termios_to_kernel_termios(real_tty->termios_locked,
923 (struct termios __user *) arg)) 1000 (struct termios __user *) arg))
924 return -EFAULT; 1001 ret = -EFAULT;
925 return 0; 1002 mutex_unlock(&real_tty->termios_mutex);
1003 return ret;
926#else 1004#else
927 case TIOCGLCKTRMIOS: 1005 case TIOCGLCKTRMIOS:
1006 mutex_lock(&real_tty->termios_mutex);
928 if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios_locked)) 1007 if (kernel_termios_to_user_termios_1((struct termios __user *)arg, real_tty->termios_locked))
929 return -EFAULT; 1008 ret = -EFAULT;
930 return 0; 1009 mutex_unlock(&real_tty->termios_mutex);
1010 return ret;
931 case TIOCSLCKTRMIOS: 1011 case TIOCSLCKTRMIOS:
932 if (!capable(CAP_SYS_ADMIN)) 1012 if (!capable(CAP_SYS_ADMIN))
933 return -EPERM; 1013 ret = -EPERM;
1014 mutex_lock(&real_tty->termios_mutex);
934 if (user_termios_to_kernel_termios_1(real_tty->termios_locked, 1015 if (user_termios_to_kernel_termios_1(real_tty->termios_locked,
935 (struct termios __user *) arg)) 1016 (struct termios __user *) arg))
936 return -EFAULT; 1017 ret = -EFAULT;
937 return 0; 1018 mutex_unlock(&real_tty->termios_mutex);
1019 return ret;
938#endif 1020#endif
1021#ifdef TCGETX
1022 case TCGETX:
1023 if (real_tty->termiox == NULL)
1024 return -EINVAL;
1025 mutex_lock(&real_tty->termios_mutex);
1026 if (copy_to_user(p, real_tty->termiox, sizeof(struct termiox)))
1027 ret = -EFAULT;
1028 mutex_unlock(&real_tty->termios_mutex);
1029 return ret;
1030 case TCSETX:
1031 return set_termiox(real_tty, p, 0);
1032 case TCSETXW:
1033 return set_termiox(real_tty, p, TERMIOS_WAIT);
1034 case TCSETXF:
1035 return set_termiox(real_tty, p, TERMIOS_FLUSH);
1036#endif
939 case TIOCGSOFTCAR: 1037 case TIOCGSOFTCAR:
940 /* FIXME: for correctness we may need to take the termios 1038 mutex_lock(&real_tty->termios_mutex);
941 lock here - review */ 1039 ret = put_user(C_CLOCAL(real_tty) ? 1 : 0,
942 return put_user(C_CLOCAL(real_tty) ? 1 : 0,
943 (int __user *)arg); 1040 (int __user *)arg);
1041 mutex_unlock(&real_tty->termios_mutex);
1042 return ret;
944 case TIOCSSOFTCAR: 1043 case TIOCSSOFTCAR:
945 if (get_user(arg, (unsigned int __user *) arg)) 1044 if (get_user(arg, (unsigned int __user *) arg))
946 return -EFAULT; 1045 return -EFAULT;
@@ -980,7 +1079,7 @@ int tty_perform_flush(struct tty_struct *tty, unsigned long arg)
980} 1079}
981EXPORT_SYMBOL_GPL(tty_perform_flush); 1080EXPORT_SYMBOL_GPL(tty_perform_flush);
982 1081
983int n_tty_ioctl(struct tty_struct *tty, struct file *file, 1082int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file,
984 unsigned int cmd, unsigned long arg) 1083 unsigned int cmd, unsigned long arg)
985{ 1084{
986 unsigned long flags; 1085 unsigned long flags;
@@ -1018,13 +1117,6 @@ int n_tty_ioctl(struct tty_struct *tty, struct file *file,
1018 return 0; 1117 return 0;
1019 case TCFLSH: 1118 case TCFLSH:
1020 return tty_perform_flush(tty, arg); 1119 return tty_perform_flush(tty, arg);
1021 case TIOCOUTQ:
1022 return put_user(tty_chars_in_buffer(tty), (int __user *) arg);
1023 case TIOCINQ:
1024 retval = tty->read_cnt;
1025 if (L_ICANON(tty))
1026 retval = inq_canon(tty);
1027 return put_user(retval, (unsigned int __user *) arg);
1028 case TIOCPKT: 1120 case TIOCPKT:
1029 { 1121 {
1030 int pktmode; 1122 int pktmode;
@@ -1050,4 +1142,4 @@ int n_tty_ioctl(struct tty_struct *tty, struct file *file,
1050 return tty_mode_ioctl(tty, file, cmd, arg); 1142 return tty_mode_ioctl(tty, file, cmd, arg);
1051 } 1143 }
1052} 1144}
1053EXPORT_SYMBOL(n_tty_ioctl); 1145EXPORT_SYMBOL(n_tty_ioctl_helper);
diff --git a/drivers/char/tty_port.c b/drivers/char/tty_port.c
new file mode 100644
index 000000000000..553b0e9d8d17
--- /dev/null
+++ b/drivers/char/tty_port.c
@@ -0,0 +1,96 @@
1/*
2 * Tty port functions
3 */
4
5#include <linux/types.h>
6#include <linux/errno.h>
7#include <linux/tty.h>
8#include <linux/tty_driver.h>
9#include <linux/tty_flip.h>
10#include <linux/timer.h>
11#include <linux/string.h>
12#include <linux/slab.h>
13#include <linux/sched.h>
14#include <linux/init.h>
15#include <linux/wait.h>
16#include <linux/bitops.h>
17#include <linux/delay.h>
18#include <linux/module.h>
19
20void tty_port_init(struct tty_port *port)
21{
22 memset(port, 0, sizeof(*port));
23 init_waitqueue_head(&port->open_wait);
24 init_waitqueue_head(&port->close_wait);
25 mutex_init(&port->mutex);
26 spin_lock_init(&port->lock);
27 port->close_delay = (50 * HZ) / 100;
28 port->closing_wait = (3000 * HZ) / 100;
29}
30EXPORT_SYMBOL(tty_port_init);
31
32int tty_port_alloc_xmit_buf(struct tty_port *port)
33{
34 /* We may sleep in get_zeroed_page() */
35 mutex_lock(&port->mutex);
36 if (port->xmit_buf == NULL)
37 port->xmit_buf = (unsigned char *)get_zeroed_page(GFP_KERNEL);
38 mutex_unlock(&port->mutex);
39 if (port->xmit_buf == NULL)
40 return -ENOMEM;
41 return 0;
42}
43EXPORT_SYMBOL(tty_port_alloc_xmit_buf);
44
45void tty_port_free_xmit_buf(struct tty_port *port)
46{
47 mutex_lock(&port->mutex);
48 if (port->xmit_buf != NULL) {
49 free_page((unsigned long)port->xmit_buf);
50 port->xmit_buf = NULL;
51 }
52 mutex_unlock(&port->mutex);
53}
54EXPORT_SYMBOL(tty_port_free_xmit_buf);
55
56
57/**
58 * tty_port_tty_get - get a tty reference
59 * @port: tty port
60 *
61 * Return a refcount protected tty instance or NULL if the port is not
62 * associated with a tty (eg due to close or hangup)
63 */
64
65struct tty_struct *tty_port_tty_get(struct tty_port *port)
66{
67 unsigned long flags;
68 struct tty_struct *tty;
69
70 spin_lock_irqsave(&port->lock, flags);
71 tty = tty_kref_get(port->tty);
72 spin_unlock_irqrestore(&port->lock, flags);
73 return tty;
74}
75EXPORT_SYMBOL(tty_port_tty_get);
76
77/**
78 * tty_port_tty_set - set the tty of a port
79 * @port: tty port
80 * @tty: the tty
81 *
82 * Associate the port and tty pair. Manages any internal refcounts.
83 * Pass NULL to deassociate a port
84 */
85
86void tty_port_tty_set(struct tty_port *port, struct tty_struct *tty)
87{
88 unsigned long flags;
89
90 spin_lock_irqsave(&port->lock, flags);
91 if (port->tty)
92 tty_kref_put(port->tty);
93 port->tty = tty;
94 spin_unlock_irqrestore(&port->lock, flags);
95}
96EXPORT_SYMBOL(tty_port_tty_set);
diff --git a/drivers/char/vc_screen.c b/drivers/char/vc_screen.c
index c2ae52dd53d1..4f3b3f95fc42 100644
--- a/drivers/char/vc_screen.c
+++ b/drivers/char/vc_screen.c
@@ -481,10 +481,10 @@ static struct class *vc_class;
481 481
482void vcs_make_sysfs(struct tty_struct *tty) 482void vcs_make_sysfs(struct tty_struct *tty)
483{ 483{
484 device_create_drvdata(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 1), 484 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 1), NULL,
485 NULL, "vcs%u", tty->index + 1); 485 "vcs%u", tty->index + 1);
486 device_create_drvdata(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 129), 486 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, tty->index + 129), NULL,
487 NULL, "vcsa%u", tty->index + 1); 487 "vcsa%u", tty->index + 1);
488} 488}
489 489
490void vcs_remove_sysfs(struct tty_struct *tty) 490void vcs_remove_sysfs(struct tty_struct *tty)
@@ -499,7 +499,7 @@ int __init vcs_init(void)
499 panic("unable to get major %d for vcs device", VCS_MAJOR); 499 panic("unable to get major %d for vcs device", VCS_MAJOR);
500 vc_class = class_create(THIS_MODULE, "vc"); 500 vc_class = class_create(THIS_MODULE, "vc");
501 501
502 device_create_drvdata(vc_class, NULL, MKDEV(VCS_MAJOR, 0), NULL, "vcs"); 502 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 0), NULL, "vcs");
503 device_create_drvdata(vc_class, NULL, MKDEV(VCS_MAJOR, 128), NULL, "vcsa"); 503 device_create(vc_class, NULL, MKDEV(VCS_MAJOR, 128), NULL, "vcsa");
504 return 0; 504 return 0;
505} 505}
diff --git a/drivers/char/viotape.c b/drivers/char/viotape.c
index 7a70a40ad639..ffc9254f7e02 100644
--- a/drivers/char/viotape.c
+++ b/drivers/char/viotape.c
@@ -886,10 +886,10 @@ static int viotape_probe(struct vio_dev *vdev, const struct vio_device_id *id)
886 state[i].cur_part = 0; 886 state[i].cur_part = 0;
887 for (j = 0; j < MAX_PARTITIONS; ++j) 887 for (j = 0; j < MAX_PARTITIONS; ++j)
888 state[i].part_stat_rwi[j] = VIOT_IDLE; 888 state[i].part_stat_rwi[j] = VIOT_IDLE;
889 device_create_drvdata(tape_class, NULL, MKDEV(VIOTAPE_MAJOR, i), 889 device_create(tape_class, NULL, MKDEV(VIOTAPE_MAJOR, i), NULL,
890 NULL, "iseries!vt%d", i); 890 "iseries!vt%d", i);
891 device_create_drvdata(tape_class, NULL, MKDEV(VIOTAPE_MAJOR, i | 0x80), 891 device_create(tape_class, NULL, MKDEV(VIOTAPE_MAJOR, i | 0x80), NULL,
892 NULL, "iseries!nvt%d", i); 892 "iseries!nvt%d", i);
893 printk(VIOTAPE_KERN_INFO "tape iseries/vt%d is iSeries " 893 printk(VIOTAPE_KERN_INFO "tape iseries/vt%d is iSeries "
894 "resource %10.10s type %4.4s, model %3.3s\n", 894 "resource %10.10s type %4.4s, model %3.3s\n",
895 i, viotape_unitinfo[i].rsrcname, 895 i, viotape_unitinfo[i].rsrcname,
diff --git a/drivers/char/vt.c b/drivers/char/vt.c
index 60359c360912..d8f83e26e4a4 100644
--- a/drivers/char/vt.c
+++ b/drivers/char/vt.c
@@ -59,7 +59,7 @@
59 * by Martin Mares <mj@atrey.karlin.mff.cuni.cz>, July 1998 59 * by Martin Mares <mj@atrey.karlin.mff.cuni.cz>, July 1998
60 * 60 *
61 * Removed old-style timers, introduced console_timer, made timer 61 * Removed old-style timers, introduced console_timer, made timer
62 * deletion SMP-safe. 17Jun00, Andrew Morton <andrewm@uow.edu.au> 62 * deletion SMP-safe. 17Jun00, Andrew Morton
63 * 63 *
64 * Removed console_lock, enabled interrupts across all console operations 64 * Removed console_lock, enabled interrupts across all console operations
65 * 13 March 2001, Andrew Morton 65 * 13 March 2001, Andrew Morton
@@ -100,10 +100,10 @@
100#include <linux/font.h> 100#include <linux/font.h>
101#include <linux/bitops.h> 101#include <linux/bitops.h>
102#include <linux/notifier.h> 102#include <linux/notifier.h>
103 103#include <linux/device.h>
104#include <asm/io.h> 104#include <linux/io.h>
105#include <asm/system.h> 105#include <asm/system.h>
106#include <asm/uaccess.h> 106#include <linux/uaccess.h>
107 107
108#define MAX_NR_CON_DRIVER 16 108#define MAX_NR_CON_DRIVER 16
109 109
@@ -301,7 +301,7 @@ static void scrup(struct vc_data *vc, unsigned int t, unsigned int b, int nr)
301 d = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t); 301 d = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t);
302 s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * (t + nr)); 302 s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * (t + nr));
303 scr_memmovew(d, s, (b - t - nr) * vc->vc_size_row); 303 scr_memmovew(d, s, (b - t - nr) * vc->vc_size_row);
304 scr_memsetw(d + (b - t - nr) * vc->vc_cols, vc->vc_scrl_erase_char, 304 scr_memsetw(d + (b - t - nr) * vc->vc_cols, vc->vc_video_erase_char,
305 vc->vc_size_row * nr); 305 vc->vc_size_row * nr);
306} 306}
307 307
@@ -319,7 +319,7 @@ static void scrdown(struct vc_data *vc, unsigned int t, unsigned int b, int nr)
319 s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t); 319 s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t);
320 step = vc->vc_cols * nr; 320 step = vc->vc_cols * nr;
321 scr_memmovew(s + step, s, (b - t - nr) * vc->vc_size_row); 321 scr_memmovew(s + step, s, (b - t - nr) * vc->vc_size_row);
322 scr_memsetw(s, vc->vc_scrl_erase_char, 2 * step); 322 scr_memsetw(s, vc->vc_video_erase_char, 2 * step);
323} 323}
324 324
325static void do_update_region(struct vc_data *vc, unsigned long start, int count) 325static void do_update_region(struct vc_data *vc, unsigned long start, int count)
@@ -434,7 +434,6 @@ static void update_attr(struct vc_data *vc)
434 vc->vc_blink, vc->vc_underline, 434 vc->vc_blink, vc->vc_underline,
435 vc->vc_reverse ^ vc->vc_decscnm, vc->vc_italic); 435 vc->vc_reverse ^ vc->vc_decscnm, vc->vc_italic);
436 vc->vc_video_erase_char = (build_attr(vc, vc->vc_color, 1, vc->vc_blink, 0, vc->vc_decscnm, 0) << 8) | ' '; 436 vc->vc_video_erase_char = (build_attr(vc, vc->vc_color, 1, vc->vc_blink, 0, vc->vc_decscnm, 0) << 8) | ' ';
437 vc->vc_scrl_erase_char = (build_attr(vc, vc->vc_def_color, 1, false, false, vc->vc_decscnm, false) << 8) | ' ';
438} 437}
439 438
440/* Note: inverting the screen twice should revert to the original state */ 439/* Note: inverting the screen twice should revert to the original state */
@@ -2136,27 +2135,9 @@ static int do_con_write(struct tty_struct *tty, const unsigned char *buf, int co
2136 release_console_sem(); 2135 release_console_sem();
2137 return 0; 2136 return 0;
2138 } 2137 }
2139 release_console_sem();
2140
2141 orig_buf = buf; 2138 orig_buf = buf;
2142 orig_count = count; 2139 orig_count = count;
2143 2140
2144 /* At this point 'buf' is guaranteed to be a kernel buffer
2145 * and therefore no access to userspace (and therefore sleeping)
2146 * will be needed. The con_buf_mtx serializes all tty based
2147 * console rendering and vcs write/read operations. We hold
2148 * the console spinlock during the entire write.
2149 */
2150
2151 acquire_console_sem();
2152
2153 vc = tty->driver_data;
2154 if (vc == NULL) {
2155 printk(KERN_ERR "vt: argh, driver_data _became_ NULL !\n");
2156 release_console_sem();
2157 goto out;
2158 }
2159
2160 himask = vc->vc_hi_font_mask; 2141 himask = vc->vc_hi_font_mask;
2161 charmask = himask ? 0x1ff : 0xff; 2142 charmask = himask ? 0x1ff : 0xff;
2162 2143
@@ -2370,8 +2351,6 @@ rescan_last_byte:
2370 FLUSH 2351 FLUSH
2371 console_conditional_schedule(); 2352 console_conditional_schedule();
2372 release_console_sem(); 2353 release_console_sem();
2373
2374out:
2375 notify_update(vc); 2354 notify_update(vc);
2376 return n; 2355 return n;
2377#undef FLUSH 2356#undef FLUSH
@@ -2583,8 +2562,6 @@ int tioclinux(struct tty_struct *tty, unsigned long arg)
2583 int lines; 2562 int lines;
2584 int ret; 2563 int ret;
2585 2564
2586 if (tty->driver->type != TTY_DRIVER_TYPE_CONSOLE)
2587 return -EINVAL;
2588 if (current->signal->tty != tty && !capable(CAP_SYS_ADMIN)) 2565 if (current->signal->tty != tty && !capable(CAP_SYS_ADMIN))
2589 return -EPERM; 2566 return -EPERM;
2590 if (get_user(type, p)) 2567 if (get_user(type, p))
@@ -2778,6 +2755,12 @@ static int con_open(struct tty_struct *tty, struct file *filp)
2778 ret = vc_allocate(currcons); 2755 ret = vc_allocate(currcons);
2779 if (ret == 0) { 2756 if (ret == 0) {
2780 struct vc_data *vc = vc_cons[currcons].d; 2757 struct vc_data *vc = vc_cons[currcons].d;
2758
2759 /* Still being freed */
2760 if (vc->vc_tty) {
2761 release_console_sem();
2762 return -ERESTARTSYS;
2763 }
2781 tty->driver_data = vc; 2764 tty->driver_data = vc;
2782 vc->vc_tty = tty; 2765 vc->vc_tty = tty;
2783 2766
@@ -2798,34 +2781,20 @@ static int con_open(struct tty_struct *tty, struct file *filp)
2798 return ret; 2781 return ret;
2799} 2782}
2800 2783
2801/*
2802 * We take tty_mutex in here to prevent another thread from coming in via init_dev
2803 * and taking a ref against the tty while we're in the process of forgetting
2804 * about it and cleaning things up.
2805 *
2806 * This is because vcs_remove_sysfs() can sleep and will drop the BKL.
2807 */
2808static void con_close(struct tty_struct *tty, struct file *filp) 2784static void con_close(struct tty_struct *tty, struct file *filp)
2809{ 2785{
2810 mutex_lock(&tty_mutex); 2786 /* Nothing to do - we defer to shutdown */
2811 acquire_console_sem(); 2787}
2812 if (tty && tty->count == 1) {
2813 struct vc_data *vc = tty->driver_data;
2814 2788
2815 if (vc) 2789static void con_shutdown(struct tty_struct *tty)
2816 vc->vc_tty = NULL; 2790{
2817 tty->driver_data = NULL; 2791 struct vc_data *vc = tty->driver_data;
2818 vcs_remove_sysfs(tty); 2792 BUG_ON(vc == NULL);
2819 release_console_sem(); 2793 acquire_console_sem();
2820 mutex_unlock(&tty_mutex); 2794 vc->vc_tty = NULL;
2821 /* 2795 vcs_remove_sysfs(tty);
2822 * tty_mutex is released, but we still hold BKL, so there is
2823 * still exclusion against init_dev()
2824 */
2825 return;
2826 }
2827 release_console_sem(); 2796 release_console_sem();
2828 mutex_unlock(&tty_mutex); 2797 tty_shutdown(tty);
2829} 2798}
2830 2799
2831static int default_italic_color = 2; // green (ASCII) 2800static int default_italic_color = 2; // green (ASCII)
@@ -2950,10 +2919,19 @@ static const struct tty_operations con_ops = {
2950 .throttle = con_throttle, 2919 .throttle = con_throttle,
2951 .unthrottle = con_unthrottle, 2920 .unthrottle = con_unthrottle,
2952 .resize = vt_resize, 2921 .resize = vt_resize,
2922 .shutdown = con_shutdown
2953}; 2923};
2954 2924
2955int __init vty_init(void) 2925static struct cdev vc0_cdev;
2926
2927int __init vty_init(const struct file_operations *console_fops)
2956{ 2928{
2929 cdev_init(&vc0_cdev, console_fops);
2930 if (cdev_add(&vc0_cdev, MKDEV(TTY_MAJOR, 0), 1) ||
2931 register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0)
2932 panic("Couldn't register /dev/tty0 driver\n");
2933 device_create(tty_class, NULL, MKDEV(TTY_MAJOR, 0), NULL, "tty0");
2934
2957 vcs_init(); 2935 vcs_init();
2958 2936
2959 console_driver = alloc_tty_driver(MAX_NR_CONSOLES); 2937 console_driver = alloc_tty_driver(MAX_NR_CONSOLES);
@@ -2972,7 +2950,6 @@ int __init vty_init(void)
2972 tty_set_operations(console_driver, &con_ops); 2950 tty_set_operations(console_driver, &con_ops);
2973 if (tty_register_driver(console_driver)) 2951 if (tty_register_driver(console_driver))
2974 panic("Couldn't register console driver\n"); 2952 panic("Couldn't register console driver\n");
2975
2976 kbd_init(); 2953 kbd_init();
2977 console_map_init(); 2954 console_map_init();
2978#ifdef CONFIG_PROM_CONSOLE 2955#ifdef CONFIG_PROM_CONSOLE
@@ -3466,7 +3443,7 @@ int register_con_driver(const struct consw *csw, int first, int last)
3466 if (retval) 3443 if (retval)
3467 goto err; 3444 goto err;
3468 3445
3469 con_driver->dev = device_create_drvdata(vtconsole_class, NULL, 3446 con_driver->dev = device_create(vtconsole_class, NULL,
3470 MKDEV(0, con_driver->node), 3447 MKDEV(0, con_driver->node),
3471 NULL, "vtcon%i", 3448 NULL, "vtcon%i",
3472 con_driver->node); 3449 con_driver->node);
@@ -3577,7 +3554,7 @@ static int __init vtconsole_class_init(void)
3577 struct con_driver *con = &registered_con_driver[i]; 3554 struct con_driver *con = &registered_con_driver[i];
3578 3555
3579 if (con->con && !con->dev) { 3556 if (con->con && !con->dev) {
3580 con->dev = device_create_drvdata(vtconsole_class, NULL, 3557 con->dev = device_create(vtconsole_class, NULL,
3581 MKDEV(0, con->node), 3558 MKDEV(0, con->node),
3582 NULL, "vtcon%i", 3559 NULL, "vtcon%i",
3583 con->node); 3560 con->node);
diff --git a/drivers/char/vt_ioctl.c b/drivers/char/vt_ioctl.c
index c904e9ad4a71..8944ce508e2f 100644
--- a/drivers/char/vt_ioctl.c
+++ b/drivers/char/vt_ioctl.c
@@ -395,6 +395,8 @@ int vt_ioctl(struct tty_struct *tty, struct file * file,
395 395
396 kbd = kbd_table + console; 396 kbd = kbd_table + console;
397 switch (cmd) { 397 switch (cmd) {
398 case TIOCLINUX:
399 return tioclinux(tty, arg);
398 case KIOCSOUND: 400 case KIOCSOUND:
399 if (!perm) 401 if (!perm)
400 goto eperm; 402 goto eperm;
diff --git a/drivers/char/xilinx_hwicap/xilinx_hwicap.c b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
index 278c9857bcf5..ed132fe55d3d 100644
--- a/drivers/char/xilinx_hwicap/xilinx_hwicap.c
+++ b/drivers/char/xilinx_hwicap/xilinx_hwicap.c
@@ -657,8 +657,7 @@ static int __devinit hwicap_setup(struct device *dev, int id,
657 goto failed3; 657 goto failed3;
658 } 658 }
659 659
660 device_create_drvdata(icap_class, dev, devt, NULL, 660 device_create(icap_class, dev, devt, NULL, "%s%d", DRIVER_NAME, id);
661 "%s%d", DRIVER_NAME, id);
662 return 0; /* success */ 661 return 0; /* success */
663 662
664 failed3: 663 failed3:
diff --git a/drivers/dca/dca-sysfs.c b/drivers/dca/dca-sysfs.c
index 7af4b403bd2d..bb538b9690e0 100644
--- a/drivers/dca/dca-sysfs.c
+++ b/drivers/dca/dca-sysfs.c
@@ -15,9 +15,8 @@ int dca_sysfs_add_req(struct dca_provider *dca, struct device *dev, int slot)
15 struct device *cd; 15 struct device *cd;
16 static int req_count; 16 static int req_count;
17 17
18 cd = device_create_drvdata(dca_class, dca->cd, 18 cd = device_create(dca_class, dca->cd, MKDEV(0, slot + 1), NULL,
19 MKDEV(0, slot + 1), NULL, 19 "requester%d", req_count++);
20 "requester%d", req_count++);
21 if (IS_ERR(cd)) 20 if (IS_ERR(cd))
22 return PTR_ERR(cd); 21 return PTR_ERR(cd);
23 return 0; 22 return 0;
@@ -48,8 +47,7 @@ idr_try_again:
48 return err; 47 return err;
49 } 48 }
50 49
51 cd = device_create_drvdata(dca_class, dev, MKDEV(0, 0), NULL, 50 cd = device_create(dca_class, dev, MKDEV(0, 0), NULL, "dca%d", dca->id);
52 "dca%d", dca->id);
53 if (IS_ERR(cd)) { 51 if (IS_ERR(cd)) {
54 spin_lock(&dca_idr_lock); 52 spin_lock(&dca_idr_lock);
55 idr_remove(&dca_idr, dca->id); 53 idr_remove(&dca_idr, dca->id);
diff --git a/drivers/edac/i5000_edac.c b/drivers/edac/i5000_edac.c
index 4a16b5b61cfb..f0d9b415db50 100644
--- a/drivers/edac/i5000_edac.c
+++ b/drivers/edac/i5000_edac.c
@@ -119,6 +119,7 @@
119#define FERR_NF_UNCORRECTABLE (FERR_NF_M12ERR | \ 119#define FERR_NF_UNCORRECTABLE (FERR_NF_M12ERR | \
120 FERR_NF_M11ERR | \ 120 FERR_NF_M11ERR | \
121 FERR_NF_M10ERR | \ 121 FERR_NF_M10ERR | \
122 FERR_NF_M9ERR | \
122 FERR_NF_M8ERR | \ 123 FERR_NF_M8ERR | \
123 FERR_NF_M7ERR | \ 124 FERR_NF_M7ERR | \
124 FERR_NF_M6ERR | \ 125 FERR_NF_M6ERR | \
@@ -301,6 +302,9 @@ static char *numcol_toString[] = {
301}; 302};
302#endif 303#endif
303 304
305/* enables the report of miscellaneous messages as CE errors - default off */
306static int misc_messages;
307
304/* Enumeration of supported devices */ 308/* Enumeration of supported devices */
305enum i5000_chips { 309enum i5000_chips {
306 I5000P = 0, 310 I5000P = 0,
@@ -466,7 +470,8 @@ static void i5000_process_fatal_error_info(struct mem_ctl_info *mci,
466 struct i5000_error_info *info, 470 struct i5000_error_info *info,
467 int handle_errors) 471 int handle_errors)
468{ 472{
469 char msg[EDAC_MC_LABEL_LEN + 1 + 90]; 473 char msg[EDAC_MC_LABEL_LEN + 1 + 160];
474 char *specific = NULL;
470 u32 allErrors; 475 u32 allErrors;
471 int branch; 476 int branch;
472 int channel; 477 int channel;
@@ -480,11 +485,6 @@ static void i5000_process_fatal_error_info(struct mem_ctl_info *mci,
480 if (!allErrors) 485 if (!allErrors)
481 return; /* if no error, return now */ 486 return; /* if no error, return now */
482 487
483 /* ONLY ONE of the possible error bits will be set, as per the docs */
484 i5000_mc_printk(mci, KERN_ERR,
485 "FATAL ERRORS Found!!! 1st FATAL Err Reg= 0x%x\n",
486 allErrors);
487
488 branch = EXTRACT_FBDCHAN_INDX(info->ferr_fat_fbd); 488 branch = EXTRACT_FBDCHAN_INDX(info->ferr_fat_fbd);
489 channel = branch; 489 channel = branch;
490 490
@@ -501,28 +501,42 @@ static void i5000_process_fatal_error_info(struct mem_ctl_info *mci,
501 rdwr ? "Write" : "Read", ras, cas); 501 rdwr ? "Write" : "Read", ras, cas);
502 502
503 /* Only 1 bit will be on */ 503 /* Only 1 bit will be on */
504 if (allErrors & FERR_FAT_M1ERR) { 504 switch (allErrors) {
505 i5000_mc_printk(mci, KERN_ERR, 505 case FERR_FAT_M1ERR:
506 "Alert on non-redundant retry or fast " 506 specific = "Alert on non-redundant retry or fast "
507 "reset timeout\n"); 507 "reset timeout";
508 508 break;
509 } else if (allErrors & FERR_FAT_M2ERR) { 509 case FERR_FAT_M2ERR:
510 i5000_mc_printk(mci, KERN_ERR, 510 specific = "Northbound CRC error on non-redundant "
511 "Northbound CRC error on non-redundant " 511 "retry";
512 "retry\n"); 512 break;
513 513 case FERR_FAT_M3ERR:
514 } else if (allErrors & FERR_FAT_M3ERR) { 514 {
515 i5000_mc_printk(mci, KERN_ERR, 515 static int done;
516 ">Tmid Thermal event with intelligent " 516
517 "throttling disabled\n"); 517 /*
518 * This error is generated to inform that the intelligent
519 * throttling is disabled and the temperature passed the
520 * specified middle point. Since this is something the BIOS
521 * should take care of, we'll warn only once to avoid
522 * worthlessly flooding the log.
523 */
524 if (done)
525 return;
526 done++;
527
528 specific = ">Tmid Thermal event with intelligent "
529 "throttling disabled";
530 }
531 break;
518 } 532 }
519 533
520 /* Form out message */ 534 /* Form out message */
521 snprintf(msg, sizeof(msg), 535 snprintf(msg, sizeof(msg),
522 "(Branch=%d DRAM-Bank=%d RDWR=%s RAS=%d CAS=%d " 536 "(Branch=%d DRAM-Bank=%d RDWR=%s RAS=%d CAS=%d "
523 "FATAL Err=0x%x)", 537 "FATAL Err=0x%x (%s))",
524 branch >> 1, bank, rdwr ? "Write" : "Read", ras, cas, 538 branch >> 1, bank, rdwr ? "Write" : "Read", ras, cas,
525 allErrors); 539 allErrors, specific);
526 540
527 /* Call the helper to output message */ 541 /* Call the helper to output message */
528 edac_mc_handle_fbd_ue(mci, rank, channel, channel + 1, msg); 542 edac_mc_handle_fbd_ue(mci, rank, channel, channel + 1, msg);
@@ -539,7 +553,8 @@ static void i5000_process_nonfatal_error_info(struct mem_ctl_info *mci,
539 struct i5000_error_info *info, 553 struct i5000_error_info *info,
540 int handle_errors) 554 int handle_errors)
541{ 555{
542 char msg[EDAC_MC_LABEL_LEN + 1 + 90]; 556 char msg[EDAC_MC_LABEL_LEN + 1 + 170];
557 char *specific = NULL;
543 u32 allErrors; 558 u32 allErrors;
544 u32 ue_errors; 559 u32 ue_errors;
545 u32 ce_errors; 560 u32 ce_errors;
@@ -557,10 +572,6 @@ static void i5000_process_nonfatal_error_info(struct mem_ctl_info *mci,
557 return; /* if no error, return now */ 572 return; /* if no error, return now */
558 573
559 /* ONLY ONE of the possible error bits will be set, as per the docs */ 574 /* ONLY ONE of the possible error bits will be set, as per the docs */
560 i5000_mc_printk(mci, KERN_WARNING,
561 "NON-FATAL ERRORS Found!!! 1st NON-FATAL Err "
562 "Reg= 0x%x\n", allErrors);
563
564 ue_errors = allErrors & FERR_NF_UNCORRECTABLE; 575 ue_errors = allErrors & FERR_NF_UNCORRECTABLE;
565 if (ue_errors) { 576 if (ue_errors) {
566 debugf0("\tUncorrected bits= 0x%x\n", ue_errors); 577 debugf0("\tUncorrected bits= 0x%x\n", ue_errors);
@@ -579,12 +590,47 @@ static void i5000_process_nonfatal_error_info(struct mem_ctl_info *mci,
579 rank, channel, channel + 1, branch >> 1, bank, 590 rank, channel, channel + 1, branch >> 1, bank,
580 rdwr ? "Write" : "Read", ras, cas); 591 rdwr ? "Write" : "Read", ras, cas);
581 592
593 switch (ue_errors) {
594 case FERR_NF_M12ERR:
595 specific = "Non-Aliased Uncorrectable Patrol Data ECC";
596 break;
597 case FERR_NF_M11ERR:
598 specific = "Non-Aliased Uncorrectable Spare-Copy "
599 "Data ECC";
600 break;
601 case FERR_NF_M10ERR:
602 specific = "Non-Aliased Uncorrectable Mirrored Demand "
603 "Data ECC";
604 break;
605 case FERR_NF_M9ERR:
606 specific = "Non-Aliased Uncorrectable Non-Mirrored "
607 "Demand Data ECC";
608 break;
609 case FERR_NF_M8ERR:
610 specific = "Aliased Uncorrectable Patrol Data ECC";
611 break;
612 case FERR_NF_M7ERR:
613 specific = "Aliased Uncorrectable Spare-Copy Data ECC";
614 break;
615 case FERR_NF_M6ERR:
616 specific = "Aliased Uncorrectable Mirrored Demand "
617 "Data ECC";
618 break;
619 case FERR_NF_M5ERR:
620 specific = "Aliased Uncorrectable Non-Mirrored Demand "
621 "Data ECC";
622 break;
623 case FERR_NF_M4ERR:
624 specific = "Uncorrectable Data ECC on Replay";
625 break;
626 }
627
582 /* Form out message */ 628 /* Form out message */
583 snprintf(msg, sizeof(msg), 629 snprintf(msg, sizeof(msg),
584 "(Branch=%d DRAM-Bank=%d RDWR=%s RAS=%d " 630 "(Branch=%d DRAM-Bank=%d RDWR=%s RAS=%d "
585 "CAS=%d, UE Err=0x%x)", 631 "CAS=%d, UE Err=0x%x (%s))",
586 branch >> 1, bank, rdwr ? "Write" : "Read", ras, cas, 632 branch >> 1, bank, rdwr ? "Write" : "Read", ras, cas,
587 ue_errors); 633 ue_errors, specific);
588 634
589 /* Call the helper to output message */ 635 /* Call the helper to output message */
590 edac_mc_handle_fbd_ue(mci, rank, channel, channel + 1, msg); 636 edac_mc_handle_fbd_ue(mci, rank, channel, channel + 1, msg);
@@ -616,51 +662,74 @@ static void i5000_process_nonfatal_error_info(struct mem_ctl_info *mci,
616 rank, channel, branch >> 1, bank, 662 rank, channel, branch >> 1, bank,
617 rdwr ? "Write" : "Read", ras, cas); 663 rdwr ? "Write" : "Read", ras, cas);
618 664
665 switch (ce_errors) {
666 case FERR_NF_M17ERR:
667 specific = "Correctable Non-Mirrored Demand Data ECC";
668 break;
669 case FERR_NF_M18ERR:
670 specific = "Correctable Mirrored Demand Data ECC";
671 break;
672 case FERR_NF_M19ERR:
673 specific = "Correctable Spare-Copy Data ECC";
674 break;
675 case FERR_NF_M20ERR:
676 specific = "Correctable Patrol Data ECC";
677 break;
678 }
679
619 /* Form out message */ 680 /* Form out message */
620 snprintf(msg, sizeof(msg), 681 snprintf(msg, sizeof(msg),
621 "(Branch=%d DRAM-Bank=%d RDWR=%s RAS=%d " 682 "(Branch=%d DRAM-Bank=%d RDWR=%s RAS=%d "
622 "CAS=%d, CE Err=0x%x)", branch >> 1, bank, 683 "CAS=%d, CE Err=0x%x (%s))", branch >> 1, bank,
623 rdwr ? "Write" : "Read", ras, cas, ce_errors); 684 rdwr ? "Write" : "Read", ras, cas, ce_errors,
685 specific);
624 686
625 /* Call the helper to output message */ 687 /* Call the helper to output message */
626 edac_mc_handle_fbd_ce(mci, rank, channel, msg); 688 edac_mc_handle_fbd_ce(mci, rank, channel, msg);
627 } 689 }
628 690
629 /* See if any of the thermal errors have fired */ 691 if (!misc_messages)
630 misc_errors = allErrors & FERR_NF_THERMAL; 692 return;
631 if (misc_errors) {
632 i5000_printk(KERN_WARNING, "\tTHERMAL Error, bits= 0x%x\n",
633 misc_errors);
634 }
635
636 /* See if any of the thermal errors have fired */
637 misc_errors = allErrors & FERR_NF_NON_RETRY;
638 if (misc_errors) {
639 i5000_printk(KERN_WARNING, "\tNON-Retry Errors, bits= 0x%x\n",
640 misc_errors);
641 }
642 693
643 /* See if any of the thermal errors have fired */ 694 misc_errors = allErrors & (FERR_NF_NON_RETRY | FERR_NF_NORTH_CRC |
644 misc_errors = allErrors & FERR_NF_NORTH_CRC; 695 FERR_NF_SPD_PROTOCOL | FERR_NF_DIMM_SPARE);
645 if (misc_errors) { 696 if (misc_errors) {
646 i5000_printk(KERN_WARNING, 697 switch (misc_errors) {
647 "\tNORTHBOUND CRC Error, bits= 0x%x\n", 698 case FERR_NF_M13ERR:
648 misc_errors); 699 specific = "Non-Retry or Redundant Retry FBD Memory "
649 } 700 "Alert or Redundant Fast Reset Timeout";
701 break;
702 case FERR_NF_M14ERR:
703 specific = "Non-Retry or Redundant Retry FBD "
704 "Configuration Alert";
705 break;
706 case FERR_NF_M15ERR:
707 specific = "Non-Retry or Redundant Retry FBD "
708 "Northbound CRC error on read data";
709 break;
710 case FERR_NF_M21ERR:
711 specific = "FBD Northbound CRC error on "
712 "FBD Sync Status";
713 break;
714 case FERR_NF_M22ERR:
715 specific = "SPD protocol error";
716 break;
717 case FERR_NF_M27ERR:
718 specific = "DIMM-spare copy started";
719 break;
720 case FERR_NF_M28ERR:
721 specific = "DIMM-spare copy completed";
722 break;
723 }
724 branch = EXTRACT_FBDCHAN_INDX(info->ferr_nf_fbd);
650 725
651 /* See if any of the thermal errors have fired */ 726 /* Form out message */
652 misc_errors = allErrors & FERR_NF_SPD_PROTOCOL; 727 snprintf(msg, sizeof(msg),
653 if (misc_errors) { 728 "(Branch=%d Err=%#x (%s))", branch >> 1,
654 i5000_printk(KERN_WARNING, 729 misc_errors, specific);
655 "\tSPD Protocol Error, bits= 0x%x\n",
656 misc_errors);
657 }
658 730
659 /* See if any of the thermal errors have fired */ 731 /* Call the helper to output message */
660 misc_errors = allErrors & FERR_NF_DIMM_SPARE; 732 edac_mc_handle_fbd_ce(mci, 0, 0, msg);
661 if (misc_errors) {
662 i5000_printk(KERN_WARNING, "\tDIMM-Spare Error, bits= 0x%x\n",
663 misc_errors);
664 } 733 }
665} 734}
666 735
@@ -1497,3 +1566,6 @@ MODULE_DESCRIPTION("MC Driver for Intel I5000 memory controllers - "
1497 1566
1498module_param(edac_op_state, int, 0444); 1567module_param(edac_op_state, int, 0444);
1499MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI"); 1568MODULE_PARM_DESC(edac_op_state, "EDAC Error Reporting state: 0=Poll,1=NMI");
1569module_param(misc_messages, int, 0444);
1570MODULE_PARM_DESC(misc_messages, "Log miscellaneous non fatal messages");
1571
diff --git a/drivers/edac/i82443bxgx_edac.c b/drivers/edac/i82443bxgx_edac.c
index c5305e3ee434..577760a82a0f 100644
--- a/drivers/edac/i82443bxgx_edac.c
+++ b/drivers/edac/i82443bxgx_edac.c
@@ -114,6 +114,12 @@ struct i82443bxgx_edacmc_error_info {
114 114
115static struct edac_pci_ctl_info *i82443bxgx_pci; 115static struct edac_pci_ctl_info *i82443bxgx_pci;
116 116
117static struct pci_dev *mci_pdev; /* init dev: in case that AGP code has
118 * already registered driver
119 */
120
121static int i82443bxgx_registered = 1;
122
117static void i82443bxgx_edacmc_get_error_info(struct mem_ctl_info *mci, 123static void i82443bxgx_edacmc_get_error_info(struct mem_ctl_info *mci,
118 struct i82443bxgx_edacmc_error_info 124 struct i82443bxgx_edacmc_error_info
119 *info) 125 *info)
@@ -345,10 +351,17 @@ EXPORT_SYMBOL_GPL(i82443bxgx_edacmc_probe1);
345static int __devinit i82443bxgx_edacmc_init_one(struct pci_dev *pdev, 351static int __devinit i82443bxgx_edacmc_init_one(struct pci_dev *pdev,
346 const struct pci_device_id *ent) 352 const struct pci_device_id *ent)
347{ 353{
354 int rc;
355
348 debugf0("MC: " __FILE__ ": %s()\n", __func__); 356 debugf0("MC: " __FILE__ ": %s()\n", __func__);
349 357
350 /* don't need to call pci_device_enable() */ 358 /* don't need to call pci_device_enable() */
351 return i82443bxgx_edacmc_probe1(pdev, ent->driver_data); 359 rc = i82443bxgx_edacmc_probe1(pdev, ent->driver_data);
360
361 if (mci_pdev == NULL)
362 mci_pdev = pci_dev_get(pdev);
363
364 return rc;
352} 365}
353 366
354static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev) 367static void __devexit i82443bxgx_edacmc_remove_one(struct pci_dev *pdev)
@@ -387,15 +400,61 @@ static struct pci_driver i82443bxgx_edacmc_driver = {
387 400
388static int __init i82443bxgx_edacmc_init(void) 401static int __init i82443bxgx_edacmc_init(void)
389{ 402{
403 int pci_rc;
390 /* Ensure that the OPSTATE is set correctly for POLL or NMI */ 404 /* Ensure that the OPSTATE is set correctly for POLL or NMI */
391 opstate_init(); 405 opstate_init();
392 406
393 return pci_register_driver(&i82443bxgx_edacmc_driver); 407 pci_rc = pci_register_driver(&i82443bxgx_edacmc_driver);
408 if (pci_rc < 0)
409 goto fail0;
410
411 if (mci_pdev == NULL) {
412 const struct pci_device_id *id = &i82443bxgx_pci_tbl[0];
413 int i = 0;
414 i82443bxgx_registered = 0;
415
416 while (mci_pdev == NULL && id->vendor != 0) {
417 mci_pdev = pci_get_device(id->vendor,
418 id->device, NULL);
419 i++;
420 id = &i82443bxgx_pci_tbl[i];
421 }
422 if (!mci_pdev) {
423 debugf0("i82443bxgx pci_get_device fail\n");
424 pci_rc = -ENODEV;
425 goto fail1;
426 }
427
428 pci_rc = i82443bxgx_edacmc_init_one(mci_pdev, i82443bxgx_pci_tbl);
429
430 if (pci_rc < 0) {
431 debugf0("i82443bxgx init fail\n");
432 pci_rc = -ENODEV;
433 goto fail1;
434 }
435 }
436
437 return 0;
438
439fail1:
440 pci_unregister_driver(&i82443bxgx_edacmc_driver);
441
442fail0:
443 if (mci_pdev != NULL)
444 pci_dev_put(mci_pdev);
445
446 return pci_rc;
394} 447}
395 448
396static void __exit i82443bxgx_edacmc_exit(void) 449static void __exit i82443bxgx_edacmc_exit(void)
397{ 450{
398 pci_unregister_driver(&i82443bxgx_edacmc_driver); 451 pci_unregister_driver(&i82443bxgx_edacmc_driver);
452
453 if (!i82443bxgx_registered)
454 i82443bxgx_edacmc_remove_one(mci_pdev);
455
456 if (mci_pdev)
457 pci_dev_put(mci_pdev);
399} 458}
400 459
401module_init(i82443bxgx_edacmc_init); 460module_init(i82443bxgx_edacmc_init);
diff --git a/drivers/edac/mpc85xx_edac.c b/drivers/edac/mpc85xx_edac.c
index 2265d9ca1535..0cfcb2d075a0 100644
--- a/drivers/edac/mpc85xx_edac.c
+++ b/drivers/edac/mpc85xx_edac.c
@@ -17,6 +17,7 @@
17#include <linux/io.h> 17#include <linux/io.h>
18#include <linux/mod_devicetable.h> 18#include <linux/mod_devicetable.h>
19#include <linux/edac.h> 19#include <linux/edac.h>
20#include <linux/smp.h>
20 21
21#include <linux/of_platform.h> 22#include <linux/of_platform.h>
22#include <linux/of_device.h> 23#include <linux/of_device.h>
@@ -40,7 +41,7 @@ static u32 orig_pci_err_en;
40#endif 41#endif
41 42
42static u32 orig_l2_err_disable; 43static u32 orig_l2_err_disable;
43static u32 orig_hid1; 44static u32 orig_hid1[2];
44 45
45/************************ MC SYSFS parts ***********************************/ 46/************************ MC SYSFS parts ***********************************/
46 47
@@ -647,6 +648,9 @@ static struct of_device_id mpc85xx_l2_err_of_match[] = {
647 { 648 {
648 .compatible = "fsl,8568-l2-cache-controller", 649 .compatible = "fsl,8568-l2-cache-controller",
649 }, 650 },
651 {
652 .compatible = "fsl,mpc8572-l2-cache-controller",
653 },
650 {}, 654 {},
651}; 655};
652 656
@@ -912,7 +916,8 @@ static int __devinit mpc85xx_mc_err_probe(struct of_device *op,
912 /* register interrupts */ 916 /* register interrupts */
913 pdata->irq = irq_of_parse_and_map(op->node, 0); 917 pdata->irq = irq_of_parse_and_map(op->node, 0);
914 res = devm_request_irq(&op->dev, pdata->irq, 918 res = devm_request_irq(&op->dev, pdata->irq,
915 mpc85xx_mc_isr, IRQF_DISABLED, 919 mpc85xx_mc_isr,
920 IRQF_DISABLED | IRQF_SHARED,
916 "[EDAC] MC err", mci); 921 "[EDAC] MC err", mci);
917 if (res < 0) { 922 if (res < 0) {
918 printk(KERN_ERR "%s: Unable to request irq %d for " 923 printk(KERN_ERR "%s: Unable to request irq %d for "
@@ -980,6 +985,9 @@ static struct of_device_id mpc85xx_mc_err_of_match[] = {
980 { 985 {
981 .compatible = "fsl,8568-memory-controller", 986 .compatible = "fsl,8568-memory-controller",
982 }, 987 },
988 {
989 .compatible = "fsl,mpc8572-memory-controller",
990 },
983 {}, 991 {},
984}; 992};
985 993
@@ -995,6 +1003,14 @@ static struct of_platform_driver mpc85xx_mc_err_driver = {
995 }, 1003 },
996}; 1004};
997 1005
1006
1007static void __init mpc85xx_mc_clear_rfxe(void *data)
1008{
1009 orig_hid1[smp_processor_id()] = mfspr(SPRN_HID1);
1010 mtspr(SPRN_HID1, (orig_hid1[smp_processor_id()] & ~0x20000));
1011}
1012
1013
998static int __init mpc85xx_mc_init(void) 1014static int __init mpc85xx_mc_init(void)
999{ 1015{
1000 int res = 0; 1016 int res = 0;
@@ -1030,19 +1046,22 @@ static int __init mpc85xx_mc_init(void)
1030 * need to clear HID1[RFXE] to disable machine check int 1046 * need to clear HID1[RFXE] to disable machine check int
1031 * so we can catch it 1047 * so we can catch it
1032 */ 1048 */
1033 if (edac_op_state == EDAC_OPSTATE_INT) { 1049 if (edac_op_state == EDAC_OPSTATE_INT)
1034 orig_hid1 = mfspr(SPRN_HID1); 1050 on_each_cpu(mpc85xx_mc_clear_rfxe, NULL, 0);
1035 mtspr(SPRN_HID1, (orig_hid1 & ~0x20000));
1036 }
1037 1051
1038 return 0; 1052 return 0;
1039} 1053}
1040 1054
1041module_init(mpc85xx_mc_init); 1055module_init(mpc85xx_mc_init);
1042 1056
1057static void __exit mpc85xx_mc_restore_hid1(void *data)
1058{
1059 mtspr(SPRN_HID1, orig_hid1[smp_processor_id()]);
1060}
1061
1043static void __exit mpc85xx_mc_exit(void) 1062static void __exit mpc85xx_mc_exit(void)
1044{ 1063{
1045 mtspr(SPRN_HID1, orig_hid1); 1064 on_each_cpu(mpc85xx_mc_restore_hid1, NULL, 0);
1046#ifdef CONFIG_PCI 1065#ifdef CONFIG_PCI
1047 of_unregister_platform_driver(&mpc85xx_pci_err_driver); 1066 of_unregister_platform_driver(&mpc85xx_pci_err_driver);
1048#endif 1067#endif
diff --git a/drivers/firewire/fw-card.c b/drivers/firewire/fw-card.c
index bbd73a406e53..418c18f07e9d 100644
--- a/drivers/firewire/fw-card.c
+++ b/drivers/firewire/fw-card.c
@@ -189,39 +189,16 @@ static const char gap_count_table[] = {
189 63, 5, 7, 8, 10, 13, 16, 18, 21, 24, 26, 29, 32, 35, 37, 40 189 63, 5, 7, 8, 10, 13, 16, 18, 21, 24, 26, 29, 32, 35, 37, 40
190}; 190};
191 191
192struct bm_data {
193 struct fw_transaction t;
194 struct {
195 __be32 arg;
196 __be32 data;
197 } lock;
198 u32 old;
199 int rcode;
200 struct completion done;
201};
202
203static void
204complete_bm_lock(struct fw_card *card, int rcode,
205 void *payload, size_t length, void *data)
206{
207 struct bm_data *bmd = data;
208
209 if (rcode == RCODE_COMPLETE)
210 bmd->old = be32_to_cpu(*(__be32 *) payload);
211 bmd->rcode = rcode;
212 complete(&bmd->done);
213}
214
215static void 192static void
216fw_card_bm_work(struct work_struct *work) 193fw_card_bm_work(struct work_struct *work)
217{ 194{
218 struct fw_card *card = container_of(work, struct fw_card, work.work); 195 struct fw_card *card = container_of(work, struct fw_card, work.work);
219 struct fw_device *root_device; 196 struct fw_device *root_device;
220 struct fw_node *root_node, *local_node; 197 struct fw_node *root_node, *local_node;
221 struct bm_data bmd;
222 unsigned long flags; 198 unsigned long flags;
223 int root_id, new_root_id, irm_id, gap_count, generation, grace; 199 int root_id, new_root_id, irm_id, gap_count, generation, grace, rcode;
224 bool do_reset = false; 200 bool do_reset = false;
201 __be32 lock_data[2];
225 202
226 spin_lock_irqsave(&card->lock, flags); 203 spin_lock_irqsave(&card->lock, flags);
227 local_node = card->local_node; 204 local_node = card->local_node;
@@ -263,33 +240,28 @@ fw_card_bm_work(struct work_struct *work)
263 goto pick_me; 240 goto pick_me;
264 } 241 }
265 242
266 bmd.lock.arg = cpu_to_be32(0x3f); 243 lock_data[0] = cpu_to_be32(0x3f);
267 bmd.lock.data = cpu_to_be32(local_node->node_id); 244 lock_data[1] = cpu_to_be32(local_node->node_id);
268 245
269 spin_unlock_irqrestore(&card->lock, flags); 246 spin_unlock_irqrestore(&card->lock, flags);
270 247
271 init_completion(&bmd.done); 248 rcode = fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP,
272 fw_send_request(card, &bmd.t, TCODE_LOCK_COMPARE_SWAP, 249 irm_id, generation, SCODE_100,
273 irm_id, generation, 250 CSR_REGISTER_BASE + CSR_BUS_MANAGER_ID,
274 SCODE_100, CSR_REGISTER_BASE + CSR_BUS_MANAGER_ID, 251 lock_data, sizeof(lock_data));
275 &bmd.lock, sizeof(bmd.lock),
276 complete_bm_lock, &bmd);
277 wait_for_completion(&bmd.done);
278 252
279 if (bmd.rcode == RCODE_GENERATION) { 253 if (rcode == RCODE_GENERATION)
280 /* 254 /* Another bus reset, BM work has been rescheduled. */
281 * Another bus reset happened. Just return,
282 * the BM work has been rescheduled.
283 */
284 goto out; 255 goto out;
285 }
286 256
287 if (bmd.rcode == RCODE_COMPLETE && bmd.old != 0x3f) 257 if (rcode == RCODE_COMPLETE &&
258 lock_data[0] != cpu_to_be32(0x3f))
288 /* Somebody else is BM, let them do the work. */ 259 /* Somebody else is BM, let them do the work. */
289 goto out; 260 goto out;
290 261
291 spin_lock_irqsave(&card->lock, flags); 262 spin_lock_irqsave(&card->lock, flags);
292 if (bmd.rcode != RCODE_COMPLETE) { 263
264 if (rcode != RCODE_COMPLETE) {
293 /* 265 /*
294 * The lock request failed, maybe the IRM 266 * The lock request failed, maybe the IRM
295 * isn't really IRM capable after all. Let's 267 * isn't really IRM capable after all. Let's
diff --git a/drivers/firewire/fw-cdev.c b/drivers/firewire/fw-cdev.c
index 2e6d5848d217..ed03234cbea8 100644
--- a/drivers/firewire/fw-cdev.c
+++ b/drivers/firewire/fw-cdev.c
@@ -720,8 +720,8 @@ static int ioctl_create_iso_context(struct client *client, void *buffer)
720#define GET_PAYLOAD_LENGTH(v) ((v) & 0xffff) 720#define GET_PAYLOAD_LENGTH(v) ((v) & 0xffff)
721#define GET_INTERRUPT(v) (((v) >> 16) & 0x01) 721#define GET_INTERRUPT(v) (((v) >> 16) & 0x01)
722#define GET_SKIP(v) (((v) >> 17) & 0x01) 722#define GET_SKIP(v) (((v) >> 17) & 0x01)
723#define GET_TAG(v) (((v) >> 18) & 0x02) 723#define GET_TAG(v) (((v) >> 18) & 0x03)
724#define GET_SY(v) (((v) >> 20) & 0x04) 724#define GET_SY(v) (((v) >> 20) & 0x0f)
725#define GET_HEADER_LENGTH(v) (((v) >> 24) & 0xff) 725#define GET_HEADER_LENGTH(v) (((v) >> 24) & 0xff)
726 726
727static int ioctl_queue_iso(struct client *client, void *buffer) 727static int ioctl_queue_iso(struct client *client, void *buffer)
@@ -913,7 +913,7 @@ dispatch_ioctl(struct client *client, unsigned int cmd, void __user *arg)
913 return -EFAULT; 913 return -EFAULT;
914 } 914 }
915 915
916 return 0; 916 return retval;
917} 917}
918 918
919static long 919static long
diff --git a/drivers/firewire/fw-device.c b/drivers/firewire/fw-device.c
index 0855fb5568e8..3fccdd484100 100644
--- a/drivers/firewire/fw-device.c
+++ b/drivers/firewire/fw-device.c
@@ -381,46 +381,21 @@ static struct device_attribute fw_device_attributes[] = {
381 __ATTR_NULL, 381 __ATTR_NULL,
382}; 382};
383 383
384struct read_quadlet_callback_data {
385 struct completion done;
386 int rcode;
387 u32 data;
388};
389
390static void
391complete_transaction(struct fw_card *card, int rcode,
392 void *payload, size_t length, void *data)
393{
394 struct read_quadlet_callback_data *callback_data = data;
395
396 if (rcode == RCODE_COMPLETE)
397 callback_data->data = be32_to_cpu(*(__be32 *)payload);
398 callback_data->rcode = rcode;
399 complete(&callback_data->done);
400}
401
402static int 384static int
403read_rom(struct fw_device *device, int generation, int index, u32 *data) 385read_rom(struct fw_device *device, int generation, int index, u32 *data)
404{ 386{
405 struct read_quadlet_callback_data callback_data; 387 int rcode;
406 struct fw_transaction t;
407 u64 offset;
408 388
409 /* device->node_id, accessed below, must not be older than generation */ 389 /* device->node_id, accessed below, must not be older than generation */
410 smp_rmb(); 390 smp_rmb();
411 391
412 init_completion(&callback_data.done); 392 rcode = fw_run_transaction(device->card, TCODE_READ_QUADLET_REQUEST,
413
414 offset = (CSR_REGISTER_BASE | CSR_CONFIG_ROM) + index * 4;
415 fw_send_request(device->card, &t, TCODE_READ_QUADLET_REQUEST,
416 device->node_id, generation, device->max_speed, 393 device->node_id, generation, device->max_speed,
417 offset, NULL, 4, complete_transaction, &callback_data); 394 (CSR_REGISTER_BASE | CSR_CONFIG_ROM) + index * 4,
418 395 data, 4);
419 wait_for_completion(&callback_data.done); 396 be32_to_cpus(data);
420
421 *data = callback_data.data;
422 397
423 return callback_data.rcode; 398 return rcode;
424} 399}
425 400
426#define READ_BIB_ROM_SIZE 256 401#define READ_BIB_ROM_SIZE 256
diff --git a/drivers/firewire/fw-sbp2.c b/drivers/firewire/fw-sbp2.c
index aaff50ebba1d..ef0b9b419c27 100644
--- a/drivers/firewire/fw-sbp2.c
+++ b/drivers/firewire/fw-sbp2.c
@@ -29,6 +29,7 @@
29 */ 29 */
30 30
31#include <linux/blkdev.h> 31#include <linux/blkdev.h>
32#include <linux/bug.h>
32#include <linux/delay.h> 33#include <linux/delay.h>
33#include <linux/device.h> 34#include <linux/device.h>
34#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
@@ -181,10 +182,16 @@ struct sbp2_target {
181#define SBP2_MAX_LOGIN_ORB_TIMEOUT 40000U /* Timeout in ms */ 182#define SBP2_MAX_LOGIN_ORB_TIMEOUT 40000U /* Timeout in ms */
182#define SBP2_ORB_TIMEOUT 2000U /* Timeout in ms */ 183#define SBP2_ORB_TIMEOUT 2000U /* Timeout in ms */
183#define SBP2_ORB_NULL 0x80000000 184#define SBP2_ORB_NULL 0x80000000
184#define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000
185#define SBP2_RETRY_LIMIT 0xf /* 15 retries */ 185#define SBP2_RETRY_LIMIT 0xf /* 15 retries */
186#define SBP2_CYCLE_LIMIT (0xc8 << 12) /* 200 125us cycles */ 186#define SBP2_CYCLE_LIMIT (0xc8 << 12) /* 200 125us cycles */
187 187
188/*
189 * The default maximum s/g segment size of a FireWire controller is
190 * usually 0x10000, but SBP-2 only allows 0xffff. Since buffers have to
191 * be quadlet-aligned, we set the length limit to 0xffff & ~3.
192 */
193#define SBP2_MAX_SEG_SIZE 0xfffc
194
188/* Unit directory keys */ 195/* Unit directory keys */
189#define SBP2_CSR_UNIT_CHARACTERISTICS 0x3a 196#define SBP2_CSR_UNIT_CHARACTERISTICS 0x3a
190#define SBP2_CSR_FIRMWARE_REVISION 0x3c 197#define SBP2_CSR_FIRMWARE_REVISION 0x3c
@@ -621,25 +628,15 @@ sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id,
621 return retval; 628 return retval;
622} 629}
623 630
624static void
625complete_agent_reset_write(struct fw_card *card, int rcode,
626 void *payload, size_t length, void *done)
627{
628 complete(done);
629}
630
631static void sbp2_agent_reset(struct sbp2_logical_unit *lu) 631static void sbp2_agent_reset(struct sbp2_logical_unit *lu)
632{ 632{
633 struct fw_device *device = fw_device(lu->tgt->unit->device.parent); 633 struct fw_device *device = fw_device(lu->tgt->unit->device.parent);
634 DECLARE_COMPLETION_ONSTACK(done); 634 __be32 d = 0;
635 struct fw_transaction t;
636 static u32 z;
637 635
638 fw_send_request(device->card, &t, TCODE_WRITE_QUADLET_REQUEST, 636 fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST,
639 lu->tgt->node_id, lu->generation, device->max_speed, 637 lu->tgt->node_id, lu->generation, device->max_speed,
640 lu->command_block_agent_address + SBP2_AGENT_RESET, 638 lu->command_block_agent_address + SBP2_AGENT_RESET,
641 &z, sizeof(z), complete_agent_reset_write, &done); 639 &d, sizeof(d));
642 wait_for_completion(&done);
643} 640}
644 641
645static void 642static void
@@ -653,7 +650,7 @@ static void sbp2_agent_reset_no_wait(struct sbp2_logical_unit *lu)
653{ 650{
654 struct fw_device *device = fw_device(lu->tgt->unit->device.parent); 651 struct fw_device *device = fw_device(lu->tgt->unit->device.parent);
655 struct fw_transaction *t; 652 struct fw_transaction *t;
656 static u32 z; 653 static __be32 d;
657 654
658 t = kmalloc(sizeof(*t), GFP_ATOMIC); 655 t = kmalloc(sizeof(*t), GFP_ATOMIC);
659 if (t == NULL) 656 if (t == NULL)
@@ -662,7 +659,7 @@ static void sbp2_agent_reset_no_wait(struct sbp2_logical_unit *lu)
662 fw_send_request(device->card, t, TCODE_WRITE_QUADLET_REQUEST, 659 fw_send_request(device->card, t, TCODE_WRITE_QUADLET_REQUEST,
663 lu->tgt->node_id, lu->generation, device->max_speed, 660 lu->tgt->node_id, lu->generation, device->max_speed,
664 lu->command_block_agent_address + SBP2_AGENT_RESET, 661 lu->command_block_agent_address + SBP2_AGENT_RESET,
665 &z, sizeof(z), complete_agent_reset_write_no_wait, t); 662 &d, sizeof(d), complete_agent_reset_write_no_wait, t);
666} 663}
667 664
668static void sbp2_set_generation(struct sbp2_logical_unit *lu, int generation) 665static void sbp2_set_generation(struct sbp2_logical_unit *lu, int generation)
@@ -823,13 +820,6 @@ static void sbp2_target_put(struct sbp2_target *tgt)
823 kref_put(&tgt->kref, sbp2_release_target); 820 kref_put(&tgt->kref, sbp2_release_target);
824} 821}
825 822
826static void
827complete_set_busy_timeout(struct fw_card *card, int rcode,
828 void *payload, size_t length, void *done)
829{
830 complete(done);
831}
832
833/* 823/*
834 * Write retransmit retry values into the BUSY_TIMEOUT register. 824 * Write retransmit retry values into the BUSY_TIMEOUT register.
835 * - The single-phase retry protocol is supported by all SBP-2 devices, but the 825 * - The single-phase retry protocol is supported by all SBP-2 devices, but the
@@ -849,17 +839,12 @@ complete_set_busy_timeout(struct fw_card *card, int rcode,
849static void sbp2_set_busy_timeout(struct sbp2_logical_unit *lu) 839static void sbp2_set_busy_timeout(struct sbp2_logical_unit *lu)
850{ 840{
851 struct fw_device *device = fw_device(lu->tgt->unit->device.parent); 841 struct fw_device *device = fw_device(lu->tgt->unit->device.parent);
852 DECLARE_COMPLETION_ONSTACK(done); 842 __be32 d = cpu_to_be32(SBP2_CYCLE_LIMIT | SBP2_RETRY_LIMIT);
853 struct fw_transaction t;
854 static __be32 busy_timeout;
855
856 busy_timeout = cpu_to_be32(SBP2_CYCLE_LIMIT | SBP2_RETRY_LIMIT);
857 843
858 fw_send_request(device->card, &t, TCODE_WRITE_QUADLET_REQUEST, 844 fw_run_transaction(device->card, TCODE_WRITE_QUADLET_REQUEST,
859 lu->tgt->node_id, lu->generation, device->max_speed, 845 lu->tgt->node_id, lu->generation, device->max_speed,
860 CSR_REGISTER_BASE + CSR_BUSY_TIMEOUT, &busy_timeout, 846 CSR_REGISTER_BASE + CSR_BUSY_TIMEOUT,
861 sizeof(busy_timeout), complete_set_busy_timeout, &done); 847 &d, sizeof(d));
862 wait_for_completion(&done);
863} 848}
864 849
865static void sbp2_reconnect(struct work_struct *work); 850static void sbp2_reconnect(struct work_struct *work);
@@ -1121,6 +1106,10 @@ static int sbp2_probe(struct device *dev)
1121 struct Scsi_Host *shost; 1106 struct Scsi_Host *shost;
1122 u32 model, firmware_revision; 1107 u32 model, firmware_revision;
1123 1108
1109 if (dma_get_max_seg_size(device->card->device) > SBP2_MAX_SEG_SIZE)
1110 BUG_ON(dma_set_max_seg_size(device->card->device,
1111 SBP2_MAX_SEG_SIZE));
1112
1124 shost = scsi_host_alloc(&scsi_driver_template, sizeof(*tgt)); 1113 shost = scsi_host_alloc(&scsi_driver_template, sizeof(*tgt));
1125 if (shost == NULL) 1114 if (shost == NULL)
1126 return -ENOMEM; 1115 return -ENOMEM;
@@ -1369,14 +1358,12 @@ static int
1369sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device, 1358sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device,
1370 struct sbp2_logical_unit *lu) 1359 struct sbp2_logical_unit *lu)
1371{ 1360{
1372 struct scatterlist *sg; 1361 struct scatterlist *sg = scsi_sglist(orb->cmd);
1373 int sg_len, l, i, j, count; 1362 int i, n;
1374 dma_addr_t sg_addr; 1363
1375 1364 n = dma_map_sg(device->card->device, sg, scsi_sg_count(orb->cmd),
1376 sg = scsi_sglist(orb->cmd); 1365 orb->cmd->sc_data_direction);
1377 count = dma_map_sg(device->card->device, sg, scsi_sg_count(orb->cmd), 1366 if (n == 0)
1378 orb->cmd->sc_data_direction);
1379 if (count == 0)
1380 goto fail; 1367 goto fail;
1381 1368
1382 /* 1369 /*
@@ -1386,7 +1373,7 @@ sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device,
1386 * as the second generation iPod which doesn't support page 1373 * as the second generation iPod which doesn't support page
1387 * tables. 1374 * tables.
1388 */ 1375 */
1389 if (count == 1 && sg_dma_len(sg) < SBP2_MAX_SG_ELEMENT_LENGTH) { 1376 if (n == 1) {
1390 orb->request.data_descriptor.high = 1377 orb->request.data_descriptor.high =
1391 cpu_to_be32(lu->tgt->address_high); 1378 cpu_to_be32(lu->tgt->address_high);
1392 orb->request.data_descriptor.low = 1379 orb->request.data_descriptor.low =
@@ -1396,29 +1383,9 @@ sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device,
1396 return 0; 1383 return 0;
1397 } 1384 }
1398 1385
1399 /* 1386 for_each_sg(sg, sg, n, i) {
1400 * Convert the scatterlist to an sbp2 page table. If any 1387 orb->page_table[i].high = cpu_to_be32(sg_dma_len(sg) << 16);
1401 * scatterlist entries are too big for sbp2, we split them as we 1388 orb->page_table[i].low = cpu_to_be32(sg_dma_address(sg));
1402 * go. Even if we ask the block I/O layer to not give us sg
1403 * elements larger than 65535 bytes, some IOMMUs may merge sg elements
1404 * during DMA mapping, and Linux currently doesn't prevent this.
1405 */
1406 for (i = 0, j = 0; i < count; i++, sg = sg_next(sg)) {
1407 sg_len = sg_dma_len(sg);
1408 sg_addr = sg_dma_address(sg);
1409 while (sg_len) {
1410 /* FIXME: This won't get us out of the pinch. */
1411 if (unlikely(j >= ARRAY_SIZE(orb->page_table))) {
1412 fw_error("page table overflow\n");
1413 goto fail_page_table;
1414 }
1415 l = min(sg_len, SBP2_MAX_SG_ELEMENT_LENGTH);
1416 orb->page_table[j].low = cpu_to_be32(sg_addr);
1417 orb->page_table[j].high = cpu_to_be32(l << 16);
1418 sg_addr += l;
1419 sg_len -= l;
1420 j++;
1421 }
1422 } 1389 }
1423 1390
1424 orb->page_table_bus = 1391 orb->page_table_bus =
@@ -1437,13 +1404,13 @@ sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device,
1437 orb->request.data_descriptor.high = cpu_to_be32(lu->tgt->address_high); 1404 orb->request.data_descriptor.high = cpu_to_be32(lu->tgt->address_high);
1438 orb->request.data_descriptor.low = cpu_to_be32(orb->page_table_bus); 1405 orb->request.data_descriptor.low = cpu_to_be32(orb->page_table_bus);
1439 orb->request.misc |= cpu_to_be32(COMMAND_ORB_PAGE_TABLE_PRESENT | 1406 orb->request.misc |= cpu_to_be32(COMMAND_ORB_PAGE_TABLE_PRESENT |
1440 COMMAND_ORB_DATA_SIZE(j)); 1407 COMMAND_ORB_DATA_SIZE(n));
1441 1408
1442 return 0; 1409 return 0;
1443 1410
1444 fail_page_table: 1411 fail_page_table:
1445 dma_unmap_sg(device->card->device, sg, scsi_sg_count(orb->cmd), 1412 dma_unmap_sg(device->card->device, scsi_sglist(orb->cmd),
1446 orb->cmd->sc_data_direction); 1413 scsi_sg_count(orb->cmd), orb->cmd->sc_data_direction);
1447 fail: 1414 fail:
1448 return -ENOMEM; 1415 return -ENOMEM;
1449} 1416}
@@ -1456,7 +1423,7 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1456 struct fw_device *device = fw_device(lu->tgt->unit->device.parent); 1423 struct fw_device *device = fw_device(lu->tgt->unit->device.parent);
1457 struct sbp2_command_orb *orb; 1424 struct sbp2_command_orb *orb;
1458 unsigned int max_payload; 1425 unsigned int max_payload;
1459 int retval = SCSI_MLQUEUE_HOST_BUSY; 1426 int generation, retval = SCSI_MLQUEUE_HOST_BUSY;
1460 1427
1461 /* 1428 /*
1462 * Bidirectional commands are not yet implemented, and unknown 1429 * Bidirectional commands are not yet implemented, and unknown
@@ -1500,6 +1467,9 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1500 if (cmd->sc_data_direction == DMA_FROM_DEVICE) 1467 if (cmd->sc_data_direction == DMA_FROM_DEVICE)
1501 orb->request.misc |= cpu_to_be32(COMMAND_ORB_DIRECTION); 1468 orb->request.misc |= cpu_to_be32(COMMAND_ORB_DIRECTION);
1502 1469
1470 generation = device->generation;
1471 smp_rmb(); /* sbp2_map_scatterlist looks at tgt->address_high */
1472
1503 if (scsi_sg_count(cmd) && sbp2_map_scatterlist(orb, device, lu) < 0) 1473 if (scsi_sg_count(cmd) && sbp2_map_scatterlist(orb, device, lu) < 0)
1504 goto out; 1474 goto out;
1505 1475
@@ -1512,7 +1482,7 @@ static int sbp2_scsi_queuecommand(struct scsi_cmnd *cmd, scsi_done_fn_t done)
1512 if (dma_mapping_error(device->card->device, orb->base.request_bus)) 1482 if (dma_mapping_error(device->card->device, orb->base.request_bus))
1513 goto out; 1483 goto out;
1514 1484
1515 sbp2_send_orb(&orb->base, lu, lu->tgt->node_id, lu->generation, 1485 sbp2_send_orb(&orb->base, lu, lu->tgt->node_id, generation,
1516 lu->command_block_agent_address + SBP2_ORB_POINTER); 1486 lu->command_block_agent_address + SBP2_ORB_POINTER);
1517 retval = 0; 1487 retval = 0;
1518 out: 1488 out:
@@ -1564,6 +1534,8 @@ static int sbp2_scsi_slave_configure(struct scsi_device *sdev)
1564 if (lu->tgt->workarounds & SBP2_WORKAROUND_128K_MAX_TRANS) 1534 if (lu->tgt->workarounds & SBP2_WORKAROUND_128K_MAX_TRANS)
1565 blk_queue_max_sectors(sdev->request_queue, 128 * 1024 / 512); 1535 blk_queue_max_sectors(sdev->request_queue, 128 * 1024 / 512);
1566 1536
1537 blk_queue_max_segment_size(sdev->request_queue, SBP2_MAX_SEG_SIZE);
1538
1567 return 0; 1539 return 0;
1568} 1540}
1569 1541
diff --git a/drivers/firewire/fw-transaction.c b/drivers/firewire/fw-transaction.c
index e5d1a0b64fcf..022ac4fabb67 100644
--- a/drivers/firewire/fw-transaction.c
+++ b/drivers/firewire/fw-transaction.c
@@ -247,7 +247,7 @@ fw_fill_request(struct fw_packet *packet, int tcode, int tlabel,
247 */ 247 */
248void 248void
249fw_send_request(struct fw_card *card, struct fw_transaction *t, 249fw_send_request(struct fw_card *card, struct fw_transaction *t,
250 int tcode, int node_id, int generation, int speed, 250 int tcode, int destination_id, int generation, int speed,
251 unsigned long long offset, 251 unsigned long long offset,
252 void *payload, size_t length, 252 void *payload, size_t length,
253 fw_transaction_callback_t callback, void *callback_data) 253 fw_transaction_callback_t callback, void *callback_data)
@@ -279,13 +279,14 @@ fw_send_request(struct fw_card *card, struct fw_transaction *t,
279 card->current_tlabel = (card->current_tlabel + 1) & 0x1f; 279 card->current_tlabel = (card->current_tlabel + 1) & 0x1f;
280 card->tlabel_mask |= (1 << tlabel); 280 card->tlabel_mask |= (1 << tlabel);
281 281
282 t->node_id = node_id; 282 t->node_id = destination_id;
283 t->tlabel = tlabel; 283 t->tlabel = tlabel;
284 t->callback = callback; 284 t->callback = callback;
285 t->callback_data = callback_data; 285 t->callback_data = callback_data;
286 286
287 fw_fill_request(&t->packet, tcode, t->tlabel, node_id, card->node_id, 287 fw_fill_request(&t->packet, tcode, t->tlabel,
288 generation, speed, offset, payload, length); 288 destination_id, card->node_id, generation,
289 speed, offset, payload, length);
289 t->packet.callback = transmit_complete_callback; 290 t->packet.callback = transmit_complete_callback;
290 291
291 list_add_tail(&t->link, &card->transaction_list); 292 list_add_tail(&t->link, &card->transaction_list);
@@ -296,6 +297,45 @@ fw_send_request(struct fw_card *card, struct fw_transaction *t,
296} 297}
297EXPORT_SYMBOL(fw_send_request); 298EXPORT_SYMBOL(fw_send_request);
298 299
300struct transaction_callback_data {
301 struct completion done;
302 void *payload;
303 int rcode;
304};
305
306static void transaction_callback(struct fw_card *card, int rcode,
307 void *payload, size_t length, void *data)
308{
309 struct transaction_callback_data *d = data;
310
311 if (rcode == RCODE_COMPLETE)
312 memcpy(d->payload, payload, length);
313 d->rcode = rcode;
314 complete(&d->done);
315}
316
317/**
318 * fw_run_transaction - send request and sleep until transaction is completed
319 *
320 * Returns the RCODE.
321 */
322int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
323 int generation, int speed, unsigned long long offset,
324 void *data, size_t length)
325{
326 struct transaction_callback_data d;
327 struct fw_transaction t;
328
329 init_completion(&d.done);
330 d.payload = data;
331 fw_send_request(card, &t, tcode, destination_id, generation, speed,
332 offset, data, length, transaction_callback, &d);
333 wait_for_completion(&d.done);
334
335 return d.rcode;
336}
337EXPORT_SYMBOL(fw_run_transaction);
338
299static DEFINE_MUTEX(phy_config_mutex); 339static DEFINE_MUTEX(phy_config_mutex);
300static DECLARE_COMPLETION(phy_config_done); 340static DECLARE_COMPLETION(phy_config_done);
301 341
diff --git a/drivers/firewire/fw-transaction.h b/drivers/firewire/fw-transaction.h
index 2ae1b0d6cb7b..027f58ce81ad 100644
--- a/drivers/firewire/fw-transaction.h
+++ b/drivers/firewire/fw-transaction.h
@@ -426,11 +426,14 @@ fw_core_initiate_bus_reset(struct fw_card *card, int short_reset);
426 426
427void 427void
428fw_send_request(struct fw_card *card, struct fw_transaction *t, 428fw_send_request(struct fw_card *card, struct fw_transaction *t,
429 int tcode, int node_id, int generation, int speed, 429 int tcode, int destination_id, int generation, int speed,
430 unsigned long long offset, 430 unsigned long long offset, void *data, size_t length,
431 void *data, size_t length,
432 fw_transaction_callback_t callback, void *callback_data); 431 fw_transaction_callback_t callback, void *callback_data);
433 432
433int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
434 int generation, int speed, unsigned long long offset,
435 void *data, size_t length);
436
434int fw_cancel_transaction(struct fw_card *card, 437int fw_cancel_transaction(struct fw_card *card,
435 struct fw_transaction *transaction); 438 struct fw_transaction *transaction);
436 439
diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
index 455575be3560..3e526b6d00cb 100644
--- a/drivers/firmware/dmi_scan.c
+++ b/drivers/firmware/dmi_scan.c
@@ -15,6 +15,11 @@
15 */ 15 */
16static char dmi_empty_string[] = " "; 16static char dmi_empty_string[] = " ";
17 17
18/*
19 * Catch too early calls to dmi_check_system():
20 */
21static int dmi_initialized;
22
18static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s) 23static const char * __init dmi_string_nosave(const struct dmi_header *dm, u8 s)
19{ 24{
20 const u8 *bp = ((u8 *) dm) + dm->length; 25 const u8 *bp = ((u8 *) dm) + dm->length;
@@ -366,7 +371,7 @@ void __init dmi_scan_machine(void)
366 371
367 if (efi_enabled) { 372 if (efi_enabled) {
368 if (efi.smbios == EFI_INVALID_TABLE_ADDR) 373 if (efi.smbios == EFI_INVALID_TABLE_ADDR)
369 goto out; 374 goto error;
370 375
371 /* This is called as a core_initcall() because it isn't 376 /* This is called as a core_initcall() because it isn't
372 * needed during early boot. This also means we can 377 * needed during early boot. This also means we can
@@ -374,13 +379,13 @@ void __init dmi_scan_machine(void)
374 */ 379 */
375 p = dmi_ioremap(efi.smbios, 32); 380 p = dmi_ioremap(efi.smbios, 32);
376 if (p == NULL) 381 if (p == NULL)
377 goto out; 382 goto error;
378 383
379 rc = dmi_present(p + 0x10); /* offset of _DMI_ string */ 384 rc = dmi_present(p + 0x10); /* offset of _DMI_ string */
380 dmi_iounmap(p, 32); 385 dmi_iounmap(p, 32);
381 if (!rc) { 386 if (!rc) {
382 dmi_available = 1; 387 dmi_available = 1;
383 return; 388 goto out;
384 } 389 }
385 } 390 }
386 else { 391 else {
@@ -391,19 +396,22 @@ void __init dmi_scan_machine(void)
391 */ 396 */
392 p = dmi_ioremap(0xF0000, 0x10000); 397 p = dmi_ioremap(0xF0000, 0x10000);
393 if (p == NULL) 398 if (p == NULL)
394 goto out; 399 goto error;
395 400
396 for (q = p; q < p + 0x10000; q += 16) { 401 for (q = p; q < p + 0x10000; q += 16) {
397 rc = dmi_present(q); 402 rc = dmi_present(q);
398 if (!rc) { 403 if (!rc) {
399 dmi_available = 1; 404 dmi_available = 1;
400 dmi_iounmap(p, 0x10000); 405 dmi_iounmap(p, 0x10000);
401 return; 406 goto out;
402 } 407 }
403 } 408 }
404 dmi_iounmap(p, 0x10000); 409 dmi_iounmap(p, 0x10000);
405 } 410 }
406 out: printk(KERN_INFO "DMI not present or invalid.\n"); 411 error:
412 printk(KERN_INFO "DMI not present or invalid.\n");
413 out:
414 dmi_initialized = 1;
407} 415}
408 416
409/** 417/**
@@ -424,6 +432,8 @@ int dmi_check_system(const struct dmi_system_id *list)
424 int i, count = 0; 432 int i, count = 0;
425 const struct dmi_system_id *d = list; 433 const struct dmi_system_id *d = list;
426 434
435 WARN(!dmi_initialized, KERN_ERR "dmi check: not initialized yet.\n");
436
427 while (d->ident) { 437 while (d->ident) {
428 for (i = 0; i < ARRAY_SIZE(d->matches); i++) { 438 for (i = 0; i < ARRAY_SIZE(d->matches); i++) {
429 int s = d->matches[i].slot; 439 int s = d->matches[i].slot;
diff --git a/drivers/firmware/iscsi_ibft.c b/drivers/firmware/iscsi_ibft.c
index b91ef63126ed..deb154aa47c4 100644
--- a/drivers/firmware/iscsi_ibft.c
+++ b/drivers/firmware/iscsi_ibft.c
@@ -334,9 +334,9 @@ static void ibft_release(struct kobject *kobj)
334/* 334/*
335 * Routines for parsing the iBFT data to be human readable. 335 * Routines for parsing the iBFT data to be human readable.
336 */ 336 */
337ssize_t ibft_attr_show_initiator(struct ibft_kobject *entry, 337static ssize_t ibft_attr_show_initiator(struct ibft_kobject *entry,
338 struct ibft_attribute *attr, 338 struct ibft_attribute *attr,
339 char *buf) 339 char *buf)
340{ 340{
341 struct ibft_initiator *initiator = entry->initiator; 341 struct ibft_initiator *initiator = entry->initiator;
342 void *ibft_loc = entry->header; 342 void *ibft_loc = entry->header;
@@ -376,9 +376,9 @@ ssize_t ibft_attr_show_initiator(struct ibft_kobject *entry,
376 return str - buf; 376 return str - buf;
377} 377}
378 378
379ssize_t ibft_attr_show_nic(struct ibft_kobject *entry, 379static ssize_t ibft_attr_show_nic(struct ibft_kobject *entry,
380 struct ibft_attribute *attr, 380 struct ibft_attribute *attr,
381 char *buf) 381 char *buf)
382{ 382{
383 struct ibft_nic *nic = entry->nic; 383 struct ibft_nic *nic = entry->nic;
384 void *ibft_loc = entry->header; 384 void *ibft_loc = entry->header;
@@ -440,9 +440,9 @@ ssize_t ibft_attr_show_nic(struct ibft_kobject *entry,
440 return str - buf; 440 return str - buf;
441}; 441};
442 442
443ssize_t ibft_attr_show_target(struct ibft_kobject *entry, 443static ssize_t ibft_attr_show_target(struct ibft_kobject *entry,
444 struct ibft_attribute *attr, 444 struct ibft_attribute *attr,
445 char *buf) 445 char *buf)
446{ 446{
447 struct ibft_tgt *tgt = entry->tgt; 447 struct ibft_tgt *tgt = entry->tgt;
448 void *ibft_loc = entry->header; 448 void *ibft_loc = entry->header;
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 8d2940517c99..9112830107a5 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -67,17 +67,28 @@ static inline void desc_set_label(struct gpio_desc *d, const char *label)
67 * when setting direction, and otherwise illegal. Until board setup code 67 * when setting direction, and otherwise illegal. Until board setup code
68 * and drivers use explicit requests everywhere (which won't happen when 68 * and drivers use explicit requests everywhere (which won't happen when
69 * those calls have no teeth) we can't avoid autorequesting. This nag 69 * those calls have no teeth) we can't avoid autorequesting. This nag
70 * message should motivate switching to explicit requests... 70 * message should motivate switching to explicit requests... so should
71 * the weaker cleanup after faults, compared to gpio_request().
71 */ 72 */
72static void gpio_ensure_requested(struct gpio_desc *desc) 73static int gpio_ensure_requested(struct gpio_desc *desc, unsigned offset)
73{ 74{
74 if (test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0) { 75 if (test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0) {
75 pr_warning("GPIO-%d autorequested\n", (int)(desc - gpio_desc)); 76 struct gpio_chip *chip = desc->chip;
77 int gpio = chip->base + offset;
78
79 if (!try_module_get(chip->owner)) {
80 pr_err("GPIO-%d: module can't be gotten \n", gpio);
81 clear_bit(FLAG_REQUESTED, &desc->flags);
82 /* lose */
83 return -EIO;
84 }
85 pr_warning("GPIO-%d autorequested\n", gpio);
76 desc_set_label(desc, "[auto]"); 86 desc_set_label(desc, "[auto]");
77 if (!try_module_get(desc->chip->owner)) 87 /* caller must chip->request() w/o spinlock */
78 pr_err("GPIO-%d: module can't be gotten \n", 88 if (chip->request)
79 (int)(desc - gpio_desc)); 89 return 1;
80 } 90 }
91 return 0;
81} 92}
82 93
83/* caller holds gpio_lock *OR* gpio is marked as requested */ 94/* caller holds gpio_lock *OR* gpio is marked as requested */
@@ -752,6 +763,7 @@ EXPORT_SYMBOL_GPL(gpiochip_remove);
752int gpio_request(unsigned gpio, const char *label) 763int gpio_request(unsigned gpio, const char *label)
753{ 764{
754 struct gpio_desc *desc; 765 struct gpio_desc *desc;
766 struct gpio_chip *chip;
755 int status = -EINVAL; 767 int status = -EINVAL;
756 unsigned long flags; 768 unsigned long flags;
757 769
@@ -760,14 +772,15 @@ int gpio_request(unsigned gpio, const char *label)
760 if (!gpio_is_valid(gpio)) 772 if (!gpio_is_valid(gpio))
761 goto done; 773 goto done;
762 desc = &gpio_desc[gpio]; 774 desc = &gpio_desc[gpio];
763 if (desc->chip == NULL) 775 chip = desc->chip;
776 if (chip == NULL)
764 goto done; 777 goto done;
765 778
766 if (!try_module_get(desc->chip->owner)) 779 if (!try_module_get(chip->owner))
767 goto done; 780 goto done;
768 781
769 /* NOTE: gpio_request() can be called in early boot, 782 /* NOTE: gpio_request() can be called in early boot,
770 * before IRQs are enabled. 783 * before IRQs are enabled, for non-sleeping (SOC) GPIOs.
771 */ 784 */
772 785
773 if (test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0) { 786 if (test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0) {
@@ -775,7 +788,20 @@ int gpio_request(unsigned gpio, const char *label)
775 status = 0; 788 status = 0;
776 } else { 789 } else {
777 status = -EBUSY; 790 status = -EBUSY;
778 module_put(desc->chip->owner); 791 module_put(chip->owner);
792 }
793
794 if (chip->request) {
795 /* chip->request may sleep */
796 spin_unlock_irqrestore(&gpio_lock, flags);
797 status = chip->request(chip, gpio - chip->base);
798 spin_lock_irqsave(&gpio_lock, flags);
799
800 if (status < 0) {
801 desc_set_label(desc, NULL);
802 module_put(chip->owner);
803 clear_bit(FLAG_REQUESTED, &desc->flags);
804 }
779 } 805 }
780 806
781done: 807done:
@@ -791,6 +817,9 @@ void gpio_free(unsigned gpio)
791{ 817{
792 unsigned long flags; 818 unsigned long flags;
793 struct gpio_desc *desc; 819 struct gpio_desc *desc;
820 struct gpio_chip *chip;
821
822 might_sleep();
794 823
795 if (!gpio_is_valid(gpio)) { 824 if (!gpio_is_valid(gpio)) {
796 WARN_ON(extra_checks); 825 WARN_ON(extra_checks);
@@ -802,9 +831,17 @@ void gpio_free(unsigned gpio)
802 spin_lock_irqsave(&gpio_lock, flags); 831 spin_lock_irqsave(&gpio_lock, flags);
803 832
804 desc = &gpio_desc[gpio]; 833 desc = &gpio_desc[gpio];
805 if (desc->chip && test_and_clear_bit(FLAG_REQUESTED, &desc->flags)) { 834 chip = desc->chip;
835 if (chip && test_bit(FLAG_REQUESTED, &desc->flags)) {
836 if (chip->free) {
837 spin_unlock_irqrestore(&gpio_lock, flags);
838 might_sleep_if(extra_checks && chip->can_sleep);
839 chip->free(chip, gpio - chip->base);
840 spin_lock_irqsave(&gpio_lock, flags);
841 }
806 desc_set_label(desc, NULL); 842 desc_set_label(desc, NULL);
807 module_put(desc->chip->owner); 843 module_put(desc->chip->owner);
844 clear_bit(FLAG_REQUESTED, &desc->flags);
808 } else 845 } else
809 WARN_ON(extra_checks); 846 WARN_ON(extra_checks);
810 847
@@ -869,7 +906,9 @@ int gpio_direction_input(unsigned gpio)
869 gpio -= chip->base; 906 gpio -= chip->base;
870 if (gpio >= chip->ngpio) 907 if (gpio >= chip->ngpio)
871 goto fail; 908 goto fail;
872 gpio_ensure_requested(desc); 909 status = gpio_ensure_requested(desc, gpio);
910 if (status < 0)
911 goto fail;
873 912
874 /* now we know the gpio is valid and chip won't vanish */ 913 /* now we know the gpio is valid and chip won't vanish */
875 914
@@ -877,9 +916,22 @@ int gpio_direction_input(unsigned gpio)
877 916
878 might_sleep_if(extra_checks && chip->can_sleep); 917 might_sleep_if(extra_checks && chip->can_sleep);
879 918
919 if (status) {
920 status = chip->request(chip, gpio);
921 if (status < 0) {
922 pr_debug("GPIO-%d: chip request fail, %d\n",
923 chip->base + gpio, status);
924 /* and it's not available to anyone else ...
925 * gpio_request() is the fully clean solution.
926 */
927 goto lose;
928 }
929 }
930
880 status = chip->direction_input(chip, gpio); 931 status = chip->direction_input(chip, gpio);
881 if (status == 0) 932 if (status == 0)
882 clear_bit(FLAG_IS_OUT, &desc->flags); 933 clear_bit(FLAG_IS_OUT, &desc->flags);
934lose:
883 return status; 935 return status;
884fail: 936fail:
885 spin_unlock_irqrestore(&gpio_lock, flags); 937 spin_unlock_irqrestore(&gpio_lock, flags);
@@ -907,7 +959,9 @@ int gpio_direction_output(unsigned gpio, int value)
907 gpio -= chip->base; 959 gpio -= chip->base;
908 if (gpio >= chip->ngpio) 960 if (gpio >= chip->ngpio)
909 goto fail; 961 goto fail;
910 gpio_ensure_requested(desc); 962 status = gpio_ensure_requested(desc, gpio);
963 if (status < 0)
964 goto fail;
911 965
912 /* now we know the gpio is valid and chip won't vanish */ 966 /* now we know the gpio is valid and chip won't vanish */
913 967
@@ -915,9 +969,22 @@ int gpio_direction_output(unsigned gpio, int value)
915 969
916 might_sleep_if(extra_checks && chip->can_sleep); 970 might_sleep_if(extra_checks && chip->can_sleep);
917 971
972 if (status) {
973 status = chip->request(chip, gpio);
974 if (status < 0) {
975 pr_debug("GPIO-%d: chip request fail, %d\n",
976 chip->base + gpio, status);
977 /* and it's not available to anyone else ...
978 * gpio_request() is the fully clean solution.
979 */
980 goto lose;
981 }
982 }
983
918 status = chip->direction_output(chip, gpio, value); 984 status = chip->direction_output(chip, gpio, value);
919 if (status == 0) 985 if (status == 0)
920 set_bit(FLAG_IS_OUT, &desc->flags); 986 set_bit(FLAG_IS_OUT, &desc->flags);
987lose:
921 return status; 988 return status;
922fail: 989fail:
923 spin_unlock_irqrestore(&gpio_lock, flags); 990 spin_unlock_irqrestore(&gpio_lock, flags);
@@ -1008,6 +1075,24 @@ int __gpio_cansleep(unsigned gpio)
1008} 1075}
1009EXPORT_SYMBOL_GPL(__gpio_cansleep); 1076EXPORT_SYMBOL_GPL(__gpio_cansleep);
1010 1077
1078/**
1079 * __gpio_to_irq() - return the IRQ corresponding to a GPIO
1080 * @gpio: gpio whose IRQ will be returned (already requested)
1081 * Context: any
1082 *
1083 * This is used directly or indirectly to implement gpio_to_irq().
1084 * It returns the number of the IRQ signaled by this (input) GPIO,
1085 * or a negative errno.
1086 */
1087int __gpio_to_irq(unsigned gpio)
1088{
1089 struct gpio_chip *chip;
1090
1091 chip = gpio_to_chip(gpio);
1092 return chip->to_irq ? chip->to_irq(chip, gpio - chip->base) : -ENXIO;
1093}
1094EXPORT_SYMBOL_GPL(__gpio_to_irq);
1095
1011 1096
1012 1097
1013/* There's no value in making it easy to inline GPIO calls that may sleep. 1098/* There's no value in making it easy to inline GPIO calls that may sleep.
diff --git a/drivers/gpio/max7301.c b/drivers/gpio/max7301.c
index 39c795ad8312..8b24d784db93 100644
--- a/drivers/gpio/max7301.c
+++ b/drivers/gpio/max7301.c
@@ -255,10 +255,6 @@ static int __devinit max7301_probe(struct spi_device *spi)
255 ts->chip.dev = &spi->dev; 255 ts->chip.dev = &spi->dev;
256 ts->chip.owner = THIS_MODULE; 256 ts->chip.owner = THIS_MODULE;
257 257
258 ret = gpiochip_add(&ts->chip);
259 if (ret)
260 goto exit_destroy;
261
262 /* 258 /*
263 * tristate all pins in hardware and cache the 259 * tristate all pins in hardware and cache the
264 * register values for later use. 260 * register values for later use.
@@ -269,17 +265,19 @@ static int __devinit max7301_probe(struct spi_device *spi)
269 max7301_write(spi, 0x08 + i, 0xAA); 265 max7301_write(spi, 0x08 + i, 0xAA);
270 ts->port_config[i] = 0xAA; 266 ts->port_config[i] = 0xAA;
271 for (j = 0; j < 4; j++) { 267 for (j = 0; j < 4; j++) {
272 int idx = ts->chip.base + (i - 1) * 4 + j; 268 int offset = (i - 1) * 4 + j;
273 ret = gpio_direction_input(idx); 269 ret = max7301_direction_input(&ts->chip, offset);
274 if (ret) 270 if (ret)
275 goto exit_remove; 271 goto exit_destroy;
276 gpio_free(idx);
277 } 272 }
278 } 273 }
274
275 ret = gpiochip_add(&ts->chip);
276 if (ret)
277 goto exit_destroy;
278
279 return ret; 279 return ret;
280 280
281exit_remove:
282 gpiochip_remove(&ts->chip);
283exit_destroy: 281exit_destroy:
284 dev_set_drvdata(&spi->dev, NULL); 282 dev_set_drvdata(&spi->dev, NULL);
285 mutex_destroy(&ts->lock); 283 mutex_destroy(&ts->lock);
@@ -325,13 +323,15 @@ static int __init max7301_init(void)
325{ 323{
326 return spi_register_driver(&max7301_driver); 324 return spi_register_driver(&max7301_driver);
327} 325}
326/* register after spi postcore initcall and before
327 * subsys initcalls that may rely on these GPIOs
328 */
329subsys_initcall(max7301_init);
328 330
329static void __exit max7301_exit(void) 331static void __exit max7301_exit(void)
330{ 332{
331 spi_unregister_driver(&max7301_driver); 333 spi_unregister_driver(&max7301_driver);
332} 334}
333
334module_init(max7301_init);
335module_exit(max7301_exit); 335module_exit(max7301_exit);
336 336
337MODULE_AUTHOR("Juergen Beisert"); 337MODULE_AUTHOR("Juergen Beisert");
diff --git a/drivers/gpio/max732x.c b/drivers/gpio/max732x.c
index b51c8135ca28..55ae9a41897a 100644
--- a/drivers/gpio/max732x.c
+++ b/drivers/gpio/max732x.c
@@ -372,7 +372,10 @@ static int __init max732x_init(void)
372{ 372{
373 return i2c_add_driver(&max732x_driver); 373 return i2c_add_driver(&max732x_driver);
374} 374}
375module_init(max732x_init); 375/* register after i2c postcore initcall and before
376 * subsys initcalls that may rely on these GPIOs
377 */
378subsys_initcall(max732x_init);
376 379
377static void __exit max732x_exit(void) 380static void __exit max732x_exit(void)
378{ 381{
diff --git a/drivers/gpio/mcp23s08.c b/drivers/gpio/mcp23s08.c
index 8a1b405fefda..89c1d222e9d1 100644
--- a/drivers/gpio/mcp23s08.c
+++ b/drivers/gpio/mcp23s08.c
@@ -419,7 +419,10 @@ static int __init mcp23s08_init(void)
419{ 419{
420 return spi_register_driver(&mcp23s08_driver); 420 return spi_register_driver(&mcp23s08_driver);
421} 421}
422module_init(mcp23s08_init); 422/* register after spi postcore initcall and before
423 * subsys initcalls that may rely on these GPIOs
424 */
425subsys_initcall(mcp23s08_init);
423 426
424static void __exit mcp23s08_exit(void) 427static void __exit mcp23s08_exit(void)
425{ 428{
diff --git a/drivers/gpio/pca953x.c b/drivers/gpio/pca953x.c
index cc8468692ae0..9ceeb89f1325 100644
--- a/drivers/gpio/pca953x.c
+++ b/drivers/gpio/pca953x.c
@@ -289,7 +289,10 @@ static int __init pca953x_init(void)
289{ 289{
290 return i2c_add_driver(&pca953x_driver); 290 return i2c_add_driver(&pca953x_driver);
291} 291}
292module_init(pca953x_init); 292/* register after i2c postcore initcall and before
293 * subsys initcalls that may rely on these GPIOs
294 */
295subsys_initcall(pca953x_init);
293 296
294static void __exit pca953x_exit(void) 297static void __exit pca953x_exit(void)
295{ 298{
diff --git a/drivers/gpio/pcf857x.c b/drivers/gpio/pcf857x.c
index fc9c6ae739ee..4bc2070dd4a1 100644
--- a/drivers/gpio/pcf857x.c
+++ b/drivers/gpio/pcf857x.c
@@ -351,7 +351,10 @@ static int __init pcf857x_init(void)
351{ 351{
352 return i2c_add_driver(&pcf857x_driver); 352 return i2c_add_driver(&pcf857x_driver);
353} 353}
354module_init(pcf857x_init); 354/* register after i2c postcore initcall and before
355 * subsys initcalls that may rely on these GPIOs
356 */
357subsys_initcall(pcf857x_init);
355 358
356static void __exit pcf857x_exit(void) 359static void __exit pcf857x_exit(void)
357{ 360{
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 88974342933c..9ac4720e647b 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -517,7 +517,7 @@ static int i915_dispatch_flip(struct drm_device * dev)
517 RING_LOCALS; 517 RING_LOCALS;
518 518
519 DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n", 519 DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n",
520 __FUNCTION__, 520 __func__,
521 dev_priv->current_page, 521 dev_priv->current_page,
522 dev_priv->sarea_priv->pf_current_page); 522 dev_priv->sarea_priv->pf_current_page);
523 523
@@ -642,7 +642,7 @@ static int i915_cmdbuffer(struct drm_device *dev, void *data,
642static int i915_flip_bufs(struct drm_device *dev, void *data, 642static int i915_flip_bufs(struct drm_device *dev, void *data,
643 struct drm_file *file_priv) 643 struct drm_file *file_priv)
644{ 644{
645 DRM_DEBUG("%s\n", __FUNCTION__); 645 DRM_DEBUG("%s\n", __func__);
646 646
647 LOCK_TEST_WITH_RETURN(dev, file_priv); 647 LOCK_TEST_WITH_RETURN(dev, file_priv);
648 648
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index cacf89e65af4..f5999a91614e 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -67,4 +67,201 @@ config HIDRAW
67 67
68source "drivers/hid/usbhid/Kconfig" 68source "drivers/hid/usbhid/Kconfig"
69 69
70menu "Special HID drivers"
71 depends on HID
72
73config HID_COMPAT
74 bool "Load all HID drivers on hid core load"
75 default y
76 ---help---
77 Compatible option for older userspace. If you have system without udev
78 support of module loading through aliases and also old
79 module-init-tools which can't handle hid bus, choose Y here. Otherwise
80 say N. If you say N and your userspace is old enough, the only
81 functionality you lose is modules autoloading.
82
83 If unsure, say Y.
84
85config HID_A4TECH
86 tristate "A4 tech" if EMBEDDED
87 depends on USB_HID
88 default y
89 ---help---
90 Support for A4 tech X5 and WOP-35 / Trust 450L mice.
91
92config HID_APPLE
93 tristate "Apple" if EMBEDDED
94 depends on (USB_HID || BT_HIDP)
95 default y
96 ---help---
97 Support for some Apple devices which less or more break
98 HID specification.
99
100 Say Y here if you want support for keyboards of Apple iBooks, PowerBooks,
101 MacBooks, MacBook Pros and Apple Aluminum.
102
103config HID_BELKIN
104 tristate "Belkin" if EMBEDDED
105 depends on USB_HID
106 default y
107 ---help---
108 Support for Belkin Flip KVM and Wireless keyboard.
109
110config HID_BRIGHT
111 tristate "Bright" if EMBEDDED
112 depends on USB_HID
113 default y
114 ---help---
115 Support for Bright ABNT-2 keyboard.
116
117config HID_CHERRY
118 tristate "Cherry" if EMBEDDED
119 depends on USB_HID
120 default y
121 ---help---
122 Support for Cherry Cymotion keyboard.
123
124config HID_CHICONY
125 tristate "Chicony" if EMBEDDED
126 depends on USB_HID
127 default y
128 ---help---
129 Support for Chicony Tactical pad.
130
131config HID_CYPRESS
132 tristate "Cypress" if EMBEDDED
133 depends on USB_HID
134 default y
135 ---help---
136 Support for cypress mouse and barcode readers.
137
138config HID_DELL
139 tristate "Dell" if EMBEDDED
140 depends on USB_HID
141 default y
142 ---help---
143 Support for quirky Dell HID hardware that require
144 special LED handling (W7658 and SK8115 models)
145
146config HID_EZKEY
147 tristate "Ezkey" if EMBEDDED
148 depends on USB_HID
149 default y
150 ---help---
151 Support for Ezkey BTC 8193 keyboard.
152
153config HID_GYRATION
154 tristate "Gyration" if EMBEDDED
155 depends on USB_HID
156 default y
157 ---help---
158 Support for Gyration remote control.
159
160config HID_LOGITECH
161 tristate "Logitech" if EMBEDDED
162 depends on USB_HID
163 default y
164 ---help---
165 Support for Logitech devices that are not fully compliant with HID standard.
166
167config LOGITECH_FF
168 bool "Logitech force feedback"
169 depends on HID_LOGITECH
170 select INPUT_FF_MEMLESS
171 help
172 Say Y here if you have one of these devices:
173 - Logitech WingMan Cordless RumblePad
174 - Logitech WingMan Cordless RumblePad 2
175 - Logitech WingMan Force 3D
176 - Logitech Formula Force EX
177 - Logitech MOMO Force wheel
178
179 and if you want to enable force feedback for them.
180 Note: if you say N here, this device will still be supported, but without
181 force feedback.
182
183config LOGIRUMBLEPAD2_FF
184 bool "Logitech Rumblepad 2 force feedback"
185 depends on HID_LOGITECH
186 select INPUT_FF_MEMLESS
187 help
188 Say Y here if you want to enable force feedback support for Logitech
189 Rumblepad 2 devices.
190
191config HID_MICROSOFT
192 tristate "Microsoft" if EMBEDDED
193 depends on USB_HID
194 default y
195 ---help---
196 Support for Microsoft devices that are not fully compliant with HID standard.
197
198config HID_MONTEREY
199 tristate "Monterey" if EMBEDDED
200 depends on USB_HID
201 default y
202 ---help---
203 Support for Monterey Genius KB29E.
204
205config HID_PANTHERLORD
206 tristate "Pantherlord devices support" if EMBEDDED
207 depends on USB_HID
208 default y
209 ---help---
210 Support for PantherLord/GreenAsia based device support.
211
212config PANTHERLORD_FF
213 bool "Pantherlord force feedback support"
214 depends on HID_PANTHERLORD
215 select INPUT_FF_MEMLESS
216 help
217 Say Y here if you have a PantherLord/GreenAsia based game controller
218 or adapter and want to enable force feedback support for it.
219
220config HID_PETALYNX
221 tristate "Petalynx" if EMBEDDED
222 depends on USB_HID
223 default y
224 ---help---
225 Support for Petalynx Maxter remote control.
226
227config HID_SAMSUNG
228 tristate "Samsung" if EMBEDDED
229 depends on USB_HID
230 default y
231 ---help---
232 Support for Samsung InfraRed remote control.
233
234config HID_SONY
235 tristate "Sony" if EMBEDDED
236 depends on USB_HID
237 default y
238 ---help---
239 Support for Sony PS3 controller.
240
241config HID_SUNPLUS
242 tristate "Sunplus" if EMBEDDED
243 depends on USB_HID
244 default y
245 ---help---
246 Support for Sunplus wireless desktop.
247
248config THRUSTMASTER_FF
249 tristate "ThrustMaster devices support"
250 default m
251 depends on USB_HID
252 select INPUT_FF_MEMLESS
253 help
254 Say Y here if you have a THRUSTMASTER FireStore Dual Power 2 or
255 a THRUSTMASTER Ferrari GT Rumble Force or Force Feedback Wheel.
256
257config ZEROPLUS_FF
258 tristate "Zeroplus based game controller support"
259 default m
260 depends on USB_HID
261 select INPUT_FF_MEMLESS
262 help
263 Say Y here if you have a Zeroplus based game controller.
264
265endmenu
266
70endif # HID_SUPPORT 267endif # HID_SUPPORT
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index 275dc522c738..b09e43e7413e 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -1,13 +1,46 @@
1# 1#
2# Makefile for the HID driver 2# Makefile for the HID driver
3# 3#
4hid-objs := hid-core.o hid-input.o hid-input-quirks.o 4hid-objs := hid-core.o hid-input.o
5 5
6obj-$(CONFIG_HID) += hid.o 6obj-$(CONFIG_HID) += hid.o
7 7
8hid-$(CONFIG_HID_DEBUG) += hid-debug.o 8hid-$(CONFIG_HID_DEBUG) += hid-debug.o
9hid-$(CONFIG_HIDRAW) += hidraw.o 9hid-$(CONFIG_HIDRAW) += hidraw.o
10 10
11ifdef CONFIG_HID_COMPAT
12obj-m += hid-dummy.o
13endif
14
15hid-logitech-objs := hid-lg.o
16ifdef CONFIG_LOGITECH_FF
17 hid-logitech-objs += hid-lgff.o
18endif
19ifdef CONFIG_LOGIRUMBLEPAD2_FF
20 hid-logitech-objs += hid-lg2ff.o
21endif
22
23obj-$(CONFIG_HID_A4TECH) += hid-a4tech.o
24obj-$(CONFIG_HID_APPLE) += hid-apple.o
25obj-$(CONFIG_HID_BELKIN) += hid-belkin.o
26obj-$(CONFIG_HID_BRIGHT) += hid-bright.o
27obj-$(CONFIG_HID_CHERRY) += hid-cherry.o
28obj-$(CONFIG_HID_CHICONY) += hid-chicony.o
29obj-$(CONFIG_HID_CYPRESS) += hid-cypress.o
30obj-$(CONFIG_HID_DELL) += hid-dell.o
31obj-$(CONFIG_HID_EZKEY) += hid-ezkey.o
32obj-$(CONFIG_HID_GYRATION) += hid-gyration.o
33obj-$(CONFIG_HID_LOGITECH) += hid-logitech.o
34obj-$(CONFIG_HID_MICROSOFT) += hid-microsoft.o
35obj-$(CONFIG_HID_MONTEREY) += hid-monterey.o
36obj-$(CONFIG_HID_PANTHERLORD) += hid-pl.o
37obj-$(CONFIG_HID_PETALYNX) += hid-petalynx.o
38obj-$(CONFIG_HID_SAMSUNG) += hid-samsung.o
39obj-$(CONFIG_HID_SONY) += hid-sony.o
40obj-$(CONFIG_HID_SUNPLUS) += hid-sunplus.o
41obj-$(CONFIG_THRUSTMASTER_FF) += hid-tmff.o
42obj-$(CONFIG_ZEROPLUS_FF) += hid-zpff.o
43
11obj-$(CONFIG_USB_HID) += usbhid/ 44obj-$(CONFIG_USB_HID) += usbhid/
12obj-$(CONFIG_USB_MOUSE) += usbhid/ 45obj-$(CONFIG_USB_MOUSE) += usbhid/
13obj-$(CONFIG_USB_KBD) += usbhid/ 46obj-$(CONFIG_USB_KBD) += usbhid/
diff --git a/drivers/hid/hid-a4tech.c b/drivers/hid/hid-a4tech.c
new file mode 100644
index 000000000000..ebca00e6c103
--- /dev/null
+++ b/drivers/hid/hid-a4tech.c
@@ -0,0 +1,162 @@
1/*
2 * HID driver for some a4tech "special" devices
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/input.h>
21#include <linux/hid.h>
22#include <linux/module.h>
23
24#include "hid-ids.h"
25
26#define A4_2WHEEL_MOUSE_HACK_7 0x01
27#define A4_2WHEEL_MOUSE_HACK_B8 0x02
28
29struct a4tech_sc {
30 unsigned long quirks;
31 unsigned int hw_wheel;
32 __s32 delayed_value;
33};
34
35static int a4_input_mapped(struct hid_device *hdev, struct hid_input *hi,
36 struct hid_field *field, struct hid_usage *usage,
37 unsigned long **bit, int *max)
38{
39 struct a4tech_sc *a4 = hid_get_drvdata(hdev);
40
41 if (usage->type == EV_REL && usage->code == REL_WHEEL)
42 set_bit(REL_HWHEEL, *bit);
43
44 if ((a4->quirks & A4_2WHEEL_MOUSE_HACK_7) && usage->hid == 0x00090007)
45 return -1;
46
47 return 0;
48}
49
50static int a4_event(struct hid_device *hdev, struct hid_field *field,
51 struct hid_usage *usage, __s32 value)
52{
53 struct a4tech_sc *a4 = hid_get_drvdata(hdev);
54 struct input_dev *input;
55
56 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
57 !usage->type)
58 return 0;
59
60 input = field->hidinput->input;
61
62 if (a4->quirks & A4_2WHEEL_MOUSE_HACK_B8) {
63 if (usage->type == EV_REL && usage->code == REL_WHEEL) {
64 a4->delayed_value = value;
65 return 1;
66 }
67
68 if (usage->hid == 0x000100b8) {
69 input_event(input, EV_REL, value ? REL_HWHEEL :
70 REL_WHEEL, a4->delayed_value);
71 return 1;
72 }
73 }
74
75 if ((a4->quirks & A4_2WHEEL_MOUSE_HACK_7) && usage->hid == 0x00090007) {
76 a4->hw_wheel = !!value;
77 return 1;
78 }
79
80 if (usage->code == REL_WHEEL && a4->hw_wheel) {
81 input_event(input, usage->type, REL_HWHEEL, value);
82 return 1;
83 }
84
85 return 0;
86}
87
88static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id)
89{
90 struct a4tech_sc *a4;
91 int ret;
92
93 a4 = kzalloc(sizeof(*a4), GFP_KERNEL);
94 if (a4 == NULL) {
95 dev_err(&hdev->dev, "can't alloc device descriptor\n");
96 ret = -ENOMEM;
97 goto err_free;
98 }
99
100 a4->quirks = id->driver_data;
101
102 hid_set_drvdata(hdev, a4);
103
104 ret = hid_parse(hdev);
105 if (ret) {
106 dev_err(&hdev->dev, "parse failed\n");
107 goto err_free;
108 }
109
110 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
111 if (ret) {
112 dev_err(&hdev->dev, "hw start failed\n");
113 goto err_free;
114 }
115
116 return 0;
117err_free:
118 kfree(a4);
119 return ret;
120}
121
122static void a4_remove(struct hid_device *hdev)
123{
124 struct a4tech_sc *a4 = hid_get_drvdata(hdev);
125
126 hid_hw_stop(hdev);
127 kfree(a4);
128}
129
130static const struct hid_device_id a4_devices[] = {
131 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU),
132 .driver_data = A4_2WHEEL_MOUSE_HACK_7 },
133 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D),
134 .driver_data = A4_2WHEEL_MOUSE_HACK_B8 },
135 { }
136};
137MODULE_DEVICE_TABLE(hid, a4_devices);
138
139static struct hid_driver a4_driver = {
140 .name = "a4tech",
141 .id_table = a4_devices,
142 .input_mapped = a4_input_mapped,
143 .event = a4_event,
144 .probe = a4_probe,
145 .remove = a4_remove,
146};
147
148static int a4_init(void)
149{
150 return hid_register_driver(&a4_driver);
151}
152
153static void a4_exit(void)
154{
155 hid_unregister_driver(&a4_driver);
156}
157
158module_init(a4_init);
159module_exit(a4_exit);
160MODULE_LICENSE("GPL");
161
162HID_COMPAT_LOAD_DRIVER(a4tech);
diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c
new file mode 100644
index 000000000000..fd7f896b34f7
--- /dev/null
+++ b/drivers/hid/hid-apple.c
@@ -0,0 +1,484 @@
1/*
2 * USB HID quirks support for Linux
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby <jirislaby@gmail.com>
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/hid.h>
21#include <linux/module.h>
22#include <linux/usb.h>
23
24#include "hid-ids.h"
25
26#define APPLE_RDESC_JIS 0x0001
27#define APPLE_IGNORE_MOUSE 0x0002
28#define APPLE_HAS_FN 0x0004
29#define APPLE_HIDDEV 0x0008
30#define APPLE_ISO_KEYBOARD 0x0010
31#define APPLE_MIGHTYMOUSE 0x0020
32#define APPLE_INVERT_HWHEEL 0x0040
33#define APPLE_IGNORE_HIDINPUT 0x0080
34#define APPLE_NUMLOCK_EMULATION 0x0100
35
36#define APPLE_FLAG_FKEY 0x01
37
38static unsigned int fnmode = 1;
39module_param(fnmode, uint, 0644);
40MODULE_PARM_DESC(fnmode, "Mode of fn key on Apple keyboards (0 = disabled, "
41 "[1] = fkeyslast, 2 = fkeysfirst)");
42
43struct apple_sc {
44 unsigned long quirks;
45 unsigned int fn_on;
46 DECLARE_BITMAP(pressed_fn, KEY_CNT);
47 DECLARE_BITMAP(pressed_numlock, KEY_CNT);
48};
49
50struct apple_key_translation {
51 u16 from;
52 u16 to;
53 u8 flags;
54};
55
56static struct apple_key_translation apple_fn_keys[] = {
57 { KEY_BACKSPACE, KEY_DELETE },
58 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
59 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
60 { KEY_F3, KEY_FN_F5, APPLE_FLAG_FKEY }, /* Exposé */
61 { KEY_F4, KEY_FN_F4, APPLE_FLAG_FKEY }, /* Dashboard */
62 { KEY_F5, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY },
63 { KEY_F6, KEY_KBDILLUMUP, APPLE_FLAG_FKEY },
64 { KEY_F7, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY },
65 { KEY_F8, KEY_PLAYPAUSE, APPLE_FLAG_FKEY },
66 { KEY_F9, KEY_NEXTSONG, APPLE_FLAG_FKEY },
67 { KEY_F10, KEY_MUTE, APPLE_FLAG_FKEY },
68 { KEY_F11, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
69 { KEY_F12, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
70 { KEY_UP, KEY_PAGEUP },
71 { KEY_DOWN, KEY_PAGEDOWN },
72 { KEY_LEFT, KEY_HOME },
73 { KEY_RIGHT, KEY_END },
74 { }
75};
76
77static struct apple_key_translation powerbook_fn_keys[] = {
78 { KEY_BACKSPACE, KEY_DELETE },
79 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
80 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
81 { KEY_F3, KEY_MUTE, APPLE_FLAG_FKEY },
82 { KEY_F4, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
83 { KEY_F5, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
84 { KEY_F6, KEY_NUMLOCK, APPLE_FLAG_FKEY },
85 { KEY_F7, KEY_SWITCHVIDEOMODE, APPLE_FLAG_FKEY },
86 { KEY_F8, KEY_KBDILLUMTOGGLE, APPLE_FLAG_FKEY },
87 { KEY_F9, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY },
88 { KEY_F10, KEY_KBDILLUMUP, APPLE_FLAG_FKEY },
89 { KEY_UP, KEY_PAGEUP },
90 { KEY_DOWN, KEY_PAGEDOWN },
91 { KEY_LEFT, KEY_HOME },
92 { KEY_RIGHT, KEY_END },
93 { }
94};
95
96static struct apple_key_translation powerbook_numlock_keys[] = {
97 { KEY_J, KEY_KP1 },
98 { KEY_K, KEY_KP2 },
99 { KEY_L, KEY_KP3 },
100 { KEY_U, KEY_KP4 },
101 { KEY_I, KEY_KP5 },
102 { KEY_O, KEY_KP6 },
103 { KEY_7, KEY_KP7 },
104 { KEY_8, KEY_KP8 },
105 { KEY_9, KEY_KP9 },
106 { KEY_M, KEY_KP0 },
107 { KEY_DOT, KEY_KPDOT },
108 { KEY_SLASH, KEY_KPPLUS },
109 { KEY_SEMICOLON, KEY_KPMINUS },
110 { KEY_P, KEY_KPASTERISK },
111 { KEY_MINUS, KEY_KPEQUAL },
112 { KEY_0, KEY_KPSLASH },
113 { KEY_F6, KEY_NUMLOCK },
114 { KEY_KPENTER, KEY_KPENTER },
115 { KEY_BACKSPACE, KEY_BACKSPACE },
116 { }
117};
118
119static struct apple_key_translation apple_iso_keyboard[] = {
120 { KEY_GRAVE, KEY_102ND },
121 { KEY_102ND, KEY_GRAVE },
122 { }
123};
124
125static struct apple_key_translation *apple_find_translation(
126 struct apple_key_translation *table, u16 from)
127{
128 struct apple_key_translation *trans;
129
130 /* Look for the translation */
131 for (trans = table; trans->from; trans++)
132 if (trans->from == from)
133 return trans;
134
135 return NULL;
136}
137
138static int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
139 struct hid_usage *usage, __s32 value)
140{
141 struct apple_sc *asc = hid_get_drvdata(hid);
142 struct apple_key_translation *trans;
143
144 if (usage->code == KEY_FN) {
145 asc->fn_on = !!value;
146 input_event(input, usage->type, usage->code, value);
147 return 1;
148 }
149
150 if (fnmode) {
151 int do_translate;
152
153 trans = apple_find_translation((hid->product < 0x220 ||
154 hid->product >= 0x300) ?
155 powerbook_fn_keys : apple_fn_keys,
156 usage->code);
157 if (trans) {
158 if (test_bit(usage->code, asc->pressed_fn))
159 do_translate = 1;
160 else if (trans->flags & APPLE_FLAG_FKEY)
161 do_translate = (fnmode == 2 && asc->fn_on) ||
162 (fnmode == 1 && !asc->fn_on);
163 else
164 do_translate = asc->fn_on;
165
166 if (do_translate) {
167 if (value)
168 set_bit(usage->code, asc->pressed_fn);
169 else
170 clear_bit(usage->code, asc->pressed_fn);
171
172 input_event(input, usage->type, trans->to,
173 value);
174
175 return 1;
176 }
177 }
178
179 if (asc->quirks & APPLE_NUMLOCK_EMULATION &&
180 (test_bit(usage->code, asc->pressed_numlock) ||
181 test_bit(LED_NUML, input->led))) {
182 trans = apple_find_translation(powerbook_numlock_keys,
183 usage->code);
184
185 if (trans) {
186 if (value)
187 set_bit(usage->code,
188 asc->pressed_numlock);
189 else
190 clear_bit(usage->code,
191 asc->pressed_numlock);
192
193 input_event(input, usage->type, trans->to,
194 value);
195 }
196
197 return 1;
198 }
199 }
200
201 if (asc->quirks & APPLE_ISO_KEYBOARD) {
202 trans = apple_find_translation(apple_iso_keyboard, usage->code);
203 if (trans) {
204 input_event(input, usage->type, trans->to, value);
205 return 1;
206 }
207 }
208
209 return 0;
210}
211
212static int apple_event(struct hid_device *hdev, struct hid_field *field,
213 struct hid_usage *usage, __s32 value)
214{
215 struct apple_sc *asc = hid_get_drvdata(hdev);
216
217 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
218 !usage->type)
219 return 0;
220
221 if ((asc->quirks & APPLE_INVERT_HWHEEL) &&
222 usage->code == REL_HWHEEL) {
223 input_event(field->hidinput->input, usage->type, usage->code,
224 -value);
225 return 1;
226 }
227
228 if ((asc->quirks & APPLE_HAS_FN) &&
229 hidinput_apple_event(hdev, field->hidinput->input,
230 usage, value))
231 return 1;
232
233
234 return 0;
235}
236
237/*
238 * MacBook JIS keyboard has wrong logical maximum
239 */
240static void apple_report_fixup(struct hid_device *hdev, __u8 *rdesc,
241 unsigned int rsize)
242{
243 struct apple_sc *asc = hid_get_drvdata(hdev);
244
245 if ((asc->quirks & APPLE_RDESC_JIS) && rsize >= 60 &&
246 rdesc[53] == 0x65 && rdesc[59] == 0x65) {
247 dev_info(&hdev->dev, "fixing up MacBook JIS keyboard report "
248 "descriptor\n");
249 rdesc[53] = rdesc[59] = 0xe7;
250 }
251}
252
253static void apple_setup_input(struct input_dev *input)
254{
255 struct apple_key_translation *trans;
256
257 set_bit(KEY_NUMLOCK, input->keybit);
258
259 /* Enable all needed keys */
260 for (trans = apple_fn_keys; trans->from; trans++)
261 set_bit(trans->to, input->keybit);
262
263 for (trans = powerbook_fn_keys; trans->from; trans++)
264 set_bit(trans->to, input->keybit);
265
266 for (trans = powerbook_numlock_keys; trans->from; trans++)
267 set_bit(trans->to, input->keybit);
268
269 for (trans = apple_iso_keyboard; trans->from; trans++)
270 set_bit(trans->to, input->keybit);
271}
272
273static int apple_input_mapping(struct hid_device *hdev, struct hid_input *hi,
274 struct hid_field *field, struct hid_usage *usage,
275 unsigned long **bit, int *max)
276{
277 if (usage->hid == (HID_UP_CUSTOM | 0x0003)) {
278 /* The fn key on Apple USB keyboards */
279 set_bit(EV_REP, hi->input->evbit);
280 hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_FN);
281 apple_setup_input(hi->input);
282 return 1;
283 }
284
285 /* we want the hid layer to go through standard path (set and ignore) */
286 return 0;
287}
288
289static int apple_input_mapped(struct hid_device *hdev, struct hid_input *hi,
290 struct hid_field *field, struct hid_usage *usage,
291 unsigned long **bit, int *max)
292{
293 struct apple_sc *asc = hid_get_drvdata(hdev);
294
295 if (asc->quirks & APPLE_MIGHTYMOUSE) {
296 if (usage->hid == HID_GD_Z)
297 hid_map_usage(hi, usage, bit, max, EV_REL, REL_HWHEEL);
298 else if (usage->code == BTN_1)
299 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_2);
300 else if (usage->code == BTN_2)
301 hid_map_usage(hi, usage, bit, max, EV_KEY, BTN_1);
302 }
303
304 return 0;
305}
306
307static int apple_probe(struct hid_device *hdev,
308 const struct hid_device_id *id)
309{
310 unsigned long quirks = id->driver_data;
311 struct apple_sc *asc;
312 unsigned int connect_mask = HID_CONNECT_DEFAULT;
313 int ret;
314
315 /* return something else or move to hid layer? device will reside
316 allocated */
317 if (id->bus == BUS_USB && (quirks & APPLE_IGNORE_MOUSE) &&
318 to_usb_interface(hdev->dev.parent)->cur_altsetting->
319 desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE)
320 return -ENODEV;
321
322 asc = kzalloc(sizeof(*asc), GFP_KERNEL);
323 if (asc == NULL) {
324 dev_err(&hdev->dev, "can't alloc apple descriptor\n");
325 return -ENOMEM;
326 }
327
328 asc->quirks = quirks;
329
330 hid_set_drvdata(hdev, asc);
331
332 ret = hid_parse(hdev);
333 if (ret) {
334 dev_err(&hdev->dev, "parse failed\n");
335 goto err_free;
336 }
337
338 if (quirks & APPLE_HIDDEV)
339 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
340 if (quirks & APPLE_IGNORE_HIDINPUT)
341 connect_mask &= ~HID_CONNECT_HIDINPUT;
342
343 ret = hid_hw_start(hdev, connect_mask);
344 if (ret) {
345 dev_err(&hdev->dev, "hw start failed\n");
346 goto err_free;
347 }
348
349 return 0;
350err_free:
351 kfree(asc);
352 return ret;
353}
354
355static void apple_remove(struct hid_device *hdev)
356{
357 hid_hw_stop(hdev);
358 kfree(hid_get_drvdata(hdev));
359}
360
361static const struct hid_device_id apple_devices[] = {
362 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL),
363 .driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT },
364 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4),
365 .driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT },
366 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE),
367 .driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL },
368
369 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI),
370 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
371 APPLE_IGNORE_MOUSE },
372 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO),
373 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
374 APPLE_IGNORE_MOUSE },
375 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI),
376 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
377 APPLE_IGNORE_MOUSE },
378 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO),
379 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
380 APPLE_IGNORE_MOUSE | APPLE_ISO_KEYBOARD },
381 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS),
382 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
383 APPLE_IGNORE_MOUSE },
384 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI),
385 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
386 APPLE_IGNORE_MOUSE },
387 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO),
388 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
389 APPLE_IGNORE_MOUSE | APPLE_ISO_KEYBOARD },
390 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS),
391 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
392 APPLE_IGNORE_MOUSE | APPLE_RDESC_JIS },
393 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI),
394 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
395 APPLE_IGNORE_MOUSE },
396 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO),
397 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
398 APPLE_IGNORE_MOUSE | APPLE_ISO_KEYBOARD },
399 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS),
400 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
401 APPLE_IGNORE_MOUSE | APPLE_RDESC_JIS},
402 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI),
403 .driver_data = APPLE_HAS_FN },
404 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO),
405 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD },
406 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS),
407 .driver_data = APPLE_HAS_FN },
408 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI),
409 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
410 APPLE_IGNORE_MOUSE },
411 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO),
412 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
413 APPLE_IGNORE_MOUSE },
414 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS),
415 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
416 APPLE_IGNORE_MOUSE | APPLE_RDESC_JIS },
417 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI),
418 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
419 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO),
420 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
421 APPLE_ISO_KEYBOARD },
422 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS),
423 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN },
424 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI),
425 .driver_data = APPLE_HAS_FN | APPLE_IGNORE_MOUSE },
426 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO),
427 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD |
428 APPLE_IGNORE_MOUSE },
429 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS),
430 .driver_data = APPLE_HAS_FN | APPLE_IGNORE_MOUSE | APPLE_RDESC_JIS },
431 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI),
432 .driver_data = APPLE_HAS_FN | APPLE_IGNORE_MOUSE },
433 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO),
434 .driver_data = APPLE_HAS_FN | APPLE_ISO_KEYBOARD |
435 APPLE_IGNORE_MOUSE },
436 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS),
437 .driver_data = APPLE_HAS_FN | APPLE_IGNORE_MOUSE | APPLE_RDESC_JIS },
438 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY),
439 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
440 APPLE_IGNORE_MOUSE },
441 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY),
442 .driver_data = APPLE_NUMLOCK_EMULATION | APPLE_HAS_FN |
443 APPLE_IGNORE_MOUSE },
444
445 /* Apple wireless Mighty Mouse */
446 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 0x030c),
447 .driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL },
448
449 { }
450};
451MODULE_DEVICE_TABLE(hid, apple_devices);
452
453static struct hid_driver apple_driver = {
454 .name = "apple",
455 .id_table = apple_devices,
456 .report_fixup = apple_report_fixup,
457 .probe = apple_probe,
458 .remove = apple_remove,
459 .event = apple_event,
460 .input_mapping = apple_input_mapping,
461 .input_mapped = apple_input_mapped,
462};
463
464static int apple_init(void)
465{
466 int ret;
467
468 ret = hid_register_driver(&apple_driver);
469 if (ret)
470 printk(KERN_ERR "can't register apple driver\n");
471
472 return ret;
473}
474
475static void apple_exit(void)
476{
477 hid_unregister_driver(&apple_driver);
478}
479
480module_init(apple_init);
481module_exit(apple_exit);
482MODULE_LICENSE("GPL");
483
484HID_COMPAT_LOAD_DRIVER(apple);
diff --git a/drivers/hid/hid-belkin.c b/drivers/hid/hid-belkin.c
new file mode 100644
index 000000000000..12c8a9ba6ed6
--- /dev/null
+++ b/drivers/hid/hid-belkin.c
@@ -0,0 +1,105 @@
1/*
2 * HID driver for some belkin "special" devices
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/hid.h>
21#include <linux/module.h>
22
23#include "hid-ids.h"
24
25#define BELKIN_HIDDEV 0x01
26#define BELKIN_WKBD 0x02
27
28#define belkin_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
29 EV_KEY, (c))
30static int belkin_input_mapping(struct hid_device *hdev, struct hid_input *hi,
31 struct hid_field *field, struct hid_usage *usage,
32 unsigned long **bit, int *max)
33{
34 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
35
36 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER ||
37 !(quirks & BELKIN_WKBD))
38 return 0;
39
40 switch (usage->hid & HID_USAGE) {
41 case 0x03a: belkin_map_key_clear(KEY_SOUND); break;
42 case 0x03b: belkin_map_key_clear(KEY_CAMERA); break;
43 case 0x03c: belkin_map_key_clear(KEY_DOCUMENTS); break;
44 default:
45 return 0;
46 }
47 return 1;
48}
49
50static int belkin_probe(struct hid_device *hdev, const struct hid_device_id *id)
51{
52 unsigned long quirks = id->driver_data;
53 int ret;
54
55 hid_set_drvdata(hdev, (void *)quirks);
56
57 ret = hid_parse(hdev);
58 if (ret) {
59 dev_err(&hdev->dev, "parse failed\n");
60 goto err_free;
61 }
62
63 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT |
64 ((quirks & BELKIN_HIDDEV) ? HID_CONNECT_HIDDEV_FORCE : 0));
65 if (ret) {
66 dev_err(&hdev->dev, "hw start failed\n");
67 goto err_free;
68 }
69
70 return 0;
71err_free:
72 return ret;
73}
74
75static const struct hid_device_id belkin_devices[] = {
76 { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM),
77 .driver_data = BELKIN_HIDDEV },
78 { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD),
79 .driver_data = BELKIN_WKBD },
80 { }
81};
82MODULE_DEVICE_TABLE(hid, belkin_devices);
83
84static struct hid_driver belkin_driver = {
85 .name = "belkin",
86 .id_table = belkin_devices,
87 .input_mapping = belkin_input_mapping,
88 .probe = belkin_probe,
89};
90
91static int belkin_init(void)
92{
93 return hid_register_driver(&belkin_driver);
94}
95
96static void belkin_exit(void)
97{
98 hid_unregister_driver(&belkin_driver);
99}
100
101module_init(belkin_init);
102module_exit(belkin_exit);
103MODULE_LICENSE("GPL");
104
105HID_COMPAT_LOAD_DRIVER(belkin);
diff --git a/drivers/hid/hid-bright.c b/drivers/hid/hid-bright.c
new file mode 100644
index 000000000000..38517a117dfd
--- /dev/null
+++ b/drivers/hid/hid-bright.c
@@ -0,0 +1,71 @@
1/*
2 * HID driver for some bright "special" devices
3 *
4 * Copyright (c) 2008 Mauro Carvalho Chehab <mchehab@redhat.com>
5 *
6 * Based on hid-dell driver
7 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 2 of the License, or (at your option)
13 * any later version.
14 */
15
16#include <linux/device.h>
17#include <linux/hid.h>
18#include <linux/module.h>
19
20#include "hid-ids.h"
21
22static int bright_probe(struct hid_device *hdev, const struct hid_device_id *id)
23{
24 int ret;
25
26 ret = hid_parse(hdev);
27 if (ret) {
28 dev_err(&hdev->dev, "parse failed\n");
29 goto err_free;
30 }
31
32 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
33 if (ret) {
34 dev_err(&hdev->dev, "hw start failed\n");
35 goto err_free;
36 }
37
38 usbhid_set_leds(hdev);
39
40 return 0;
41err_free:
42 return ret;
43}
44
45static const struct hid_device_id bright_devices[] = {
46 { HID_USB_DEVICE(USB_VENDOR_ID_BRIGHT, USB_DEVICE_ID_BRIGHT_ABNT2) },
47 { }
48};
49MODULE_DEVICE_TABLE(hid, bright_devices);
50
51static struct hid_driver bright_driver = {
52 .name = "bright",
53 .id_table = bright_devices,
54 .probe = bright_probe,
55};
56
57static int bright_init(void)
58{
59 return hid_register_driver(&bright_driver);
60}
61
62static void bright_exit(void)
63{
64 hid_unregister_driver(&bright_driver);
65}
66
67module_init(bright_init);
68module_exit(bright_exit);
69MODULE_LICENSE("GPL");
70
71HID_COMPAT_LOAD_DRIVER(bright);
diff --git a/drivers/hid/hid-cherry.c b/drivers/hid/hid-cherry.c
new file mode 100644
index 000000000000..b833b9769aba
--- /dev/null
+++ b/drivers/hid/hid-cherry.c
@@ -0,0 +1,87 @@
1/*
2 * HID driver for some cherry "special" devices
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/hid.h>
21#include <linux/module.h>
22
23#include "hid-ids.h"
24
25/*
26 * Cherry Cymotion keyboard have an invalid HID report descriptor,
27 * that needs fixing before we can parse it.
28 */
29static void ch_report_fixup(struct hid_device *hdev, __u8 *rdesc,
30 unsigned int rsize)
31{
32 if (rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
33 dev_info(&hdev->dev, "fixing up Cherry Cymotion report "
34 "descriptor\n");
35 rdesc[11] = rdesc[16] = 0xff;
36 rdesc[12] = rdesc[17] = 0x03;
37 }
38}
39
40#define ch_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
41 EV_KEY, (c))
42static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
43 struct hid_field *field, struct hid_usage *usage,
44 unsigned long **bit, int *max)
45{
46 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
47 return 0;
48
49 switch (usage->hid & HID_USAGE) {
50 case 0x301: ch_map_key_clear(KEY_PROG1); break;
51 case 0x302: ch_map_key_clear(KEY_PROG2); break;
52 case 0x303: ch_map_key_clear(KEY_PROG3); break;
53 default:
54 return 0;
55 }
56
57 return 1;
58}
59
60static const struct hid_device_id ch_devices[] = {
61 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
62 { }
63};
64MODULE_DEVICE_TABLE(hid, ch_devices);
65
66static struct hid_driver ch_driver = {
67 .name = "cherry",
68 .id_table = ch_devices,
69 .report_fixup = ch_report_fixup,
70 .input_mapping = ch_input_mapping,
71};
72
73static int ch_init(void)
74{
75 return hid_register_driver(&ch_driver);
76}
77
78static void ch_exit(void)
79{
80 hid_unregister_driver(&ch_driver);
81}
82
83module_init(ch_init);
84module_exit(ch_exit);
85MODULE_LICENSE("GPL");
86
87HID_COMPAT_LOAD_DRIVER(cherry);
diff --git a/drivers/hid/hid-chicony.c b/drivers/hid/hid-chicony.c
new file mode 100644
index 000000000000..a54d4096e0f7
--- /dev/null
+++ b/drivers/hid/hid-chicony.c
@@ -0,0 +1,80 @@
1/*
2 * HID driver for some chicony "special" devices
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/input.h>
21#include <linux/hid.h>
22#include <linux/module.h>
23
24#include "hid-ids.h"
25
26#define ch_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
27 EV_KEY, (c))
28static int ch_input_mapping(struct hid_device *hdev, struct hid_input *hi,
29 struct hid_field *field, struct hid_usage *usage,
30 unsigned long **bit, int *max)
31{
32 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
33 return 0;
34
35 set_bit(EV_REP, hi->input->evbit);
36 switch (usage->hid & HID_USAGE) {
37 case 0xff01: ch_map_key_clear(BTN_1); break;
38 case 0xff02: ch_map_key_clear(BTN_2); break;
39 case 0xff03: ch_map_key_clear(BTN_3); break;
40 case 0xff04: ch_map_key_clear(BTN_4); break;
41 case 0xff05: ch_map_key_clear(BTN_5); break;
42 case 0xff06: ch_map_key_clear(BTN_6); break;
43 case 0xff07: ch_map_key_clear(BTN_7); break;
44 case 0xff08: ch_map_key_clear(BTN_8); break;
45 case 0xff09: ch_map_key_clear(BTN_9); break;
46 case 0xff0a: ch_map_key_clear(BTN_A); break;
47 case 0xff0b: ch_map_key_clear(BTN_B); break;
48 default:
49 return 0;
50 }
51 return 1;
52}
53
54static const struct hid_device_id ch_devices[] = {
55 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
56 { }
57};
58MODULE_DEVICE_TABLE(hid, ch_devices);
59
60static struct hid_driver ch_driver = {
61 .name = "chicony",
62 .id_table = ch_devices,
63 .input_mapping = ch_input_mapping,
64};
65
66static int ch_init(void)
67{
68 return hid_register_driver(&ch_driver);
69}
70
71static void ch_exit(void)
72{
73 hid_unregister_driver(&ch_driver);
74}
75
76module_init(ch_init);
77module_exit(ch_exit);
78MODULE_LICENSE("GPL");
79
80HID_COMPAT_LOAD_DRIVER(chicony);
diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index 426ac5add585..721a36d97582 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -33,6 +33,8 @@
33#include <linux/hid-debug.h> 33#include <linux/hid-debug.h>
34#include <linux/hidraw.h> 34#include <linux/hidraw.h>
35 35
36#include "hid-ids.h"
37
36/* 38/*
37 * Version Information 39 * Version Information
38 */ 40 */
@@ -268,9 +270,9 @@ static int hid_add_field(struct hid_parser *parser, unsigned report_type, unsign
268static u32 item_udata(struct hid_item *item) 270static u32 item_udata(struct hid_item *item)
269{ 271{
270 switch (item->size) { 272 switch (item->size) {
271 case 1: return item->data.u8; 273 case 1: return item->data.u8;
272 case 2: return item->data.u16; 274 case 2: return item->data.u16;
273 case 4: return item->data.u32; 275 case 4: return item->data.u32;
274 } 276 }
275 return 0; 277 return 0;
276} 278}
@@ -278,9 +280,9 @@ static u32 item_udata(struct hid_item *item)
278static s32 item_sdata(struct hid_item *item) 280static s32 item_sdata(struct hid_item *item)
279{ 281{
280 switch (item->size) { 282 switch (item->size) {
281 case 1: return item->data.s8; 283 case 1: return item->data.s8;
282 case 2: return item->data.s16; 284 case 2: return item->data.s16;
283 case 4: return item->data.s32; 285 case 4: return item->data.s32;
284 } 286 }
285 return 0; 287 return 0;
286} 288}
@@ -292,87 +294,91 @@ static s32 item_sdata(struct hid_item *item)
292static int hid_parser_global(struct hid_parser *parser, struct hid_item *item) 294static int hid_parser_global(struct hid_parser *parser, struct hid_item *item)
293{ 295{
294 switch (item->tag) { 296 switch (item->tag) {
297 case HID_GLOBAL_ITEM_TAG_PUSH:
295 298
296 case HID_GLOBAL_ITEM_TAG_PUSH: 299 if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) {
297 300 dbg_hid("global enviroment stack overflow\n");
298 if (parser->global_stack_ptr == HID_GLOBAL_STACK_SIZE) { 301 return -1;
299 dbg_hid("global enviroment stack overflow\n"); 302 }
300 return -1;
301 }
302 303
303 memcpy(parser->global_stack + parser->global_stack_ptr++, 304 memcpy(parser->global_stack + parser->global_stack_ptr++,
304 &parser->global, sizeof(struct hid_global)); 305 &parser->global, sizeof(struct hid_global));
305 return 0; 306 return 0;
306 307
307 case HID_GLOBAL_ITEM_TAG_POP: 308 case HID_GLOBAL_ITEM_TAG_POP:
308 309
309 if (!parser->global_stack_ptr) { 310 if (!parser->global_stack_ptr) {
310 dbg_hid("global enviroment stack underflow\n"); 311 dbg_hid("global enviroment stack underflow\n");
311 return -1; 312 return -1;
312 } 313 }
313
314 memcpy(&parser->global, parser->global_stack + --parser->global_stack_ptr,
315 sizeof(struct hid_global));
316 return 0;
317 314
318 case HID_GLOBAL_ITEM_TAG_USAGE_PAGE: 315 memcpy(&parser->global, parser->global_stack +
319 parser->global.usage_page = item_udata(item); 316 --parser->global_stack_ptr, sizeof(struct hid_global));
320 return 0; 317 return 0;
321 318
322 case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM: 319 case HID_GLOBAL_ITEM_TAG_USAGE_PAGE:
323 parser->global.logical_minimum = item_sdata(item); 320 parser->global.usage_page = item_udata(item);
324 return 0; 321 return 0;
325 322
326 case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM: 323 case HID_GLOBAL_ITEM_TAG_LOGICAL_MINIMUM:
327 if (parser->global.logical_minimum < 0) 324 parser->global.logical_minimum = item_sdata(item);
328 parser->global.logical_maximum = item_sdata(item); 325 return 0;
329 else
330 parser->global.logical_maximum = item_udata(item);
331 return 0;
332 326
333 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM: 327 case HID_GLOBAL_ITEM_TAG_LOGICAL_MAXIMUM:
334 parser->global.physical_minimum = item_sdata(item); 328 if (parser->global.logical_minimum < 0)
335 return 0; 329 parser->global.logical_maximum = item_sdata(item);
330 else
331 parser->global.logical_maximum = item_udata(item);
332 return 0;
336 333
337 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM: 334 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MINIMUM:
338 if (parser->global.physical_minimum < 0) 335 parser->global.physical_minimum = item_sdata(item);
339 parser->global.physical_maximum = item_sdata(item); 336 return 0;
340 else
341 parser->global.physical_maximum = item_udata(item);
342 return 0;
343 337
344 case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT: 338 case HID_GLOBAL_ITEM_TAG_PHYSICAL_MAXIMUM:
345 parser->global.unit_exponent = item_sdata(item); 339 if (parser->global.physical_minimum < 0)
346 return 0; 340 parser->global.physical_maximum = item_sdata(item);
341 else
342 parser->global.physical_maximum = item_udata(item);
343 return 0;
347 344
348 case HID_GLOBAL_ITEM_TAG_UNIT: 345 case HID_GLOBAL_ITEM_TAG_UNIT_EXPONENT:
349 parser->global.unit = item_udata(item); 346 parser->global.unit_exponent = item_sdata(item);
350 return 0; 347 return 0;
351 348
352 case HID_GLOBAL_ITEM_TAG_REPORT_SIZE: 349 case HID_GLOBAL_ITEM_TAG_UNIT:
353 if ((parser->global.report_size = item_udata(item)) > 32) { 350 parser->global.unit = item_udata(item);
354 dbg_hid("invalid report_size %d\n", parser->global.report_size); 351 return 0;
355 return -1;
356 }
357 return 0;
358 352
359 case HID_GLOBAL_ITEM_TAG_REPORT_COUNT: 353 case HID_GLOBAL_ITEM_TAG_REPORT_SIZE:
360 if ((parser->global.report_count = item_udata(item)) > HID_MAX_USAGES) { 354 parser->global.report_size = item_udata(item);
361 dbg_hid("invalid report_count %d\n", parser->global.report_count); 355 if (parser->global.report_size > 32) {
362 return -1; 356 dbg_hid("invalid report_size %d\n",
363 } 357 parser->global.report_size);
364 return 0; 358 return -1;
359 }
360 return 0;
365 361
366 case HID_GLOBAL_ITEM_TAG_REPORT_ID: 362 case HID_GLOBAL_ITEM_TAG_REPORT_COUNT:
367 if ((parser->global.report_id = item_udata(item)) == 0) { 363 parser->global.report_count = item_udata(item);
368 dbg_hid("report_id 0 is invalid\n"); 364 if (parser->global.report_count > HID_MAX_USAGES) {
369 return -1; 365 dbg_hid("invalid report_count %d\n",
370 } 366 parser->global.report_count);
371 return 0; 367 return -1;
368 }
369 return 0;
372 370
373 default: 371 case HID_GLOBAL_ITEM_TAG_REPORT_ID:
374 dbg_hid("unknown global tag 0x%x\n", item->tag); 372 parser->global.report_id = item_udata(item);
373 if (parser->global.report_id == 0) {
374 dbg_hid("report_id 0 is invalid\n");
375 return -1; 375 return -1;
376 }
377 return 0;
378
379 default:
380 dbg_hid("unknown global tag 0x%x\n", item->tag);
381 return -1;
376 } 382 }
377} 383}
378 384
@@ -393,77 +399,76 @@ static int hid_parser_local(struct hid_parser *parser, struct hid_item *item)
393 data = item_udata(item); 399 data = item_udata(item);
394 400
395 switch (item->tag) { 401 switch (item->tag) {
396 402 case HID_LOCAL_ITEM_TAG_DELIMITER:
397 case HID_LOCAL_ITEM_TAG_DELIMITER: 403
398 404 if (data) {
399 if (data) { 405 /*
400 /* 406 * We treat items before the first delimiter
401 * We treat items before the first delimiter 407 * as global to all usage sets (branch 0).
402 * as global to all usage sets (branch 0). 408 * In the moment we process only these global
403 * In the moment we process only these global 409 * items and the first delimiter set.
404 * items and the first delimiter set. 410 */
405 */ 411 if (parser->local.delimiter_depth != 0) {
406 if (parser->local.delimiter_depth != 0) { 412 dbg_hid("nested delimiters\n");
407 dbg_hid("nested delimiters\n"); 413 return -1;
408 return -1;
409 }
410 parser->local.delimiter_depth++;
411 parser->local.delimiter_branch++;
412 } else {
413 if (parser->local.delimiter_depth < 1) {
414 dbg_hid("bogus close delimiter\n");
415 return -1;
416 }
417 parser->local.delimiter_depth--;
418 } 414 }
419 return 1; 415 parser->local.delimiter_depth++;
420 416 parser->local.delimiter_branch++;
421 case HID_LOCAL_ITEM_TAG_USAGE: 417 } else {
422 418 if (parser->local.delimiter_depth < 1) {
423 if (parser->local.delimiter_branch > 1) { 419 dbg_hid("bogus close delimiter\n");
424 dbg_hid("alternative usage ignored\n"); 420 return -1;
425 return 0;
426 } 421 }
422 parser->local.delimiter_depth--;
423 }
424 return 1;
427 425
428 if (item->size <= 2) 426 case HID_LOCAL_ITEM_TAG_USAGE:
429 data = (parser->global.usage_page << 16) + data;
430 427
431 return hid_add_usage(parser, data); 428 if (parser->local.delimiter_branch > 1) {
429 dbg_hid("alternative usage ignored\n");
430 return 0;
431 }
432 432
433 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM: 433 if (item->size <= 2)
434 data = (parser->global.usage_page << 16) + data;
434 435
435 if (parser->local.delimiter_branch > 1) { 436 return hid_add_usage(parser, data);
436 dbg_hid("alternative usage ignored\n");
437 return 0;
438 }
439 437
440 if (item->size <= 2) 438 case HID_LOCAL_ITEM_TAG_USAGE_MINIMUM:
441 data = (parser->global.usage_page << 16) + data;
442 439
443 parser->local.usage_minimum = data; 440 if (parser->local.delimiter_branch > 1) {
441 dbg_hid("alternative usage ignored\n");
444 return 0; 442 return 0;
443 }
445 444
446 case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM: 445 if (item->size <= 2)
446 data = (parser->global.usage_page << 16) + data;
447 447
448 if (parser->local.delimiter_branch > 1) { 448 parser->local.usage_minimum = data;
449 dbg_hid("alternative usage ignored\n"); 449 return 0;
450 return 0;
451 }
452 450
453 if (item->size <= 2) 451 case HID_LOCAL_ITEM_TAG_USAGE_MAXIMUM:
454 data = (parser->global.usage_page << 16) + data;
455 452
456 for (n = parser->local.usage_minimum; n <= data; n++) 453 if (parser->local.delimiter_branch > 1) {
457 if (hid_add_usage(parser, n)) { 454 dbg_hid("alternative usage ignored\n");
458 dbg_hid("hid_add_usage failed\n");
459 return -1;
460 }
461 return 0; 455 return 0;
456 }
462 457
463 default: 458 if (item->size <= 2)
459 data = (parser->global.usage_page << 16) + data;
464 460
465 dbg_hid("unknown local item tag 0x%x\n", item->tag); 461 for (n = parser->local.usage_minimum; n <= data; n++)
466 return 0; 462 if (hid_add_usage(parser, n)) {
463 dbg_hid("hid_add_usage failed\n");
464 return -1;
465 }
466 return 0;
467
468 default:
469
470 dbg_hid("unknown local item tag 0x%x\n", item->tag);
471 return 0;
467 } 472 }
468 return 0; 473 return 0;
469} 474}
@@ -480,24 +485,24 @@ static int hid_parser_main(struct hid_parser *parser, struct hid_item *item)
480 data = item_udata(item); 485 data = item_udata(item);
481 486
482 switch (item->tag) { 487 switch (item->tag) {
483 case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION: 488 case HID_MAIN_ITEM_TAG_BEGIN_COLLECTION:
484 ret = open_collection(parser, data & 0xff); 489 ret = open_collection(parser, data & 0xff);
485 break; 490 break;
486 case HID_MAIN_ITEM_TAG_END_COLLECTION: 491 case HID_MAIN_ITEM_TAG_END_COLLECTION:
487 ret = close_collection(parser); 492 ret = close_collection(parser);
488 break; 493 break;
489 case HID_MAIN_ITEM_TAG_INPUT: 494 case HID_MAIN_ITEM_TAG_INPUT:
490 ret = hid_add_field(parser, HID_INPUT_REPORT, data); 495 ret = hid_add_field(parser, HID_INPUT_REPORT, data);
491 break; 496 break;
492 case HID_MAIN_ITEM_TAG_OUTPUT: 497 case HID_MAIN_ITEM_TAG_OUTPUT:
493 ret = hid_add_field(parser, HID_OUTPUT_REPORT, data); 498 ret = hid_add_field(parser, HID_OUTPUT_REPORT, data);
494 break; 499 break;
495 case HID_MAIN_ITEM_TAG_FEATURE: 500 case HID_MAIN_ITEM_TAG_FEATURE:
496 ret = hid_add_field(parser, HID_FEATURE_REPORT, data); 501 ret = hid_add_field(parser, HID_FEATURE_REPORT, data);
497 break; 502 break;
498 default: 503 default:
499 dbg_hid("unknown main item tag 0x%x\n", item->tag); 504 dbg_hid("unknown main item tag 0x%x\n", item->tag);
500 ret = 0; 505 ret = 0;
501 } 506 }
502 507
503 memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */ 508 memset(&parser->local, 0, sizeof(parser->local)); /* Reset the local parser environment */
@@ -534,9 +539,10 @@ static void hid_free_report(struct hid_report *report)
534 * Free a device structure, all reports, and all fields. 539 * Free a device structure, all reports, and all fields.
535 */ 540 */
536 541
537void hid_free_device(struct hid_device *device) 542static void hid_device_release(struct device *dev)
538{ 543{
539 unsigned i,j; 544 struct hid_device *device = container_of(dev, struct hid_device, dev);
545 unsigned i, j;
540 546
541 for (i = 0; i < HID_REPORT_TYPES; i++) { 547 for (i = 0; i < HID_REPORT_TYPES; i++) {
542 struct hid_report_enum *report_enum = device->report_enum + i; 548 struct hid_report_enum *report_enum = device->report_enum + i;
@@ -552,7 +558,6 @@ void hid_free_device(struct hid_device *device)
552 kfree(device->collection); 558 kfree(device->collection);
553 kfree(device); 559 kfree(device);
554} 560}
555EXPORT_SYMBOL_GPL(hid_free_device);
556 561
557/* 562/*
558 * Fetch a report description item from the data stream. We support long 563 * Fetch a report description item from the data stream. We support long
@@ -593,47 +598,52 @@ static u8 *fetch_item(__u8 *start, __u8 *end, struct hid_item *item)
593 item->size = b & 3; 598 item->size = b & 3;
594 599
595 switch (item->size) { 600 switch (item->size) {
601 case 0:
602 return start;
596 603
597 case 0: 604 case 1:
598 return start; 605 if ((end - start) < 1)
599 606 return NULL;
600 case 1: 607 item->data.u8 = *start++;
601 if ((end - start) < 1) 608 return start;
602 return NULL;
603 item->data.u8 = *start++;
604 return start;
605 609
606 case 2: 610 case 2:
607 if ((end - start) < 2) 611 if ((end - start) < 2)
608 return NULL; 612 return NULL;
609 item->data.u16 = get_unaligned_le16(start); 613 item->data.u16 = get_unaligned_le16(start);
610 start = (__u8 *)((__le16 *)start + 1); 614 start = (__u8 *)((__le16 *)start + 1);
611 return start; 615 return start;
612 616
613 case 3: 617 case 3:
614 item->size++; 618 item->size++;
615 if ((end - start) < 4) 619 if ((end - start) < 4)
616 return NULL; 620 return NULL;
617 item->data.u32 = get_unaligned_le32(start); 621 item->data.u32 = get_unaligned_le32(start);
618 start = (__u8 *)((__le32 *)start + 1); 622 start = (__u8 *)((__le32 *)start + 1);
619 return start; 623 return start;
620 } 624 }
621 625
622 return NULL; 626 return NULL;
623} 627}
624 628
625/* 629/**
630 * hid_parse_report - parse device report
631 *
632 * @device: hid device
633 * @start: report start
634 * @size: report size
635 *
626 * Parse a report description into a hid_device structure. Reports are 636 * Parse a report description into a hid_device structure. Reports are
627 * enumerated, fields are attached to these reports. 637 * enumerated, fields are attached to these reports.
638 * 0 returned on success, otherwise nonzero error value.
628 */ 639 */
629 640int hid_parse_report(struct hid_device *device, __u8 *start,
630struct hid_device *hid_parse_report(__u8 *start, unsigned size) 641 unsigned size)
631{ 642{
632 struct hid_device *device;
633 struct hid_parser *parser; 643 struct hid_parser *parser;
634 struct hid_item item; 644 struct hid_item item;
635 __u8 *end; 645 __u8 *end;
636 unsigned i; 646 int ret;
637 static int (*dispatch_type[])(struct hid_parser *parser, 647 static int (*dispatch_type[])(struct hid_parser *parser,
638 struct hid_item *item) = { 648 struct hid_item *item) = {
639 hid_parser_main, 649 hid_parser_main,
@@ -642,76 +652,57 @@ struct hid_device *hid_parse_report(__u8 *start, unsigned size)
642 hid_parser_reserved 652 hid_parser_reserved
643 }; 653 };
644 654
645 if (!(device = kzalloc(sizeof(struct hid_device), GFP_KERNEL))) 655 if (device->driver->report_fixup)
646 return NULL; 656 device->driver->report_fixup(device, start, size);
647 657
648 if (!(device->collection = kzalloc(sizeof(struct hid_collection) * 658 device->rdesc = kmalloc(size, GFP_KERNEL);
649 HID_DEFAULT_NUM_COLLECTIONS, GFP_KERNEL))) { 659 if (device->rdesc == NULL)
650 kfree(device); 660 return -ENOMEM;
651 return NULL;
652 }
653 device->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
654
655 for (i = 0; i < HID_REPORT_TYPES; i++)
656 INIT_LIST_HEAD(&device->report_enum[i].report_list);
657
658 if (!(device->rdesc = kmalloc(size, GFP_KERNEL))) {
659 kfree(device->collection);
660 kfree(device);
661 return NULL;
662 }
663 memcpy(device->rdesc, start, size); 661 memcpy(device->rdesc, start, size);
664 device->rsize = size; 662 device->rsize = size;
665 663
666 if (!(parser = vmalloc(sizeof(struct hid_parser)))) { 664 parser = vmalloc(sizeof(struct hid_parser));
667 kfree(device->rdesc); 665 if (!parser) {
668 kfree(device->collection); 666 ret = -ENOMEM;
669 kfree(device); 667 goto err;
670 return NULL;
671 } 668 }
669
672 memset(parser, 0, sizeof(struct hid_parser)); 670 memset(parser, 0, sizeof(struct hid_parser));
673 parser->device = device; 671 parser->device = device;
674 672
675 end = start + size; 673 end = start + size;
674 ret = -EINVAL;
676 while ((start = fetch_item(start, end, &item)) != NULL) { 675 while ((start = fetch_item(start, end, &item)) != NULL) {
677 676
678 if (item.format != HID_ITEM_FORMAT_SHORT) { 677 if (item.format != HID_ITEM_FORMAT_SHORT) {
679 dbg_hid("unexpected long global item\n"); 678 dbg_hid("unexpected long global item\n");
680 hid_free_device(device); 679 goto err;
681 vfree(parser);
682 return NULL;
683 } 680 }
684 681
685 if (dispatch_type[item.type](parser, &item)) { 682 if (dispatch_type[item.type](parser, &item)) {
686 dbg_hid("item %u %u %u %u parsing failed\n", 683 dbg_hid("item %u %u %u %u parsing failed\n",
687 item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag); 684 item.format, (unsigned)item.size, (unsigned)item.type, (unsigned)item.tag);
688 hid_free_device(device); 685 goto err;
689 vfree(parser);
690 return NULL;
691 } 686 }
692 687
693 if (start == end) { 688 if (start == end) {
694 if (parser->collection_stack_ptr) { 689 if (parser->collection_stack_ptr) {
695 dbg_hid("unbalanced collection at end of report description\n"); 690 dbg_hid("unbalanced collection at end of report description\n");
696 hid_free_device(device); 691 goto err;
697 vfree(parser);
698 return NULL;
699 } 692 }
700 if (parser->local.delimiter_depth) { 693 if (parser->local.delimiter_depth) {
701 dbg_hid("unbalanced delimiter at end of report description\n"); 694 dbg_hid("unbalanced delimiter at end of report description\n");
702 hid_free_device(device); 695 goto err;
703 vfree(parser);
704 return NULL;
705 } 696 }
706 vfree(parser); 697 vfree(parser);
707 return device; 698 return 0;
708 } 699 }
709 } 700 }
710 701
711 dbg_hid("item fetching failed at offset %d\n", (int)(end - start)); 702 dbg_hid("item fetching failed at offset %d\n", (int)(end - start));
712 hid_free_device(device); 703err:
713 vfree(parser); 704 vfree(parser);
714 return NULL; 705 return ret;
715} 706}
716EXPORT_SYMBOL_GPL(hid_parse_report); 707EXPORT_SYMBOL_GPL(hid_parse_report);
717 708
@@ -724,9 +715,9 @@ EXPORT_SYMBOL_GPL(hid_parse_report);
724static s32 snto32(__u32 value, unsigned n) 715static s32 snto32(__u32 value, unsigned n)
725{ 716{
726 switch (n) { 717 switch (n) {
727 case 8: return ((__s8)value); 718 case 8: return ((__s8)value);
728 case 16: return ((__s16)value); 719 case 16: return ((__s16)value);
729 case 32: return ((__s32)value); 720 case 32: return ((__s32)value);
730 } 721 }
731 return value & (1 << (n - 1)) ? value | (-1 << n) : value; 722 return value & (1 << (n - 1)) ? value | (-1 << n) : value;
732} 723}
@@ -815,9 +806,73 @@ static __inline__ int search(__s32 *array, __s32 value, unsigned n)
815 return -1; 806 return -1;
816} 807}
817 808
818static void hid_process_event(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value, int interrupt) 809/**
810 * hid_match_report - check if driver's raw_event should be called
811 *
812 * @hid: hid device
813 * @report_type: type to match against
814 *
815 * compare hid->driver->report_table->report_type to report->type
816 */
817static int hid_match_report(struct hid_device *hid, struct hid_report *report)
818{
819 const struct hid_report_id *id = hid->driver->report_table;
820
821 if (!id) /* NULL means all */
822 return 1;
823
824 for (; id->report_type != HID_TERMINATOR; id++)
825 if (id->report_type == HID_ANY_ID ||
826 id->report_type == report->type)
827 return 1;
828 return 0;
829}
830
831/**
832 * hid_match_usage - check if driver's event should be called
833 *
834 * @hid: hid device
835 * @usage: usage to match against
836 *
837 * compare hid->driver->usage_table->usage_{type,code} to
838 * usage->usage_{type,code}
839 */
840static int hid_match_usage(struct hid_device *hid, struct hid_usage *usage)
819{ 841{
842 const struct hid_usage_id *id = hid->driver->usage_table;
843
844 if (!id) /* NULL means all */
845 return 1;
846
847 for (; id->usage_type != HID_ANY_ID - 1; id++)
848 if ((id->usage_hid == HID_ANY_ID ||
849 id->usage_hid == usage->hid) &&
850 (id->usage_type == HID_ANY_ID ||
851 id->usage_type == usage->type) &&
852 (id->usage_code == HID_ANY_ID ||
853 id->usage_code == usage->code))
854 return 1;
855 return 0;
856}
857
858static void hid_process_event(struct hid_device *hid, struct hid_field *field,
859 struct hid_usage *usage, __s32 value, int interrupt)
860{
861 struct hid_driver *hdrv = hid->driver;
862 int ret;
863
820 hid_dump_input(usage, value); 864 hid_dump_input(usage, value);
865
866 if (hdrv && hdrv->event && hid_match_usage(hid, usage)) {
867 ret = hdrv->event(hid, field, usage, value);
868 if (ret != 0) {
869 if (ret < 0)
870 dbg_hid("%s's event failed with %d\n",
871 hdrv->name, ret);
872 return;
873 }
874 }
875
821 if (hid->claimed & HID_CLAIMED_INPUT) 876 if (hid->claimed & HID_CLAIMED_INPUT)
822 hidinput_hid_event(hid, field, usage, value); 877 hidinput_hid_event(hid, field, usage, value);
823 if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event) 878 if (hid->claimed & HID_CLAIMED_HIDDEV && interrupt && hid->hiddev_hid_event)
@@ -946,44 +1001,47 @@ int hid_set_field(struct hid_field *field, unsigned offset, __s32 value)
946} 1001}
947EXPORT_SYMBOL_GPL(hid_set_field); 1002EXPORT_SYMBOL_GPL(hid_set_field);
948 1003
949int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt) 1004static struct hid_report *hid_get_report(struct hid_report_enum *report_enum,
1005 const u8 *data)
950{ 1006{
951 struct hid_report_enum *report_enum = hid->report_enum + type;
952 struct hid_report *report; 1007 struct hid_report *report;
953 int n, rsize, i; 1008 unsigned int n = 0; /* Normally report number is 0 */
954 1009
955 if (!hid) 1010 /* Device uses numbered reports, data[0] is report number */
956 return -ENODEV; 1011 if (report_enum->numbered)
1012 n = *data;
957 1013
958 if (!size) { 1014 report = report_enum->report_id_hash[n];
959 dbg_hid("empty report\n"); 1015 if (report == NULL)
960 return -1; 1016 dbg_hid("undefined report_id %u received\n", n);
961 }
962 1017
963 dbg_hid("report (size %u) (%snumbered)\n", size, report_enum->numbered ? "" : "un"); 1018 return report;
1019}
964 1020
965 n = 0; /* Normally report number is 0 */ 1021void hid_report_raw_event(struct hid_device *hid, int type, u8 *data, int size,
966 if (report_enum->numbered) { /* Device uses numbered reports, data[0] is report number */ 1022 int interrupt)
967 n = *data++; 1023{
968 size--; 1024 struct hid_report_enum *report_enum = hid->report_enum + type;
969 } 1025 struct hid_report *report;
1026 unsigned int a;
1027 int rsize, csize = size;
1028 u8 *cdata = data;
970 1029
971 /* dump the report */ 1030 report = hid_get_report(report_enum, data);
972 dbg_hid("report %d (size %u) = ", n, size); 1031 if (!report)
973 for (i = 0; i < size; i++) 1032 return;
974 dbg_hid_line(" %02x", data[i]);
975 dbg_hid_line("\n");
976 1033
977 if (!(report = report_enum->report_id_hash[n])) { 1034 if (report_enum->numbered) {
978 dbg_hid("undefined report_id %d received\n", n); 1035 cdata++;
979 return -1; 1036 csize--;
980 } 1037 }
981 1038
982 rsize = ((report->size - 1) >> 3) + 1; 1039 rsize = ((report->size - 1) >> 3) + 1;
983 1040
984 if (size < rsize) { 1041 if (csize < rsize) {
985 dbg_hid("report %d is too short, (%d < %d)\n", report->id, size, rsize); 1042 dbg_hid("report %d is too short, (%d < %d)\n", report->id,
986 memset(data + size, 0, rsize - size); 1043 csize, rsize);
1044 memset(cdata + csize, 0, rsize - csize);
987 } 1045 }
988 1046
989 if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event) 1047 if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_report_event)
@@ -996,24 +1054,663 @@ int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int i
996 hidraw_report_event(hid, data, size); 1054 hidraw_report_event(hid, data, size);
997 } 1055 }
998 1056
999 for (n = 0; n < report->maxfield; n++) 1057 for (a = 0; a < report->maxfield; a++)
1000 hid_input_field(hid, report->field[n], data, interrupt); 1058 hid_input_field(hid, report->field[a], cdata, interrupt);
1001 1059
1002 if (hid->claimed & HID_CLAIMED_INPUT) 1060 if (hid->claimed & HID_CLAIMED_INPUT)
1003 hidinput_report_event(hid, report); 1061 hidinput_report_event(hid, report);
1062}
1063EXPORT_SYMBOL_GPL(hid_report_raw_event);
1064
1065/**
1066 * hid_input_report - report data from lower layer (usb, bt...)
1067 *
1068 * @hid: hid device
1069 * @type: HID report type (HID_*_REPORT)
1070 * @data: report contents
1071 * @size: size of data parameter
1072 * @interrupt: called from atomic?
1073 *
1074 * This is data entry for lower layers.
1075 */
1076int hid_input_report(struct hid_device *hid, int type, u8 *data, int size, int interrupt)
1077{
1078 struct hid_report_enum *report_enum = hid->report_enum + type;
1079 struct hid_driver *hdrv = hid->driver;
1080 struct hid_report *report;
1081 unsigned int i;
1082 int ret;
1083
1084 if (!hid || !hid->driver)
1085 return -ENODEV;
1086
1087 if (!size) {
1088 dbg_hid("empty report\n");
1089 return -1;
1090 }
1091
1092 dbg_hid("report (size %u) (%snumbered)\n", size, report_enum->numbered ? "" : "un");
1093
1094 report = hid_get_report(report_enum, data);
1095 if (!report)
1096 return -1;
1097
1098 /* dump the report */
1099 dbg_hid("report %d (size %u) = ", report->id, size);
1100 for (i = 0; i < size; i++)
1101 dbg_hid_line(" %02x", data[i]);
1102 dbg_hid_line("\n");
1103
1104 if (hdrv && hdrv->raw_event && hid_match_report(hid, report)) {
1105 ret = hdrv->raw_event(hid, report, data, size);
1106 if (ret != 0)
1107 return ret < 0 ? ret : 0;
1108 }
1109
1110 hid_report_raw_event(hid, type, data, size, interrupt);
1004 1111
1005 return 0; 1112 return 0;
1006} 1113}
1007EXPORT_SYMBOL_GPL(hid_input_report); 1114EXPORT_SYMBOL_GPL(hid_input_report);
1008 1115
1116static bool hid_match_one_id(struct hid_device *hdev,
1117 const struct hid_device_id *id)
1118{
1119 return id->bus == hdev->bus &&
1120 (id->vendor == HID_ANY_ID || id->vendor == hdev->vendor) &&
1121 (id->product == HID_ANY_ID || id->product == hdev->product);
1122}
1123
1124static const struct hid_device_id *hid_match_id(struct hid_device *hdev,
1125 const struct hid_device_id *id)
1126{
1127 for (; id->bus; id++)
1128 if (hid_match_one_id(hdev, id))
1129 return id;
1130
1131 return NULL;
1132}
1133
1134static const struct hid_device_id hid_hiddev_list[] = {
1135 { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS) },
1136 { HID_USB_DEVICE(USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1) },
1137 { }
1138};
1139
1140static bool hid_hiddev(struct hid_device *hdev)
1141{
1142 return !!hid_match_id(hdev, hid_hiddev_list);
1143}
1144
1145int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
1146{
1147 static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
1148 "Joystick", "Gamepad", "Keyboard", "Keypad",
1149 "Multi-Axis Controller"
1150 };
1151 const char *type, *bus;
1152 char buf[64];
1153 unsigned int i;
1154 int len;
1155
1156 if (hdev->bus != BUS_USB)
1157 connect_mask &= ~HID_CONNECT_HIDDEV;
1158 if (hid_hiddev(hdev))
1159 connect_mask |= HID_CONNECT_HIDDEV_FORCE;
1160
1161 if ((connect_mask & HID_CONNECT_HIDINPUT) && !hidinput_connect(hdev,
1162 connect_mask & HID_CONNECT_HIDINPUT_FORCE))
1163 hdev->claimed |= HID_CLAIMED_INPUT;
1164 if ((connect_mask & HID_CONNECT_HIDDEV) && hdev->hiddev_connect &&
1165 !hdev->hiddev_connect(hdev,
1166 connect_mask & HID_CONNECT_HIDDEV_FORCE))
1167 hdev->claimed |= HID_CLAIMED_HIDDEV;
1168 if ((connect_mask & HID_CONNECT_HIDRAW) && !hidraw_connect(hdev))
1169 hdev->claimed |= HID_CLAIMED_HIDRAW;
1170
1171 if (!hdev->claimed) {
1172 dev_err(&hdev->dev, "claimed by neither input, hiddev nor "
1173 "hidraw\n");
1174 return -ENODEV;
1175 }
1176
1177 if ((hdev->claimed & HID_CLAIMED_INPUT) &&
1178 (connect_mask & HID_CONNECT_FF) && hdev->ff_init)
1179 hdev->ff_init(hdev);
1180
1181 len = 0;
1182 if (hdev->claimed & HID_CLAIMED_INPUT)
1183 len += sprintf(buf + len, "input");
1184 if (hdev->claimed & HID_CLAIMED_HIDDEV)
1185 len += sprintf(buf + len, "%shiddev%d", len ? "," : "",
1186 hdev->minor);
1187 if (hdev->claimed & HID_CLAIMED_HIDRAW)
1188 len += sprintf(buf + len, "%shidraw%d", len ? "," : "",
1189 ((struct hidraw *)hdev->hidraw)->minor);
1190
1191 type = "Device";
1192 for (i = 0; i < hdev->maxcollection; i++) {
1193 struct hid_collection *col = &hdev->collection[i];
1194 if (col->type == HID_COLLECTION_APPLICATION &&
1195 (col->usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
1196 (col->usage & 0xffff) < ARRAY_SIZE(types)) {
1197 type = types[col->usage & 0xffff];
1198 break;
1199 }
1200 }
1201
1202 switch (hdev->bus) {
1203 case BUS_USB:
1204 bus = "USB";
1205 break;
1206 case BUS_BLUETOOTH:
1207 bus = "BLUETOOTH";
1208 break;
1209 default:
1210 bus = "<UNKNOWN>";
1211 }
1212
1213 dev_info(&hdev->dev, "%s: %s HID v%x.%02x %s [%s] on %s\n",
1214 buf, bus, hdev->version >> 8, hdev->version & 0xff,
1215 type, hdev->name, hdev->phys);
1216
1217 return 0;
1218}
1219EXPORT_SYMBOL_GPL(hid_connect);
1220
1221static const struct hid_device_id hid_blacklist[] = {
1222 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) },
1223 { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) },
1224 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) },
1225 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) },
1226 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) },
1227 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) },
1228 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) },
1229 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI) },
1230 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO) },
1231 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS) },
1232 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI) },
1233 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO) },
1234 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS) },
1235 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI) },
1236 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO) },
1237 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS) },
1238 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI) },
1239 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO) },
1240 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS) },
1241 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI) },
1242 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO) },
1243 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS) },
1244 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI) },
1245 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO) },
1246 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS) },
1247 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI) },
1248 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO) },
1249 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS) },
1250 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI) },
1251 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO) },
1252 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS) },
1253 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY) },
1254 { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY) },
1255 { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) },
1256 { HID_USB_DEVICE(USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM) },
1257 { HID_USB_DEVICE(USB_VENDOR_ID_BRIGHT, USB_DEVICE_ID_BRIGHT_ABNT2) },
1258 { HID_USB_DEVICE(USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION) },
1259 { HID_USB_DEVICE(USB_VENDOR_ID_CHICONY, USB_DEVICE_ID_CHICONY_TACTICAL_PAD) },
1260 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1) },
1261 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2) },
1262 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE) },
1263 { HID_USB_DEVICE(USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_W7658) },
1264 { HID_USB_DEVICE(USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_SK8115) },
1265 { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
1266 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
1267 { HID_USB_DEVICE(USB_VENDOR_ID_LABTEC, USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD) },
1268 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER) },
1269 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER) },
1270 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2) },
1271 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER) },
1272 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP) },
1273 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE) },
1274 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI) },
1275 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_KBD) },
1276 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD) },
1277 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500) },
1278 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_LX3) },
1279 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_V150) },
1280 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D) },
1281 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL) },
1282 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD) },
1283 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2) },
1284 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D) },
1285 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO) },
1286 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL) },
1287 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2) },
1288 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2) },
1289 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV) },
1290 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K) },
1291 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K) },
1292 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB) },
1293 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0) },
1294 { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
1295 { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
1296 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
1297 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
1298 { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
1299
1300 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_APPLE, 0x030c) },
1301 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT) },
1302 { }
1303};
1304
1305static int hid_bus_match(struct device *dev, struct device_driver *drv)
1306{
1307 struct hid_driver *hdrv = container_of(drv, struct hid_driver, driver);
1308 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1309
1310 if (!hid_match_id(hdev, hdrv->id_table))
1311 return 0;
1312
1313 /* generic wants all non-blacklisted */
1314 if (!strncmp(hdrv->name, "generic-", 8))
1315 return !hid_match_id(hdev, hid_blacklist);
1316
1317 return 1;
1318}
1319
1320static int hid_device_probe(struct device *dev)
1321{
1322 struct hid_driver *hdrv = container_of(dev->driver,
1323 struct hid_driver, driver);
1324 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1325 const struct hid_device_id *id;
1326 int ret = 0;
1327
1328 if (!hdev->driver) {
1329 id = hid_match_id(hdev, hdrv->id_table);
1330 if (id == NULL)
1331 return -ENODEV;
1332
1333 hdev->driver = hdrv;
1334 if (hdrv->probe) {
1335 ret = hdrv->probe(hdev, id);
1336 } else { /* default probe */
1337 ret = hid_parse(hdev);
1338 if (!ret)
1339 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
1340 }
1341 if (ret)
1342 hdev->driver = NULL;
1343 }
1344 return ret;
1345}
1346
1347static int hid_device_remove(struct device *dev)
1348{
1349 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1350 struct hid_driver *hdrv = hdev->driver;
1351
1352 if (hdrv) {
1353 if (hdrv->remove)
1354 hdrv->remove(hdev);
1355 else /* default remove */
1356 hid_hw_stop(hdev);
1357 hdev->driver = NULL;
1358 }
1359
1360 return 0;
1361}
1362
1363static int hid_uevent(struct device *dev, struct kobj_uevent_env *env)
1364{
1365 struct hid_device *hdev = container_of(dev, struct hid_device, dev);
1366
1367 if (add_uevent_var(env, "HID_ID=%04X:%08X:%08X",
1368 hdev->bus, hdev->vendor, hdev->product))
1369 return -ENOMEM;
1370
1371 if (add_uevent_var(env, "HID_NAME=%s", hdev->name))
1372 return -ENOMEM;
1373
1374 if (add_uevent_var(env, "HID_PHYS=%s", hdev->phys))
1375 return -ENOMEM;
1376
1377 if (add_uevent_var(env, "HID_UNIQ=%s", hdev->uniq))
1378 return -ENOMEM;
1379
1380 if (add_uevent_var(env, "MODALIAS=hid:b%04Xv%08Xp%08X",
1381 hdev->bus, hdev->vendor, hdev->product))
1382 return -ENOMEM;
1383
1384 return 0;
1385}
1386
1387static struct bus_type hid_bus_type = {
1388 .name = "hid",
1389 .match = hid_bus_match,
1390 .probe = hid_device_probe,
1391 .remove = hid_device_remove,
1392 .uevent = hid_uevent,
1393};
1394
1395static const struct hid_device_id hid_ignore_list[] = {
1396 { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR) },
1397 { HID_USB_DEVICE(USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302) },
1398 { HID_USB_DEVICE(USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X) },
1399 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01) },
1400 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10) },
1401 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20) },
1402 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21) },
1403 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22) },
1404 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23) },
1405 { HID_USB_DEVICE(USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24) },
1406 { HID_USB_DEVICE(USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1) },
1407 { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) },
1408 { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_LCM)},
1409 { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) },
1410 { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) },
1411 { HID_USB_DEVICE(USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X) },
1412 { HID_USB_DEVICE(USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109) },
1413 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM) },
1414 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE) },
1415 { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE) },
1416 { HID_USB_DEVICE(USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20) },
1417 { HID_USB_DEVICE(USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5) },
1418 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR) },
1419 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0001) },
1420 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0002) },
1421 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0003) },
1422 { HID_USB_DEVICE(USB_VENDOR_ID_GENERAL_TOUCH, 0x0004) },
1423 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30) },
1424 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30) },
1425 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT) },
1426 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT) },
1427 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT) },
1428 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT) },
1429 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT) },
1430 { HID_USB_DEVICE(USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL) },
1431 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2) },
1432 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN) },
1433 { HID_USB_DEVICE(USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER) },
1434 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003) },
1435 { HID_USB_DEVICE(USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY) },
1436 { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE) },
1437 { HID_USB_DEVICE(USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB) },
1438 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90) },
1439 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100) },
1440 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101) },
1441 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103) },
1442 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104) },
1443 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105) },
1444 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106) },
1445 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107) },
1446 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108) },
1447 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200) },
1448 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201) },
1449 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202) },
1450 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203) },
1451 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204) },
1452 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205) },
1453 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206) },
1454 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207) },
1455 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300) },
1456 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301) },
1457 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302) },
1458 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303) },
1459 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304) },
1460 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305) },
1461 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306) },
1462 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307) },
1463 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308) },
1464 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309) },
1465 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400) },
1466 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401) },
1467 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402) },
1468 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403) },
1469 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404) },
1470 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405) },
1471 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500) },
1472 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501) },
1473 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502) },
1474 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503) },
1475 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504) },
1476 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000) },
1477 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001) },
1478 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002) },
1479 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003) },
1480 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004) },
1481 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005) },
1482 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006) },
1483 { HID_USB_DEVICE(USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007) },
1484 { HID_USB_DEVICE(USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA) },
1485 { HID_USB_DEVICE(USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO) },
1486 { HID_USB_DEVICE(USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560) },
1487 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY) },
1488 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY) },
1489 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY) },
1490 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM) },
1491 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP) },
1492 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP) },
1493 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1) },
1494 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2) },
1495 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM) },
1496 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB) },
1497 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT) },
1498 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER) },
1499 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL) },
1500 { HID_USB_DEVICE(USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST) },
1501 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS) },
1502 { HID_USB_DEVICE(USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS) },
1503 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1) },
1504 { HID_USB_DEVICE(USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2) },
1505 { HID_USB_DEVICE(USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY) },
1506 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100) },
1507 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20) },
1508 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30) },
1509 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100) },
1510 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108) },
1511 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118) },
1512 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200) },
1513 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300) },
1514 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400) },
1515 { HID_USB_DEVICE(USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500) },
1516 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0001) },
1517 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0002) },
1518 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0003) },
1519 { HID_USB_DEVICE(USB_VENDOR_ID_PANJIT, 0x0004) },
1520 { HID_USB_DEVICE(USB_VENDOR_ID_SOUNDGRAPH, USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD) },
1521 { HID_USB_DEVICE(USB_VENDOR_ID_SOUNDGRAPH, USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD2) },
1522 { HID_USB_DEVICE(USB_VENDOR_ID_SOUNDGRAPH, USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD3) },
1523 { HID_USB_DEVICE(USB_VENDOR_ID_TENX, USB_DEVICE_ID_TENX_IBUDDY1) },
1524 { HID_USB_DEVICE(USB_VENDOR_ID_TENX, USB_DEVICE_ID_TENX_IBUDDY2) },
1525 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) },
1526 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304) },
1527 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651) },
1528 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654) },
1529 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO) },
1530 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP) },
1531 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP) },
1532 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS) },
1533 { HID_USB_DEVICE(USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC) },
1534 { HID_USB_DEVICE(USB_VENDOR_ID_WACOM, HID_ANY_ID) },
1535 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20) },
1536 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20) },
1537 { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT) },
1538 { HID_USB_DEVICE(USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K) },
1539 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
1540 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
1541 { }
1542};
1543
1544static bool hid_ignore(struct hid_device *hdev)
1545{
1546 switch (hdev->vendor) {
1547 case USB_VENDOR_ID_CODEMERCS:
1548 /* ignore all Code Mercenaries IOWarrior devices */
1549 if (hdev->product >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
1550 hdev->product <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
1551 return true;
1552 break;
1553 case USB_VENDOR_ID_LOGITECH:
1554 if (hdev->product >= USB_DEVICE_ID_LOGITECH_HARMONY_FIRST &&
1555 hdev->product <= USB_DEVICE_ID_LOGITECH_HARMONY_LAST)
1556 return true;
1557 break;
1558 }
1559
1560 return !!hid_match_id(hdev, hid_ignore_list);
1561}
1562
1563int hid_add_device(struct hid_device *hdev)
1564{
1565 static atomic_t id = ATOMIC_INIT(0);
1566 int ret;
1567
1568 if (WARN_ON(hdev->status & HID_STAT_ADDED))
1569 return -EBUSY;
1570
1571 /* we need to kill them here, otherwise they will stay allocated to
1572 * wait for coming driver */
1573 if (hid_ignore(hdev))
1574 return -ENODEV;
1575
1576 /* XXX hack, any other cleaner solution < 20 bus_id bytes? */
1577 sprintf(hdev->dev.bus_id, "%04X:%04X:%04X.%04X", hdev->bus,
1578 hdev->vendor, hdev->product, atomic_inc_return(&id));
1579
1580 ret = device_add(&hdev->dev);
1581 if (!ret)
1582 hdev->status |= HID_STAT_ADDED;
1583
1584 return ret;
1585}
1586EXPORT_SYMBOL_GPL(hid_add_device);
1587
1588/**
1589 * hid_allocate_device - allocate new hid device descriptor
1590 *
1591 * Allocate and initialize hid device, so that hid_destroy_device might be
1592 * used to free it.
1593 *
1594 * New hid_device pointer is returned on success, otherwise ERR_PTR encoded
1595 * error value.
1596 */
1597struct hid_device *hid_allocate_device(void)
1598{
1599 struct hid_device *hdev;
1600 unsigned int i;
1601 int ret = -ENOMEM;
1602
1603 hdev = kzalloc(sizeof(*hdev), GFP_KERNEL);
1604 if (hdev == NULL)
1605 return ERR_PTR(ret);
1606
1607 device_initialize(&hdev->dev);
1608 hdev->dev.release = hid_device_release;
1609 hdev->dev.bus = &hid_bus_type;
1610
1611 hdev->collection = kcalloc(HID_DEFAULT_NUM_COLLECTIONS,
1612 sizeof(struct hid_collection), GFP_KERNEL);
1613 if (hdev->collection == NULL)
1614 goto err;
1615 hdev->collection_size = HID_DEFAULT_NUM_COLLECTIONS;
1616
1617 for (i = 0; i < HID_REPORT_TYPES; i++)
1618 INIT_LIST_HEAD(&hdev->report_enum[i].report_list);
1619
1620 return hdev;
1621err:
1622 put_device(&hdev->dev);
1623 return ERR_PTR(ret);
1624}
1625EXPORT_SYMBOL_GPL(hid_allocate_device);
1626
1627static void hid_remove_device(struct hid_device *hdev)
1628{
1629 if (hdev->status & HID_STAT_ADDED) {
1630 device_del(&hdev->dev);
1631 hdev->status &= ~HID_STAT_ADDED;
1632 }
1633}
1634
1635/**
1636 * hid_destroy_device - free previously allocated device
1637 *
1638 * @hdev: hid device
1639 *
1640 * If you allocate hid_device through hid_allocate_device, you should ever
1641 * free by this function.
1642 */
1643void hid_destroy_device(struct hid_device *hdev)
1644{
1645 hid_remove_device(hdev);
1646 put_device(&hdev->dev);
1647}
1648EXPORT_SYMBOL_GPL(hid_destroy_device);
1649
1650int __hid_register_driver(struct hid_driver *hdrv, struct module *owner,
1651 const char *mod_name)
1652{
1653 hdrv->driver.name = hdrv->name;
1654 hdrv->driver.bus = &hid_bus_type;
1655 hdrv->driver.owner = owner;
1656 hdrv->driver.mod_name = mod_name;
1657
1658 return driver_register(&hdrv->driver);
1659}
1660EXPORT_SYMBOL_GPL(__hid_register_driver);
1661
1662void hid_unregister_driver(struct hid_driver *hdrv)
1663{
1664 driver_unregister(&hdrv->driver);
1665}
1666EXPORT_SYMBOL_GPL(hid_unregister_driver);
1667
1668#ifdef CONFIG_HID_COMPAT
1669static void hid_compat_load(struct work_struct *ws)
1670{
1671 request_module("hid-dummy");
1672}
1673static DECLARE_WORK(hid_compat_work, hid_compat_load);
1674static struct workqueue_struct *hid_compat_wq;
1675#endif
1676
1009static int __init hid_init(void) 1677static int __init hid_init(void)
1010{ 1678{
1011 return hidraw_init(); 1679 int ret;
1680
1681 ret = bus_register(&hid_bus_type);
1682 if (ret) {
1683 printk(KERN_ERR "HID: can't register hid bus\n");
1684 goto err;
1685 }
1686
1687 ret = hidraw_init();
1688 if (ret)
1689 goto err_bus;
1690
1691#ifdef CONFIG_HID_COMPAT
1692 hid_compat_wq = create_workqueue("hid_compat");
1693 if (!hid_compat_wq) {
1694 hidraw_exit();
1695 goto err;
1696 }
1697 queue_work(hid_compat_wq, &hid_compat_work);
1698#endif
1699
1700 return 0;
1701err_bus:
1702 bus_unregister(&hid_bus_type);
1703err:
1704 return ret;
1012} 1705}
1013 1706
1014static void __exit hid_exit(void) 1707static void __exit hid_exit(void)
1015{ 1708{
1709#ifdef CONFIG_HID_COMPAT
1710 destroy_workqueue(hid_compat_wq);
1711#endif
1016 hidraw_exit(); 1712 hidraw_exit();
1713 bus_unregister(&hid_bus_type);
1017} 1714}
1018 1715
1019module_init(hid_init); 1716module_init(hid_init);
diff --git a/drivers/hid/hid-cypress.c b/drivers/hid/hid-cypress.c
new file mode 100644
index 000000000000..5d69d27b935d
--- /dev/null
+++ b/drivers/hid/hid-cypress.c
@@ -0,0 +1,158 @@
1/*
2 * HID driver for some cypress "special" devices
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/hid.h>
21#include <linux/input.h>
22#include <linux/module.h>
23
24#include "hid-ids.h"
25
26#define CP_RDESC_SWAPPED_MIN_MAX 0x01
27#define CP_2WHEEL_MOUSE_HACK 0x02
28#define CP_2WHEEL_MOUSE_HACK_ON 0x04
29
30/*
31 * Some USB barcode readers from cypress have usage min and usage max in
32 * the wrong order
33 */
34static void cp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
35 unsigned int rsize)
36{
37 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
38 unsigned int i;
39
40 if (!(quirks & CP_RDESC_SWAPPED_MIN_MAX))
41 return;
42
43 for (i = 0; i < rsize - 4; i++)
44 if (rdesc[i] == 0x29 && rdesc[i + 2] == 0x19) {
45 __u8 tmp;
46
47 rdesc[i] = 0x19;
48 rdesc[i + 2] = 0x29;
49 tmp = rdesc[i + 3];
50 rdesc[i + 3] = rdesc[i + 1];
51 rdesc[i + 1] = tmp;
52 }
53}
54
55static int cp_input_mapped(struct hid_device *hdev, struct hid_input *hi,
56 struct hid_field *field, struct hid_usage *usage,
57 unsigned long **bit, int *max)
58{
59 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
60
61 if (!(quirks & CP_2WHEEL_MOUSE_HACK))
62 return 0;
63
64 if (usage->type == EV_REL && usage->code == REL_WHEEL)
65 set_bit(REL_HWHEEL, *bit);
66 if (usage->hid == 0x00090005)
67 return -1;
68
69 return 0;
70}
71
72static int cp_event(struct hid_device *hdev, struct hid_field *field,
73 struct hid_usage *usage, __s32 value)
74{
75 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
76
77 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
78 !usage->type || !(quirks & CP_2WHEEL_MOUSE_HACK))
79 return 0;
80
81 if (usage->hid == 0x00090005) {
82 if (value)
83 quirks |= CP_2WHEEL_MOUSE_HACK_ON;
84 else
85 quirks &= ~CP_2WHEEL_MOUSE_HACK_ON;
86 hid_set_drvdata(hdev, (void *)quirks);
87 return 1;
88 }
89
90 if (usage->code == REL_WHEEL && (quirks & CP_2WHEEL_MOUSE_HACK_ON)) {
91 struct input_dev *input = field->hidinput->input;
92
93 input_event(input, usage->type, REL_HWHEEL, value);
94 return 1;
95 }
96
97 return 0;
98}
99
100static int cp_probe(struct hid_device *hdev, const struct hid_device_id *id)
101{
102 unsigned long quirks = id->driver_data;
103 int ret;
104
105 hid_set_drvdata(hdev, (void *)quirks);
106
107 ret = hid_parse(hdev);
108 if (ret) {
109 dev_err(&hdev->dev, "parse failed\n");
110 goto err_free;
111 }
112
113 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
114 if (ret) {
115 dev_err(&hdev->dev, "hw start failed\n");
116 goto err_free;
117 }
118
119 return 0;
120err_free:
121 return ret;
122}
123
124static const struct hid_device_id cp_devices[] = {
125 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1),
126 .driver_data = CP_RDESC_SWAPPED_MIN_MAX },
127 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2),
128 .driver_data = CP_RDESC_SWAPPED_MIN_MAX },
129 { HID_USB_DEVICE(USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE),
130 .driver_data = CP_2WHEEL_MOUSE_HACK },
131 { }
132};
133MODULE_DEVICE_TABLE(hid, cp_devices);
134
135static struct hid_driver cp_driver = {
136 .name = "cypress",
137 .id_table = cp_devices,
138 .report_fixup = cp_report_fixup,
139 .input_mapped = cp_input_mapped,
140 .event = cp_event,
141 .probe = cp_probe,
142};
143
144static int cp_init(void)
145{
146 return hid_register_driver(&cp_driver);
147}
148
149static void cp_exit(void)
150{
151 hid_unregister_driver(&cp_driver);
152}
153
154module_init(cp_init);
155module_exit(cp_exit);
156MODULE_LICENSE("GPL");
157
158HID_COMPAT_LOAD_DRIVER(cypress);
diff --git a/drivers/hid/hid-dell.c b/drivers/hid/hid-dell.c
new file mode 100644
index 000000000000..1a0d0dfc62fc
--- /dev/null
+++ b/drivers/hid/hid-dell.c
@@ -0,0 +1,75 @@
1/*
2 * HID driver for some dell "special" devices
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/hid.h>
21#include <linux/module.h>
22
23#include "hid-ids.h"
24
25static int dell_probe(struct hid_device *hdev, const struct hid_device_id *id)
26{
27 int ret;
28
29 ret = hid_parse(hdev);
30 if (ret) {
31 dev_err(&hdev->dev, "parse failed\n");
32 goto err_free;
33 }
34
35 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
36 if (ret) {
37 dev_err(&hdev->dev, "hw start failed\n");
38 goto err_free;
39 }
40
41 usbhid_set_leds(hdev);
42
43 return 0;
44err_free:
45 return ret;
46}
47
48static const struct hid_device_id dell_devices[] = {
49 { HID_USB_DEVICE(USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_W7658) },
50 { HID_USB_DEVICE(USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_SK8115) },
51 { }
52};
53MODULE_DEVICE_TABLE(hid, dell_devices);
54
55static struct hid_driver dell_driver = {
56 .name = "dell",
57 .id_table = dell_devices,
58 .probe = dell_probe,
59};
60
61static int dell_init(void)
62{
63 return hid_register_driver(&dell_driver);
64}
65
66static void dell_exit(void)
67{
68 hid_unregister_driver(&dell_driver);
69}
70
71module_init(dell_init);
72module_exit(dell_exit);
73MODULE_LICENSE("GPL");
74
75HID_COMPAT_LOAD_DRIVER(dell);
diff --git a/drivers/hid/hid-dummy.c b/drivers/hid/hid-dummy.c
new file mode 100644
index 000000000000..e148f86fb58e
--- /dev/null
+++ b/drivers/hid/hid-dummy.c
@@ -0,0 +1,72 @@
1#include <linux/autoconf.h>
2#include <linux/module.h>
3#include <linux/hid.h>
4
5static int __init hid_dummy_init(void)
6{
7#ifdef CONFIG_HID_A4TECH_MODULE
8 HID_COMPAT_CALL_DRIVER(a4tech);
9#endif
10#ifdef CONFIG_HID_APPLE_MODULE
11 HID_COMPAT_CALL_DRIVER(apple);
12#endif
13#ifdef CONFIG_HID_BELKIN_MODULE
14 HID_COMPAT_CALL_DRIVER(belkin);
15#endif
16#ifdef CONFIG_HID_BRIGHT_MODULE
17 HID_COMPAT_CALL_DRIVER(bright);
18#endif
19#ifdef CONFIG_HID_CHERRY_MODULE
20 HID_COMPAT_CALL_DRIVER(cherry);
21#endif
22#ifdef CONFIG_HID_CHICONY_MODULE
23 HID_COMPAT_CALL_DRIVER(chicony);
24#endif
25#ifdef CONFIG_HID_CYPRESS_MODULE
26 HID_COMPAT_CALL_DRIVER(cypress);
27#endif
28#ifdef CONFIG_HID_DELL_MODULE
29 HID_COMPAT_CALL_DRIVER(dell);
30#endif
31#ifdef CONFIG_HID_EZKEY_MODULE
32 HID_COMPAT_CALL_DRIVER(ezkey);
33#endif
34#ifdef CONFIG_HID_GYRATION_MODULE
35 HID_COMPAT_CALL_DRIVER(gyration);
36#endif
37#ifdef CONFIG_HID_LOGITECH_MODULE
38 HID_COMPAT_CALL_DRIVER(logitech);
39#endif
40#ifdef CONFIG_HID_MICROSOFT_MODULE
41 HID_COMPAT_CALL_DRIVER(microsoft);
42#endif
43#ifdef CONFIG_HID_MONTEREY_MODULE
44 HID_COMPAT_CALL_DRIVER(monterey);
45#endif
46#ifdef CONFIG_HID_PANTHERLORD_MODULE
47 HID_COMPAT_CALL_DRIVER(pantherlord);
48#endif
49#ifdef CONFIG_HID_PETALYNX_MODULE
50 HID_COMPAT_CALL_DRIVER(petalynx);
51#endif
52#ifdef CONFIG_HID_SAMSUNG_MODULE
53 HID_COMPAT_CALL_DRIVER(samsung);
54#endif
55#ifdef CONFIG_HID_SONY_MODULE
56 HID_COMPAT_CALL_DRIVER(sony);
57#endif
58#ifdef CONFIG_HID_SUNPLUS_MODULE
59 HID_COMPAT_CALL_DRIVER(sunplus);
60#endif
61#ifdef CONFIG_THRUSTMASTER_FF_MODULE
62 HID_COMPAT_CALL_DRIVER(thrustmaster);
63#endif
64#ifdef CONFIG_ZEROPLUS_FF_MODULE
65 HID_COMPAT_CALL_DRIVER(zeroplus);
66#endif
67
68 return -EIO;
69}
70module_init(hid_dummy_init);
71
72MODULE_LICENSE("GPL");
diff --git a/drivers/hid/hid-ezkey.c b/drivers/hid/hid-ezkey.c
new file mode 100644
index 000000000000..deb42f931b7e
--- /dev/null
+++ b/drivers/hid/hid-ezkey.c
@@ -0,0 +1,95 @@
1/*
2 * HID driver for some ezkey "special" devices
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/input.h>
21#include <linux/hid.h>
22#include <linux/module.h>
23
24#include "hid-ids.h"
25
26#define ez_map_rel(c) hid_map_usage(hi, usage, bit, max, EV_REL, (c))
27#define ez_map_key(c) hid_map_usage(hi, usage, bit, max, EV_KEY, (c))
28
29static int ez_input_mapping(struct hid_device *hdev, struct hid_input *hi,
30 struct hid_field *field, struct hid_usage *usage,
31 unsigned long **bit, int *max)
32{
33 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
34 return 0;
35
36 switch (usage->hid & HID_USAGE) {
37 case 0x230: ez_map_key(BTN_MOUSE); break;
38 case 0x231: ez_map_rel(REL_WHEEL); break;
39 /*
40 * this keyboard has a scrollwheel implemented in
41 * totally broken way. We map this usage temporarily
42 * to HWHEEL and handle it in the event quirk handler
43 */
44 case 0x232: ez_map_rel(REL_HWHEEL); break;
45 default:
46 return 0;
47 }
48 return 1;
49}
50
51static int ez_event(struct hid_device *hdev, struct hid_field *field,
52 struct hid_usage *usage, __s32 value)
53{
54 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
55 !usage->type)
56 return 0;
57
58 /* handle the temporary quirky mapping to HWHEEL */
59 if (usage->type == EV_REL && usage->code == REL_HWHEEL) {
60 struct input_dev *input = field->hidinput->input;
61 input_event(input, usage->type, REL_WHEEL, -value);
62 return 1;
63 }
64
65 return 0;
66}
67
68static const struct hid_device_id ez_devices[] = {
69 { HID_USB_DEVICE(USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193) },
70 { }
71};
72MODULE_DEVICE_TABLE(hid, ez_devices);
73
74static struct hid_driver ez_driver = {
75 .name = "ezkey",
76 .id_table = ez_devices,
77 .input_mapping = ez_input_mapping,
78 .event = ez_event,
79};
80
81static int ez_init(void)
82{
83 return hid_register_driver(&ez_driver);
84}
85
86static void ez_exit(void)
87{
88 hid_unregister_driver(&ez_driver);
89}
90
91module_init(ez_init);
92module_exit(ez_exit);
93MODULE_LICENSE("GPL");
94
95HID_COMPAT_LOAD_DRIVER(ezkey);
diff --git a/drivers/hid/hid-gyration.c b/drivers/hid/hid-gyration.c
new file mode 100644
index 000000000000..ac5120f542cc
--- /dev/null
+++ b/drivers/hid/hid-gyration.c
@@ -0,0 +1,96 @@
1/*
2 * HID driver for some gyration "special" devices
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/input.h>
21#include <linux/hid.h>
22#include <linux/module.h>
23
24#include "hid-ids.h"
25
26#define gy_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
27 EV_KEY, (c))
28static int gyration_input_mapping(struct hid_device *hdev, struct hid_input *hi,
29 struct hid_field *field, struct hid_usage *usage,
30 unsigned long **bit, int *max)
31{
32 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
33 return 0;
34
35 set_bit(EV_REP, hi->input->evbit);
36 switch (usage->hid & HID_USAGE) {
37 /* Reported on Gyration MCE Remote */
38 case 0x00d: gy_map_key_clear(KEY_HOME); break;
39 case 0x024: gy_map_key_clear(KEY_DVD); break;
40 case 0x025: gy_map_key_clear(KEY_PVR); break;
41 case 0x046: gy_map_key_clear(KEY_MEDIA); break;
42 case 0x047: gy_map_key_clear(KEY_MP3); break;
43 case 0x049: gy_map_key_clear(KEY_CAMERA); break;
44 case 0x04a: gy_map_key_clear(KEY_VIDEO); break;
45
46 default:
47 return 0;
48 }
49 return 1;
50}
51
52static int gyration_event(struct hid_device *hdev, struct hid_field *field,
53 struct hid_usage *usage, __s32 value)
54{
55 struct input_dev *input = field->hidinput->input;
56
57 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK &&
58 (usage->hid & 0xff) == 0x82) {
59 input_event(input, usage->type, usage->code, 1);
60 input_sync(input);
61 input_event(input, usage->type, usage->code, 0);
62 input_sync(input);
63 return 1;
64 }
65
66 return 0;
67}
68
69static const struct hid_device_id gyration_devices[] = {
70 { HID_USB_DEVICE(USB_VENDOR_ID_GYRATION, USB_DEVICE_ID_GYRATION_REMOTE) },
71 { }
72};
73MODULE_DEVICE_TABLE(hid, gyration_devices);
74
75static struct hid_driver gyration_driver = {
76 .name = "gyration",
77 .id_table = gyration_devices,
78 .input_mapping = gyration_input_mapping,
79 .event = gyration_event,
80};
81
82static int gyration_init(void)
83{
84 return hid_register_driver(&gyration_driver);
85}
86
87static void gyration_exit(void)
88{
89 hid_unregister_driver(&gyration_driver);
90}
91
92module_init(gyration_init);
93module_exit(gyration_exit);
94MODULE_LICENSE("GPL");
95
96HID_COMPAT_LOAD_DRIVER(gyration);
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
new file mode 100644
index 000000000000..d9a1ba920c23
--- /dev/null
+++ b/drivers/hid/hid-ids.h
@@ -0,0 +1,406 @@
1/*
2 * USB HID quirks support for Linux
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 */
10
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 Free
14 * Software Foundation; either version 2 of the License, or (at your option)
15 * any later version.
16 */
17
18#ifndef HID_IDS_H_FILE
19#define HID_IDS_H_FILE
20
21#define USB_VENDOR_ID_A4TECH 0x09da
22#define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006
23#define USB_DEVICE_ID_A4TECH_X5_005D 0x000a
24
25#define USB_VENDOR_ID_AASHIMA 0x06d6
26#define USB_DEVICE_ID_AASHIMA_GAMEPAD 0x0025
27#define USB_DEVICE_ID_AASHIMA_PREDATOR 0x0026
28
29#define USB_VENDOR_ID_ACECAD 0x0460
30#define USB_DEVICE_ID_ACECAD_FLAIR 0x0004
31#define USB_DEVICE_ID_ACECAD_302 0x0008
32
33#define USB_VENDOR_ID_ADS_TECH 0x06e1
34#define USB_DEVICE_ID_ADS_TECH_RADIO_SI470X 0xa155
35
36#define USB_VENDOR_ID_AFATECH 0x15a4
37#define USB_DEVICE_ID_AFATECH_AF9016 0x9016
38
39#define USB_VENDOR_ID_AIPTEK 0x08ca
40#define USB_DEVICE_ID_AIPTEK_01 0x0001
41#define USB_DEVICE_ID_AIPTEK_10 0x0010
42#define USB_DEVICE_ID_AIPTEK_20 0x0020
43#define USB_DEVICE_ID_AIPTEK_21 0x0021
44#define USB_DEVICE_ID_AIPTEK_22 0x0022
45#define USB_DEVICE_ID_AIPTEK_23 0x0023
46#define USB_DEVICE_ID_AIPTEK_24 0x0024
47
48#define USB_VENDOR_ID_AIRCABLE 0x16CA
49#define USB_DEVICE_ID_AIRCABLE1 0x1502
50
51#define USB_VENDOR_ID_ALCOR 0x058f
52#define USB_DEVICE_ID_ALCOR_USBRS232 0x9720
53
54#define USB_VENDOR_ID_ALPS 0x0433
55#define USB_DEVICE_ID_IBM_GAMEPAD 0x1101
56
57#define USB_VENDOR_ID_APPLE 0x05ac
58#define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304
59#define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI 0x020e
60#define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO 0x020f
61#define USB_DEVICE_ID_APPLE_GEYSER_ANSI 0x0214
62#define USB_DEVICE_ID_APPLE_GEYSER_ISO 0x0215
63#define USB_DEVICE_ID_APPLE_GEYSER_JIS 0x0216
64#define USB_DEVICE_ID_APPLE_GEYSER3_ANSI 0x0217
65#define USB_DEVICE_ID_APPLE_GEYSER3_ISO 0x0218
66#define USB_DEVICE_ID_APPLE_GEYSER3_JIS 0x0219
67#define USB_DEVICE_ID_APPLE_GEYSER4_ANSI 0x021a
68#define USB_DEVICE_ID_APPLE_GEYSER4_ISO 0x021b
69#define USB_DEVICE_ID_APPLE_GEYSER4_JIS 0x021c
70#define USB_DEVICE_ID_APPLE_ALU_ANSI 0x0220
71#define USB_DEVICE_ID_APPLE_ALU_ISO 0x0221
72#define USB_DEVICE_ID_APPLE_ALU_JIS 0x0222
73#define USB_DEVICE_ID_APPLE_WELLSPRING_ANSI 0x0223
74#define USB_DEVICE_ID_APPLE_WELLSPRING_ISO 0x0224
75#define USB_DEVICE_ID_APPLE_WELLSPRING_JIS 0x0225
76#define USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI 0x0229
77#define USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO 0x022a
78#define USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS 0x022b
79#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI 0x022c
80#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO 0x022d
81#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS 0x022e
82#define USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI 0x0230
83#define USB_DEVICE_ID_APPLE_WELLSPRING2_ISO 0x0231
84#define USB_DEVICE_ID_APPLE_WELLSPRING2_JIS 0x0232
85#define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY 0x030a
86#define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY 0x030b
87#define USB_DEVICE_ID_APPLE_ATV_IRCONTROL 0x8241
88#define USB_DEVICE_ID_APPLE_IRCONTROL4 0x8242
89
90#define USB_VENDOR_ID_ASUS 0x0b05
91#define USB_DEVICE_ID_ASUS_LCM 0x1726
92
93#define USB_VENDOR_ID_ATEN 0x0557
94#define USB_DEVICE_ID_ATEN_UC100KM 0x2004
95#define USB_DEVICE_ID_ATEN_CS124U 0x2202
96#define USB_DEVICE_ID_ATEN_2PORTKVM 0x2204
97#define USB_DEVICE_ID_ATEN_4PORTKVM 0x2205
98#define USB_DEVICE_ID_ATEN_4PORTKVMC 0x2208
99
100#define USB_VENDOR_ID_AVERMEDIA 0x07ca
101#define USB_DEVICE_ID_AVER_FM_MR800 0xb800
102
103#define USB_VENDOR_ID_BELKIN 0x050d
104#define USB_DEVICE_ID_FLIP_KVM 0x3201
105
106#define USB_VENDOR_ID_BRIGHT 0x1241
107#define USB_DEVICE_ID_BRIGHT_ABNT2 0x1503
108
109#define USB_VENDOR_ID_BERKSHIRE 0x0c98
110#define USB_DEVICE_ID_BERKSHIRE_PCWD 0x1140
111
112#define USB_VENDOR_ID_CHERRY 0x046a
113#define USB_DEVICE_ID_CHERRY_CYMOTION 0x0023
114
115#define USB_VENDOR_ID_CHIC 0x05fe
116#define USB_DEVICE_ID_CHIC_GAMEPAD 0x0014
117
118#define USB_VENDOR_ID_CHICONY 0x04f2
119#define USB_DEVICE_ID_CHICONY_TACTICAL_PAD 0x0418
120
121#define USB_VENDOR_ID_CIDC 0x1677
122
123#define USB_VENDOR_ID_CMEDIA 0x0d8c
124#define USB_DEVICE_ID_CM109 0x000e
125
126#define USB_VENDOR_ID_CODEMERCS 0x07c0
127#define USB_DEVICE_ID_CODEMERCS_IOW_FIRST 0x1500
128#define USB_DEVICE_ID_CODEMERCS_IOW_LAST 0x15ff
129
130#define USB_VENDOR_ID_CYGNAL 0x10c4
131#define USB_DEVICE_ID_CYGNAL_RADIO_SI470X 0x818a
132
133#define USB_VENDOR_ID_CYPRESS 0x04b4
134#define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001
135#define USB_DEVICE_ID_CYPRESS_HIDCOM 0x5500
136#define USB_DEVICE_ID_CYPRESS_ULTRAMOUSE 0x7417
137#define USB_DEVICE_ID_CYPRESS_BARCODE_1 0xde61
138#define USB_DEVICE_ID_CYPRESS_BARCODE_2 0xde64
139
140#define USB_VENDOR_ID_DELL 0x413c
141#define USB_DEVICE_ID_DELL_W7658 0x2005
142#define USB_DEVICE_ID_DELL_SK8115 0x2105
143
144#define USB_VENDOR_ID_DELORME 0x1163
145#define USB_DEVICE_ID_DELORME_EARTHMATE 0x0100
146#define USB_DEVICE_ID_DELORME_EM_LT20 0x0200
147
148#define USB_VENDOR_ID_DMI 0x0c0b
149#define USB_DEVICE_ID_DMI_ENC 0x5fab
150
151#define USB_VENDOR_ID_ELO 0x04E7
152#define USB_DEVICE_ID_ELO_TS2700 0x0020
153
154#define USB_VENDOR_ID_ESSENTIAL_REALITY 0x0d7f
155#define USB_DEVICE_ID_ESSENTIAL_REALITY_P5 0x0100
156
157#define USB_VENDOR_ID_EZKEY 0x0518
158#define USB_DEVICE_ID_BTC_8193 0x0002
159
160#define USB_VENDOR_ID_GAMERON 0x0810
161#define USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR 0x0001
162
163#define USB_VENDOR_ID_GENERAL_TOUCH 0x0dfc
164
165#define USB_VENDOR_ID_GLAB 0x06c2
166#define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038
167#define USB_DEVICE_ID_1_PHIDGETSERVO_30 0x0039
168#define USB_DEVICE_ID_0_0_4_IF_KIT 0x0040
169#define USB_DEVICE_ID_0_16_16_IF_KIT 0x0044
170#define USB_DEVICE_ID_8_8_8_IF_KIT 0x0045
171#define USB_DEVICE_ID_0_8_7_IF_KIT 0x0051
172#define USB_DEVICE_ID_0_8_8_IF_KIT 0x0053
173#define USB_DEVICE_ID_PHIDGET_MOTORCONTROL 0x0058
174
175#define USB_VENDOR_ID_GOTOP 0x08f2
176#define USB_DEVICE_ID_SUPER_Q2 0x007f
177#define USB_DEVICE_ID_GOGOPEN 0x00ce
178#define USB_DEVICE_ID_PENPOWER 0x00f4
179
180#define USB_VENDOR_ID_GREENASIA 0x0e8f
181
182#define USB_VENDOR_ID_GRETAGMACBETH 0x0971
183#define USB_DEVICE_ID_GRETAGMACBETH_HUEY 0x2005
184
185#define USB_VENDOR_ID_GRIFFIN 0x077d
186#define USB_DEVICE_ID_POWERMATE 0x0410
187#define USB_DEVICE_ID_SOUNDKNOB 0x04AA
188
189#define USB_VENDOR_ID_GTCO 0x078c
190#define USB_DEVICE_ID_GTCO_90 0x0090
191#define USB_DEVICE_ID_GTCO_100 0x0100
192#define USB_DEVICE_ID_GTCO_101 0x0101
193#define USB_DEVICE_ID_GTCO_103 0x0103
194#define USB_DEVICE_ID_GTCO_104 0x0104
195#define USB_DEVICE_ID_GTCO_105 0x0105
196#define USB_DEVICE_ID_GTCO_106 0x0106
197#define USB_DEVICE_ID_GTCO_107 0x0107
198#define USB_DEVICE_ID_GTCO_108 0x0108
199#define USB_DEVICE_ID_GTCO_200 0x0200
200#define USB_DEVICE_ID_GTCO_201 0x0201
201#define USB_DEVICE_ID_GTCO_202 0x0202
202#define USB_DEVICE_ID_GTCO_203 0x0203
203#define USB_DEVICE_ID_GTCO_204 0x0204
204#define USB_DEVICE_ID_GTCO_205 0x0205
205#define USB_DEVICE_ID_GTCO_206 0x0206
206#define USB_DEVICE_ID_GTCO_207 0x0207
207#define USB_DEVICE_ID_GTCO_300 0x0300
208#define USB_DEVICE_ID_GTCO_301 0x0301
209#define USB_DEVICE_ID_GTCO_302 0x0302
210#define USB_DEVICE_ID_GTCO_303 0x0303
211#define USB_DEVICE_ID_GTCO_304 0x0304
212#define USB_DEVICE_ID_GTCO_305 0x0305
213#define USB_DEVICE_ID_GTCO_306 0x0306
214#define USB_DEVICE_ID_GTCO_307 0x0307
215#define USB_DEVICE_ID_GTCO_308 0x0308
216#define USB_DEVICE_ID_GTCO_309 0x0309
217#define USB_DEVICE_ID_GTCO_400 0x0400
218#define USB_DEVICE_ID_GTCO_401 0x0401
219#define USB_DEVICE_ID_GTCO_402 0x0402
220#define USB_DEVICE_ID_GTCO_403 0x0403
221#define USB_DEVICE_ID_GTCO_404 0x0404
222#define USB_DEVICE_ID_GTCO_405 0x0405
223#define USB_DEVICE_ID_GTCO_500 0x0500
224#define USB_DEVICE_ID_GTCO_501 0x0501
225#define USB_DEVICE_ID_GTCO_502 0x0502
226#define USB_DEVICE_ID_GTCO_503 0x0503
227#define USB_DEVICE_ID_GTCO_504 0x0504
228#define USB_DEVICE_ID_GTCO_1000 0x1000
229#define USB_DEVICE_ID_GTCO_1001 0x1001
230#define USB_DEVICE_ID_GTCO_1002 0x1002
231#define USB_DEVICE_ID_GTCO_1003 0x1003
232#define USB_DEVICE_ID_GTCO_1004 0x1004
233#define USB_DEVICE_ID_GTCO_1005 0x1005
234#define USB_DEVICE_ID_GTCO_1006 0x1006
235#define USB_DEVICE_ID_GTCO_1007 0x1007
236
237#define USB_VENDOR_ID_GYRATION 0x0c16
238#define USB_DEVICE_ID_GYRATION_REMOTE 0x0002
239
240#define USB_VENDOR_ID_HAPP 0x078b
241#define USB_DEVICE_ID_UGCI_DRIVING 0x0010
242#define USB_DEVICE_ID_UGCI_FLYING 0x0020
243#define USB_DEVICE_ID_UGCI_FIGHTING 0x0030
244
245#define USB_VENDOR_ID_IMATION 0x0718
246#define USB_DEVICE_ID_DISC_STAKKA 0xd000
247
248#define USB_VENDOR_ID_KBGEAR 0x084e
249#define USB_DEVICE_ID_KBGEAR_JAMSTUDIO 0x1001
250
251#define USB_VENDOR_ID_LABTEC 0x1020
252#define USB_DEVICE_ID_LABTEC_WIRELESS_KEYBOARD 0x0006
253
254#define USB_VENDOR_ID_LD 0x0f11
255#define USB_DEVICE_ID_LD_CASSY 0x1000
256#define USB_DEVICE_ID_LD_POCKETCASSY 0x1010
257#define USB_DEVICE_ID_LD_MOBILECASSY 0x1020
258#define USB_DEVICE_ID_LD_JWM 0x1080
259#define USB_DEVICE_ID_LD_DMMP 0x1081
260#define USB_DEVICE_ID_LD_UMIP 0x1090
261#define USB_DEVICE_ID_LD_XRAY1 0x1100
262#define USB_DEVICE_ID_LD_XRAY2 0x1101
263#define USB_DEVICE_ID_LD_VIDEOCOM 0x1200
264#define USB_DEVICE_ID_LD_COM3LAB 0x2000
265#define USB_DEVICE_ID_LD_TELEPORT 0x2010
266#define USB_DEVICE_ID_LD_NETWORKANALYSER 0x2020
267#define USB_DEVICE_ID_LD_POWERCONTROL 0x2030
268#define USB_DEVICE_ID_LD_MACHINETEST 0x2040
269
270#define USB_VENDOR_ID_LOGITECH 0x046d
271#define USB_DEVICE_ID_LOGITECH_LX3 0xc044
272#define USB_DEVICE_ID_LOGITECH_V150 0xc047
273#define USB_DEVICE_ID_LOGITECH_RECEIVER 0xc101
274#define USB_DEVICE_ID_LOGITECH_HARMONY_FIRST 0xc110
275#define USB_DEVICE_ID_LOGITECH_HARMONY_LAST 0xc14f
276#define USB_DEVICE_ID_LOGITECH_RUMBLEPAD 0xc211
277#define USB_DEVICE_ID_LOGITECH_EXTREME_3D 0xc215
278#define USB_DEVICE_ID_LOGITECH_RUMBLEPAD2 0xc218
279#define USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2 0xc219
280#define USB_DEVICE_ID_LOGITECH_WINGMAN_F3D 0xc283
281#define USB_DEVICE_ID_LOGITECH_FORCE3D_PRO 0xc286
282#define USB_DEVICE_ID_LOGITECH_WHEEL 0xc294
283#define USB_DEVICE_ID_LOGITECH_MOMO_WHEEL 0xc295
284#define USB_DEVICE_ID_LOGITECH_ELITE_KBD 0xc30a
285#define USB_DEVICE_ID_LOGITECH_KBD 0xc311
286#define USB_DEVICE_ID_S510_RECEIVER 0xc50c
287#define USB_DEVICE_ID_S510_RECEIVER_2 0xc517
288#define USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500 0xc512
289#define USB_DEVICE_ID_MX3000_RECEIVER 0xc513
290#define USB_DEVICE_ID_DINOVO_DESKTOP 0xc704
291#define USB_DEVICE_ID_DINOVO_EDGE 0xc714
292#define USB_DEVICE_ID_DINOVO_MINI 0xc71f
293#define USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2 0xca03
294
295#define USB_VENDOR_ID_MCC 0x09db
296#define USB_DEVICE_ID_MCC_PMD1024LS 0x0076
297#define USB_DEVICE_ID_MCC_PMD1208LS 0x007a
298
299#define USB_VENDOR_ID_MGE 0x0463
300#define USB_DEVICE_ID_MGE_UPS 0xffff
301#define USB_DEVICE_ID_MGE_UPS1 0x0001
302
303#define USB_VENDOR_ID_MICROCHIP 0x04d8
304#define USB_DEVICE_ID_PICKIT1 0x0032
305#define USB_DEVICE_ID_PICKIT2 0x0033
306
307#define USB_VENDOR_ID_MICROSOFT 0x045e
308#define USB_DEVICE_ID_SIDEWINDER_GV 0x003b
309#define USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0 0x009d
310#define USB_DEVICE_ID_MS_NE4K 0x00db
311#define USB_DEVICE_ID_MS_LK6K 0x00f9
312#define USB_DEVICE_ID_MS_PRESENTER_8K_BT 0x0701
313#define USB_DEVICE_ID_MS_PRESENTER_8K_USB 0x0713
314
315
316#define USB_VENDOR_ID_MONTEREY 0x0566
317#define USB_DEVICE_ID_GENIUS_KB29E 0x3004
318
319#define USB_VENDOR_ID_NCR 0x0404
320#define USB_DEVICE_ID_NCR_FIRST 0x0300
321#define USB_DEVICE_ID_NCR_LAST 0x03ff
322
323#define USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR 0x0400
324#define USB_DEVICE_ID_N_S_HARMONY 0xc359
325
326#define USB_VENDOR_ID_NATSU 0x08b7
327#define USB_DEVICE_ID_NATSU_GAMEPAD 0x0001
328
329#define USB_VENDOR_ID_NEC 0x073e
330#define USB_DEVICE_ID_NEC_USB_GAME_PAD 0x0301
331
332#define USB_VENDOR_ID_ONTRAK 0x0a07
333#define USB_DEVICE_ID_ONTRAK_ADU100 0x0064
334
335#define USB_VENDOR_ID_PANJIT 0x134c
336
337#define USB_VENDOR_ID_PANTHERLORD 0x0810
338#define USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK 0x0001
339
340#define USB_VENDOR_ID_PETALYNX 0x18b1
341#define USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE 0x0037
342
343#define USB_VENDOR_ID_PLAYDOTCOM 0x0b43
344#define USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII 0x0003
345
346#define USB_VENDOR_ID_SAITEK 0x06a3
347#define USB_DEVICE_ID_SAITEK_RUMBLEPAD 0xff17
348
349#define USB_VENDOR_ID_SAMSUNG 0x0419
350#define USB_DEVICE_ID_SAMSUNG_IR_REMOTE 0x0001
351
352#define USB_VENDOR_ID_SONY 0x054c
353#define USB_DEVICE_ID_SONY_PS3_CONTROLLER 0x0268
354
355#define USB_VENDOR_ID_SOUNDGRAPH 0x15c2
356#define USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD 0x0038
357#define USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD2 0x0036
358#define USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD3 0x0034
359
360#define USB_VENDOR_ID_SUN 0x0430
361#define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab
362
363#define USB_VENDOR_ID_SUNPLUS 0x04fc
364#define USB_DEVICE_ID_SUNPLUS_WDESKTOP 0x05d8
365
366#define USB_VENDOR_ID_TENX 0x1130
367#define USB_DEVICE_ID_TENX_IBUDDY1 0x0001
368#define USB_DEVICE_ID_TENX_IBUDDY2 0x0002
369
370#define USB_VENDOR_ID_THRUSTMASTER 0x044f
371
372#define USB_VENDOR_ID_TOPMAX 0x0663
373#define USB_DEVICE_ID_TOPMAX_COBRAPAD 0x0103
374
375#define USB_VENDOR_ID_TURBOX 0x062a
376#define USB_DEVICE_ID_TURBOX_KEYBOARD 0x0201
377
378#define USB_VENDOR_ID_VERNIER 0x08f7
379#define USB_DEVICE_ID_VERNIER_LABPRO 0x0001
380#define USB_DEVICE_ID_VERNIER_GOTEMP 0x0002
381#define USB_DEVICE_ID_VERNIER_SKIP 0x0003
382#define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004
383#define USB_DEVICE_ID_VERNIER_LCSPEC 0x0006
384
385#define USB_VENDOR_ID_WACOM 0x056a
386
387#define USB_VENDOR_ID_WISEGROUP 0x0925
388#define USB_DEVICE_ID_1_PHIDGETSERVO_20 0x8101
389#define USB_DEVICE_ID_4_PHIDGETSERVO_20 0x8104
390#define USB_DEVICE_ID_8_8_4_IF_KIT 0x8201
391#define USB_DEVICE_ID_QUAD_USB_JOYPAD 0x8800
392#define USB_DEVICE_ID_DUAL_USB_JOYPAD 0x8866
393
394#define USB_VENDOR_ID_WISEGROUP_LTD 0x6666
395#define USB_VENDOR_ID_WISEGROUP_LTD2 0x6677
396#define USB_DEVICE_ID_SMARTJOY_DUAL_PLUS 0x8802
397
398#define USB_VENDOR_ID_YEALINK 0x6993
399#define USB_DEVICE_ID_YEALINK_P1K_P4K_B2K 0xb001
400
401#define USB_VENDOR_ID_ZEROPLUS 0x0c12
402
403#define USB_VENDOR_ID_KYE 0x0458
404#define USB_DEVICE_ID_KYE_GPEN_560 0x5003
405
406#endif
diff --git a/drivers/hid/hid-input-quirks.c b/drivers/hid/hid-input-quirks.c
deleted file mode 100644
index 16feea014494..000000000000
--- a/drivers/hid/hid-input-quirks.c
+++ /dev/null
@@ -1,484 +0,0 @@
1/*
2 * HID-input usage mapping quirks
3 *
4 * This is used to handle HID-input mappings for devices violating
5 * HUT 1.12 specification.
6 *
7 * Copyright (c) 2007-2008 Jiri Kosina
8 */
9
10/*
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the Free
13 * Software Foundation; either version 2 of the License
14 */
15
16#include <linux/input.h>
17#include <linux/hid.h>
18
19#define map_abs(c) do { usage->code = c; usage->type = EV_ABS; *bit = input->absbit; *max = ABS_MAX; } while (0)
20#define map_rel(c) do { usage->code = c; usage->type = EV_REL; *bit = input->relbit; *max = REL_MAX; } while (0)
21#define map_key(c) do { usage->code = c; usage->type = EV_KEY; *bit = input->keybit; *max = KEY_MAX; } while (0)
22#define map_led(c) do { usage->code = c; usage->type = EV_LED; *bit = input->ledbit; *max = LED_MAX; } while (0)
23
24#define map_abs_clear(c) do { map_abs(c); clear_bit(c, *bit); } while (0)
25#define map_key_clear(c) do { map_key(c); clear_bit(c, *bit); } while (0)
26
27static int quirk_belkin_wkbd(struct hid_usage *usage, struct input_dev *input,
28 unsigned long **bit, int *max)
29{
30 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
31 return 0;
32
33 switch (usage->hid & HID_USAGE) {
34 case 0x03a: map_key_clear(KEY_SOUND); break;
35 case 0x03b: map_key_clear(KEY_CAMERA); break;
36 case 0x03c: map_key_clear(KEY_DOCUMENTS); break;
37 default:
38 return 0;
39 }
40 return 1;
41}
42
43static int quirk_cherry_cymotion(struct hid_usage *usage, struct input_dev *input,
44 unsigned long **bit, int *max)
45{
46 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
47 return 0;
48
49 switch (usage->hid & HID_USAGE) {
50 case 0x301: map_key_clear(KEY_PROG1); break;
51 case 0x302: map_key_clear(KEY_PROG2); break;
52 case 0x303: map_key_clear(KEY_PROG3); break;
53 default:
54 return 0;
55 }
56 return 1;
57}
58
59static int quirk_logitech_ultrax_remote(struct hid_usage *usage, struct input_dev *input,
60 unsigned long **bit, int *max)
61{
62 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
63 return 0;
64
65 set_bit(EV_REP, input->evbit);
66 switch(usage->hid & HID_USAGE) {
67 /* Reported on Logitech Ultra X Media Remote */
68 case 0x004: map_key_clear(KEY_AGAIN); break;
69 case 0x00d: map_key_clear(KEY_HOME); break;
70 case 0x024: map_key_clear(KEY_SHUFFLE); break;
71 case 0x025: map_key_clear(KEY_TV); break;
72 case 0x026: map_key_clear(KEY_MENU); break;
73 case 0x031: map_key_clear(KEY_AUDIO); break;
74 case 0x032: map_key_clear(KEY_TEXT); break;
75 case 0x033: map_key_clear(KEY_LAST); break;
76 case 0x047: map_key_clear(KEY_MP3); break;
77 case 0x048: map_key_clear(KEY_DVD); break;
78 case 0x049: map_key_clear(KEY_MEDIA); break;
79 case 0x04a: map_key_clear(KEY_VIDEO); break;
80 case 0x04b: map_key_clear(KEY_ANGLE); break;
81 case 0x04c: map_key_clear(KEY_LANGUAGE); break;
82 case 0x04d: map_key_clear(KEY_SUBTITLE); break;
83 case 0x051: map_key_clear(KEY_RED); break;
84 case 0x052: map_key_clear(KEY_CLOSE); break;
85
86 default:
87 return 0;
88 }
89 return 1;
90}
91
92static int quirk_gyration_remote(struct hid_usage *usage, struct input_dev *input,
93 unsigned long **bit, int *max)
94{
95 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
96 return 0;
97
98 set_bit(EV_REP, input->evbit);
99 switch(usage->hid & HID_USAGE) {
100 /* Reported on Gyration MCE Remote */
101 case 0x00d: map_key_clear(KEY_HOME); break;
102 case 0x024: map_key_clear(KEY_DVD); break;
103 case 0x025: map_key_clear(KEY_PVR); break;
104 case 0x046: map_key_clear(KEY_MEDIA); break;
105 case 0x047: map_key_clear(KEY_MP3); break;
106 case 0x049: map_key_clear(KEY_CAMERA); break;
107 case 0x04a: map_key_clear(KEY_VIDEO); break;
108
109 default:
110 return 0;
111 }
112 return 1;
113}
114
115static int quirk_chicony_tactical_pad(struct hid_usage *usage, struct input_dev *input,
116 unsigned long **bit, int *max)
117{
118 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
119 return 0;
120
121 set_bit(EV_REP, input->evbit);
122 switch (usage->hid & HID_USAGE) {
123 case 0xff01: map_key_clear(BTN_1); break;
124 case 0xff02: map_key_clear(BTN_2); break;
125 case 0xff03: map_key_clear(BTN_3); break;
126 case 0xff04: map_key_clear(BTN_4); break;
127 case 0xff05: map_key_clear(BTN_5); break;
128 case 0xff06: map_key_clear(BTN_6); break;
129 case 0xff07: map_key_clear(BTN_7); break;
130 case 0xff08: map_key_clear(BTN_8); break;
131 case 0xff09: map_key_clear(BTN_9); break;
132 case 0xff0a: map_key_clear(BTN_A); break;
133 case 0xff0b: map_key_clear(BTN_B); break;
134 default:
135 return 0;
136 }
137 return 1;
138}
139
140static int quirk_microsoft_ergonomy_kb(struct hid_usage *usage, struct input_dev *input,
141 unsigned long **bit, int *max)
142{
143 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
144 return 0;
145
146 switch(usage->hid & HID_USAGE) {
147 case 0xfd06: map_key_clear(KEY_CHAT); break;
148 case 0xfd07: map_key_clear(KEY_PHONE); break;
149 case 0xff05:
150 set_bit(EV_REP, input->evbit);
151 map_key_clear(KEY_F13);
152 set_bit(KEY_F14, input->keybit);
153 set_bit(KEY_F15, input->keybit);
154 set_bit(KEY_F16, input->keybit);
155 set_bit(KEY_F17, input->keybit);
156 set_bit(KEY_F18, input->keybit);
157 default:
158 return 0;
159 }
160 return 1;
161}
162
163static int quirk_microsoft_presenter_8k(struct hid_usage *usage, struct input_dev *input,
164 unsigned long **bit, int *max)
165{
166 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
167 return 0;
168
169 set_bit(EV_REP, input->evbit);
170 switch(usage->hid & HID_USAGE) {
171 case 0xfd08: map_key_clear(KEY_FORWARD); break;
172 case 0xfd09: map_key_clear(KEY_BACK); break;
173 case 0xfd0b: map_key_clear(KEY_PLAYPAUSE); break;
174 case 0xfd0e: map_key_clear(KEY_CLOSE); break;
175 case 0xfd0f: map_key_clear(KEY_PLAY); break;
176 default:
177 return 0;
178 }
179 return 1;
180}
181
182static int quirk_petalynx_remote(struct hid_usage *usage, struct input_dev *input,
183 unsigned long **bit, int *max)
184{
185 if (((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR) &&
186 ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER))
187 return 0;
188
189 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_LOGIVENDOR)
190 switch(usage->hid & HID_USAGE) {
191 case 0x05a: map_key_clear(KEY_TEXT); break;
192 case 0x05b: map_key_clear(KEY_RED); break;
193 case 0x05c: map_key_clear(KEY_GREEN); break;
194 case 0x05d: map_key_clear(KEY_YELLOW); break;
195 case 0x05e: map_key_clear(KEY_BLUE); break;
196 default:
197 return 0;
198 }
199
200 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER)
201 switch(usage->hid & HID_USAGE) {
202 case 0x0f6: map_key_clear(KEY_NEXT); break;
203 case 0x0fa: map_key_clear(KEY_BACK); break;
204 default:
205 return 0;
206 }
207 return 1;
208}
209
210static int quirk_logitech_wireless(struct hid_usage *usage, struct input_dev *input,
211 unsigned long **bit, int *max)
212{
213 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
214 return 0;
215
216 switch (usage->hid & HID_USAGE) {
217 case 0x1001: map_key_clear(KEY_MESSENGER); break;
218 case 0x1003: map_key_clear(KEY_SOUND); break;
219 case 0x1004: map_key_clear(KEY_VIDEO); break;
220 case 0x1005: map_key_clear(KEY_AUDIO); break;
221 case 0x100a: map_key_clear(KEY_DOCUMENTS); break;
222 case 0x1011: map_key_clear(KEY_PREVIOUSSONG); break;
223 case 0x1012: map_key_clear(KEY_NEXTSONG); break;
224 case 0x1013: map_key_clear(KEY_CAMERA); break;
225 case 0x1014: map_key_clear(KEY_MESSENGER); break;
226 case 0x1015: map_key_clear(KEY_RECORD); break;
227 case 0x1016: map_key_clear(KEY_PLAYER); break;
228 case 0x1017: map_key_clear(KEY_EJECTCD); break;
229 case 0x1018: map_key_clear(KEY_MEDIA); break;
230 case 0x1019: map_key_clear(KEY_PROG1); break;
231 case 0x101a: map_key_clear(KEY_PROG2); break;
232 case 0x101b: map_key_clear(KEY_PROG3); break;
233 case 0x101f: map_key_clear(KEY_ZOOMIN); break;
234 case 0x1020: map_key_clear(KEY_ZOOMOUT); break;
235 case 0x1021: map_key_clear(KEY_ZOOMRESET); break;
236 case 0x1023: map_key_clear(KEY_CLOSE); break;
237 case 0x1027: map_key_clear(KEY_MENU); break;
238 /* this one is marked as 'Rotate' */
239 case 0x1028: map_key_clear(KEY_ANGLE); break;
240 case 0x1029: map_key_clear(KEY_SHUFFLE); break;
241 case 0x102a: map_key_clear(KEY_BACK); break;
242 case 0x102b: map_key_clear(KEY_CYCLEWINDOWS); break;
243 case 0x1041: map_key_clear(KEY_BATTERY); break;
244 case 0x1042: map_key_clear(KEY_WORDPROCESSOR); break;
245 case 0x1043: map_key_clear(KEY_SPREADSHEET); break;
246 case 0x1044: map_key_clear(KEY_PRESENTATION); break;
247 case 0x1045: map_key_clear(KEY_UNDO); break;
248 case 0x1046: map_key_clear(KEY_REDO); break;
249 case 0x1047: map_key_clear(KEY_PRINT); break;
250 case 0x1048: map_key_clear(KEY_SAVE); break;
251 case 0x1049: map_key_clear(KEY_PROG1); break;
252 case 0x104a: map_key_clear(KEY_PROG2); break;
253 case 0x104b: map_key_clear(KEY_PROG3); break;
254 case 0x104c: map_key_clear(KEY_PROG4); break;
255
256 default:
257 return 0;
258 }
259 return 1;
260}
261
262static int quirk_cherry_genius_29e(struct hid_usage *usage, struct input_dev *input,
263 unsigned long **bit, int *max)
264{
265 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
266 return 0;
267
268 switch (usage->hid & HID_USAGE) {
269 case 0x156: map_key_clear(KEY_WORDPROCESSOR); break;
270 case 0x157: map_key_clear(KEY_SPREADSHEET); break;
271 case 0x158: map_key_clear(KEY_PRESENTATION); break;
272 case 0x15c: map_key_clear(KEY_STOP); break;
273
274 default:
275 return 0;
276 }
277 return 1;
278}
279
280static int quirk_btc_8193(struct hid_usage *usage, struct input_dev *input,
281 unsigned long **bit, int *max)
282{
283 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
284 return 0;
285
286 switch (usage->hid & HID_USAGE) {
287 case 0x230: map_key(BTN_MOUSE); break;
288 case 0x231: map_rel(REL_WHEEL); break;
289 /*
290 * this keyboard has a scrollwheel implemented in
291 * totally broken way. We map this usage temporarily
292 * to HWHEEL and handle it in the event quirk handler
293 */
294 case 0x232: map_rel(REL_HWHEEL); break;
295
296 default:
297 return 0;
298 }
299 return 1;
300}
301
302static int quirk_sunplus_wdesktop(struct hid_usage *usage, struct input_dev *input,
303 unsigned long **bit, int *max)
304{
305 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
306 return 0;
307
308 switch (usage->hid & HID_USAGE) {
309 case 0x2003: map_key_clear(KEY_ZOOMIN); break;
310 case 0x2103: map_key_clear(KEY_ZOOMOUT); break;
311 default:
312 return 0;
313 }
314 return 1;
315}
316
317#define VENDOR_ID_BELKIN 0x1020
318#define DEVICE_ID_BELKIN_WIRELESS_KEYBOARD 0x0006
319
320#define VENDOR_ID_CHERRY 0x046a
321#define DEVICE_ID_CHERRY_CYMOTION 0x0023
322
323#define VENDOR_ID_CHICONY 0x04f2
324#define DEVICE_ID_CHICONY_TACTICAL_PAD 0x0418
325
326#define VENDOR_ID_EZKEY 0x0518
327#define DEVICE_ID_BTC_8193 0x0002
328
329#define VENDOR_ID_GYRATION 0x0c16
330#define DEVICE_ID_GYRATION_REMOTE 0x0002
331
332#define VENDOR_ID_LOGITECH 0x046d
333#define DEVICE_ID_LOGITECH_RECEIVER 0xc101
334#define DEVICE_ID_S510_RECEIVER 0xc50c
335#define DEVICE_ID_S510_RECEIVER_2 0xc517
336#define DEVICE_ID_MX3000_RECEIVER 0xc513
337
338#define VENDOR_ID_MICROSOFT 0x045e
339#define DEVICE_ID_MS4K 0x00db
340#define DEVICE_ID_MS6K 0x00f9
341#define DEVICE_IS_MS_PRESENTER_8K_BT 0x0701
342#define DEVICE_ID_MS_PRESENTER_8K_USB 0x0713
343
344#define VENDOR_ID_MONTEREY 0x0566
345#define DEVICE_ID_GENIUS_KB29E 0x3004
346
347#define VENDOR_ID_PETALYNX 0x18b1
348#define DEVICE_ID_PETALYNX_MAXTER_REMOTE 0x0037
349
350#define VENDOR_ID_SUNPLUS 0x04fc
351#define DEVICE_ID_SUNPLUS_WDESKTOP 0x05d8
352
353static const struct hid_input_blacklist {
354 __u16 idVendor;
355 __u16 idProduct;
356 int (*quirk)(struct hid_usage *, struct input_dev *, unsigned long **, int *);
357} hid_input_blacklist[] = {
358 { VENDOR_ID_BELKIN, DEVICE_ID_BELKIN_WIRELESS_KEYBOARD, quirk_belkin_wkbd },
359
360 { VENDOR_ID_CHERRY, DEVICE_ID_CHERRY_CYMOTION, quirk_cherry_cymotion },
361
362 { VENDOR_ID_CHICONY, DEVICE_ID_CHICONY_TACTICAL_PAD, quirk_chicony_tactical_pad },
363
364 { VENDOR_ID_EZKEY, DEVICE_ID_BTC_8193, quirk_btc_8193 },
365
366 { VENDOR_ID_GYRATION, DEVICE_ID_GYRATION_REMOTE, quirk_gyration_remote },
367
368 { VENDOR_ID_LOGITECH, DEVICE_ID_LOGITECH_RECEIVER, quirk_logitech_ultrax_remote },
369 { VENDOR_ID_LOGITECH, DEVICE_ID_S510_RECEIVER, quirk_logitech_wireless },
370 { VENDOR_ID_LOGITECH, DEVICE_ID_S510_RECEIVER_2, quirk_logitech_wireless },
371 { VENDOR_ID_LOGITECH, DEVICE_ID_MX3000_RECEIVER, quirk_logitech_wireless },
372
373 { VENDOR_ID_MICROSOFT, DEVICE_ID_MS4K, quirk_microsoft_ergonomy_kb },
374 { VENDOR_ID_MICROSOFT, DEVICE_ID_MS6K, quirk_microsoft_ergonomy_kb },
375 { VENDOR_ID_MICROSOFT, DEVICE_IS_MS_PRESENTER_8K_BT, quirk_microsoft_presenter_8k },
376 { VENDOR_ID_MICROSOFT, DEVICE_ID_MS_PRESENTER_8K_USB, quirk_microsoft_presenter_8k },
377
378 { VENDOR_ID_MONTEREY, DEVICE_ID_GENIUS_KB29E, quirk_cherry_genius_29e },
379
380 { VENDOR_ID_PETALYNX, DEVICE_ID_PETALYNX_MAXTER_REMOTE, quirk_petalynx_remote },
381
382 { VENDOR_ID_SUNPLUS, DEVICE_ID_SUNPLUS_WDESKTOP, quirk_sunplus_wdesktop },
383
384 { 0, 0, NULL }
385};
386
387int hidinput_mapping_quirks(struct hid_usage *usage,
388 struct input_dev *input,
389 unsigned long **bit, int *max)
390{
391 struct hid_device *device = input_get_drvdata(input);
392 int i = 0;
393
394 while (hid_input_blacklist[i].quirk) {
395 if (hid_input_blacklist[i].idVendor == device->vendor &&
396 hid_input_blacklist[i].idProduct == device->product)
397 return hid_input_blacklist[i].quirk(usage, input, bit, max);
398 i++;
399 }
400 return 0;
401}
402
403int hidinput_event_quirks(struct hid_device *hid, struct hid_field *field, struct hid_usage *usage, __s32 value)
404{
405 struct input_dev *input;
406
407 input = field->hidinput->input;
408
409 if (((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_5) && (usage->hid == 0x00090005))
410 || ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_7) && (usage->hid == 0x00090007))) {
411 if (value) hid->quirks |= HID_QUIRK_2WHEEL_MOUSE_HACK_ON;
412 else hid->quirks &= ~HID_QUIRK_2WHEEL_MOUSE_HACK_ON;
413 return 1;
414 }
415
416 if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_B8) &&
417 (usage->type == EV_REL) &&
418 (usage->code == REL_WHEEL)) {
419 hid->delayed_value = value;
420 return 1;
421 }
422
423 if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_B8) &&
424 (usage->hid == 0x000100b8)) {
425 input_event(input, EV_REL, value ? REL_HWHEEL : REL_WHEEL, hid->delayed_value);
426 return 1;
427 }
428
429 if ((hid->quirks & HID_QUIRK_INVERT_HWHEEL) && (usage->code == REL_HWHEEL)) {
430 input_event(input, usage->type, usage->code, -value);
431 return 1;
432 }
433
434 if ((hid->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_ON) && (usage->code == REL_WHEEL)) {
435 input_event(input, usage->type, REL_HWHEEL, value);
436 return 1;
437 }
438
439 if ((hid->quirks & HID_QUIRK_APPLE_HAS_FN) && hidinput_apple_event(hid, input, usage, value))
440 return 1;
441
442 /* Handling MS keyboards special buttons */
443 if (hid->quirks & HID_QUIRK_MICROSOFT_KEYS &&
444 usage->hid == (HID_UP_MSVENDOR | 0xff05)) {
445 int key = 0;
446 static int last_key = 0;
447 switch (value) {
448 case 0x01: key = KEY_F14; break;
449 case 0x02: key = KEY_F15; break;
450 case 0x04: key = KEY_F16; break;
451 case 0x08: key = KEY_F17; break;
452 case 0x10: key = KEY_F18; break;
453 default: break;
454 }
455 if (key) {
456 input_event(input, usage->type, key, 1);
457 last_key = key;
458 } else {
459 input_event(input, usage->type, last_key, 0);
460 }
461 }
462
463 /* handle the temporary quirky mapping to HWHEEL */
464 if (hid->quirks & HID_QUIRK_HWHEEL_WHEEL_INVERT &&
465 usage->type == EV_REL && usage->code == REL_HWHEEL) {
466 input_event(input, usage->type, REL_WHEEL, -value);
467 return 1;
468 }
469
470 /* Gyration MCE remote "Sleep" key */
471 if (hid->vendor == VENDOR_ID_GYRATION &&
472 hid->product == DEVICE_ID_GYRATION_REMOTE &&
473 (usage->hid & HID_USAGE_PAGE) == HID_UP_GENDESK &&
474 (usage->hid & 0xff) == 0x82) {
475 input_event(input, usage->type, usage->code, 1);
476 input_sync(input);
477 input_event(input, usage->type, usage->code, 0);
478 input_sync(input);
479 return 1;
480 }
481 return 0;
482}
483
484
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 1b2e8dc3398d..7f183b7147e1 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -32,11 +32,6 @@
32#include <linux/hid.h> 32#include <linux/hid.h>
33#include <linux/hid-debug.h> 33#include <linux/hid-debug.h>
34 34
35static int hid_apple_fnmode = 1;
36module_param_named(pb_fnmode, hid_apple_fnmode, int, 0644);
37MODULE_PARM_DESC(pb_fnmode,
38 "Mode of fn key on Apple keyboards (0 = disabled, 1 = fkeyslast, 2 = fkeysfirst)");
39
40#define unk KEY_UNKNOWN 35#define unk KEY_UNKNOWN
41 36
42static const unsigned char hid_keyboard[256] = { 37static const unsigned char hid_keyboard[256] = {
@@ -58,227 +53,20 @@ static const unsigned char hid_keyboard[256] = {
58 150,158,159,128,136,177,178,176,142,152,173,140,unk,unk,unk,unk 53 150,158,159,128,136,177,178,176,142,152,173,140,unk,unk,unk,unk
59}; 54};
60 55
61/* extended mapping for certain Logitech hardware (Logitech cordless desktop LX500) */
62#define LOGITECH_EXPANDED_KEYMAP_SIZE 80
63static int logitech_expanded_keymap[LOGITECH_EXPANDED_KEYMAP_SIZE] = {
64 0,216, 0,213,175,156, 0, 0, 0, 0,
65 144, 0, 0, 0, 0, 0, 0, 0, 0,212,
66 174,167,152,161,112, 0, 0, 0,154, 0,
67 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
68 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
69 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
70 0, 0, 0, 0, 0,183,184,185,186,187,
71 188,189,190,191,192,193,194, 0, 0, 0
72};
73
74static const struct { 56static const struct {
75 __s32 x; 57 __s32 x;
76 __s32 y; 58 __s32 y;
77} hid_hat_to_axis[] = {{ 0, 0}, { 0,-1}, { 1,-1}, { 1, 0}, { 1, 1}, { 0, 1}, {-1, 1}, {-1, 0}, {-1,-1}}; 59} hid_hat_to_axis[] = {{ 0, 0}, { 0,-1}, { 1,-1}, { 1, 0}, { 1, 1}, { 0, 1}, {-1, 1}, {-1, 0}, {-1,-1}};
78 60
79#define map_abs(c) do { usage->code = c; usage->type = EV_ABS; bit = input->absbit; max = ABS_MAX; } while (0) 61#define map_abs(c) hid_map_usage(hidinput, usage, &bit, &max, EV_ABS, (c))
80#define map_rel(c) do { usage->code = c; usage->type = EV_REL; bit = input->relbit; max = REL_MAX; } while (0) 62#define map_rel(c) hid_map_usage(hidinput, usage, &bit, &max, EV_REL, (c))
81#define map_key(c) do { usage->code = c; usage->type = EV_KEY; bit = input->keybit; max = KEY_MAX; } while (0) 63#define map_key(c) hid_map_usage(hidinput, usage, &bit, &max, EV_KEY, (c))
82#define map_led(c) do { usage->code = c; usage->type = EV_LED; bit = input->ledbit; max = LED_MAX; } while (0) 64#define map_led(c) hid_map_usage(hidinput, usage, &bit, &max, EV_LED, (c))
83
84#define map_abs_clear(c) do { map_abs(c); clear_bit(c, bit); } while (0)
85#define map_key_clear(c) do { map_key(c); clear_bit(c, bit); } while (0)
86
87#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
88
89struct hidinput_key_translation {
90 u16 from;
91 u16 to;
92 u8 flags;
93};
94
95#define APPLE_FLAG_FKEY 0x01
96
97static struct hidinput_key_translation apple_fn_keys[] = {
98 { KEY_BACKSPACE, KEY_DELETE },
99 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
100 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
101 { KEY_F3, KEY_FN_F5, APPLE_FLAG_FKEY }, /* Exposé */
102 { KEY_F4, KEY_FN_F4, APPLE_FLAG_FKEY }, /* Dashboard */
103 { KEY_F5, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY },
104 { KEY_F6, KEY_KBDILLUMUP, APPLE_FLAG_FKEY },
105 { KEY_F7, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY },
106 { KEY_F8, KEY_PLAYPAUSE, APPLE_FLAG_FKEY },
107 { KEY_F9, KEY_NEXTSONG, APPLE_FLAG_FKEY },
108 { KEY_F10, KEY_MUTE, APPLE_FLAG_FKEY },
109 { KEY_F11, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
110 { KEY_F12, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
111 { KEY_UP, KEY_PAGEUP },
112 { KEY_DOWN, KEY_PAGEDOWN },
113 { KEY_LEFT, KEY_HOME },
114 { KEY_RIGHT, KEY_END },
115 { }
116};
117
118static struct hidinput_key_translation powerbook_fn_keys[] = {
119 { KEY_BACKSPACE, KEY_DELETE },
120 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
121 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
122 { KEY_F3, KEY_MUTE, APPLE_FLAG_FKEY },
123 { KEY_F4, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
124 { KEY_F5, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
125 { KEY_F6, KEY_NUMLOCK, APPLE_FLAG_FKEY },
126 { KEY_F7, KEY_SWITCHVIDEOMODE, APPLE_FLAG_FKEY },
127 { KEY_F8, KEY_KBDILLUMTOGGLE, APPLE_FLAG_FKEY },
128 { KEY_F9, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY },
129 { KEY_F10, KEY_KBDILLUMUP, APPLE_FLAG_FKEY },
130 { KEY_UP, KEY_PAGEUP },
131 { KEY_DOWN, KEY_PAGEDOWN },
132 { KEY_LEFT, KEY_HOME },
133 { KEY_RIGHT, KEY_END },
134 { }
135};
136
137static struct hidinput_key_translation powerbook_numlock_keys[] = {
138 { KEY_J, KEY_KP1 },
139 { KEY_K, KEY_KP2 },
140 { KEY_L, KEY_KP3 },
141 { KEY_U, KEY_KP4 },
142 { KEY_I, KEY_KP5 },
143 { KEY_O, KEY_KP6 },
144 { KEY_7, KEY_KP7 },
145 { KEY_8, KEY_KP8 },
146 { KEY_9, KEY_KP9 },
147 { KEY_M, KEY_KP0 },
148 { KEY_DOT, KEY_KPDOT },
149 { KEY_SLASH, KEY_KPPLUS },
150 { KEY_SEMICOLON, KEY_KPMINUS },
151 { KEY_P, KEY_KPASTERISK },
152 { KEY_MINUS, KEY_KPEQUAL },
153 { KEY_0, KEY_KPSLASH },
154 { KEY_F6, KEY_NUMLOCK },
155 { KEY_KPENTER, KEY_KPENTER },
156 { KEY_BACKSPACE, KEY_BACKSPACE },
157 { }
158};
159
160static struct hidinput_key_translation apple_iso_keyboard[] = {
161 { KEY_GRAVE, KEY_102ND },
162 { KEY_102ND, KEY_GRAVE },
163 { }
164};
165 65
166static struct hidinput_key_translation *find_translation(struct hidinput_key_translation *table, u16 from) 66#define map_abs_clear(c) hid_map_usage_clear(hidinput, usage, &bit, \
167{ 67 &max, EV_ABS, (c))
168 struct hidinput_key_translation *trans; 68#define map_key_clear(c) hid_map_usage_clear(hidinput, usage, &bit, \
169 69 &max, EV_KEY, (c))
170 /* Look for the translation */
171 for (trans = table; trans->from; trans++)
172 if (trans->from == from)
173 return trans;
174
175 return NULL;
176}
177
178int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
179 struct hid_usage *usage, __s32 value)
180{
181 struct hidinput_key_translation *trans;
182
183 if (usage->code == KEY_FN) {
184 if (value) hid->quirks |= HID_QUIRK_APPLE_FN_ON;
185 else hid->quirks &= ~HID_QUIRK_APPLE_FN_ON;
186
187 input_event(input, usage->type, usage->code, value);
188
189 return 1;
190 }
191
192 if (hid_apple_fnmode) {
193 int do_translate;
194
195 trans = find_translation((hid->product < 0x220 ||
196 hid->product >= 0x300) ?
197 powerbook_fn_keys : apple_fn_keys,
198 usage->code);
199 if (trans) {
200 if (test_bit(usage->code, hid->apple_pressed_fn))
201 do_translate = 1;
202 else if (trans->flags & APPLE_FLAG_FKEY)
203 do_translate =
204 (hid_apple_fnmode == 2 && (hid->quirks & HID_QUIRK_APPLE_FN_ON)) ||
205 (hid_apple_fnmode == 1 && !(hid->quirks & HID_QUIRK_APPLE_FN_ON));
206 else
207 do_translate = (hid->quirks & HID_QUIRK_APPLE_FN_ON);
208
209 if (do_translate) {
210 if (value)
211 set_bit(usage->code, hid->apple_pressed_fn);
212 else
213 clear_bit(usage->code, hid->apple_pressed_fn);
214
215 input_event(input, usage->type, trans->to, value);
216
217 return 1;
218 }
219 }
220
221 if (hid->quirks & HID_QUIRK_APPLE_NUMLOCK_EMULATION && (
222 test_bit(usage->code, hid->pb_pressed_numlock) ||
223 test_bit(LED_NUML, input->led))) {
224 trans = find_translation(powerbook_numlock_keys, usage->code);
225
226 if (trans) {
227 if (value)
228 set_bit(usage->code, hid->pb_pressed_numlock);
229 else
230 clear_bit(usage->code, hid->pb_pressed_numlock);
231
232 input_event(input, usage->type, trans->to, value);
233 }
234
235 return 1;
236 }
237 }
238
239 if (hid->quirks & HID_QUIRK_APPLE_ISO_KEYBOARD) {
240 trans = find_translation(apple_iso_keyboard, usage->code);
241 if (trans) {
242 input_event(input, usage->type, trans->to, value);
243 return 1;
244 }
245 }
246
247 return 0;
248}
249
250static void hidinput_apple_setup(struct input_dev *input)
251{
252 struct hidinput_key_translation *trans;
253
254 set_bit(KEY_NUMLOCK, input->keybit);
255
256 /* Enable all needed keys */
257 for (trans = apple_fn_keys; trans->from; trans++)
258 set_bit(trans->to, input->keybit);
259
260 for (trans = powerbook_fn_keys; trans->from; trans++)
261 set_bit(trans->to, input->keybit);
262
263 for (trans = powerbook_numlock_keys; trans->from; trans++)
264 set_bit(trans->to, input->keybit);
265
266 for (trans = apple_iso_keyboard; trans->from; trans++)
267 set_bit(trans->to, input->keybit);
268
269}
270#else
271inline int hidinput_apple_event(struct hid_device *hid,
272 struct input_dev *input,
273 struct hid_usage *usage, __s32 value)
274{
275 return 0;
276}
277
278static inline void hidinput_apple_setup(struct input_dev *input)
279{
280}
281#endif
282 70
283static inline int match_scancode(int code, int scancode) 71static inline int match_scancode(int code, int scancode)
284{ 72{
@@ -366,7 +154,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
366{ 154{
367 struct input_dev *input = hidinput->input; 155 struct input_dev *input = hidinput->input;
368 struct hid_device *device = input_get_drvdata(input); 156 struct hid_device *device = input_get_drvdata(input);
369 int max = 0, code, ret; 157 int max = 0, code;
370 unsigned long *bit = NULL; 158 unsigned long *bit = NULL;
371 159
372 field->hidinput = hidinput; 160 field->hidinput = hidinput;
@@ -385,406 +173,345 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
385 goto ignore; 173 goto ignore;
386 } 174 }
387 175
388 /* handle input mappings for quirky devices */ 176 if (device->driver->input_mapping) {
389 ret = hidinput_mapping_quirks(usage, input, &bit, &max); 177 int ret = device->driver->input_mapping(device, hidinput, field,
390 if (ret) 178 usage, &bit, &max);
391 goto mapped; 179 if (ret > 0)
180 goto mapped;
181 if (ret < 0)
182 goto ignore;
183 }
392 184
393 switch (usage->hid & HID_USAGE_PAGE) { 185 switch (usage->hid & HID_USAGE_PAGE) {
186 case HID_UP_UNDEFINED:
187 goto ignore;
394 188
395 case HID_UP_UNDEFINED: 189 case HID_UP_KEYBOARD:
396 goto ignore; 190 set_bit(EV_REP, input->evbit);
397
398 case HID_UP_KEYBOARD:
399 191
400 set_bit(EV_REP, input->evbit); 192 if ((usage->hid & HID_USAGE) < 256) {
193 if (!hid_keyboard[usage->hid & HID_USAGE]) goto ignore;
194 map_key_clear(hid_keyboard[usage->hid & HID_USAGE]);
195 } else
196 map_key(KEY_UNKNOWN);
401 197
402 if ((usage->hid & HID_USAGE) < 256) { 198 break;
403 if (!hid_keyboard[usage->hid & HID_USAGE]) goto ignore;
404 map_key_clear(hid_keyboard[usage->hid & HID_USAGE]);
405 } else
406 map_key(KEY_UNKNOWN);
407 199
408 break; 200 case HID_UP_BUTTON:
201 code = ((usage->hid - 1) & 0xf);
409 202
410 case HID_UP_BUTTON: 203 switch (field->application) {
411 204 case HID_GD_MOUSE:
412 code = ((usage->hid - 1) & 0xf); 205 case HID_GD_POINTER: code += 0x110; break;
413 206 case HID_GD_JOYSTICK: code += 0x120; break;
414 switch (field->application) { 207 case HID_GD_GAMEPAD: code += 0x130; break;
415 case HID_GD_MOUSE: 208 default:
416 case HID_GD_POINTER: code += 0x110; break; 209 switch (field->physical) {
417 case HID_GD_JOYSTICK: code += 0x120; break; 210 case HID_GD_MOUSE:
418 case HID_GD_GAMEPAD: code += 0x130; break; 211 case HID_GD_POINTER: code += 0x110; break;
419 default: 212 case HID_GD_JOYSTICK: code += 0x120; break;
420 switch (field->physical) { 213 case HID_GD_GAMEPAD: code += 0x130; break;
421 case HID_GD_MOUSE: 214 default: code += 0x100;
422 case HID_GD_POINTER: code += 0x110; break;
423 case HID_GD_JOYSTICK: code += 0x120; break;
424 case HID_GD_GAMEPAD: code += 0x130; break;
425 default: code += 0x100;
426 }
427 }
428
429 /* Special handling for Logitech Cordless Desktop */
430 if (field->application != HID_GD_MOUSE) {
431 if (device->quirks & HID_QUIRK_LOGITECH_EXPANDED_KEYMAP) {
432 int hid = usage->hid & HID_USAGE;
433 if (hid < LOGITECH_EXPANDED_KEYMAP_SIZE && logitech_expanded_keymap[hid] != 0)
434 code = logitech_expanded_keymap[hid];
435 }
436 } else {
437 if (device->quirks & HID_QUIRK_LOGITECH_IGNORE_DOUBLED_WHEEL) {
438 int hid = usage->hid & HID_USAGE;
439 if (hid == 7 || hid == 8)
440 goto ignore;
441 }
442 } 215 }
216 }
443 217
444 map_key(code); 218 map_key(code);
445 break; 219 break;
446 220
447 221 case HID_UP_SIMULATION:
448 case HID_UP_SIMULATION: 222 switch (usage->hid & 0xffff) {
449 223 case 0xba: map_abs(ABS_RUDDER); break;
450 switch (usage->hid & 0xffff) { 224 case 0xbb: map_abs(ABS_THROTTLE); break;
451 case 0xba: map_abs(ABS_RUDDER); break; 225 case 0xc4: map_abs(ABS_GAS); break;
452 case 0xbb: map_abs(ABS_THROTTLE); break; 226 case 0xc5: map_abs(ABS_BRAKE); break;
453 case 0xc4: map_abs(ABS_GAS); break; 227 case 0xc8: map_abs(ABS_WHEEL); break;
454 case 0xc5: map_abs(ABS_BRAKE); break; 228 default: goto ignore;
455 case 0xc8: map_abs(ABS_WHEEL); break; 229 }
456 default: goto ignore; 230 break;
231
232 case HID_UP_GENDESK:
233 if ((usage->hid & 0xf0) == 0x80) { /* SystemControl */
234 switch (usage->hid & 0xf) {
235 case 0x1: map_key_clear(KEY_POWER); break;
236 case 0x2: map_key_clear(KEY_SLEEP); break;
237 case 0x3: map_key_clear(KEY_WAKEUP); break;
238 default: goto unknown;
457 } 239 }
458 break; 240 break;
241 }
459 242
460 case HID_UP_GENDESK: 243 if ((usage->hid & 0xf0) == 0x90) { /* D-pad */
461
462 if ((usage->hid & 0xf0) == 0x80) { /* SystemControl */
463 switch (usage->hid & 0xf) {
464 case 0x1: map_key_clear(KEY_POWER); break;
465 case 0x2: map_key_clear(KEY_SLEEP); break;
466 case 0x3: map_key_clear(KEY_WAKEUP); break;
467 default: goto unknown;
468 }
469 break;
470 }
471
472 if ((usage->hid & 0xf0) == 0x90) { /* D-pad */
473 switch (usage->hid) {
474 case HID_GD_UP: usage->hat_dir = 1; break;
475 case HID_GD_DOWN: usage->hat_dir = 5; break;
476 case HID_GD_RIGHT: usage->hat_dir = 3; break;
477 case HID_GD_LEFT: usage->hat_dir = 7; break;
478 default: goto unknown;
479 }
480 if (field->dpad) {
481 map_abs(field->dpad);
482 goto ignore;
483 }
484 map_abs(ABS_HAT0X);
485 break;
486 }
487
488 switch (usage->hid) { 244 switch (usage->hid) {
489 245 case HID_GD_UP: usage->hat_dir = 1; break;
490 /* These usage IDs map directly to the usage codes. */ 246 case HID_GD_DOWN: usage->hat_dir = 5; break;
491 case HID_GD_X: case HID_GD_Y: case HID_GD_Z: 247 case HID_GD_RIGHT: usage->hat_dir = 3; break;
492 case HID_GD_RX: case HID_GD_RY: case HID_GD_RZ: 248 case HID_GD_LEFT: usage->hat_dir = 7; break;
493 case HID_GD_SLIDER: case HID_GD_DIAL: case HID_GD_WHEEL: 249 default: goto unknown;
494 if (field->flags & HID_MAIN_ITEM_RELATIVE)
495 map_rel(usage->hid & 0xf);
496 else
497 map_abs(usage->hid & 0xf);
498 break;
499
500 case HID_GD_HATSWITCH:
501 usage->hat_min = field->logical_minimum;
502 usage->hat_max = field->logical_maximum;
503 map_abs(ABS_HAT0X);
504 break;
505
506 case HID_GD_START: map_key_clear(BTN_START); break;
507 case HID_GD_SELECT: map_key_clear(BTN_SELECT); break;
508
509 default: goto unknown;
510 } 250 }
511 251 if (field->dpad) {
512 break; 252 map_abs(field->dpad);
513 253 goto ignore;
514 case HID_UP_LED:
515
516 switch (usage->hid & 0xffff) { /* HID-Value: */
517 case 0x01: map_led (LED_NUML); break; /* "Num Lock" */
518 case 0x02: map_led (LED_CAPSL); break; /* "Caps Lock" */
519 case 0x03: map_led (LED_SCROLLL); break; /* "Scroll Lock" */
520 case 0x04: map_led (LED_COMPOSE); break; /* "Compose" */
521 case 0x05: map_led (LED_KANA); break; /* "Kana" */
522 case 0x27: map_led (LED_SLEEP); break; /* "Stand-By" */
523 case 0x4c: map_led (LED_SUSPEND); break; /* "System Suspend" */
524 case 0x09: map_led (LED_MUTE); break; /* "Mute" */
525 case 0x4b: map_led (LED_MISC); break; /* "Generic Indicator" */
526 case 0x19: map_led (LED_MAIL); break; /* "Message Waiting" */
527 case 0x4d: map_led (LED_CHARGING); break; /* "External Power Connected" */
528
529 default: goto ignore;
530 } 254 }
255 map_abs(ABS_HAT0X);
531 break; 256 break;
257 }
532 258
533 case HID_UP_DIGITIZER: 259 switch (usage->hid) {
534 260 /* These usage IDs map directly to the usage codes. */
535 switch (usage->hid & 0xff) { 261 case HID_GD_X: case HID_GD_Y: case HID_GD_Z:
536 262 case HID_GD_RX: case HID_GD_RY: case HID_GD_RZ:
537 case 0x30: /* TipPressure */ 263 case HID_GD_SLIDER: case HID_GD_DIAL: case HID_GD_WHEEL:
538 if (!test_bit(BTN_TOUCH, input->keybit)) { 264 if (field->flags & HID_MAIN_ITEM_RELATIVE)
539 device->quirks |= HID_QUIRK_NOTOUCH; 265 map_rel(usage->hid & 0xf);
540 set_bit(EV_KEY, input->evbit); 266 else
541 set_bit(BTN_TOUCH, input->keybit); 267 map_abs(usage->hid & 0xf);
542 } 268 break;
543
544 map_abs_clear(ABS_PRESSURE);
545 break;
546
547 case 0x32: /* InRange */
548 switch (field->physical & 0xff) {
549 case 0x21: map_key(BTN_TOOL_MOUSE); break;
550 case 0x22: map_key(BTN_TOOL_FINGER); break;
551 default: map_key(BTN_TOOL_PEN); break;
552 }
553 break;
554 269
555 case 0x3c: /* Invert */ 270 case HID_GD_HATSWITCH:
556 map_key_clear(BTN_TOOL_RUBBER); 271 usage->hat_min = field->logical_minimum;
557 break; 272 usage->hat_max = field->logical_maximum;
273 map_abs(ABS_HAT0X);
274 break;
558 275
559 case 0x33: /* Touch */ 276 case HID_GD_START: map_key_clear(BTN_START); break;
560 case 0x42: /* TipSwitch */ 277 case HID_GD_SELECT: map_key_clear(BTN_SELECT); break;
561 case 0x43: /* TipSwitch2 */
562 device->quirks &= ~HID_QUIRK_NOTOUCH;
563 map_key_clear(BTN_TOUCH);
564 break;
565 278
566 case 0x44: /* BarrelSwitch */ 279 default: goto unknown;
567 map_key_clear(BTN_STYLUS); 280 }
568 break;
569 281
570 default: goto unknown; 282 break;
283
284 case HID_UP_LED:
285 switch (usage->hid & 0xffff) { /* HID-Value: */
286 case 0x01: map_led (LED_NUML); break; /* "Num Lock" */
287 case 0x02: map_led (LED_CAPSL); break; /* "Caps Lock" */
288 case 0x03: map_led (LED_SCROLLL); break; /* "Scroll Lock" */
289 case 0x04: map_led (LED_COMPOSE); break; /* "Compose" */
290 case 0x05: map_led (LED_KANA); break; /* "Kana" */
291 case 0x27: map_led (LED_SLEEP); break; /* "Stand-By" */
292 case 0x4c: map_led (LED_SUSPEND); break; /* "System Suspend" */
293 case 0x09: map_led (LED_MUTE); break; /* "Mute" */
294 case 0x4b: map_led (LED_MISC); break; /* "Generic Indicator" */
295 case 0x19: map_led (LED_MAIL); break; /* "Message Waiting" */
296 case 0x4d: map_led (LED_CHARGING); break; /* "External Power Connected" */
297
298 default: goto ignore;
299 }
300 break;
301
302 case HID_UP_DIGITIZER:
303 switch (usage->hid & 0xff) {
304 case 0x30: /* TipPressure */
305 if (!test_bit(BTN_TOUCH, input->keybit)) {
306 device->quirks |= HID_QUIRK_NOTOUCH;
307 set_bit(EV_KEY, input->evbit);
308 set_bit(BTN_TOUCH, input->keybit);
571 } 309 }
310 map_abs_clear(ABS_PRESSURE);
572 break; 311 break;
573 312
574 case HID_UP_CONSUMER: /* USB HUT v1.1, pages 56-62 */ 313 case 0x32: /* InRange */
575 314 switch (field->physical & 0xff) {
576 switch (usage->hid & HID_USAGE) { 315 case 0x21: map_key(BTN_TOOL_MOUSE); break;
577 case 0x000: goto ignore; 316 case 0x22: map_key(BTN_TOOL_FINGER); break;
578 case 0x034: map_key_clear(KEY_SLEEP); break; 317 default: map_key(BTN_TOOL_PEN); break;
579 case 0x036: map_key_clear(BTN_MISC); break;
580
581 case 0x040: map_key_clear(KEY_MENU); break;
582 case 0x045: map_key_clear(KEY_RADIO); break;
583
584 case 0x083: map_key_clear(KEY_LAST); break;
585 case 0x088: map_key_clear(KEY_PC); break;
586 case 0x089: map_key_clear(KEY_TV); break;
587 case 0x08a: map_key_clear(KEY_WWW); break;
588 case 0x08b: map_key_clear(KEY_DVD); break;
589 case 0x08c: map_key_clear(KEY_PHONE); break;
590 case 0x08d: map_key_clear(KEY_PROGRAM); break;
591 case 0x08e: map_key_clear(KEY_VIDEOPHONE); break;
592 case 0x08f: map_key_clear(KEY_GAMES); break;
593 case 0x090: map_key_clear(KEY_MEMO); break;
594 case 0x091: map_key_clear(KEY_CD); break;
595 case 0x092: map_key_clear(KEY_VCR); break;
596 case 0x093: map_key_clear(KEY_TUNER); break;
597 case 0x094: map_key_clear(KEY_EXIT); break;
598 case 0x095: map_key_clear(KEY_HELP); break;
599 case 0x096: map_key_clear(KEY_TAPE); break;
600 case 0x097: map_key_clear(KEY_TV2); break;
601 case 0x098: map_key_clear(KEY_SAT); break;
602 case 0x09a: map_key_clear(KEY_PVR); break;
603
604 case 0x09c: map_key_clear(KEY_CHANNELUP); break;
605 case 0x09d: map_key_clear(KEY_CHANNELDOWN); break;
606 case 0x0a0: map_key_clear(KEY_VCR2); break;
607
608 case 0x0b0: map_key_clear(KEY_PLAY); break;
609 case 0x0b1: map_key_clear(KEY_PAUSE); break;
610 case 0x0b2: map_key_clear(KEY_RECORD); break;
611 case 0x0b3: map_key_clear(KEY_FASTFORWARD); break;
612 case 0x0b4: map_key_clear(KEY_REWIND); break;
613 case 0x0b5: map_key_clear(KEY_NEXTSONG); break;
614 case 0x0b6: map_key_clear(KEY_PREVIOUSSONG); break;
615 case 0x0b7: map_key_clear(KEY_STOPCD); break;
616 case 0x0b8: map_key_clear(KEY_EJECTCD); break;
617 case 0x0bc: map_key_clear(KEY_MEDIA_REPEAT); break;
618
619 case 0x0cd: map_key_clear(KEY_PLAYPAUSE); break;
620 case 0x0e0: map_abs_clear(ABS_VOLUME); break;
621 case 0x0e2: map_key_clear(KEY_MUTE); break;
622 case 0x0e5: map_key_clear(KEY_BASSBOOST); break;
623 case 0x0e9: map_key_clear(KEY_VOLUMEUP); break;
624 case 0x0ea: map_key_clear(KEY_VOLUMEDOWN); break;
625
626 case 0x182: map_key_clear(KEY_BOOKMARKS); break;
627 case 0x183: map_key_clear(KEY_CONFIG); break;
628 case 0x184: map_key_clear(KEY_WORDPROCESSOR); break;
629 case 0x185: map_key_clear(KEY_EDITOR); break;
630 case 0x186: map_key_clear(KEY_SPREADSHEET); break;
631 case 0x187: map_key_clear(KEY_GRAPHICSEDITOR); break;
632 case 0x188: map_key_clear(KEY_PRESENTATION); break;
633 case 0x189: map_key_clear(KEY_DATABASE); break;
634 case 0x18a: map_key_clear(KEY_MAIL); break;
635 case 0x18b: map_key_clear(KEY_NEWS); break;
636 case 0x18c: map_key_clear(KEY_VOICEMAIL); break;
637 case 0x18d: map_key_clear(KEY_ADDRESSBOOK); break;
638 case 0x18e: map_key_clear(KEY_CALENDAR); break;
639 case 0x191: map_key_clear(KEY_FINANCE); break;
640 case 0x192: map_key_clear(KEY_CALC); break;
641 case 0x194: map_key_clear(KEY_FILE); break;
642 case 0x196: map_key_clear(KEY_WWW); break;
643 case 0x19c: map_key_clear(KEY_LOGOFF); break;
644 case 0x19e: map_key_clear(KEY_COFFEE); break;
645 case 0x1a6: map_key_clear(KEY_HELP); break;
646 case 0x1a7: map_key_clear(KEY_DOCUMENTS); break;
647 case 0x1ab: map_key_clear(KEY_SPELLCHECK); break;
648 case 0x1b6: map_key_clear(KEY_MEDIA); break;
649 case 0x1b7: map_key_clear(KEY_SOUND); break;
650 case 0x1bc: map_key_clear(KEY_MESSENGER); break;
651 case 0x1bd: map_key_clear(KEY_INFO); break;
652 case 0x201: map_key_clear(KEY_NEW); break;
653 case 0x202: map_key_clear(KEY_OPEN); break;
654 case 0x203: map_key_clear(KEY_CLOSE); break;
655 case 0x204: map_key_clear(KEY_EXIT); break;
656 case 0x207: map_key_clear(KEY_SAVE); break;
657 case 0x208: map_key_clear(KEY_PRINT); break;
658 case 0x209: map_key_clear(KEY_PROPS); break;
659 case 0x21a: map_key_clear(KEY_UNDO); break;
660 case 0x21b: map_key_clear(KEY_COPY); break;
661 case 0x21c: map_key_clear(KEY_CUT); break;
662 case 0x21d: map_key_clear(KEY_PASTE); break;
663 case 0x21f: map_key_clear(KEY_FIND); break;
664 case 0x221: map_key_clear(KEY_SEARCH); break;
665 case 0x222: map_key_clear(KEY_GOTO); break;
666 case 0x223: map_key_clear(KEY_HOMEPAGE); break;
667 case 0x224: map_key_clear(KEY_BACK); break;
668 case 0x225: map_key_clear(KEY_FORWARD); break;
669 case 0x226: map_key_clear(KEY_STOP); break;
670 case 0x227: map_key_clear(KEY_REFRESH); break;
671 case 0x22a: map_key_clear(KEY_BOOKMARKS); break;
672 case 0x22d: map_key_clear(KEY_ZOOMIN); break;
673 case 0x22e: map_key_clear(KEY_ZOOMOUT); break;
674 case 0x22f: map_key_clear(KEY_ZOOMRESET); break;
675 case 0x233: map_key_clear(KEY_SCROLLUP); break;
676 case 0x234: map_key_clear(KEY_SCROLLDOWN); break;
677 case 0x238: map_rel(REL_HWHEEL); break;
678 case 0x25f: map_key_clear(KEY_CANCEL); break;
679 case 0x279: map_key_clear(KEY_REDO); break;
680
681 case 0x289: map_key_clear(KEY_REPLY); break;
682 case 0x28b: map_key_clear(KEY_FORWARDMAIL); break;
683 case 0x28c: map_key_clear(KEY_SEND); break;
684
685 default: goto ignore;
686 } 318 }
687 break; 319 break;
688 320
689 case HID_UP_HPVENDOR: /* Reported on a Dutch layout HP5308 */ 321 case 0x3c: /* Invert */
690 322 map_key_clear(BTN_TOOL_RUBBER);
691 set_bit(EV_REP, input->evbit);
692 switch (usage->hid & HID_USAGE) {
693 case 0x021: map_key_clear(KEY_PRINT); break;
694 case 0x070: map_key_clear(KEY_HP); break;
695 case 0x071: map_key_clear(KEY_CAMERA); break;
696 case 0x072: map_key_clear(KEY_SOUND); break;
697 case 0x073: map_key_clear(KEY_QUESTION); break;
698 case 0x080: map_key_clear(KEY_EMAIL); break;
699 case 0x081: map_key_clear(KEY_CHAT); break;
700 case 0x082: map_key_clear(KEY_SEARCH); break;
701 case 0x083: map_key_clear(KEY_CONNECT); break;
702 case 0x084: map_key_clear(KEY_FINANCE); break;
703 case 0x085: map_key_clear(KEY_SPORT); break;
704 case 0x086: map_key_clear(KEY_SHOP); break;
705 default: goto ignore;
706 }
707 break; 323 break;
708 324
709 case HID_UP_MSVENDOR: 325 case 0x33: /* Touch */
710 326 case 0x42: /* TipSwitch */
711 goto ignore; 327 case 0x43: /* TipSwitch2 */
712 328 device->quirks &= ~HID_QUIRK_NOTOUCH;
713 case HID_UP_CUSTOM: /* Reported on Logitech and Apple USB keyboards */ 329 map_key_clear(BTN_TOUCH);
714 330 break;
715 set_bit(EV_REP, input->evbit);
716 switch(usage->hid & HID_USAGE) {
717 case 0x003:
718 /* The fn key on Apple USB keyboards */
719 map_key_clear(KEY_FN);
720 hidinput_apple_setup(input);
721 break;
722 331
723 default: goto ignore; 332 case 0x44: /* BarrelSwitch */
724 } 333 map_key_clear(BTN_STYLUS);
725 break; 334 break;
726 335
727 case HID_UP_LOGIVENDOR: 336 default: goto unknown;
337 }
338 break;
339
340 case HID_UP_CONSUMER: /* USB HUT v1.1, pages 56-62 */
341 switch (usage->hid & HID_USAGE) {
342 case 0x000: goto ignore;
343 case 0x034: map_key_clear(KEY_SLEEP); break;
344 case 0x036: map_key_clear(BTN_MISC); break;
345
346 case 0x040: map_key_clear(KEY_MENU); break;
347 case 0x045: map_key_clear(KEY_RADIO); break;
348
349 case 0x083: map_key_clear(KEY_LAST); break;
350 case 0x088: map_key_clear(KEY_PC); break;
351 case 0x089: map_key_clear(KEY_TV); break;
352 case 0x08a: map_key_clear(KEY_WWW); break;
353 case 0x08b: map_key_clear(KEY_DVD); break;
354 case 0x08c: map_key_clear(KEY_PHONE); break;
355 case 0x08d: map_key_clear(KEY_PROGRAM); break;
356 case 0x08e: map_key_clear(KEY_VIDEOPHONE); break;
357 case 0x08f: map_key_clear(KEY_GAMES); break;
358 case 0x090: map_key_clear(KEY_MEMO); break;
359 case 0x091: map_key_clear(KEY_CD); break;
360 case 0x092: map_key_clear(KEY_VCR); break;
361 case 0x093: map_key_clear(KEY_TUNER); break;
362 case 0x094: map_key_clear(KEY_EXIT); break;
363 case 0x095: map_key_clear(KEY_HELP); break;
364 case 0x096: map_key_clear(KEY_TAPE); break;
365 case 0x097: map_key_clear(KEY_TV2); break;
366 case 0x098: map_key_clear(KEY_SAT); break;
367 case 0x09a: map_key_clear(KEY_PVR); break;
368
369 case 0x09c: map_key_clear(KEY_CHANNELUP); break;
370 case 0x09d: map_key_clear(KEY_CHANNELDOWN); break;
371 case 0x0a0: map_key_clear(KEY_VCR2); break;
372
373 case 0x0b0: map_key_clear(KEY_PLAY); break;
374 case 0x0b1: map_key_clear(KEY_PAUSE); break;
375 case 0x0b2: map_key_clear(KEY_RECORD); break;
376 case 0x0b3: map_key_clear(KEY_FASTFORWARD); break;
377 case 0x0b4: map_key_clear(KEY_REWIND); break;
378 case 0x0b5: map_key_clear(KEY_NEXTSONG); break;
379 case 0x0b6: map_key_clear(KEY_PREVIOUSSONG); break;
380 case 0x0b7: map_key_clear(KEY_STOPCD); break;
381 case 0x0b8: map_key_clear(KEY_EJECTCD); break;
382 case 0x0bc: map_key_clear(KEY_MEDIA_REPEAT); break;
383
384 case 0x0cd: map_key_clear(KEY_PLAYPAUSE); break;
385 case 0x0e0: map_abs_clear(ABS_VOLUME); break;
386 case 0x0e2: map_key_clear(KEY_MUTE); break;
387 case 0x0e5: map_key_clear(KEY_BASSBOOST); break;
388 case 0x0e9: map_key_clear(KEY_VOLUMEUP); break;
389 case 0x0ea: map_key_clear(KEY_VOLUMEDOWN); break;
390
391 case 0x182: map_key_clear(KEY_BOOKMARKS); break;
392 case 0x183: map_key_clear(KEY_CONFIG); break;
393 case 0x184: map_key_clear(KEY_WORDPROCESSOR); break;
394 case 0x185: map_key_clear(KEY_EDITOR); break;
395 case 0x186: map_key_clear(KEY_SPREADSHEET); break;
396 case 0x187: map_key_clear(KEY_GRAPHICSEDITOR); break;
397 case 0x188: map_key_clear(KEY_PRESENTATION); break;
398 case 0x189: map_key_clear(KEY_DATABASE); break;
399 case 0x18a: map_key_clear(KEY_MAIL); break;
400 case 0x18b: map_key_clear(KEY_NEWS); break;
401 case 0x18c: map_key_clear(KEY_VOICEMAIL); break;
402 case 0x18d: map_key_clear(KEY_ADDRESSBOOK); break;
403 case 0x18e: map_key_clear(KEY_CALENDAR); break;
404 case 0x191: map_key_clear(KEY_FINANCE); break;
405 case 0x192: map_key_clear(KEY_CALC); break;
406 case 0x194: map_key_clear(KEY_FILE); break;
407 case 0x196: map_key_clear(KEY_WWW); break;
408 case 0x19c: map_key_clear(KEY_LOGOFF); break;
409 case 0x19e: map_key_clear(KEY_COFFEE); break;
410 case 0x1a6: map_key_clear(KEY_HELP); break;
411 case 0x1a7: map_key_clear(KEY_DOCUMENTS); break;
412 case 0x1ab: map_key_clear(KEY_SPELLCHECK); break;
413 case 0x1b6: map_key_clear(KEY_MEDIA); break;
414 case 0x1b7: map_key_clear(KEY_SOUND); break;
415 case 0x1bc: map_key_clear(KEY_MESSENGER); break;
416 case 0x1bd: map_key_clear(KEY_INFO); break;
417 case 0x201: map_key_clear(KEY_NEW); break;
418 case 0x202: map_key_clear(KEY_OPEN); break;
419 case 0x203: map_key_clear(KEY_CLOSE); break;
420 case 0x204: map_key_clear(KEY_EXIT); break;
421 case 0x207: map_key_clear(KEY_SAVE); break;
422 case 0x208: map_key_clear(KEY_PRINT); break;
423 case 0x209: map_key_clear(KEY_PROPS); break;
424 case 0x21a: map_key_clear(KEY_UNDO); break;
425 case 0x21b: map_key_clear(KEY_COPY); break;
426 case 0x21c: map_key_clear(KEY_CUT); break;
427 case 0x21d: map_key_clear(KEY_PASTE); break;
428 case 0x21f: map_key_clear(KEY_FIND); break;
429 case 0x221: map_key_clear(KEY_SEARCH); break;
430 case 0x222: map_key_clear(KEY_GOTO); break;
431 case 0x223: map_key_clear(KEY_HOMEPAGE); break;
432 case 0x224: map_key_clear(KEY_BACK); break;
433 case 0x225: map_key_clear(KEY_FORWARD); break;
434 case 0x226: map_key_clear(KEY_STOP); break;
435 case 0x227: map_key_clear(KEY_REFRESH); break;
436 case 0x22a: map_key_clear(KEY_BOOKMARKS); break;
437 case 0x22d: map_key_clear(KEY_ZOOMIN); break;
438 case 0x22e: map_key_clear(KEY_ZOOMOUT); break;
439 case 0x22f: map_key_clear(KEY_ZOOMRESET); break;
440 case 0x233: map_key_clear(KEY_SCROLLUP); break;
441 case 0x234: map_key_clear(KEY_SCROLLDOWN); break;
442 case 0x238: map_rel(REL_HWHEEL); break;
443 case 0x25f: map_key_clear(KEY_CANCEL); break;
444 case 0x279: map_key_clear(KEY_REDO); break;
445
446 case 0x289: map_key_clear(KEY_REPLY); break;
447 case 0x28b: map_key_clear(KEY_FORWARDMAIL); break;
448 case 0x28c: map_key_clear(KEY_SEND); break;
449
450 default: goto ignore;
451 }
452 break;
453
454 case HID_UP_HPVENDOR: /* Reported on a Dutch layout HP5308 */
455 set_bit(EV_REP, input->evbit);
456 switch (usage->hid & HID_USAGE) {
457 case 0x021: map_key_clear(KEY_PRINT); break;
458 case 0x070: map_key_clear(KEY_HP); break;
459 case 0x071: map_key_clear(KEY_CAMERA); break;
460 case 0x072: map_key_clear(KEY_SOUND); break;
461 case 0x073: map_key_clear(KEY_QUESTION); break;
462 case 0x080: map_key_clear(KEY_EMAIL); break;
463 case 0x081: map_key_clear(KEY_CHAT); break;
464 case 0x082: map_key_clear(KEY_SEARCH); break;
465 case 0x083: map_key_clear(KEY_CONNECT); break;
466 case 0x084: map_key_clear(KEY_FINANCE); break;
467 case 0x085: map_key_clear(KEY_SPORT); break;
468 case 0x086: map_key_clear(KEY_SHOP); break;
469 default: goto ignore;
470 }
471 break;
728 472
729 goto ignore; 473 case HID_UP_MSVENDOR:
730 474 goto ignore;
731 case HID_UP_PID:
732 475
733 switch(usage->hid & HID_USAGE) { 476 case HID_UP_CUSTOM: /* Reported on Logitech and Apple USB keyboards */
734 case 0xa4: map_key_clear(BTN_DEAD); break; 477 set_bit(EV_REP, input->evbit);
735 default: goto ignore; 478 goto ignore;
736 }
737 break;
738 479
739 default: 480 case HID_UP_LOGIVENDOR:
740 unknown: 481 goto ignore;
741 if (field->report_size == 1) { 482
742 if (field->report->type == HID_OUTPUT_REPORT) { 483 case HID_UP_PID:
743 map_led(LED_MISC); 484 switch (usage->hid & HID_USAGE) {
744 break; 485 case 0xa4: map_key_clear(BTN_DEAD); break;
745 } 486 default: goto ignore;
746 map_key(BTN_MISC); 487 }
747 break; 488 break;
748 } 489
749 if (field->flags & HID_MAIN_ITEM_RELATIVE) { 490 default:
750 map_rel(REL_MISC); 491 unknown:
492 if (field->report_size == 1) {
493 if (field->report->type == HID_OUTPUT_REPORT) {
494 map_led(LED_MISC);
751 break; 495 break;
752 } 496 }
753 map_abs(ABS_MISC); 497 map_key(BTN_MISC);
498 break;
499 }
500 if (field->flags & HID_MAIN_ITEM_RELATIVE) {
501 map_rel(REL_MISC);
754 break; 502 break;
503 }
504 map_abs(ABS_MISC);
505 break;
755 } 506 }
756 507
757mapped: 508mapped:
758 if (device->quirks & HID_QUIRK_MIGHTYMOUSE) { 509 if (device->driver->input_mapped && device->driver->input_mapped(device,
759 if (usage->hid == HID_GD_Z) 510 hidinput, field, usage, &bit, &max) < 0)
760 map_rel(REL_HWHEEL);
761 else if (usage->code == BTN_1)
762 map_key(BTN_2);
763 else if (usage->code == BTN_2)
764 map_key(BTN_1);
765 }
766
767 if ((device->quirks & (HID_QUIRK_2WHEEL_MOUSE_HACK_7 | HID_QUIRK_2WHEEL_MOUSE_HACK_5 |
768 HID_QUIRK_2WHEEL_MOUSE_HACK_B8)) && (usage->type == EV_REL) &&
769 (usage->code == REL_WHEEL))
770 set_bit(REL_HWHEEL, bit);
771
772 if (((device->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_5) && (usage->hid == 0x00090005))
773 || ((device->quirks & HID_QUIRK_2WHEEL_MOUSE_HACK_7) && (usage->hid == 0x00090007)))
774 goto ignore; 511 goto ignore;
775 512
776 if ((device->quirks & HID_QUIRK_BAD_RELATIVE_KEYS) &&
777 usage->type == EV_KEY && (field->flags & HID_MAIN_ITEM_RELATIVE))
778 field->flags &= ~HID_MAIN_ITEM_RELATIVE;
779
780 set_bit(usage->type, input->evbit); 513 set_bit(usage->type, input->evbit);
781 514
782 if (device->quirks & HID_QUIRK_DUPLICATE_USAGES &&
783 (usage->type == EV_KEY ||
784 usage->type == EV_REL ||
785 usage->type == EV_ABS))
786 clear_bit(usage->code, bit);
787
788 while (usage->code <= max && test_and_set_bit(usage->code, bit)) 515 while (usage->code <= max && test_and_set_bit(usage->code, bit))
789 usage->code = find_next_zero_bit(bit, max + 1, usage->code); 516 usage->code = find_next_zero_bit(bit, max + 1, usage->code);
790 517
@@ -858,10 +585,6 @@ void hidinput_hid_event(struct hid_device *hid, struct hid_field *field, struct
858 if (!usage->type) 585 if (!usage->type)
859 return; 586 return;
860 587
861 /* handle input events for quirky devices */
862 if (hidinput_event_quirks(hid, field, usage, value))
863 return;
864
865 if (usage->hat_min < usage->hat_max || usage->hat_dir) { 588 if (usage->hat_min < usage->hat_max || usage->hat_dir) {
866 int hat_dir = usage->hat_dir; 589 int hat_dir = usage->hat_dir;
867 if (!hat_dir) 590 if (!hat_dir)
@@ -961,14 +684,14 @@ static int hidinput_open(struct input_dev *dev)
961{ 684{
962 struct hid_device *hid = input_get_drvdata(dev); 685 struct hid_device *hid = input_get_drvdata(dev);
963 686
964 return hid->hid_open(hid); 687 return hid->ll_driver->open(hid);
965} 688}
966 689
967static void hidinput_close(struct input_dev *dev) 690static void hidinput_close(struct input_dev *dev)
968{ 691{
969 struct hid_device *hid = input_get_drvdata(dev); 692 struct hid_device *hid = input_get_drvdata(dev);
970 693
971 hid->hid_close(hid); 694 hid->ll_driver->close(hid);
972} 695}
973 696
974/* 697/*
@@ -977,7 +700,7 @@ static void hidinput_close(struct input_dev *dev)
977 * Read all reports and initialize the absolute field values. 700 * Read all reports and initialize the absolute field values.
978 */ 701 */
979 702
980int hidinput_connect(struct hid_device *hid) 703int hidinput_connect(struct hid_device *hid, unsigned int force)
981{ 704{
982 struct hid_report *report; 705 struct hid_report *report;
983 struct hid_input *hidinput = NULL; 706 struct hid_input *hidinput = NULL;
@@ -985,19 +708,20 @@ int hidinput_connect(struct hid_device *hid)
985 int i, j, k; 708 int i, j, k;
986 int max_report_type = HID_OUTPUT_REPORT; 709 int max_report_type = HID_OUTPUT_REPORT;
987 710
988 if (hid->quirks & HID_QUIRK_IGNORE_HIDINPUT)
989 return -1;
990
991 INIT_LIST_HEAD(&hid->inputs); 711 INIT_LIST_HEAD(&hid->inputs);
992 712
993 for (i = 0; i < hid->maxcollection; i++) 713 if (!force) {
994 if (hid->collection[i].type == HID_COLLECTION_APPLICATION || 714 for (i = 0; i < hid->maxcollection; i++) {
995 hid->collection[i].type == HID_COLLECTION_PHYSICAL) 715 struct hid_collection *col = &hid->collection[i];
996 if (IS_INPUT_APPLICATION(hid->collection[i].usage)) 716 if (col->type == HID_COLLECTION_APPLICATION ||
997 break; 717 col->type == HID_COLLECTION_PHYSICAL)
718 if (IS_INPUT_APPLICATION(col->usage))
719 break;
720 }
998 721
999 if (i == hid->maxcollection && (hid->quirks & HID_QUIRK_HIDINPUT) == 0) 722 if (i == hid->maxcollection)
1000 return -1; 723 return -1;
724 }
1001 725
1002 if (hid->quirks & HID_QUIRK_SKIP_OUTPUT_REPORTS) 726 if (hid->quirks & HID_QUIRK_SKIP_OUTPUT_REPORTS)
1003 max_report_type = HID_INPUT_REPORT; 727 max_report_type = HID_INPUT_REPORT;
@@ -1019,7 +743,8 @@ int hidinput_connect(struct hid_device *hid)
1019 } 743 }
1020 744
1021 input_set_drvdata(input_dev, hid); 745 input_set_drvdata(input_dev, hid);
1022 input_dev->event = hid->hidinput_input_event; 746 input_dev->event =
747 hid->ll_driver->hidinput_input_event;
1023 input_dev->open = hidinput_open; 748 input_dev->open = hidinput_open;
1024 input_dev->close = hidinput_close; 749 input_dev->close = hidinput_close;
1025 input_dev->setkeycode = hidinput_setkeycode; 750 input_dev->setkeycode = hidinput_setkeycode;
@@ -1032,7 +757,7 @@ int hidinput_connect(struct hid_device *hid)
1032 input_dev->id.vendor = hid->vendor; 757 input_dev->id.vendor = hid->vendor;
1033 input_dev->id.product = hid->product; 758 input_dev->id.product = hid->product;
1034 input_dev->id.version = hid->version; 759 input_dev->id.version = hid->version;
1035 input_dev->dev.parent = hid->dev; 760 input_dev->dev.parent = hid->dev.parent;
1036 hidinput->input = input_dev; 761 hidinput->input = input_dev;
1037 list_add_tail(&hidinput->list, &hid->inputs); 762 list_add_tail(&hidinput->list, &hid->inputs);
1038 } 763 }
diff --git a/drivers/hid/hid-lg.c b/drivers/hid/hid-lg.c
new file mode 100644
index 000000000000..406d8c82abf1
--- /dev/null
+++ b/drivers/hid/hid-lg.c
@@ -0,0 +1,342 @@
1/*
2 * HID driver for some logitech "special" devices
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/hid.h>
21#include <linux/module.h>
22
23#include "hid-ids.h"
24#include "hid-lg.h"
25
26#define LG_RDESC 0x001
27#define LG_BAD_RELATIVE_KEYS 0x002
28#define LG_DUPLICATE_USAGES 0x004
29#define LG_RESET_LEDS 0x008
30#define LG_EXPANDED_KEYMAP 0x010
31#define LG_IGNORE_DOUBLED_WHEEL 0x020
32#define LG_WIRELESS 0x040
33#define LG_INVERT_HWHEEL 0x080
34#define LG_NOGET 0x100
35#define LG_FF 0x200
36#define LG_FF2 0x400
37
38/*
39 * Certain Logitech keyboards send in report #3 keys which are far
40 * above the logical maximum described in descriptor. This extends
41 * the original value of 0x28c of logical maximum to 0x104d
42 */
43static void lg_report_fixup(struct hid_device *hdev, __u8 *rdesc,
44 unsigned int rsize)
45{
46 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
47
48 if ((quirks & LG_RDESC) && rsize >= 90 && rdesc[83] == 0x26 &&
49 rdesc[84] == 0x8c && rdesc[85] == 0x02) {
50 dev_info(&hdev->dev, "fixing up Logitech keyboard report "
51 "descriptor\n");
52 rdesc[84] = rdesc[89] = 0x4d;
53 rdesc[85] = rdesc[90] = 0x10;
54 }
55}
56
57#define lg_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
58 EV_KEY, (c))
59
60static int lg_ultrax_remote_mapping(struct hid_input *hi,
61 struct hid_usage *usage, unsigned long **bit, int *max)
62{
63 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_LOGIVENDOR)
64 return 0;
65
66 set_bit(EV_REP, hi->input->evbit);
67 switch (usage->hid & HID_USAGE) {
68 /* Reported on Logitech Ultra X Media Remote */
69 case 0x004: lg_map_key_clear(KEY_AGAIN); break;
70 case 0x00d: lg_map_key_clear(KEY_HOME); break;
71 case 0x024: lg_map_key_clear(KEY_SHUFFLE); break;
72 case 0x025: lg_map_key_clear(KEY_TV); break;
73 case 0x026: lg_map_key_clear(KEY_MENU); break;
74 case 0x031: lg_map_key_clear(KEY_AUDIO); break;
75 case 0x032: lg_map_key_clear(KEY_TEXT); break;
76 case 0x033: lg_map_key_clear(KEY_LAST); break;
77 case 0x047: lg_map_key_clear(KEY_MP3); break;
78 case 0x048: lg_map_key_clear(KEY_DVD); break;
79 case 0x049: lg_map_key_clear(KEY_MEDIA); break;
80 case 0x04a: lg_map_key_clear(KEY_VIDEO); break;
81 case 0x04b: lg_map_key_clear(KEY_ANGLE); break;
82 case 0x04c: lg_map_key_clear(KEY_LANGUAGE); break;
83 case 0x04d: lg_map_key_clear(KEY_SUBTITLE); break;
84 case 0x051: lg_map_key_clear(KEY_RED); break;
85 case 0x052: lg_map_key_clear(KEY_CLOSE); break;
86
87 default:
88 return 0;
89 }
90 return 1;
91}
92
93static int lg_wireless_mapping(struct hid_input *hi, struct hid_usage *usage,
94 unsigned long **bit, int *max)
95{
96 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
97 return 0;
98
99 switch (usage->hid & HID_USAGE) {
100 case 0x1001: lg_map_key_clear(KEY_MESSENGER); break;
101 case 0x1003: lg_map_key_clear(KEY_SOUND); break;
102 case 0x1004: lg_map_key_clear(KEY_VIDEO); break;
103 case 0x1005: lg_map_key_clear(KEY_AUDIO); break;
104 case 0x100a: lg_map_key_clear(KEY_DOCUMENTS); break;
105 case 0x1011: lg_map_key_clear(KEY_PREVIOUSSONG); break;
106 case 0x1012: lg_map_key_clear(KEY_NEXTSONG); break;
107 case 0x1013: lg_map_key_clear(KEY_CAMERA); break;
108 case 0x1014: lg_map_key_clear(KEY_MESSENGER); break;
109 case 0x1015: lg_map_key_clear(KEY_RECORD); break;
110 case 0x1016: lg_map_key_clear(KEY_PLAYER); break;
111 case 0x1017: lg_map_key_clear(KEY_EJECTCD); break;
112 case 0x1018: lg_map_key_clear(KEY_MEDIA); break;
113 case 0x1019: lg_map_key_clear(KEY_PROG1); break;
114 case 0x101a: lg_map_key_clear(KEY_PROG2); break;
115 case 0x101b: lg_map_key_clear(KEY_PROG3); break;
116 case 0x101f: lg_map_key_clear(KEY_ZOOMIN); break;
117 case 0x1020: lg_map_key_clear(KEY_ZOOMOUT); break;
118 case 0x1021: lg_map_key_clear(KEY_ZOOMRESET); break;
119 case 0x1023: lg_map_key_clear(KEY_CLOSE); break;
120 case 0x1027: lg_map_key_clear(KEY_MENU); break;
121 /* this one is marked as 'Rotate' */
122 case 0x1028: lg_map_key_clear(KEY_ANGLE); break;
123 case 0x1029: lg_map_key_clear(KEY_SHUFFLE); break;
124 case 0x102a: lg_map_key_clear(KEY_BACK); break;
125 case 0x102b: lg_map_key_clear(KEY_CYCLEWINDOWS); break;
126 case 0x1041: lg_map_key_clear(KEY_BATTERY); break;
127 case 0x1042: lg_map_key_clear(KEY_WORDPROCESSOR); break;
128 case 0x1043: lg_map_key_clear(KEY_SPREADSHEET); break;
129 case 0x1044: lg_map_key_clear(KEY_PRESENTATION); break;
130 case 0x1045: lg_map_key_clear(KEY_UNDO); break;
131 case 0x1046: lg_map_key_clear(KEY_REDO); break;
132 case 0x1047: lg_map_key_clear(KEY_PRINT); break;
133 case 0x1048: lg_map_key_clear(KEY_SAVE); break;
134 case 0x1049: lg_map_key_clear(KEY_PROG1); break;
135 case 0x104a: lg_map_key_clear(KEY_PROG2); break;
136 case 0x104b: lg_map_key_clear(KEY_PROG3); break;
137 case 0x104c: lg_map_key_clear(KEY_PROG4); break;
138
139 default:
140 return 0;
141 }
142 return 1;
143}
144
145static int lg_input_mapping(struct hid_device *hdev, struct hid_input *hi,
146 struct hid_field *field, struct hid_usage *usage,
147 unsigned long **bit, int *max)
148{
149 /* extended mapping for certain Logitech hardware (Logitech cordless
150 desktop LX500) */
151 static const u8 e_keymap[] = {
152 0,216, 0,213,175,156, 0, 0, 0, 0,
153 144, 0, 0, 0, 0, 0, 0, 0, 0,212,
154 174,167,152,161,112, 0, 0, 0,154, 0,
155 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
156 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
157 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
158 0, 0, 0, 0, 0,183,184,185,186,187,
159 188,189,190,191,192,193,194, 0, 0, 0
160 };
161 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
162 unsigned int hid = usage->hid;
163
164 if (hdev->product == USB_DEVICE_ID_LOGITECH_RECEIVER &&
165 lg_ultrax_remote_mapping(hi, usage, bit, max))
166 return 1;
167
168 if ((quirks & LG_WIRELESS) && lg_wireless_mapping(hi, usage, bit, max))
169 return 1;
170
171 if ((hid & HID_USAGE_PAGE) != HID_UP_BUTTON)
172 return 0;
173
174 hid &= HID_USAGE;
175
176 /* Special handling for Logitech Cordless Desktop */
177 if (field->application == HID_GD_MOUSE) {
178 if ((quirks & LG_IGNORE_DOUBLED_WHEEL) &&
179 (hid == 7 || hid == 8))
180 return -1;
181 } else {
182 if ((quirks & LG_EXPANDED_KEYMAP) &&
183 hid < ARRAY_SIZE(e_keymap) &&
184 e_keymap[hid] != 0) {
185 hid_map_usage(hi, usage, bit, max, EV_KEY,
186 e_keymap[hid]);
187 return 1;
188 }
189 }
190
191 return 0;
192}
193
194static int lg_input_mapped(struct hid_device *hdev, struct hid_input *hi,
195 struct hid_field *field, struct hid_usage *usage,
196 unsigned long **bit, int *max)
197{
198 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
199
200 if ((quirks & LG_BAD_RELATIVE_KEYS) && usage->type == EV_KEY &&
201 (field->flags & HID_MAIN_ITEM_RELATIVE))
202 field->flags &= ~HID_MAIN_ITEM_RELATIVE;
203
204 if ((quirks & LG_DUPLICATE_USAGES) && (usage->type == EV_KEY ||
205 usage->type == EV_REL || usage->type == EV_ABS))
206 clear_bit(usage->code, *bit);
207
208 return 0;
209}
210
211static int lg_event(struct hid_device *hdev, struct hid_field *field,
212 struct hid_usage *usage, __s32 value)
213{
214 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
215
216 if ((quirks & LG_INVERT_HWHEEL) && usage->code == REL_HWHEEL) {
217 input_event(field->hidinput->input, usage->type, usage->code,
218 -value);
219 return 1;
220 }
221
222 return 0;
223}
224
225static int lg_probe(struct hid_device *hdev, const struct hid_device_id *id)
226{
227 unsigned long quirks = id->driver_data;
228 unsigned int connect_mask = HID_CONNECT_DEFAULT;
229 int ret;
230
231 hid_set_drvdata(hdev, (void *)quirks);
232
233 if (quirks & LG_NOGET)
234 hdev->quirks |= HID_QUIRK_NOGET;
235
236 ret = hid_parse(hdev);
237 if (ret) {
238 dev_err(&hdev->dev, "parse failed\n");
239 goto err_free;
240 }
241
242 if (quirks & (LG_FF | LG_FF2))
243 connect_mask &= ~HID_CONNECT_FF;
244
245 ret = hid_hw_start(hdev, connect_mask);
246 if (ret) {
247 dev_err(&hdev->dev, "hw start failed\n");
248 goto err_free;
249 }
250
251 if (quirks & LG_RESET_LEDS)
252 usbhid_set_leds(hdev);
253
254 if (quirks & LG_FF)
255 lgff_init(hdev);
256 if (quirks & LG_FF2)
257 lg2ff_init(hdev);
258
259 return 0;
260err_free:
261 return ret;
262}
263
264static const struct hid_device_id lg_devices[] = {
265 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER),
266 .driver_data = LG_RDESC | LG_WIRELESS },
267 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER),
268 .driver_data = LG_RDESC | LG_WIRELESS },
269 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2),
270 .driver_data = LG_RDESC | LG_WIRELESS },
271
272 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER),
273 .driver_data = LG_BAD_RELATIVE_KEYS },
274
275 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP),
276 .driver_data = LG_DUPLICATE_USAGES },
277 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE),
278 .driver_data = LG_DUPLICATE_USAGES },
279 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI),
280 .driver_data = LG_DUPLICATE_USAGES },
281
282 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_KBD),
283 .driver_data = LG_RESET_LEDS },
284
285 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD),
286 .driver_data = LG_IGNORE_DOUBLED_WHEEL | LG_EXPANDED_KEYMAP },
287 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500),
288 .driver_data = LG_IGNORE_DOUBLED_WHEEL | LG_EXPANDED_KEYMAP },
289
290 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_LX3),
291 .driver_data = LG_INVERT_HWHEEL },
292 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_V150),
293 .driver_data = LG_INVERT_HWHEEL },
294
295 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D),
296 .driver_data = LG_NOGET },
297 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL),
298 .driver_data = LG_NOGET | LG_FF },
299
300 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD),
301 .driver_data = LG_FF },
302 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2_2),
303 .driver_data = LG_FF },
304 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WINGMAN_F3D),
305 .driver_data = LG_FF },
306 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_FORCE3D_PRO),
307 .driver_data = LG_FF },
308 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL),
309 .driver_data = LG_FF },
310 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_MOMO_WHEEL2),
311 .driver_data = LG_FF },
312 { HID_USB_DEVICE(USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RUMBLEPAD2),
313 .driver_data = LG_FF2 },
314 { }
315};
316MODULE_DEVICE_TABLE(hid, lg_devices);
317
318static struct hid_driver lg_driver = {
319 .name = "logitech",
320 .id_table = lg_devices,
321 .report_fixup = lg_report_fixup,
322 .input_mapping = lg_input_mapping,
323 .input_mapped = lg_input_mapped,
324 .event = lg_event,
325 .probe = lg_probe,
326};
327
328static int lg_init(void)
329{
330 return hid_register_driver(&lg_driver);
331}
332
333static void lg_exit(void)
334{
335 hid_unregister_driver(&lg_driver);
336}
337
338module_init(lg_init);
339module_exit(lg_exit);
340MODULE_LICENSE("GPL");
341
342HID_COMPAT_LOAD_DRIVER(logitech);
diff --git a/drivers/hid/hid-lg.h b/drivers/hid/hid-lg.h
new file mode 100644
index 000000000000..27ae750ca878
--- /dev/null
+++ b/drivers/hid/hid-lg.h
@@ -0,0 +1,18 @@
1#ifndef __HID_LG_H
2#define __HID_LG_H
3
4#include <linux/autoconf.h>
5
6#ifdef CONFIG_LOGITECH_FF
7int lgff_init(struct hid_device *hdev);
8#else
9static inline int lgff_init(struct hid_device *hdev) { return -1; }
10#endif
11
12#ifdef CONFIG_LOGIRUMBLEPAD2_FF
13int lg2ff_init(struct hid_device *hdev);
14#else
15static inline int lg2ff_init(struct hid_device *hdev) { return -1; }
16#endif
17
18#endif
diff --git a/drivers/hid/usbhid/hid-lg2ff.c b/drivers/hid/hid-lg2ff.c
index d469bd0061c9..4e6dc6e26523 100644
--- a/drivers/hid/usbhid/hid-lg2ff.c
+++ b/drivers/hid/hid-lg2ff.c
@@ -24,7 +24,9 @@
24#include <linux/input.h> 24#include <linux/input.h>
25#include <linux/usb.h> 25#include <linux/usb.h>
26#include <linux/hid.h> 26#include <linux/hid.h>
27#include "usbhid.h" 27
28#include "usbhid/usbhid.h"
29#include "hid-lg.h"
28 30
29struct lg2ff_device { 31struct lg2ff_device {
30 struct hid_report *report; 32 struct hid_report *report;
@@ -57,7 +59,7 @@ static int play_effect(struct input_dev *dev, void *data,
57 return 0; 59 return 0;
58} 60}
59 61
60int hid_lg2ff_init(struct hid_device *hid) 62int lg2ff_init(struct hid_device *hid)
61{ 63{
62 struct lg2ff_device *lg2ff; 64 struct lg2ff_device *lg2ff;
63 struct hid_report *report; 65 struct hid_report *report;
@@ -69,18 +71,18 @@ int hid_lg2ff_init(struct hid_device *hid)
69 int error; 71 int error;
70 72
71 if (list_empty(report_list)) { 73 if (list_empty(report_list)) {
72 printk(KERN_ERR "hid-lg2ff: no output report found\n"); 74 dev_err(&hid->dev, "no output report found\n");
73 return -ENODEV; 75 return -ENODEV;
74 } 76 }
75 77
76 report = list_entry(report_list->next, struct hid_report, list); 78 report = list_entry(report_list->next, struct hid_report, list);
77 79
78 if (report->maxfield < 1) { 80 if (report->maxfield < 1) {
79 printk(KERN_ERR "hid-lg2ff: output report is empty\n"); 81 dev_err(&hid->dev, "output report is empty\n");
80 return -ENODEV; 82 return -ENODEV;
81 } 83 }
82 if (report->field[0]->report_count < 7) { 84 if (report->field[0]->report_count < 7) {
83 printk(KERN_ERR "hid-lg2ff: not enough values in the field\n"); 85 dev_err(&hid->dev, "not enough values in the field\n");
84 return -ENODEV; 86 return -ENODEV;
85 } 87 }
86 88
@@ -107,7 +109,7 @@ int hid_lg2ff_init(struct hid_device *hid)
107 109
108 usbhid_submit_report(hid, report, USB_DIR_OUT); 110 usbhid_submit_report(hid, report, USB_DIR_OUT);
109 111
110 printk(KERN_INFO "Force feedback for Logitech Rumblepad 2 by " 112 dev_info(&hid->dev, "Force feedback for Logitech Rumblepad 2 by "
111 "Anssi Hannula <anssi.hannula@gmail.com>\n"); 113 "Anssi Hannula <anssi.hannula@gmail.com>\n");
112 114
113 return 0; 115 return 0;
diff --git a/drivers/hid/usbhid/hid-lgff.c b/drivers/hid/hid-lgff.c
index 4b7ab6a46d93..51aff08e10ce 100644
--- a/drivers/hid/usbhid/hid-lgff.c
+++ b/drivers/hid/hid-lgff.c
@@ -30,7 +30,9 @@
30#include <linux/input.h> 30#include <linux/input.h>
31#include <linux/usb.h> 31#include <linux/usb.h>
32#include <linux/hid.h> 32#include <linux/hid.h>
33#include "usbhid.h" 33
34#include "usbhid/usbhid.h"
35#include "hid-lg.h"
34 36
35struct dev_type { 37struct dev_type {
36 u16 idVendor; 38 u16 idVendor;
@@ -48,6 +50,12 @@ static const signed short ff_joystick[] = {
48 -1 50 -1
49}; 51};
50 52
53static const signed short ff_wheel[] = {
54 FF_CONSTANT,
55 FF_AUTOCENTER,
56 -1
57};
58
51static const struct dev_type devices[] = { 59static const struct dev_type devices[] = {
52 { 0x046d, 0xc211, ff_rumble }, 60 { 0x046d, 0xc211, ff_rumble },
53 { 0x046d, 0xc219, ff_rumble }, 61 { 0x046d, 0xc219, ff_rumble },
@@ -55,7 +63,7 @@ static const struct dev_type devices[] = {
55 { 0x046d, 0xc286, ff_joystick }, 63 { 0x046d, 0xc286, ff_joystick },
56 { 0x046d, 0xc294, ff_joystick }, 64 { 0x046d, 0xc294, ff_joystick },
57 { 0x046d, 0xc295, ff_joystick }, 65 { 0x046d, 0xc295, ff_joystick },
58 { 0x046d, 0xca03, ff_joystick }, 66 { 0x046d, 0xca03, ff_wheel },
59}; 67};
60 68
61static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *effect) 69static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *effect)
@@ -100,7 +108,24 @@ static int hid_lgff_play(struct input_dev *dev, void *data, struct ff_effect *ef
100 return 0; 108 return 0;
101} 109}
102 110
103int hid_lgff_init(struct hid_device* hid) 111static void hid_lgff_set_autocenter(struct input_dev *dev, u16 magnitude)
112{
113 struct hid_device *hid = input_get_drvdata(dev);
114 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
115 struct hid_report *report = list_entry(report_list->next, struct hid_report, list);
116 __s32 *value = report->field[0]->value;
117 magnitude = (magnitude >> 12) & 0xf;
118 *value++ = 0xfe;
119 *value++ = 0x0d;
120 *value++ = magnitude; /* clockwise strength */
121 *value++ = magnitude; /* counter-clockwise strength */
122 *value++ = 0x80;
123 *value++ = 0x00;
124 *value = 0x00;
125 usbhid_submit_report(hid, report, USB_DIR_OUT);
126}
127
128int lgff_init(struct hid_device* hid)
104{ 129{
105 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); 130 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list);
106 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list; 131 struct list_head *report_list = &hid->report_enum[HID_OUTPUT_REPORT].report_list;
@@ -145,6 +170,9 @@ int hid_lgff_init(struct hid_device* hid)
145 if (error) 170 if (error)
146 return error; 171 return error;
147 172
173 if ( test_bit(FF_AUTOCENTER, dev->ffbit) )
174 dev->ff->set_autocenter = hid_lgff_set_autocenter;
175
148 printk(KERN_INFO "Force feedback for Logitech force feedback devices by Johann Deneux <johann.deneux@it.uu.se>\n"); 176 printk(KERN_INFO "Force feedback for Logitech force feedback devices by Johann Deneux <johann.deneux@it.uu.se>\n");
149 177
150 return 0; 178 return 0;
diff --git a/drivers/hid/hid-microsoft.c b/drivers/hid/hid-microsoft.c
new file mode 100644
index 000000000000..d718b1607d0f
--- /dev/null
+++ b/drivers/hid/hid-microsoft.c
@@ -0,0 +1,219 @@
1/*
2 * HID driver for some microsoft "special" devices
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/input.h>
21#include <linux/hid.h>
22#include <linux/module.h>
23
24#include "hid-ids.h"
25
26#define MS_HIDINPUT 0x01
27#define MS_ERGONOMY 0x02
28#define MS_PRESENTER 0x04
29#define MS_RDESC 0x08
30#define MS_NOGET 0x10
31
32/*
33 * Microsoft Wireless Desktop Receiver (Model 1028) has several
34 * 'Usage Min/Max' where it ought to have 'Physical Min/Max'
35 */
36static void ms_report_fixup(struct hid_device *hdev, __u8 *rdesc,
37 unsigned int rsize)
38{
39 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
40
41 if ((quirks & MS_RDESC) && rsize == 571 && rdesc[284] == 0x19 &&
42 rdesc[286] == 0x2a && rdesc[304] == 0x19 &&
43 rdesc[306] == 0x29 && rdesc[352] == 0x1a &&
44 rdesc[355] == 0x2a && rdesc[557] == 0x19 &&
45 rdesc[559] == 0x29) {
46 dev_info(&hdev->dev, "fixing up Microsoft Wireless Receiver "
47 "Model 1028 report descriptor\n");
48 rdesc[284] = rdesc[304] = rdesc[557] = 0x35;
49 rdesc[352] = 0x36;
50 rdesc[286] = rdesc[355] = 0x46;
51 rdesc[306] = rdesc[559] = 0x45;
52 }
53}
54
55#define ms_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
56 EV_KEY, (c))
57static int ms_ergonomy_kb_quirk(struct hid_input *hi, struct hid_usage *usage,
58 unsigned long **bit, int *max)
59{
60 struct input_dev *input = hi->input;
61
62 switch (usage->hid & HID_USAGE) {
63 case 0xfd06: ms_map_key_clear(KEY_CHAT); break;
64 case 0xfd07: ms_map_key_clear(KEY_PHONE); break;
65 case 0xff05:
66 set_bit(EV_REP, input->evbit);
67 ms_map_key_clear(KEY_F13);
68 set_bit(KEY_F14, input->keybit);
69 set_bit(KEY_F15, input->keybit);
70 set_bit(KEY_F16, input->keybit);
71 set_bit(KEY_F17, input->keybit);
72 set_bit(KEY_F18, input->keybit);
73 default:
74 return 0;
75 }
76 return 1;
77}
78
79static int ms_presenter_8k_quirk(struct hid_input *hi, struct hid_usage *usage,
80 unsigned long **bit, int *max)
81{
82 set_bit(EV_REP, hi->input->evbit);
83 switch (usage->hid & HID_USAGE) {
84 case 0xfd08: ms_map_key_clear(KEY_FORWARD); break;
85 case 0xfd09: ms_map_key_clear(KEY_BACK); break;
86 case 0xfd0b: ms_map_key_clear(KEY_PLAYPAUSE); break;
87 case 0xfd0e: ms_map_key_clear(KEY_CLOSE); break;
88 case 0xfd0f: ms_map_key_clear(KEY_PLAY); break;
89 default:
90 return 0;
91 }
92 return 1;
93}
94
95static int ms_input_mapping(struct hid_device *hdev, struct hid_input *hi,
96 struct hid_field *field, struct hid_usage *usage,
97 unsigned long **bit, int *max)
98{
99 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
100
101 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_MSVENDOR)
102 return 0;
103
104 if (quirks & MS_ERGONOMY) {
105 int ret = ms_ergonomy_kb_quirk(hi, usage, bit, max);
106 if (ret)
107 return ret;
108 }
109
110 if ((quirks & MS_PRESENTER) &&
111 ms_presenter_8k_quirk(hi, usage, bit, max))
112 return 1;
113
114 return 0;
115}
116
117static int ms_event(struct hid_device *hdev, struct hid_field *field,
118 struct hid_usage *usage, __s32 value)
119{
120 unsigned long quirks = (unsigned long)hid_get_drvdata(hdev);
121
122 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
123 !usage->type)
124 return 0;
125
126 /* Handling MS keyboards special buttons */
127 if (quirks & MS_ERGONOMY && usage->hid == (HID_UP_MSVENDOR | 0xff05)) {
128 struct input_dev *input = field->hidinput->input;
129 static unsigned int last_key = 0;
130 unsigned int key = 0;
131 switch (value) {
132 case 0x01: key = KEY_F14; break;
133 case 0x02: key = KEY_F15; break;
134 case 0x04: key = KEY_F16; break;
135 case 0x08: key = KEY_F17; break;
136 case 0x10: key = KEY_F18; break;
137 }
138 if (key) {
139 input_event(input, usage->type, key, 1);
140 last_key = key;
141 } else
142 input_event(input, usage->type, last_key, 0);
143
144 return 1;
145 }
146
147 return 0;
148}
149
150static int ms_probe(struct hid_device *hdev, const struct hid_device_id *id)
151{
152 unsigned long quirks = id->driver_data;
153 int ret;
154
155 hid_set_drvdata(hdev, (void *)quirks);
156
157 if (quirks & MS_NOGET)
158 hdev->quirks |= HID_QUIRK_NOGET;
159
160 ret = hid_parse(hdev);
161 if (ret) {
162 dev_err(&hdev->dev, "parse failed\n");
163 goto err_free;
164 }
165
166 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT | ((quirks & MS_HIDINPUT) ?
167 HID_CONNECT_HIDINPUT_FORCE : 0));
168 if (ret) {
169 dev_err(&hdev->dev, "hw start failed\n");
170 goto err_free;
171 }
172
173 return 0;
174err_free:
175 return ret;
176}
177
178static const struct hid_device_id ms_devices[] = {
179 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV),
180 .driver_data = MS_HIDINPUT },
181 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K),
182 .driver_data = MS_ERGONOMY },
183 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K),
184 .driver_data = MS_ERGONOMY | MS_RDESC },
185 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_USB),
186 .driver_data = MS_PRESENTER },
187 { HID_USB_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0),
188 .driver_data = MS_NOGET },
189
190 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_PRESENTER_8K_BT),
191 .driver_data = MS_PRESENTER },
192 { }
193};
194MODULE_DEVICE_TABLE(hid, ms_devices);
195
196static struct hid_driver ms_driver = {
197 .name = "microsoft",
198 .id_table = ms_devices,
199 .report_fixup = ms_report_fixup,
200 .input_mapping = ms_input_mapping,
201 .event = ms_event,
202 .probe = ms_probe,
203};
204
205static int ms_init(void)
206{
207 return hid_register_driver(&ms_driver);
208}
209
210static void ms_exit(void)
211{
212 hid_unregister_driver(&ms_driver);
213}
214
215module_init(ms_init);
216module_exit(ms_exit);
217MODULE_LICENSE("GPL");
218
219HID_COMPAT_LOAD_DRIVER(microsoft);
diff --git a/drivers/hid/hid-monterey.c b/drivers/hid/hid-monterey.c
new file mode 100644
index 000000000000..f3a85a065f18
--- /dev/null
+++ b/drivers/hid/hid-monterey.c
@@ -0,0 +1,82 @@
1/*
2 * HID driver for some monterey "special" devices
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/hid.h>
21#include <linux/module.h>
22
23#include "hid-ids.h"
24
25static void mr_report_fixup(struct hid_device *hdev, __u8 *rdesc,
26 unsigned int rsize)
27{
28 if (rsize >= 30 && rdesc[29] == 0x05 && rdesc[30] == 0x09) {
29 dev_info(&hdev->dev, "fixing up button/consumer in HID report "
30 "descriptor\n");
31 rdesc[30] = 0x0c;
32 }
33}
34
35#define mr_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
36 EV_KEY, (c))
37static int mr_input_mapping(struct hid_device *hdev, struct hid_input *hi,
38 struct hid_field *field, struct hid_usage *usage,
39 unsigned long **bit, int *max)
40{
41 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
42 return 0;
43
44 switch (usage->hid & HID_USAGE) {
45 case 0x156: mr_map_key_clear(KEY_WORDPROCESSOR); break;
46 case 0x157: mr_map_key_clear(KEY_SPREADSHEET); break;
47 case 0x158: mr_map_key_clear(KEY_PRESENTATION); break;
48 case 0x15c: mr_map_key_clear(KEY_STOP); break;
49 default:
50 return 0;
51 }
52 return 1;
53}
54
55static const struct hid_device_id mr_devices[] = {
56 { HID_USB_DEVICE(USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E) },
57 { }
58};
59MODULE_DEVICE_TABLE(hid, mr_devices);
60
61static struct hid_driver mr_driver = {
62 .name = "monterey",
63 .id_table = mr_devices,
64 .report_fixup = mr_report_fixup,
65 .input_mapping = mr_input_mapping,
66};
67
68static int mr_init(void)
69{
70 return hid_register_driver(&mr_driver);
71}
72
73static void mr_exit(void)
74{
75 hid_unregister_driver(&mr_driver);
76}
77
78module_init(mr_init);
79module_exit(mr_exit);
80MODULE_LICENSE("GPL");
81
82HID_COMPAT_LOAD_DRIVER(monterey);
diff --git a/drivers/hid/hid-petalynx.c b/drivers/hid/hid-petalynx.c
new file mode 100644
index 000000000000..10945fe12d50
--- /dev/null
+++ b/drivers/hid/hid-petalynx.c
@@ -0,0 +1,122 @@
1/*
2 * HID driver for some petalynx "special" devices
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/hid.h>
21#include <linux/module.h>
22
23#include "hid-ids.h"
24
25/* Petalynx Maxter Remote has maximum for consumer page set too low */
26static void pl_report_fixup(struct hid_device *hdev, __u8 *rdesc,
27 unsigned int rsize)
28{
29 if (rsize >= 60 && rdesc[39] == 0x2a && rdesc[40] == 0xf5 &&
30 rdesc[41] == 0x00 && rdesc[59] == 0x26 &&
31 rdesc[60] == 0xf9 && rdesc[61] == 0x00) {
32 dev_info(&hdev->dev, "fixing up Petalynx Maxter Remote report "
33 "descriptor\n");
34 rdesc[60] = 0xfa;
35 rdesc[40] = 0xfa;
36 }
37}
38
39#define pl_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
40 EV_KEY, (c))
41static int pl_input_mapping(struct hid_device *hdev, struct hid_input *hi,
42 struct hid_field *field, struct hid_usage *usage,
43 unsigned long **bit, int *max)
44{
45 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_LOGIVENDOR) {
46 switch (usage->hid & HID_USAGE) {
47 case 0x05a: pl_map_key_clear(KEY_TEXT); break;
48 case 0x05b: pl_map_key_clear(KEY_RED); break;
49 case 0x05c: pl_map_key_clear(KEY_GREEN); break;
50 case 0x05d: pl_map_key_clear(KEY_YELLOW); break;
51 case 0x05e: pl_map_key_clear(KEY_BLUE); break;
52 default:
53 return 0;
54 }
55 return 1;
56 }
57
58 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER) {
59 switch (usage->hid & HID_USAGE) {
60 case 0x0f6: pl_map_key_clear(KEY_NEXT); break;
61 case 0x0fa: pl_map_key_clear(KEY_BACK); break;
62 default:
63 return 0;
64 }
65 return 1;
66 }
67
68 return 0;
69}
70
71static int pl_probe(struct hid_device *hdev, const struct hid_device_id *id)
72{
73 int ret;
74
75 hdev->quirks |= HID_QUIRK_NOGET;
76
77 ret = hid_parse(hdev);
78 if (ret) {
79 dev_err(&hdev->dev, "parse failed\n");
80 goto err_free;
81 }
82
83 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
84 if (ret) {
85 dev_err(&hdev->dev, "hw start failed\n");
86 goto err_free;
87 }
88
89 return 0;
90err_free:
91 return ret;
92}
93
94static const struct hid_device_id pl_devices[] = {
95 { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) },
96 { }
97};
98MODULE_DEVICE_TABLE(hid, pl_devices);
99
100static struct hid_driver pl_driver = {
101 .name = "petalynx",
102 .id_table = pl_devices,
103 .report_fixup = pl_report_fixup,
104 .input_mapping = pl_input_mapping,
105 .probe = pl_probe,
106};
107
108static int pl_init(void)
109{
110 return hid_register_driver(&pl_driver);
111}
112
113static void pl_exit(void)
114{
115 hid_unregister_driver(&pl_driver);
116}
117
118module_init(pl_init);
119module_exit(pl_exit);
120MODULE_LICENSE("GPL");
121
122HID_COMPAT_LOAD_DRIVER(petalynx);
diff --git a/drivers/hid/usbhid/hid-plff.c b/drivers/hid/hid-pl.c
index 9eb83cf9d22b..acd815586182 100644
--- a/drivers/hid/usbhid/hid-plff.c
+++ b/drivers/hid/hid-pl.c
@@ -9,7 +9,7 @@
9 * - contains two reports, one for each port (HID_QUIRK_MULTI_INPUT) 9 * - contains two reports, one for each port (HID_QUIRK_MULTI_INPUT)
10 * 10 *
11 * 0e8f:0003 "GreenAsia Inc. USB Joystick " 11 * 0e8f:0003 "GreenAsia Inc. USB Joystick "
12 * - tested with Köng Gaming gamepad 12 * - tested with K??ng Gaming gamepad
13 * 13 *
14 * Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com> 14 * Copyright (c) 2007 Anssi Hannula <anssi.hannula@gmail.com>
15 */ 15 */
@@ -38,7 +38,11 @@
38#include <linux/input.h> 38#include <linux/input.h>
39#include <linux/usb.h> 39#include <linux/usb.h>
40#include <linux/hid.h> 40#include <linux/hid.h>
41#include "usbhid.h" 41
42#include "hid-ids.h"
43
44#ifdef CONFIG_PANTHERLORD_FF
45#include "usbhid/usbhid.h"
42 46
43struct plff_device { 47struct plff_device {
44 struct hid_report *report; 48 struct hid_report *report;
@@ -66,7 +70,7 @@ static int hid_plff_play(struct input_dev *dev, void *data,
66 return 0; 70 return 0;
67} 71}
68 72
69int hid_plff_init(struct hid_device *hid) 73static int plff_init(struct hid_device *hid)
70{ 74{
71 struct plff_device *plff; 75 struct plff_device *plff;
72 struct hid_report *report; 76 struct hid_report *report;
@@ -86,7 +90,7 @@ int hid_plff_init(struct hid_device *hid)
86 currently unknown. */ 90 currently unknown. */
87 91
88 if (list_empty(report_list)) { 92 if (list_empty(report_list)) {
89 printk(KERN_ERR "hid-plff: no output reports found\n"); 93 dev_err(&hid->dev, "no output reports found\n");
90 return -ENODEV; 94 return -ENODEV;
91 } 95 }
92 96
@@ -95,18 +99,19 @@ int hid_plff_init(struct hid_device *hid)
95 report_ptr = report_ptr->next; 99 report_ptr = report_ptr->next;
96 100
97 if (report_ptr == report_list) { 101 if (report_ptr == report_list) {
98 printk(KERN_ERR "hid-plff: required output report is missing\n"); 102 dev_err(&hid->dev, "required output report is "
103 "missing\n");
99 return -ENODEV; 104 return -ENODEV;
100 } 105 }
101 106
102 report = list_entry(report_ptr, struct hid_report, list); 107 report = list_entry(report_ptr, struct hid_report, list);
103 if (report->maxfield < 1) { 108 if (report->maxfield < 1) {
104 printk(KERN_ERR "hid-plff: no fields in the report\n"); 109 dev_err(&hid->dev, "no fields in the report\n");
105 return -ENODEV; 110 return -ENODEV;
106 } 111 }
107 112
108 if (report->field[0]->report_count < 4) { 113 if (report->field[0]->report_count < 4) {
109 printk(KERN_ERR "hid-plff: not enough values in the field\n"); 114 dev_err(&hid->dev, "not enough values in the field\n");
110 return -ENODEV; 115 return -ENODEV;
111 } 116 }
112 117
@@ -132,8 +137,70 @@ int hid_plff_init(struct hid_device *hid)
132 usbhid_submit_report(hid, plff->report, USB_DIR_OUT); 137 usbhid_submit_report(hid, plff->report, USB_DIR_OUT);
133 } 138 }
134 139
135 printk(KERN_INFO "hid-plff: Force feedback for PantherLord/GreenAsia " 140 dev_info(&hid->dev, "Force feedback for PantherLord/GreenAsia "
136 "devices by Anssi Hannula <anssi.hannula@gmail.com>\n"); 141 "devices by Anssi Hannula <anssi.hannula@gmail.com>\n");
137 142
138 return 0; 143 return 0;
139} 144}
145#else
146static inline int plff_init(struct hid_device *hid)
147{
148 return 0;
149}
150#endif
151
152static int pl_probe(struct hid_device *hdev, const struct hid_device_id *id)
153{
154 int ret;
155
156 if (id->driver_data)
157 hdev->quirks |= HID_QUIRK_MULTI_INPUT;
158
159 ret = hid_parse(hdev);
160 if (ret) {
161 dev_err(&hdev->dev, "parse failed\n");
162 goto err;
163 }
164
165 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
166 if (ret) {
167 dev_err(&hdev->dev, "hw start failed\n");
168 goto err;
169 }
170
171 plff_init(hdev);
172
173 return 0;
174err:
175 return ret;
176}
177
178static const struct hid_device_id pl_devices[] = {
179 { HID_USB_DEVICE(USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR),
180 .driver_data = 1 }, /* Twin USB Joystick */
181 { HID_USB_DEVICE(USB_VENDOR_ID_GREENASIA, 0x0003), }, /* GreenAsia Inc. USB Joystick */
182 { }
183};
184MODULE_DEVICE_TABLE(hid, pl_devices);
185
186static struct hid_driver pl_driver = {
187 .name = "pantherlord",
188 .id_table = pl_devices,
189 .probe = pl_probe,
190};
191
192static int pl_init(void)
193{
194 return hid_register_driver(&pl_driver);
195}
196
197static void pl_exit(void)
198{
199 hid_unregister_driver(&pl_driver);
200}
201
202module_init(pl_init);
203module_exit(pl_exit);
204MODULE_LICENSE("GPL");
205
206HID_COMPAT_LOAD_DRIVER(pantherlord);
diff --git a/drivers/hid/hid-samsung.c b/drivers/hid/hid-samsung.c
new file mode 100644
index 000000000000..15f3c0492450
--- /dev/null
+++ b/drivers/hid/hid-samsung.c
@@ -0,0 +1,100 @@
1/*
2 * HID driver for some samsung "special" devices
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/hid.h>
21#include <linux/module.h>
22
23#include "hid-ids.h"
24
25/*
26 * Samsung IrDA remote controller (reports as Cypress USB Mouse).
27 *
28 * Vendor specific report #4 has a size of 48 bit,
29 * and therefore is not accepted when inspecting the descriptors.
30 * As a workaround we reinterpret the report as:
31 * Variable type, count 6, size 8 bit, log. maximum 255
32 * The burden to reconstruct the data is moved into user space.
33 */
34static void samsung_report_fixup(struct hid_device *hdev, __u8 *rdesc,
35 unsigned int rsize)
36{
37 if (rsize >= 182 && rdesc[175] == 0x25 && rdesc[176] == 0x40 &&
38 rdesc[177] == 0x75 && rdesc[178] == 0x30 &&
39 rdesc[179] == 0x95 && rdesc[180] == 0x01 &&
40 rdesc[182] == 0x40) {
41 dev_info(&hdev->dev, "fixing up Samsung IrDA report "
42 "descriptor\n");
43 rdesc[176] = 0xff;
44 rdesc[178] = 0x08;
45 rdesc[180] = 0x06;
46 rdesc[182] = 0x42;
47 }
48}
49
50static int samsung_probe(struct hid_device *hdev,
51 const struct hid_device_id *id)
52{
53 int ret;
54
55 ret = hid_parse(hdev);
56 if (ret) {
57 dev_err(&hdev->dev, "parse failed\n");
58 goto err_free;
59 }
60
61 ret = hid_hw_start(hdev, (HID_CONNECT_DEFAULT & ~HID_CONNECT_HIDINPUT) |
62 HID_CONNECT_HIDDEV_FORCE);
63 if (ret) {
64 dev_err(&hdev->dev, "hw start failed\n");
65 goto err_free;
66 }
67
68 return 0;
69err_free:
70 return ret;
71}
72
73static const struct hid_device_id samsung_devices[] = {
74 { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) },
75 { }
76};
77MODULE_DEVICE_TABLE(hid, samsung_devices);
78
79static struct hid_driver samsung_driver = {
80 .name = "samsung",
81 .id_table = samsung_devices,
82 .report_fixup = samsung_report_fixup,
83 .probe = samsung_probe,
84};
85
86static int samsung_init(void)
87{
88 return hid_register_driver(&samsung_driver);
89}
90
91static void samsung_exit(void)
92{
93 hid_unregister_driver(&samsung_driver);
94}
95
96module_init(samsung_init);
97module_exit(samsung_exit);
98MODULE_LICENSE("GPL");
99
100HID_COMPAT_LOAD_DRIVER(samsung);
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
new file mode 100644
index 000000000000..3af8095a7de1
--- /dev/null
+++ b/drivers/hid/hid-sony.c
@@ -0,0 +1,110 @@
1/*
2 * HID driver for some sony "special" devices
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/hid.h>
21#include <linux/module.h>
22#include <linux/usb.h>
23
24#include "hid-ids.h"
25
26/*
27 * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller
28 * to "operational". Without this, the ps3 controller will not report any
29 * events.
30 */
31static int sony_set_operational(struct hid_device *hdev)
32{
33 struct usb_interface *intf = to_usb_interface(hdev->dev.parent);
34 struct usb_device *dev = interface_to_usbdev(intf);
35 __u16 ifnum = intf->cur_altsetting->desc.bInterfaceNumber;
36 int ret;
37 char *buf = kmalloc(18, GFP_KERNEL);
38
39 if (!buf)
40 return -ENOMEM;
41
42 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
43 HID_REQ_GET_REPORT,
44 USB_DIR_IN | USB_TYPE_CLASS |
45 USB_RECIP_INTERFACE,
46 (3 << 8) | 0xf2, ifnum, buf, 17,
47 USB_CTRL_GET_TIMEOUT);
48 if (ret < 0)
49 dev_err(&hdev->dev, "can't set operational mode\n");
50
51 kfree(buf);
52
53 return ret;
54}
55
56static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
57{
58 int ret;
59
60 ret = hid_parse(hdev);
61 if (ret) {
62 dev_err(&hdev->dev, "parse failed\n");
63 goto err_free;
64 }
65
66 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT |
67 HID_CONNECT_HIDDEV_FORCE);
68 if (ret) {
69 dev_err(&hdev->dev, "hw start failed\n");
70 goto err_free;
71 }
72
73 ret = sony_set_operational(hdev);
74 if (ret)
75 goto err_stop;
76
77 return 0;
78err_stop:
79 hid_hw_stop(hdev);
80err_free:
81 return ret;
82}
83
84static const struct hid_device_id sony_devices[] = {
85 { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) },
86 { }
87};
88MODULE_DEVICE_TABLE(hid, sony_devices);
89
90static struct hid_driver sony_driver = {
91 .name = "sony",
92 .id_table = sony_devices,
93 .probe = sony_probe,
94};
95
96static int sony_init(void)
97{
98 return hid_register_driver(&sony_driver);
99}
100
101static void sony_exit(void)
102{
103 hid_unregister_driver(&sony_driver);
104}
105
106module_init(sony_init);
107module_exit(sony_exit);
108MODULE_LICENSE("GPL");
109
110HID_COMPAT_LOAD_DRIVER(sony);
diff --git a/drivers/hid/hid-sunplus.c b/drivers/hid/hid-sunplus.c
new file mode 100644
index 000000000000..5ba68f7dbb78
--- /dev/null
+++ b/drivers/hid/hid-sunplus.c
@@ -0,0 +1,82 @@
1/*
2 * HID driver for some sunplus "special" devices
3 *
4 * Copyright (c) 1999 Andreas Gal
5 * Copyright (c) 2000-2005 Vojtech Pavlik <vojtech@suse.cz>
6 * Copyright (c) 2005 Michael Haboustak <mike-@cinci.rr.com> for Concept2, Inc
7 * Copyright (c) 2006-2007 Jiri Kosina
8 * Copyright (c) 2007 Paul Walmsley
9 * Copyright (c) 2008 Jiri Slaby
10 */
11
12/*
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the Free
15 * Software Foundation; either version 2 of the License, or (at your option)
16 * any later version.
17 */
18
19#include <linux/device.h>
20#include <linux/hid.h>
21#include <linux/module.h>
22
23#include "hid-ids.h"
24
25static void sp_report_fixup(struct hid_device *hdev, __u8 *rdesc,
26 unsigned int rsize)
27{
28 if (rsize >= 107 && rdesc[104] == 0x26 && rdesc[105] == 0x80 &&
29 rdesc[106] == 0x03) {
30 dev_info(&hdev->dev, "fixing up Sunplus Wireless Desktop "
31 "report descriptor\n");
32 rdesc[105] = rdesc[110] = 0x03;
33 rdesc[106] = rdesc[111] = 0x21;
34 }
35}
36
37#define sp_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \
38 EV_KEY, (c))
39static int sp_input_mapping(struct hid_device *hdev, struct hid_input *hi,
40 struct hid_field *field, struct hid_usage *usage,
41 unsigned long **bit, int *max)
42{
43 if ((usage->hid & HID_USAGE_PAGE) != HID_UP_CONSUMER)
44 return 0;
45
46 switch (usage->hid & HID_USAGE) {
47 case 0x2003: sp_map_key_clear(KEY_ZOOMIN); break;
48 case 0x2103: sp_map_key_clear(KEY_ZOOMOUT); break;
49 default:
50 return 0;
51 }
52 return 1;
53}
54
55static const struct hid_device_id sp_devices[] = {
56 { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) },
57 { }
58};
59MODULE_DEVICE_TABLE(hid, sp_devices);
60
61static struct hid_driver sp_driver = {
62 .name = "sunplus",
63 .id_table = sp_devices,
64 .report_fixup = sp_report_fixup,
65 .input_mapping = sp_input_mapping,
66};
67
68static int sp_init(void)
69{
70 return hid_register_driver(&sp_driver);
71}
72
73static void sp_exit(void)
74{
75 hid_unregister_driver(&sp_driver);
76}
77
78module_init(sp_init);
79module_exit(sp_exit);
80MODULE_LICENSE("GPL");
81
82HID_COMPAT_LOAD_DRIVER(sunplus);
diff --git a/drivers/hid/usbhid/hid-tmff.c b/drivers/hid/hid-tmff.c
index 144578b1a00c..1b7cba0f7e1f 100644
--- a/drivers/hid/usbhid/hid-tmff.c
+++ b/drivers/hid/hid-tmff.c
@@ -27,23 +27,17 @@
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 */ 28 */
29 29
30#include <linux/hid.h>
30#include <linux/input.h> 31#include <linux/input.h>
31
32#undef DEBUG
33#include <linux/usb.h> 32#include <linux/usb.h>
34 33
35#include <linux/hid.h> 34#include "hid-ids.h"
36#include "usbhid.h" 35
36#include "usbhid/usbhid.h"
37 37
38/* Usages for thrustmaster devices I know about */ 38/* Usages for thrustmaster devices I know about */
39#define THRUSTMASTER_USAGE_FF (HID_UP_GENDESK | 0xbb) 39#define THRUSTMASTER_USAGE_FF (HID_UP_GENDESK | 0xbb)
40 40
41struct dev_type {
42 u16 idVendor;
43 u16 idProduct;
44 const signed short *ff;
45};
46
47static const signed short ff_rumble[] = { 41static const signed short ff_rumble[] = {
48 FF_RUMBLE, 42 FF_RUMBLE,
49 -1 43 -1
@@ -54,21 +48,13 @@ static const signed short ff_joystick[] = {
54 -1 48 -1
55}; 49};
56 50
57static const struct dev_type devices[] = {
58 { 0x44f, 0xb300, ff_rumble },
59 { 0x44f, 0xb304, ff_rumble },
60 { 0x44f, 0xb651, ff_rumble }, /* FGT Rumble Force Wheel */
61 { 0x44f, 0xb654, ff_joystick }, /* FGT Force Feedback Wheel */
62};
63
64struct tmff_device { 51struct tmff_device {
65 struct hid_report *report; 52 struct hid_report *report;
66 struct hid_field *ff_field; 53 struct hid_field *ff_field;
67}; 54};
68 55
69/* Changes values from 0 to 0xffff into values from minimum to maximum */ 56/* Changes values from 0 to 0xffff into values from minimum to maximum */
70static inline int hid_tmff_scale_u16(unsigned int in, 57static inline int tmff_scale_u16(unsigned int in, int minimum, int maximum)
71 int minimum, int maximum)
72{ 58{
73 int ret; 59 int ret;
74 60
@@ -81,8 +67,7 @@ static inline int hid_tmff_scale_u16(unsigned int in,
81} 67}
82 68
83/* Changes values from -0x80 to 0x7f into values from minimum to maximum */ 69/* Changes values from -0x80 to 0x7f into values from minimum to maximum */
84static inline int hid_tmff_scale_s8(int in, 70static inline int tmff_scale_s8(int in, int minimum, int maximum)
85 int minimum, int maximum)
86{ 71{
87 int ret; 72 int ret;
88 73
@@ -94,7 +79,8 @@ static inline int hid_tmff_scale_s8(int in,
94 return ret; 79 return ret;
95} 80}
96 81
97static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *effect) 82static int tmff_play(struct input_dev *dev, void *data,
83 struct ff_effect *effect)
98{ 84{
99 struct hid_device *hid = input_get_drvdata(dev); 85 struct hid_device *hid = input_get_drvdata(dev);
100 struct tmff_device *tmff = data; 86 struct tmff_device *tmff = data;
@@ -104,10 +90,10 @@ static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *ef
104 90
105 switch (effect->type) { 91 switch (effect->type) {
106 case FF_CONSTANT: 92 case FF_CONSTANT:
107 x = hid_tmff_scale_s8(effect->u.ramp.start_level, 93 x = tmff_scale_s8(effect->u.ramp.start_level,
108 ff_field->logical_minimum, 94 ff_field->logical_minimum,
109 ff_field->logical_maximum); 95 ff_field->logical_maximum);
110 y = hid_tmff_scale_s8(effect->u.ramp.end_level, 96 y = tmff_scale_s8(effect->u.ramp.end_level,
111 ff_field->logical_minimum, 97 ff_field->logical_minimum,
112 ff_field->logical_maximum); 98 ff_field->logical_maximum);
113 99
@@ -118,10 +104,10 @@ static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *ef
118 break; 104 break;
119 105
120 case FF_RUMBLE: 106 case FF_RUMBLE:
121 left = hid_tmff_scale_u16(effect->u.rumble.weak_magnitude, 107 left = tmff_scale_u16(effect->u.rumble.weak_magnitude,
122 ff_field->logical_minimum, 108 ff_field->logical_minimum,
123 ff_field->logical_maximum); 109 ff_field->logical_maximum);
124 right = hid_tmff_scale_u16(effect->u.rumble.strong_magnitude, 110 right = tmff_scale_u16(effect->u.rumble.strong_magnitude,
125 ff_field->logical_minimum, 111 ff_field->logical_minimum,
126 ff_field->logical_maximum); 112 ff_field->logical_maximum);
127 113
@@ -134,14 +120,14 @@ static int hid_tmff_play(struct input_dev *dev, void *data, struct ff_effect *ef
134 return 0; 120 return 0;
135} 121}
136 122
137int hid_tmff_init(struct hid_device *hid) 123static int tmff_init(struct hid_device *hid, const signed short *ff_bits)
138{ 124{
139 struct tmff_device *tmff; 125 struct tmff_device *tmff;
140 struct hid_report *report; 126 struct hid_report *report;
141 struct list_head *report_list; 127 struct list_head *report_list;
142 struct hid_input *hidinput = list_entry(hid->inputs.next, struct hid_input, list); 128 struct hid_input *hidinput = list_entry(hid->inputs.next,
129 struct hid_input, list);
143 struct input_dev *input_dev = hidinput->input; 130 struct input_dev *input_dev = hidinput->input;
144 const signed short *ff_bits = ff_joystick;
145 int error; 131 int error;
146 int i; 132 int i;
147 133
@@ -163,63 +149,121 @@ int hid_tmff_init(struct hid_device *hid)
163 switch (field->usage[0].hid) { 149 switch (field->usage[0].hid) {
164 case THRUSTMASTER_USAGE_FF: 150 case THRUSTMASTER_USAGE_FF:
165 if (field->report_count < 2) { 151 if (field->report_count < 2) {
166 warn("ignoring FF field with report_count < 2"); 152 dev_warn(&hid->dev, "ignoring FF field "
153 "with report_count < 2\n");
167 continue; 154 continue;
168 } 155 }
169 156
170 if (field->logical_maximum == field->logical_minimum) { 157 if (field->logical_maximum ==
171 warn("ignoring FF field with logical_maximum == logical_minimum"); 158 field->logical_minimum) {
159 dev_warn(&hid->dev, "ignoring FF field "
160 "with logical_maximum "
161 "== logical_minimum\n");
172 continue; 162 continue;
173 } 163 }
174 164
175 if (tmff->report && tmff->report != report) { 165 if (tmff->report && tmff->report != report) {
176 warn("ignoring FF field in other report"); 166 dev_warn(&hid->dev, "ignoring FF field "
167 "in other report\n");
177 continue; 168 continue;
178 } 169 }
179 170
180 if (tmff->ff_field && tmff->ff_field != field) { 171 if (tmff->ff_field && tmff->ff_field != field) {
181 warn("ignoring duplicate FF field"); 172 dev_warn(&hid->dev, "ignoring "
173 "duplicate FF field\n");
182 continue; 174 continue;
183 } 175 }
184 176
185 tmff->report = report; 177 tmff->report = report;
186 tmff->ff_field = field; 178 tmff->ff_field = field;
187 179
188 for (i = 0; i < ARRAY_SIZE(devices); i++) {
189 if (input_dev->id.vendor == devices[i].idVendor &&
190 input_dev->id.product == devices[i].idProduct) {
191 ff_bits = devices[i].ff;
192 break;
193 }
194 }
195
196 for (i = 0; ff_bits[i] >= 0; i++) 180 for (i = 0; ff_bits[i] >= 0; i++)
197 set_bit(ff_bits[i], input_dev->ffbit); 181 set_bit(ff_bits[i], input_dev->ffbit);
198 182
199 break; 183 break;
200 184
201 default: 185 default:
202 warn("ignoring unknown output usage %08x", field->usage[0].hid); 186 dev_warn(&hid->dev, "ignoring unknown output "
187 "usage %08x\n",
188 field->usage[0].hid);
203 continue; 189 continue;
204 } 190 }
205 } 191 }
206 } 192 }
207 193
208 if (!tmff->report) { 194 if (!tmff->report) {
209 err("cant find FF field in output reports\n"); 195 dev_err(&hid->dev, "can't find FF field in output reports\n");
210 error = -ENODEV; 196 error = -ENODEV;
211 goto fail; 197 goto fail;
212 } 198 }
213 199
214 error = input_ff_create_memless(input_dev, tmff, hid_tmff_play); 200 error = input_ff_create_memless(input_dev, tmff, tmff_play);
215 if (error) 201 if (error)
216 goto fail; 202 goto fail;
217 203
218 info("Force feedback for ThrustMaster devices by Zinx Verituse <zinx@epicsol.org>"); 204 dev_info(&hid->dev, "force feedback for ThrustMaster devices by Zinx "
205 "Verituse <zinx@epicsol.org>");
219 return 0; 206 return 0;
220 207
221 fail: 208fail:
222 kfree(tmff); 209 kfree(tmff);
223 return error; 210 return error;
224} 211}
225 212
213static int tm_probe(struct hid_device *hdev, const struct hid_device_id *id)
214{
215 int ret;
216
217 ret = hid_parse(hdev);
218 if (ret) {
219 dev_err(&hdev->dev, "parse failed\n");
220 goto err;
221 }
222
223 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
224 if (ret) {
225 dev_err(&hdev->dev, "hw start failed\n");
226 goto err;
227 }
228
229 tmff_init(hdev, (void *)id->driver_data);
230
231 return 0;
232err:
233 return ret;
234}
235
236static const struct hid_device_id tm_devices[] = {
237 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300),
238 .driver_data = (unsigned long)ff_rumble },
239 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb304),
240 .driver_data = (unsigned long)ff_rumble },
241 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb651), /* FGT Rumble Force Wheel */
242 .driver_data = (unsigned long)ff_rumble },
243 { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb654), /* FGT Force Feedback Wheel */
244 .driver_data = (unsigned long)ff_joystick },
245 { }
246};
247MODULE_DEVICE_TABLE(hid, tm_devices);
248
249static struct hid_driver tm_driver = {
250 .name = "thrustmaster",
251 .id_table = tm_devices,
252 .probe = tm_probe,
253};
254
255static int tm_init(void)
256{
257 return hid_register_driver(&tm_driver);
258}
259
260static void tm_exit(void)
261{
262 hid_unregister_driver(&tm_driver);
263}
264
265module_init(tm_init);
266module_exit(tm_exit);
267MODULE_LICENSE("GPL");
268
269HID_COMPAT_LOAD_DRIVER(thrustmaster);
diff --git a/drivers/hid/usbhid/hid-zpff.c b/drivers/hid/hid-zpff.c
index 5a688274f6a3..ea82f3718b21 100644
--- a/drivers/hid/usbhid/hid-zpff.c
+++ b/drivers/hid/hid-zpff.c
@@ -21,16 +21,19 @@
21 */ 21 */
22 22
23 23
24#include <linux/hid.h>
24#include <linux/input.h> 25#include <linux/input.h>
25#include <linux/usb.h> 26#include <linux/usb.h>
26#include <linux/hid.h> 27
27#include "usbhid.h" 28#include "hid-ids.h"
29
30#include "usbhid/usbhid.h"
28 31
29struct zpff_device { 32struct zpff_device {
30 struct hid_report *report; 33 struct hid_report *report;
31}; 34};
32 35
33static int hid_zpff_play(struct input_dev *dev, void *data, 36static int zpff_play(struct input_dev *dev, void *data,
34 struct ff_effect *effect) 37 struct ff_effect *effect)
35{ 38{
36 struct hid_device *hid = input_get_drvdata(dev); 39 struct hid_device *hid = input_get_drvdata(dev);
@@ -58,7 +61,7 @@ static int hid_zpff_play(struct input_dev *dev, void *data,
58 return 0; 61 return 0;
59} 62}
60 63
61int hid_zpff_init(struct hid_device *hid) 64static int zpff_init(struct hid_device *hid)
62{ 65{
63 struct zpff_device *zpff; 66 struct zpff_device *zpff;
64 struct hid_report *report; 67 struct hid_report *report;
@@ -70,14 +73,14 @@ int hid_zpff_init(struct hid_device *hid)
70 int error; 73 int error;
71 74
72 if (list_empty(report_list)) { 75 if (list_empty(report_list)) {
73 printk(KERN_ERR "hid-zpff: no output report found\n"); 76 dev_err(&hid->dev, "no output report found\n");
74 return -ENODEV; 77 return -ENODEV;
75 } 78 }
76 79
77 report = list_entry(report_list->next, struct hid_report, list); 80 report = list_entry(report_list->next, struct hid_report, list);
78 81
79 if (report->maxfield < 4) { 82 if (report->maxfield < 4) {
80 printk(KERN_ERR "hid-zpff: not enough fields in report\n"); 83 dev_err(&hid->dev, "not enough fields in report\n");
81 return -ENODEV; 84 return -ENODEV;
82 } 85 }
83 86
@@ -87,7 +90,7 @@ int hid_zpff_init(struct hid_device *hid)
87 90
88 set_bit(FF_RUMBLE, dev->ffbit); 91 set_bit(FF_RUMBLE, dev->ffbit);
89 92
90 error = input_ff_create_memless(dev, zpff, hid_zpff_play); 93 error = input_ff_create_memless(dev, zpff, zpff_play);
91 if (error) { 94 if (error) {
92 kfree(zpff); 95 kfree(zpff);
93 return error; 96 return error;
@@ -100,8 +103,60 @@ int hid_zpff_init(struct hid_device *hid)
100 zpff->report->field[3]->value[0] = 0x00; 103 zpff->report->field[3]->value[0] = 0x00;
101 usbhid_submit_report(hid, zpff->report, USB_DIR_OUT); 104 usbhid_submit_report(hid, zpff->report, USB_DIR_OUT);
102 105
103 printk(KERN_INFO "Force feedback for Zeroplus based devices by " 106 dev_info(&hid->dev, "force feedback for Zeroplus based devices by "
104 "Anssi Hannula <anssi.hannula@gmail.com>\n"); 107 "Anssi Hannula <anssi.hannula@gmail.com>\n");
105 108
106 return 0; 109 return 0;
107} 110}
111
112static int zp_probe(struct hid_device *hdev, const struct hid_device_id *id)
113{
114 int ret;
115
116 ret = hid_parse(hdev);
117 if (ret) {
118 dev_err(&hdev->dev, "parse failed\n");
119 goto err;
120 }
121
122 ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF);
123 if (ret) {
124 dev_err(&hdev->dev, "hw start failed\n");
125 goto err;
126 }
127
128 zpff_init(hdev);
129
130 return 0;
131err:
132 return ret;
133}
134
135static const struct hid_device_id zp_devices[] = {
136 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) },
137 { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) },
138 { }
139};
140MODULE_DEVICE_TABLE(hid, zp_devices);
141
142static struct hid_driver zp_driver = {
143 .name = "zeroplus",
144 .id_table = zp_devices,
145 .probe = zp_probe,
146};
147
148static int zp_init(void)
149{
150 return hid_register_driver(&zp_driver);
151}
152
153static void zp_exit(void)
154{
155 hid_unregister_driver(&zp_driver);
156}
157
158module_init(zp_init);
159module_exit(zp_exit);
160MODULE_LICENSE("GPL");
161
162HID_COMPAT_LOAD_DRIVER(zeroplus);
diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c
index c40f0403edaf..af3edb98df43 100644
--- a/drivers/hid/hidraw.c
+++ b/drivers/hid/hidraw.c
@@ -113,7 +113,7 @@ static ssize_t hidraw_write(struct file *file, const char __user *buffer, size_t
113 if (!dev->hid_output_raw_report) 113 if (!dev->hid_output_raw_report)
114 return -ENODEV; 114 return -ENODEV;
115 115
116 if (count > HID_MIN_BUFFER_SIZE) { 116 if (count > HID_MAX_BUFFER_SIZE) {
117 printk(KERN_WARNING "hidraw: pid %d passed too large report\n", 117 printk(KERN_WARNING "hidraw: pid %d passed too large report\n",
118 task_pid_nr(current)); 118 task_pid_nr(current));
119 return -EINVAL; 119 return -EINVAL;
@@ -181,7 +181,7 @@ static int hidraw_open(struct inode *inode, struct file *file)
181 181
182 dev = hidraw_table[minor]; 182 dev = hidraw_table[minor];
183 if (!dev->open++) 183 if (!dev->open++)
184 dev->hid->hid_open(dev->hid); 184 dev->hid->ll_driver->open(dev->hid);
185 185
186out_unlock: 186out_unlock:
187 spin_unlock(&minors_lock); 187 spin_unlock(&minors_lock);
@@ -207,7 +207,7 @@ static int hidraw_release(struct inode * inode, struct file * file)
207 dev = hidraw_table[minor]; 207 dev = hidraw_table[minor];
208 if (!dev->open--) { 208 if (!dev->open--) {
209 if (list->hidraw->exist) 209 if (list->hidraw->exist)
210 dev->hid->hid_close(dev->hid); 210 dev->hid->ll_driver->close(dev->hid);
211 else 211 else
212 kfree(list->hidraw); 212 kfree(list->hidraw);
213 } 213 }
@@ -326,9 +326,8 @@ int hidraw_connect(struct hid_device *hid)
326 goto out; 326 goto out;
327 } 327 }
328 328
329 dev->dev = device_create_drvdata(hidraw_class, NULL, 329 dev->dev = device_create(hidraw_class, NULL, MKDEV(hidraw_major, minor),
330 MKDEV(hidraw_major, minor), NULL, 330 NULL, "%s%d", "hidraw", minor);
331 "%s%d", "hidraw", minor);
332 331
333 if (IS_ERR(dev->dev)) { 332 if (IS_ERR(dev->dev)) {
334 spin_lock(&minors_lock); 333 spin_lock(&minors_lock);
@@ -367,7 +366,7 @@ void hidraw_disconnect(struct hid_device *hid)
367 device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor)); 366 device_destroy(hidraw_class, MKDEV(hidraw_major, hidraw->minor));
368 367
369 if (hidraw->open) { 368 if (hidraw->open) {
370 hid->hid_close(hid); 369 hid->ll_driver->close(hid);
371 wake_up_interruptible(&hidraw->wait); 370 wake_up_interruptible(&hidraw->wait);
372 } else { 371 } else {
373 kfree(hidraw); 372 kfree(hidraw);
diff --git a/drivers/hid/usbhid/Kconfig b/drivers/hid/usbhid/Kconfig
index 18f09104765c..5d9aa95fc3ef 100644
--- a/drivers/hid/usbhid/Kconfig
+++ b/drivers/hid/usbhid/Kconfig
@@ -24,88 +24,13 @@ config USB_HID
24comment "Input core support is needed for USB HID input layer or HIDBP support" 24comment "Input core support is needed for USB HID input layer or HIDBP support"
25 depends on USB_HID && INPUT=n 25 depends on USB_HID && INPUT=n
26 26
27config USB_HIDINPUT_POWERBOOK
28 bool "Enable support for Apple laptop/aluminum USB special keys"
29 default n
30 depends on USB_HID
31 help
32 Say Y here if you want support for the special keys (Fn, Numlock) on
33 Apple iBooks, PowerBooks, MacBooks, MacBook Pros and aluminum USB
34 keyboards.
35
36 If unsure, say N.
37
38config HID_FF
39 bool "Force feedback support (EXPERIMENTAL)"
40 depends on USB_HID && EXPERIMENTAL
41 help
42 Say Y here is you want force feedback support for a few HID devices.
43 See below for a list of supported devices.
44
45 See <file:Documentation/input/ff.txt> for a description of the force
46 feedback API.
47
48 If unsure, say N.
49
50config HID_PID 27config HID_PID
51 bool "PID device support" 28 bool "PID device support"
52 depends on HID_FF
53 help 29 help
54 Say Y here if you have a PID-compliant device and wish to enable force 30 Say Y here if you have a PID-compliant device and wish to enable force
55 feedback for it. Microsoft Sidewinder Force Feedback 2 is one of such 31 feedback for it. Microsoft Sidewinder Force Feedback 2 is one of such
56 devices. 32 devices.
57 33
58config LOGITECH_FF
59 bool "Logitech devices support"
60 depends on HID_FF
61 select INPUT_FF_MEMLESS if USB_HID
62 help
63 Say Y here if you have one of these devices:
64 - Logitech WingMan Cordless RumblePad
65 - Logitech WingMan Cordless RumblePad 2
66 - Logitech WingMan Force 3D
67 - Logitech Formula Force EX
68 - Logitech MOMO Force wheel
69
70 and if you want to enable force feedback for them.
71 Note: if you say N here, this device will still be supported, but without
72 force feedback.
73
74config LOGIRUMBLEPAD2_FF
75 bool "Logitech Rumblepad 2 support"
76 depends on HID_FF
77 select INPUT_FF_MEMLESS if USB_HID
78 help
79 Say Y here if you want to enable force feedback support for Logitech
80 Rumblepad 2 devices.
81
82config PANTHERLORD_FF
83 bool "PantherLord/GreenAsia based device support"
84 depends on HID_FF
85 select INPUT_FF_MEMLESS if USB_HID
86 help
87 Say Y here if you have a PantherLord/GreenAsia based game controller
88 or adapter and want to enable force feedback support for it.
89
90config THRUSTMASTER_FF
91 bool "ThrustMaster devices support"
92 depends on HID_FF
93 select INPUT_FF_MEMLESS if USB_HID
94 help
95 Say Y here if you have a THRUSTMASTER FireStore Dual Power 2 or
96 a THRUSTMASTER Ferrari GT Rumble Force or Force Feedback Wheel,
97 and want to enable force feedback support for it.
98 Note: if you say N here, this device will still be supported, but without
99 force feedback.
100
101config ZEROPLUS_FF
102 bool "Zeroplus based game controller support"
103 depends on HID_FF
104 select INPUT_FF_MEMLESS if USB_HID
105 help
106 Say Y here if you have a Zeroplus based game controller and want to
107 enable force feedback for it.
108
109config USB_HIDDEV 34config USB_HIDDEV
110 bool "/dev/hiddev raw HID device support" 35 bool "/dev/hiddev raw HID device support"
111 depends on USB_HID 36 depends on USB_HID
diff --git a/drivers/hid/usbhid/Makefile b/drivers/hid/usbhid/Makefile
index 00a7b7090192..1329ecb37a1c 100644
--- a/drivers/hid/usbhid/Makefile
+++ b/drivers/hid/usbhid/Makefile
@@ -13,24 +13,6 @@ endif
13ifeq ($(CONFIG_HID_PID),y) 13ifeq ($(CONFIG_HID_PID),y)
14 usbhid-objs += hid-pidff.o 14 usbhid-objs += hid-pidff.o
15endif 15endif
16ifeq ($(CONFIG_LOGITECH_FF),y)
17 usbhid-objs += hid-lgff.o
18endif
19ifeq ($(CONFIG_LOGIRUMBLEPAD2_FF),y)
20 usbhid-objs += hid-lg2ff.o
21endif
22ifeq ($(CONFIG_PANTHERLORD_FF),y)
23 usbhid-objs += hid-plff.o
24endif
25ifeq ($(CONFIG_THRUSTMASTER_FF),y)
26 usbhid-objs += hid-tmff.o
27endif
28ifeq ($(CONFIG_ZEROPLUS_FF),y)
29 usbhid-objs += hid-zpff.o
30endif
31ifeq ($(CONFIG_HID_FF),y)
32 usbhid-objs += hid-ff.o
33endif
34 16
35obj-$(CONFIG_USB_HID) += usbhid.o 17obj-$(CONFIG_USB_HID) += usbhid.o
36obj-$(CONFIG_USB_KBD) += usbkbd.o 18obj-$(CONFIG_USB_KBD) += usbkbd.o
diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c
index 27fe4d8912cb..1d3b8a394d46 100644
--- a/drivers/hid/usbhid/hid-core.c
+++ b/drivers/hid/usbhid/hid-core.c
@@ -44,8 +44,6 @@
44#define DRIVER_DESC "USB HID core driver" 44#define DRIVER_DESC "USB HID core driver"
45#define DRIVER_LICENSE "GPL" 45#define DRIVER_LICENSE "GPL"
46 46
47static char *hid_types[] = {"Device", "Pointer", "Mouse", "Device", "Joystick",
48 "Gamepad", "Keyboard", "Keypad", "Multi-Axis Controller"};
49/* 47/*
50 * Module parameters. 48 * Module parameters.
51 */ 49 */
@@ -61,12 +59,6 @@ MODULE_PARM_DESC(quirks, "Add/modify USB HID quirks by specifying "
61 " quirks=vendorID:productID:quirks" 59 " quirks=vendorID:productID:quirks"
62 " where vendorID, productID, and quirks are all in" 60 " where vendorID, productID, and quirks are all in"
63 " 0x-prefixed hex"); 61 " 0x-prefixed hex");
64static char *rdesc_quirks_param[MAX_USBHID_BOOT_QUIRKS] = { [ 0 ... (MAX_USBHID_BOOT_QUIRKS - 1) ] = NULL };
65module_param_array_named(rdesc_quirks, rdesc_quirks_param, charp, NULL, 0444);
66MODULE_PARM_DESC(rdesc_quirks, "Add/modify report descriptor quirks by specifying "
67 " rdesc_quirks=vendorID:productID:rdesc_quirks"
68 " where vendorID, productID, and rdesc_quirks are all in"
69 " 0x-prefixed hex");
70/* 62/*
71 * Input submission and I/O error handler. 63 * Input submission and I/O error handler.
72 */ 64 */
@@ -197,31 +189,32 @@ static void hid_irq_in(struct urb *urb)
197 int status; 189 int status;
198 190
199 switch (urb->status) { 191 switch (urb->status) {
200 case 0: /* success */ 192 case 0: /* success */
201 usbhid->retry_delay = 0; 193 usbhid->retry_delay = 0;
202 hid_input_report(urb->context, HID_INPUT_REPORT, 194 hid_input_report(urb->context, HID_INPUT_REPORT,
203 urb->transfer_buffer, 195 urb->transfer_buffer,
204 urb->actual_length, 1); 196 urb->actual_length, 1);
205 break; 197 break;
206 case -EPIPE: /* stall */ 198 case -EPIPE: /* stall */
207 clear_bit(HID_IN_RUNNING, &usbhid->iofl); 199 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
208 set_bit(HID_CLEAR_HALT, &usbhid->iofl); 200 set_bit(HID_CLEAR_HALT, &usbhid->iofl);
209 schedule_work(&usbhid->reset_work); 201 schedule_work(&usbhid->reset_work);
210 return; 202 return;
211 case -ECONNRESET: /* unlink */ 203 case -ECONNRESET: /* unlink */
212 case -ENOENT: 204 case -ENOENT:
213 case -ESHUTDOWN: /* unplug */ 205 case -ESHUTDOWN: /* unplug */
214 clear_bit(HID_IN_RUNNING, &usbhid->iofl); 206 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
215 return; 207 return;
216 case -EILSEQ: /* protocol error or unplug */ 208 case -EILSEQ: /* protocol error or unplug */
217 case -EPROTO: /* protocol error or unplug */ 209 case -EPROTO: /* protocol error or unplug */
218 case -ETIME: /* protocol error or unplug */ 210 case -ETIME: /* protocol error or unplug */
219 case -ETIMEDOUT: /* Should never happen, but... */ 211 case -ETIMEDOUT: /* Should never happen, but... */
220 clear_bit(HID_IN_RUNNING, &usbhid->iofl); 212 clear_bit(HID_IN_RUNNING, &usbhid->iofl);
221 hid_io_error(hid); 213 hid_io_error(hid);
222 return; 214 return;
223 default: /* error */ 215 default: /* error */
224 warn("input irq status %d received", urb->status); 216 dev_warn(&urb->dev->dev, "input irq status %d "
217 "received\n", urb->status);
225 } 218 }
226 219
227 status = usb_submit_urb(urb, GFP_ATOMIC); 220 status = usb_submit_urb(urb, GFP_ATOMIC);
@@ -240,13 +233,16 @@ static void hid_irq_in(struct urb *urb)
240static int hid_submit_out(struct hid_device *hid) 233static int hid_submit_out(struct hid_device *hid)
241{ 234{
242 struct hid_report *report; 235 struct hid_report *report;
236 char *raw_report;
243 struct usbhid_device *usbhid = hid->driver_data; 237 struct usbhid_device *usbhid = hid->driver_data;
244 238
245 report = usbhid->out[usbhid->outtail]; 239 report = usbhid->out[usbhid->outtail].report;
240 raw_report = usbhid->out[usbhid->outtail].raw_report;
246 241
247 hid_output_report(report, usbhid->outbuf);
248 usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0); 242 usbhid->urbout->transfer_buffer_length = ((report->size - 1) >> 3) + 1 + (report->id > 0);
249 usbhid->urbout->dev = hid_to_usb_dev(hid); 243 usbhid->urbout->dev = hid_to_usb_dev(hid);
244 memcpy(usbhid->outbuf, raw_report, usbhid->urbout->transfer_buffer_length);
245 kfree(raw_report);
250 246
251 dbg_hid("submitting out urb\n"); 247 dbg_hid("submitting out urb\n");
252 248
@@ -262,17 +258,20 @@ static int hid_submit_ctrl(struct hid_device *hid)
262{ 258{
263 struct hid_report *report; 259 struct hid_report *report;
264 unsigned char dir; 260 unsigned char dir;
261 char *raw_report;
265 int len; 262 int len;
266 struct usbhid_device *usbhid = hid->driver_data; 263 struct usbhid_device *usbhid = hid->driver_data;
267 264
268 report = usbhid->ctrl[usbhid->ctrltail].report; 265 report = usbhid->ctrl[usbhid->ctrltail].report;
266 raw_report = usbhid->ctrl[usbhid->ctrltail].raw_report;
269 dir = usbhid->ctrl[usbhid->ctrltail].dir; 267 dir = usbhid->ctrl[usbhid->ctrltail].dir;
270 268
271 len = ((report->size - 1) >> 3) + 1 + (report->id > 0); 269 len = ((report->size - 1) >> 3) + 1 + (report->id > 0);
272 if (dir == USB_DIR_OUT) { 270 if (dir == USB_DIR_OUT) {
273 hid_output_report(report, usbhid->ctrlbuf);
274 usbhid->urbctrl->pipe = usb_sndctrlpipe(hid_to_usb_dev(hid), 0); 271 usbhid->urbctrl->pipe = usb_sndctrlpipe(hid_to_usb_dev(hid), 0);
275 usbhid->urbctrl->transfer_buffer_length = len; 272 usbhid->urbctrl->transfer_buffer_length = len;
273 memcpy(usbhid->ctrlbuf, raw_report, len);
274 kfree(raw_report);
276 } else { 275 } else {
277 int maxpacket, padlen; 276 int maxpacket, padlen;
278 277
@@ -319,17 +318,18 @@ static void hid_irq_out(struct urb *urb)
319 int unplug = 0; 318 int unplug = 0;
320 319
321 switch (urb->status) { 320 switch (urb->status) {
322 case 0: /* success */ 321 case 0: /* success */
323 break; 322 break;
324 case -ESHUTDOWN: /* unplug */ 323 case -ESHUTDOWN: /* unplug */
325 unplug = 1; 324 unplug = 1;
326 case -EILSEQ: /* protocol error or unplug */ 325 case -EILSEQ: /* protocol error or unplug */
327 case -EPROTO: /* protocol error or unplug */ 326 case -EPROTO: /* protocol error or unplug */
328 case -ECONNRESET: /* unlink */ 327 case -ECONNRESET: /* unlink */
329 case -ENOENT: 328 case -ENOENT:
330 break; 329 break;
331 default: /* error */ 330 default: /* error */
332 warn("output irq status %d received", urb->status); 331 dev_warn(&urb->dev->dev, "output irq status %d "
332 "received\n", urb->status);
333 } 333 }
334 334
335 spin_lock_irqsave(&usbhid->outlock, flags); 335 spin_lock_irqsave(&usbhid->outlock, flags);
@@ -367,21 +367,23 @@ static void hid_ctrl(struct urb *urb)
367 spin_lock_irqsave(&usbhid->ctrllock, flags); 367 spin_lock_irqsave(&usbhid->ctrllock, flags);
368 368
369 switch (urb->status) { 369 switch (urb->status) {
370 case 0: /* success */ 370 case 0: /* success */
371 if (usbhid->ctrl[usbhid->ctrltail].dir == USB_DIR_IN) 371 if (usbhid->ctrl[usbhid->ctrltail].dir == USB_DIR_IN)
372 hid_input_report(urb->context, usbhid->ctrl[usbhid->ctrltail].report->type, 372 hid_input_report(urb->context,
373 urb->transfer_buffer, urb->actual_length, 0); 373 usbhid->ctrl[usbhid->ctrltail].report->type,
374 break; 374 urb->transfer_buffer, urb->actual_length, 0);
375 case -ESHUTDOWN: /* unplug */ 375 break;
376 unplug = 1; 376 case -ESHUTDOWN: /* unplug */
377 case -EILSEQ: /* protocol error or unplug */ 377 unplug = 1;
378 case -EPROTO: /* protocol error or unplug */ 378 case -EILSEQ: /* protocol error or unplug */
379 case -ECONNRESET: /* unlink */ 379 case -EPROTO: /* protocol error or unplug */
380 case -ENOENT: 380 case -ECONNRESET: /* unlink */
381 case -EPIPE: /* report not available */ 381 case -ENOENT:
382 break; 382 case -EPIPE: /* report not available */
383 default: /* error */ 383 break;
384 warn("ctrl urb status %d received", urb->status); 384 default: /* error */
385 dev_warn(&urb->dev->dev, "ctrl urb status %d "
386 "received\n", urb->status);
385 } 387 }
386 388
387 if (unplug) 389 if (unplug)
@@ -408,6 +410,7 @@ void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, uns
408 int head; 410 int head;
409 unsigned long flags; 411 unsigned long flags;
410 struct usbhid_device *usbhid = hid->driver_data; 412 struct usbhid_device *usbhid = hid->driver_data;
413 int len = ((report->size - 1) >> 3) + 1 + (report->id > 0);
411 414
412 if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN) 415 if ((hid->quirks & HID_QUIRK_NOGET) && dir == USB_DIR_IN)
413 return; 416 return;
@@ -418,11 +421,18 @@ void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, uns
418 421
419 if ((head = (usbhid->outhead + 1) & (HID_OUTPUT_FIFO_SIZE - 1)) == usbhid->outtail) { 422 if ((head = (usbhid->outhead + 1) & (HID_OUTPUT_FIFO_SIZE - 1)) == usbhid->outtail) {
420 spin_unlock_irqrestore(&usbhid->outlock, flags); 423 spin_unlock_irqrestore(&usbhid->outlock, flags);
421 warn("output queue full"); 424 dev_warn(&hid->dev, "output queue full\n");
422 return; 425 return;
423 } 426 }
424 427
425 usbhid->out[usbhid->outhead] = report; 428 usbhid->out[usbhid->outhead].raw_report = kmalloc(len, GFP_ATOMIC);
429 if (!usbhid->out[usbhid->outhead].raw_report) {
430 spin_unlock_irqrestore(&usbhid->outlock, flags);
431 warn("output queueing failed");
432 return;
433 }
434 hid_output_report(report, usbhid->out[usbhid->outhead].raw_report);
435 usbhid->out[usbhid->outhead].report = report;
426 usbhid->outhead = head; 436 usbhid->outhead = head;
427 437
428 if (!test_and_set_bit(HID_OUT_RUNNING, &usbhid->iofl)) 438 if (!test_and_set_bit(HID_OUT_RUNNING, &usbhid->iofl))
@@ -437,10 +447,19 @@ void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, uns
437 447
438 if ((head = (usbhid->ctrlhead + 1) & (HID_CONTROL_FIFO_SIZE - 1)) == usbhid->ctrltail) { 448 if ((head = (usbhid->ctrlhead + 1) & (HID_CONTROL_FIFO_SIZE - 1)) == usbhid->ctrltail) {
439 spin_unlock_irqrestore(&usbhid->ctrllock, flags); 449 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
440 warn("control queue full"); 450 dev_warn(&hid->dev, "control queue full\n");
441 return; 451 return;
442 } 452 }
443 453
454 if (dir == USB_DIR_OUT) {
455 usbhid->ctrl[usbhid->ctrlhead].raw_report = kmalloc(len, GFP_ATOMIC);
456 if (!usbhid->ctrl[usbhid->ctrlhead].raw_report) {
457 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
458 warn("control queueing failed");
459 return;
460 }
461 hid_output_report(report, usbhid->ctrl[usbhid->ctrlhead].raw_report);
462 }
444 usbhid->ctrl[usbhid->ctrlhead].report = report; 463 usbhid->ctrl[usbhid->ctrlhead].report = report;
445 usbhid->ctrl[usbhid->ctrlhead].dir = dir; 464 usbhid->ctrl[usbhid->ctrlhead].dir = dir;
446 usbhid->ctrlhead = head; 465 usbhid->ctrlhead = head;
@@ -451,6 +470,7 @@ void usbhid_submit_report(struct hid_device *hid, struct hid_report *report, uns
451 470
452 spin_unlock_irqrestore(&usbhid->ctrllock, flags); 471 spin_unlock_irqrestore(&usbhid->ctrllock, flags);
453} 472}
473EXPORT_SYMBOL_GPL(usbhid_submit_report);
454 474
455static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value) 475static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
456{ 476{
@@ -465,7 +485,7 @@ static int usb_hidinput_input_event(struct input_dev *dev, unsigned int type, un
465 return -1; 485 return -1;
466 486
467 if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) { 487 if ((offset = hidinput_find_field(hid, type, code, &field)) == -1) {
468 warn("event field not found"); 488 dev_warn(&dev->dev, "event field not found\n");
469 return -1; 489 return -1;
470 } 490 }
471 491
@@ -568,7 +588,7 @@ void usbhid_init_reports(struct hid_device *hid)
568 } 588 }
569 589
570 if (err) 590 if (err)
571 warn("timeout initializing reports"); 591 dev_warn(&hid->dev, "timeout initializing reports\n");
572} 592}
573 593
574/* 594/*
@@ -598,7 +618,7 @@ static int hid_find_field_early(struct hid_device *hid, unsigned int page,
598 return -1; 618 return -1;
599} 619}
600 620
601static void usbhid_set_leds(struct hid_device *hid) 621void usbhid_set_leds(struct hid_device *hid)
602{ 622{
603 struct hid_field *field; 623 struct hid_field *field;
604 int offset; 624 int offset;
@@ -608,6 +628,7 @@ static void usbhid_set_leds(struct hid_device *hid)
608 usbhid_submit_report(hid, field->report, USB_DIR_OUT); 628 usbhid_submit_report(hid, field->report, USB_DIR_OUT);
609 } 629 }
610} 630}
631EXPORT_SYMBOL_GPL(usbhid_set_leds);
611 632
612/* 633/*
613 * Traverse the supplied list of reports and find the longest 634 * Traverse the supplied list of reports and find the longest
@@ -675,43 +696,16 @@ static void hid_free_buffers(struct usb_device *dev, struct hid_device *hid)
675 usb_buffer_free(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma); 696 usb_buffer_free(dev, usbhid->bufsize, usbhid->ctrlbuf, usbhid->ctrlbuf_dma);
676} 697}
677 698
678/* 699static int usbhid_parse(struct hid_device *hid)
679 * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller
680 * to "operational". Without this, the ps3 controller will not report any
681 * events.
682 */
683static void hid_fixup_sony_ps3_controller(struct usb_device *dev, int ifnum)
684{
685 int result;
686 char *buf = kmalloc(18, GFP_KERNEL);
687
688 if (!buf)
689 return;
690
691 result = usb_control_msg(dev, usb_rcvctrlpipe(dev, 0),
692 HID_REQ_GET_REPORT,
693 USB_DIR_IN | USB_TYPE_CLASS |
694 USB_RECIP_INTERFACE,
695 (3 << 8) | 0xf2, ifnum, buf, 17,
696 USB_CTRL_GET_TIMEOUT);
697
698 if (result < 0)
699 err_hid("%s failed: %d\n", __func__, result);
700
701 kfree(buf);
702}
703
704static struct hid_device *usb_hid_configure(struct usb_interface *intf)
705{ 700{
701 struct usb_interface *intf = to_usb_interface(hid->dev.parent);
706 struct usb_host_interface *interface = intf->cur_altsetting; 702 struct usb_host_interface *interface = intf->cur_altsetting;
707 struct usb_device *dev = interface_to_usbdev (intf); 703 struct usb_device *dev = interface_to_usbdev (intf);
708 struct hid_descriptor *hdesc; 704 struct hid_descriptor *hdesc;
709 struct hid_device *hid;
710 u32 quirks = 0; 705 u32 quirks = 0;
711 unsigned int insize = 0, rsize = 0; 706 unsigned int rsize = 0;
712 char *rdesc; 707 char *rdesc;
713 int n, len; 708 int ret, n;
714 struct usbhid_device *usbhid;
715 709
716 quirks = usbhid_lookup_quirk(le16_to_cpu(dev->descriptor.idVendor), 710 quirks = usbhid_lookup_quirk(le16_to_cpu(dev->descriptor.idVendor),
717 le16_to_cpu(dev->descriptor.idProduct)); 711 le16_to_cpu(dev->descriptor.idProduct));
@@ -724,63 +718,75 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
724 quirks |= HID_QUIRK_NOGET; 718 quirks |= HID_QUIRK_NOGET;
725 } 719 }
726 720
727 if (quirks & HID_QUIRK_IGNORE)
728 return NULL;
729
730 if ((quirks & HID_QUIRK_IGNORE_MOUSE) &&
731 (interface->desc.bInterfaceProtocol == USB_INTERFACE_PROTOCOL_MOUSE))
732 return NULL;
733
734
735 if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) && 721 if (usb_get_extra_descriptor(interface, HID_DT_HID, &hdesc) &&
736 (!interface->desc.bNumEndpoints || 722 (!interface->desc.bNumEndpoints ||
737 usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) { 723 usb_get_extra_descriptor(&interface->endpoint[0], HID_DT_HID, &hdesc))) {
738 dbg_hid("class descriptor not present\n"); 724 dbg_hid("class descriptor not present\n");
739 return NULL; 725 return -ENODEV;
740 } 726 }
741 727
728 hid->version = le16_to_cpu(hdesc->bcdHID);
729 hid->country = hdesc->bCountryCode;
730
742 for (n = 0; n < hdesc->bNumDescriptors; n++) 731 for (n = 0; n < hdesc->bNumDescriptors; n++)
743 if (hdesc->desc[n].bDescriptorType == HID_DT_REPORT) 732 if (hdesc->desc[n].bDescriptorType == HID_DT_REPORT)
744 rsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength); 733 rsize = le16_to_cpu(hdesc->desc[n].wDescriptorLength);
745 734
746 if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) { 735 if (!rsize || rsize > HID_MAX_DESCRIPTOR_SIZE) {
747 dbg_hid("weird size of report descriptor (%u)\n", rsize); 736 dbg_hid("weird size of report descriptor (%u)\n", rsize);
748 return NULL; 737 return -EINVAL;
749 } 738 }
750 739
751 if (!(rdesc = kmalloc(rsize, GFP_KERNEL))) { 740 if (!(rdesc = kmalloc(rsize, GFP_KERNEL))) {
752 dbg_hid("couldn't allocate rdesc memory\n"); 741 dbg_hid("couldn't allocate rdesc memory\n");
753 return NULL; 742 return -ENOMEM;
754 } 743 }
755 744
756 hid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0); 745 hid_set_idle(dev, interface->desc.bInterfaceNumber, 0, 0);
757 746
758 if ((n = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber, HID_DT_REPORT, rdesc, rsize)) < 0) { 747 ret = hid_get_class_descriptor(dev, interface->desc.bInterfaceNumber,
748 HID_DT_REPORT, rdesc, rsize);
749 if (ret < 0) {
759 dbg_hid("reading report descriptor failed\n"); 750 dbg_hid("reading report descriptor failed\n");
760 kfree(rdesc); 751 kfree(rdesc);
761 return NULL; 752 goto err;
762 } 753 }
763 754
764 usbhid_fixup_report_descriptor(le16_to_cpu(dev->descriptor.idVendor),
765 le16_to_cpu(dev->descriptor.idProduct), rdesc,
766 rsize, rdesc_quirks_param);
767
768 dbg_hid("report descriptor (size %u, read %d) = ", rsize, n); 755 dbg_hid("report descriptor (size %u, read %d) = ", rsize, n);
769 for (n = 0; n < rsize; n++) 756 for (n = 0; n < rsize; n++)
770 dbg_hid_line(" %02x", (unsigned char) rdesc[n]); 757 dbg_hid_line(" %02x", (unsigned char) rdesc[n]);
771 dbg_hid_line("\n"); 758 dbg_hid_line("\n");
772 759
773 if (!(hid = hid_parse_report(rdesc, n))) { 760 ret = hid_parse_report(hid, rdesc, rsize);
761 kfree(rdesc);
762 if (ret) {
774 dbg_hid("parsing report descriptor failed\n"); 763 dbg_hid("parsing report descriptor failed\n");
775 kfree(rdesc); 764 goto err;
776 return NULL;
777 } 765 }
778 766
779 kfree(rdesc);
780 hid->quirks = quirks; 767 hid->quirks = quirks;
781 768
782 if (!(usbhid = kzalloc(sizeof(struct usbhid_device), GFP_KERNEL))) 769 return 0;
783 goto fail_no_usbhid; 770err:
771 return ret;
772}
773
774static int usbhid_start(struct hid_device *hid)
775{
776 struct usb_interface *intf = to_usb_interface(hid->dev.parent);
777 struct usb_host_interface *interface = intf->cur_altsetting;
778 struct usb_device *dev = interface_to_usbdev(intf);
779 struct usbhid_device *usbhid;
780 unsigned int n, insize = 0;
781 int ret;
782
783 WARN_ON(hid->driver_data);
784
785 usbhid = kzalloc(sizeof(struct usbhid_device), GFP_KERNEL);
786 if (usbhid == NULL) {
787 ret = -ENOMEM;
788 goto err;
789 }
784 790
785 hid->driver_data = usbhid; 791 hid->driver_data = usbhid;
786 usbhid->hid = hid; 792 usbhid->hid = hid;
@@ -799,28 +805,11 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
799 insize = HID_MAX_BUFFER_SIZE; 805 insize = HID_MAX_BUFFER_SIZE;
800 806
801 if (hid_alloc_buffers(dev, hid)) { 807 if (hid_alloc_buffers(dev, hid)) {
802 hid_free_buffers(dev, hid); 808 ret = -ENOMEM;
803 goto fail; 809 goto fail;
804 } 810 }
805 811
806 hid->name[0] = 0;
807
808 if (dev->manufacturer)
809 strlcpy(hid->name, dev->manufacturer, sizeof(hid->name));
810
811 if (dev->product) {
812 if (dev->manufacturer)
813 strlcat(hid->name, " ", sizeof(hid->name));
814 strlcat(hid->name, dev->product, sizeof(hid->name));
815 }
816
817 if (!strlen(hid->name))
818 snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x",
819 le16_to_cpu(dev->descriptor.idVendor),
820 le16_to_cpu(dev->descriptor.idProduct));
821
822 for (n = 0; n < interface->desc.bNumEndpoints; n++) { 812 for (n = 0; n < interface->desc.bNumEndpoints; n++) {
823
824 struct usb_endpoint_descriptor *endpoint; 813 struct usb_endpoint_descriptor *endpoint;
825 int pipe; 814 int pipe;
826 int interval; 815 int interval;
@@ -832,7 +821,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
832 interval = endpoint->bInterval; 821 interval = endpoint->bInterval;
833 822
834 /* Some vendors give fullspeed interval on highspeed devides */ 823 /* Some vendors give fullspeed interval on highspeed devides */
835 if (quirks & HID_QUIRK_FULLSPEED_INTERVAL && 824 if (hid->quirks & HID_QUIRK_FULLSPEED_INTERVAL &&
836 dev->speed == USB_SPEED_HIGH) { 825 dev->speed == USB_SPEED_HIGH) {
837 interval = fls(endpoint->bInterval*8); 826 interval = fls(endpoint->bInterval*8);
838 printk(KERN_INFO "%s: Fixing fullspeed to highspeed interval: %d -> %d\n", 827 printk(KERN_INFO "%s: Fixing fullspeed to highspeed interval: %d -> %d\n",
@@ -843,6 +832,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
843 if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0) 832 if (hid->collection->usage == HID_GD_MOUSE && hid_mousepoll_interval > 0)
844 interval = hid_mousepoll_interval; 833 interval = hid_mousepoll_interval;
845 834
835 ret = -ENOMEM;
846 if (usb_endpoint_dir_in(endpoint)) { 836 if (usb_endpoint_dir_in(endpoint)) {
847 if (usbhid->urbin) 837 if (usbhid->urbin)
848 continue; 838 continue;
@@ -868,6 +858,7 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
868 858
869 if (!usbhid->urbin) { 859 if (!usbhid->urbin) {
870 err_hid("couldn't find an input interrupt endpoint"); 860 err_hid("couldn't find an input interrupt endpoint");
861 ret = -ENODEV;
871 goto fail; 862 goto fail;
872 } 863 }
873 864
@@ -879,44 +870,25 @@ static struct hid_device *usb_hid_configure(struct usb_interface *intf)
879 spin_lock_init(&usbhid->outlock); 870 spin_lock_init(&usbhid->outlock);
880 spin_lock_init(&usbhid->ctrllock); 871 spin_lock_init(&usbhid->ctrllock);
881 872
882 hid->version = le16_to_cpu(hdesc->bcdHID);
883 hid->country = hdesc->bCountryCode;
884 hid->dev = &intf->dev;
885 usbhid->intf = intf; 873 usbhid->intf = intf;
886 usbhid->ifnum = interface->desc.bInterfaceNumber; 874 usbhid->ifnum = interface->desc.bInterfaceNumber;
887 875
888 hid->bus = BUS_USB;
889 hid->vendor = le16_to_cpu(dev->descriptor.idVendor);
890 hid->product = le16_to_cpu(dev->descriptor.idProduct);
891
892 usb_make_path(dev, hid->phys, sizeof(hid->phys));
893 strlcat(hid->phys, "/input", sizeof(hid->phys));
894 len = strlen(hid->phys);
895 if (len < sizeof(hid->phys) - 1)
896 snprintf(hid->phys + len, sizeof(hid->phys) - len,
897 "%d", intf->altsetting[0].desc.bInterfaceNumber);
898
899 if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0)
900 hid->uniq[0] = 0;
901
902 usbhid->urbctrl = usb_alloc_urb(0, GFP_KERNEL); 876 usbhid->urbctrl = usb_alloc_urb(0, GFP_KERNEL);
903 if (!usbhid->urbctrl) 877 if (!usbhid->urbctrl) {
878 ret = -ENOMEM;
904 goto fail; 879 goto fail;
880 }
905 881
906 usb_fill_control_urb(usbhid->urbctrl, dev, 0, (void *) usbhid->cr, 882 usb_fill_control_urb(usbhid->urbctrl, dev, 0, (void *) usbhid->cr,
907 usbhid->ctrlbuf, 1, hid_ctrl, hid); 883 usbhid->ctrlbuf, 1, hid_ctrl, hid);
908 usbhid->urbctrl->setup_dma = usbhid->cr_dma; 884 usbhid->urbctrl->setup_dma = usbhid->cr_dma;
909 usbhid->urbctrl->transfer_dma = usbhid->ctrlbuf_dma; 885 usbhid->urbctrl->transfer_dma = usbhid->ctrlbuf_dma;
910 usbhid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP); 886 usbhid->urbctrl->transfer_flags |= (URB_NO_TRANSFER_DMA_MAP | URB_NO_SETUP_DMA_MAP);
911 hid->hidinput_input_event = usb_hidinput_input_event; 887
912 hid->hid_open = usbhid_open; 888 usbhid_init_reports(hid);
913 hid->hid_close = usbhid_close; 889 hid_dump_device(hid);
914#ifdef CONFIG_USB_HIDDEV 890
915 hid->hiddev_hid_event = hiddev_hid_event; 891 return 0;
916 hid->hiddev_report_event = hiddev_report_event;
917#endif
918 hid->hid_output_raw_report = usbhid_output_raw_report;
919 return hid;
920 892
921fail: 893fail:
922 usb_free_urb(usbhid->urbin); 894 usb_free_urb(usbhid->urbin);
@@ -924,24 +896,18 @@ fail:
924 usb_free_urb(usbhid->urbctrl); 896 usb_free_urb(usbhid->urbctrl);
925 hid_free_buffers(dev, hid); 897 hid_free_buffers(dev, hid);
926 kfree(usbhid); 898 kfree(usbhid);
927fail_no_usbhid: 899err:
928 hid_free_device(hid); 900 return ret;
929
930 return NULL;
931} 901}
932 902
933static void hid_disconnect(struct usb_interface *intf) 903static void usbhid_stop(struct hid_device *hid)
934{ 904{
935 struct hid_device *hid = usb_get_intfdata (intf); 905 struct usbhid_device *usbhid = hid->driver_data;
936 struct usbhid_device *usbhid;
937 906
938 if (!hid) 907 if (WARN_ON(!usbhid))
939 return; 908 return;
940 909
941 usbhid = hid->driver_data;
942
943 spin_lock_irq(&usbhid->inlock); /* Sync with error handler */ 910 spin_lock_irq(&usbhid->inlock); /* Sync with error handler */
944 usb_set_intfdata(intf, NULL);
945 set_bit(HID_DISCONNECTED, &usbhid->iofl); 911 set_bit(HID_DISCONNECTED, &usbhid->iofl);
946 spin_unlock_irq(&usbhid->inlock); 912 spin_unlock_irq(&usbhid->inlock);
947 usb_kill_urb(usbhid->urbin); 913 usb_kill_urb(usbhid->urbin);
@@ -958,86 +924,100 @@ static void hid_disconnect(struct usb_interface *intf)
958 if (hid->claimed & HID_CLAIMED_HIDRAW) 924 if (hid->claimed & HID_CLAIMED_HIDRAW)
959 hidraw_disconnect(hid); 925 hidraw_disconnect(hid);
960 926
927 hid->claimed = 0;
928
961 usb_free_urb(usbhid->urbin); 929 usb_free_urb(usbhid->urbin);
962 usb_free_urb(usbhid->urbctrl); 930 usb_free_urb(usbhid->urbctrl);
963 usb_free_urb(usbhid->urbout); 931 usb_free_urb(usbhid->urbout);
964 932
965 hid_free_buffers(hid_to_usb_dev(hid), hid); 933 hid_free_buffers(hid_to_usb_dev(hid), hid);
966 kfree(usbhid); 934 kfree(usbhid);
967 hid_free_device(hid); 935 hid->driver_data = NULL;
968} 936}
969 937
938static struct hid_ll_driver usb_hid_driver = {
939 .parse = usbhid_parse,
940 .start = usbhid_start,
941 .stop = usbhid_stop,
942 .open = usbhid_open,
943 .close = usbhid_close,
944 .hidinput_input_event = usb_hidinput_input_event,
945};
946
970static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id) 947static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id)
971{ 948{
949 struct usb_device *dev = interface_to_usbdev(intf);
972 struct hid_device *hid; 950 struct hid_device *hid;
973 char path[64]; 951 size_t len;
974 int i; 952 int ret;
975 char *c;
976 953
977 dbg_hid("HID probe called for ifnum %d\n", 954 dbg_hid("HID probe called for ifnum %d\n",
978 intf->altsetting->desc.bInterfaceNumber); 955 intf->altsetting->desc.bInterfaceNumber);
979 956
980 if (!(hid = usb_hid_configure(intf))) 957 hid = hid_allocate_device();
981 return -ENODEV; 958 if (IS_ERR(hid))
982 959 return PTR_ERR(hid);
983 usbhid_init_reports(hid);
984 hid_dump_device(hid);
985 if (hid->quirks & HID_QUIRK_RESET_LEDS)
986 usbhid_set_leds(hid);
987
988 if (!hidinput_connect(hid))
989 hid->claimed |= HID_CLAIMED_INPUT;
990 if (!hiddev_connect(hid))
991 hid->claimed |= HID_CLAIMED_HIDDEV;
992 if (!hidraw_connect(hid))
993 hid->claimed |= HID_CLAIMED_HIDRAW;
994 960
995 usb_set_intfdata(intf, hid); 961 usb_set_intfdata(intf, hid);
962 hid->ll_driver = &usb_hid_driver;
963 hid->hid_output_raw_report = usbhid_output_raw_report;
964 hid->ff_init = hid_pidff_init;
965#ifdef CONFIG_USB_HIDDEV
966 hid->hiddev_connect = hiddev_connect;
967 hid->hiddev_hid_event = hiddev_hid_event;
968 hid->hiddev_report_event = hiddev_report_event;
969#endif
970 hid->dev.parent = &intf->dev;
971 hid->bus = BUS_USB;
972 hid->vendor = le16_to_cpu(dev->descriptor.idVendor);
973 hid->product = le16_to_cpu(dev->descriptor.idProduct);
974 hid->name[0] = 0;
996 975
997 if (!hid->claimed) { 976 if (dev->manufacturer)
998 printk ("HID device claimed by neither input, hiddev nor hidraw\n"); 977 strlcpy(hid->name, dev->manufacturer, sizeof(hid->name));
999 hid_disconnect(intf); 978
1000 return -ENODEV; 979 if (dev->product) {
980 if (dev->manufacturer)
981 strlcat(hid->name, " ", sizeof(hid->name));
982 strlcat(hid->name, dev->product, sizeof(hid->name));
1001 } 983 }
1002 984
1003 if ((hid->claimed & HID_CLAIMED_INPUT)) 985 if (!strlen(hid->name))
1004 hid_ff_init(hid); 986 snprintf(hid->name, sizeof(hid->name), "HID %04x:%04x",
987 le16_to_cpu(dev->descriptor.idVendor),
988 le16_to_cpu(dev->descriptor.idProduct));
1005 989
1006 if (hid->quirks & HID_QUIRK_SONY_PS3_CONTROLLER) 990 usb_make_path(dev, hid->phys, sizeof(hid->phys));
1007 hid_fixup_sony_ps3_controller(interface_to_usbdev(intf), 991 strlcat(hid->phys, "/input", sizeof(hid->phys));
1008 intf->cur_altsetting->desc.bInterfaceNumber); 992 len = strlen(hid->phys);
993 if (len < sizeof(hid->phys) - 1)
994 snprintf(hid->phys + len, sizeof(hid->phys) - len,
995 "%d", intf->altsetting[0].desc.bInterfaceNumber);
1009 996
1010 printk(KERN_INFO); 997 if (usb_string(dev, dev->descriptor.iSerialNumber, hid->uniq, 64) <= 0)
998 hid->uniq[0] = 0;
1011 999
1012 if (hid->claimed & HID_CLAIMED_INPUT) 1000 ret = hid_add_device(hid);
1013 printk("input"); 1001 if (ret) {
1014 if ((hid->claimed & HID_CLAIMED_INPUT) && ((hid->claimed & HID_CLAIMED_HIDDEV) || 1002 if (ret != -ENODEV)
1015 hid->claimed & HID_CLAIMED_HIDRAW)) 1003 dev_err(&intf->dev, "can't add hid device: %d\n", ret);
1016 printk(","); 1004 goto err;
1017 if (hid->claimed & HID_CLAIMED_HIDDEV)
1018 printk("hiddev%d", hid->minor);
1019 if ((hid->claimed & HID_CLAIMED_INPUT) && (hid->claimed & HID_CLAIMED_HIDDEV) &&
1020 (hid->claimed & HID_CLAIMED_HIDRAW))
1021 printk(",");
1022 if (hid->claimed & HID_CLAIMED_HIDRAW)
1023 printk("hidraw%d", ((struct hidraw*)hid->hidraw)->minor);
1024
1025 c = "Device";
1026 for (i = 0; i < hid->maxcollection; i++) {
1027 if (hid->collection[i].type == HID_COLLECTION_APPLICATION &&
1028 (hid->collection[i].usage & HID_USAGE_PAGE) == HID_UP_GENDESK &&
1029 (hid->collection[i].usage & 0xffff) < ARRAY_SIZE(hid_types)) {
1030 c = hid_types[hid->collection[i].usage & 0xffff];
1031 break;
1032 }
1033 } 1005 }
1034 1006
1035 usb_make_path(interface_to_usbdev(intf), path, 63); 1007 return 0;
1008err:
1009 hid_destroy_device(hid);
1010 return ret;
1011}
1036 1012
1037 printk(": USB HID v%x.%02x %s [%s] on %s\n", 1013static void hid_disconnect(struct usb_interface *intf)
1038 hid->version >> 8, hid->version & 0xff, c, hid->name, path); 1014{
1015 struct hid_device *hid = usb_get_intfdata(intf);
1039 1016
1040 return 0; 1017 if (WARN_ON(!hid))
1018 return;
1019
1020 hid_destroy_device(hid);
1041} 1021}
1042 1022
1043static int hid_suspend(struct usb_interface *intf, pm_message_t message) 1023static int hid_suspend(struct usb_interface *intf, pm_message_t message)
@@ -1107,9 +1087,22 @@ static struct usb_driver hid_driver = {
1107 .supports_autosuspend = 1, 1087 .supports_autosuspend = 1,
1108}; 1088};
1109 1089
1090static const struct hid_device_id hid_usb_table[] = {
1091 { HID_USB_DEVICE(HID_ANY_ID, HID_ANY_ID) },
1092 { }
1093};
1094
1095static struct hid_driver hid_usb_driver = {
1096 .name = "generic-usb",
1097 .id_table = hid_usb_table,
1098};
1099
1110static int __init hid_init(void) 1100static int __init hid_init(void)
1111{ 1101{
1112 int retval; 1102 int retval;
1103 retval = hid_register_driver(&hid_usb_driver);
1104 if (retval)
1105 goto hid_register_fail;
1113 retval = usbhid_quirks_init(quirks_param); 1106 retval = usbhid_quirks_init(quirks_param);
1114 if (retval) 1107 if (retval)
1115 goto usbhid_quirks_init_fail; 1108 goto usbhid_quirks_init_fail;
@@ -1119,7 +1112,8 @@ static int __init hid_init(void)
1119 retval = usb_register(&hid_driver); 1112 retval = usb_register(&hid_driver);
1120 if (retval) 1113 if (retval)
1121 goto usb_register_fail; 1114 goto usb_register_fail;
1122 info(DRIVER_VERSION ":" DRIVER_DESC); 1115 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
1116 DRIVER_DESC "\n");
1123 1117
1124 return 0; 1118 return 0;
1125usb_register_fail: 1119usb_register_fail:
@@ -1127,6 +1121,8 @@ usb_register_fail:
1127hiddev_init_fail: 1121hiddev_init_fail:
1128 usbhid_quirks_exit(); 1122 usbhid_quirks_exit();
1129usbhid_quirks_init_fail: 1123usbhid_quirks_init_fail:
1124 hid_unregister_driver(&hid_usb_driver);
1125hid_register_fail:
1130 return retval; 1126 return retval;
1131} 1127}
1132 1128
@@ -1135,6 +1131,7 @@ static void __exit hid_exit(void)
1135 usb_deregister(&hid_driver); 1131 usb_deregister(&hid_driver);
1136 hiddev_exit(); 1132 hiddev_exit();
1137 usbhid_quirks_exit(); 1133 usbhid_quirks_exit();
1134 hid_unregister_driver(&hid_usb_driver);
1138} 1135}
1139 1136
1140module_init(hid_init); 1137module_init(hid_init);
diff --git a/drivers/hid/usbhid/hid-ff.c b/drivers/hid/usbhid/hid-ff.c
deleted file mode 100644
index 1d0dac52f166..000000000000
--- a/drivers/hid/usbhid/hid-ff.c
+++ /dev/null
@@ -1,95 +0,0 @@
1/*
2 * Force feedback support for hid devices.
3 * Not all hid devices use the same protocol. For example, some use PID,
4 * other use their own proprietary procotol.
5 *
6 * Copyright (c) 2002-2004 Johann Deneux
7 */
8
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 * Should you need to contact me, the author, you can do so by
25 * e-mail - mail your message to <johann.deneux@it.uu.se>
26 */
27
28#include <linux/input.h>
29
30#undef DEBUG
31#include <linux/usb.h>
32
33#include <linux/hid.h>
34#include "usbhid.h"
35
36/*
37 * This table contains pointers to initializers. To add support for new
38 * devices, you need to add the USB vendor and product ids here.
39 */
40struct hid_ff_initializer {
41 u16 idVendor;
42 u16 idProduct;
43 int (*init)(struct hid_device*);
44};
45
46/*
47 * We try pidff when no other driver is found because PID is the
48 * standards compliant way of implementing force feedback in HID.
49 * pidff_init() will quickly abort if the device doesn't appear to
50 * be a PID device
51 */
52static struct hid_ff_initializer inits[] = {
53#ifdef CONFIG_LOGITECH_FF
54 { 0x46d, 0xc211, hid_lgff_init }, /* Logitech Cordless rumble pad */
55 { 0x46d, 0xc219, hid_lgff_init }, /* Logitech Cordless rumble pad 2 */
56 { 0x46d, 0xc283, hid_lgff_init }, /* Logitech Wingman Force 3d */
57 { 0x46d, 0xc286, hid_lgff_init }, /* Logitech Force 3D Pro Joystick */
58 { 0x46d, 0xc294, hid_lgff_init }, /* Logitech Formula Force EX */
59 { 0x46d, 0xc295, hid_lgff_init }, /* Logitech MOMO force wheel */
60 { 0x46d, 0xca03, hid_lgff_init }, /* Logitech MOMO force wheel */
61#endif
62#ifdef CONFIG_LOGIRUMBLEPAD2_FF
63 { 0x46d, 0xc218, hid_lg2ff_init }, /* Logitech Rumblepad 2 */
64#endif
65#ifdef CONFIG_PANTHERLORD_FF
66 { 0x810, 0x0001, hid_plff_init }, /* "Twin USB Joystick" */
67 { 0xe8f, 0x0003, hid_plff_init }, /* "GreenAsia Inc. USB Joystick " */
68#endif
69#ifdef CONFIG_THRUSTMASTER_FF
70 { 0x44f, 0xb300, hid_tmff_init },
71 { 0x44f, 0xb304, hid_tmff_init },
72 { 0x44f, 0xb651, hid_tmff_init }, /* FGT Rumble Force Wheel */
73 { 0x44f, 0xb654, hid_tmff_init }, /* FGT Force Feedback Wheel */
74#endif
75#ifdef CONFIG_ZEROPLUS_FF
76 { 0xc12, 0x0005, hid_zpff_init },
77 { 0xc12, 0x0030, hid_zpff_init },
78#endif
79 { 0, 0, hid_pidff_init} /* Matches anything */
80};
81
82int hid_ff_init(struct hid_device* hid)
83{
84 struct hid_ff_initializer *init;
85 int vendor = le16_to_cpu(hid_to_usb_dev(hid)->descriptor.idVendor);
86 int product = le16_to_cpu(hid_to_usb_dev(hid)->descriptor.idProduct);
87
88 for (init = inits; init->idVendor; init++)
89 if (init->idVendor == vendor && init->idProduct == product)
90 break;
91
92 return init->init(hid);
93}
94EXPORT_SYMBOL_GPL(hid_ff_init);
95
diff --git a/drivers/hid/usbhid/hid-pidff.c b/drivers/hid/usbhid/hid-pidff.c
index 011326178c06..484e3eec2f88 100644
--- a/drivers/hid/usbhid/hid-pidff.c
+++ b/drivers/hid/usbhid/hid-pidff.c
@@ -397,7 +397,6 @@ static void pidff_set_condition_report(struct pidff_device *pidff,
397 effect->u.condition[i].left_saturation); 397 effect->u.condition[i].left_saturation);
398 pidff_set(&pidff->set_condition[PID_DEAD_BAND], 398 pidff_set(&pidff->set_condition[PID_DEAD_BAND],
399 effect->u.condition[i].deadband); 399 effect->u.condition[i].deadband);
400 usbhid_wait_io(pidff->hid);
401 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_CONDITION], 400 usbhid_submit_report(pidff->hid, pidff->reports[PID_SET_CONDITION],
402 USB_DIR_OUT); 401 USB_DIR_OUT);
403 } 402 }
@@ -512,7 +511,6 @@ static void pidff_playback_pid(struct pidff_device *pidff, int pid_id, int n)
512 pidff->effect_operation[PID_LOOP_COUNT].value[0] = n; 511 pidff->effect_operation[PID_LOOP_COUNT].value[0] = n;
513 } 512 }
514 513
515 usbhid_wait_io(pidff->hid);
516 usbhid_submit_report(pidff->hid, pidff->reports[PID_EFFECT_OPERATION], 514 usbhid_submit_report(pidff->hid, pidff->reports[PID_EFFECT_OPERATION],
517 USB_DIR_OUT); 515 USB_DIR_OUT);
518} 516}
@@ -548,6 +546,9 @@ static int pidff_erase_effect(struct input_dev *dev, int effect_id)
548 int pid_id = pidff->pid_id[effect_id]; 546 int pid_id = pidff->pid_id[effect_id];
549 547
550 debug("starting to erase %d/%d", effect_id, pidff->pid_id[effect_id]); 548 debug("starting to erase %d/%d", effect_id, pidff->pid_id[effect_id]);
549 /* Wait for the queue to clear. We do not want a full fifo to
550 prevent the effect removal. */
551 usbhid_wait_io(pidff->hid);
551 pidff_playback_pid(pidff, pid_id, 0); 552 pidff_playback_pid(pidff, pid_id, 0);
552 pidff_erase_pid(pidff, pid_id); 553 pidff_erase_pid(pidff, pid_id);
553 554
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index b15f88249639..47ebe045f9b5 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -17,412 +17,7 @@
17 17
18#include <linux/hid.h> 18#include <linux/hid.h>
19 19
20#define USB_VENDOR_ID_A4TECH 0x09da 20#include "../hid-ids.h"
21#define USB_DEVICE_ID_A4TECH_WCP32PU 0x0006
22#define USB_DEVICE_ID_A4TECH_X5_005D 0x000a
23
24#define USB_VENDOR_ID_AASHIMA 0x06d6
25#define USB_DEVICE_ID_AASHIMA_GAMEPAD 0x0025
26#define USB_DEVICE_ID_AASHIMA_PREDATOR 0x0026
27
28#define USB_VENDOR_ID_ACECAD 0x0460
29#define USB_DEVICE_ID_ACECAD_FLAIR 0x0004
30#define USB_DEVICE_ID_ACECAD_302 0x0008
31
32#define USB_VENDOR_ID_ADS_TECH 0x06e1
33#define USB_DEVICE_ID_ADS_TECH_RADIO_SI470X 0xa155
34
35#define USB_VENDOR_ID_AFATECH 0x15a4
36#define USB_DEVICE_ID_AFATECH_AF9016 0x9016
37
38#define USB_VENDOR_ID_AIPTEK 0x08ca
39#define USB_DEVICE_ID_AIPTEK_01 0x0001
40#define USB_DEVICE_ID_AIPTEK_10 0x0010
41#define USB_DEVICE_ID_AIPTEK_20 0x0020
42#define USB_DEVICE_ID_AIPTEK_21 0x0021
43#define USB_DEVICE_ID_AIPTEK_22 0x0022
44#define USB_DEVICE_ID_AIPTEK_23 0x0023
45#define USB_DEVICE_ID_AIPTEK_24 0x0024
46
47#define USB_VENDOR_ID_AIRCABLE 0x16CA
48#define USB_DEVICE_ID_AIRCABLE1 0x1502
49
50#define USB_VENDOR_ID_ALCOR 0x058f
51#define USB_DEVICE_ID_ALCOR_USBRS232 0x9720
52
53#define USB_VENDOR_ID_ALPS 0x0433
54#define USB_DEVICE_ID_IBM_GAMEPAD 0x1101
55
56#define USB_VENDOR_ID_APPLE 0x05ac
57#define USB_DEVICE_ID_APPLE_MIGHTYMOUSE 0x0304
58#define USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI 0x020e
59#define USB_DEVICE_ID_APPLE_FOUNTAIN_ISO 0x020f
60#define USB_DEVICE_ID_APPLE_GEYSER_ANSI 0x0214
61#define USB_DEVICE_ID_APPLE_GEYSER_ISO 0x0215
62#define USB_DEVICE_ID_APPLE_GEYSER_JIS 0x0216
63#define USB_DEVICE_ID_APPLE_GEYSER3_ANSI 0x0217
64#define USB_DEVICE_ID_APPLE_GEYSER3_ISO 0x0218
65#define USB_DEVICE_ID_APPLE_GEYSER3_JIS 0x0219
66#define USB_DEVICE_ID_APPLE_GEYSER4_ANSI 0x021a
67#define USB_DEVICE_ID_APPLE_GEYSER4_ISO 0x021b
68#define USB_DEVICE_ID_APPLE_GEYSER4_JIS 0x021c
69#define USB_DEVICE_ID_APPLE_ALU_ANSI 0x0220
70#define USB_DEVICE_ID_APPLE_ALU_ISO 0x0221
71#define USB_DEVICE_ID_APPLE_ALU_JIS 0x0222
72#define USB_DEVICE_ID_APPLE_WELLSPRING_ANSI 0x0223
73#define USB_DEVICE_ID_APPLE_WELLSPRING_ISO 0x0224
74#define USB_DEVICE_ID_APPLE_WELLSPRING_JIS 0x0225
75#define USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI 0x0229
76#define USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO 0x022a
77#define USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS 0x022b
78#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI 0x022c
79#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO 0x022d
80#define USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS 0x022e
81#define USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI 0x0230
82#define USB_DEVICE_ID_APPLE_WELLSPRING2_ISO 0x0231
83#define USB_DEVICE_ID_APPLE_WELLSPRING2_JIS 0x0232
84#define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY 0x030a
85#define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY 0x030b
86#define USB_DEVICE_ID_APPLE_IRCONTROL4 0x8242
87
88#define USB_VENDOR_ID_ASUS 0x0b05
89#define USB_DEVICE_ID_ASUS_LCM 0x1726
90
91#define USB_VENDOR_ID_ATEN 0x0557
92#define USB_DEVICE_ID_ATEN_UC100KM 0x2004
93#define USB_DEVICE_ID_ATEN_CS124U 0x2202
94#define USB_DEVICE_ID_ATEN_2PORTKVM 0x2204
95#define USB_DEVICE_ID_ATEN_4PORTKVM 0x2205
96#define USB_DEVICE_ID_ATEN_4PORTKVMC 0x2208
97
98#define USB_VENDOR_ID_BELKIN 0x050d
99#define USB_DEVICE_ID_FLIP_KVM 0x3201
100
101#define USB_VENDOR_ID_BERKSHIRE 0x0c98
102#define USB_DEVICE_ID_BERKSHIRE_PCWD 0x1140
103
104#define USB_VENDOR_ID_CHERRY 0x046a
105#define USB_DEVICE_ID_CHERRY_CYMOTION 0x0023
106
107#define USB_VENDOR_ID_CHIC 0x05fe
108#define USB_DEVICE_ID_CHIC_GAMEPAD 0x0014
109
110#define USB_VENDOR_ID_CIDC 0x1677
111
112#define USB_VENDOR_ID_CMEDIA 0x0d8c
113#define USB_DEVICE_ID_CM109 0x000e
114
115#define USB_VENDOR_ID_CODEMERCS 0x07c0
116#define USB_DEVICE_ID_CODEMERCS_IOW_FIRST 0x1500
117#define USB_DEVICE_ID_CODEMERCS_IOW_LAST 0x15ff
118
119#define USB_VENDOR_ID_CYGNAL 0x10c4
120#define USB_DEVICE_ID_CYGNAL_RADIO_SI470X 0x818a
121
122#define USB_VENDOR_ID_CYPRESS 0x04b4
123#define USB_DEVICE_ID_CYPRESS_MOUSE 0x0001
124#define USB_DEVICE_ID_CYPRESS_HIDCOM 0x5500
125#define USB_DEVICE_ID_CYPRESS_ULTRAMOUSE 0x7417
126#define USB_DEVICE_ID_CYPRESS_BARCODE_1 0xde61
127#define USB_DEVICE_ID_CYPRESS_BARCODE_2 0xde64
128
129#define USB_VENDOR_ID_DELL 0x413c
130#define USB_DEVICE_ID_DELL_W7658 0x2005
131
132#define USB_VENDOR_ID_DELORME 0x1163
133#define USB_DEVICE_ID_DELORME_EARTHMATE 0x0100
134#define USB_DEVICE_ID_DELORME_EM_LT20 0x0200
135
136#define USB_VENDOR_ID_DMI 0x0c0b
137#define USB_DEVICE_ID_DMI_ENC 0x5fab
138
139#define USB_VENDOR_ID_ELO 0x04E7
140#define USB_DEVICE_ID_ELO_TS2700 0x0020
141
142#define USB_VENDOR_ID_ESSENTIAL_REALITY 0x0d7f
143#define USB_DEVICE_ID_ESSENTIAL_REALITY_P5 0x0100
144
145#define USB_VENDOR_ID_EZKEY 0x0518
146#define USB_DEVICE_ID_BTC_8193 0x0002
147
148#define USB_VENDOR_ID_GAMERON 0x0810
149#define USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR 0x0001
150
151#define USB_VENDOR_ID_GENERAL_TOUCH 0x0dfc
152
153#define USB_VENDOR_ID_GLAB 0x06c2
154#define USB_DEVICE_ID_4_PHIDGETSERVO_30 0x0038
155#define USB_DEVICE_ID_1_PHIDGETSERVO_30 0x0039
156#define USB_DEVICE_ID_0_0_4_IF_KIT 0x0040
157#define USB_DEVICE_ID_0_16_16_IF_KIT 0x0044
158#define USB_DEVICE_ID_8_8_8_IF_KIT 0x0045
159#define USB_DEVICE_ID_0_8_7_IF_KIT 0x0051
160#define USB_DEVICE_ID_0_8_8_IF_KIT 0x0053
161#define USB_DEVICE_ID_PHIDGET_MOTORCONTROL 0x0058
162
163#define USB_VENDOR_ID_GOTOP 0x08f2
164#define USB_DEVICE_ID_SUPER_Q2 0x007f
165#define USB_DEVICE_ID_GOGOPEN 0x00ce
166#define USB_DEVICE_ID_PENPOWER 0x00f4
167
168#define USB_VENDOR_ID_GRETAGMACBETH 0x0971
169#define USB_DEVICE_ID_GRETAGMACBETH_HUEY 0x2005
170
171#define USB_VENDOR_ID_GRIFFIN 0x077d
172#define USB_DEVICE_ID_POWERMATE 0x0410
173#define USB_DEVICE_ID_SOUNDKNOB 0x04AA
174
175#define USB_VENDOR_ID_GTCO 0x078c
176#define USB_DEVICE_ID_GTCO_90 0x0090
177#define USB_DEVICE_ID_GTCO_100 0x0100
178#define USB_DEVICE_ID_GTCO_101 0x0101
179#define USB_DEVICE_ID_GTCO_103 0x0103
180#define USB_DEVICE_ID_GTCO_104 0x0104
181#define USB_DEVICE_ID_GTCO_105 0x0105
182#define USB_DEVICE_ID_GTCO_106 0x0106
183#define USB_DEVICE_ID_GTCO_107 0x0107
184#define USB_DEVICE_ID_GTCO_108 0x0108
185#define USB_DEVICE_ID_GTCO_200 0x0200
186#define USB_DEVICE_ID_GTCO_201 0x0201
187#define USB_DEVICE_ID_GTCO_202 0x0202
188#define USB_DEVICE_ID_GTCO_203 0x0203
189#define USB_DEVICE_ID_GTCO_204 0x0204
190#define USB_DEVICE_ID_GTCO_205 0x0205
191#define USB_DEVICE_ID_GTCO_206 0x0206
192#define USB_DEVICE_ID_GTCO_207 0x0207
193#define USB_DEVICE_ID_GTCO_300 0x0300
194#define USB_DEVICE_ID_GTCO_301 0x0301
195#define USB_DEVICE_ID_GTCO_302 0x0302
196#define USB_DEVICE_ID_GTCO_303 0x0303
197#define USB_DEVICE_ID_GTCO_304 0x0304
198#define USB_DEVICE_ID_GTCO_305 0x0305
199#define USB_DEVICE_ID_GTCO_306 0x0306
200#define USB_DEVICE_ID_GTCO_307 0x0307
201#define USB_DEVICE_ID_GTCO_308 0x0308
202#define USB_DEVICE_ID_GTCO_309 0x0309
203#define USB_DEVICE_ID_GTCO_400 0x0400
204#define USB_DEVICE_ID_GTCO_401 0x0401
205#define USB_DEVICE_ID_GTCO_402 0x0402
206#define USB_DEVICE_ID_GTCO_403 0x0403
207#define USB_DEVICE_ID_GTCO_404 0x0404
208#define USB_DEVICE_ID_GTCO_405 0x0405
209#define USB_DEVICE_ID_GTCO_500 0x0500
210#define USB_DEVICE_ID_GTCO_501 0x0501
211#define USB_DEVICE_ID_GTCO_502 0x0502
212#define USB_DEVICE_ID_GTCO_503 0x0503
213#define USB_DEVICE_ID_GTCO_504 0x0504
214#define USB_DEVICE_ID_GTCO_1000 0x1000
215#define USB_DEVICE_ID_GTCO_1001 0x1001
216#define USB_DEVICE_ID_GTCO_1002 0x1002
217#define USB_DEVICE_ID_GTCO_1003 0x1003
218#define USB_DEVICE_ID_GTCO_1004 0x1004
219#define USB_DEVICE_ID_GTCO_1005 0x1005
220#define USB_DEVICE_ID_GTCO_1006 0x1006
221#define USB_DEVICE_ID_GTCO_1007 0x1007
222#define USB_VENDOR_ID_HAPP 0x078b
223#define USB_DEVICE_ID_UGCI_DRIVING 0x0010
224#define USB_DEVICE_ID_UGCI_FLYING 0x0020
225#define USB_DEVICE_ID_UGCI_FIGHTING 0x0030
226
227#define USB_VENDOR_ID_IMATION 0x0718
228#define USB_DEVICE_ID_DISC_STAKKA 0xd000
229
230#define USB_VENDOR_ID_KBGEAR 0x084e
231#define USB_DEVICE_ID_KBGEAR_JAMSTUDIO 0x1001
232
233#define USB_VENDOR_ID_LD 0x0f11
234#define USB_DEVICE_ID_LD_CASSY 0x1000
235#define USB_DEVICE_ID_LD_POCKETCASSY 0x1010
236#define USB_DEVICE_ID_LD_MOBILECASSY 0x1020
237#define USB_DEVICE_ID_LD_JWM 0x1080
238#define USB_DEVICE_ID_LD_DMMP 0x1081
239#define USB_DEVICE_ID_LD_UMIP 0x1090
240#define USB_DEVICE_ID_LD_XRAY1 0x1100
241#define USB_DEVICE_ID_LD_XRAY2 0x1101
242#define USB_DEVICE_ID_LD_VIDEOCOM 0x1200
243#define USB_DEVICE_ID_LD_COM3LAB 0x2000
244#define USB_DEVICE_ID_LD_TELEPORT 0x2010
245#define USB_DEVICE_ID_LD_NETWORKANALYSER 0x2020
246#define USB_DEVICE_ID_LD_POWERCONTROL 0x2030
247#define USB_DEVICE_ID_LD_MACHINETEST 0x2040
248
249#define USB_VENDOR_ID_LOGITECH 0x046d
250#define USB_DEVICE_ID_LOGITECH_LX3 0xc044
251#define USB_DEVICE_ID_LOGITECH_V150 0xc047
252#define USB_DEVICE_ID_LOGITECH_RECEIVER 0xc101
253#define USB_DEVICE_ID_LOGITECH_HARMONY 0xc110
254#define USB_DEVICE_ID_LOGITECH_HARMONY_2 0xc111
255#define USB_DEVICE_ID_LOGITECH_HARMONY_3 0xc112
256#define USB_DEVICE_ID_LOGITECH_HARMONY_4 0xc113
257#define USB_DEVICE_ID_LOGITECH_HARMONY_5 0xc114
258#define USB_DEVICE_ID_LOGITECH_HARMONY_6 0xc115
259#define USB_DEVICE_ID_LOGITECH_HARMONY_7 0xc116
260#define USB_DEVICE_ID_LOGITECH_HARMONY_8 0xc117
261#define USB_DEVICE_ID_LOGITECH_HARMONY_9 0xc118
262#define USB_DEVICE_ID_LOGITECH_HARMONY_10 0xc119
263#define USB_DEVICE_ID_LOGITECH_HARMONY_11 0xc11a
264#define USB_DEVICE_ID_LOGITECH_HARMONY_12 0xc11b
265#define USB_DEVICE_ID_LOGITECH_HARMONY_13 0xc11c
266#define USB_DEVICE_ID_LOGITECH_HARMONY_14 0xc11d
267#define USB_DEVICE_ID_LOGITECH_HARMONY_15 0xc11e
268#define USB_DEVICE_ID_LOGITECH_HARMONY_16 0xc11f
269#define USB_DEVICE_ID_LOGITECH_HARMONY_17 0xc120
270#define USB_DEVICE_ID_LOGITECH_HARMONY_18 0xc121
271#define USB_DEVICE_ID_LOGITECH_HARMONY_19 0xc122
272#define USB_DEVICE_ID_LOGITECH_HARMONY_20 0xc123
273#define USB_DEVICE_ID_LOGITECH_HARMONY_21 0xc124
274#define USB_DEVICE_ID_LOGITECH_HARMONY_22 0xc125
275#define USB_DEVICE_ID_LOGITECH_HARMONY_23 0xc126
276#define USB_DEVICE_ID_LOGITECH_HARMONY_24 0xc127
277#define USB_DEVICE_ID_LOGITECH_HARMONY_25 0xc128
278#define USB_DEVICE_ID_LOGITECH_HARMONY_26 0xc129
279#define USB_DEVICE_ID_LOGITECH_HARMONY_27 0xc12a
280#define USB_DEVICE_ID_LOGITECH_HARMONY_28 0xc12b
281#define USB_DEVICE_ID_LOGITECH_HARMONY_29 0xc12c
282#define USB_DEVICE_ID_LOGITECH_HARMONY_30 0xc12d
283#define USB_DEVICE_ID_LOGITECH_HARMONY_31 0xc12e
284#define USB_DEVICE_ID_LOGITECH_HARMONY_32 0xc12f
285#define USB_DEVICE_ID_LOGITECH_HARMONY_33 0xc130
286#define USB_DEVICE_ID_LOGITECH_HARMONY_34 0xc131
287#define USB_DEVICE_ID_LOGITECH_HARMONY_35 0xc132
288#define USB_DEVICE_ID_LOGITECH_HARMONY_36 0xc133
289#define USB_DEVICE_ID_LOGITECH_HARMONY_37 0xc134
290#define USB_DEVICE_ID_LOGITECH_HARMONY_38 0xc135
291#define USB_DEVICE_ID_LOGITECH_HARMONY_39 0xc136
292#define USB_DEVICE_ID_LOGITECH_HARMONY_40 0xc137
293#define USB_DEVICE_ID_LOGITECH_HARMONY_41 0xc138
294#define USB_DEVICE_ID_LOGITECH_HARMONY_42 0xc139
295#define USB_DEVICE_ID_LOGITECH_HARMONY_43 0xc13a
296#define USB_DEVICE_ID_LOGITECH_HARMONY_44 0xc13b
297#define USB_DEVICE_ID_LOGITECH_HARMONY_45 0xc13c
298#define USB_DEVICE_ID_LOGITECH_HARMONY_46 0xc13d
299#define USB_DEVICE_ID_LOGITECH_HARMONY_47 0xc13e
300#define USB_DEVICE_ID_LOGITECH_HARMONY_48 0xc13f
301#define USB_DEVICE_ID_LOGITECH_HARMONY_49 0xc140
302#define USB_DEVICE_ID_LOGITECH_HARMONY_50 0xc141
303#define USB_DEVICE_ID_LOGITECH_HARMONY_51 0xc142
304#define USB_DEVICE_ID_LOGITECH_HARMONY_52 0xc143
305#define USB_DEVICE_ID_LOGITECH_HARMONY_53 0xc144
306#define USB_DEVICE_ID_LOGITECH_HARMONY_54 0xc145
307#define USB_DEVICE_ID_LOGITECH_HARMONY_55 0xc146
308#define USB_DEVICE_ID_LOGITECH_HARMONY_56 0xc147
309#define USB_DEVICE_ID_LOGITECH_HARMONY_57 0xc148
310#define USB_DEVICE_ID_LOGITECH_HARMONY_58 0xc149
311#define USB_DEVICE_ID_LOGITECH_HARMONY_59 0xc14a
312#define USB_DEVICE_ID_LOGITECH_HARMONY_60 0xc14b
313#define USB_DEVICE_ID_LOGITECH_HARMONY_61 0xc14c
314#define USB_DEVICE_ID_LOGITECH_HARMONY_62 0xc14d
315#define USB_DEVICE_ID_LOGITECH_HARMONY_63 0xc14e
316#define USB_DEVICE_ID_LOGITECH_HARMONY_64 0xc14f
317#define USB_DEVICE_ID_LOGITECH_EXTREME_3D 0xc215
318#define USB_DEVICE_ID_LOGITECH_WHEEL 0xc294
319#define USB_DEVICE_ID_LOGITECH_ELITE_KBD 0xc30a
320#define USB_DEVICE_ID_LOGITECH_KBD 0xc311
321#define USB_DEVICE_ID_S510_RECEIVER 0xc50c
322#define USB_DEVICE_ID_S510_RECEIVER_2 0xc517
323#define USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500 0xc512
324#define USB_DEVICE_ID_MX3000_RECEIVER 0xc513
325#define USB_DEVICE_ID_DINOVO_DESKTOP 0xc704
326#define USB_DEVICE_ID_DINOVO_EDGE 0xc714
327#define USB_DEVICE_ID_DINOVO_MINI 0xc71f
328
329#define USB_VENDOR_ID_MCC 0x09db
330#define USB_DEVICE_ID_MCC_PMD1024LS 0x0076
331#define USB_DEVICE_ID_MCC_PMD1208LS 0x007a
332
333#define USB_VENDOR_ID_MGE 0x0463
334#define USB_DEVICE_ID_MGE_UPS 0xffff
335#define USB_DEVICE_ID_MGE_UPS1 0x0001
336
337#define USB_VENDOR_ID_MICROCHIP 0x04d8
338#define USB_DEVICE_ID_PICKIT1 0x0032
339#define USB_DEVICE_ID_PICKIT2 0x0033
340
341#define USB_VENDOR_ID_MICROSOFT 0x045e
342#define USB_DEVICE_ID_SIDEWINDER_GV 0x003b
343#define USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0 0x009d
344#define USB_DEVICE_ID_DESKTOP_RECV_1028 0x00f9
345#define USB_DEVICE_ID_MS_NE4K 0x00db
346#define USB_DEVICE_ID_MS_LK6K 0x00f9
347
348#define USB_VENDOR_ID_MONTEREY 0x0566
349#define USB_DEVICE_ID_GENIUS_KB29E 0x3004
350
351#define USB_VENDOR_ID_NCR 0x0404
352#define USB_DEVICE_ID_NCR_FIRST 0x0300
353#define USB_DEVICE_ID_NCR_LAST 0x03ff
354
355#define USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR 0x0400
356#define USB_DEVICE_ID_N_S_HARMONY 0xc359
357
358#define USB_VENDOR_ID_NATSU 0x08b7
359#define USB_DEVICE_ID_NATSU_GAMEPAD 0x0001
360
361#define USB_VENDOR_ID_NEC 0x073e
362#define USB_DEVICE_ID_NEC_USB_GAME_PAD 0x0301
363
364#define USB_VENDOR_ID_ONTRAK 0x0a07
365#define USB_DEVICE_ID_ONTRAK_ADU100 0x0064
366
367#define USB_VENDOR_ID_PANJIT 0x134c
368
369#define USB_VENDOR_ID_PANTHERLORD 0x0810
370#define USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK 0x0001
371
372#define USB_VENDOR_ID_PETALYNX 0x18b1
373#define USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE 0x0037
374
375#define USB_VENDOR_ID_PLAYDOTCOM 0x0b43
376#define USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII 0x0003
377
378#define USB_VENDOR_ID_SAITEK 0x06a3
379#define USB_DEVICE_ID_SAITEK_RUMBLEPAD 0xff17
380
381#define USB_VENDOR_ID_SAMSUNG 0x0419
382#define USB_DEVICE_ID_SAMSUNG_IR_REMOTE 0x0001
383
384#define USB_VENDOR_ID_SONY 0x054c
385#define USB_DEVICE_ID_SONY_PS3_CONTROLLER 0x0268
386
387#define USB_VENDOR_ID_SOUNDGRAPH 0x15c2
388#define USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD 0x0038
389
390#define USB_VENDOR_ID_SUN 0x0430
391#define USB_DEVICE_ID_RARITAN_KVM_DONGLE 0xcdab
392
393#define USB_VENDOR_ID_SUNPLUS 0x04fc
394#define USB_DEVICE_ID_SUNPLUS_WDESKTOP 0x05d8
395
396#define USB_VENDOR_ID_TOPMAX 0x0663
397#define USB_DEVICE_ID_TOPMAX_COBRAPAD 0x0103
398
399#define USB_VENDOR_ID_TURBOX 0x062a
400#define USB_DEVICE_ID_TURBOX_KEYBOARD 0x0201
401
402#define USB_VENDOR_ID_VERNIER 0x08f7
403#define USB_DEVICE_ID_VERNIER_LABPRO 0x0001
404#define USB_DEVICE_ID_VERNIER_GOTEMP 0x0002
405#define USB_DEVICE_ID_VERNIER_SKIP 0x0003
406#define USB_DEVICE_ID_VERNIER_CYCLOPS 0x0004
407#define USB_DEVICE_ID_VERNIER_LCSPEC 0x0006
408
409#define USB_VENDOR_ID_WACOM 0x056a
410
411#define USB_VENDOR_ID_WISEGROUP 0x0925
412#define USB_DEVICE_ID_1_PHIDGETSERVO_20 0x8101
413#define USB_DEVICE_ID_4_PHIDGETSERVO_20 0x8104
414#define USB_DEVICE_ID_8_8_4_IF_KIT 0x8201
415#define USB_DEVICE_ID_QUAD_USB_JOYPAD 0x8800
416#define USB_DEVICE_ID_DUAL_USB_JOYPAD 0x8866
417
418#define USB_VENDOR_ID_WISEGROUP_LTD 0x6677
419#define USB_DEVICE_ID_SMARTJOY_DUAL_PLUS 0x8802
420
421#define USB_VENDOR_ID_YEALINK 0x6993
422#define USB_DEVICE_ID_YEALINK_P1K_P4K_B2K 0xb001
423
424#define USB_VENDOR_ID_KYE 0x0458
425#define USB_DEVICE_ID_KYE_GPEN_560 0x5003
426 21
427/* 22/*
428 * Alphabetically sorted blacklist by quirk type. 23 * Alphabetically sorted blacklist by quirk type.
@@ -433,18 +28,10 @@ static const struct hid_blacklist {
433 __u16 idProduct; 28 __u16 idProduct;
434 __u32 quirks; 29 __u32 quirks;
435} hid_blacklist[] = { 30} hid_blacklist[] = {
436
437 { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU, HID_QUIRK_2WHEEL_MOUSE_HACK_7 },
438 { USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D, HID_QUIRK_2WHEEL_MOUSE_HACK_B8 },
439 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_MOUSE, HID_QUIRK_2WHEEL_MOUSE_HACK_5 },
440
441 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_RECEIVER, HID_QUIRK_BAD_RELATIVE_KEYS },
442
443 { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_GAMEPAD, HID_QUIRK_BADPAD }, 31 { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_GAMEPAD, HID_QUIRK_BADPAD },
444 { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_PREDATOR, HID_QUIRK_BADPAD }, 32 { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_PREDATOR, HID_QUIRK_BADPAD },
445 { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD }, 33 { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD },
446 { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD }, 34 { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD },
447 { USB_VENDOR_ID_GAMERON, USB_DEVICE_ID_GAMERON_DUAL_PSX_ADAPTOR, HID_QUIRK_MULTI_INPUT },
448 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, 35 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
449 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FLYING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, 36 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FLYING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
450 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FIGHTING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, 37 { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FIGHTING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT },
@@ -453,169 +40,11 @@ static const struct hid_blacklist {
453 { USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD }, 40 { USB_VENDOR_ID_SAITEK, USB_DEVICE_ID_SAITEK_RUMBLEPAD, HID_QUIRK_BADPAD },
454 { USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD }, 41 { USB_VENDOR_ID_TOPMAX, USB_DEVICE_ID_TOPMAX_COBRAPAD, HID_QUIRK_BADPAD },
455 42
456 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_DESKTOP, HID_QUIRK_DUPLICATE_USAGES },
457 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_EDGE, HID_QUIRK_DUPLICATE_USAGES },
458 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_DINOVO_MINI, HID_QUIRK_DUPLICATE_USAGES },
459
460 { USB_VENDOR_ID_AFATECH, USB_DEVICE_ID_AFATECH_AF9016, HID_QUIRK_FULLSPEED_INTERVAL }, 43 { USB_VENDOR_ID_AFATECH, USB_DEVICE_ID_AFATECH_AF9016, HID_QUIRK_FULLSPEED_INTERVAL },
461 44
462 { USB_VENDOR_ID_BELKIN, USB_DEVICE_ID_FLIP_KVM, HID_QUIRK_HIDDEV },
463 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4, HID_QUIRK_HIDDEV | HID_QUIRK_IGNORE_HIDINPUT },
464 { USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE, HID_QUIRK_HIDDEV | HID_QUIRK_IGNORE_HIDINPUT },
465 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_SIDEWINDER_GV, HID_QUIRK_HIDINPUT },
466
467 { USB_VENDOR_ID_EZKEY, USB_DEVICE_ID_BTC_8193, HID_QUIRK_HWHEEL_WHEEL_INVERT },
468
469 { USB_VENDOR_ID_ADS_TECH, USB_DEVICE_ID_ADS_TECH_RADIO_SI470X, HID_QUIRK_IGNORE },
470 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_01, HID_QUIRK_IGNORE },
471 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_10, HID_QUIRK_IGNORE },
472 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_20, HID_QUIRK_IGNORE },
473 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_21, HID_QUIRK_IGNORE },
474 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_22, HID_QUIRK_IGNORE },
475 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_23, HID_QUIRK_IGNORE },
476 { USB_VENDOR_ID_AIPTEK, USB_DEVICE_ID_AIPTEK_24, HID_QUIRK_IGNORE },
477 { USB_VENDOR_ID_AIRCABLE, USB_DEVICE_ID_AIRCABLE1, HID_QUIRK_IGNORE },
478 { USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232, HID_QUIRK_IGNORE },
479 { USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_LCM, HID_QUIRK_IGNORE},
480 { USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD, HID_QUIRK_IGNORE },
481 { USB_VENDOR_ID_CIDC, 0x0103, HID_QUIRK_IGNORE },
482 { USB_VENDOR_ID_CYGNAL, USB_DEVICE_ID_CYGNAL_RADIO_SI470X, HID_QUIRK_IGNORE },
483 { USB_VENDOR_ID_CMEDIA, USB_DEVICE_ID_CM109, HID_QUIRK_IGNORE },
484 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_HIDCOM, HID_QUIRK_IGNORE },
485 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_ULTRAMOUSE, HID_QUIRK_IGNORE },
486 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EARTHMATE, HID_QUIRK_IGNORE },
487 { USB_VENDOR_ID_DELORME, USB_DEVICE_ID_DELORME_EM_LT20, HID_QUIRK_IGNORE },
488 { USB_VENDOR_ID_ESSENTIAL_REALITY, USB_DEVICE_ID_ESSENTIAL_REALITY_P5, HID_QUIRK_IGNORE },
489 { USB_VENDOR_ID_GENERAL_TOUCH, 0x0001, HID_QUIRK_IGNORE },
490 { USB_VENDOR_ID_GENERAL_TOUCH, 0x0002, HID_QUIRK_IGNORE },
491 { USB_VENDOR_ID_GENERAL_TOUCH, 0x0003, HID_QUIRK_IGNORE },
492 { USB_VENDOR_ID_GENERAL_TOUCH, 0x0004, HID_QUIRK_IGNORE },
493 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_4_PHIDGETSERVO_30, HID_QUIRK_IGNORE },
494 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_1_PHIDGETSERVO_30, HID_QUIRK_IGNORE },
495 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_0_4_IF_KIT, HID_QUIRK_IGNORE },
496 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_16_16_IF_KIT, HID_QUIRK_IGNORE },
497 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_8_8_8_IF_KIT, HID_QUIRK_IGNORE },
498 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_7_IF_KIT, HID_QUIRK_IGNORE },
499 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_0_8_8_IF_KIT, HID_QUIRK_IGNORE },
500 { USB_VENDOR_ID_GLAB, USB_DEVICE_ID_PHIDGET_MOTORCONTROL, HID_QUIRK_IGNORE },
501 { USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_SUPER_Q2, HID_QUIRK_IGNORE },
502 { USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_GOGOPEN, HID_QUIRK_IGNORE },
503 { USB_VENDOR_ID_GOTOP, USB_DEVICE_ID_PENPOWER, HID_QUIRK_IGNORE },
504 { USB_VENDOR_ID_GRETAGMACBETH, USB_DEVICE_ID_GRETAGMACBETH_HUEY, HID_QUIRK_IGNORE },
505 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_POWERMATE, HID_QUIRK_IGNORE },
506 { USB_VENDOR_ID_GRIFFIN, USB_DEVICE_ID_SOUNDKNOB, HID_QUIRK_IGNORE },
507 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_90, HID_QUIRK_IGNORE },
508 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_100, HID_QUIRK_IGNORE },
509 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_101, HID_QUIRK_IGNORE },
510 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_103, HID_QUIRK_IGNORE },
511 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_104, HID_QUIRK_IGNORE },
512 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_105, HID_QUIRK_IGNORE },
513 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_106, HID_QUIRK_IGNORE },
514 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_107, HID_QUIRK_IGNORE },
515 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_108, HID_QUIRK_IGNORE },
516 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_200, HID_QUIRK_IGNORE },
517 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_201, HID_QUIRK_IGNORE },
518 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_202, HID_QUIRK_IGNORE },
519 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_203, HID_QUIRK_IGNORE },
520 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_204, HID_QUIRK_IGNORE },
521 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_205, HID_QUIRK_IGNORE },
522 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_206, HID_QUIRK_IGNORE },
523 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_207, HID_QUIRK_IGNORE },
524 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_300, HID_QUIRK_IGNORE },
525 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_301, HID_QUIRK_IGNORE },
526 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_302, HID_QUIRK_IGNORE },
527 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_303, HID_QUIRK_IGNORE },
528 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_304, HID_QUIRK_IGNORE },
529 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_305, HID_QUIRK_IGNORE },
530 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_306, HID_QUIRK_IGNORE },
531 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_307, HID_QUIRK_IGNORE },
532 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_308, HID_QUIRK_IGNORE },
533 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_309, HID_QUIRK_IGNORE },
534 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_400, HID_QUIRK_IGNORE },
535 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_401, HID_QUIRK_IGNORE },
536 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_402, HID_QUIRK_IGNORE },
537 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_403, HID_QUIRK_IGNORE },
538 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_404, HID_QUIRK_IGNORE },
539 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_405, HID_QUIRK_IGNORE },
540 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_500, HID_QUIRK_IGNORE },
541 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_501, HID_QUIRK_IGNORE },
542 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_502, HID_QUIRK_IGNORE },
543 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_503, HID_QUIRK_IGNORE },
544 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_504, HID_QUIRK_IGNORE },
545 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1000, HID_QUIRK_IGNORE },
546 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1001, HID_QUIRK_IGNORE },
547 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1002, HID_QUIRK_IGNORE },
548 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1003, HID_QUIRK_IGNORE },
549 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1004, HID_QUIRK_IGNORE },
550 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1005, HID_QUIRK_IGNORE },
551 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1006, HID_QUIRK_IGNORE },
552 { USB_VENDOR_ID_GTCO, USB_DEVICE_ID_GTCO_1007, HID_QUIRK_IGNORE },
553 { USB_VENDOR_ID_IMATION, USB_DEVICE_ID_DISC_STAKKA, HID_QUIRK_IGNORE },
554 { USB_VENDOR_ID_KBGEAR, USB_DEVICE_ID_KBGEAR_JAMSTUDIO, HID_QUIRK_IGNORE },
555 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_CASSY, HID_QUIRK_IGNORE },
556 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POCKETCASSY, HID_QUIRK_IGNORE },
557 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MOBILECASSY, HID_QUIRK_IGNORE },
558 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_JWM, HID_QUIRK_IGNORE },
559 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_DMMP, HID_QUIRK_IGNORE },
560 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_UMIP, HID_QUIRK_IGNORE },
561 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY1, HID_QUIRK_IGNORE },
562 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_XRAY2, HID_QUIRK_IGNORE },
563 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_VIDEOCOM, HID_QUIRK_IGNORE },
564 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_COM3LAB, HID_QUIRK_IGNORE },
565 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_TELEPORT, HID_QUIRK_IGNORE },
566 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_NETWORKANALYSER, HID_QUIRK_IGNORE },
567 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_POWERCONTROL, HID_QUIRK_IGNORE },
568 { USB_VENDOR_ID_LD, USB_DEVICE_ID_LD_MACHINETEST, HID_QUIRK_IGNORE },
569 { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1024LS, HID_QUIRK_IGNORE },
570 { USB_VENDOR_ID_MCC, USB_DEVICE_ID_MCC_PMD1208LS, HID_QUIRK_IGNORE },
571 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS, HID_QUIRK_IGNORE },
572 { USB_VENDOR_ID_MGE, USB_DEVICE_ID_MGE_UPS1, HID_QUIRK_IGNORE },
573 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100, HID_QUIRK_IGNORE },
574 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 20, HID_QUIRK_IGNORE },
575 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 30, HID_QUIRK_IGNORE },
576 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 100, HID_QUIRK_IGNORE },
577 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 108, HID_QUIRK_IGNORE },
578 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 118, HID_QUIRK_IGNORE },
579 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 200, HID_QUIRK_IGNORE },
580 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 300, HID_QUIRK_IGNORE },
581 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 400, HID_QUIRK_IGNORE },
582 { USB_VENDOR_ID_ONTRAK, USB_DEVICE_ID_ONTRAK_ADU100 + 500, HID_QUIRK_IGNORE },
583 { USB_VENDOR_ID_PANJIT, 0x0001, HID_QUIRK_IGNORE },
584 { USB_VENDOR_ID_PANJIT, 0x0002, HID_QUIRK_IGNORE },
585 { USB_VENDOR_ID_PANJIT, 0x0003, HID_QUIRK_IGNORE },
586 { USB_VENDOR_ID_PANJIT, 0x0004, HID_QUIRK_IGNORE },
587 { USB_VENDOR_ID_SOUNDGRAPH, USB_DEVICE_ID_SOUNDGRAPH_IMON_LCD, HID_QUIRK_IGNORE },
588 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LABPRO, HID_QUIRK_IGNORE },
589 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_GOTEMP, HID_QUIRK_IGNORE },
590 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_SKIP, HID_QUIRK_IGNORE },
591 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_CYCLOPS, HID_QUIRK_IGNORE },
592 { USB_VENDOR_ID_VERNIER, USB_DEVICE_ID_VERNIER_LCSPEC, HID_QUIRK_IGNORE },
593 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_4_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
594 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_1_PHIDGETSERVO_20, HID_QUIRK_IGNORE },
595 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_8_8_4_IF_KIT, HID_QUIRK_IGNORE },
596 { USB_VENDOR_ID_YEALINK, USB_DEVICE_ID_YEALINK_P1K_P4K_B2K, HID_QUIRK_IGNORE },
597
598 { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_FLAIR, HID_QUIRK_IGNORE },
599 { USB_VENDOR_ID_ACECAD, USB_DEVICE_ID_ACECAD_302, HID_QUIRK_IGNORE },
600
601 { USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT1, HID_QUIRK_IGNORE },
602 { USB_VENDOR_ID_MICROCHIP, USB_DEVICE_ID_PICKIT2, HID_QUIRK_IGNORE },
603
604 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_ELITE_KBD, HID_QUIRK_LOGITECH_IGNORE_DOUBLED_WHEEL | HID_QUIRK_LOGITECH_EXPANDED_KEYMAP },
605 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_CORDLESS_DESKTOP_LX500, HID_QUIRK_LOGITECH_IGNORE_DOUBLED_WHEEL | HID_QUIRK_LOGITECH_EXPANDED_KEYMAP },
606 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_LX3, HID_QUIRK_INVERT_HWHEEL },
607 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_V150, HID_QUIRK_INVERT_HWHEEL },
608
609 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_NE4K, HID_QUIRK_MICROSOFT_KEYS },
610 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_MS_LK6K, HID_QUIRK_MICROSOFT_KEYS },
611
612 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE, HID_QUIRK_MIGHTYMOUSE | HID_QUIRK_INVERT_HWHEEL },
613
614 { USB_VENDOR_ID_PANTHERLORD, USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK, HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS }, 45 { USB_VENDOR_ID_PANTHERLORD, USB_DEVICE_ID_PANTHERLORD_TWIN_USB_JOYSTICK, HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS },
615 { USB_VENDOR_ID_PLAYDOTCOM, USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII, HID_QUIRK_MULTI_INPUT }, 46 { USB_VENDOR_ID_PLAYDOTCOM, USB_DEVICE_ID_PLAYDOTCOM_EMS_USBII, HID_QUIRK_MULTI_INPUT },
616 47
617 { USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER, HID_QUIRK_SONY_PS3_CONTROLLER | HID_QUIRK_HIDDEV },
618
619 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_UC100KM, HID_QUIRK_NOGET }, 48 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_UC100KM, HID_QUIRK_NOGET },
620 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS124U, HID_QUIRK_NOGET }, 49 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_CS124U, HID_QUIRK_NOGET },
621 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET }, 50 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_2PORTKVM, HID_QUIRK_NOGET },
@@ -623,144 +52,13 @@ static const struct hid_blacklist {
623 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET }, 52 { USB_VENDOR_ID_ATEN, USB_DEVICE_ID_ATEN_4PORTKVMC, HID_QUIRK_NOGET },
624 { USB_VENDOR_ID_DMI, USB_DEVICE_ID_DMI_ENC, HID_QUIRK_NOGET }, 53 { USB_VENDOR_ID_DMI, USB_DEVICE_ID_DMI_ENC, HID_QUIRK_NOGET },
625 { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET }, 54 { USB_VENDOR_ID_ELO, USB_DEVICE_ID_ELO_TS2700, HID_QUIRK_NOGET },
626 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_EXTREME_3D, HID_QUIRK_NOGET },
627 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_WHEEL, HID_QUIRK_NOGET },
628 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_WIRELESS_OPTICAL_DESKTOP_3_0, HID_QUIRK_NOGET },
629 { USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE, HID_QUIRK_NOGET },
630 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET }, 55 { USB_VENDOR_ID_SUN, USB_DEVICE_ID_RARITAN_KVM_DONGLE, HID_QUIRK_NOGET },
631 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET }, 56 { USB_VENDOR_ID_TURBOX, USB_DEVICE_ID_TURBOX_KEYBOARD, HID_QUIRK_NOGET },
632 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS }, 57 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_DUAL_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT | HID_QUIRK_SKIP_OUTPUT_REPORTS },
633 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_QUAD_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, 58 { USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_QUAD_USB_JOYPAD, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
634 59
635 { USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT }, 60 { USB_VENDOR_ID_WISEGROUP_LTD, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
636 61 { USB_VENDOR_ID_WISEGROUP_LTD2, USB_DEVICE_ID_SMARTJOY_DUAL_PLUS, HID_QUIRK_NOGET | HID_QUIRK_MULTI_INPUT },
637 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
638 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
639 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ANSI, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
640 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_ISO, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_APPLE_ISO_KEYBOARD},
641 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER_JIS, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
642 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ANSI, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
643 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_ISO, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_APPLE_ISO_KEYBOARD},
644 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER3_JIS, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
645 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
646 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_APPLE_ISO_KEYBOARD},
647 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
648 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ANSI, HID_QUIRK_APPLE_HAS_FN },
649 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_ISO, HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_APPLE_ISO_KEYBOARD },
650 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_JIS, HID_QUIRK_APPLE_HAS_FN },
651 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
652 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
653 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
654 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ANSI, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN },
655 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_ISO, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_APPLE_ISO_KEYBOARD },
656 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ALU_WIRELESS_JIS, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN },
657 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ANSI, HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
658 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_ISO, HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_APPLE_ISO_KEYBOARD | HID_QUIRK_IGNORE_MOUSE},
659 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING_JIS, HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE},
660 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ANSI, HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE},
661 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_ISO, HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_APPLE_ISO_KEYBOARD | HID_QUIRK_IGNORE_MOUSE },
662 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WELLSPRING2_JIS, HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
663 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
664 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY, HID_QUIRK_APPLE_NUMLOCK_EMULATION | HID_QUIRK_APPLE_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
665
666 { USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_W7658, HID_QUIRK_RESET_LEDS },
667 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_KBD, HID_QUIRK_RESET_LEDS },
668 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY, HID_QUIRK_IGNORE },
669 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_2, HID_QUIRK_IGNORE },
670 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_3, HID_QUIRK_IGNORE },
671 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_4, HID_QUIRK_IGNORE },
672 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_5, HID_QUIRK_IGNORE },
673 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_6, HID_QUIRK_IGNORE },
674 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_7, HID_QUIRK_IGNORE },
675 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_8, HID_QUIRK_IGNORE },
676 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_9, HID_QUIRK_IGNORE },
677 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_10, HID_QUIRK_IGNORE },
678 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_11, HID_QUIRK_IGNORE },
679 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_12, HID_QUIRK_IGNORE },
680 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_13, HID_QUIRK_IGNORE },
681 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_14, HID_QUIRK_IGNORE },
682 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_15, HID_QUIRK_IGNORE },
683 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_16, HID_QUIRK_IGNORE },
684 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_17, HID_QUIRK_IGNORE },
685 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_18, HID_QUIRK_IGNORE },
686 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_19, HID_QUIRK_IGNORE },
687 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_20, HID_QUIRK_IGNORE },
688 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_21, HID_QUIRK_IGNORE },
689 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_22, HID_QUIRK_IGNORE },
690 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_23, HID_QUIRK_IGNORE },
691 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_24, HID_QUIRK_IGNORE },
692 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_25, HID_QUIRK_IGNORE },
693 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_26, HID_QUIRK_IGNORE },
694 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_27, HID_QUIRK_IGNORE },
695 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_28, HID_QUIRK_IGNORE },
696 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_29, HID_QUIRK_IGNORE },
697 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_30, HID_QUIRK_IGNORE },
698 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_31, HID_QUIRK_IGNORE },
699 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_32, HID_QUIRK_IGNORE },
700 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_33, HID_QUIRK_IGNORE },
701 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_34, HID_QUIRK_IGNORE },
702 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_35, HID_QUIRK_IGNORE },
703 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_36, HID_QUIRK_IGNORE },
704 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_37, HID_QUIRK_IGNORE },
705 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_38, HID_QUIRK_IGNORE },
706 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_39, HID_QUIRK_IGNORE },
707 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_40, HID_QUIRK_IGNORE },
708 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_41, HID_QUIRK_IGNORE },
709 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_42, HID_QUIRK_IGNORE },
710 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_43, HID_QUIRK_IGNORE },
711 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_44, HID_QUIRK_IGNORE },
712 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_45, HID_QUIRK_IGNORE },
713 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_46, HID_QUIRK_IGNORE },
714 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_47, HID_QUIRK_IGNORE },
715 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_48, HID_QUIRK_IGNORE },
716 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_49, HID_QUIRK_IGNORE },
717 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_50, HID_QUIRK_IGNORE },
718 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_51, HID_QUIRK_IGNORE },
719 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_52, HID_QUIRK_IGNORE },
720 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_53, HID_QUIRK_IGNORE },
721 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_54, HID_QUIRK_IGNORE },
722 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_55, HID_QUIRK_IGNORE },
723 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_56, HID_QUIRK_IGNORE },
724 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_57, HID_QUIRK_IGNORE },
725 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_58, HID_QUIRK_IGNORE },
726 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_59, HID_QUIRK_IGNORE },
727 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_60, HID_QUIRK_IGNORE },
728 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_61, HID_QUIRK_IGNORE },
729 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_62, HID_QUIRK_IGNORE },
730 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_63, HID_QUIRK_IGNORE },
731 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_LOGITECH_HARMONY_64, HID_QUIRK_IGNORE },
732 { USB_VENDOR_ID_NATIONAL_SEMICONDUCTOR, USB_DEVICE_ID_N_S_HARMONY, HID_QUIRK_IGNORE },
733 { USB_VENDOR_ID_KYE, USB_DEVICE_ID_KYE_GPEN_560, HID_QUIRK_IGNORE },
734
735 { 0, 0 }
736};
737
738/* Quirks for devices which require report descriptor fixup go here */
739static const struct hid_rdesc_blacklist {
740 __u16 idVendor;
741 __u16 idProduct;
742 __u32 quirks;
743} hid_rdesc_blacklist[] = {
744
745 { USB_VENDOR_ID_CHERRY, USB_DEVICE_ID_CHERRY_CYMOTION, HID_QUIRK_RDESC_CYMOTION },
746
747 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_MX3000_RECEIVER, HID_QUIRK_RDESC_LOGITECH },
748 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER, HID_QUIRK_RDESC_LOGITECH },
749 { USB_VENDOR_ID_LOGITECH, USB_DEVICE_ID_S510_RECEIVER_2, HID_QUIRK_RDESC_LOGITECH },
750 { USB_VENDOR_ID_MICROSOFT, USB_DEVICE_ID_DESKTOP_RECV_1028, HID_QUIRK_RDESC_MICROSOFT_RECV_1028 },
751
752 { USB_VENDOR_ID_MONTEREY, USB_DEVICE_ID_GENIUS_KB29E, HID_QUIRK_RDESC_BUTTON_CONSUMER },
753
754 { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS, HID_QUIRK_RDESC_MACBOOK_JIS },
755
756 { USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE, HID_QUIRK_RDESC_PETALYNX },
757
758 { USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE, HID_QUIRK_RDESC_SAMSUNG_REMOTE },
759
760 { USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP, HID_QUIRK_RDESC_SUNPLUS_WDESKTOP },
761
762 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_1, HID_QUIRK_RDESC_SWAPPED_MIN_MAX },
763 { USB_VENDOR_ID_CYPRESS, USB_DEVICE_ID_CYPRESS_BARCODE_2, HID_QUIRK_RDESC_SWAPPED_MIN_MAX },
764 62
765 { 0, 0 } 63 { 0, 0 }
766}; 64};
@@ -974,16 +272,6 @@ u32 usbhid_lookup_quirk(const u16 idVendor, const u16 idProduct)
974 u32 quirks = 0; 272 u32 quirks = 0;
975 const struct hid_blacklist *bl_entry = NULL; 273 const struct hid_blacklist *bl_entry = NULL;
976 274
977 /* Ignore all Wacom devices */
978 if (idVendor == USB_VENDOR_ID_WACOM)
979 return HID_QUIRK_IGNORE;
980
981 /* ignore all Code Mercenaries IOWarrior devices */
982 if (idVendor == USB_VENDOR_ID_CODEMERCS)
983 if (idProduct >= USB_DEVICE_ID_CODEMERCS_IOW_FIRST &&
984 idProduct <= USB_DEVICE_ID_CODEMERCS_IOW_LAST)
985 return HID_QUIRK_IGNORE;
986
987 /* NCR devices must not be queried for reports */ 275 /* NCR devices must not be queried for reports */
988 if (idVendor == USB_VENDOR_ID_NCR && 276 if (idVendor == USB_VENDOR_ID_NCR &&
989 idProduct >= USB_DEVICE_ID_NCR_FIRST && 277 idProduct >= USB_DEVICE_ID_NCR_FIRST &&
@@ -1002,221 +290,3 @@ u32 usbhid_lookup_quirk(const u16 idVendor, const u16 idProduct)
1002} 290}
1003 291
1004EXPORT_SYMBOL_GPL(usbhid_lookup_quirk); 292EXPORT_SYMBOL_GPL(usbhid_lookup_quirk);
1005
1006/*
1007 * Cherry Cymotion keyboard have an invalid HID report descriptor,
1008 * that needs fixing before we can parse it.
1009 */
1010static void usbhid_fixup_cymotion_descriptor(char *rdesc, int rsize)
1011{
1012 if (rsize >= 17 && rdesc[11] == 0x3c && rdesc[12] == 0x02) {
1013 printk(KERN_INFO "Fixing up Cherry Cymotion report descriptor\n");
1014 rdesc[11] = rdesc[16] = 0xff;
1015 rdesc[12] = rdesc[17] = 0x03;
1016 }
1017}
1018
1019
1020/*
1021 * Certain Logitech keyboards send in report #3 keys which are far
1022 * above the logical maximum described in descriptor. This extends
1023 * the original value of 0x28c of logical maximum to 0x104d
1024 */
1025static void usbhid_fixup_logitech_descriptor(unsigned char *rdesc, int rsize)
1026{
1027 if (rsize >= 90 && rdesc[83] == 0x26
1028 && rdesc[84] == 0x8c
1029 && rdesc[85] == 0x02) {
1030 printk(KERN_INFO "Fixing up Logitech keyboard report descriptor\n");
1031 rdesc[84] = rdesc[89] = 0x4d;
1032 rdesc[85] = rdesc[90] = 0x10;
1033 }
1034}
1035
1036static void usbhid_fixup_sunplus_wdesktop(unsigned char *rdesc, int rsize)
1037{
1038 if (rsize >= 107 && rdesc[104] == 0x26
1039 && rdesc[105] == 0x80
1040 && rdesc[106] == 0x03) {
1041 printk(KERN_INFO "Fixing up Sunplus Wireless Desktop report descriptor\n");
1042 rdesc[105] = rdesc[110] = 0x03;
1043 rdesc[106] = rdesc[111] = 0x21;
1044 }
1045}
1046
1047/*
1048 * Samsung IrDA remote controller (reports as Cypress USB Mouse).
1049 *
1050 * Vendor specific report #4 has a size of 48 bit,
1051 * and therefore is not accepted when inspecting the descriptors.
1052 * As a workaround we reinterpret the report as:
1053 * Variable type, count 6, size 8 bit, log. maximum 255
1054 * The burden to reconstruct the data is moved into user space.
1055 */
1056static void usbhid_fixup_samsung_irda_descriptor(unsigned char *rdesc,
1057 int rsize)
1058{
1059 if (rsize >= 182 && rdesc[175] == 0x25
1060 && rdesc[176] == 0x40
1061 && rdesc[177] == 0x75
1062 && rdesc[178] == 0x30
1063 && rdesc[179] == 0x95
1064 && rdesc[180] == 0x01
1065 && rdesc[182] == 0x40) {
1066 printk(KERN_INFO "Fixing up Samsung IrDA report descriptor\n");
1067 rdesc[176] = 0xff;
1068 rdesc[178] = 0x08;
1069 rdesc[180] = 0x06;
1070 rdesc[182] = 0x42;
1071 }
1072}
1073
1074/* Petalynx Maxter Remote has maximum for consumer page set too low */
1075static void usbhid_fixup_petalynx_descriptor(unsigned char *rdesc, int rsize)
1076{
1077 if (rsize >= 60 && rdesc[39] == 0x2a
1078 && rdesc[40] == 0xf5
1079 && rdesc[41] == 0x00
1080 && rdesc[59] == 0x26
1081 && rdesc[60] == 0xf9
1082 && rdesc[61] == 0x00) {
1083 printk(KERN_INFO "Fixing up Petalynx Maxter Remote report descriptor\n");
1084 rdesc[60] = 0xfa;
1085 rdesc[40] = 0xfa;
1086 }
1087}
1088
1089/*
1090 * Some USB barcode readers from cypress have usage min and usage max in
1091 * the wrong order
1092 */
1093static void usbhid_fixup_cypress_descriptor(unsigned char *rdesc, int rsize)
1094{
1095 short fixed = 0;
1096 int i;
1097
1098 for (i = 0; i < rsize - 4; i++) {
1099 if (rdesc[i] == 0x29 && rdesc [i+2] == 0x19) {
1100 unsigned char tmp;
1101
1102 rdesc[i] = 0x19; rdesc[i+2] = 0x29;
1103 tmp = rdesc[i+3];
1104 rdesc[i+3] = rdesc[i+1];
1105 rdesc[i+1] = tmp;
1106 }
1107 }
1108
1109 if (fixed)
1110 printk(KERN_INFO "Fixing up Cypress report descriptor\n");
1111}
1112
1113/*
1114 * MacBook JIS keyboard has wrong logical maximum
1115 */
1116static void usbhid_fixup_macbook_descriptor(unsigned char *rdesc, int rsize)
1117{
1118 if (rsize >= 60 && rdesc[53] == 0x65
1119 && rdesc[59] == 0x65) {
1120 printk(KERN_INFO "Fixing up MacBook JIS keyboard report descriptor\n");
1121 rdesc[53] = rdesc[59] = 0xe7;
1122 }
1123}
1124
1125static void usbhid_fixup_button_consumer_descriptor(unsigned char *rdesc, int rsize)
1126{
1127 if (rsize >= 30 && rdesc[29] == 0x05
1128 && rdesc[30] == 0x09) {
1129 printk(KERN_INFO "Fixing up button/consumer in HID report descriptor\n");
1130 rdesc[30] = 0x0c;
1131 }
1132}
1133
1134/*
1135 * Microsoft Wireless Desktop Receiver (Model 1028) has several
1136 * 'Usage Min/Max' where it ought to have 'Physical Min/Max'
1137 */
1138static void usbhid_fixup_microsoft_descriptor(unsigned char *rdesc, int rsize)
1139{
1140 if (rsize == 571 && rdesc[284] == 0x19
1141 && rdesc[286] == 0x2a
1142 && rdesc[304] == 0x19
1143 && rdesc[306] == 0x29
1144 && rdesc[352] == 0x1a
1145 && rdesc[355] == 0x2a
1146 && rdesc[557] == 0x19
1147 && rdesc[559] == 0x29) {
1148 printk(KERN_INFO "Fixing up Microsoft Wireless Receiver Model 1028 report descriptor\n");
1149 rdesc[284] = rdesc[304] = rdesc[557] = 0x35;
1150 rdesc[352] = 0x36;
1151 rdesc[286] = rdesc[355] = 0x46;
1152 rdesc[306] = rdesc[559] = 0x45;
1153 }
1154}
1155
1156static void __usbhid_fixup_report_descriptor(__u32 quirks, char *rdesc, unsigned rsize)
1157{
1158 if ((quirks & HID_QUIRK_RDESC_CYMOTION))
1159 usbhid_fixup_cymotion_descriptor(rdesc, rsize);
1160
1161 if (quirks & HID_QUIRK_RDESC_LOGITECH)
1162 usbhid_fixup_logitech_descriptor(rdesc, rsize);
1163
1164 if (quirks & HID_QUIRK_RDESC_SWAPPED_MIN_MAX)
1165 usbhid_fixup_cypress_descriptor(rdesc, rsize);
1166
1167 if (quirks & HID_QUIRK_RDESC_PETALYNX)
1168 usbhid_fixup_petalynx_descriptor(rdesc, rsize);
1169
1170 if (quirks & HID_QUIRK_RDESC_MACBOOK_JIS)
1171 usbhid_fixup_macbook_descriptor(rdesc, rsize);
1172
1173 if (quirks & HID_QUIRK_RDESC_BUTTON_CONSUMER)
1174 usbhid_fixup_button_consumer_descriptor(rdesc, rsize);
1175
1176 if (quirks & HID_QUIRK_RDESC_SAMSUNG_REMOTE)
1177 usbhid_fixup_samsung_irda_descriptor(rdesc, rsize);
1178
1179 if (quirks & HID_QUIRK_RDESC_MICROSOFT_RECV_1028)
1180 usbhid_fixup_microsoft_descriptor(rdesc, rsize);
1181
1182 if (quirks & HID_QUIRK_RDESC_SUNPLUS_WDESKTOP)
1183 usbhid_fixup_sunplus_wdesktop(rdesc, rsize);
1184}
1185
1186/**
1187 * usbhid_fixup_report_descriptor: check if report descriptor needs fixup
1188 *
1189 * Description:
1190 * Walks the hid_rdesc_blacklist[] array and checks whether the device
1191 * is known to have broken report descriptor that needs to be fixed up
1192 * prior to entering the HID parser
1193 *
1194 * Returns: nothing
1195 */
1196void usbhid_fixup_report_descriptor(const u16 idVendor, const u16 idProduct,
1197 char *rdesc, unsigned rsize, char **quirks_param)
1198{
1199 int n, m;
1200 u16 paramVendor, paramProduct;
1201 u32 quirks;
1202
1203 /* static rdesc quirk entries */
1204 for (n = 0; hid_rdesc_blacklist[n].idVendor; n++)
1205 if (hid_rdesc_blacklist[n].idVendor == idVendor &&
1206 hid_rdesc_blacklist[n].idProduct == idProduct)
1207 __usbhid_fixup_report_descriptor(hid_rdesc_blacklist[n].quirks,
1208 rdesc, rsize);
1209
1210 /* runtime rdesc quirk entries handling */
1211 for (n = 0; quirks_param[n] && n < MAX_USBHID_BOOT_QUIRKS; n++) {
1212 m = sscanf(quirks_param[n], "0x%hx:0x%hx:0x%x",
1213 &paramVendor, &paramProduct, &quirks);
1214
1215 if (m != 3)
1216 printk(KERN_WARNING
1217 "Could not parse HID quirk module param %s\n",
1218 quirks_param[n]);
1219 else if (paramVendor == idVendor && paramProduct == idProduct)
1220 __usbhid_fixup_report_descriptor(quirks, rdesc, rsize);
1221 }
1222}
diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
index 842e9edb888e..babd65dd46ad 100644
--- a/drivers/hid/usbhid/hiddev.c
+++ b/drivers/hid/usbhid/hiddev.c
@@ -790,21 +790,23 @@ static struct usb_class_driver hiddev_class = {
790/* 790/*
791 * This is where hid.c calls us to connect a hid device to the hiddev driver 791 * This is where hid.c calls us to connect a hid device to the hiddev driver
792 */ 792 */
793int hiddev_connect(struct hid_device *hid) 793int hiddev_connect(struct hid_device *hid, unsigned int force)
794{ 794{
795 struct hiddev *hiddev; 795 struct hiddev *hiddev;
796 struct usbhid_device *usbhid = hid->driver_data; 796 struct usbhid_device *usbhid = hid->driver_data;
797 int i;
798 int retval; 797 int retval;
799 798
800 for (i = 0; i < hid->maxcollection; i++) 799 if (!force) {
801 if (hid->collection[i].type == 800 unsigned int i;
802 HID_COLLECTION_APPLICATION && 801 for (i = 0; i < hid->maxcollection; i++)
803 !IS_INPUT_APPLICATION(hid->collection[i].usage)) 802 if (hid->collection[i].type ==
804 break; 803 HID_COLLECTION_APPLICATION &&
804 !IS_INPUT_APPLICATION(hid->collection[i].usage))
805 break;
805 806
806 if (i == hid->maxcollection && (hid->quirks & HID_QUIRK_HIDDEV) == 0) 807 if (i == hid->maxcollection)
807 return -1; 808 return -1;
809 }
808 810
809 if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL))) 811 if (!(hiddev = kzalloc(sizeof(struct hiddev), GFP_KERNEL)))
810 return -1; 812 return -1;
diff --git a/drivers/hid/usbhid/usbhid.h b/drivers/hid/usbhid/usbhid.h
index 62d2d7c925bd..abedb13c623e 100644
--- a/drivers/hid/usbhid/usbhid.h
+++ b/drivers/hid/usbhid/usbhid.h
@@ -67,7 +67,7 @@ struct usbhid_device {
67 spinlock_t ctrllock; /* Control fifo spinlock */ 67 spinlock_t ctrllock; /* Control fifo spinlock */
68 68
69 struct urb *urbout; /* Output URB */ 69 struct urb *urbout; /* Output URB */
70 struct hid_report *out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */ 70 struct hid_output_fifo out[HID_CONTROL_FIFO_SIZE]; /* Output pipe fifo */
71 unsigned char outhead, outtail; /* Output pipe fifo head & tail */ 71 unsigned char outhead, outtail; /* Output pipe fifo head & tail */
72 char *outbuf; /* Output buffer */ 72 char *outbuf; /* Output buffer */
73 dma_addr_t outbuf_dma; /* Output buffer dma */ 73 dma_addr_t outbuf_dma; /* Output buffer dma */
@@ -82,7 +82,7 @@ struct usbhid_device {
82}; 82};
83 83
84#define hid_to_usb_dev(hid_dev) \ 84#define hid_to_usb_dev(hid_dev) \
85 container_of(hid_dev->dev->parent, struct usb_device, dev) 85 container_of(hid_dev->dev.parent->parent, struct usb_device, dev)
86 86
87#endif 87#endif
88 88
diff --git a/drivers/hid/usbhid/usbkbd.c b/drivers/hid/usbhid/usbkbd.c
index 0caaafe01843..b342926dd7fc 100644
--- a/drivers/hid/usbhid/usbkbd.c
+++ b/drivers/hid/usbhid/usbkbd.c
@@ -105,14 +105,16 @@ static void usb_kbd_irq(struct urb *urb)
105 if (usb_kbd_keycode[kbd->old[i]]) 105 if (usb_kbd_keycode[kbd->old[i]])
106 input_report_key(kbd->dev, usb_kbd_keycode[kbd->old[i]], 0); 106 input_report_key(kbd->dev, usb_kbd_keycode[kbd->old[i]], 0);
107 else 107 else
108 info("Unknown key (scancode %#x) released.", kbd->old[i]); 108 dev_info(&urb->dev->dev,
109 "Unknown key (scancode %#x) released.\n", kbd->old[i]);
109 } 110 }
110 111
111 if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) == kbd->old + 8) { 112 if (kbd->new[i] > 3 && memscan(kbd->old + 2, kbd->new[i], 6) == kbd->old + 8) {
112 if (usb_kbd_keycode[kbd->new[i]]) 113 if (usb_kbd_keycode[kbd->new[i]])
113 input_report_key(kbd->dev, usb_kbd_keycode[kbd->new[i]], 1); 114 input_report_key(kbd->dev, usb_kbd_keycode[kbd->new[i]], 1);
114 else 115 else
115 info("Unknown key (scancode %#x) pressed.", kbd->new[i]); 116 dev_info(&urb->dev->dev,
117 "Unknown key (scancode %#x) released.\n", kbd->new[i]);
116 } 118 }
117 } 119 }
118 120
@@ -159,7 +161,8 @@ static void usb_kbd_led(struct urb *urb)
159 struct usb_kbd *kbd = urb->context; 161 struct usb_kbd *kbd = urb->context;
160 162
161 if (urb->status) 163 if (urb->status)
162 warn("led urb status %d received", urb->status); 164 dev_warn(&urb->dev->dev, "led urb status %d received\n",
165 urb->status);
163 166
164 if (*(kbd->leds) == kbd->newleds) 167 if (*(kbd->leds) == kbd->newleds)
165 return; 168 return;
@@ -352,7 +355,8 @@ static int __init usb_kbd_init(void)
352{ 355{
353 int result = usb_register(&usb_kbd_driver); 356 int result = usb_register(&usb_kbd_driver);
354 if (result == 0) 357 if (result == 0)
355 info(DRIVER_VERSION ":" DRIVER_DESC); 358 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
359 DRIVER_DESC "\n");
356 return result; 360 return result;
357} 361}
358 362
diff --git a/drivers/hid/usbhid/usbmouse.c b/drivers/hid/usbhid/usbmouse.c
index 35689ef172cc..72ab4b268096 100644
--- a/drivers/hid/usbhid/usbmouse.c
+++ b/drivers/hid/usbhid/usbmouse.c
@@ -31,6 +31,11 @@
31#include <linux/usb/input.h> 31#include <linux/usb/input.h>
32#include <linux/hid.h> 32#include <linux/hid.h>
33 33
34/* for apple IDs */
35#ifdef CONFIG_USB_HID_MODULE
36#include "../hid-ids.h"
37#endif
38
34/* 39/*
35 * Version Information 40 * Version Information
36 */ 41 */
@@ -240,7 +245,8 @@ static int __init usb_mouse_init(void)
240{ 245{
241 int retval = usb_register(&usb_mouse_driver); 246 int retval = usb_register(&usb_mouse_driver);
242 if (retval == 0) 247 if (retval == 0)
243 info(DRIVER_VERSION ":" DRIVER_DESC); 248 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
249 DRIVER_DESC "\n");
244 return retval; 250 return retval;
245} 251}
246 252
diff --git a/drivers/hwmon/ams/ams.h b/drivers/hwmon/ams/ams.h
index a6221e5dd984..221ef6915a5f 100644
--- a/drivers/hwmon/ams/ams.h
+++ b/drivers/hwmon/ams/ams.h
@@ -4,7 +4,7 @@
4#include <linux/mutex.h> 4#include <linux/mutex.h>
5#include <linux/spinlock.h> 5#include <linux/spinlock.h>
6#include <linux/types.h> 6#include <linux/types.h>
7#include <asm/of_device.h> 7#include <linux/of_device.h>
8 8
9enum ams_irq { 9enum ams_irq {
10 AMS_IRQ_FREEFALL = 0x01, 10 AMS_IRQ_FREEFALL = 0x01,
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c
index cdb8311e4ef7..27a5d397f9a1 100644
--- a/drivers/hwmon/dme1737.c
+++ b/drivers/hwmon/dme1737.c
@@ -175,11 +175,11 @@ static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23};
175 * Data structures and manipulation thereof 175 * Data structures and manipulation thereof
176 * --------------------------------------------------------------------- */ 176 * --------------------------------------------------------------------- */
177 177
178/* For ISA chips, we abuse the i2c_client addr and name fields. We also use
179 the driver field to differentiate between I2C and ISA chips. */
180struct dme1737_data { 178struct dme1737_data {
181 struct i2c_client client; 179 struct i2c_client *client; /* for I2C devices only */
182 struct device *hwmon_dev; 180 struct device *hwmon_dev;
181 const char *name;
182 unsigned int addr; /* for ISA devices only */
183 183
184 struct mutex update_lock; 184 struct mutex update_lock;
185 int valid; /* !=0 if following fields are valid */ 185 int valid; /* !=0 if following fields are valid */
@@ -512,11 +512,12 @@ static inline int PWM_OFF_TO_REG(int val, int ix, int reg)
512 * before calling dme1737_read or dme1737_write. 512 * before calling dme1737_read or dme1737_write.
513 * --------------------------------------------------------------------- */ 513 * --------------------------------------------------------------------- */
514 514
515static u8 dme1737_read(struct i2c_client *client, u8 reg) 515static u8 dme1737_read(const struct dme1737_data *data, u8 reg)
516{ 516{
517 struct i2c_client *client = data->client;
517 s32 val; 518 s32 val;
518 519
519 if (client->driver) { /* I2C device */ 520 if (client) { /* I2C device */
520 val = i2c_smbus_read_byte_data(client, reg); 521 val = i2c_smbus_read_byte_data(client, reg);
521 522
522 if (val < 0) { 523 if (val < 0) {
@@ -525,18 +526,19 @@ static u8 dme1737_read(struct i2c_client *client, u8 reg)
525 "maintainer.\n", reg); 526 "maintainer.\n", reg);
526 } 527 }
527 } else { /* ISA device */ 528 } else { /* ISA device */
528 outb(reg, client->addr); 529 outb(reg, data->addr);
529 val = inb(client->addr + 1); 530 val = inb(data->addr + 1);
530 } 531 }
531 532
532 return val; 533 return val;
533} 534}
534 535
535static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 val) 536static s32 dme1737_write(const struct dme1737_data *data, u8 reg, u8 val)
536{ 537{
538 struct i2c_client *client = data->client;
537 s32 res = 0; 539 s32 res = 0;
538 540
539 if (client->driver) { /* I2C device */ 541 if (client) { /* I2C device */
540 res = i2c_smbus_write_byte_data(client, reg, val); 542 res = i2c_smbus_write_byte_data(client, reg, val);
541 543
542 if (res < 0) { 544 if (res < 0) {
@@ -545,8 +547,8 @@ static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 val)
545 "maintainer.\n", reg); 547 "maintainer.\n", reg);
546 } 548 }
547 } else { /* ISA device */ 549 } else { /* ISA device */
548 outb(reg, client->addr); 550 outb(reg, data->addr);
549 outb(val, client->addr + 1); 551 outb(val, data->addr + 1);
550 } 552 }
551 553
552 return res; 554 return res;
@@ -555,7 +557,6 @@ static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 val)
555static struct dme1737_data *dme1737_update_device(struct device *dev) 557static struct dme1737_data *dme1737_update_device(struct device *dev)
556{ 558{
557 struct dme1737_data *data = dev_get_drvdata(dev); 559 struct dme1737_data *data = dev_get_drvdata(dev);
558 struct i2c_client *client = &data->client;
559 int ix; 560 int ix;
560 u8 lsb[5]; 561 u8 lsb[5];
561 562
@@ -563,7 +564,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
563 564
564 /* Enable a Vbat monitoring cycle every 10 mins */ 565 /* Enable a Vbat monitoring cycle every 10 mins */
565 if (time_after(jiffies, data->last_vbat + 600 * HZ) || !data->valid) { 566 if (time_after(jiffies, data->last_vbat + 600 * HZ) || !data->valid) {
566 dme1737_write(client, DME1737_REG_CONFIG, dme1737_read(client, 567 dme1737_write(data, DME1737_REG_CONFIG, dme1737_read(data,
567 DME1737_REG_CONFIG) | 0x10); 568 DME1737_REG_CONFIG) | 0x10);
568 data->last_vbat = jiffies; 569 data->last_vbat = jiffies;
569 } 570 }
@@ -571,7 +572,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
571 /* Sample register contents every 1 sec */ 572 /* Sample register contents every 1 sec */
572 if (time_after(jiffies, data->last_update + HZ) || !data->valid) { 573 if (time_after(jiffies, data->last_update + HZ) || !data->valid) {
573 if (data->type != sch5027) { 574 if (data->type != sch5027) {
574 data->vid = dme1737_read(client, DME1737_REG_VID) & 575 data->vid = dme1737_read(data, DME1737_REG_VID) &
575 0x3f; 576 0x3f;
576 } 577 }
577 578
@@ -580,11 +581,11 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
580 /* Voltage inputs are stored as 16 bit values even 581 /* Voltage inputs are stored as 16 bit values even
581 * though they have only 12 bits resolution. This is 582 * though they have only 12 bits resolution. This is
582 * to make it consistent with the temp inputs. */ 583 * to make it consistent with the temp inputs. */
583 data->in[ix] = dme1737_read(client, 584 data->in[ix] = dme1737_read(data,
584 DME1737_REG_IN(ix)) << 8; 585 DME1737_REG_IN(ix)) << 8;
585 data->in_min[ix] = dme1737_read(client, 586 data->in_min[ix] = dme1737_read(data,
586 DME1737_REG_IN_MIN(ix)); 587 DME1737_REG_IN_MIN(ix));
587 data->in_max[ix] = dme1737_read(client, 588 data->in_max[ix] = dme1737_read(data,
588 DME1737_REG_IN_MAX(ix)); 589 DME1737_REG_IN_MAX(ix));
589 } 590 }
590 591
@@ -595,14 +596,14 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
595 * to take advantage of implicit conversions between 596 * to take advantage of implicit conversions between
596 * register values (2's complement) and temp values 597 * register values (2's complement) and temp values
597 * (signed decimal). */ 598 * (signed decimal). */
598 data->temp[ix] = dme1737_read(client, 599 data->temp[ix] = dme1737_read(data,
599 DME1737_REG_TEMP(ix)) << 8; 600 DME1737_REG_TEMP(ix)) << 8;
600 data->temp_min[ix] = dme1737_read(client, 601 data->temp_min[ix] = dme1737_read(data,
601 DME1737_REG_TEMP_MIN(ix)); 602 DME1737_REG_TEMP_MIN(ix));
602 data->temp_max[ix] = dme1737_read(client, 603 data->temp_max[ix] = dme1737_read(data,
603 DME1737_REG_TEMP_MAX(ix)); 604 DME1737_REG_TEMP_MAX(ix));
604 if (data->type != sch5027) { 605 if (data->type != sch5027) {
605 data->temp_offset[ix] = dme1737_read(client, 606 data->temp_offset[ix] = dme1737_read(data,
606 DME1737_REG_TEMP_OFFSET(ix)); 607 DME1737_REG_TEMP_OFFSET(ix));
607 } 608 }
608 } 609 }
@@ -612,7 +613,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
612 * which the registers are read (MSB first, then LSB) is 613 * which the registers are read (MSB first, then LSB) is
613 * important! */ 614 * important! */
614 for (ix = 0; ix < ARRAY_SIZE(lsb); ix++) { 615 for (ix = 0; ix < ARRAY_SIZE(lsb); ix++) {
615 lsb[ix] = dme1737_read(client, 616 lsb[ix] = dme1737_read(data,
616 DME1737_REG_IN_TEMP_LSB(ix)); 617 DME1737_REG_IN_TEMP_LSB(ix));
617 } 618 }
618 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) { 619 for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) {
@@ -631,19 +632,19 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
631 if (!(data->has_fan & (1 << ix))) { 632 if (!(data->has_fan & (1 << ix))) {
632 continue; 633 continue;
633 } 634 }
634 data->fan[ix] = dme1737_read(client, 635 data->fan[ix] = dme1737_read(data,
635 DME1737_REG_FAN(ix)); 636 DME1737_REG_FAN(ix));
636 data->fan[ix] |= dme1737_read(client, 637 data->fan[ix] |= dme1737_read(data,
637 DME1737_REG_FAN(ix) + 1) << 8; 638 DME1737_REG_FAN(ix) + 1) << 8;
638 data->fan_min[ix] = dme1737_read(client, 639 data->fan_min[ix] = dme1737_read(data,
639 DME1737_REG_FAN_MIN(ix)); 640 DME1737_REG_FAN_MIN(ix));
640 data->fan_min[ix] |= dme1737_read(client, 641 data->fan_min[ix] |= dme1737_read(data,
641 DME1737_REG_FAN_MIN(ix) + 1) << 8; 642 DME1737_REG_FAN_MIN(ix) + 1) << 8;
642 data->fan_opt[ix] = dme1737_read(client, 643 data->fan_opt[ix] = dme1737_read(data,
643 DME1737_REG_FAN_OPT(ix)); 644 DME1737_REG_FAN_OPT(ix));
644 /* fan_max exists only for fan[5-6] */ 645 /* fan_max exists only for fan[5-6] */
645 if (ix > 3) { 646 if (ix > 3) {
646 data->fan_max[ix - 4] = dme1737_read(client, 647 data->fan_max[ix - 4] = dme1737_read(data,
647 DME1737_REG_FAN_MAX(ix)); 648 DME1737_REG_FAN_MAX(ix));
648 } 649 }
649 } 650 }
@@ -655,63 +656,63 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
655 if (!(data->has_pwm & (1 << ix))) { 656 if (!(data->has_pwm & (1 << ix))) {
656 continue; 657 continue;
657 } 658 }
658 data->pwm[ix] = dme1737_read(client, 659 data->pwm[ix] = dme1737_read(data,
659 DME1737_REG_PWM(ix)); 660 DME1737_REG_PWM(ix));
660 data->pwm_freq[ix] = dme1737_read(client, 661 data->pwm_freq[ix] = dme1737_read(data,
661 DME1737_REG_PWM_FREQ(ix)); 662 DME1737_REG_PWM_FREQ(ix));
662 /* pwm_config and pwm_min exist only for pwm[1-3] */ 663 /* pwm_config and pwm_min exist only for pwm[1-3] */
663 if (ix < 3) { 664 if (ix < 3) {
664 data->pwm_config[ix] = dme1737_read(client, 665 data->pwm_config[ix] = dme1737_read(data,
665 DME1737_REG_PWM_CONFIG(ix)); 666 DME1737_REG_PWM_CONFIG(ix));
666 data->pwm_min[ix] = dme1737_read(client, 667 data->pwm_min[ix] = dme1737_read(data,
667 DME1737_REG_PWM_MIN(ix)); 668 DME1737_REG_PWM_MIN(ix));
668 } 669 }
669 } 670 }
670 for (ix = 0; ix < ARRAY_SIZE(data->pwm_rr); ix++) { 671 for (ix = 0; ix < ARRAY_SIZE(data->pwm_rr); ix++) {
671 data->pwm_rr[ix] = dme1737_read(client, 672 data->pwm_rr[ix] = dme1737_read(data,
672 DME1737_REG_PWM_RR(ix)); 673 DME1737_REG_PWM_RR(ix));
673 } 674 }
674 675
675 /* Thermal zone registers */ 676 /* Thermal zone registers */
676 for (ix = 0; ix < ARRAY_SIZE(data->zone_low); ix++) { 677 for (ix = 0; ix < ARRAY_SIZE(data->zone_low); ix++) {
677 data->zone_low[ix] = dme1737_read(client, 678 data->zone_low[ix] = dme1737_read(data,
678 DME1737_REG_ZONE_LOW(ix)); 679 DME1737_REG_ZONE_LOW(ix));
679 data->zone_abs[ix] = dme1737_read(client, 680 data->zone_abs[ix] = dme1737_read(data,
680 DME1737_REG_ZONE_ABS(ix)); 681 DME1737_REG_ZONE_ABS(ix));
681 } 682 }
682 if (data->type != sch5027) { 683 if (data->type != sch5027) {
683 for (ix = 0; ix < ARRAY_SIZE(data->zone_hyst); ix++) { 684 for (ix = 0; ix < ARRAY_SIZE(data->zone_hyst); ix++) {
684 data->zone_hyst[ix] = dme1737_read(client, 685 data->zone_hyst[ix] = dme1737_read(data,
685 DME1737_REG_ZONE_HYST(ix)); 686 DME1737_REG_ZONE_HYST(ix));
686 } 687 }
687 } 688 }
688 689
689 /* Alarm registers */ 690 /* Alarm registers */
690 data->alarms = dme1737_read(client, 691 data->alarms = dme1737_read(data,
691 DME1737_REG_ALARM1); 692 DME1737_REG_ALARM1);
692 /* Bit 7 tells us if the other alarm registers are non-zero and 693 /* Bit 7 tells us if the other alarm registers are non-zero and
693 * therefore also need to be read */ 694 * therefore also need to be read */
694 if (data->alarms & 0x80) { 695 if (data->alarms & 0x80) {
695 data->alarms |= dme1737_read(client, 696 data->alarms |= dme1737_read(data,
696 DME1737_REG_ALARM2) << 8; 697 DME1737_REG_ALARM2) << 8;
697 data->alarms |= dme1737_read(client, 698 data->alarms |= dme1737_read(data,
698 DME1737_REG_ALARM3) << 16; 699 DME1737_REG_ALARM3) << 16;
699 } 700 }
700 701
701 /* The ISA chips require explicit clearing of alarm bits. 702 /* The ISA chips require explicit clearing of alarm bits.
702 * Don't worry, an alarm will come back if the condition 703 * Don't worry, an alarm will come back if the condition
703 * that causes it still exists */ 704 * that causes it still exists */
704 if (!client->driver) { 705 if (!data->client) {
705 if (data->alarms & 0xff0000) { 706 if (data->alarms & 0xff0000) {
706 dme1737_write(client, DME1737_REG_ALARM3, 707 dme1737_write(data, DME1737_REG_ALARM3,
707 0xff); 708 0xff);
708 } 709 }
709 if (data->alarms & 0xff00) { 710 if (data->alarms & 0xff00) {
710 dme1737_write(client, DME1737_REG_ALARM2, 711 dme1737_write(data, DME1737_REG_ALARM2,
711 0xff); 712 0xff);
712 } 713 }
713 if (data->alarms & 0xff) { 714 if (data->alarms & 0xff) {
714 dme1737_write(client, DME1737_REG_ALARM1, 715 dme1737_write(data, DME1737_REG_ALARM1,
715 0xff); 716 0xff);
716 } 717 }
717 } 718 }
@@ -770,7 +771,6 @@ static ssize_t set_in(struct device *dev, struct device_attribute *attr,
770 const char *buf, size_t count) 771 const char *buf, size_t count)
771{ 772{
772 struct dme1737_data *data = dev_get_drvdata(dev); 773 struct dme1737_data *data = dev_get_drvdata(dev);
773 struct i2c_client *client = &data->client;
774 struct sensor_device_attribute_2 774 struct sensor_device_attribute_2
775 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 775 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
776 int ix = sensor_attr_2->index; 776 int ix = sensor_attr_2->index;
@@ -781,12 +781,12 @@ static ssize_t set_in(struct device *dev, struct device_attribute *attr,
781 switch (fn) { 781 switch (fn) {
782 case SYS_IN_MIN: 782 case SYS_IN_MIN:
783 data->in_min[ix] = IN_TO_REG(val, data->in_nominal[ix]); 783 data->in_min[ix] = IN_TO_REG(val, data->in_nominal[ix]);
784 dme1737_write(client, DME1737_REG_IN_MIN(ix), 784 dme1737_write(data, DME1737_REG_IN_MIN(ix),
785 data->in_min[ix]); 785 data->in_min[ix]);
786 break; 786 break;
787 case SYS_IN_MAX: 787 case SYS_IN_MAX:
788 data->in_max[ix] = IN_TO_REG(val, data->in_nominal[ix]); 788 data->in_max[ix] = IN_TO_REG(val, data->in_nominal[ix]);
789 dme1737_write(client, DME1737_REG_IN_MAX(ix), 789 dme1737_write(data, DME1737_REG_IN_MAX(ix),
790 data->in_max[ix]); 790 data->in_max[ix]);
791 break; 791 break;
792 default: 792 default:
@@ -850,7 +850,6 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
850 const char *buf, size_t count) 850 const char *buf, size_t count)
851{ 851{
852 struct dme1737_data *data = dev_get_drvdata(dev); 852 struct dme1737_data *data = dev_get_drvdata(dev);
853 struct i2c_client *client = &data->client;
854 struct sensor_device_attribute_2 853 struct sensor_device_attribute_2
855 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 854 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
856 int ix = sensor_attr_2->index; 855 int ix = sensor_attr_2->index;
@@ -861,17 +860,17 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
861 switch (fn) { 860 switch (fn) {
862 case SYS_TEMP_MIN: 861 case SYS_TEMP_MIN:
863 data->temp_min[ix] = TEMP_TO_REG(val); 862 data->temp_min[ix] = TEMP_TO_REG(val);
864 dme1737_write(client, DME1737_REG_TEMP_MIN(ix), 863 dme1737_write(data, DME1737_REG_TEMP_MIN(ix),
865 data->temp_min[ix]); 864 data->temp_min[ix]);
866 break; 865 break;
867 case SYS_TEMP_MAX: 866 case SYS_TEMP_MAX:
868 data->temp_max[ix] = TEMP_TO_REG(val); 867 data->temp_max[ix] = TEMP_TO_REG(val);
869 dme1737_write(client, DME1737_REG_TEMP_MAX(ix), 868 dme1737_write(data, DME1737_REG_TEMP_MAX(ix),
870 data->temp_max[ix]); 869 data->temp_max[ix]);
871 break; 870 break;
872 case SYS_TEMP_OFFSET: 871 case SYS_TEMP_OFFSET:
873 data->temp_offset[ix] = TEMP_TO_REG(val); 872 data->temp_offset[ix] = TEMP_TO_REG(val);
874 dme1737_write(client, DME1737_REG_TEMP_OFFSET(ix), 873 dme1737_write(data, DME1737_REG_TEMP_OFFSET(ix),
875 data->temp_offset[ix]); 874 data->temp_offset[ix]);
876 break; 875 break;
877 default: 876 default:
@@ -939,7 +938,6 @@ static ssize_t set_zone(struct device *dev, struct device_attribute *attr,
939 const char *buf, size_t count) 938 const char *buf, size_t count)
940{ 939{
941 struct dme1737_data *data = dev_get_drvdata(dev); 940 struct dme1737_data *data = dev_get_drvdata(dev);
942 struct i2c_client *client = &data->client;
943 struct sensor_device_attribute_2 941 struct sensor_device_attribute_2
944 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 942 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
945 int ix = sensor_attr_2->index; 943 int ix = sensor_attr_2->index;
@@ -950,37 +948,37 @@ static ssize_t set_zone(struct device *dev, struct device_attribute *attr,
950 switch (fn) { 948 switch (fn) {
951 case SYS_ZONE_AUTO_POINT1_TEMP_HYST: 949 case SYS_ZONE_AUTO_POINT1_TEMP_HYST:
952 /* Refresh the cache */ 950 /* Refresh the cache */
953 data->zone_low[ix] = dme1737_read(client, 951 data->zone_low[ix] = dme1737_read(data,
954 DME1737_REG_ZONE_LOW(ix)); 952 DME1737_REG_ZONE_LOW(ix));
955 /* Modify the temp hyst value */ 953 /* Modify the temp hyst value */
956 data->zone_hyst[ix == 2] = TEMP_HYST_TO_REG( 954 data->zone_hyst[ix == 2] = TEMP_HYST_TO_REG(
957 TEMP_FROM_REG(data->zone_low[ix], 8) - 955 TEMP_FROM_REG(data->zone_low[ix], 8) -
958 val, ix, dme1737_read(client, 956 val, ix, dme1737_read(data,
959 DME1737_REG_ZONE_HYST(ix == 2))); 957 DME1737_REG_ZONE_HYST(ix == 2)));
960 dme1737_write(client, DME1737_REG_ZONE_HYST(ix == 2), 958 dme1737_write(data, DME1737_REG_ZONE_HYST(ix == 2),
961 data->zone_hyst[ix == 2]); 959 data->zone_hyst[ix == 2]);
962 break; 960 break;
963 case SYS_ZONE_AUTO_POINT1_TEMP: 961 case SYS_ZONE_AUTO_POINT1_TEMP:
964 data->zone_low[ix] = TEMP_TO_REG(val); 962 data->zone_low[ix] = TEMP_TO_REG(val);
965 dme1737_write(client, DME1737_REG_ZONE_LOW(ix), 963 dme1737_write(data, DME1737_REG_ZONE_LOW(ix),
966 data->zone_low[ix]); 964 data->zone_low[ix]);
967 break; 965 break;
968 case SYS_ZONE_AUTO_POINT2_TEMP: 966 case SYS_ZONE_AUTO_POINT2_TEMP:
969 /* Refresh the cache */ 967 /* Refresh the cache */
970 data->zone_low[ix] = dme1737_read(client, 968 data->zone_low[ix] = dme1737_read(data,
971 DME1737_REG_ZONE_LOW(ix)); 969 DME1737_REG_ZONE_LOW(ix));
972 /* Modify the temp range value (which is stored in the upper 970 /* Modify the temp range value (which is stored in the upper
973 * nibble of the pwm_freq register) */ 971 * nibble of the pwm_freq register) */
974 data->pwm_freq[ix] = TEMP_RANGE_TO_REG(val - 972 data->pwm_freq[ix] = TEMP_RANGE_TO_REG(val -
975 TEMP_FROM_REG(data->zone_low[ix], 8), 973 TEMP_FROM_REG(data->zone_low[ix], 8),
976 dme1737_read(client, 974 dme1737_read(data,
977 DME1737_REG_PWM_FREQ(ix))); 975 DME1737_REG_PWM_FREQ(ix)));
978 dme1737_write(client, DME1737_REG_PWM_FREQ(ix), 976 dme1737_write(data, DME1737_REG_PWM_FREQ(ix),
979 data->pwm_freq[ix]); 977 data->pwm_freq[ix]);
980 break; 978 break;
981 case SYS_ZONE_AUTO_POINT3_TEMP: 979 case SYS_ZONE_AUTO_POINT3_TEMP:
982 data->zone_abs[ix] = TEMP_TO_REG(val); 980 data->zone_abs[ix] = TEMP_TO_REG(val);
983 dme1737_write(client, DME1737_REG_ZONE_ABS(ix), 981 dme1737_write(data, DME1737_REG_ZONE_ABS(ix),
984 data->zone_abs[ix]); 982 data->zone_abs[ix]);
985 break; 983 break;
986 default: 984 default:
@@ -1046,7 +1044,6 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
1046 const char *buf, size_t count) 1044 const char *buf, size_t count)
1047{ 1045{
1048 struct dme1737_data *data = dev_get_drvdata(dev); 1046 struct dme1737_data *data = dev_get_drvdata(dev);
1049 struct i2c_client *client = &data->client;
1050 struct sensor_device_attribute_2 1047 struct sensor_device_attribute_2
1051 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 1048 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
1052 int ix = sensor_attr_2->index; 1049 int ix = sensor_attr_2->index;
@@ -1060,21 +1057,21 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
1060 data->fan_min[ix] = FAN_TO_REG(val, 0); 1057 data->fan_min[ix] = FAN_TO_REG(val, 0);
1061 } else { 1058 } else {
1062 /* Refresh the cache */ 1059 /* Refresh the cache */
1063 data->fan_opt[ix] = dme1737_read(client, 1060 data->fan_opt[ix] = dme1737_read(data,
1064 DME1737_REG_FAN_OPT(ix)); 1061 DME1737_REG_FAN_OPT(ix));
1065 /* Modify the fan min value */ 1062 /* Modify the fan min value */
1066 data->fan_min[ix] = FAN_TO_REG(val, 1063 data->fan_min[ix] = FAN_TO_REG(val,
1067 FAN_TPC_FROM_REG(data->fan_opt[ix])); 1064 FAN_TPC_FROM_REG(data->fan_opt[ix]));
1068 } 1065 }
1069 dme1737_write(client, DME1737_REG_FAN_MIN(ix), 1066 dme1737_write(data, DME1737_REG_FAN_MIN(ix),
1070 data->fan_min[ix] & 0xff); 1067 data->fan_min[ix] & 0xff);
1071 dme1737_write(client, DME1737_REG_FAN_MIN(ix) + 1, 1068 dme1737_write(data, DME1737_REG_FAN_MIN(ix) + 1,
1072 data->fan_min[ix] >> 8); 1069 data->fan_min[ix] >> 8);
1073 break; 1070 break;
1074 case SYS_FAN_MAX: 1071 case SYS_FAN_MAX:
1075 /* Only valid for fan[5-6] */ 1072 /* Only valid for fan[5-6] */
1076 data->fan_max[ix - 4] = FAN_MAX_TO_REG(val); 1073 data->fan_max[ix - 4] = FAN_MAX_TO_REG(val);
1077 dme1737_write(client, DME1737_REG_FAN_MAX(ix), 1074 dme1737_write(data, DME1737_REG_FAN_MAX(ix),
1078 data->fan_max[ix - 4]); 1075 data->fan_max[ix - 4]);
1079 break; 1076 break;
1080 case SYS_FAN_TYPE: 1077 case SYS_FAN_TYPE:
@@ -1086,9 +1083,9 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
1086 val); 1083 val);
1087 goto exit; 1084 goto exit;
1088 } 1085 }
1089 data->fan_opt[ix] = FAN_TYPE_TO_REG(val, dme1737_read(client, 1086 data->fan_opt[ix] = FAN_TYPE_TO_REG(val, dme1737_read(data,
1090 DME1737_REG_FAN_OPT(ix))); 1087 DME1737_REG_FAN_OPT(ix)));
1091 dme1737_write(client, DME1737_REG_FAN_OPT(ix), 1088 dme1737_write(data, DME1737_REG_FAN_OPT(ix),
1092 data->fan_opt[ix]); 1089 data->fan_opt[ix]);
1093 break; 1090 break;
1094 default: 1091 default:
@@ -1185,7 +1182,6 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1185 const char *buf, size_t count) 1182 const char *buf, size_t count)
1186{ 1183{
1187 struct dme1737_data *data = dev_get_drvdata(dev); 1184 struct dme1737_data *data = dev_get_drvdata(dev);
1188 struct i2c_client *client = &data->client;
1189 struct sensor_device_attribute_2 1185 struct sensor_device_attribute_2
1190 *sensor_attr_2 = to_sensor_dev_attr_2(attr); 1186 *sensor_attr_2 = to_sensor_dev_attr_2(attr);
1191 int ix = sensor_attr_2->index; 1187 int ix = sensor_attr_2->index;
@@ -1196,12 +1192,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1196 switch (fn) { 1192 switch (fn) {
1197 case SYS_PWM: 1193 case SYS_PWM:
1198 data->pwm[ix] = SENSORS_LIMIT(val, 0, 255); 1194 data->pwm[ix] = SENSORS_LIMIT(val, 0, 255);
1199 dme1737_write(client, DME1737_REG_PWM(ix), data->pwm[ix]); 1195 dme1737_write(data, DME1737_REG_PWM(ix), data->pwm[ix]);
1200 break; 1196 break;
1201 case SYS_PWM_FREQ: 1197 case SYS_PWM_FREQ:
1202 data->pwm_freq[ix] = PWM_FREQ_TO_REG(val, dme1737_read(client, 1198 data->pwm_freq[ix] = PWM_FREQ_TO_REG(val, dme1737_read(data,
1203 DME1737_REG_PWM_FREQ(ix))); 1199 DME1737_REG_PWM_FREQ(ix)));
1204 dme1737_write(client, DME1737_REG_PWM_FREQ(ix), 1200 dme1737_write(data, DME1737_REG_PWM_FREQ(ix),
1205 data->pwm_freq[ix]); 1201 data->pwm_freq[ix]);
1206 break; 1202 break;
1207 case SYS_PWM_ENABLE: 1203 case SYS_PWM_ENABLE:
@@ -1214,7 +1210,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1214 goto exit; 1210 goto exit;
1215 } 1211 }
1216 /* Refresh the cache */ 1212 /* Refresh the cache */
1217 data->pwm_config[ix] = dme1737_read(client, 1213 data->pwm_config[ix] = dme1737_read(data,
1218 DME1737_REG_PWM_CONFIG(ix)); 1214 DME1737_REG_PWM_CONFIG(ix));
1219 if (val == PWM_EN_FROM_REG(data->pwm_config[ix])) { 1215 if (val == PWM_EN_FROM_REG(data->pwm_config[ix])) {
1220 /* Bail out if no change */ 1216 /* Bail out if no change */
@@ -1226,14 +1222,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1226 data->pwm_acz[ix] = PWM_ACZ_FROM_REG( 1222 data->pwm_acz[ix] = PWM_ACZ_FROM_REG(
1227 data->pwm_config[ix]); 1223 data->pwm_config[ix]);
1228 /* Save the current ramp rate state and disable it */ 1224 /* Save the current ramp rate state and disable it */
1229 data->pwm_rr[ix > 0] = dme1737_read(client, 1225 data->pwm_rr[ix > 0] = dme1737_read(data,
1230 DME1737_REG_PWM_RR(ix > 0)); 1226 DME1737_REG_PWM_RR(ix > 0));
1231 data->pwm_rr_en &= ~(1 << ix); 1227 data->pwm_rr_en &= ~(1 << ix);
1232 if (PWM_RR_EN_FROM_REG(data->pwm_rr[ix > 0], ix)) { 1228 if (PWM_RR_EN_FROM_REG(data->pwm_rr[ix > 0], ix)) {
1233 data->pwm_rr_en |= (1 << ix); 1229 data->pwm_rr_en |= (1 << ix);
1234 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(0, ix, 1230 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(0, ix,
1235 data->pwm_rr[ix > 0]); 1231 data->pwm_rr[ix > 0]);
1236 dme1737_write(client, 1232 dme1737_write(data,
1237 DME1737_REG_PWM_RR(ix > 0), 1233 DME1737_REG_PWM_RR(ix > 0),
1238 data->pwm_rr[ix > 0]); 1234 data->pwm_rr[ix > 0]);
1239 } 1235 }
@@ -1247,14 +1243,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1247 /* Turn fan fully on */ 1243 /* Turn fan fully on */
1248 data->pwm_config[ix] = PWM_EN_TO_REG(0, 1244 data->pwm_config[ix] = PWM_EN_TO_REG(0,
1249 data->pwm_config[ix]); 1245 data->pwm_config[ix]);
1250 dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), 1246 dme1737_write(data, DME1737_REG_PWM_CONFIG(ix),
1251 data->pwm_config[ix]); 1247 data->pwm_config[ix]);
1252 break; 1248 break;
1253 case 1: 1249 case 1:
1254 /* Turn on manual mode */ 1250 /* Turn on manual mode */
1255 data->pwm_config[ix] = PWM_EN_TO_REG(1, 1251 data->pwm_config[ix] = PWM_EN_TO_REG(1,
1256 data->pwm_config[ix]); 1252 data->pwm_config[ix]);
1257 dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), 1253 dme1737_write(data, DME1737_REG_PWM_CONFIG(ix),
1258 data->pwm_config[ix]); 1254 data->pwm_config[ix]);
1259 /* Change permissions of pwm[ix] to read-writeable */ 1255 /* Change permissions of pwm[ix] to read-writeable */
1260 dme1737_chmod_file(dev, dme1737_pwm_chmod_attr[ix], 1256 dme1737_chmod_file(dev, dme1737_pwm_chmod_attr[ix],
@@ -1269,14 +1265,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1269 data->pwm_config[ix] = PWM_ACZ_TO_REG( 1265 data->pwm_config[ix] = PWM_ACZ_TO_REG(
1270 data->pwm_acz[ix], 1266 data->pwm_acz[ix],
1271 data->pwm_config[ix]); 1267 data->pwm_config[ix]);
1272 dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), 1268 dme1737_write(data, DME1737_REG_PWM_CONFIG(ix),
1273 data->pwm_config[ix]); 1269 data->pwm_config[ix]);
1274 /* Enable PWM ramp rate if previously enabled */ 1270 /* Enable PWM ramp rate if previously enabled */
1275 if (data->pwm_rr_en & (1 << ix)) { 1271 if (data->pwm_rr_en & (1 << ix)) {
1276 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(1, ix, 1272 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(1, ix,
1277 dme1737_read(client, 1273 dme1737_read(data,
1278 DME1737_REG_PWM_RR(ix > 0))); 1274 DME1737_REG_PWM_RR(ix > 0)));
1279 dme1737_write(client, 1275 dme1737_write(data,
1280 DME1737_REG_PWM_RR(ix > 0), 1276 DME1737_REG_PWM_RR(ix > 0),
1281 data->pwm_rr[ix > 0]); 1277 data->pwm_rr[ix > 0]);
1282 } 1278 }
@@ -1286,9 +1282,9 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1286 case SYS_PWM_RAMP_RATE: 1282 case SYS_PWM_RAMP_RATE:
1287 /* Only valid for pwm[1-3] */ 1283 /* Only valid for pwm[1-3] */
1288 /* Refresh the cache */ 1284 /* Refresh the cache */
1289 data->pwm_config[ix] = dme1737_read(client, 1285 data->pwm_config[ix] = dme1737_read(data,
1290 DME1737_REG_PWM_CONFIG(ix)); 1286 DME1737_REG_PWM_CONFIG(ix));
1291 data->pwm_rr[ix > 0] = dme1737_read(client, 1287 data->pwm_rr[ix > 0] = dme1737_read(data,
1292 DME1737_REG_PWM_RR(ix > 0)); 1288 DME1737_REG_PWM_RR(ix > 0));
1293 /* Set the ramp rate value */ 1289 /* Set the ramp rate value */
1294 if (val > 0) { 1290 if (val > 0) {
@@ -1301,7 +1297,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1301 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(val > 0, ix, 1297 data->pwm_rr[ix > 0] = PWM_RR_EN_TO_REG(val > 0, ix,
1302 data->pwm_rr[ix > 0]); 1298 data->pwm_rr[ix > 0]);
1303 } 1299 }
1304 dme1737_write(client, DME1737_REG_PWM_RR(ix > 0), 1300 dme1737_write(data, DME1737_REG_PWM_RR(ix > 0),
1305 data->pwm_rr[ix > 0]); 1301 data->pwm_rr[ix > 0]);
1306 break; 1302 break;
1307 case SYS_PWM_AUTO_CHANNELS_ZONE: 1303 case SYS_PWM_AUTO_CHANNELS_ZONE:
@@ -1315,14 +1311,14 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1315 goto exit; 1311 goto exit;
1316 } 1312 }
1317 /* Refresh the cache */ 1313 /* Refresh the cache */
1318 data->pwm_config[ix] = dme1737_read(client, 1314 data->pwm_config[ix] = dme1737_read(data,
1319 DME1737_REG_PWM_CONFIG(ix)); 1315 DME1737_REG_PWM_CONFIG(ix));
1320 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) { 1316 if (PWM_EN_FROM_REG(data->pwm_config[ix]) == 2) {
1321 /* PWM is already in auto mode so update the temp 1317 /* PWM is already in auto mode so update the temp
1322 * channel assignment */ 1318 * channel assignment */
1323 data->pwm_config[ix] = PWM_ACZ_TO_REG(val, 1319 data->pwm_config[ix] = PWM_ACZ_TO_REG(val,
1324 data->pwm_config[ix]); 1320 data->pwm_config[ix]);
1325 dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), 1321 dme1737_write(data, DME1737_REG_PWM_CONFIG(ix),
1326 data->pwm_config[ix]); 1322 data->pwm_config[ix]);
1327 } else { 1323 } else {
1328 /* PWM is not in auto mode so we save the temp 1324 /* PWM is not in auto mode so we save the temp
@@ -1333,7 +1329,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1333 case SYS_PWM_AUTO_PWM_MIN: 1329 case SYS_PWM_AUTO_PWM_MIN:
1334 /* Only valid for pwm[1-3] */ 1330 /* Only valid for pwm[1-3] */
1335 /* Refresh the cache */ 1331 /* Refresh the cache */
1336 data->pwm_min[ix] = dme1737_read(client, 1332 data->pwm_min[ix] = dme1737_read(data,
1337 DME1737_REG_PWM_MIN(ix)); 1333 DME1737_REG_PWM_MIN(ix));
1338 /* There are only 2 values supported for the auto_pwm_min 1334 /* There are only 2 values supported for the auto_pwm_min
1339 * value: 0 or auto_point1_pwm. So if the temperature drops 1335 * value: 0 or auto_point1_pwm. So if the temperature drops
@@ -1341,20 +1337,20 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1341 * off or runs at auto_point1_pwm duty-cycle. */ 1337 * off or runs at auto_point1_pwm duty-cycle. */
1342 if (val > ((data->pwm_min[ix] + 1) / 2)) { 1338 if (val > ((data->pwm_min[ix] + 1) / 2)) {
1343 data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix, 1339 data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix,
1344 dme1737_read(client, 1340 dme1737_read(data,
1345 DME1737_REG_PWM_RR(0))); 1341 DME1737_REG_PWM_RR(0)));
1346 } else { 1342 } else {
1347 data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix, 1343 data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix,
1348 dme1737_read(client, 1344 dme1737_read(data,
1349 DME1737_REG_PWM_RR(0))); 1345 DME1737_REG_PWM_RR(0)));
1350 } 1346 }
1351 dme1737_write(client, DME1737_REG_PWM_RR(0), 1347 dme1737_write(data, DME1737_REG_PWM_RR(0),
1352 data->pwm_rr[0]); 1348 data->pwm_rr[0]);
1353 break; 1349 break;
1354 case SYS_PWM_AUTO_POINT1_PWM: 1350 case SYS_PWM_AUTO_POINT1_PWM:
1355 /* Only valid for pwm[1-3] */ 1351 /* Only valid for pwm[1-3] */
1356 data->pwm_min[ix] = SENSORS_LIMIT(val, 0, 255); 1352 data->pwm_min[ix] = SENSORS_LIMIT(val, 0, 255);
1357 dme1737_write(client, DME1737_REG_PWM_MIN(ix), 1353 dme1737_write(data, DME1737_REG_PWM_MIN(ix),
1358 data->pwm_min[ix]); 1354 data->pwm_min[ix]);
1359 break; 1355 break;
1360 default: 1356 default:
@@ -1402,7 +1398,7 @@ static ssize_t show_name(struct device *dev, struct device_attribute *attr,
1402{ 1398{
1403 struct dme1737_data *data = dev_get_drvdata(dev); 1399 struct dme1737_data *data = dev_get_drvdata(dev);
1404 1400
1405 return sprintf(buf, "%s\n", data->client.name); 1401 return sprintf(buf, "%s\n", data->name);
1406} 1402}
1407 1403
1408/* --------------------------------------------------------------------- 1404/* ---------------------------------------------------------------------
@@ -1908,7 +1904,7 @@ static void dme1737_remove_files(struct device *dev)
1908 1904
1909 sysfs_remove_group(&dev->kobj, &dme1737_group); 1905 sysfs_remove_group(&dev->kobj, &dme1737_group);
1910 1906
1911 if (!data->client.driver) { 1907 if (!data->client) {
1912 sysfs_remove_file(&dev->kobj, &dev_attr_name.attr); 1908 sysfs_remove_file(&dev->kobj, &dev_attr_name.attr);
1913 } 1909 }
1914} 1910}
@@ -1919,7 +1915,7 @@ static int dme1737_create_files(struct device *dev)
1919 int err, ix; 1915 int err, ix;
1920 1916
1921 /* Create a name attribute for ISA devices */ 1917 /* Create a name attribute for ISA devices */
1922 if (!data->client.driver && 1918 if (!data->client &&
1923 (err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr))) { 1919 (err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr))) {
1924 goto exit; 1920 goto exit;
1925 } 1921 }
@@ -2013,14 +2009,14 @@ exit:
2013static int dme1737_init_device(struct device *dev) 2009static int dme1737_init_device(struct device *dev)
2014{ 2010{
2015 struct dme1737_data *data = dev_get_drvdata(dev); 2011 struct dme1737_data *data = dev_get_drvdata(dev);
2016 struct i2c_client *client = &data->client; 2012 struct i2c_client *client = data->client;
2017 int ix; 2013 int ix;
2018 u8 reg; 2014 u8 reg;
2019 2015
2020 /* Point to the right nominal voltages array */ 2016 /* Point to the right nominal voltages array */
2021 data->in_nominal = IN_NOMINAL(data->type); 2017 data->in_nominal = IN_NOMINAL(data->type);
2022 2018
2023 data->config = dme1737_read(client, DME1737_REG_CONFIG); 2019 data->config = dme1737_read(data, DME1737_REG_CONFIG);
2024 /* Inform if part is not monitoring/started */ 2020 /* Inform if part is not monitoring/started */
2025 if (!(data->config & 0x01)) { 2021 if (!(data->config & 0x01)) {
2026 if (!force_start) { 2022 if (!force_start) {
@@ -2032,7 +2028,7 @@ static int dme1737_init_device(struct device *dev)
2032 2028
2033 /* Force monitoring */ 2029 /* Force monitoring */
2034 data->config |= 0x01; 2030 data->config |= 0x01;
2035 dme1737_write(client, DME1737_REG_CONFIG, data->config); 2031 dme1737_write(data, DME1737_REG_CONFIG, data->config);
2036 } 2032 }
2037 /* Inform if part is not ready */ 2033 /* Inform if part is not ready */
2038 if (!(data->config & 0x04)) { 2034 if (!(data->config & 0x04)) {
@@ -2041,8 +2037,8 @@ static int dme1737_init_device(struct device *dev)
2041 } 2037 }
2042 2038
2043 /* Determine which optional fan and pwm features are enabled/present */ 2039 /* Determine which optional fan and pwm features are enabled/present */
2044 if (client->driver) { /* I2C chip */ 2040 if (client) { /* I2C chip */
2045 data->config2 = dme1737_read(client, DME1737_REG_CONFIG2); 2041 data->config2 = dme1737_read(data, DME1737_REG_CONFIG2);
2046 /* Check if optional fan3 input is enabled */ 2042 /* Check if optional fan3 input is enabled */
2047 if (data->config2 & 0x04) { 2043 if (data->config2 & 0x04) {
2048 data->has_fan |= (1 << 2); 2044 data->has_fan |= (1 << 2);
@@ -2051,7 +2047,7 @@ static int dme1737_init_device(struct device *dev)
2051 /* Fan4 and pwm3 are only available if the client's I2C address 2047 /* Fan4 and pwm3 are only available if the client's I2C address
2052 * is the default 0x2e. Otherwise the I/Os associated with 2048 * is the default 0x2e. Otherwise the I/Os associated with
2053 * these functions are used for addr enable/select. */ 2049 * these functions are used for addr enable/select. */
2054 if (data->client.addr == 0x2e) { 2050 if (client->addr == 0x2e) {
2055 data->has_fan |= (1 << 3); 2051 data->has_fan |= (1 << 3);
2056 data->has_pwm |= (1 << 2); 2052 data->has_pwm |= (1 << 2);
2057 } 2053 }
@@ -2086,16 +2082,16 @@ static int dme1737_init_device(struct device *dev)
2086 (data->has_fan & (1 << 4)) ? "yes" : "no", 2082 (data->has_fan & (1 << 4)) ? "yes" : "no",
2087 (data->has_fan & (1 << 5)) ? "yes" : "no"); 2083 (data->has_fan & (1 << 5)) ? "yes" : "no");
2088 2084
2089 reg = dme1737_read(client, DME1737_REG_TACH_PWM); 2085 reg = dme1737_read(data, DME1737_REG_TACH_PWM);
2090 /* Inform if fan-to-pwm mapping differs from the default */ 2086 /* Inform if fan-to-pwm mapping differs from the default */
2091 if (client->driver && reg != 0xa4) { /* I2C chip */ 2087 if (client && reg != 0xa4) { /* I2C chip */
2092 dev_warn(dev, "Non-standard fan to pwm mapping: " 2088 dev_warn(dev, "Non-standard fan to pwm mapping: "
2093 "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, " 2089 "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, "
2094 "fan4->pwm%d. Please report to the driver " 2090 "fan4->pwm%d. Please report to the driver "
2095 "maintainer.\n", 2091 "maintainer.\n",
2096 (reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1, 2092 (reg & 0x03) + 1, ((reg >> 2) & 0x03) + 1,
2097 ((reg >> 4) & 0x03) + 1, ((reg >> 6) & 0x03) + 1); 2093 ((reg >> 4) & 0x03) + 1, ((reg >> 6) & 0x03) + 1);
2098 } else if (!client->driver && reg != 0x24) { /* ISA chip */ 2094 } else if (!client && reg != 0x24) { /* ISA chip */
2099 dev_warn(dev, "Non-standard fan to pwm mapping: " 2095 dev_warn(dev, "Non-standard fan to pwm mapping: "
2100 "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d. " 2096 "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d. "
2101 "Please report to the driver maintainer.\n", 2097 "Please report to the driver maintainer.\n",
@@ -2108,7 +2104,7 @@ static int dme1737_init_device(struct device *dev)
2108 * disabled). */ 2104 * disabled). */
2109 if (!(data->config & 0x02)) { 2105 if (!(data->config & 0x02)) {
2110 for (ix = 0; ix < 3; ix++) { 2106 for (ix = 0; ix < 3; ix++) {
2111 data->pwm_config[ix] = dme1737_read(client, 2107 data->pwm_config[ix] = dme1737_read(data,
2112 DME1737_REG_PWM_CONFIG(ix)); 2108 DME1737_REG_PWM_CONFIG(ix));
2113 if ((data->has_pwm & (1 << ix)) && 2109 if ((data->has_pwm & (1 << ix)) &&
2114 (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) { 2110 (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) {
@@ -2116,8 +2112,8 @@ static int dme1737_init_device(struct device *dev)
2116 "manual mode.\n", ix + 1); 2112 "manual mode.\n", ix + 1);
2117 data->pwm_config[ix] = PWM_EN_TO_REG(1, 2113 data->pwm_config[ix] = PWM_EN_TO_REG(1,
2118 data->pwm_config[ix]); 2114 data->pwm_config[ix]);
2119 dme1737_write(client, DME1737_REG_PWM(ix), 0); 2115 dme1737_write(data, DME1737_REG_PWM(ix), 0);
2120 dme1737_write(client, 2116 dme1737_write(data,
2121 DME1737_REG_PWM_CONFIG(ix), 2117 DME1737_REG_PWM_CONFIG(ix),
2122 data->pwm_config[ix]); 2118 data->pwm_config[ix]);
2123 } 2119 }
@@ -2191,37 +2187,24 @@ exit:
2191 return err; 2187 return err;
2192} 2188}
2193 2189
2194static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address, 2190/* Return 0 if detection is successful, -ENODEV otherwise */
2195 int kind) 2191static int dme1737_i2c_detect(struct i2c_client *client, int kind,
2192 struct i2c_board_info *info)
2196{ 2193{
2194 struct i2c_adapter *adapter = client->adapter;
2195 struct device *dev = &adapter->dev;
2197 u8 company, verstep = 0; 2196 u8 company, verstep = 0;
2198 struct i2c_client *client;
2199 struct dme1737_data *data;
2200 struct device *dev;
2201 int err = 0;
2202 const char *name; 2197 const char *name;
2203 2198
2204 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 2199 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
2205 goto exit; 2200 return -ENODEV;
2206 }
2207
2208 if (!(data = kzalloc(sizeof(struct dme1737_data), GFP_KERNEL))) {
2209 err = -ENOMEM;
2210 goto exit;
2211 } 2201 }
2212 2202
2213 client = &data->client;
2214 i2c_set_clientdata(client, data);
2215 client->addr = address;
2216 client->adapter = adapter;
2217 client->driver = &dme1737_i2c_driver;
2218 dev = &client->dev;
2219
2220 /* A negative kind means that the driver was loaded with no force 2203 /* A negative kind means that the driver was loaded with no force
2221 * parameter (default), so we must identify the chip. */ 2204 * parameter (default), so we must identify the chip. */
2222 if (kind < 0) { 2205 if (kind < 0) {
2223 company = dme1737_read(client, DME1737_REG_COMPANY); 2206 company = i2c_smbus_read_byte_data(client, DME1737_REG_COMPANY);
2224 verstep = dme1737_read(client, DME1737_REG_VERSTEP); 2207 verstep = i2c_smbus_read_byte_data(client, DME1737_REG_VERSTEP);
2225 2208
2226 if (company == DME1737_COMPANY_SMSC && 2209 if (company == DME1737_COMPANY_SMSC &&
2227 (verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP) { 2210 (verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP) {
@@ -2230,8 +2213,7 @@ static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address,
2230 verstep == SCH5027_VERSTEP) { 2213 verstep == SCH5027_VERSTEP) {
2231 kind = sch5027; 2214 kind = sch5027;
2232 } else { 2215 } else {
2233 err = -ENODEV; 2216 return -ENODEV;
2234 goto exit_kfree;
2235 } 2217 }
2236 } 2218 }
2237 2219
@@ -2241,32 +2223,44 @@ static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address,
2241 kind = dme1737; 2223 kind = dme1737;
2242 name = "dme1737"; 2224 name = "dme1737";
2243 } 2225 }
2244 data->type = kind;
2245
2246 /* Fill in the remaining client fields and put it into the global
2247 * list */
2248 strlcpy(client->name, name, I2C_NAME_SIZE);
2249 mutex_init(&data->update_lock);
2250
2251 /* Tell the I2C layer a new client has arrived */
2252 if ((err = i2c_attach_client(client))) {
2253 goto exit_kfree;
2254 }
2255 2226
2256 dev_info(dev, "Found a %s chip at 0x%02x (rev 0x%02x).\n", 2227 dev_info(dev, "Found a %s chip at 0x%02x (rev 0x%02x).\n",
2257 kind == sch5027 ? "SCH5027" : "DME1737", client->addr, 2228 kind == sch5027 ? "SCH5027" : "DME1737", client->addr,
2258 verstep); 2229 verstep);
2230 strlcpy(info->type, name, I2C_NAME_SIZE);
2231
2232 return 0;
2233}
2234
2235static int dme1737_i2c_probe(struct i2c_client *client,
2236 const struct i2c_device_id *id)
2237{
2238 struct dme1737_data *data;
2239 struct device *dev = &client->dev;
2240 int err;
2241
2242 data = kzalloc(sizeof(struct dme1737_data), GFP_KERNEL);
2243 if (!data) {
2244 err = -ENOMEM;
2245 goto exit;
2246 }
2247
2248 i2c_set_clientdata(client, data);
2249 data->type = id->driver_data;
2250 data->client = client;
2251 data->name = client->name;
2252 mutex_init(&data->update_lock);
2259 2253
2260 /* Initialize the DME1737 chip */ 2254 /* Initialize the DME1737 chip */
2261 if ((err = dme1737_init_device(dev))) { 2255 if ((err = dme1737_init_device(dev))) {
2262 dev_err(dev, "Failed to initialize device.\n"); 2256 dev_err(dev, "Failed to initialize device.\n");
2263 goto exit_detach; 2257 goto exit_kfree;
2264 } 2258 }
2265 2259
2266 /* Create sysfs files */ 2260 /* Create sysfs files */
2267 if ((err = dme1737_create_files(dev))) { 2261 if ((err = dme1737_create_files(dev))) {
2268 dev_err(dev, "Failed to create sysfs files.\n"); 2262 dev_err(dev, "Failed to create sysfs files.\n");
2269 goto exit_detach; 2263 goto exit_kfree;
2270 } 2264 }
2271 2265
2272 /* Register device */ 2266 /* Register device */
@@ -2281,45 +2275,40 @@ static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address,
2281 2275
2282exit_remove: 2276exit_remove:
2283 dme1737_remove_files(dev); 2277 dme1737_remove_files(dev);
2284exit_detach:
2285 i2c_detach_client(client);
2286exit_kfree: 2278exit_kfree:
2287 kfree(data); 2279 kfree(data);
2288exit: 2280exit:
2289 return err; 2281 return err;
2290} 2282}
2291 2283
2292static int dme1737_i2c_attach_adapter(struct i2c_adapter *adapter) 2284static int dme1737_i2c_remove(struct i2c_client *client)
2293{
2294 if (!(adapter->class & I2C_CLASS_HWMON)) {
2295 return 0;
2296 }
2297
2298 return i2c_probe(adapter, &addr_data, dme1737_i2c_detect);
2299}
2300
2301static int dme1737_i2c_detach_client(struct i2c_client *client)
2302{ 2285{
2303 struct dme1737_data *data = i2c_get_clientdata(client); 2286 struct dme1737_data *data = i2c_get_clientdata(client);
2304 int err;
2305 2287
2306 hwmon_device_unregister(data->hwmon_dev); 2288 hwmon_device_unregister(data->hwmon_dev);
2307 dme1737_remove_files(&client->dev); 2289 dme1737_remove_files(&client->dev);
2308 2290
2309 if ((err = i2c_detach_client(client))) {
2310 return err;
2311 }
2312
2313 kfree(data); 2291 kfree(data);
2314 return 0; 2292 return 0;
2315} 2293}
2316 2294
2295static const struct i2c_device_id dme1737_id[] = {
2296 { "dme1737", dme1737 },
2297 { "sch5027", sch5027 },
2298 { }
2299};
2300MODULE_DEVICE_TABLE(i2c, dme1737_id);
2301
2317static struct i2c_driver dme1737_i2c_driver = { 2302static struct i2c_driver dme1737_i2c_driver = {
2303 .class = I2C_CLASS_HWMON,
2318 .driver = { 2304 .driver = {
2319 .name = "dme1737", 2305 .name = "dme1737",
2320 }, 2306 },
2321 .attach_adapter = dme1737_i2c_attach_adapter, 2307 .probe = dme1737_i2c_probe,
2322 .detach_client = dme1737_i2c_detach_client, 2308 .remove = dme1737_i2c_remove,
2309 .id_table = dme1737_id,
2310 .detect = dme1737_i2c_detect,
2311 .address_data = &addr_data,
2323}; 2312};
2324 2313
2325/* --------------------------------------------------------------------- 2314/* ---------------------------------------------------------------------
@@ -2403,7 +2392,6 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
2403{ 2392{
2404 u8 company, device; 2393 u8 company, device;
2405 struct resource *res; 2394 struct resource *res;
2406 struct i2c_client *client;
2407 struct dme1737_data *data; 2395 struct dme1737_data *data;
2408 struct device *dev = &pdev->dev; 2396 struct device *dev = &pdev->dev;
2409 int err; 2397 int err;
@@ -2422,15 +2410,13 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
2422 goto exit_release_region; 2410 goto exit_release_region;
2423 } 2411 }
2424 2412
2425 client = &data->client; 2413 data->addr = res->start;
2426 i2c_set_clientdata(client, data);
2427 client->addr = res->start;
2428 platform_set_drvdata(pdev, data); 2414 platform_set_drvdata(pdev, data);
2429 2415
2430 /* Skip chip detection if module is loaded with force_id parameter */ 2416 /* Skip chip detection if module is loaded with force_id parameter */
2431 if (!force_id) { 2417 if (!force_id) {
2432 company = dme1737_read(client, DME1737_REG_COMPANY); 2418 company = dme1737_read(data, DME1737_REG_COMPANY);
2433 device = dme1737_read(client, DME1737_REG_DEVICE); 2419 device = dme1737_read(data, DME1737_REG_DEVICE);
2434 2420
2435 if (!((company == DME1737_COMPANY_SMSC) && 2421 if (!((company == DME1737_COMPANY_SMSC) &&
2436 (device == SCH311X_DEVICE))) { 2422 (device == SCH311X_DEVICE))) {
@@ -2441,10 +2427,10 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
2441 data->type = sch311x; 2427 data->type = sch311x;
2442 2428
2443 /* Fill in the remaining client fields and initialize the mutex */ 2429 /* Fill in the remaining client fields and initialize the mutex */
2444 strlcpy(client->name, "sch311x", I2C_NAME_SIZE); 2430 data->name = "sch311x";
2445 mutex_init(&data->update_lock); 2431 mutex_init(&data->update_lock);
2446 2432
2447 dev_info(dev, "Found a SCH311x chip at 0x%04x\n", client->addr); 2433 dev_info(dev, "Found a SCH311x chip at 0x%04x\n", data->addr);
2448 2434
2449 /* Initialize the chip */ 2435 /* Initialize the chip */
2450 if ((err = dme1737_init_device(dev))) { 2436 if ((err = dme1737_init_device(dev))) {
@@ -2485,7 +2471,7 @@ static int __devexit dme1737_isa_remove(struct platform_device *pdev)
2485 2471
2486 hwmon_device_unregister(data->hwmon_dev); 2472 hwmon_device_unregister(data->hwmon_dev);
2487 dme1737_remove_files(&pdev->dev); 2473 dme1737_remove_files(&pdev->dev);
2488 release_region(data->client.addr, DME1737_EXTENT); 2474 release_region(data->addr, DME1737_EXTENT);
2489 platform_set_drvdata(pdev, NULL); 2475 platform_set_drvdata(pdev, NULL);
2490 kfree(data); 2476 kfree(data);
2491 2477
diff --git a/drivers/hwmon/hwmon.c b/drivers/hwmon/hwmon.c
index 7321a88a5112..076a59cdabe9 100644
--- a/drivers/hwmon/hwmon.c
+++ b/drivers/hwmon/hwmon.c
@@ -55,8 +55,8 @@ again:
55 return ERR_PTR(err); 55 return ERR_PTR(err);
56 56
57 id = id & MAX_ID_MASK; 57 id = id & MAX_ID_MASK;
58 hwdev = device_create_drvdata(hwmon_class, dev, MKDEV(0, 0), NULL, 58 hwdev = device_create(hwmon_class, dev, MKDEV(0, 0), NULL,
59 HWMON_ID_FORMAT, id); 59 HWMON_ID_FORMAT, id);
60 60
61 if (IS_ERR(hwdev)) { 61 if (IS_ERR(hwdev)) {
62 spin_lock(&idr_lock); 62 spin_lock(&idr_lock);
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 6ee997b2817c..acadbc51fc0f 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -55,7 +55,7 @@ config I2C_AMD756
55 55
56config I2C_AMD756_S4882 56config I2C_AMD756_S4882
57 tristate "SMBus multiplexing on the Tyan S4882" 57 tristate "SMBus multiplexing on the Tyan S4882"
58 depends on I2C_AMD756 && EXPERIMENTAL 58 depends on I2C_AMD756 && X86 && EXPERIMENTAL
59 help 59 help
60 Enabling this option will add specific SMBus support for the Tyan 60 Enabling this option will add specific SMBus support for the Tyan
61 S4882 motherboard. On this 4-CPU board, the SMBus is multiplexed 61 S4882 motherboard. On this 4-CPU board, the SMBus is multiplexed
@@ -148,7 +148,7 @@ config I2C_NFORCE2
148 148
149config I2C_NFORCE2_S4985 149config I2C_NFORCE2_S4985
150 tristate "SMBus multiplexing on the Tyan S4985" 150 tristate "SMBus multiplexing on the Tyan S4985"
151 depends on I2C_NFORCE2 && EXPERIMENTAL 151 depends on I2C_NFORCE2 && X86 && EXPERIMENTAL
152 help 152 help
153 Enabling this option will add specific SMBus support for the Tyan 153 Enabling this option will add specific SMBus support for the Tyan
154 S4985 motherboard. On this 4-CPU board, the SMBus is multiplexed 154 S4985 motherboard. On this 4-CPU board, the SMBus is multiplexed
@@ -209,7 +209,7 @@ config I2C_VIA
209 will be called i2c-via. 209 will be called i2c-via.
210 210
211config I2C_VIAPRO 211config I2C_VIAPRO
212 tristate "VIA VT82C596/82C686/82xx and CX700" 212 tristate "VIA VT82C596/82C686/82xx and CX700/VX800/VX820"
213 depends on PCI 213 depends on PCI
214 help 214 help
215 If you say yes to this option, support will be included for the VIA 215 If you say yes to this option, support will be included for the VIA
@@ -223,6 +223,8 @@ config I2C_VIAPRO
223 VT8237R/A/S 223 VT8237R/A/S
224 VT8251 224 VT8251
225 CX700 225 CX700
226 VX800
227 VX820
226 228
227 This driver can also be built as a module. If so, the module 229 This driver can also be built as a module. If so, the module
228 will be called i2c-viapro. 230 will be called i2c-viapro.
@@ -330,6 +332,18 @@ config I2C_GPIO
330 This is a very simple bitbanging I2C driver utilizing the 332 This is a very simple bitbanging I2C driver utilizing the
331 arch-neutral GPIO API to control the SCL and SDA lines. 333 arch-neutral GPIO API to control the SCL and SDA lines.
332 334
335config I2C_HIGHLANDER
336 tristate "Highlander FPGA SMBus interface"
337 depends on SH_HIGHLANDER
338 help
339 If you say yes to this option, support will be included for
340 the SMBus interface located in the FPGA on various Highlander
341 boards, particularly the R0P7780LC0011RL and R0P7785LC0011RL
342 FPGAs. This is wholly unrelated to the SoC I2C.
343
344 This driver can also be built as a module. If so, the module
345 will be called i2c-highlander.
346
333config I2C_IBM_IIC 347config I2C_IBM_IIC
334 tristate "IBM PPC 4xx on-chip I2C interface" 348 tristate "IBM PPC 4xx on-chip I2C interface"
335 depends on 4xx 349 depends on 4xx
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 97dbfa2107fe..0c2c4b26cdf1 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -31,6 +31,7 @@ obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
31obj-$(CONFIG_I2C_CPM) += i2c-cpm.o 31obj-$(CONFIG_I2C_CPM) += i2c-cpm.o
32obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o 32obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o
33obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o 33obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o
34obj-$(CONFIG_I2C_HIGHLANDER) += i2c-highlander.o
34obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o 35obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o
35obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o 36obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o
36obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o 37obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o
diff --git a/drivers/i2c/busses/i2c-highlander.c b/drivers/i2c/busses/i2c-highlander.c
new file mode 100644
index 000000000000..f4d22ae9d294
--- /dev/null
+++ b/drivers/i2c/busses/i2c-highlander.c
@@ -0,0 +1,498 @@
1/*
2 * Renesas Solutions Highlander FPGA I2C/SMBus support.
3 *
4 * Supported devices: R0P7780LC0011RL, R0P7785LC0011RL
5 *
6 * Copyright (C) 2008 Paul Mundt
7 * Copyright (C) 2008 Renesas Solutions Corp.
8 * Copyright (C) 2008 Atom Create Engineering Co., Ltd.
9 *
10 * This file is subject to the terms and conditions of the GNU General
11 * Public License version 2. See the file "COPYING" in the main directory
12 * of this archive for more details.
13 */
14#include <linux/module.h>
15#include <linux/init.h>
16#include <linux/interrupt.h>
17#include <linux/i2c.h>
18#include <linux/platform_device.h>
19#include <linux/completion.h>
20#include <linux/io.h>
21#include <linux/delay.h>
22
23#define SMCR 0x00
24#define SMCR_START (1 << 0)
25#define SMCR_IRIC (1 << 1)
26#define SMCR_BBSY (1 << 2)
27#define SMCR_ACKE (1 << 3)
28#define SMCR_RST (1 << 4)
29#define SMCR_IEIC (1 << 6)
30
31#define SMSMADR 0x02
32
33#define SMMR 0x04
34#define SMMR_MODE0 (1 << 0)
35#define SMMR_MODE1 (1 << 1)
36#define SMMR_CAP (1 << 3)
37#define SMMR_TMMD (1 << 4)
38#define SMMR_SP (1 << 7)
39
40#define SMSADR 0x06
41#define SMTRDR 0x46
42
43struct highlander_i2c_dev {
44 struct device *dev;
45 void __iomem *base;
46 struct i2c_adapter adapter;
47 struct completion cmd_complete;
48 unsigned long last_read_time;
49 int irq;
50 u8 *buf;
51 size_t buf_len;
52};
53
54static int iic_force_poll, iic_force_normal;
55static int iic_timeout = 1000, iic_read_delay;
56
57static inline void highlander_i2c_irq_enable(struct highlander_i2c_dev *dev)
58{
59 iowrite16(ioread16(dev->base + SMCR) | SMCR_IEIC, dev->base + SMCR);
60}
61
62static inline void highlander_i2c_irq_disable(struct highlander_i2c_dev *dev)
63{
64 iowrite16(ioread16(dev->base + SMCR) & ~SMCR_IEIC, dev->base + SMCR);
65}
66
67static inline void highlander_i2c_start(struct highlander_i2c_dev *dev)
68{
69 iowrite16(ioread16(dev->base + SMCR) | SMCR_START, dev->base + SMCR);
70}
71
72static inline void highlander_i2c_done(struct highlander_i2c_dev *dev)
73{
74 iowrite16(ioread16(dev->base + SMCR) | SMCR_IRIC, dev->base + SMCR);
75}
76
77static void highlander_i2c_setup(struct highlander_i2c_dev *dev)
78{
79 u16 smmr;
80
81 smmr = ioread16(dev->base + SMMR);
82 smmr |= SMMR_TMMD;
83
84 if (iic_force_normal)
85 smmr &= ~SMMR_SP;
86 else
87 smmr |= SMMR_SP;
88
89 iowrite16(smmr, dev->base + SMMR);
90}
91
92static void smbus_write_data(u8 *src, u16 *dst, int len)
93{
94 for (; len > 1; len -= 2) {
95 *dst++ = be16_to_cpup((u16 *)src);
96 src += 2;
97 }
98
99 if (len)
100 *dst = *src << 8;
101}
102
103static void smbus_read_data(u16 *src, u8 *dst, int len)
104{
105 for (; len > 1; len -= 2) {
106 *(u16 *)dst = cpu_to_be16p(src++);
107 dst += 2;
108 }
109
110 if (len)
111 *dst = *src >> 8;
112}
113
114static void highlander_i2c_command(struct highlander_i2c_dev *dev,
115 u8 command, int len)
116{
117 unsigned int i;
118 u16 cmd = (command << 8) | command;
119
120 for (i = 0; i < len; i += 2) {
121 if (len - i == 1)
122 cmd = command << 8;
123 iowrite16(cmd, dev->base + SMSADR + i);
124 dev_dbg(dev->dev, "command data[%x] 0x%04x\n", i/2, cmd);
125 }
126}
127
128static int highlander_i2c_wait_for_bbsy(struct highlander_i2c_dev *dev)
129{
130 unsigned long timeout;
131
132 timeout = jiffies + msecs_to_jiffies(iic_timeout);
133 while (ioread16(dev->base + SMCR) & SMCR_BBSY) {
134 if (time_after(jiffies, timeout)) {
135 dev_warn(dev->dev, "timeout waiting for bus ready\n");
136 return -ETIMEDOUT;
137 }
138
139 msleep(1);
140 }
141
142 return 0;
143}
144
145static int highlander_i2c_reset(struct highlander_i2c_dev *dev)
146{
147 iowrite16(ioread16(dev->base + SMCR) | SMCR_RST, dev->base + SMCR);
148 return highlander_i2c_wait_for_bbsy(dev);
149}
150
151static int highlander_i2c_wait_for_ack(struct highlander_i2c_dev *dev)
152{
153 u16 tmp = ioread16(dev->base + SMCR);
154
155 if ((tmp & (SMCR_IRIC | SMCR_ACKE)) == SMCR_ACKE) {
156 dev_warn(dev->dev, "ack abnormality\n");
157 return highlander_i2c_reset(dev);
158 }
159
160 return 0;
161}
162
163static irqreturn_t highlander_i2c_irq(int irq, void *dev_id)
164{
165 struct highlander_i2c_dev *dev = dev_id;
166
167 highlander_i2c_done(dev);
168 complete(&dev->cmd_complete);
169
170 return IRQ_HANDLED;
171}
172
173static void highlander_i2c_poll(struct highlander_i2c_dev *dev)
174{
175 unsigned long timeout;
176 u16 smcr;
177
178 timeout = jiffies + msecs_to_jiffies(iic_timeout);
179 for (;;) {
180 smcr = ioread16(dev->base + SMCR);
181
182 /*
183 * Don't bother checking ACKE here, this and the reset
184 * are handled in highlander_i2c_wait_xfer_done() when
185 * waiting for the ACK.
186 */
187
188 if (smcr & SMCR_IRIC)
189 return;
190 if (time_after(jiffies, timeout))
191 break;
192
193 cpu_relax();
194 cond_resched();
195 }
196
197 dev_err(dev->dev, "polling timed out\n");
198}
199
200static inline int highlander_i2c_wait_xfer_done(struct highlander_i2c_dev *dev)
201{
202 if (dev->irq)
203 wait_for_completion_timeout(&dev->cmd_complete,
204 msecs_to_jiffies(iic_timeout));
205 else
206 /* busy looping, the IRQ of champions */
207 highlander_i2c_poll(dev);
208
209 return highlander_i2c_wait_for_ack(dev);
210}
211
212static int highlander_i2c_read(struct highlander_i2c_dev *dev)
213{
214 int i, cnt;
215 u16 data[16];
216
217 if (highlander_i2c_wait_for_bbsy(dev))
218 return -EAGAIN;
219
220 highlander_i2c_start(dev);
221
222 if (highlander_i2c_wait_xfer_done(dev)) {
223 dev_err(dev->dev, "Arbitration loss\n");
224 return -EAGAIN;
225 }
226
227 /*
228 * The R0P7780LC0011RL FPGA needs a significant delay between
229 * data read cycles, otherwise the transciever gets confused and
230 * garbage is returned when the read is subsequently aborted.
231 *
232 * It is not sufficient to wait for BBSY.
233 *
234 * While this generally only applies to the older SH7780-based
235 * Highlanders, the same issue can be observed on SH7785 ones,
236 * albeit less frequently. SH7780-based Highlanders may need
237 * this to be as high as 1000 ms.
238 */
239 if (iic_read_delay && time_before(jiffies, dev->last_read_time +
240 msecs_to_jiffies(iic_read_delay)))
241 msleep(jiffies_to_msecs((dev->last_read_time +
242 msecs_to_jiffies(iic_read_delay)) - jiffies));
243
244 cnt = (dev->buf_len + 1) >> 1;
245 for (i = 0; i < cnt; i++) {
246 data[i] = ioread16(dev->base + SMTRDR + (i * sizeof(u16)));
247 dev_dbg(dev->dev, "read data[%x] 0x%04x\n", i, data[i]);
248 }
249
250 smbus_read_data(data, dev->buf, dev->buf_len);
251
252 dev->last_read_time = jiffies;
253
254 return 0;
255}
256
257static int highlander_i2c_write(struct highlander_i2c_dev *dev)
258{
259 int i, cnt;
260 u16 data[16];
261
262 smbus_write_data(dev->buf, data, dev->buf_len);
263
264 cnt = (dev->buf_len + 1) >> 1;
265 for (i = 0; i < cnt; i++) {
266 iowrite16(data[i], dev->base + SMTRDR + (i * sizeof(u16)));
267 dev_dbg(dev->dev, "write data[%x] 0x%04x\n", i, data[i]);
268 }
269
270 if (highlander_i2c_wait_for_bbsy(dev))
271 return -EAGAIN;
272
273 highlander_i2c_start(dev);
274
275 return highlander_i2c_wait_xfer_done(dev);
276}
277
278static int highlander_i2c_smbus_xfer(struct i2c_adapter *adap, u16 addr,
279 unsigned short flags, char read_write,
280 u8 command, int size,
281 union i2c_smbus_data *data)
282{
283 struct highlander_i2c_dev *dev = i2c_get_adapdata(adap);
284 int read = read_write & I2C_SMBUS_READ;
285 u16 tmp;
286
287 init_completion(&dev->cmd_complete);
288
289 dev_dbg(dev->dev, "addr %04x, command %02x, read_write %d, size %d\n",
290 addr, command, read_write, size);
291
292 /*
293 * Set up the buffer and transfer size
294 */
295 switch (size) {
296 case I2C_SMBUS_BYTE_DATA:
297 dev->buf = &data->byte;
298 dev->buf_len = 1;
299 break;
300 case I2C_SMBUS_I2C_BLOCK_DATA:
301 dev->buf = &data->block[1];
302 dev->buf_len = data->block[0];
303 break;
304 default:
305 dev_err(dev->dev, "unsupported command %d\n", size);
306 return -EINVAL;
307 }
308
309 /*
310 * Encode the mode setting
311 */
312 tmp = ioread16(dev->base + SMMR);
313 tmp &= ~(SMMR_MODE0 | SMMR_MODE1);
314
315 switch (dev->buf_len) {
316 case 1:
317 /* default */
318 break;
319 case 8:
320 tmp |= SMMR_MODE0;
321 break;
322 case 16:
323 tmp |= SMMR_MODE1;
324 break;
325 case 32:
326 tmp |= (SMMR_MODE0 | SMMR_MODE1);
327 break;
328 default:
329 dev_err(dev->dev, "unsupported xfer size %d\n", dev->buf_len);
330 return -EINVAL;
331 }
332
333 iowrite16(tmp, dev->base + SMMR);
334
335 /* Ensure we're in a sane state */
336 highlander_i2c_done(dev);
337
338 /* Set slave address */
339 iowrite16((addr << 1) | read, dev->base + SMSMADR);
340
341 highlander_i2c_command(dev, command, dev->buf_len);
342
343 if (read)
344 return highlander_i2c_read(dev);
345 else
346 return highlander_i2c_write(dev);
347}
348
349static u32 highlander_i2c_func(struct i2c_adapter *adapter)
350{
351 return I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_I2C_BLOCK;
352}
353
354static const struct i2c_algorithm highlander_i2c_algo = {
355 .smbus_xfer = highlander_i2c_smbus_xfer,
356 .functionality = highlander_i2c_func,
357};
358
359static int __devinit highlander_i2c_probe(struct platform_device *pdev)
360{
361 struct highlander_i2c_dev *dev;
362 struct i2c_adapter *adap;
363 struct resource *res;
364 int ret;
365
366 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
367 if (unlikely(!res)) {
368 dev_err(&pdev->dev, "no mem resource\n");
369 return -ENODEV;
370 }
371
372 dev = kzalloc(sizeof(struct highlander_i2c_dev), GFP_KERNEL);
373 if (unlikely(!dev))
374 return -ENOMEM;
375
376 dev->base = ioremap_nocache(res->start, res->end - res->start + 1);
377 if (unlikely(!dev->base)) {
378 ret = -ENXIO;
379 goto err;
380 }
381
382 dev->dev = &pdev->dev;
383 platform_set_drvdata(pdev, dev);
384
385 dev->irq = platform_get_irq(pdev, 0);
386 if (iic_force_poll)
387 dev->irq = 0;
388
389 if (dev->irq) {
390 ret = request_irq(dev->irq, highlander_i2c_irq, IRQF_DISABLED,
391 pdev->name, dev);
392 if (unlikely(ret))
393 goto err_unmap;
394
395 highlander_i2c_irq_enable(dev);
396 } else {
397 dev_notice(&pdev->dev, "no IRQ, using polling mode\n");
398 highlander_i2c_irq_disable(dev);
399 }
400
401 dev->last_read_time = jiffies; /* initial read jiffies */
402
403 highlander_i2c_setup(dev);
404
405 adap = &dev->adapter;
406 i2c_set_adapdata(adap, dev);
407 adap->owner = THIS_MODULE;
408 adap->class = I2C_CLASS_HWMON;
409 strlcpy(adap->name, "HL FPGA I2C adapter", sizeof(adap->name));
410 adap->algo = &highlander_i2c_algo;
411 adap->dev.parent = &pdev->dev;
412 adap->nr = pdev->id;
413
414 /*
415 * Reset the adapter
416 */
417 ret = highlander_i2c_reset(dev);
418 if (unlikely(ret)) {
419 dev_err(&pdev->dev, "controller didn't come up\n");
420 goto err_free_irq;
421 }
422
423 ret = i2c_add_numbered_adapter(adap);
424 if (unlikely(ret)) {
425 dev_err(&pdev->dev, "failure adding adapter\n");
426 goto err_free_irq;
427 }
428
429 return 0;
430
431err_free_irq:
432 if (dev->irq)
433 free_irq(dev->irq, dev);
434err_unmap:
435 iounmap(dev->base);
436err:
437 kfree(dev);
438
439 platform_set_drvdata(pdev, NULL);
440
441 return ret;
442}
443
444static int __devexit highlander_i2c_remove(struct platform_device *pdev)
445{
446 struct highlander_i2c_dev *dev = platform_get_drvdata(pdev);
447
448 i2c_del_adapter(&dev->adapter);
449
450 if (dev->irq)
451 free_irq(dev->irq, dev);
452
453 iounmap(dev->base);
454 kfree(dev);
455
456 platform_set_drvdata(pdev, NULL);
457
458 return 0;
459}
460
461static struct platform_driver highlander_i2c_driver = {
462 .driver = {
463 .name = "i2c-highlander",
464 .owner = THIS_MODULE,
465 },
466
467 .probe = highlander_i2c_probe,
468 .remove = __devexit_p(highlander_i2c_remove),
469};
470
471static int __init highlander_i2c_init(void)
472{
473 return platform_driver_register(&highlander_i2c_driver);
474}
475
476static void __exit highlander_i2c_exit(void)
477{
478 platform_driver_unregister(&highlander_i2c_driver);
479}
480
481module_init(highlander_i2c_init);
482module_exit(highlander_i2c_exit);
483
484MODULE_AUTHOR("Paul Mundt");
485MODULE_DESCRIPTION("Renesas Highlander FPGA I2C/SMBus adapter");
486MODULE_LICENSE("GPL v2");
487
488module_param(iic_force_poll, bool, 0);
489module_param(iic_force_normal, bool, 0);
490module_param(iic_timeout, int, 0);
491module_param(iic_read_delay, int, 0);
492
493MODULE_PARM_DESC(iic_force_poll, "Force polling mode");
494MODULE_PARM_DESC(iic_force_normal,
495 "Force normal mode (100 kHz), default is fast mode (400 kHz)");
496MODULE_PARM_DESC(iic_timeout, "Set timeout value in msecs (default 1000 ms)");
497MODULE_PARM_DESC(iic_read_delay,
498 "Delay between data read cycles (default 0 ms)");
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 27443f073bc9..a9a45fcc8544 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -312,7 +312,6 @@ static struct i2c_adapter mpc_ops = {
312 .name = "MPC adapter", 312 .name = "MPC adapter",
313 .id = I2C_HW_MPC107, 313 .id = I2C_HW_MPC107,
314 .algo = &mpc_algo, 314 .algo = &mpc_algo,
315 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
316 .timeout = 1, 315 .timeout = 1,
317}; 316};
318 317
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index e7eb7bf9ddec..608038d64f81 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -589,11 +589,16 @@ omap_i2c_probe(struct platform_device *pdev)
589 589
590 dev->dev = &pdev->dev; 590 dev->dev = &pdev->dev;
591 dev->irq = irq->start; 591 dev->irq = irq->start;
592 dev->base = (void __iomem *) IO_ADDRESS(mem->start); 592 dev->base = ioremap(mem->start, mem->end - mem->start + 1);
593 if (!dev->base) {
594 r = -ENOMEM;
595 goto err_free_mem;
596 }
597
593 platform_set_drvdata(pdev, dev); 598 platform_set_drvdata(pdev, dev);
594 599
595 if ((r = omap_i2c_get_clocks(dev)) != 0) 600 if ((r = omap_i2c_get_clocks(dev)) != 0)
596 goto err_free_mem; 601 goto err_iounmap;
597 602
598 omap_i2c_unidle(dev); 603 omap_i2c_unidle(dev);
599 604
@@ -640,6 +645,8 @@ err_unuse_clocks:
640 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 645 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
641 omap_i2c_idle(dev); 646 omap_i2c_idle(dev);
642 omap_i2c_put_clocks(dev); 647 omap_i2c_put_clocks(dev);
648err_iounmap:
649 iounmap(dev->base);
643err_free_mem: 650err_free_mem:
644 platform_set_drvdata(pdev, NULL); 651 platform_set_drvdata(pdev, NULL);
645 kfree(dev); 652 kfree(dev);
@@ -661,6 +668,7 @@ omap_i2c_remove(struct platform_device *pdev)
661 i2c_del_adapter(&dev->adapter); 668 i2c_del_adapter(&dev->adapter);
662 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 669 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
663 omap_i2c_put_clocks(dev); 670 omap_i2c_put_clocks(dev);
671 iounmap(dev->base);
664 kfree(dev); 672 kfree(dev);
665 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 673 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
666 release_mem_region(mem->start, (mem->end - mem->start) + 1); 674 release_mem_region(mem->start, (mem->end - mem->start) + 1);
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c
index c6faf9bdad18..b2b8380f6602 100644
--- a/drivers/i2c/busses/i2c-parport-light.c
+++ b/drivers/i2c/busses/i2c-parport-light.c
@@ -123,11 +123,6 @@ static struct i2c_adapter parport_adapter = {
123static int __devinit i2c_parport_probe(struct platform_device *pdev) 123static int __devinit i2c_parport_probe(struct platform_device *pdev)
124{ 124{
125 int err; 125 int err;
126 struct resource *res;
127
128 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
129 if (!request_region(res->start, res->end - res->start + 1, DRVNAME))
130 return -EBUSY;
131 126
132 /* Reset hardware to a sane state (SCL and SDA high) */ 127 /* Reset hardware to a sane state (SCL and SDA high) */
133 parport_setsda(NULL, 1); 128 parport_setsda(NULL, 1);
@@ -138,29 +133,19 @@ static int __devinit i2c_parport_probe(struct platform_device *pdev)
138 133
139 parport_adapter.dev.parent = &pdev->dev; 134 parport_adapter.dev.parent = &pdev->dev;
140 err = i2c_bit_add_bus(&parport_adapter); 135 err = i2c_bit_add_bus(&parport_adapter);
141 if (err) { 136 if (err)
142 dev_err(&pdev->dev, "Unable to register with I2C\n"); 137 dev_err(&pdev->dev, "Unable to register with I2C\n");
143 goto exit_region;
144 }
145 return 0;
146
147exit_region:
148 release_region(res->start, res->end - res->start + 1);
149 return err; 138 return err;
150} 139}
151 140
152static int __devexit i2c_parport_remove(struct platform_device *pdev) 141static int __devexit i2c_parport_remove(struct platform_device *pdev)
153{ 142{
154 struct resource *res;
155
156 i2c_del_adapter(&parport_adapter); 143 i2c_del_adapter(&parport_adapter);
157 144
158 /* Un-init if needed (power off...) */ 145 /* Un-init if needed (power off...) */
159 if (adapter_parm[type].init.val) 146 if (adapter_parm[type].init.val)
160 line_set(0, &adapter_parm[type].init); 147 line_set(0, &adapter_parm[type].init);
161 148
162 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
163 release_region(res->start, res->end - res->start + 1);
164 return 0; 149 return 0;
165} 150}
166 151
@@ -175,12 +160,6 @@ static struct platform_driver i2c_parport_driver = {
175 160
176static int __init i2c_parport_device_add(u16 address) 161static int __init i2c_parport_device_add(u16 address)
177{ 162{
178 struct resource res = {
179 .start = address,
180 .end = address + 2,
181 .name = DRVNAME,
182 .flags = IORESOURCE_IO,
183 };
184 int err; 163 int err;
185 164
186 pdev = platform_device_alloc(DRVNAME, -1); 165 pdev = platform_device_alloc(DRVNAME, -1);
@@ -190,13 +169,6 @@ static int __init i2c_parport_device_add(u16 address)
190 goto exit; 169 goto exit;
191 } 170 }
192 171
193 err = platform_device_add_resources(pdev, &res, 1);
194 if (err) {
195 printk(KERN_ERR DRVNAME ": Device resource addition failed "
196 "(%d)\n", err);
197 goto exit_device_put;
198 }
199
200 err = platform_device_add(pdev); 172 err = platform_device_add(pdev);
201 if (err) { 173 if (err) {
202 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", 174 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
@@ -231,13 +203,16 @@ static int __init i2c_parport_init(void)
231 base = DEFAULT_BASE; 203 base = DEFAULT_BASE;
232 } 204 }
233 205
206 if (!request_region(base, 3, DRVNAME))
207 return -EBUSY;
208
234 if (!adapter_parm[type].getscl.val) 209 if (!adapter_parm[type].getscl.val)
235 parport_algo_data.getscl = NULL; 210 parport_algo_data.getscl = NULL;
236 211
237 /* Sets global pdev as a side effect */ 212 /* Sets global pdev as a side effect */
238 err = i2c_parport_device_add(base); 213 err = i2c_parport_device_add(base);
239 if (err) 214 if (err)
240 goto exit; 215 goto exit_release;
241 216
242 err = platform_driver_register(&i2c_parport_driver); 217 err = platform_driver_register(&i2c_parport_driver);
243 if (err) 218 if (err)
@@ -247,7 +222,8 @@ static int __init i2c_parport_init(void)
247 222
248exit_device: 223exit_device:
249 platform_device_unregister(pdev); 224 platform_device_unregister(pdev);
250exit: 225exit_release:
226 release_region(base, 3);
251 return err; 227 return err;
252} 228}
253 229
@@ -255,6 +231,7 @@ static void __exit i2c_parport_exit(void)
255{ 231{
256 platform_driver_unregister(&i2c_parport_driver); 232 platform_driver_unregister(&i2c_parport_driver);
257 platform_device_unregister(pdev); 233 platform_device_unregister(pdev);
234 release_region(base, 3);
258} 235}
259 236
260MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 237MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c
index a119784bae10..9eb76268ec78 100644
--- a/drivers/i2c/busses/i2c-pca-isa.c
+++ b/drivers/i2c/busses/i2c-pca-isa.c
@@ -36,8 +36,8 @@
36#define DRIVER "i2c-pca-isa" 36#define DRIVER "i2c-pca-isa"
37#define IO_SIZE 4 37#define IO_SIZE 4
38 38
39static unsigned long base = 0x330; 39static unsigned long base;
40static int irq = 10; 40static int irq = -1;
41 41
42/* Data sheet recommends 59kHz for 100kHz operation due to variation 42/* Data sheet recommends 59kHz for 100kHz operation due to variation
43 * in the actual clock rate */ 43 * in the actual clock rate */
@@ -107,13 +107,26 @@ static struct i2c_adapter pca_isa_ops = {
107 .timeout = 100, 107 .timeout = 100,
108}; 108};
109 109
110static int __devinit pca_isa_match(struct device *dev, unsigned int id)
111{
112 int match = base != 0;
113
114 if (match) {
115 if (irq <= -1)
116 dev_warn(dev, "Using polling mode (specify irq)\n");
117 } else
118 dev_err(dev, "Please specify I/O base\n");
119
120 return match;
121}
122
110static int __devinit pca_isa_probe(struct device *dev, unsigned int id) 123static int __devinit pca_isa_probe(struct device *dev, unsigned int id)
111{ 124{
112 init_waitqueue_head(&pca_wait); 125 init_waitqueue_head(&pca_wait);
113 126
114 dev_info(dev, "i/o base %#08lx. irq %d\n", base, irq); 127 dev_info(dev, "i/o base %#08lx. irq %d\n", base, irq);
115 128
116#ifdef CONFIG_PPC_MERGE 129#ifdef CONFIG_PPC
117 if (check_legacy_ioport(base)) { 130 if (check_legacy_ioport(base)) {
118 dev_err(dev, "I/O address %#08lx is not available\n", base); 131 dev_err(dev, "I/O address %#08lx is not available\n", base);
119 goto out; 132 goto out;
@@ -153,7 +166,7 @@ static int __devexit pca_isa_remove(struct device *dev, unsigned int id)
153{ 166{
154 i2c_del_adapter(&pca_isa_ops); 167 i2c_del_adapter(&pca_isa_ops);
155 168
156 if (irq > 0) { 169 if (irq > -1) {
157 disable_irq(irq); 170 disable_irq(irq);
158 free_irq(irq, &pca_isa_ops); 171 free_irq(irq, &pca_isa_ops);
159 } 172 }
@@ -163,6 +176,7 @@ static int __devexit pca_isa_remove(struct device *dev, unsigned int id)
163} 176}
164 177
165static struct isa_driver pca_isa_driver = { 178static struct isa_driver pca_isa_driver = {
179 .match = pca_isa_match,
166 .probe = pca_isa_probe, 180 .probe = pca_isa_probe,
167 .remove = __devexit_p(pca_isa_remove), 181 .remove = __devexit_p(pca_isa_remove),
168 .driver = { 182 .driver = {
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 862eb352a2d9..73dc52e114eb 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -36,6 +36,7 @@
36 VT8237S 0x3372 yes 36 VT8237S 0x3372 yes
37 VT8251 0x3287 yes 37 VT8251 0x3287 yes
38 CX700 0x8324 yes 38 CX700 0x8324 yes
39 VX800/VX820 0x8353 yes
39 40
40 Note: we assume there can only be one device, with one SMBus interface. 41 Note: we assume there can only be one device, with one SMBus interface.
41*/ 42*/
@@ -82,6 +83,7 @@ static unsigned short SMBHSTCFG = 0xD2;
82#define VT596_BYTE 0x04 83#define VT596_BYTE 0x04
83#define VT596_BYTE_DATA 0x08 84#define VT596_BYTE_DATA 0x08
84#define VT596_WORD_DATA 0x0C 85#define VT596_WORD_DATA 0x0C
86#define VT596_PROC_CALL 0x10
85#define VT596_BLOCK_DATA 0x14 87#define VT596_BLOCK_DATA 0x14
86#define VT596_I2C_BLOCK_DATA 0x34 88#define VT596_I2C_BLOCK_DATA 0x34
87 89
@@ -232,6 +234,12 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
232 } 234 }
233 size = VT596_WORD_DATA; 235 size = VT596_WORD_DATA;
234 break; 236 break;
237 case I2C_SMBUS_PROC_CALL:
238 outb_p(command, SMBHSTCMD);
239 outb_p(data->word & 0xff, SMBHSTDAT0);
240 outb_p((data->word & 0xff00) >> 8, SMBHSTDAT1);
241 size = VT596_PROC_CALL;
242 break;
235 case I2C_SMBUS_I2C_BLOCK_DATA: 243 case I2C_SMBUS_I2C_BLOCK_DATA:
236 if (!(vt596_features & FEATURE_I2CBLOCK)) 244 if (!(vt596_features & FEATURE_I2CBLOCK))
237 goto exit_unsupported; 245 goto exit_unsupported;
@@ -262,6 +270,9 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
262 if (status) 270 if (status)
263 return status; 271 return status;
264 272
273 if (size == VT596_PROC_CALL)
274 read_write = I2C_SMBUS_READ;
275
265 if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK)) 276 if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK))
266 return 0; 277 return 0;
267 278
@@ -271,6 +282,7 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
271 data->byte = inb_p(SMBHSTDAT0); 282 data->byte = inb_p(SMBHSTDAT0);
272 break; 283 break;
273 case VT596_WORD_DATA: 284 case VT596_WORD_DATA:
285 case VT596_PROC_CALL:
274 data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); 286 data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
275 break; 287 break;
276 case VT596_I2C_BLOCK_DATA: 288 case VT596_I2C_BLOCK_DATA:
@@ -295,7 +307,7 @@ static u32 vt596_func(struct i2c_adapter *adapter)
295{ 307{
296 u32 func = I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 308 u32 func = I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
297 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 309 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
298 I2C_FUNC_SMBUS_BLOCK_DATA; 310 I2C_SMBUS_PROC_CALL | I2C_FUNC_SMBUS_BLOCK_DATA;
299 311
300 if (vt596_features & FEATURE_I2CBLOCK) 312 if (vt596_features & FEATURE_I2CBLOCK)
301 func |= I2C_FUNC_SMBUS_I2C_BLOCK; 313 func |= I2C_FUNC_SMBUS_I2C_BLOCK;
@@ -396,6 +408,7 @@ found:
396 408
397 switch (pdev->device) { 409 switch (pdev->device) {
398 case PCI_DEVICE_ID_VIA_CX700: 410 case PCI_DEVICE_ID_VIA_CX700:
411 case PCI_DEVICE_ID_VIA_VX800:
399 case PCI_DEVICE_ID_VIA_8251: 412 case PCI_DEVICE_ID_VIA_8251:
400 case PCI_DEVICE_ID_VIA_8237: 413 case PCI_DEVICE_ID_VIA_8237:
401 case PCI_DEVICE_ID_VIA_8237A: 414 case PCI_DEVICE_ID_VIA_8237A:
@@ -459,6 +472,8 @@ static struct pci_device_id vt596_ids[] = {
459 .driver_data = SMBBA3 }, 472 .driver_data = SMBBA3 },
460 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_CX700), 473 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_CX700),
461 .driver_data = SMBBA3 }, 474 .driver_data = SMBBA3 },
475 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX800),
476 .driver_data = SMBBA3 },
462 { 0, } 477 { 0, }
463}; 478};
464 479
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index a95cb9465d65..17356827b93d 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -172,4 +172,15 @@ config MENELAUS
172 and other features that are often used in portable devices like 172 and other features that are often used in portable devices like
173 cell phones and PDAs. 173 cell phones and PDAs.
174 174
175config MCU_MPC8349EMITX
176 tristate "MPC8349E-mITX MCU driver"
177 depends on I2C && PPC_83xx
178 select GENERIC_GPIO
179 select ARCH_REQUIRE_GPIOLIB
180 help
181 Say Y here to enable soft power-off functionality on the Freescale
182 boards with the MPC8349E-mITX-compatible MCU chips. This driver will
183 also register MCU GPIOs with the generic GPIO API, so you'll able
184 to use MCU pins as GPIOs.
185
175endmenu 186endmenu
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
index 39e3e69ed125..ca520fa143d6 100644
--- a/drivers/i2c/chips/Makefile
+++ b/drivers/i2c/chips/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o
21obj-$(CONFIG_TPS65010) += tps65010.o 21obj-$(CONFIG_TPS65010) += tps65010.o
22obj-$(CONFIG_MENELAUS) += menelaus.o 22obj-$(CONFIG_MENELAUS) += menelaus.o
23obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o 23obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o
24obj-$(CONFIG_MCU_MPC8349EMITX) += mcu_mpc8349emitx.o
24 25
25ifeq ($(CONFIG_I2C_DEBUG_CHIP),y) 26ifeq ($(CONFIG_I2C_DEBUG_CHIP),y)
26EXTRA_CFLAGS += -DDEBUG 27EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c
index 4655b794ebe3..28902ebd5539 100644
--- a/drivers/i2c/chips/isp1301_omap.c
+++ b/drivers/i2c/chips/isp1301_omap.c
@@ -49,10 +49,9 @@ MODULE_LICENSE("GPL");
49 49
50struct isp1301 { 50struct isp1301 {
51 struct otg_transceiver otg; 51 struct otg_transceiver otg;
52 struct i2c_client client; 52 struct i2c_client *client;
53 void (*i2c_release)(struct device *dev); 53 void (*i2c_release)(struct device *dev);
54 54
55 int irq;
56 int irq_type; 55 int irq_type;
57 56
58 u32 last_otg_ctrl; 57 u32 last_otg_ctrl;
@@ -138,14 +137,6 @@ static inline void notresponding(struct isp1301 *isp)
138 137
139/*-------------------------------------------------------------------------*/ 138/*-------------------------------------------------------------------------*/
140 139
141/* only two addresses possible */
142#define ISP_BASE 0x2c
143static unsigned short normal_i2c[] = {
144 ISP_BASE, ISP_BASE + 1,
145 I2C_CLIENT_END };
146
147I2C_CLIENT_INSMOD;
148
149static struct i2c_driver isp1301_driver; 140static struct i2c_driver isp1301_driver;
150 141
151/* smbus apis are used for portability */ 142/* smbus apis are used for portability */
@@ -153,25 +144,25 @@ static struct i2c_driver isp1301_driver;
153static inline u8 144static inline u8
154isp1301_get_u8(struct isp1301 *isp, u8 reg) 145isp1301_get_u8(struct isp1301 *isp, u8 reg)
155{ 146{
156 return i2c_smbus_read_byte_data(&isp->client, reg + 0); 147 return i2c_smbus_read_byte_data(isp->client, reg + 0);
157} 148}
158 149
159static inline int 150static inline int
160isp1301_get_u16(struct isp1301 *isp, u8 reg) 151isp1301_get_u16(struct isp1301 *isp, u8 reg)
161{ 152{
162 return i2c_smbus_read_word_data(&isp->client, reg); 153 return i2c_smbus_read_word_data(isp->client, reg);
163} 154}
164 155
165static inline int 156static inline int
166isp1301_set_bits(struct isp1301 *isp, u8 reg, u8 bits) 157isp1301_set_bits(struct isp1301 *isp, u8 reg, u8 bits)
167{ 158{
168 return i2c_smbus_write_byte_data(&isp->client, reg + 0, bits); 159 return i2c_smbus_write_byte_data(isp->client, reg + 0, bits);
169} 160}
170 161
171static inline int 162static inline int
172isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits) 163isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits)
173{ 164{
174 return i2c_smbus_write_byte_data(&isp->client, reg + 1, bits); 165 return i2c_smbus_write_byte_data(isp->client, reg + 1, bits);
175} 166}
176 167
177/*-------------------------------------------------------------------------*/ 168/*-------------------------------------------------------------------------*/
@@ -349,10 +340,10 @@ isp1301_defer_work(struct isp1301 *isp, int work)
349 int status; 340 int status;
350 341
351 if (isp && !test_and_set_bit(work, &isp->todo)) { 342 if (isp && !test_and_set_bit(work, &isp->todo)) {
352 (void) get_device(&isp->client.dev); 343 (void) get_device(&isp->client->dev);
353 status = schedule_work(&isp->work); 344 status = schedule_work(&isp->work);
354 if (!status && !isp->working) 345 if (!status && !isp->working)
355 dev_vdbg(&isp->client.dev, 346 dev_vdbg(&isp->client->dev,
356 "work item %d may be lost\n", work); 347 "work item %d may be lost\n", work);
357 } 348 }
358} 349}
@@ -1135,7 +1126,7 @@ isp1301_work(struct work_struct *work)
1135 /* transfer state from otg engine to isp1301 */ 1126 /* transfer state from otg engine to isp1301 */
1136 if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) { 1127 if (test_and_clear_bit(WORK_UPDATE_ISP, &isp->todo)) {
1137 otg_update_isp(isp); 1128 otg_update_isp(isp);
1138 put_device(&isp->client.dev); 1129 put_device(&isp->client->dev);
1139 } 1130 }
1140#endif 1131#endif
1141 /* transfer state from isp1301 to otg engine */ 1132 /* transfer state from isp1301 to otg engine */
@@ -1143,7 +1134,7 @@ isp1301_work(struct work_struct *work)
1143 u8 stat = isp1301_clear_latch(isp); 1134 u8 stat = isp1301_clear_latch(isp);
1144 1135
1145 isp_update_otg(isp, stat); 1136 isp_update_otg(isp, stat);
1146 put_device(&isp->client.dev); 1137 put_device(&isp->client->dev);
1147 } 1138 }
1148 1139
1149 if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) { 1140 if (test_and_clear_bit(WORK_HOST_RESUME, &isp->todo)) {
@@ -1178,7 +1169,7 @@ isp1301_work(struct work_struct *work)
1178 } 1169 }
1179 host_resume(isp); 1170 host_resume(isp);
1180 // mdelay(10); 1171 // mdelay(10);
1181 put_device(&isp->client.dev); 1172 put_device(&isp->client->dev);
1182 } 1173 }
1183 1174
1184 if (test_and_clear_bit(WORK_TIMER, &isp->todo)) { 1175 if (test_and_clear_bit(WORK_TIMER, &isp->todo)) {
@@ -1187,15 +1178,15 @@ isp1301_work(struct work_struct *work)
1187 if (!stop) 1178 if (!stop)
1188 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES); 1179 mod_timer(&isp->timer, jiffies + TIMER_JIFFIES);
1189#endif 1180#endif
1190 put_device(&isp->client.dev); 1181 put_device(&isp->client->dev);
1191 } 1182 }
1192 1183
1193 if (isp->todo) 1184 if (isp->todo)
1194 dev_vdbg(&isp->client.dev, 1185 dev_vdbg(&isp->client->dev,
1195 "work done, todo = 0x%lx\n", 1186 "work done, todo = 0x%lx\n",
1196 isp->todo); 1187 isp->todo);
1197 if (stop) { 1188 if (stop) {
1198 dev_dbg(&isp->client.dev, "stop\n"); 1189 dev_dbg(&isp->client->dev, "stop\n");
1199 break; 1190 break;
1200 } 1191 }
1201 } while (isp->todo); 1192 } while (isp->todo);
@@ -1219,7 +1210,7 @@ static void isp1301_release(struct device *dev)
1219{ 1210{
1220 struct isp1301 *isp; 1211 struct isp1301 *isp;
1221 1212
1222 isp = container_of(dev, struct isp1301, client.dev); 1213 isp = dev_get_drvdata(dev);
1223 1214
1224 /* ugly -- i2c hijacks our memory hook to wait_for_completion() */ 1215 /* ugly -- i2c hijacks our memory hook to wait_for_completion() */
1225 if (isp->i2c_release) 1216 if (isp->i2c_release)
@@ -1229,15 +1220,15 @@ static void isp1301_release(struct device *dev)
1229 1220
1230static struct isp1301 *the_transceiver; 1221static struct isp1301 *the_transceiver;
1231 1222
1232static int isp1301_detach_client(struct i2c_client *i2c) 1223static int __exit isp1301_remove(struct i2c_client *i2c)
1233{ 1224{
1234 struct isp1301 *isp; 1225 struct isp1301 *isp;
1235 1226
1236 isp = container_of(i2c, struct isp1301, client); 1227 isp = i2c_get_clientdata(i2c);
1237 1228
1238 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0); 1229 isp1301_clear_bits(isp, ISP1301_INTERRUPT_FALLING, ~0);
1239 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0); 1230 isp1301_clear_bits(isp, ISP1301_INTERRUPT_RISING, ~0);
1240 free_irq(isp->irq, isp); 1231 free_irq(i2c->irq, isp);
1241#ifdef CONFIG_USB_OTG 1232#ifdef CONFIG_USB_OTG
1242 otg_unbind(isp); 1233 otg_unbind(isp);
1243#endif 1234#endif
@@ -1252,7 +1243,7 @@ static int isp1301_detach_client(struct i2c_client *i2c)
1252 put_device(&i2c->dev); 1243 put_device(&i2c->dev);
1253 the_transceiver = 0; 1244 the_transceiver = 0;
1254 1245
1255 return i2c_detach_client(i2c); 1246 return 0;
1256} 1247}
1257 1248
1258/*-------------------------------------------------------------------------*/ 1249/*-------------------------------------------------------------------------*/
@@ -1285,7 +1276,7 @@ static int isp1301_otg_enable(struct isp1301 *isp)
1285 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, 1276 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1286 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND); 1277 INTR_VBUS_VLD | INTR_SESS_VLD | INTR_ID_GND);
1287 1278
1288 dev_info(&isp->client.dev, "ready for dual-role USB ...\n"); 1279 dev_info(&isp->client->dev, "ready for dual-role USB ...\n");
1289 1280
1290 return 0; 1281 return 0;
1291} 1282}
@@ -1310,7 +1301,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
1310 1301
1311#ifdef CONFIG_USB_OTG 1302#ifdef CONFIG_USB_OTG
1312 isp->otg.host = host; 1303 isp->otg.host = host;
1313 dev_dbg(&isp->client.dev, "registered host\n"); 1304 dev_dbg(&isp->client->dev, "registered host\n");
1314 host_suspend(isp); 1305 host_suspend(isp);
1315 if (isp->otg.gadget) 1306 if (isp->otg.gadget)
1316 return isp1301_otg_enable(isp); 1307 return isp1301_otg_enable(isp);
@@ -1325,7 +1316,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
1325 if (machine_is_omap_h2()) 1316 if (machine_is_omap_h2())
1326 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); 1317 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
1327 1318
1328 dev_info(&isp->client.dev, "A-Host sessions ok\n"); 1319 dev_info(&isp->client->dev, "A-Host sessions ok\n");
1329 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING, 1320 isp1301_set_bits(isp, ISP1301_INTERRUPT_RISING,
1330 INTR_ID_GND); 1321 INTR_ID_GND);
1331 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, 1322 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
@@ -1343,7 +1334,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
1343 return 0; 1334 return 0;
1344 1335
1345#else 1336#else
1346 dev_dbg(&isp->client.dev, "host sessions not allowed\n"); 1337 dev_dbg(&isp->client->dev, "host sessions not allowed\n");
1347 return -EINVAL; 1338 return -EINVAL;
1348#endif 1339#endif
1349 1340
@@ -1370,7 +1361,7 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
1370 1361
1371#ifdef CONFIG_USB_OTG 1362#ifdef CONFIG_USB_OTG
1372 isp->otg.gadget = gadget; 1363 isp->otg.gadget = gadget;
1373 dev_dbg(&isp->client.dev, "registered gadget\n"); 1364 dev_dbg(&isp->client->dev, "registered gadget\n");
1374 /* gadget driver may be suspended until vbus_connect () */ 1365 /* gadget driver may be suspended until vbus_connect () */
1375 if (isp->otg.host) 1366 if (isp->otg.host)
1376 return isp1301_otg_enable(isp); 1367 return isp1301_otg_enable(isp);
@@ -1395,7 +1386,7 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
1395 INTR_SESS_VLD); 1386 INTR_SESS_VLD);
1396 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING, 1387 isp1301_set_bits(isp, ISP1301_INTERRUPT_FALLING,
1397 INTR_VBUS_VLD); 1388 INTR_VBUS_VLD);
1398 dev_info(&isp->client.dev, "B-Peripheral sessions ok\n"); 1389 dev_info(&isp->client->dev, "B-Peripheral sessions ok\n");
1399 dump_regs(isp, __func__); 1390 dump_regs(isp, __func__);
1400 1391
1401 /* If this has a Mini-AB connector, this mode is highly 1392 /* If this has a Mini-AB connector, this mode is highly
@@ -1408,7 +1399,7 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
1408 return 0; 1399 return 0;
1409 1400
1410#else 1401#else
1411 dev_dbg(&isp->client.dev, "peripheral sessions not allowed\n"); 1402 dev_dbg(&isp->client->dev, "peripheral sessions not allowed\n");
1412 return -EINVAL; 1403 return -EINVAL;
1413#endif 1404#endif
1414} 1405}
@@ -1508,12 +1499,10 @@ isp1301_start_hnp(struct otg_transceiver *dev)
1508 1499
1509/*-------------------------------------------------------------------------*/ 1500/*-------------------------------------------------------------------------*/
1510 1501
1511/* no error returns, they'd just make bus scanning stop */ 1502static int __init isp1301_probe(struct i2c_client *i2c)
1512static int isp1301_probe(struct i2c_adapter *bus, int address, int kind)
1513{ 1503{
1514 int status; 1504 int status;
1515 struct isp1301 *isp; 1505 struct isp1301 *isp;
1516 struct i2c_client *i2c;
1517 1506
1518 if (the_transceiver) 1507 if (the_transceiver)
1519 return 0; 1508 return 0;
@@ -1527,37 +1516,19 @@ static int isp1301_probe(struct i2c_adapter *bus, int address, int kind)
1527 isp->timer.function = isp1301_timer; 1516 isp->timer.function = isp1301_timer;
1528 isp->timer.data = (unsigned long) isp; 1517 isp->timer.data = (unsigned long) isp;
1529 1518
1530 isp->irq = -1; 1519 i2c_set_clientdata(i2c, isp);
1531 isp->client.addr = address; 1520 isp->client = i2c;
1532 i2c_set_clientdata(&isp->client, isp);
1533 isp->client.adapter = bus;
1534 isp->client.driver = &isp1301_driver;
1535 strlcpy(isp->client.name, DRIVER_NAME, I2C_NAME_SIZE);
1536 i2c = &isp->client;
1537
1538 /* if this is a true probe, verify the chip ... */
1539 if (kind < 0) {
1540 status = isp1301_get_u16(isp, ISP1301_VENDOR_ID);
1541 if (status != I2C_VENDOR_ID_PHILIPS) {
1542 dev_dbg(&bus->dev, "addr %d not philips id: %d\n",
1543 address, status);
1544 goto fail1;
1545 }
1546 status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID);
1547 if (status != I2C_PRODUCT_ID_PHILIPS_1301) {
1548 dev_dbg(&bus->dev, "%d not isp1301, %d\n",
1549 address, status);
1550 goto fail1;
1551 }
1552 }
1553 1521
1554 status = i2c_attach_client(i2c); 1522 /* verify the chip (shouldn't be necesary) */
1555 if (status < 0) { 1523 status = isp1301_get_u16(isp, ISP1301_VENDOR_ID);
1556 dev_dbg(&bus->dev, "can't attach %s to device %d, err %d\n", 1524 if (status != I2C_VENDOR_ID_PHILIPS) {
1557 DRIVER_NAME, address, status); 1525 dev_dbg(&i2c->dev, "not philips id: %d\n", status);
1558fail1: 1526 goto fail;
1559 kfree(isp); 1527 }
1560 return 0; 1528 status = isp1301_get_u16(isp, ISP1301_PRODUCT_ID);
1529 if (status != I2C_PRODUCT_ID_PHILIPS_1301) {
1530 dev_dbg(&i2c->dev, "not isp1301, %d\n", status);
1531 goto fail;
1561 } 1532 }
1562 isp->i2c_release = i2c->dev.release; 1533 isp->i2c_release = i2c->dev.release;
1563 i2c->dev.release = isp1301_release; 1534 i2c->dev.release = isp1301_release;
@@ -1586,7 +1557,7 @@ fail1:
1586 status = otg_bind(isp); 1557 status = otg_bind(isp);
1587 if (status < 0) { 1558 if (status < 0) {
1588 dev_dbg(&i2c->dev, "can't bind OTG\n"); 1559 dev_dbg(&i2c->dev, "can't bind OTG\n");
1589 goto fail2; 1560 goto fail;
1590 } 1561 }
1591#endif 1562#endif
1592 1563
@@ -1599,26 +1570,21 @@ fail1:
1599 1570
1600 /* IRQ wired at M14 */ 1571 /* IRQ wired at M14 */
1601 omap_cfg_reg(M14_1510_GPIO2); 1572 omap_cfg_reg(M14_1510_GPIO2);
1602 isp->irq = OMAP_GPIO_IRQ(2);
1603 if (gpio_request(2, "isp1301") == 0) 1573 if (gpio_request(2, "isp1301") == 0)
1604 gpio_direction_input(2); 1574 gpio_direction_input(2);
1605 isp->irq_type = IRQF_TRIGGER_FALLING; 1575 isp->irq_type = IRQF_TRIGGER_FALLING;
1606 } 1576 }
1607 1577
1608 isp->irq_type |= IRQF_SAMPLE_RANDOM; 1578 isp->irq_type |= IRQF_SAMPLE_RANDOM;
1609 status = request_irq(isp->irq, isp1301_irq, 1579 status = request_irq(i2c->irq, isp1301_irq,
1610 isp->irq_type, DRIVER_NAME, isp); 1580 isp->irq_type, DRIVER_NAME, isp);
1611 if (status < 0) { 1581 if (status < 0) {
1612 dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n", 1582 dev_dbg(&i2c->dev, "can't get IRQ %d, err %d\n",
1613 isp->irq, status); 1583 i2c->irq, status);
1614#ifdef CONFIG_USB_OTG 1584 goto fail;
1615fail2:
1616#endif
1617 i2c_detach_client(i2c);
1618 goto fail1;
1619 } 1585 }
1620 1586
1621 isp->otg.dev = &isp->client.dev; 1587 isp->otg.dev = &i2c->dev;
1622 isp->otg.label = DRIVER_NAME; 1588 isp->otg.label = DRIVER_NAME;
1623 1589
1624 isp->otg.set_host = isp1301_set_host, 1590 isp->otg.set_host = isp1301_set_host,
@@ -1649,22 +1615,25 @@ fail2:
1649 status); 1615 status);
1650 1616
1651 return 0; 1617 return 0;
1652}
1653 1618
1654static int isp1301_scan_bus(struct i2c_adapter *bus) 1619fail:
1655{ 1620 kfree(isp);
1656 if (!i2c_check_functionality(bus, I2C_FUNC_SMBUS_BYTE_DATA 1621 return -ENODEV;
1657 | I2C_FUNC_SMBUS_READ_WORD_DATA))
1658 return -EINVAL;
1659 return i2c_probe(bus, &addr_data, isp1301_probe);
1660} 1622}
1661 1623
1624static const struct i2c_device_id isp1301_id[] = {
1625 { "isp1301_omap", 0 },
1626 { }
1627};
1628MODULE_DEVICE_TABLE(i2c, isp1301_id);
1629
1662static struct i2c_driver isp1301_driver = { 1630static struct i2c_driver isp1301_driver = {
1663 .driver = { 1631 .driver = {
1664 .name = "isp1301_omap", 1632 .name = "isp1301_omap",
1665 }, 1633 },
1666 .attach_adapter = isp1301_scan_bus, 1634 .probe = isp1301_probe,
1667 .detach_client = isp1301_detach_client, 1635 .remove = __exit_p(isp1301_remove),
1636 .id_table = isp1301_id,
1668}; 1637};
1669 1638
1670/*-------------------------------------------------------------------------*/ 1639/*-------------------------------------------------------------------------*/
diff --git a/drivers/i2c/chips/mcu_mpc8349emitx.c b/drivers/i2c/chips/mcu_mpc8349emitx.c
new file mode 100644
index 000000000000..82a9bcb858b6
--- /dev/null
+++ b/drivers/i2c/chips/mcu_mpc8349emitx.c
@@ -0,0 +1,209 @@
1/*
2 * Power Management and GPIO expander driver for MPC8349E-mITX-compatible MCU
3 *
4 * Copyright (c) 2008 MontaVista Software, Inc.
5 *
6 * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
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
14#include <linux/init.h>
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/device.h>
18#include <linux/mutex.h>
19#include <linux/i2c.h>
20#include <linux/gpio.h>
21#include <linux/of.h>
22#include <linux/of_gpio.h>
23#include <asm/prom.h>
24#include <asm/machdep.h>
25
26/*
27 * I don't have specifications for the MCU firmware, I found this register
28 * and bits positions by the trial&error method.
29 */
30#define MCU_REG_CTRL 0x20
31#define MCU_CTRL_POFF 0x40
32
33#define MCU_NUM_GPIO 2
34
35struct mcu {
36 struct mutex lock;
37 struct device_node *np;
38 struct i2c_client *client;
39 struct of_gpio_chip of_gc;
40 u8 reg_ctrl;
41};
42
43static struct mcu *glob_mcu;
44
45static void mcu_power_off(void)
46{
47 struct mcu *mcu = glob_mcu;
48
49 pr_info("Sending power-off request to the MCU...\n");
50 mutex_lock(&mcu->lock);
51 i2c_smbus_write_byte_data(glob_mcu->client, MCU_REG_CTRL,
52 mcu->reg_ctrl | MCU_CTRL_POFF);
53 mutex_unlock(&mcu->lock);
54}
55
56static void mcu_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
57{
58 struct of_gpio_chip *of_gc = to_of_gpio_chip(gc);
59 struct mcu *mcu = container_of(of_gc, struct mcu, of_gc);
60 u8 bit = 1 << (4 + gpio);
61
62 mutex_lock(&mcu->lock);
63 if (val)
64 mcu->reg_ctrl &= ~bit;
65 else
66 mcu->reg_ctrl |= bit;
67
68 i2c_smbus_write_byte_data(mcu->client, MCU_REG_CTRL, mcu->reg_ctrl);
69 mutex_unlock(&mcu->lock);
70}
71
72static int mcu_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
73{
74 mcu_gpio_set(gc, gpio, val);
75 return 0;
76}
77
78static int mcu_gpiochip_add(struct mcu *mcu)
79{
80 struct device_node *np;
81 struct of_gpio_chip *of_gc = &mcu->of_gc;
82 struct gpio_chip *gc = &of_gc->gc;
83 int ret;
84
85 np = of_find_compatible_node(NULL, NULL, "fsl,mcu-mpc8349emitx");
86 if (!np)
87 return -ENODEV;
88
89 gc->owner = THIS_MODULE;
90 gc->label = np->full_name;
91 gc->can_sleep = 1;
92 gc->ngpio = MCU_NUM_GPIO;
93 gc->base = -1;
94 gc->set = mcu_gpio_set;
95 gc->direction_output = mcu_gpio_dir_out;
96 of_gc->gpio_cells = 2;
97 of_gc->xlate = of_gpio_simple_xlate;
98
99 np->data = of_gc;
100 mcu->np = np;
101
102 /*
103 * We don't want to lose the node, its ->data and ->full_name...
104 * So, if succeeded, we don't put the node here.
105 */
106 ret = gpiochip_add(gc);
107 if (ret)
108 of_node_put(np);
109 return ret;
110}
111
112static int mcu_gpiochip_remove(struct mcu *mcu)
113{
114 int ret;
115
116 ret = gpiochip_remove(&mcu->of_gc.gc);
117 if (ret)
118 return ret;
119 of_node_put(mcu->np);
120
121 return 0;
122}
123
124static int __devinit mcu_probe(struct i2c_client *client,
125 const struct i2c_device_id *id)
126{
127 struct mcu *mcu;
128 int ret;
129
130 mcu = kzalloc(sizeof(*mcu), GFP_KERNEL);
131 if (!mcu)
132 return -ENOMEM;
133
134 mutex_init(&mcu->lock);
135 mcu->client = client;
136 i2c_set_clientdata(client, mcu);
137
138 ret = i2c_smbus_read_byte_data(mcu->client, MCU_REG_CTRL);
139 if (ret < 0)
140 goto err;
141 mcu->reg_ctrl = ret;
142
143 ret = mcu_gpiochip_add(mcu);
144 if (ret)
145 goto err;
146
147 /* XXX: this is potentially racy, but there is no lock for ppc_md */
148 if (!ppc_md.power_off) {
149 glob_mcu = mcu;
150 ppc_md.power_off = mcu_power_off;
151 dev_info(&client->dev, "will provide power-off service\n");
152 }
153
154 return 0;
155err:
156 kfree(mcu);
157 return ret;
158}
159
160static int __devexit mcu_remove(struct i2c_client *client)
161{
162 struct mcu *mcu = i2c_get_clientdata(client);
163 int ret;
164
165 if (glob_mcu == mcu) {
166 ppc_md.power_off = NULL;
167 glob_mcu = NULL;
168 }
169
170 ret = mcu_gpiochip_remove(mcu);
171 if (ret)
172 return ret;
173 i2c_set_clientdata(client, NULL);
174 kfree(mcu);
175 return 0;
176}
177
178static const struct i2c_device_id mcu_ids[] = {
179 { "mcu-mpc8349emitx", },
180 {},
181};
182MODULE_DEVICE_TABLE(i2c, mcu_ids);
183
184static struct i2c_driver mcu_driver = {
185 .driver = {
186 .name = "mcu-mpc8349emitx",
187 .owner = THIS_MODULE,
188 },
189 .probe = mcu_probe,
190 .remove = __devexit_p(mcu_remove),
191 .id_table = mcu_ids,
192};
193
194static int __init mcu_init(void)
195{
196 return i2c_add_driver(&mcu_driver);
197}
198module_init(mcu_init);
199
200static void __exit mcu_exit(void)
201{
202 i2c_del_driver(&mcu_driver);
203}
204module_exit(mcu_exit);
205
206MODULE_DESCRIPTION("Power Management and GPIO expander driver for "
207 "MPC8349E-mITX-compatible MCU");
208MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");
209MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index cf02e8fceb42..acf8b9d5f575 100644
--- a/drivers/i2c/chips/tps65010.c
+++ b/drivers/i2c/chips/tps65010.c
@@ -456,14 +456,17 @@ static irqreturn_t tps65010_irq(int irq, void *_tps)
456 456
457/* offsets 0..3 == GPIO1..GPIO4 457/* offsets 0..3 == GPIO1..GPIO4
458 * offsets 4..5 == LED1/nPG, LED2 (we set one of the non-BLINK modes) 458 * offsets 4..5 == LED1/nPG, LED2 (we set one of the non-BLINK modes)
459 * offset 6 == vibrator motor driver
459 */ 460 */
460static void 461static void
461tps65010_gpio_set(struct gpio_chip *chip, unsigned offset, int value) 462tps65010_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
462{ 463{
463 if (offset < 4) 464 if (offset < 4)
464 tps65010_set_gpio_out_value(offset + 1, value); 465 tps65010_set_gpio_out_value(offset + 1, value);
465 else 466 else if (offset < 6)
466 tps65010_set_led(offset - 3, value ? ON : OFF); 467 tps65010_set_led(offset - 3, value ? ON : OFF);
468 else
469 tps65010_set_vib(value);
467} 470}
468 471
469static int 472static int
@@ -477,8 +480,10 @@ tps65010_output(struct gpio_chip *chip, unsigned offset, int value)
477 if (!(tps->outmask & (1 << offset))) 480 if (!(tps->outmask & (1 << offset)))
478 return -EINVAL; 481 return -EINVAL;
479 tps65010_set_gpio_out_value(offset + 1, value); 482 tps65010_set_gpio_out_value(offset + 1, value);
480 } else 483 } else if (offset < 6)
481 tps65010_set_led(offset - 3, value ? ON : OFF); 484 tps65010_set_led(offset - 3, value ? ON : OFF);
485 else
486 tps65010_set_vib(value);
482 487
483 return 0; 488 return 0;
484} 489}
@@ -646,7 +651,7 @@ static int tps65010_probe(struct i2c_client *client,
646 tps->chip.get = tps65010_gpio_get; 651 tps->chip.get = tps65010_gpio_get;
647 652
648 tps->chip.base = board->base; 653 tps->chip.base = board->base;
649 tps->chip.ngpio = 6; 654 tps->chip.ngpio = 7;
650 tps->chip.can_sleep = 1; 655 tps->chip.can_sleep = 1;
651 656
652 status = gpiochip_add(&tps->chip); 657 status = gpiochip_add(&tps->chip);
@@ -675,6 +680,7 @@ static const struct i2c_device_id tps65010_id[] = {
675 { "tps65011", TPS65011 }, 680 { "tps65011", TPS65011 },
676 { "tps65012", TPS65012 }, 681 { "tps65012", TPS65012 },
677 { "tps65013", TPS65013 }, 682 { "tps65013", TPS65013 },
683 { "tps65014", TPS65011 }, /* tps65011 charging at 6.5V max */
678 { } 684 { }
679}; 685};
680MODULE_DEVICE_TABLE(i2c, tps65010_id); 686MODULE_DEVICE_TABLE(i2c, tps65010_id);
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index b346a687ab59..42e852d79ffa 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -437,6 +437,10 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
437{ 437{
438 int res = 0, dummy; 438 int res = 0, dummy;
439 439
440 /* Can't register until after driver model init */
441 if (unlikely(WARN_ON(!i2c_bus_type.p)))
442 return -EAGAIN;
443
440 mutex_init(&adap->bus_lock); 444 mutex_init(&adap->bus_lock);
441 mutex_init(&adap->clist_lock); 445 mutex_init(&adap->clist_lock);
442 INIT_LIST_HEAD(&adap->clients); 446 INIT_LIST_HEAD(&adap->clients);
@@ -696,6 +700,10 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
696{ 700{
697 int res; 701 int res;
698 702
703 /* Can't register until after driver model init */
704 if (unlikely(WARN_ON(!i2c_bus_type.p)))
705 return -EAGAIN;
706
699 /* new style driver methods can't mix with legacy ones */ 707 /* new style driver methods can't mix with legacy ones */
700 if (is_newstyle_driver(driver)) { 708 if (is_newstyle_driver(driver)) {
701 if (driver->attach_adapter || driver->detach_adapter 709 if (driver->attach_adapter || driver->detach_adapter
@@ -978,7 +986,10 @@ static void __exit i2c_exit(void)
978 bus_unregister(&i2c_bus_type); 986 bus_unregister(&i2c_bus_type);
979} 987}
980 988
981subsys_initcall(i2c_init); 989/* We must initialize early, because some subsystems register i2c drivers
990 * in subsys_initcall() code, but are linked (and initialized) before i2c.
991 */
992postcore_initcall(i2c_init);
982module_exit(i2c_exit); 993module_exit(i2c_exit);
983 994
984/* ---------------------------------------------------- 995/* ----------------------------------------------------
@@ -1677,6 +1688,28 @@ s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
1677EXPORT_SYMBOL(i2c_smbus_write_word_data); 1688EXPORT_SYMBOL(i2c_smbus_write_word_data);
1678 1689
1679/** 1690/**
1691 * i2c_smbus_process_call - SMBus "process call" protocol
1692 * @client: Handle to slave device
1693 * @command: Byte interpreted by slave
1694 * @value: 16-bit "word" being written
1695 *
1696 * This executes the SMBus "process call" protocol, returning negative errno
1697 * else a 16-bit unsigned "word" received from the device.
1698 */
1699s32 i2c_smbus_process_call(struct i2c_client *client, u8 command, u16 value)
1700{
1701 union i2c_smbus_data data;
1702 int status;
1703 data.word = value;
1704
1705 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1706 I2C_SMBUS_WRITE, command,
1707 I2C_SMBUS_PROC_CALL, &data);
1708 return (status < 0) ? status : data.word;
1709}
1710EXPORT_SYMBOL(i2c_smbus_process_call);
1711
1712/**
1680 * i2c_smbus_read_block_data - SMBus "block read" protocol 1713 * i2c_smbus_read_block_data - SMBus "block read" protocol
1681 * @client: Handle to slave device 1714 * @client: Handle to slave device
1682 * @command: Byte interpreted by slave 1715 * @command: Byte interpreted by slave
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 307d976c9b69..c171988a9f51 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -521,9 +521,9 @@ static int i2cdev_attach_adapter(struct i2c_adapter *adap)
521 return PTR_ERR(i2c_dev); 521 return PTR_ERR(i2c_dev);
522 522
523 /* register this i2c device with the driver core */ 523 /* register this i2c device with the driver core */
524 i2c_dev->dev = device_create_drvdata(i2c_dev_class, &adap->dev, 524 i2c_dev->dev = device_create(i2c_dev_class, &adap->dev,
525 MKDEV(I2C_MAJOR, adap->nr), 525 MKDEV(I2C_MAJOR, adap->nr), NULL,
526 NULL, "i2c-%d", adap->nr); 526 "i2c-%d", adap->nr);
527 if (IS_ERR(i2c_dev->dev)) { 527 if (IS_ERR(i2c_dev->dev)) {
528 res = PTR_ERR(i2c_dev->dev); 528 res = PTR_ERR(i2c_dev->dev);
529 goto error; 529 goto error;
diff --git a/drivers/ide/Kconfig b/drivers/ide/Kconfig
index b50b5dac95b0..74a369a6116f 100644
--- a/drivers/ide/Kconfig
+++ b/drivers/ide/Kconfig
@@ -4,7 +4,7 @@
4 4
5# Select HAVE_IDE if IDE is supported 5# Select HAVE_IDE if IDE is supported
6config HAVE_IDE 6config HAVE_IDE
7 def_bool n 7 bool
8 8
9menuconfig IDE 9menuconfig IDE
10 tristate "ATA/ATAPI/MFM/RLL support" 10 tristate "ATA/ATAPI/MFM/RLL support"
@@ -54,38 +54,6 @@ menuconfig IDE
54 54
55if IDE 55if IDE
56 56
57config BLK_DEV_IDE
58 tristate "Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support"
59 ---help---
60 If you say Y here, you will use the full-featured IDE driver to
61 control up to ten ATA/IDE interfaces, each being able to serve a
62 "master" and a "slave" device, for a total of up to twenty ATA/IDE
63 disk/cdrom/tape/floppy drives.
64
65 Useful information about large (>540 MB) IDE disks, multiple
66 interfaces, what to do if ATA/IDE devices are not automatically
67 detected, sound card ATA/IDE ports, module support, and other
68 topics, is contained in <file:Documentation/ide/ide.txt>. For detailed
69 information about hard drives, consult the Disk-HOWTO and the
70 Multi-Disk-HOWTO, available from
71 <http://www.tldp.org/docs.html#howto>.
72
73 To fine-tune ATA/IDE drive/interface parameters for improved
74 performance, look for the hdparm package at
75 <ftp://ibiblio.org/pub/Linux/system/hardware/>.
76
77 To compile this driver as a module, choose M here and read
78 <file:Documentation/ide/ide.txt>. The module will be called ide-mod.
79 Do not compile this driver as a module if your root file system (the
80 one containing the directory /) is located on an IDE device.
81
82 If you have one or more IDE drives, say Y or M here. If your system
83 has no IDE drives, or if memory requirements are really tight, you
84 could say N here, and select the "Old hard disk driver" below
85 instead to save about 13 KB of memory in the kernel.
86
87if BLK_DEV_IDE
88
89comment "Please see Documentation/ide/ide.txt for help/info on IDE drives" 57comment "Please see Documentation/ide/ide.txt for help/info on IDE drives"
90 58
91config IDE_TIMINGS 59config IDE_TIMINGS
@@ -348,7 +316,7 @@ config BLK_DEV_IDEPCI
348 316
349config IDEPCI_PCIBUS_ORDER 317config IDEPCI_PCIBUS_ORDER
350 bool "Probe IDE PCI devices in the PCI bus order (DEPRECATED)" 318 bool "Probe IDE PCI devices in the PCI bus order (DEPRECATED)"
351 depends on BLK_DEV_IDE=y && BLK_DEV_IDEPCI 319 depends on IDE=y && BLK_DEV_IDEPCI
352 default y 320 default y
353 help 321 help
354 Probe IDE PCI devices in the order in which they appear on the 322 Probe IDE PCI devices in the order in which they appear on the
@@ -729,7 +697,7 @@ endif
729 697
730config BLK_DEV_IDE_PMAC 698config BLK_DEV_IDE_PMAC
731 tristate "PowerMac on-board IDE support" 699 tristate "PowerMac on-board IDE support"
732 depends on PPC_PMAC && IDE=y && BLK_DEV_IDE=y 700 depends on PPC_PMAC && IDE=y
733 select IDE_TIMINGS 701 select IDE_TIMINGS
734 help 702 help
735 This driver provides support for the on-board IDE controller on 703 This driver provides support for the on-board IDE controller on
@@ -963,6 +931,4 @@ config BLK_DEV_IDEDMA
963 def_bool BLK_DEV_IDEDMA_SFF || BLK_DEV_IDEDMA_PMAC || \ 931 def_bool BLK_DEV_IDEDMA_SFF || BLK_DEV_IDEDMA_PMAC || \
964 BLK_DEV_IDEDMA_ICS || BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA 932 BLK_DEV_IDEDMA_ICS || BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
965 933
966endif
967
968endif # IDE 934endif # IDE
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile
index 308b8a12f314..ceaf779054ea 100644
--- a/drivers/ide/Makefile
+++ b/drivers/ide/Makefile
@@ -5,24 +5,25 @@
5EXTRA_CFLAGS += -Idrivers/ide 5EXTRA_CFLAGS += -Idrivers/ide
6 6
7ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \ 7ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \
8 ide-taskfile.o ide-pio-blacklist.o 8 ide-taskfile.o ide-park.o ide-pio-blacklist.o
9 9
10# core IDE code 10# core IDE code
11ide-core-$(CONFIG_IDE_TIMINGS) += ide-timings.o 11ide-core-$(CONFIG_IDE_TIMINGS) += ide-timings.o
12ide-core-$(CONFIG_IDE_ATAPI) += ide-atapi.o 12ide-core-$(CONFIG_IDE_ATAPI) += ide-atapi.o
13ide-core-$(CONFIG_BLK_DEV_IDEPCI) += setup-pci.o 13ide-core-$(CONFIG_BLK_DEV_IDEPCI) += setup-pci.o
14ide-core-$(CONFIG_BLK_DEV_IDEDMA) += ide-dma.o 14ide-core-$(CONFIG_BLK_DEV_IDEDMA) += ide-dma.o
15ide-core-$(CONFIG_BLK_DEV_IDEDMA_SFF) += ide-dma-sff.o
15ide-core-$(CONFIG_IDE_PROC_FS) += ide-proc.o 16ide-core-$(CONFIG_IDE_PROC_FS) += ide-proc.o
16ide-core-$(CONFIG_BLK_DEV_IDEACPI) += ide-acpi.o 17ide-core-$(CONFIG_BLK_DEV_IDEACPI) += ide-acpi.o
17 18
18obj-$(CONFIG_BLK_DEV_IDE) += ide-core.o 19obj-$(CONFIG_IDE) += ide-core.o
19 20
20ifeq ($(CONFIG_IDE_ARM), y) 21ifeq ($(CONFIG_IDE_ARM), y)
21 ide-arm-core-y += arm/ide_arm.o 22 ide-arm-core-y += arm/ide_arm.o
22 obj-y += ide-arm-core.o 23 obj-y += ide-arm-core.o
23endif 24endif
24 25
25obj-$(CONFIG_BLK_DEV_IDE) += legacy/ pci/ 26obj-$(CONFIG_IDE) += legacy/ pci/
26 27
27obj-$(CONFIG_IDEPCI_PCIBUS_ORDER) += ide-scan-pci.o 28obj-$(CONFIG_IDEPCI_PCIBUS_ORDER) += ide-scan-pci.o
28 29
@@ -31,15 +32,21 @@ ifeq ($(CONFIG_BLK_DEV_CMD640), y)
31 obj-y += cmd640-core.o 32 obj-y += cmd640-core.o
32endif 33endif
33 34
34obj-$(CONFIG_BLK_DEV_IDE) += ppc/ 35obj-$(CONFIG_IDE) += ppc/
35obj-$(CONFIG_IDE_H8300) += h8300/ 36obj-$(CONFIG_IDE_H8300) += h8300/
36obj-$(CONFIG_IDE_GENERIC) += ide-generic.o 37obj-$(CONFIG_IDE_GENERIC) += ide-generic.o
37obj-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o 38obj-$(CONFIG_BLK_DEV_IDEPNP) += ide-pnp.o
38 39
40ide-disk_mod-y += ide-disk.o ide-disk_ioctl.o
39ide-cd_mod-y += ide-cd.o ide-cd_ioctl.o ide-cd_verbose.o 41ide-cd_mod-y += ide-cd.o ide-cd_ioctl.o ide-cd_verbose.o
40ide-floppy_mod-y += ide-floppy.o ide-floppy_ioctl.o 42ide-floppy_mod-y += ide-floppy.o ide-floppy_ioctl.o
41 43
42obj-$(CONFIG_BLK_DEV_IDEDISK) += ide-disk.o 44ifeq ($(CONFIG_IDE_PROC_FS), y)
45 ide-disk_mod-y += ide-disk_proc.o
46 ide-floppy_mod-y += ide-floppy_proc.o
47endif
48
49obj-$(CONFIG_BLK_DEV_IDEDISK) += ide-disk_mod.o
43obj-$(CONFIG_BLK_DEV_IDECD) += ide-cd_mod.o 50obj-$(CONFIG_BLK_DEV_IDECD) += ide-cd_mod.o
44obj-$(CONFIG_BLK_DEV_IDEFLOPPY) += ide-floppy_mod.o 51obj-$(CONFIG_BLK_DEV_IDEFLOPPY) += ide-floppy_mod.o
45obj-$(CONFIG_BLK_DEV_IDETAPE) += ide-tape.o 52obj-$(CONFIG_BLK_DEV_IDETAPE) += ide-tape.o
@@ -54,4 +61,4 @@ ifeq ($(CONFIG_BLK_DEV_PLATFORM), y)
54 obj-y += ide-platform-core.o 61 obj-y += ide-platform-core.o
55endif 62endif
56 63
57obj-$(CONFIG_BLK_DEV_IDE) += arm/ mips/ 64obj-$(CONFIG_IDE) += arm/ mips/
diff --git a/drivers/ide/arm/icside.c b/drivers/ide/arm/icside.c
index 70f5b164828b..76bdc9a27f6f 100644
--- a/drivers/ide/arm/icside.c
+++ b/drivers/ide/arm/icside.c
@@ -372,25 +372,6 @@ static int icside_dma_test_irq(ide_drive_t *drive)
372 ICS_ARCIN_V6_INTRSTAT_1)) & 1; 372 ICS_ARCIN_V6_INTRSTAT_1)) & 1;
373} 373}
374 374
375static void icside_dma_timeout(ide_drive_t *drive)
376{
377 ide_hwif_t *hwif = drive->hwif;
378
379 printk(KERN_ERR "%s: DMA timeout occurred: ", drive->name);
380
381 if (icside_dma_test_irq(drive))
382 return;
383
384 ide_dump_status(drive, "DMA timeout", hwif->tp_ops->read_status(hwif));
385
386 icside_dma_end(drive);
387}
388
389static void icside_dma_lost_irq(ide_drive_t *drive)
390{
391 printk(KERN_ERR "%s: IRQ lost\n", drive->name);
392}
393
394static int icside_dma_init(ide_hwif_t *hwif, const struct ide_port_info *d) 375static int icside_dma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
395{ 376{
396 hwif->dmatable_cpu = NULL; 377 hwif->dmatable_cpu = NULL;
@@ -406,8 +387,8 @@ static const struct ide_dma_ops icside_v6_dma_ops = {
406 .dma_start = icside_dma_start, 387 .dma_start = icside_dma_start,
407 .dma_end = icside_dma_end, 388 .dma_end = icside_dma_end,
408 .dma_test_irq = icside_dma_test_irq, 389 .dma_test_irq = icside_dma_test_irq,
409 .dma_timeout = icside_dma_timeout, 390 .dma_timeout = ide_dma_timeout,
410 .dma_lost_irq = icside_dma_lost_irq, 391 .dma_lost_irq = ide_dma_lost_irq,
411}; 392};
412#else 393#else
413#define icside_v6_dma_ops NULL 394#define icside_v6_dma_ops NULL
diff --git a/drivers/ide/h8300/ide-h8300.c b/drivers/ide/h8300/ide-h8300.c
index bde7a585f198..e2cdd2e9cdec 100644
--- a/drivers/ide/h8300/ide-h8300.c
+++ b/drivers/ide/h8300/ide-h8300.c
@@ -80,7 +80,7 @@ static void h8300_tf_load(ide_drive_t *drive, ide_task_t *task)
80 outb(tf->lbah, io_ports->lbah_addr); 80 outb(tf->lbah, io_ports->lbah_addr);
81 81
82 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) 82 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
83 outb((tf->device & HIHI) | drive->select.all, 83 outb((tf->device & HIHI) | drive->select,
84 io_ports->device_addr); 84 io_ports->device_addr);
85} 85}
86 86
diff --git a/drivers/ide/ide-acpi.c b/drivers/ide/ide-acpi.c
index 2427c380b3dc..244a8a052ce8 100644
--- a/drivers/ide/ide-acpi.c
+++ b/drivers/ide/ide-acpi.c
@@ -290,7 +290,7 @@ static int do_drive_get_GTF(ide_drive_t *drive,
290 DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n", 290 DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n",
291 hwif->name, dev->bus_id, port, hwif->channel); 291 hwif->name, dev->bus_id, port, hwif->channel);
292 292
293 if (!drive->present) { 293 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) {
294 DEBPRINT("%s drive %d:%d not present\n", 294 DEBPRINT("%s drive %d:%d not present\n",
295 hwif->name, hwif->channel, port); 295 hwif->name, hwif->channel, port);
296 goto out; 296 goto out;
@@ -420,8 +420,9 @@ static int do_drive_set_taskfiles(ide_drive_t *drive,
420 420
421 DEBPRINT("ENTER: %s, hard_port#: %d\n", drive->name, drive->dn); 421 DEBPRINT("ENTER: %s, hard_port#: %d\n", drive->name, drive->dn);
422 422
423 if (!drive->present) 423 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
424 goto out; 424 goto out;
425
425 if (!gtf_count) /* shouldn't be here */ 426 if (!gtf_count) /* shouldn't be here */
426 goto out; 427 goto out;
427 428
@@ -660,7 +661,8 @@ void ide_acpi_set_state(ide_hwif_t *hwif, int on)
660 if (!drive->acpidata->obj_handle) 661 if (!drive->acpidata->obj_handle)
661 drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive); 662 drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
662 663
663 if (drive->acpidata->obj_handle && drive->present) { 664 if (drive->acpidata->obj_handle &&
665 (drive->dev_flags & IDE_DFLAG_PRESENT)) {
664 acpi_bus_set_power(drive->acpidata->obj_handle, 666 acpi_bus_set_power(drive->acpidata->obj_handle,
665 on? ACPI_STATE_D0: ACPI_STATE_D3); 667 on? ACPI_STATE_D0: ACPI_STATE_D3);
666 } 668 }
@@ -720,7 +722,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
720 722
721 memset(drive->acpidata, 0, sizeof(*drive->acpidata)); 723 memset(drive->acpidata, 0, sizeof(*drive->acpidata));
722 724
723 if (!drive->present) 725 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
724 continue; 726 continue;
725 727
726 err = taskfile_lib_get_identify(drive, drive->acpidata->idbuff); 728 err = taskfile_lib_get_identify(drive, drive->acpidata->idbuff);
@@ -745,7 +747,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
745 for (i = 0; i < MAX_DRIVES; i++) { 747 for (i = 0; i < MAX_DRIVES; i++) {
746 drive = &hwif->drives[i]; 748 drive = &hwif->drives[i];
747 749
748 if (drive->present) 750 if (drive->dev_flags & IDE_DFLAG_PRESENT)
749 /* Execute ACPI startup code */ 751 /* Execute ACPI startup code */
750 ide_acpi_exec_tfs(drive); 752 ide_acpi_exec_tfs(drive);
751 } 753 }
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c
index 608c5bade929..2e305714c209 100644
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -124,8 +124,8 @@ EXPORT_SYMBOL_GPL(ide_init_pc);
124 * the current request, so that it will be processed immediately, on the next 124 * the current request, so that it will be processed immediately, on the next
125 * pass through the driver. 125 * pass through the driver.
126 */ 126 */
127void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk, 127static void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
128 struct ide_atapi_pc *pc, struct request *rq) 128 struct ide_atapi_pc *pc, struct request *rq)
129{ 129{
130 blk_rq_init(NULL, rq); 130 blk_rq_init(NULL, rq);
131 rq->cmd_type = REQ_TYPE_SPECIAL; 131 rq->cmd_type = REQ_TYPE_SPECIAL;
@@ -137,7 +137,6 @@ void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
137 rq->cmd[13] = REQ_IDETAPE_PC1; 137 rq->cmd[13] = REQ_IDETAPE_PC1;
138 ide_do_drive_cmd(drive, rq); 138 ide_do_drive_cmd(drive, rq);
139} 139}
140EXPORT_SYMBOL_GPL(ide_queue_pc_head);
141 140
142/* 141/*
143 * Add a special packet command request to the tail of the request queue, 142 * Add a special packet command request to the tail of the request queue,
@@ -203,25 +202,80 @@ int ide_set_media_lock(ide_drive_t *drive, struct gendisk *disk, int on)
203} 202}
204EXPORT_SYMBOL_GPL(ide_set_media_lock); 203EXPORT_SYMBOL_GPL(ide_set_media_lock);
205 204
206/* TODO: unify the code thus making some arguments go away */ 205void ide_create_request_sense_cmd(ide_drive_t *drive, struct ide_atapi_pc *pc)
207ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
208 ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry,
209 void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *),
210 void (*retry_pc)(ide_drive_t *), void (*dsc_handle)(ide_drive_t *),
211 int (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned, int))
212{ 206{
207 ide_init_pc(pc);
208 pc->c[0] = REQUEST_SENSE;
209 if (drive->media == ide_floppy) {
210 pc->c[4] = 255;
211 pc->req_xfer = 18;
212 } else {
213 pc->c[4] = 20;
214 pc->req_xfer = 20;
215 }
216}
217EXPORT_SYMBOL_GPL(ide_create_request_sense_cmd);
218
219/*
220 * Called when an error was detected during the last packet command.
221 * We queue a request sense packet command in the head of the request list.
222 */
223void ide_retry_pc(ide_drive_t *drive, struct gendisk *disk)
224{
225 struct request *rq = &drive->request_sense_rq;
226 struct ide_atapi_pc *pc = &drive->request_sense_pc;
227
228 (void)ide_read_error(drive);
229 ide_create_request_sense_cmd(drive, pc);
230 if (drive->media == ide_tape)
231 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
232 ide_queue_pc_head(drive, disk, pc, rq);
233}
234EXPORT_SYMBOL_GPL(ide_retry_pc);
235
236int ide_scsi_expiry(ide_drive_t *drive)
237{
238 struct ide_atapi_pc *pc = drive->pc;
239
240 debug_log("%s called for %lu at %lu\n", __func__,
241 pc->scsi_cmd->serial_number, jiffies);
242
243 pc->flags |= PC_FLAG_TIMEDOUT;
244
245 return 0; /* we do not want the IDE subsystem to retry */
246}
247EXPORT_SYMBOL_GPL(ide_scsi_expiry);
248
249/*
250 * This is the usual interrupt handler which will be called during a packet
251 * command. We will transfer some of the data (as requested by the drive)
252 * and will re-point interrupt handler to us.
253 */
254static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
255{
256 struct ide_atapi_pc *pc = drive->pc;
213 ide_hwif_t *hwif = drive->hwif; 257 ide_hwif_t *hwif = drive->hwif;
214 struct request *rq = hwif->hwgroup->rq; 258 struct request *rq = hwif->hwgroup->rq;
215 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 259 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
216 xfer_func_t *xferfunc; 260 xfer_func_t *xferfunc;
217 unsigned int temp; 261 ide_expiry_t *expiry;
262 unsigned int timeout, temp;
218 u16 bcount; 263 u16 bcount;
219 u8 stat, ireason, scsi = drive->scsi; 264 u8 stat, ireason, scsi = !!(drive->dev_flags & IDE_DFLAG_SCSI), dsc = 0;
220 265
221 debug_log("Enter %s - interrupt handler\n", __func__); 266 debug_log("Enter %s - interrupt handler\n", __func__);
222 267
268 if (scsi) {
269 timeout = ide_scsi_get_timeout(pc);
270 expiry = ide_scsi_expiry;
271 } else {
272 timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
273 : WAIT_TAPE_CMD;
274 expiry = NULL;
275 }
276
223 if (pc->flags & PC_FLAG_TIMEDOUT) { 277 if (pc->flags & PC_FLAG_TIMEDOUT) {
224 drive->pc_callback(drive); 278 drive->pc_callback(drive, 0);
225 return ide_stopped; 279 return ide_stopped;
226 } 280 }
227 281
@@ -238,8 +292,8 @@ ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
238 pc->flags |= PC_FLAG_DMA_ERROR; 292 pc->flags |= PC_FLAG_DMA_ERROR;
239 } else { 293 } else {
240 pc->xferred = pc->req_xfer; 294 pc->xferred = pc->req_xfer;
241 if (update_buffers) 295 if (drive->pc_update_buffers)
242 update_buffers(drive, pc); 296 drive->pc_update_buffers(drive, pc);
243 } 297 }
244 debug_log("%s: DMA finished\n", drive->name); 298 debug_log("%s: DMA finished\n", drive->name);
245 } 299 }
@@ -276,21 +330,19 @@ ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
276 debug_log("[cmd %x]: check condition\n", rq->cmd[0]); 330 debug_log("[cmd %x]: check condition\n", rq->cmd[0]);
277 331
278 /* Retry operation */ 332 /* Retry operation */
279 retry_pc(drive); 333 ide_retry_pc(drive, rq->rq_disk);
280 334
281 /* queued, but not started */ 335 /* queued, but not started */
282 return ide_stopped; 336 return ide_stopped;
283 } 337 }
284cmd_finished: 338cmd_finished:
285 pc->error = 0; 339 pc->error = 0;
286 if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && 340
287 (stat & ATA_DSC) == 0) { 341 if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0)
288 dsc_handle(drive); 342 dsc = 1;
289 return ide_stopped;
290 }
291 343
292 /* Command finished - Call the callback function */ 344 /* Command finished - Call the callback function */
293 drive->pc_callback(drive); 345 drive->pc_callback(drive, dsc);
294 346
295 return ide_stopped; 347 return ide_stopped;
296 } 348 }
@@ -336,7 +388,8 @@ cmd_finished:
336 temp = 0; 388 temp = 0;
337 if (temp) { 389 if (temp) {
338 if (pc->sg) 390 if (pc->sg)
339 io_buffers(drive, pc, temp, 0); 391 drive->pc_io_buffers(drive, pc,
392 temp, 0);
340 else 393 else
341 tp_ops->input_data(drive, NULL, 394 tp_ops->input_data(drive, NULL,
342 pc->cur_pos, temp); 395 pc->cur_pos, temp);
@@ -348,9 +401,7 @@ cmd_finished:
348 pc->xferred += temp; 401 pc->xferred += temp;
349 pc->cur_pos += temp; 402 pc->cur_pos += temp;
350 ide_pad_transfer(drive, 0, bcount - temp); 403 ide_pad_transfer(drive, 0, bcount - temp);
351 ide_set_handler(drive, handler, timeout, 404 goto next_irq;
352 expiry);
353 return ide_started;
354 } 405 }
355 debug_log("The device wants to send us more data than " 406 debug_log("The device wants to send us more data than "
356 "expected - allowing transfer\n"); 407 "expected - allowing transfer\n");
@@ -362,7 +413,7 @@ cmd_finished:
362 if ((drive->media == ide_floppy && !scsi && !pc->buf) || 413 if ((drive->media == ide_floppy && !scsi && !pc->buf) ||
363 (drive->media == ide_tape && !scsi && pc->bh) || 414 (drive->media == ide_tape && !scsi && pc->bh) ||
364 (scsi && pc->sg)) { 415 (scsi && pc->sg)) {
365 int done = io_buffers(drive, pc, bcount, 416 int done = drive->pc_io_buffers(drive, pc, bcount,
366 !!(pc->flags & PC_FLAG_WRITING)); 417 !!(pc->flags & PC_FLAG_WRITING));
367 418
368 /* FIXME: don't do partial completions */ 419 /* FIXME: don't do partial completions */
@@ -377,12 +428,11 @@ cmd_finished:
377 428
378 debug_log("[cmd %x] transferred %d bytes on that intr.\n", 429 debug_log("[cmd %x] transferred %d bytes on that intr.\n",
379 rq->cmd[0], bcount); 430 rq->cmd[0], bcount);
380 431next_irq:
381 /* And set the interrupt handler again */ 432 /* And set the interrupt handler again */
382 ide_set_handler(drive, handler, timeout, expiry); 433 ide_set_handler(drive, ide_pc_intr, timeout, expiry);
383 return ide_started; 434 return ide_started;
384} 435}
385EXPORT_SYMBOL_GPL(ide_pc_intr);
386 436
387static u8 ide_read_ireason(ide_drive_t *drive) 437static u8 ide_read_ireason(ide_drive_t *drive)
388{ 438{
@@ -418,12 +468,22 @@ static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason)
418 return ireason; 468 return ireason;
419} 469}
420 470
421ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc, 471static int ide_delayed_transfer_pc(ide_drive_t *drive)
422 ide_handler_t *handler, unsigned int timeout,
423 ide_expiry_t *expiry)
424{ 472{
473 /* Send the actual packet */
474 drive->hwif->tp_ops->output_data(drive, NULL, drive->pc->c, 12);
475
476 /* Timeout for the packet command */
477 return WAIT_FLOPPY_CMD;
478}
479
480static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
481{
482 struct ide_atapi_pc *pc = drive->pc;
425 ide_hwif_t *hwif = drive->hwif; 483 ide_hwif_t *hwif = drive->hwif;
426 struct request *rq = hwif->hwgroup->rq; 484 struct request *rq = hwif->hwgroup->rq;
485 ide_expiry_t *expiry;
486 unsigned int timeout;
427 ide_startstop_t startstop; 487 ide_startstop_t startstop;
428 u8 ireason; 488 u8 ireason;
429 489
@@ -434,7 +494,8 @@ ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
434 } 494 }
435 495
436 ireason = ide_read_ireason(drive); 496 ireason = ide_read_ireason(drive);
437 if (drive->media == ide_tape && !drive->scsi) 497 if (drive->media == ide_tape &&
498 (drive->dev_flags & IDE_DFLAG_SCSI) == 0)
438 ireason = ide_wait_ireason(drive, ireason); 499 ireason = ide_wait_ireason(drive, ireason);
439 500
440 if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) { 501 if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) {
@@ -443,8 +504,27 @@ ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
443 return ide_do_reset(drive); 504 return ide_do_reset(drive);
444 } 505 }
445 506
507 /*
508 * If necessary schedule the packet transfer to occur 'timeout'
509 * miliseconds later in ide_delayed_transfer_pc() after the device
510 * says it's ready for a packet.
511 */
512 if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) {
513 timeout = drive->pc_delay;
514 expiry = &ide_delayed_transfer_pc;
515 } else {
516 if (drive->dev_flags & IDE_DFLAG_SCSI) {
517 timeout = ide_scsi_get_timeout(pc);
518 expiry = ide_scsi_expiry;
519 } else {
520 timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
521 : WAIT_TAPE_CMD;
522 expiry = NULL;
523 }
524 }
525
446 /* Set the interrupt routine */ 526 /* Set the interrupt routine */
447 ide_set_handler(drive, handler, timeout, expiry); 527 ide_set_handler(drive, ide_pc_intr, timeout, expiry);
448 528
449 /* Begin DMA, if necessary */ 529 /* Begin DMA, if necessary */
450 if (pc->flags & PC_FLAG_DMA_OK) { 530 if (pc->flags & PC_FLAG_DMA_OK) {
@@ -458,22 +538,22 @@ ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
458 538
459 return ide_started; 539 return ide_started;
460} 540}
461EXPORT_SYMBOL_GPL(ide_transfer_pc);
462 541
463ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_atapi_pc *pc, 542ide_startstop_t ide_issue_pc(ide_drive_t *drive, unsigned int timeout,
464 ide_handler_t *handler, unsigned int timeout,
465 ide_expiry_t *expiry) 543 ide_expiry_t *expiry)
466{ 544{
545 struct ide_atapi_pc *pc = drive->pc;
467 ide_hwif_t *hwif = drive->hwif; 546 ide_hwif_t *hwif = drive->hwif;
547 u32 tf_flags;
468 u16 bcount; 548 u16 bcount;
469 u8 dma = 0; 549 u8 scsi = !!(drive->dev_flags & IDE_DFLAG_SCSI);
470 550
471 /* We haven't transferred any data yet */ 551 /* We haven't transferred any data yet */
472 pc->xferred = 0; 552 pc->xferred = 0;
473 pc->cur_pos = pc->buf; 553 pc->cur_pos = pc->buf;
474 554
475 /* Request to transfer the entire buffer at once */ 555 /* Request to transfer the entire buffer at once */
476 if (drive->media == ide_tape && !drive->scsi) 556 if (drive->media == ide_tape && scsi == 0)
477 bcount = pc->req_xfer; 557 bcount = pc->req_xfer;
478 else 558 else
479 bcount = min(pc->req_xfer, 63 * 1024); 559 bcount = min(pc->req_xfer, 63 * 1024);
@@ -483,28 +563,35 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
483 ide_dma_off(drive); 563 ide_dma_off(drive);
484 } 564 }
485 565
486 if ((pc->flags & PC_FLAG_DMA_OK) && drive->using_dma) { 566 if ((pc->flags & PC_FLAG_DMA_OK) &&
487 if (drive->scsi) 567 (drive->dev_flags & IDE_DFLAG_USING_DMA)) {
568 if (scsi)
488 hwif->sg_mapped = 1; 569 hwif->sg_mapped = 1;
489 dma = !hwif->dma_ops->dma_setup(drive); 570 drive->dma = !hwif->dma_ops->dma_setup(drive);
490 if (drive->scsi) 571 if (scsi)
491 hwif->sg_mapped = 0; 572 hwif->sg_mapped = 0;
492 } 573 }
493 574
494 if (!dma) 575 if (!drive->dma)
495 pc->flags &= ~PC_FLAG_DMA_OK; 576 pc->flags &= ~PC_FLAG_DMA_OK;
496 577
497 ide_pktcmd_tf_load(drive, drive->scsi ? 0 : IDE_TFLAG_OUT_DEVICE, 578 if (scsi)
498 bcount, dma); 579 tf_flags = 0;
580 else if (drive->media == ide_cdrom || drive->media == ide_optical)
581 tf_flags = IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL;
582 else
583 tf_flags = IDE_TFLAG_OUT_DEVICE;
584
585 ide_pktcmd_tf_load(drive, tf_flags, bcount, drive->dma);
499 586
500 /* Issue the packet command */ 587 /* Issue the packet command */
501 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { 588 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
502 ide_execute_command(drive, ATA_CMD_PACKET, handler, 589 ide_execute_command(drive, ATA_CMD_PACKET, ide_transfer_pc,
503 timeout, NULL); 590 timeout, NULL);
504 return ide_started; 591 return ide_started;
505 } else { 592 } else {
506 ide_execute_pkt_cmd(drive); 593 ide_execute_pkt_cmd(drive);
507 return (*handler)(drive); 594 return ide_transfer_pc(drive);
508 } 595 }
509} 596}
510EXPORT_SYMBOL_GPL(ide_issue_pc); 597EXPORT_SYMBOL_GPL(ide_issue_pc);
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 465a92ca0179..3308b1cd3a33 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -23,6 +23,9 @@
23 * Documentation/ide/ChangeLog.ide-cd.1994-2004 23 * Documentation/ide/ChangeLog.ide-cd.1994-2004
24 */ 24 */
25 25
26#define DRV_NAME "ide-cd"
27#define PFX DRV_NAME ": "
28
26#define IDECD_VERSION "5.00" 29#define IDECD_VERSION "5.00"
27 30
28#include <linux/module.h> 31#include <linux/module.h>
@@ -50,12 +53,15 @@
50 53
51#include "ide-cd.h" 54#include "ide-cd.h"
52 55
53static DEFINE_MUTEX(idecd_ref_mutex); 56#define IDECD_DEBUG_LOG 1
54 57
55#define to_ide_cd(obj) container_of(obj, struct cdrom_info, kref) 58#if IDECD_DEBUG_LOG
59#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, args)
60#else
61#define ide_debug_log(lvl, fmt, args...) do {} while (0)
62#endif
56 63
57#define ide_cd_g(disk) \ 64static DEFINE_MUTEX(idecd_ref_mutex);
58 container_of((disk)->private_data, struct cdrom_info, driver)
59 65
60static void ide_cd_release(struct kref *); 66static void ide_cd_release(struct kref *);
61 67
@@ -64,7 +70,7 @@ static struct cdrom_info *ide_cd_get(struct gendisk *disk)
64 struct cdrom_info *cd = NULL; 70 struct cdrom_info *cd = NULL;
65 71
66 mutex_lock(&idecd_ref_mutex); 72 mutex_lock(&idecd_ref_mutex);
67 cd = ide_cd_g(disk); 73 cd = ide_drv_g(disk, cdrom_info);
68 if (cd) { 74 if (cd) {
69 if (ide_device_get(cd->drive)) 75 if (ide_device_get(cd->drive))
70 cd = NULL; 76 cd = NULL;
@@ -102,6 +108,9 @@ static int cdrom_log_sense(ide_drive_t *drive, struct request *rq,
102{ 108{
103 int log = 0; 109 int log = 0;
104 110
111 ide_debug_log(IDE_DBG_SENSE, "Call %s, sense_key: 0x%x\n", __func__,
112 sense->sense_key);
113
105 if (!sense || !rq || (rq->cmd_flags & REQ_QUIET)) 114 if (!sense || !rq || (rq->cmd_flags & REQ_QUIET))
106 return 0; 115 return 0;
107 116
@@ -150,6 +159,14 @@ static void cdrom_analyze_sense_data(ide_drive_t *drive,
150 unsigned long bio_sectors; 159 unsigned long bio_sectors;
151 struct cdrom_info *info = drive->driver_data; 160 struct cdrom_info *info = drive->driver_data;
152 161
162 ide_debug_log(IDE_DBG_SENSE, "Call %s, error_code: 0x%x, "
163 "sense_key: 0x%x\n", __func__, sense->error_code,
164 sense->sense_key);
165
166 if (failed_command)
167 ide_debug_log(IDE_DBG_SENSE, "%s: failed cmd: 0x%x\n",
168 __func__, failed_command->cmd[0]);
169
153 if (!cdrom_log_sense(drive, failed_command, sense)) 170 if (!cdrom_log_sense(drive, failed_command, sense))
154 return; 171 return;
155 172
@@ -200,6 +217,8 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
200 struct cdrom_info *info = drive->driver_data; 217 struct cdrom_info *info = drive->driver_data;
201 struct request *rq = &info->request_sense_request; 218 struct request *rq = &info->request_sense_request;
202 219
220 ide_debug_log(IDE_DBG_SENSE, "Call %s\n", __func__);
221
203 if (sense == NULL) 222 if (sense == NULL)
204 sense = &info->sense_data; 223 sense = &info->sense_data;
205 224
@@ -219,6 +238,10 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
219 /* NOTE! Save the failed command in "rq->buffer" */ 238 /* NOTE! Save the failed command in "rq->buffer" */
220 rq->buffer = (void *) failed_command; 239 rq->buffer = (void *) failed_command;
221 240
241 if (failed_command)
242 ide_debug_log(IDE_DBG_SENSE, "failed_cmd: 0x%x\n",
243 failed_command->cmd[0]);
244
222 ide_do_drive_cmd(drive, rq); 245 ide_do_drive_cmd(drive, rq);
223} 246}
224 247
@@ -227,6 +250,10 @@ static void cdrom_end_request(ide_drive_t *drive, int uptodate)
227 struct request *rq = HWGROUP(drive)->rq; 250 struct request *rq = HWGROUP(drive)->rq;
228 int nsectors = rq->hard_cur_sectors; 251 int nsectors = rq->hard_cur_sectors;
229 252
253 ide_debug_log(IDE_DBG_FUNC, "Call %s, cmd: 0x%x, uptodate: 0x%x, "
254 "nsectors: %d\n", __func__, rq->cmd[0], uptodate,
255 nsectors);
256
230 if (blk_sense_request(rq) && uptodate) { 257 if (blk_sense_request(rq) && uptodate) {
231 /* 258 /*
232 * For REQ_TYPE_SENSE, "rq->buffer" points to the original 259 * For REQ_TYPE_SENSE, "rq->buffer" points to the original
@@ -269,6 +296,9 @@ static void cdrom_end_request(ide_drive_t *drive, int uptodate)
269 if (!nsectors) 296 if (!nsectors)
270 nsectors = 1; 297 nsectors = 1;
271 298
299 ide_debug_log(IDE_DBG_FUNC, "Exit %s, uptodate: 0x%x, nsectors: %d\n",
300 __func__, uptodate, nsectors);
301
272 ide_end_request(drive, uptodate, nsectors); 302 ide_end_request(drive, uptodate, nsectors);
273} 303}
274 304
@@ -304,11 +334,15 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
304 sense_key = err >> 4; 334 sense_key = err >> 4;
305 335
306 if (rq == NULL) { 336 if (rq == NULL) {
307 printk(KERN_ERR "%s: missing rq in %s\n", 337 printk(KERN_ERR PFX "%s: missing rq in %s\n",
308 drive->name, __func__); 338 drive->name, __func__);
309 return 1; 339 return 1;
310 } 340 }
311 341
342 ide_debug_log(IDE_DBG_RQ, "%s: stat: 0x%x, good_stat: 0x%x, "
343 "rq->cmd_type: 0x%x, err: 0x%x\n", __func__, stat,
344 good_stat, rq->cmd_type, err);
345
312 if (blk_sense_request(rq)) { 346 if (blk_sense_request(rq)) {
313 /* 347 /*
314 * We got an error trying to get sense info from the drive 348 * We got an error trying to get sense info from the drive
@@ -374,7 +408,8 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
374 cdrom_saw_media_change(drive); 408 cdrom_saw_media_change(drive);
375 409
376 /* fail the request */ 410 /* fail the request */
377 printk(KERN_ERR "%s: tray open\n", drive->name); 411 printk(KERN_ERR PFX "%s: tray open\n",
412 drive->name);
378 do_end_request = 1; 413 do_end_request = 1;
379 } else { 414 } else {
380 struct cdrom_info *info = drive->driver_data; 415 struct cdrom_info *info = drive->driver_data;
@@ -460,7 +495,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
460 if (stat & ATA_ERR) 495 if (stat & ATA_ERR)
461 cdrom_queue_request_sense(drive, NULL, NULL); 496 cdrom_queue_request_sense(drive, NULL, NULL);
462 } else { 497 } else {
463 blk_dump_rq_flags(rq, "ide-cd: bad rq"); 498 blk_dump_rq_flags(rq, PFX "bad rq");
464 cdrom_end_request(drive, 0); 499 cdrom_end_request(drive, 0);
465 } 500 }
466 501
@@ -488,6 +523,9 @@ static int cdrom_timer_expiry(ide_drive_t *drive)
488 struct request *rq = HWGROUP(drive)->rq; 523 struct request *rq = HWGROUP(drive)->rq;
489 unsigned long wait = 0; 524 unsigned long wait = 0;
490 525
526 ide_debug_log(IDE_DBG_RQ, "Call %s: rq->cmd[0]: 0x%x\n", __func__,
527 rq->cmd[0]);
528
491 /* 529 /*
492 * Some commands are *slow* and normally take a long time to complete. 530 * Some commands are *slow* and normally take a long time to complete.
493 * Usually we can use the ATAPI "disconnect" to bypass this, but not all 531 * Usually we can use the ATAPI "disconnect" to bypass this, but not all
@@ -504,7 +542,7 @@ static int cdrom_timer_expiry(ide_drive_t *drive)
504 break; 542 break;
505 default: 543 default:
506 if (!(rq->cmd_flags & REQ_QUIET)) 544 if (!(rq->cmd_flags & REQ_QUIET))
507 printk(KERN_INFO "ide-cd: cmd 0x%x timed out\n", 545 printk(KERN_INFO PFX "cmd 0x%x timed out\n",
508 rq->cmd[0]); 546 rq->cmd[0]);
509 wait = 0; 547 wait = 0;
510 break; 548 break;
@@ -524,20 +562,21 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive,
524 int xferlen, 562 int xferlen,
525 ide_handler_t *handler) 563 ide_handler_t *handler)
526{ 564{
527 struct cdrom_info *info = drive->driver_data;
528 ide_hwif_t *hwif = drive->hwif; 565 ide_hwif_t *hwif = drive->hwif;
529 566
567 ide_debug_log(IDE_DBG_PC, "Call %s, xferlen: %d\n", __func__, xferlen);
568
530 /* FIXME: for Virtual DMA we must check harder */ 569 /* FIXME: for Virtual DMA we must check harder */
531 if (info->dma) 570 if (drive->dma)
532 info->dma = !hwif->dma_ops->dma_setup(drive); 571 drive->dma = !hwif->dma_ops->dma_setup(drive);
533 572
534 /* set up the controller registers */ 573 /* set up the controller registers */
535 ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL, 574 ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL,
536 xferlen, info->dma); 575 xferlen, drive->dma);
537 576
538 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { 577 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
539 /* waiting for CDB interrupt, not DMA yet. */ 578 /* waiting for CDB interrupt, not DMA yet. */
540 if (info->dma) 579 if (drive->dma)
541 drive->waiting_for_dma = 0; 580 drive->waiting_for_dma = 0;
542 581
543 /* packet command */ 582 /* packet command */
@@ -564,9 +603,10 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
564{ 603{
565 ide_hwif_t *hwif = drive->hwif; 604 ide_hwif_t *hwif = drive->hwif;
566 int cmd_len; 605 int cmd_len;
567 struct cdrom_info *info = drive->driver_data;
568 ide_startstop_t startstop; 606 ide_startstop_t startstop;
569 607
608 ide_debug_log(IDE_DBG_PC, "Call %s\n", __func__);
609
570 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { 610 if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
571 /* 611 /*
572 * Here we should have been called after receiving an interrupt 612 * Here we should have been called after receiving an interrupt
@@ -578,7 +618,7 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
578 return ide_stopped; 618 return ide_stopped;
579 619
580 /* ok, next interrupt will be DMA interrupt */ 620 /* ok, next interrupt will be DMA interrupt */
581 if (info->dma) 621 if (drive->dma)
582 drive->waiting_for_dma = 1; 622 drive->waiting_for_dma = 1;
583 } else { 623 } else {
584 /* otherwise, we must wait for DRQ to get set */ 624 /* otherwise, we must wait for DRQ to get set */
@@ -599,7 +639,7 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
599 hwif->tp_ops->output_data(drive, NULL, rq->cmd, cmd_len); 639 hwif->tp_ops->output_data(drive, NULL, rq->cmd, cmd_len);
600 640
601 /* start the DMA if need be */ 641 /* start the DMA if need be */
602 if (info->dma) 642 if (drive->dma)
603 hwif->dma_ops->dma_start(drive); 643 hwif->dma_ops->dma_start(drive);
604 644
605 return ide_started; 645 return ide_started;
@@ -615,6 +655,9 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
615{ 655{
616 ide_hwif_t *hwif = drive->hwif; 656 ide_hwif_t *hwif = drive->hwif;
617 657
658 ide_debug_log(IDE_DBG_FUNC, "Call %s, ireason: 0x%x, rw: 0x%x\n",
659 __func__, ireason, rw);
660
618 /* 661 /*
619 * ireason == 0: the drive wants to receive data from us 662 * ireason == 0: the drive wants to receive data from us
620 * ireason == 2: the drive is expecting to transfer data to us 663 * ireason == 2: the drive is expecting to transfer data to us
@@ -624,7 +667,7 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
624 else if (ireason == (rw << 1)) { 667 else if (ireason == (rw << 1)) {
625 668
626 /* whoops... */ 669 /* whoops... */
627 printk(KERN_ERR "%s: %s: wrong transfer direction!\n", 670 printk(KERN_ERR PFX "%s: %s: wrong transfer direction!\n",
628 drive->name, __func__); 671 drive->name, __func__);
629 672
630 ide_pad_transfer(drive, rw, len); 673 ide_pad_transfer(drive, rw, len);
@@ -637,7 +680,7 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
637 return 0; 680 return 0;
638 } else { 681 } else {
639 /* drive wants a command packet, or invalid ireason... */ 682 /* drive wants a command packet, or invalid ireason... */
640 printk(KERN_ERR "%s: %s: bad interrupt reason 0x%02x\n", 683 printk(KERN_ERR PFX "%s: %s: bad interrupt reason 0x%02x\n",
641 drive->name, __func__, ireason); 684 drive->name, __func__, ireason);
642 } 685 }
643 686
@@ -654,17 +697,19 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
654 */ 697 */
655static int ide_cd_check_transfer_size(ide_drive_t *drive, int len) 698static int ide_cd_check_transfer_size(ide_drive_t *drive, int len)
656{ 699{
700 ide_debug_log(IDE_DBG_FUNC, "Call %s, len: %d\n", __func__, len);
701
657 if ((len % SECTOR_SIZE) == 0) 702 if ((len % SECTOR_SIZE) == 0)
658 return 0; 703 return 0;
659 704
660 printk(KERN_ERR "%s: %s: Bad transfer size %d\n", 705 printk(KERN_ERR PFX "%s: %s: Bad transfer size %d\n", drive->name,
661 drive->name, __func__, len); 706 __func__, len);
662 707
663 if (drive->atapi_flags & IDE_AFLAG_LIMIT_NFRAMES) 708 if (drive->atapi_flags & IDE_AFLAG_LIMIT_NFRAMES)
664 printk(KERN_ERR " This drive is not supported by " 709 printk(KERN_ERR PFX "This drive is not supported by this "
665 "this version of the driver\n"); 710 "version of the driver\n");
666 else { 711 else {
667 printk(KERN_ERR " Trying to limit transfer sizes\n"); 712 printk(KERN_ERR PFX "Trying to limit transfer sizes\n");
668 drive->atapi_flags |= IDE_AFLAG_LIMIT_NFRAMES; 713 drive->atapi_flags |= IDE_AFLAG_LIMIT_NFRAMES;
669 } 714 }
670 715
@@ -676,6 +721,9 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *);
676static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive, 721static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
677 struct request *rq) 722 struct request *rq)
678{ 723{
724 ide_debug_log(IDE_DBG_RQ, "Call %s: rq->cmd_flags: 0x%x\n", __func__,
725 rq->cmd_flags);
726
679 if (rq_data_dir(rq) == READ) { 727 if (rq_data_dir(rq) == READ) {
680 unsigned short sectors_per_frame = 728 unsigned short sectors_per_frame =
681 queue_hardsect_size(drive->queue) >> SECTOR_BITS; 729 queue_hardsect_size(drive->queue) >> SECTOR_BITS;
@@ -695,7 +743,7 @@ static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
695 /* sanity check... */ 743 /* sanity check... */
696 if (rq->current_nr_sectors != 744 if (rq->current_nr_sectors !=
697 bio_cur_sectors(rq->bio)) { 745 bio_cur_sectors(rq->bio)) {
698 printk(KERN_ERR "%s: %s: buffer botch (%u)\n", 746 printk(KERN_ERR PFX "%s: %s: buffer botch (%u)\n",
699 drive->name, __func__, 747 drive->name, __func__,
700 rq->current_nr_sectors); 748 rq->current_nr_sectors);
701 cdrom_end_request(drive, 0); 749 cdrom_end_request(drive, 0);
@@ -704,11 +752,7 @@ static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
704 rq->current_nr_sectors += nskip; 752 rq->current_nr_sectors += nskip;
705 } 753 }
706 } 754 }
707#if 0 755
708 else
709 /* the immediate bit */
710 rq->cmd[1] = 1 << 3;
711#endif
712 /* set up the command */ 756 /* set up the command */
713 rq->timeout = ATAPI_WAIT_PC; 757 rq->timeout = ATAPI_WAIT_PC;
714 758
@@ -739,6 +783,8 @@ static ide_startstop_t cdrom_seek_intr(ide_drive_t *drive)
739 int stat; 783 int stat;
740 static int retry = 10; 784 static int retry = 10;
741 785
786 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
787
742 if (cdrom_decode_status(drive, 0, &stat)) 788 if (cdrom_decode_status(drive, 0, &stat))
743 return ide_stopped; 789 return ide_stopped;
744 790
@@ -746,7 +792,7 @@ static ide_startstop_t cdrom_seek_intr(ide_drive_t *drive)
746 792
747 if (retry && time_after(jiffies, info->start_seek + IDECD_SEEK_TIMER)) { 793 if (retry && time_after(jiffies, info->start_seek + IDECD_SEEK_TIMER)) {
748 if (--retry == 0) 794 if (--retry == 0)
749 drive->dsc_overlap = 0; 795 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
750 } 796 }
751 return ide_stopped; 797 return ide_stopped;
752} 798}
@@ -755,6 +801,8 @@ static void ide_cd_prepare_seek_request(ide_drive_t *drive, struct request *rq)
755{ 801{
756 sector_t frame = rq->sector; 802 sector_t frame = rq->sector;
757 803
804 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
805
758 sector_div(frame, queue_hardsect_size(drive->queue) >> SECTOR_BITS); 806 sector_div(frame, queue_hardsect_size(drive->queue) >> SECTOR_BITS);
759 807
760 memset(rq->cmd, 0, BLK_MAX_CDB); 808 memset(rq->cmd, 0, BLK_MAX_CDB);
@@ -775,8 +823,11 @@ static ide_startstop_t cdrom_start_seek_continuation(ide_drive_t *drive)
775 * Fix up a possibly partially-processed request so that we can start it over 823 * Fix up a possibly partially-processed request so that we can start it over
776 * entirely, or even put it back on the request queue. 824 * entirely, or even put it back on the request queue.
777 */ 825 */
778static void restore_request(struct request *rq) 826static void ide_cd_restore_request(ide_drive_t *drive, struct request *rq)
779{ 827{
828
829 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
830
780 if (rq->buffer != bio_data(rq->bio)) { 831 if (rq->buffer != bio_data(rq->bio)) {
781 sector_t n = 832 sector_t n =
782 (rq->buffer - (char *)bio_data(rq->bio)) / SECTOR_SIZE; 833 (rq->buffer - (char *)bio_data(rq->bio)) / SECTOR_SIZE;
@@ -795,8 +846,11 @@ static void restore_request(struct request *rq)
795/* 846/*
796 * All other packet commands. 847 * All other packet commands.
797 */ 848 */
798static void ide_cd_request_sense_fixup(struct request *rq) 849static void ide_cd_request_sense_fixup(ide_drive_t *drive, struct request *rq)
799{ 850{
851
852 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
853
800 /* 854 /*
801 * Some of the trailing request sense fields are optional, 855 * Some of the trailing request sense fields are optional,
802 * and some drives don't send them. Sigh. 856 * and some drives don't send them. Sigh.
@@ -822,6 +876,10 @@ int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd,
822 if (!sense) 876 if (!sense)
823 sense = &local_sense; 877 sense = &local_sense;
824 878
879 ide_debug_log(IDE_DBG_PC, "Call %s, rq->cmd[0]: 0x%x, write: 0x%x, "
880 "timeout: %d, cmd_flags: 0x%x\n", __func__, cmd[0], write,
881 timeout, cmd_flags);
882
825 /* start of retry loop */ 883 /* start of retry loop */
826 do { 884 do {
827 struct request *rq; 885 struct request *rq;
@@ -895,7 +953,6 @@ static int cdrom_newpc_intr_dummy_cb(struct request *rq)
895static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) 953static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
896{ 954{
897 ide_hwif_t *hwif = drive->hwif; 955 ide_hwif_t *hwif = drive->hwif;
898 struct cdrom_info *info = drive->driver_data;
899 struct request *rq = HWGROUP(drive)->rq; 956 struct request *rq = HWGROUP(drive)->rq;
900 xfer_func_t *xferfunc; 957 xfer_func_t *xferfunc;
901 ide_expiry_t *expiry = NULL; 958 ide_expiry_t *expiry = NULL;
@@ -905,13 +962,16 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
905 u16 len; 962 u16 len;
906 u8 ireason; 963 u8 ireason;
907 964
965 ide_debug_log(IDE_DBG_PC, "Call %s, rq->cmd[0]: 0x%x, write: 0x%x\n",
966 __func__, rq->cmd[0], write);
967
908 /* check for errors */ 968 /* check for errors */
909 dma = info->dma; 969 dma = drive->dma;
910 if (dma) { 970 if (dma) {
911 info->dma = 0; 971 drive->dma = 0;
912 dma_error = hwif->dma_ops->dma_end(drive); 972 dma_error = hwif->dma_ops->dma_end(drive);
913 if (dma_error) { 973 if (dma_error) {
914 printk(KERN_ERR "%s: DMA %s error\n", drive->name, 974 printk(KERN_ERR PFX "%s: DMA %s error\n", drive->name,
915 write ? "write" : "read"); 975 write ? "write" : "read");
916 ide_dma_off(drive); 976 ide_dma_off(drive);
917 } 977 }
@@ -937,6 +997,9 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
937 if (thislen > len) 997 if (thislen > len)
938 thislen = len; 998 thislen = len;
939 999
1000 ide_debug_log(IDE_DBG_PC, "%s: DRQ: stat: 0x%x, thislen: %d\n",
1001 __func__, stat, thislen);
1002
940 /* If DRQ is clear, the command has completed. */ 1003 /* If DRQ is clear, the command has completed. */
941 if ((stat & ATA_DRQ) == 0) { 1004 if ((stat & ATA_DRQ) == 0) {
942 if (blk_fs_request(rq)) { 1005 if (blk_fs_request(rq)) {
@@ -946,7 +1009,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
946 */ 1009 */
947 uptodate = 1; 1010 uptodate = 1;
948 if (rq->current_nr_sectors > 0) { 1011 if (rq->current_nr_sectors > 0) {
949 printk(KERN_ERR "%s: %s: data underrun " 1012 printk(KERN_ERR PFX "%s: %s: data underrun "
950 "(%d blocks)\n", 1013 "(%d blocks)\n",
951 drive->name, __func__, 1014 drive->name, __func__,
952 rq->current_nr_sectors); 1015 rq->current_nr_sectors);
@@ -957,7 +1020,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
957 cdrom_end_request(drive, uptodate); 1020 cdrom_end_request(drive, uptodate);
958 return ide_stopped; 1021 return ide_stopped;
959 } else if (!blk_pc_request(rq)) { 1022 } else if (!blk_pc_request(rq)) {
960 ide_cd_request_sense_fixup(rq); 1023 ide_cd_request_sense_fixup(drive, rq);
961 /* complain if we still have data left to transfer */ 1024 /* complain if we still have data left to transfer */
962 uptodate = rq->data_len ? 0 : 1; 1025 uptodate = rq->data_len ? 0 : 1;
963 } 1026 }
@@ -1000,6 +1063,9 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1000 xferfunc = hwif->tp_ops->input_data; 1063 xferfunc = hwif->tp_ops->input_data;
1001 } 1064 }
1002 1065
1066 ide_debug_log(IDE_DBG_PC, "%s: data transfer, rq->cmd_type: 0x%x, "
1067 "ireason: 0x%x\n", __func__, rq->cmd_type, ireason);
1068
1003 /* transfer data */ 1069 /* transfer data */
1004 while (thislen > 0) { 1070 while (thislen > 0) {
1005 u8 *ptr = blk_fs_request(rq) ? NULL : rq->data; 1071 u8 *ptr = blk_fs_request(rq) ? NULL : rq->data;
@@ -1024,7 +1090,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
1024 */ 1090 */
1025 ide_pad_transfer(drive, 0, thislen); 1091 ide_pad_transfer(drive, 0, thislen);
1026 else { 1092 else {
1027 printk(KERN_ERR "%s: confused, missing data\n", 1093 printk(KERN_ERR PFX "%s: confused, missing data\n",
1028 drive->name); 1094 drive->name);
1029 blk_dump_rq_flags(rq, rq_data_dir(rq) 1095 blk_dump_rq_flags(rq, rq_data_dir(rq)
1030 ? "cdrom_newpc_intr, write" 1096 ? "cdrom_newpc_intr, write"
@@ -1111,6 +1177,9 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
1111 unsigned short sectors_per_frame = 1177 unsigned short sectors_per_frame =
1112 queue_hardsect_size(drive->queue) >> SECTOR_BITS; 1178 queue_hardsect_size(drive->queue) >> SECTOR_BITS;
1113 1179
1180 ide_debug_log(IDE_DBG_RQ, "Call %s, write: 0x%x, secs_per_frame: %u\n",
1181 __func__, write, sectors_per_frame);
1182
1114 if (write) { 1183 if (write) {
1115 /* disk has become write protected */ 1184 /* disk has become write protected */
1116 if (get_disk_ro(cd->disk)) { 1185 if (get_disk_ro(cd->disk)) {
@@ -1122,7 +1191,7 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
1122 * We may be retrying this request after an error. Fix up any 1191 * We may be retrying this request after an error. Fix up any
1123 * weirdness which might be present in the request packet. 1192 * weirdness which might be present in the request packet.
1124 */ 1193 */
1125 restore_request(rq); 1194 ide_cd_restore_request(drive, rq);
1126 } 1195 }
1127 1196
1128 /* use DMA, if possible / writes *must* be hardware frame aligned */ 1197 /* use DMA, if possible / writes *must* be hardware frame aligned */
@@ -1132,9 +1201,9 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
1132 cdrom_end_request(drive, 0); 1201 cdrom_end_request(drive, 0);
1133 return ide_stopped; 1202 return ide_stopped;
1134 } 1203 }
1135 cd->dma = 0; 1204 drive->dma = 0;
1136 } else 1205 } else
1137 cd->dma = drive->using_dma; 1206 drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
1138 1207
1139 if (write) 1208 if (write)
1140 cd->devinfo.media_written = 1; 1209 cd->devinfo.media_written = 1;
@@ -1151,14 +1220,16 @@ static ide_startstop_t cdrom_do_newpc_cont(ide_drive_t *drive)
1151 1220
1152static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq) 1221static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
1153{ 1222{
1154 struct cdrom_info *info = drive->driver_data; 1223
1224 ide_debug_log(IDE_DBG_PC, "Call %s, rq->cmd_type: 0x%x\n", __func__,
1225 rq->cmd_type);
1155 1226
1156 if (blk_pc_request(rq)) 1227 if (blk_pc_request(rq))
1157 rq->cmd_flags |= REQ_QUIET; 1228 rq->cmd_flags |= REQ_QUIET;
1158 else 1229 else
1159 rq->cmd_flags &= ~REQ_FAILED; 1230 rq->cmd_flags &= ~REQ_FAILED;
1160 1231
1161 info->dma = 0; 1232 drive->dma = 0;
1162 1233
1163 /* sg request */ 1234 /* sg request */
1164 if (rq->bio || ((rq->cmd_type == REQ_TYPE_ATA_PC) && rq->data_len)) { 1235 if (rq->bio || ((rq->cmd_type == REQ_TYPE_ATA_PC) && rq->data_len)) {
@@ -1171,7 +1242,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
1171 else 1242 else
1172 buf = rq->data; 1243 buf = rq->data;
1173 1244
1174 info->dma = drive->using_dma; 1245 drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
1175 1246
1176 /* 1247 /*
1177 * check if dma is safe 1248 * check if dma is safe
@@ -1182,7 +1253,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
1182 alignment = queue_dma_alignment(q) | q->dma_pad_mask; 1253 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
1183 if ((unsigned long)buf & alignment || rq->data_len & alignment 1254 if ((unsigned long)buf & alignment || rq->data_len & alignment
1184 || object_is_on_stack(buf)) 1255 || object_is_on_stack(buf))
1185 info->dma = 0; 1256 drive->dma = 0;
1186 } 1257 }
1187} 1258}
1188 1259
@@ -1196,6 +1267,9 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1196 ide_handler_t *fn; 1267 ide_handler_t *fn;
1197 int xferlen; 1268 int xferlen;
1198 1269
1270 ide_debug_log(IDE_DBG_RQ, "Call %s, rq->cmd_type: 0x%x, block: %llu\n",
1271 __func__, rq->cmd_type, (unsigned long long)block);
1272
1199 if (blk_fs_request(rq)) { 1273 if (blk_fs_request(rq)) {
1200 if (drive->atapi_flags & IDE_AFLAG_SEEKING) { 1274 if (drive->atapi_flags & IDE_AFLAG_SEEKING) {
1201 ide_hwif_t *hwif = drive->hwif; 1275 ide_hwif_t *hwif = drive->hwif;
@@ -1208,7 +1282,7 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1208 IDECD_SEEK_TIMER); 1282 IDECD_SEEK_TIMER);
1209 return ide_stopped; 1283 return ide_stopped;
1210 } 1284 }
1211 printk(KERN_ERR "%s: DSC timeout\n", 1285 printk(KERN_ERR PFX "%s: DSC timeout\n",
1212 drive->name); 1286 drive->name);
1213 } 1287 }
1214 drive->atapi_flags &= ~IDE_AFLAG_SEEKING; 1288 drive->atapi_flags &= ~IDE_AFLAG_SEEKING;
@@ -1216,11 +1290,11 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1216 if (rq_data_dir(rq) == READ && 1290 if (rq_data_dir(rq) == READ &&
1217 IDE_LARGE_SEEK(info->last_block, block, 1291 IDE_LARGE_SEEK(info->last_block, block,
1218 IDECD_SEEK_THRESHOLD) && 1292 IDECD_SEEK_THRESHOLD) &&
1219 drive->dsc_overlap) { 1293 (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP)) {
1220 xferlen = 0; 1294 xferlen = 0;
1221 fn = cdrom_start_seek_continuation; 1295 fn = cdrom_start_seek_continuation;
1222 1296
1223 info->dma = 0; 1297 drive->dma = 0;
1224 info->start_seek = jiffies; 1298 info->start_seek = jiffies;
1225 1299
1226 ide_cd_prepare_seek_request(drive, rq); 1300 ide_cd_prepare_seek_request(drive, rq);
@@ -1249,7 +1323,7 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
1249 cdrom_end_request(drive, 1); 1323 cdrom_end_request(drive, 1);
1250 return ide_stopped; 1324 return ide_stopped;
1251 } else { 1325 } else {
1252 blk_dump_rq_flags(rq, "ide-cd bad flags"); 1326 blk_dump_rq_flags(rq, DRV_NAME " bad flags");
1253 cdrom_end_request(drive, 0); 1327 cdrom_end_request(drive, 0);
1254 return ide_stopped; 1328 return ide_stopped;
1255 } 1329 }
@@ -1279,6 +1353,8 @@ int cdrom_check_status(ide_drive_t *drive, struct request_sense *sense)
1279 struct cdrom_device_info *cdi = &info->devinfo; 1353 struct cdrom_device_info *cdi = &info->devinfo;
1280 unsigned char cmd[BLK_MAX_CDB]; 1354 unsigned char cmd[BLK_MAX_CDB];
1281 1355
1356 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1357
1282 memset(cmd, 0, BLK_MAX_CDB); 1358 memset(cmd, 0, BLK_MAX_CDB);
1283 cmd[0] = GPCMD_TEST_UNIT_READY; 1359 cmd[0] = GPCMD_TEST_UNIT_READY;
1284 1360
@@ -1305,6 +1381,8 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
1305 unsigned len = sizeof(capbuf); 1381 unsigned len = sizeof(capbuf);
1306 u32 blocklen; 1382 u32 blocklen;
1307 1383
1384 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1385
1308 memset(cmd, 0, BLK_MAX_CDB); 1386 memset(cmd, 0, BLK_MAX_CDB);
1309 cmd[0] = GPCMD_READ_CDVD_CAPACITY; 1387 cmd[0] = GPCMD_READ_CDVD_CAPACITY;
1310 1388
@@ -1324,10 +1402,10 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
1324 case 4096: 1402 case 4096:
1325 break; 1403 break;
1326 default: 1404 default:
1327 printk(KERN_ERR "%s: weird block size %u\n", 1405 printk(KERN_ERR PFX "%s: weird block size %u\n",
1328 drive->name, blocklen); 1406 drive->name, blocklen);
1329 printk(KERN_ERR "%s: default to 2kb block size\n", 1407 printk(KERN_ERR PFX "%s: default to 2kb block size\n",
1330 drive->name); 1408 drive->name);
1331 blocklen = 2048; 1409 blocklen = 2048;
1332 break; 1410 break;
1333 } 1411 }
@@ -1343,6 +1421,8 @@ static int cdrom_read_tocentry(ide_drive_t *drive, int trackno, int msf_flag,
1343{ 1421{
1344 unsigned char cmd[BLK_MAX_CDB]; 1422 unsigned char cmd[BLK_MAX_CDB];
1345 1423
1424 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1425
1346 memset(cmd, 0, BLK_MAX_CDB); 1426 memset(cmd, 0, BLK_MAX_CDB);
1347 1427
1348 cmd[0] = GPCMD_READ_TOC_PMA_ATIP; 1428 cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
@@ -1371,11 +1451,13 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
1371 long last_written; 1451 long last_written;
1372 unsigned long sectors_per_frame = SECTORS_PER_FRAME; 1452 unsigned long sectors_per_frame = SECTORS_PER_FRAME;
1373 1453
1454 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1455
1374 if (toc == NULL) { 1456 if (toc == NULL) {
1375 /* try to allocate space */ 1457 /* try to allocate space */
1376 toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL); 1458 toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL);
1377 if (toc == NULL) { 1459 if (toc == NULL) {
1378 printk(KERN_ERR "%s: No cdrom TOC buffer!\n", 1460 printk(KERN_ERR PFX "%s: No cdrom TOC buffer!\n",
1379 drive->name); 1461 drive->name);
1380 return -ENOMEM; 1462 return -ENOMEM;
1381 } 1463 }
@@ -1531,6 +1613,8 @@ int ide_cdrom_get_capabilities(ide_drive_t *drive, u8 *buf)
1531 struct packet_command cgc; 1613 struct packet_command cgc;
1532 int stat, attempts = 3, size = ATAPI_CAPABILITIES_PAGE_SIZE; 1614 int stat, attempts = 3, size = ATAPI_CAPABILITIES_PAGE_SIZE;
1533 1615
1616 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1617
1534 if ((drive->atapi_flags & IDE_AFLAG_FULL_CAPS_PAGE) == 0) 1618 if ((drive->atapi_flags & IDE_AFLAG_FULL_CAPS_PAGE) == 0)
1535 size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE; 1619 size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE;
1536 1620
@@ -1549,6 +1633,8 @@ void ide_cdrom_update_speed(ide_drive_t *drive, u8 *buf)
1549 struct cdrom_info *cd = drive->driver_data; 1633 struct cdrom_info *cd = drive->driver_data;
1550 u16 curspeed, maxspeed; 1634 u16 curspeed, maxspeed;
1551 1635
1636 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
1637
1552 if (drive->atapi_flags & IDE_AFLAG_LE_SPEED_FIELDS) { 1638 if (drive->atapi_flags & IDE_AFLAG_LE_SPEED_FIELDS) {
1553 curspeed = le16_to_cpup((__le16 *)&buf[8 + 14]); 1639 curspeed = le16_to_cpup((__le16 *)&buf[8 + 14]);
1554 maxspeed = le16_to_cpup((__le16 *)&buf[8 + 8]); 1640 maxspeed = le16_to_cpup((__le16 *)&buf[8 + 8]);
@@ -1589,6 +1675,8 @@ static int ide_cdrom_register(ide_drive_t *drive, int nslots)
1589 struct cdrom_info *info = drive->driver_data; 1675 struct cdrom_info *info = drive->driver_data;
1590 struct cdrom_device_info *devinfo = &info->devinfo; 1676 struct cdrom_device_info *devinfo = &info->devinfo;
1591 1677
1678 ide_debug_log(IDE_DBG_PROBE, "Call %s, nslots: %d\n", __func__, nslots);
1679
1592 devinfo->ops = &ide_cdrom_dops; 1680 devinfo->ops = &ide_cdrom_dops;
1593 devinfo->speed = info->current_speed; 1681 devinfo->speed = info->current_speed;
1594 devinfo->capacity = nslots; 1682 devinfo->capacity = nslots;
@@ -1610,13 +1698,17 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
1610 mechtype_t mechtype; 1698 mechtype_t mechtype;
1611 int nslots = 1; 1699 int nslots = 1;
1612 1700
1701 ide_debug_log(IDE_DBG_PROBE, "Call %s, drive->media: 0x%x, "
1702 "drive->atapi_flags: 0x%lx\n", __func__, drive->media,
1703 drive->atapi_flags);
1704
1613 cdi->mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R | 1705 cdi->mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R |
1614 CDC_DVD_RAM | CDC_SELECT_DISC | CDC_PLAY_AUDIO | 1706 CDC_DVD_RAM | CDC_SELECT_DISC | CDC_PLAY_AUDIO |
1615 CDC_MO_DRIVE | CDC_RAM); 1707 CDC_MO_DRIVE | CDC_RAM);
1616 1708
1617 if (drive->media == ide_optical) { 1709 if (drive->media == ide_optical) {
1618 cdi->mask &= ~(CDC_MO_DRIVE | CDC_RAM); 1710 cdi->mask &= ~(CDC_MO_DRIVE | CDC_RAM);
1619 printk(KERN_ERR "%s: ATAPI magneto-optical drive\n", 1711 printk(KERN_ERR PFX "%s: ATAPI magneto-optical drive\n",
1620 drive->name); 1712 drive->name);
1621 return nslots; 1713 return nslots;
1622 } 1714 }
@@ -1674,7 +1766,7 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
1674 1766
1675 ide_cdrom_update_speed(drive, buf); 1767 ide_cdrom_update_speed(drive, buf);
1676 1768
1677 printk(KERN_INFO "%s: ATAPI", drive->name); 1769 printk(KERN_INFO PFX "%s: ATAPI", drive->name);
1678 1770
1679 /* don't print speed if the drive reported 0 */ 1771 /* don't print speed if the drive reported 0 */
1680 if (cd->max_speed) 1772 if (cd->max_speed)
@@ -1697,7 +1789,8 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
1697 else 1789 else
1698 printk(KERN_CONT " drive"); 1790 printk(KERN_CONT " drive");
1699 1791
1700 printk(KERN_CONT ", %dkB Cache\n", be16_to_cpup((__be16 *)&buf[8 + 12])); 1792 printk(KERN_CONT ", %dkB Cache\n",
1793 be16_to_cpup((__be16 *)&buf[8 + 12]));
1701 1794
1702 return nslots; 1795 return nslots;
1703} 1796}
@@ -1809,7 +1902,7 @@ static ide_proc_entry_t idecd_proc[] = {
1809 { NULL, 0, NULL, NULL } 1902 { NULL, 0, NULL, NULL }
1810}; 1903};
1811 1904
1812ide_devset_rw_field(dsc_overlap, dsc_overlap); 1905ide_devset_rw_flag(dsc_overlap, IDE_DFLAG_DSC_OVERLAP);
1813 1906
1814static const struct ide_proc_devset idecd_settings[] = { 1907static const struct ide_proc_devset idecd_settings[] = {
1815 IDE_PROC_DEVSET(dsc_overlap, 0, 1), 1908 IDE_PROC_DEVSET(dsc_overlap, 0, 1),
@@ -1884,6 +1977,8 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1884 char *fw_rev = (char *)&id[ATA_ID_FW_REV]; 1977 char *fw_rev = (char *)&id[ATA_ID_FW_REV];
1885 int nslots; 1978 int nslots;
1886 1979
1980 ide_debug_log(IDE_DBG_PROBE, "Call %s\n", __func__);
1981
1887 blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn); 1982 blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn);
1888 blk_queue_dma_alignment(drive->queue, 31); 1983 blk_queue_dma_alignment(drive->queue, 31);
1889 blk_queue_update_dma_pad(drive->queue, 15); 1984 blk_queue_update_dma_pad(drive->queue, 15);
@@ -1891,14 +1986,9 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1891 if (!drive->queue->unplug_delay) 1986 if (!drive->queue->unplug_delay)
1892 drive->queue->unplug_delay = 1; 1987 drive->queue->unplug_delay = 1;
1893 1988
1894 drive->special.all = 0;
1895
1896 drive->atapi_flags = IDE_AFLAG_MEDIA_CHANGED | IDE_AFLAG_NO_EJECT | 1989 drive->atapi_flags = IDE_AFLAG_MEDIA_CHANGED | IDE_AFLAG_NO_EJECT |
1897 ide_cd_flags(id); 1990 ide_cd_flags(id);
1898 1991
1899 if ((id[ATA_ID_CONFIG] & 0x0060) == 0x20)
1900 drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
1901
1902 if ((drive->atapi_flags & IDE_AFLAG_VERTOS_300_SSD) && 1992 if ((drive->atapi_flags & IDE_AFLAG_VERTOS_300_SSD) &&
1903 fw_rev[4] == '1' && fw_rev[6] <= '2') 1993 fw_rev[4] == '1' && fw_rev[6] <= '2')
1904 drive->atapi_flags |= (IDE_AFLAG_TOCTRACKS_AS_BCD | 1994 drive->atapi_flags |= (IDE_AFLAG_TOCTRACKS_AS_BCD |
@@ -1915,10 +2005,13 @@ static int ide_cdrom_setup(ide_drive_t *drive)
1915 /* set correct block size */ 2005 /* set correct block size */
1916 blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE); 2006 blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE);
1917 2007
1918 drive->dsc_overlap = (drive->next != drive); 2008 if (drive->next != drive)
2009 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
2010 else
2011 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
1919 2012
1920 if (ide_cdrom_register(drive, nslots)) { 2013 if (ide_cdrom_register(drive, nslots)) {
1921 printk(KERN_ERR "%s: %s failed to register device with the" 2014 printk(KERN_ERR PFX "%s: %s failed to register device with the"
1922 " cdrom driver.\n", drive->name, __func__); 2015 " cdrom driver.\n", drive->name, __func__);
1923 cd->devinfo.handle = NULL; 2016 cd->devinfo.handle = NULL;
1924 return 1; 2017 return 1;
@@ -1932,6 +2025,8 @@ static void ide_cd_remove(ide_drive_t *drive)
1932{ 2025{
1933 struct cdrom_info *info = drive->driver_data; 2026 struct cdrom_info *info = drive->driver_data;
1934 2027
2028 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
2029
1935 ide_proc_unregister_driver(drive, info->driver); 2030 ide_proc_unregister_driver(drive, info->driver);
1936 2031
1937 del_gendisk(info->disk); 2032 del_gendisk(info->disk);
@@ -1941,15 +2036,17 @@ static void ide_cd_remove(ide_drive_t *drive)
1941 2036
1942static void ide_cd_release(struct kref *kref) 2037static void ide_cd_release(struct kref *kref)
1943{ 2038{
1944 struct cdrom_info *info = to_ide_cd(kref); 2039 struct cdrom_info *info = to_ide_drv(kref, cdrom_info);
1945 struct cdrom_device_info *devinfo = &info->devinfo; 2040 struct cdrom_device_info *devinfo = &info->devinfo;
1946 ide_drive_t *drive = info->drive; 2041 ide_drive_t *drive = info->drive;
1947 struct gendisk *g = info->disk; 2042 struct gendisk *g = info->disk;
1948 2043
2044 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
2045
1949 kfree(info->toc); 2046 kfree(info->toc);
1950 if (devinfo->handle == drive) 2047 if (devinfo->handle == drive)
1951 unregister_cdrom(devinfo); 2048 unregister_cdrom(devinfo);
1952 drive->dsc_overlap = 0; 2049 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
1953 drive->driver_data = NULL; 2050 drive->driver_data = NULL;
1954 blk_queue_prep_rq(drive->queue, NULL); 2051 blk_queue_prep_rq(drive->queue, NULL);
1955 g->private_data = NULL; 2052 g->private_data = NULL;
@@ -1968,7 +2065,6 @@ static ide_driver_t ide_cdrom_driver = {
1968 .probe = ide_cd_probe, 2065 .probe = ide_cd_probe,
1969 .remove = ide_cd_remove, 2066 .remove = ide_cd_remove,
1970 .version = IDECD_VERSION, 2067 .version = IDECD_VERSION,
1971 .media = ide_cdrom,
1972 .do_request = ide_cd_do_request, 2068 .do_request = ide_cd_do_request,
1973 .end_request = ide_end_request, 2069 .end_request = ide_end_request,
1974 .error = __ide_error, 2070 .error = __ide_error,
@@ -1999,7 +2095,7 @@ static int idecd_open(struct inode *inode, struct file *file)
1999static int idecd_release(struct inode *inode, struct file *file) 2095static int idecd_release(struct inode *inode, struct file *file)
2000{ 2096{
2001 struct gendisk *disk = inode->i_bdev->bd_disk; 2097 struct gendisk *disk = inode->i_bdev->bd_disk;
2002 struct cdrom_info *info = ide_cd_g(disk); 2098 struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
2003 2099
2004 cdrom_release(&info->devinfo, file); 2100 cdrom_release(&info->devinfo, file);
2005 2101
@@ -2051,7 +2147,7 @@ static int idecd_ioctl(struct inode *inode, struct file *file,
2051 unsigned int cmd, unsigned long arg) 2147 unsigned int cmd, unsigned long arg)
2052{ 2148{
2053 struct block_device *bdev = inode->i_bdev; 2149 struct block_device *bdev = inode->i_bdev;
2054 struct cdrom_info *info = ide_cd_g(bdev->bd_disk); 2150 struct cdrom_info *info = ide_drv_g(bdev->bd_disk, cdrom_info);
2055 int err; 2151 int err;
2056 2152
2057 switch (cmd) { 2153 switch (cmd) {
@@ -2072,13 +2168,13 @@ static int idecd_ioctl(struct inode *inode, struct file *file,
2072 2168
2073static int idecd_media_changed(struct gendisk *disk) 2169static int idecd_media_changed(struct gendisk *disk)
2074{ 2170{
2075 struct cdrom_info *info = ide_cd_g(disk); 2171 struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
2076 return cdrom_media_changed(&info->devinfo); 2172 return cdrom_media_changed(&info->devinfo);
2077} 2173}
2078 2174
2079static int idecd_revalidate_disk(struct gendisk *disk) 2175static int idecd_revalidate_disk(struct gendisk *disk)
2080{ 2176{
2081 struct cdrom_info *info = ide_cd_g(disk); 2177 struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
2082 struct request_sense sense; 2178 struct request_sense sense;
2083 2179
2084 ide_cd_read_toc(info->drive, &sense); 2180 ide_cd_read_toc(info->drive, &sense);
@@ -2097,8 +2193,11 @@ static struct block_device_operations idecd_ops = {
2097 2193
2098/* module options */ 2194/* module options */
2099static char *ignore; 2195static char *ignore;
2100
2101module_param(ignore, charp, 0400); 2196module_param(ignore, charp, 0400);
2197
2198static unsigned long debug_mask;
2199module_param(debug_mask, ulong, 0644);
2200
2102MODULE_DESCRIPTION("ATAPI CD-ROM Driver"); 2201MODULE_DESCRIPTION("ATAPI CD-ROM Driver");
2103 2202
2104static int ide_cd_probe(ide_drive_t *drive) 2203static int ide_cd_probe(ide_drive_t *drive)
@@ -2107,6 +2206,10 @@ static int ide_cd_probe(ide_drive_t *drive)
2107 struct gendisk *g; 2206 struct gendisk *g;
2108 struct request_sense sense; 2207 struct request_sense sense;
2109 2208
2209 ide_debug_log(IDE_DBG_PROBE, "Call %s, drive->driver_req: %s, "
2210 "drive->media: 0x%x\n", __func__, drive->driver_req,
2211 drive->media);
2212
2110 if (!strstr("ide-cdrom", drive->driver_req)) 2213 if (!strstr("ide-cdrom", drive->driver_req))
2111 goto failed; 2214 goto failed;
2112 2215
@@ -2116,14 +2219,17 @@ static int ide_cd_probe(ide_drive_t *drive)
2116 /* skip drives that we were told to ignore */ 2219 /* skip drives that we were told to ignore */
2117 if (ignore != NULL) { 2220 if (ignore != NULL) {
2118 if (strstr(ignore, drive->name)) { 2221 if (strstr(ignore, drive->name)) {
2119 printk(KERN_INFO "ide-cd: ignoring drive %s\n", 2222 printk(KERN_INFO PFX "ignoring drive %s\n",
2120 drive->name); 2223 drive->name);
2121 goto failed; 2224 goto failed;
2122 } 2225 }
2123 } 2226 }
2227
2228 drive->debug_mask = debug_mask;
2229
2124 info = kzalloc(sizeof(struct cdrom_info), GFP_KERNEL); 2230 info = kzalloc(sizeof(struct cdrom_info), GFP_KERNEL);
2125 if (info == NULL) { 2231 if (info == NULL) {
2126 printk(KERN_ERR "%s: Can't allocate a cdrom structure\n", 2232 printk(KERN_ERR PFX "%s: Can't allocate a cdrom structure\n",
2127 drive->name); 2233 drive->name);
2128 goto failed; 2234 goto failed;
2129 } 2235 }
@@ -2171,6 +2277,7 @@ static void __exit ide_cdrom_exit(void)
2171 2277
2172static int __init ide_cdrom_init(void) 2278static int __init ide_cdrom_init(void)
2173{ 2279{
2280 printk(KERN_INFO DRV_NAME " driver " IDECD_VERSION "\n");
2174 return driver_register(&ide_cdrom_driver.gen_driver); 2281 return driver_register(&ide_cdrom_driver.gen_driver);
2175} 2282}
2176 2283
diff --git a/drivers/ide/ide-cd.h b/drivers/ide/ide-cd.h
index 61a4599b77db..5882b9a9ea8b 100644
--- a/drivers/ide/ide-cd.h
+++ b/drivers/ide/ide-cd.h
@@ -88,7 +88,6 @@ struct cdrom_info {
88 struct request_sense sense_data; 88 struct request_sense sense_data;
89 89
90 struct request request_sense_request; 90 struct request request_sense_request;
91 int dma;
92 unsigned long last_block; 91 unsigned long last_block;
93 unsigned long start_seek; 92 unsigned long start_seek;
94 93
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 01846f244b40..3853bde8eedc 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -45,21 +45,12 @@
45#define IDE_DISK_MINORS 0 45#define IDE_DISK_MINORS 0
46#endif 46#endif
47 47
48struct ide_disk_obj { 48#include "ide-disk.h"
49 ide_drive_t *drive;
50 ide_driver_t *driver;
51 struct gendisk *disk;
52 struct kref kref;
53 unsigned int openers; /* protected by BKL for now */
54};
55 49
56static DEFINE_MUTEX(idedisk_ref_mutex); 50static DEFINE_MUTEX(idedisk_ref_mutex);
57 51
58#define to_ide_disk(obj) container_of(obj, struct ide_disk_obj, kref) 52#define to_ide_disk(obj) container_of(obj, struct ide_disk_obj, kref)
59 53
60#define ide_disk_g(disk) \
61 container_of((disk)->private_data, struct ide_disk_obj, driver)
62
63static void ide_disk_release(struct kref *); 54static void ide_disk_release(struct kref *);
64 55
65static struct ide_disk_obj *ide_disk_get(struct gendisk *disk) 56static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
@@ -140,9 +131,9 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
140 sector_t block) 131 sector_t block)
141{ 132{
142 ide_hwif_t *hwif = HWIF(drive); 133 ide_hwif_t *hwif = HWIF(drive);
143 unsigned int dma = drive->using_dma;
144 u16 nsectors = (u16)rq->nr_sectors; 134 u16 nsectors = (u16)rq->nr_sectors;
145 u8 lba48 = (drive->addressing == 1) ? 1 : 0; 135 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
136 u8 dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
146 ide_task_t task; 137 ide_task_t task;
147 struct ide_taskfile *tf = &task.tf; 138 struct ide_taskfile *tf = &task.tf;
148 ide_startstop_t rc; 139 ide_startstop_t rc;
@@ -162,7 +153,7 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
162 memset(&task, 0, sizeof(task)); 153 memset(&task, 0, sizeof(task));
163 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 154 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
164 155
165 if (drive->select.b.lba) { 156 if (drive->dev_flags & IDE_DFLAG_LBA) {
166 if (lba48) { 157 if (lba48) {
167 pr_debug("%s: LBA=0x%012llx\n", drive->name, 158 pr_debug("%s: LBA=0x%012llx\n", drive->name,
168 (unsigned long long)block); 159 (unsigned long long)block);
@@ -187,6 +178,8 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
187 tf->lbah = block >>= 8; 178 tf->lbah = block >>= 8;
188 tf->device = (block >> 8) & 0xf; 179 tf->device = (block >> 8) & 0xf;
189 } 180 }
181
182 tf->device |= ATA_LBA;
190 } else { 183 } else {
191 unsigned int sect, head, cyl, track; 184 unsigned int sect, head, cyl, track;
192 185
@@ -237,7 +230,7 @@ static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
237{ 230{
238 ide_hwif_t *hwif = HWIF(drive); 231 ide_hwif_t *hwif = HWIF(drive);
239 232
240 BUG_ON(drive->blocked); 233 BUG_ON(drive->dev_flags & IDE_DFLAG_BLOCKED);
241 234
242 if (!blk_fs_request(rq)) { 235 if (!blk_fs_request(rq)) {
243 blk_dump_rq_flags(rq, "ide_do_rw_disk - bad command"); 236 blk_dump_rq_flags(rq, "ide_do_rw_disk - bad command");
@@ -384,139 +377,39 @@ static void idedisk_check_hpa(ide_drive_t *drive)
384static void init_idedisk_capacity(ide_drive_t *drive) 377static void init_idedisk_capacity(ide_drive_t *drive)
385{ 378{
386 u16 *id = drive->id; 379 u16 *id = drive->id;
387 /* 380 int lba;
388 * If this drive supports the Host Protected Area feature set,
389 * then we may need to change our opinion about the drive's capacity.
390 */
391 int hpa = ata_id_hpa_enabled(id);
392 381
393 if (ata_id_lba48_enabled(id)) { 382 if (ata_id_lba48_enabled(id)) {
394 /* drive speaks 48-bit LBA */ 383 /* drive speaks 48-bit LBA */
395 drive->select.b.lba = 1; 384 lba = 1;
396 drive->capacity64 = ata_id_u64(id, ATA_ID_LBA_CAPACITY_2); 385 drive->capacity64 = ata_id_u64(id, ATA_ID_LBA_CAPACITY_2);
397 if (hpa)
398 idedisk_check_hpa(drive);
399 } else if (ata_id_has_lba(id) && ata_id_is_lba_capacity_ok(id)) { 386 } else if (ata_id_has_lba(id) && ata_id_is_lba_capacity_ok(id)) {
400 /* drive speaks 28-bit LBA */ 387 /* drive speaks 28-bit LBA */
401 drive->select.b.lba = 1; 388 lba = 1;
402 drive->capacity64 = ata_id_u32(id, ATA_ID_LBA_CAPACITY); 389 drive->capacity64 = ata_id_u32(id, ATA_ID_LBA_CAPACITY);
403 if (hpa)
404 idedisk_check_hpa(drive);
405 } else { 390 } else {
406 /* drive speaks boring old 28-bit CHS */ 391 /* drive speaks boring old 28-bit CHS */
392 lba = 0;
407 drive->capacity64 = drive->cyl * drive->head * drive->sect; 393 drive->capacity64 = drive->cyl * drive->head * drive->sect;
408 } 394 }
409}
410 395
411static sector_t idedisk_capacity(ide_drive_t *drive) 396 if (lba) {
412{ 397 drive->dev_flags |= IDE_DFLAG_LBA;
413 return drive->capacity64;
414}
415 398
416#ifdef CONFIG_IDE_PROC_FS 399 /*
417static int smart_enable(ide_drive_t *drive) 400 * If this device supports the Host Protected Area feature set,
418{ 401 * then we may need to change our opinion about its capacity.
419 ide_task_t args; 402 */
420 struct ide_taskfile *tf = &args.tf; 403 if (ata_id_hpa_enabled(id))
421 404 idedisk_check_hpa(drive);
422 memset(&args, 0, sizeof(ide_task_t));
423 tf->feature = ATA_SMART_ENABLE;
424 tf->lbam = ATA_SMART_LBAM_PASS;
425 tf->lbah = ATA_SMART_LBAH_PASS;
426 tf->command = ATA_CMD_SMART;
427 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
428 return ide_no_data_taskfile(drive, &args);
429}
430
431static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
432{
433 ide_task_t args;
434 struct ide_taskfile *tf = &args.tf;
435
436 memset(&args, 0, sizeof(ide_task_t));
437 tf->feature = sub_cmd;
438 tf->nsect = 0x01;
439 tf->lbam = ATA_SMART_LBAM_PASS;
440 tf->lbah = ATA_SMART_LBAH_PASS;
441 tf->command = ATA_CMD_SMART;
442 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
443 args.data_phase = TASKFILE_IN;
444 (void) smart_enable(drive);
445 return ide_raw_taskfile(drive, &args, buf, 1);
446}
447
448static int proc_idedisk_read_cache
449 (char *page, char **start, off_t off, int count, int *eof, void *data)
450{
451 ide_drive_t *drive = (ide_drive_t *) data;
452 char *out = page;
453 int len;
454
455 if (drive->id_read)
456 len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
457 else
458 len = sprintf(out, "(none)\n");
459
460 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
461}
462
463static int proc_idedisk_read_capacity
464 (char *page, char **start, off_t off, int count, int *eof, void *data)
465{
466 ide_drive_t*drive = (ide_drive_t *)data;
467 int len;
468
469 len = sprintf(page, "%llu\n", (long long)idedisk_capacity(drive));
470
471 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
472}
473
474static int proc_idedisk_read_smart(char *page, char **start, off_t off,
475 int count, int *eof, void *data, u8 sub_cmd)
476{
477 ide_drive_t *drive = (ide_drive_t *)data;
478 int len = 0, i = 0;
479
480 if (get_smart_data(drive, page, sub_cmd) == 0) {
481 unsigned short *val = (unsigned short *) page;
482 char *out = (char *)val + SECTOR_SIZE;
483
484 page = out;
485 do {
486 out += sprintf(out, "%04x%c", le16_to_cpu(*val),
487 (++i & 7) ? ' ' : '\n');
488 val += 1;
489 } while (i < SECTOR_SIZE / 2);
490 len = out - page;
491 } 405 }
492
493 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
494} 406}
495 407
496static int proc_idedisk_read_sv 408sector_t ide_disk_capacity(ide_drive_t *drive)
497 (char *page, char **start, off_t off, int count, int *eof, void *data)
498{ 409{
499 return proc_idedisk_read_smart(page, start, off, count, eof, data, 410 return drive->capacity64;
500 ATA_SMART_READ_VALUES);
501}
502
503static int proc_idedisk_read_st
504 (char *page, char **start, off_t off, int count, int *eof, void *data)
505{
506 return proc_idedisk_read_smart(page, start, off, count, eof, data,
507 ATA_SMART_READ_THRESHOLDS);
508} 411}
509 412
510static ide_proc_entry_t idedisk_proc[] = {
511 { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL },
512 { "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL },
513 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
514 { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv, NULL },
515 { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st, NULL },
516 { NULL, 0, NULL, NULL }
517};
518#endif /* CONFIG_IDE_PROC_FS */
519
520static void idedisk_prepare_flush(struct request_queue *q, struct request *rq) 413static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
521{ 414{
522 ide_drive_t *drive = q->queuedata; 415 ide_drive_t *drive = q->queuedata;
@@ -568,25 +461,43 @@ static int set_multcount(ide_drive_t *drive, int arg)
568 return (drive->mult_count == arg) ? 0 : -EIO; 461 return (drive->mult_count == arg) ? 0 : -EIO;
569} 462}
570 463
571ide_devset_get(nowerr, nowerr); 464ide_devset_get_flag(nowerr, IDE_DFLAG_NOWERR);
572 465
573static int set_nowerr(ide_drive_t *drive, int arg) 466static int set_nowerr(ide_drive_t *drive, int arg)
574{ 467{
575 if (arg < 0 || arg > 1) 468 if (arg < 0 || arg > 1)
576 return -EINVAL; 469 return -EINVAL;
577 470
578 drive->nowerr = arg; 471 if (arg)
472 drive->dev_flags |= IDE_DFLAG_NOWERR;
473 else
474 drive->dev_flags &= ~IDE_DFLAG_NOWERR;
475
579 drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT; 476 drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT;
477
580 return 0; 478 return 0;
581} 479}
582 480
481static int ide_do_setfeature(ide_drive_t *drive, u8 feature, u8 nsect)
482{
483 ide_task_t task;
484
485 memset(&task, 0, sizeof(task));
486 task.tf.feature = feature;
487 task.tf.nsect = nsect;
488 task.tf.command = ATA_CMD_SET_FEATURES;
489 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
490
491 return ide_no_data_taskfile(drive, &task);
492}
493
583static void update_ordered(ide_drive_t *drive) 494static void update_ordered(ide_drive_t *drive)
584{ 495{
585 u16 *id = drive->id; 496 u16 *id = drive->id;
586 unsigned ordered = QUEUE_ORDERED_NONE; 497 unsigned ordered = QUEUE_ORDERED_NONE;
587 prepare_flush_fn *prep_fn = NULL; 498 prepare_flush_fn *prep_fn = NULL;
588 499
589 if (drive->wcache) { 500 if (drive->dev_flags & IDE_DFLAG_WCACHE) {
590 unsigned long long capacity; 501 unsigned long long capacity;
591 int barrier; 502 int barrier;
592 /* 503 /*
@@ -597,9 +508,11 @@ static void update_ordered(ide_drive_t *drive)
597 * time we have trimmed the drive capacity if LBA48 is 508 * time we have trimmed the drive capacity if LBA48 is
598 * not available so we don't need to recheck that. 509 * not available so we don't need to recheck that.
599 */ 510 */
600 capacity = idedisk_capacity(drive); 511 capacity = ide_disk_capacity(drive);
601 barrier = ata_id_flush_enabled(id) && !drive->noflush && 512 barrier = ata_id_flush_enabled(id) &&
602 (drive->addressing == 0 || capacity <= (1ULL << 28) || 513 (drive->dev_flags & IDE_DFLAG_NOFLUSH) == 0 &&
514 ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 ||
515 capacity <= (1ULL << 28) ||
603 ata_id_flush_ext_enabled(id)); 516 ata_id_flush_ext_enabled(id));
604 517
605 printk(KERN_INFO "%s: cache flushes %ssupported\n", 518 printk(KERN_INFO "%s: cache flushes %ssupported\n",
@@ -615,25 +528,24 @@ static void update_ordered(ide_drive_t *drive)
615 blk_queue_ordered(drive->queue, ordered, prep_fn); 528 blk_queue_ordered(drive->queue, ordered, prep_fn);
616} 529}
617 530
618ide_devset_get(wcache, wcache); 531ide_devset_get_flag(wcache, IDE_DFLAG_WCACHE);
619 532
620static int set_wcache(ide_drive_t *drive, int arg) 533static int set_wcache(ide_drive_t *drive, int arg)
621{ 534{
622 ide_task_t args;
623 int err = 1; 535 int err = 1;
624 536
625 if (arg < 0 || arg > 1) 537 if (arg < 0 || arg > 1)
626 return -EINVAL; 538 return -EINVAL;
627 539
628 if (ata_id_flush_enabled(drive->id)) { 540 if (ata_id_flush_enabled(drive->id)) {
629 memset(&args, 0, sizeof(ide_task_t)); 541 err = ide_do_setfeature(drive,
630 args.tf.feature = arg ? 542 arg ? SETFEATURES_WC_ON : SETFEATURES_WC_OFF, 0);
631 SETFEATURES_WC_ON : SETFEATURES_WC_OFF; 543 if (err == 0) {
632 args.tf.command = ATA_CMD_SET_FEATURES; 544 if (arg)
633 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 545 drive->dev_flags |= IDE_DFLAG_WCACHE;
634 err = ide_no_data_taskfile(drive, &args); 546 else
635 if (err == 0) 547 drive->dev_flags &= ~IDE_DFLAG_WCACHE;
636 drive->wcache = arg; 548 }
637 } 549 }
638 550
639 update_ordered(drive); 551 update_ordered(drive);
@@ -658,22 +570,18 @@ ide_devset_get(acoustic, acoustic);
658 570
659static int set_acoustic(ide_drive_t *drive, int arg) 571static int set_acoustic(ide_drive_t *drive, int arg)
660{ 572{
661 ide_task_t args;
662
663 if (arg < 0 || arg > 254) 573 if (arg < 0 || arg > 254)
664 return -EINVAL; 574 return -EINVAL;
665 575
666 memset(&args, 0, sizeof(ide_task_t)); 576 ide_do_setfeature(drive,
667 args.tf.feature = arg ? SETFEATURES_AAM_ON : SETFEATURES_AAM_OFF; 577 arg ? SETFEATURES_AAM_ON : SETFEATURES_AAM_OFF, arg);
668 args.tf.nsect = arg; 578
669 args.tf.command = ATA_CMD_SET_FEATURES;
670 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
671 ide_no_data_taskfile(drive, &args);
672 drive->acoustic = arg; 579 drive->acoustic = arg;
580
673 return 0; 581 return 0;
674} 582}
675 583
676ide_devset_get(addressing, addressing); 584ide_devset_get_flag(addressing, IDE_DFLAG_LBA48);
677 585
678/* 586/*
679 * drive->addressing: 587 * drive->addressing:
@@ -686,49 +594,27 @@ static int set_addressing(ide_drive_t *drive, int arg)
686 if (arg < 0 || arg > 2) 594 if (arg < 0 || arg > 2)
687 return -EINVAL; 595 return -EINVAL;
688 596
689 drive->addressing = 0; 597 if (arg && ((drive->hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
690 598 ata_id_lba48_enabled(drive->id) == 0))
691 if (drive->hwif->host_flags & IDE_HFLAG_NO_LBA48)
692 return 0;
693
694 if (ata_id_lba48_enabled(drive->id) == 0)
695 return -EIO; 599 return -EIO;
696 600
697 drive->addressing = arg; 601 if (arg == 2)
602 arg = 0;
603
604 if (arg)
605 drive->dev_flags |= IDE_DFLAG_LBA48;
606 else
607 drive->dev_flags &= ~IDE_DFLAG_LBA48;
698 608
699 return 0; 609 return 0;
700} 610}
701 611
702ide_devset_rw(acoustic, acoustic); 612ide_ext_devset_rw(acoustic, acoustic);
703ide_devset_rw(address, addressing); 613ide_ext_devset_rw(address, addressing);
704ide_devset_rw(multcount, multcount); 614ide_ext_devset_rw(multcount, multcount);
705ide_devset_rw(wcache, wcache); 615ide_ext_devset_rw(wcache, wcache);
706
707ide_devset_rw_sync(nowerr, nowerr);
708 616
709#ifdef CONFIG_IDE_PROC_FS 617ide_ext_devset_rw_sync(nowerr, nowerr);
710ide_devset_rw_field(bios_cyl, bios_cyl);
711ide_devset_rw_field(bios_head, bios_head);
712ide_devset_rw_field(bios_sect, bios_sect);
713ide_devset_rw_field(failures, failures);
714ide_devset_rw_field(lun, lun);
715ide_devset_rw_field(max_failures, max_failures);
716
717static const struct ide_proc_devset idedisk_settings[] = {
718 IDE_PROC_DEVSET(acoustic, 0, 254),
719 IDE_PROC_DEVSET(address, 0, 2),
720 IDE_PROC_DEVSET(bios_cyl, 0, 65535),
721 IDE_PROC_DEVSET(bios_head, 0, 255),
722 IDE_PROC_DEVSET(bios_sect, 0, 63),
723 IDE_PROC_DEVSET(failures, 0, 65535),
724 IDE_PROC_DEVSET(lun, 0, 7),
725 IDE_PROC_DEVSET(max_failures, 0, 65535),
726 IDE_PROC_DEVSET(multcount, 0, 16),
727 IDE_PROC_DEVSET(nowerr, 0, 1),
728 IDE_PROC_DEVSET(wcache, 0, 1),
729 { 0 },
730};
731#endif
732 618
733static void idedisk_setup(ide_drive_t *drive) 619static void idedisk_setup(ide_drive_t *drive)
734{ 620{
@@ -740,20 +626,20 @@ static void idedisk_setup(ide_drive_t *drive)
740 626
741 ide_proc_register_driver(drive, idkp->driver); 627 ide_proc_register_driver(drive, idkp->driver);
742 628
743 if (drive->id_read == 0) 629 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0)
744 return; 630 return;
745 631
746 if (drive->removable) { 632 if (drive->dev_flags & IDE_DFLAG_REMOVABLE) {
747 /* 633 /*
748 * Removable disks (eg. SYQUEST); ignore 'WD' drives 634 * Removable disks (eg. SYQUEST); ignore 'WD' drives
749 */ 635 */
750 if (m[0] != 'W' || m[1] != 'D') 636 if (m[0] != 'W' || m[1] != 'D')
751 drive->doorlocking = 1; 637 drive->dev_flags |= IDE_DFLAG_DOORLOCKING;
752 } 638 }
753 639
754 (void)set_addressing(drive, 1); 640 (void)set_addressing(drive, 1);
755 641
756 if (drive->addressing == 1) { 642 if (drive->dev_flags & IDE_DFLAG_LBA48) {
757 int max_s = 2048; 643 int max_s = 2048;
758 644
759 if (max_s > hwif->rqsize) 645 if (max_s > hwif->rqsize)
@@ -769,7 +655,8 @@ static void idedisk_setup(ide_drive_t *drive)
769 init_idedisk_capacity(drive); 655 init_idedisk_capacity(drive);
770 656
771 /* limit drive capacity to 137GB if LBA48 cannot be used */ 657 /* limit drive capacity to 137GB if LBA48 cannot be used */
772 if (drive->addressing == 0 && drive->capacity64 > 1ULL << 28) { 658 if ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 &&
659 drive->capacity64 > 1ULL << 28) {
773 printk(KERN_WARNING "%s: cannot use LBA48 - full capacity " 660 printk(KERN_WARNING "%s: cannot use LBA48 - full capacity "
774 "%llu sectors (%llu MB)\n", 661 "%llu sectors (%llu MB)\n",
775 drive->name, (unsigned long long)drive->capacity64, 662 drive->name, (unsigned long long)drive->capacity64,
@@ -777,22 +664,23 @@ static void idedisk_setup(ide_drive_t *drive)
777 drive->capacity64 = 1ULL << 28; 664 drive->capacity64 = 1ULL << 28;
778 } 665 }
779 666
780 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && drive->addressing) { 667 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) &&
668 (drive->dev_flags & IDE_DFLAG_LBA48)) {
781 if (drive->capacity64 > 1ULL << 28) { 669 if (drive->capacity64 > 1ULL << 28) {
782 printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode" 670 printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode"
783 " will be used for accessing sectors " 671 " will be used for accessing sectors "
784 "> %u\n", drive->name, 1 << 28); 672 "> %u\n", drive->name, 1 << 28);
785 } else 673 } else
786 drive->addressing = 0; 674 drive->dev_flags &= ~IDE_DFLAG_LBA48;
787 } 675 }
788 676
789 /* 677 /*
790 * if possible, give fdisk access to more of the drive, 678 * if possible, give fdisk access to more of the drive,
791 * by correcting bios_cyls: 679 * by correcting bios_cyls:
792 */ 680 */
793 capacity = idedisk_capacity(drive); 681 capacity = ide_disk_capacity(drive);
794 682
795 if (!drive->forced_geom) { 683 if ((drive->dev_flags & IDE_DFLAG_FORCED_GEOM) == 0) {
796 if (ata_id_lba48_enabled(drive->id)) { 684 if (ata_id_lba48_enabled(drive->id)) {
797 /* compatibility */ 685 /* compatibility */
798 drive->bios_sect = 63; 686 drive->bios_sect = 63;
@@ -827,14 +715,15 @@ static void idedisk_setup(ide_drive_t *drive)
827 715
828 /* write cache enabled? */ 716 /* write cache enabled? */
829 if ((id[ATA_ID_CSFO] & 1) || ata_id_wcache_enabled(id)) 717 if ((id[ATA_ID_CSFO] & 1) || ata_id_wcache_enabled(id))
830 drive->wcache = 1; 718 drive->dev_flags |= IDE_DFLAG_WCACHE;
831 719
832 set_wcache(drive, 1); 720 set_wcache(drive, 1);
833} 721}
834 722
835static void ide_cacheflush_p(ide_drive_t *drive) 723static void ide_cacheflush_p(ide_drive_t *drive)
836{ 724{
837 if (!drive->wcache || ata_id_flush_enabled(drive->id) == 0) 725 if (ata_id_flush_enabled(drive->id) == 0 ||
726 (drive->dev_flags & IDE_DFLAG_WCACHE) == 0)
838 return; 727 return;
839 728
840 if (do_idedisk_flushcache(drive)) 729 if (do_idedisk_flushcache(drive))
@@ -918,13 +807,12 @@ static ide_driver_t idedisk_driver = {
918 .resume = ide_disk_resume, 807 .resume = ide_disk_resume,
919 .shutdown = ide_device_shutdown, 808 .shutdown = ide_device_shutdown,
920 .version = IDEDISK_VERSION, 809 .version = IDEDISK_VERSION,
921 .media = ide_disk,
922 .do_request = ide_do_rw_disk, 810 .do_request = ide_do_rw_disk,
923 .end_request = ide_end_request, 811 .end_request = ide_end_request,
924 .error = __ide_error, 812 .error = __ide_error,
925#ifdef CONFIG_IDE_PROC_FS 813#ifdef CONFIG_IDE_PROC_FS
926 .proc = idedisk_proc, 814 .proc = ide_disk_proc,
927 .settings = idedisk_settings, 815 .settings = ide_disk_settings,
928#endif 816#endif
929}; 817};
930 818
@@ -953,15 +841,16 @@ static int idedisk_open(struct inode *inode, struct file *filp)
953 841
954 idkp->openers++; 842 idkp->openers++;
955 843
956 if (drive->removable && idkp->openers == 1) { 844 if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
957 check_disk_change(inode->i_bdev); 845 check_disk_change(inode->i_bdev);
958 /* 846 /*
959 * Ignore the return code from door_lock, 847 * Ignore the return code from door_lock,
960 * since the open() has already succeeded, 848 * since the open() has already succeeded,
961 * and the door_lock is irrelevant at this point. 849 * and the door_lock is irrelevant at this point.
962 */ 850 */
963 if (drive->doorlocking && idedisk_set_doorlock(drive, 1)) 851 if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) &&
964 drive->doorlocking = 0; 852 idedisk_set_doorlock(drive, 1))
853 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
965 } 854 }
966 return 0; 855 return 0;
967} 856}
@@ -975,9 +864,10 @@ static int idedisk_release(struct inode *inode, struct file *filp)
975 if (idkp->openers == 1) 864 if (idkp->openers == 1)
976 ide_cacheflush_p(drive); 865 ide_cacheflush_p(drive);
977 866
978 if (drive->removable && idkp->openers == 1) { 867 if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
979 if (drive->doorlocking && idedisk_set_doorlock(drive, 0)) 868 if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) &&
980 drive->doorlocking = 0; 869 idedisk_set_doorlock(drive, 0))
870 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
981 } 871 }
982 872
983 idkp->openers--; 873 idkp->openers--;
@@ -998,48 +888,25 @@ static int idedisk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
998 return 0; 888 return 0;
999} 889}
1000 890
1001static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = {
1002{ HDIO_GET_ADDRESS, HDIO_SET_ADDRESS, &ide_devset_address },
1003{ HDIO_GET_MULTCOUNT, HDIO_SET_MULTCOUNT, &ide_devset_multcount },
1004{ HDIO_GET_NOWERR, HDIO_SET_NOWERR, &ide_devset_nowerr },
1005{ HDIO_GET_WCACHE, HDIO_SET_WCACHE, &ide_devset_wcache },
1006{ HDIO_GET_ACOUSTIC, HDIO_SET_ACOUSTIC, &ide_devset_acoustic },
1007{ 0 }
1008};
1009
1010static int idedisk_ioctl(struct inode *inode, struct file *file,
1011 unsigned int cmd, unsigned long arg)
1012{
1013 struct block_device *bdev = inode->i_bdev;
1014 struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
1015 ide_drive_t *drive = idkp->drive;
1016 int err;
1017
1018 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings);
1019 if (err != -EOPNOTSUPP)
1020 return err;
1021
1022 return generic_ide_ioctl(drive, file, bdev, cmd, arg);
1023}
1024
1025static int idedisk_media_changed(struct gendisk *disk) 891static int idedisk_media_changed(struct gendisk *disk)
1026{ 892{
1027 struct ide_disk_obj *idkp = ide_disk_g(disk); 893 struct ide_disk_obj *idkp = ide_disk_g(disk);
1028 ide_drive_t *drive = idkp->drive; 894 ide_drive_t *drive = idkp->drive;
1029 895
1030 /* do not scan partitions twice if this is a removable device */ 896 /* do not scan partitions twice if this is a removable device */
1031 if (drive->attach) { 897 if (drive->dev_flags & IDE_DFLAG_ATTACH) {
1032 drive->attach = 0; 898 drive->dev_flags &= ~IDE_DFLAG_ATTACH;
1033 return 0; 899 return 0;
1034 } 900 }
901
1035 /* if removable, always assume it was changed */ 902 /* if removable, always assume it was changed */
1036 return drive->removable; 903 return !!(drive->dev_flags & IDE_DFLAG_REMOVABLE);
1037} 904}
1038 905
1039static int idedisk_revalidate_disk(struct gendisk *disk) 906static int idedisk_revalidate_disk(struct gendisk *disk)
1040{ 907{
1041 struct ide_disk_obj *idkp = ide_disk_g(disk); 908 struct ide_disk_obj *idkp = ide_disk_g(disk);
1042 set_capacity(disk, idedisk_capacity(idkp->drive)); 909 set_capacity(disk, ide_disk_capacity(idkp->drive));
1043 return 0; 910 return 0;
1044} 911}
1045 912
@@ -1047,7 +914,7 @@ static struct block_device_operations idedisk_ops = {
1047 .owner = THIS_MODULE, 914 .owner = THIS_MODULE,
1048 .open = idedisk_open, 915 .open = idedisk_open,
1049 .release = idedisk_release, 916 .release = idedisk_release,
1050 .ioctl = idedisk_ioctl, 917 .ioctl = ide_disk_ioctl,
1051 .getgeo = idedisk_getgeo, 918 .getgeo = idedisk_getgeo,
1052 .media_changed = idedisk_media_changed, 919 .media_changed = idedisk_media_changed,
1053 .revalidate_disk = idedisk_revalidate_disk 920 .revalidate_disk = idedisk_revalidate_disk
@@ -1088,19 +955,20 @@ static int ide_disk_probe(ide_drive_t *drive)
1088 drive->driver_data = idkp; 955 drive->driver_data = idkp;
1089 956
1090 idedisk_setup(drive); 957 idedisk_setup(drive);
1091 if ((!drive->head || drive->head > 16) && !drive->select.b.lba) { 958 if ((drive->dev_flags & IDE_DFLAG_LBA) == 0 &&
959 (drive->head == 0 || drive->head > 16)) {
1092 printk(KERN_ERR "%s: INVALID GEOMETRY: %d PHYSICAL HEADS?\n", 960 printk(KERN_ERR "%s: INVALID GEOMETRY: %d PHYSICAL HEADS?\n",
1093 drive->name, drive->head); 961 drive->name, drive->head);
1094 drive->attach = 0; 962 drive->dev_flags &= ~IDE_DFLAG_ATTACH;
1095 } else 963 } else
1096 drive->attach = 1; 964 drive->dev_flags |= IDE_DFLAG_ATTACH;
1097 965
1098 g->minors = IDE_DISK_MINORS; 966 g->minors = IDE_DISK_MINORS;
1099 g->driverfs_dev = &drive->gendev; 967 g->driverfs_dev = &drive->gendev;
1100 g->flags |= GENHD_FL_EXT_DEVT; 968 g->flags |= GENHD_FL_EXT_DEVT;
1101 if (drive->removable) 969 if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
1102 g->flags |= GENHD_FL_REMOVABLE; 970 g->flags = GENHD_FL_REMOVABLE;
1103 set_capacity(g, idedisk_capacity(drive)); 971 set_capacity(g, ide_disk_capacity(drive));
1104 g->fops = &idedisk_ops; 972 g->fops = &idedisk_ops;
1105 add_disk(g); 973 add_disk(g);
1106 return 0; 974 return 0;
@@ -1122,6 +990,7 @@ static int __init idedisk_init(void)
1122} 990}
1123 991
1124MODULE_ALIAS("ide:*m-disk*"); 992MODULE_ALIAS("ide:*m-disk*");
993MODULE_ALIAS("ide-disk");
1125module_init(idedisk_init); 994module_init(idedisk_init);
1126module_exit(idedisk_exit); 995module_exit(idedisk_exit);
1127MODULE_LICENSE("GPL"); 996MODULE_LICENSE("GPL");
diff --git a/drivers/ide/ide-disk.h b/drivers/ide/ide-disk.h
new file mode 100644
index 000000000000..a82fa4355665
--- /dev/null
+++ b/drivers/ide/ide-disk.h
@@ -0,0 +1,32 @@
1#ifndef __IDE_DISK_H
2#define __IDE_DISK_H
3
4struct ide_disk_obj {
5 ide_drive_t *drive;
6 ide_driver_t *driver;
7 struct gendisk *disk;
8 struct kref kref;
9 unsigned int openers; /* protected by BKL for now */
10};
11
12#define ide_disk_g(disk) \
13 container_of((disk)->private_data, struct ide_disk_obj, driver)
14
15/* ide-disk.c */
16sector_t ide_disk_capacity(ide_drive_t *);
17ide_decl_devset(address);
18ide_decl_devset(multcount);
19ide_decl_devset(nowerr);
20ide_decl_devset(wcache);
21ide_decl_devset(acoustic);
22
23/* ide-disk_ioctl.c */
24int ide_disk_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
25
26#ifdef CONFIG_IDE_PROC_FS
27/* ide-disk_proc.c */
28extern ide_proc_entry_t ide_disk_proc[];
29extern const struct ide_proc_devset ide_disk_settings[];
30#endif
31
32#endif /* __IDE_DISK_H */
diff --git a/drivers/ide/ide-disk_ioctl.c b/drivers/ide/ide-disk_ioctl.c
new file mode 100644
index 000000000000..a6cf1a03a806
--- /dev/null
+++ b/drivers/ide/ide-disk_ioctl.c
@@ -0,0 +1,29 @@
1#include <linux/kernel.h>
2#include <linux/ide.h>
3#include <linux/hdreg.h>
4
5#include "ide-disk.h"
6
7static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = {
8{ HDIO_GET_ADDRESS, HDIO_SET_ADDRESS, &ide_devset_address },
9{ HDIO_GET_MULTCOUNT, HDIO_SET_MULTCOUNT, &ide_devset_multcount },
10{ HDIO_GET_NOWERR, HDIO_SET_NOWERR, &ide_devset_nowerr },
11{ HDIO_GET_WCACHE, HDIO_SET_WCACHE, &ide_devset_wcache },
12{ HDIO_GET_ACOUSTIC, HDIO_SET_ACOUSTIC, &ide_devset_acoustic },
13{ 0 }
14};
15
16int ide_disk_ioctl(struct inode *inode, struct file *file,
17 unsigned int cmd, unsigned long arg)
18{
19 struct block_device *bdev = inode->i_bdev;
20 struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
21 ide_drive_t *drive = idkp->drive;
22 int err;
23
24 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings);
25 if (err != -EOPNOTSUPP)
26 return err;
27
28 return generic_ide_ioctl(drive, file, bdev, cmd, arg);
29}
diff --git a/drivers/ide/ide-disk_proc.c b/drivers/ide/ide-disk_proc.c
new file mode 100644
index 000000000000..4724976afe71
--- /dev/null
+++ b/drivers/ide/ide-disk_proc.c
@@ -0,0 +1,129 @@
1#include <linux/kernel.h>
2#include <linux/ide.h>
3#include <linux/hdreg.h>
4
5#include "ide-disk.h"
6
7static int smart_enable(ide_drive_t *drive)
8{
9 ide_task_t args;
10 struct ide_taskfile *tf = &args.tf;
11
12 memset(&args, 0, sizeof(ide_task_t));
13 tf->feature = ATA_SMART_ENABLE;
14 tf->lbam = ATA_SMART_LBAM_PASS;
15 tf->lbah = ATA_SMART_LBAH_PASS;
16 tf->command = ATA_CMD_SMART;
17 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
18 return ide_no_data_taskfile(drive, &args);
19}
20
21static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
22{
23 ide_task_t args;
24 struct ide_taskfile *tf = &args.tf;
25
26 memset(&args, 0, sizeof(ide_task_t));
27 tf->feature = sub_cmd;
28 tf->nsect = 0x01;
29 tf->lbam = ATA_SMART_LBAM_PASS;
30 tf->lbah = ATA_SMART_LBAH_PASS;
31 tf->command = ATA_CMD_SMART;
32 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
33 args.data_phase = TASKFILE_IN;
34 (void) smart_enable(drive);
35 return ide_raw_taskfile(drive, &args, buf, 1);
36}
37
38static int proc_idedisk_read_cache
39 (char *page, char **start, off_t off, int count, int *eof, void *data)
40{
41 ide_drive_t *drive = (ide_drive_t *) data;
42 char *out = page;
43 int len;
44
45 if (drive->dev_flags & IDE_DFLAG_ID_READ)
46 len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
47 else
48 len = sprintf(out, "(none)\n");
49
50 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
51}
52
53static int proc_idedisk_read_capacity
54 (char *page, char **start, off_t off, int count, int *eof, void *data)
55{
56 ide_drive_t*drive = (ide_drive_t *)data;
57 int len;
58
59 len = sprintf(page, "%llu\n", (long long)ide_disk_capacity(drive));
60
61 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
62}
63
64static int proc_idedisk_read_smart(char *page, char **start, off_t off,
65 int count, int *eof, void *data, u8 sub_cmd)
66{
67 ide_drive_t *drive = (ide_drive_t *)data;
68 int len = 0, i = 0;
69
70 if (get_smart_data(drive, page, sub_cmd) == 0) {
71 unsigned short *val = (unsigned short *) page;
72 char *out = (char *)val + SECTOR_SIZE;
73
74 page = out;
75 do {
76 out += sprintf(out, "%04x%c", le16_to_cpu(*val),
77 (++i & 7) ? ' ' : '\n');
78 val += 1;
79 } while (i < SECTOR_SIZE / 2);
80 len = out - page;
81 }
82
83 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
84}
85
86static int proc_idedisk_read_sv
87 (char *page, char **start, off_t off, int count, int *eof, void *data)
88{
89 return proc_idedisk_read_smart(page, start, off, count, eof, data,
90 ATA_SMART_READ_VALUES);
91}
92
93static int proc_idedisk_read_st
94 (char *page, char **start, off_t off, int count, int *eof, void *data)
95{
96 return proc_idedisk_read_smart(page, start, off, count, eof, data,
97 ATA_SMART_READ_THRESHOLDS);
98}
99
100ide_proc_entry_t ide_disk_proc[] = {
101 { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL },
102 { "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL },
103 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
104 { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv, NULL },
105 { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st, NULL },
106 { NULL, 0, NULL, NULL }
107};
108
109ide_devset_rw_field(bios_cyl, bios_cyl);
110ide_devset_rw_field(bios_head, bios_head);
111ide_devset_rw_field(bios_sect, bios_sect);
112ide_devset_rw_field(failures, failures);
113ide_devset_rw_field(lun, lun);
114ide_devset_rw_field(max_failures, max_failures);
115
116const struct ide_proc_devset ide_disk_settings[] = {
117 IDE_PROC_DEVSET(acoustic, 0, 254),
118 IDE_PROC_DEVSET(address, 0, 2),
119 IDE_PROC_DEVSET(bios_cyl, 0, 65535),
120 IDE_PROC_DEVSET(bios_head, 0, 255),
121 IDE_PROC_DEVSET(bios_sect, 0, 63),
122 IDE_PROC_DEVSET(failures, 0, 65535),
123 IDE_PROC_DEVSET(lun, 0, 7),
124 IDE_PROC_DEVSET(max_failures, 0, 65535),
125 IDE_PROC_DEVSET(multcount, 0, 16),
126 IDE_PROC_DEVSET(nowerr, 0, 1),
127 IDE_PROC_DEVSET(wcache, 0, 1),
128 { 0 },
129};
diff --git a/drivers/ide/ide-dma-sff.c b/drivers/ide/ide-dma-sff.c
new file mode 100644
index 000000000000..0903782689e9
--- /dev/null
+++ b/drivers/ide/ide-dma-sff.c
@@ -0,0 +1,356 @@
1#include <linux/types.h>
2#include <linux/kernel.h>
3#include <linux/ide.h>
4#include <linux/scatterlist.h>
5#include <linux/dma-mapping.h>
6#include <linux/io.h>
7
8/**
9 * config_drive_for_dma - attempt to activate IDE DMA
10 * @drive: the drive to place in DMA mode
11 *
12 * If the drive supports at least mode 2 DMA or UDMA of any kind
13 * then attempt to place it into DMA mode. Drives that are known to
14 * support DMA but predate the DMA properties or that are known
15 * to have DMA handling bugs are also set up appropriately based
16 * on the good/bad drive lists.
17 */
18
19int config_drive_for_dma(ide_drive_t *drive)
20{
21 ide_hwif_t *hwif = drive->hwif;
22 u16 *id = drive->id;
23
24 if (drive->media != ide_disk) {
25 if (hwif->host_flags & IDE_HFLAG_NO_ATAPI_DMA)
26 return 0;
27 }
28
29 /*
30 * Enable DMA on any drive that has
31 * UltraDMA (mode 0/1/2/3/4/5/6) enabled
32 */
33 if ((id[ATA_ID_FIELD_VALID] & 4) &&
34 ((id[ATA_ID_UDMA_MODES] >> 8) & 0x7f))
35 return 1;
36
37 /*
38 * Enable DMA on any drive that has mode2 DMA
39 * (multi or single) enabled
40 */
41 if (id[ATA_ID_FIELD_VALID] & 2) /* regular DMA */
42 if ((id[ATA_ID_MWDMA_MODES] & 0x404) == 0x404 ||
43 (id[ATA_ID_SWDMA_MODES] & 0x404) == 0x404)
44 return 1;
45
46 /* Consult the list of known "good" drives */
47 if (ide_dma_good_drive(drive))
48 return 1;
49
50 return 0;
51}
52
53/**
54 * ide_dma_host_set - Enable/disable DMA on a host
55 * @drive: drive to control
56 *
57 * Enable/disable DMA on an IDE controller following generic
58 * bus-mastering IDE controller behaviour.
59 */
60
61void ide_dma_host_set(ide_drive_t *drive, int on)
62{
63 ide_hwif_t *hwif = drive->hwif;
64 u8 unit = drive->dn & 1;
65 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
66
67 if (on)
68 dma_stat |= (1 << (5 + unit));
69 else
70 dma_stat &= ~(1 << (5 + unit));
71
72 if (hwif->host_flags & IDE_HFLAG_MMIO)
73 writeb(dma_stat,
74 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
75 else
76 outb(dma_stat, hwif->dma_base + ATA_DMA_STATUS);
77}
78EXPORT_SYMBOL_GPL(ide_dma_host_set);
79
80/**
81 * ide_build_dmatable - build IDE DMA table
82 *
83 * ide_build_dmatable() prepares a dma request. We map the command
84 * to get the pci bus addresses of the buffers and then build up
85 * the PRD table that the IDE layer wants to be fed.
86 *
87 * Most chipsets correctly interpret a length of 0x0000 as 64KB,
88 * but at least one (e.g. CS5530) misinterprets it as zero (!).
89 * So we break the 64KB entry into two 32KB entries instead.
90 *
91 * Returns the number of built PRD entries if all went okay,
92 * returns 0 otherwise.
93 *
94 * May also be invoked from trm290.c
95 */
96
97int ide_build_dmatable(ide_drive_t *drive, struct request *rq)
98{
99 ide_hwif_t *hwif = drive->hwif;
100 __le32 *table = (__le32 *)hwif->dmatable_cpu;
101 unsigned int is_trm290 = (hwif->chipset == ide_trm290) ? 1 : 0;
102 unsigned int count = 0;
103 int i;
104 struct scatterlist *sg;
105
106 hwif->sg_nents = ide_build_sglist(drive, rq);
107 if (hwif->sg_nents == 0)
108 return 0;
109
110 for_each_sg(hwif->sg_table, sg, hwif->sg_nents, i) {
111 u32 cur_addr, cur_len, xcount, bcount;
112
113 cur_addr = sg_dma_address(sg);
114 cur_len = sg_dma_len(sg);
115
116 /*
117 * Fill in the dma table, without crossing any 64kB boundaries.
118 * Most hardware requires 16-bit alignment of all blocks,
119 * but the trm290 requires 32-bit alignment.
120 */
121
122 while (cur_len) {
123 if (count++ >= PRD_ENTRIES)
124 goto use_pio_instead;
125
126 bcount = 0x10000 - (cur_addr & 0xffff);
127 if (bcount > cur_len)
128 bcount = cur_len;
129 *table++ = cpu_to_le32(cur_addr);
130 xcount = bcount & 0xffff;
131 if (is_trm290)
132 xcount = ((xcount >> 2) - 1) << 16;
133 if (xcount == 0x0000) {
134 if (count++ >= PRD_ENTRIES)
135 goto use_pio_instead;
136 *table++ = cpu_to_le32(0x8000);
137 *table++ = cpu_to_le32(cur_addr + 0x8000);
138 xcount = 0x8000;
139 }
140 *table++ = cpu_to_le32(xcount);
141 cur_addr += bcount;
142 cur_len -= bcount;
143 }
144 }
145
146 if (count) {
147 if (!is_trm290)
148 *--table |= cpu_to_le32(0x80000000);
149 return count;
150 }
151
152use_pio_instead:
153 printk(KERN_ERR "%s: %s\n", drive->name,
154 count ? "DMA table too small" : "empty DMA table?");
155
156 ide_destroy_dmatable(drive);
157
158 return 0; /* revert to PIO for this request */
159}
160EXPORT_SYMBOL_GPL(ide_build_dmatable);
161
162/**
163 * ide_dma_setup - begin a DMA phase
164 * @drive: target device
165 *
166 * Build an IDE DMA PRD (IDE speak for scatter gather table)
167 * and then set up the DMA transfer registers for a device
168 * that follows generic IDE PCI DMA behaviour. Controllers can
169 * override this function if they need to
170 *
171 * Returns 0 on success. If a PIO fallback is required then 1
172 * is returned.
173 */
174
175int ide_dma_setup(ide_drive_t *drive)
176{
177 ide_hwif_t *hwif = drive->hwif;
178 struct request *rq = hwif->hwgroup->rq;
179 unsigned int reading;
180 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
181 u8 dma_stat;
182
183 if (rq_data_dir(rq))
184 reading = 0;
185 else
186 reading = 1 << 3;
187
188 /* fall back to pio! */
189 if (!ide_build_dmatable(drive, rq)) {
190 ide_map_sg(drive, rq);
191 return 1;
192 }
193
194 /* PRD table */
195 if (hwif->host_flags & IDE_HFLAG_MMIO)
196 writel(hwif->dmatable_dma,
197 (void __iomem *)(hwif->dma_base + ATA_DMA_TABLE_OFS));
198 else
199 outl(hwif->dmatable_dma, hwif->dma_base + ATA_DMA_TABLE_OFS);
200
201 /* specify r/w */
202 if (mmio)
203 writeb(reading, (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
204 else
205 outb(reading, hwif->dma_base + ATA_DMA_CMD);
206
207 /* read DMA status for INTR & ERROR flags */
208 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
209
210 /* clear INTR & ERROR flags */
211 if (mmio)
212 writeb(dma_stat | 6,
213 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
214 else
215 outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS);
216
217 drive->waiting_for_dma = 1;
218 return 0;
219}
220EXPORT_SYMBOL_GPL(ide_dma_setup);
221
222/**
223 * dma_timer_expiry - handle a DMA timeout
224 * @drive: Drive that timed out
225 *
226 * An IDE DMA transfer timed out. In the event of an error we ask
227 * the driver to resolve the problem, if a DMA transfer is still
228 * in progress we continue to wait (arguably we need to add a
229 * secondary 'I don't care what the drive thinks' timeout here)
230 * Finally if we have an interrupt we let it complete the I/O.
231 * But only one time - we clear expiry and if it's still not
232 * completed after WAIT_CMD, we error and retry in PIO.
233 * This can occur if an interrupt is lost or due to hang or bugs.
234 */
235
236static int dma_timer_expiry(ide_drive_t *drive)
237{
238 ide_hwif_t *hwif = drive->hwif;
239 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
240
241 printk(KERN_WARNING "%s: %s: DMA status (0x%02x)\n",
242 drive->name, __func__, dma_stat);
243
244 if ((dma_stat & 0x18) == 0x18) /* BUSY Stupid Early Timer !! */
245 return WAIT_CMD;
246
247 hwif->hwgroup->expiry = NULL; /* one free ride for now */
248
249 /* 1 dmaing, 2 error, 4 intr */
250 if (dma_stat & 2) /* ERROR */
251 return -1;
252
253 if (dma_stat & 1) /* DMAing */
254 return WAIT_CMD;
255
256 if (dma_stat & 4) /* Got an Interrupt */
257 return WAIT_CMD;
258
259 return 0; /* Status is unknown -- reset the bus */
260}
261
262void ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
263{
264 /* issue cmd to drive */
265 ide_execute_command(drive, command, &ide_dma_intr, 2 * WAIT_CMD,
266 dma_timer_expiry);
267}
268EXPORT_SYMBOL_GPL(ide_dma_exec_cmd);
269
270void ide_dma_start(ide_drive_t *drive)
271{
272 ide_hwif_t *hwif = drive->hwif;
273 u8 dma_cmd;
274
275 /* Note that this is done *after* the cmd has
276 * been issued to the drive, as per the BM-IDE spec.
277 * The Promise Ultra33 doesn't work correctly when
278 * we do this part before issuing the drive cmd.
279 */
280 if (hwif->host_flags & IDE_HFLAG_MMIO) {
281 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
282 /* start DMA */
283 writeb(dma_cmd | 1,
284 (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
285 } else {
286 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
287 outb(dma_cmd | 1, hwif->dma_base + ATA_DMA_CMD);
288 }
289
290 wmb();
291}
292EXPORT_SYMBOL_GPL(ide_dma_start);
293
294/* returns 1 on error, 0 otherwise */
295int ide_dma_end(ide_drive_t *drive)
296{
297 ide_hwif_t *hwif = drive->hwif;
298 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
299 u8 dma_stat = 0, dma_cmd = 0;
300
301 drive->waiting_for_dma = 0;
302
303 if (mmio) {
304 /* get DMA command mode */
305 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
306 /* stop DMA */
307 writeb(dma_cmd & ~1,
308 (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
309 } else {
310 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
311 outb(dma_cmd & ~1, hwif->dma_base + ATA_DMA_CMD);
312 }
313
314 /* get DMA status */
315 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
316
317 if (mmio)
318 /* clear the INTR & ERROR bits */
319 writeb(dma_stat | 6,
320 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
321 else
322 outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS);
323
324 /* purge DMA mappings */
325 ide_destroy_dmatable(drive);
326 /* verify good DMA status */
327 wmb();
328 return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0;
329}
330EXPORT_SYMBOL_GPL(ide_dma_end);
331
332/* returns 1 if dma irq issued, 0 otherwise */
333int ide_dma_test_irq(ide_drive_t *drive)
334{
335 ide_hwif_t *hwif = drive->hwif;
336 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
337
338 /* return 1 if INTR asserted */
339 if ((dma_stat & 4) == 4)
340 return 1;
341
342 return 0;
343}
344EXPORT_SYMBOL_GPL(ide_dma_test_irq);
345
346const struct ide_dma_ops sff_dma_ops = {
347 .dma_host_set = ide_dma_host_set,
348 .dma_setup = ide_dma_setup,
349 .dma_exec_cmd = ide_dma_exec_cmd,
350 .dma_start = ide_dma_start,
351 .dma_end = ide_dma_end,
352 .dma_test_irq = ide_dma_test_irq,
353 .dma_timeout = ide_dma_timeout,
354 .dma_lost_irq = ide_dma_lost_irq,
355};
356EXPORT_SYMBOL_GPL(sff_dma_ops);
diff --git a/drivers/ide/ide-dma.c b/drivers/ide/ide-dma.c
index ef2f1504c0d5..fffd11717b2d 100644
--- a/drivers/ide/ide-dma.c
+++ b/drivers/ide/ide-dma.c
@@ -28,24 +28,13 @@
28 * for supplying a Promise UDMA board & WD UDMA drive for this work! 28 * for supplying a Promise UDMA board & WD UDMA drive for this work!
29 */ 29 */
30 30
31#include <linux/module.h>
32#include <linux/types.h> 31#include <linux/types.h>
33#include <linux/kernel.h> 32#include <linux/kernel.h>
34#include <linux/timer.h>
35#include <linux/mm.h>
36#include <linux/interrupt.h>
37#include <linux/pci.h>
38#include <linux/init.h>
39#include <linux/ide.h> 33#include <linux/ide.h>
40#include <linux/delay.h>
41#include <linux/scatterlist.h> 34#include <linux/scatterlist.h>
42#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
43 36
44#include <asm/io.h> 37static const struct drive_list_entry drive_whitelist[] = {
45#include <asm/irq.h>
46
47static const struct drive_list_entry drive_whitelist [] = {
48
49 { "Micropolis 2112A" , NULL }, 38 { "Micropolis 2112A" , NULL },
50 { "CONNER CTMA 4000" , NULL }, 39 { "CONNER CTMA 4000" , NULL },
51 { "CONNER CTT8000-A" , NULL }, 40 { "CONNER CTT8000-A" , NULL },
@@ -53,8 +42,7 @@ static const struct drive_list_entry drive_whitelist [] = {
53 { NULL , NULL } 42 { NULL , NULL }
54}; 43};
55 44
56static const struct drive_list_entry drive_blacklist [] = { 45static const struct drive_list_entry drive_blacklist[] = {
57
58 { "WDC AC11000H" , NULL }, 46 { "WDC AC11000H" , NULL },
59 { "WDC AC22100H" , NULL }, 47 { "WDC AC22100H" , NULL },
60 { "WDC AC32500H" , NULL }, 48 { "WDC AC32500H" , NULL },
@@ -94,11 +82,11 @@ static const struct drive_list_entry drive_blacklist [] = {
94 * ide_dma_intr - IDE DMA interrupt handler 82 * ide_dma_intr - IDE DMA interrupt handler
95 * @drive: the drive the interrupt is for 83 * @drive: the drive the interrupt is for
96 * 84 *
97 * Handle an interrupt completing a read/write DMA transfer on an 85 * Handle an interrupt completing a read/write DMA transfer on an
98 * IDE device 86 * IDE device
99 */ 87 */
100 88
101ide_startstop_t ide_dma_intr (ide_drive_t *drive) 89ide_startstop_t ide_dma_intr(ide_drive_t *drive)
102{ 90{
103 ide_hwif_t *hwif = drive->hwif; 91 ide_hwif_t *hwif = drive->hwif;
104 u8 stat = 0, dma_stat = 0; 92 u8 stat = 0, dma_stat = 0;
@@ -108,20 +96,19 @@ ide_startstop_t ide_dma_intr (ide_drive_t *drive)
108 96
109 if (OK_STAT(stat, DRIVE_READY, drive->bad_wstat | ATA_DRQ)) { 97 if (OK_STAT(stat, DRIVE_READY, drive->bad_wstat | ATA_DRQ)) {
110 if (!dma_stat) { 98 if (!dma_stat) {
111 struct request *rq = HWGROUP(drive)->rq; 99 struct request *rq = hwif->hwgroup->rq;
112 100
113 task_end_request(drive, rq, stat); 101 task_end_request(drive, rq, stat);
114 return ide_stopped; 102 return ide_stopped;
115 } 103 }
116 printk(KERN_ERR "%s: dma_intr: bad DMA status (dma_stat=%x)\n", 104 printk(KERN_ERR "%s: %s: bad DMA status (0x%02x)\n",
117 drive->name, dma_stat); 105 drive->name, __func__, dma_stat);
118 } 106 }
119 return ide_error(drive, "dma_intr", stat); 107 return ide_error(drive, "dma_intr", stat);
120} 108}
121
122EXPORT_SYMBOL_GPL(ide_dma_intr); 109EXPORT_SYMBOL_GPL(ide_dma_intr);
123 110
124static int ide_dma_good_drive(ide_drive_t *drive) 111int ide_dma_good_drive(ide_drive_t *drive)
125{ 112{
126 return ide_in_drive_list(drive->id, drive_whitelist); 113 return ide_in_drive_list(drive->id, drive_whitelist);
127} 114}
@@ -139,7 +126,7 @@ static int ide_dma_good_drive(ide_drive_t *drive)
139 126
140int ide_build_sglist(ide_drive_t *drive, struct request *rq) 127int ide_build_sglist(ide_drive_t *drive, struct request *rq)
141{ 128{
142 ide_hwif_t *hwif = HWIF(drive); 129 ide_hwif_t *hwif = drive->hwif;
143 struct scatterlist *sg = hwif->sg_table; 130 struct scatterlist *sg = hwif->sg_table;
144 131
145 ide_map_sg(drive, rq); 132 ide_map_sg(drive, rq);
@@ -152,106 +139,8 @@ int ide_build_sglist(ide_drive_t *drive, struct request *rq)
152 return dma_map_sg(hwif->dev, sg, hwif->sg_nents, 139 return dma_map_sg(hwif->dev, sg, hwif->sg_nents,
153 hwif->sg_dma_direction); 140 hwif->sg_dma_direction);
154} 141}
155
156EXPORT_SYMBOL_GPL(ide_build_sglist); 142EXPORT_SYMBOL_GPL(ide_build_sglist);
157 143
158#ifdef CONFIG_BLK_DEV_IDEDMA_SFF
159/**
160 * ide_build_dmatable - build IDE DMA table
161 *
162 * ide_build_dmatable() prepares a dma request. We map the command
163 * to get the pci bus addresses of the buffers and then build up
164 * the PRD table that the IDE layer wants to be fed. The code
165 * knows about the 64K wrap bug in the CS5530.
166 *
167 * Returns the number of built PRD entries if all went okay,
168 * returns 0 otherwise.
169 *
170 * May also be invoked from trm290.c
171 */
172
173int ide_build_dmatable (ide_drive_t *drive, struct request *rq)
174{
175 ide_hwif_t *hwif = HWIF(drive);
176 __le32 *table = (__le32 *)hwif->dmatable_cpu;
177 unsigned int is_trm290 = (hwif->chipset == ide_trm290) ? 1 : 0;
178 unsigned int count = 0;
179 int i;
180 struct scatterlist *sg;
181
182 hwif->sg_nents = i = ide_build_sglist(drive, rq);
183
184 if (!i)
185 return 0;
186
187 sg = hwif->sg_table;
188 while (i) {
189 u32 cur_addr;
190 u32 cur_len;
191
192 cur_addr = sg_dma_address(sg);
193 cur_len = sg_dma_len(sg);
194
195 /*
196 * Fill in the dma table, without crossing any 64kB boundaries.
197 * Most hardware requires 16-bit alignment of all blocks,
198 * but the trm290 requires 32-bit alignment.
199 */
200
201 while (cur_len) {
202 if (count++ >= PRD_ENTRIES) {
203 printk(KERN_ERR "%s: DMA table too small\n", drive->name);
204 goto use_pio_instead;
205 } else {
206 u32 xcount, bcount = 0x10000 - (cur_addr & 0xffff);
207
208 if (bcount > cur_len)
209 bcount = cur_len;
210 *table++ = cpu_to_le32(cur_addr);
211 xcount = bcount & 0xffff;
212 if (is_trm290)
213 xcount = ((xcount >> 2) - 1) << 16;
214 else if (xcount == 0x0000) {
215 /*
216 * Most chipsets correctly interpret a length of 0x0000 as 64KB,
217 * but at least one (e.g. CS5530) misinterprets it as zero (!).
218 * So here we break the 64KB entry into two 32KB entries instead.
219 */
220 if (count++ >= PRD_ENTRIES) {
221 printk(KERN_ERR "%s: DMA table too small\n", drive->name);
222 goto use_pio_instead;
223 }
224 *table++ = cpu_to_le32(0x8000);
225 *table++ = cpu_to_le32(cur_addr + 0x8000);
226 xcount = 0x8000;
227 }
228 *table++ = cpu_to_le32(xcount);
229 cur_addr += bcount;
230 cur_len -= bcount;
231 }
232 }
233
234 sg = sg_next(sg);
235 i--;
236 }
237
238 if (count) {
239 if (!is_trm290)
240 *--table |= cpu_to_le32(0x80000000);
241 return count;
242 }
243
244 printk(KERN_ERR "%s: empty DMA table?\n", drive->name);
245
246use_pio_instead:
247 ide_destroy_dmatable(drive);
248
249 return 0; /* revert to PIO for this request */
250}
251
252EXPORT_SYMBOL_GPL(ide_build_dmatable);
253#endif
254
255/** 144/**
256 * ide_destroy_dmatable - clean up DMA mapping 145 * ide_destroy_dmatable - clean up DMA mapping
257 * @drive: The drive to unmap 146 * @drive: The drive to unmap
@@ -262,147 +151,30 @@ EXPORT_SYMBOL_GPL(ide_build_dmatable);
262 * an oops as only one mapping can be live for each target at a given 151 * an oops as only one mapping can be live for each target at a given
263 * time. 152 * time.
264 */ 153 */
265 154
266void ide_destroy_dmatable (ide_drive_t *drive) 155void ide_destroy_dmatable(ide_drive_t *drive)
267{ 156{
268 ide_hwif_t *hwif = drive->hwif; 157 ide_hwif_t *hwif = drive->hwif;
269 158
270 dma_unmap_sg(hwif->dev, hwif->sg_table, hwif->sg_nents, 159 dma_unmap_sg(hwif->dev, hwif->sg_table, hwif->sg_nents,
271 hwif->sg_dma_direction); 160 hwif->sg_dma_direction);
272} 161}
273
274EXPORT_SYMBOL_GPL(ide_destroy_dmatable); 162EXPORT_SYMBOL_GPL(ide_destroy_dmatable);
275 163
276#ifdef CONFIG_BLK_DEV_IDEDMA_SFF
277/**
278 * config_drive_for_dma - attempt to activate IDE DMA
279 * @drive: the drive to place in DMA mode
280 *
281 * If the drive supports at least mode 2 DMA or UDMA of any kind
282 * then attempt to place it into DMA mode. Drives that are known to
283 * support DMA but predate the DMA properties or that are known
284 * to have DMA handling bugs are also set up appropriately based
285 * on the good/bad drive lists.
286 */
287
288static int config_drive_for_dma (ide_drive_t *drive)
289{
290 ide_hwif_t *hwif = drive->hwif;
291 u16 *id = drive->id;
292
293 if (drive->media != ide_disk) {
294 if (hwif->host_flags & IDE_HFLAG_NO_ATAPI_DMA)
295 return 0;
296 }
297
298 /*
299 * Enable DMA on any drive that has
300 * UltraDMA (mode 0/1/2/3/4/5/6) enabled
301 */
302 if ((id[ATA_ID_FIELD_VALID] & 4) &&
303 ((id[ATA_ID_UDMA_MODES] >> 8) & 0x7f))
304 return 1;
305
306 /*
307 * Enable DMA on any drive that has mode2 DMA
308 * (multi or single) enabled
309 */
310 if (id[ATA_ID_FIELD_VALID] & 2) /* regular DMA */
311 if ((id[ATA_ID_MWDMA_MODES] & 0x404) == 0x404 ||
312 (id[ATA_ID_SWDMA_MODES] & 0x404) == 0x404)
313 return 1;
314
315 /* Consult the list of known "good" drives */
316 if (ide_dma_good_drive(drive))
317 return 1;
318
319 return 0;
320}
321
322/**
323 * dma_timer_expiry - handle a DMA timeout
324 * @drive: Drive that timed out
325 *
326 * An IDE DMA transfer timed out. In the event of an error we ask
327 * the driver to resolve the problem, if a DMA transfer is still
328 * in progress we continue to wait (arguably we need to add a
329 * secondary 'I don't care what the drive thinks' timeout here)
330 * Finally if we have an interrupt we let it complete the I/O.
331 * But only one time - we clear expiry and if it's still not
332 * completed after WAIT_CMD, we error and retry in PIO.
333 * This can occur if an interrupt is lost or due to hang or bugs.
334 */
335
336static int dma_timer_expiry (ide_drive_t *drive)
337{
338 ide_hwif_t *hwif = HWIF(drive);
339 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
340
341 printk(KERN_WARNING "%s: dma_timer_expiry: dma status == 0x%02x\n",
342 drive->name, dma_stat);
343
344 if ((dma_stat & 0x18) == 0x18) /* BUSY Stupid Early Timer !! */
345 return WAIT_CMD;
346
347 HWGROUP(drive)->expiry = NULL; /* one free ride for now */
348
349 /* 1 dmaing, 2 error, 4 intr */
350 if (dma_stat & 2) /* ERROR */
351 return -1;
352
353 if (dma_stat & 1) /* DMAing */
354 return WAIT_CMD;
355
356 if (dma_stat & 4) /* Got an Interrupt */
357 return WAIT_CMD;
358
359 return 0; /* Status is unknown -- reset the bus */
360}
361
362/**
363 * ide_dma_host_set - Enable/disable DMA on a host
364 * @drive: drive to control
365 *
366 * Enable/disable DMA on an IDE controller following generic
367 * bus-mastering IDE controller behaviour.
368 */
369
370void ide_dma_host_set(ide_drive_t *drive, int on)
371{
372 ide_hwif_t *hwif = HWIF(drive);
373 u8 unit = (drive->select.b.unit & 0x01);
374 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
375
376 if (on)
377 dma_stat |= (1 << (5 + unit));
378 else
379 dma_stat &= ~(1 << (5 + unit));
380
381 if (hwif->host_flags & IDE_HFLAG_MMIO)
382 writeb(dma_stat,
383 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
384 else
385 outb(dma_stat, hwif->dma_base + ATA_DMA_STATUS);
386}
387
388EXPORT_SYMBOL_GPL(ide_dma_host_set);
389#endif /* CONFIG_BLK_DEV_IDEDMA_SFF */
390
391/** 164/**
392 * ide_dma_off_quietly - Generic DMA kill 165 * ide_dma_off_quietly - Generic DMA kill
393 * @drive: drive to control 166 * @drive: drive to control
394 * 167 *
395 * Turn off the current DMA on this IDE controller. 168 * Turn off the current DMA on this IDE controller.
396 */ 169 */
397 170
398void ide_dma_off_quietly(ide_drive_t *drive) 171void ide_dma_off_quietly(ide_drive_t *drive)
399{ 172{
400 drive->using_dma = 0; 173 drive->dev_flags &= ~IDE_DFLAG_USING_DMA;
401 ide_toggle_bounce(drive, 0); 174 ide_toggle_bounce(drive, 0);
402 175
403 drive->hwif->dma_ops->dma_host_set(drive, 0); 176 drive->hwif->dma_ops->dma_host_set(drive, 0);
404} 177}
405
406EXPORT_SYMBOL(ide_dma_off_quietly); 178EXPORT_SYMBOL(ide_dma_off_quietly);
407 179
408/** 180/**
@@ -418,7 +190,6 @@ void ide_dma_off(ide_drive_t *drive)
418 printk(KERN_INFO "%s: DMA disabled\n", drive->name); 190 printk(KERN_INFO "%s: DMA disabled\n", drive->name);
419 ide_dma_off_quietly(drive); 191 ide_dma_off_quietly(drive);
420} 192}
421
422EXPORT_SYMBOL(ide_dma_off); 193EXPORT_SYMBOL(ide_dma_off);
423 194
424/** 195/**
@@ -430,167 +201,13 @@ EXPORT_SYMBOL(ide_dma_off);
430 201
431void ide_dma_on(ide_drive_t *drive) 202void ide_dma_on(ide_drive_t *drive)
432{ 203{
433 drive->using_dma = 1; 204 drive->dev_flags |= IDE_DFLAG_USING_DMA;
434 ide_toggle_bounce(drive, 1); 205 ide_toggle_bounce(drive, 1);
435 206
436 drive->hwif->dma_ops->dma_host_set(drive, 1); 207 drive->hwif->dma_ops->dma_host_set(drive, 1);
437} 208}
438 209
439#ifdef CONFIG_BLK_DEV_IDEDMA_SFF 210int __ide_dma_bad_drive(ide_drive_t *drive)
440/**
441 * ide_dma_setup - begin a DMA phase
442 * @drive: target device
443 *
444 * Build an IDE DMA PRD (IDE speak for scatter gather table)
445 * and then set up the DMA transfer registers for a device
446 * that follows generic IDE PCI DMA behaviour. Controllers can
447 * override this function if they need to
448 *
449 * Returns 0 on success. If a PIO fallback is required then 1
450 * is returned.
451 */
452
453int ide_dma_setup(ide_drive_t *drive)
454{
455 ide_hwif_t *hwif = drive->hwif;
456 struct request *rq = HWGROUP(drive)->rq;
457 unsigned int reading;
458 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
459 u8 dma_stat;
460
461 if (rq_data_dir(rq))
462 reading = 0;
463 else
464 reading = 1 << 3;
465
466 /* fall back to pio! */
467 if (!ide_build_dmatable(drive, rq)) {
468 ide_map_sg(drive, rq);
469 return 1;
470 }
471
472 /* PRD table */
473 if (hwif->host_flags & IDE_HFLAG_MMIO)
474 writel(hwif->dmatable_dma,
475 (void __iomem *)(hwif->dma_base + ATA_DMA_TABLE_OFS));
476 else
477 outl(hwif->dmatable_dma, hwif->dma_base + ATA_DMA_TABLE_OFS);
478
479 /* specify r/w */
480 if (mmio)
481 writeb(reading, (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
482 else
483 outb(reading, hwif->dma_base + ATA_DMA_CMD);
484
485 /* read DMA status for INTR & ERROR flags */
486 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
487
488 /* clear INTR & ERROR flags */
489 if (mmio)
490 writeb(dma_stat | 6,
491 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
492 else
493 outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS);
494
495 drive->waiting_for_dma = 1;
496 return 0;
497}
498
499EXPORT_SYMBOL_GPL(ide_dma_setup);
500
501void ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
502{
503 /* issue cmd to drive */
504 ide_execute_command(drive, command, &ide_dma_intr, 2*WAIT_CMD, dma_timer_expiry);
505}
506EXPORT_SYMBOL_GPL(ide_dma_exec_cmd);
507
508void ide_dma_start(ide_drive_t *drive)
509{
510 ide_hwif_t *hwif = drive->hwif;
511 u8 dma_cmd;
512
513 /* Note that this is done *after* the cmd has
514 * been issued to the drive, as per the BM-IDE spec.
515 * The Promise Ultra33 doesn't work correctly when
516 * we do this part before issuing the drive cmd.
517 */
518 if (hwif->host_flags & IDE_HFLAG_MMIO) {
519 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
520 /* start DMA */
521 writeb(dma_cmd | 1,
522 (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
523 } else {
524 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
525 outb(dma_cmd | 1, hwif->dma_base + ATA_DMA_CMD);
526 }
527
528 hwif->dma = 1;
529 wmb();
530}
531
532EXPORT_SYMBOL_GPL(ide_dma_start);
533
534/* returns 1 on error, 0 otherwise */
535int __ide_dma_end (ide_drive_t *drive)
536{
537 ide_hwif_t *hwif = drive->hwif;
538 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
539 u8 dma_stat = 0, dma_cmd = 0;
540
541 drive->waiting_for_dma = 0;
542
543 if (mmio) {
544 /* get DMA command mode */
545 dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
546 /* stop DMA */
547 writeb(dma_cmd & ~1,
548 (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
549 } else {
550 dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
551 outb(dma_cmd & ~1, hwif->dma_base + ATA_DMA_CMD);
552 }
553
554 /* get DMA status */
555 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
556
557 if (mmio)
558 /* clear the INTR & ERROR bits */
559 writeb(dma_stat | 6,
560 (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
561 else
562 outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS);
563
564 /* purge DMA mappings */
565 ide_destroy_dmatable(drive);
566 /* verify good DMA status */
567 hwif->dma = 0;
568 wmb();
569 return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0;
570}
571
572EXPORT_SYMBOL(__ide_dma_end);
573
574/* returns 1 if dma irq issued, 0 otherwise */
575int ide_dma_test_irq(ide_drive_t *drive)
576{
577 ide_hwif_t *hwif = HWIF(drive);
578 u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
579
580 /* return 1 if INTR asserted */
581 if ((dma_stat & 4) == 4)
582 return 1;
583 if (!drive->waiting_for_dma)
584 printk(KERN_WARNING "%s: (%s) called while not waiting\n",
585 drive->name, __func__);
586 return 0;
587}
588EXPORT_SYMBOL_GPL(ide_dma_test_irq);
589#else
590static inline int config_drive_for_dma(ide_drive_t *drive) { return 0; }
591#endif /* CONFIG_BLK_DEV_IDEDMA_SFF */
592
593int __ide_dma_bad_drive (ide_drive_t *drive)
594{ 211{
595 u16 *id = drive->id; 212 u16 *id = drive->id;
596 213
@@ -602,7 +219,6 @@ int __ide_dma_bad_drive (ide_drive_t *drive)
602 } 219 }
603 return 0; 220 return 0;
604} 221}
605
606EXPORT_SYMBOL(__ide_dma_bad_drive); 222EXPORT_SYMBOL(__ide_dma_bad_drive);
607 223
608static const u8 xfer_mode_bases[] = { 224static const u8 xfer_mode_bases[] = {
@@ -618,7 +234,7 @@ static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base, u8 req_mode)
618 const struct ide_port_ops *port_ops = hwif->port_ops; 234 const struct ide_port_ops *port_ops = hwif->port_ops;
619 unsigned int mask = 0; 235 unsigned int mask = 0;
620 236
621 switch(base) { 237 switch (base) {
622 case XFER_UDMA_0: 238 case XFER_UDMA_0:
623 if ((id[ATA_ID_FIELD_VALID] & 4) == 0) 239 if ((id[ATA_ID_FIELD_VALID] & 4) == 0)
624 break; 240 break;
@@ -719,7 +335,6 @@ u8 ide_find_dma_mode(ide_drive_t *drive, u8 req_mode)
719 335
720 return mode; 336 return mode;
721} 337}
722
723EXPORT_SYMBOL_GPL(ide_find_dma_mode); 338EXPORT_SYMBOL_GPL(ide_find_dma_mode);
724 339
725static int ide_tune_dma(ide_drive_t *drive) 340static int ide_tune_dma(ide_drive_t *drive)
@@ -727,7 +342,8 @@ static int ide_tune_dma(ide_drive_t *drive)
727 ide_hwif_t *hwif = drive->hwif; 342 ide_hwif_t *hwif = drive->hwif;
728 u8 speed; 343 u8 speed;
729 344
730 if (drive->nodma || ata_id_has_dma(drive->id) == 0) 345 if (ata_id_has_dma(drive->id) == 0 ||
346 (drive->dev_flags & IDE_DFLAG_NODMA))
731 return 0; 347 return 0;
732 348
733 /* consult the list of known "bad" drives */ 349 /* consult the list of known "bad" drives */
@@ -827,66 +443,59 @@ void ide_check_dma_crc(ide_drive_t *drive)
827 ide_dma_on(drive); 443 ide_dma_on(drive);
828} 444}
829 445
830#ifdef CONFIG_BLK_DEV_IDEDMA_SFF 446void ide_dma_lost_irq(ide_drive_t *drive)
831void ide_dma_lost_irq (ide_drive_t *drive)
832{ 447{
833 printk("%s: DMA interrupt recovery\n", drive->name); 448 printk(KERN_ERR "%s: DMA interrupt recovery\n", drive->name);
834} 449}
450EXPORT_SYMBOL_GPL(ide_dma_lost_irq);
835 451
836EXPORT_SYMBOL(ide_dma_lost_irq); 452void ide_dma_timeout(ide_drive_t *drive)
837
838void ide_dma_timeout (ide_drive_t *drive)
839{ 453{
840 ide_hwif_t *hwif = HWIF(drive); 454 ide_hwif_t *hwif = drive->hwif;
841 455
842 printk(KERN_ERR "%s: timeout waiting for DMA\n", drive->name); 456 printk(KERN_ERR "%s: timeout waiting for DMA\n", drive->name);
843 457
844 if (hwif->dma_ops->dma_test_irq(drive)) 458 if (hwif->dma_ops->dma_test_irq(drive))
845 return; 459 return;
846 460
461 ide_dump_status(drive, "DMA timeout", hwif->tp_ops->read_status(hwif));
462
847 hwif->dma_ops->dma_end(drive); 463 hwif->dma_ops->dma_end(drive);
848} 464}
849 465EXPORT_SYMBOL_GPL(ide_dma_timeout);
850EXPORT_SYMBOL(ide_dma_timeout);
851 466
852void ide_release_dma_engine(ide_hwif_t *hwif) 467void ide_release_dma_engine(ide_hwif_t *hwif)
853{ 468{
854 if (hwif->dmatable_cpu) { 469 if (hwif->dmatable_cpu) {
855 struct pci_dev *pdev = to_pci_dev(hwif->dev); 470 int prd_size = hwif->prd_max_nents * hwif->prd_ent_size;
856 471
857 pci_free_consistent(pdev, PRD_ENTRIES * PRD_BYTES, 472 dma_free_coherent(hwif->dev, prd_size,
858 hwif->dmatable_cpu, hwif->dmatable_dma); 473 hwif->dmatable_cpu, hwif->dmatable_dma);
859 hwif->dmatable_cpu = NULL; 474 hwif->dmatable_cpu = NULL;
860 } 475 }
861} 476}
477EXPORT_SYMBOL_GPL(ide_release_dma_engine);
862 478
863int ide_allocate_dma_engine(ide_hwif_t *hwif) 479int ide_allocate_dma_engine(ide_hwif_t *hwif)
864{ 480{
865 struct pci_dev *pdev = to_pci_dev(hwif->dev); 481 int prd_size;
866 482
867 hwif->dmatable_cpu = pci_alloc_consistent(pdev, 483 if (hwif->prd_max_nents == 0)
868 PRD_ENTRIES * PRD_BYTES, 484 hwif->prd_max_nents = PRD_ENTRIES;
869 &hwif->dmatable_dma); 485 if (hwif->prd_ent_size == 0)
486 hwif->prd_ent_size = PRD_BYTES;
870 487
871 if (hwif->dmatable_cpu) 488 prd_size = hwif->prd_max_nents * hwif->prd_ent_size;
872 return 0;
873 489
874 printk(KERN_ERR "%s: -- Error, unable to allocate DMA table.\n", 490 hwif->dmatable_cpu = dma_alloc_coherent(hwif->dev, prd_size,
491 &hwif->dmatable_dma,
492 GFP_ATOMIC);
493 if (hwif->dmatable_cpu == NULL) {
494 printk(KERN_ERR "%s: unable to allocate PRD table\n",
875 hwif->name); 495 hwif->name);
496 return -ENOMEM;
497 }
876 498
877 return 1; 499 return 0;
878} 500}
879EXPORT_SYMBOL_GPL(ide_allocate_dma_engine); 501EXPORT_SYMBOL_GPL(ide_allocate_dma_engine);
880
881const struct ide_dma_ops sff_dma_ops = {
882 .dma_host_set = ide_dma_host_set,
883 .dma_setup = ide_dma_setup,
884 .dma_exec_cmd = ide_dma_exec_cmd,
885 .dma_start = ide_dma_start,
886 .dma_end = __ide_dma_end,
887 .dma_test_irq = ide_dma_test_irq,
888 .dma_timeout = ide_dma_timeout,
889 .dma_lost_irq = ide_dma_lost_irq,
890};
891EXPORT_SYMBOL_GPL(sff_dma_ops);
892#endif /* CONFIG_BLK_DEV_IDEDMA_SFF */
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index d36f155470a4..cf0aa25470ee 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#define DRV_NAME "ide-floppy" 18#define DRV_NAME "ide-floppy"
19#define PFX DRV_NAME ": "
19 20
20#define IDEFLOPPY_VERSION "1.00" 21#define IDEFLOPPY_VERSION "1.00"
21 22
@@ -48,17 +49,17 @@
48 49
49#include "ide-floppy.h" 50#include "ide-floppy.h"
50 51
51/* define to see debug info */ 52/* module parameters */
52#define IDEFLOPPY_DEBUG_LOG 0 53static unsigned long debug_mask;
54module_param(debug_mask, ulong, 0644);
53 55
54/* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */ 56/* define to see debug info */
55#define IDEFLOPPY_DEBUG(fmt, args...) 57#define IDEFLOPPY_DEBUG_LOG 0
56 58
57#if IDEFLOPPY_DEBUG_LOG 59#if IDEFLOPPY_DEBUG_LOG
58#define debug_log(fmt, args...) \ 60#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, args)
59 printk(KERN_INFO "ide-floppy: " fmt, ## args)
60#else 61#else
61#define debug_log(fmt, args...) do {} while (0) 62#define ide_debug_log(lvl, fmt, args...) do {} while (0)
62#endif 63#endif
63 64
64/* 65/*
@@ -73,18 +74,17 @@
73#define CAPACITY_CURRENT 0x02 74#define CAPACITY_CURRENT 0x02
74#define CAPACITY_NO_CARTRIDGE 0x03 75#define CAPACITY_NO_CARTRIDGE 0x03
75 76
76#define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */ 77/*
78 * The following delay solves a problem with ATAPI Zip 100 drive where BSY bit
79 * was apparently being deasserted before the unit was ready to receive data.
80 */
81#define IDEFLOPPY_PC_DELAY (HZ/20) /* default delay for ZIP 100 (50ms) */
77 82
78/* Error code returned in rq->errors to the higher part of the driver. */ 83/* Error code returned in rq->errors to the higher part of the driver. */
79#define IDEFLOPPY_ERROR_GENERAL 101 84#define IDEFLOPPY_ERROR_GENERAL 101
80 85
81static DEFINE_MUTEX(idefloppy_ref_mutex); 86static DEFINE_MUTEX(idefloppy_ref_mutex);
82 87
83#define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
84
85#define ide_floppy_g(disk) \
86 container_of((disk)->private_data, struct ide_floppy_obj, driver)
87
88static void idefloppy_cleanup_obj(struct kref *); 88static void idefloppy_cleanup_obj(struct kref *);
89 89
90static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk) 90static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
@@ -92,7 +92,7 @@ static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
92 struct ide_floppy_obj *floppy = NULL; 92 struct ide_floppy_obj *floppy = NULL;
93 93
94 mutex_lock(&idefloppy_ref_mutex); 94 mutex_lock(&idefloppy_ref_mutex);
95 floppy = ide_floppy_g(disk); 95 floppy = ide_drv_g(disk, ide_floppy_obj);
96 if (floppy) { 96 if (floppy) {
97 if (ide_device_get(floppy->drive)) 97 if (ide_device_get(floppy->drive))
98 floppy = NULL; 98 floppy = NULL;
@@ -123,13 +123,21 @@ static int idefloppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
123 struct request *rq = HWGROUP(drive)->rq; 123 struct request *rq = HWGROUP(drive)->rq;
124 int error; 124 int error;
125 125
126 debug_log("Reached %s\n", __func__); 126 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
127 127
128 switch (uptodate) { 128 switch (uptodate) {
129 case 0: error = IDEFLOPPY_ERROR_GENERAL; break; 129 case 0:
130 case 1: error = 0; break; 130 error = IDEFLOPPY_ERROR_GENERAL;
131 default: error = uptodate; 131 break;
132
133 case 1:
134 error = 0;
135 break;
136
137 default:
138 error = uptodate;
132 } 139 }
140
133 if (error) 141 if (error)
134 floppy->failed_pc = NULL; 142 floppy->failed_pc = NULL;
135 /* Why does this happen? */ 143 /* Why does this happen? */
@@ -156,13 +164,13 @@ static void idefloppy_update_buffers(ide_drive_t *drive,
156 idefloppy_end_request(drive, 1, 0); 164 idefloppy_end_request(drive, 1, 0);
157} 165}
158 166
159static void ide_floppy_callback(ide_drive_t *drive) 167static void ide_floppy_callback(ide_drive_t *drive, int dsc)
160{ 168{
161 idefloppy_floppy_t *floppy = drive->driver_data; 169 idefloppy_floppy_t *floppy = drive->driver_data;
162 struct ide_atapi_pc *pc = floppy->pc; 170 struct ide_atapi_pc *pc = drive->pc;
163 int uptodate = pc->error ? 0 : 1; 171 int uptodate = pc->error ? 0 : 1;
164 172
165 debug_log("Reached %s\n", __func__); 173 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
166 174
167 if (floppy->failed_pc == pc) 175 if (floppy->failed_pc == pc)
168 floppy->failed_pc = NULL; 176 floppy->failed_pc = NULL;
@@ -171,7 +179,7 @@ static void ide_floppy_callback(ide_drive_t *drive)
171 (pc->rq && blk_pc_request(pc->rq))) 179 (pc->rq && blk_pc_request(pc->rq)))
172 uptodate = 1; /* FIXME */ 180 uptodate = 1; /* FIXME */
173 else if (pc->c[0] == GPCMD_REQUEST_SENSE) { 181 else if (pc->c[0] == GPCMD_REQUEST_SENSE) {
174 u8 *buf = floppy->pc->buf; 182 u8 *buf = pc->buf;
175 183
176 if (!pc->error) { 184 if (!pc->error) {
177 floppy->sense_key = buf[2] & 0x0F; 185 floppy->sense_key = buf[2] & 0x0F;
@@ -181,99 +189,20 @@ static void ide_floppy_callback(ide_drive_t *drive)
181 (u16)get_unaligned((u16 *)&buf[16]) : 0x10000; 189 (u16)get_unaligned((u16 *)&buf[16]) : 0x10000;
182 190
183 if (floppy->failed_pc) 191 if (floppy->failed_pc)
184 debug_log("pc = %x, ", floppy->failed_pc->c[0]); 192 ide_debug_log(IDE_DBG_PC, "pc = %x, ",
193 floppy->failed_pc->c[0]);
185 194
186 debug_log("sense key = %x, asc = %x, ascq = %x\n", 195 ide_debug_log(IDE_DBG_SENSE, "sense key = %x, asc = %x,"
187 floppy->sense_key, floppy->asc, floppy->ascq); 196 "ascq = %x\n", floppy->sense_key,
197 floppy->asc, floppy->ascq);
188 } else 198 } else
189 printk(KERN_ERR "Error in REQUEST SENSE itself - " 199 printk(KERN_ERR PFX "Error in REQUEST SENSE itself - "
190 "Aborting request!\n"); 200 "Aborting request!\n");
191 } 201 }
192 202
193 idefloppy_end_request(drive, uptodate, 0); 203 idefloppy_end_request(drive, uptodate, 0);
194} 204}
195 205
196void ide_floppy_create_request_sense_cmd(struct ide_atapi_pc *pc)
197{
198 ide_init_pc(pc);
199 pc->c[0] = GPCMD_REQUEST_SENSE;
200 pc->c[4] = 255;
201 pc->req_xfer = 18;
202}
203
204/*
205 * Called when an error was detected during the last packet command. We queue a
206 * request sense packet command in the head of the request list.
207 */
208static void idefloppy_retry_pc(ide_drive_t *drive)
209{
210 struct ide_floppy_obj *floppy = drive->driver_data;
211 struct request *rq = &floppy->request_sense_rq;
212 struct ide_atapi_pc *pc = &floppy->request_sense_pc;
213
214 (void)ide_read_error(drive);
215 ide_floppy_create_request_sense_cmd(pc);
216 ide_queue_pc_head(drive, floppy->disk, pc, rq);
217}
218
219/* The usual interrupt handler called during a packet command. */
220static ide_startstop_t idefloppy_pc_intr(ide_drive_t *drive)
221{
222 idefloppy_floppy_t *floppy = drive->driver_data;
223
224 return ide_pc_intr(drive, floppy->pc, idefloppy_pc_intr,
225 WAIT_FLOPPY_CMD, NULL, idefloppy_update_buffers,
226 idefloppy_retry_pc, NULL, ide_io_buffers);
227}
228
229/*
230 * What we have here is a classic case of a top half / bottom half interrupt
231 * service routine. In interrupt mode, the device sends an interrupt to signal
232 * that it is ready to receive a packet. However, we need to delay about 2-3
233 * ticks before issuing the packet or we gets in trouble.
234 */
235static int idefloppy_transfer_pc(ide_drive_t *drive)
236{
237 idefloppy_floppy_t *floppy = drive->driver_data;
238
239 /* Send the actual packet */
240 drive->hwif->tp_ops->output_data(drive, NULL, floppy->pc->c, 12);
241
242 /* Timeout for the packet command */
243 return WAIT_FLOPPY_CMD;
244}
245
246/*
247 * Called as an interrupt (or directly). When the device says it's ready for a
248 * packet, we schedule the packet transfer to occur about 2-3 ticks later in
249 * transfer_pc.
250 */
251static ide_startstop_t idefloppy_start_pc_transfer(ide_drive_t *drive)
252{
253 idefloppy_floppy_t *floppy = drive->driver_data;
254 struct ide_atapi_pc *pc = floppy->pc;
255 ide_expiry_t *expiry;
256 unsigned int timeout;
257
258 /*
259 * The following delay solves a problem with ATAPI Zip 100 drives
260 * where the Busy flag was apparently being deasserted before the
261 * unit was ready to receive data. This was happening on a
262 * 1200 MHz Athlon system. 10/26/01 25msec is too short,
263 * 40 and 50msec work well. idefloppy_pc_intr will not be actually
264 * used until after the packet is moved in about 50 msec.
265 */
266 if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) {
267 timeout = floppy->ticks;
268 expiry = &idefloppy_transfer_pc;
269 } else {
270 timeout = WAIT_FLOPPY_CMD;
271 expiry = NULL;
272 }
273
274 return ide_transfer_pc(drive, pc, idefloppy_pc_intr, timeout, expiry);
275}
276
277static void ide_floppy_report_error(idefloppy_floppy_t *floppy, 206static void ide_floppy_report_error(idefloppy_floppy_t *floppy,
278 struct ide_atapi_pc *pc) 207 struct ide_atapi_pc *pc)
279{ 208{
@@ -283,7 +212,7 @@ static void ide_floppy_report_error(idefloppy_floppy_t *floppy,
283 floppy->ascq == 0x00) 212 floppy->ascq == 0x00)
284 return; 213 return;
285 214
286 printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x, key = %2x, " 215 printk(KERN_ERR PFX "%s: I/O error, pc = %2x, key = %2x, "
287 "asc = %2x, ascq = %2x\n", 216 "asc = %2x, ascq = %2x\n",
288 floppy->drive->name, pc->c[0], floppy->sense_key, 217 floppy->drive->name, pc->c[0], floppy->sense_key,
289 floppy->asc, floppy->ascq); 218 floppy->asc, floppy->ascq);
@@ -298,8 +227,9 @@ static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
298 if (floppy->failed_pc == NULL && 227 if (floppy->failed_pc == NULL &&
299 pc->c[0] != GPCMD_REQUEST_SENSE) 228 pc->c[0] != GPCMD_REQUEST_SENSE)
300 floppy->failed_pc = pc; 229 floppy->failed_pc = pc;
230
301 /* Set the current packet command */ 231 /* Set the current packet command */
302 floppy->pc = pc; 232 drive->pc = pc;
303 233
304 if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) { 234 if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) {
305 if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR)) 235 if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR))
@@ -308,16 +238,15 @@ static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
308 pc->error = IDEFLOPPY_ERROR_GENERAL; 238 pc->error = IDEFLOPPY_ERROR_GENERAL;
309 239
310 floppy->failed_pc = NULL; 240 floppy->failed_pc = NULL;
311 drive->pc_callback(drive); 241 drive->pc_callback(drive, 0);
312 return ide_stopped; 242 return ide_stopped;
313 } 243 }
314 244
315 debug_log("Retry number - %d\n", pc->retries); 245 ide_debug_log(IDE_DBG_FUNC, "%s: Retry #%d\n", __func__, pc->retries);
316 246
317 pc->retries++; 247 pc->retries++;
318 248
319 return ide_issue_pc(drive, pc, idefloppy_start_pc_transfer, 249 return ide_issue_pc(drive, WAIT_FLOPPY_CMD, NULL);
320 WAIT_FLOPPY_CMD, NULL);
321} 250}
322 251
323void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *pc) 252void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *pc)
@@ -347,23 +276,23 @@ void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
347 length += 32; 276 length += 32;
348 break; 277 break;
349 default: 278 default:
350 printk(KERN_ERR "ide-floppy: unsupported page code " 279 printk(KERN_ERR PFX "unsupported page code in %s\n", __func__);
351 "in create_mode_sense_cmd\n");
352 } 280 }
353 put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]); 281 put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]);
354 pc->req_xfer = length; 282 pc->req_xfer = length;
355} 283}
356 284
357static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy, 285static void idefloppy_create_rw_cmd(ide_drive_t *drive,
358 struct ide_atapi_pc *pc, struct request *rq, 286 struct ide_atapi_pc *pc, struct request *rq,
359 unsigned long sector) 287 unsigned long sector)
360{ 288{
289 idefloppy_floppy_t *floppy = drive->driver_data;
361 int block = sector / floppy->bs_factor; 290 int block = sector / floppy->bs_factor;
362 int blocks = rq->nr_sectors / floppy->bs_factor; 291 int blocks = rq->nr_sectors / floppy->bs_factor;
363 int cmd = rq_data_dir(rq); 292 int cmd = rq_data_dir(rq);
364 293
365 debug_log("create_rw10_cmd: block == %d, blocks == %d\n", 294 ide_debug_log(IDE_DBG_FUNC, "%s: block: %d, blocks: %d\n", __func__,
366 block, blocks); 295 block, blocks);
367 296
368 ide_init_pc(pc); 297 ide_init_pc(pc);
369 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10; 298 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
@@ -408,41 +337,42 @@ static ide_startstop_t idefloppy_do_request(ide_drive_t *drive,
408 struct ide_atapi_pc *pc; 337 struct ide_atapi_pc *pc;
409 unsigned long block = (unsigned long)block_s; 338 unsigned long block = (unsigned long)block_s;
410 339
411 debug_log("%s: dev: %s, cmd: 0x%x, cmd_type: %x, errors: %d\n", 340 ide_debug_log(IDE_DBG_FUNC, "%s: dev: %s, cmd: 0x%x, cmd_type: %x, "
412 __func__, rq->rq_disk ? rq->rq_disk->disk_name : "?", 341 "errors: %d\n",
413 rq->cmd[0], rq->cmd_type, rq->errors); 342 __func__, rq->rq_disk ? rq->rq_disk->disk_name : "?",
343 rq->cmd[0], rq->cmd_type, rq->errors);
414 344
415 debug_log("%s: sector: %ld, nr_sectors: %ld, current_nr_sectors: %d\n", 345 ide_debug_log(IDE_DBG_FUNC, "%s: sector: %ld, nr_sectors: %ld, "
416 __func__, (long)rq->sector, rq->nr_sectors, 346 "current_nr_sectors: %d\n",
417 rq->current_nr_sectors); 347 __func__, (long)rq->sector, rq->nr_sectors,
348 rq->current_nr_sectors);
418 349
419 if (rq->errors >= ERROR_MAX) { 350 if (rq->errors >= ERROR_MAX) {
420 if (floppy->failed_pc) 351 if (floppy->failed_pc)
421 ide_floppy_report_error(floppy, floppy->failed_pc); 352 ide_floppy_report_error(floppy, floppy->failed_pc);
422 else 353 else
423 printk(KERN_ERR "ide-floppy: %s: I/O error\n", 354 printk(KERN_ERR PFX "%s: I/O error\n", drive->name);
424 drive->name); 355
425 idefloppy_end_request(drive, 0, 0); 356 idefloppy_end_request(drive, 0, 0);
426 return ide_stopped; 357 return ide_stopped;
427 } 358 }
428 if (blk_fs_request(rq)) { 359 if (blk_fs_request(rq)) {
429 if (((long)rq->sector % floppy->bs_factor) || 360 if (((long)rq->sector % floppy->bs_factor) ||
430 (rq->nr_sectors % floppy->bs_factor)) { 361 (rq->nr_sectors % floppy->bs_factor)) {
431 printk(KERN_ERR "%s: unsupported r/w request size\n", 362 printk(KERN_ERR PFX "%s: unsupported r/w rq size\n",
432 drive->name); 363 drive->name);
433 idefloppy_end_request(drive, 0, 0); 364 idefloppy_end_request(drive, 0, 0);
434 return ide_stopped; 365 return ide_stopped;
435 } 366 }
436 pc = &floppy->queued_pc; 367 pc = &floppy->queued_pc;
437 idefloppy_create_rw_cmd(floppy, pc, rq, block); 368 idefloppy_create_rw_cmd(drive, pc, rq, block);
438 } else if (blk_special_request(rq)) { 369 } else if (blk_special_request(rq)) {
439 pc = (struct ide_atapi_pc *) rq->buffer; 370 pc = (struct ide_atapi_pc *) rq->buffer;
440 } else if (blk_pc_request(rq)) { 371 } else if (blk_pc_request(rq)) {
441 pc = &floppy->queued_pc; 372 pc = &floppy->queued_pc;
442 idefloppy_blockpc_cmd(floppy, pc, rq); 373 idefloppy_blockpc_cmd(floppy, pc, rq);
443 } else { 374 } else {
444 blk_dump_rq_flags(rq, 375 blk_dump_rq_flags(rq, PFX "unsupported command in queue");
445 "ide-floppy: unsupported command in queue");
446 idefloppy_end_request(drive, 0, 0); 376 idefloppy_end_request(drive, 0, 0);
447 return ide_stopped; 377 return ide_stopped;
448 } 378 }
@@ -475,8 +405,7 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
475 ide_floppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE); 405 ide_floppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE);
476 406
477 if (ide_queue_pc_tail(drive, disk, &pc)) { 407 if (ide_queue_pc_tail(drive, disk, &pc)) {
478 printk(KERN_ERR "ide-floppy: Can't get flexible disk page" 408 printk(KERN_ERR PFX "Can't get flexible disk page params\n");
479 " parameters\n");
480 return 1; 409 return 1;
481 } 410 }
482 411
@@ -499,7 +428,7 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
499 capacity = cyls * heads * sectors * sector_size; 428 capacity = cyls * heads * sectors * sector_size;
500 429
501 if (memcmp(page, &floppy->flexible_disk_page, 32)) 430 if (memcmp(page, &floppy->flexible_disk_page, 32))
502 printk(KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, " 431 printk(KERN_INFO PFX "%s: %dkB, %d/%d/%d CHS, %d kBps, "
503 "%d sector size, %d rpm\n", 432 "%d sector size, %d rpm\n",
504 drive->name, capacity / 1024, cyls, heads, 433 drive->name, capacity / 1024, cyls, heads,
505 sectors, transfer_rate / 8, sector_size, rpm); 434 sectors, transfer_rate / 8, sector_size, rpm);
@@ -511,7 +440,7 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
511 lba_capacity = floppy->blocks * floppy->block_size; 440 lba_capacity = floppy->blocks * floppy->block_size;
512 441
513 if (capacity < lba_capacity) { 442 if (capacity < lba_capacity) {
514 printk(KERN_NOTICE "%s: The disk reports a capacity of %d " 443 printk(KERN_NOTICE PFX "%s: The disk reports a capacity of %d "
515 "bytes, but the drive only handles %d\n", 444 "bytes, but the drive only handles %d\n",
516 drive->name, lba_capacity, capacity); 445 drive->name, lba_capacity, capacity);
517 floppy->blocks = floppy->block_size ? 446 floppy->blocks = floppy->block_size ?
@@ -541,7 +470,7 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
541 470
542 ide_floppy_create_read_capacity_cmd(&pc); 471 ide_floppy_create_read_capacity_cmd(&pc);
543 if (ide_queue_pc_tail(drive, disk, &pc)) { 472 if (ide_queue_pc_tail(drive, disk, &pc)) {
544 printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); 473 printk(KERN_ERR PFX "Can't get floppy parameters\n");
545 return 1; 474 return 1;
546 } 475 }
547 header_len = pc.buf[3]; 476 header_len = pc.buf[3];
@@ -554,8 +483,9 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
554 blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]); 483 blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]);
555 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]); 484 length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]);
556 485
557 debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n", 486 ide_debug_log(IDE_DBG_PROBE, "Descriptor %d: %dkB, %d blocks, "
558 i, blocks * length / 1024, blocks, length); 487 "%d sector size\n",
488 i, blocks * length / 1024, blocks, length);
559 489
560 if (i) 490 if (i)
561 continue; 491 continue;
@@ -575,23 +505,24 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
575 case CAPACITY_CURRENT: 505 case CAPACITY_CURRENT:
576 /* Normal Zip/LS-120 disks */ 506 /* Normal Zip/LS-120 disks */
577 if (memcmp(cap_desc, &floppy->cap_desc, 8)) 507 if (memcmp(cap_desc, &floppy->cap_desc, 8))
578 printk(KERN_INFO "%s: %dkB, %d blocks, %d " 508 printk(KERN_INFO PFX "%s: %dkB, %d blocks, %d "
579 "sector size\n", drive->name, 509 "sector size\n",
580 blocks * length / 1024, blocks, length); 510 drive->name, blocks * length / 1024,
511 blocks, length);
581 memcpy(&floppy->cap_desc, cap_desc, 8); 512 memcpy(&floppy->cap_desc, cap_desc, 8);
582 513
583 if (!length || length % 512) { 514 if (!length || length % 512) {
584 printk(KERN_NOTICE "%s: %d bytes block size " 515 printk(KERN_NOTICE PFX "%s: %d bytes block size"
585 "not supported\n", drive->name, length); 516 " not supported\n", drive->name, length);
586 } else { 517 } else {
587 floppy->blocks = blocks; 518 floppy->blocks = blocks;
588 floppy->block_size = length; 519 floppy->block_size = length;
589 floppy->bs_factor = length / 512; 520 floppy->bs_factor = length / 512;
590 if (floppy->bs_factor != 1) 521 if (floppy->bs_factor != 1)
591 printk(KERN_NOTICE "%s: warning: non " 522 printk(KERN_NOTICE PFX "%s: Warning: "
592 "512 bytes block size not " 523 "non 512 bytes block size not "
593 "fully supported\n", 524 "fully supported\n",
594 drive->name); 525 drive->name);
595 rc = 0; 526 rc = 0;
596 } 527 }
597 break; 528 break;
@@ -600,15 +531,16 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
600 * This is a KERN_ERR so it appears on screen 531 * This is a KERN_ERR so it appears on screen
601 * for the user to see 532 * for the user to see
602 */ 533 */
603 printk(KERN_ERR "%s: No disk in drive\n", drive->name); 534 printk(KERN_ERR PFX "%s: No disk in drive\n",
535 drive->name);
604 break; 536 break;
605 case CAPACITY_INVALID: 537 case CAPACITY_INVALID:
606 printk(KERN_ERR "%s: Invalid capacity for disk " 538 printk(KERN_ERR PFX "%s: Invalid capacity for disk "
607 "in drive\n", drive->name); 539 "in drive\n", drive->name);
608 break; 540 break;
609 } 541 }
610 debug_log("Descriptor 0 Code: %d\n", 542 ide_debug_log(IDE_DBG_PROBE, "Descriptor 0 Code: %d\n",
611 pc.buf[desc_start + 4] & 0x03); 543 pc.buf[desc_start + 4] & 0x03);
612 } 544 }
613 545
614 /* Clik! disk does not support get_flexible_disk_page */ 546 /* Clik! disk does not support get_flexible_disk_page */
@@ -620,7 +552,7 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
620 return rc; 552 return rc;
621} 553}
622 554
623static sector_t idefloppy_capacity(ide_drive_t *drive) 555sector_t ide_floppy_capacity(ide_drive_t *drive)
624{ 556{
625 idefloppy_floppy_t *floppy = drive->driver_data; 557 idefloppy_floppy_t *floppy = drive->driver_data;
626 unsigned long capacity = floppy->blocks * floppy->bs_factor; 558 unsigned long capacity = floppy->blocks * floppy->bs_factor;
@@ -628,46 +560,14 @@ static sector_t idefloppy_capacity(ide_drive_t *drive)
628 return capacity; 560 return capacity;
629} 561}
630 562
631#ifdef CONFIG_IDE_PROC_FS
632ide_devset_rw_field(bios_cyl, bios_cyl);
633ide_devset_rw_field(bios_head, bios_head);
634ide_devset_rw_field(bios_sect, bios_sect);
635
636static int get_ticks(ide_drive_t *drive)
637{
638 idefloppy_floppy_t *floppy = drive->driver_data;
639 return floppy->ticks;
640}
641
642static int set_ticks(ide_drive_t *drive, int arg)
643{
644 idefloppy_floppy_t *floppy = drive->driver_data;
645 floppy->ticks = arg;
646 return 0;
647}
648
649IDE_DEVSET(ticks, DS_SYNC, get_ticks, set_ticks);
650
651static const struct ide_proc_devset idefloppy_settings[] = {
652 IDE_PROC_DEVSET(bios_cyl, 0, 1023),
653 IDE_PROC_DEVSET(bios_head, 0, 255),
654 IDE_PROC_DEVSET(bios_sect, 0, 63),
655 IDE_PROC_DEVSET(ticks, 0, 255),
656 { 0 },
657};
658#endif
659
660static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy) 563static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
661{ 564{
662 u16 *id = drive->id; 565 u16 *id = drive->id;
663 u8 gcw[2];
664
665 *((u16 *)&gcw) = id[ATA_ID_CONFIG];
666 566
667 drive->pc_callback = ide_floppy_callback; 567 drive->pc_callback = ide_floppy_callback;
568 drive->pc_update_buffers = idefloppy_update_buffers;
569 drive->pc_io_buffers = ide_io_buffers;
668 570
669 if (((gcw[0] & 0x60) >> 5) == 1)
670 drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
671 /* 571 /*
672 * We used to check revisions here. At this point however I'm giving up. 572 * We used to check revisions here. At this point however I'm giving up.
673 * Just assume they are all broken, its easier. 573 * Just assume they are all broken, its easier.
@@ -680,7 +580,7 @@ static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
680 if (!strncmp((char *)&id[ATA_ID_PROD], "IOMEGA ZIP 100 ATAPI", 20)) { 580 if (!strncmp((char *)&id[ATA_ID_PROD], "IOMEGA ZIP 100 ATAPI", 20)) {
681 drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE; 581 drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE;
682 /* This value will be visible in the /proc/ide/hdx/settings */ 582 /* This value will be visible in the /proc/ide/hdx/settings */
683 floppy->ticks = IDEFLOPPY_TICKS_DELAY; 583 drive->pc_delay = IDEFLOPPY_PC_DELAY;
684 blk_queue_max_sectors(drive->queue, 64); 584 blk_queue_max_sectors(drive->queue, 64);
685 } 585 }
686 586
@@ -714,7 +614,7 @@ static void ide_floppy_remove(ide_drive_t *drive)
714 614
715static void idefloppy_cleanup_obj(struct kref *kref) 615static void idefloppy_cleanup_obj(struct kref *kref)
716{ 616{
717 struct ide_floppy_obj *floppy = to_ide_floppy(kref); 617 struct ide_floppy_obj *floppy = to_ide_drv(kref, ide_floppy_obj);
718 ide_drive_t *drive = floppy->drive; 618 ide_drive_t *drive = floppy->drive;
719 struct gendisk *g = floppy->disk; 619 struct gendisk *g = floppy->disk;
720 620
@@ -724,24 +624,6 @@ static void idefloppy_cleanup_obj(struct kref *kref)
724 kfree(floppy); 624 kfree(floppy);
725} 625}
726 626
727#ifdef CONFIG_IDE_PROC_FS
728static int proc_idefloppy_read_capacity(char *page, char **start, off_t off,
729 int count, int *eof, void *data)
730{
731 ide_drive_t*drive = (ide_drive_t *)data;
732 int len;
733
734 len = sprintf(page, "%llu\n", (long long)idefloppy_capacity(drive));
735 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
736}
737
738static ide_proc_entry_t idefloppy_proc[] = {
739 { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL },
740 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
741 { NULL, 0, NULL, NULL }
742};
743#endif /* CONFIG_IDE_PROC_FS */
744
745static int ide_floppy_probe(ide_drive_t *); 627static int ide_floppy_probe(ide_drive_t *);
746 628
747static ide_driver_t idefloppy_driver = { 629static ide_driver_t idefloppy_driver = {
@@ -753,13 +635,12 @@ static ide_driver_t idefloppy_driver = {
753 .probe = ide_floppy_probe, 635 .probe = ide_floppy_probe,
754 .remove = ide_floppy_remove, 636 .remove = ide_floppy_remove,
755 .version = IDEFLOPPY_VERSION, 637 .version = IDEFLOPPY_VERSION,
756 .media = ide_floppy,
757 .do_request = idefloppy_do_request, 638 .do_request = idefloppy_do_request,
758 .end_request = idefloppy_end_request, 639 .end_request = idefloppy_end_request,
759 .error = __ide_error, 640 .error = __ide_error,
760#ifdef CONFIG_IDE_PROC_FS 641#ifdef CONFIG_IDE_PROC_FS
761 .proc = idefloppy_proc, 642 .proc = ide_floppy_proc,
762 .settings = idefloppy_settings, 643 .settings = ide_floppy_settings,
763#endif 644#endif
764}; 645};
765 646
@@ -770,14 +651,14 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
770 ide_drive_t *drive; 651 ide_drive_t *drive;
771 int ret = 0; 652 int ret = 0;
772 653
773 debug_log("Reached %s\n", __func__);
774
775 floppy = ide_floppy_get(disk); 654 floppy = ide_floppy_get(disk);
776 if (!floppy) 655 if (!floppy)
777 return -ENXIO; 656 return -ENXIO;
778 657
779 drive = floppy->drive; 658 drive = floppy->drive;
780 659
660 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
661
781 floppy->openers++; 662 floppy->openers++;
782 663
783 if (floppy->openers == 1) { 664 if (floppy->openers == 1) {
@@ -822,10 +703,10 @@ out_put_floppy:
822static int idefloppy_release(struct inode *inode, struct file *filp) 703static int idefloppy_release(struct inode *inode, struct file *filp)
823{ 704{
824 struct gendisk *disk = inode->i_bdev->bd_disk; 705 struct gendisk *disk = inode->i_bdev->bd_disk;
825 struct ide_floppy_obj *floppy = ide_floppy_g(disk); 706 struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
826 ide_drive_t *drive = floppy->drive; 707 ide_drive_t *drive = floppy->drive;
827 708
828 debug_log("Reached %s\n", __func__); 709 ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
829 710
830 if (floppy->openers == 1) { 711 if (floppy->openers == 1) {
831 ide_set_media_lock(drive, disk, 0); 712 ide_set_media_lock(drive, disk, 0);
@@ -841,7 +722,8 @@ static int idefloppy_release(struct inode *inode, struct file *filp)
841 722
842static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo) 723static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
843{ 724{
844 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk); 725 struct ide_floppy_obj *floppy = ide_drv_g(bdev->bd_disk,
726 ide_floppy_obj);
845 ide_drive_t *drive = floppy->drive; 727 ide_drive_t *drive = floppy->drive;
846 728
847 geo->heads = drive->bios_head; 729 geo->heads = drive->bios_head;
@@ -850,64 +732,15 @@ static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
850 return 0; 732 return 0;
851} 733}
852 734
853static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc,
854 unsigned long arg, unsigned int cmd)
855{
856 idefloppy_floppy_t *floppy = drive->driver_data;
857 struct gendisk *disk = floppy->disk;
858 int prevent = (arg && cmd != CDROMEJECT) ? 1 : 0;
859
860 if (floppy->openers > 1)
861 return -EBUSY;
862
863 ide_set_media_lock(drive, disk, prevent);
864
865 if (cmd == CDROMEJECT)
866 ide_do_start_stop(drive, disk, 2);
867
868 return 0;
869}
870
871static int idefloppy_ioctl(struct inode *inode, struct file *file,
872 unsigned int cmd, unsigned long arg)
873{
874 struct block_device *bdev = inode->i_bdev;
875 struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
876 ide_drive_t *drive = floppy->drive;
877 struct ide_atapi_pc pc;
878 void __user *argp = (void __user *)arg;
879 int err;
880
881 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR)
882 return ide_floppy_lockdoor(drive, &pc, arg, cmd);
883
884 err = ide_floppy_format_ioctl(drive, file, cmd, argp);
885 if (err != -ENOTTY)
886 return err;
887
888 /*
889 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
890 * and CDROM_SEND_PACKET (legacy) ioctls
891 */
892 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
893 err = scsi_cmd_ioctl(file, bdev->bd_disk->queue,
894 bdev->bd_disk, cmd, argp);
895
896 if (err == -ENOTTY)
897 err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
898
899 return err;
900}
901
902static int idefloppy_media_changed(struct gendisk *disk) 735static int idefloppy_media_changed(struct gendisk *disk)
903{ 736{
904 struct ide_floppy_obj *floppy = ide_floppy_g(disk); 737 struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
905 ide_drive_t *drive = floppy->drive; 738 ide_drive_t *drive = floppy->drive;
906 int ret; 739 int ret;
907 740
908 /* do not scan partitions twice if this is a removable device */ 741 /* do not scan partitions twice if this is a removable device */
909 if (drive->attach) { 742 if (drive->dev_flags & IDE_DFLAG_ATTACH) {
910 drive->attach = 0; 743 drive->dev_flags &= ~IDE_DFLAG_ATTACH;
911 return 0; 744 return 0;
912 } 745 }
913 ret = !!(drive->atapi_flags & IDE_AFLAG_MEDIA_CHANGED); 746 ret = !!(drive->atapi_flags & IDE_AFLAG_MEDIA_CHANGED);
@@ -917,8 +750,8 @@ static int idefloppy_media_changed(struct gendisk *disk)
917 750
918static int idefloppy_revalidate_disk(struct gendisk *disk) 751static int idefloppy_revalidate_disk(struct gendisk *disk)
919{ 752{
920 struct ide_floppy_obj *floppy = ide_floppy_g(disk); 753 struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
921 set_capacity(disk, idefloppy_capacity(floppy->drive)); 754 set_capacity(disk, ide_floppy_capacity(floppy->drive));
922 return 0; 755 return 0;
923} 756}
924 757
@@ -926,7 +759,7 @@ static struct block_device_operations idefloppy_ops = {
926 .owner = THIS_MODULE, 759 .owner = THIS_MODULE,
927 .open = idefloppy_open, 760 .open = idefloppy_open,
928 .release = idefloppy_release, 761 .release = idefloppy_release,
929 .ioctl = idefloppy_ioctl, 762 .ioctl = ide_floppy_ioctl,
930 .getgeo = idefloppy_getgeo, 763 .getgeo = idefloppy_getgeo,
931 .media_changed = idefloppy_media_changed, 764 .media_changed = idefloppy_media_changed,
932 .revalidate_disk = idefloppy_revalidate_disk 765 .revalidate_disk = idefloppy_revalidate_disk
@@ -944,14 +777,14 @@ static int ide_floppy_probe(ide_drive_t *drive)
944 goto failed; 777 goto failed;
945 778
946 if (!ide_check_atapi_device(drive, DRV_NAME)) { 779 if (!ide_check_atapi_device(drive, DRV_NAME)) {
947 printk(KERN_ERR "ide-floppy: %s: not supported by this version" 780 printk(KERN_ERR PFX "%s: not supported by this version of "
948 " of ide-floppy\n", drive->name); 781 DRV_NAME "\n", drive->name);
949 goto failed; 782 goto failed;
950 } 783 }
951 floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL); 784 floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL);
952 if (!floppy) { 785 if (!floppy) {
953 printk(KERN_ERR "ide-floppy: %s: Can't allocate a floppy" 786 printk(KERN_ERR PFX "%s: Can't allocate a floppy structure\n",
954 " structure\n", drive->name); 787 drive->name);
955 goto failed; 788 goto failed;
956 } 789 }
957 790
@@ -971,13 +804,16 @@ static int ide_floppy_probe(ide_drive_t *drive)
971 804
972 drive->driver_data = floppy; 805 drive->driver_data = floppy;
973 806
807 drive->debug_mask = debug_mask;
808
974 idefloppy_setup(drive, floppy); 809 idefloppy_setup(drive, floppy);
810 drive->dev_flags |= IDE_DFLAG_ATTACH;
975 811
976 g->minors = 1 << PARTN_BITS; 812 g->minors = 1 << PARTN_BITS;
977 g->driverfs_dev = &drive->gendev; 813 g->driverfs_dev = &drive->gendev;
978 g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0; 814 if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
815 g->flags = GENHD_FL_REMOVABLE;
979 g->fops = &idefloppy_ops; 816 g->fops = &idefloppy_ops;
980 drive->attach = 1;
981 add_disk(g); 817 add_disk(g);
982 return 0; 818 return 0;
983 819
@@ -994,7 +830,7 @@ static void __exit idefloppy_exit(void)
994 830
995static int __init idefloppy_init(void) 831static int __init idefloppy_init(void)
996{ 832{
997 printk("ide-floppy driver " IDEFLOPPY_VERSION "\n"); 833 printk(KERN_INFO DRV_NAME " driver " IDEFLOPPY_VERSION "\n");
998 return driver_register(&idefloppy_driver.gen_driver); 834 return driver_register(&idefloppy_driver.gen_driver);
999} 835}
1000 836
diff --git a/drivers/ide/ide-floppy.h b/drivers/ide/ide-floppy.h
index ecadc2bc322d..17cf865e583d 100644
--- a/drivers/ide/ide-floppy.h
+++ b/drivers/ide/ide-floppy.h
@@ -13,20 +13,14 @@ typedef struct ide_floppy_obj {
13 struct kref kref; 13 struct kref kref;
14 unsigned int openers; /* protected by BKL for now */ 14 unsigned int openers; /* protected by BKL for now */
15 15
16 /* Current packet command */
17 struct ide_atapi_pc *pc;
18 /* Last failed packet command */ 16 /* Last failed packet command */
19 struct ide_atapi_pc *failed_pc; 17 struct ide_atapi_pc *failed_pc;
20 /* used for blk_{fs,pc}_request() requests */ 18 /* used for blk_{fs,pc}_request() requests */
21 struct ide_atapi_pc queued_pc; 19 struct ide_atapi_pc queued_pc;
22 20
23 struct ide_atapi_pc request_sense_pc;
24 struct request request_sense_rq;
25
26 /* Last error information */ 21 /* Last error information */
27 u8 sense_key, asc, ascq; 22 u8 sense_key, asc, ascq;
28 /* delay this long before sending packet command */ 23
29 u8 ticks;
30 int progress_indication; 24 int progress_indication;
31 25
32 /* Device information */ 26 /* Device information */
@@ -54,10 +48,15 @@ typedef struct ide_floppy_obj {
54/* ide-floppy.c */ 48/* ide-floppy.c */
55void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *, u8); 49void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *, u8);
56void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *); 50void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *);
57void ide_floppy_create_request_sense_cmd(struct ide_atapi_pc *); 51sector_t ide_floppy_capacity(ide_drive_t *);
58 52
59/* ide-floppy_ioctl.c */ 53/* ide-floppy_ioctl.c */
60int ide_floppy_format_ioctl(ide_drive_t *, struct file *, unsigned int, 54int ide_floppy_ioctl(struct inode *, struct file *, unsigned, unsigned long);
61 void __user *); 55
56#ifdef CONFIG_IDE_PROC_FS
57/* ide-floppy_proc.c */
58extern ide_proc_entry_t ide_floppy_proc[];
59extern const struct ide_proc_devset ide_floppy_settings[];
60#endif
62 61
63#endif /*__IDE_FLOPPY_H */ 62#endif /*__IDE_FLOPPY_H */
diff --git a/drivers/ide/ide-floppy_ioctl.c b/drivers/ide/ide-floppy_ioctl.c
index 5ffc4512d14b..a3a7a0809e2b 100644
--- a/drivers/ide/ide-floppy_ioctl.c
+++ b/drivers/ide/ide-floppy_ioctl.c
@@ -195,7 +195,7 @@ static int ide_floppy_get_format_progress(ide_drive_t *drive, int __user *arg)
195 int progress_indication = 0x10000; 195 int progress_indication = 0x10000;
196 196
197 if (drive->atapi_flags & IDE_AFLAG_SRFP) { 197 if (drive->atapi_flags & IDE_AFLAG_SRFP) {
198 ide_floppy_create_request_sense_cmd(&pc); 198 ide_create_request_sense_cmd(drive, &pc);
199 if (ide_queue_pc_tail(drive, floppy->disk, &pc)) 199 if (ide_queue_pc_tail(drive, floppy->disk, &pc))
200 return -EIO; 200 return -EIO;
201 201
@@ -223,8 +223,26 @@ static int ide_floppy_get_format_progress(ide_drive_t *drive, int __user *arg)
223 return 0; 223 return 0;
224} 224}
225 225
226int ide_floppy_format_ioctl(ide_drive_t *drive, struct file *file, 226static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc,
227 unsigned int cmd, void __user *argp) 227 unsigned long arg, unsigned int cmd)
228{
229 idefloppy_floppy_t *floppy = drive->driver_data;
230 struct gendisk *disk = floppy->disk;
231 int prevent = (arg && cmd != CDROMEJECT) ? 1 : 0;
232
233 if (floppy->openers > 1)
234 return -EBUSY;
235
236 ide_set_media_lock(drive, disk, prevent);
237
238 if (cmd == CDROMEJECT)
239 ide_do_start_stop(drive, disk, 2);
240
241 return 0;
242}
243
244static int ide_floppy_format_ioctl(ide_drive_t *drive, struct file *file,
245 unsigned int cmd, void __user *argp)
228{ 246{
229 switch (cmd) { 247 switch (cmd) {
230 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED: 248 case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
@@ -241,3 +259,35 @@ int ide_floppy_format_ioctl(ide_drive_t *drive, struct file *file,
241 return -ENOTTY; 259 return -ENOTTY;
242 } 260 }
243} 261}
262
263int ide_floppy_ioctl(struct inode *inode, struct file *file,
264 unsigned int cmd, unsigned long arg)
265{
266 struct block_device *bdev = inode->i_bdev;
267 struct ide_floppy_obj *floppy = ide_drv_g(bdev->bd_disk,
268 ide_floppy_obj);
269 ide_drive_t *drive = floppy->drive;
270 struct ide_atapi_pc pc;
271 void __user *argp = (void __user *)arg;
272 int err;
273
274 if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR)
275 return ide_floppy_lockdoor(drive, &pc, arg, cmd);
276
277 err = ide_floppy_format_ioctl(drive, file, cmd, argp);
278 if (err != -ENOTTY)
279 return err;
280
281 /*
282 * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
283 * and CDROM_SEND_PACKET (legacy) ioctls
284 */
285 if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
286 err = scsi_cmd_ioctl(file, bdev->bd_disk->queue,
287 bdev->bd_disk, cmd, argp);
288
289 if (err == -ENOTTY)
290 err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
291
292 return err;
293}
diff --git a/drivers/ide/ide-floppy_proc.c b/drivers/ide/ide-floppy_proc.c
new file mode 100644
index 000000000000..76f0c6c4eca3
--- /dev/null
+++ b/drivers/ide/ide-floppy_proc.c
@@ -0,0 +1,33 @@
1#include <linux/kernel.h>
2#include <linux/ide.h>
3
4#include "ide-floppy.h"
5
6static int proc_idefloppy_read_capacity(char *page, char **start, off_t off,
7 int count, int *eof, void *data)
8{
9 ide_drive_t*drive = (ide_drive_t *)data;
10 int len;
11
12 len = sprintf(page, "%llu\n", (long long)ide_floppy_capacity(drive));
13 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
14}
15
16ide_proc_entry_t ide_floppy_proc[] = {
17 { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL },
18 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
19 { NULL, 0, NULL, NULL }
20};
21
22ide_devset_rw_field(bios_cyl, bios_cyl);
23ide_devset_rw_field(bios_head, bios_head);
24ide_devset_rw_field(bios_sect, bios_sect);
25ide_devset_rw_field(ticks, pc_delay);
26
27const struct ide_proc_devset ide_floppy_settings[] = {
28 IDE_PROC_DEVSET(bios_cyl, 0, 1023),
29 IDE_PROC_DEVSET(bios_head, 0, 255),
30 IDE_PROC_DEVSET(bios_sect, 0, 63),
31 IDE_PROC_DEVSET(ticks, 0, 255),
32 { 0 },
33};
diff --git a/drivers/ide/ide-generic.c b/drivers/ide/ide-generic.c
index 0a3cb0c33ae5..81a5282ce1eb 100644
--- a/drivers/ide/ide-generic.c
+++ b/drivers/ide/ide-generic.c
@@ -137,15 +137,10 @@ static void ide_generic_check_pci_legacy_iobases(int *primary, int *secondary)
137 137
138static int __init ide_generic_init(void) 138static int __init ide_generic_init(void)
139{ 139{
140 hw_regs_t hw[MAX_HWIFS], *hws[MAX_HWIFS]; 140 hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
141 struct ide_host *host;
142 unsigned long io_addr; 141 unsigned long io_addr;
143 int i, rc, primary = 0, secondary = 0; 142 int i, rc = 0, primary = 0, secondary = 0;
144 143
145#ifdef CONFIG_MIPS
146 if (!ide_probe_legacy())
147 return -ENODEV;
148#endif
149 ide_generic_check_pci_legacy_iobases(&primary, &secondary); 144 ide_generic_check_pci_legacy_iobases(&primary, &secondary);
150 145
151 if (!probe_mask) { 146 if (!probe_mask) {
@@ -161,13 +156,9 @@ static int __init ide_generic_init(void)
161 printk(KERN_INFO DRV_NAME ": enforcing probing of I/O ports " 156 printk(KERN_INFO DRV_NAME ": enforcing probing of I/O ports "
162 "upon user request\n"); 157 "upon user request\n");
163 158
164 memset(hws, 0, sizeof(hw_regs_t *) * MAX_HWIFS);
165
166 for (i = 0; i < ARRAY_SIZE(legacy_bases); i++) { 159 for (i = 0; i < ARRAY_SIZE(legacy_bases); i++) {
167 io_addr = legacy_bases[i]; 160 io_addr = legacy_bases[i];
168 161
169 hws[i] = NULL;
170
171 if ((probe_mask & (1 << i)) && io_addr) { 162 if ((probe_mask & (1 << i)) && io_addr) {
172 if (!request_region(io_addr, 8, DRV_NAME)) { 163 if (!request_region(io_addr, 8, DRV_NAME)) {
173 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX " 164 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX "
@@ -184,45 +175,27 @@ static int __init ide_generic_init(void)
184 continue; 175 continue;
185 } 176 }
186 177
187 memset(&hw[i], 0, sizeof(hw[i])); 178 memset(&hw, 0, sizeof(hw));
188 ide_std_init_ports(&hw[i], io_addr, io_addr + 0x206); 179 ide_std_init_ports(&hw, io_addr, io_addr + 0x206);
189#ifdef CONFIG_IA64 180#ifdef CONFIG_IA64
190 hw[i].irq = isa_irq_to_vector(legacy_irqs[i]); 181 hw.irq = isa_irq_to_vector(legacy_irqs[i]);
191#else 182#else
192 hw[i].irq = legacy_irqs[i]; 183 hw.irq = legacy_irqs[i];
193#endif 184#endif
194 hw[i].chipset = ide_generic; 185 hw.chipset = ide_generic;
195 186
196 hws[i] = &hw[i]; 187 rc = ide_host_add(NULL, hws, NULL);
188 if (rc) {
189 release_region(io_addr + 0x206, 1);
190 release_region(io_addr, 8);
191 }
197 } 192 }
198 } 193 }
199 194
200 host = ide_host_alloc_all(NULL, hws);
201 if (host == NULL) {
202 rc = -ENOMEM;
203 goto err;
204 }
205
206 rc = ide_host_register(host, NULL, hws);
207 if (rc)
208 goto err_free;
209
210 if (ide_generic_sysfs_init()) 195 if (ide_generic_sysfs_init())
211 printk(KERN_ERR DRV_NAME ": failed to create ide_generic " 196 printk(KERN_ERR DRV_NAME ": failed to create ide_generic "
212 "class\n"); 197 "class\n");
213 198
214 return 0;
215err_free:
216 ide_host_free(host);
217err:
218 for (i = 0; i < MAX_HWIFS; i++) {
219 if (hws[i] == NULL)
220 continue;
221
222 io_addr = hws[i]->io_ports.data_addr;
223 release_region(io_addr + 0x206, 1);
224 release_region(io_addr, 8);
225 }
226 return rc; 199 return rc;
227} 200}
228 201
diff --git a/drivers/ide/ide-io.c b/drivers/ide/ide-io.c
index 1c51949833be..77c6eaeacefa 100644
--- a/drivers/ide/ide-io.c
+++ b/drivers/ide/ide-io.c
@@ -78,8 +78,9 @@ static int __ide_end_request(ide_drive_t *drive, struct request *rq,
78 * decide whether to reenable DMA -- 3 is a random magic for now, 78 * decide whether to reenable DMA -- 3 is a random magic for now,
79 * if we DMA timeout more than 3 times, just stay in PIO 79 * if we DMA timeout more than 3 times, just stay in PIO
80 */ 80 */
81 if (drive->state == DMA_PIO_RETRY && drive->retry_pio <= 3) { 81 if ((drive->dev_flags & IDE_DFLAG_DMA_PIO_RETRY) &&
82 drive->state = 0; 82 drive->retry_pio <= 3) {
83 drive->dev_flags &= ~IDE_DFLAG_DMA_PIO_RETRY;
83 ide_dma_on(drive); 84 ide_dma_on(drive);
84 } 85 }
85 86
@@ -131,21 +132,6 @@ int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors)
131} 132}
132EXPORT_SYMBOL(ide_end_request); 133EXPORT_SYMBOL(ide_end_request);
133 134
134/*
135 * Power Management state machine. This one is rather trivial for now,
136 * we should probably add more, like switching back to PIO on suspend
137 * to help some BIOSes, re-do the door locking on resume, etc...
138 */
139
140enum {
141 ide_pm_flush_cache = ide_pm_state_start_suspend,
142 idedisk_pm_standby,
143
144 idedisk_pm_restore_pio = ide_pm_state_start_resume,
145 idedisk_pm_idle,
146 ide_pm_restore_dma,
147};
148
149static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 stat, u8 error) 135static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 stat, u8 error)
150{ 136{
151 struct request_pm_state *pm = rq->data; 137 struct request_pm_state *pm = rq->data;
@@ -154,20 +140,20 @@ static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 s
154 return; 140 return;
155 141
156 switch (pm->pm_step) { 142 switch (pm->pm_step) {
157 case ide_pm_flush_cache: /* Suspend step 1 (flush cache) complete */ 143 case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */
158 if (pm->pm_state == PM_EVENT_FREEZE) 144 if (pm->pm_state == PM_EVENT_FREEZE)
159 pm->pm_step = ide_pm_state_completed; 145 pm->pm_step = IDE_PM_COMPLETED;
160 else 146 else
161 pm->pm_step = idedisk_pm_standby; 147 pm->pm_step = IDE_PM_STANDBY;
162 break; 148 break;
163 case idedisk_pm_standby: /* Suspend step 2 (standby) complete */ 149 case IDE_PM_STANDBY: /* Suspend step 2 (standby) */
164 pm->pm_step = ide_pm_state_completed; 150 pm->pm_step = IDE_PM_COMPLETED;
165 break; 151 break;
166 case idedisk_pm_restore_pio: /* Resume step 1 complete */ 152 case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */
167 pm->pm_step = idedisk_pm_idle; 153 pm->pm_step = IDE_PM_IDLE;
168 break; 154 break;
169 case idedisk_pm_idle: /* Resume step 2 (idle) complete */ 155 case IDE_PM_IDLE: /* Resume step 2 (idle)*/
170 pm->pm_step = ide_pm_restore_dma; 156 pm->pm_step = IDE_PM_RESTORE_DMA;
171 break; 157 break;
172 } 158 }
173} 159}
@@ -180,11 +166,12 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
180 memset(args, 0, sizeof(*args)); 166 memset(args, 0, sizeof(*args));
181 167
182 switch (pm->pm_step) { 168 switch (pm->pm_step) {
183 case ide_pm_flush_cache: /* Suspend step 1 (flush cache) */ 169 case IDE_PM_FLUSH_CACHE: /* Suspend step 1 (flush cache) */
184 if (drive->media != ide_disk) 170 if (drive->media != ide_disk)
185 break; 171 break;
186 /* Not supported? Switch to next step now. */ 172 /* Not supported? Switch to next step now. */
187 if (!drive->wcache || ata_id_flush_enabled(drive->id) == 0) { 173 if (ata_id_flush_enabled(drive->id) == 0 ||
174 (drive->dev_flags & IDE_DFLAG_WCACHE) == 0) {
188 ide_complete_power_step(drive, rq, 0, 0); 175 ide_complete_power_step(drive, rq, 0, 0);
189 return ide_stopped; 176 return ide_stopped;
190 } 177 }
@@ -193,27 +180,23 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
193 else 180 else
194 args->tf.command = ATA_CMD_FLUSH; 181 args->tf.command = ATA_CMD_FLUSH;
195 goto out_do_tf; 182 goto out_do_tf;
196 183 case IDE_PM_STANDBY: /* Suspend step 2 (standby) */
197 case idedisk_pm_standby: /* Suspend step 2 (standby) */
198 args->tf.command = ATA_CMD_STANDBYNOW1; 184 args->tf.command = ATA_CMD_STANDBYNOW1;
199 goto out_do_tf; 185 goto out_do_tf;
200 186 case IDE_PM_RESTORE_PIO: /* Resume step 1 (restore PIO) */
201 case idedisk_pm_restore_pio: /* Resume step 1 (restore PIO) */
202 ide_set_max_pio(drive); 187 ide_set_max_pio(drive);
203 /* 188 /*
204 * skip idedisk_pm_idle for ATAPI devices 189 * skip IDE_PM_IDLE for ATAPI devices
205 */ 190 */
206 if (drive->media != ide_disk) 191 if (drive->media != ide_disk)
207 pm->pm_step = ide_pm_restore_dma; 192 pm->pm_step = IDE_PM_RESTORE_DMA;
208 else 193 else
209 ide_complete_power_step(drive, rq, 0, 0); 194 ide_complete_power_step(drive, rq, 0, 0);
210 return ide_stopped; 195 return ide_stopped;
211 196 case IDE_PM_IDLE: /* Resume step 2 (idle) */
212 case idedisk_pm_idle: /* Resume step 2 (idle) */
213 args->tf.command = ATA_CMD_IDLEIMMEDIATE; 197 args->tf.command = ATA_CMD_IDLEIMMEDIATE;
214 goto out_do_tf; 198 goto out_do_tf;
215 199 case IDE_PM_RESTORE_DMA: /* Resume step 3 (restore DMA) */
216 case ide_pm_restore_dma: /* Resume step 3 (restore DMA) */
217 /* 200 /*
218 * Right now, all we do is call ide_set_dma(drive), 201 * Right now, all we do is call ide_set_dma(drive),
219 * we could be smarter and check for current xfer_speed 202 * we could be smarter and check for current xfer_speed
@@ -222,12 +205,13 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
222 if (drive->hwif->dma_ops == NULL) 205 if (drive->hwif->dma_ops == NULL)
223 break; 206 break;
224 /* 207 /*
225 * TODO: respect ->using_dma setting 208 * TODO: respect IDE_DFLAG_USING_DMA
226 */ 209 */
227 ide_set_dma(drive); 210 ide_set_dma(drive);
228 break; 211 break;
229 } 212 }
230 pm->pm_step = ide_pm_state_completed; 213
214 pm->pm_step = IDE_PM_COMPLETED;
231 return ide_stopped; 215 return ide_stopped;
232 216
233out_do_tf: 217out_do_tf:
@@ -287,7 +271,7 @@ static void ide_complete_pm_request (ide_drive_t *drive, struct request *rq)
287 if (blk_pm_suspend_request(rq)) { 271 if (blk_pm_suspend_request(rq)) {
288 blk_stop_queue(drive->queue); 272 blk_stop_queue(drive->queue);
289 } else { 273 } else {
290 drive->blocked = 0; 274 drive->dev_flags &= ~IDE_DFLAG_BLOCKED;
291 blk_start_queue(drive->queue); 275 blk_start_queue(drive->queue);
292 } 276 }
293 HWGROUP(drive)->rq = NULL; 277 HWGROUP(drive)->rq = NULL;
@@ -343,7 +327,7 @@ void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
343 drive->name, rq->pm->pm_step, stat, err); 327 drive->name, rq->pm->pm_step, stat, err);
344#endif 328#endif
345 ide_complete_power_step(drive, rq, stat, err); 329 ide_complete_power_step(drive, rq, stat, err);
346 if (pm->pm_step == ide_pm_state_completed) 330 if (pm->pm_step == IDE_PM_COMPLETED)
347 ide_complete_pm_request(drive, rq); 331 ide_complete_pm_request(drive, rq);
348 return; 332 return;
349 } 333 }
@@ -374,13 +358,14 @@ static ide_startstop_t ide_ata_error(ide_drive_t *drive, struct request *rq, u8
374{ 358{
375 ide_hwif_t *hwif = drive->hwif; 359 ide_hwif_t *hwif = drive->hwif;
376 360
377 if ((stat & ATA_BUSY) || ((stat & ATA_DF) && !drive->nowerr)) { 361 if ((stat & ATA_BUSY) ||
362 ((stat & ATA_DF) && (drive->dev_flags & IDE_DFLAG_NOWERR) == 0)) {
378 /* other bits are useless when BUSY */ 363 /* other bits are useless when BUSY */
379 rq->errors |= ERROR_RESET; 364 rq->errors |= ERROR_RESET;
380 } else if (stat & ATA_ERR) { 365 } else if (stat & ATA_ERR) {
381 /* err has different meaning on cdrom and tape */ 366 /* err has different meaning on cdrom and tape */
382 if (err == ATA_ABORTED) { 367 if (err == ATA_ABORTED) {
383 if (drive->select.b.lba && 368 if ((drive->dev_flags & IDE_DFLAG_LBA) &&
384 /* some newer drives don't support ATA_CMD_INIT_DEV_PARAMS */ 369 /* some newer drives don't support ATA_CMD_INIT_DEV_PARAMS */
385 hwif->tp_ops->read_status(hwif) == ATA_CMD_INIT_DEV_PARAMS) 370 hwif->tp_ops->read_status(hwif) == ATA_CMD_INIT_DEV_PARAMS)
386 return ide_stopped; 371 return ide_stopped;
@@ -428,7 +413,8 @@ static ide_startstop_t ide_atapi_error(ide_drive_t *drive, struct request *rq, u
428{ 413{
429 ide_hwif_t *hwif = drive->hwif; 414 ide_hwif_t *hwif = drive->hwif;
430 415
431 if ((stat & ATA_BUSY) || ((stat & ATA_DF) && !drive->nowerr)) { 416 if ((stat & ATA_BUSY) ||
417 ((stat & ATA_DF) && (drive->dev_flags & IDE_DFLAG_NOWERR) == 0)) {
432 /* other bits are useless when BUSY */ 418 /* other bits are useless when BUSY */
433 rq->errors |= ERROR_RESET; 419 rq->errors |= ERROR_RESET;
434 } else { 420 } else {
@@ -509,7 +495,7 @@ static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
509 tf->lbal = drive->sect; 495 tf->lbal = drive->sect;
510 tf->lbam = drive->cyl; 496 tf->lbam = drive->cyl;
511 tf->lbah = drive->cyl >> 8; 497 tf->lbah = drive->cyl >> 8;
512 tf->device = ((drive->head - 1) | drive->select.all) & ~ATA_LBA; 498 tf->device = (drive->head - 1) | drive->select;
513 tf->command = ATA_CMD_INIT_DEV_PARAMS; 499 tf->command = ATA_CMD_INIT_DEV_PARAMS;
514} 500}
515 501
@@ -557,30 +543,6 @@ static ide_startstop_t ide_disk_special(ide_drive_t *drive)
557 return ide_started; 543 return ide_started;
558} 544}
559 545
560/*
561 * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
562 */
563static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
564{
565 switch (req_pio) {
566 case 202:
567 case 201:
568 case 200:
569 case 102:
570 case 101:
571 case 100:
572 return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
573 case 9:
574 case 8:
575 return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
576 case 7:
577 case 6:
578 return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
579 default:
580 return 0;
581 }
582}
583
584/** 546/**
585 * do_special - issue some special commands 547 * do_special - issue some special commands
586 * @drive: drive the command is for 548 * @drive: drive the command is for
@@ -598,45 +560,12 @@ static ide_startstop_t do_special (ide_drive_t *drive)
598#ifdef DEBUG 560#ifdef DEBUG
599 printk("%s: do_special: 0x%02x\n", drive->name, s->all); 561 printk("%s: do_special: 0x%02x\n", drive->name, s->all);
600#endif 562#endif
601 if (s->b.set_tune) { 563 if (drive->media == ide_disk)
602 ide_hwif_t *hwif = drive->hwif; 564 return ide_disk_special(drive);
603 const struct ide_port_ops *port_ops = hwif->port_ops;
604 u8 req_pio = drive->tune_req;
605
606 s->b.set_tune = 0;
607
608 if (set_pio_mode_abuse(drive->hwif, req_pio)) {
609 /*
610 * take ide_lock for drive->[no_]unmask/[no_]io_32bit
611 */
612 if (req_pio == 8 || req_pio == 9) {
613 unsigned long flags;
614
615 spin_lock_irqsave(&ide_lock, flags);
616 port_ops->set_pio_mode(drive, req_pio);
617 spin_unlock_irqrestore(&ide_lock, flags);
618 } else
619 port_ops->set_pio_mode(drive, req_pio);
620 } else {
621 int keep_dma = drive->using_dma;
622
623 ide_set_pio(drive, req_pio);
624
625 if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) {
626 if (keep_dma)
627 ide_dma_on(drive);
628 }
629 }
630
631 return ide_stopped;
632 } else {
633 if (drive->media == ide_disk)
634 return ide_disk_special(drive);
635 565
636 s->all = 0; 566 s->all = 0;
637 drive->mult_req = 0; 567 drive->mult_req = 0;
638 return ide_stopped; 568 return ide_stopped;
639 }
640} 569}
641 570
642void ide_map_sg(ide_drive_t *drive, struct request *rq) 571void ide_map_sg(ide_drive_t *drive, struct request *rq)
@@ -726,10 +655,7 @@ int ide_devset_execute(ide_drive_t *drive, const struct ide_devset *setting,
726 if (!(setting->flags & DS_SYNC)) 655 if (!(setting->flags & DS_SYNC))
727 return setting->set(drive, arg); 656 return setting->set(drive, arg);
728 657
729 rq = blk_get_request(q, READ, GFP_KERNEL); 658 rq = blk_get_request(q, READ, __GFP_WAIT);
730 if (!rq)
731 return -ENOMEM;
732
733 rq->cmd_type = REQ_TYPE_SPECIAL; 659 rq->cmd_type = REQ_TYPE_SPECIAL;
734 rq->cmd_len = 5; 660 rq->cmd_len = 5;
735 rq->cmd[0] = REQ_DEVSET_EXEC; 661 rq->cmd[0] = REQ_DEVSET_EXEC;
@@ -746,7 +672,32 @@ EXPORT_SYMBOL_GPL(ide_devset_execute);
746 672
747static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq) 673static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq)
748{ 674{
749 switch (rq->cmd[0]) { 675 u8 cmd = rq->cmd[0];
676
677 if (cmd == REQ_PARK_HEADS || cmd == REQ_UNPARK_HEADS) {
678 ide_task_t task;
679 struct ide_taskfile *tf = &task.tf;
680
681 memset(&task, 0, sizeof(task));
682 if (cmd == REQ_PARK_HEADS) {
683 drive->sleep = *(unsigned long *)rq->special;
684 drive->dev_flags |= IDE_DFLAG_SLEEPING;
685 tf->command = ATA_CMD_IDLEIMMEDIATE;
686 tf->feature = 0x44;
687 tf->lbal = 0x4c;
688 tf->lbam = 0x4e;
689 tf->lbah = 0x55;
690 task.tf_flags |= IDE_TFLAG_CUSTOM_HANDLER;
691 } else /* cmd == REQ_UNPARK_HEADS */
692 tf->command = ATA_CMD_CHK_POWER;
693
694 task.tf_flags |= IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
695 task.rq = rq;
696 drive->hwif->data_phase = task.data_phase = TASKFILE_NO_DATA;
697 return do_rw_taskfile(drive, &task);
698 }
699
700 switch (cmd) {
750 case REQ_DEVSET_EXEC: 701 case REQ_DEVSET_EXEC:
751 { 702 {
752 int err, (*setfunc)(ide_drive_t *, int) = rq->special; 703 int err, (*setfunc)(ide_drive_t *, int) = rq->special;
@@ -773,11 +724,11 @@ static void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
773 struct request_pm_state *pm = rq->data; 724 struct request_pm_state *pm = rq->data;
774 725
775 if (blk_pm_suspend_request(rq) && 726 if (blk_pm_suspend_request(rq) &&
776 pm->pm_step == ide_pm_state_start_suspend) 727 pm->pm_step == IDE_PM_START_SUSPEND)
777 /* Mark drive blocked when starting the suspend sequence. */ 728 /* Mark drive blocked when starting the suspend sequence. */
778 drive->blocked = 1; 729 drive->dev_flags |= IDE_DFLAG_BLOCKED;
779 else if (blk_pm_resume_request(rq) && 730 else if (blk_pm_resume_request(rq) &&
780 pm->pm_step == ide_pm_state_start_resume) { 731 pm->pm_step == IDE_PM_START_RESUME) {
781 /* 732 /*
782 * The first thing we do on wakeup is to wait for BSY bit to 733 * The first thing we do on wakeup is to wait for BSY bit to
783 * go away (with a looong timeout) as a drive on this hwif may 734 * go away (with a looong timeout) as a drive on this hwif may
@@ -857,7 +808,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
857#endif 808#endif
858 startstop = ide_start_power_step(drive, rq); 809 startstop = ide_start_power_step(drive, rq);
859 if (startstop == ide_stopped && 810 if (startstop == ide_stopped &&
860 pm->pm_step == ide_pm_state_completed) 811 pm->pm_step == IDE_PM_COMPLETED)
861 ide_complete_pm_request(drive, rq); 812 ide_complete_pm_request(drive, rq);
862 return startstop; 813 return startstop;
863 } else if (!rq->rq_disk && blk_special_request(rq)) 814 } else if (!rq->rq_disk && blk_special_request(rq))
@@ -895,7 +846,7 @@ void ide_stall_queue (ide_drive_t *drive, unsigned long timeout)
895 if (timeout > WAIT_WORSTCASE) 846 if (timeout > WAIT_WORSTCASE)
896 timeout = WAIT_WORSTCASE; 847 timeout = WAIT_WORSTCASE;
897 drive->sleep = timeout + jiffies; 848 drive->sleep = timeout + jiffies;
898 drive->sleeping = 1; 849 drive->dev_flags |= IDE_DFLAG_SLEEPING;
899} 850}
900 851
901EXPORT_SYMBOL(ide_stall_queue); 852EXPORT_SYMBOL(ide_stall_queue);
@@ -935,18 +886,23 @@ repeat:
935 } 886 }
936 887
937 do { 888 do {
938 if ((!drive->sleeping || time_after_eq(jiffies, drive->sleep)) 889 u8 dev_s = !!(drive->dev_flags & IDE_DFLAG_SLEEPING);
939 && !elv_queue_empty(drive->queue)) { 890 u8 best_s = (best && !!(best->dev_flags & IDE_DFLAG_SLEEPING));
940 if (!best 891
941 || (drive->sleeping && (!best->sleeping || time_before(drive->sleep, best->sleep))) 892 if ((dev_s == 0 || time_after_eq(jiffies, drive->sleep)) &&
942 || (!best->sleeping && time_before(WAKEUP(drive), WAKEUP(best)))) 893 !elv_queue_empty(drive->queue)) {
943 { 894 if (best == NULL ||
895 (dev_s && (best_s == 0 || time_before(drive->sleep, best->sleep))) ||
896 (best_s == 0 && time_before(WAKEUP(drive), WAKEUP(best)))) {
944 if (!blk_queue_plugged(drive->queue)) 897 if (!blk_queue_plugged(drive->queue))
945 best = drive; 898 best = drive;
946 } 899 }
947 } 900 }
948 } while ((drive = drive->next) != hwgroup->drive); 901 } while ((drive = drive->next) != hwgroup->drive);
949 if (best && best->nice1 && !best->sleeping && best != hwgroup->drive && best->service_time > WAIT_MIN_SLEEP) { 902
903 if (best && (best->dev_flags & IDE_DFLAG_NICE1) &&
904 (best->dev_flags & IDE_DFLAG_SLEEPING) == 0 &&
905 best != hwgroup->drive && best->service_time > WAIT_MIN_SLEEP) {
950 long t = (signed long)(WAKEUP(best) - jiffies); 906 long t = (signed long)(WAKEUP(best) - jiffies);
951 if (t >= WAIT_MIN_SLEEP) { 907 if (t >= WAIT_MIN_SLEEP) {
952 /* 908 /*
@@ -955,7 +911,7 @@ repeat:
955 */ 911 */
956 drive = best->next; 912 drive = best->next;
957 do { 913 do {
958 if (!drive->sleeping 914 if ((drive->dev_flags & IDE_DFLAG_SLEEPING) == 0
959 && time_before(jiffies - best->service_time, WAKEUP(drive)) 915 && time_before(jiffies - best->service_time, WAKEUP(drive))
960 && time_before(WAKEUP(drive), jiffies + t)) 916 && time_before(WAKEUP(drive), jiffies + t))
961 { 917 {
@@ -1026,7 +982,9 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
1026 hwgroup->rq = NULL; 982 hwgroup->rq = NULL;
1027 drive = hwgroup->drive; 983 drive = hwgroup->drive;
1028 do { 984 do {
1029 if (drive->sleeping && (!sleeping || time_before(drive->sleep, sleep))) { 985 if ((drive->dev_flags & IDE_DFLAG_SLEEPING) &&
986 (sleeping == 0 ||
987 time_before(drive->sleep, sleep))) {
1030 sleeping = 1; 988 sleeping = 1;
1031 sleep = drive->sleep; 989 sleep = drive->sleep;
1032 } 990 }
@@ -1075,7 +1033,7 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
1075 } 1033 }
1076 hwgroup->hwif = hwif; 1034 hwgroup->hwif = hwif;
1077 hwgroup->drive = drive; 1035 hwgroup->drive = drive;
1078 drive->sleeping = 0; 1036 drive->dev_flags &= ~(IDE_DFLAG_SLEEPING | IDE_DFLAG_PARKED);
1079 drive->service_start = jiffies; 1037 drive->service_start = jiffies;
1080 1038
1081 if (blk_queue_plugged(drive->queue)) { 1039 if (blk_queue_plugged(drive->queue)) {
@@ -1109,7 +1067,9 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
1109 * We count how many times we loop here to make sure we service 1067 * We count how many times we loop here to make sure we service
1110 * all drives in the hwgroup without looping for ever 1068 * all drives in the hwgroup without looping for ever
1111 */ 1069 */
1112 if (drive->blocked && !blk_pm_request(rq) && !(rq->cmd_flags & REQ_PREEMPT)) { 1070 if ((drive->dev_flags & IDE_DFLAG_BLOCKED) &&
1071 blk_pm_request(rq) == 0 &&
1072 (rq->cmd_flags & REQ_PREEMPT) == 0) {
1113 drive = drive->next ? drive->next : hwgroup->drive; 1073 drive = drive->next ? drive->next : hwgroup->drive;
1114 if (loops++ < 4 && !blk_queue_plugged(drive->queue)) 1074 if (loops++ < 4 && !blk_queue_plugged(drive->queue))
1115 goto again; 1075 goto again;
@@ -1182,8 +1142,8 @@ static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
1182 * a timeout -- we'll reenable after we finish this next request 1142 * a timeout -- we'll reenable after we finish this next request
1183 * (or rather the first chunk of it) in pio. 1143 * (or rather the first chunk of it) in pio.
1184 */ 1144 */
1145 drive->dev_flags |= IDE_DFLAG_DMA_PIO_RETRY;
1185 drive->retry_pio++; 1146 drive->retry_pio++;
1186 drive->state = DMA_PIO_RETRY;
1187 ide_dma_off_quietly(drive); 1147 ide_dma_off_quietly(drive);
1188 1148
1189 /* 1149 /*
@@ -1480,23 +1440,16 @@ irqreturn_t ide_intr (int irq, void *dev_id)
1480 del_timer(&hwgroup->timer); 1440 del_timer(&hwgroup->timer);
1481 spin_unlock(&ide_lock); 1441 spin_unlock(&ide_lock);
1482 1442
1483 /* Some controllers might set DMA INTR no matter DMA or PIO; 1443 if (hwif->port_ops && hwif->port_ops->clear_irq)
1484 * bmdma status might need to be cleared even for 1444 hwif->port_ops->clear_irq(drive);
1485 * PIO interrupts to prevent spurious/lost irq.
1486 */
1487 if (hwif->ide_dma_clear_irq && !(drive->waiting_for_dma))
1488 /* ide_dma_end() needs bmdma status for error checking.
1489 * So, skip clearing bmdma status here and leave it
1490 * to ide_dma_end() if this is dma interrupt.
1491 */
1492 hwif->ide_dma_clear_irq(drive);
1493 1445
1494 if (drive->unmask) 1446 if (drive->dev_flags & IDE_DFLAG_UNMASK)
1495 local_irq_enable_in_hardirq(); 1447 local_irq_enable_in_hardirq();
1448
1496 /* service this interrupt, may set handler for next interrupt */ 1449 /* service this interrupt, may set handler for next interrupt */
1497 startstop = handler(drive); 1450 startstop = handler(drive);
1498 spin_lock_irq(&ide_lock);
1499 1451
1452 spin_lock_irq(&ide_lock);
1500 /* 1453 /*
1501 * Note that handler() may have set things up for another 1454 * Note that handler() may have set things up for another
1502 * interrupt to occur soon, but it cannot happen until 1455 * interrupt to occur soon, but it cannot happen until
diff --git a/drivers/ide/ide-ioctls.c b/drivers/ide/ide-ioctls.c
index cf01564901af..a90945f49792 100644
--- a/drivers/ide/ide-ioctls.c
+++ b/drivers/ide/ide-ioctls.c
@@ -62,7 +62,7 @@ static int ide_get_identity_ioctl(ide_drive_t *drive, unsigned int cmd,
62 int size = (cmd == HDIO_GET_IDENTITY) ? (ATA_ID_WORDS * 2) : 142; 62 int size = (cmd == HDIO_GET_IDENTITY) ? (ATA_ID_WORDS * 2) : 142;
63 int rc = 0; 63 int rc = 0;
64 64
65 if (drive->id_read == 0) { 65 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
66 rc = -ENOMSG; 66 rc = -ENOMSG;
67 goto out; 67 goto out;
68 } 68 }
@@ -86,8 +86,10 @@ out:
86 86
87static int ide_get_nice_ioctl(ide_drive_t *drive, unsigned long arg) 87static int ide_get_nice_ioctl(ide_drive_t *drive, unsigned long arg)
88{ 88{
89 return put_user((drive->dsc_overlap << IDE_NICE_DSC_OVERLAP) | 89 return put_user((!!(drive->dev_flags & IDE_DFLAG_DSC_OVERLAP)
90 (drive->nice1 << IDE_NICE_1), (long __user *)arg); 90 << IDE_NICE_DSC_OVERLAP) |
91 (!!(drive->dev_flags & IDE_DFLAG_NICE1)
92 << IDE_NICE_1), (long __user *)arg);
91} 93}
92 94
93static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg) 95static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg)
@@ -97,11 +99,18 @@ static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg)
97 99
98 if (((arg >> IDE_NICE_DSC_OVERLAP) & 1) && 100 if (((arg >> IDE_NICE_DSC_OVERLAP) & 1) &&
99 (drive->media == ide_disk || drive->media == ide_floppy || 101 (drive->media == ide_disk || drive->media == ide_floppy ||
100 drive->scsi)) 102 (drive->dev_flags & IDE_DFLAG_SCSI)))
101 return -EPERM; 103 return -EPERM;
102 104
103 drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1; 105 if ((arg >> IDE_NICE_DSC_OVERLAP) & 1)
104 drive->nice1 = (arg >> IDE_NICE_1) & 1; 106 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
107 else
108 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
109
110 if ((arg >> IDE_NICE_1) & 1)
111 drive->dev_flags |= IDE_DFLAG_NICE1;
112 else
113 drive->dev_flags &= ~IDE_DFLAG_NICE1;
105 114
106 return 0; 115 return 0;
107} 116}
diff --git a/drivers/ide/ide-iops.c b/drivers/ide/ide-iops.c
index 0a2fd3b37ac4..b762deb2dacb 100644
--- a/drivers/ide/ide-iops.c
+++ b/drivers/ide/ide-iops.c
@@ -181,7 +181,7 @@ void ide_tf_load(ide_drive_t *drive, ide_task_t *task)
181 tf_outb(tf->lbah, io_ports->lbah_addr); 181 tf_outb(tf->lbah, io_ports->lbah_addr);
182 182
183 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) 183 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
184 tf_outb((tf->device & HIHI) | drive->select.all, 184 tf_outb((tf->device & HIHI) | drive->select,
185 io_ports->device_addr); 185 io_ports->device_addr);
186} 186}
187EXPORT_SYMBOL_GPL(ide_tf_load); 187EXPORT_SYMBOL_GPL(ide_tf_load);
@@ -647,7 +647,7 @@ u8 eighty_ninty_three (ide_drive_t *drive)
647 return 1; 647 return 1;
648 648
649no_80w: 649no_80w:
650 if (drive->udma33_warned == 1) 650 if (drive->dev_flags & IDE_DFLAG_UDMA33_WARNED)
651 return 0; 651 return 0;
652 652
653 printk(KERN_WARNING "%s: %s side 80-wire cable detection failed, " 653 printk(KERN_WARNING "%s: %s side 80-wire cable detection failed, "
@@ -655,7 +655,7 @@ no_80w:
655 drive->name, 655 drive->name,
656 hwif->cbl == ATA_CBL_PATA80 ? "drive" : "host"); 656 hwif->cbl == ATA_CBL_PATA80 ? "drive" : "host");
657 657
658 drive->udma33_warned = 1; 658 drive->dev_flags |= IDE_DFLAG_UDMA33_WARNED;
659 659
660 return 0; 660 return 0;
661} 661}
@@ -711,7 +711,7 @@ int ide_driveid_update(ide_drive_t *drive)
711 711
712 kfree(id); 712 kfree(id);
713 713
714 if (drive->using_dma && ide_id_dma_bug(drive)) 714 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) && ide_id_dma_bug(drive))
715 ide_dma_off(drive); 715 ide_dma_off(drive);
716 716
717 return 1; 717 return 1;
@@ -790,7 +790,7 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
790 790
791 skip: 791 skip:
792#ifdef CONFIG_BLK_DEV_IDEDMA 792#ifdef CONFIG_BLK_DEV_IDEDMA
793 if (speed >= XFER_SW_DMA_0 && drive->using_dma) 793 if (speed >= XFER_SW_DMA_0 && (drive->dev_flags & IDE_DFLAG_USING_DMA))
794 hwif->dma_ops->dma_host_set(drive, 1); 794 hwif->dma_ops->dma_host_set(drive, 1);
795 else if (hwif->dma_ops) /* check if host supports DMA */ 795 else if (hwif->dma_ops) /* check if host supports DMA */
796 ide_dma_off_quietly(drive); 796 ide_dma_off_quietly(drive);
@@ -940,6 +940,25 @@ static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive)
940 return ide_stopped; 940 return ide_stopped;
941} 941}
942 942
943static void ide_reset_report_error(ide_hwif_t *hwif, u8 err)
944{
945 static const char *err_master_vals[] =
946 { NULL, "passed", "formatter device error",
947 "sector buffer error", "ECC circuitry error",
948 "controlling MPU error" };
949
950 u8 err_master = err & 0x7f;
951
952 printk(KERN_ERR "%s: reset: master: ", hwif->name);
953 if (err_master && err_master < 6)
954 printk(KERN_CONT "%s", err_master_vals[err_master]);
955 else
956 printk(KERN_CONT "error (0x%02x?)", err);
957 if (err & 0x80)
958 printk(KERN_CONT "; slave: failed");
959 printk(KERN_CONT "\n");
960}
961
943/* 962/*
944 * reset_pollfunc() gets invoked to poll the interface for completion every 50ms 963 * reset_pollfunc() gets invoked to poll the interface for completion every 50ms
945 * during an ide reset operation. If the drives have not yet responded, 964 * during an ide reset operation. If the drives have not yet responded,
@@ -975,31 +994,14 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive)
975 drive->failures++; 994 drive->failures++;
976 err = -EIO; 995 err = -EIO;
977 } else { 996 } else {
978 printk("%s: reset: ", hwif->name);
979 tmp = ide_read_error(drive); 997 tmp = ide_read_error(drive);
980 998
981 if (tmp == 1) { 999 if (tmp == 1) {
982 printk("success\n"); 1000 printk(KERN_INFO "%s: reset: success\n", hwif->name);
983 drive->failures = 0; 1001 drive->failures = 0;
984 } else { 1002 } else {
1003 ide_reset_report_error(hwif, tmp);
985 drive->failures++; 1004 drive->failures++;
986 printk("master: ");
987 switch (tmp & 0x7f) {
988 case 1: printk("passed");
989 break;
990 case 2: printk("formatter device error");
991 break;
992 case 3: printk("sector buffer error");
993 break;
994 case 4: printk("ECC circuitry error");
995 break;
996 case 5: printk("controlling MPU error");
997 break;
998 default:printk("error (0x%02x?)", tmp);
999 }
1000 if (tmp & 0x80)
1001 printk("; slave: failed");
1002 printk("\n");
1003 err = -EIO; 1005 err = -EIO;
1004 } 1006 }
1005 } 1007 }
@@ -1016,9 +1018,14 @@ static void ide_disk_pre_reset(ide_drive_t *drive)
1016 drive->special.all = 0; 1018 drive->special.all = 0;
1017 drive->special.b.set_geometry = legacy; 1019 drive->special.b.set_geometry = legacy;
1018 drive->special.b.recalibrate = legacy; 1020 drive->special.b.recalibrate = legacy;
1021
1019 drive->mult_count = 0; 1022 drive->mult_count = 0;
1020 if (!drive->keep_settings && !drive->using_dma) 1023 drive->dev_flags &= ~IDE_DFLAG_PARKED;
1024
1025 if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0 &&
1026 (drive->dev_flags & IDE_DFLAG_USING_DMA) == 0)
1021 drive->mult_req = 0; 1027 drive->mult_req = 0;
1028
1022 if (drive->mult_req != drive->mult_count) 1029 if (drive->mult_req != drive->mult_count)
1023 drive->special.b.set_multmode = 1; 1030 drive->special.b.set_multmode = 1;
1024} 1031}
@@ -1030,18 +1037,18 @@ static void pre_reset(ide_drive_t *drive)
1030 if (drive->media == ide_disk) 1037 if (drive->media == ide_disk)
1031 ide_disk_pre_reset(drive); 1038 ide_disk_pre_reset(drive);
1032 else 1039 else
1033 drive->post_reset = 1; 1040 drive->dev_flags |= IDE_DFLAG_POST_RESET;
1034 1041
1035 if (drive->using_dma) { 1042 if (drive->dev_flags & IDE_DFLAG_USING_DMA) {
1036 if (drive->crc_count) 1043 if (drive->crc_count)
1037 ide_check_dma_crc(drive); 1044 ide_check_dma_crc(drive);
1038 else 1045 else
1039 ide_dma_off(drive); 1046 ide_dma_off(drive);
1040 } 1047 }
1041 1048
1042 if (!drive->keep_settings) { 1049 if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0) {
1043 if (!drive->using_dma) { 1050 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0) {
1044 drive->unmask = 0; 1051 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
1045 drive->io_32bit = 0; 1052 drive->io_32bit = 0;
1046 } 1053 }
1047 return; 1054 return;
@@ -1073,12 +1080,13 @@ static void pre_reset(ide_drive_t *drive)
1073static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi) 1080static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1074{ 1081{
1075 unsigned int unit; 1082 unsigned int unit;
1076 unsigned long flags; 1083 unsigned long flags, timeout;
1077 ide_hwif_t *hwif; 1084 ide_hwif_t *hwif;
1078 ide_hwgroup_t *hwgroup; 1085 ide_hwgroup_t *hwgroup;
1079 struct ide_io_ports *io_ports; 1086 struct ide_io_ports *io_ports;
1080 const struct ide_tp_ops *tp_ops; 1087 const struct ide_tp_ops *tp_ops;
1081 const struct ide_port_ops *port_ops; 1088 const struct ide_port_ops *port_ops;
1089 DEFINE_WAIT(wait);
1082 1090
1083 spin_lock_irqsave(&ide_lock, flags); 1091 spin_lock_irqsave(&ide_lock, flags);
1084 hwif = HWIF(drive); 1092 hwif = HWIF(drive);
@@ -1105,6 +1113,31 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
1105 return ide_started; 1113 return ide_started;
1106 } 1114 }
1107 1115
1116 /* We must not disturb devices in the IDE_DFLAG_PARKED state. */
1117 do {
1118 unsigned long now;
1119
1120 prepare_to_wait(&ide_park_wq, &wait, TASK_UNINTERRUPTIBLE);
1121 timeout = jiffies;
1122 for (unit = 0; unit < MAX_DRIVES; unit++) {
1123 ide_drive_t *tdrive = &hwif->drives[unit];
1124
1125 if (tdrive->dev_flags & IDE_DFLAG_PRESENT &&
1126 tdrive->dev_flags & IDE_DFLAG_PARKED &&
1127 time_after(tdrive->sleep, timeout))
1128 timeout = tdrive->sleep;
1129 }
1130
1131 now = jiffies;
1132 if (time_before_eq(timeout, now))
1133 break;
1134
1135 spin_unlock_irqrestore(&ide_lock, flags);
1136 timeout = schedule_timeout_uninterruptible(timeout - now);
1137 spin_lock_irqsave(&ide_lock, flags);
1138 } while (timeout);
1139 finish_wait(&ide_park_wq, &wait);
1140
1108 /* 1141 /*
1109 * First, reset any device state data we were maintaining 1142 * First, reset any device state data we were maintaining
1110 * for any of the drives on this interface. 1143 * for any of the drives on this interface.
diff --git a/drivers/ide/ide-lib.c b/drivers/ide/ide-lib.c
index ed426dd0fdd8..9fc4cfb2a272 100644
--- a/drivers/ide/ide-lib.c
+++ b/drivers/ide/ide-lib.c
@@ -317,7 +317,7 @@ static void ide_dump_sector(ide_drive_t *drive)
317{ 317{
318 ide_task_t task; 318 ide_task_t task;
319 struct ide_taskfile *tf = &task.tf; 319 struct ide_taskfile *tf = &task.tf;
320 int lba48 = (drive->addressing == 1) ? 1 : 0; 320 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
321 321
322 memset(&task, 0, sizeof(task)); 322 memset(&task, 0, sizeof(task));
323 if (lba48) 323 if (lba48)
diff --git a/drivers/ide/ide-park.c b/drivers/ide/ide-park.c
new file mode 100644
index 000000000000..03b00e57e93f
--- /dev/null
+++ b/drivers/ide/ide-park.c
@@ -0,0 +1,121 @@
1#include <linux/kernel.h>
2#include <linux/ide.h>
3#include <linux/jiffies.h>
4#include <linux/blkdev.h>
5
6DECLARE_WAIT_QUEUE_HEAD(ide_park_wq);
7
8static void issue_park_cmd(ide_drive_t *drive, unsigned long timeout)
9{
10 struct request_queue *q = drive->queue;
11 struct request *rq;
12 int rc;
13
14 timeout += jiffies;
15 spin_lock_irq(&ide_lock);
16 if (drive->dev_flags & IDE_DFLAG_PARKED) {
17 ide_hwgroup_t *hwgroup = drive->hwif->hwgroup;
18 int reset_timer;
19
20 reset_timer = time_before(timeout, drive->sleep);
21 drive->sleep = timeout;
22 wake_up_all(&ide_park_wq);
23 if (reset_timer && hwgroup->sleeping &&
24 del_timer(&hwgroup->timer)) {
25 hwgroup->sleeping = 0;
26 hwgroup->busy = 0;
27 blk_start_queueing(q);
28 }
29 spin_unlock_irq(&ide_lock);
30 return;
31 }
32 spin_unlock_irq(&ide_lock);
33
34 rq = blk_get_request(q, READ, __GFP_WAIT);
35 rq->cmd[0] = REQ_PARK_HEADS;
36 rq->cmd_len = 1;
37 rq->cmd_type = REQ_TYPE_SPECIAL;
38 rq->special = &timeout;
39 rc = blk_execute_rq(q, NULL, rq, 1);
40 blk_put_request(rq);
41 if (rc)
42 goto out;
43
44 /*
45 * Make sure that *some* command is sent to the drive after the
46 * timeout has expired, so power management will be reenabled.
47 */
48 rq = blk_get_request(q, READ, GFP_NOWAIT);
49 if (unlikely(!rq))
50 goto out;
51
52 rq->cmd[0] = REQ_UNPARK_HEADS;
53 rq->cmd_len = 1;
54 rq->cmd_type = REQ_TYPE_SPECIAL;
55 elv_add_request(q, rq, ELEVATOR_INSERT_FRONT, 1);
56
57out:
58 return;
59}
60
61ssize_t ide_park_show(struct device *dev, struct device_attribute *attr,
62 char *buf)
63{
64 ide_drive_t *drive = to_ide_device(dev);
65 unsigned long now;
66 unsigned int msecs;
67
68 if (drive->dev_flags & IDE_DFLAG_NO_UNLOAD)
69 return -EOPNOTSUPP;
70
71 spin_lock_irq(&ide_lock);
72 now = jiffies;
73 if (drive->dev_flags & IDE_DFLAG_PARKED &&
74 time_after(drive->sleep, now))
75 msecs = jiffies_to_msecs(drive->sleep - now);
76 else
77 msecs = 0;
78 spin_unlock_irq(&ide_lock);
79
80 return snprintf(buf, 20, "%u\n", msecs);
81}
82
83ssize_t ide_park_store(struct device *dev, struct device_attribute *attr,
84 const char *buf, size_t len)
85{
86#define MAX_PARK_TIMEOUT 30000
87 ide_drive_t *drive = to_ide_device(dev);
88 long int input;
89 int rc;
90
91 rc = strict_strtol(buf, 10, &input);
92 if (rc || input < -2)
93 return -EINVAL;
94 if (input > MAX_PARK_TIMEOUT) {
95 input = MAX_PARK_TIMEOUT;
96 rc = -EOVERFLOW;
97 }
98
99 mutex_lock(&ide_setting_mtx);
100 if (input >= 0) {
101 if (drive->dev_flags & IDE_DFLAG_NO_UNLOAD)
102 rc = -EOPNOTSUPP;
103 else if (input || drive->dev_flags & IDE_DFLAG_PARKED)
104 issue_park_cmd(drive, msecs_to_jiffies(input));
105 } else {
106 if (drive->media == ide_disk)
107 switch (input) {
108 case -1:
109 drive->dev_flags &= ~IDE_DFLAG_NO_UNLOAD;
110 break;
111 case -2:
112 drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
113 break;
114 }
115 else
116 rc = -EOPNOTSUPP;
117 }
118 mutex_unlock(&ide_setting_mtx);
119
120 return rc ? rc : len;
121}
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 06575a12b635..19f8c7770a25 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -121,7 +121,8 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
121 /* read 512 bytes of id info */ 121 /* read 512 bytes of id info */
122 hwif->tp_ops->input_data(drive, NULL, id, SECTOR_SIZE); 122 hwif->tp_ops->input_data(drive, NULL, id, SECTOR_SIZE);
123 123
124 drive->id_read = 1; 124 drive->dev_flags |= IDE_DFLAG_ID_READ;
125
125 local_irq_enable(); 126 local_irq_enable();
126#ifdef DEBUG 127#ifdef DEBUG
127 printk(KERN_INFO "%s: dumping identify data\n", drive->name); 128 printk(KERN_INFO "%s: dumping identify data\n", drive->name);
@@ -153,8 +154,8 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
153 154
154 printk(KERN_INFO "%s: %s, ", drive->name, m); 155 printk(KERN_INFO "%s: %s, ", drive->name, m);
155 156
156 drive->present = 1; 157 drive->dev_flags |= IDE_DFLAG_PRESENT;
157 drive->dead = 0; 158 drive->dev_flags &= ~IDE_DFLAG_DEAD;
158 159
159 /* 160 /*
160 * Check for an ATAPI device 161 * Check for an ATAPI device
@@ -172,14 +173,14 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
172 printk(KERN_CONT "cdrom or floppy?, assuming "); 173 printk(KERN_CONT "cdrom or floppy?, assuming ");
173 if (drive->media != ide_cdrom) { 174 if (drive->media != ide_cdrom) {
174 printk(KERN_CONT "FLOPPY"); 175 printk(KERN_CONT "FLOPPY");
175 drive->removable = 1; 176 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
176 break; 177 break;
177 } 178 }
178 } 179 }
179 /* Early cdrom models used zero */ 180 /* Early cdrom models used zero */
180 type = ide_cdrom; 181 type = ide_cdrom;
181 case ide_cdrom: 182 case ide_cdrom:
182 drive->removable = 1; 183 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
183#ifdef CONFIG_PPC 184#ifdef CONFIG_PPC
184 /* kludge for Apple PowerBook internal zip */ 185 /* kludge for Apple PowerBook internal zip */
185 if (!strstr(m, "CD-ROM") && strstr(m, "ZIP")) { 186 if (!strstr(m, "CD-ROM") && strstr(m, "ZIP")) {
@@ -195,7 +196,7 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
195 break; 196 break;
196 case ide_optical: 197 case ide_optical:
197 printk(KERN_CONT "OPTICAL"); 198 printk(KERN_CONT "OPTICAL");
198 drive->removable = 1; 199 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
199 break; 200 break;
200 default: 201 default:
201 printk(KERN_CONT "UNKNOWN (type %d)", type); 202 printk(KERN_CONT "UNKNOWN (type %d)", type);
@@ -205,6 +206,10 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
205 drive->media = type; 206 drive->media = type;
206 /* an ATAPI device ignores DRDY */ 207 /* an ATAPI device ignores DRDY */
207 drive->ready_stat = 0; 208 drive->ready_stat = 0;
209 if (ata_id_cdb_intr(id))
210 drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
211 /* we don't do head unloading on ATAPI devices */
212 drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
208 return; 213 return;
209 } 214 }
210 215
@@ -216,17 +221,20 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
216 221
217 /* CF devices are *not* removable in Linux definition of the term */ 222 /* CF devices are *not* removable in Linux definition of the term */
218 if (is_cfa == 0 && (id[ATA_ID_CONFIG] & (1 << 7))) 223 if (is_cfa == 0 && (id[ATA_ID_CONFIG] & (1 << 7)))
219 drive->removable = 1; 224 drive->dev_flags |= IDE_DFLAG_REMOVABLE;
220 225
221 drive->media = ide_disk; 226 drive->media = ide_disk;
222 227
228 if (!ata_id_has_unload(drive->id))
229 drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
230
223 printk(KERN_CONT "%s DISK drive\n", is_cfa ? "CFA" : "ATA"); 231 printk(KERN_CONT "%s DISK drive\n", is_cfa ? "CFA" : "ATA");
224 232
225 return; 233 return;
226 234
227err_misc: 235err_misc:
228 kfree(id); 236 kfree(id);
229 drive->present = 0; 237 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
230 return; 238 return;
231} 239}
232 240
@@ -426,16 +434,15 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
426 ide_hwif_t *hwif = HWIF(drive); 434 ide_hwif_t *hwif = HWIF(drive);
427 const struct ide_tp_ops *tp_ops = hwif->tp_ops; 435 const struct ide_tp_ops *tp_ops = hwif->tp_ops;
428 int rc; 436 int rc;
429 u8 stat; 437 u8 present = !!(drive->dev_flags & IDE_DFLAG_PRESENT), stat;
438
439 /* avoid waiting for inappropriate probes */
440 if (present && drive->media != ide_disk && cmd == ATA_CMD_ID_ATA)
441 return 4;
430 442
431 if (drive->present) {
432 /* avoid waiting for inappropriate probes */
433 if (drive->media != ide_disk && cmd == ATA_CMD_ID_ATA)
434 return 4;
435 }
436#ifdef DEBUG 443#ifdef DEBUG
437 printk(KERN_INFO "probing for %s: present=%d, media=%d, probetype=%s\n", 444 printk(KERN_INFO "probing for %s: present=%d, media=%d, probetype=%s\n",
438 drive->name, drive->present, drive->media, 445 drive->name, present, drive->media,
439 (cmd == ATA_CMD_ID_ATA) ? "ATA" : "ATAPI"); 446 (cmd == ATA_CMD_ID_ATA) ? "ATA" : "ATAPI");
440#endif 447#endif
441 448
@@ -446,8 +453,8 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
446 SELECT_DRIVE(drive); 453 SELECT_DRIVE(drive);
447 msleep(50); 454 msleep(50);
448 455
449 if (ide_read_device(drive) != drive->select.all && !drive->present) { 456 if (ide_read_device(drive) != drive->select && present == 0) {
450 if (drive->select.b.unit != 0) { 457 if (drive->dn & 1) {
451 /* exit with drive0 selected */ 458 /* exit with drive0 selected */
452 SELECT_DRIVE(&hwif->drives[0]); 459 SELECT_DRIVE(&hwif->drives[0]);
453 /* allow ATA_BUSY to assert & clear */ 460 /* allow ATA_BUSY to assert & clear */
@@ -460,7 +467,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
460 stat = tp_ops->read_status(hwif); 467 stat = tp_ops->read_status(hwif);
461 468
462 if (OK_STAT(stat, ATA_DRDY, ATA_BUSY) || 469 if (OK_STAT(stat, ATA_DRDY, ATA_BUSY) ||
463 drive->present || cmd == ATA_CMD_ID_ATAPI) { 470 present || cmd == ATA_CMD_ID_ATAPI) {
464 /* send cmd and wait */ 471 /* send cmd and wait */
465 if ((rc = try_to_identify(drive, cmd))) { 472 if ((rc = try_to_identify(drive, cmd))) {
466 /* failed: try again */ 473 /* failed: try again */
@@ -493,7 +500,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
493 /* not present or maybe ATAPI */ 500 /* not present or maybe ATAPI */
494 rc = 3; 501 rc = 3;
495 } 502 }
496 if (drive->select.b.unit != 0) { 503 if (drive->dn & 1) {
497 /* exit with drive0 selected */ 504 /* exit with drive0 selected */
498 SELECT_DRIVE(&hwif->drives[0]); 505 SELECT_DRIVE(&hwif->drives[0]);
499 msleep(50); 506 msleep(50);
@@ -542,8 +549,8 @@ static void enable_nest (ide_drive_t *drive)
542 * and presents things to the user as needed. 549 * and presents things to the user as needed.
543 * 550 *
544 * Returns: 0 no device was found 551 * Returns: 0 no device was found
545 * 1 device was found (note: drive->present might 552 * 1 device was found
546 * still be 0) 553 * (note: IDE_DFLAG_PRESENT might still be not set)
547 */ 554 */
548 555
549static inline u8 probe_for_drive (ide_drive_t *drive) 556static inline u8 probe_for_drive (ide_drive_t *drive)
@@ -559,10 +566,10 @@ static inline u8 probe_for_drive (ide_drive_t *drive)
559 * Also note that 0 everywhere means "can't do X" 566 * Also note that 0 everywhere means "can't do X"
560 */ 567 */
561 568
569 drive->dev_flags &= ~IDE_DFLAG_ID_READ;
570
562 drive->id = kzalloc(SECTOR_SIZE, GFP_KERNEL); 571 drive->id = kzalloc(SECTOR_SIZE, GFP_KERNEL);
563 drive->id_read = 0; 572 if (drive->id == NULL) {
564 if(drive->id == NULL)
565 {
566 printk(KERN_ERR "ide: out of memory for id data.\n"); 573 printk(KERN_ERR "ide: out of memory for id data.\n");
567 return 0; 574 return 0;
568 } 575 }
@@ -571,14 +578,14 @@ static inline u8 probe_for_drive (ide_drive_t *drive)
571 strcpy(m, "UNKNOWN"); 578 strcpy(m, "UNKNOWN");
572 579
573 /* skip probing? */ 580 /* skip probing? */
574 if (!drive->noprobe) { 581 if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0) {
575retry: 582retry:
576 /* if !(success||timed-out) */ 583 /* if !(success||timed-out) */
577 if (do_probe(drive, ATA_CMD_ID_ATA) >= 2) 584 if (do_probe(drive, ATA_CMD_ID_ATA) >= 2)
578 /* look for ATAPI device */ 585 /* look for ATAPI device */
579 (void)do_probe(drive, ATA_CMD_ID_ATAPI); 586 (void)do_probe(drive, ATA_CMD_ID_ATAPI);
580 587
581 if (!drive->present) 588 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
582 /* drive not found */ 589 /* drive not found */
583 return 0; 590 return 0;
584 591
@@ -588,7 +595,7 @@ retry:
588 } 595 }
589 596
590 /* identification failed? */ 597 /* identification failed? */
591 if (!drive->id_read) { 598 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
592 if (drive->media == ide_disk) { 599 if (drive->media == ide_disk) {
593 printk(KERN_INFO "%s: non-IDE drive, CHS=%d/%d/%d\n", 600 printk(KERN_INFO "%s: non-IDE drive, CHS=%d/%d/%d\n",
594 drive->name, drive->cyl, 601 drive->name, drive->cyl,
@@ -598,15 +605,17 @@ retry:
598 } else { 605 } else {
599 /* nuke it */ 606 /* nuke it */
600 printk(KERN_WARNING "%s: Unknown device on bus refused identification. Ignoring.\n", drive->name); 607 printk(KERN_WARNING "%s: Unknown device on bus refused identification. Ignoring.\n", drive->name);
601 drive->present = 0; 608 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
602 } 609 }
603 } 610 }
604 /* drive was found */ 611 /* drive was found */
605 } 612 }
606 if(!drive->present) 613
614 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
607 return 0; 615 return 0;
616
608 /* The drive wasn't being helpful. Add generic info only */ 617 /* The drive wasn't being helpful. Add generic info only */
609 if (drive->id_read == 0) { 618 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
610 generic_id(drive); 619 generic_id(drive);
611 return 1; 620 return 1;
612 } 621 }
@@ -616,7 +625,7 @@ retry:
616 ide_disk_init_mult_count(drive); 625 ide_disk_init_mult_count(drive);
617 } 626 }
618 627
619 return drive->present; 628 return !!(drive->dev_flags & IDE_DFLAG_PRESENT);
620} 629}
621 630
622static void hwif_release_dev(struct device *dev) 631static void hwif_release_dev(struct device *dev)
@@ -648,8 +657,8 @@ static int ide_register_port(ide_hwif_t *hwif)
648 goto out; 657 goto out;
649 } 658 }
650 659
651 hwif->portdev = device_create_drvdata(ide_port_class, &hwif->gendev, 660 hwif->portdev = device_create(ide_port_class, &hwif->gendev,
652 MKDEV(0, 0), hwif, hwif->name); 661 MKDEV(0, 0), hwif, hwif->name);
653 if (IS_ERR(hwif->portdev)) { 662 if (IS_ERR(hwif->portdev)) {
654 ret = PTR_ERR(hwif->portdev); 663 ret = PTR_ERR(hwif->portdev);
655 device_unregister(&hwif->gendev); 664 device_unregister(&hwif->gendev);
@@ -707,7 +716,8 @@ static int ide_port_wait_ready(ide_hwif_t *hwif)
707 ide_drive_t *drive = &hwif->drives[unit]; 716 ide_drive_t *drive = &hwif->drives[unit];
708 717
709 /* Ignore disks that we will not probe for later. */ 718 /* Ignore disks that we will not probe for later. */
710 if (!drive->noprobe || drive->present) { 719 if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0 ||
720 (drive->dev_flags & IDE_DFLAG_PRESENT)) {
711 SELECT_DRIVE(drive); 721 SELECT_DRIVE(drive);
712 hwif->tp_ops->set_irq(hwif, 1); 722 hwif->tp_ops->set_irq(hwif, 1);
713 mdelay(2); 723 mdelay(2);
@@ -739,7 +749,7 @@ void ide_undecoded_slave(ide_drive_t *dev1)
739{ 749{
740 ide_drive_t *dev0 = &dev1->hwif->drives[0]; 750 ide_drive_t *dev0 = &dev1->hwif->drives[0];
741 751
742 if ((dev1->dn & 1) == 0 || dev0->present == 0) 752 if ((dev1->dn & 1) == 0 || (dev0->dev_flags & IDE_DFLAG_PRESENT) == 0)
743 return; 753 return;
744 754
745 /* If the models don't match they are not the same product */ 755 /* If the models don't match they are not the same product */
@@ -759,7 +769,7 @@ void ide_undecoded_slave(ide_drive_t *dev1)
759 /* Appears to be an IDE flash adapter with decode bugs */ 769 /* Appears to be an IDE flash adapter with decode bugs */
760 printk(KERN_WARNING "ide-probe: ignoring undecoded slave\n"); 770 printk(KERN_WARNING "ide-probe: ignoring undecoded slave\n");
761 771
762 dev1->present = 0; 772 dev1->dev_flags &= ~IDE_DFLAG_PRESENT;
763} 773}
764 774
765EXPORT_SYMBOL_GPL(ide_undecoded_slave); 775EXPORT_SYMBOL_GPL(ide_undecoded_slave);
@@ -772,7 +782,8 @@ static int ide_probe_port(ide_hwif_t *hwif)
772 782
773 BUG_ON(hwif->present); 783 BUG_ON(hwif->present);
774 784
775 if (hwif->drives[0].noprobe && hwif->drives[1].noprobe) 785 if ((hwif->drives[0].dev_flags & IDE_DFLAG_NOPROBE) &&
786 (hwif->drives[1].dev_flags & IDE_DFLAG_NOPROBE))
776 return -EACCES; 787 return -EACCES;
777 788
778 /* 789 /*
@@ -794,9 +805,9 @@ static int ide_probe_port(ide_hwif_t *hwif)
794 */ 805 */
795 for (unit = 0; unit < MAX_DRIVES; ++unit) { 806 for (unit = 0; unit < MAX_DRIVES; ++unit) {
796 ide_drive_t *drive = &hwif->drives[unit]; 807 ide_drive_t *drive = &hwif->drives[unit];
797 drive->dn = (hwif->channel ? 2 : 0) + unit; 808
798 (void) probe_for_drive(drive); 809 (void) probe_for_drive(drive);
799 if (drive->present) 810 if (drive->dev_flags & IDE_DFLAG_PRESENT)
800 rc = 0; 811 rc = 0;
801 } 812 }
802 813
@@ -820,17 +831,19 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
820 for (unit = 0; unit < MAX_DRIVES; unit++) { 831 for (unit = 0; unit < MAX_DRIVES; unit++) {
821 ide_drive_t *drive = &hwif->drives[unit]; 832 ide_drive_t *drive = &hwif->drives[unit];
822 833
823 if (drive->present && port_ops && port_ops->quirkproc) 834 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
824 port_ops->quirkproc(drive); 835 if (port_ops && port_ops->quirkproc)
836 port_ops->quirkproc(drive);
837 }
825 } 838 }
826 839
827 for (unit = 0; unit < MAX_DRIVES; ++unit) { 840 for (unit = 0; unit < MAX_DRIVES; ++unit) {
828 ide_drive_t *drive = &hwif->drives[unit]; 841 ide_drive_t *drive = &hwif->drives[unit];
829 842
830 if (drive->present) { 843 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
831 ide_set_max_pio(drive); 844 ide_set_max_pio(drive);
832 845
833 drive->nice1 = 1; 846 drive->dev_flags |= IDE_DFLAG_NICE1;
834 847
835 if (hwif->dma_ops) 848 if (hwif->dma_ops)
836 ide_set_dma(drive); 849 ide_set_dma(drive);
@@ -840,14 +853,14 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
840 for (unit = 0; unit < MAX_DRIVES; ++unit) { 853 for (unit = 0; unit < MAX_DRIVES; ++unit) {
841 ide_drive_t *drive = &hwif->drives[unit]; 854 ide_drive_t *drive = &hwif->drives[unit];
842 855
843 if (hwif->host_flags & IDE_HFLAG_NO_IO_32BIT) 856 if ((hwif->host_flags & IDE_HFLAG_NO_IO_32BIT) ||
844 drive->no_io_32bit = 1; 857 drive->id[ATA_ID_DWORD_IO])
858 drive->dev_flags |= IDE_DFLAG_NO_IO_32BIT;
845 else 859 else
846 drive->no_io_32bit = drive->id[ATA_ID_DWORD_IO] ? 1 : 0; 860 drive->dev_flags &= ~IDE_DFLAG_NO_IO_32BIT;
847 } 861 }
848} 862}
849 863
850#if MAX_HWIFS > 1
851/* 864/*
852 * save_match() is used to simplify logic in init_irq() below. 865 * save_match() is used to simplify logic in init_irq() below.
853 * 866 *
@@ -872,7 +885,6 @@ static void save_match(ide_hwif_t *hwif, ide_hwif_t *new, ide_hwif_t **match)
872 if (!m || m->irq != hwif->irq) /* don't undo a prior perfect match */ 885 if (!m || m->irq != hwif->irq) /* don't undo a prior perfect match */
873 *match = new; 886 *match = new;
874} 887}
875#endif /* MAX_HWIFS > 1 */
876 888
877/* 889/*
878 * init request queue 890 * init request queue
@@ -951,26 +963,33 @@ static void ide_add_drive_to_hwgroup(ide_drive_t *drive)
951 * - allocate the block device queue 963 * - allocate the block device queue
952 * - link drive into the hwgroup 964 * - link drive into the hwgroup
953 */ 965 */
954static void ide_port_setup_devices(ide_hwif_t *hwif) 966static int ide_port_setup_devices(ide_hwif_t *hwif)
955{ 967{
956 int i; 968 int i, j = 0;
957 969
958 mutex_lock(&ide_cfg_mtx); 970 mutex_lock(&ide_cfg_mtx);
959 for (i = 0; i < MAX_DRIVES; i++) { 971 for (i = 0; i < MAX_DRIVES; i++) {
960 ide_drive_t *drive = &hwif->drives[i]; 972 ide_drive_t *drive = &hwif->drives[i];
961 973
962 if (!drive->present) 974 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
963 continue; 975 continue;
964 976
965 if (ide_init_queue(drive)) { 977 if (ide_init_queue(drive)) {
966 printk(KERN_ERR "ide: failed to init %s\n", 978 printk(KERN_ERR "ide: failed to init %s\n",
967 drive->name); 979 drive->name);
980 kfree(drive->id);
981 drive->id = NULL;
982 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
968 continue; 983 continue;
969 } 984 }
970 985
986 j++;
987
971 ide_add_drive_to_hwgroup(drive); 988 ide_add_drive_to_hwgroup(drive);
972 } 989 }
973 mutex_unlock(&ide_cfg_mtx); 990 mutex_unlock(&ide_cfg_mtx);
991
992 return j;
974} 993}
975 994
976static ide_hwif_t *ide_ports[MAX_HWIFS]; 995static ide_hwif_t *ide_ports[MAX_HWIFS];
@@ -1029,7 +1048,7 @@ static int init_irq (ide_hwif_t *hwif)
1029 1048
1030 mutex_lock(&ide_cfg_mtx); 1049 mutex_lock(&ide_cfg_mtx);
1031 hwif->hwgroup = NULL; 1050 hwif->hwgroup = NULL;
1032#if MAX_HWIFS > 1 1051
1033 /* 1052 /*
1034 * Group up with any other hwifs that share our irq(s). 1053 * Group up with any other hwifs that share our irq(s).
1035 */ 1054 */
@@ -1054,7 +1073,7 @@ static int init_irq (ide_hwif_t *hwif)
1054 } 1073 }
1055 } 1074 }
1056 } 1075 }
1057#endif /* MAX_HWIFS > 1 */ 1076
1058 /* 1077 /*
1059 * If we are still without a hwgroup, then form a new one 1078 * If we are still without a hwgroup, then form a new one
1060 */ 1079 */
@@ -1153,12 +1172,13 @@ static struct kobject *ata_probe(dev_t dev, int *part, void *data)
1153 ide_hwif_t *hwif = data; 1172 ide_hwif_t *hwif = data;
1154 int unit = *part >> PARTN_BITS; 1173 int unit = *part >> PARTN_BITS;
1155 ide_drive_t *drive = &hwif->drives[unit]; 1174 ide_drive_t *drive = &hwif->drives[unit];
1156 if (!drive->present) 1175
1176 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
1157 return NULL; 1177 return NULL;
1158 1178
1159 if (drive->media == ide_disk) 1179 if (drive->media == ide_disk)
1160 request_module("ide-disk"); 1180 request_module("ide-disk");
1161 if (drive->scsi) 1181 if (drive->dev_flags & IDE_DFLAG_SCSI)
1162 request_module("ide-scsi"); 1182 request_module("ide-scsi");
1163 if (drive->media == ide_cdrom || drive->media == ide_optical) 1183 if (drive->media == ide_cdrom || drive->media == ide_optical)
1164 request_module("ide-cd"); 1184 request_module("ide-cd");
@@ -1205,7 +1225,7 @@ EXPORT_SYMBOL_GPL(ide_unregister_region);
1205void ide_init_disk(struct gendisk *disk, ide_drive_t *drive) 1225void ide_init_disk(struct gendisk *disk, ide_drive_t *drive)
1206{ 1226{
1207 ide_hwif_t *hwif = drive->hwif; 1227 ide_hwif_t *hwif = drive->hwif;
1208 unsigned int unit = (drive->select.all >> 4) & 1; 1228 unsigned int unit = drive->dn & 1;
1209 1229
1210 disk->major = hwif->major; 1230 disk->major = hwif->major;
1211 disk->first_minor = unit << PARTN_BITS; 1231 disk->first_minor = unit << PARTN_BITS;
@@ -1248,7 +1268,7 @@ static void drive_release_dev (struct device *dev)
1248 ide_remove_drive_from_hwgroup(drive); 1268 ide_remove_drive_from_hwgroup(drive);
1249 kfree(drive->id); 1269 kfree(drive->id);
1250 drive->id = NULL; 1270 drive->id = NULL;
1251 drive->present = 0; 1271 drive->dev_flags &= ~IDE_DFLAG_PRESENT;
1252 /* Messed up locking ... */ 1272 /* Messed up locking ... */
1253 spin_unlock_irq(&ide_lock); 1273 spin_unlock_irq(&ide_lock);
1254 blk_cleanup_queue(drive->queue); 1274 blk_cleanup_queue(drive->queue);
@@ -1327,7 +1347,7 @@ static void hwif_register_devices(ide_hwif_t *hwif)
1327 struct device *dev = &drive->gendev; 1347 struct device *dev = &drive->gendev;
1328 int ret; 1348 int ret;
1329 1349
1330 if (!drive->present) 1350 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
1331 continue; 1351 continue;
1332 1352
1333 snprintf(dev->bus_id, BUS_ID_SIZE, "%u.%u", hwif->index, i); 1353 snprintf(dev->bus_id, BUS_ID_SIZE, "%u.%u", hwif->index, i);
@@ -1351,12 +1371,14 @@ static void ide_port_init_devices(ide_hwif_t *hwif)
1351 for (i = 0; i < MAX_DRIVES; i++) { 1371 for (i = 0; i < MAX_DRIVES; i++) {
1352 ide_drive_t *drive = &hwif->drives[i]; 1372 ide_drive_t *drive = &hwif->drives[i];
1353 1373
1374 drive->dn = i + hwif->channel * 2;
1375
1354 if (hwif->host_flags & IDE_HFLAG_IO_32BIT) 1376 if (hwif->host_flags & IDE_HFLAG_IO_32BIT)
1355 drive->io_32bit = 1; 1377 drive->io_32bit = 1;
1356 if (hwif->host_flags & IDE_HFLAG_UNMASK_IRQS) 1378 if (hwif->host_flags & IDE_HFLAG_UNMASK_IRQS)
1357 drive->unmask = 1; 1379 drive->dev_flags |= IDE_DFLAG_UNMASK;
1358 if (hwif->host_flags & IDE_HFLAG_NO_UNMASK_IRQS) 1380 if (hwif->host_flags & IDE_HFLAG_NO_UNMASK_IRQS)
1359 drive->no_unmask = 1; 1381 drive->dev_flags |= IDE_DFLAG_NO_UNMASK;
1360 1382
1361 if (port_ops && port_ops->init_dev) 1383 if (port_ops && port_ops->init_dev)
1362 port_ops->init_dev(drive); 1384 port_ops->init_dev(drive);
@@ -1513,19 +1535,14 @@ static int ide_find_port_slot(const struct ide_port_info *d)
1513 * ports 0x1f0/0x170 (the ide0/ide1 defaults). 1535 * ports 0x1f0/0x170 (the ide0/ide1 defaults).
1514 */ 1536 */
1515 mutex_lock(&ide_cfg_mtx); 1537 mutex_lock(&ide_cfg_mtx);
1516 if (MAX_HWIFS == 1) { 1538 if (bootable) {
1517 if (ide_indexes == 0 && i == 0) 1539 if ((ide_indexes | i) != (1 << MAX_HWIFS) - 1)
1518 idx = 1; 1540 idx = ffz(ide_indexes | i);
1519 } else { 1541 } else {
1520 if (bootable) { 1542 if ((ide_indexes | 3) != (1 << MAX_HWIFS) - 1)
1521 if ((ide_indexes | i) != (1 << MAX_HWIFS) - 1) 1543 idx = ffz(ide_indexes | 3);
1522 idx = ffz(ide_indexes | i); 1544 else if ((ide_indexes & 3) != 3)
1523 } else { 1545 idx = ffz(ide_indexes);
1524 if ((ide_indexes | 3) != (1 << MAX_HWIFS) - 1)
1525 idx = ffz(ide_indexes | 3);
1526 else if ((ide_indexes & 3) != 3)
1527 idx = ffz(ide_indexes);
1528 }
1529 } 1546 }
1530 if (idx >= 0) 1547 if (idx >= 0)
1531 ide_indexes |= (1 << idx); 1548 ide_indexes |= (1 << idx);
@@ -1541,8 +1558,7 @@ static void ide_free_port_slot(int idx)
1541 mutex_unlock(&ide_cfg_mtx); 1558 mutex_unlock(&ide_cfg_mtx);
1542} 1559}
1543 1560
1544struct ide_host *ide_host_alloc_all(const struct ide_port_info *d, 1561struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
1545 hw_regs_t **hws)
1546{ 1562{
1547 struct ide_host *host; 1563 struct ide_host *host;
1548 int i; 1564 int i;
@@ -1551,7 +1567,7 @@ struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
1551 if (host == NULL) 1567 if (host == NULL)
1552 return NULL; 1568 return NULL;
1553 1569
1554 for (i = 0; i < MAX_HWIFS; i++) { 1570 for (i = 0; i < MAX_HOST_PORTS; i++) {
1555 ide_hwif_t *hwif; 1571 ide_hwif_t *hwif;
1556 int idx; 1572 int idx;
1557 1573
@@ -1593,18 +1609,6 @@ struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
1593 1609
1594 return host; 1610 return host;
1595} 1611}
1596EXPORT_SYMBOL_GPL(ide_host_alloc_all);
1597
1598struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
1599{
1600 hw_regs_t *hws_all[MAX_HWIFS];
1601 int i;
1602
1603 for (i = 0; i < MAX_HWIFS; i++)
1604 hws_all[i] = (i < 4) ? hws[i] : NULL;
1605
1606 return ide_host_alloc_all(d, hws_all);
1607}
1608EXPORT_SYMBOL_GPL(ide_host_alloc); 1612EXPORT_SYMBOL_GPL(ide_host_alloc);
1609 1613
1610int ide_host_register(struct ide_host *host, const struct ide_port_info *d, 1614int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
@@ -1613,7 +1617,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1613 ide_hwif_t *hwif, *mate = NULL; 1617 ide_hwif_t *hwif, *mate = NULL;
1614 int i, j = 0; 1618 int i, j = 0;
1615 1619
1616 for (i = 0; i < MAX_HWIFS; i++) { 1620 for (i = 0; i < MAX_HOST_PORTS; i++) {
1617 hwif = host->ports[i]; 1621 hwif = host->ports[i];
1618 1622
1619 if (hwif == NULL) { 1623 if (hwif == NULL) {
@@ -1626,22 +1630,22 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1626 1630
1627 if (d == NULL) { 1631 if (d == NULL) {
1628 mate = NULL; 1632 mate = NULL;
1629 continue; 1633 } else {
1630 } 1634 if ((i & 1) && mate) {
1635 hwif->mate = mate;
1636 mate->mate = hwif;
1637 }
1631 1638
1632 if ((i & 1) && mate) { 1639 mate = (i & 1) ? NULL : hwif;
1633 hwif->mate = mate;
1634 mate->mate = hwif;
1635 }
1636 1640
1637 mate = (i & 1) ? NULL : hwif; 1641 ide_init_port(hwif, i & 1, d);
1642 ide_port_cable_detect(hwif);
1643 }
1638 1644
1639 ide_init_port(hwif, i & 1, d);
1640 ide_port_cable_detect(hwif);
1641 ide_port_init_devices(hwif); 1645 ide_port_init_devices(hwif);
1642 } 1646 }
1643 1647
1644 for (i = 0; i < MAX_HWIFS; i++) { 1648 for (i = 0; i < MAX_HOST_PORTS; i++) {
1645 hwif = host->ports[i]; 1649 hwif = host->ports[i];
1646 1650
1647 if (hwif == NULL) 1651 if (hwif == NULL)
@@ -1658,7 +1662,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1658 ide_port_tune_devices(hwif); 1662 ide_port_tune_devices(hwif);
1659 } 1663 }
1660 1664
1661 for (i = 0; i < MAX_HWIFS; i++) { 1665 for (i = 0; i < MAX_HOST_PORTS; i++) {
1662 hwif = host->ports[i]; 1666 hwif = host->ports[i];
1663 1667
1664 if (hwif == NULL) 1668 if (hwif == NULL)
@@ -1671,10 +1675,13 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1671 continue; 1675 continue;
1672 } 1676 }
1673 1677
1674 j++;
1675
1676 if (hwif->present) 1678 if (hwif->present)
1677 ide_port_setup_devices(hwif); 1679 if (ide_port_setup_devices(hwif) == 0) {
1680 hwif->present = 0;
1681 continue;
1682 }
1683
1684 j++;
1678 1685
1679 ide_acpi_init(hwif); 1686 ide_acpi_init(hwif);
1680 1687
@@ -1682,7 +1689,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1682 ide_acpi_port_init_devices(hwif); 1689 ide_acpi_port_init_devices(hwif);
1683 } 1690 }
1684 1691
1685 for (i = 0; i < MAX_HWIFS; i++) { 1692 for (i = 0; i < MAX_HOST_PORTS; i++) {
1686 hwif = host->ports[i]; 1693 hwif = host->ports[i];
1687 1694
1688 if (hwif == NULL) 1695 if (hwif == NULL)
@@ -1695,7 +1702,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
1695 hwif_register_devices(hwif); 1702 hwif_register_devices(hwif);
1696 } 1703 }
1697 1704
1698 for (i = 0; i < MAX_HWIFS; i++) { 1705 for (i = 0; i < MAX_HOST_PORTS; i++) {
1699 hwif = host->ports[i]; 1706 hwif = host->ports[i];
1700 1707
1701 if (hwif == NULL) 1708 if (hwif == NULL)
@@ -1740,7 +1747,7 @@ void ide_host_free(struct ide_host *host)
1740 ide_hwif_t *hwif; 1747 ide_hwif_t *hwif;
1741 int i; 1748 int i;
1742 1749
1743 for (i = 0; i < MAX_HWIFS; i++) { 1750 for (i = 0; i < MAX_HOST_PORTS; i++) {
1744 hwif = host->ports[i]; 1751 hwif = host->ports[i];
1745 1752
1746 if (hwif == NULL) 1753 if (hwif == NULL)
@@ -1758,7 +1765,7 @@ void ide_host_remove(struct ide_host *host)
1758{ 1765{
1759 int i; 1766 int i;
1760 1767
1761 for (i = 0; i < MAX_HWIFS; i++) { 1768 for (i = 0; i < MAX_HOST_PORTS; i++) {
1762 if (host->ports[i]) 1769 if (host->ports[i])
1763 ide_unregister(host->ports[i]); 1770 ide_unregister(host->ports[i]);
1764 } 1771 }
diff --git a/drivers/ide/ide-proc.c b/drivers/ide/ide-proc.c
index e7030a491463..b26926487cc0 100644
--- a/drivers/ide/ide-proc.c
+++ b/drivers/ide/ide-proc.c
@@ -227,7 +227,7 @@ static int set_xfer_rate (ide_drive_t *drive, int arg)
227 227
228ide_devset_rw(current_speed, xfer_rate); 228ide_devset_rw(current_speed, xfer_rate);
229ide_devset_rw_field(init_speed, init_speed); 229ide_devset_rw_field(init_speed, init_speed);
230ide_devset_rw_field(nice1, nice1); 230ide_devset_rw_flag(nice1, IDE_DFLAG_NICE1);
231ide_devset_rw_field(number, dn); 231ide_devset_rw_field(number, dn);
232 232
233static const struct ide_proc_devset ide_generic_settings[] = { 233static const struct ide_proc_devset ide_generic_settings[] = {
@@ -622,9 +622,7 @@ void ide_proc_port_register_devices(ide_hwif_t *hwif)
622 for (d = 0; d < MAX_DRIVES; d++) { 622 for (d = 0; d < MAX_DRIVES; d++) {
623 ide_drive_t *drive = &hwif->drives[d]; 623 ide_drive_t *drive = &hwif->drives[d];
624 624
625 if (!drive->present) 625 if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0 || drive->proc)
626 continue;
627 if (drive->proc)
628 continue; 626 continue;
629 627
630 drive->proc = proc_mkdir(drive->name, parent); 628 drive->proc = proc_mkdir(drive->name, parent);
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index f8c84df4a0bc..d879c7797cde 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -172,23 +172,16 @@ typedef struct ide_tape_obj {
172 struct kref kref; 172 struct kref kref;
173 173
174 /* 174 /*
175 * pc points to the current processed packet command.
176 *
177 * failed_pc points to the last failed packet command, or contains 175 * failed_pc points to the last failed packet command, or contains
178 * NULL if we do not need to retry any packet command. This is 176 * NULL if we do not need to retry any packet command. This is
179 * required since an additional packet command is needed before the 177 * required since an additional packet command is needed before the
180 * retry, to get detailed information on what went wrong. 178 * retry, to get detailed information on what went wrong.
181 */ 179 */
182 /* Current packet command */
183 struct ide_atapi_pc *pc;
184 /* Last failed packet command */ 180 /* Last failed packet command */
185 struct ide_atapi_pc *failed_pc; 181 struct ide_atapi_pc *failed_pc;
186 /* used by REQ_IDETAPE_{READ,WRITE} requests */ 182 /* used by REQ_IDETAPE_{READ,WRITE} requests */
187 struct ide_atapi_pc queued_pc; 183 struct ide_atapi_pc queued_pc;
188 184
189 struct ide_atapi_pc request_sense_pc;
190 struct request request_sense_rq;
191
192 /* 185 /*
193 * DSC polling variables. 186 * DSC polling variables.
194 * 187 *
@@ -274,11 +267,6 @@ static DEFINE_MUTEX(idetape_ref_mutex);
274 267
275static struct class *idetape_sysfs_class; 268static struct class *idetape_sysfs_class;
276 269
277#define to_ide_tape(obj) container_of(obj, struct ide_tape_obj, kref)
278
279#define ide_tape_g(disk) \
280 container_of((disk)->private_data, struct ide_tape_obj, driver)
281
282static void ide_tape_release(struct kref *); 270static void ide_tape_release(struct kref *);
283 271
284static struct ide_tape_obj *ide_tape_get(struct gendisk *disk) 272static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
@@ -286,7 +274,7 @@ static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
286 struct ide_tape_obj *tape = NULL; 274 struct ide_tape_obj *tape = NULL;
287 275
288 mutex_lock(&idetape_ref_mutex); 276 mutex_lock(&idetape_ref_mutex);
289 tape = ide_tape_g(disk); 277 tape = ide_drv_g(disk, ide_tape_obj);
290 if (tape) { 278 if (tape) {
291 if (ide_device_get(tape->drive)) 279 if (ide_device_get(tape->drive))
292 tape = NULL; 280 tape = NULL;
@@ -313,8 +301,6 @@ static void ide_tape_put(struct ide_tape_obj *tape)
313 */ 301 */
314static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES]; 302static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES];
315 303
316#define ide_tape_f(file) ((file)->private_data)
317
318static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i) 304static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i)
319{ 305{
320 struct ide_tape_obj *tape = NULL; 306 struct ide_tape_obj *tape = NULL;
@@ -522,14 +508,19 @@ static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
522 return 0; 508 return 0;
523} 509}
524 510
525static void ide_tape_callback(ide_drive_t *drive) 511static void ide_tape_handle_dsc(ide_drive_t *);
512
513static void ide_tape_callback(ide_drive_t *drive, int dsc)
526{ 514{
527 idetape_tape_t *tape = drive->driver_data; 515 idetape_tape_t *tape = drive->driver_data;
528 struct ide_atapi_pc *pc = tape->pc; 516 struct ide_atapi_pc *pc = drive->pc;
529 int uptodate = pc->error ? 0 : 1; 517 int uptodate = pc->error ? 0 : 1;
530 518
531 debug_log(DBG_PROCS, "Enter %s\n", __func__); 519 debug_log(DBG_PROCS, "Enter %s\n", __func__);
532 520
521 if (dsc)
522 ide_tape_handle_dsc(drive);
523
533 if (tape->failed_pc == pc) 524 if (tape->failed_pc == pc)
534 tape->failed_pc = NULL; 525 tape->failed_pc = NULL;
535 526
@@ -558,7 +549,7 @@ static void ide_tape_callback(ide_drive_t *drive)
558 if (pc->error) 549 if (pc->error)
559 uptodate = pc->error; 550 uptodate = pc->error;
560 } else if (pc->c[0] == READ_POSITION && uptodate) { 551 } else if (pc->c[0] == READ_POSITION && uptodate) {
561 u8 *readpos = tape->pc->buf; 552 u8 *readpos = pc->buf;
562 553
563 debug_log(DBG_SENSE, "BOP - %s\n", 554 debug_log(DBG_SENSE, "BOP - %s\n",
564 (readpos[0] & 0x80) ? "Yes" : "No"); 555 (readpos[0] & 0x80) ? "Yes" : "No");
@@ -583,31 +574,6 @@ static void ide_tape_callback(ide_drive_t *drive)
583 idetape_end_request(drive, uptodate, 0); 574 idetape_end_request(drive, uptodate, 0);
584} 575}
585 576
586static void idetape_create_request_sense_cmd(struct ide_atapi_pc *pc)
587{
588 ide_init_pc(pc);
589 pc->c[0] = REQUEST_SENSE;
590 pc->c[4] = 20;
591 pc->req_xfer = 20;
592}
593
594/*
595 * idetape_retry_pc is called when an error was detected during the
596 * last packet command. We queue a request sense packet command in
597 * the head of the request list.
598 */
599static void idetape_retry_pc(ide_drive_t *drive)
600{
601 struct ide_tape_obj *tape = drive->driver_data;
602 struct request *rq = &tape->request_sense_rq;
603 struct ide_atapi_pc *pc = &tape->request_sense_pc;
604
605 (void)ide_read_error(drive);
606 idetape_create_request_sense_cmd(pc);
607 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
608 ide_queue_pc_head(drive, tape->disk, pc, rq);
609}
610
611/* 577/*
612 * Postpone the current request so that ide.c will be able to service requests 578 * Postpone the current request so that ide.c will be able to service requests
613 * from another device on the same hwgroup while we are polling for DSC. 579 * from another device on the same hwgroup while we are polling for DSC.
@@ -646,34 +612,18 @@ static int ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
646} 612}
647 613
648/* 614/*
649 * This is the usual interrupt handler which will be called during a packet
650 * command. We will transfer some of the data (as requested by the drive) and
651 * will re-point interrupt handler to us. When data transfer is finished, we
652 * will act according to the algorithm described before
653 * idetape_issue_pc.
654 */
655static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
656{
657 idetape_tape_t *tape = drive->driver_data;
658
659 return ide_pc_intr(drive, tape->pc, idetape_pc_intr, WAIT_TAPE_CMD,
660 NULL, idetape_update_buffers, idetape_retry_pc,
661 ide_tape_handle_dsc, ide_tape_io_buffers);
662}
663
664/*
665 * Packet Command Interface 615 * Packet Command Interface
666 * 616 *
667 * The current Packet Command is available in tape->pc, and will not change 617 * The current Packet Command is available in drive->pc, and will not change
668 * until we finish handling it. Each packet command is associated with a 618 * until we finish handling it. Each packet command is associated with a
669 * callback function that will be called when the command is finished. 619 * callback function that will be called when the command is finished.
670 * 620 *
671 * The handling will be done in three stages: 621 * The handling will be done in three stages:
672 * 622 *
673 * 1. idetape_issue_pc will send the packet command to the drive, and will set 623 * 1. idetape_issue_pc will send the packet command to the drive, and will set
674 * the interrupt handler to idetape_pc_intr. 624 * the interrupt handler to ide_pc_intr.
675 * 625 *
676 * 2. On each interrupt, idetape_pc_intr will be called. This step will be 626 * 2. On each interrupt, ide_pc_intr will be called. This step will be
677 * repeated until the device signals us that no more interrupts will be issued. 627 * repeated until the device signals us that no more interrupts will be issued.
678 * 628 *
679 * 3. ATAPI Tape media access commands have immediate status with a delayed 629 * 3. ATAPI Tape media access commands have immediate status with a delayed
@@ -697,20 +647,13 @@ static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
697 * again, the callback function will be called and then we will handle the next 647 * again, the callback function will be called and then we will handle the next
698 * request. 648 * request.
699 */ 649 */
700static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive)
701{
702 idetape_tape_t *tape = drive->driver_data;
703
704 return ide_transfer_pc(drive, tape->pc, idetape_pc_intr,
705 WAIT_TAPE_CMD, NULL);
706}
707 650
708static ide_startstop_t idetape_issue_pc(ide_drive_t *drive, 651static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
709 struct ide_atapi_pc *pc) 652 struct ide_atapi_pc *pc)
710{ 653{
711 idetape_tape_t *tape = drive->driver_data; 654 idetape_tape_t *tape = drive->driver_data;
712 655
713 if (tape->pc->c[0] == REQUEST_SENSE && 656 if (drive->pc->c[0] == REQUEST_SENSE &&
714 pc->c[0] == REQUEST_SENSE) { 657 pc->c[0] == REQUEST_SENSE) {
715 printk(KERN_ERR "ide-tape: possible ide-tape.c bug - " 658 printk(KERN_ERR "ide-tape: possible ide-tape.c bug - "
716 "Two request sense in serial were issued\n"); 659 "Two request sense in serial were issued\n");
@@ -718,8 +661,9 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
718 661
719 if (tape->failed_pc == NULL && pc->c[0] != REQUEST_SENSE) 662 if (tape->failed_pc == NULL && pc->c[0] != REQUEST_SENSE)
720 tape->failed_pc = pc; 663 tape->failed_pc = pc;
664
721 /* Set the current packet command */ 665 /* Set the current packet command */
722 tape->pc = pc; 666 drive->pc = pc;
723 667
724 if (pc->retries > IDETAPE_MAX_PC_RETRIES || 668 if (pc->retries > IDETAPE_MAX_PC_RETRIES ||
725 (pc->flags & PC_FLAG_ABORT)) { 669 (pc->flags & PC_FLAG_ABORT)) {
@@ -743,15 +687,14 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
743 pc->error = IDETAPE_ERROR_GENERAL; 687 pc->error = IDETAPE_ERROR_GENERAL;
744 } 688 }
745 tape->failed_pc = NULL; 689 tape->failed_pc = NULL;
746 drive->pc_callback(drive); 690 drive->pc_callback(drive, 0);
747 return ide_stopped; 691 return ide_stopped;
748 } 692 }
749 debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]); 693 debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]);
750 694
751 pc->retries++; 695 pc->retries++;
752 696
753 return ide_issue_pc(drive, pc, idetape_transfer_pc, 697 return ide_issue_pc(drive, WAIT_TAPE_CMD, NULL);
754 WAIT_TAPE_CMD, NULL);
755} 698}
756 699
757/* A mode sense command is used to "sense" tape parameters. */ 700/* A mode sense command is used to "sense" tape parameters. */
@@ -785,7 +728,7 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
785{ 728{
786 ide_hwif_t *hwif = drive->hwif; 729 ide_hwif_t *hwif = drive->hwif;
787 idetape_tape_t *tape = drive->driver_data; 730 idetape_tape_t *tape = drive->driver_data;
788 struct ide_atapi_pc *pc = tape->pc; 731 struct ide_atapi_pc *pc = drive->pc;
789 u8 stat; 732 u8 stat;
790 733
791 stat = hwif->tp_ops->read_status(hwif); 734 stat = hwif->tp_ops->read_status(hwif);
@@ -797,7 +740,7 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
797 printk(KERN_ERR "ide-tape: %s: I/O error, ", 740 printk(KERN_ERR "ide-tape: %s: I/O error, ",
798 tape->name); 741 tape->name);
799 /* Retry operation */ 742 /* Retry operation */
800 idetape_retry_pc(drive); 743 ide_retry_pc(drive, tape->disk);
801 return ide_stopped; 744 return ide_stopped;
802 } 745 }
803 pc->error = 0; 746 pc->error = 0;
@@ -805,7 +748,7 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
805 pc->error = IDETAPE_ERROR_GENERAL; 748 pc->error = IDETAPE_ERROR_GENERAL;
806 tape->failed_pc = NULL; 749 tape->failed_pc = NULL;
807 } 750 }
808 drive->pc_callback(drive); 751 drive->pc_callback(drive, 0);
809 return ide_stopped; 752 return ide_stopped;
810} 753}
811 754
@@ -862,7 +805,7 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
862 } 805 }
863 806
864 /* Retry a failed packet command */ 807 /* Retry a failed packet command */
865 if (tape->failed_pc && tape->pc->c[0] == REQUEST_SENSE) { 808 if (tape->failed_pc && drive->pc->c[0] == REQUEST_SENSE) {
866 pc = tape->failed_pc; 809 pc = tape->failed_pc;
867 goto out; 810 goto out;
868 } 811 }
@@ -883,12 +826,13 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
883 */ 826 */
884 stat = hwif->tp_ops->read_status(hwif); 827 stat = hwif->tp_ops->read_status(hwif);
885 828
886 if (!drive->dsc_overlap && !(rq->cmd[13] & REQ_IDETAPE_PC2)) 829 if ((drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) == 0 &&
830 (rq->cmd[13] & REQ_IDETAPE_PC2) == 0)
887 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags); 831 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
888 832
889 if (drive->post_reset == 1) { 833 if (drive->dev_flags & IDE_DFLAG_POST_RESET) {
890 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags); 834 set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
891 drive->post_reset = 0; 835 drive->dev_flags &= ~IDE_DFLAG_POST_RESET;
892 } 836 }
893 837
894 if (!test_and_clear_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags) && 838 if (!test_and_clear_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags) &&
@@ -1411,7 +1355,7 @@ static int idetape_init_read(ide_drive_t *drive)
1411 * No point in issuing this if DSC overlap isn't supported, some 1355 * No point in issuing this if DSC overlap isn't supported, some
1412 * drives (Seagate STT3401A) will return an error. 1356 * drives (Seagate STT3401A) will return an error.
1413 */ 1357 */
1414 if (drive->dsc_overlap) { 1358 if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
1415 bytes_read = idetape_queue_rw_tail(drive, 1359 bytes_read = idetape_queue_rw_tail(drive,
1416 REQ_IDETAPE_READ, 0, 1360 REQ_IDETAPE_READ, 0,
1417 tape->merge_bh); 1361 tape->merge_bh);
@@ -1592,7 +1536,7 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
1592static ssize_t idetape_chrdev_read(struct file *file, char __user *buf, 1536static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
1593 size_t count, loff_t *ppos) 1537 size_t count, loff_t *ppos)
1594{ 1538{
1595 struct ide_tape_obj *tape = ide_tape_f(file); 1539 struct ide_tape_obj *tape = file->private_data;
1596 ide_drive_t *drive = tape->drive; 1540 ide_drive_t *drive = tape->drive;
1597 ssize_t bytes_read, temp, actually_read = 0, rc; 1541 ssize_t bytes_read, temp, actually_read = 0, rc;
1598 ssize_t ret = 0; 1542 ssize_t ret = 0;
@@ -1654,7 +1598,7 @@ finish:
1654static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf, 1598static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
1655 size_t count, loff_t *ppos) 1599 size_t count, loff_t *ppos)
1656{ 1600{
1657 struct ide_tape_obj *tape = ide_tape_f(file); 1601 struct ide_tape_obj *tape = file->private_data;
1658 ide_drive_t *drive = tape->drive; 1602 ide_drive_t *drive = tape->drive;
1659 ssize_t actually_written = 0; 1603 ssize_t actually_written = 0;
1660 ssize_t ret = 0; 1604 ssize_t ret = 0;
@@ -1687,7 +1631,7 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
1687 * point in issuing this if DSC overlap isn't supported, some 1631 * point in issuing this if DSC overlap isn't supported, some
1688 * drives (Seagate STT3401A) will return an error. 1632 * drives (Seagate STT3401A) will return an error.
1689 */ 1633 */
1690 if (drive->dsc_overlap) { 1634 if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
1691 ssize_t retval = idetape_queue_rw_tail(drive, 1635 ssize_t retval = idetape_queue_rw_tail(drive,
1692 REQ_IDETAPE_WRITE, 0, 1636 REQ_IDETAPE_WRITE, 0,
1693 tape->merge_bh); 1637 tape->merge_bh);
@@ -1886,7 +1830,7 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
1886static int idetape_chrdev_ioctl(struct inode *inode, struct file *file, 1830static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
1887 unsigned int cmd, unsigned long arg) 1831 unsigned int cmd, unsigned long arg)
1888{ 1832{
1889 struct ide_tape_obj *tape = ide_tape_f(file); 1833 struct ide_tape_obj *tape = file->private_data;
1890 ide_drive_t *drive = tape->drive; 1834 ide_drive_t *drive = tape->drive;
1891 struct mtop mtop; 1835 struct mtop mtop;
1892 struct mtget mtget; 1836 struct mtget mtget;
@@ -2063,7 +2007,7 @@ static void idetape_write_release(ide_drive_t *drive, unsigned int minor)
2063 2007
2064static int idetape_chrdev_release(struct inode *inode, struct file *filp) 2008static int idetape_chrdev_release(struct inode *inode, struct file *filp)
2065{ 2009{
2066 struct ide_tape_obj *tape = ide_tape_f(filp); 2010 struct ide_tape_obj *tape = filp->private_data;
2067 ide_drive_t *drive = tape->drive; 2011 ide_drive_t *drive = tape->drive;
2068 unsigned int minor = iminor(inode); 2012 unsigned int minor = iminor(inode);
2069 2013
@@ -2202,7 +2146,7 @@ static int divf_tdsc(ide_drive_t *drive) { return HZ; }
2202static int divf_buffer(ide_drive_t *drive) { return 2; } 2146static int divf_buffer(ide_drive_t *drive) { return 2; }
2203static int divf_buffer_size(ide_drive_t *drive) { return 1024; } 2147static int divf_buffer_size(ide_drive_t *drive) { return 1024; }
2204 2148
2205ide_devset_rw_field(dsc_overlap, dsc_overlap); 2149ide_devset_rw_flag(dsc_overlap, IDE_DFLAG_DSC_OVERLAP);
2206 2150
2207ide_tape_devset_rw_field(debug_mask, debug_mask); 2151ide_tape_devset_rw_field(debug_mask, debug_mask);
2208ide_tape_devset_rw_field(tdsc, best_dsc_rw_freq); 2152ide_tape_devset_rw_field(tdsc, best_dsc_rw_freq);
@@ -2241,33 +2185,32 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2241 unsigned long t; 2185 unsigned long t;
2242 int speed; 2186 int speed;
2243 int buffer_size; 2187 int buffer_size;
2244 u8 gcw[2];
2245 u16 *ctl = (u16 *)&tape->caps[12]; 2188 u16 *ctl = (u16 *)&tape->caps[12];
2246 2189
2247 drive->pc_callback = ide_tape_callback; 2190 drive->pc_callback = ide_tape_callback;
2191 drive->pc_update_buffers = idetape_update_buffers;
2192 drive->pc_io_buffers = ide_tape_io_buffers;
2248 2193
2249 spin_lock_init(&tape->lock); 2194 spin_lock_init(&tape->lock);
2250 drive->dsc_overlap = 1; 2195
2196 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
2197
2251 if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) { 2198 if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) {
2252 printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n", 2199 printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n",
2253 tape->name); 2200 tape->name);
2254 drive->dsc_overlap = 0; 2201 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
2255 } 2202 }
2203
2256 /* Seagate Travan drives do not support DSC overlap. */ 2204 /* Seagate Travan drives do not support DSC overlap. */
2257 if (strstr((char *)&drive->id[ATA_ID_PROD], "Seagate STT3401")) 2205 if (strstr((char *)&drive->id[ATA_ID_PROD], "Seagate STT3401"))
2258 drive->dsc_overlap = 0; 2206 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
2207
2259 tape->minor = minor; 2208 tape->minor = minor;
2260 tape->name[0] = 'h'; 2209 tape->name[0] = 'h';
2261 tape->name[1] = 't'; 2210 tape->name[1] = 't';
2262 tape->name[2] = '0' + minor; 2211 tape->name[2] = '0' + minor;
2263 tape->chrdev_dir = IDETAPE_DIR_NONE; 2212 tape->chrdev_dir = IDETAPE_DIR_NONE;
2264 2213
2265 *((u16 *)&gcw) = drive->id[ATA_ID_CONFIG];
2266
2267 /* Command packet DRQ type */
2268 if (((gcw[0] & 0x60) >> 5) == 1)
2269 set_bit(IDE_AFLAG_DRQ_INTERRUPT, &drive->atapi_flags);
2270
2271 idetape_get_inquiry_results(drive); 2214 idetape_get_inquiry_results(drive);
2272 idetape_get_mode_sense_results(drive); 2215 idetape_get_mode_sense_results(drive);
2273 ide_tape_get_bsize_from_bdesc(drive); 2216 ide_tape_get_bsize_from_bdesc(drive);
@@ -2302,7 +2245,7 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2302 (*(u16 *)&tape->caps[16] * 512) / tape->buffer_size, 2245 (*(u16 *)&tape->caps[16] * 512) / tape->buffer_size,
2303 tape->buffer_size / 1024, 2246 tape->buffer_size / 1024,
2304 tape->best_dsc_rw_freq * 1000 / HZ, 2247 tape->best_dsc_rw_freq * 1000 / HZ,
2305 drive->using_dma ? ", DMA":""); 2248 (drive->dev_flags & IDE_DFLAG_USING_DMA) ? ", DMA" : "");
2306 2249
2307 ide_proc_register_driver(drive, tape->driver); 2250 ide_proc_register_driver(drive, tape->driver);
2308} 2251}
@@ -2320,13 +2263,13 @@ static void ide_tape_remove(ide_drive_t *drive)
2320 2263
2321static void ide_tape_release(struct kref *kref) 2264static void ide_tape_release(struct kref *kref)
2322{ 2265{
2323 struct ide_tape_obj *tape = to_ide_tape(kref); 2266 struct ide_tape_obj *tape = to_ide_drv(kref, ide_tape_obj);
2324 ide_drive_t *drive = tape->drive; 2267 ide_drive_t *drive = tape->drive;
2325 struct gendisk *g = tape->disk; 2268 struct gendisk *g = tape->disk;
2326 2269
2327 BUG_ON(tape->merge_bh_size); 2270 BUG_ON(tape->merge_bh_size);
2328 2271
2329 drive->dsc_overlap = 0; 2272 drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
2330 drive->driver_data = NULL; 2273 drive->driver_data = NULL;
2331 device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor)); 2274 device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor));
2332 device_destroy(idetape_sysfs_class, 2275 device_destroy(idetape_sysfs_class,
@@ -2368,7 +2311,6 @@ static ide_driver_t idetape_driver = {
2368 .probe = ide_tape_probe, 2311 .probe = ide_tape_probe,
2369 .remove = ide_tape_remove, 2312 .remove = ide_tape_remove,
2370 .version = IDETAPE_VERSION, 2313 .version = IDETAPE_VERSION,
2371 .media = ide_tape,
2372 .do_request = idetape_do_request, 2314 .do_request = idetape_do_request,
2373 .end_request = idetape_end_request, 2315 .end_request = idetape_end_request,
2374 .error = __ide_error, 2316 .error = __ide_error,
@@ -2403,7 +2345,7 @@ static int idetape_open(struct inode *inode, struct file *filp)
2403static int idetape_release(struct inode *inode, struct file *filp) 2345static int idetape_release(struct inode *inode, struct file *filp)
2404{ 2346{
2405 struct gendisk *disk = inode->i_bdev->bd_disk; 2347 struct gendisk *disk = inode->i_bdev->bd_disk;
2406 struct ide_tape_obj *tape = ide_tape_g(disk); 2348 struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj);
2407 2349
2408 ide_tape_put(tape); 2350 ide_tape_put(tape);
2409 2351
@@ -2414,7 +2356,7 @@ static int idetape_ioctl(struct inode *inode, struct file *file,
2414 unsigned int cmd, unsigned long arg) 2356 unsigned int cmd, unsigned long arg)
2415{ 2357{
2416 struct block_device *bdev = inode->i_bdev; 2358 struct block_device *bdev = inode->i_bdev;
2417 struct ide_tape_obj *tape = ide_tape_g(bdev->bd_disk); 2359 struct ide_tape_obj *tape = ide_drv_g(bdev->bd_disk, ide_tape_obj);
2418 ide_drive_t *drive = tape->drive; 2360 ide_drive_t *drive = tape->drive;
2419 int err = generic_ide_ioctl(drive, file, bdev, cmd, arg); 2361 int err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
2420 if (err == -EINVAL) 2362 if (err == -EINVAL)
@@ -2441,7 +2383,8 @@ static int ide_tape_probe(ide_drive_t *drive)
2441 if (drive->media != ide_tape) 2383 if (drive->media != ide_tape)
2442 goto failed; 2384 goto failed;
2443 2385
2444 if (drive->id_read == 1 && !ide_check_atapi_device(drive, DRV_NAME)) { 2386 if ((drive->dev_flags & IDE_DFLAG_ID_READ) &&
2387 ide_check_atapi_device(drive, DRV_NAME) == 0) {
2445 printk(KERN_ERR "ide-tape: %s: not supported by this version of" 2388 printk(KERN_ERR "ide-tape: %s: not supported by this version of"
2446 " the driver\n", drive->name); 2389 " the driver\n", drive->name);
2447 goto failed; 2390 goto failed;
@@ -2477,12 +2420,11 @@ static int ide_tape_probe(ide_drive_t *drive)
2477 2420
2478 idetape_setup(drive, tape, minor); 2421 idetape_setup(drive, tape, minor);
2479 2422
2480 device_create_drvdata(idetape_sysfs_class, &drive->gendev, 2423 device_create(idetape_sysfs_class, &drive->gendev,
2481 MKDEV(IDETAPE_MAJOR, minor), NULL, 2424 MKDEV(IDETAPE_MAJOR, minor), NULL, "%s", tape->name);
2482 "%s", tape->name); 2425 device_create(idetape_sysfs_class, &drive->gendev,
2483 device_create_drvdata(idetape_sysfs_class, &drive->gendev, 2426 MKDEV(IDETAPE_MAJOR, minor + 128), NULL,
2484 MKDEV(IDETAPE_MAJOR, minor + 128), NULL, 2427 "n%s", tape->name);
2485 "n%s", tape->name);
2486 2428
2487 g->fops = &idetape_block_ops; 2429 g->fops = &idetape_block_ops;
2488 ide_register_region(g); 2430 ide_register_region(g);
diff --git a/drivers/ide/ide-taskfile.c b/drivers/ide/ide-taskfile.c
index 487b18b3ebae..bf4fb9d8d176 100644
--- a/drivers/ide/ide-taskfile.c
+++ b/drivers/ide/ide-taskfile.c
@@ -53,9 +53,6 @@ int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf)
53} 53}
54 54
55static ide_startstop_t task_no_data_intr(ide_drive_t *); 55static ide_startstop_t task_no_data_intr(ide_drive_t *);
56static ide_startstop_t set_geometry_intr(ide_drive_t *);
57static ide_startstop_t recal_intr(ide_drive_t *);
58static ide_startstop_t set_multmode_intr(ide_drive_t *);
59static ide_startstop_t pre_task_out_intr(ide_drive_t *, struct request *); 56static ide_startstop_t pre_task_out_intr(ide_drive_t *, struct request *);
60static ide_startstop_t task_in_intr(ide_drive_t *); 57static ide_startstop_t task_in_intr(ide_drive_t *);
61 58
@@ -79,6 +76,8 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
79 if (task->tf_flags & IDE_TFLAG_FLAGGED) 76 if (task->tf_flags & IDE_TFLAG_FLAGGED)
80 task->tf_flags |= IDE_TFLAG_FLAGGED_SET_IN_FLAGS; 77 task->tf_flags |= IDE_TFLAG_FLAGGED_SET_IN_FLAGS;
81 78
79 memcpy(&hwif->task, task, sizeof(*task));
80
82 if ((task->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) { 81 if ((task->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) {
83 ide_tf_dump(drive->name, tf); 82 ide_tf_dump(drive->name, tf);
84 tp_ops->set_irq(hwif, 1); 83 tp_ops->set_irq(hwif, 1);
@@ -99,24 +98,12 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
99 case TASKFILE_NO_DATA: 98 case TASKFILE_NO_DATA:
100 if (handler == NULL) 99 if (handler == NULL)
101 handler = task_no_data_intr; 100 handler = task_no_data_intr;
102 if (task->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) {
103 switch (tf->command) {
104 case ATA_CMD_INIT_DEV_PARAMS:
105 handler = set_geometry_intr;
106 break;
107 case ATA_CMD_RESTORE:
108 handler = recal_intr;
109 break;
110 case ATA_CMD_SET_MULTI:
111 handler = set_multmode_intr;
112 break;
113 }
114 }
115 ide_execute_command(drive, tf->command, handler, 101 ide_execute_command(drive, tf->command, handler,
116 WAIT_WORSTCASE, NULL); 102 WAIT_WORSTCASE, NULL);
117 return ide_started; 103 return ide_started;
118 default: 104 default:
119 if (drive->using_dma == 0 || dma_ops->dma_setup(drive)) 105 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0 ||
106 dma_ops->dma_setup(drive))
120 return ide_stopped; 107 return ide_stopped;
121 dma_ops->dma_exec_cmd(drive, tf->command); 108 dma_ops->dma_exec_cmd(drive, tf->command);
122 dma_ops->dma_start(drive); 109 dma_ops->dma_start(drive);
@@ -126,33 +113,15 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
126EXPORT_SYMBOL_GPL(do_rw_taskfile); 113EXPORT_SYMBOL_GPL(do_rw_taskfile);
127 114
128/* 115/*
129 * set_multmode_intr() is invoked on completion of a ATA_CMD_SET_MULTI cmd. 116 * Handler for commands without a data phase
130 */
131static ide_startstop_t set_multmode_intr(ide_drive_t *drive)
132{
133 ide_hwif_t *hwif = drive->hwif;
134 u8 stat;
135
136 local_irq_enable_in_hardirq();
137 stat = hwif->tp_ops->read_status(hwif);
138
139 if (OK_STAT(stat, ATA_DRDY, BAD_STAT))
140 drive->mult_count = drive->mult_req;
141 else {
142 drive->mult_req = drive->mult_count = 0;
143 drive->special.b.recalibrate = 1;
144 (void) ide_dump_status(drive, "set_multmode", stat);
145 }
146 return ide_stopped;
147}
148
149/*
150 * set_geometry_intr() is invoked on completion of a ATA_CMD_INIT_DEV_PARAMS cmd.
151 */ 117 */
152static ide_startstop_t set_geometry_intr(ide_drive_t *drive) 118static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
153{ 119{
154 ide_hwif_t *hwif = drive->hwif; 120 ide_hwif_t *hwif = drive->hwif;
155 int retries = 5; 121 ide_task_t *task = &hwif->task;
122 struct ide_taskfile *tf = &task->tf;
123 int custom = (task->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) ? 1 : 0;
124 int retries = (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) ? 5 : 1;
156 u8 stat; 125 u8 stat;
157 126
158 local_irq_enable_in_hardirq(); 127 local_irq_enable_in_hardirq();
@@ -164,50 +133,36 @@ static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
164 udelay(10); 133 udelay(10);
165 }; 134 };
166 135
167 if (OK_STAT(stat, ATA_DRDY, BAD_STAT)) 136 if (!OK_STAT(stat, ATA_DRDY, BAD_STAT)) {
168 return ide_stopped; 137 if (custom && tf->command == ATA_CMD_SET_MULTI) {
169 138 drive->mult_req = drive->mult_count = 0;
170 if (stat & (ATA_ERR | ATA_DRQ)) 139 drive->special.b.recalibrate = 1;
171 return ide_error(drive, "set_geometry_intr", stat); 140 (void)ide_dump_status(drive, __func__, stat);
172 141 return ide_stopped;
173 ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL); 142 } else if (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) {
174 return ide_started; 143 if ((stat & (ATA_ERR | ATA_DRQ)) == 0) {
175} 144 ide_set_handler(drive, &task_no_data_intr,
176 145 WAIT_WORSTCASE, NULL);
177/* 146 return ide_started;
178 * recal_intr() is invoked on completion of a ATA_CMD_RESTORE (recalibrate) cmd. 147 }
179 */ 148 }
180static ide_startstop_t recal_intr(ide_drive_t *drive)
181{
182 ide_hwif_t *hwif = drive->hwif;
183 u8 stat;
184
185 local_irq_enable_in_hardirq();
186 stat = hwif->tp_ops->read_status(hwif);
187
188 if (!OK_STAT(stat, ATA_DRDY, BAD_STAT))
189 return ide_error(drive, "recal_intr", stat);
190 return ide_stopped;
191}
192
193/*
194 * Handler for commands without a data phase
195 */
196static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
197{
198 ide_hwif_t *hwif = drive->hwif;
199 ide_task_t *args = hwif->hwgroup->rq->special;
200 u8 stat;
201
202 local_irq_enable_in_hardirq();
203 stat = hwif->tp_ops->read_status(hwif);
204
205 if (!OK_STAT(stat, ATA_DRDY, BAD_STAT))
206 return ide_error(drive, "task_no_data_intr", stat); 149 return ide_error(drive, "task_no_data_intr", stat);
207 /* calls ide_end_drive_cmd */ 150 /* calls ide_end_drive_cmd */
151 }
208 152
209 if (args) 153 if (!custom)
154 ide_end_drive_cmd(drive, stat, ide_read_error(drive));
155 else if (tf->command == ATA_CMD_IDLEIMMEDIATE) {
156 hwif->tp_ops->tf_read(drive, task);
157 if (tf->lbal != 0xc4) {
158 printk(KERN_ERR "%s: head unload failed!\n",
159 drive->name);
160 ide_tf_dump(drive->name, tf);
161 } else
162 drive->dev_flags |= IDE_DFLAG_PARKED;
210 ide_end_drive_cmd(drive, stat, ide_read_error(drive)); 163 ide_end_drive_cmd(drive, stat, ide_read_error(drive));
164 } else if (tf->command == ATA_CMD_SET_MULTI)
165 drive->mult_count = drive->mult_req;
211 166
212 return ide_stopped; 167 return ide_stopped;
213} 168}
@@ -469,13 +424,12 @@ static ide_startstop_t pre_task_out_intr(ide_drive_t *drive, struct request *rq)
469 if (ide_wait_stat(&startstop, drive, ATA_DRQ, 424 if (ide_wait_stat(&startstop, drive, ATA_DRQ,
470 drive->bad_wstat, WAIT_DRQ)) { 425 drive->bad_wstat, WAIT_DRQ)) {
471 printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n", 426 printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n",
472 drive->name, 427 drive->name, drive->hwif->data_phase ? "MULT" : "",
473 drive->hwif->data_phase ? "MULT" : "", 428 (drive->dev_flags & IDE_DFLAG_LBA48) ? "_EXT" : "");
474 drive->addressing ? "_EXT" : "");
475 return startstop; 429 return startstop;
476 } 430 }
477 431
478 if (!drive->unmask) 432 if ((drive->dev_flags & IDE_DFLAG_UNMASK) == 0)
479 local_irq_disable(); 433 local_irq_disable();
480 434
481 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL); 435 ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
@@ -591,7 +545,7 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
591 545
592 args.tf_flags = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE | 546 args.tf_flags = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE |
593 IDE_TFLAG_IN_TF; 547 IDE_TFLAG_IN_TF;
594 if (drive->addressing == 1) 548 if (drive->dev_flags & IDE_DFLAG_LBA48)
595 args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB); 549 args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB);
596 550
597 if (req_task->out_flags.all) { 551 if (req_task->out_flags.all) {
@@ -694,7 +648,7 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
694 if ((args.tf_flags & IDE_TFLAG_FLAGGED_SET_IN_FLAGS) && 648 if ((args.tf_flags & IDE_TFLAG_FLAGGED_SET_IN_FLAGS) &&
695 req_task->in_flags.all == 0) { 649 req_task->in_flags.all == 0) {
696 req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS; 650 req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
697 if (drive->addressing == 1) 651 if (drive->dev_flags & IDE_DFLAG_LBA48)
698 req_task->in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8); 652 req_task->in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
699 } 653 }
700 654
diff --git a/drivers/ide/ide.c b/drivers/ide/ide.c
index 9dcf5aed92cb..04f8f13cb9d7 100644
--- a/drivers/ide/ide.c
+++ b/drivers/ide/ide.c
@@ -114,7 +114,7 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif)
114 memset(drive, 0, sizeof(*drive)); 114 memset(drive, 0, sizeof(*drive));
115 115
116 drive->media = ide_disk; 116 drive->media = ide_disk;
117 drive->select.all = (unit<<4)|0xa0; 117 drive->select = (unit << 4) | ATA_DEVICE_OBS;
118 drive->hwif = hwif; 118 drive->hwif = hwif;
119 drive->ready_stat = ATA_DRDY; 119 drive->ready_stat = ATA_DRDY;
120 drive->bad_wstat = BAD_W_STAT; 120 drive->bad_wstat = BAD_W_STAT;
@@ -138,7 +138,7 @@ static void __ide_port_unregister_devices(ide_hwif_t *hwif)
138 for (i = 0; i < MAX_DRIVES; i++) { 138 for (i = 0; i < MAX_DRIVES; i++) {
139 ide_drive_t *drive = &hwif->drives[i]; 139 ide_drive_t *drive = &hwif->drives[i];
140 140
141 if (drive->present) { 141 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
142 spin_unlock_irq(&ide_lock); 142 spin_unlock_irq(&ide_lock);
143 device_unregister(&drive->gendev); 143 device_unregister(&drive->gendev);
144 wait_for_completion(&drive->gendev_rel_comp); 144 wait_for_completion(&drive->gendev_rel_comp);
@@ -227,8 +227,7 @@ void ide_unregister(ide_hwif_t *hwif)
227 kfree(hwif->sg_table); 227 kfree(hwif->sg_table);
228 unregister_blkdev(hwif->major, hwif->name); 228 unregister_blkdev(hwif->major, hwif->name);
229 229
230 if (hwif->dma_base) 230 ide_release_dma_engine(hwif);
231 ide_release_dma_engine(hwif);
232 231
233 mutex_unlock(&ide_cfg_mtx); 232 mutex_unlock(&ide_cfg_mtx);
234} 233}
@@ -254,7 +253,7 @@ ide_devset_get(io_32bit, io_32bit);
254 253
255static int set_io_32bit(ide_drive_t *drive, int arg) 254static int set_io_32bit(ide_drive_t *drive, int arg)
256{ 255{
257 if (drive->no_io_32bit) 256 if (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT)
258 return -EPERM; 257 return -EPERM;
259 258
260 if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1)) 259 if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
@@ -265,19 +264,22 @@ static int set_io_32bit(ide_drive_t *drive, int arg)
265 return 0; 264 return 0;
266} 265}
267 266
268ide_devset_get(ksettings, keep_settings); 267ide_devset_get_flag(ksettings, IDE_DFLAG_KEEP_SETTINGS);
269 268
270static int set_ksettings(ide_drive_t *drive, int arg) 269static int set_ksettings(ide_drive_t *drive, int arg)
271{ 270{
272 if (arg < 0 || arg > 1) 271 if (arg < 0 || arg > 1)
273 return -EINVAL; 272 return -EINVAL;
274 273
275 drive->keep_settings = arg; 274 if (arg)
275 drive->dev_flags |= IDE_DFLAG_KEEP_SETTINGS;
276 else
277 drive->dev_flags &= ~IDE_DFLAG_KEEP_SETTINGS;
276 278
277 return 0; 279 return 0;
278} 280}
279 281
280ide_devset_get(using_dma, using_dma); 282ide_devset_get_flag(using_dma, IDE_DFLAG_USING_DMA);
281 283
282static int set_using_dma(ide_drive_t *drive, int arg) 284static int set_using_dma(ide_drive_t *drive, int arg)
283{ 285{
@@ -311,9 +313,32 @@ out:
311#endif 313#endif
312} 314}
313 315
316/*
317 * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
318 */
319static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
320{
321 switch (req_pio) {
322 case 202:
323 case 201:
324 case 200:
325 case 102:
326 case 101:
327 case 100:
328 return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
329 case 9:
330 case 8:
331 return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
332 case 7:
333 case 6:
334 return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
335 default:
336 return 0;
337 }
338}
339
314static int set_pio_mode(ide_drive_t *drive, int arg) 340static int set_pio_mode(ide_drive_t *drive, int arg)
315{ 341{
316 struct request *rq;
317 ide_hwif_t *hwif = drive->hwif; 342 ide_hwif_t *hwif = drive->hwif;
318 const struct ide_port_ops *port_ops = hwif->port_ops; 343 const struct ide_port_ops *port_ops = hwif->port_ops;
319 344
@@ -324,56 +349,65 @@ static int set_pio_mode(ide_drive_t *drive, int arg)
324 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)) 349 (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
325 return -ENOSYS; 350 return -ENOSYS;
326 351
327 if (drive->special.b.set_tune) 352 if (set_pio_mode_abuse(drive->hwif, arg)) {
328 return -EBUSY; 353 if (arg == 8 || arg == 9) {
354 unsigned long flags;
329 355
330 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 356 /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */
331 rq->cmd_type = REQ_TYPE_ATA_TASKFILE; 357 spin_lock_irqsave(&ide_lock, flags);
358 port_ops->set_pio_mode(drive, arg);
359 spin_unlock_irqrestore(&ide_lock, flags);
360 } else
361 port_ops->set_pio_mode(drive, arg);
362 } else {
363 int keep_dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
332 364
333 drive->tune_req = (u8) arg; 365 ide_set_pio(drive, arg);
334 drive->special.b.set_tune = 1;
335 366
336 blk_execute_rq(drive->queue, NULL, rq, 0); 367 if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) {
337 blk_put_request(rq); 368 if (keep_dma)
369 ide_dma_on(drive);
370 }
371 }
338 372
339 return 0; 373 return 0;
340} 374}
341 375
342ide_devset_get(unmaskirq, unmask); 376ide_devset_get_flag(unmaskirq, IDE_DFLAG_UNMASK);
343 377
344static int set_unmaskirq(ide_drive_t *drive, int arg) 378static int set_unmaskirq(ide_drive_t *drive, int arg)
345{ 379{
346 if (drive->no_unmask) 380 if (drive->dev_flags & IDE_DFLAG_NO_UNMASK)
347 return -EPERM; 381 return -EPERM;
348 382
349 if (arg < 0 || arg > 1) 383 if (arg < 0 || arg > 1)
350 return -EINVAL; 384 return -EINVAL;
351 385
352 drive->unmask = arg; 386 if (arg)
387 drive->dev_flags |= IDE_DFLAG_UNMASK;
388 else
389 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
353 390
354 return 0; 391 return 0;
355} 392}
356 393
357#define ide_gen_devset_rw(_name, _func) \ 394ide_ext_devset_rw_sync(io_32bit, io_32bit);
358__IDE_DEVSET(_name, DS_SYNC, get_##_func, set_##_func) 395ide_ext_devset_rw_sync(keepsettings, ksettings);
359 396ide_ext_devset_rw_sync(unmaskirq, unmaskirq);
360ide_gen_devset_rw(io_32bit, io_32bit); 397ide_ext_devset_rw_sync(using_dma, using_dma);
361ide_gen_devset_rw(keepsettings, ksettings); 398__IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode);
362ide_gen_devset_rw(unmaskirq, unmaskirq);
363ide_gen_devset_rw(using_dma, using_dma);
364__IDE_DEVSET(pio_mode, 0, NULL, set_pio_mode);
365 399
366static int generic_ide_suspend(struct device *dev, pm_message_t mesg) 400static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
367{ 401{
368 ide_drive_t *drive = dev->driver_data; 402 ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
369 ide_hwif_t *hwif = HWIF(drive); 403 ide_hwif_t *hwif = HWIF(drive);
370 struct request *rq; 404 struct request *rq;
371 struct request_pm_state rqpm; 405 struct request_pm_state rqpm;
372 ide_task_t args; 406 ide_task_t args;
373 int ret; 407 int ret;
374 408
375 /* Call ACPI _GTM only once */ 409 /* call ACPI _GTM only once */
376 if (!(drive->dn % 2)) 410 if ((drive->dn & 1) == 0 || pair == NULL)
377 ide_acpi_get_timing(hwif); 411 ide_acpi_get_timing(hwif);
378 412
379 memset(&rqpm, 0, sizeof(rqpm)); 413 memset(&rqpm, 0, sizeof(rqpm));
@@ -382,33 +416,32 @@ static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
382 rq->cmd_type = REQ_TYPE_PM_SUSPEND; 416 rq->cmd_type = REQ_TYPE_PM_SUSPEND;
383 rq->special = &args; 417 rq->special = &args;
384 rq->data = &rqpm; 418 rq->data = &rqpm;
385 rqpm.pm_step = ide_pm_state_start_suspend; 419 rqpm.pm_step = IDE_PM_START_SUSPEND;
386 if (mesg.event == PM_EVENT_PRETHAW) 420 if (mesg.event == PM_EVENT_PRETHAW)
387 mesg.event = PM_EVENT_FREEZE; 421 mesg.event = PM_EVENT_FREEZE;
388 rqpm.pm_state = mesg.event; 422 rqpm.pm_state = mesg.event;
389 423
390 ret = blk_execute_rq(drive->queue, NULL, rq, 0); 424 ret = blk_execute_rq(drive->queue, NULL, rq, 0);
391 blk_put_request(rq); 425 blk_put_request(rq);
392 /* only call ACPI _PS3 after both drivers are suspended */ 426
393 if (!ret && (((drive->dn % 2) && hwif->drives[0].present 427 /* call ACPI _PS3 only after both devices are suspended */
394 && hwif->drives[1].present) 428 if (ret == 0 && ((drive->dn & 1) || pair == NULL))
395 || !hwif->drives[0].present
396 || !hwif->drives[1].present))
397 ide_acpi_set_state(hwif, 0); 429 ide_acpi_set_state(hwif, 0);
430
398 return ret; 431 return ret;
399} 432}
400 433
401static int generic_ide_resume(struct device *dev) 434static int generic_ide_resume(struct device *dev)
402{ 435{
403 ide_drive_t *drive = dev->driver_data; 436 ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
404 ide_hwif_t *hwif = HWIF(drive); 437 ide_hwif_t *hwif = HWIF(drive);
405 struct request *rq; 438 struct request *rq;
406 struct request_pm_state rqpm; 439 struct request_pm_state rqpm;
407 ide_task_t args; 440 ide_task_t args;
408 int err; 441 int err;
409 442
410 /* Call ACPI _STM only once */ 443 /* call ACPI _PS0 / _STM only once */
411 if (!(drive->dn % 2)) { 444 if ((drive->dn & 1) == 0 || pair == NULL) {
412 ide_acpi_set_state(hwif, 1); 445 ide_acpi_set_state(hwif, 1);
413 ide_acpi_push_timing(hwif); 446 ide_acpi_push_timing(hwif);
414 } 447 }
@@ -422,7 +455,7 @@ static int generic_ide_resume(struct device *dev)
422 rq->cmd_flags |= REQ_PREEMPT; 455 rq->cmd_flags |= REQ_PREEMPT;
423 rq->special = &args; 456 rq->special = &args;
424 rq->data = &rqpm; 457 rq->data = &rqpm;
425 rqpm.pm_step = ide_pm_state_start_resume; 458 rqpm.pm_step = IDE_PM_START_RESUME;
426 rqpm.pm_state = PM_EVENT_ON; 459 rqpm.pm_state = PM_EVENT_ON;
427 460
428 err = blk_execute_rq(drive->queue, NULL, rq, 1); 461 err = blk_execute_rq(drive->queue, NULL, rq, 1);
@@ -554,6 +587,7 @@ static struct device_attribute ide_dev_attrs[] = {
554 __ATTR_RO(model), 587 __ATTR_RO(model),
555 __ATTR_RO(firmware), 588 __ATTR_RO(firmware),
556 __ATTR(serial, 0400, serial_show, NULL), 589 __ATTR(serial, 0400, serial_show, NULL),
590 __ATTR(unload_heads, 0644, ide_park_show, ide_park_store),
557 __ATTR_NULL 591 __ATTR_NULL
558}; 592};
559 593
@@ -708,22 +742,22 @@ static int ide_set_disk_chs(const char *str, struct kernel_param *kp)
708module_param_call(chs, ide_set_disk_chs, NULL, NULL, 0); 742module_param_call(chs, ide_set_disk_chs, NULL, NULL, 0);
709MODULE_PARM_DESC(chs, "force device as a disk (using CHS)"); 743MODULE_PARM_DESC(chs, "force device as a disk (using CHS)");
710 744
711static void ide_dev_apply_params(ide_drive_t *drive) 745static void ide_dev_apply_params(ide_drive_t *drive, u8 unit)
712{ 746{
713 int i = drive->hwif->index * MAX_DRIVES + drive->select.b.unit; 747 int i = drive->hwif->index * MAX_DRIVES + unit;
714 748
715 if (ide_nodma & (1 << i)) { 749 if (ide_nodma & (1 << i)) {
716 printk(KERN_INFO "ide: disallowing DMA for %s\n", drive->name); 750 printk(KERN_INFO "ide: disallowing DMA for %s\n", drive->name);
717 drive->nodma = 1; 751 drive->dev_flags |= IDE_DFLAG_NODMA;
718 } 752 }
719 if (ide_noflush & (1 << i)) { 753 if (ide_noflush & (1 << i)) {
720 printk(KERN_INFO "ide: disabling flush requests for %s\n", 754 printk(KERN_INFO "ide: disabling flush requests for %s\n",
721 drive->name); 755 drive->name);
722 drive->noflush = 1; 756 drive->dev_flags |= IDE_DFLAG_NOFLUSH;
723 } 757 }
724 if (ide_noprobe & (1 << i)) { 758 if (ide_noprobe & (1 << i)) {
725 printk(KERN_INFO "ide: skipping probe for %s\n", drive->name); 759 printk(KERN_INFO "ide: skipping probe for %s\n", drive->name);
726 drive->noprobe = 1; 760 drive->dev_flags |= IDE_DFLAG_NOPROBE;
727 } 761 }
728 if (ide_nowerr & (1 << i)) { 762 if (ide_nowerr & (1 << i)) {
729 printk(KERN_INFO "ide: ignoring the ATA_DF bit for %s\n", 763 printk(KERN_INFO "ide: ignoring the ATA_DF bit for %s\n",
@@ -732,7 +766,7 @@ static void ide_dev_apply_params(ide_drive_t *drive)
732 } 766 }
733 if (ide_cdroms & (1 << i)) { 767 if (ide_cdroms & (1 << i)) {
734 printk(KERN_INFO "ide: forcing %s as a CD-ROM\n", drive->name); 768 printk(KERN_INFO "ide: forcing %s as a CD-ROM\n", drive->name);
735 drive->present = 1; 769 drive->dev_flags |= IDE_DFLAG_PRESENT;
736 drive->media = ide_cdrom; 770 drive->media = ide_cdrom;
737 /* an ATAPI device ignores DRDY */ 771 /* an ATAPI device ignores DRDY */
738 drive->ready_stat = 0; 772 drive->ready_stat = 0;
@@ -741,11 +775,12 @@ static void ide_dev_apply_params(ide_drive_t *drive)
741 drive->cyl = drive->bios_cyl = ide_disks_chs[i].cyl; 775 drive->cyl = drive->bios_cyl = ide_disks_chs[i].cyl;
742 drive->head = drive->bios_head = ide_disks_chs[i].head; 776 drive->head = drive->bios_head = ide_disks_chs[i].head;
743 drive->sect = drive->bios_sect = ide_disks_chs[i].sect; 777 drive->sect = drive->bios_sect = ide_disks_chs[i].sect;
744 drive->forced_geom = 1; 778
745 printk(KERN_INFO "ide: forcing %s as a disk (%d/%d/%d)\n", 779 printk(KERN_INFO "ide: forcing %s as a disk (%d/%d/%d)\n",
746 drive->name, 780 drive->name,
747 drive->cyl, drive->head, drive->sect); 781 drive->cyl, drive->head, drive->sect);
748 drive->present = 1; 782
783 drive->dev_flags |= IDE_DFLAG_FORCED_GEOM | IDE_DFLAG_PRESENT;
749 drive->media = ide_disk; 784 drive->media = ide_disk;
750 drive->ready_stat = ATA_DRDY; 785 drive->ready_stat = ATA_DRDY;
751 } 786 }
@@ -785,7 +820,7 @@ void ide_port_apply_params(ide_hwif_t *hwif)
785 } 820 }
786 821
787 for (i = 0; i < MAX_DRIVES; i++) 822 for (i = 0; i < MAX_DRIVES; i++)
788 ide_dev_apply_params(&hwif->drives[i]); 823 ide_dev_apply_params(&hwif->drives[i], i);
789} 824}
790 825
791/* 826/*
diff --git a/drivers/ide/legacy/ali14xx.c b/drivers/ide/legacy/ali14xx.c
index 7276c96aaa2a..90da1f953ed0 100644
--- a/drivers/ide/legacy/ali14xx.c
+++ b/drivers/ide/legacy/ali14xx.c
@@ -131,7 +131,7 @@ static void ali14xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
131 drive->name, pio, time1, time2, param1, param2, param3, param4); 131 drive->name, pio, time1, time2, param1, param2, param3, param4);
132 132
133 /* stuff timing parameters into controller registers */ 133 /* stuff timing parameters into controller registers */
134 driveNum = (HWIF(drive)->index << 1) + drive->select.b.unit; 134 driveNum = (drive->hwif->index << 1) + (drive->dn & 1);
135 spin_lock_irqsave(&ali14xx_lock, flags); 135 spin_lock_irqsave(&ali14xx_lock, flags);
136 outb_p(regOn, basePort); 136 outb_p(regOn, basePort);
137 outReg(param1, regTab[driveNum].reg1); 137 outReg(param1, regTab[driveNum].reg1);
diff --git a/drivers/ide/legacy/ht6560b.c b/drivers/ide/legacy/ht6560b.c
index 5123ea291d07..c7e5c2246b79 100644
--- a/drivers/ide/legacy/ht6560b.c
+++ b/drivers/ide/legacy/ht6560b.c
@@ -120,7 +120,8 @@ static void ht6560b_selectproc (ide_drive_t *drive)
120 * Need to enforce prefetch sometimes because otherwise 120 * Need to enforce prefetch sometimes because otherwise
121 * it'll hang (hard). 121 * it'll hang (hard).
122 */ 122 */
123 if (drive->media != ide_disk || !drive->present) 123 if (drive->media != ide_disk ||
124 (drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
124 select |= HT_PREFETCH_MODE; 125 select |= HT_PREFETCH_MODE;
125 126
126 if (select != current_select || timing != current_timing) { 127 if (select != current_select || timing != current_timing) {
@@ -249,11 +250,11 @@ static void ht_set_prefetch(ide_drive_t *drive, u8 state)
249 */ 250 */
250 if (state) { 251 if (state) {
251 drive->drive_data |= t; /* enable prefetch mode */ 252 drive->drive_data |= t; /* enable prefetch mode */
252 drive->no_unmask = 1; 253 drive->dev_flags |= IDE_DFLAG_NO_UNMASK;
253 drive->unmask = 0; 254 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
254 } else { 255 } else {
255 drive->drive_data &= ~t; /* disable prefetch mode */ 256 drive->drive_data &= ~t; /* disable prefetch mode */
256 drive->no_unmask = 0; 257 drive->dev_flags &= ~IDE_DFLAG_NO_UNMASK;
257 } 258 }
258 259
259 spin_unlock_irqrestore(&ht6560b_lock, flags); 260 spin_unlock_irqrestore(&ht6560b_lock, flags);
diff --git a/drivers/ide/legacy/ide-4drives.c b/drivers/ide/legacy/ide-4drives.c
index c76d55de6996..9e85b1ec9607 100644
--- a/drivers/ide/legacy/ide-4drives.c
+++ b/drivers/ide/legacy/ide-4drives.c
@@ -14,7 +14,7 @@ MODULE_PARM_DESC(probe, "probe for generic IDE chipset with 4 drives/port");
14static void ide_4drives_init_dev(ide_drive_t *drive) 14static void ide_4drives_init_dev(ide_drive_t *drive)
15{ 15{
16 if (drive->hwif->channel) 16 if (drive->hwif->channel)
17 drive->select.all ^= 0x20; 17 drive->select ^= 0x20;
18} 18}
19 19
20static const struct ide_port_ops ide_4drives_port_ops = { 20static const struct ide_port_ops ide_4drives_port_ops = {
diff --git a/drivers/ide/legacy/ide-cs.c b/drivers/ide/legacy/ide-cs.c
index ee6fc30d5e2b..cb199c815b53 100644
--- a/drivers/ide/legacy/ide-cs.c
+++ b/drivers/ide/legacy/ide-cs.c
@@ -219,103 +219,91 @@ out_release:
219#define CS_CHECK(fn, ret) \ 219#define CS_CHECK(fn, ret) \
220do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 220do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
221 221
222struct pcmcia_config_check {
223 unsigned long ctl_base;
224 int skip_vcc;
225 int is_kme;
226};
227
228static int pcmcia_check_one_config(struct pcmcia_device *pdev,
229 cistpl_cftable_entry_t *cfg,
230 cistpl_cftable_entry_t *dflt,
231 unsigned int vcc,
232 void *priv_data)
233{
234 struct pcmcia_config_check *stk = priv_data;
235
236 /* Check for matching Vcc, unless we're desperate */
237 if (!stk->skip_vcc) {
238 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
239 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
240 return -ENODEV;
241 } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
242 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] / 10000)
243 return -ENODEV;
244 }
245 }
246
247 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
248 pdev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
249 else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
250 pdev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
251
252 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
253 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
254 pdev->conf.ConfigIndex = cfg->index;
255 pdev->io.BasePort1 = io->win[0].base;
256 pdev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
257 if (!(io->flags & CISTPL_IO_16BIT))
258 pdev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
259 if (io->nwin == 2) {
260 pdev->io.NumPorts1 = 8;
261 pdev->io.BasePort2 = io->win[1].base;
262 pdev->io.NumPorts2 = (stk->is_kme) ? 2 : 1;
263 if (pcmcia_request_io(pdev, &pdev->io) != 0)
264 return -ENODEV;
265 stk->ctl_base = pdev->io.BasePort2;
266 } else if ((io->nwin == 1) && (io->win[0].len >= 16)) {
267 pdev->io.NumPorts1 = io->win[0].len;
268 pdev->io.NumPorts2 = 0;
269 if (pcmcia_request_io(pdev, &pdev->io) != 0)
270 return -ENODEV;
271 stk->ctl_base = pdev->io.BasePort1 + 0x0e;
272 } else
273 return -ENODEV;
274 /* If we've got this far, we're done */
275 return 0;
276 }
277 return -ENODEV;
278}
279
222static int ide_config(struct pcmcia_device *link) 280static int ide_config(struct pcmcia_device *link)
223{ 281{
224 ide_info_t *info = link->priv; 282 ide_info_t *info = link->priv;
225 tuple_t tuple; 283 struct pcmcia_config_check *stk = NULL;
226 struct { 284 int last_ret = 0, last_fn = 0, is_kme = 0;
227 u_short buf[128];
228 cisparse_t parse;
229 config_info_t conf;
230 cistpl_cftable_entry_t dflt;
231 } *stk = NULL;
232 cistpl_cftable_entry_t *cfg;
233 int pass, last_ret = 0, last_fn = 0, is_kme = 0;
234 unsigned long io_base, ctl_base; 285 unsigned long io_base, ctl_base;
235 struct ide_host *host; 286 struct ide_host *host;
236 287
237 DEBUG(0, "ide_config(0x%p)\n", link); 288 DEBUG(0, "ide_config(0x%p)\n", link);
238 289
239 stk = kzalloc(sizeof(*stk), GFP_KERNEL);
240 if (!stk) goto err_mem;
241 cfg = &stk->parse.cftable_entry;
242
243 tuple.TupleData = (cisdata_t *)&stk->buf;
244 tuple.TupleOffset = 0;
245 tuple.TupleDataMax = 255;
246 tuple.Attributes = 0;
247
248 is_kme = ((link->manf_id == MANFID_KME) && 290 is_kme = ((link->manf_id == MANFID_KME) &&
249 ((link->card_id == PRODID_KME_KXLC005_A) || 291 ((link->card_id == PRODID_KME_KXLC005_A) ||
250 (link->card_id == PRODID_KME_KXLC005_B))); 292 (link->card_id == PRODID_KME_KXLC005_B)));
251 293
252 /* Not sure if this is right... look up the current Vcc */ 294 stk = kzalloc(sizeof(*stk), GFP_KERNEL);
253 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &stk->conf)); 295 if (!stk)
254 296 goto err_mem;
255 pass = io_base = ctl_base = 0; 297 stk->is_kme = is_kme;
256 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 298 stk->skip_vcc = io_base = ctl_base = 0;
257 tuple.Attributes = 0; 299
258 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); 300 if (pcmcia_loop_config(link, pcmcia_check_one_config, stk)) {
259 while (1) { 301 stk->skip_vcc = 1;
260 if (pcmcia_get_tuple_data(link, &tuple) != 0) goto next_entry; 302 if (pcmcia_loop_config(link, pcmcia_check_one_config, stk))
261 if (pcmcia_parse_tuple(link, &tuple, &stk->parse) != 0) goto next_entry; 303 goto failed; /* No suitable config found */
262
263 /* Check for matching Vcc, unless we're desperate */
264 if (!pass) {
265 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
266 if (stk->conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
267 goto next_entry;
268 } else if (stk->dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
269 if (stk->conf.Vcc != stk->dflt.vcc.param[CISTPL_POWER_VNOM] / 10000)
270 goto next_entry;
271 }
272 }
273
274 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
275 link->conf.Vpp =
276 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
277 else if (stk->dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
278 link->conf.Vpp =
279 stk->dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
280
281 if ((cfg->io.nwin > 0) || (stk->dflt.io.nwin > 0)) {
282 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &stk->dflt.io;
283 link->conf.ConfigIndex = cfg->index;
284 link->io.BasePort1 = io->win[0].base;
285 link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
286 if (!(io->flags & CISTPL_IO_16BIT))
287 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
288 if (io->nwin == 2) {
289 link->io.NumPorts1 = 8;
290 link->io.BasePort2 = io->win[1].base;
291 link->io.NumPorts2 = (is_kme) ? 2 : 1;
292 if (pcmcia_request_io(link, &link->io) != 0)
293 goto next_entry;
294 io_base = link->io.BasePort1;
295 ctl_base = link->io.BasePort2;
296 } else if ((io->nwin == 1) && (io->win[0].len >= 16)) {
297 link->io.NumPorts1 = io->win[0].len;
298 link->io.NumPorts2 = 0;
299 if (pcmcia_request_io(link, &link->io) != 0)
300 goto next_entry;
301 io_base = link->io.BasePort1;
302 ctl_base = link->io.BasePort1 + 0x0e;
303 } else goto next_entry;
304 /* If we've got this far, we're done */
305 break;
306 }
307
308 next_entry:
309 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
310 memcpy(&stk->dflt, cfg, sizeof(stk->dflt));
311 if (pass) {
312 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
313 } else if (pcmcia_get_next_tuple(link, &tuple) != 0) {
314 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
315 memset(&stk->dflt, 0, sizeof(stk->dflt));
316 pass++;
317 }
318 } 304 }
305 io_base = link->io.BasePort1;
306 ctl_base = stk->ctl_base;
319 307
320 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 308 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
321 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); 309 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
@@ -403,8 +391,10 @@ static struct pcmcia_device_id ide_ids[] = {
403 PCMCIA_DEVICE_MANF_CARD(0x000a, 0x0000), /* I-O Data CFA */ 391 PCMCIA_DEVICE_MANF_CARD(0x000a, 0x0000), /* I-O Data CFA */
404 PCMCIA_DEVICE_MANF_CARD(0x001c, 0x0001), /* Mitsubishi CFA */ 392 PCMCIA_DEVICE_MANF_CARD(0x001c, 0x0001), /* Mitsubishi CFA */
405 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704), 393 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704),
394 PCMCIA_DEVICE_MANF_CARD(0x0032, 0x2904),
406 PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401), /* SanDisk CFA */ 395 PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401), /* SanDisk CFA */
407 PCMCIA_DEVICE_MANF_CARD(0x004f, 0x0000), /* Kingston */ 396 PCMCIA_DEVICE_MANF_CARD(0x004f, 0x0000), /* Kingston */
397 PCMCIA_DEVICE_MANF_CARD(0x0097, 0x1620), /* TI emulated */
408 PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000), /* Toshiba */ 398 PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000), /* Toshiba */
409 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d), 399 PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d),
410 PCMCIA_DEVICE_MANF_CARD(0x00ce, 0x0000), /* Samsung */ 400 PCMCIA_DEVICE_MANF_CARD(0x00ce, 0x0000), /* Samsung */
diff --git a/drivers/ide/legacy/qd65xx.c b/drivers/ide/legacy/qd65xx.c
index ec408b3a7100..bc27c7aba936 100644
--- a/drivers/ide/legacy/qd65xx.c
+++ b/drivers/ide/legacy/qd65xx.c
@@ -305,7 +305,7 @@ static void __init qd6580_init_dev(ide_drive_t *drive)
305 } else 305 } else
306 t2 = t1 = hwif->channel ? QD6580_DEF_DATA2 : QD6580_DEF_DATA; 306 t2 = t1 = hwif->channel ? QD6580_DEF_DATA2 : QD6580_DEF_DATA;
307 307
308 drive->drive_data = drive->select.b.unit ? t2 : t1; 308 drive->drive_data = (drive->dn & 1) ? t2 : t1;
309} 309}
310 310
311static const struct ide_port_ops qd6500_port_ops = { 311static const struct ide_port_ops qd6500_port_ops = {
diff --git a/drivers/ide/mips/au1xxx-ide.c b/drivers/ide/mips/au1xxx-ide.c
index 11b7f61aae40..0ec8fd1e4dcb 100644
--- a/drivers/ide/mips/au1xxx-ide.c
+++ b/drivers/ide/mips/au1xxx-ide.c
@@ -322,11 +322,7 @@ static int auide_dma_setup(ide_drive_t *drive)
322} 322}
323 323
324static int auide_dma_test_irq(ide_drive_t *drive) 324static int auide_dma_test_irq(ide_drive_t *drive)
325{ 325{
326 if (drive->waiting_for_dma == 0)
327 printk(KERN_WARNING "%s: ide_dma_test_irq \
328 called while not waiting\n", drive->name);
329
330 /* If dbdma didn't execute the STOP command yet, the 326 /* If dbdma didn't execute the STOP command yet, the
331 * active bit is still set 327 * active bit is still set
332 */ 328 */
@@ -344,11 +340,6 @@ static void auide_dma_host_set(ide_drive_t *drive, int on)
344{ 340{
345} 341}
346 342
347static void auide_dma_lost_irq(ide_drive_t *drive)
348{
349 printk(KERN_ERR "%s: IRQ lost\n", drive->name);
350}
351
352static void auide_ddma_tx_callback(int irq, void *param) 343static void auide_ddma_tx_callback(int irq, void *param)
353{ 344{
354 _auide_hwif *ahwif = (_auide_hwif*)param; 345 _auide_hwif *ahwif = (_auide_hwif*)param;
@@ -375,18 +366,6 @@ static void auide_init_dbdma_dev(dbdev_tab_t *dev, u32 dev_id, u32 tsize, u32 de
375} 366}
376 367
377#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA 368#ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
378static void auide_dma_timeout(ide_drive_t *drive)
379{
380 ide_hwif_t *hwif = HWIF(drive);
381
382 printk(KERN_ERR "%s: DMA timeout occurred: ", drive->name);
383
384 if (auide_dma_test_irq(drive))
385 return;
386
387 auide_dma_end(drive);
388}
389
390static const struct ide_dma_ops au1xxx_dma_ops = { 369static const struct ide_dma_ops au1xxx_dma_ops = {
391 .dma_host_set = auide_dma_host_set, 370 .dma_host_set = auide_dma_host_set,
392 .dma_setup = auide_dma_setup, 371 .dma_setup = auide_dma_setup,
@@ -394,8 +373,8 @@ static const struct ide_dma_ops au1xxx_dma_ops = {
394 .dma_start = auide_dma_start, 373 .dma_start = auide_dma_start,
395 .dma_end = auide_dma_end, 374 .dma_end = auide_dma_end,
396 .dma_test_irq = auide_dma_test_irq, 375 .dma_test_irq = auide_dma_test_irq,
397 .dma_lost_irq = auide_dma_lost_irq, 376 .dma_lost_irq = ide_dma_lost_irq,
398 .dma_timeout = auide_dma_timeout, 377 .dma_timeout = ide_dma_timeout,
399}; 378};
400 379
401static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d) 380static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
@@ -448,10 +427,9 @@ static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
448 NUM_DESCRIPTORS); 427 NUM_DESCRIPTORS);
449 auide->rx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->rx_chan, 428 auide->rx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->rx_chan,
450 NUM_DESCRIPTORS); 429 NUM_DESCRIPTORS);
451 430
452 hwif->dmatable_cpu = dma_alloc_coherent(hwif->dev, 431 /* FIXME: check return value */
453 PRD_ENTRIES * PRD_BYTES, /* 1 Page */ 432 (void)ide_allocate_dma_engine(hwif);
454 &hwif->dmatable_dma, GFP_KERNEL);
455 433
456 au1xxx_dbdma_start( auide->tx_chan ); 434 au1xxx_dbdma_start( auide->tx_chan );
457 au1xxx_dbdma_start( auide->rx_chan ); 435 au1xxx_dbdma_start( auide->rx_chan );
diff --git a/drivers/ide/pci/aec62xx.c b/drivers/ide/pci/aec62xx.c
index e7475ba559c7..4142c698e0d3 100644
--- a/drivers/ide/pci/aec62xx.c
+++ b/drivers/ide/pci/aec62xx.c
@@ -115,7 +115,7 @@ static void aec6260_set_mode(ide_drive_t *drive, const u8 speed)
115 struct pci_dev *dev = to_pci_dev(hwif->dev); 115 struct pci_dev *dev = to_pci_dev(hwif->dev);
116 struct ide_host *host = pci_get_drvdata(dev); 116 struct ide_host *host = pci_get_drvdata(dev);
117 struct chipset_bus_clock_list_entry *bus_clock = host->host_priv; 117 struct chipset_bus_clock_list_entry *bus_clock = host->host_priv;
118 u8 unit = (drive->select.b.unit & 0x01); 118 u8 unit = drive->dn & 1;
119 u8 tmp1 = 0, tmp2 = 0; 119 u8 tmp1 = 0, tmp2 = 0;
120 u8 ultra = 0, drive_conf = 0, ultra_conf = 0; 120 u8 ultra = 0, drive_conf = 0, ultra_conf = 0;
121 unsigned long flags; 121 unsigned long flags;
@@ -302,7 +302,7 @@ static const struct pci_device_id aec62xx_pci_tbl[] = {
302}; 302};
303MODULE_DEVICE_TABLE(pci, aec62xx_pci_tbl); 303MODULE_DEVICE_TABLE(pci, aec62xx_pci_tbl);
304 304
305static struct pci_driver driver = { 305static struct pci_driver aec62xx_pci_driver = {
306 .name = "AEC62xx_IDE", 306 .name = "AEC62xx_IDE",
307 .id_table = aec62xx_pci_tbl, 307 .id_table = aec62xx_pci_tbl,
308 .probe = aec62xx_init_one, 308 .probe = aec62xx_init_one,
@@ -313,12 +313,12 @@ static struct pci_driver driver = {
313 313
314static int __init aec62xx_ide_init(void) 314static int __init aec62xx_ide_init(void)
315{ 315{
316 return ide_pci_register_driver(&driver); 316 return ide_pci_register_driver(&aec62xx_pci_driver);
317} 317}
318 318
319static void __exit aec62xx_ide_exit(void) 319static void __exit aec62xx_ide_exit(void)
320{ 320{
321 pci_unregister_driver(&driver); 321 pci_unregister_driver(&aec62xx_pci_driver);
322} 322}
323 323
324module_init(aec62xx_ide_init); 324module_init(aec62xx_ide_init);
diff --git a/drivers/ide/pci/alim15x3.c b/drivers/ide/pci/alim15x3.c
index 053c75263918..daf9dce39e52 100644
--- a/drivers/ide/pci/alim15x3.c
+++ b/drivers/ide/pci/alim15x3.c
@@ -77,8 +77,7 @@ static void ali_set_pio_mode(ide_drive_t *drive, const u8 pio)
77 int bus_speed = ide_pci_clk ? ide_pci_clk : 33; 77 int bus_speed = ide_pci_clk ? ide_pci_clk : 33;
78 int port = hwif->channel ? 0x5c : 0x58; 78 int port = hwif->channel ? 0x5c : 0x58;
79 int portFIFO = hwif->channel ? 0x55 : 0x54; 79 int portFIFO = hwif->channel ? 0x55 : 0x54;
80 u8 cd_dma_fifo = 0; 80 u8 cd_dma_fifo = 0, unit = drive->dn & 1;
81 int unit = drive->select.b.unit & 1;
82 81
83 if ((s_clc = (s_time * bus_speed + 999) / 1000) >= 8) 82 if ((s_clc = (s_time * bus_speed + 999) / 1000) >= 8)
84 s_clc = 0; 83 s_clc = 0;
@@ -112,7 +111,7 @@ static void ali_set_pio_mode(ide_drive_t *drive, const u8 pio)
112 } 111 }
113 112
114 pci_write_config_byte(dev, port, s_clc); 113 pci_write_config_byte(dev, port, s_clc);
115 pci_write_config_byte(dev, port+drive->select.b.unit+2, (a_clc << 4) | r_clc); 114 pci_write_config_byte(dev, port + unit + 2, (a_clc << 4) | r_clc);
116 local_irq_restore(flags); 115 local_irq_restore(flags);
117} 116}
118 117
@@ -154,7 +153,7 @@ static void ali_set_dma_mode(ide_drive_t *drive, const u8 speed)
154 ide_hwif_t *hwif = HWIF(drive); 153 ide_hwif_t *hwif = HWIF(drive);
155 struct pci_dev *dev = to_pci_dev(hwif->dev); 154 struct pci_dev *dev = to_pci_dev(hwif->dev);
156 u8 speed1 = speed; 155 u8 speed1 = speed;
157 u8 unit = (drive->select.b.unit & 0x01); 156 u8 unit = drive->dn & 1;
158 u8 tmpbyte = 0x00; 157 u8 tmpbyte = 0x00;
159 int m5229_udma = (hwif->channel) ? 0x57 : 0x56; 158 int m5229_udma = (hwif->channel) ? 0x57 : 0x56;
160 159
@@ -508,7 +507,7 @@ static const struct ide_dma_ops ali_dma_ops = {
508 .dma_setup = ali15x3_dma_setup, 507 .dma_setup = ali15x3_dma_setup,
509 .dma_exec_cmd = ide_dma_exec_cmd, 508 .dma_exec_cmd = ide_dma_exec_cmd,
510 .dma_start = ide_dma_start, 509 .dma_start = ide_dma_start,
511 .dma_end = __ide_dma_end, 510 .dma_end = ide_dma_end,
512 .dma_test_irq = ide_dma_test_irq, 511 .dma_test_irq = ide_dma_test_irq,
513 .dma_lost_irq = ide_dma_lost_irq, 512 .dma_lost_irq = ide_dma_lost_irq,
514 .dma_timeout = ide_dma_timeout, 513 .dma_timeout = ide_dma_timeout,
@@ -576,7 +575,7 @@ static const struct pci_device_id alim15x3_pci_tbl[] = {
576}; 575};
577MODULE_DEVICE_TABLE(pci, alim15x3_pci_tbl); 576MODULE_DEVICE_TABLE(pci, alim15x3_pci_tbl);
578 577
579static struct pci_driver driver = { 578static struct pci_driver alim15x3_pci_driver = {
580 .name = "ALI15x3_IDE", 579 .name = "ALI15x3_IDE",
581 .id_table = alim15x3_pci_tbl, 580 .id_table = alim15x3_pci_tbl,
582 .probe = alim15x3_init_one, 581 .probe = alim15x3_init_one,
@@ -587,12 +586,12 @@ static struct pci_driver driver = {
587 586
588static int __init ali15x3_ide_init(void) 587static int __init ali15x3_ide_init(void)
589{ 588{
590 return ide_pci_register_driver(&driver); 589 return ide_pci_register_driver(&alim15x3_pci_driver);
591} 590}
592 591
593static void __exit ali15x3_ide_exit(void) 592static void __exit ali15x3_ide_exit(void)
594{ 593{
595 return pci_unregister_driver(&driver); 594 return pci_unregister_driver(&alim15x3_pci_driver);
596} 595}
597 596
598module_init(ali15x3_ide_init); 597module_init(ali15x3_ide_init);
diff --git a/drivers/ide/pci/amd74xx.c b/drivers/ide/pci/amd74xx.c
index 824471f91bf5..81ec73134eda 100644
--- a/drivers/ide/pci/amd74xx.c
+++ b/drivers/ide/pci/amd74xx.c
@@ -92,7 +92,7 @@ static void amd_set_drive(ide_drive_t *drive, const u8 speed)
92 92
93 ide_timing_compute(drive, speed, &t, T, UT); 93 ide_timing_compute(drive, speed, &t, T, UT);
94 94
95 if (peer->present) { 95 if (peer->dev_flags & IDE_DFLAG_PRESENT) {
96 ide_timing_compute(peer, peer->current_speed, &p, T, UT); 96 ide_timing_compute(peer, peer->current_speed, &p, T, UT);
97 ide_timing_merge(&p, &t, &t, IDE_TIMING_8BIT); 97 ide_timing_merge(&p, &t, &t, IDE_TIMING_8BIT);
98 } 98 }
@@ -319,7 +319,7 @@ static const struct pci_device_id amd74xx_pci_tbl[] = {
319}; 319};
320MODULE_DEVICE_TABLE(pci, amd74xx_pci_tbl); 320MODULE_DEVICE_TABLE(pci, amd74xx_pci_tbl);
321 321
322static struct pci_driver driver = { 322static struct pci_driver amd74xx_pci_driver = {
323 .name = "AMD_IDE", 323 .name = "AMD_IDE",
324 .id_table = amd74xx_pci_tbl, 324 .id_table = amd74xx_pci_tbl,
325 .probe = amd74xx_probe, 325 .probe = amd74xx_probe,
@@ -330,12 +330,12 @@ static struct pci_driver driver = {
330 330
331static int __init amd74xx_ide_init(void) 331static int __init amd74xx_ide_init(void)
332{ 332{
333 return ide_pci_register_driver(&driver); 333 return ide_pci_register_driver(&amd74xx_pci_driver);
334} 334}
335 335
336static void __exit amd74xx_ide_exit(void) 336static void __exit amd74xx_ide_exit(void)
337{ 337{
338 pci_unregister_driver(&driver); 338 pci_unregister_driver(&amd74xx_pci_driver);
339} 339}
340 340
341module_init(amd74xx_ide_init); 341module_init(amd74xx_ide_init);
diff --git a/drivers/ide/pci/atiixp.c b/drivers/ide/pci/atiixp.c
index e4437034dd08..b2735d28f5cc 100644
--- a/drivers/ide/pci/atiixp.c
+++ b/drivers/ide/pci/atiixp.c
@@ -182,7 +182,7 @@ static const struct pci_device_id atiixp_pci_tbl[] = {
182}; 182};
183MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl); 183MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl);
184 184
185static struct pci_driver driver = { 185static struct pci_driver atiixp_pci_driver = {
186 .name = "ATIIXP_IDE", 186 .name = "ATIIXP_IDE",
187 .id_table = atiixp_pci_tbl, 187 .id_table = atiixp_pci_tbl,
188 .probe = atiixp_init_one, 188 .probe = atiixp_init_one,
@@ -193,12 +193,12 @@ static struct pci_driver driver = {
193 193
194static int __init atiixp_ide_init(void) 194static int __init atiixp_ide_init(void)
195{ 195{
196 return ide_pci_register_driver(&driver); 196 return ide_pci_register_driver(&atiixp_pci_driver);
197} 197}
198 198
199static void __exit atiixp_ide_exit(void) 199static void __exit atiixp_ide_exit(void)
200{ 200{
201 pci_unregister_driver(&driver); 201 pci_unregister_driver(&atiixp_pci_driver);
202} 202}
203 203
204module_init(atiixp_ide_init); 204module_init(atiixp_ide_init);
diff --git a/drivers/ide/pci/cmd640.c b/drivers/ide/pci/cmd640.c
index 7f39cdb41410..e4306647d00d 100644
--- a/drivers/ide/pci/cmd640.c
+++ b/drivers/ide/pci/cmd640.c
@@ -378,13 +378,13 @@ static void __set_prefetch_mode(ide_drive_t *drive, int mode)
378{ 378{
379 if (mode) { /* want prefetch on? */ 379 if (mode) { /* want prefetch on? */
380#if CMD640_PREFETCH_MASKS 380#if CMD640_PREFETCH_MASKS
381 drive->no_unmask = 1; 381 drive->dev_flags |= IDE_DFLAG_NO_UNMASK;
382 drive->unmask = 0; 382 drive->dev_flags &= ~IDE_DFLAG_UNMASK;
383#endif 383#endif
384 drive->no_io_32bit = 0; 384 drive->dev_flags &= ~IDE_DFLAG_NO_IO_32BIT;
385 } else { 385 } else {
386 drive->no_unmask = 0; 386 drive->dev_flags &= ~IDE_DFLAG_NO_UNMASK;
387 drive->no_io_32bit = 1; 387 drive->dev_flags |= IDE_DFLAG_NO_IO_32BIT;
388 drive->io_32bit = 0; 388 drive->io_32bit = 0;
389 } 389 }
390} 390}
@@ -468,10 +468,10 @@ static void program_drive_counts(ide_drive_t *drive, unsigned int index)
468 */ 468 */
469 if (index > 1) { 469 if (index > 1) {
470 ide_hwif_t *hwif = drive->hwif; 470 ide_hwif_t *hwif = drive->hwif;
471 ide_drive_t *peer = &hwif->drives[!drive->select.b.unit]; 471 ide_drive_t *peer = &hwif->drives[!(drive->dn & 1)];
472 unsigned int mate = index ^ 1; 472 unsigned int mate = index ^ 1;
473 473
474 if (peer->present) { 474 if (peer->dev_flags & IDE_DFLAG_PRESENT) {
475 if (setup_count < setup_counts[mate]) 475 if (setup_count < setup_counts[mate])
476 setup_count = setup_counts[mate]; 476 setup_count = setup_counts[mate];
477 if (active_count < active_counts[mate]) 477 if (active_count < active_counts[mate])
@@ -607,7 +607,7 @@ static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio)
607 607
608static void cmd640_init_dev(ide_drive_t *drive) 608static void cmd640_init_dev(ide_drive_t *drive)
609{ 609{
610 unsigned int i = drive->hwif->channel * 2 + drive->select.b.unit; 610 unsigned int i = drive->hwif->channel * 2 + (drive->dn & 1);
611 611
612#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED 612#ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
613 /* 613 /*
@@ -626,7 +626,7 @@ static void cmd640_init_dev(ide_drive_t *drive)
626 */ 626 */
627 check_prefetch(drive, i); 627 check_prefetch(drive, i);
628 printk(KERN_INFO DRV_NAME ": drive%d timings/prefetch(%s) preserved\n", 628 printk(KERN_INFO DRV_NAME ": drive%d timings/prefetch(%s) preserved\n",
629 i, drive->no_io_32bit ? "off" : "on"); 629 i, (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT) ? "off" : "on");
630#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */ 630#endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */
631} 631}
632 632
diff --git a/drivers/ide/pci/cmd64x.c b/drivers/ide/pci/cmd64x.c
index 456dee18b660..935385c77e06 100644
--- a/drivers/ide/pci/cmd64x.c
+++ b/drivers/ide/pci/cmd64x.c
@@ -228,7 +228,7 @@ static int cmd648_dma_end(ide_drive_t *drive)
228{ 228{
229 ide_hwif_t *hwif = HWIF(drive); 229 ide_hwif_t *hwif = HWIF(drive);
230 unsigned long base = hwif->dma_base - (hwif->channel * 8); 230 unsigned long base = hwif->dma_base - (hwif->channel * 8);
231 int err = __ide_dma_end(drive); 231 int err = ide_dma_end(drive);
232 u8 irq_mask = hwif->channel ? MRDMODE_INTR_CH1 : 232 u8 irq_mask = hwif->channel ? MRDMODE_INTR_CH1 :
233 MRDMODE_INTR_CH0; 233 MRDMODE_INTR_CH0;
234 u8 mrdmode = inb(base + 1); 234 u8 mrdmode = inb(base + 1);
@@ -248,7 +248,7 @@ static int cmd64x_dma_end(ide_drive_t *drive)
248 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 : 248 u8 irq_mask = hwif->channel ? ARTTIM23_INTR_CH1 :
249 CFR_INTR_CH0; 249 CFR_INTR_CH0;
250 u8 irq_stat = 0; 250 u8 irq_stat = 0;
251 int err = __ide_dma_end(drive); 251 int err = ide_dma_end(drive);
252 252
253 (void) pci_read_config_byte(dev, irq_reg, &irq_stat); 253 (void) pci_read_config_byte(dev, irq_reg, &irq_stat);
254 /* clear the interrupt bit */ 254 /* clear the interrupt bit */
@@ -505,7 +505,7 @@ static const struct pci_device_id cmd64x_pci_tbl[] = {
505}; 505};
506MODULE_DEVICE_TABLE(pci, cmd64x_pci_tbl); 506MODULE_DEVICE_TABLE(pci, cmd64x_pci_tbl);
507 507
508static struct pci_driver driver = { 508static struct pci_driver cmd64x_pci_driver = {
509 .name = "CMD64x_IDE", 509 .name = "CMD64x_IDE",
510 .id_table = cmd64x_pci_tbl, 510 .id_table = cmd64x_pci_tbl,
511 .probe = cmd64x_init_one, 511 .probe = cmd64x_init_one,
@@ -516,12 +516,12 @@ static struct pci_driver driver = {
516 516
517static int __init cmd64x_ide_init(void) 517static int __init cmd64x_ide_init(void)
518{ 518{
519 return ide_pci_register_driver(&driver); 519 return ide_pci_register_driver(&cmd64x_pci_driver);
520} 520}
521 521
522static void __exit cmd64x_ide_exit(void) 522static void __exit cmd64x_ide_exit(void)
523{ 523{
524 pci_unregister_driver(&driver); 524 pci_unregister_driver(&cmd64x_pci_driver);
525} 525}
526 526
527module_init(cmd64x_ide_init); 527module_init(cmd64x_ide_init);
diff --git a/drivers/ide/pci/cs5520.c b/drivers/ide/pci/cs5520.c
index d6341f7c4144..5efb467f8fa0 100644
--- a/drivers/ide/pci/cs5520.c
+++ b/drivers/ide/pci/cs5520.c
@@ -145,7 +145,7 @@ static const struct pci_device_id cs5520_pci_tbl[] = {
145}; 145};
146MODULE_DEVICE_TABLE(pci, cs5520_pci_tbl); 146MODULE_DEVICE_TABLE(pci, cs5520_pci_tbl);
147 147
148static struct pci_driver driver = { 148static struct pci_driver cs5520_pci_driver = {
149 .name = "Cyrix_IDE", 149 .name = "Cyrix_IDE",
150 .id_table = cs5520_pci_tbl, 150 .id_table = cs5520_pci_tbl,
151 .probe = cs5520_init_one, 151 .probe = cs5520_init_one,
@@ -155,7 +155,7 @@ static struct pci_driver driver = {
155 155
156static int __init cs5520_ide_init(void) 156static int __init cs5520_ide_init(void)
157{ 157{
158 return ide_pci_register_driver(&driver); 158 return ide_pci_register_driver(&cs5520_pci_driver);
159} 159}
160 160
161module_init(cs5520_ide_init); 161module_init(cs5520_ide_init);
diff --git a/drivers/ide/pci/cs5530.c b/drivers/ide/pci/cs5530.c
index da42fa7e9f97..53f079cc00af 100644
--- a/drivers/ide/pci/cs5530.c
+++ b/drivers/ide/pci/cs5530.c
@@ -267,7 +267,7 @@ static const struct pci_device_id cs5530_pci_tbl[] = {
267}; 267};
268MODULE_DEVICE_TABLE(pci, cs5530_pci_tbl); 268MODULE_DEVICE_TABLE(pci, cs5530_pci_tbl);
269 269
270static struct pci_driver driver = { 270static struct pci_driver cs5530_pci_driver = {
271 .name = "CS5530 IDE", 271 .name = "CS5530 IDE",
272 .id_table = cs5530_pci_tbl, 272 .id_table = cs5530_pci_tbl,
273 .probe = cs5530_init_one, 273 .probe = cs5530_init_one,
@@ -278,12 +278,12 @@ static struct pci_driver driver = {
278 278
279static int __init cs5530_ide_init(void) 279static int __init cs5530_ide_init(void)
280{ 280{
281 return ide_pci_register_driver(&driver); 281 return ide_pci_register_driver(&cs5530_pci_driver);
282} 282}
283 283
284static void __exit cs5530_ide_exit(void) 284static void __exit cs5530_ide_exit(void)
285{ 285{
286 pci_unregister_driver(&driver); 286 pci_unregister_driver(&cs5530_pci_driver);
287} 287}
288 288
289module_init(cs5530_ide_init); 289module_init(cs5530_ide_init);
diff --git a/drivers/ide/pci/cs5535.c b/drivers/ide/pci/cs5535.c
index 1e5bc59ea2fb..983d957a0189 100644
--- a/drivers/ide/pci/cs5535.c
+++ b/drivers/ide/pci/cs5535.c
@@ -76,7 +76,7 @@ static unsigned int cs5535_udma_timings[5] =
76static void cs5535_set_speed(ide_drive_t *drive, const u8 speed) 76static void cs5535_set_speed(ide_drive_t *drive, const u8 speed)
77{ 77{
78 u32 reg = 0, dummy; 78 u32 reg = 0, dummy;
79 int unit = drive->select.b.unit; 79 u8 unit = drive->dn & 1;
80 80
81 /* Set the PIO timings */ 81 /* Set the PIO timings */
82 if (speed < XFER_SW_DMA_0) { 82 if (speed < XFER_SW_DMA_0) {
@@ -192,7 +192,7 @@ static const struct pci_device_id cs5535_pci_tbl[] = {
192 192
193MODULE_DEVICE_TABLE(pci, cs5535_pci_tbl); 193MODULE_DEVICE_TABLE(pci, cs5535_pci_tbl);
194 194
195static struct pci_driver driver = { 195static struct pci_driver cs5535_pci_driver = {
196 .name = "CS5535_IDE", 196 .name = "CS5535_IDE",
197 .id_table = cs5535_pci_tbl, 197 .id_table = cs5535_pci_tbl,
198 .probe = cs5535_init_one, 198 .probe = cs5535_init_one,
@@ -203,12 +203,12 @@ static struct pci_driver driver = {
203 203
204static int __init cs5535_ide_init(void) 204static int __init cs5535_ide_init(void)
205{ 205{
206 return ide_pci_register_driver(&driver); 206 return ide_pci_register_driver(&cs5535_pci_driver);
207} 207}
208 208
209static void __exit cs5535_ide_exit(void) 209static void __exit cs5535_ide_exit(void)
210{ 210{
211 pci_unregister_driver(&driver); 211 pci_unregister_driver(&cs5535_pci_driver);
212} 212}
213 213
214module_init(cs5535_ide_init); 214module_init(cs5535_ide_init);
diff --git a/drivers/ide/pci/cy82c693.c b/drivers/ide/pci/cy82c693.c
index 69820e9224d1..5297f07d2933 100644
--- a/drivers/ide/pci/cy82c693.c
+++ b/drivers/ide/pci/cy82c693.c
@@ -50,18 +50,11 @@
50 50
51#define DRV_NAME "cy82c693" 51#define DRV_NAME "cy82c693"
52 52
53/* the current version */
54#define CY82_VERSION "CY82C693U driver v0.34 99-13-12 Andreas S. Krebs (akrebs@altavista.net)"
55
56/* 53/*
57 * The following are used to debug the driver. 54 * The following are used to debug the driver.
58 */ 55 */
59#define CY82C693_DEBUG_LOGS 0
60#define CY82C693_DEBUG_INFO 0 56#define CY82C693_DEBUG_INFO 0
61 57
62/* define CY82C693_SETDMA_CLOCK to set DMA Controller Clock Speed to ATCLK */
63#undef CY82C693_SETDMA_CLOCK
64
65/* 58/*
66 * NOTE: the value for busmaster timeout is tricky and I got it by 59 * NOTE: the value for busmaster timeout is tricky and I got it by
67 * trial and error! By using a to low value will cause DMA timeouts 60 * trial and error! By using a to low value will cause DMA timeouts
@@ -89,7 +82,6 @@
89#define CY82_INDEX_PORT 0x22 82#define CY82_INDEX_PORT 0x22
90#define CY82_DATA_PORT 0x23 83#define CY82_DATA_PORT 0x23
91 84
92#define CY82_INDEX_CTRLREG1 0x01
93#define CY82_INDEX_CHANNEL0 0x30 85#define CY82_INDEX_CHANNEL0 0x30
94#define CY82_INDEX_CHANNEL1 0x31 86#define CY82_INDEX_CHANNEL1 0x31
95#define CY82_INDEX_TIMEOUT 0x32 87#define CY82_INDEX_TIMEOUT 0x32
@@ -179,17 +171,6 @@ static void cy82c693_set_dma_mode(ide_drive_t *drive, const u8 mode)
179 171
180 index = hwif->channel ? CY82_INDEX_CHANNEL1 : CY82_INDEX_CHANNEL0; 172 index = hwif->channel ? CY82_INDEX_CHANNEL1 : CY82_INDEX_CHANNEL0;
181 173
182#if CY82C693_DEBUG_LOGS
183 /* for debug let's show the previous values */
184
185 outb(index, CY82_INDEX_PORT);
186 data = inb(CY82_DATA_PORT);
187
188 printk(KERN_INFO "%s (ch=%d, dev=%d): DMA mode is %d (single=%d)\n",
189 drive->name, HWIF(drive)->channel, drive->select.b.unit,
190 (data&0x3), ((data>>2)&1));
191#endif /* CY82C693_DEBUG_LOGS */
192
193 data = (mode & 3) | (single << 2); 174 data = (mode & 3) | (single << 2);
194 175
195 outb(index, CY82_INDEX_PORT); 176 outb(index, CY82_INDEX_PORT);
@@ -197,8 +178,7 @@ static void cy82c693_set_dma_mode(ide_drive_t *drive, const u8 mode)
197 178
198#if CY82C693_DEBUG_INFO 179#if CY82C693_DEBUG_INFO
199 printk(KERN_INFO "%s (ch=%d, dev=%d): set DMA mode to %d (single=%d)\n", 180 printk(KERN_INFO "%s (ch=%d, dev=%d): set DMA mode to %d (single=%d)\n",
200 drive->name, HWIF(drive)->channel, drive->select.b.unit, 181 drive->name, hwif->channel, drive->dn & 1, mode & 3, single);
201 mode & 3, single);
202#endif /* CY82C693_DEBUG_INFO */ 182#endif /* CY82C693_DEBUG_INFO */
203 183
204 /* 184 /*
@@ -239,50 +219,11 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
239 } 219 }
240 } 220 }
241 221
242#if CY82C693_DEBUG_LOGS
243 /* for debug let's show the register values */
244
245 if (drive->select.b.unit == 0) {
246 /*
247 * get master drive registers
248 * address setup control register
249 * is 32 bit !!!
250 */
251 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl);
252 addrCtrl &= 0x0F;
253
254 /* now let's get the remaining registers */
255 pci_read_config_byte(dev, CY82_IDE_MASTER_IOR, &pclk.time_16r);
256 pci_read_config_byte(dev, CY82_IDE_MASTER_IOW, &pclk.time_16w);
257 pci_read_config_byte(dev, CY82_IDE_MASTER_8BIT, &pclk.time_8);
258 } else {
259 /*
260 * set slave drive registers
261 * address setup control register
262 * is 32 bit !!!
263 */
264 pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl);
265
266 addrCtrl &= 0xF0;
267 addrCtrl >>= 4;
268
269 /* now let's get the remaining registers */
270 pci_read_config_byte(dev, CY82_IDE_SLAVE_IOR, &pclk.time_16r);
271 pci_read_config_byte(dev, CY82_IDE_SLAVE_IOW, &pclk.time_16w);
272 pci_read_config_byte(dev, CY82_IDE_SLAVE_8BIT, &pclk.time_8);
273 }
274
275 printk(KERN_INFO "%s (ch=%d, dev=%d): PIO timing is "
276 "(addr=0x%X, ior=0x%X, iow=0x%X, 8bit=0x%X)\n",
277 drive->name, hwif->channel, drive->select.b.unit,
278 addrCtrl, pclk.time_16r, pclk.time_16w, pclk.time_8);
279#endif /* CY82C693_DEBUG_LOGS */
280
281 /* let's calc the values for this PIO mode */ 222 /* let's calc the values for this PIO mode */
282 compute_clocks(pio, &pclk); 223 compute_clocks(pio, &pclk);
283 224
284 /* now let's write the clocks registers */ 225 /* now let's write the clocks registers */
285 if (drive->select.b.unit == 0) { 226 if ((drive->dn & 1) == 0) {
286 /* 227 /*
287 * set master drive 228 * set master drive
288 * address setup control register 229 * address setup control register
@@ -324,63 +265,11 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
324#if CY82C693_DEBUG_INFO 265#if CY82C693_DEBUG_INFO
325 printk(KERN_INFO "%s (ch=%d, dev=%d): set PIO timing to " 266 printk(KERN_INFO "%s (ch=%d, dev=%d): set PIO timing to "
326 "(addr=0x%X, ior=0x%X, iow=0x%X, 8bit=0x%X)\n", 267 "(addr=0x%X, ior=0x%X, iow=0x%X, 8bit=0x%X)\n",
327 drive->name, hwif->channel, drive->select.b.unit, 268 drive->name, hwif->channel, drive->dn & 1,
328 addrCtrl, pclk.time_16r, pclk.time_16w, pclk.time_8); 269 addrCtrl, pclk.time_16r, pclk.time_16w, pclk.time_8);
329#endif /* CY82C693_DEBUG_INFO */ 270#endif /* CY82C693_DEBUG_INFO */
330} 271}
331 272
332/*
333 * this function is called during init and is used to setup the cy82c693 chip
334 */
335static unsigned int init_chipset_cy82c693(struct pci_dev *dev)
336{
337 if (PCI_FUNC(dev->devfn) != 1)
338 return 0;
339
340#ifdef CY82C693_SETDMA_CLOCK
341 u8 data = 0;
342#endif /* CY82C693_SETDMA_CLOCK */
343
344 /* write info about this verion of the driver */
345 printk(KERN_INFO CY82_VERSION "\n");
346
347#ifdef CY82C693_SETDMA_CLOCK
348 /* okay let's set the DMA clock speed */
349
350 outb(CY82_INDEX_CTRLREG1, CY82_INDEX_PORT);
351 data = inb(CY82_DATA_PORT);
352
353#if CY82C693_DEBUG_INFO
354 printk(KERN_INFO DRV_NAME ": Peripheral Configuration Register: 0x%X\n",
355 data);
356#endif /* CY82C693_DEBUG_INFO */
357
358 /*
359 * for some reason sometimes the DMA controller
360 * speed is set to ATCLK/2 ???? - we fix this here
361 *
362 * note: i don't know what causes this strange behaviour,
363 * but even changing the dma speed doesn't solve it :-(
364 * the ide performance is still only half the normal speed
365 *
366 * if anybody knows what goes wrong with my machine, please
367 * let me know - ASK
368 */
369
370 data |= 0x03;
371
372 outb(CY82_INDEX_CTRLREG1, CY82_INDEX_PORT);
373 outb(data, CY82_DATA_PORT);
374
375#if CY82C693_DEBUG_INFO
376 printk(KERN_INFO ": New Peripheral Configuration Register: 0x%X\n",
377 data);
378#endif /* CY82C693_DEBUG_INFO */
379
380#endif /* CY82C693_SETDMA_CLOCK */
381 return 0;
382}
383
384static void __devinit init_iops_cy82c693(ide_hwif_t *hwif) 273static void __devinit init_iops_cy82c693(ide_hwif_t *hwif)
385{ 274{
386 static ide_hwif_t *primary; 275 static ide_hwif_t *primary;
@@ -401,7 +290,6 @@ static const struct ide_port_ops cy82c693_port_ops = {
401 290
402static const struct ide_port_info cy82c693_chipset __devinitdata = { 291static const struct ide_port_info cy82c693_chipset __devinitdata = {
403 .name = DRV_NAME, 292 .name = DRV_NAME,
404 .init_chipset = init_chipset_cy82c693,
405 .init_iops = init_iops_cy82c693, 293 .init_iops = init_iops_cy82c693,
406 .port_ops = &cy82c693_port_ops, 294 .port_ops = &cy82c693_port_ops,
407 .chipset = ide_cy82c693, 295 .chipset = ide_cy82c693,
@@ -443,7 +331,7 @@ static const struct pci_device_id cy82c693_pci_tbl[] = {
443}; 331};
444MODULE_DEVICE_TABLE(pci, cy82c693_pci_tbl); 332MODULE_DEVICE_TABLE(pci, cy82c693_pci_tbl);
445 333
446static struct pci_driver driver = { 334static struct pci_driver cy82c693_pci_driver = {
447 .name = "Cypress_IDE", 335 .name = "Cypress_IDE",
448 .id_table = cy82c693_pci_tbl, 336 .id_table = cy82c693_pci_tbl,
449 .probe = cy82c693_init_one, 337 .probe = cy82c693_init_one,
@@ -454,12 +342,12 @@ static struct pci_driver driver = {
454 342
455static int __init cy82c693_ide_init(void) 343static int __init cy82c693_ide_init(void)
456{ 344{
457 return ide_pci_register_driver(&driver); 345 return ide_pci_register_driver(&cy82c693_pci_driver);
458} 346}
459 347
460static void __exit cy82c693_ide_exit(void) 348static void __exit cy82c693_ide_exit(void)
461{ 349{
462 pci_unregister_driver(&driver); 350 pci_unregister_driver(&cy82c693_pci_driver);
463} 351}
464 352
465module_init(cy82c693_ide_init); 353module_init(cy82c693_ide_init);
diff --git a/drivers/ide/pci/delkin_cb.c b/drivers/ide/pci/delkin_cb.c
index 83b63b365e51..8689a706f537 100644
--- a/drivers/ide/pci/delkin_cb.c
+++ b/drivers/ide/pci/delkin_cb.c
@@ -117,7 +117,7 @@ static struct pci_device_id delkin_cb_pci_tbl[] __devinitdata = {
117}; 117};
118MODULE_DEVICE_TABLE(pci, delkin_cb_pci_tbl); 118MODULE_DEVICE_TABLE(pci, delkin_cb_pci_tbl);
119 119
120static struct pci_driver driver = { 120static struct pci_driver delkin_cb_pci_driver = {
121 .name = "Delkin-ASKA-Workbit Cardbus IDE", 121 .name = "Delkin-ASKA-Workbit Cardbus IDE",
122 .id_table = delkin_cb_pci_tbl, 122 .id_table = delkin_cb_pci_tbl,
123 .probe = delkin_cb_probe, 123 .probe = delkin_cb_probe,
@@ -126,12 +126,12 @@ static struct pci_driver driver = {
126 126
127static int __init delkin_cb_init(void) 127static int __init delkin_cb_init(void)
128{ 128{
129 return pci_register_driver(&driver); 129 return pci_register_driver(&delkin_cb_pci_driver);
130} 130}
131 131
132static void __exit delkin_cb_exit(void) 132static void __exit delkin_cb_exit(void)
133{ 133{
134 pci_unregister_driver(&driver); 134 pci_unregister_driver(&delkin_cb_pci_driver);
135} 135}
136 136
137module_init(delkin_cb_init); 137module_init(delkin_cb_init);
diff --git a/drivers/ide/pci/generic.c b/drivers/ide/pci/generic.c
index 092b238cb250..474f96a7c076 100644
--- a/drivers/ide/pci/generic.c
+++ b/drivers/ide/pci/generic.c
@@ -166,7 +166,7 @@ static const struct pci_device_id generic_pci_tbl[] = {
166}; 166};
167MODULE_DEVICE_TABLE(pci, generic_pci_tbl); 167MODULE_DEVICE_TABLE(pci, generic_pci_tbl);
168 168
169static struct pci_driver driver = { 169static struct pci_driver generic_pci_driver = {
170 .name = "PCI_IDE", 170 .name = "PCI_IDE",
171 .id_table = generic_pci_tbl, 171 .id_table = generic_pci_tbl,
172 .probe = generic_init_one, 172 .probe = generic_init_one,
@@ -177,12 +177,12 @@ static struct pci_driver driver = {
177 177
178static int __init generic_ide_init(void) 178static int __init generic_ide_init(void)
179{ 179{
180 return ide_pci_register_driver(&driver); 180 return ide_pci_register_driver(&generic_pci_driver);
181} 181}
182 182
183static void __exit generic_ide_exit(void) 183static void __exit generic_ide_exit(void)
184{ 184{
185 pci_unregister_driver(&driver); 185 pci_unregister_driver(&generic_pci_driver);
186} 186}
187 187
188module_init(generic_ide_init); 188module_init(generic_ide_init);
diff --git a/drivers/ide/pci/hpt34x.c b/drivers/ide/pci/hpt34x.c
index 644de29f8fe4..fb1a3aa57f07 100644
--- a/drivers/ide/pci/hpt34x.c
+++ b/drivers/ide/pci/hpt34x.c
@@ -166,7 +166,7 @@ static const struct pci_device_id hpt34x_pci_tbl[] = {
166}; 166};
167MODULE_DEVICE_TABLE(pci, hpt34x_pci_tbl); 167MODULE_DEVICE_TABLE(pci, hpt34x_pci_tbl);
168 168
169static struct pci_driver driver = { 169static struct pci_driver hpt34x_pci_driver = {
170 .name = "HPT34x_IDE", 170 .name = "HPT34x_IDE",
171 .id_table = hpt34x_pci_tbl, 171 .id_table = hpt34x_pci_tbl,
172 .probe = hpt34x_init_one, 172 .probe = hpt34x_init_one,
@@ -177,12 +177,12 @@ static struct pci_driver driver = {
177 177
178static int __init hpt34x_ide_init(void) 178static int __init hpt34x_ide_init(void)
179{ 179{
180 return ide_pci_register_driver(&driver); 180 return ide_pci_register_driver(&hpt34x_pci_driver);
181} 181}
182 182
183static void __exit hpt34x_ide_exit(void) 183static void __exit hpt34x_ide_exit(void)
184{ 184{
185 pci_unregister_driver(&driver); 185 pci_unregister_driver(&hpt34x_pci_driver);
186} 186}
187 187
188module_init(hpt34x_ide_init); 188module_init(hpt34x_ide_init);
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index a194022b6a61..9cf171cb9376 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -835,7 +835,7 @@ static int hpt370_dma_end(ide_drive_t *drive)
835 if (dma_stat & 0x01) 835 if (dma_stat & 0x01)
836 hpt370_irq_timeout(drive); 836 hpt370_irq_timeout(drive);
837 } 837 }
838 return __ide_dma_end(drive); 838 return ide_dma_end(drive);
839} 839}
840 840
841static void hpt370_dma_timeout(ide_drive_t *drive) 841static void hpt370_dma_timeout(ide_drive_t *drive)
@@ -863,9 +863,6 @@ static int hpt374_dma_test_irq(ide_drive_t *drive)
863 if (dma_stat & 4) 863 if (dma_stat & 4)
864 return 1; 864 return 1;
865 865
866 if (!drive->waiting_for_dma)
867 printk(KERN_WARNING "%s: (%s) called while not waiting\n",
868 drive->name, __func__);
869 return 0; 866 return 0;
870} 867}
871 868
@@ -880,7 +877,7 @@ static int hpt374_dma_end(ide_drive_t *drive)
880 pci_read_config_byte(dev, mcr_addr, &mcr); 877 pci_read_config_byte(dev, mcr_addr, &mcr);
881 if (bwsr & mask) 878 if (bwsr & mask)
882 pci_write_config_byte(dev, mcr_addr, mcr | 0x30); 879 pci_write_config_byte(dev, mcr_addr, mcr | 0x30);
883 return __ide_dma_end(drive); 880 return ide_dma_end(drive);
884} 881}
885 882
886/** 883/**
@@ -1456,7 +1453,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
1456 .dma_setup = ide_dma_setup, 1453 .dma_setup = ide_dma_setup,
1457 .dma_exec_cmd = ide_dma_exec_cmd, 1454 .dma_exec_cmd = ide_dma_exec_cmd,
1458 .dma_start = ide_dma_start, 1455 .dma_start = ide_dma_start,
1459 .dma_end = __ide_dma_end, 1456 .dma_end = ide_dma_end,
1460 .dma_test_irq = ide_dma_test_irq, 1457 .dma_test_irq = ide_dma_test_irq,
1461 .dma_lost_irq = hpt366_dma_lost_irq, 1458 .dma_lost_irq = hpt366_dma_lost_irq,
1462 .dma_timeout = ide_dma_timeout, 1459 .dma_timeout = ide_dma_timeout,
@@ -1622,7 +1619,7 @@ static const struct pci_device_id hpt366_pci_tbl[] __devinitconst = {
1622}; 1619};
1623MODULE_DEVICE_TABLE(pci, hpt366_pci_tbl); 1620MODULE_DEVICE_TABLE(pci, hpt366_pci_tbl);
1624 1621
1625static struct pci_driver driver = { 1622static struct pci_driver hpt366_pci_driver = {
1626 .name = "HPT366_IDE", 1623 .name = "HPT366_IDE",
1627 .id_table = hpt366_pci_tbl, 1624 .id_table = hpt366_pci_tbl,
1628 .probe = hpt366_init_one, 1625 .probe = hpt366_init_one,
@@ -1633,12 +1630,12 @@ static struct pci_driver driver = {
1633 1630
1634static int __init hpt366_ide_init(void) 1631static int __init hpt366_ide_init(void)
1635{ 1632{
1636 return ide_pci_register_driver(&driver); 1633 return ide_pci_register_driver(&hpt366_pci_driver);
1637} 1634}
1638 1635
1639static void __exit hpt366_ide_exit(void) 1636static void __exit hpt366_ide_exit(void)
1640{ 1637{
1641 pci_unregister_driver(&driver); 1638 pci_unregister_driver(&hpt366_pci_driver);
1642} 1639}
1643 1640
1644module_init(hpt366_ide_init); 1641module_init(hpt366_ide_init);
diff --git a/drivers/ide/pci/it8213.c b/drivers/ide/pci/it8213.c
index 0954ccd08d6f..7c2feeb3c5ec 100644
--- a/drivers/ide/pci/it8213.c
+++ b/drivers/ide/pci/it8213.c
@@ -189,7 +189,7 @@ static const struct pci_device_id it8213_pci_tbl[] = {
189 189
190MODULE_DEVICE_TABLE(pci, it8213_pci_tbl); 190MODULE_DEVICE_TABLE(pci, it8213_pci_tbl);
191 191
192static struct pci_driver driver = { 192static struct pci_driver it8213_pci_driver = {
193 .name = "ITE8213_IDE", 193 .name = "ITE8213_IDE",
194 .id_table = it8213_pci_tbl, 194 .id_table = it8213_pci_tbl,
195 .probe = it8213_init_one, 195 .probe = it8213_init_one,
@@ -200,12 +200,12 @@ static struct pci_driver driver = {
200 200
201static int __init it8213_ide_init(void) 201static int __init it8213_ide_init(void)
202{ 202{
203 return ide_pci_register_driver(&driver); 203 return ide_pci_register_driver(&it8213_pci_driver);
204} 204}
205 205
206static void __exit it8213_ide_exit(void) 206static void __exit it8213_ide_exit(void)
207{ 207{
208 pci_unregister_driver(&driver); 208 pci_unregister_driver(&it8213_pci_driver);
209} 209}
210 210
211module_init(it8213_ide_init); 211module_init(it8213_ide_init);
diff --git a/drivers/ide/pci/it821x.c b/drivers/ide/pci/it821x.c
index 46edd083b348..995e18bb3139 100644
--- a/drivers/ide/pci/it821x.c
+++ b/drivers/ide/pci/it821x.c
@@ -138,8 +138,7 @@ static void it821x_program_udma(ide_drive_t *drive, u16 timing)
138 struct pci_dev *dev = to_pci_dev(hwif->dev); 138 struct pci_dev *dev = to_pci_dev(hwif->dev);
139 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 139 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
140 int channel = hwif->channel; 140 int channel = hwif->channel;
141 int unit = drive->select.b.unit; 141 u8 unit = drive->dn & 1, conf;
142 u8 conf;
143 142
144 /* Program UDMA timing bits */ 143 /* Program UDMA timing bits */
145 if(itdev->clock_mode == ATA_66) 144 if(itdev->clock_mode == ATA_66)
@@ -168,13 +167,11 @@ static void it821x_clock_strategy(ide_drive_t *drive)
168 ide_hwif_t *hwif = drive->hwif; 167 ide_hwif_t *hwif = drive->hwif;
169 struct pci_dev *dev = to_pci_dev(hwif->dev); 168 struct pci_dev *dev = to_pci_dev(hwif->dev);
170 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 169 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
170 ide_drive_t *pair;
171 int clock, altclock, sel = 0;
172 u8 unit = drive->dn & 1, v;
171 173
172 u8 unit = drive->select.b.unit; 174 pair = &hwif->drives[1 - unit];
173 ide_drive_t *pair = &hwif->drives[1-unit];
174
175 int clock, altclock;
176 u8 v;
177 int sel = 0;
178 175
179 if(itdev->want[0][0] > itdev->want[1][0]) { 176 if(itdev->want[0][0] > itdev->want[1][0]) {
180 clock = itdev->want[0][1]; 177 clock = itdev->want[0][1];
@@ -240,16 +237,17 @@ static void it821x_clock_strategy(ide_drive_t *drive)
240 237
241static void it821x_set_pio_mode(ide_drive_t *drive, const u8 pio) 238static void it821x_set_pio_mode(ide_drive_t *drive, const u8 pio)
242{ 239{
243 ide_hwif_t *hwif = drive->hwif; 240 ide_hwif_t *hwif = drive->hwif;
244 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 241 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
245 int unit = drive->select.b.unit; 242 ide_drive_t *pair;
246 ide_drive_t *pair = &hwif->drives[1 - unit]; 243 u8 unit = drive->dn & 1, set_pio = pio;
247 u8 set_pio = pio;
248 244
249 /* Spec says 89 ref driver uses 88 */ 245 /* Spec says 89 ref driver uses 88 */
250 static u16 pio_timings[]= { 0xAA88, 0xA382, 0xA181, 0x3332, 0x3121 }; 246 static u16 pio_timings[]= { 0xAA88, 0xA382, 0xA181, 0x3332, 0x3121 };
251 static u8 pio_want[] = { ATA_66, ATA_66, ATA_66, ATA_66, ATA_ANY }; 247 static u8 pio_want[] = { ATA_66, ATA_66, ATA_66, ATA_66, ATA_ANY };
252 248
249 pair = &hwif->drives[1 - unit];
250
253 /* 251 /*
254 * Compute the best PIO mode we can for a given device. We must 252 * Compute the best PIO mode we can for a given device. We must
255 * pick a speed that does not cause problems with the other device 253 * pick a speed that does not cause problems with the other device
@@ -286,9 +284,7 @@ static void it821x_tune_mwdma (ide_drive_t *drive, byte mode_wanted)
286 ide_hwif_t *hwif = drive->hwif; 284 ide_hwif_t *hwif = drive->hwif;
287 struct pci_dev *dev = to_pci_dev(hwif->dev); 285 struct pci_dev *dev = to_pci_dev(hwif->dev);
288 struct it821x_dev *itdev = (void *)ide_get_hwifdata(hwif); 286 struct it821x_dev *itdev = (void *)ide_get_hwifdata(hwif);
289 int unit = drive->select.b.unit; 287 u8 unit = drive->dn & 1, channel = hwif->channel, conf;
290 int channel = hwif->channel;
291 u8 conf;
292 288
293 static u16 dma[] = { 0x8866, 0x3222, 0x3121 }; 289 static u16 dma[] = { 0x8866, 0x3222, 0x3121 };
294 static u8 mwdma_want[] = { ATA_ANY, ATA_66, ATA_ANY }; 290 static u8 mwdma_want[] = { ATA_ANY, ATA_66, ATA_ANY };
@@ -325,9 +321,7 @@ static void it821x_tune_udma (ide_drive_t *drive, byte mode_wanted)
325 ide_hwif_t *hwif = drive->hwif; 321 ide_hwif_t *hwif = drive->hwif;
326 struct pci_dev *dev = to_pci_dev(hwif->dev); 322 struct pci_dev *dev = to_pci_dev(hwif->dev);
327 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 323 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
328 int unit = drive->select.b.unit; 324 u8 unit = drive->dn & 1, channel = hwif->channel, conf;
329 int channel = hwif->channel;
330 u8 conf;
331 325
332 static u16 udma[] = { 0x4433, 0x4231, 0x3121, 0x2121, 0x1111, 0x2211, 0x1111 }; 326 static u16 udma[] = { 0x4433, 0x4231, 0x3121, 0x2121, 0x1111, 0x2211, 0x1111 };
333 static u8 udma_want[] = { ATA_ANY, ATA_50, ATA_ANY, ATA_66, ATA_66, ATA_50, ATA_66 }; 327 static u8 udma_want[] = { ATA_ANY, ATA_50, ATA_ANY, ATA_66, ATA_66, ATA_50, ATA_66 };
@@ -369,7 +363,8 @@ static void it821x_dma_start(ide_drive_t *drive)
369{ 363{
370 ide_hwif_t *hwif = drive->hwif; 364 ide_hwif_t *hwif = drive->hwif;
371 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 365 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
372 int unit = drive->select.b.unit; 366 u8 unit = drive->dn & 1;
367
373 if(itdev->mwdma[unit] != MWDMA_OFF) 368 if(itdev->mwdma[unit] != MWDMA_OFF)
374 it821x_program(drive, itdev->mwdma[unit]); 369 it821x_program(drive, itdev->mwdma[unit]);
375 else if(itdev->udma[unit] != UDMA_OFF && itdev->timing10) 370 else if(itdev->udma[unit] != UDMA_OFF && itdev->timing10)
@@ -389,9 +384,10 @@ static void it821x_dma_start(ide_drive_t *drive)
389static int it821x_dma_end(ide_drive_t *drive) 384static int it821x_dma_end(ide_drive_t *drive)
390{ 385{
391 ide_hwif_t *hwif = drive->hwif; 386 ide_hwif_t *hwif = drive->hwif;
392 int unit = drive->select.b.unit;
393 struct it821x_dev *itdev = ide_get_hwifdata(hwif); 387 struct it821x_dev *itdev = ide_get_hwifdata(hwif);
394 int ret = __ide_dma_end(drive); 388 int ret = ide_dma_end(drive);
389 u8 unit = drive->dn & 1;
390
395 if(itdev->mwdma[unit] != MWDMA_OFF) 391 if(itdev->mwdma[unit] != MWDMA_OFF)
396 it821x_program(drive, itdev->pio[unit]); 392 it821x_program(drive, itdev->pio[unit]);
397 return ret; 393 return ret;
@@ -454,7 +450,7 @@ static void it821x_quirkproc(ide_drive_t *drive)
454 * IRQ mask as we may well be in PIO (eg rev 0x10) 450 * IRQ mask as we may well be in PIO (eg rev 0x10)
455 * for now and we know unmasking is safe on this chipset. 451 * for now and we know unmasking is safe on this chipset.
456 */ 452 */
457 drive->unmask = 1; 453 drive->dev_flags |= IDE_DFLAG_UNMASK;
458 } else { 454 } else {
459 /* 455 /*
460 * Perform fixups on smart mode. We need to "lose" some 456 * Perform fixups on smart mode. We need to "lose" some
@@ -680,7 +676,7 @@ static const struct pci_device_id it821x_pci_tbl[] = {
680 676
681MODULE_DEVICE_TABLE(pci, it821x_pci_tbl); 677MODULE_DEVICE_TABLE(pci, it821x_pci_tbl);
682 678
683static struct pci_driver driver = { 679static struct pci_driver it821x_pci_driver = {
684 .name = "ITE821x IDE", 680 .name = "ITE821x IDE",
685 .id_table = it821x_pci_tbl, 681 .id_table = it821x_pci_tbl,
686 .probe = it821x_init_one, 682 .probe = it821x_init_one,
@@ -691,12 +687,12 @@ static struct pci_driver driver = {
691 687
692static int __init it821x_ide_init(void) 688static int __init it821x_ide_init(void)
693{ 689{
694 return ide_pci_register_driver(&driver); 690 return ide_pci_register_driver(&it821x_pci_driver);
695} 691}
696 692
697static void __exit it821x_ide_exit(void) 693static void __exit it821x_ide_exit(void)
698{ 694{
699 pci_unregister_driver(&driver); 695 pci_unregister_driver(&it821x_pci_driver);
700} 696}
701 697
702module_init(it821x_ide_init); 698module_init(it821x_ide_init);
diff --git a/drivers/ide/pci/jmicron.c b/drivers/ide/pci/jmicron.c
index acd647110648..9a68433cf46d 100644
--- a/drivers/ide/pci/jmicron.c
+++ b/drivers/ide/pci/jmicron.c
@@ -149,7 +149,7 @@ static struct pci_device_id jmicron_pci_tbl[] = {
149 149
150MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl); 150MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
151 151
152static struct pci_driver driver = { 152static struct pci_driver jmicron_pci_driver = {
153 .name = "JMicron IDE", 153 .name = "JMicron IDE",
154 .id_table = jmicron_pci_tbl, 154 .id_table = jmicron_pci_tbl,
155 .probe = jmicron_init_one, 155 .probe = jmicron_init_one,
@@ -160,12 +160,12 @@ static struct pci_driver driver = {
160 160
161static int __init jmicron_ide_init(void) 161static int __init jmicron_ide_init(void)
162{ 162{
163 return ide_pci_register_driver(&driver); 163 return ide_pci_register_driver(&jmicron_pci_driver);
164} 164}
165 165
166static void __exit jmicron_ide_exit(void) 166static void __exit jmicron_ide_exit(void)
167{ 167{
168 pci_unregister_driver(&driver); 168 pci_unregister_driver(&jmicron_pci_driver);
169} 169}
170 170
171module_init(jmicron_ide_init); 171module_init(jmicron_ide_init);
diff --git a/drivers/ide/pci/ns87415.c b/drivers/ide/pci/ns87415.c
index 53bd645736d9..13789060f407 100644
--- a/drivers/ide/pci/ns87415.c
+++ b/drivers/ide/pci/ns87415.c
@@ -137,7 +137,7 @@ static void __devinit superio_init_iops(struct hwif_s *hwif)
137static unsigned int ns87415_count = 0, ns87415_control[MAX_HWIFS] = { 0 }; 137static unsigned int ns87415_count = 0, ns87415_control[MAX_HWIFS] = { 0 };
138 138
139/* 139/*
140 * This routine either enables/disables (according to drive->present) 140 * This routine either enables/disables (according to IDE_DFLAG_PRESENT)
141 * the IRQ associated with the port (HWIF(drive)), 141 * the IRQ associated with the port (HWIF(drive)),
142 * and selects either PIO or DMA handshaking for the next I/O operation. 142 * and selects either PIO or DMA handshaking for the next I/O operation.
143 */ 143 */
@@ -153,11 +153,15 @@ static void ns87415_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
153 153
154 /* Adjust IRQ enable bit */ 154 /* Adjust IRQ enable bit */
155 bit = 1 << (8 + hwif->channel); 155 bit = 1 << (8 + hwif->channel);
156 new = drive->present ? (new & ~bit) : (new | bit); 156
157 if (drive->dev_flags & IDE_DFLAG_PRESENT)
158 new &= ~bit;
159 else
160 new |= bit;
157 161
158 /* Select PIO or DMA, DMA may only be selected for one drive/channel. */ 162 /* Select PIO or DMA, DMA may only be selected for one drive/channel. */
159 bit = 1 << (20 + drive->select.b.unit + (hwif->channel << 1)); 163 bit = 1 << (20 + (drive->dn & 1) + (hwif->channel << 1));
160 other = 1 << (20 + (1 - drive->select.b.unit) + (hwif->channel << 1)); 164 other = 1 << (20 + (1 - (drive->dn & 1)) + (hwif->channel << 1));
161 new = use_dma ? ((new & ~other) | bit) : (new & ~bit); 165 new = use_dma ? ((new & ~other) | bit) : (new & ~bit);
162 166
163 if (new != *old) { 167 if (new != *old) {
@@ -187,7 +191,8 @@ static void ns87415_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
187 191
188static void ns87415_selectproc (ide_drive_t *drive) 192static void ns87415_selectproc (ide_drive_t *drive)
189{ 193{
190 ns87415_prepare_drive (drive, drive->using_dma); 194 ns87415_prepare_drive(drive,
195 !!(drive->dev_flags & IDE_DFLAG_USING_DMA));
191} 196}
192 197
193static int ns87415_dma_end(ide_drive_t *drive) 198static int ns87415_dma_end(ide_drive_t *drive)
@@ -334,7 +339,7 @@ static const struct pci_device_id ns87415_pci_tbl[] = {
334}; 339};
335MODULE_DEVICE_TABLE(pci, ns87415_pci_tbl); 340MODULE_DEVICE_TABLE(pci, ns87415_pci_tbl);
336 341
337static struct pci_driver driver = { 342static struct pci_driver ns87415_pci_driver = {
338 .name = "NS87415_IDE", 343 .name = "NS87415_IDE",
339 .id_table = ns87415_pci_tbl, 344 .id_table = ns87415_pci_tbl,
340 .probe = ns87415_init_one, 345 .probe = ns87415_init_one,
@@ -345,12 +350,12 @@ static struct pci_driver driver = {
345 350
346static int __init ns87415_ide_init(void) 351static int __init ns87415_ide_init(void)
347{ 352{
348 return ide_pci_register_driver(&driver); 353 return ide_pci_register_driver(&ns87415_pci_driver);
349} 354}
350 355
351static void __exit ns87415_ide_exit(void) 356static void __exit ns87415_ide_exit(void)
352{ 357{
353 pci_unregister_driver(&driver); 358 pci_unregister_driver(&ns87415_pci_driver);
354} 359}
355 360
356module_init(ns87415_ide_init); 361module_init(ns87415_ide_init);
diff --git a/drivers/ide/pci/opti621.c b/drivers/ide/pci/opti621.c
index 3de11ddcf863..6048eda3cd61 100644
--- a/drivers/ide/pci/opti621.c
+++ b/drivers/ide/pci/opti621.c
@@ -179,7 +179,7 @@ static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio)
179 misc = addr_timings[clk][addr_pio]; 179 misc = addr_timings[clk][addr_pio];
180 180
181 /* select Index-0/1 for Register-A/B */ 181 /* select Index-0/1 for Register-A/B */
182 write_reg(drive->select.b.unit, MISC_REG); 182 write_reg(drive->dn & 1, MISC_REG);
183 /* set read cycle timings */ 183 /* set read cycle timings */
184 write_reg(tim, READ_REG); 184 write_reg(tim, READ_REG);
185 /* set write cycle timings */ 185 /* set write cycle timings */
@@ -220,7 +220,7 @@ static const struct pci_device_id opti621_pci_tbl[] = {
220}; 220};
221MODULE_DEVICE_TABLE(pci, opti621_pci_tbl); 221MODULE_DEVICE_TABLE(pci, opti621_pci_tbl);
222 222
223static struct pci_driver driver = { 223static struct pci_driver opti621_pci_driver = {
224 .name = "Opti621_IDE", 224 .name = "Opti621_IDE",
225 .id_table = opti621_pci_tbl, 225 .id_table = opti621_pci_tbl,
226 .probe = opti621_init_one, 226 .probe = opti621_init_one,
@@ -231,12 +231,12 @@ static struct pci_driver driver = {
231 231
232static int __init opti621_ide_init(void) 232static int __init opti621_ide_init(void)
233{ 233{
234 return ide_pci_register_driver(&driver); 234 return ide_pci_register_driver(&opti621_pci_driver);
235} 235}
236 236
237static void __exit opti621_ide_exit(void) 237static void __exit opti621_ide_exit(void)
238{ 238{
239 pci_unregister_driver(&driver); 239 pci_unregister_driver(&opti621_pci_driver);
240} 240}
241 241
242module_init(opti621_ide_init); 242module_init(opti621_ide_init);
diff --git a/drivers/ide/pci/pdc202xx_new.c b/drivers/ide/pci/pdc202xx_new.c
index 9fc59962553b..211ae46e3e0c 100644
--- a/drivers/ide/pci/pdc202xx_new.c
+++ b/drivers/ide/pci/pdc202xx_new.c
@@ -561,7 +561,7 @@ static const struct pci_device_id pdc202new_pci_tbl[] = {
561}; 561};
562MODULE_DEVICE_TABLE(pci, pdc202new_pci_tbl); 562MODULE_DEVICE_TABLE(pci, pdc202new_pci_tbl);
563 563
564static struct pci_driver driver = { 564static struct pci_driver pdc202new_pci_driver = {
565 .name = "Promise_IDE", 565 .name = "Promise_IDE",
566 .id_table = pdc202new_pci_tbl, 566 .id_table = pdc202new_pci_tbl,
567 .probe = pdc202new_init_one, 567 .probe = pdc202new_init_one,
@@ -572,12 +572,12 @@ static struct pci_driver driver = {
572 572
573static int __init pdc202new_ide_init(void) 573static int __init pdc202new_ide_init(void)
574{ 574{
575 return ide_pci_register_driver(&driver); 575 return ide_pci_register_driver(&pdc202new_pci_driver);
576} 576}
577 577
578static void __exit pdc202new_ide_exit(void) 578static void __exit pdc202new_ide_exit(void)
579{ 579{
580 pci_unregister_driver(&driver); 580 pci_unregister_driver(&pdc202new_pci_driver);
581} 581}
582 582
583module_init(pdc202new_ide_init); 583module_init(pdc202new_ide_init);
diff --git a/drivers/ide/pci/pdc202xx_old.c b/drivers/ide/pci/pdc202xx_old.c
index cb6d2a00c514..799557c25eef 100644
--- a/drivers/ide/pci/pdc202xx_old.c
+++ b/drivers/ide/pci/pdc202xx_old.c
@@ -168,7 +168,7 @@ static void pdc202xx_dma_start(ide_drive_t *drive)
168{ 168{
169 if (drive->current_speed > XFER_UDMA_2) 169 if (drive->current_speed > XFER_UDMA_2)
170 pdc_old_enable_66MHz_clock(drive->hwif); 170 pdc_old_enable_66MHz_clock(drive->hwif);
171 if (drive->media != ide_disk || drive->addressing == 1) { 171 if (drive->media != ide_disk || (drive->dev_flags & IDE_DFLAG_LBA48)) {
172 struct request *rq = HWGROUP(drive)->rq; 172 struct request *rq = HWGROUP(drive)->rq;
173 ide_hwif_t *hwif = HWIF(drive); 173 ide_hwif_t *hwif = HWIF(drive);
174 unsigned long high_16 = hwif->extra_base - 16; 174 unsigned long high_16 = hwif->extra_base - 16;
@@ -188,7 +188,7 @@ static void pdc202xx_dma_start(ide_drive_t *drive)
188 188
189static int pdc202xx_dma_end(ide_drive_t *drive) 189static int pdc202xx_dma_end(ide_drive_t *drive)
190{ 190{
191 if (drive->media != ide_disk || drive->addressing == 1) { 191 if (drive->media != ide_disk || (drive->dev_flags & IDE_DFLAG_LBA48)) {
192 ide_hwif_t *hwif = HWIF(drive); 192 ide_hwif_t *hwif = HWIF(drive);
193 unsigned long high_16 = hwif->extra_base - 16; 193 unsigned long high_16 = hwif->extra_base - 16;
194 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20); 194 unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
@@ -200,7 +200,7 @@ static int pdc202xx_dma_end(ide_drive_t *drive)
200 } 200 }
201 if (drive->current_speed > XFER_UDMA_2) 201 if (drive->current_speed > XFER_UDMA_2)
202 pdc_old_disable_66MHz_clock(drive->hwif); 202 pdc_old_disable_66MHz_clock(drive->hwif);
203 return __ide_dma_end(drive); 203 return ide_dma_end(drive);
204} 204}
205 205
206static int pdc202xx_dma_test_irq(ide_drive_t *drive) 206static int pdc202xx_dma_test_irq(ide_drive_t *drive)
@@ -333,7 +333,7 @@ static const struct ide_dma_ops pdc20246_dma_ops = {
333 .dma_setup = ide_dma_setup, 333 .dma_setup = ide_dma_setup,
334 .dma_exec_cmd = ide_dma_exec_cmd, 334 .dma_exec_cmd = ide_dma_exec_cmd,
335 .dma_start = ide_dma_start, 335 .dma_start = ide_dma_start,
336 .dma_end = __ide_dma_end, 336 .dma_end = ide_dma_end,
337 .dma_test_irq = pdc202xx_dma_test_irq, 337 .dma_test_irq = pdc202xx_dma_test_irq,
338 .dma_lost_irq = pdc202xx_dma_lost_irq, 338 .dma_lost_irq = pdc202xx_dma_lost_irq,
339 .dma_timeout = pdc202xx_dma_timeout, 339 .dma_timeout = pdc202xx_dma_timeout,
@@ -426,7 +426,7 @@ static const struct pci_device_id pdc202xx_pci_tbl[] = {
426}; 426};
427MODULE_DEVICE_TABLE(pci, pdc202xx_pci_tbl); 427MODULE_DEVICE_TABLE(pci, pdc202xx_pci_tbl);
428 428
429static struct pci_driver driver = { 429static struct pci_driver pdc202xx_pci_driver = {
430 .name = "Promise_Old_IDE", 430 .name = "Promise_Old_IDE",
431 .id_table = pdc202xx_pci_tbl, 431 .id_table = pdc202xx_pci_tbl,
432 .probe = pdc202xx_init_one, 432 .probe = pdc202xx_init_one,
@@ -437,12 +437,12 @@ static struct pci_driver driver = {
437 437
438static int __init pdc202xx_ide_init(void) 438static int __init pdc202xx_ide_init(void)
439{ 439{
440 return ide_pci_register_driver(&driver); 440 return ide_pci_register_driver(&pdc202xx_pci_driver);
441} 441}
442 442
443static void __exit pdc202xx_ide_exit(void) 443static void __exit pdc202xx_ide_exit(void)
444{ 444{
445 pci_unregister_driver(&driver); 445 pci_unregister_driver(&pdc202xx_pci_driver);
446} 446}
447 447
448module_init(pdc202xx_ide_init); 448module_init(pdc202xx_ide_init);
diff --git a/drivers/ide/pci/piix.c b/drivers/ide/pci/piix.c
index a06c03f8e295..d63f9fdca76b 100644
--- a/drivers/ide/pci/piix.c
+++ b/drivers/ide/pci/piix.c
@@ -215,17 +215,26 @@ static unsigned int init_chipset_ich(struct pci_dev *dev)
215} 215}
216 216
217/** 217/**
218 * piix_dma_clear_irq - clear BMDMA status 218 * ich_clear_irq - clear BMDMA status
219 * @drive: IDE drive to clear 219 * @drive: IDE drive
220 * 220 *
221 * Called from ide_intr() for PIO interrupts 221 * ICHx contollers set DMA INTR no matter DMA or PIO.
222 * to clear BMDMA status as needed by ICHx 222 * BMDMA status might need to be cleared even for
223 * PIO interrupts to prevent spurious/lost IRQ.
223 */ 224 */
224static void piix_dma_clear_irq(ide_drive_t *drive) 225static void ich_clear_irq(ide_drive_t *drive)
225{ 226{
226 ide_hwif_t *hwif = HWIF(drive); 227 ide_hwif_t *hwif = HWIF(drive);
227 u8 dma_stat; 228 u8 dma_stat;
228 229
230 /*
231 * ide_dma_end() needs BMDMA status for error checking.
232 * So, skip clearing BMDMA status here and leave it
233 * to ide_dma_end() if this is DMA interrupt.
234 */
235 if (drive->waiting_for_dma || hwif->dma_base == 0)
236 return;
237
229 /* clear the INTR & ERROR bits */ 238 /* clear the INTR & ERROR bits */
230 dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS); 239 dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS);
231 /* Should we force the bit as well ? */ 240 /* Should we force the bit as well ? */
@@ -249,6 +258,7 @@ static const struct ich_laptop ich_laptop[] = {
249 { 0x27DF, 0x1025, 0x0110 }, /* ICH7 on Acer 3682WLMi */ 258 { 0x27DF, 0x1025, 0x0110 }, /* ICH7 on Acer 3682WLMi */
250 { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */ 259 { 0x27DF, 0x1043, 0x1267 }, /* ICH7 on Asus W5F */
251 { 0x27DF, 0x103C, 0x30A1 }, /* ICH7 on HP Compaq nc2400 */ 260 { 0x27DF, 0x103C, 0x30A1 }, /* ICH7 on HP Compaq nc2400 */
261 { 0x27DF, 0x1071, 0xD221 }, /* ICH7 on Hercules EC-900 */
252 { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on Acer Aspire 2023WLMi */ 262 { 0x24CA, 0x1025, 0x0061 }, /* ICH4 on Acer Aspire 2023WLMi */
253 { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */ 263 { 0x2653, 0x1043, 0x82D8 }, /* ICH6M on Asus Eee 701 */
254 /* end marker */ 264 /* end marker */
@@ -293,21 +303,19 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
293 hwif->ultra_mask = hwif->mwdma_mask = hwif->swdma_mask = 0; 303 hwif->ultra_mask = hwif->mwdma_mask = hwif->swdma_mask = 0;
294} 304}
295 305
296static void __devinit init_hwif_ich(ide_hwif_t *hwif)
297{
298 init_hwif_piix(hwif);
299
300 /* ICHx need to clear the BMDMA status for all interrupts */
301 if (hwif->dma_base)
302 hwif->ide_dma_clear_irq = &piix_dma_clear_irq;
303}
304
305static const struct ide_port_ops piix_port_ops = { 306static const struct ide_port_ops piix_port_ops = {
306 .set_pio_mode = piix_set_pio_mode, 307 .set_pio_mode = piix_set_pio_mode,
307 .set_dma_mode = piix_set_dma_mode, 308 .set_dma_mode = piix_set_dma_mode,
308 .cable_detect = piix_cable_detect, 309 .cable_detect = piix_cable_detect,
309}; 310};
310 311
312static const struct ide_port_ops ich_port_ops = {
313 .set_pio_mode = piix_set_pio_mode,
314 .set_dma_mode = piix_set_dma_mode,
315 .clear_irq = ich_clear_irq,
316 .cable_detect = piix_cable_detect,
317};
318
311#ifndef CONFIG_IA64 319#ifndef CONFIG_IA64
312 #define IDE_HFLAGS_PIIX IDE_HFLAG_LEGACY_IRQS 320 #define IDE_HFLAGS_PIIX IDE_HFLAG_LEGACY_IRQS
313#else 321#else
@@ -331,9 +339,9 @@ static const struct ide_port_ops piix_port_ops = {
331 { \ 339 { \
332 .name = DRV_NAME, \ 340 .name = DRV_NAME, \
333 .init_chipset = init_chipset_ich, \ 341 .init_chipset = init_chipset_ich, \
334 .init_hwif = init_hwif_ich, \ 342 .init_hwif = init_hwif_piix, \
335 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \ 343 .enablebits = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \
336 .port_ops = &piix_port_ops, \ 344 .port_ops = &ich_port_ops, \
337 .host_flags = IDE_HFLAGS_PIIX, \ 345 .host_flags = IDE_HFLAGS_PIIX, \
338 .pio_mask = ATA_PIO4, \ 346 .pio_mask = ATA_PIO4, \
339 .swdma_mask = ATA_SWDMA2_ONLY, \ 347 .swdma_mask = ATA_SWDMA2_ONLY, \
@@ -444,7 +452,7 @@ static const struct pci_device_id piix_pci_tbl[] = {
444}; 452};
445MODULE_DEVICE_TABLE(pci, piix_pci_tbl); 453MODULE_DEVICE_TABLE(pci, piix_pci_tbl);
446 454
447static struct pci_driver driver = { 455static struct pci_driver piix_pci_driver = {
448 .name = "PIIX_IDE", 456 .name = "PIIX_IDE",
449 .id_table = piix_pci_tbl, 457 .id_table = piix_pci_tbl,
450 .probe = piix_init_one, 458 .probe = piix_init_one,
@@ -456,12 +464,12 @@ static struct pci_driver driver = {
456static int __init piix_ide_init(void) 464static int __init piix_ide_init(void)
457{ 465{
458 piix_check_450nx(); 466 piix_check_450nx();
459 return ide_pci_register_driver(&driver); 467 return ide_pci_register_driver(&piix_pci_driver);
460} 468}
461 469
462static void __exit piix_ide_exit(void) 470static void __exit piix_ide_exit(void)
463{ 471{
464 pci_unregister_driver(&driver); 472 pci_unregister_driver(&piix_pci_driver);
465} 473}
466 474
467module_init(piix_ide_init); 475module_init(piix_ide_init);
diff --git a/drivers/ide/pci/rz1000.c b/drivers/ide/pci/rz1000.c
index c117a068761b..7daf0135cbac 100644
--- a/drivers/ide/pci/rz1000.c
+++ b/drivers/ide/pci/rz1000.c
@@ -59,7 +59,7 @@ static const struct pci_device_id rz1000_pci_tbl[] = {
59}; 59};
60MODULE_DEVICE_TABLE(pci, rz1000_pci_tbl); 60MODULE_DEVICE_TABLE(pci, rz1000_pci_tbl);
61 61
62static struct pci_driver driver = { 62static struct pci_driver rz1000_pci_driver = {
63 .name = "RZ1000_IDE", 63 .name = "RZ1000_IDE",
64 .id_table = rz1000_pci_tbl, 64 .id_table = rz1000_pci_tbl,
65 .probe = rz1000_init_one, 65 .probe = rz1000_init_one,
@@ -68,12 +68,12 @@ static struct pci_driver driver = {
68 68
69static int __init rz1000_ide_init(void) 69static int __init rz1000_ide_init(void)
70{ 70{
71 return ide_pci_register_driver(&driver); 71 return ide_pci_register_driver(&rz1000_pci_driver);
72} 72}
73 73
74static void __exit rz1000_ide_exit(void) 74static void __exit rz1000_ide_exit(void)
75{ 75{
76 pci_unregister_driver(&driver); 76 pci_unregister_driver(&rz1000_pci_driver);
77} 77}
78 78
79module_init(rz1000_ide_init); 79module_init(rz1000_ide_init);
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c
index bdc1fed41260..f1a8758e3a99 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/pci/sc1200.c
@@ -126,7 +126,6 @@ static void sc1200_set_dma_mode(ide_drive_t *drive, const u8 mode)
126{ 126{
127 ide_hwif_t *hwif = HWIF(drive); 127 ide_hwif_t *hwif = HWIF(drive);
128 struct pci_dev *dev = to_pci_dev(hwif->dev); 128 struct pci_dev *dev = to_pci_dev(hwif->dev);
129 int unit = drive->select.b.unit;
130 unsigned int reg, timings; 129 unsigned int reg, timings;
131 unsigned short pci_clock; 130 unsigned short pci_clock;
132 unsigned int basereg = hwif->channel ? 0x50 : 0x40; 131 unsigned int basereg = hwif->channel ? 0x50 : 0x40;
@@ -155,7 +154,7 @@ static void sc1200_set_dma_mode(ide_drive_t *drive, const u8 mode)
155 else 154 else
156 timings = mwdma_timing[pci_clock][mode - XFER_MW_DMA_0]; 155 timings = mwdma_timing[pci_clock][mode - XFER_MW_DMA_0];
157 156
158 if (unit == 0) { /* are we configuring drive0? */ 157 if ((drive->dn & 1) == 0) {
159 pci_read_config_dword(dev, basereg + 4, &reg); 158 pci_read_config_dword(dev, basereg + 4, &reg);
160 timings |= reg & 0x80000000; /* preserve PIO format bit */ 159 timings |= reg & 0x80000000; /* preserve PIO format bit */
161 pci_write_config_dword(dev, basereg + 4, timings); 160 pci_write_config_dword(dev, basereg + 4, timings);
@@ -216,7 +215,8 @@ static void sc1200_set_pio_mode(ide_drive_t *drive, const u8 pio)
216 if (mode != -1) { 215 if (mode != -1) {
217 printk("SC1200: %s: changing (U)DMA mode\n", drive->name); 216 printk("SC1200: %s: changing (U)DMA mode\n", drive->name);
218 ide_dma_off_quietly(drive); 217 ide_dma_off_quietly(drive);
219 if (ide_set_dma_mode(drive, mode) == 0 && drive->using_dma) 218 if (ide_set_dma_mode(drive, mode) == 0 &&
219 (drive->dev_flags & IDE_DFLAG_USING_DMA))
220 hwif->dma_ops->dma_host_set(drive, 1); 220 hwif->dma_ops->dma_host_set(drive, 1);
221 return; 221 return;
222 } 222 }
@@ -328,7 +328,7 @@ static const struct pci_device_id sc1200_pci_tbl[] = {
328}; 328};
329MODULE_DEVICE_TABLE(pci, sc1200_pci_tbl); 329MODULE_DEVICE_TABLE(pci, sc1200_pci_tbl);
330 330
331static struct pci_driver driver = { 331static struct pci_driver sc1200_pci_driver = {
332 .name = "SC1200_IDE", 332 .name = "SC1200_IDE",
333 .id_table = sc1200_pci_tbl, 333 .id_table = sc1200_pci_tbl,
334 .probe = sc1200_init_one, 334 .probe = sc1200_init_one,
@@ -341,12 +341,12 @@ static struct pci_driver driver = {
341 341
342static int __init sc1200_ide_init(void) 342static int __init sc1200_ide_init(void)
343{ 343{
344 return ide_pci_register_driver(&driver); 344 return ide_pci_register_driver(&sc1200_pci_driver);
345} 345}
346 346
347static void __exit sc1200_ide_exit(void) 347static void __exit sc1200_ide_exit(void)
348{ 348{
349 pci_unregister_driver(&driver); 349 pci_unregister_driver(&sc1200_pci_driver);
350} 350}
351 351
352module_init(sc1200_ide_init); 352module_init(sc1200_ide_init);
diff --git a/drivers/ide/pci/scc_pata.c b/drivers/ide/pci/scc_pata.c
index e92a874b31df..9ce1d8059921 100644
--- a/drivers/ide/pci/scc_pata.c
+++ b/drivers/ide/pci/scc_pata.c
@@ -291,7 +291,7 @@ static void scc_set_dma_mode(ide_drive_t *drive, const u8 speed)
291static void scc_dma_host_set(ide_drive_t *drive, int on) 291static void scc_dma_host_set(ide_drive_t *drive, int on)
292{ 292{
293 ide_hwif_t *hwif = drive->hwif; 293 ide_hwif_t *hwif = drive->hwif;
294 u8 unit = (drive->select.b.unit & 0x01); 294 u8 unit = drive->dn & 1;
295 u8 dma_stat = scc_ide_inb(hwif->dma_base + 4); 295 u8 dma_stat = scc_ide_inb(hwif->dma_base + 4);
296 296
297 if (on) 297 if (on)
@@ -353,7 +353,6 @@ static void scc_dma_start(ide_drive_t *drive)
353 353
354 /* start DMA */ 354 /* start DMA */
355 scc_ide_outb(dma_cmd | 1, hwif->dma_base); 355 scc_ide_outb(dma_cmd | 1, hwif->dma_base);
356 hwif->dma = 1;
357 wmb(); 356 wmb();
358} 357}
359 358
@@ -374,7 +373,6 @@ static int __scc_dma_end(ide_drive_t *drive)
374 /* purge DMA mappings */ 373 /* purge DMA mappings */
375 ide_destroy_dmatable(drive); 374 ide_destroy_dmatable(drive);
376 /* verify good DMA status */ 375 /* verify good DMA status */
377 hwif->dma = 0;
378 wmb(); 376 wmb();
379 return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0; 377 return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0;
380} 378}
@@ -511,9 +509,6 @@ static int scc_dma_test_irq(ide_drive_t *drive)
511 if (int_stat & INTSTS_IOIRQS) 509 if (int_stat & INTSTS_IOIRQS)
512 return 1; 510 return 1;
513 511
514 if (!drive->waiting_for_dma)
515 printk(KERN_WARNING "%s: (%s) called while not waiting\n",
516 drive->name, __func__);
517 return 0; 512 return 0;
518} 513}
519 514
@@ -710,7 +705,7 @@ static void scc_tf_load(ide_drive_t *drive, ide_task_t *task)
710 scc_ide_outb(tf->lbah, io_ports->lbah_addr); 705 scc_ide_outb(tf->lbah, io_ports->lbah_addr);
711 706
712 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE) 707 if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
713 scc_ide_outb((tf->device & HIHI) | drive->select.all, 708 scc_ide_outb((tf->device & HIHI) | drive->select,
714 io_ports->device_addr); 709 io_ports->device_addr);
715} 710}
716 711
@@ -826,6 +821,12 @@ static void __devinit init_iops_scc(ide_hwif_t *hwif)
826 init_mmio_iops_scc(hwif); 821 init_mmio_iops_scc(hwif);
827} 822}
828 823
824static int __devinit scc_init_dma(ide_hwif_t *hwif,
825 const struct ide_port_info *d)
826{
827 return ide_allocate_dma_engine(hwif);
828}
829
829static u8 scc_cable_detect(ide_hwif_t *hwif) 830static u8 scc_cable_detect(ide_hwif_t *hwif)
830{ 831{
831 return ATA_CBL_PATA80; 832 return ATA_CBL_PATA80;
@@ -890,6 +891,7 @@ static const struct ide_dma_ops scc_dma_ops = {
890 { \ 891 { \
891 .name = name_str, \ 892 .name = name_str, \
892 .init_iops = init_iops_scc, \ 893 .init_iops = init_iops_scc, \
894 .init_dma = scc_init_dma, \
893 .init_hwif = init_hwif_scc, \ 895 .init_hwif = init_hwif_scc, \
894 .tp_ops = &scc_tp_ops, \ 896 .tp_ops = &scc_tp_ops, \
895 .port_ops = &scc_port_ops, \ 897 .port_ops = &scc_port_ops, \
@@ -927,13 +929,6 @@ static void __devexit scc_remove(struct pci_dev *dev)
927{ 929{
928 struct scc_ports *ports = pci_get_drvdata(dev); 930 struct scc_ports *ports = pci_get_drvdata(dev);
929 struct ide_host *host = ports->host; 931 struct ide_host *host = ports->host;
930 ide_hwif_t *hwif = host->ports[0];
931
932 if (hwif->dmatable_cpu) {
933 pci_free_consistent(dev, PRD_ENTRIES * PRD_BYTES,
934 hwif->dmatable_cpu, hwif->dmatable_dma);
935 hwif->dmatable_cpu = NULL;
936 }
937 932
938 ide_host_remove(host); 933 ide_host_remove(host);
939 934
@@ -949,7 +944,7 @@ static const struct pci_device_id scc_pci_tbl[] = {
949}; 944};
950MODULE_DEVICE_TABLE(pci, scc_pci_tbl); 945MODULE_DEVICE_TABLE(pci, scc_pci_tbl);
951 946
952static struct pci_driver driver = { 947static struct pci_driver scc_pci_driver = {
953 .name = "SCC IDE", 948 .name = "SCC IDE",
954 .id_table = scc_pci_tbl, 949 .id_table = scc_pci_tbl,
955 .probe = scc_init_one, 950 .probe = scc_init_one,
@@ -958,14 +953,14 @@ static struct pci_driver driver = {
958 953
959static int scc_ide_init(void) 954static int scc_ide_init(void)
960{ 955{
961 return ide_pci_register_driver(&driver); 956 return ide_pci_register_driver(&scc_pci_driver);
962} 957}
963 958
964module_init(scc_ide_init); 959module_init(scc_ide_init);
965/* -- No exit code? 960/* -- No exit code?
966static void scc_ide_exit(void) 961static void scc_ide_exit(void)
967{ 962{
968 ide_pci_unregister_driver(&driver); 963 ide_pci_unregister_driver(&scc_pci_driver);
969} 964}
970module_exit(scc_ide_exit); 965module_exit(scc_ide_exit);
971 */ 966 */
diff --git a/drivers/ide/pci/serverworks.c b/drivers/ide/pci/serverworks.c
index 3dff2aea317e..437bc919dafd 100644
--- a/drivers/ide/pci/serverworks.c
+++ b/drivers/ide/pci/serverworks.c
@@ -153,7 +153,7 @@ static void svwks_set_dma_mode(ide_drive_t *drive, const u8 speed)
153 153
154 ide_hwif_t *hwif = HWIF(drive); 154 ide_hwif_t *hwif = HWIF(drive);
155 struct pci_dev *dev = to_pci_dev(hwif->dev); 155 struct pci_dev *dev = to_pci_dev(hwif->dev);
156 u8 unit = (drive->select.b.unit & 0x01); 156 u8 unit = drive->dn & 1;
157 157
158 u8 ultra_enable = 0, ultra_timing = 0, dma_timing = 0; 158 u8 ultra_enable = 0, ultra_timing = 0, dma_timing = 0;
159 159
@@ -443,7 +443,7 @@ static const struct pci_device_id svwks_pci_tbl[] = {
443}; 443};
444MODULE_DEVICE_TABLE(pci, svwks_pci_tbl); 444MODULE_DEVICE_TABLE(pci, svwks_pci_tbl);
445 445
446static struct pci_driver driver = { 446static struct pci_driver svwks_pci_driver = {
447 .name = "Serverworks_IDE", 447 .name = "Serverworks_IDE",
448 .id_table = svwks_pci_tbl, 448 .id_table = svwks_pci_tbl,
449 .probe = svwks_init_one, 449 .probe = svwks_init_one,
@@ -454,12 +454,12 @@ static struct pci_driver driver = {
454 454
455static int __init svwks_ide_init(void) 455static int __init svwks_ide_init(void)
456{ 456{
457 return ide_pci_register_driver(&driver); 457 return ide_pci_register_driver(&svwks_pci_driver);
458} 458}
459 459
460static void __exit svwks_ide_exit(void) 460static void __exit svwks_ide_exit(void)
461{ 461{
462 pci_unregister_driver(&driver); 462 pci_unregister_driver(&svwks_pci_driver);
463} 463}
464 464
465module_init(svwks_ide_init); 465module_init(svwks_ide_init);
diff --git a/drivers/ide/pci/sgiioc4.c b/drivers/ide/pci/sgiioc4.c
index 1017fb4f6317..dd634541ce36 100644
--- a/drivers/ide/pci/sgiioc4.c
+++ b/drivers/ide/pci/sgiioc4.c
@@ -1,5 +1,6 @@
1/* 1/*
2 * Copyright (c) 2003-2006 Silicon Graphics, Inc. All Rights Reserved. 2 * Copyright (c) 2003-2006 Silicon Graphics, Inc. All Rights Reserved.
3 * Copyright (C) 2008 MontaVista Software, Inc.
3 * 4 *
4 * This program is free software; you can redistribute it and/or modify it 5 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License 6 * under the terms of version 2 of the GNU General Public License
@@ -150,7 +151,7 @@ sgiioc4_clearirq(ide_drive_t * drive)
150 int count = 0; 151 int count = 0;
151 152
152 stat = sgiioc4_read_status(hwif); 153 stat = sgiioc4_read_status(hwif);
153 while ((stat & 0x80) && (count++ < 100)) { 154 while ((stat & ATA_BUSY) && (count++ < 100)) {
154 udelay(1); 155 udelay(1);
155 stat = sgiioc4_read_status(hwif); 156 stat = sgiioc4_read_status(hwif);
156 } 157 }
@@ -310,7 +311,7 @@ static u8 sgiioc4_read_status(ide_hwif_t *hwif)
310 u8 reg = (u8) readb((void __iomem *) port); 311 u8 reg = (u8) readb((void __iomem *) port);
311 312
312 if ((port & 0xFFF) == 0x11C) { /* Status register of IOC4 */ 313 if ((port & 0xFFF) == 0x11C) { /* Status register of IOC4 */
313 if (reg & 0x51) { /* Not busy...check for interrupt */ 314 if (!(reg & ATA_BUSY)) { /* Not busy... check for interrupt */
314 unsigned long other_ir = port - 0x110; 315 unsigned long other_ir = port - 0x110;
315 unsigned int intr_reg = (u32) readl((void __iomem *) other_ir); 316 unsigned int intr_reg = (u32) readl((void __iomem *) other_ir);
316 317
@@ -338,35 +339,31 @@ ide_dma_sgiioc4(ide_hwif_t *hwif, const struct ide_port_info *d)
338 if (dma_base == 0) 339 if (dma_base == 0)
339 return -1; 340 return -1;
340 341
341 printk(KERN_INFO "%s: BM-DMA at 0x%04lx-0x%04lx\n", hwif->name, 342 printk(KERN_INFO " %s: MMIO-DMA\n", hwif->name);
342 dma_base, dma_base + num_ports - 1);
343 343
344 if (!request_mem_region(dma_base, num_ports, hwif->name)) { 344 if (request_mem_region(dma_base, num_ports, hwif->name) == NULL) {
345 printk(KERN_ERR 345 printk(KERN_ERR "%s(%s) -- ERROR: addresses 0x%08lx to 0x%08lx "
346 "%s(%s) -- ERROR, Addresses 0x%p to 0x%p " 346 "already in use\n", __func__, hwif->name,
347 "ALREADY in use\n", 347 dma_base, dma_base + num_ports - 1);
348 __func__, hwif->name, (void *) dma_base,
349 (void *) dma_base + num_ports - 1);
350 return -1; 348 return -1;
351 } 349 }
352 350
353 virt_dma_base = ioremap(dma_base, num_ports); 351 virt_dma_base = ioremap(dma_base, num_ports);
354 if (virt_dma_base == NULL) { 352 if (virt_dma_base == NULL) {
355 printk(KERN_ERR 353 printk(KERN_ERR "%s(%s) -- ERROR: unable to map addresses "
356 "%s(%s) -- ERROR, Unable to map addresses 0x%lx to 0x%lx\n", 354 "0x%lx to 0x%lx\n", __func__, hwif->name,
357 __func__, hwif->name, dma_base, dma_base + num_ports - 1); 355 dma_base, dma_base + num_ports - 1);
358 goto dma_remap_failure; 356 goto dma_remap_failure;
359 } 357 }
360 hwif->dma_base = (unsigned long) virt_dma_base; 358 hwif->dma_base = (unsigned long) virt_dma_base;
361 359
362 hwif->dmatable_cpu = pci_alloc_consistent(dev, 360 hwif->sg_max_nents = IOC4_PRD_ENTRIES;
363 IOC4_PRD_ENTRIES * IOC4_PRD_BYTES,
364 &hwif->dmatable_dma);
365 361
366 if (!hwif->dmatable_cpu) 362 hwif->prd_max_nents = IOC4_PRD_ENTRIES;
367 goto dma_pci_alloc_failure; 363 hwif->prd_ent_size = IOC4_PRD_BYTES;
368 364
369 hwif->sg_max_nents = IOC4_PRD_ENTRIES; 365 if (ide_allocate_dma_engine(hwif))
366 goto dma_pci_alloc_failure;
370 367
371 pad = pci_alloc_consistent(dev, IOC4_IDE_CACHELINE_SIZE, 368 pad = pci_alloc_consistent(dev, IOC4_IDE_CACHELINE_SIZE,
372 (dma_addr_t *)&hwif->extra_base); 369 (dma_addr_t *)&hwif->extra_base);
@@ -375,13 +372,11 @@ ide_dma_sgiioc4(ide_hwif_t *hwif, const struct ide_port_info *d)
375 return 0; 372 return 0;
376 } 373 }
377 374
378 pci_free_consistent(dev, IOC4_PRD_ENTRIES * IOC4_PRD_BYTES, 375 ide_release_dma_engine(hwif);
379 hwif->dmatable_cpu, hwif->dmatable_dma); 376
380 printk(KERN_INFO 377 printk(KERN_ERR "%s(%s) -- ERROR: Unable to allocate DMA maps\n",
381 "%s() -- Error! Unable to allocate DMA Maps for drive %s\n",
382 __func__, hwif->name); 378 __func__, hwif->name);
383 printk(KERN_INFO 379 printk(KERN_INFO "%s: changing from DMA to PIO mode", hwif->name);
384 "Changing from DMA to PIO mode for Drive %s\n", hwif->name);
385 380
386dma_pci_alloc_failure: 381dma_pci_alloc_failure:
387 iounmap(virt_dma_base); 382 iounmap(virt_dma_base);
@@ -617,14 +612,12 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
617 irqport = (unsigned long) virt_base + IOC4_INTR_OFFSET; 612 irqport = (unsigned long) virt_base + IOC4_INTR_OFFSET;
618 613
619 cmd_phys_base = bar0 + IOC4_CMD_OFFSET; 614 cmd_phys_base = bar0 + IOC4_CMD_OFFSET;
620 if (!request_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE, 615 if (request_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE,
621 DRV_NAME)) { 616 DRV_NAME) == NULL) {
622 printk(KERN_ERR 617 printk(KERN_ERR "%s %s -- ERROR: addresses 0x%08lx to 0x%08lx "
623 "%s %s: -- ERROR, Addresses " 618 "already in use\n", DRV_NAME, pci_name(dev),
624 "0x%p to 0x%p ALREADY in use\n", 619 cmd_phys_base, cmd_phys_base + IOC4_CMD_CTL_BLK_SIZE);
625 DRV_NAME, pci_name(dev), (void *)cmd_phys_base, 620 return -EBUSY;
626 (void *) cmd_phys_base + IOC4_CMD_CTL_BLK_SIZE);
627 return -ENOMEM;
628 } 621 }
629 622
630 /* Initialize the IO registers */ 623 /* Initialize the IO registers */
diff --git a/drivers/ide/pci/siimage.c b/drivers/ide/pci/siimage.c
index 174a873b4c64..eb4faf92c571 100644
--- a/drivers/ide/pci/siimage.c
+++ b/drivers/ide/pci/siimage.c
@@ -116,13 +116,14 @@ static inline unsigned long siimage_seldev(ide_drive_t *drive, int r)
116{ 116{
117 ide_hwif_t *hwif = HWIF(drive); 117 ide_hwif_t *hwif = HWIF(drive);
118 unsigned long base = (unsigned long)hwif->hwif_data; 118 unsigned long base = (unsigned long)hwif->hwif_data;
119 u8 unit = drive->dn & 1;
119 120
120 base += 0xA0 + r; 121 base += 0xA0 + r;
121 if (hwif->host_flags & IDE_HFLAG_MMIO) 122 if (hwif->host_flags & IDE_HFLAG_MMIO)
122 base += hwif->channel << 6; 123 base += hwif->channel << 6;
123 else 124 else
124 base += hwif->channel << 4; 125 base += hwif->channel << 4;
125 base |= drive->select.b.unit << drive->select.b.unit; 126 base |= unit << unit;
126 return base; 127 return base;
127} 128}
128 129
@@ -255,7 +256,7 @@ static void sil_set_pio_mode(ide_drive_t *drive, u8 pio)
255 u8 addr_mask = hwif->channel ? (mmio ? 0xF4 : 0x84) 256 u8 addr_mask = hwif->channel ? (mmio ? 0xF4 : 0x84)
256 : (mmio ? 0xB4 : 0x80); 257 : (mmio ? 0xB4 : 0x80);
257 u8 mode = 0; 258 u8 mode = 0;
258 u8 unit = drive->select.b.unit; 259 u8 unit = drive->dn & 1;
259 260
260 /* trim *taskfile* PIO to the slowest of the master/slave */ 261 /* trim *taskfile* PIO to the slowest of the master/slave */
261 if (pair) { 262 if (pair) {
@@ -301,9 +302,9 @@ static void sil_set_dma_mode(ide_drive_t *drive, const u8 speed)
301 302
302 ide_hwif_t *hwif = HWIF(drive); 303 ide_hwif_t *hwif = HWIF(drive);
303 struct pci_dev *dev = to_pci_dev(hwif->dev); 304 struct pci_dev *dev = to_pci_dev(hwif->dev);
304 u16 ultra = 0, multi = 0;
305 u8 mode = 0, unit = drive->select.b.unit;
306 unsigned long base = (unsigned long)hwif->hwif_data; 305 unsigned long base = (unsigned long)hwif->hwif_data;
306 u16 ultra = 0, multi = 0;
307 u8 mode = 0, unit = drive->dn & 1;
307 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; 308 u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
308 u8 scsc = 0, addr_mask = hwif->channel ? (mmio ? 0xF4 : 0x84) 309 u8 scsc = 0, addr_mask = hwif->channel ? (mmio ? 0xF4 : 0x84)
309 : (mmio ? 0xB4 : 0x80); 310 : (mmio ? 0xB4 : 0x80);
@@ -712,7 +713,7 @@ static const struct ide_dma_ops sil_dma_ops = {
712 .dma_setup = ide_dma_setup, 713 .dma_setup = ide_dma_setup,
713 .dma_exec_cmd = ide_dma_exec_cmd, 714 .dma_exec_cmd = ide_dma_exec_cmd,
714 .dma_start = ide_dma_start, 715 .dma_start = ide_dma_start,
715 .dma_end = __ide_dma_end, 716 .dma_end = ide_dma_end,
716 .dma_test_irq = siimage_dma_test_irq, 717 .dma_test_irq = siimage_dma_test_irq,
717 .dma_timeout = ide_dma_timeout, 718 .dma_timeout = ide_dma_timeout,
718 .dma_lost_irq = ide_dma_lost_irq, 719 .dma_lost_irq = ide_dma_lost_irq,
@@ -829,7 +830,7 @@ static const struct pci_device_id siimage_pci_tbl[] = {
829}; 830};
830MODULE_DEVICE_TABLE(pci, siimage_pci_tbl); 831MODULE_DEVICE_TABLE(pci, siimage_pci_tbl);
831 832
832static struct pci_driver driver = { 833static struct pci_driver siimage_pci_driver = {
833 .name = "SiI_IDE", 834 .name = "SiI_IDE",
834 .id_table = siimage_pci_tbl, 835 .id_table = siimage_pci_tbl,
835 .probe = siimage_init_one, 836 .probe = siimage_init_one,
@@ -840,12 +841,12 @@ static struct pci_driver driver = {
840 841
841static int __init siimage_ide_init(void) 842static int __init siimage_ide_init(void)
842{ 843{
843 return ide_pci_register_driver(&driver); 844 return ide_pci_register_driver(&siimage_pci_driver);
844} 845}
845 846
846static void __exit siimage_ide_exit(void) 847static void __exit siimage_ide_exit(void)
847{ 848{
848 pci_unregister_driver(&driver); 849 pci_unregister_driver(&siimage_pci_driver);
849} 850}
850 851
851module_init(siimage_ide_init); 852module_init(siimage_ide_init);
diff --git a/drivers/ide/pci/sis5513.c b/drivers/ide/pci/sis5513.c
index 734dd41f1f67..ad32e18c5ba3 100644
--- a/drivers/ide/pci/sis5513.c
+++ b/drivers/ide/pci/sis5513.c
@@ -605,7 +605,7 @@ static const struct pci_device_id sis5513_pci_tbl[] = {
605}; 605};
606MODULE_DEVICE_TABLE(pci, sis5513_pci_tbl); 606MODULE_DEVICE_TABLE(pci, sis5513_pci_tbl);
607 607
608static struct pci_driver driver = { 608static struct pci_driver sis5513_pci_driver = {
609 .name = "SIS_IDE", 609 .name = "SIS_IDE",
610 .id_table = sis5513_pci_tbl, 610 .id_table = sis5513_pci_tbl,
611 .probe = sis5513_init_one, 611 .probe = sis5513_init_one,
@@ -616,12 +616,12 @@ static struct pci_driver driver = {
616 616
617static int __init sis5513_ide_init(void) 617static int __init sis5513_ide_init(void)
618{ 618{
619 return ide_pci_register_driver(&driver); 619 return ide_pci_register_driver(&sis5513_pci_driver);
620} 620}
621 621
622static void __exit sis5513_ide_exit(void) 622static void __exit sis5513_ide_exit(void)
623{ 623{
624 pci_unregister_driver(&driver); 624 pci_unregister_driver(&sis5513_pci_driver);
625} 625}
626 626
627module_init(sis5513_ide_init); 627module_init(sis5513_ide_init);
diff --git a/drivers/ide/pci/sl82c105.c b/drivers/ide/pci/sl82c105.c
index 37a6b7bdc040..84dc33602ff8 100644
--- a/drivers/ide/pci/sl82c105.c
+++ b/drivers/ide/pci/sl82c105.c
@@ -207,7 +207,7 @@ static int sl82c105_dma_end(ide_drive_t *drive)
207 207
208 DBG(("%s(drive:%s)\n", __func__, drive->name)); 208 DBG(("%s(drive:%s)\n", __func__, drive->name));
209 209
210 ret = __ide_dma_end(drive); 210 ret = ide_dma_end(drive);
211 211
212 pci_write_config_word(dev, reg, drive->drive_data); 212 pci_write_config_word(dev, reg, drive->drive_data);
213 213
@@ -345,7 +345,7 @@ static const struct pci_device_id sl82c105_pci_tbl[] = {
345}; 345};
346MODULE_DEVICE_TABLE(pci, sl82c105_pci_tbl); 346MODULE_DEVICE_TABLE(pci, sl82c105_pci_tbl);
347 347
348static struct pci_driver driver = { 348static struct pci_driver sl82c105_pci_driver = {
349 .name = "W82C105_IDE", 349 .name = "W82C105_IDE",
350 .id_table = sl82c105_pci_tbl, 350 .id_table = sl82c105_pci_tbl,
351 .probe = sl82c105_init_one, 351 .probe = sl82c105_init_one,
@@ -356,12 +356,12 @@ static struct pci_driver driver = {
356 356
357static int __init sl82c105_ide_init(void) 357static int __init sl82c105_ide_init(void)
358{ 358{
359 return ide_pci_register_driver(&driver); 359 return ide_pci_register_driver(&sl82c105_pci_driver);
360} 360}
361 361
362static void __exit sl82c105_ide_exit(void) 362static void __exit sl82c105_ide_exit(void)
363{ 363{
364 pci_unregister_driver(&driver); 364 pci_unregister_driver(&sl82c105_pci_driver);
365} 365}
366 366
367module_init(sl82c105_ide_init); 367module_init(sl82c105_ide_init);
diff --git a/drivers/ide/pci/slc90e66.c b/drivers/ide/pci/slc90e66.c
index a9551a13ac57..0f759e4ed779 100644
--- a/drivers/ide/pci/slc90e66.c
+++ b/drivers/ide/pci/slc90e66.c
@@ -154,7 +154,7 @@ static const struct pci_device_id slc90e66_pci_tbl[] = {
154}; 154};
155MODULE_DEVICE_TABLE(pci, slc90e66_pci_tbl); 155MODULE_DEVICE_TABLE(pci, slc90e66_pci_tbl);
156 156
157static struct pci_driver driver = { 157static struct pci_driver slc90e66_pci_driver = {
158 .name = "SLC90e66_IDE", 158 .name = "SLC90e66_IDE",
159 .id_table = slc90e66_pci_tbl, 159 .id_table = slc90e66_pci_tbl,
160 .probe = slc90e66_init_one, 160 .probe = slc90e66_init_one,
@@ -165,12 +165,12 @@ static struct pci_driver driver = {
165 165
166static int __init slc90e66_ide_init(void) 166static int __init slc90e66_ide_init(void)
167{ 167{
168 return ide_pci_register_driver(&driver); 168 return ide_pci_register_driver(&slc90e66_pci_driver);
169} 169}
170 170
171static void __exit slc90e66_ide_exit(void) 171static void __exit slc90e66_ide_exit(void)
172{ 172{
173 pci_unregister_driver(&driver); 173 pci_unregister_driver(&slc90e66_pci_driver);
174} 174}
175 175
176module_init(slc90e66_ide_init); 176module_init(slc90e66_ide_init);
diff --git a/drivers/ide/pci/tc86c001.c b/drivers/ide/pci/tc86c001.c
index 927277c54ec9..93e2cce4b296 100644
--- a/drivers/ide/pci/tc86c001.c
+++ b/drivers/ide/pci/tc86c001.c
@@ -186,7 +186,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
186 .dma_setup = ide_dma_setup, 186 .dma_setup = ide_dma_setup,
187 .dma_exec_cmd = ide_dma_exec_cmd, 187 .dma_exec_cmd = ide_dma_exec_cmd,
188 .dma_start = tc86c001_dma_start, 188 .dma_start = tc86c001_dma_start,
189 .dma_end = __ide_dma_end, 189 .dma_end = ide_dma_end,
190 .dma_test_irq = ide_dma_test_irq, 190 .dma_test_irq = ide_dma_test_irq,
191 .dma_lost_irq = ide_dma_lost_irq, 191 .dma_lost_irq = ide_dma_lost_irq,
192 .dma_timeout = ide_dma_timeout, 192 .dma_timeout = ide_dma_timeout,
@@ -245,7 +245,7 @@ static const struct pci_device_id tc86c001_pci_tbl[] = {
245}; 245};
246MODULE_DEVICE_TABLE(pci, tc86c001_pci_tbl); 246MODULE_DEVICE_TABLE(pci, tc86c001_pci_tbl);
247 247
248static struct pci_driver driver = { 248static struct pci_driver tc86c001_pci_driver = {
249 .name = "TC86C001", 249 .name = "TC86C001",
250 .id_table = tc86c001_pci_tbl, 250 .id_table = tc86c001_pci_tbl,
251 .probe = tc86c001_init_one, 251 .probe = tc86c001_init_one,
@@ -254,12 +254,12 @@ static struct pci_driver driver = {
254 254
255static int __init tc86c001_ide_init(void) 255static int __init tc86c001_ide_init(void)
256{ 256{
257 return ide_pci_register_driver(&driver); 257 return ide_pci_register_driver(&tc86c001_pci_driver);
258} 258}
259 259
260static void __exit tc86c001_ide_exit(void) 260static void __exit tc86c001_ide_exit(void)
261{ 261{
262 pci_unregister_driver(&driver); 262 pci_unregister_driver(&tc86c001_pci_driver);
263} 263}
264 264
265module_init(tc86c001_ide_init); 265module_init(tc86c001_ide_init);
diff --git a/drivers/ide/pci/triflex.c b/drivers/ide/pci/triflex.c
index be8715dcee05..b6ff40336aa9 100644
--- a/drivers/ide/pci/triflex.c
+++ b/drivers/ide/pci/triflex.c
@@ -38,13 +38,12 @@ static void triflex_set_mode(ide_drive_t *drive, const u8 speed)
38{ 38{
39 ide_hwif_t *hwif = HWIF(drive); 39 ide_hwif_t *hwif = HWIF(drive);
40 struct pci_dev *dev = to_pci_dev(hwif->dev); 40 struct pci_dev *dev = to_pci_dev(hwif->dev);
41 u8 channel_offset = hwif->channel ? 0x74 : 0x70;
42 u16 timing = 0;
43 u32 triflex_timings = 0; 41 u32 triflex_timings = 0;
44 u8 unit = (drive->select.b.unit & 0x01); 42 u16 timing = 0;
45 43 u8 channel_offset = hwif->channel ? 0x74 : 0x70, unit = drive->dn & 1;
44
46 pci_read_config_dword(dev, channel_offset, &triflex_timings); 45 pci_read_config_dword(dev, channel_offset, &triflex_timings);
47 46
48 switch(speed) { 47 switch(speed) {
49 case XFER_MW_DMA_2: 48 case XFER_MW_DMA_2:
50 timing = 0x0103; 49 timing = 0x0103;
@@ -114,7 +113,7 @@ static const struct pci_device_id triflex_pci_tbl[] = {
114}; 113};
115MODULE_DEVICE_TABLE(pci, triflex_pci_tbl); 114MODULE_DEVICE_TABLE(pci, triflex_pci_tbl);
116 115
117static struct pci_driver driver = { 116static struct pci_driver triflex_pci_driver = {
118 .name = "TRIFLEX_IDE", 117 .name = "TRIFLEX_IDE",
119 .id_table = triflex_pci_tbl, 118 .id_table = triflex_pci_tbl,
120 .probe = triflex_init_one, 119 .probe = triflex_init_one,
@@ -125,12 +124,12 @@ static struct pci_driver driver = {
125 124
126static int __init triflex_ide_init(void) 125static int __init triflex_ide_init(void)
127{ 126{
128 return ide_pci_register_driver(&driver); 127 return ide_pci_register_driver(&triflex_pci_driver);
129} 128}
130 129
131static void __exit triflex_ide_exit(void) 130static void __exit triflex_ide_exit(void)
132{ 131{
133 pci_unregister_driver(&driver); 132 pci_unregister_driver(&triflex_pci_driver);
134} 133}
135 134
136module_init(triflex_ide_init); 135module_init(triflex_ide_init);
diff --git a/drivers/ide/pci/trm290.c b/drivers/ide/pci/trm290.c
index 4dfbc6a68b5b..75ea61526566 100644
--- a/drivers/ide/pci/trm290.c
+++ b/drivers/ide/pci/trm290.c
@@ -161,7 +161,7 @@ static void trm290_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
161 } 161 }
162 162
163 /* enable IRQ if not probing */ 163 /* enable IRQ if not probing */
164 if (drive->present) { 164 if (drive->dev_flags & IDE_DFLAG_PRESENT) {
165 reg = inw(hwif->config_data + 3); 165 reg = inw(hwif->config_data + 3);
166 reg &= 0x13; 166 reg &= 0x13;
167 reg &= ~(1 << hwif->channel); 167 reg &= ~(1 << hwif->channel);
@@ -173,7 +173,7 @@ static void trm290_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
173 173
174static void trm290_selectproc (ide_drive_t *drive) 174static void trm290_selectproc (ide_drive_t *drive)
175{ 175{
176 trm290_prepare_drive(drive, drive->using_dma); 176 trm290_prepare_drive(drive, !!(drive->dev_flags & IDE_DFLAG_USING_DMA));
177} 177}
178 178
179static void trm290_dma_exec_cmd(ide_drive_t *drive, u8 command) 179static void trm290_dma_exec_cmd(ide_drive_t *drive, u8 command)
@@ -350,7 +350,7 @@ static const struct pci_device_id trm290_pci_tbl[] = {
350}; 350};
351MODULE_DEVICE_TABLE(pci, trm290_pci_tbl); 351MODULE_DEVICE_TABLE(pci, trm290_pci_tbl);
352 352
353static struct pci_driver driver = { 353static struct pci_driver trm290_pci_driver = {
354 .name = "TRM290_IDE", 354 .name = "TRM290_IDE",
355 .id_table = trm290_pci_tbl, 355 .id_table = trm290_pci_tbl,
356 .probe = trm290_init_one, 356 .probe = trm290_init_one,
@@ -359,12 +359,12 @@ static struct pci_driver driver = {
359 359
360static int __init trm290_ide_init(void) 360static int __init trm290_ide_init(void)
361{ 361{
362 return ide_pci_register_driver(&driver); 362 return ide_pci_register_driver(&trm290_pci_driver);
363} 363}
364 364
365static void __exit trm290_ide_exit(void) 365static void __exit trm290_ide_exit(void)
366{ 366{
367 pci_unregister_driver(&driver); 367 pci_unregister_driver(&trm290_pci_driver);
368} 368}
369 369
370module_init(trm290_ide_init); 370module_init(trm290_ide_init);
diff --git a/drivers/ide/pci/via82cxxx.c b/drivers/ide/pci/via82cxxx.c
index acacdaab69c2..2a812d3207e9 100644
--- a/drivers/ide/pci/via82cxxx.c
+++ b/drivers/ide/pci/via82cxxx.c
@@ -487,7 +487,7 @@ static const struct pci_device_id via_pci_tbl[] = {
487}; 487};
488MODULE_DEVICE_TABLE(pci, via_pci_tbl); 488MODULE_DEVICE_TABLE(pci, via_pci_tbl);
489 489
490static struct pci_driver driver = { 490static struct pci_driver via_pci_driver = {
491 .name = "VIA_IDE", 491 .name = "VIA_IDE",
492 .id_table = via_pci_tbl, 492 .id_table = via_pci_tbl,
493 .probe = via_init_one, 493 .probe = via_init_one,
@@ -498,12 +498,12 @@ static struct pci_driver driver = {
498 498
499static int __init via_ide_init(void) 499static int __init via_ide_init(void)
500{ 500{
501 return ide_pci_register_driver(&driver); 501 return ide_pci_register_driver(&via_pci_driver);
502} 502}
503 503
504static void __exit via_ide_exit(void) 504static void __exit via_ide_exit(void)
505{ 505{
506 pci_unregister_driver(&driver); 506 pci_unregister_driver(&via_pci_driver);
507} 507}
508 508
509module_init(via_ide_init); 509module_init(via_ide_init);
diff --git a/drivers/ide/ppc/pmac.c b/drivers/ide/ppc/pmac.c
index c3432da78d52..2e19d6298536 100644
--- a/drivers/ide/ppc/pmac.c
+++ b/drivers/ide/ppc/pmac.c
@@ -430,10 +430,7 @@ pmac_ide_selectproc(ide_drive_t *drive)
430 pmac_ide_hwif_t *pmif = 430 pmac_ide_hwif_t *pmif =
431 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 431 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
432 432
433 if (pmif == NULL) 433 if (drive->dn & 1)
434 return;
435
436 if (drive->select.b.unit & 0x01)
437 writel(pmif->timings[1], PMAC_IDE_REG(IDE_TIMING_CONFIG)); 434 writel(pmif->timings[1], PMAC_IDE_REG(IDE_TIMING_CONFIG));
438 else 435 else
439 writel(pmif->timings[0], PMAC_IDE_REG(IDE_TIMING_CONFIG)); 436 writel(pmif->timings[0], PMAC_IDE_REG(IDE_TIMING_CONFIG));
@@ -452,10 +449,7 @@ pmac_ide_kauai_selectproc(ide_drive_t *drive)
452 pmac_ide_hwif_t *pmif = 449 pmac_ide_hwif_t *pmif =
453 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 450 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
454 451
455 if (pmif == NULL) 452 if (drive->dn & 1) {
456 return;
457
458 if (drive->select.b.unit & 0x01) {
459 writel(pmif->timings[1], PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG)); 453 writel(pmif->timings[1], PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG));
460 writel(pmif->timings[3], PMAC_IDE_REG(IDE_KAUAI_ULTRA_CONFIG)); 454 writel(pmif->timings[3], PMAC_IDE_REG(IDE_KAUAI_ULTRA_CONFIG));
461 } else { 455 } else {
@@ -475,9 +469,6 @@ pmac_ide_do_update_timings(ide_drive_t *drive)
475 pmac_ide_hwif_t *pmif = 469 pmac_ide_hwif_t *pmif =
476 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 470 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
477 471
478 if (pmif == NULL)
479 return;
480
481 if (pmif->kind == controller_sh_ata6 || 472 if (pmif->kind == controller_sh_ata6 ||
482 pmif->kind == controller_un_ata6 || 473 pmif->kind == controller_un_ata6 ||
483 pmif->kind == controller_k2_ata6) 474 pmif->kind == controller_k2_ata6)
@@ -524,11 +515,8 @@ pmac_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
524 unsigned accessTime, recTime; 515 unsigned accessTime, recTime;
525 unsigned int cycle_time; 516 unsigned int cycle_time;
526 517
527 if (pmif == NULL)
528 return;
529
530 /* which drive is it ? */ 518 /* which drive is it ? */
531 timings = &pmif->timings[drive->select.b.unit & 0x01]; 519 timings = &pmif->timings[drive->dn & 1];
532 t = *timings; 520 t = *timings;
533 521
534 cycle_time = ide_pio_cycle_time(drive, pio); 522 cycle_time = ide_pio_cycle_time(drive, pio);
@@ -805,9 +793,9 @@ static void pmac_ide_set_dma_mode(ide_drive_t *drive, const u8 speed)
805 ide_hwif_t *hwif = drive->hwif; 793 ide_hwif_t *hwif = drive->hwif;
806 pmac_ide_hwif_t *pmif = 794 pmac_ide_hwif_t *pmif =
807 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 795 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
808 int unit = (drive->select.b.unit & 0x01);
809 int ret = 0; 796 int ret = 0;
810 u32 *timings, *timings2, tl[2]; 797 u32 *timings, *timings2, tl[2];
798 u8 unit = drive->dn & 1;
811 799
812 timings = &pmif->timings[unit]; 800 timings = &pmif->timings[unit];
813 timings2 = &pmif->timings[unit+2]; 801 timings2 = &pmif->timings[unit+2];
@@ -966,11 +954,11 @@ static void pmac_ide_init_dev(ide_drive_t *drive)
966 if (pmif->mediabay) { 954 if (pmif->mediabay) {
967#ifdef CONFIG_PMAC_MEDIABAY 955#ifdef CONFIG_PMAC_MEDIABAY
968 if (check_media_bay_by_base(pmif->regbase, MB_CD) == 0) { 956 if (check_media_bay_by_base(pmif->regbase, MB_CD) == 0) {
969 drive->noprobe = 0; 957 drive->dev_flags &= ~IDE_DFLAG_NOPROBE;
970 return; 958 return;
971 } 959 }
972#endif 960#endif
973 drive->noprobe = 1; 961 drive->dev_flags |= IDE_DFLAG_NOPROBE;
974 } 962 }
975} 963}
976 964
@@ -1535,18 +1523,6 @@ use_pio_instead:
1535 return 0; /* revert to PIO for this request */ 1523 return 0; /* revert to PIO for this request */
1536} 1524}
1537 1525
1538/* Teardown mappings after DMA has completed. */
1539static void
1540pmac_ide_destroy_dmatable (ide_drive_t *drive)
1541{
1542 ide_hwif_t *hwif = drive->hwif;
1543
1544 if (hwif->sg_nents) {
1545 ide_destroy_dmatable(drive);
1546 hwif->sg_nents = 0;
1547 }
1548}
1549
1550/* 1526/*
1551 * Prepare a DMA transfer. We build the DMA table, adjust the timings for 1527 * Prepare a DMA transfer. We build the DMA table, adjust the timings for
1552 * a read on KeyLargo ATA/66 and mark us as waiting for DMA completion 1528 * a read on KeyLargo ATA/66 and mark us as waiting for DMA completion
@@ -1558,12 +1534,7 @@ pmac_ide_dma_setup(ide_drive_t *drive)
1558 pmac_ide_hwif_t *pmif = 1534 pmac_ide_hwif_t *pmif =
1559 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 1535 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
1560 struct request *rq = HWGROUP(drive)->rq; 1536 struct request *rq = HWGROUP(drive)->rq;
1561 u8 unit = (drive->select.b.unit & 0x01); 1537 u8 unit = drive->dn & 1, ata4 = (pmif->kind == controller_kl_ata4);
1562 u8 ata4;
1563
1564 if (pmif == NULL)
1565 return 1;
1566 ata4 = (pmif->kind == controller_kl_ata4);
1567 1538
1568 if (!pmac_ide_build_dmatable(drive, rq)) { 1539 if (!pmac_ide_build_dmatable(drive, rq)) {
1569 ide_map_sg(drive, rq); 1540 ide_map_sg(drive, rq);
@@ -1617,17 +1588,15 @@ pmac_ide_dma_end (ide_drive_t *drive)
1617 ide_hwif_t *hwif = drive->hwif; 1588 ide_hwif_t *hwif = drive->hwif;
1618 pmac_ide_hwif_t *pmif = 1589 pmac_ide_hwif_t *pmif =
1619 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 1590 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
1620 volatile struct dbdma_regs __iomem *dma; 1591 volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
1621 u32 dstat; 1592 u32 dstat;
1622
1623 if (pmif == NULL)
1624 return 0;
1625 dma = pmif->dma_regs;
1626 1593
1627 drive->waiting_for_dma = 0; 1594 drive->waiting_for_dma = 0;
1628 dstat = readl(&dma->status); 1595 dstat = readl(&dma->status);
1629 writel(((RUN|WAKE|DEAD) << 16), &dma->control); 1596 writel(((RUN|WAKE|DEAD) << 16), &dma->control);
1630 pmac_ide_destroy_dmatable(drive); 1597
1598 ide_destroy_dmatable(drive);
1599
1631 /* verify good dma status. we don't check for ACTIVE beeing 0. We should... 1600 /* verify good dma status. we don't check for ACTIVE beeing 0. We should...
1632 * in theory, but with ATAPI decices doing buffer underruns, that would 1601 * in theory, but with ATAPI decices doing buffer underruns, that would
1633 * cause us to disable DMA, which isn't what we want 1602 * cause us to disable DMA, which isn't what we want
@@ -1647,13 +1616,9 @@ pmac_ide_dma_test_irq (ide_drive_t *drive)
1647 ide_hwif_t *hwif = drive->hwif; 1616 ide_hwif_t *hwif = drive->hwif;
1648 pmac_ide_hwif_t *pmif = 1617 pmac_ide_hwif_t *pmif =
1649 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 1618 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
1650 volatile struct dbdma_regs __iomem *dma; 1619 volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
1651 unsigned long status, timeout; 1620 unsigned long status, timeout;
1652 1621
1653 if (pmif == NULL)
1654 return 0;
1655 dma = pmif->dma_regs;
1656
1657 /* We have to things to deal with here: 1622 /* We have to things to deal with here:
1658 * 1623 *
1659 * - The dbdma won't stop if the command was started 1624 * - The dbdma won't stop if the command was started
@@ -1672,9 +1637,6 @@ pmac_ide_dma_test_irq (ide_drive_t *drive)
1672 status = readl(&dma->status); 1637 status = readl(&dma->status);
1673 if (!(status & ACTIVE)) 1638 if (!(status & ACTIVE))
1674 return 1; 1639 return 1;
1675 if (!drive->waiting_for_dma)
1676 printk(KERN_WARNING "ide%d, ide_dma_test_irq \
1677 called while not waiting\n", HWIF(drive)->index);
1678 1640
1679 /* If dbdma didn't execute the STOP command yet, the 1641 /* If dbdma didn't execute the STOP command yet, the
1680 * active bit is still set. We consider that we aren't 1642 * active bit is still set. We consider that we aren't
@@ -1709,14 +1671,9 @@ pmac_ide_dma_lost_irq (ide_drive_t *drive)
1709 ide_hwif_t *hwif = drive->hwif; 1671 ide_hwif_t *hwif = drive->hwif;
1710 pmac_ide_hwif_t *pmif = 1672 pmac_ide_hwif_t *pmif =
1711 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent); 1673 (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
1712 volatile struct dbdma_regs __iomem *dma; 1674 volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
1713 unsigned long status; 1675 unsigned long status = readl(&dma->status);
1714
1715 if (pmif == NULL)
1716 return;
1717 dma = pmif->dma_regs;
1718 1676
1719 status = readl(&dma->status);
1720 printk(KERN_ERR "ide-pmac lost interrupt, dma status: %lx\n", status); 1677 printk(KERN_ERR "ide-pmac lost interrupt, dma status: %lx\n", status);
1721} 1678}
1722 1679
diff --git a/drivers/ieee1394/csr1212.c b/drivers/ieee1394/csr1212.c
index 9f95337139e3..5e38a68b8af2 100644
--- a/drivers/ieee1394/csr1212.c
+++ b/drivers/ieee1394/csr1212.c
@@ -84,7 +84,7 @@ static const u8 csr1212_key_id_type_map[0x30] = {
84 84
85 85
86#define quads_to_bytes(_q) ((_q) * sizeof(u32)) 86#define quads_to_bytes(_q) ((_q) * sizeof(u32))
87#define bytes_to_quads(_b) (((_b) + sizeof(u32) - 1) / sizeof(u32)) 87#define bytes_to_quads(_b) DIV_ROUND_UP(_b, sizeof(u32))
88 88
89static void free_keyval(struct csr1212_keyval *kv) 89static void free_keyval(struct csr1212_keyval *kv)
90{ 90{
diff --git a/drivers/ieee1394/dv1394.c b/drivers/ieee1394/dv1394.c
index b6eb2cf25914..2f83543a9dfc 100644
--- a/drivers/ieee1394/dv1394.c
+++ b/drivers/ieee1394/dv1394.c
@@ -918,7 +918,7 @@ static int do_dv1394_init(struct video_card *video, struct dv1394_init *init)
918 /* default SYT offset is 3 cycles */ 918 /* default SYT offset is 3 cycles */
919 init->syt_offset = 3; 919 init->syt_offset = 3;
920 920
921 if ( (init->channel > 63) || (init->channel < 0) ) 921 if (init->channel > 63)
922 init->channel = 63; 922 init->channel = 63;
923 923
924 chan_mask = (u64)1 << init->channel; 924 chan_mask = (u64)1 << init->channel;
@@ -2296,10 +2296,10 @@ static void dv1394_add_host(struct hpsb_host *host)
2296 2296
2297 ohci = (struct ti_ohci *)host->hostdata; 2297 ohci = (struct ti_ohci *)host->hostdata;
2298 2298
2299 device_create_drvdata(hpsb_protocol_class, NULL, 2299 device_create(hpsb_protocol_class, NULL,
2300 MKDEV(IEEE1394_MAJOR, 2300 MKDEV(IEEE1394_MAJOR,
2301 IEEE1394_MINOR_BLOCK_DV1394 * 16 + (id<<2)), NULL, 2301 IEEE1394_MINOR_BLOCK_DV1394 * 16 + (id<<2)),
2302 "dv1394-%d", id); 2302 NULL, "dv1394-%d", id);
2303 2303
2304 dv1394_init(ohci, DV1394_NTSC, MODE_RECEIVE); 2304 dv1394_init(ohci, DV1394_NTSC, MODE_RECEIVE);
2305 dv1394_init(ohci, DV1394_NTSC, MODE_TRANSMIT); 2305 dv1394_init(ohci, DV1394_NTSC, MODE_TRANSMIT);
diff --git a/drivers/ieee1394/eth1394.c b/drivers/ieee1394/eth1394.c
index b166b3575fa6..20128692b339 100644
--- a/drivers/ieee1394/eth1394.c
+++ b/drivers/ieee1394/eth1394.c
@@ -1361,7 +1361,7 @@ static unsigned int ether1394_encapsulate_prep(unsigned int max_payload,
1361 hdr->ff.dgl = dgl; 1361 hdr->ff.dgl = dgl;
1362 adj_max_payload = max_payload - hdr_type_len[ETH1394_HDR_LF_FF]; 1362 adj_max_payload = max_payload - hdr_type_len[ETH1394_HDR_LF_FF];
1363 } 1363 }
1364 return (dg_size + adj_max_payload - 1) / adj_max_payload; 1364 return DIV_ROUND_UP(dg_size, adj_max_payload);
1365} 1365}
1366 1366
1367static unsigned int ether1394_encapsulate(struct sk_buff *skb, 1367static unsigned int ether1394_encapsulate(struct sk_buff *skb,
diff --git a/drivers/ieee1394/nodemgr.c b/drivers/ieee1394/nodemgr.c
index 16240a789650..2376b729e876 100644
--- a/drivers/ieee1394/nodemgr.c
+++ b/drivers/ieee1394/nodemgr.c
@@ -154,9 +154,6 @@ struct host_info {
154 154
155static int nodemgr_bus_match(struct device * dev, struct device_driver * drv); 155static int nodemgr_bus_match(struct device * dev, struct device_driver * drv);
156static int nodemgr_uevent(struct device *dev, struct kobj_uevent_env *env); 156static int nodemgr_uevent(struct device *dev, struct kobj_uevent_env *env);
157static void nodemgr_resume_ne(struct node_entry *ne);
158static void nodemgr_remove_ne(struct node_entry *ne);
159static struct node_entry *find_entry_by_guid(u64 guid);
160 157
161struct bus_type ieee1394_bus_type = { 158struct bus_type ieee1394_bus_type = {
162 .name = "ieee1394", 159 .name = "ieee1394",
@@ -385,27 +382,6 @@ static ssize_t fw_get_ignore_driver(struct device *dev, struct device_attribute
385static DEVICE_ATTR(ignore_driver, S_IWUSR | S_IRUGO, fw_get_ignore_driver, fw_set_ignore_driver); 382static DEVICE_ATTR(ignore_driver, S_IWUSR | S_IRUGO, fw_get_ignore_driver, fw_set_ignore_driver);
386 383
387 384
388static ssize_t fw_set_destroy_node(struct bus_type *bus, const char *buf, size_t count)
389{
390 struct node_entry *ne;
391 u64 guid = (u64)simple_strtoull(buf, NULL, 16);
392
393 ne = find_entry_by_guid(guid);
394
395 if (ne == NULL || !ne->in_limbo)
396 return -EINVAL;
397
398 nodemgr_remove_ne(ne);
399
400 return count;
401}
402static ssize_t fw_get_destroy_node(struct bus_type *bus, char *buf)
403{
404 return sprintf(buf, "You can destroy in_limbo nodes by writing their GUID to this file\n");
405}
406static BUS_ATTR(destroy_node, S_IWUSR | S_IRUGO, fw_get_destroy_node, fw_set_destroy_node);
407
408
409static ssize_t fw_set_rescan(struct bus_type *bus, const char *buf, 385static ssize_t fw_set_rescan(struct bus_type *bus, const char *buf,
410 size_t count) 386 size_t count)
411{ 387{
@@ -442,7 +418,6 @@ static BUS_ATTR(ignore_drivers, S_IWUSR | S_IRUGO, fw_get_ignore_drivers, fw_set
442 418
443 419
444struct bus_attribute *const fw_bus_attrs[] = { 420struct bus_attribute *const fw_bus_attrs[] = {
445 &bus_attr_destroy_node,
446 &bus_attr_rescan, 421 &bus_attr_rescan,
447 &bus_attr_ignore_drivers, 422 &bus_attr_ignore_drivers,
448 NULL 423 NULL
@@ -734,10 +709,10 @@ static int nodemgr_bus_match(struct device * dev, struct device_driver * drv)
734 709
735static DEFINE_MUTEX(nodemgr_serialize_remove_uds); 710static DEFINE_MUTEX(nodemgr_serialize_remove_uds);
736 711
737static int __match_ne(struct device *dev, void *data) 712static int match_ne(struct device *dev, void *data)
738{ 713{
739 struct unit_directory *ud; 714 struct unit_directory *ud;
740 struct node_entry *ne = (struct node_entry *)data; 715 struct node_entry *ne = data;
741 716
742 ud = container_of(dev, struct unit_directory, unit_dev); 717 ud = container_of(dev, struct unit_directory, unit_dev);
743 return ud->ne == ne; 718 return ud->ne == ne;
@@ -754,8 +729,7 @@ static void nodemgr_remove_uds(struct node_entry *ne)
754 */ 729 */
755 mutex_lock(&nodemgr_serialize_remove_uds); 730 mutex_lock(&nodemgr_serialize_remove_uds);
756 for (;;) { 731 for (;;) {
757 dev = class_find_device(&nodemgr_ud_class, NULL, ne, 732 dev = class_find_device(&nodemgr_ud_class, NULL, ne, match_ne);
758 __match_ne);
759 if (!dev) 733 if (!dev)
760 break; 734 break;
761 ud = container_of(dev, struct unit_directory, unit_dev); 735 ud = container_of(dev, struct unit_directory, unit_dev);
@@ -785,7 +759,7 @@ static void nodemgr_remove_ne(struct node_entry *ne)
785 put_device(dev); 759 put_device(dev);
786} 760}
787 761
788static int __nodemgr_remove_host_dev(struct device *dev, void *data) 762static int remove_host_dev(struct device *dev, void *data)
789{ 763{
790 if (dev->bus == &ieee1394_bus_type) 764 if (dev->bus == &ieee1394_bus_type)
791 nodemgr_remove_ne(container_of(dev, struct node_entry, 765 nodemgr_remove_ne(container_of(dev, struct node_entry,
@@ -795,7 +769,7 @@ static int __nodemgr_remove_host_dev(struct device *dev, void *data)
795 769
796static void nodemgr_remove_host_dev(struct device *dev) 770static void nodemgr_remove_host_dev(struct device *dev)
797{ 771{
798 WARN_ON(device_for_each_child(dev, NULL, __nodemgr_remove_host_dev)); 772 device_for_each_child(dev, NULL, remove_host_dev);
799 sysfs_remove_link(&dev->kobj, "irm_id"); 773 sysfs_remove_link(&dev->kobj, "irm_id");
800 sysfs_remove_link(&dev->kobj, "busmgr_id"); 774 sysfs_remove_link(&dev->kobj, "busmgr_id");
801 sysfs_remove_link(&dev->kobj, "host_id"); 775 sysfs_remove_link(&dev->kobj, "host_id");
@@ -830,11 +804,10 @@ static void nodemgr_update_bus_options(struct node_entry *ne)
830} 804}
831 805
832 806
833static struct node_entry *nodemgr_create_node(octlet_t guid, struct csr1212_csr *csr, 807static struct node_entry *nodemgr_create_node(octlet_t guid,
834 struct host_info *hi, nodeid_t nodeid, 808 struct csr1212_csr *csr, struct hpsb_host *host,
835 unsigned int generation) 809 nodeid_t nodeid, unsigned int generation)
836{ 810{
837 struct hpsb_host *host = hi->host;
838 struct node_entry *ne; 811 struct node_entry *ne;
839 812
840 ne = kzalloc(sizeof(*ne), GFP_KERNEL); 813 ne = kzalloc(sizeof(*ne), GFP_KERNEL);
@@ -888,10 +861,10 @@ fail_alloc:
888 return NULL; 861 return NULL;
889} 862}
890 863
891static int __match_ne_guid(struct device *dev, void *data) 864static int match_ne_guid(struct device *dev, void *data)
892{ 865{
893 struct node_entry *ne; 866 struct node_entry *ne;
894 u64 *guid = (u64 *)data; 867 u64 *guid = data;
895 868
896 ne = container_of(dev, struct node_entry, node_dev); 869 ne = container_of(dev, struct node_entry, node_dev);
897 return ne->guid == *guid; 870 return ne->guid == *guid;
@@ -902,8 +875,7 @@ static struct node_entry *find_entry_by_guid(u64 guid)
902 struct device *dev; 875 struct device *dev;
903 struct node_entry *ne; 876 struct node_entry *ne;
904 877
905 dev = class_find_device(&nodemgr_ne_class, NULL, &guid, 878 dev = class_find_device(&nodemgr_ne_class, NULL, &guid, match_ne_guid);
906 __match_ne_guid);
907 if (!dev) 879 if (!dev)
908 return NULL; 880 return NULL;
909 ne = container_of(dev, struct node_entry, node_dev); 881 ne = container_of(dev, struct node_entry, node_dev);
@@ -912,21 +884,21 @@ static struct node_entry *find_entry_by_guid(u64 guid)
912 return ne; 884 return ne;
913} 885}
914 886
915struct match_nodeid_param { 887struct match_nodeid_parameter {
916 struct hpsb_host *host; 888 struct hpsb_host *host;
917 nodeid_t nodeid; 889 nodeid_t nodeid;
918}; 890};
919 891
920static int __match_ne_nodeid(struct device *dev, void *data) 892static int match_ne_nodeid(struct device *dev, void *data)
921{ 893{
922 int found = 0; 894 int found = 0;
923 struct node_entry *ne; 895 struct node_entry *ne;
924 struct match_nodeid_param *param = (struct match_nodeid_param *)data; 896 struct match_nodeid_parameter *p = data;
925 897
926 if (!dev) 898 if (!dev)
927 goto ret; 899 goto ret;
928 ne = container_of(dev, struct node_entry, node_dev); 900 ne = container_of(dev, struct node_entry, node_dev);
929 if (ne->host == param->host && ne->nodeid == param->nodeid) 901 if (ne->host == p->host && ne->nodeid == p->nodeid)
930 found = 1; 902 found = 1;
931ret: 903ret:
932 return found; 904 return found;
@@ -937,13 +909,12 @@ static struct node_entry *find_entry_by_nodeid(struct hpsb_host *host,
937{ 909{
938 struct device *dev; 910 struct device *dev;
939 struct node_entry *ne; 911 struct node_entry *ne;
940 struct match_nodeid_param param; 912 struct match_nodeid_parameter p;
941 913
942 param.host = host; 914 p.host = host;
943 param.nodeid = nodeid; 915 p.nodeid = nodeid;
944 916
945 dev = class_find_device(&nodemgr_ne_class, NULL, &param, 917 dev = class_find_device(&nodemgr_ne_class, NULL, &p, match_ne_nodeid);
946 __match_ne_nodeid);
947 if (!dev) 918 if (!dev)
948 return NULL; 919 return NULL;
949 ne = container_of(dev, struct node_entry, node_dev); 920 ne = container_of(dev, struct node_entry, node_dev);
@@ -990,7 +961,7 @@ fail_devreg:
990 * immediate unit directories looking for software_id and 961 * immediate unit directories looking for software_id and
991 * software_version entries, in order to get driver autoloading working. */ 962 * software_version entries, in order to get driver autoloading working. */
992static struct unit_directory *nodemgr_process_unit_directory 963static struct unit_directory *nodemgr_process_unit_directory
993 (struct host_info *hi, struct node_entry *ne, struct csr1212_keyval *ud_kv, 964 (struct node_entry *ne, struct csr1212_keyval *ud_kv,
994 unsigned int *id, struct unit_directory *parent) 965 unsigned int *id, struct unit_directory *parent)
995{ 966{
996 struct unit_directory *ud; 967 struct unit_directory *ud;
@@ -1083,7 +1054,7 @@ static struct unit_directory *nodemgr_process_unit_directory
1083 nodemgr_register_device(ne, ud, &ne->device); 1054 nodemgr_register_device(ne, ud, &ne->device);
1084 1055
1085 /* process the child unit */ 1056 /* process the child unit */
1086 ud_child = nodemgr_process_unit_directory(hi, ne, kv, id, ud); 1057 ud_child = nodemgr_process_unit_directory(ne, kv, id, ud);
1087 1058
1088 if (ud_child == NULL) 1059 if (ud_child == NULL)
1089 break; 1060 break;
@@ -1137,7 +1108,7 @@ unit_directory_error:
1137} 1108}
1138 1109
1139 1110
1140static void nodemgr_process_root_directory(struct host_info *hi, struct node_entry *ne) 1111static void nodemgr_process_root_directory(struct node_entry *ne)
1141{ 1112{
1142 unsigned int ud_id = 0; 1113 unsigned int ud_id = 0;
1143 struct csr1212_dentry *dentry; 1114 struct csr1212_dentry *dentry;
@@ -1157,7 +1128,7 @@ static void nodemgr_process_root_directory(struct host_info *hi, struct node_ent
1157 break; 1128 break;
1158 1129
1159 case CSR1212_KV_ID_UNIT: 1130 case CSR1212_KV_ID_UNIT:
1160 nodemgr_process_unit_directory(hi, ne, kv, &ud_id, NULL); 1131 nodemgr_process_unit_directory(ne, kv, &ud_id, NULL);
1161 break; 1132 break;
1162 1133
1163 case CSR1212_KV_ID_DESCRIPTOR: 1134 case CSR1212_KV_ID_DESCRIPTOR:
@@ -1273,8 +1244,7 @@ void hpsb_unregister_protocol(struct hpsb_protocol_driver *driver)
1273 * the to take whatever actions required. 1244 * the to take whatever actions required.
1274 */ 1245 */
1275static void nodemgr_update_node(struct node_entry *ne, struct csr1212_csr *csr, 1246static void nodemgr_update_node(struct node_entry *ne, struct csr1212_csr *csr,
1276 struct host_info *hi, nodeid_t nodeid, 1247 nodeid_t nodeid, unsigned int generation)
1277 unsigned int generation)
1278{ 1248{
1279 if (ne->nodeid != nodeid) { 1249 if (ne->nodeid != nodeid) {
1280 HPSB_DEBUG("Node changed: " NODE_BUS_FMT " -> " NODE_BUS_FMT, 1250 HPSB_DEBUG("Node changed: " NODE_BUS_FMT " -> " NODE_BUS_FMT,
@@ -1305,19 +1275,23 @@ static void nodemgr_update_node(struct node_entry *ne, struct csr1212_csr *csr,
1305 csr1212_destroy_csr(csr); 1275 csr1212_destroy_csr(csr);
1306 } 1276 }
1307 1277
1308 if (ne->in_limbo)
1309 nodemgr_resume_ne(ne);
1310
1311 /* Mark the node current */ 1278 /* Mark the node current */
1312 ne->generation = generation; 1279 ne->generation = generation;
1313}
1314 1280
1281 if (ne->in_limbo) {
1282 device_remove_file(&ne->device, &dev_attr_ne_in_limbo);
1283 ne->in_limbo = false;
1315 1284
1285 HPSB_DEBUG("Node reactivated: "
1286 "ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
1287 NODE_BUS_ARGS(ne->host, ne->nodeid),
1288 (unsigned long long)ne->guid);
1289 }
1290}
1316 1291
1317static void nodemgr_node_scan_one(struct host_info *hi, 1292static void nodemgr_node_scan_one(struct hpsb_host *host,
1318 nodeid_t nodeid, int generation) 1293 nodeid_t nodeid, int generation)
1319{ 1294{
1320 struct hpsb_host *host = hi->host;
1321 struct node_entry *ne; 1295 struct node_entry *ne;
1322 octlet_t guid; 1296 octlet_t guid;
1323 struct csr1212_csr *csr; 1297 struct csr1212_csr *csr;
@@ -1373,16 +1347,15 @@ static void nodemgr_node_scan_one(struct host_info *hi,
1373 } 1347 }
1374 1348
1375 if (!ne) 1349 if (!ne)
1376 nodemgr_create_node(guid, csr, hi, nodeid, generation); 1350 nodemgr_create_node(guid, csr, host, nodeid, generation);
1377 else 1351 else
1378 nodemgr_update_node(ne, csr, hi, nodeid, generation); 1352 nodemgr_update_node(ne, csr, nodeid, generation);
1379} 1353}
1380 1354
1381 1355
1382static void nodemgr_node_scan(struct host_info *hi, int generation) 1356static void nodemgr_node_scan(struct hpsb_host *host, int generation)
1383{ 1357{
1384 int count; 1358 int count;
1385 struct hpsb_host *host = hi->host;
1386 struct selfid *sid = (struct selfid *)host->topology_map; 1359 struct selfid *sid = (struct selfid *)host->topology_map;
1387 nodeid_t nodeid = LOCAL_BUS; 1360 nodeid_t nodeid = LOCAL_BUS;
1388 1361
@@ -1395,89 +1368,26 @@ static void nodemgr_node_scan(struct host_info *hi, int generation)
1395 nodeid++; 1368 nodeid++;
1396 continue; 1369 continue;
1397 } 1370 }
1398 nodemgr_node_scan_one(hi, nodeid++, generation); 1371 nodemgr_node_scan_one(host, nodeid++, generation);
1399 }
1400}
1401
1402static int __nodemgr_driver_suspend(struct device *dev, void *data)
1403{
1404 struct unit_directory *ud;
1405 struct device_driver *drv;
1406 struct node_entry *ne = (struct node_entry *)data;
1407 int error;
1408
1409 ud = container_of(dev, struct unit_directory, unit_dev);
1410 if (ud->ne == ne) {
1411 drv = get_driver(ud->device.driver);
1412 if (drv) {
1413 error = 1; /* release if suspend is not implemented */
1414 if (drv->suspend) {
1415 down(&ud->device.sem);
1416 error = drv->suspend(&ud->device, PMSG_SUSPEND);
1417 up(&ud->device.sem);
1418 }
1419 if (error)
1420 device_release_driver(&ud->device);
1421 put_driver(drv);
1422 }
1423 }
1424
1425 return 0;
1426}
1427
1428static int __nodemgr_driver_resume(struct device *dev, void *data)
1429{
1430 struct unit_directory *ud;
1431 struct device_driver *drv;
1432 struct node_entry *ne = (struct node_entry *)data;
1433
1434 ud = container_of(dev, struct unit_directory, unit_dev);
1435 if (ud->ne == ne) {
1436 drv = get_driver(ud->device.driver);
1437 if (drv) {
1438 if (drv->resume) {
1439 down(&ud->device.sem);
1440 drv->resume(&ud->device);
1441 up(&ud->device.sem);
1442 }
1443 put_driver(drv);
1444 }
1445 } 1372 }
1446
1447 return 0;
1448} 1373}
1449 1374
1450static void nodemgr_suspend_ne(struct node_entry *ne) 1375static void nodemgr_pause_ne(struct node_entry *ne)
1451{ 1376{
1452 HPSB_DEBUG("Node suspended: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]", 1377 HPSB_DEBUG("Node paused: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
1453 NODE_BUS_ARGS(ne->host, ne->nodeid), 1378 NODE_BUS_ARGS(ne->host, ne->nodeid),
1454 (unsigned long long)ne->guid); 1379 (unsigned long long)ne->guid);
1455 1380
1456 ne->in_limbo = 1; 1381 ne->in_limbo = true;
1457 WARN_ON(device_create_file(&ne->device, &dev_attr_ne_in_limbo)); 1382 WARN_ON(device_create_file(&ne->device, &dev_attr_ne_in_limbo));
1458
1459 class_for_each_device(&nodemgr_ud_class, NULL, ne,
1460 __nodemgr_driver_suspend);
1461}
1462
1463
1464static void nodemgr_resume_ne(struct node_entry *ne)
1465{
1466 ne->in_limbo = 0;
1467 device_remove_file(&ne->device, &dev_attr_ne_in_limbo);
1468
1469 class_for_each_device(&nodemgr_ud_class, NULL, ne,
1470 __nodemgr_driver_resume);
1471 HPSB_DEBUG("Node resumed: ID:BUS[" NODE_BUS_FMT "] GUID[%016Lx]",
1472 NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid);
1473} 1383}
1474 1384
1475static int __nodemgr_update_pdrv(struct device *dev, void *data) 1385static int update_pdrv(struct device *dev, void *data)
1476{ 1386{
1477 struct unit_directory *ud; 1387 struct unit_directory *ud;
1478 struct device_driver *drv; 1388 struct device_driver *drv;
1479 struct hpsb_protocol_driver *pdrv; 1389 struct hpsb_protocol_driver *pdrv;
1480 struct node_entry *ne = (struct node_entry *)data; 1390 struct node_entry *ne = data;
1481 int error; 1391 int error;
1482 1392
1483 ud = container_of(dev, struct unit_directory, unit_dev); 1393 ud = container_of(dev, struct unit_directory, unit_dev);
@@ -1503,11 +1413,9 @@ static int __nodemgr_update_pdrv(struct device *dev, void *data)
1503 1413
1504static void nodemgr_update_pdrv(struct node_entry *ne) 1414static void nodemgr_update_pdrv(struct node_entry *ne)
1505{ 1415{
1506 class_for_each_device(&nodemgr_ud_class, NULL, ne, 1416 class_for_each_device(&nodemgr_ud_class, NULL, ne, update_pdrv);
1507 __nodemgr_update_pdrv);
1508} 1417}
1509 1418
1510
1511/* Write the BROADCAST_CHANNEL as per IEEE1394a 8.3.2.3.11 and 8.4.2.3. This 1419/* Write the BROADCAST_CHANNEL as per IEEE1394a 8.3.2.3.11 and 8.4.2.3. This
1512 * seems like an optional service but in the end it is practically mandatory 1420 * seems like an optional service but in the end it is practically mandatory
1513 * as a consequence of these clauses. 1421 * as a consequence of these clauses.
@@ -1535,11 +1443,12 @@ static void nodemgr_irm_write_bc(struct node_entry *ne, int generation)
1535} 1443}
1536 1444
1537 1445
1538static void nodemgr_probe_ne(struct host_info *hi, struct node_entry *ne, int generation) 1446static void nodemgr_probe_ne(struct hpsb_host *host, struct node_entry *ne,
1447 int generation)
1539{ 1448{
1540 struct device *dev; 1449 struct device *dev;
1541 1450
1542 if (ne->host != hi->host || ne->in_limbo) 1451 if (ne->host != host || ne->in_limbo)
1543 return; 1452 return;
1544 1453
1545 dev = get_device(&ne->device); 1454 dev = get_device(&ne->device);
@@ -1554,40 +1463,40 @@ static void nodemgr_probe_ne(struct host_info *hi, struct node_entry *ne, int ge
1554 * down to the drivers. Otherwise, this is a dead node and we 1463 * down to the drivers. Otherwise, this is a dead node and we
1555 * suspend it. */ 1464 * suspend it. */
1556 if (ne->needs_probe) 1465 if (ne->needs_probe)
1557 nodemgr_process_root_directory(hi, ne); 1466 nodemgr_process_root_directory(ne);
1558 else if (ne->generation == generation) 1467 else if (ne->generation == generation)
1559 nodemgr_update_pdrv(ne); 1468 nodemgr_update_pdrv(ne);
1560 else 1469 else
1561 nodemgr_suspend_ne(ne); 1470 nodemgr_pause_ne(ne);
1562 1471
1563 put_device(dev); 1472 put_device(dev);
1564} 1473}
1565 1474
1566struct probe_param { 1475struct node_probe_parameter {
1567 struct host_info *hi; 1476 struct hpsb_host *host;
1568 int generation; 1477 int generation;
1569 bool probe_now; 1478 bool probe_now;
1570}; 1479};
1571 1480
1572static int node_probe(struct device *dev, void *data) 1481static int node_probe(struct device *dev, void *data)
1573{ 1482{
1574 struct probe_param *p = data; 1483 struct node_probe_parameter *p = data;
1575 struct node_entry *ne; 1484 struct node_entry *ne;
1576 1485
1577 if (p->generation != get_hpsb_generation(p->hi->host)) 1486 if (p->generation != get_hpsb_generation(p->host))
1578 return -EAGAIN; 1487 return -EAGAIN;
1579 1488
1580 ne = container_of(dev, struct node_entry, node_dev); 1489 ne = container_of(dev, struct node_entry, node_dev);
1581 if (ne->needs_probe == p->probe_now) 1490 if (ne->needs_probe == p->probe_now)
1582 nodemgr_probe_ne(p->hi, ne, p->generation); 1491 nodemgr_probe_ne(p->host, ne, p->generation);
1583 return 0; 1492 return 0;
1584} 1493}
1585 1494
1586static void nodemgr_node_probe(struct host_info *hi, int generation) 1495static int nodemgr_node_probe(struct hpsb_host *host, int generation)
1587{ 1496{
1588 struct probe_param p; 1497 struct node_probe_parameter p;
1589 1498
1590 p.hi = hi; 1499 p.host = host;
1591 p.generation = generation; 1500 p.generation = generation;
1592 /* 1501 /*
1593 * Do some processing of the nodes we've probed. This pulls them 1502 * Do some processing of the nodes we've probed. This pulls them
@@ -1604,11 +1513,11 @@ static void nodemgr_node_probe(struct host_info *hi, int generation)
1604 */ 1513 */
1605 p.probe_now = false; 1514 p.probe_now = false;
1606 if (class_for_each_device(&nodemgr_ne_class, NULL, &p, node_probe) != 0) 1515 if (class_for_each_device(&nodemgr_ne_class, NULL, &p, node_probe) != 0)
1607 return; 1516 return 0;
1608 1517
1609 p.probe_now = true; 1518 p.probe_now = true;
1610 if (class_for_each_device(&nodemgr_ne_class, NULL, &p, node_probe) != 0) 1519 if (class_for_each_device(&nodemgr_ne_class, NULL, &p, node_probe) != 0)
1611 return; 1520 return 0;
1612 /* 1521 /*
1613 * Now let's tell the bus to rescan our devices. This may seem 1522 * Now let's tell the bus to rescan our devices. This may seem
1614 * like overhead, but the driver-model core will only scan a 1523 * like overhead, but the driver-model core will only scan a
@@ -1620,6 +1529,27 @@ static void nodemgr_node_probe(struct host_info *hi, int generation)
1620 */ 1529 */
1621 if (bus_rescan_devices(&ieee1394_bus_type) != 0) 1530 if (bus_rescan_devices(&ieee1394_bus_type) != 0)
1622 HPSB_DEBUG("bus_rescan_devices had an error"); 1531 HPSB_DEBUG("bus_rescan_devices had an error");
1532
1533 return 1;
1534}
1535
1536static int remove_nodes_in_limbo(struct device *dev, void *data)
1537{
1538 struct node_entry *ne;
1539
1540 if (dev->bus != &ieee1394_bus_type)
1541 return 0;
1542
1543 ne = container_of(dev, struct node_entry, device);
1544 if (ne->in_limbo)
1545 nodemgr_remove_ne(ne);
1546
1547 return 0;
1548}
1549
1550static void nodemgr_remove_nodes_in_limbo(struct hpsb_host *host)
1551{
1552 device_for_each_child(&host->device, NULL, remove_nodes_in_limbo);
1623} 1553}
1624 1554
1625static int nodemgr_send_resume_packet(struct hpsb_host *host) 1555static int nodemgr_send_resume_packet(struct hpsb_host *host)
@@ -1730,10 +1660,9 @@ static int nodemgr_check_irm_capability(struct hpsb_host *host, int cycles)
1730 return 1; 1660 return 1;
1731} 1661}
1732 1662
1733static int nodemgr_host_thread(void *__hi) 1663static int nodemgr_host_thread(void *data)
1734{ 1664{
1735 struct host_info *hi = (struct host_info *)__hi; 1665 struct hpsb_host *host = data;
1736 struct hpsb_host *host = hi->host;
1737 unsigned int g, generation = 0; 1666 unsigned int g, generation = 0;
1738 int i, reset_cycles = 0; 1667 int i, reset_cycles = 0;
1739 1668
@@ -1787,36 +1716,48 @@ static int nodemgr_host_thread(void *__hi)
1787 * entries. This does not do the sysfs stuff, since that 1716 * entries. This does not do the sysfs stuff, since that
1788 * would trigger uevents and such, which is a bad idea at 1717 * would trigger uevents and such, which is a bad idea at
1789 * this point. */ 1718 * this point. */
1790 nodemgr_node_scan(hi, generation); 1719 nodemgr_node_scan(host, generation);
1791 1720
1792 /* This actually does the full probe, with sysfs 1721 /* This actually does the full probe, with sysfs
1793 * registration. */ 1722 * registration. */
1794 nodemgr_node_probe(hi, generation); 1723 if (!nodemgr_node_probe(host, generation))
1724 continue;
1795 1725
1796 /* Update some of our sysfs symlinks */ 1726 /* Update some of our sysfs symlinks */
1797 nodemgr_update_host_dev_links(host); 1727 nodemgr_update_host_dev_links(host);
1728
1729 /* Sleep 3 seconds */
1730 for (i = 3000/200; i; i--) {
1731 msleep_interruptible(200);
1732 if (kthread_should_stop())
1733 goto exit;
1734
1735 if (generation != get_hpsb_generation(host))
1736 break;
1737 }
1738 /* Remove nodes which are gone, unless a bus reset happened */
1739 if (!i)
1740 nodemgr_remove_nodes_in_limbo(host);
1798 } 1741 }
1799exit: 1742exit:
1800 HPSB_VERBOSE("NodeMgr: Exiting thread"); 1743 HPSB_VERBOSE("NodeMgr: Exiting thread");
1801 return 0; 1744 return 0;
1802} 1745}
1803 1746
1804struct host_iter_param { 1747struct per_host_parameter {
1805 void *data; 1748 void *data;
1806 int (*cb)(struct hpsb_host *, void *); 1749 int (*cb)(struct hpsb_host *, void *);
1807}; 1750};
1808 1751
1809static int __nodemgr_for_each_host(struct device *dev, void *data) 1752static int per_host(struct device *dev, void *data)
1810{ 1753{
1811 struct hpsb_host *host; 1754 struct hpsb_host *host;
1812 struct host_iter_param *hip = (struct host_iter_param *)data; 1755 struct per_host_parameter *p = data;
1813 int error = 0;
1814 1756
1815 host = container_of(dev, struct hpsb_host, host_dev); 1757 host = container_of(dev, struct hpsb_host, host_dev);
1816 error = hip->cb(host, hip->data); 1758 return p->cb(host, p->data);
1817
1818 return error;
1819} 1759}
1760
1820/** 1761/**
1821 * nodemgr_for_each_host - call a function for each IEEE 1394 host 1762 * nodemgr_for_each_host - call a function for each IEEE 1394 host
1822 * @data: an address to supply to the callback 1763 * @data: an address to supply to the callback
@@ -1831,15 +1772,11 @@ static int __nodemgr_for_each_host(struct device *dev, void *data)
1831 */ 1772 */
1832int nodemgr_for_each_host(void *data, int (*cb)(struct hpsb_host *, void *)) 1773int nodemgr_for_each_host(void *data, int (*cb)(struct hpsb_host *, void *))
1833{ 1774{
1834 struct host_iter_param hip; 1775 struct per_host_parameter p;
1835 int error;
1836
1837 hip.cb = cb;
1838 hip.data = data;
1839 error = class_for_each_device(&hpsb_host_class, NULL, &hip,
1840 __nodemgr_for_each_host);
1841 1776
1842 return error; 1777 p.cb = cb;
1778 p.data = data;
1779 return class_for_each_device(&hpsb_host_class, NULL, &p, per_host);
1843} 1780}
1844 1781
1845/* The following two convenience functions use a struct node_entry 1782/* The following two convenience functions use a struct node_entry
@@ -1893,7 +1830,7 @@ static void nodemgr_add_host(struct hpsb_host *host)
1893 return; 1830 return;
1894 } 1831 }
1895 hi->host = host; 1832 hi->host = host;
1896 hi->thread = kthread_run(nodemgr_host_thread, hi, "knodemgrd_%d", 1833 hi->thread = kthread_run(nodemgr_host_thread, host, "knodemgrd_%d",
1897 host->id); 1834 host->id);
1898 if (IS_ERR(hi->thread)) { 1835 if (IS_ERR(hi->thread)) {
1899 HPSB_ERR("NodeMgr: cannot start thread for host %d", host->id); 1836 HPSB_ERR("NodeMgr: cannot start thread for host %d", host->id);
diff --git a/drivers/ieee1394/nodemgr.h b/drivers/ieee1394/nodemgr.h
index 6eb26465a84c..4f287a3561ba 100644
--- a/drivers/ieee1394/nodemgr.h
+++ b/drivers/ieee1394/nodemgr.h
@@ -110,7 +110,7 @@ struct node_entry {
110 struct device node_dev; 110 struct device node_dev;
111 111
112 /* Means this node is not attached anymore */ 112 /* Means this node is not attached anymore */
113 int in_limbo; 113 bool in_limbo;
114 114
115 struct csr1212_csr *csr; 115 struct csr1212_csr *csr;
116}; 116};
diff --git a/drivers/ieee1394/raw1394-private.h b/drivers/ieee1394/raw1394-private.h
index a06aaad5b448..7a225a405987 100644
--- a/drivers/ieee1394/raw1394-private.h
+++ b/drivers/ieee1394/raw1394-private.h
@@ -22,6 +22,7 @@ enum raw1394_iso_state { RAW1394_ISO_INACTIVE = 0,
22struct file_info { 22struct file_info {
23 struct list_head list; 23 struct list_head list;
24 24
25 struct mutex state_mutex;
25 enum { opened, initialized, connected } state; 26 enum { opened, initialized, connected } state;
26 unsigned int protocol_version; 27 unsigned int protocol_version;
27 28
diff --git a/drivers/ieee1394/raw1394.c b/drivers/ieee1394/raw1394.c
index 6fa9e4a21840..9f19ac492106 100644
--- a/drivers/ieee1394/raw1394.c
+++ b/drivers/ieee1394/raw1394.c
@@ -34,6 +34,7 @@
34#include <linux/fs.h> 34#include <linux/fs.h>
35#include <linux/poll.h> 35#include <linux/poll.h>
36#include <linux/module.h> 36#include <linux/module.h>
37#include <linux/mutex.h>
37#include <linux/init.h> 38#include <linux/init.h>
38#include <linux/interrupt.h> 39#include <linux/interrupt.h>
39#include <linux/vmalloc.h> 40#include <linux/vmalloc.h>
@@ -2267,6 +2268,8 @@ static ssize_t raw1394_write(struct file *file, const char __user * buffer,
2267 return -EFAULT; 2268 return -EFAULT;
2268 } 2269 }
2269 2270
2271 mutex_lock(&fi->state_mutex);
2272
2270 switch (fi->state) { 2273 switch (fi->state) {
2271 case opened: 2274 case opened:
2272 retval = state_opened(fi, req); 2275 retval = state_opened(fi, req);
@@ -2281,6 +2284,8 @@ static ssize_t raw1394_write(struct file *file, const char __user * buffer,
2281 break; 2284 break;
2282 } 2285 }
2283 2286
2287 mutex_unlock(&fi->state_mutex);
2288
2284 if (retval < 0) { 2289 if (retval < 0) {
2285 free_pending_request(req); 2290 free_pending_request(req);
2286 } else { 2291 } else {
@@ -2541,109 +2546,120 @@ static int raw1394_read_cycle_timer(struct file_info *fi, void __user * uaddr)
2541static int raw1394_mmap(struct file *file, struct vm_area_struct *vma) 2546static int raw1394_mmap(struct file *file, struct vm_area_struct *vma)
2542{ 2547{
2543 struct file_info *fi = file->private_data; 2548 struct file_info *fi = file->private_data;
2549 int ret;
2550
2551 mutex_lock(&fi->state_mutex);
2544 2552
2545 if (fi->iso_state == RAW1394_ISO_INACTIVE) 2553 if (fi->iso_state == RAW1394_ISO_INACTIVE)
2546 return -EINVAL; 2554 ret = -EINVAL;
2555 else
2556 ret = dma_region_mmap(&fi->iso_handle->data_buf, file, vma);
2557
2558 mutex_unlock(&fi->state_mutex);
2547 2559
2548 return dma_region_mmap(&fi->iso_handle->data_buf, file, vma); 2560 return ret;
2549} 2561}
2550 2562
2551/* ioctl is only used for rawiso operations */ 2563static long raw1394_ioctl_inactive(struct file_info *fi, unsigned int cmd,
2552static long do_raw1394_ioctl(struct file *file, unsigned int cmd, 2564 void __user *argp)
2553 unsigned long arg) 2565{
2566 switch (cmd) {
2567 case RAW1394_IOC_ISO_XMIT_INIT:
2568 return raw1394_iso_xmit_init(fi, argp);
2569 case RAW1394_IOC_ISO_RECV_INIT:
2570 return raw1394_iso_recv_init(fi, argp);
2571 default:
2572 return -EINVAL;
2573 }
2574}
2575
2576static long raw1394_ioctl_recv(struct file_info *fi, unsigned int cmd,
2577 unsigned long arg)
2554{ 2578{
2555 struct file_info *fi = file->private_data;
2556 void __user *argp = (void __user *)arg; 2579 void __user *argp = (void __user *)arg;
2557 2580
2558 switch (fi->iso_state) { 2581 switch (cmd) {
2559 case RAW1394_ISO_INACTIVE: 2582 case RAW1394_IOC_ISO_RECV_START:{
2560 switch (cmd) { 2583 int args[3];
2561 case RAW1394_IOC_ISO_XMIT_INIT: 2584
2562 return raw1394_iso_xmit_init(fi, argp); 2585 if (copy_from_user(&args[0], argp, sizeof(args)))
2563 case RAW1394_IOC_ISO_RECV_INIT: 2586 return -EFAULT;
2564 return raw1394_iso_recv_init(fi, argp); 2587 return hpsb_iso_recv_start(fi->iso_handle,
2565 default: 2588 args[0], args[1], args[2]);
2566 break;
2567 } 2589 }
2568 break; 2590 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2569 case RAW1394_ISO_RECV: 2591 hpsb_iso_stop(fi->iso_handle);
2570 switch (cmd) { 2592 return 0;
2571 case RAW1394_IOC_ISO_RECV_START:{ 2593 case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL:
2572 /* copy args from user-space */ 2594 return hpsb_iso_recv_listen_channel(fi->iso_handle, arg);
2573 int args[3]; 2595 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL:
2574 if (copy_from_user 2596 return hpsb_iso_recv_unlisten_channel(fi->iso_handle, arg);
2575 (&args[0], argp, sizeof(args))) 2597 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK:{
2576 return -EFAULT; 2598 u64 mask;
2577 return hpsb_iso_recv_start(fi->iso_handle, 2599
2578 args[0], args[1], 2600 if (copy_from_user(&mask, argp, sizeof(mask)))
2579 args[2]); 2601 return -EFAULT;
2580 } 2602 return hpsb_iso_recv_set_channel_mask(fi->iso_handle,
2581 case RAW1394_IOC_ISO_XMIT_RECV_STOP: 2603 mask);
2582 hpsb_iso_stop(fi->iso_handle);
2583 return 0;
2584 case RAW1394_IOC_ISO_RECV_LISTEN_CHANNEL:
2585 return hpsb_iso_recv_listen_channel(fi->iso_handle,
2586 arg);
2587 case RAW1394_IOC_ISO_RECV_UNLISTEN_CHANNEL:
2588 return hpsb_iso_recv_unlisten_channel(fi->iso_handle,
2589 arg);
2590 case RAW1394_IOC_ISO_RECV_SET_CHANNEL_MASK:{
2591 /* copy the u64 from user-space */
2592 u64 mask;
2593 if (copy_from_user(&mask, argp, sizeof(mask)))
2594 return -EFAULT;
2595 return hpsb_iso_recv_set_channel_mask(fi->
2596 iso_handle,
2597 mask);
2598 }
2599 case RAW1394_IOC_ISO_GET_STATUS:
2600 return raw1394_iso_get_status(fi, argp);
2601 case RAW1394_IOC_ISO_RECV_PACKETS:
2602 return raw1394_iso_recv_packets(fi, argp);
2603 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS:
2604 return hpsb_iso_recv_release_packets(fi->iso_handle,
2605 arg);
2606 case RAW1394_IOC_ISO_RECV_FLUSH:
2607 return hpsb_iso_recv_flush(fi->iso_handle);
2608 case RAW1394_IOC_ISO_SHUTDOWN:
2609 raw1394_iso_shutdown(fi);
2610 return 0;
2611 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2612 queue_rawiso_event(fi);
2613 return 0;
2614 } 2604 }
2615 break; 2605 case RAW1394_IOC_ISO_GET_STATUS:
2616 case RAW1394_ISO_XMIT: 2606 return raw1394_iso_get_status(fi, argp);
2617 switch (cmd) { 2607 case RAW1394_IOC_ISO_RECV_PACKETS:
2618 case RAW1394_IOC_ISO_XMIT_START:{ 2608 return raw1394_iso_recv_packets(fi, argp);
2619 /* copy two ints from user-space */ 2609 case RAW1394_IOC_ISO_RECV_RELEASE_PACKETS:
2620 int args[2]; 2610 return hpsb_iso_recv_release_packets(fi->iso_handle, arg);
2621 if (copy_from_user 2611 case RAW1394_IOC_ISO_RECV_FLUSH:
2622 (&args[0], argp, sizeof(args))) 2612 return hpsb_iso_recv_flush(fi->iso_handle);
2623 return -EFAULT; 2613 case RAW1394_IOC_ISO_SHUTDOWN:
2624 return hpsb_iso_xmit_start(fi->iso_handle, 2614 raw1394_iso_shutdown(fi);
2625 args[0], args[1]); 2615 return 0;
2626 } 2616 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2627 case RAW1394_IOC_ISO_XMIT_SYNC: 2617 queue_rawiso_event(fi);
2628 return hpsb_iso_xmit_sync(fi->iso_handle); 2618 return 0;
2629 case RAW1394_IOC_ISO_XMIT_RECV_STOP: 2619 default:
2630 hpsb_iso_stop(fi->iso_handle); 2620 return -EINVAL;
2631 return 0; 2621 }
2632 case RAW1394_IOC_ISO_GET_STATUS: 2622}
2633 return raw1394_iso_get_status(fi, argp); 2623
2634 case RAW1394_IOC_ISO_XMIT_PACKETS: 2624static long raw1394_ioctl_xmit(struct file_info *fi, unsigned int cmd,
2635 return raw1394_iso_send_packets(fi, argp); 2625 void __user *argp)
2636 case RAW1394_IOC_ISO_SHUTDOWN: 2626{
2637 raw1394_iso_shutdown(fi); 2627 switch (cmd) {
2638 return 0; 2628 case RAW1394_IOC_ISO_XMIT_START:{
2639 case RAW1394_IOC_ISO_QUEUE_ACTIVITY: 2629 int args[2];
2640 queue_rawiso_event(fi); 2630
2641 return 0; 2631 if (copy_from_user(&args[0], argp, sizeof(args)))
2632 return -EFAULT;
2633 return hpsb_iso_xmit_start(fi->iso_handle,
2634 args[0], args[1]);
2642 } 2635 }
2643 break; 2636 case RAW1394_IOC_ISO_XMIT_SYNC:
2637 return hpsb_iso_xmit_sync(fi->iso_handle);
2638 case RAW1394_IOC_ISO_XMIT_RECV_STOP:
2639 hpsb_iso_stop(fi->iso_handle);
2640 return 0;
2641 case RAW1394_IOC_ISO_GET_STATUS:
2642 return raw1394_iso_get_status(fi, argp);
2643 case RAW1394_IOC_ISO_XMIT_PACKETS:
2644 return raw1394_iso_send_packets(fi, argp);
2645 case RAW1394_IOC_ISO_SHUTDOWN:
2646 raw1394_iso_shutdown(fi);
2647 return 0;
2648 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2649 queue_rawiso_event(fi);
2650 return 0;
2644 default: 2651 default:
2645 break; 2652 return -EINVAL;
2646 } 2653 }
2654}
2655
2656/* ioctl is only used for rawiso operations */
2657static long raw1394_ioctl(struct file *file, unsigned int cmd,
2658 unsigned long arg)
2659{
2660 struct file_info *fi = file->private_data;
2661 void __user *argp = (void __user *)arg;
2662 long ret;
2647 2663
2648 /* state-independent commands */ 2664 /* state-independent commands */
2649 switch(cmd) { 2665 switch(cmd) {
@@ -2653,16 +2669,25 @@ static long do_raw1394_ioctl(struct file *file, unsigned int cmd,
2653 break; 2669 break;
2654 } 2670 }
2655 2671
2656 return -EINVAL; 2672 mutex_lock(&fi->state_mutex);
2657} 2673
2674 switch (fi->iso_state) {
2675 case RAW1394_ISO_INACTIVE:
2676 ret = raw1394_ioctl_inactive(fi, cmd, argp);
2677 break;
2678 case RAW1394_ISO_RECV:
2679 ret = raw1394_ioctl_recv(fi, cmd, arg);
2680 break;
2681 case RAW1394_ISO_XMIT:
2682 ret = raw1394_ioctl_xmit(fi, cmd, argp);
2683 break;
2684 default:
2685 ret = -EINVAL;
2686 break;
2687 }
2688
2689 mutex_unlock(&fi->state_mutex);
2658 2690
2659static long raw1394_ioctl(struct file *file, unsigned int cmd,
2660 unsigned long arg)
2661{
2662 long ret;
2663 lock_kernel();
2664 ret = do_raw1394_ioctl(file, cmd, arg);
2665 unlock_kernel();
2666 return ret; 2691 return ret;
2667} 2692}
2668 2693
@@ -2700,7 +2725,7 @@ static long raw1394_iso_xmit_recv_packets32(struct file *file, unsigned int cmd,
2700 !copy_from_user(&infos32, &arg->infos, sizeof infos32)) { 2725 !copy_from_user(&infos32, &arg->infos, sizeof infos32)) {
2701 infos = compat_ptr(infos32); 2726 infos = compat_ptr(infos32);
2702 if (!copy_to_user(&dst->infos, &infos, sizeof infos)) 2727 if (!copy_to_user(&dst->infos, &infos, sizeof infos))
2703 err = do_raw1394_ioctl(file, cmd, (unsigned long)dst); 2728 err = raw1394_ioctl(file, cmd, (unsigned long)dst);
2704 } 2729 }
2705 return err; 2730 return err;
2706} 2731}
@@ -2724,7 +2749,6 @@ static long raw1394_compat_ioctl(struct file *file,
2724 void __user *argp = (void __user *)arg; 2749 void __user *argp = (void __user *)arg;
2725 long err; 2750 long err;
2726 2751
2727 lock_kernel();
2728 switch (cmd) { 2752 switch (cmd) {
2729 /* These requests have same format as long as 'int' has same size. */ 2753 /* These requests have same format as long as 'int' has same size. */
2730 case RAW1394_IOC_ISO_RECV_INIT: 2754 case RAW1394_IOC_ISO_RECV_INIT:
@@ -2741,7 +2765,7 @@ static long raw1394_compat_ioctl(struct file *file,
2741 case RAW1394_IOC_ISO_GET_STATUS: 2765 case RAW1394_IOC_ISO_GET_STATUS:
2742 case RAW1394_IOC_ISO_SHUTDOWN: 2766 case RAW1394_IOC_ISO_SHUTDOWN:
2743 case RAW1394_IOC_ISO_QUEUE_ACTIVITY: 2767 case RAW1394_IOC_ISO_QUEUE_ACTIVITY:
2744 err = do_raw1394_ioctl(file, cmd, arg); 2768 err = raw1394_ioctl(file, cmd, arg);
2745 break; 2769 break;
2746 /* These request have different format. */ 2770 /* These request have different format. */
2747 case RAW1394_IOC_ISO_RECV_PACKETS32: 2771 case RAW1394_IOC_ISO_RECV_PACKETS32:
@@ -2757,7 +2781,6 @@ static long raw1394_compat_ioctl(struct file *file,
2757 err = -EINVAL; 2781 err = -EINVAL;
2758 break; 2782 break;
2759 } 2783 }
2760 unlock_kernel();
2761 2784
2762 return err; 2785 return err;
2763} 2786}
@@ -2791,6 +2814,7 @@ static int raw1394_open(struct inode *inode, struct file *file)
2791 fi->notification = (u8) RAW1394_NOTIFY_ON; /* busreset notification */ 2814 fi->notification = (u8) RAW1394_NOTIFY_ON; /* busreset notification */
2792 2815
2793 INIT_LIST_HEAD(&fi->list); 2816 INIT_LIST_HEAD(&fi->list);
2817 mutex_init(&fi->state_mutex);
2794 fi->state = opened; 2818 fi->state = opened;
2795 INIT_LIST_HEAD(&fi->req_pending); 2819 INIT_LIST_HEAD(&fi->req_pending);
2796 INIT_LIST_HEAD(&fi->req_complete); 2820 INIT_LIST_HEAD(&fi->req_complete);
@@ -3010,10 +3034,10 @@ static int __init init_raw1394(void)
3010 hpsb_register_highlevel(&raw1394_highlevel); 3034 hpsb_register_highlevel(&raw1394_highlevel);
3011 3035
3012 if (IS_ERR 3036 if (IS_ERR
3013 (device_create_drvdata( 3037 (device_create(hpsb_protocol_class, NULL,
3014 hpsb_protocol_class, NULL, 3038 MKDEV(IEEE1394_MAJOR,
3015 MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16), 3039 IEEE1394_MINOR_BLOCK_RAW1394 * 16),
3016 NULL, RAW1394_DEVICE_NAME))) { 3040 NULL, RAW1394_DEVICE_NAME))) {
3017 ret = -EFAULT; 3041 ret = -EFAULT;
3018 goto out_unreg; 3042 goto out_unreg;
3019 } 3043 }
diff --git a/drivers/ieee1394/sbp2.c b/drivers/ieee1394/sbp2.c
index 1d6ad3435537..c52f6e6e8af2 100644
--- a/drivers/ieee1394/sbp2.c
+++ b/drivers/ieee1394/sbp2.c
@@ -526,26 +526,41 @@ static void sbp2util_write_doorbell(struct work_struct *work)
526 526
527static int sbp2util_create_command_orb_pool(struct sbp2_lu *lu) 527static int sbp2util_create_command_orb_pool(struct sbp2_lu *lu)
528{ 528{
529 struct sbp2_fwhost_info *hi = lu->hi;
530 struct sbp2_command_info *cmd; 529 struct sbp2_command_info *cmd;
530 struct device *dmadev = lu->hi->host->device.parent;
531 int i, orbs = sbp2_serialize_io ? 2 : SBP2_MAX_CMDS; 531 int i, orbs = sbp2_serialize_io ? 2 : SBP2_MAX_CMDS;
532 532
533 for (i = 0; i < orbs; i++) { 533 for (i = 0; i < orbs; i++) {
534 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); 534 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
535 if (!cmd) 535 if (!cmd)
536 return -ENOMEM; 536 goto failed_alloc;
537 cmd->command_orb_dma = dma_map_single(hi->host->device.parent, 537
538 &cmd->command_orb, 538 cmd->command_orb_dma =
539 sizeof(struct sbp2_command_orb), 539 dma_map_single(dmadev, &cmd->command_orb,
540 DMA_TO_DEVICE); 540 sizeof(struct sbp2_command_orb),
541 cmd->sge_dma = dma_map_single(hi->host->device.parent, 541 DMA_TO_DEVICE);
542 &cmd->scatter_gather_element, 542 if (dma_mapping_error(dmadev, cmd->command_orb_dma))
543 sizeof(cmd->scatter_gather_element), 543 goto failed_orb;
544 DMA_TO_DEVICE); 544
545 cmd->sge_dma =
546 dma_map_single(dmadev, &cmd->scatter_gather_element,
547 sizeof(cmd->scatter_gather_element),
548 DMA_TO_DEVICE);
549 if (dma_mapping_error(dmadev, cmd->sge_dma))
550 goto failed_sge;
551
545 INIT_LIST_HEAD(&cmd->list); 552 INIT_LIST_HEAD(&cmd->list);
546 list_add_tail(&cmd->list, &lu->cmd_orb_completed); 553 list_add_tail(&cmd->list, &lu->cmd_orb_completed);
547 } 554 }
548 return 0; 555 return 0;
556
557failed_sge:
558 dma_unmap_single(dmadev, cmd->command_orb_dma,
559 sizeof(struct sbp2_command_orb), DMA_TO_DEVICE);
560failed_orb:
561 kfree(cmd);
562failed_alloc:
563 return -ENOMEM;
549} 564}
550 565
551static void sbp2util_remove_command_orb_pool(struct sbp2_lu *lu, 566static void sbp2util_remove_command_orb_pool(struct sbp2_lu *lu,
@@ -641,24 +656,11 @@ static struct sbp2_command_info *sbp2util_allocate_command_orb(
641static void sbp2util_mark_command_completed(struct sbp2_lu *lu, 656static void sbp2util_mark_command_completed(struct sbp2_lu *lu,
642 struct sbp2_command_info *cmd) 657 struct sbp2_command_info *cmd)
643{ 658{
644 struct hpsb_host *host = lu->ud->ne->host; 659 if (scsi_sg_count(cmd->Current_SCpnt))
645 660 dma_unmap_sg(lu->ud->ne->host->device.parent,
646 if (cmd->cmd_dma) { 661 scsi_sglist(cmd->Current_SCpnt),
647 if (cmd->dma_type == CMD_DMA_SINGLE) 662 scsi_sg_count(cmd->Current_SCpnt),
648 dma_unmap_single(host->device.parent, cmd->cmd_dma, 663 cmd->Current_SCpnt->sc_data_direction);
649 cmd->dma_size, cmd->dma_dir);
650 else if (cmd->dma_type == CMD_DMA_PAGE)
651 dma_unmap_page(host->device.parent, cmd->cmd_dma,
652 cmd->dma_size, cmd->dma_dir);
653 /* XXX: Check for CMD_DMA_NONE bug */
654 cmd->dma_type = CMD_DMA_NONE;
655 cmd->cmd_dma = 0;
656 }
657 if (cmd->sge_buffer) {
658 dma_unmap_sg(host->device.parent, cmd->sge_buffer,
659 cmd->dma_size, cmd->dma_dir);
660 cmd->sge_buffer = NULL;
661 }
662 list_move_tail(&cmd->list, &lu->cmd_orb_completed); 664 list_move_tail(&cmd->list, &lu->cmd_orb_completed);
663} 665}
664 666
@@ -823,6 +825,10 @@ static struct sbp2_lu *sbp2_alloc_device(struct unit_directory *ud)
823#endif 825#endif
824 } 826 }
825 827
828 if (dma_get_max_seg_size(hi->host->device.parent) > SBP2_MAX_SEG_SIZE)
829 BUG_ON(dma_set_max_seg_size(hi->host->device.parent,
830 SBP2_MAX_SEG_SIZE));
831
826 /* Prevent unloading of the 1394 host */ 832 /* Prevent unloading of the 1394 host */
827 if (!try_module_get(hi->host->driver->owner)) { 833 if (!try_module_get(hi->host->driver->owner)) {
828 SBP2_ERR("failed to get a reference on 1394 host driver"); 834 SBP2_ERR("failed to get a reference on 1394 host driver");
@@ -1494,84 +1500,65 @@ static int sbp2_agent_reset(struct sbp2_lu *lu, int wait)
1494 return 0; 1500 return 0;
1495} 1501}
1496 1502
1497static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb, 1503static int sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb,
1498 struct sbp2_fwhost_info *hi, 1504 struct sbp2_fwhost_info *hi,
1499 struct sbp2_command_info *cmd, 1505 struct sbp2_command_info *cmd,
1500 unsigned int scsi_use_sg, 1506 unsigned int sg_count,
1501 struct scatterlist *sg, 1507 struct scatterlist *sg,
1502 u32 orb_direction, 1508 u32 orb_direction,
1503 enum dma_data_direction dma_dir) 1509 enum dma_data_direction dma_dir)
1504{ 1510{
1505 cmd->dma_dir = dma_dir; 1511 struct device *dmadev = hi->host->device.parent;
1512 struct sbp2_unrestricted_page_table *pt;
1513 int i, n;
1514
1515 n = dma_map_sg(dmadev, sg, sg_count, dma_dir);
1516 if (n == 0)
1517 return -ENOMEM;
1518
1506 orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); 1519 orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id);
1507 orb->misc |= ORB_SET_DIRECTION(orb_direction); 1520 orb->misc |= ORB_SET_DIRECTION(orb_direction);
1508 1521
1509 /* special case if only one element (and less than 64KB in size) */ 1522 /* special case if only one element (and less than 64KB in size) */
1510 if (scsi_use_sg == 1 && sg->length <= SBP2_MAX_SG_ELEMENT_LENGTH) { 1523 if (n == 1) {
1511 1524 orb->misc |= ORB_SET_DATA_SIZE(sg_dma_len(sg));
1512 cmd->dma_size = sg->length; 1525 orb->data_descriptor_lo = sg_dma_address(sg);
1513 cmd->dma_type = CMD_DMA_PAGE;
1514 cmd->cmd_dma = dma_map_page(hi->host->device.parent,
1515 sg_page(sg), sg->offset,
1516 cmd->dma_size, cmd->dma_dir);
1517
1518 orb->data_descriptor_lo = cmd->cmd_dma;
1519 orb->misc |= ORB_SET_DATA_SIZE(cmd->dma_size);
1520
1521 } else { 1526 } else {
1522 struct sbp2_unrestricted_page_table *sg_element = 1527 pt = &cmd->scatter_gather_element[0];
1523 &cmd->scatter_gather_element[0];
1524 u32 sg_count, sg_len;
1525 dma_addr_t sg_addr;
1526 int i, count = dma_map_sg(hi->host->device.parent, sg,
1527 scsi_use_sg, dma_dir);
1528
1529 cmd->dma_size = scsi_use_sg;
1530 cmd->sge_buffer = sg;
1531
1532 /* use page tables (s/g) */
1533 orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1);
1534 orb->data_descriptor_lo = cmd->sge_dma;
1535 1528
1536 /* loop through and fill out our SBP-2 page tables 1529 dma_sync_single_for_cpu(dmadev, cmd->sge_dma,
1537 * (and split up anything too large) */ 1530 sizeof(cmd->scatter_gather_element),
1538 for (i = 0, sg_count = 0; i < count; i++, sg = sg_next(sg)) { 1531 DMA_TO_DEVICE);
1539 sg_len = sg_dma_len(sg); 1532
1540 sg_addr = sg_dma_address(sg); 1533 for_each_sg(sg, sg, n, i) {
1541 while (sg_len) { 1534 pt[i].high = cpu_to_be32(sg_dma_len(sg) << 16);
1542 sg_element[sg_count].segment_base_lo = sg_addr; 1535 pt[i].low = cpu_to_be32(sg_dma_address(sg));
1543 if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) {
1544 sg_element[sg_count].length_segment_base_hi =
1545 PAGE_TABLE_SET_SEGMENT_LENGTH(SBP2_MAX_SG_ELEMENT_LENGTH);
1546 sg_addr += SBP2_MAX_SG_ELEMENT_LENGTH;
1547 sg_len -= SBP2_MAX_SG_ELEMENT_LENGTH;
1548 } else {
1549 sg_element[sg_count].length_segment_base_hi =
1550 PAGE_TABLE_SET_SEGMENT_LENGTH(sg_len);
1551 sg_len = 0;
1552 }
1553 sg_count++;
1554 }
1555 } 1536 }
1556 1537
1557 orb->misc |= ORB_SET_DATA_SIZE(sg_count); 1538 orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1) |
1539 ORB_SET_DATA_SIZE(n);
1540 orb->data_descriptor_lo = cmd->sge_dma;
1558 1541
1559 sbp2util_cpu_to_be32_buffer(sg_element, 1542 dma_sync_single_for_device(dmadev, cmd->sge_dma,
1560 (sizeof(struct sbp2_unrestricted_page_table)) * 1543 sizeof(cmd->scatter_gather_element),
1561 sg_count); 1544 DMA_TO_DEVICE);
1562 } 1545 }
1546 return 0;
1563} 1547}
1564 1548
1565static void sbp2_create_command_orb(struct sbp2_lu *lu, 1549static int sbp2_create_command_orb(struct sbp2_lu *lu,
1566 struct sbp2_command_info *cmd, 1550 struct sbp2_command_info *cmd,
1567 struct scsi_cmnd *SCpnt) 1551 struct scsi_cmnd *SCpnt)
1568{ 1552{
1569 struct sbp2_fwhost_info *hi = lu->hi; 1553 struct device *dmadev = lu->hi->host->device.parent;
1570 struct sbp2_command_orb *orb = &cmd->command_orb; 1554 struct sbp2_command_orb *orb = &cmd->command_orb;
1571 u32 orb_direction;
1572 unsigned int scsi_request_bufflen = scsi_bufflen(SCpnt); 1555 unsigned int scsi_request_bufflen = scsi_bufflen(SCpnt);
1573 enum dma_data_direction dma_dir = SCpnt->sc_data_direction; 1556 enum dma_data_direction dma_dir = SCpnt->sc_data_direction;
1557 u32 orb_direction;
1558 int ret;
1574 1559
1560 dma_sync_single_for_cpu(dmadev, cmd->command_orb_dma,
1561 sizeof(struct sbp2_command_orb), DMA_TO_DEVICE);
1575 /* 1562 /*
1576 * Set-up our command ORB. 1563 * Set-up our command ORB.
1577 * 1564 *
@@ -1602,15 +1589,21 @@ static void sbp2_create_command_orb(struct sbp2_lu *lu,
1602 orb->data_descriptor_hi = 0x0; 1589 orb->data_descriptor_hi = 0x0;
1603 orb->data_descriptor_lo = 0x0; 1590 orb->data_descriptor_lo = 0x0;
1604 orb->misc |= ORB_SET_DIRECTION(1); 1591 orb->misc |= ORB_SET_DIRECTION(1);
1605 } else 1592 ret = 0;
1606 sbp2_prep_command_orb_sg(orb, hi, cmd, scsi_sg_count(SCpnt), 1593 } else {
1607 scsi_sglist(SCpnt), 1594 ret = sbp2_prep_command_orb_sg(orb, lu->hi, cmd,
1608 orb_direction, dma_dir); 1595 scsi_sg_count(SCpnt),
1609 1596 scsi_sglist(SCpnt),
1597 orb_direction, dma_dir);
1598 }
1610 sbp2util_cpu_to_be32_buffer(orb, sizeof(*orb)); 1599 sbp2util_cpu_to_be32_buffer(orb, sizeof(*orb));
1611 1600
1612 memset(orb->cdb, 0, sizeof(orb->cdb)); 1601 memset(orb->cdb, 0, sizeof(orb->cdb));
1613 memcpy(orb->cdb, SCpnt->cmnd, SCpnt->cmd_len); 1602 memcpy(orb->cdb, SCpnt->cmnd, SCpnt->cmd_len);
1603
1604 dma_sync_single_for_device(dmadev, cmd->command_orb_dma,
1605 sizeof(struct sbp2_command_orb), DMA_TO_DEVICE);
1606 return ret;
1614} 1607}
1615 1608
1616static void sbp2_link_orb_command(struct sbp2_lu *lu, 1609static void sbp2_link_orb_command(struct sbp2_lu *lu,
@@ -1624,14 +1617,6 @@ static void sbp2_link_orb_command(struct sbp2_lu *lu,
1624 size_t length; 1617 size_t length;
1625 unsigned long flags; 1618 unsigned long flags;
1626 1619
1627 dma_sync_single_for_device(hi->host->device.parent,
1628 cmd->command_orb_dma,
1629 sizeof(struct sbp2_command_orb),
1630 DMA_TO_DEVICE);
1631 dma_sync_single_for_device(hi->host->device.parent, cmd->sge_dma,
1632 sizeof(cmd->scatter_gather_element),
1633 DMA_TO_DEVICE);
1634
1635 /* check to see if there are any previous orbs to use */ 1620 /* check to see if there are any previous orbs to use */
1636 spin_lock_irqsave(&lu->cmd_orb_lock, flags); 1621 spin_lock_irqsave(&lu->cmd_orb_lock, flags);
1637 last_orb = lu->last_orb; 1622 last_orb = lu->last_orb;
@@ -1699,9 +1684,10 @@ static int sbp2_send_command(struct sbp2_lu *lu, struct scsi_cmnd *SCpnt,
1699 if (!cmd) 1684 if (!cmd)
1700 return -EIO; 1685 return -EIO;
1701 1686
1702 sbp2_create_command_orb(lu, cmd, SCpnt); 1687 if (sbp2_create_command_orb(lu, cmd, SCpnt))
1703 sbp2_link_orb_command(lu, cmd); 1688 return -ENOMEM;
1704 1689
1690 sbp2_link_orb_command(lu, cmd);
1705 return 0; 1691 return 0;
1706} 1692}
1707 1693
@@ -1789,13 +1775,6 @@ static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid,
1789 else 1775 else
1790 cmd = sbp2util_find_command_for_orb(lu, sb->ORB_offset_lo); 1776 cmd = sbp2util_find_command_for_orb(lu, sb->ORB_offset_lo);
1791 if (cmd) { 1777 if (cmd) {
1792 dma_sync_single_for_cpu(hi->host->device.parent,
1793 cmd->command_orb_dma,
1794 sizeof(struct sbp2_command_orb),
1795 DMA_TO_DEVICE);
1796 dma_sync_single_for_cpu(hi->host->device.parent, cmd->sge_dma,
1797 sizeof(cmd->scatter_gather_element),
1798 DMA_TO_DEVICE);
1799 /* Grab SCSI command pointers and check status. */ 1778 /* Grab SCSI command pointers and check status. */
1800 /* 1779 /*
1801 * FIXME: If the src field in the status is 1, the ORB DMA must 1780 * FIXME: If the src field in the status is 1, the ORB DMA must
@@ -1912,7 +1891,6 @@ done:
1912 1891
1913static void sbp2scsi_complete_all_commands(struct sbp2_lu *lu, u32 status) 1892static void sbp2scsi_complete_all_commands(struct sbp2_lu *lu, u32 status)
1914{ 1893{
1915 struct sbp2_fwhost_info *hi = lu->hi;
1916 struct list_head *lh; 1894 struct list_head *lh;
1917 struct sbp2_command_info *cmd; 1895 struct sbp2_command_info *cmd;
1918 unsigned long flags; 1896 unsigned long flags;
@@ -1921,13 +1899,6 @@ static void sbp2scsi_complete_all_commands(struct sbp2_lu *lu, u32 status)
1921 while (!list_empty(&lu->cmd_orb_inuse)) { 1899 while (!list_empty(&lu->cmd_orb_inuse)) {
1922 lh = lu->cmd_orb_inuse.next; 1900 lh = lu->cmd_orb_inuse.next;
1923 cmd = list_entry(lh, struct sbp2_command_info, list); 1901 cmd = list_entry(lh, struct sbp2_command_info, list);
1924 dma_sync_single_for_cpu(hi->host->device.parent,
1925 cmd->command_orb_dma,
1926 sizeof(struct sbp2_command_orb),
1927 DMA_TO_DEVICE);
1928 dma_sync_single_for_cpu(hi->host->device.parent, cmd->sge_dma,
1929 sizeof(cmd->scatter_gather_element),
1930 DMA_TO_DEVICE);
1931 sbp2util_mark_command_completed(lu, cmd); 1902 sbp2util_mark_command_completed(lu, cmd);
1932 if (cmd->Current_SCpnt) { 1903 if (cmd->Current_SCpnt) {
1933 cmd->Current_SCpnt->result = status << 16; 1904 cmd->Current_SCpnt->result = status << 16;
@@ -2033,6 +2004,8 @@ static int sbp2scsi_slave_configure(struct scsi_device *sdev)
2033 sdev->start_stop_pwr_cond = 1; 2004 sdev->start_stop_pwr_cond = 1;
2034 if (lu->workarounds & SBP2_WORKAROUND_128K_MAX_TRANS) 2005 if (lu->workarounds & SBP2_WORKAROUND_128K_MAX_TRANS)
2035 blk_queue_max_sectors(sdev->request_queue, 128 * 1024 / 512); 2006 blk_queue_max_sectors(sdev->request_queue, 128 * 1024 / 512);
2007
2008 blk_queue_max_segment_size(sdev->request_queue, SBP2_MAX_SEG_SIZE);
2036 return 0; 2009 return 0;
2037} 2010}
2038 2011
@@ -2049,7 +2022,6 @@ static void sbp2scsi_slave_destroy(struct scsi_device *sdev)
2049static int sbp2scsi_abort(struct scsi_cmnd *SCpnt) 2022static int sbp2scsi_abort(struct scsi_cmnd *SCpnt)
2050{ 2023{
2051 struct sbp2_lu *lu = (struct sbp2_lu *)SCpnt->device->host->hostdata[0]; 2024 struct sbp2_lu *lu = (struct sbp2_lu *)SCpnt->device->host->hostdata[0];
2052 struct sbp2_fwhost_info *hi = lu->hi;
2053 struct sbp2_command_info *cmd; 2025 struct sbp2_command_info *cmd;
2054 unsigned long flags; 2026 unsigned long flags;
2055 2027
@@ -2063,14 +2035,6 @@ static int sbp2scsi_abort(struct scsi_cmnd *SCpnt)
2063 spin_lock_irqsave(&lu->cmd_orb_lock, flags); 2035 spin_lock_irqsave(&lu->cmd_orb_lock, flags);
2064 cmd = sbp2util_find_command_for_SCpnt(lu, SCpnt); 2036 cmd = sbp2util_find_command_for_SCpnt(lu, SCpnt);
2065 if (cmd) { 2037 if (cmd) {
2066 dma_sync_single_for_cpu(hi->host->device.parent,
2067 cmd->command_orb_dma,
2068 sizeof(struct sbp2_command_orb),
2069 DMA_TO_DEVICE);
2070 dma_sync_single_for_cpu(hi->host->device.parent,
2071 cmd->sge_dma,
2072 sizeof(cmd->scatter_gather_element),
2073 DMA_TO_DEVICE);
2074 sbp2util_mark_command_completed(lu, cmd); 2038 sbp2util_mark_command_completed(lu, cmd);
2075 if (cmd->Current_SCpnt) { 2039 if (cmd->Current_SCpnt) {
2076 cmd->Current_SCpnt->result = DID_ABORT << 16; 2040 cmd->Current_SCpnt->result = DID_ABORT << 16;
diff --git a/drivers/ieee1394/sbp2.h b/drivers/ieee1394/sbp2.h
index 875428bc8d29..c5036f1cc5b0 100644
--- a/drivers/ieee1394/sbp2.h
+++ b/drivers/ieee1394/sbp2.h
@@ -139,13 +139,10 @@ struct sbp2_logout_orb {
139 u32 status_fifo_lo; 139 u32 status_fifo_lo;
140} __attribute__((packed)); 140} __attribute__((packed));
141 141
142#define PAGE_TABLE_SET_SEGMENT_BASE_HI(v) ((v) & 0xffff)
143#define PAGE_TABLE_SET_SEGMENT_LENGTH(v) (((v) & 0xffff) << 16)
144
145struct sbp2_unrestricted_page_table { 142struct sbp2_unrestricted_page_table {
146 u32 length_segment_base_hi; 143 __be32 high;
147 u32 segment_base_lo; 144 __be32 low;
148} __attribute__((packed)); 145};
149 146
150#define RESP_STATUS_REQUEST_COMPLETE 0x0 147#define RESP_STATUS_REQUEST_COMPLETE 0x0
151#define RESP_STATUS_TRANSPORT_FAILURE 0x1 148#define RESP_STATUS_TRANSPORT_FAILURE 0x1
@@ -216,15 +213,18 @@ struct sbp2_status_block {
216#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e 213#define SBP2_UNIT_SPEC_ID_ENTRY 0x0000609e
217#define SBP2_SW_VERSION_ENTRY 0x00010483 214#define SBP2_SW_VERSION_ENTRY 0x00010483
218 215
219
220/* 216/*
221 * SCSI specific definitions 217 * The default maximum s/g segment size of a FireWire controller is
218 * usually 0x10000, but SBP-2 only allows 0xffff. Since buffers have to
219 * be quadlet-aligned, we set the length limit to 0xffff & ~3.
222 */ 220 */
221#define SBP2_MAX_SEG_SIZE 0xfffc
223 222
224#define SBP2_MAX_SG_ELEMENT_LENGTH 0xf000 223/*
225/* There is no real limitation of the queue depth (i.e. length of the linked 224 * There is no real limitation of the queue depth (i.e. length of the linked
226 * list of command ORBs) at the target. The chosen depth is merely an 225 * list of command ORBs) at the target. The chosen depth is merely an
227 * implementation detail of the sbp2 driver. */ 226 * implementation detail of the sbp2 driver.
227 */
228#define SBP2_MAX_CMDS 8 228#define SBP2_MAX_CMDS 8
229 229
230#define SBP2_SCSI_STATUS_GOOD 0x0 230#define SBP2_SCSI_STATUS_GOOD 0x0
@@ -240,12 +240,6 @@ struct sbp2_status_block {
240 * Representations of commands and devices 240 * Representations of commands and devices
241 */ 241 */
242 242
243enum sbp2_dma_types {
244 CMD_DMA_NONE,
245 CMD_DMA_PAGE,
246 CMD_DMA_SINGLE
247};
248
249/* Per SCSI command */ 243/* Per SCSI command */
250struct sbp2_command_info { 244struct sbp2_command_info {
251 struct list_head list; 245 struct list_head list;
@@ -258,11 +252,6 @@ struct sbp2_command_info {
258 struct sbp2_unrestricted_page_table 252 struct sbp2_unrestricted_page_table
259 scatter_gather_element[SG_ALL] __attribute__((aligned(8))); 253 scatter_gather_element[SG_ALL] __attribute__((aligned(8)));
260 dma_addr_t sge_dma; 254 dma_addr_t sge_dma;
261 void *sge_buffer;
262 dma_addr_t cmd_dma;
263 enum sbp2_dma_types dma_type;
264 unsigned long dma_size;
265 enum dma_data_direction dma_dir;
266}; 255};
267 256
268/* Per FireWire host */ 257/* Per FireWire host */
diff --git a/drivers/ieee1394/video1394.c b/drivers/ieee1394/video1394.c
index 25db6e67fa4e..679a918a5cc7 100644
--- a/drivers/ieee1394/video1394.c
+++ b/drivers/ieee1394/video1394.c
@@ -893,7 +893,7 @@ static long video1394_ioctl(struct file *file,
893 if (unlikely(d == NULL)) 893 if (unlikely(d == NULL))
894 return -EFAULT; 894 return -EFAULT;
895 895
896 if (unlikely((v.buffer<0) || (v.buffer>=d->num_desc - 1))) { 896 if (unlikely(v.buffer >= d->num_desc - 1)) {
897 PRINT(KERN_ERR, ohci->host->id, 897 PRINT(KERN_ERR, ohci->host->id,
898 "Buffer %d out of range",v.buffer); 898 "Buffer %d out of range",v.buffer);
899 return -EINVAL; 899 return -EINVAL;
@@ -959,7 +959,7 @@ static long video1394_ioctl(struct file *file,
959 if (unlikely(d == NULL)) 959 if (unlikely(d == NULL))
960 return -EFAULT; 960 return -EFAULT;
961 961
962 if (unlikely((v.buffer<0) || (v.buffer>d->num_desc - 1))) { 962 if (unlikely(v.buffer > d->num_desc - 1)) {
963 PRINT(KERN_ERR, ohci->host->id, 963 PRINT(KERN_ERR, ohci->host->id,
964 "Buffer %d out of range",v.buffer); 964 "Buffer %d out of range",v.buffer);
965 return -EINVAL; 965 return -EINVAL;
@@ -1030,7 +1030,7 @@ static long video1394_ioctl(struct file *file,
1030 d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel); 1030 d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel);
1031 if (d == NULL) return -EFAULT; 1031 if (d == NULL) return -EFAULT;
1032 1032
1033 if ((v.buffer<0) || (v.buffer>=d->num_desc - 1)) { 1033 if (v.buffer >= d->num_desc - 1) {
1034 PRINT(KERN_ERR, ohci->host->id, 1034 PRINT(KERN_ERR, ohci->host->id,
1035 "Buffer %d out of range",v.buffer); 1035 "Buffer %d out of range",v.buffer);
1036 return -EINVAL; 1036 return -EINVAL;
@@ -1137,7 +1137,7 @@ static long video1394_ioctl(struct file *file,
1137 d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel); 1137 d = find_ctx(&ctx->context_list, OHCI_ISO_TRANSMIT, v.channel);
1138 if (d == NULL) return -EFAULT; 1138 if (d == NULL) return -EFAULT;
1139 1139
1140 if ((v.buffer<0) || (v.buffer>=d->num_desc-1)) { 1140 if (v.buffer >= d->num_desc - 1) {
1141 PRINT(KERN_ERR, ohci->host->id, 1141 PRINT(KERN_ERR, ohci->host->id,
1142 "Buffer %d out of range",v.buffer); 1142 "Buffer %d out of range",v.buffer);
1143 return -EINVAL; 1143 return -EINVAL;
@@ -1341,9 +1341,8 @@ static void video1394_add_host (struct hpsb_host *host)
1341 hpsb_set_hostinfo_key(&video1394_highlevel, host, ohci->host->id); 1341 hpsb_set_hostinfo_key(&video1394_highlevel, host, ohci->host->id);
1342 1342
1343 minor = IEEE1394_MINOR_BLOCK_VIDEO1394 * 16 + ohci->host->id; 1343 minor = IEEE1394_MINOR_BLOCK_VIDEO1394 * 16 + ohci->host->id;
1344 device_create_drvdata(hpsb_protocol_class, NULL, 1344 device_create(hpsb_protocol_class, NULL, MKDEV(IEEE1394_MAJOR, minor),
1345 MKDEV(IEEE1394_MAJOR, minor), NULL, 1345 NULL, "%s-%d", VIDEO1394_DRIVER_NAME, ohci->host->id);
1346 "%s-%d", VIDEO1394_DRIVER_NAME, ohci->host->id);
1347} 1346}
1348 1347
1349 1348
diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
index 3cab0cedfca2..a78d35aecee3 100644
--- a/drivers/infiniband/core/cm.c
+++ b/drivers/infiniband/core/cm.c
@@ -3691,9 +3691,9 @@ static void cm_add_one(struct ib_device *ib_device)
3691 cm_dev->ib_device = ib_device; 3691 cm_dev->ib_device = ib_device;
3692 cm_get_ack_delay(cm_dev); 3692 cm_get_ack_delay(cm_dev);
3693 3693
3694 cm_dev->device = device_create_drvdata(&cm_class, &ib_device->dev, 3694 cm_dev->device = device_create(&cm_class, &ib_device->dev,
3695 MKDEV(0, 0), NULL, 3695 MKDEV(0, 0), NULL,
3696 "%s", ib_device->name); 3696 "%s", ib_device->name);
3697 if (!cm_dev->device) { 3697 if (!cm_dev->device) {
3698 kfree(cm_dev); 3698 kfree(cm_dev);
3699 return; 3699 return;
diff --git a/drivers/infiniband/core/user_mad.c b/drivers/infiniband/core/user_mad.c
index 268a2d23b7c9..8c46f2257098 100644
--- a/drivers/infiniband/core/user_mad.c
+++ b/drivers/infiniband/core/user_mad.c
@@ -1016,9 +1016,9 @@ static int ib_umad_init_port(struct ib_device *device, int port_num,
1016 if (cdev_add(port->cdev, base_dev + port->dev_num, 1)) 1016 if (cdev_add(port->cdev, base_dev + port->dev_num, 1))
1017 goto err_cdev; 1017 goto err_cdev;
1018 1018
1019 port->dev = device_create_drvdata(umad_class, device->dma_device, 1019 port->dev = device_create(umad_class, device->dma_device,
1020 port->cdev->dev, port, 1020 port->cdev->dev, port,
1021 "umad%d", port->dev_num); 1021 "umad%d", port->dev_num);
1022 if (IS_ERR(port->dev)) 1022 if (IS_ERR(port->dev))
1023 goto err_cdev; 1023 goto err_cdev;
1024 1024
@@ -1036,9 +1036,9 @@ static int ib_umad_init_port(struct ib_device *device, int port_num,
1036 if (cdev_add(port->sm_cdev, base_dev + port->dev_num + IB_UMAD_MAX_PORTS, 1)) 1036 if (cdev_add(port->sm_cdev, base_dev + port->dev_num + IB_UMAD_MAX_PORTS, 1))
1037 goto err_sm_cdev; 1037 goto err_sm_cdev;
1038 1038
1039 port->sm_dev = device_create_drvdata(umad_class, device->dma_device, 1039 port->sm_dev = device_create(umad_class, device->dma_device,
1040 port->sm_cdev->dev, port, 1040 port->sm_cdev->dev, port,
1041 "issm%d", port->dev_num); 1041 "issm%d", port->dev_num);
1042 if (IS_ERR(port->sm_dev)) 1042 if (IS_ERR(port->sm_dev))
1043 goto err_sm_cdev; 1043 goto err_sm_cdev;
1044 1044
diff --git a/drivers/infiniband/core/uverbs_main.c b/drivers/infiniband/core/uverbs_main.c
index aeee856c4060..d85af1b67027 100644
--- a/drivers/infiniband/core/uverbs_main.c
+++ b/drivers/infiniband/core/uverbs_main.c
@@ -764,12 +764,9 @@ static void ib_uverbs_add_one(struct ib_device *device)
764 if (cdev_add(uverbs_dev->cdev, IB_UVERBS_BASE_DEV + uverbs_dev->devnum, 1)) 764 if (cdev_add(uverbs_dev->cdev, IB_UVERBS_BASE_DEV + uverbs_dev->devnum, 1))
765 goto err_cdev; 765 goto err_cdev;
766 766
767 uverbs_dev->dev = device_create_drvdata(uverbs_class, 767 uverbs_dev->dev = device_create(uverbs_class, device->dma_device,
768 device->dma_device, 768 uverbs_dev->cdev->dev, uverbs_dev,
769 uverbs_dev->cdev->dev, 769 "uverbs%d", uverbs_dev->devnum);
770 uverbs_dev,
771 "uverbs%d",
772 uverbs_dev->devnum);
773 if (IS_ERR(uverbs_dev->dev)) 770 if (IS_ERR(uverbs_dev->dev))
774 goto err_cdev; 771 goto err_cdev;
775 772
diff --git a/drivers/infiniband/hw/ipath/ipath_file_ops.c b/drivers/infiniband/hw/ipath/ipath_file_ops.c
index 56c0eda3c077..1af1f3a907c6 100644
--- a/drivers/infiniband/hw/ipath/ipath_file_ops.c
+++ b/drivers/infiniband/hw/ipath/ipath_file_ops.c
@@ -2455,7 +2455,7 @@ static int init_cdev(int minor, char *name, const struct file_operations *fops,
2455 goto err_cdev; 2455 goto err_cdev;
2456 } 2456 }
2457 2457
2458 device = device_create_drvdata(ipath_class, NULL, dev, NULL, name); 2458 device = device_create(ipath_class, NULL, dev, NULL, name);
2459 2459
2460 if (IS_ERR(device)) { 2460 if (IS_ERR(device)) {
2461 ret = PTR_ERR(device); 2461 ret = PTR_ERR(device);
diff --git a/drivers/infiniband/ulp/srp/ib_srp.c b/drivers/infiniband/ulp/srp/ib_srp.c
index ed7c5f72cb8b..5b8b533f2908 100644
--- a/drivers/infiniband/ulp/srp/ib_srp.c
+++ b/drivers/infiniband/ulp/srp/ib_srp.c
@@ -1683,7 +1683,7 @@ enum {
1683 SRP_OPT_SERVICE_ID), 1683 SRP_OPT_SERVICE_ID),
1684}; 1684};
1685 1685
1686static match_table_t srp_opt_tokens = { 1686static const match_table_t srp_opt_tokens = {
1687 { SRP_OPT_ID_EXT, "id_ext=%s" }, 1687 { SRP_OPT_ID_EXT, "id_ext=%s" },
1688 { SRP_OPT_IOC_GUID, "ioc_guid=%s" }, 1688 { SRP_OPT_IOC_GUID, "ioc_guid=%s" },
1689 { SRP_OPT_DGID, "dgid=%s" }, 1689 { SRP_OPT_DGID, "dgid=%s" },
diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
index 078e4eed0894..2880eaae157a 100644
--- a/drivers/input/gameport/gameport.c
+++ b/drivers/input/gameport/gameport.c
@@ -231,6 +231,7 @@ static void gameport_find_driver(struct gameport *gameport)
231enum gameport_event_type { 231enum gameport_event_type {
232 GAMEPORT_REGISTER_PORT, 232 GAMEPORT_REGISTER_PORT,
233 GAMEPORT_REGISTER_DRIVER, 233 GAMEPORT_REGISTER_DRIVER,
234 GAMEPORT_ATTACH_DRIVER,
234}; 235};
235 236
236struct gameport_event { 237struct gameport_event {
@@ -245,11 +246,12 @@ static LIST_HEAD(gameport_event_list);
245static DECLARE_WAIT_QUEUE_HEAD(gameport_wait); 246static DECLARE_WAIT_QUEUE_HEAD(gameport_wait);
246static struct task_struct *gameport_task; 247static struct task_struct *gameport_task;
247 248
248static void gameport_queue_event(void *object, struct module *owner, 249static int gameport_queue_event(void *object, struct module *owner,
249 enum gameport_event_type event_type) 250 enum gameport_event_type event_type)
250{ 251{
251 unsigned long flags; 252 unsigned long flags;
252 struct gameport_event *event; 253 struct gameport_event *event;
254 int retval = 0;
253 255
254 spin_lock_irqsave(&gameport_event_lock, flags); 256 spin_lock_irqsave(&gameport_event_lock, flags);
255 257
@@ -268,24 +270,34 @@ static void gameport_queue_event(void *object, struct module *owner,
268 } 270 }
269 } 271 }
270 272
271 if ((event = kmalloc(sizeof(struct gameport_event), GFP_ATOMIC))) { 273 event = kmalloc(sizeof(struct gameport_event), GFP_ATOMIC);
272 if (!try_module_get(owner)) { 274 if (!event) {
273 printk(KERN_WARNING "gameport: Can't get module reference, dropping event %d\n", event_type); 275 printk(KERN_ERR
274 kfree(event); 276 "gameport: Not enough memory to queue event %d\n",
275 goto out; 277 event_type);
276 } 278 retval = -ENOMEM;
277 279 goto out;
278 event->type = event_type; 280 }
279 event->object = object;
280 event->owner = owner;
281 281
282 list_add_tail(&event->node, &gameport_event_list); 282 if (!try_module_get(owner)) {
283 wake_up(&gameport_wait); 283 printk(KERN_WARNING
284 } else { 284 "gameport: Can't get module reference, dropping event %d\n",
285 printk(KERN_ERR "gameport: Not enough memory to queue event %d\n", event_type); 285 event_type);
286 kfree(event);
287 retval = -EINVAL;
288 goto out;
286 } 289 }
290
291 event->type = event_type;
292 event->object = object;
293 event->owner = owner;
294
295 list_add_tail(&event->node, &gameport_event_list);
296 wake_up(&gameport_wait);
297
287out: 298out:
288 spin_unlock_irqrestore(&gameport_event_lock, flags); 299 spin_unlock_irqrestore(&gameport_event_lock, flags);
300 return retval;
289} 301}
290 302
291static void gameport_free_event(struct gameport_event *event) 303static void gameport_free_event(struct gameport_event *event)
@@ -378,9 +390,10 @@ static void gameport_handle_event(void)
378} 390}
379 391
380/* 392/*
381 * Remove all events that have been submitted for a given gameport port. 393 * Remove all events that have been submitted for a given object,
394 * be it a gameport port or a driver.
382 */ 395 */
383static void gameport_remove_pending_events(struct gameport *gameport) 396static void gameport_remove_pending_events(void *object)
384{ 397{
385 struct list_head *node, *next; 398 struct list_head *node, *next;
386 struct gameport_event *event; 399 struct gameport_event *event;
@@ -390,7 +403,7 @@ static void gameport_remove_pending_events(struct gameport *gameport)
390 403
391 list_for_each_safe(node, next, &gameport_event_list) { 404 list_for_each_safe(node, next, &gameport_event_list) {
392 event = list_entry(node, struct gameport_event, node); 405 event = list_entry(node, struct gameport_event, node);
393 if (event->object == gameport) { 406 if (event->object == object) {
394 list_del_init(node); 407 list_del_init(node);
395 gameport_free_event(event); 408 gameport_free_event(event);
396 } 409 }
@@ -705,10 +718,40 @@ static void gameport_add_driver(struct gameport_driver *drv)
705 drv->driver.name, error); 718 drv->driver.name, error);
706} 719}
707 720
708void __gameport_register_driver(struct gameport_driver *drv, struct module *owner) 721int __gameport_register_driver(struct gameport_driver *drv, struct module *owner,
722 const char *mod_name)
709{ 723{
724 int error;
725
710 drv->driver.bus = &gameport_bus; 726 drv->driver.bus = &gameport_bus;
711 gameport_queue_event(drv, owner, GAMEPORT_REGISTER_DRIVER); 727 drv->driver.owner = owner;
728 drv->driver.mod_name = mod_name;
729
730 /*
731 * Temporarily disable automatic binding because probing
732 * takes long time and we are better off doing it in kgameportd
733 */
734 drv->ignore = 1;
735
736 error = driver_register(&drv->driver);
737 if (error) {
738 printk(KERN_ERR
739 "gameport: driver_register() failed for %s, error: %d\n",
740 drv->driver.name, error);
741 return error;
742 }
743
744 /*
745 * Reset ignore flag and let kgameportd bind the driver to free ports
746 */
747 drv->ignore = 0;
748 error = gameport_queue_event(drv, NULL, GAMEPORT_ATTACH_DRIVER);
749 if (error) {
750 driver_unregister(&drv->driver);
751 return error;
752 }
753
754 return 0;
712} 755}
713 756
714void gameport_unregister_driver(struct gameport_driver *drv) 757void gameport_unregister_driver(struct gameport_driver *drv)
@@ -716,7 +759,9 @@ void gameport_unregister_driver(struct gameport_driver *drv)
716 struct gameport *gameport; 759 struct gameport *gameport;
717 760
718 mutex_lock(&gameport_mutex); 761 mutex_lock(&gameport_mutex);
762
719 drv->ignore = 1; /* so gameport_find_driver ignores it */ 763 drv->ignore = 1; /* so gameport_find_driver ignores it */
764 gameport_remove_pending_events(drv);
720 765
721start_over: 766start_over:
722 list_for_each_entry(gameport, &gameport_list, node) { 767 list_for_each_entry(gameport, &gameport_list, node) {
@@ -729,6 +774,7 @@ start_over:
729 } 774 }
730 775
731 driver_unregister(&drv->driver); 776 driver_unregister(&drv->driver);
777
732 mutex_unlock(&gameport_mutex); 778 mutex_unlock(&gameport_mutex);
733} 779}
734 780
diff --git a/drivers/input/joystick/a3d.c b/drivers/input/joystick/a3d.c
index 92498d470b1f..6489f4010c4f 100644
--- a/drivers/input/joystick/a3d.c
+++ b/drivers/input/joystick/a3d.c
@@ -414,8 +414,7 @@ static struct gameport_driver a3d_drv = {
414 414
415static int __init a3d_init(void) 415static int __init a3d_init(void)
416{ 416{
417 gameport_register_driver(&a3d_drv); 417 return gameport_register_driver(&a3d_drv);
418 return 0;
419} 418}
420 419
421static void __exit a3d_exit(void) 420static void __exit a3d_exit(void)
diff --git a/drivers/input/joystick/adi.c b/drivers/input/joystick/adi.c
index d1ca8a14950f..89c4c084d4ad 100644
--- a/drivers/input/joystick/adi.c
+++ b/drivers/input/joystick/adi.c
@@ -572,8 +572,7 @@ static struct gameport_driver adi_drv = {
572 572
573static int __init adi_init(void) 573static int __init adi_init(void)
574{ 574{
575 gameport_register_driver(&adi_drv); 575 return gameport_register_driver(&adi_drv);
576 return 0;
577} 576}
578 577
579static void __exit adi_exit(void) 578static void __exit adi_exit(void)
diff --git a/drivers/input/joystick/analog.c b/drivers/input/joystick/analog.c
index 708c5ae13b24..356b3a25efa2 100644
--- a/drivers/input/joystick/analog.c
+++ b/drivers/input/joystick/analog.c
@@ -761,9 +761,7 @@ static struct gameport_driver analog_drv = {
761static int __init analog_init(void) 761static int __init analog_init(void)
762{ 762{
763 analog_parse_options(); 763 analog_parse_options();
764 gameport_register_driver(&analog_drv); 764 return gameport_register_driver(&analog_drv);
765
766 return 0;
767} 765}
768 766
769static void __exit analog_exit(void) 767static void __exit analog_exit(void)
diff --git a/drivers/input/joystick/cobra.c b/drivers/input/joystick/cobra.c
index 639b975a8ed7..3497b87c3d05 100644
--- a/drivers/input/joystick/cobra.c
+++ b/drivers/input/joystick/cobra.c
@@ -263,8 +263,7 @@ static struct gameport_driver cobra_drv = {
263 263
264static int __init cobra_init(void) 264static int __init cobra_init(void)
265{ 265{
266 gameport_register_driver(&cobra_drv); 266 return gameport_register_driver(&cobra_drv);
267 return 0;
268} 267}
269 268
270static void __exit cobra_exit(void) 269static void __exit cobra_exit(void)
diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
index cb6eef1f2d99..67c207f5b1a1 100644
--- a/drivers/input/joystick/gf2k.c
+++ b/drivers/input/joystick/gf2k.c
@@ -375,8 +375,7 @@ static struct gameport_driver gf2k_drv = {
375 375
376static int __init gf2k_init(void) 376static int __init gf2k_init(void)
377{ 377{
378 gameport_register_driver(&gf2k_drv); 378 return gameport_register_driver(&gf2k_drv);
379 return 0;
380} 379}
381 380
382static void __exit gf2k_exit(void) 381static void __exit gf2k_exit(void)
diff --git a/drivers/input/joystick/grip.c b/drivers/input/joystick/grip.c
index 684e07cfccc8..fc55899ba6c5 100644
--- a/drivers/input/joystick/grip.c
+++ b/drivers/input/joystick/grip.c
@@ -426,8 +426,7 @@ static struct gameport_driver grip_drv = {
426 426
427static int __init grip_init(void) 427static int __init grip_init(void)
428{ 428{
429 gameport_register_driver(&grip_drv); 429 return gameport_register_driver(&grip_drv);
430 return 0;
431} 430}
432 431
433static void __exit grip_exit(void) 432static void __exit grip_exit(void)
diff --git a/drivers/input/joystick/grip_mp.c b/drivers/input/joystick/grip_mp.c
index 8279481b16e7..2d47baf47769 100644
--- a/drivers/input/joystick/grip_mp.c
+++ b/drivers/input/joystick/grip_mp.c
@@ -689,8 +689,7 @@ static struct gameport_driver grip_drv = {
689 689
690static int __init grip_init(void) 690static int __init grip_init(void)
691{ 691{
692 gameport_register_driver(&grip_drv); 692 return gameport_register_driver(&grip_drv);
693 return 0;
694} 693}
695 694
696static void __exit grip_exit(void) 695static void __exit grip_exit(void)
diff --git a/drivers/input/joystick/guillemot.c b/drivers/input/joystick/guillemot.c
index 25ec3fad9f27..4058d4b272fe 100644
--- a/drivers/input/joystick/guillemot.c
+++ b/drivers/input/joystick/guillemot.c
@@ -283,8 +283,7 @@ static struct gameport_driver guillemot_drv = {
283 283
284static int __init guillemot_init(void) 284static int __init guillemot_init(void)
285{ 285{
286 gameport_register_driver(&guillemot_drv); 286 return gameport_register_driver(&guillemot_drv);
287 return 0;
288} 287}
289 288
290static void __exit guillemot_exit(void) 289static void __exit guillemot_exit(void)
diff --git a/drivers/input/joystick/interact.c b/drivers/input/joystick/interact.c
index 8c3290b68205..2478289aeeea 100644
--- a/drivers/input/joystick/interact.c
+++ b/drivers/input/joystick/interact.c
@@ -317,8 +317,7 @@ static struct gameport_driver interact_drv = {
317 317
318static int __init interact_init(void) 318static int __init interact_init(void)
319{ 319{
320 gameport_register_driver(&interact_drv); 320 return gameport_register_driver(&interact_drv);
321 return 0;
322} 321}
323 322
324static void __exit interact_exit(void) 323static void __exit interact_exit(void)
diff --git a/drivers/input/joystick/joydump.c b/drivers/input/joystick/joydump.c
index 2a1b82c8b31c..cd894a0564a2 100644
--- a/drivers/input/joystick/joydump.c
+++ b/drivers/input/joystick/joydump.c
@@ -161,8 +161,7 @@ static struct gameport_driver joydump_drv = {
161 161
162static int __init joydump_init(void) 162static int __init joydump_init(void)
163{ 163{
164 gameport_register_driver(&joydump_drv); 164 return gameport_register_driver(&joydump_drv);
165 return 0;
166} 165}
167 166
168static void __exit joydump_exit(void) 167static void __exit joydump_exit(void)
diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
index 7b4865fdee54..ca13a6bec33e 100644
--- a/drivers/input/joystick/sidewinder.c
+++ b/drivers/input/joystick/sidewinder.c
@@ -818,8 +818,7 @@ static struct gameport_driver sw_drv = {
818 818
819static int __init sw_init(void) 819static int __init sw_init(void)
820{ 820{
821 gameport_register_driver(&sw_drv); 821 return gameport_register_driver(&sw_drv);
822 return 0;
823} 822}
824 823
825static void __exit sw_exit(void) 824static void __exit sw_exit(void)
diff --git a/drivers/input/joystick/tmdc.c b/drivers/input/joystick/tmdc.c
index 60c37bcb938d..d6c609807115 100644
--- a/drivers/input/joystick/tmdc.c
+++ b/drivers/input/joystick/tmdc.c
@@ -438,8 +438,7 @@ static struct gameport_driver tmdc_drv = {
438 438
439static int __init tmdc_init(void) 439static int __init tmdc_init(void)
440{ 440{
441 gameport_register_driver(&tmdc_drv); 441 return gameport_register_driver(&tmdc_drv);
442 return 0;
443} 442}
444 443
445static void __exit tmdc_exit(void) 444static void __exit tmdc_exit(void)
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 6791be81eb29..839d1c9622f6 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -455,10 +455,10 @@ static void xpad_bulk_out(struct urb *urb)
455 case -ENOENT: 455 case -ENOENT:
456 case -ESHUTDOWN: 456 case -ESHUTDOWN:
457 /* this urb is terminated, clean up */ 457 /* this urb is terminated, clean up */
458 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); 458 dbg("%s - urb shutting down with status: %d", __func__, urb->status);
459 break; 459 break;
460 default: 460 default:
461 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); 461 dbg("%s - nonzero urb status received: %d", __func__, urb->status);
462 } 462 }
463} 463}
464 464
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index b1ce10f50bcf..22016ca15351 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -834,10 +834,10 @@ static void atkbd_disconnect(struct serio *serio)
834} 834}
835 835
836/* 836/*
837 * Most special keys (Fn+F?) on Dell Latitudes do not generate release 837 * Most special keys (Fn+F?) on Dell laptops do not generate release
838 * events so we have to do it ourselves. 838 * events so we have to do it ourselves.
839 */ 839 */
840static void atkbd_latitude_keymap_fixup(struct atkbd *atkbd) 840static void atkbd_dell_laptop_keymap_fixup(struct atkbd *atkbd)
841{ 841{
842 const unsigned int forced_release_keys[] = { 842 const unsigned int forced_release_keys[] = {
843 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8f, 0x93, 843 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8f, 0x93,
@@ -1207,15 +1207,13 @@ static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t coun
1207{ 1207{
1208 struct input_dev *old_dev, *new_dev; 1208 struct input_dev *old_dev, *new_dev;
1209 unsigned long value; 1209 unsigned long value;
1210 char *rest;
1211 int err; 1210 int err;
1212 unsigned char old_extra, old_set; 1211 unsigned char old_extra, old_set;
1213 1212
1214 if (!atkbd->write) 1213 if (!atkbd->write)
1215 return -EIO; 1214 return -EIO;
1216 1215
1217 value = simple_strtoul(buf, &rest, 10); 1216 if (strict_strtoul(buf, 10, &value) || value > 1)
1218 if (*rest || value > 1)
1219 return -EINVAL; 1217 return -EINVAL;
1220 1218
1221 if (atkbd->extra != value) { 1219 if (atkbd->extra != value) {
@@ -1264,12 +1262,10 @@ static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t cou
1264{ 1262{
1265 struct input_dev *old_dev, *new_dev; 1263 struct input_dev *old_dev, *new_dev;
1266 unsigned long value; 1264 unsigned long value;
1267 char *rest;
1268 int err; 1265 int err;
1269 unsigned char old_scroll; 1266 unsigned char old_scroll;
1270 1267
1271 value = simple_strtoul(buf, &rest, 10); 1268 if (strict_strtoul(buf, 10, &value) || value > 1)
1272 if (*rest || value > 1)
1273 return -EINVAL; 1269 return -EINVAL;
1274 1270
1275 if (atkbd->scroll != value) { 1271 if (atkbd->scroll != value) {
@@ -1310,15 +1306,13 @@ static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
1310{ 1306{
1311 struct input_dev *old_dev, *new_dev; 1307 struct input_dev *old_dev, *new_dev;
1312 unsigned long value; 1308 unsigned long value;
1313 char *rest;
1314 int err; 1309 int err;
1315 unsigned char old_set, old_extra; 1310 unsigned char old_set, old_extra;
1316 1311
1317 if (!atkbd->write) 1312 if (!atkbd->write)
1318 return -EIO; 1313 return -EIO;
1319 1314
1320 value = simple_strtoul(buf, &rest, 10); 1315 if (strict_strtoul(buf, 10, &value) || (value != 2 && value != 3))
1321 if (*rest || (value != 2 && value != 3))
1322 return -EINVAL; 1316 return -EINVAL;
1323 1317
1324 if (atkbd->set != value) { 1318 if (atkbd->set != value) {
@@ -1361,15 +1355,13 @@ static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t
1361{ 1355{
1362 struct input_dev *old_dev, *new_dev; 1356 struct input_dev *old_dev, *new_dev;
1363 unsigned long value; 1357 unsigned long value;
1364 char *rest;
1365 int err; 1358 int err;
1366 unsigned char old_softrepeat, old_softraw; 1359 unsigned char old_softrepeat, old_softraw;
1367 1360
1368 if (!atkbd->write) 1361 if (!atkbd->write)
1369 return -EIO; 1362 return -EIO;
1370 1363
1371 value = simple_strtoul(buf, &rest, 10); 1364 if (strict_strtoul(buf, 10, &value) || value > 1)
1372 if (*rest || value > 1)
1373 return -EINVAL; 1365 return -EINVAL;
1374 1366
1375 if (atkbd->softrepeat != value) { 1367 if (atkbd->softrepeat != value) {
@@ -1413,12 +1405,10 @@ static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t co
1413{ 1405{
1414 struct input_dev *old_dev, *new_dev; 1406 struct input_dev *old_dev, *new_dev;
1415 unsigned long value; 1407 unsigned long value;
1416 char *rest;
1417 int err; 1408 int err;
1418 unsigned char old_softraw; 1409 unsigned char old_softraw;
1419 1410
1420 value = simple_strtoul(buf, &rest, 10); 1411 if (strict_strtoul(buf, 10, &value) || value > 1)
1421 if (*rest || value > 1)
1422 return -EINVAL; 1412 return -EINVAL;
1423 1413
1424 if (atkbd->softraw != value) { 1414 if (atkbd->softraw != value) {
@@ -1461,13 +1451,13 @@ static int __init atkbd_setup_fixup(const struct dmi_system_id *id)
1461 1451
1462static struct dmi_system_id atkbd_dmi_quirk_table[] __initdata = { 1452static struct dmi_system_id atkbd_dmi_quirk_table[] __initdata = {
1463 { 1453 {
1464 .ident = "Dell Latitude series", 1454 .ident = "Dell Laptop",
1465 .matches = { 1455 .matches = {
1466 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."), 1456 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1467 DMI_MATCH(DMI_PRODUCT_NAME, "Latitude"), 1457 DMI_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
1468 }, 1458 },
1469 .callback = atkbd_setup_fixup, 1459 .callback = atkbd_setup_fixup,
1470 .driver_data = atkbd_latitude_keymap_fixup, 1460 .driver_data = atkbd_dell_laptop_keymap_fixup,
1471 }, 1461 },
1472 { 1462 {
1473 .ident = "HP 2133", 1463 .ident = "HP 2133",
diff --git a/drivers/input/keyboard/bf54x-keys.c b/drivers/input/keyboard/bf54x-keys.c
index e348cfccc17a..19284016e0f4 100644
--- a/drivers/input/keyboard/bf54x-keys.c
+++ b/drivers/input/keyboard/bf54x-keys.c
@@ -8,7 +8,7 @@
8 * 8 *
9 * 9 *
10 * Modified: 10 * Modified:
11 * Copyright 2007 Analog Devices Inc. 11 * Copyright 2007-2008 Analog Devices Inc.
12 * 12 *
13 * Bugs: Enter bugs at http://blackfin.uclinux.org/ 13 * Bugs: Enter bugs at http://blackfin.uclinux.org/
14 * 14 *
@@ -81,6 +81,9 @@ struct bf54x_kpad {
81 unsigned short *keycode; 81 unsigned short *keycode;
82 struct timer_list timer; 82 struct timer_list timer;
83 unsigned int keyup_test_jiffies; 83 unsigned int keyup_test_jiffies;
84 unsigned short kpad_msel;
85 unsigned short kpad_prescale;
86 unsigned short kpad_ctl;
84}; 87};
85 88
86static inline int bfin_kpad_find_key(struct bf54x_kpad *bf54x_kpad, 89static inline int bfin_kpad_find_key(struct bf54x_kpad *bf54x_kpad,
@@ -360,6 +363,10 @@ static int bfin_kpad_suspend(struct platform_device *pdev, pm_message_t state)
360{ 363{
361 struct bf54x_kpad *bf54x_kpad = platform_get_drvdata(pdev); 364 struct bf54x_kpad *bf54x_kpad = platform_get_drvdata(pdev);
362 365
366 bf54x_kpad->kpad_msel = bfin_read_KPAD_MSEL();
367 bf54x_kpad->kpad_prescale = bfin_read_KPAD_PRESCALE();
368 bf54x_kpad->kpad_ctl = bfin_read_KPAD_CTL();
369
363 if (device_may_wakeup(&pdev->dev)) 370 if (device_may_wakeup(&pdev->dev))
364 enable_irq_wake(bf54x_kpad->irq); 371 enable_irq_wake(bf54x_kpad->irq);
365 372
@@ -370,6 +377,10 @@ static int bfin_kpad_resume(struct platform_device *pdev)
370{ 377{
371 struct bf54x_kpad *bf54x_kpad = platform_get_drvdata(pdev); 378 struct bf54x_kpad *bf54x_kpad = platform_get_drvdata(pdev);
372 379
380 bfin_write_KPAD_MSEL(bf54x_kpad->kpad_msel);
381 bfin_write_KPAD_PRESCALE(bf54x_kpad->kpad_prescale);
382 bfin_write_KPAD_CTL(bf54x_kpad->kpad_ctl);
383
373 if (device_may_wakeup(&pdev->dev)) 384 if (device_may_wakeup(&pdev->dev))
374 disable_irq_wake(bf54x_kpad->irq); 385 disable_irq_wake(bf54x_kpad->irq);
375 386
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index ec96b369dd7a..05f3f43582c2 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -36,9 +36,10 @@ struct gpio_keys_drvdata {
36 struct gpio_button_data data[0]; 36 struct gpio_button_data data[0];
37}; 37};
38 38
39static void gpio_keys_report_event(struct gpio_keys_button *button, 39static void gpio_keys_report_event(struct gpio_button_data *bdata)
40 struct input_dev *input)
41{ 40{
41 struct gpio_keys_button *button = bdata->button;
42 struct input_dev *input = bdata->input;
42 unsigned int type = button->type ?: EV_KEY; 43 unsigned int type = button->type ?: EV_KEY;
43 int state = (gpio_get_value(button->gpio) ? 1 : 0) ^ button->active_low; 44 int state = (gpio_get_value(button->gpio) ? 1 : 0) ^ button->active_low;
44 45
@@ -50,34 +51,23 @@ static void gpio_check_button(unsigned long _data)
50{ 51{
51 struct gpio_button_data *data = (struct gpio_button_data *)_data; 52 struct gpio_button_data *data = (struct gpio_button_data *)_data;
52 53
53 gpio_keys_report_event(data->button, data->input); 54 gpio_keys_report_event(data);
54} 55}
55 56
56static irqreturn_t gpio_keys_isr(int irq, void *dev_id) 57static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
57{ 58{
58 struct platform_device *pdev = dev_id; 59 struct gpio_button_data *bdata = dev_id;
59 struct gpio_keys_platform_data *pdata = pdev->dev.platform_data; 60 struct gpio_keys_button *button = bdata->button;
60 struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev);
61 int i;
62 61
63 for (i = 0; i < pdata->nbuttons; i++) { 62 BUG_ON(irq != gpio_to_irq(button->gpio));
64 struct gpio_keys_button *button = &pdata->buttons[i];
65 63
66 if (irq == gpio_to_irq(button->gpio)) { 64 if (button->debounce_interval)
67 struct gpio_button_data *bdata = &ddata->data[i]; 65 mod_timer(&bdata->timer,
68 66 jiffies + msecs_to_jiffies(button->debounce_interval));
69 if (button->debounce_interval) 67 else
70 mod_timer(&bdata->timer, 68 gpio_keys_report_event(bdata);
71 jiffies +
72 msecs_to_jiffies(button->debounce_interval));
73 else
74 gpio_keys_report_event(button, bdata->input);
75
76 return IRQ_HANDLED;
77 }
78 }
79 69
80 return IRQ_NONE; 70 return IRQ_HANDLED;
81} 71}
82 72
83static int __devinit gpio_keys_probe(struct platform_device *pdev) 73static int __devinit gpio_keys_probe(struct platform_device *pdev)
@@ -151,7 +141,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
151 IRQF_SAMPLE_RANDOM | IRQF_TRIGGER_RISING | 141 IRQF_SAMPLE_RANDOM | IRQF_TRIGGER_RISING |
152 IRQF_TRIGGER_FALLING, 142 IRQF_TRIGGER_FALLING,
153 button->desc ? button->desc : "gpio_keys", 143 button->desc ? button->desc : "gpio_keys",
154 pdev); 144 bdata);
155 if (error) { 145 if (error) {
156 pr_err("gpio-keys: Unable to claim irq %d; error %d\n", 146 pr_err("gpio-keys: Unable to claim irq %d; error %d\n",
157 irq, error); 147 irq, error);
@@ -178,7 +168,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
178 168
179 fail2: 169 fail2:
180 while (--i >= 0) { 170 while (--i >= 0) {
181 free_irq(gpio_to_irq(pdata->buttons[i].gpio), pdev); 171 free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]);
182 if (pdata->buttons[i].debounce_interval) 172 if (pdata->buttons[i].debounce_interval)
183 del_timer_sync(&ddata->data[i].timer); 173 del_timer_sync(&ddata->data[i].timer);
184 gpio_free(pdata->buttons[i].gpio); 174 gpio_free(pdata->buttons[i].gpio);
@@ -203,7 +193,7 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
203 193
204 for (i = 0; i < pdata->nbuttons; i++) { 194 for (i = 0; i < pdata->nbuttons; i++) {
205 int irq = gpio_to_irq(pdata->buttons[i].gpio); 195 int irq = gpio_to_irq(pdata->buttons[i].gpio);
206 free_irq(irq, pdev); 196 free_irq(irq, &ddata->data[i]);
207 if (pdata->buttons[i].debounce_interval) 197 if (pdata->buttons[i].debounce_interval)
208 del_timer_sync(&ddata->data[i].timer); 198 del_timer_sync(&ddata->data[i].timer);
209 gpio_free(pdata->buttons[i].gpio); 199 gpio_free(pdata->buttons[i].gpio);
diff --git a/drivers/input/keyboard/omap-keypad.c b/drivers/input/keyboard/omap-keypad.c
index dcea87a0bc56..69e674ecf19a 100644
--- a/drivers/input/keyboard/omap-keypad.c
+++ b/drivers/input/keyboard/omap-keypad.c
@@ -62,7 +62,7 @@ struct omap_kp {
62 unsigned int debounce; 62 unsigned int debounce;
63}; 63};
64 64
65DECLARE_TASKLET_DISABLED(kp_tasklet, omap_kp_tasklet, 0); 65static DECLARE_TASKLET_DISABLED(kp_tasklet, omap_kp_tasklet, 0);
66 66
67static int *keymap; 67static int *keymap;
68static unsigned int *row_gpios; 68static unsigned int *row_gpios;
@@ -72,12 +72,9 @@ static unsigned int *col_gpios;
72static void set_col_gpio_val(struct omap_kp *omap_kp, u8 value) 72static void set_col_gpio_val(struct omap_kp *omap_kp, u8 value)
73{ 73{
74 int col; 74 int col;
75 for (col = 0; col < omap_kp->cols; col++) { 75
76 if (value & (1 << col)) 76 for (col = 0; col < omap_kp->cols; col++)
77 omap_set_gpio_dataout(col_gpios[col], 1); 77 gpio_set_value(col_gpios[col], value & (1 << col));
78 else
79 omap_set_gpio_dataout(col_gpios[col], 0);
80 }
81} 78}
82 79
83static u8 get_row_gpio_val(struct omap_kp *omap_kp) 80static u8 get_row_gpio_val(struct omap_kp *omap_kp)
@@ -86,7 +83,7 @@ static u8 get_row_gpio_val(struct omap_kp *omap_kp)
86 u8 value = 0; 83 u8 value = 0;
87 84
88 for (row = 0; row < omap_kp->rows; row++) { 85 for (row = 0; row < omap_kp->rows; row++) {
89 if (omap_get_gpio_datain(row_gpios[row])) 86 if (gpio_get_value(row_gpios[row]))
90 value |= (1 << row); 87 value |= (1 << row);
91 } 88 }
92 return value; 89 return value;
@@ -333,23 +330,23 @@ static int __init omap_kp_probe(struct platform_device *pdev)
333 if (cpu_is_omap24xx()) { 330 if (cpu_is_omap24xx()) {
334 /* Cols: outputs */ 331 /* Cols: outputs */
335 for (col_idx = 0; col_idx < omap_kp->cols; col_idx++) { 332 for (col_idx = 0; col_idx < omap_kp->cols; col_idx++) {
336 if (omap_request_gpio(col_gpios[col_idx]) < 0) { 333 if (gpio_request(col_gpios[col_idx], "omap_kp_col") < 0) {
337 printk(KERN_ERR "Failed to request" 334 printk(KERN_ERR "Failed to request"
338 "GPIO%d for keypad\n", 335 "GPIO%d for keypad\n",
339 col_gpios[col_idx]); 336 col_gpios[col_idx]);
340 goto err1; 337 goto err1;
341 } 338 }
342 omap_set_gpio_direction(col_gpios[col_idx], 0); 339 gpio_direction_output(col_gpios[col_idx], 0);
343 } 340 }
344 /* Rows: inputs */ 341 /* Rows: inputs */
345 for (row_idx = 0; row_idx < omap_kp->rows; row_idx++) { 342 for (row_idx = 0; row_idx < omap_kp->rows; row_idx++) {
346 if (omap_request_gpio(row_gpios[row_idx]) < 0) { 343 if (gpio_request(row_gpios[row_idx], "omap_kp_row") < 0) {
347 printk(KERN_ERR "Failed to request" 344 printk(KERN_ERR "Failed to request"
348 "GPIO%d for keypad\n", 345 "GPIO%d for keypad\n",
349 row_gpios[row_idx]); 346 row_gpios[row_idx]);
350 goto err2; 347 goto err2;
351 } 348 }
352 omap_set_gpio_direction(row_gpios[row_idx], 1); 349 gpio_direction_input(row_gpios[row_idx]);
353 } 350 }
354 } else { 351 } else {
355 col_idx = 0; 352 col_idx = 0;
@@ -418,10 +415,10 @@ err3:
418 device_remove_file(&pdev->dev, &dev_attr_enable); 415 device_remove_file(&pdev->dev, &dev_attr_enable);
419err2: 416err2:
420 for (i = row_idx - 1; i >=0; i--) 417 for (i = row_idx - 1; i >=0; i--)
421 omap_free_gpio(row_gpios[i]); 418 gpio_free(row_gpios[i]);
422err1: 419err1:
423 for (i = col_idx - 1; i >=0; i--) 420 for (i = col_idx - 1; i >=0; i--)
424 omap_free_gpio(col_gpios[i]); 421 gpio_free(col_gpios[i]);
425 422
426 kfree(omap_kp); 423 kfree(omap_kp);
427 input_free_device(input_dev); 424 input_free_device(input_dev);
@@ -438,9 +435,9 @@ static int omap_kp_remove(struct platform_device *pdev)
438 if (cpu_is_omap24xx()) { 435 if (cpu_is_omap24xx()) {
439 int i; 436 int i;
440 for (i = 0; i < omap_kp->cols; i++) 437 for (i = 0; i < omap_kp->cols; i++)
441 omap_free_gpio(col_gpios[i]); 438 gpio_free(col_gpios[i]);
442 for (i = 0; i < omap_kp->rows; i++) { 439 for (i = 0; i < omap_kp->rows; i++) {
443 omap_free_gpio(row_gpios[i]); 440 gpio_free(row_gpios[i]);
444 free_irq(OMAP_GPIO_IRQ(row_gpios[i]), 0); 441 free_irq(OMAP_GPIO_IRQ(row_gpios[i]), 0);
445 } 442 }
446 } else { 443 } else {
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index e99b7882f382..199055db5082 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -180,6 +180,19 @@ config INPUT_YEALINK
180 To compile this driver as a module, choose M here: the module will be 180 To compile this driver as a module, choose M here: the module will be
181 called yealink. 181 called yealink.
182 182
183config INPUT_CM109
184 tristate "C-Media CM109 USB I/O Controller"
185 depends on EXPERIMENTAL
186 depends on USB_ARCH_HAS_HCD
187 select USB
188 help
189 Say Y here if you want to enable keyboard and buzzer functions of the
190 C-Media CM109 usb phones. The audio part is enabled by the generic
191 usb sound driver, so you might want to enable that as well.
192
193 To compile this driver as a module, choose M here: the module will be
194 called cm109.
195
183config INPUT_UINPUT 196config INPUT_UINPUT
184 tristate "User level driver support" 197 tristate "User level driver support"
185 help 198 help
diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile
index f48009b52226..d7db2aeb8a98 100644
--- a/drivers/input/misc/Makefile
+++ b/drivers/input/misc/Makefile
@@ -16,6 +16,7 @@ obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o
16obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) += keyspan_remote.o 16obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) += keyspan_remote.o
17obj-$(CONFIG_INPUT_POWERMATE) += powermate.o 17obj-$(CONFIG_INPUT_POWERMATE) += powermate.o
18obj-$(CONFIG_INPUT_YEALINK) += yealink.o 18obj-$(CONFIG_INPUT_YEALINK) += yealink.o
19obj-$(CONFIG_INPUT_CM109) += cm109.o
19obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o 20obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o
20obj-$(CONFIG_INPUT_UINPUT) += uinput.o 21obj-$(CONFIG_INPUT_UINPUT) += uinput.o
21obj-$(CONFIG_INPUT_APANEL) += apanel.o 22obj-$(CONFIG_INPUT_APANEL) += apanel.o
diff --git a/drivers/input/misc/ati_remote2.c b/drivers/input/misc/ati_remote2.c
index a7fabafbd94c..3c9988dc0e9f 100644
--- a/drivers/input/misc/ati_remote2.c
+++ b/drivers/input/misc/ati_remote2.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * ati_remote2 - ATI/Philips USB RF remote driver 2 * ati_remote2 - ATI/Philips USB RF remote driver
3 * 3 *
4 * Copyright (C) 2005 Ville Syrjala <syrjala@sci.fi> 4 * Copyright (C) 2005-2008 Ville Syrjala <syrjala@sci.fi>
5 * Copyright (C) 2007 Peter Stokes <linux@dadeos.freeserve.co.uk> 5 * Copyright (C) 2007-2008 Peter Stokes <linux@dadeos.co.uk>
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 8 * it under the terms of the GNU General Public License version 2
@@ -12,7 +12,7 @@
12#include <linux/usb/input.h> 12#include <linux/usb/input.h>
13 13
14#define DRIVER_DESC "ATI/Philips USB RF remote driver" 14#define DRIVER_DESC "ATI/Philips USB RF remote driver"
15#define DRIVER_VERSION "0.2" 15#define DRIVER_VERSION "0.3"
16 16
17MODULE_DESCRIPTION(DRIVER_DESC); 17MODULE_DESCRIPTION(DRIVER_DESC);
18MODULE_VERSION(DRIVER_VERSION); 18MODULE_VERSION(DRIVER_VERSION);
@@ -27,7 +27,7 @@ MODULE_LICENSE("GPL");
27 * A remote's "channel" may be altered by pressing and holding the "PC" button for 27 * A remote's "channel" may be altered by pressing and holding the "PC" button for
28 * approximately 3 seconds, after which the button will slowly flash the count of the 28 * approximately 3 seconds, after which the button will slowly flash the count of the
29 * currently configured "channel", using the numeric keypad enter a number between 1 and 29 * currently configured "channel", using the numeric keypad enter a number between 1 and
30 * 16 and then the "PC" button again, the button will slowly flash the count of the 30 * 16 and then press the "PC" button again, the button will slowly flash the count of the
31 * newly configured "channel". 31 * newly configured "channel".
32 */ 32 */
33 33
@@ -45,9 +45,25 @@ static struct usb_device_id ati_remote2_id_table[] = {
45}; 45};
46MODULE_DEVICE_TABLE(usb, ati_remote2_id_table); 46MODULE_DEVICE_TABLE(usb, ati_remote2_id_table);
47 47
48static struct { 48static DEFINE_MUTEX(ati_remote2_mutex);
49 int hw_code; 49
50 int key_code; 50enum {
51 ATI_REMOTE2_OPENED = 0x1,
52 ATI_REMOTE2_SUSPENDED = 0x2,
53};
54
55enum {
56 ATI_REMOTE2_AUX1,
57 ATI_REMOTE2_AUX2,
58 ATI_REMOTE2_AUX3,
59 ATI_REMOTE2_AUX4,
60 ATI_REMOTE2_PC,
61 ATI_REMOTE2_MODES,
62};
63
64static const struct {
65 u8 hw_code;
66 u16 keycode;
51} ati_remote2_key_table[] = { 67} ati_remote2_key_table[] = {
52 { 0x00, KEY_0 }, 68 { 0x00, KEY_0 },
53 { 0x01, KEY_1 }, 69 { 0x01, KEY_1 },
@@ -73,6 +89,7 @@ static struct {
73 { 0x37, KEY_RECORD }, 89 { 0x37, KEY_RECORD },
74 { 0x38, KEY_DVD }, 90 { 0x38, KEY_DVD },
75 { 0x39, KEY_TV }, 91 { 0x39, KEY_TV },
92 { 0x3f, KEY_PROG1 }, /* AUX1-AUX4 and PC */
76 { 0x54, KEY_MENU }, 93 { 0x54, KEY_MENU },
77 { 0x58, KEY_UP }, 94 { 0x58, KEY_UP },
78 { 0x59, KEY_DOWN }, 95 { 0x59, KEY_DOWN },
@@ -91,15 +108,9 @@ static struct {
91 { 0xa9, BTN_LEFT }, 108 { 0xa9, BTN_LEFT },
92 { 0xaa, BTN_RIGHT }, 109 { 0xaa, BTN_RIGHT },
93 { 0xbe, KEY_QUESTION }, 110 { 0xbe, KEY_QUESTION },
94 { 0xd5, KEY_FRONT },
95 { 0xd0, KEY_EDIT }, 111 { 0xd0, KEY_EDIT },
112 { 0xd5, KEY_FRONT },
96 { 0xf9, KEY_INFO }, 113 { 0xf9, KEY_INFO },
97 { (0x00 << 8) | 0x3f, KEY_PROG1 },
98 { (0x01 << 8) | 0x3f, KEY_PROG2 },
99 { (0x02 << 8) | 0x3f, KEY_PROG3 },
100 { (0x03 << 8) | 0x3f, KEY_PROG4 },
101 { (0x04 << 8) | 0x3f, KEY_PC },
102 { 0, KEY_RESERVED }
103}; 114};
104 115
105struct ati_remote2 { 116struct ati_remote2 {
@@ -117,46 +128,106 @@ struct ati_remote2 {
117 128
118 char name[64]; 129 char name[64];
119 char phys[64]; 130 char phys[64];
131
132 /* Each mode (AUX1-AUX4 and PC) can have an independent keymap. */
133 u16 keycode[ATI_REMOTE2_MODES][ARRAY_SIZE(ati_remote2_key_table)];
134
135 unsigned int flags;
120}; 136};
121 137
122static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id); 138static int ati_remote2_probe(struct usb_interface *interface, const struct usb_device_id *id);
123static void ati_remote2_disconnect(struct usb_interface *interface); 139static void ati_remote2_disconnect(struct usb_interface *interface);
140static int ati_remote2_suspend(struct usb_interface *interface, pm_message_t message);
141static int ati_remote2_resume(struct usb_interface *interface);
124 142
125static struct usb_driver ati_remote2_driver = { 143static struct usb_driver ati_remote2_driver = {
126 .name = "ati_remote2", 144 .name = "ati_remote2",
127 .probe = ati_remote2_probe, 145 .probe = ati_remote2_probe,
128 .disconnect = ati_remote2_disconnect, 146 .disconnect = ati_remote2_disconnect,
129 .id_table = ati_remote2_id_table, 147 .id_table = ati_remote2_id_table,
148 .suspend = ati_remote2_suspend,
149 .resume = ati_remote2_resume,
150 .supports_autosuspend = 1,
130}; 151};
131 152
132static int ati_remote2_open(struct input_dev *idev) 153static int ati_remote2_submit_urbs(struct ati_remote2 *ar2)
133{ 154{
134 struct ati_remote2 *ar2 = input_get_drvdata(idev);
135 int r; 155 int r;
136 156
137 r = usb_submit_urb(ar2->urb[0], GFP_KERNEL); 157 r = usb_submit_urb(ar2->urb[0], GFP_KERNEL);
138 if (r) { 158 if (r) {
139 dev_err(&ar2->intf[0]->dev, 159 dev_err(&ar2->intf[0]->dev,
140 "%s: usb_submit_urb() = %d\n", __func__, r); 160 "%s(): usb_submit_urb() = %d\n", __func__, r);
141 return r; 161 return r;
142 } 162 }
143 r = usb_submit_urb(ar2->urb[1], GFP_KERNEL); 163 r = usb_submit_urb(ar2->urb[1], GFP_KERNEL);
144 if (r) { 164 if (r) {
145 usb_kill_urb(ar2->urb[0]); 165 usb_kill_urb(ar2->urb[0]);
146 dev_err(&ar2->intf[1]->dev, 166 dev_err(&ar2->intf[1]->dev,
147 "%s: usb_submit_urb() = %d\n", __func__, r); 167 "%s(): usb_submit_urb() = %d\n", __func__, r);
148 return r; 168 return r;
149 } 169 }
150 170
151 return 0; 171 return 0;
152} 172}
153 173
174static void ati_remote2_kill_urbs(struct ati_remote2 *ar2)
175{
176 usb_kill_urb(ar2->urb[1]);
177 usb_kill_urb(ar2->urb[0]);
178}
179
180static int ati_remote2_open(struct input_dev *idev)
181{
182 struct ati_remote2 *ar2 = input_get_drvdata(idev);
183 int r;
184
185 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
186
187 r = usb_autopm_get_interface(ar2->intf[0]);
188 if (r) {
189 dev_err(&ar2->intf[0]->dev,
190 "%s(): usb_autopm_get_interface() = %d\n", __func__, r);
191 goto fail1;
192 }
193
194 mutex_lock(&ati_remote2_mutex);
195
196 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED)) {
197 r = ati_remote2_submit_urbs(ar2);
198 if (r)
199 goto fail2;
200 }
201
202 ar2->flags |= ATI_REMOTE2_OPENED;
203
204 mutex_unlock(&ati_remote2_mutex);
205
206 usb_autopm_put_interface(ar2->intf[0]);
207
208 return 0;
209
210 fail2:
211 mutex_unlock(&ati_remote2_mutex);
212 usb_autopm_put_interface(ar2->intf[0]);
213 fail1:
214 return r;
215}
216
154static void ati_remote2_close(struct input_dev *idev) 217static void ati_remote2_close(struct input_dev *idev)
155{ 218{
156 struct ati_remote2 *ar2 = input_get_drvdata(idev); 219 struct ati_remote2 *ar2 = input_get_drvdata(idev);
157 220
158 usb_kill_urb(ar2->urb[0]); 221 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
159 usb_kill_urb(ar2->urb[1]); 222
223 mutex_lock(&ati_remote2_mutex);
224
225 if (!(ar2->flags & ATI_REMOTE2_SUSPENDED))
226 ati_remote2_kill_urbs(ar2);
227
228 ar2->flags &= ~ATI_REMOTE2_OPENED;
229
230 mutex_unlock(&ati_remote2_mutex);
160} 231}
161 232
162static void ati_remote2_input_mouse(struct ati_remote2 *ar2) 233static void ati_remote2_input_mouse(struct ati_remote2 *ar2)
@@ -172,7 +243,7 @@ static void ati_remote2_input_mouse(struct ati_remote2 *ar2)
172 243
173 mode = data[0] & 0x0F; 244 mode = data[0] & 0x0F;
174 245
175 if (mode > 4) { 246 if (mode > ATI_REMOTE2_PC) {
176 dev_err(&ar2->intf[0]->dev, 247 dev_err(&ar2->intf[0]->dev,
177 "Unknown mode byte (%02x %02x %02x %02x)\n", 248 "Unknown mode byte (%02x %02x %02x %02x)\n",
178 data[3], data[2], data[1], data[0]); 249 data[3], data[2], data[1], data[0]);
@@ -191,7 +262,7 @@ static int ati_remote2_lookup(unsigned int hw_code)
191{ 262{
192 int i; 263 int i;
193 264
194 for (i = 0; ati_remote2_key_table[i].key_code != KEY_RESERVED; i++) 265 for (i = 0; i < ARRAY_SIZE(ati_remote2_key_table); i++)
195 if (ati_remote2_key_table[i].hw_code == hw_code) 266 if (ati_remote2_key_table[i].hw_code == hw_code)
196 return i; 267 return i;
197 268
@@ -211,7 +282,7 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2)
211 282
212 mode = data[0] & 0x0F; 283 mode = data[0] & 0x0F;
213 284
214 if (mode > 4) { 285 if (mode > ATI_REMOTE2_PC) {
215 dev_err(&ar2->intf[1]->dev, 286 dev_err(&ar2->intf[1]->dev,
216 "Unknown mode byte (%02x %02x %02x %02x)\n", 287 "Unknown mode byte (%02x %02x %02x %02x)\n",
217 data[3], data[2], data[1], data[0]); 288 data[3], data[2], data[1], data[0]);
@@ -219,10 +290,6 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2)
219 } 290 }
220 291
221 hw_code = data[2]; 292 hw_code = data[2];
222 /*
223 * Mode keys (AUX1-AUX4, PC) all generate the same code byte.
224 * Use the mode byte to figure out which one was pressed.
225 */
226 if (hw_code == 0x3f) { 293 if (hw_code == 0x3f) {
227 /* 294 /*
228 * For some incomprehensible reason the mouse pad generates 295 * For some incomprehensible reason the mouse pad generates
@@ -236,8 +303,6 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2)
236 303
237 if (data[1] == 0) 304 if (data[1] == 0)
238 ar2->mode = mode; 305 ar2->mode = mode;
239
240 hw_code |= mode << 8;
241 } 306 }
242 307
243 if (!((1 << mode) & mode_mask)) 308 if (!((1 << mode) & mode_mask))
@@ -260,8 +325,8 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2)
260 case 2: /* repeat */ 325 case 2: /* repeat */
261 326
262 /* No repeat for mouse buttons. */ 327 /* No repeat for mouse buttons. */
263 if (ati_remote2_key_table[index].key_code == BTN_LEFT || 328 if (ar2->keycode[mode][index] == BTN_LEFT ||
264 ati_remote2_key_table[index].key_code == BTN_RIGHT) 329 ar2->keycode[mode][index] == BTN_RIGHT)
265 return; 330 return;
266 331
267 if (!time_after_eq(jiffies, ar2->jiffies)) 332 if (!time_after_eq(jiffies, ar2->jiffies))
@@ -276,7 +341,7 @@ static void ati_remote2_input_key(struct ati_remote2 *ar2)
276 return; 341 return;
277 } 342 }
278 343
279 input_event(idev, EV_KEY, ati_remote2_key_table[index].key_code, data[1]); 344 input_event(idev, EV_KEY, ar2->keycode[mode][index], data[1]);
280 input_sync(idev); 345 input_sync(idev);
281} 346}
282 347
@@ -287,6 +352,7 @@ static void ati_remote2_complete_mouse(struct urb *urb)
287 352
288 switch (urb->status) { 353 switch (urb->status) {
289 case 0: 354 case 0:
355 usb_mark_last_busy(ar2->udev);
290 ati_remote2_input_mouse(ar2); 356 ati_remote2_input_mouse(ar2);
291 break; 357 break;
292 case -ENOENT: 358 case -ENOENT:
@@ -297,6 +363,7 @@ static void ati_remote2_complete_mouse(struct urb *urb)
297 "%s(): urb status = %d\n", __func__, urb->status); 363 "%s(): urb status = %d\n", __func__, urb->status);
298 return; 364 return;
299 default: 365 default:
366 usb_mark_last_busy(ar2->udev);
300 dev_err(&ar2->intf[0]->dev, 367 dev_err(&ar2->intf[0]->dev,
301 "%s(): urb status = %d\n", __func__, urb->status); 368 "%s(): urb status = %d\n", __func__, urb->status);
302 } 369 }
@@ -314,6 +381,7 @@ static void ati_remote2_complete_key(struct urb *urb)
314 381
315 switch (urb->status) { 382 switch (urb->status) {
316 case 0: 383 case 0:
384 usb_mark_last_busy(ar2->udev);
317 ati_remote2_input_key(ar2); 385 ati_remote2_input_key(ar2);
318 break; 386 break;
319 case -ENOENT: 387 case -ENOENT:
@@ -324,6 +392,7 @@ static void ati_remote2_complete_key(struct urb *urb)
324 "%s(): urb status = %d\n", __func__, urb->status); 392 "%s(): urb status = %d\n", __func__, urb->status);
325 return; 393 return;
326 default: 394 default:
395 usb_mark_last_busy(ar2->udev);
327 dev_err(&ar2->intf[1]->dev, 396 dev_err(&ar2->intf[1]->dev,
328 "%s(): urb status = %d\n", __func__, urb->status); 397 "%s(): urb status = %d\n", __func__, urb->status);
329 } 398 }
@@ -334,10 +403,60 @@ static void ati_remote2_complete_key(struct urb *urb)
334 "%s(): usb_submit_urb() = %d\n", __func__, r); 403 "%s(): usb_submit_urb() = %d\n", __func__, r);
335} 404}
336 405
406static int ati_remote2_getkeycode(struct input_dev *idev,
407 int scancode, int *keycode)
408{
409 struct ati_remote2 *ar2 = input_get_drvdata(idev);
410 int index, mode;
411
412 mode = scancode >> 8;
413 if (mode > ATI_REMOTE2_PC || !((1 << mode) & mode_mask))
414 return -EINVAL;
415
416 index = ati_remote2_lookup(scancode & 0xFF);
417 if (index < 0)
418 return -EINVAL;
419
420 *keycode = ar2->keycode[mode][index];
421 return 0;
422}
423
424static int ati_remote2_setkeycode(struct input_dev *idev, int scancode, int keycode)
425{
426 struct ati_remote2 *ar2 = input_get_drvdata(idev);
427 int index, mode, old_keycode;
428
429 mode = scancode >> 8;
430 if (mode > ATI_REMOTE2_PC || !((1 << mode) & mode_mask))
431 return -EINVAL;
432
433 index = ati_remote2_lookup(scancode & 0xFF);
434 if (index < 0)
435 return -EINVAL;
436
437 if (keycode < KEY_RESERVED || keycode > KEY_MAX)
438 return -EINVAL;
439
440 old_keycode = ar2->keycode[mode][index];
441 ar2->keycode[mode][index] = keycode;
442 set_bit(keycode, idev->keybit);
443
444 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
445 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
446 if (ar2->keycode[mode][index] == old_keycode)
447 return 0;
448 }
449 }
450
451 clear_bit(old_keycode, idev->keybit);
452
453 return 0;
454}
455
337static int ati_remote2_input_init(struct ati_remote2 *ar2) 456static int ati_remote2_input_init(struct ati_remote2 *ar2)
338{ 457{
339 struct input_dev *idev; 458 struct input_dev *idev;
340 int i, retval; 459 int index, mode, retval;
341 460
342 idev = input_allocate_device(); 461 idev = input_allocate_device();
343 if (!idev) 462 if (!idev)
@@ -350,8 +469,26 @@ static int ati_remote2_input_init(struct ati_remote2 *ar2)
350 idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) | 469 idev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
351 BIT_MASK(BTN_RIGHT); 470 BIT_MASK(BTN_RIGHT);
352 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y); 471 idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
353 for (i = 0; ati_remote2_key_table[i].key_code != KEY_RESERVED; i++) 472
354 set_bit(ati_remote2_key_table[i].key_code, idev->keybit); 473 for (mode = 0; mode < ATI_REMOTE2_MODES; mode++) {
474 for (index = 0; index < ARRAY_SIZE(ati_remote2_key_table); index++) {
475 ar2->keycode[mode][index] = ati_remote2_key_table[index].keycode;
476 set_bit(ar2->keycode[mode][index], idev->keybit);
477 }
478 }
479
480 /* AUX1-AUX4 and PC generate the same scancode. */
481 index = ati_remote2_lookup(0x3f);
482 ar2->keycode[ATI_REMOTE2_AUX1][index] = KEY_PROG1;
483 ar2->keycode[ATI_REMOTE2_AUX2][index] = KEY_PROG2;
484 ar2->keycode[ATI_REMOTE2_AUX3][index] = KEY_PROG3;
485 ar2->keycode[ATI_REMOTE2_AUX4][index] = KEY_PROG4;
486 ar2->keycode[ATI_REMOTE2_PC][index] = KEY_PC;
487 set_bit(KEY_PROG1, idev->keybit);
488 set_bit(KEY_PROG2, idev->keybit);
489 set_bit(KEY_PROG3, idev->keybit);
490 set_bit(KEY_PROG4, idev->keybit);
491 set_bit(KEY_PC, idev->keybit);
355 492
356 idev->rep[REP_DELAY] = 250; 493 idev->rep[REP_DELAY] = 250;
357 idev->rep[REP_PERIOD] = 33; 494 idev->rep[REP_PERIOD] = 33;
@@ -359,6 +496,9 @@ static int ati_remote2_input_init(struct ati_remote2 *ar2)
359 idev->open = ati_remote2_open; 496 idev->open = ati_remote2_open;
360 idev->close = ati_remote2_close; 497 idev->close = ati_remote2_close;
361 498
499 idev->getkeycode = ati_remote2_getkeycode;
500 idev->setkeycode = ati_remote2_setkeycode;
501
362 idev->name = ar2->name; 502 idev->name = ar2->name;
363 idev->phys = ar2->phys; 503 idev->phys = ar2->phys;
364 504
@@ -490,6 +630,8 @@ static int ati_remote2_probe(struct usb_interface *interface, const struct usb_d
490 630
491 usb_set_intfdata(interface, ar2); 631 usb_set_intfdata(interface, ar2);
492 632
633 interface->needs_remote_wakeup = 1;
634
493 return 0; 635 return 0;
494 636
495 fail2: 637 fail2:
@@ -522,6 +664,57 @@ static void ati_remote2_disconnect(struct usb_interface *interface)
522 kfree(ar2); 664 kfree(ar2);
523} 665}
524 666
667static int ati_remote2_suspend(struct usb_interface *interface,
668 pm_message_t message)
669{
670 struct ati_remote2 *ar2;
671 struct usb_host_interface *alt = interface->cur_altsetting;
672
673 if (alt->desc.bInterfaceNumber)
674 return 0;
675
676 ar2 = usb_get_intfdata(interface);
677
678 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
679
680 mutex_lock(&ati_remote2_mutex);
681
682 if (ar2->flags & ATI_REMOTE2_OPENED)
683 ati_remote2_kill_urbs(ar2);
684
685 ar2->flags |= ATI_REMOTE2_SUSPENDED;
686
687 mutex_unlock(&ati_remote2_mutex);
688
689 return 0;
690}
691
692static int ati_remote2_resume(struct usb_interface *interface)
693{
694 struct ati_remote2 *ar2;
695 struct usb_host_interface *alt = interface->cur_altsetting;
696 int r = 0;
697
698 if (alt->desc.bInterfaceNumber)
699 return 0;
700
701 ar2 = usb_get_intfdata(interface);
702
703 dev_dbg(&ar2->intf[0]->dev, "%s()\n", __func__);
704
705 mutex_lock(&ati_remote2_mutex);
706
707 if (ar2->flags & ATI_REMOTE2_OPENED)
708 r = ati_remote2_submit_urbs(ar2);
709
710 if (!r)
711 ar2->flags &= ~ATI_REMOTE2_SUSPENDED;
712
713 mutex_unlock(&ati_remote2_mutex);
714
715 return r;
716}
717
525static int __init ati_remote2_init(void) 718static int __init ati_remote2_init(void)
526{ 719{
527 int r; 720 int r;
diff --git a/drivers/input/misc/cm109.c b/drivers/input/misc/cm109.c
new file mode 100644
index 000000000000..bce160f4349b
--- /dev/null
+++ b/drivers/input/misc/cm109.c
@@ -0,0 +1,882 @@
1/*
2 * Driver for the VoIP USB phones with CM109 chipsets.
3 *
4 * Copyright (C) 2007 - 2008 Alfred E. Heggestad <aeh@db.org>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2.
9 */
10
11/*
12 * Tested devices:
13 * - Komunikate KIP1000
14 * - Genius G-talk
15 * - Allied-Telesis Corega USBPH01
16 * - ...
17 *
18 * This driver is based on the yealink.c driver
19 *
20 * Thanks to:
21 * - Authors of yealink.c
22 * - Thomas Reitmayr
23 * - Oliver Neukum for good review comments and code
24 * - Shaun Jackman <sjackman@gmail.com> for Genius G-talk keymap
25 * - Dmitry Torokhov for valuable input and review
26 *
27 * Todo:
28 * - Read/write EEPROM
29 */
30
31#include <linux/kernel.h>
32#include <linux/init.h>
33#include <linux/slab.h>
34#include <linux/module.h>
35#include <linux/moduleparam.h>
36#include <linux/rwsem.h>
37#include <linux/usb/input.h>
38
39#define DRIVER_VERSION "20080805"
40#define DRIVER_AUTHOR "Alfred E. Heggestad"
41#define DRIVER_DESC "CM109 phone driver"
42
43static char *phone = "kip1000";
44module_param(phone, charp, S_IRUSR);
45MODULE_PARM_DESC(phone, "Phone name {kip1000, gtalk, usbph01}");
46
47enum {
48 /* HID Registers */
49 HID_IR0 = 0x00, /* Record/Playback-mute button, Volume up/down */
50 HID_IR1 = 0x01, /* GPI, generic registers or EEPROM_DATA0 */
51 HID_IR2 = 0x02, /* Generic registers or EEPROM_DATA1 */
52 HID_IR3 = 0x03, /* Generic registers or EEPROM_CTRL */
53 HID_OR0 = 0x00, /* Mapping control, buzzer, SPDIF (offset 0x04) */
54 HID_OR1 = 0x01, /* GPO - General Purpose Output */
55 HID_OR2 = 0x02, /* Set GPIO to input/output mode */
56 HID_OR3 = 0x03, /* SPDIF status channel or EEPROM_CTRL */
57
58 /* HID_IR0 */
59 RECORD_MUTE = 1 << 3,
60 PLAYBACK_MUTE = 1 << 2,
61 VOLUME_DOWN = 1 << 1,
62 VOLUME_UP = 1 << 0,
63
64 /* HID_OR0 */
65 /* bits 7-6
66 0: HID_OR1-2 are used for GPO; HID_OR0, 3 are used for buzzer
67 and SPDIF
68 1: HID_OR0-3 are used as generic HID registers
69 2: Values written to HID_OR0-3 are also mapped to MCU_CTRL,
70 EEPROM_DATA0-1, EEPROM_CTRL (see Note)
71 3: Reserved
72 */
73 HID_OR_GPO_BUZ_SPDIF = 0 << 6,
74 HID_OR_GENERIC_HID_REG = 1 << 6,
75 HID_OR_MAP_MCU_EEPROM = 2 << 6,
76
77 BUZZER_ON = 1 << 5,
78
79 /* up to 256 normal keys, up to 16 special keys */
80 KEYMAP_SIZE = 256 + 16,
81};
82
83/* CM109 protocol packet */
84struct cm109_ctl_packet {
85 u8 byte[4];
86} __attribute__ ((packed));
87
88enum { USB_PKT_LEN = sizeof(struct cm109_ctl_packet) };
89
90/* CM109 device structure */
91struct cm109_dev {
92 struct input_dev *idev; /* input device */
93 struct usb_device *udev; /* usb device */
94 struct usb_interface *intf;
95
96 /* irq input channel */
97 struct cm109_ctl_packet *irq_data;
98 dma_addr_t irq_dma;
99 struct urb *urb_irq;
100
101 /* control output channel */
102 struct cm109_ctl_packet *ctl_data;
103 dma_addr_t ctl_dma;
104 struct usb_ctrlrequest *ctl_req;
105 dma_addr_t ctl_req_dma;
106 struct urb *urb_ctl;
107 /*
108 * The 3 bitfields below are protected by ctl_submit_lock.
109 * They have to be separate since they are accessed from IRQ
110 * context.
111 */
112 unsigned irq_urb_pending:1; /* irq_urb is in flight */
113 unsigned ctl_urb_pending:1; /* ctl_urb is in flight */
114 unsigned buzzer_pending:1; /* need to issue buzz command */
115 spinlock_t ctl_submit_lock;
116
117 unsigned char buzzer_state; /* on/off */
118
119 /* flags */
120 unsigned open:1;
121 unsigned resetting:1;
122 unsigned shutdown:1;
123
124 /* This mutex protects writes to the above flags */
125 struct mutex pm_mutex;
126
127 unsigned short keymap[KEYMAP_SIZE];
128
129 char phys[64]; /* physical device path */
130 int key_code; /* last reported key */
131 int keybit; /* 0=new scan 1,2,4,8=scan columns */
132 u8 gpi; /* Cached value of GPI (high nibble) */
133};
134
135/******************************************************************************
136 * CM109 key interface
137 *****************************************************************************/
138
139static unsigned short special_keymap(int code)
140{
141 if (code > 0xff) {
142 switch (code - 0xff) {
143 case RECORD_MUTE: return KEY_MUTE;
144 case PLAYBACK_MUTE: return KEY_MUTE;
145 case VOLUME_DOWN: return KEY_VOLUMEDOWN;
146 case VOLUME_UP: return KEY_VOLUMEUP;
147 }
148 }
149 return KEY_RESERVED;
150}
151
152/* Map device buttons to internal key events.
153 *
154 * The "up" and "down" keys, are symbolised by arrows on the button.
155 * The "pickup" and "hangup" keys are symbolised by a green and red phone
156 * on the button.
157
158 Komunikate KIP1000 Keyboard Matrix
159
160 -> -- 1 -- 2 -- 3 --> GPI pin 4 (0x10)
161 | | | |
162 <- -- 4 -- 5 -- 6 --> GPI pin 5 (0x20)
163 | | | |
164 END - 7 -- 8 -- 9 --> GPI pin 6 (0x40)
165 | | | |
166 OK -- * -- 0 -- # --> GPI pin 7 (0x80)
167 | | | |
168
169 /|\ /|\ /|\ /|\
170 | | | |
171GPO
172pin: 3 2 1 0
173 0x8 0x4 0x2 0x1
174
175 */
176static unsigned short keymap_kip1000(int scancode)
177{
178 switch (scancode) { /* phone key: */
179 case 0x82: return KEY_NUMERIC_0; /* 0 */
180 case 0x14: return KEY_NUMERIC_1; /* 1 */
181 case 0x12: return KEY_NUMERIC_2; /* 2 */
182 case 0x11: return KEY_NUMERIC_3; /* 3 */
183 case 0x24: return KEY_NUMERIC_4; /* 4 */
184 case 0x22: return KEY_NUMERIC_5; /* 5 */
185 case 0x21: return KEY_NUMERIC_6; /* 6 */
186 case 0x44: return KEY_NUMERIC_7; /* 7 */
187 case 0x42: return KEY_NUMERIC_8; /* 8 */
188 case 0x41: return KEY_NUMERIC_9; /* 9 */
189 case 0x81: return KEY_NUMERIC_POUND; /* # */
190 case 0x84: return KEY_NUMERIC_STAR; /* * */
191 case 0x88: return KEY_ENTER; /* pickup */
192 case 0x48: return KEY_ESC; /* hangup */
193 case 0x28: return KEY_LEFT; /* IN */
194 case 0x18: return KEY_RIGHT; /* OUT */
195 default: return special_keymap(scancode);
196 }
197}
198
199/*
200 Contributed by Shaun Jackman <sjackman@gmail.com>
201
202 Genius G-Talk keyboard matrix
203 0 1 2 3
204 4: 0 4 8 Talk
205 5: 1 5 9 End
206 6: 2 6 # Up
207 7: 3 7 * Down
208*/
209static unsigned short keymap_gtalk(int scancode)
210{
211 switch (scancode) {
212 case 0x11: return KEY_NUMERIC_0;
213 case 0x21: return KEY_NUMERIC_1;
214 case 0x41: return KEY_NUMERIC_2;
215 case 0x81: return KEY_NUMERIC_3;
216 case 0x12: return KEY_NUMERIC_4;
217 case 0x22: return KEY_NUMERIC_5;
218 case 0x42: return KEY_NUMERIC_6;
219 case 0x82: return KEY_NUMERIC_7;
220 case 0x14: return KEY_NUMERIC_8;
221 case 0x24: return KEY_NUMERIC_9;
222 case 0x44: return KEY_NUMERIC_POUND; /* # */
223 case 0x84: return KEY_NUMERIC_STAR; /* * */
224 case 0x18: return KEY_ENTER; /* Talk (green handset) */
225 case 0x28: return KEY_ESC; /* End (red handset) */
226 case 0x48: return KEY_UP; /* Menu up (rocker switch) */
227 case 0x88: return KEY_DOWN; /* Menu down (rocker switch) */
228 default: return special_keymap(scancode);
229 }
230}
231
232/*
233 * Keymap for Allied-Telesis Corega USBPH01
234 * http://www.alliedtelesis-corega.com/2/1344/1437/1360/chprd.html
235 *
236 * Contributed by july@nat.bg
237 */
238static unsigned short keymap_usbph01(int scancode)
239{
240 switch (scancode) {
241 case 0x11: return KEY_NUMERIC_0; /* 0 */
242 case 0x21: return KEY_NUMERIC_1; /* 1 */
243 case 0x41: return KEY_NUMERIC_2; /* 2 */
244 case 0x81: return KEY_NUMERIC_3; /* 3 */
245 case 0x12: return KEY_NUMERIC_4; /* 4 */
246 case 0x22: return KEY_NUMERIC_5; /* 5 */
247 case 0x42: return KEY_NUMERIC_6; /* 6 */
248 case 0x82: return KEY_NUMERIC_7; /* 7 */
249 case 0x14: return KEY_NUMERIC_8; /* 8 */
250 case 0x24: return KEY_NUMERIC_9; /* 9 */
251 case 0x44: return KEY_NUMERIC_POUND; /* # */
252 case 0x84: return KEY_NUMERIC_STAR; /* * */
253 case 0x18: return KEY_ENTER; /* pickup */
254 case 0x28: return KEY_ESC; /* hangup */
255 case 0x48: return KEY_LEFT; /* IN */
256 case 0x88: return KEY_RIGHT; /* OUT */
257 default: return special_keymap(scancode);
258 }
259}
260
261static unsigned short (*keymap)(int) = keymap_kip1000;
262
263/*
264 * Completes a request by converting the data into events for the
265 * input subsystem.
266 */
267static void report_key(struct cm109_dev *dev, int key)
268{
269 struct input_dev *idev = dev->idev;
270
271 if (dev->key_code >= 0) {
272 /* old key up */
273 input_report_key(idev, dev->key_code, 0);
274 }
275
276 dev->key_code = key;
277 if (key >= 0) {
278 /* new valid key */
279 input_report_key(idev, key, 1);
280 }
281
282 input_sync(idev);
283}
284
285/******************************************************************************
286 * CM109 usb communication interface
287 *****************************************************************************/
288
289static void cm109_submit_buzz_toggle(struct cm109_dev *dev)
290{
291 int error;
292
293 if (dev->buzzer_state)
294 dev->ctl_data->byte[HID_OR0] |= BUZZER_ON;
295 else
296 dev->ctl_data->byte[HID_OR0] &= ~BUZZER_ON;
297
298 error = usb_submit_urb(dev->urb_ctl, GFP_ATOMIC);
299 if (error)
300 err("%s: usb_submit_urb (urb_ctl) failed %d", __func__, error);
301}
302
303/*
304 * IRQ handler
305 */
306static void cm109_urb_irq_callback(struct urb *urb)
307{
308 struct cm109_dev *dev = urb->context;
309 const int status = urb->status;
310 int error;
311
312 dev_dbg(&urb->dev->dev, "### URB IRQ: [0x%02x 0x%02x 0x%02x 0x%02x] keybit=0x%02x\n",
313 dev->irq_data->byte[0],
314 dev->irq_data->byte[1],
315 dev->irq_data->byte[2],
316 dev->irq_data->byte[3],
317 dev->keybit);
318
319 if (status) {
320 if (status == -ESHUTDOWN)
321 return;
322 err("%s: urb status %d", __func__, status);
323 }
324
325 /* Special keys */
326 if (dev->irq_data->byte[HID_IR0] & 0x0f) {
327 const int code = (dev->irq_data->byte[HID_IR0] & 0x0f);
328 report_key(dev, dev->keymap[0xff + code]);
329 }
330
331 /* Scan key column */
332 if (dev->keybit == 0xf) {
333
334 /* Any changes ? */
335 if ((dev->gpi & 0xf0) == (dev->irq_data->byte[HID_IR1] & 0xf0))
336 goto out;
337
338 dev->gpi = dev->irq_data->byte[HID_IR1] & 0xf0;
339 dev->keybit = 0x1;
340 } else {
341 report_key(dev, dev->keymap[dev->irq_data->byte[HID_IR1]]);
342
343 dev->keybit <<= 1;
344 if (dev->keybit > 0x8)
345 dev->keybit = 0xf;
346 }
347
348 out:
349
350 spin_lock(&dev->ctl_submit_lock);
351
352 dev->irq_urb_pending = 0;
353
354 if (likely(!dev->shutdown)) {
355
356 if (dev->buzzer_state)
357 dev->ctl_data->byte[HID_OR0] |= BUZZER_ON;
358 else
359 dev->ctl_data->byte[HID_OR0] &= ~BUZZER_ON;
360
361 dev->ctl_data->byte[HID_OR1] = dev->keybit;
362 dev->ctl_data->byte[HID_OR2] = dev->keybit;
363
364 dev->buzzer_pending = 0;
365 dev->ctl_urb_pending = 1;
366
367 error = usb_submit_urb(dev->urb_ctl, GFP_ATOMIC);
368 if (error)
369 err("%s: usb_submit_urb (urb_ctl) failed %d",
370 __func__, error);
371 }
372
373 spin_unlock(&dev->ctl_submit_lock);
374}
375
376static void cm109_urb_ctl_callback(struct urb *urb)
377{
378 struct cm109_dev *dev = urb->context;
379 const int status = urb->status;
380 int error;
381
382 dev_dbg(&urb->dev->dev, "### URB CTL: [0x%02x 0x%02x 0x%02x 0x%02x]\n",
383 dev->ctl_data->byte[0],
384 dev->ctl_data->byte[1],
385 dev->ctl_data->byte[2],
386 dev->ctl_data->byte[3]);
387
388 if (status)
389 err("%s: urb status %d", __func__, status);
390
391 spin_lock(&dev->ctl_submit_lock);
392
393 dev->ctl_urb_pending = 0;
394
395 if (likely(!dev->shutdown)) {
396
397 if (dev->buzzer_pending) {
398 dev->buzzer_pending = 0;
399 dev->ctl_urb_pending = 1;
400 cm109_submit_buzz_toggle(dev);
401 } else if (likely(!dev->irq_urb_pending)) {
402 /* ask for key data */
403 dev->irq_urb_pending = 1;
404 error = usb_submit_urb(dev->urb_irq, GFP_ATOMIC);
405 if (error)
406 err("%s: usb_submit_urb (urb_irq) failed %d",
407 __func__, error);
408 }
409 }
410
411 spin_unlock(&dev->ctl_submit_lock);
412}
413
414static void cm109_toggle_buzzer_async(struct cm109_dev *dev)
415{
416 unsigned long flags;
417
418 spin_lock_irqsave(&dev->ctl_submit_lock, flags);
419
420 if (dev->ctl_urb_pending) {
421 /* URB completion will resubmit */
422 dev->buzzer_pending = 1;
423 } else {
424 dev->ctl_urb_pending = 1;
425 cm109_submit_buzz_toggle(dev);
426 }
427
428 spin_unlock_irqrestore(&dev->ctl_submit_lock, flags);
429}
430
431static void cm109_toggle_buzzer_sync(struct cm109_dev *dev, int on)
432{
433 int error;
434
435 if (on)
436 dev->ctl_data->byte[HID_OR0] |= BUZZER_ON;
437 else
438 dev->ctl_data->byte[HID_OR0] &= ~BUZZER_ON;
439
440 error = usb_control_msg(dev->udev,
441 usb_sndctrlpipe(dev->udev, 0),
442 dev->ctl_req->bRequest,
443 dev->ctl_req->bRequestType,
444 le16_to_cpu(dev->ctl_req->wValue),
445 le16_to_cpu(dev->ctl_req->wIndex),
446 dev->ctl_data,
447 USB_PKT_LEN, USB_CTRL_SET_TIMEOUT);
448 if (error && error != EINTR)
449 err("%s: usb_control_msg() failed %d", __func__, error);
450}
451
452static void cm109_stop_traffic(struct cm109_dev *dev)
453{
454 dev->shutdown = 1;
455 /*
456 * Make sure other CPUs see this
457 */
458 smp_wmb();
459
460 usb_kill_urb(dev->urb_ctl);
461 usb_kill_urb(dev->urb_irq);
462
463 cm109_toggle_buzzer_sync(dev, 0);
464
465 dev->shutdown = 0;
466 smp_wmb();
467}
468
469static void cm109_restore_state(struct cm109_dev *dev)
470{
471 if (dev->open) {
472 /*
473 * Restore buzzer state.
474 * This will also kick regular URB submission
475 */
476 cm109_toggle_buzzer_async(dev);
477 }
478}
479
480/******************************************************************************
481 * input event interface
482 *****************************************************************************/
483
484static int cm109_input_open(struct input_dev *idev)
485{
486 struct cm109_dev *dev = input_get_drvdata(idev);
487 int error;
488
489 error = usb_autopm_get_interface(dev->intf);
490 if (error < 0) {
491 err("%s - cannot autoresume, result %d",
492 __func__, error);
493 return error;
494 }
495
496 mutex_lock(&dev->pm_mutex);
497
498 dev->buzzer_state = 0;
499 dev->key_code = -1; /* no keys pressed */
500 dev->keybit = 0xf;
501
502 /* issue INIT */
503 dev->ctl_data->byte[HID_OR0] = HID_OR_GPO_BUZ_SPDIF;
504 dev->ctl_data->byte[HID_OR1] = dev->keybit;
505 dev->ctl_data->byte[HID_OR2] = dev->keybit;
506 dev->ctl_data->byte[HID_OR3] = 0x00;
507
508 error = usb_submit_urb(dev->urb_ctl, GFP_KERNEL);
509 if (error)
510 err("%s: usb_submit_urb (urb_ctl) failed %d", __func__, error);
511 else
512 dev->open = 1;
513
514 mutex_unlock(&dev->pm_mutex);
515
516 if (error)
517 usb_autopm_put_interface(dev->intf);
518
519 return error;
520}
521
522static void cm109_input_close(struct input_dev *idev)
523{
524 struct cm109_dev *dev = input_get_drvdata(idev);
525
526 mutex_lock(&dev->pm_mutex);
527
528 /*
529 * Once we are here event delivery is stopped so we
530 * don't need to worry about someone starting buzzer
531 * again
532 */
533 cm109_stop_traffic(dev);
534 dev->open = 0;
535
536 mutex_unlock(&dev->pm_mutex);
537
538 usb_autopm_put_interface(dev->intf);
539}
540
541static int cm109_input_ev(struct input_dev *idev, unsigned int type,
542 unsigned int code, int value)
543{
544 struct cm109_dev *dev = input_get_drvdata(idev);
545
546 dev_dbg(&dev->udev->dev,
547 "input_ev: type=%u code=%u value=%d\n", type, code, value);
548
549 if (type != EV_SND)
550 return -EINVAL;
551
552 switch (code) {
553 case SND_TONE:
554 case SND_BELL:
555 dev->buzzer_state = !!value;
556 if (!dev->resetting)
557 cm109_toggle_buzzer_async(dev);
558 return 0;
559
560 default:
561 return -EINVAL;
562 }
563}
564
565
566/******************************************************************************
567 * Linux interface and usb initialisation
568 *****************************************************************************/
569
570struct driver_info {
571 char *name;
572};
573
574static const struct driver_info info_cm109 = {
575 .name = "CM109 USB driver",
576};
577
578enum {
579 VENDOR_ID = 0x0d8c, /* C-Media Electronics */
580 PRODUCT_ID_CM109 = 0x000e, /* CM109 defines range 0x0008 - 0x000f */
581};
582
583/* table of devices that work with this driver */
584static const struct usb_device_id cm109_usb_table[] = {
585 {
586 .match_flags = USB_DEVICE_ID_MATCH_DEVICE |
587 USB_DEVICE_ID_MATCH_INT_INFO,
588 .idVendor = VENDOR_ID,
589 .idProduct = PRODUCT_ID_CM109,
590 .bInterfaceClass = USB_CLASS_HID,
591 .bInterfaceSubClass = 0,
592 .bInterfaceProtocol = 0,
593 .driver_info = (kernel_ulong_t) &info_cm109
594 },
595 /* you can add more devices here with product ID 0x0008 - 0x000f */
596 { }
597};
598
599static void cm109_usb_cleanup(struct cm109_dev *dev)
600{
601 if (dev->ctl_req)
602 usb_buffer_free(dev->udev, sizeof(*(dev->ctl_req)),
603 dev->ctl_req, dev->ctl_req_dma);
604 if (dev->ctl_data)
605 usb_buffer_free(dev->udev, USB_PKT_LEN,
606 dev->ctl_data, dev->ctl_dma);
607 if (dev->irq_data)
608 usb_buffer_free(dev->udev, USB_PKT_LEN,
609 dev->irq_data, dev->irq_dma);
610
611 usb_free_urb(dev->urb_irq); /* parameter validation in core/urb */
612 usb_free_urb(dev->urb_ctl); /* parameter validation in core/urb */
613 kfree(dev);
614}
615
616static void cm109_usb_disconnect(struct usb_interface *interface)
617{
618 struct cm109_dev *dev = usb_get_intfdata(interface);
619
620 usb_set_intfdata(interface, NULL);
621 input_unregister_device(dev->idev);
622 cm109_usb_cleanup(dev);
623}
624
625static int cm109_usb_probe(struct usb_interface *intf,
626 const struct usb_device_id *id)
627{
628 struct usb_device *udev = interface_to_usbdev(intf);
629 struct driver_info *nfo = (struct driver_info *)id->driver_info;
630 struct usb_host_interface *interface;
631 struct usb_endpoint_descriptor *endpoint;
632 struct cm109_dev *dev;
633 struct input_dev *input_dev = NULL;
634 int ret, pipe, i;
635 int error = -ENOMEM;
636
637 interface = intf->cur_altsetting;
638 endpoint = &interface->endpoint[0].desc;
639
640 if (!usb_endpoint_is_int_in(endpoint))
641 return -ENODEV;
642
643 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
644 if (!dev)
645 return -ENOMEM;
646
647 spin_lock_init(&dev->ctl_submit_lock);
648 mutex_init(&dev->pm_mutex);
649
650 dev->udev = udev;
651 dev->intf = intf;
652
653 dev->idev = input_dev = input_allocate_device();
654 if (!input_dev)
655 goto err_out;
656
657 /* allocate usb buffers */
658 dev->irq_data = usb_buffer_alloc(udev, USB_PKT_LEN,
659 GFP_KERNEL, &dev->irq_dma);
660 if (!dev->irq_data)
661 goto err_out;
662
663 dev->ctl_data = usb_buffer_alloc(udev, USB_PKT_LEN,
664 GFP_KERNEL, &dev->ctl_dma);
665 if (!dev->ctl_data)
666 goto err_out;
667
668 dev->ctl_req = usb_buffer_alloc(udev, sizeof(*(dev->ctl_req)),
669 GFP_KERNEL, &dev->ctl_req_dma);
670 if (!dev->ctl_req)
671 goto err_out;
672
673 /* allocate urb structures */
674 dev->urb_irq = usb_alloc_urb(0, GFP_KERNEL);
675 if (!dev->urb_irq)
676 goto err_out;
677
678 dev->urb_ctl = usb_alloc_urb(0, GFP_KERNEL);
679 if (!dev->urb_ctl)
680 goto err_out;
681
682 /* get a handle to the interrupt data pipe */
683 pipe = usb_rcvintpipe(udev, endpoint->bEndpointAddress);
684 ret = usb_maxpacket(udev, pipe, usb_pipeout(pipe));
685 if (ret != USB_PKT_LEN)
686 err("invalid payload size %d, expected %d", ret, USB_PKT_LEN);
687
688 /* initialise irq urb */
689 usb_fill_int_urb(dev->urb_irq, udev, pipe, dev->irq_data,
690 USB_PKT_LEN,
691 cm109_urb_irq_callback, dev, endpoint->bInterval);
692 dev->urb_irq->transfer_dma = dev->irq_dma;
693 dev->urb_irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
694 dev->urb_irq->dev = udev;
695
696 /* initialise ctl urb */
697 dev->ctl_req->bRequestType = USB_TYPE_CLASS | USB_RECIP_INTERFACE |
698 USB_DIR_OUT;
699 dev->ctl_req->bRequest = USB_REQ_SET_CONFIGURATION;
700 dev->ctl_req->wValue = cpu_to_le16(0x200);
701 dev->ctl_req->wIndex = cpu_to_le16(interface->desc.bInterfaceNumber);
702 dev->ctl_req->wLength = cpu_to_le16(USB_PKT_LEN);
703
704 usb_fill_control_urb(dev->urb_ctl, udev, usb_sndctrlpipe(udev, 0),
705 (void *)dev->ctl_req, dev->ctl_data, USB_PKT_LEN,
706 cm109_urb_ctl_callback, dev);
707 dev->urb_ctl->setup_dma = dev->ctl_req_dma;
708 dev->urb_ctl->transfer_dma = dev->ctl_dma;
709 dev->urb_ctl->transfer_flags |= URB_NO_SETUP_DMA_MAP |
710 URB_NO_TRANSFER_DMA_MAP;
711 dev->urb_ctl->dev = udev;
712
713 /* find out the physical bus location */
714 usb_make_path(udev, dev->phys, sizeof(dev->phys));
715 strlcat(dev->phys, "/input0", sizeof(dev->phys));
716
717 /* register settings for the input device */
718 input_dev->name = nfo->name;
719 input_dev->phys = dev->phys;
720 usb_to_input_id(udev, &input_dev->id);
721 input_dev->dev.parent = &intf->dev;
722
723 input_set_drvdata(input_dev, dev);
724 input_dev->open = cm109_input_open;
725 input_dev->close = cm109_input_close;
726 input_dev->event = cm109_input_ev;
727
728 input_dev->keycode = dev->keymap;
729 input_dev->keycodesize = sizeof(unsigned char);
730 input_dev->keycodemax = ARRAY_SIZE(dev->keymap);
731
732 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_SND);
733 input_dev->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE);
734
735 /* register available key events */
736 for (i = 0; i < KEYMAP_SIZE; i++) {
737 unsigned short k = keymap(i);
738 dev->keymap[i] = k;
739 __set_bit(k, input_dev->keybit);
740 }
741 __clear_bit(KEY_RESERVED, input_dev->keybit);
742
743 error = input_register_device(dev->idev);
744 if (error)
745 goto err_out;
746
747 usb_set_intfdata(intf, dev);
748
749 return 0;
750
751 err_out:
752 input_free_device(input_dev);
753 cm109_usb_cleanup(dev);
754 return error;
755}
756
757static int cm109_usb_suspend(struct usb_interface *intf, pm_message_t message)
758{
759 struct cm109_dev *dev = usb_get_intfdata(intf);
760
761 dev_info(&intf->dev, "cm109: usb_suspend (event=%d)\n", message.event);
762
763 mutex_lock(&dev->pm_mutex);
764 cm109_stop_traffic(dev);
765 mutex_unlock(&dev->pm_mutex);
766
767 return 0;
768}
769
770static int cm109_usb_resume(struct usb_interface *intf)
771{
772 struct cm109_dev *dev = usb_get_intfdata(intf);
773
774 dev_info(&intf->dev, "cm109: usb_resume\n");
775
776 mutex_lock(&dev->pm_mutex);
777 cm109_restore_state(dev);
778 mutex_unlock(&dev->pm_mutex);
779
780 return 0;
781}
782
783static int cm109_usb_pre_reset(struct usb_interface *intf)
784{
785 struct cm109_dev *dev = usb_get_intfdata(intf);
786
787 mutex_lock(&dev->pm_mutex);
788
789 /*
790 * Make sure input events don't try to toggle buzzer
791 * while we are resetting
792 */
793 dev->resetting = 1;
794 smp_wmb();
795
796 cm109_stop_traffic(dev);
797
798 return 0;
799}
800
801static int cm109_usb_post_reset(struct usb_interface *intf)
802{
803 struct cm109_dev *dev = usb_get_intfdata(intf);
804
805 dev->resetting = 0;
806 smp_wmb();
807
808 cm109_restore_state(dev);
809
810 mutex_unlock(&dev->pm_mutex);
811
812 return 0;
813}
814
815static struct usb_driver cm109_driver = {
816 .name = "cm109",
817 .probe = cm109_usb_probe,
818 .disconnect = cm109_usb_disconnect,
819 .suspend = cm109_usb_suspend,
820 .resume = cm109_usb_resume,
821 .reset_resume = cm109_usb_resume,
822 .pre_reset = cm109_usb_pre_reset,
823 .post_reset = cm109_usb_post_reset,
824 .id_table = cm109_usb_table,
825 .supports_autosuspend = 1,
826};
827
828static int __init cm109_select_keymap(void)
829{
830 /* Load the phone keymap */
831 if (!strcasecmp(phone, "kip1000")) {
832 keymap = keymap_kip1000;
833 printk(KERN_INFO KBUILD_MODNAME ": "
834 "Keymap for Komunikate KIP1000 phone loaded\n");
835 } else if (!strcasecmp(phone, "gtalk")) {
836 keymap = keymap_gtalk;
837 printk(KERN_INFO KBUILD_MODNAME ": "
838 "Keymap for Genius G-talk phone loaded\n");
839 } else if (!strcasecmp(phone, "usbph01")) {
840 keymap = keymap_usbph01;
841 printk(KERN_INFO KBUILD_MODNAME ": "
842 "Keymap for Allied-Telesis Corega USBPH01 phone loaded\n");
843 } else {
844 printk(KERN_ERR KBUILD_MODNAME ": "
845 "Unsupported phone: %s\n", phone);
846 return -EINVAL;
847 }
848
849 return 0;
850}
851
852static int __init cm109_init(void)
853{
854 int err;
855
856 err = cm109_select_keymap();
857 if (err)
858 return err;
859
860 err = usb_register(&cm109_driver);
861 if (err)
862 return err;
863
864 printk(KERN_INFO KBUILD_MODNAME ": "
865 DRIVER_DESC ": " DRIVER_VERSION " (C) " DRIVER_AUTHOR "\n");
866
867 return 0;
868}
869
870static void __exit cm109_exit(void)
871{
872 usb_deregister(&cm109_driver);
873}
874
875module_init(cm109_init);
876module_exit(cm109_exit);
877
878MODULE_DEVICE_TABLE(usb, cm109_usb_table);
879
880MODULE_AUTHOR(DRIVER_AUTHOR);
881MODULE_DESCRIPTION(DRIVER_DESC);
882MODULE_LICENSE("GPL");
diff --git a/drivers/input/misc/hp_sdc_rtc.c b/drivers/input/misc/hp_sdc_rtc.c
index daa9d4220331..82ec6b1b6467 100644
--- a/drivers/input/misc/hp_sdc_rtc.c
+++ b/drivers/input/misc/hp_sdc_rtc.c
@@ -458,35 +458,35 @@ static int hp_sdc_rtc_proc_output (char *buf)
458 p += sprintf(p, "i8042 rtc\t: READ FAILED!\n"); 458 p += sprintf(p, "i8042 rtc\t: READ FAILED!\n");
459 } else { 459 } else {
460 p += sprintf(p, "i8042 rtc\t: %ld.%02d seconds\n", 460 p += sprintf(p, "i8042 rtc\t: %ld.%02d seconds\n",
461 tv.tv_sec, tv.tv_usec/1000); 461 tv.tv_sec, (int)tv.tv_usec/1000);
462 } 462 }
463 463
464 if (hp_sdc_rtc_read_fhs(&tv)) { 464 if (hp_sdc_rtc_read_fhs(&tv)) {
465 p += sprintf(p, "handshake\t: READ FAILED!\n"); 465 p += sprintf(p, "handshake\t: READ FAILED!\n");
466 } else { 466 } else {
467 p += sprintf(p, "handshake\t: %ld.%02d seconds\n", 467 p += sprintf(p, "handshake\t: %ld.%02d seconds\n",
468 tv.tv_sec, tv.tv_usec/1000); 468 tv.tv_sec, (int)tv.tv_usec/1000);
469 } 469 }
470 470
471 if (hp_sdc_rtc_read_mt(&tv)) { 471 if (hp_sdc_rtc_read_mt(&tv)) {
472 p += sprintf(p, "alarm\t\t: READ FAILED!\n"); 472 p += sprintf(p, "alarm\t\t: READ FAILED!\n");
473 } else { 473 } else {
474 p += sprintf(p, "alarm\t\t: %ld.%02d seconds\n", 474 p += sprintf(p, "alarm\t\t: %ld.%02d seconds\n",
475 tv.tv_sec, tv.tv_usec/1000); 475 tv.tv_sec, (int)tv.tv_usec/1000);
476 } 476 }
477 477
478 if (hp_sdc_rtc_read_dt(&tv)) { 478 if (hp_sdc_rtc_read_dt(&tv)) {
479 p += sprintf(p, "delay\t\t: READ FAILED!\n"); 479 p += sprintf(p, "delay\t\t: READ FAILED!\n");
480 } else { 480 } else {
481 p += sprintf(p, "delay\t\t: %ld.%02d seconds\n", 481 p += sprintf(p, "delay\t\t: %ld.%02d seconds\n",
482 tv.tv_sec, tv.tv_usec/1000); 482 tv.tv_sec, (int)tv.tv_usec/1000);
483 } 483 }
484 484
485 if (hp_sdc_rtc_read_ct(&tv)) { 485 if (hp_sdc_rtc_read_ct(&tv)) {
486 p += sprintf(p, "periodic\t: READ FAILED!\n"); 486 p += sprintf(p, "periodic\t: READ FAILED!\n");
487 } else { 487 } else {
488 p += sprintf(p, "periodic\t: %ld.%02d seconds\n", 488 p += sprintf(p, "periodic\t: %ld.%02d seconds\n",
489 tv.tv_sec, tv.tv_usec/1000); 489 tv.tv_sec, (int)tv.tv_usec/1000);
490 } 490 }
491 491
492 p += sprintf(p, 492 p += sprintf(p,
diff --git a/drivers/input/misc/map_to_7segment.h b/drivers/input/misc/map_to_7segment.h
deleted file mode 100644
index a424094d9fe2..000000000000
--- a/drivers/input/misc/map_to_7segment.h
+++ /dev/null
@@ -1,189 +0,0 @@
1/*
2 * drivers/usb/input/map_to_7segment.h
3 *
4 * Copyright (c) 2005 Henk Vergonet <Henk.Vergonet@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#ifndef MAP_TO_7SEGMENT_H
22#define MAP_TO_7SEGMENT_H
23
24/* This file provides translation primitives and tables for the conversion
25 * of (ASCII) characters to a 7-segments notation.
26 *
27 * The 7 segment's wikipedia notation below is used as standard.
28 * See: http://en.wikipedia.org/wiki/Seven_segment_display
29 *
30 * Notation: +-a-+
31 * f b
32 * +-g-+
33 * e c
34 * +-d-+
35 *
36 * Usage:
37 *
38 * Register a map variable, and fill it with a character set:
39 * static SEG7_DEFAULT_MAP(map_seg7);
40 *
41 *
42 * Then use for conversion:
43 * seg7 = map_to_seg7(&map_seg7, some_char);
44 * ...
45 *
46 * In device drivers it is recommended, if required, to make the char map
47 * accessible via the sysfs interface using the following scheme:
48 *
49 * static ssize_t show_map(struct device *dev, char *buf) {
50 * memcpy(buf, &map_seg7, sizeof(map_seg7));
51 * return sizeof(map_seg7);
52 * }
53 * static ssize_t store_map(struct device *dev, const char *buf, size_t cnt) {
54 * if(cnt != sizeof(map_seg7))
55 * return -EINVAL;
56 * memcpy(&map_seg7, buf, cnt);
57 * return cnt;
58 * }
59 * static DEVICE_ATTR(map_seg7, PERMS_RW, show_map, store_map);
60 *
61 * History:
62 * 2005-05-31 RFC linux-kernel@vger.kernel.org
63 */
64#include <linux/errno.h>
65
66
67#define BIT_SEG7_A 0
68#define BIT_SEG7_B 1
69#define BIT_SEG7_C 2
70#define BIT_SEG7_D 3
71#define BIT_SEG7_E 4
72#define BIT_SEG7_F 5
73#define BIT_SEG7_G 6
74#define BIT_SEG7_RESERVED 7
75
76struct seg7_conversion_map {
77 unsigned char table[128];
78};
79
80static inline int map_to_seg7(struct seg7_conversion_map *map, int c)
81{
82 return c >= 0 && c < sizeof(map->table) ? map->table[c] : -EINVAL;
83}
84
85#define SEG7_CONVERSION_MAP(_name, _map) \
86 struct seg7_conversion_map _name = { .table = { _map } }
87
88/*
89 * It is recommended to use a facility that allows user space to redefine
90 * custom character sets for LCD devices. Please use a sysfs interface
91 * as described above.
92 */
93#define MAP_TO_SEG7_SYSFS_FILE "map_seg7"
94
95/*******************************************************************************
96 * ASCII conversion table
97 ******************************************************************************/
98
99#define _SEG7(l,a,b,c,d,e,f,g) \
100 ( a<<BIT_SEG7_A | b<<BIT_SEG7_B | c<<BIT_SEG7_C | d<<BIT_SEG7_D | \
101 e<<BIT_SEG7_E | f<<BIT_SEG7_F | g<<BIT_SEG7_G )
102
103#define _MAP_0_32_ASCII_SEG7_NON_PRINTABLE \
104 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
105
106#define _MAP_33_47_ASCII_SEG7_SYMBOL \
107 _SEG7('!',0,0,0,0,1,1,0), _SEG7('"',0,1,0,0,0,1,0), _SEG7('#',0,1,1,0,1,1,0),\
108 _SEG7('$',1,0,1,1,0,1,1), _SEG7('%',0,0,1,0,0,1,0), _SEG7('&',1,0,1,1,1,1,1),\
109 _SEG7('\'',0,0,0,0,0,1,0),_SEG7('(',1,0,0,1,1,1,0), _SEG7(')',1,1,1,1,0,0,0),\
110 _SEG7('*',0,1,1,0,1,1,1), _SEG7('+',0,1,1,0,0,0,1), _SEG7(',',0,0,0,0,1,0,0),\
111 _SEG7('-',0,0,0,0,0,0,1), _SEG7('.',0,0,0,0,1,0,0), _SEG7('/',0,1,0,0,1,0,1),
112
113#define _MAP_48_57_ASCII_SEG7_NUMERIC \
114 _SEG7('0',1,1,1,1,1,1,0), _SEG7('1',0,1,1,0,0,0,0), _SEG7('2',1,1,0,1,1,0,1),\
115 _SEG7('3',1,1,1,1,0,0,1), _SEG7('4',0,1,1,0,0,1,1), _SEG7('5',1,0,1,1,0,1,1),\
116 _SEG7('6',1,0,1,1,1,1,1), _SEG7('7',1,1,1,0,0,0,0), _SEG7('8',1,1,1,1,1,1,1),\
117 _SEG7('9',1,1,1,1,0,1,1),
118
119#define _MAP_58_64_ASCII_SEG7_SYMBOL \
120 _SEG7(':',0,0,0,1,0,0,1), _SEG7(';',0,0,0,1,0,0,1), _SEG7('<',1,0,0,0,0,1,1),\
121 _SEG7('=',0,0,0,1,0,0,1), _SEG7('>',1,1,0,0,0,0,1), _SEG7('?',1,1,1,0,0,1,0),\
122 _SEG7('@',1,1,0,1,1,1,1),
123
124#define _MAP_65_90_ASCII_SEG7_ALPHA_UPPR \
125 _SEG7('A',1,1,1,0,1,1,1), _SEG7('B',1,1,1,1,1,1,1), _SEG7('C',1,0,0,1,1,1,0),\
126 _SEG7('D',1,1,1,1,1,1,0), _SEG7('E',1,0,0,1,1,1,1), _SEG7('F',1,0,0,0,1,1,1),\
127 _SEG7('G',1,1,1,1,0,1,1), _SEG7('H',0,1,1,0,1,1,1), _SEG7('I',0,1,1,0,0,0,0),\
128 _SEG7('J',0,1,1,1,0,0,0), _SEG7('K',0,1,1,0,1,1,1), _SEG7('L',0,0,0,1,1,1,0),\
129 _SEG7('M',1,1,1,0,1,1,0), _SEG7('N',1,1,1,0,1,1,0), _SEG7('O',1,1,1,1,1,1,0),\
130 _SEG7('P',1,1,0,0,1,1,1), _SEG7('Q',1,1,1,1,1,1,0), _SEG7('R',1,1,1,0,1,1,1),\
131 _SEG7('S',1,0,1,1,0,1,1), _SEG7('T',0,0,0,1,1,1,1), _SEG7('U',0,1,1,1,1,1,0),\
132 _SEG7('V',0,1,1,1,1,1,0), _SEG7('W',0,1,1,1,1,1,1), _SEG7('X',0,1,1,0,1,1,1),\
133 _SEG7('Y',0,1,1,0,0,1,1), _SEG7('Z',1,1,0,1,1,0,1),
134
135#define _MAP_91_96_ASCII_SEG7_SYMBOL \
136 _SEG7('[',1,0,0,1,1,1,0), _SEG7('\\',0,0,1,0,0,1,1),_SEG7(']',1,1,1,1,0,0,0),\
137 _SEG7('^',1,1,0,0,0,1,0), _SEG7('_',0,0,0,1,0,0,0), _SEG7('`',0,1,0,0,0,0,0),
138
139#define _MAP_97_122_ASCII_SEG7_ALPHA_LOWER \
140 _SEG7('A',1,1,1,0,1,1,1), _SEG7('b',0,0,1,1,1,1,1), _SEG7('c',0,0,0,1,1,0,1),\
141 _SEG7('d',0,1,1,1,1,0,1), _SEG7('E',1,0,0,1,1,1,1), _SEG7('F',1,0,0,0,1,1,1),\
142 _SEG7('G',1,1,1,1,0,1,1), _SEG7('h',0,0,1,0,1,1,1), _SEG7('i',0,0,1,0,0,0,0),\
143 _SEG7('j',0,0,1,1,0,0,0), _SEG7('k',0,0,1,0,1,1,1), _SEG7('L',0,0,0,1,1,1,0),\
144 _SEG7('M',1,1,1,0,1,1,0), _SEG7('n',0,0,1,0,1,0,1), _SEG7('o',0,0,1,1,1,0,1),\
145 _SEG7('P',1,1,0,0,1,1,1), _SEG7('q',1,1,1,0,0,1,1), _SEG7('r',0,0,0,0,1,0,1),\
146 _SEG7('S',1,0,1,1,0,1,1), _SEG7('T',0,0,0,1,1,1,1), _SEG7('u',0,0,1,1,1,0,0),\
147 _SEG7('v',0,0,1,1,1,0,0), _SEG7('W',0,1,1,1,1,1,1), _SEG7('X',0,1,1,0,1,1,1),\
148 _SEG7('y',0,1,1,1,0,1,1), _SEG7('Z',1,1,0,1,1,0,1),
149
150#define _MAP_123_126_ASCII_SEG7_SYMBOL \
151 _SEG7('{',1,0,0,1,1,1,0), _SEG7('|',0,0,0,0,1,1,0), _SEG7('}',1,1,1,1,0,0,0),\
152 _SEG7('~',1,0,0,0,0,0,0),
153
154/* Maps */
155
156/* This set tries to map as close as possible to the visible characteristics
157 * of the ASCII symbol, lowercase and uppercase letters may differ in
158 * presentation on the display.
159 */
160#define MAP_ASCII7SEG_ALPHANUM \
161 _MAP_0_32_ASCII_SEG7_NON_PRINTABLE \
162 _MAP_33_47_ASCII_SEG7_SYMBOL \
163 _MAP_48_57_ASCII_SEG7_NUMERIC \
164 _MAP_58_64_ASCII_SEG7_SYMBOL \
165 _MAP_65_90_ASCII_SEG7_ALPHA_UPPR \
166 _MAP_91_96_ASCII_SEG7_SYMBOL \
167 _MAP_97_122_ASCII_SEG7_ALPHA_LOWER \
168 _MAP_123_126_ASCII_SEG7_SYMBOL
169
170/* This set tries to map as close as possible to the symbolic characteristics
171 * of the ASCII character for maximum discrimination.
172 * For now this means all alpha chars are in lower case representations.
173 * (This for example facilitates the use of hex numbers with uppercase input.)
174 */
175#define MAP_ASCII7SEG_ALPHANUM_LC \
176 _MAP_0_32_ASCII_SEG7_NON_PRINTABLE \
177 _MAP_33_47_ASCII_SEG7_SYMBOL \
178 _MAP_48_57_ASCII_SEG7_NUMERIC \
179 _MAP_58_64_ASCII_SEG7_SYMBOL \
180 _MAP_97_122_ASCII_SEG7_ALPHA_LOWER \
181 _MAP_91_96_ASCII_SEG7_SYMBOL \
182 _MAP_97_122_ASCII_SEG7_ALPHA_LOWER \
183 _MAP_123_126_ASCII_SEG7_SYMBOL
184
185#define SEG7_DEFAULT_MAP(_name) \
186 SEG7_CONVERSION_MAP(_name,MAP_ASCII7SEG_ALPHANUM)
187
188#endif /* MAP_TO_7SEGMENT_H */
189
diff --git a/drivers/input/misc/wistron_btns.c b/drivers/input/misc/wistron_btns.c
index fe268be3293b..7c8957dd22c0 100644
--- a/drivers/input/misc/wistron_btns.c
+++ b/drivers/input/misc/wistron_btns.c
@@ -277,6 +277,16 @@ static struct key_entry keymap_fs_amilo_pro_v2000[] __initdata = {
277 { KE_END, 0 } 277 { KE_END, 0 }
278}; 278};
279 279
280static struct key_entry keymap_fs_amilo_pro_v3505[] __initdata = {
281 { KE_KEY, 0x01, {KEY_HELP} }, /* Fn+F1 */
282 { KE_KEY, 0x06, {KEY_DISPLAYTOGGLE} }, /* Fn+F4 */
283 { KE_BLUETOOTH, 0x30 }, /* Fn+F10 */
284 { KE_KEY, 0x31, {KEY_MAIL} }, /* mail button */
285 { KE_KEY, 0x36, {KEY_WWW} }, /* www button */
286 { KE_WIFI, 0x78 }, /* satelite dish button */
287 { KE_END, 0 }
288};
289
280static struct key_entry keymap_fujitsu_n3510[] __initdata = { 290static struct key_entry keymap_fujitsu_n3510[] __initdata = {
281 { KE_KEY, 0x11, {KEY_PROG1} }, 291 { KE_KEY, 0x11, {KEY_PROG1} },
282 { KE_KEY, 0x12, {KEY_PROG2} }, 292 { KE_KEY, 0x12, {KEY_PROG2} },
@@ -618,6 +628,15 @@ static struct dmi_system_id dmi_ids[] __initdata = {
618 }, 628 },
619 { 629 {
620 .callback = dmi_matched, 630 .callback = dmi_matched,
631 .ident = "Fujitsu-Siemens Amilo Pro Edition V3505",
632 .matches = {
633 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
634 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pro Edition V3505"),
635 },
636 .driver_data = keymap_fs_amilo_pro_v3505
637 },
638 {
639 .callback = dmi_matched,
621 .ident = "Fujitsu-Siemens Amilo M7400", 640 .ident = "Fujitsu-Siemens Amilo M7400",
622 .matches = { 641 .matches = {
623 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"), 642 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
diff --git a/drivers/input/misc/yealink.c b/drivers/input/misc/yealink.c
index facefd3dba29..11b5c7e84ed1 100644
--- a/drivers/input/misc/yealink.c
+++ b/drivers/input/misc/yealink.c
@@ -52,8 +52,8 @@
52#include <linux/module.h> 52#include <linux/module.h>
53#include <linux/rwsem.h> 53#include <linux/rwsem.h>
54#include <linux/usb/input.h> 54#include <linux/usb/input.h>
55#include <linux/map_to_7segment.h>
55 56
56#include "map_to_7segment.h"
57#include "yealink.h" 57#include "yealink.h"
58 58
59#define DRIVER_VERSION "yld-20051230" 59#define DRIVER_VERSION "yld-20051230"
diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index f996546fc443..f488b6852baf 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -96,6 +96,16 @@ config MOUSE_PS2_TOUCHKIT
96 96
97 If unsure, say N. 97 If unsure, say N.
98 98
99config MOUSE_PS2_OLPC
100 bool "OLPC PS/2 mouse protocol extension"
101 depends on MOUSE_PS2 && OLPC
102 help
103 Say Y here if you have an OLPC XO-1 laptop (with built-in
104 PS/2 touchpad/tablet device). The manufacturer calls the
105 touchpad an HGPK.
106
107 If unsure, say N.
108
99config MOUSE_SERIAL 109config MOUSE_SERIAL
100 tristate "Serial mouse" 110 tristate "Serial mouse"
101 select SERIO 111 select SERIO
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index d4d202516090..8e6e69097801 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_MOUSE_GPIO) += gpio_mouse.o
21psmouse-objs := psmouse-base.o synaptics.o 21psmouse-objs := psmouse-base.o synaptics.o
22 22
23psmouse-$(CONFIG_MOUSE_PS2_ALPS) += alps.o 23psmouse-$(CONFIG_MOUSE_PS2_ALPS) += alps.o
24psmouse-$(CONFIG_MOUSE_PS2_OLPC) += hgpk.o
24psmouse-$(CONFIG_MOUSE_PS2_LOGIPS2PP) += logips2pp.o 25psmouse-$(CONFIG_MOUSE_PS2_LOGIPS2PP) += logips2pp.o
25psmouse-$(CONFIG_MOUSE_PS2_LIFEBOOK) += lifebook.o 26psmouse-$(CONFIG_MOUSE_PS2_LIFEBOOK) += lifebook.o
26psmouse-$(CONFIG_MOUSE_PS2_TRACKPOINT) += trackpoint.o 27psmouse-$(CONFIG_MOUSE_PS2_TRACKPOINT) += trackpoint.o
diff --git a/drivers/input/mouse/alps.c b/drivers/input/mouse/alps.c
index 385e32bcf6a6..cbedf957cc58 100644
--- a/drivers/input/mouse/alps.c
+++ b/drivers/input/mouse/alps.c
@@ -54,6 +54,7 @@ static const struct alps_model_info alps_model_data[] = {
54 { { 0x20, 0x02, 0x0e }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */ 54 { { 0x20, 0x02, 0x0e }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, /* XXX */
55 { { 0x22, 0x02, 0x0a }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT }, 55 { { 0x22, 0x02, 0x0a }, 0xf8, 0xf8, ALPS_PASS | ALPS_DUALPOINT },
56 { { 0x22, 0x02, 0x14 }, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */ 56 { { 0x22, 0x02, 0x14 }, 0xff, 0xff, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude D600 */
57 { { 0x62, 0x02, 0x14 }, 0xcf, 0xcf, ALPS_PASS | ALPS_DUALPOINT }, /* Dell Latitude E6500 */
57 { { 0x73, 0x02, 0x50 }, 0xcf, 0xcf, ALPS_FW_BK_1 } /* Dell Vostro 1400 */ 58 { { 0x73, 0x02, 0x50 }, 0xcf, 0xcf, ALPS_FW_BK_1 } /* Dell Vostro 1400 */
58}; 59};
59 60
diff --git a/drivers/input/mouse/appletouch.c b/drivers/input/mouse/appletouch.c
index 1f41ae94f26b..079816e6b23b 100644
--- a/drivers/input/mouse/appletouch.c
+++ b/drivers/input/mouse/appletouch.c
@@ -136,12 +136,28 @@ MODULE_DEVICE_TABLE(usb, atp_table);
136#define ATP_GEYSER_MODE_REQUEST_INDEX 0 136#define ATP_GEYSER_MODE_REQUEST_INDEX 0
137#define ATP_GEYSER_MODE_VENDOR_VALUE 0x04 137#define ATP_GEYSER_MODE_VENDOR_VALUE 0x04
138 138
139/**
140 * enum atp_status_bits - status bit meanings
141 *
142 * These constants represent the meaning of the status bits.
143 * (only Geyser 3/4)
144 *
145 * @ATP_STATUS_BUTTON: The button was pressed
146 * @ATP_STATUS_BASE_UPDATE: Update of the base values (untouched pad)
147 * @ATP_STATUS_FROM_RESET: Reset previously performed
148 */
149enum atp_status_bits {
150 ATP_STATUS_BUTTON = BIT(0),
151 ATP_STATUS_BASE_UPDATE = BIT(2),
152 ATP_STATUS_FROM_RESET = BIT(4),
153};
154
139/* Structure to hold all of our device specific stuff */ 155/* Structure to hold all of our device specific stuff */
140struct atp { 156struct atp {
141 char phys[64]; 157 char phys[64];
142 struct usb_device *udev; /* usb device */ 158 struct usb_device *udev; /* usb device */
143 struct urb *urb; /* usb request block */ 159 struct urb *urb; /* usb request block */
144 signed char *data; /* transferred data */ 160 u8 *data; /* transferred data */
145 struct input_dev *input; /* input dev */ 161 struct input_dev *input; /* input dev */
146 enum atp_touchpad_type type; /* type of touchpad */ 162 enum atp_touchpad_type type; /* type of touchpad */
147 bool open; 163 bool open;
@@ -251,8 +267,6 @@ static void atp_reinit(struct work_struct *work)
251 int retval; 267 int retval;
252 268
253 dprintk("appletouch: putting appletouch to sleep (reinit)\n"); 269 dprintk("appletouch: putting appletouch to sleep (reinit)\n");
254 dev->idlecount = 0;
255
256 atp_geyser_init(udev); 270 atp_geyser_init(udev);
257 271
258 retval = usb_submit_urb(dev->urb, GFP_ATOMIC); 272 retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
@@ -327,11 +341,14 @@ static inline void atp_report_fingers(struct input_dev *input, int fingers)
327 input_report_key(input, BTN_TOOL_TRIPLETAP, fingers > 2); 341 input_report_key(input, BTN_TOOL_TRIPLETAP, fingers > 2);
328} 342}
329 343
330static void atp_complete(struct urb *urb) 344/* Check URB status and for correct length of data package */
345
346#define ATP_URB_STATUS_SUCCESS 0
347#define ATP_URB_STATUS_ERROR 1
348#define ATP_URB_STATUS_ERROR_FATAL 2
349
350static int atp_status_check(struct urb *urb)
331{ 351{
332 int x, y, x_z, y_z, x_f, y_f;
333 int retval, i, j;
334 int key;
335 struct atp *dev = urb->context; 352 struct atp *dev = urb->context;
336 353
337 switch (urb->status) { 354 switch (urb->status) {
@@ -351,11 +368,12 @@ static void atp_complete(struct urb *urb)
351 /* This urb is terminated, clean up */ 368 /* This urb is terminated, clean up */
352 dbg("atp_complete: urb shutting down with status: %d", 369 dbg("atp_complete: urb shutting down with status: %d",
353 urb->status); 370 urb->status);
354 return; 371 return ATP_URB_STATUS_ERROR_FATAL;
372
355 default: 373 default:
356 dbg("atp_complete: nonzero urb status received: %d", 374 dbg("atp_complete: nonzero urb status received: %d",
357 urb->status); 375 urb->status);
358 goto exit; 376 return ATP_URB_STATUS_ERROR;
359 } 377 }
360 378
361 /* drop incomplete datasets */ 379 /* drop incomplete datasets */
@@ -363,30 +381,33 @@ static void atp_complete(struct urb *urb)
363 dprintk("appletouch: incomplete data package" 381 dprintk("appletouch: incomplete data package"
364 " (first byte: %d, length: %d).\n", 382 " (first byte: %d, length: %d).\n",
365 dev->data[0], dev->urb->actual_length); 383 dev->data[0], dev->urb->actual_length);
366 goto exit; 384 return ATP_URB_STATUS_ERROR;
367 } 385 }
368 386
369 /* reorder the sensors values */ 387 return ATP_URB_STATUS_SUCCESS;
370 if (dev->type == ATP_GEYSER3 || dev->type == ATP_GEYSER4) { 388}
371 memset(dev->xy_cur, 0, sizeof(dev->xy_cur));
372 389
373 /* 390/*
374 * The values are laid out like this: 391 * USB interrupt callback functions
375 * -, Y1, Y2, -, Y3, Y4, -, ..., -, X1, X2, -, X3, X4, ... 392 */
376 * '-' is an unused value.
377 */
378 393
379 /* read X values */ 394/* Interrupt function for older touchpads: FOUNTAIN/GEYSER1/GEYSER2 */
380 for (i = 0, j = 19; i < 20; i += 2, j += 3) { 395
381 dev->xy_cur[i] = dev->data[j + 1]; 396static void atp_complete_geyser_1_2(struct urb *urb)
382 dev->xy_cur[i + 1] = dev->data[j + 2]; 397{
383 } 398 int x, y, x_z, y_z, x_f, y_f;
384 /* read Y values */ 399 int retval, i, j;
385 for (i = 0, j = 1; i < 9; i += 2, j += 3) { 400 int key;
386 dev->xy_cur[ATP_XSENSORS + i] = dev->data[j + 1]; 401 struct atp *dev = urb->context;
387 dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 2]; 402 int status = atp_status_check(urb);
388 } 403
389 } else if (dev->type == ATP_GEYSER2) { 404 if (status == ATP_URB_STATUS_ERROR_FATAL)
405 return;
406 else if (status == ATP_URB_STATUS_ERROR)
407 goto exit;
408
409 /* reorder the sensors values */
410 if (dev->type == ATP_GEYSER2) {
390 memset(dev->xy_cur, 0, sizeof(dev->xy_cur)); 411 memset(dev->xy_cur, 0, sizeof(dev->xy_cur));
391 412
392 /* 413 /*
@@ -427,34 +448,40 @@ static void atp_complete(struct urb *urb)
427 /* first sample */ 448 /* first sample */
428 dev->valid = true; 449 dev->valid = true;
429 dev->x_old = dev->y_old = -1; 450 dev->x_old = dev->y_old = -1;
451
452 /* Store first sample */
430 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old)); 453 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
431 454
432 if (dev->size_detect_done || 455 /* Perform size detection, if not done already */
433 dev->type == ATP_GEYSER3) /* No 17" Macbooks (yet) */ 456 if (!dev->size_detect_done) {
434 goto exit; 457
458 /* 17" Powerbooks have extra X sensors */
459 for (i = (dev->type == ATP_GEYSER2 ? 15 : 16);
460 i < ATP_XSENSORS; i++) {
461 if (!dev->xy_cur[i])
462 continue;
463
464 printk(KERN_INFO
465 "appletouch: 17\" model detected.\n");
466
467 if (dev->type == ATP_GEYSER2)
468 input_set_abs_params(dev->input, ABS_X,
469 0,
470 (20 - 1) *
471 ATP_XFACT - 1,
472 ATP_FUZZ, 0);
473 else
474 input_set_abs_params(dev->input, ABS_X,
475 0,
476 (26 - 1) *
477 ATP_XFACT - 1,
478 ATP_FUZZ, 0);
479 break;
480 }
435 481
436 /* 17" Powerbooks have extra X sensors */ 482 dev->size_detect_done = 1;
437 for (i = (dev->type == ATP_GEYSER2 ? 15 : 16); 483 goto exit;
438 i < ATP_XSENSORS; i++) {
439 if (!dev->xy_cur[i])
440 continue;
441
442 printk(KERN_INFO "appletouch: 17\" model detected.\n");
443 if (dev->type == ATP_GEYSER2)
444 input_set_abs_params(dev->input, ABS_X, 0,
445 (20 - 1) *
446 ATP_XFACT - 1,
447 ATP_FUZZ, 0);
448 else
449 input_set_abs_params(dev->input, ABS_X, 0,
450 (ATP_XSENSORS - 1) *
451 ATP_XFACT - 1,
452 ATP_FUZZ, 0);
453 break;
454 } 484 }
455
456 dev->size_detect_done = 1;
457 goto exit;
458 } 485 }
459 486
460 for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) { 487 for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) {
@@ -475,7 +502,118 @@ static void atp_complete(struct urb *urb)
475 ATP_XFACT, &x_z, &x_f); 502 ATP_XFACT, &x_z, &x_f);
476 y = atp_calculate_abs(dev->xy_acc + ATP_XSENSORS, ATP_YSENSORS, 503 y = atp_calculate_abs(dev->xy_acc + ATP_XSENSORS, ATP_YSENSORS,
477 ATP_YFACT, &y_z, &y_f); 504 ATP_YFACT, &y_z, &y_f);
478 key = dev->data[dev->datalen - 1] & 1; 505 key = dev->data[dev->datalen - 1] & ATP_STATUS_BUTTON;
506
507 if (x && y) {
508 if (dev->x_old != -1) {
509 x = (dev->x_old * 3 + x) >> 2;
510 y = (dev->y_old * 3 + y) >> 2;
511 dev->x_old = x;
512 dev->y_old = y;
513
514 if (debug > 1)
515 printk(KERN_DEBUG "appletouch: "
516 "X: %3d Y: %3d Xz: %3d Yz: %3d\n",
517 x, y, x_z, y_z);
518
519 input_report_key(dev->input, BTN_TOUCH, 1);
520 input_report_abs(dev->input, ABS_X, x);
521 input_report_abs(dev->input, ABS_Y, y);
522 input_report_abs(dev->input, ABS_PRESSURE,
523 min(ATP_PRESSURE, x_z + y_z));
524 atp_report_fingers(dev->input, max(x_f, y_f));
525 }
526 dev->x_old = x;
527 dev->y_old = y;
528
529 } else if (!x && !y) {
530
531 dev->x_old = dev->y_old = -1;
532 input_report_key(dev->input, BTN_TOUCH, 0);
533 input_report_abs(dev->input, ABS_PRESSURE, 0);
534 atp_report_fingers(dev->input, 0);
535
536 /* reset the accumulator on release */
537 memset(dev->xy_acc, 0, sizeof(dev->xy_acc));
538 }
539
540 input_report_key(dev->input, BTN_LEFT, key);
541 input_sync(dev->input);
542
543 exit:
544 retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
545 if (retval)
546 err("atp_complete: usb_submit_urb failed with result %d",
547 retval);
548}
549
550/* Interrupt function for older touchpads: GEYSER3/GEYSER4 */
551
552static void atp_complete_geyser_3_4(struct urb *urb)
553{
554 int x, y, x_z, y_z, x_f, y_f;
555 int retval, i, j;
556 int key;
557 struct atp *dev = urb->context;
558 int status = atp_status_check(urb);
559
560 if (status == ATP_URB_STATUS_ERROR_FATAL)
561 return;
562 else if (status == ATP_URB_STATUS_ERROR)
563 goto exit;
564
565 /* Reorder the sensors values:
566 *
567 * The values are laid out like this:
568 * -, Y1, Y2, -, Y3, Y4, -, ..., -, X1, X2, -, X3, X4, ...
569 * '-' is an unused value.
570 */
571
572 /* read X values */
573 for (i = 0, j = 19; i < 20; i += 2, j += 3) {
574 dev->xy_cur[i] = dev->data[j + 1];
575 dev->xy_cur[i + 1] = dev->data[j + 2];
576 }
577 /* read Y values */
578 for (i = 0, j = 1; i < 9; i += 2, j += 3) {
579 dev->xy_cur[ATP_XSENSORS + i] = dev->data[j + 1];
580 dev->xy_cur[ATP_XSENSORS + i + 1] = dev->data[j + 2];
581 }
582
583 dbg_dump("sample", dev->xy_cur);
584
585 /* Just update the base values (i.e. touchpad in untouched state) */
586 if (dev->data[dev->datalen - 1] & ATP_STATUS_BASE_UPDATE) {
587
588 dprintk(KERN_DEBUG "appletouch: updated base values\n");
589
590 memcpy(dev->xy_old, dev->xy_cur, sizeof(dev->xy_old));
591 goto exit;
592 }
593
594 for (i = 0; i < ATP_XSENSORS + ATP_YSENSORS; i++) {
595 /* calculate the change */
596 dev->xy_acc[i] = dev->xy_cur[i] - dev->xy_old[i];
597
598 /* this is a round-robin value, so couple with that */
599 if (dev->xy_acc[i] > 127)
600 dev->xy_acc[i] -= 256;
601
602 if (dev->xy_acc[i] < -127)
603 dev->xy_acc[i] += 256;
604
605 /* prevent down drifting */
606 if (dev->xy_acc[i] < 0)
607 dev->xy_acc[i] = 0;
608 }
609
610 dbg_dump("accumulator", dev->xy_acc);
611
612 x = atp_calculate_abs(dev->xy_acc, ATP_XSENSORS,
613 ATP_XFACT, &x_z, &x_f);
614 y = atp_calculate_abs(dev->xy_acc + ATP_XSENSORS, ATP_YSENSORS,
615 ATP_YFACT, &y_z, &y_f);
616 key = dev->data[dev->datalen - 1] & ATP_STATUS_BUTTON;
479 617
480 if (x && y) { 618 if (x && y) {
481 if (dev->x_old != -1) { 619 if (dev->x_old != -1) {
@@ -514,28 +652,27 @@ static void atp_complete(struct urb *urb)
514 input_sync(dev->input); 652 input_sync(dev->input);
515 653
516 /* 654 /*
517 * Many Geysers will continue to send packets continually after 655 * Geysers 3/4 will continue to send packets continually after
518 * the first touch unless reinitialised. Do so if it's been 656 * the first touch unless reinitialised. Do so if it's been
519 * idle for a while in order to avoid waking the kernel up 657 * idle for a while in order to avoid waking the kernel up
520 * several hundred times a second. Re-initialization does not 658 * several hundred times a second.
521 * work on Fountain touchpads.
522 */ 659 */
523 if (dev->type != ATP_FOUNTAIN) { 660
524 /* 661 /*
525 * Button must not be pressed when entering suspend, 662 * Button must not be pressed when entering suspend,
526 * otherwise we will never release the button. 663 * otherwise we will never release the button.
527 */ 664 */
528 if (!x && !y && !key) { 665 if (!x && !y && !key) {
529 dev->idlecount++; 666 dev->idlecount++;
530 if (dev->idlecount == 10) { 667 if (dev->idlecount == 10) {
531 dev->valid = false; 668 dev->x_old = dev->y_old = -1;
532 schedule_work(&dev->work);
533 /* Don't resubmit urb here, wait for reinit */
534 return;
535 }
536 } else
537 dev->idlecount = 0; 669 dev->idlecount = 0;
538 } 670 schedule_work(&dev->work);
671 /* Don't resubmit urb here, wait for reinit */
672 return;
673 }
674 } else
675 dev->idlecount = 0;
539 676
540 exit: 677 exit:
541 retval = usb_submit_urb(dev->urb, GFP_ATOMIC); 678 retval = usb_submit_urb(dev->urb, GFP_ATOMIC);
@@ -632,9 +769,19 @@ static int atp_probe(struct usb_interface *iface,
632 if (!dev->data) 769 if (!dev->data)
633 goto err_free_urb; 770 goto err_free_urb;
634 771
635 usb_fill_int_urb(dev->urb, udev, 772 /* Select the USB complete (callback) function */
636 usb_rcvintpipe(udev, int_in_endpointAddr), 773 if (dev->type == ATP_FOUNTAIN ||
637 dev->data, dev->datalen, atp_complete, dev, 1); 774 dev->type == ATP_GEYSER1 ||
775 dev->type == ATP_GEYSER2)
776 usb_fill_int_urb(dev->urb, udev,
777 usb_rcvintpipe(udev, int_in_endpointAddr),
778 dev->data, dev->datalen,
779 atp_complete_geyser_1_2, dev, 1);
780 else
781 usb_fill_int_urb(dev->urb, udev,
782 usb_rcvintpipe(udev, int_in_endpointAddr),
783 dev->data, dev->datalen,
784 atp_complete_geyser_3_4, dev, 1);
638 785
639 error = atp_handle_geyser(dev); 786 error = atp_handle_geyser(dev);
640 if (error) 787 if (error)
@@ -751,8 +898,6 @@ static int atp_suspend(struct usb_interface *iface, pm_message_t message)
751 struct atp *dev = usb_get_intfdata(iface); 898 struct atp *dev = usb_get_intfdata(iface);
752 899
753 usb_kill_urb(dev->urb); 900 usb_kill_urb(dev->urb);
754 dev->valid = false;
755
756 return 0; 901 return 0;
757} 902}
758 903
diff --git a/drivers/input/mouse/hgpk.c b/drivers/input/mouse/hgpk.c
new file mode 100644
index 000000000000..e82d34201e97
--- /dev/null
+++ b/drivers/input/mouse/hgpk.c
@@ -0,0 +1,477 @@
1/*
2 * OLPC HGPK (XO-1) touchpad PS/2 mouse driver
3 *
4 * Copyright (c) 2006-2008 One Laptop Per Child
5 * Authors:
6 * Zephaniah E. Hull
7 * Andres Salomon <dilinger@debian.org>
8 *
9 * This driver is partly based on the ALPS driver, which is:
10 *
11 * Copyright (c) 2003 Neil Brown <neilb@cse.unsw.edu.au>
12 * Copyright (c) 2003-2005 Peter Osterlund <petero2@telia.com>
13 * Copyright (c) 2004 Dmitry Torokhov <dtor@mail.ru>
14 * Copyright (c) 2005 Vojtech Pavlik <vojtech@suse.cz>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2 as
18 * published by the Free Software Foundation.
19 */
20
21/*
22 * The spec from ALPS is available from
23 * <http://wiki.laptop.org/go/Touch_Pad/Tablet>. It refers to this
24 * device as HGPK (Hybrid GS, PT, and Keymatrix).
25 *
26 * The earliest versions of the device had simultaneous reporting; that
27 * was removed. After that, the device used the Advanced Mode GS/PT streaming
28 * stuff. That turned out to be too buggy to support, so we've finally
29 * switched to Mouse Mode (which utilizes only the center 1/3 of the touchpad).
30 */
31
32#define DEBUG
33#include <linux/input.h>
34#include <linux/serio.h>
35#include <linux/libps2.h>
36#include <linux/delay.h>
37#include <asm/olpc.h>
38
39#include "psmouse.h"
40#include "hgpk.h"
41
42static int tpdebug;
43module_param(tpdebug, int, 0644);
44MODULE_PARM_DESC(tpdebug, "enable debugging, dumping packets to KERN_DEBUG.");
45
46static int recalib_delta = 100;
47module_param(recalib_delta, int, 0644);
48MODULE_PARM_DESC(recalib_delta,
49 "packets containing a delta this large will cause a recalibration.");
50
51/*
52 * When the touchpad gets ultra-sensitive, one can keep their finger 1/2"
53 * above the pad and still have it send packets. This causes a jump cursor
54 * when one places their finger on the pad. We can probably detect the
55 * jump as we see a large deltas (>= 100px). In mouse mode, I've been
56 * unable to even come close to 100px deltas during normal usage, so I think
57 * this threshold is safe. If a large delta occurs, trigger a recalibration.
58 */
59static void hgpk_jumpy_hack(struct psmouse *psmouse, int x, int y)
60{
61 struct hgpk_data *priv = psmouse->private;
62
63 if (abs(x) > recalib_delta || abs(y) > recalib_delta) {
64 hgpk_err(psmouse, ">%dpx jump detected (%d,%d)\n",
65 recalib_delta, x, y);
66 /* My car gets forty rods to the hogshead and that's the
67 * way I likes it! */
68 psmouse_queue_work(psmouse, &priv->recalib_wq,
69 msecs_to_jiffies(1000));
70 }
71}
72
73/*
74 * We have no idea why this particular hardware bug occurs. The touchpad
75 * will randomly start spewing packets without anything touching the
76 * pad. This wouldn't necessarily be bad, but it's indicative of a
77 * severely miscalibrated pad; attempting to use the touchpad while it's
78 * spewing means the cursor will jump all over the place, and act "drunk".
79 *
80 * The packets that are spewed tend to all have deltas between -2 and 2, and
81 * the cursor will move around without really going very far. It will
82 * tend to end up in the same location; if we tally up the changes over
83 * 100 packets, we end up w/ a final delta of close to 0. This happens
84 * pretty regularly when the touchpad is spewing, and is pretty hard to
85 * manually trigger (at least for *my* fingers). So, it makes a perfect
86 * scheme for detecting spews.
87 */
88static void hgpk_spewing_hack(struct psmouse *psmouse,
89 int l, int r, int x, int y)
90{
91 struct hgpk_data *priv = psmouse->private;
92
93 /* ignore button press packets; many in a row could trigger
94 * a false-positive! */
95 if (l || r)
96 return;
97
98 priv->x_tally += x;
99 priv->y_tally += y;
100
101 if (++priv->count > 100) {
102 if (abs(priv->x_tally) < 3 && abs(priv->y_tally) < 3) {
103 hgpk_dbg(psmouse, "packet spew detected (%d,%d)\n",
104 priv->x_tally, priv->y_tally);
105 psmouse_queue_work(psmouse, &priv->recalib_wq,
106 msecs_to_jiffies(1000));
107 }
108 /* reset every 100 packets */
109 priv->count = 0;
110 priv->x_tally = 0;
111 priv->y_tally = 0;
112 }
113}
114
115/*
116 * HGPK Mouse Mode format (standard mouse format, sans middle button)
117 *
118 * byte 0: y-over x-over y-neg x-neg 1 0 swr swl
119 * byte 1: x7 x6 x5 x4 x3 x2 x1 x0
120 * byte 2: y7 y6 y5 y4 y3 y2 y1 y0
121 *
122 * swr/swl are the left/right buttons.
123 * x-neg/y-neg are the x and y delta negative bits
124 * x-over/y-over are the x and y overflow bits
125 */
126static int hgpk_validate_byte(unsigned char *packet)
127{
128 return (packet[0] & 0x0C) == 0x08;
129}
130
131static void hgpk_process_packet(struct psmouse *psmouse)
132{
133 struct input_dev *dev = psmouse->dev;
134 unsigned char *packet = psmouse->packet;
135 int x, y, left, right;
136
137 left = packet[0] & 1;
138 right = (packet[0] >> 1) & 1;
139
140 x = packet[1] - ((packet[0] << 4) & 0x100);
141 y = ((packet[0] << 3) & 0x100) - packet[2];
142
143 hgpk_jumpy_hack(psmouse, x, y);
144 hgpk_spewing_hack(psmouse, left, right, x, y);
145
146 if (tpdebug)
147 hgpk_dbg(psmouse, "l=%d r=%d x=%d y=%d\n", left, right, x, y);
148
149 input_report_key(dev, BTN_LEFT, left);
150 input_report_key(dev, BTN_RIGHT, right);
151
152 input_report_rel(dev, REL_X, x);
153 input_report_rel(dev, REL_Y, y);
154
155 input_sync(dev);
156}
157
158static psmouse_ret_t hgpk_process_byte(struct psmouse *psmouse)
159{
160 struct hgpk_data *priv = psmouse->private;
161
162 if (hgpk_validate_byte(psmouse->packet)) {
163 hgpk_dbg(psmouse, "%s: (%d) %02x %02x %02x\n",
164 __func__, psmouse->pktcnt, psmouse->packet[0],
165 psmouse->packet[1], psmouse->packet[2]);
166 return PSMOUSE_BAD_DATA;
167 }
168
169 if (psmouse->pktcnt >= psmouse->pktsize) {
170 hgpk_process_packet(psmouse);
171 return PSMOUSE_FULL_PACKET;
172 }
173
174 if (priv->recalib_window) {
175 if (time_before(jiffies, priv->recalib_window)) {
176 /*
177 * ugh, got a packet inside our recalibration
178 * window, schedule another recalibration.
179 */
180 hgpk_dbg(psmouse,
181 "packet inside calibration window, "
182 "queueing another recalibration\n");
183 psmouse_queue_work(psmouse, &priv->recalib_wq,
184 msecs_to_jiffies(1000));
185 }
186 priv->recalib_window = 0;
187 }
188
189 return PSMOUSE_GOOD_DATA;
190}
191
192static int hgpk_force_recalibrate(struct psmouse *psmouse)
193{
194 struct ps2dev *ps2dev = &psmouse->ps2dev;
195 struct hgpk_data *priv = psmouse->private;
196
197 /* C-series touchpads added the recalibrate command */
198 if (psmouse->model < HGPK_MODEL_C)
199 return 0;
200
201 /* we don't want to race with the irq handler, nor with resyncs */
202 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
203
204 /* start by resetting the device */
205 psmouse_reset(psmouse);
206
207 /* send the recalibrate request */
208 if (ps2_command(ps2dev, NULL, 0xf5) ||
209 ps2_command(ps2dev, NULL, 0xf5) ||
210 ps2_command(ps2dev, NULL, 0xe6) ||
211 ps2_command(ps2dev, NULL, 0xf5)) {
212 return -1;
213 }
214
215 /* according to ALPS, 150mS is required for recalibration */
216 msleep(150);
217
218 /* XXX: If a finger is down during this delay, recalibration will
219 * detect capacitance incorrectly. This is a hardware bug, and
220 * we don't have a good way to deal with it. The 2s window stuff
221 * (below) is our best option for now.
222 */
223
224 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_ENABLE))
225 return -1;
226
227 psmouse_set_state(psmouse, PSMOUSE_ACTIVATED);
228
229 /* After we recalibrate, we shouldn't get any packets for 2s. If
230 * we do, it's likely that someone's finger was on the touchpad.
231 * If someone's finger *was* on the touchpad, it's probably
232 * miscalibrated. So, we should schedule another recalibration
233 */
234 priv->recalib_window = jiffies + msecs_to_jiffies(2000);
235
236 return 0;
237}
238
239/*
240 * This kills power to the touchpad; according to ALPS, current consumption
241 * goes down to 50uA after running this. To turn power back on, we drive
242 * MS-DAT low.
243 */
244static int hgpk_toggle_power(struct psmouse *psmouse, int enable)
245{
246 struct ps2dev *ps2dev = &psmouse->ps2dev;
247 int timeo;
248
249 /* Added on D-series touchpads */
250 if (psmouse->model < HGPK_MODEL_D)
251 return 0;
252
253 if (enable) {
254 psmouse_set_state(psmouse, PSMOUSE_INITIALIZING);
255
256 /*
257 * Sending a byte will drive MS-DAT low; this will wake up
258 * the controller. Once we get an ACK back from it, it
259 * means we can continue with the touchpad re-init. ALPS
260 * tells us that 1s should be long enough, so set that as
261 * the upper bound.
262 */
263 for (timeo = 20; timeo > 0; timeo--) {
264 if (!ps2_sendbyte(&psmouse->ps2dev,
265 PSMOUSE_CMD_DISABLE, 20))
266 break;
267 msleep(50);
268 }
269
270 psmouse_reset(psmouse);
271
272 /* should be all set, enable the touchpad */
273 ps2_command(&psmouse->ps2dev, NULL, PSMOUSE_CMD_ENABLE);
274 psmouse_set_state(psmouse, PSMOUSE_ACTIVATED);
275
276 } else {
277 hgpk_dbg(psmouse, "Powering off touchpad.\n");
278 psmouse_set_state(psmouse, PSMOUSE_IGNORE);
279
280 if (ps2_command(ps2dev, NULL, 0xec) ||
281 ps2_command(ps2dev, NULL, 0xec) ||
282 ps2_command(ps2dev, NULL, 0xea)) {
283 return -1;
284 }
285
286 /* probably won't see an ACK, the touchpad will be off */
287 ps2_sendbyte(&psmouse->ps2dev, 0xec, 20);
288 }
289
290 return 0;
291}
292
293static int hgpk_poll(struct psmouse *psmouse)
294{
295 /* We can't poll, so always return failure. */
296 return -1;
297}
298
299static int hgpk_reconnect(struct psmouse *psmouse)
300{
301 /* During suspend/resume the ps2 rails remain powered. We don't want
302 * to do a reset because it's flush data out of buffers; however,
303 * earlier prototypes (B1) had some brokenness that required a reset. */
304 if (olpc_board_at_least(olpc_board(0xb2)))
305 if (psmouse->ps2dev.serio->dev.power.power_state.event !=
306 PM_EVENT_ON)
307 return 0;
308
309 psmouse_reset(psmouse);
310
311 return 0;
312}
313
314static ssize_t hgpk_show_powered(struct psmouse *psmouse, void *data, char *buf)
315{
316 struct hgpk_data *priv = psmouse->private;
317
318 return sprintf(buf, "%d\n", priv->powered);
319}
320
321static ssize_t hgpk_set_powered(struct psmouse *psmouse, void *data,
322 const char *buf, size_t count)
323{
324 struct hgpk_data *priv = psmouse->private;
325 unsigned long value;
326 int err;
327
328 err = strict_strtoul(buf, 10, &value);
329 if (err || value > 1)
330 return -EINVAL;
331
332 if (value != priv->powered) {
333 /*
334 * hgpk_toggle_power will deal w/ state so
335 * we're not racing w/ irq
336 */
337 err = hgpk_toggle_power(psmouse, value);
338 if (!err)
339 priv->powered = value;
340 }
341
342 return err ? err : count;
343}
344
345__PSMOUSE_DEFINE_ATTR(powered, S_IWUSR | S_IRUGO, NULL,
346 hgpk_show_powered, hgpk_set_powered, 0);
347
348static void hgpk_disconnect(struct psmouse *psmouse)
349{
350 struct hgpk_data *priv = psmouse->private;
351
352 device_remove_file(&psmouse->ps2dev.serio->dev,
353 &psmouse_attr_powered.dattr);
354 psmouse_reset(psmouse);
355 kfree(priv);
356}
357
358static void hgpk_recalib_work(struct work_struct *work)
359{
360 struct delayed_work *w = container_of(work, struct delayed_work, work);
361 struct hgpk_data *priv = container_of(w, struct hgpk_data, recalib_wq);
362 struct psmouse *psmouse = priv->psmouse;
363
364 hgpk_dbg(psmouse, "recalibrating touchpad..\n");
365
366 if (hgpk_force_recalibrate(psmouse))
367 hgpk_err(psmouse, "recalibration failed!\n");
368}
369
370static int hgpk_register(struct psmouse *psmouse)
371{
372 struct input_dev *dev = psmouse->dev;
373 int err;
374
375 /* unset the things that psmouse-base sets which we don't have */
376 __clear_bit(BTN_MIDDLE, dev->keybit);
377
378 /* set the things we do have */
379 __set_bit(EV_KEY, dev->evbit);
380 __set_bit(EV_REL, dev->evbit);
381
382 __set_bit(REL_X, dev->relbit);
383 __set_bit(REL_Y, dev->relbit);
384
385 __set_bit(BTN_LEFT, dev->keybit);
386 __set_bit(BTN_RIGHT, dev->keybit);
387
388 /* register handlers */
389 psmouse->protocol_handler = hgpk_process_byte;
390 psmouse->poll = hgpk_poll;
391 psmouse->disconnect = hgpk_disconnect;
392 psmouse->reconnect = hgpk_reconnect;
393 psmouse->pktsize = 3;
394
395 /* Disable the idle resync. */
396 psmouse->resync_time = 0;
397 /* Reset after a lot of bad bytes. */
398 psmouse->resetafter = 1024;
399
400 err = device_create_file(&psmouse->ps2dev.serio->dev,
401 &psmouse_attr_powered.dattr);
402 if (err)
403 hgpk_err(psmouse, "Failed to create sysfs attribute\n");
404
405 return err;
406}
407
408int hgpk_init(struct psmouse *psmouse)
409{
410 struct hgpk_data *priv;
411 int err = -ENOMEM;
412
413 priv = kzalloc(sizeof(struct hgpk_data), GFP_KERNEL);
414 if (!priv)
415 goto alloc_fail;
416
417 psmouse->private = priv;
418 priv->psmouse = psmouse;
419 priv->powered = 1;
420 INIT_DELAYED_WORK(&priv->recalib_wq, hgpk_recalib_work);
421
422 err = psmouse_reset(psmouse);
423 if (err)
424 goto init_fail;
425
426 err = hgpk_register(psmouse);
427 if (err)
428 goto init_fail;
429
430 return 0;
431
432init_fail:
433 kfree(priv);
434alloc_fail:
435 return err;
436}
437
438static enum hgpk_model_t hgpk_get_model(struct psmouse *psmouse)
439{
440 struct ps2dev *ps2dev = &psmouse->ps2dev;
441 unsigned char param[3];
442
443 /* E7, E7, E7, E9 gets us a 3 byte identifier */
444 if (ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
445 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
446 ps2_command(ps2dev, NULL, PSMOUSE_CMD_SETSCALE21) ||
447 ps2_command(ps2dev, param, PSMOUSE_CMD_GETINFO)) {
448 return -EIO;
449 }
450
451 hgpk_dbg(psmouse, "ID: %02x %02x %02x", param[0], param[1], param[2]);
452
453 /* HGPK signature: 0x67, 0x00, 0x<model> */
454 if (param[0] != 0x67 || param[1] != 0x00)
455 return -ENODEV;
456
457 hgpk_info(psmouse, "OLPC touchpad revision 0x%x\n", param[2]);
458
459 return param[2];
460}
461
462int hgpk_detect(struct psmouse *psmouse, int set_properties)
463{
464 int version;
465
466 version = hgpk_get_model(psmouse);
467 if (version < 0)
468 return version;
469
470 if (set_properties) {
471 psmouse->vendor = "ALPS";
472 psmouse->name = "HGPK";
473 psmouse->model = version;
474 }
475
476 return 0;
477}
diff --git a/drivers/input/mouse/hgpk.h b/drivers/input/mouse/hgpk.h
new file mode 100644
index 000000000000..a4b2a96f5f54
--- /dev/null
+++ b/drivers/input/mouse/hgpk.h
@@ -0,0 +1,49 @@
1/*
2 * OLPC HGPK (XO-1) touchpad PS/2 mouse driver
3 */
4
5#ifndef _HGPK_H
6#define _HGPK_H
7
8enum hgpk_model_t {
9 HGPK_MODEL_PREA = 0x0a, /* pre-B1s */
10 HGPK_MODEL_A = 0x14, /* found on B1s, PT disabled in hardware */
11 HGPK_MODEL_B = 0x28, /* B2s, has capacitance issues */
12 HGPK_MODEL_C = 0x3c,
13 HGPK_MODEL_D = 0x50, /* C1, mass production */
14};
15
16struct hgpk_data {
17 struct psmouse *psmouse;
18 int powered;
19 int count, x_tally, y_tally; /* hardware workaround stuff */
20 unsigned long recalib_window;
21 struct delayed_work recalib_wq;
22};
23
24#define hgpk_dbg(psmouse, format, arg...) \
25 dev_dbg(&(psmouse)->ps2dev.serio->dev, format, ## arg)
26#define hgpk_err(psmouse, format, arg...) \
27 dev_err(&(psmouse)->ps2dev.serio->dev, format, ## arg)
28#define hgpk_info(psmouse, format, arg...) \
29 dev_info(&(psmouse)->ps2dev.serio->dev, format, ## arg)
30#define hgpk_warn(psmouse, format, arg...) \
31 dev_warn(&(psmouse)->ps2dev.serio->dev, format, ## arg)
32#define hgpk_notice(psmouse, format, arg...) \
33 dev_notice(&(psmouse)->ps2dev.serio->dev, format, ## arg)
34
35#ifdef CONFIG_MOUSE_PS2_OLPC
36int hgpk_detect(struct psmouse *psmouse, int set_properties);
37int hgpk_init(struct psmouse *psmouse);
38#else
39static inline int hgpk_detect(struct psmouse *psmouse, int set_properties)
40{
41 return -ENODEV;
42}
43static inline int hgpk_init(struct psmouse *psmouse)
44{
45 return -ENODEV;
46}
47#endif
48
49#endif
diff --git a/drivers/input/mouse/logips2pp.c b/drivers/input/mouse/logips2pp.c
index 0c5660d28caa..390f1dbb98a4 100644
--- a/drivers/input/mouse/logips2pp.c
+++ b/drivers/input/mouse/logips2pp.c
@@ -157,10 +157,8 @@ static ssize_t ps2pp_attr_show_smartscroll(struct psmouse *psmouse, void *data,
157static ssize_t ps2pp_attr_set_smartscroll(struct psmouse *psmouse, void *data, const char *buf, size_t count) 157static ssize_t ps2pp_attr_set_smartscroll(struct psmouse *psmouse, void *data, const char *buf, size_t count)
158{ 158{
159 unsigned long value; 159 unsigned long value;
160 char *rest;
161 160
162 value = simple_strtoul(buf, &rest, 10); 161 if (strict_strtoul(buf, 10, &value) || value > 1)
163 if (*rest || value > 1)
164 return -EINVAL; 162 return -EINVAL;
165 163
166 ps2pp_set_smartscroll(psmouse, value); 164 ps2pp_set_smartscroll(psmouse, value);
diff --git a/drivers/input/mouse/psmouse-base.c b/drivers/input/mouse/psmouse-base.c
index f5a6be1d3c46..126e977e199e 100644
--- a/drivers/input/mouse/psmouse-base.c
+++ b/drivers/input/mouse/psmouse-base.c
@@ -25,6 +25,7 @@
25#include "synaptics.h" 25#include "synaptics.h"
26#include "logips2pp.h" 26#include "logips2pp.h"
27#include "alps.h" 27#include "alps.h"
28#include "hgpk.h"
28#include "lifebook.h" 29#include "lifebook.h"
29#include "trackpoint.h" 30#include "trackpoint.h"
30#include "touchkit_ps2.h" 31#include "touchkit_ps2.h"
@@ -201,6 +202,12 @@ static psmouse_ret_t psmouse_process_byte(struct psmouse *psmouse)
201 return PSMOUSE_FULL_PACKET; 202 return PSMOUSE_FULL_PACKET;
202} 203}
203 204
205void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work,
206 unsigned long delay)
207{
208 queue_delayed_work(kpsmoused_wq, work, delay);
209}
210
204/* 211/*
205 * __psmouse_set_state() sets new psmouse state and resets all flags. 212 * __psmouse_set_state() sets new psmouse state and resets all flags.
206 */ 213 */
@@ -220,7 +227,7 @@ static inline void __psmouse_set_state(struct psmouse *psmouse, enum psmouse_sta
220 * is not a concern. 227 * is not a concern.
221 */ 228 */
222 229
223static void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state) 230void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state)
224{ 231{
225 serio_pause_rx(psmouse->ps2dev.serio); 232 serio_pause_rx(psmouse->ps2dev.serio);
226 __psmouse_set_state(psmouse, new_state); 233 __psmouse_set_state(psmouse, new_state);
@@ -305,7 +312,7 @@ static irqreturn_t psmouse_interrupt(struct serio *serio,
305 psmouse->name, psmouse->phys, psmouse->pktcnt); 312 psmouse->name, psmouse->phys, psmouse->pktcnt);
306 psmouse->badbyte = psmouse->packet[0]; 313 psmouse->badbyte = psmouse->packet[0];
307 __psmouse_set_state(psmouse, PSMOUSE_RESYNCING); 314 __psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
308 queue_work(kpsmoused_wq, &psmouse->resync_work); 315 psmouse_queue_work(psmouse, &psmouse->resync_work, 0);
309 goto out; 316 goto out;
310 } 317 }
311 318
@@ -342,7 +349,7 @@ static irqreturn_t psmouse_interrupt(struct serio *serio,
342 time_after(jiffies, psmouse->last + psmouse->resync_time * HZ)) { 349 time_after(jiffies, psmouse->last + psmouse->resync_time * HZ)) {
343 psmouse->badbyte = psmouse->packet[0]; 350 psmouse->badbyte = psmouse->packet[0];
344 __psmouse_set_state(psmouse, PSMOUSE_RESYNCING); 351 __psmouse_set_state(psmouse, PSMOUSE_RESYNCING);
345 queue_work(kpsmoused_wq, &psmouse->resync_work); 352 psmouse_queue_work(psmouse, &psmouse->resync_work, 0);
346 goto out; 353 goto out;
347 } 354 }
348 355
@@ -630,8 +637,20 @@ static int psmouse_extensions(struct psmouse *psmouse,
630 } 637 }
631 } 638 }
632 639
633 if (max_proto > PSMOUSE_IMEX) { 640/*
641 * Try OLPC HGPK touchpad.
642 */
643 if (max_proto > PSMOUSE_IMEX &&
644 hgpk_detect(psmouse, set_properties) == 0) {
645 if (!set_properties || hgpk_init(psmouse) == 0)
646 return PSMOUSE_HGPK;
647/*
648 * Init failed, try basic relative protocols
649 */
650 max_proto = PSMOUSE_IMEX;
651 }
634 652
653 if (max_proto > PSMOUSE_IMEX) {
635 if (genius_detect(psmouse, set_properties) == 0) 654 if (genius_detect(psmouse, set_properties) == 0)
636 return PSMOUSE_GENPS; 655 return PSMOUSE_GENPS;
637 656
@@ -762,6 +781,14 @@ static const struct psmouse_protocol psmouse_protocols[] = {
762 .detect = touchkit_ps2_detect, 781 .detect = touchkit_ps2_detect,
763 }, 782 },
764#endif 783#endif
784#ifdef CONFIG_MOUSE_PS2_OLPC
785 {
786 .type = PSMOUSE_HGPK,
787 .name = "OLPC HGPK",
788 .alias = "hgpk",
789 .detect = hgpk_detect,
790 },
791#endif
765 { 792 {
766 .type = PSMOUSE_CORTRON, 793 .type = PSMOUSE_CORTRON,
767 .name = "CortronPS/2", 794 .name = "CortronPS/2",
@@ -935,7 +962,7 @@ static int psmouse_poll(struct psmouse *psmouse)
935static void psmouse_resync(struct work_struct *work) 962static void psmouse_resync(struct work_struct *work)
936{ 963{
937 struct psmouse *parent = NULL, *psmouse = 964 struct psmouse *parent = NULL, *psmouse =
938 container_of(work, struct psmouse, resync_work); 965 container_of(work, struct psmouse, resync_work.work);
939 struct serio *serio = psmouse->ps2dev.serio; 966 struct serio *serio = psmouse->ps2dev.serio;
940 psmouse_ret_t rc = PSMOUSE_GOOD_DATA; 967 psmouse_ret_t rc = PSMOUSE_GOOD_DATA;
941 int failed = 0, enabled = 0; 968 int failed = 0, enabled = 0;
@@ -1194,7 +1221,7 @@ static int psmouse_connect(struct serio *serio, struct serio_driver *drv)
1194 goto err_free; 1221 goto err_free;
1195 1222
1196 ps2_init(&psmouse->ps2dev, serio); 1223 ps2_init(&psmouse->ps2dev, serio);
1197 INIT_WORK(&psmouse->resync_work, psmouse_resync); 1224 INIT_DELAYED_WORK(&psmouse->resync_work, psmouse_resync);
1198 psmouse->dev = input_dev; 1225 psmouse->dev = input_dev;
1199 snprintf(psmouse->phys, sizeof(psmouse->phys), "%s/input0", serio->phys); 1226 snprintf(psmouse->phys, sizeof(psmouse->phys), "%s/input0", serio->phys);
1200 1227
@@ -1395,25 +1422,29 @@ ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *dev
1395 1422
1396 psmouse = serio_get_drvdata(serio); 1423 psmouse = serio_get_drvdata(serio);
1397 1424
1398 if (psmouse->state == PSMOUSE_IGNORE) { 1425 if (attr->protect) {
1399 retval = -ENODEV; 1426 if (psmouse->state == PSMOUSE_IGNORE) {
1400 goto out_unlock; 1427 retval = -ENODEV;
1401 } 1428 goto out_unlock;
1429 }
1402 1430
1403 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) { 1431 if (serio->parent && serio->id.type == SERIO_PS_PSTHRU) {
1404 parent = serio_get_drvdata(serio->parent); 1432 parent = serio_get_drvdata(serio->parent);
1405 psmouse_deactivate(parent); 1433 psmouse_deactivate(parent);
1406 } 1434 }
1407 1435
1408 psmouse_deactivate(psmouse); 1436 psmouse_deactivate(psmouse);
1437 }
1409 1438
1410 retval = attr->set(psmouse, attr->data, buf, count); 1439 retval = attr->set(psmouse, attr->data, buf, count);
1411 1440
1412 if (retval != -ENODEV) 1441 if (attr->protect) {
1413 psmouse_activate(psmouse); 1442 if (retval != -ENODEV)
1443 psmouse_activate(psmouse);
1414 1444
1415 if (parent) 1445 if (parent)
1416 psmouse_activate(parent); 1446 psmouse_activate(parent);
1447 }
1417 1448
1418 out_unlock: 1449 out_unlock:
1419 mutex_unlock(&psmouse_mutex); 1450 mutex_unlock(&psmouse_mutex);
@@ -1433,10 +1464,8 @@ static ssize_t psmouse_set_int_attr(struct psmouse *psmouse, void *offset, const
1433{ 1464{
1434 unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset); 1465 unsigned int *field = (unsigned int *)((char *)psmouse + (size_t)offset);
1435 unsigned long value; 1466 unsigned long value;
1436 char *rest;
1437 1467
1438 value = simple_strtoul(buf, &rest, 10); 1468 if (strict_strtoul(buf, 10, &value))
1439 if (*rest)
1440 return -EINVAL; 1469 return -EINVAL;
1441 1470
1442 if ((unsigned int)value != value) 1471 if ((unsigned int)value != value)
@@ -1549,10 +1578,8 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
1549static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const char *buf, size_t count) 1578static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const char *buf, size_t count)
1550{ 1579{
1551 unsigned long value; 1580 unsigned long value;
1552 char *rest;
1553 1581
1554 value = simple_strtoul(buf, &rest, 10); 1582 if (strict_strtoul(buf, 10, &value))
1555 if (*rest)
1556 return -EINVAL; 1583 return -EINVAL;
1557 1584
1558 psmouse->set_rate(psmouse, value); 1585 psmouse->set_rate(psmouse, value);
@@ -1562,10 +1589,8 @@ static ssize_t psmouse_attr_set_rate(struct psmouse *psmouse, void *data, const
1562static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data, const char *buf, size_t count) 1589static ssize_t psmouse_attr_set_resolution(struct psmouse *psmouse, void *data, const char *buf, size_t count)
1563{ 1590{
1564 unsigned long value; 1591 unsigned long value;
1565 char *rest;
1566 1592
1567 value = simple_strtoul(buf, &rest, 10); 1593 if (strict_strtoul(buf, 10, &value))
1568 if (*rest)
1569 return -EINVAL; 1594 return -EINVAL;
1570 1595
1571 psmouse->set_resolution(psmouse, value); 1596 psmouse->set_resolution(psmouse, value);
diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
index 1317bdd8cc7c..8b608a1cdd12 100644
--- a/drivers/input/mouse/psmouse.h
+++ b/drivers/input/mouse/psmouse.h
@@ -39,7 +39,7 @@ struct psmouse {
39 void *private; 39 void *private;
40 struct input_dev *dev; 40 struct input_dev *dev;
41 struct ps2dev ps2dev; 41 struct ps2dev ps2dev;
42 struct work_struct resync_work; 42 struct delayed_work resync_work;
43 char *vendor; 43 char *vendor;
44 char *name; 44 char *name;
45 unsigned char packet[8]; 45 unsigned char packet[8];
@@ -89,20 +89,24 @@ enum psmouse_type {
89 PSMOUSE_TRACKPOINT, 89 PSMOUSE_TRACKPOINT,
90 PSMOUSE_TOUCHKIT_PS2, 90 PSMOUSE_TOUCHKIT_PS2,
91 PSMOUSE_CORTRON, 91 PSMOUSE_CORTRON,
92 PSMOUSE_HGPK,
92 PSMOUSE_AUTO /* This one should always be last */ 93 PSMOUSE_AUTO /* This one should always be last */
93}; 94};
94 95
96void psmouse_queue_work(struct psmouse *psmouse, struct delayed_work *work,
97 unsigned long delay);
95int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command); 98int psmouse_sliced_command(struct psmouse *psmouse, unsigned char command);
96int psmouse_reset(struct psmouse *psmouse); 99int psmouse_reset(struct psmouse *psmouse);
100void psmouse_set_state(struct psmouse *psmouse, enum psmouse_state new_state);
97void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution); 101void psmouse_set_resolution(struct psmouse *psmouse, unsigned int resolution);
98 102
99
100struct psmouse_attribute { 103struct psmouse_attribute {
101 struct device_attribute dattr; 104 struct device_attribute dattr;
102 void *data; 105 void *data;
103 ssize_t (*show)(struct psmouse *psmouse, void *data, char *buf); 106 ssize_t (*show)(struct psmouse *psmouse, void *data, char *buf);
104 ssize_t (*set)(struct psmouse *psmouse, void *data, 107 ssize_t (*set)(struct psmouse *psmouse, void *data,
105 const char *buf, size_t count); 108 const char *buf, size_t count);
109 int protect;
106}; 110};
107#define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr) 111#define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
108 112
@@ -111,7 +115,7 @@ ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *at
111ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *attr, 115ssize_t psmouse_attr_set_helper(struct device *dev, struct device_attribute *attr,
112 const char *buf, size_t count); 116 const char *buf, size_t count);
113 117
114#define PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set) \ 118#define __PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, _protect) \
115static ssize_t _show(struct psmouse *, void *data, char *); \ 119static ssize_t _show(struct psmouse *, void *data, char *); \
116static ssize_t _set(struct psmouse *, void *data, const char *, size_t); \ 120static ssize_t _set(struct psmouse *, void *data, const char *, size_t); \
117static struct psmouse_attribute psmouse_attr_##_name = { \ 121static struct psmouse_attribute psmouse_attr_##_name = { \
@@ -126,6 +130,10 @@ static struct psmouse_attribute psmouse_attr_##_name = { \
126 .data = _data, \ 130 .data = _data, \
127 .show = _show, \ 131 .show = _show, \
128 .set = _set, \ 132 .set = _set, \
133 .protect = _protect, \
129} 134}
130 135
136#define PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set) \
137 __PSMOUSE_DEFINE_ATTR(_name, _mode, _data, _show, _set, 1)
138
131#endif /* _PSMOUSE_H */ 139#endif /* _PSMOUSE_H */
diff --git a/drivers/input/mouse/trackpoint.c b/drivers/input/mouse/trackpoint.c
index 26b845fc186a..e68c814c4361 100644
--- a/drivers/input/mouse/trackpoint.c
+++ b/drivers/input/mouse/trackpoint.c
@@ -89,10 +89,8 @@ static ssize_t trackpoint_set_int_attr(struct psmouse *psmouse, void *data,
89 struct trackpoint_attr_data *attr = data; 89 struct trackpoint_attr_data *attr = data;
90 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset); 90 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset);
91 unsigned long value; 91 unsigned long value;
92 char *rest;
93 92
94 value = simple_strtoul(buf, &rest, 10); 93 if (strict_strtoul(buf, 10, &value) || value > 255)
95 if (*rest || value > 255)
96 return -EINVAL; 94 return -EINVAL;
97 95
98 *field = value; 96 *field = value;
@@ -117,10 +115,8 @@ static ssize_t trackpoint_set_bit_attr(struct psmouse *psmouse, void *data,
117 struct trackpoint_attr_data *attr = data; 115 struct trackpoint_attr_data *attr = data;
118 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset); 116 unsigned char *field = (unsigned char *)((char *)tp + attr->field_offset);
119 unsigned long value; 117 unsigned long value;
120 char *rest;
121 118
122 value = simple_strtoul(buf, &rest, 10); 119 if (strict_strtoul(buf, 10, &value) || value > 1)
123 if (*rest || value > 1)
124 return -EINVAL; 120 return -EINVAL;
125 121
126 if (attr->inverted) 122 if (attr->inverted)
diff --git a/drivers/input/serio/hp_sdc.c b/drivers/input/serio/hp_sdc.c
index 0d395979b2d1..bfe49243f38b 100644
--- a/drivers/input/serio/hp_sdc.c
+++ b/drivers/input/serio/hp_sdc.c
@@ -323,7 +323,7 @@ static void hp_sdc_tasklet(unsigned long foo)
323 * it back to the application. and be less verbose. 323 * it back to the application. and be less verbose.
324 */ 324 */
325 printk(KERN_WARNING PREFIX "read timeout (%ius)!\n", 325 printk(KERN_WARNING PREFIX "read timeout (%ius)!\n",
326 tv.tv_usec - hp_sdc.rtv.tv_usec); 326 (int)(tv.tv_usec - hp_sdc.rtv.tv_usec));
327 curr->idx += hp_sdc.rqty; 327 curr->idx += hp_sdc.rqty;
328 hp_sdc.rqty = 0; 328 hp_sdc.rqty = 0;
329 tmp = curr->seq[curr->actidx]; 329 tmp = curr->seq[curr->actidx];
diff --git a/drivers/input/serio/i8042-io.h b/drivers/input/serio/i8042-io.h
index f451c7351a9d..847f4aad7ed5 100644
--- a/drivers/input/serio/i8042-io.h
+++ b/drivers/input/serio/i8042-io.h
@@ -67,7 +67,7 @@ static inline int i8042_platform_init(void)
67 * On some platforms touching the i8042 data register region can do really 67 * On some platforms touching the i8042 data register region can do really
68 * bad things. Because of this the region is always reserved on such boxes. 68 * bad things. Because of this the region is always reserved on such boxes.
69 */ 69 */
70#if defined(CONFIG_PPC_MERGE) 70#if defined(CONFIG_PPC)
71 if (check_legacy_ioport(I8042_DATA_REG)) 71 if (check_legacy_ioport(I8042_DATA_REG))
72 return -ENODEV; 72 return -ENODEV;
73#endif 73#endif
diff --git a/drivers/input/serio/i8042-x86ia64io.h b/drivers/input/serio/i8042-x86ia64io.h
index 5aafe24984c5..a321aea2c7b5 100644
--- a/drivers/input/serio/i8042-x86ia64io.h
+++ b/drivers/input/serio/i8042-x86ia64io.h
@@ -322,6 +322,13 @@ static struct dmi_system_id __initdata i8042_dmi_nomux_table[] = {
322 DMI_MATCH(DMI_PRODUCT_NAME, "N34AS6"), 322 DMI_MATCH(DMI_PRODUCT_NAME, "N34AS6"),
323 }, 323 },
324 }, 324 },
325 {
326 .ident = "IBM 2656",
327 .matches = {
328 DMI_MATCH(DMI_SYS_VENDOR, "IBM"),
329 DMI_MATCH(DMI_PRODUCT_NAME, "2656"),
330 },
331 },
325 { } 332 { }
326}; 333};
327 334
diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
index c9397c8ee97e..470770c09260 100644
--- a/drivers/input/serio/serio_raw.c
+++ b/drivers/input/serio/serio_raw.c
@@ -373,6 +373,12 @@ static struct serio_device_id serio_raw_serio_ids[] = {
373 .id = SERIO_ANY, 373 .id = SERIO_ANY,
374 .extra = SERIO_ANY, 374 .extra = SERIO_ANY,
375 }, 375 },
376 {
377 .type = SERIO_8042_XL,
378 .proto = SERIO_ANY,
379 .id = SERIO_ANY,
380 .extra = SERIO_ANY,
381 },
376 { 0 } 382 { 0 }
377}; 383};
378 384
diff --git a/drivers/input/tablet/aiptek.c b/drivers/input/tablet/aiptek.c
index 8f037a1d44a6..e53c838f1866 100644
--- a/drivers/input/tablet/aiptek.c
+++ b/drivers/input/tablet/aiptek.c
@@ -1202,16 +1202,22 @@ static ssize_t
1202store_tabletXtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1202store_tabletXtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1203{ 1203{
1204 struct aiptek *aiptek = dev_get_drvdata(dev); 1204 struct aiptek *aiptek = dev_get_drvdata(dev);
1205 int x; 1205 long x;
1206
1207 if (strict_strtol(buf, 10, &x)) {
1208 size_t len = buf[count - 1] == '\n' ? count - 1 : count;
1209
1210 if (strncmp(buf, "disable", len))
1211 return -EINVAL;
1206 1212
1207 if (strcmp(buf, "disable") == 0) {
1208 aiptek->newSetting.xTilt = AIPTEK_TILT_DISABLE; 1213 aiptek->newSetting.xTilt = AIPTEK_TILT_DISABLE;
1209 } else { 1214 } else {
1210 x = (int)simple_strtol(buf, NULL, 10); 1215 if (x < AIPTEK_TILT_MIN || x > AIPTEK_TILT_MAX)
1211 if (x >= AIPTEK_TILT_MIN && x <= AIPTEK_TILT_MAX) { 1216 return -EINVAL;
1212 aiptek->newSetting.xTilt = x; 1217
1213 } 1218 aiptek->newSetting.xTilt = x;
1214 } 1219 }
1220
1215 return count; 1221 return count;
1216} 1222}
1217 1223
@@ -1238,16 +1244,22 @@ static ssize_t
1238store_tabletYtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1244store_tabletYtilt(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1239{ 1245{
1240 struct aiptek *aiptek = dev_get_drvdata(dev); 1246 struct aiptek *aiptek = dev_get_drvdata(dev);
1241 int y; 1247 long y;
1248
1249 if (strict_strtol(buf, 10, &y)) {
1250 size_t len = buf[count - 1] == '\n' ? count - 1 : count;
1251
1252 if (strncmp(buf, "disable", len))
1253 return -EINVAL;
1242 1254
1243 if (strcmp(buf, "disable") == 0) {
1244 aiptek->newSetting.yTilt = AIPTEK_TILT_DISABLE; 1255 aiptek->newSetting.yTilt = AIPTEK_TILT_DISABLE;
1245 } else { 1256 } else {
1246 y = (int)simple_strtol(buf, NULL, 10); 1257 if (y < AIPTEK_TILT_MIN || y > AIPTEK_TILT_MAX)
1247 if (y >= AIPTEK_TILT_MIN && y <= AIPTEK_TILT_MAX) { 1258 return -EINVAL;
1248 aiptek->newSetting.yTilt = y; 1259
1249 } 1260 aiptek->newSetting.yTilt = y;
1250 } 1261 }
1262
1251 return count; 1263 return count;
1252} 1264}
1253 1265
@@ -1269,8 +1281,12 @@ static ssize_t
1269store_tabletJitterDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1281store_tabletJitterDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1270{ 1282{
1271 struct aiptek *aiptek = dev_get_drvdata(dev); 1283 struct aiptek *aiptek = dev_get_drvdata(dev);
1284 long j;
1285
1286 if (strict_strtol(buf, 10, &j))
1287 return -EINVAL;
1272 1288
1273 aiptek->newSetting.jitterDelay = (int)simple_strtol(buf, NULL, 10); 1289 aiptek->newSetting.jitterDelay = (int)j;
1274 return count; 1290 return count;
1275} 1291}
1276 1292
@@ -1294,8 +1310,12 @@ static ssize_t
1294store_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1310store_tabletProgrammableDelay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1295{ 1311{
1296 struct aiptek *aiptek = dev_get_drvdata(dev); 1312 struct aiptek *aiptek = dev_get_drvdata(dev);
1313 long d;
1297 1314
1298 aiptek->newSetting.programmableDelay = (int)simple_strtol(buf, NULL, 10); 1315 if (strict_strtol(buf, 10, &d))
1316 return -EINVAL;
1317
1318 aiptek->newSetting.programmableDelay = (int)d;
1299 return count; 1319 return count;
1300} 1320}
1301 1321
@@ -1541,8 +1561,11 @@ static ssize_t
1541store_tabletWheel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 1561store_tabletWheel(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
1542{ 1562{
1543 struct aiptek *aiptek = dev_get_drvdata(dev); 1563 struct aiptek *aiptek = dev_get_drvdata(dev);
1564 long w;
1565
1566 if (strict_strtol(buf, 10, &w)) return -EINVAL;
1544 1567
1545 aiptek->newSetting.wheel = (int)simple_strtol(buf, NULL, 10); 1568 aiptek->newSetting.wheel = (int)w;
1546 return count; 1569 return count;
1547} 1570}
1548 1571
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 8583c766d565..b9b7fc6ff1eb 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -69,6 +69,17 @@ struct ts_event {
69 int ignore; 69 int ignore;
70}; 70};
71 71
72/*
73 * We allocate this separately to avoid cache line sharing issues when
74 * driver is used with DMA-based SPI controllers (like atmel_spi) on
75 * systems where main memory is not DMA-coherent (most non-x86 boards).
76 */
77struct ads7846_packet {
78 u8 read_x, read_y, read_z1, read_z2, pwrdown;
79 u16 dummy; /* for the pwrdown read */
80 struct ts_event tc;
81};
82
72struct ads7846 { 83struct ads7846 {
73 struct input_dev *input; 84 struct input_dev *input;
74 char phys[32]; 85 char phys[32];
@@ -86,9 +97,7 @@ struct ads7846 {
86 u16 x_plate_ohms; 97 u16 x_plate_ohms;
87 u16 pressure_max; 98 u16 pressure_max;
88 99
89 u8 read_x, read_y, read_z1, read_z2, pwrdown; 100 struct ads7846_packet *packet;
90 u16 dummy; /* for the pwrdown read */
91 struct ts_event tc;
92 101
93 struct spi_transfer xfer[18]; 102 struct spi_transfer xfer[18];
94 struct spi_message msg[5]; 103 struct spi_message msg[5];
@@ -463,10 +472,11 @@ static ssize_t ads7846_disable_store(struct device *dev,
463 const char *buf, size_t count) 472 const char *buf, size_t count)
464{ 473{
465 struct ads7846 *ts = dev_get_drvdata(dev); 474 struct ads7846 *ts = dev_get_drvdata(dev);
466 char *endp; 475 long i;
467 int i; 476
477 if (strict_strtoul(buf, 10, &i))
478 return -EINVAL;
468 479
469 i = simple_strtoul(buf, &endp, 10);
470 spin_lock_irq(&ts->lock); 480 spin_lock_irq(&ts->lock);
471 481
472 if (i) 482 if (i)
@@ -512,16 +522,17 @@ static int get_pendown_state(struct ads7846 *ts)
512static void ads7846_rx(void *ads) 522static void ads7846_rx(void *ads)
513{ 523{
514 struct ads7846 *ts = ads; 524 struct ads7846 *ts = ads;
525 struct ads7846_packet *packet = ts->packet;
515 unsigned Rt; 526 unsigned Rt;
516 u16 x, y, z1, z2; 527 u16 x, y, z1, z2;
517 528
518 /* ads7846_rx_val() did in-place conversion (including byteswap) from 529 /* ads7846_rx_val() did in-place conversion (including byteswap) from
519 * on-the-wire format as part of debouncing to get stable readings. 530 * on-the-wire format as part of debouncing to get stable readings.
520 */ 531 */
521 x = ts->tc.x; 532 x = packet->tc.x;
522 y = ts->tc.y; 533 y = packet->tc.y;
523 z1 = ts->tc.z1; 534 z1 = packet->tc.z1;
524 z2 = ts->tc.z2; 535 z2 = packet->tc.z2;
525 536
526 /* range filtering */ 537 /* range filtering */
527 if (x == MAX_12BIT) 538 if (x == MAX_12BIT)
@@ -545,10 +556,10 @@ static void ads7846_rx(void *ads)
545 * the maximum. Don't report it to user space, repeat at least 556 * the maximum. Don't report it to user space, repeat at least
546 * once more the measurement 557 * once more the measurement
547 */ 558 */
548 if (ts->tc.ignore || Rt > ts->pressure_max) { 559 if (packet->tc.ignore || Rt > ts->pressure_max) {
549#ifdef VERBOSE 560#ifdef VERBOSE
550 pr_debug("%s: ignored %d pressure %d\n", 561 pr_debug("%s: ignored %d pressure %d\n",
551 ts->spi->dev.bus_id, ts->tc.ignore, Rt); 562 ts->spi->dev.bus_id, packet->tc.ignore, Rt);
552#endif 563#endif
553 hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_PERIOD), 564 hrtimer_start(&ts->timer, ktime_set(0, TS_POLL_PERIOD),
554 HRTIMER_MODE_REL); 565 HRTIMER_MODE_REL);
@@ -641,6 +652,7 @@ static int ads7846_no_filter(void *ads, int data_idx, int *val)
641static void ads7846_rx_val(void *ads) 652static void ads7846_rx_val(void *ads)
642{ 653{
643 struct ads7846 *ts = ads; 654 struct ads7846 *ts = ads;
655 struct ads7846_packet *packet = ts->packet;
644 struct spi_message *m; 656 struct spi_message *m;
645 struct spi_transfer *t; 657 struct spi_transfer *t;
646 int val; 658 int val;
@@ -660,7 +672,7 @@ static void ads7846_rx_val(void *ads)
660 case ADS7846_FILTER_REPEAT: 672 case ADS7846_FILTER_REPEAT:
661 break; 673 break;
662 case ADS7846_FILTER_IGNORE: 674 case ADS7846_FILTER_IGNORE:
663 ts->tc.ignore = 1; 675 packet->tc.ignore = 1;
664 /* Last message will contain ads7846_rx() as the 676 /* Last message will contain ads7846_rx() as the
665 * completion function. 677 * completion function.
666 */ 678 */
@@ -668,7 +680,7 @@ static void ads7846_rx_val(void *ads)
668 break; 680 break;
669 case ADS7846_FILTER_OK: 681 case ADS7846_FILTER_OK:
670 *(u16 *)t->rx_buf = val; 682 *(u16 *)t->rx_buf = val;
671 ts->tc.ignore = 0; 683 packet->tc.ignore = 0;
672 m = &ts->msg[++ts->msg_idx]; 684 m = &ts->msg[++ts->msg_idx];
673 break; 685 break;
674 default: 686 default:
@@ -773,7 +785,6 @@ static void ads7846_disable(struct ads7846 *ts)
773 /* we know the chip's in lowpower mode since we always 785 /* we know the chip's in lowpower mode since we always
774 * leave it that way after every request 786 * leave it that way after every request
775 */ 787 */
776
777} 788}
778 789
779/* Must be called with ts->lock held */ 790/* Must be called with ts->lock held */
@@ -849,6 +860,7 @@ static int __devinit setup_pendown(struct spi_device *spi, struct ads7846 *ts)
849static int __devinit ads7846_probe(struct spi_device *spi) 860static int __devinit ads7846_probe(struct spi_device *spi)
850{ 861{
851 struct ads7846 *ts; 862 struct ads7846 *ts;
863 struct ads7846_packet *packet;
852 struct input_dev *input_dev; 864 struct input_dev *input_dev;
853 struct ads7846_platform_data *pdata = spi->dev.platform_data; 865 struct ads7846_platform_data *pdata = spi->dev.platform_data;
854 struct spi_message *m; 866 struct spi_message *m;
@@ -884,14 +896,16 @@ static int __devinit ads7846_probe(struct spi_device *spi)
884 return err; 896 return err;
885 897
886 ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL); 898 ts = kzalloc(sizeof(struct ads7846), GFP_KERNEL);
899 packet = kzalloc(sizeof(struct ads7846_packet), GFP_KERNEL);
887 input_dev = input_allocate_device(); 900 input_dev = input_allocate_device();
888 if (!ts || !input_dev) { 901 if (!ts || !packet || !input_dev) {
889 err = -ENOMEM; 902 err = -ENOMEM;
890 goto err_free_mem; 903 goto err_free_mem;
891 } 904 }
892 905
893 dev_set_drvdata(&spi->dev, ts); 906 dev_set_drvdata(&spi->dev, ts);
894 907
908 ts->packet = packet;
895 ts->spi = spi; 909 ts->spi = spi;
896 ts->input = input_dev; 910 ts->input = input_dev;
897 ts->vref_mv = pdata->vref_mv; 911 ts->vref_mv = pdata->vref_mv;
@@ -963,13 +977,13 @@ static int __devinit ads7846_probe(struct spi_device *spi)
963 spi_message_init(m); 977 spi_message_init(m);
964 978
965 /* y- still on; turn on only y+ (and ADC) */ 979 /* y- still on; turn on only y+ (and ADC) */
966 ts->read_y = READ_Y(vref); 980 packet->read_y = READ_Y(vref);
967 x->tx_buf = &ts->read_y; 981 x->tx_buf = &packet->read_y;
968 x->len = 1; 982 x->len = 1;
969 spi_message_add_tail(x, m); 983 spi_message_add_tail(x, m);
970 984
971 x++; 985 x++;
972 x->rx_buf = &ts->tc.y; 986 x->rx_buf = &packet->tc.y;
973 x->len = 2; 987 x->len = 2;
974 spi_message_add_tail(x, m); 988 spi_message_add_tail(x, m);
975 989
@@ -981,12 +995,12 @@ static int __devinit ads7846_probe(struct spi_device *spi)
981 x->delay_usecs = pdata->settle_delay_usecs; 995 x->delay_usecs = pdata->settle_delay_usecs;
982 996
983 x++; 997 x++;
984 x->tx_buf = &ts->read_y; 998 x->tx_buf = &packet->read_y;
985 x->len = 1; 999 x->len = 1;
986 spi_message_add_tail(x, m); 1000 spi_message_add_tail(x, m);
987 1001
988 x++; 1002 x++;
989 x->rx_buf = &ts->tc.y; 1003 x->rx_buf = &packet->tc.y;
990 x->len = 2; 1004 x->len = 2;
991 spi_message_add_tail(x, m); 1005 spi_message_add_tail(x, m);
992 } 1006 }
@@ -999,13 +1013,13 @@ static int __devinit ads7846_probe(struct spi_device *spi)
999 1013
1000 /* turn y- off, x+ on, then leave in lowpower */ 1014 /* turn y- off, x+ on, then leave in lowpower */
1001 x++; 1015 x++;
1002 ts->read_x = READ_X(vref); 1016 packet->read_x = READ_X(vref);
1003 x->tx_buf = &ts->read_x; 1017 x->tx_buf = &packet->read_x;
1004 x->len = 1; 1018 x->len = 1;
1005 spi_message_add_tail(x, m); 1019 spi_message_add_tail(x, m);
1006 1020
1007 x++; 1021 x++;
1008 x->rx_buf = &ts->tc.x; 1022 x->rx_buf = &packet->tc.x;
1009 x->len = 2; 1023 x->len = 2;
1010 spi_message_add_tail(x, m); 1024 spi_message_add_tail(x, m);
1011 1025
@@ -1014,12 +1028,12 @@ static int __devinit ads7846_probe(struct spi_device *spi)
1014 x->delay_usecs = pdata->settle_delay_usecs; 1028 x->delay_usecs = pdata->settle_delay_usecs;
1015 1029
1016 x++; 1030 x++;
1017 x->tx_buf = &ts->read_x; 1031 x->tx_buf = &packet->read_x;
1018 x->len = 1; 1032 x->len = 1;
1019 spi_message_add_tail(x, m); 1033 spi_message_add_tail(x, m);
1020 1034
1021 x++; 1035 x++;
1022 x->rx_buf = &ts->tc.x; 1036 x->rx_buf = &packet->tc.x;
1023 x->len = 2; 1037 x->len = 2;
1024 spi_message_add_tail(x, m); 1038 spi_message_add_tail(x, m);
1025 } 1039 }
@@ -1033,13 +1047,13 @@ static int __devinit ads7846_probe(struct spi_device *spi)
1033 spi_message_init(m); 1047 spi_message_init(m);
1034 1048
1035 x++; 1049 x++;
1036 ts->read_z1 = READ_Z1(vref); 1050 packet->read_z1 = READ_Z1(vref);
1037 x->tx_buf = &ts->read_z1; 1051 x->tx_buf = &packet->read_z1;
1038 x->len = 1; 1052 x->len = 1;
1039 spi_message_add_tail(x, m); 1053 spi_message_add_tail(x, m);
1040 1054
1041 x++; 1055 x++;
1042 x->rx_buf = &ts->tc.z1; 1056 x->rx_buf = &packet->tc.z1;
1043 x->len = 2; 1057 x->len = 2;
1044 spi_message_add_tail(x, m); 1058 spi_message_add_tail(x, m);
1045 1059
@@ -1048,12 +1062,12 @@ static int __devinit ads7846_probe(struct spi_device *spi)
1048 x->delay_usecs = pdata->settle_delay_usecs; 1062 x->delay_usecs = pdata->settle_delay_usecs;
1049 1063
1050 x++; 1064 x++;
1051 x->tx_buf = &ts->read_z1; 1065 x->tx_buf = &packet->read_z1;
1052 x->len = 1; 1066 x->len = 1;
1053 spi_message_add_tail(x, m); 1067 spi_message_add_tail(x, m);
1054 1068
1055 x++; 1069 x++;
1056 x->rx_buf = &ts->tc.z1; 1070 x->rx_buf = &packet->tc.z1;
1057 x->len = 2; 1071 x->len = 2;
1058 spi_message_add_tail(x, m); 1072 spi_message_add_tail(x, m);
1059 } 1073 }
@@ -1065,13 +1079,13 @@ static int __devinit ads7846_probe(struct spi_device *spi)
1065 spi_message_init(m); 1079 spi_message_init(m);
1066 1080
1067 x++; 1081 x++;
1068 ts->read_z2 = READ_Z2(vref); 1082 packet->read_z2 = READ_Z2(vref);
1069 x->tx_buf = &ts->read_z2; 1083 x->tx_buf = &packet->read_z2;
1070 x->len = 1; 1084 x->len = 1;
1071 spi_message_add_tail(x, m); 1085 spi_message_add_tail(x, m);
1072 1086
1073 x++; 1087 x++;
1074 x->rx_buf = &ts->tc.z2; 1088 x->rx_buf = &packet->tc.z2;
1075 x->len = 2; 1089 x->len = 2;
1076 spi_message_add_tail(x, m); 1090 spi_message_add_tail(x, m);
1077 1091
@@ -1080,12 +1094,12 @@ static int __devinit ads7846_probe(struct spi_device *spi)
1080 x->delay_usecs = pdata->settle_delay_usecs; 1094 x->delay_usecs = pdata->settle_delay_usecs;
1081 1095
1082 x++; 1096 x++;
1083 x->tx_buf = &ts->read_z2; 1097 x->tx_buf = &packet->read_z2;
1084 x->len = 1; 1098 x->len = 1;
1085 spi_message_add_tail(x, m); 1099 spi_message_add_tail(x, m);
1086 1100
1087 x++; 1101 x++;
1088 x->rx_buf = &ts->tc.z2; 1102 x->rx_buf = &packet->tc.z2;
1089 x->len = 2; 1103 x->len = 2;
1090 spi_message_add_tail(x, m); 1104 spi_message_add_tail(x, m);
1091 } 1105 }
@@ -1099,13 +1113,13 @@ static int __devinit ads7846_probe(struct spi_device *spi)
1099 spi_message_init(m); 1113 spi_message_init(m);
1100 1114
1101 x++; 1115 x++;
1102 ts->pwrdown = PWRDOWN; 1116 packet->pwrdown = PWRDOWN;
1103 x->tx_buf = &ts->pwrdown; 1117 x->tx_buf = &packet->pwrdown;
1104 x->len = 1; 1118 x->len = 1;
1105 spi_message_add_tail(x, m); 1119 spi_message_add_tail(x, m);
1106 1120
1107 x++; 1121 x++;
1108 x->rx_buf = &ts->dummy; 1122 x->rx_buf = &packet->dummy;
1109 x->len = 2; 1123 x->len = 2;
1110 CS_CHANGE(*x); 1124 CS_CHANGE(*x);
1111 spi_message_add_tail(x, m); 1125 spi_message_add_tail(x, m);
@@ -1158,6 +1172,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
1158 ts->filter_cleanup(ts->filter_data); 1172 ts->filter_cleanup(ts->filter_data);
1159 err_free_mem: 1173 err_free_mem:
1160 input_free_device(input_dev); 1174 input_free_device(input_dev);
1175 kfree(packet);
1161 kfree(ts); 1176 kfree(ts);
1162 return err; 1177 return err;
1163} 1178}
@@ -1183,6 +1198,7 @@ static int __devexit ads7846_remove(struct spi_device *spi)
1183 if (ts->filter_cleanup) 1198 if (ts->filter_cleanup)
1184 ts->filter_cleanup(ts->filter_data); 1199 ts->filter_cleanup(ts->filter_data);
1185 1200
1201 kfree(ts->packet);
1186 kfree(ts); 1202 kfree(ts);
1187 1203
1188 dev_dbg(&spi->dev, "unregistered touchscreen\n"); 1204 dev_dbg(&spi->dev, "unregistered touchscreen\n");
diff --git a/drivers/input/touchscreen/atmel_tsadcc.c b/drivers/input/touchscreen/atmel_tsadcc.c
index eee126b19e8b..a89a6a8f05e6 100644
--- a/drivers/input/touchscreen/atmel_tsadcc.c
+++ b/drivers/input/touchscreen/atmel_tsadcc.c
@@ -91,6 +91,9 @@ struct atmel_tsadcc {
91 char phys[32]; 91 char phys[32];
92 struct clk *clk; 92 struct clk *clk;
93 int irq; 93 int irq;
94 unsigned int prev_absx;
95 unsigned int prev_absy;
96 unsigned char bufferedmeasure;
94}; 97};
95 98
96static void __iomem *tsc_base; 99static void __iomem *tsc_base;
@@ -100,10 +103,9 @@ static void __iomem *tsc_base;
100 103
101static irqreturn_t atmel_tsadcc_interrupt(int irq, void *dev) 104static irqreturn_t atmel_tsadcc_interrupt(int irq, void *dev)
102{ 105{
103 struct input_dev *input_dev = ((struct atmel_tsadcc *)dev)->input; 106 struct atmel_tsadcc *ts_dev = (struct atmel_tsadcc *)dev;
107 struct input_dev *input_dev = ts_dev->input;
104 108
105 unsigned int absx;
106 unsigned int absy;
107 unsigned int status; 109 unsigned int status;
108 unsigned int reg; 110 unsigned int reg;
109 111
@@ -121,6 +123,7 @@ static irqreturn_t atmel_tsadcc_interrupt(int irq, void *dev)
121 atmel_tsadcc_write(ATMEL_TSADCC_IER, ATMEL_TSADCC_PENCNT); 123 atmel_tsadcc_write(ATMEL_TSADCC_IER, ATMEL_TSADCC_PENCNT);
122 124
123 input_report_key(input_dev, BTN_TOUCH, 0); 125 input_report_key(input_dev, BTN_TOUCH, 0);
126 ts_dev->bufferedmeasure = 0;
124 input_sync(input_dev); 127 input_sync(input_dev);
125 128
126 } else if (status & ATMEL_TSADCC_PENCNT) { 129 } else if (status & ATMEL_TSADCC_PENCNT) {
@@ -138,16 +141,23 @@ static irqreturn_t atmel_tsadcc_interrupt(int irq, void *dev)
138 } else if (status & ATMEL_TSADCC_EOC(3)) { 141 } else if (status & ATMEL_TSADCC_EOC(3)) {
139 /* Conversion finished */ 142 /* Conversion finished */
140 143
141 absx = atmel_tsadcc_read(ATMEL_TSADCC_CDR3) << 10; 144 if (ts_dev->bufferedmeasure) {
142 absx /= atmel_tsadcc_read(ATMEL_TSADCC_CDR2); 145 /* Last measurement is always discarded, since it can
143 146 * be erroneous.
144 absy = atmel_tsadcc_read(ATMEL_TSADCC_CDR1) << 10; 147 * Always report previous measurement */
145 absy /= atmel_tsadcc_read(ATMEL_TSADCC_CDR0); 148 input_report_abs(input_dev, ABS_X, ts_dev->prev_absx);
146 149 input_report_abs(input_dev, ABS_Y, ts_dev->prev_absy);
147 input_report_abs(input_dev, ABS_X, absx); 150 input_report_key(input_dev, BTN_TOUCH, 1);
148 input_report_abs(input_dev, ABS_Y, absy); 151 input_sync(input_dev);
149 input_report_key(input_dev, BTN_TOUCH, 1); 152 } else
150 input_sync(input_dev); 153 ts_dev->bufferedmeasure = 1;
154
155 /* Now make new measurement */
156 ts_dev->prev_absx = atmel_tsadcc_read(ATMEL_TSADCC_CDR3) << 10;
157 ts_dev->prev_absx /= atmel_tsadcc_read(ATMEL_TSADCC_CDR2);
158
159 ts_dev->prev_absy = atmel_tsadcc_read(ATMEL_TSADCC_CDR1) << 10;
160 ts_dev->prev_absy /= atmel_tsadcc_read(ATMEL_TSADCC_CDR0);
151 } 161 }
152 162
153 return IRQ_HANDLED; 163 return IRQ_HANDLED;
@@ -223,6 +233,7 @@ static int __devinit atmel_tsadcc_probe(struct platform_device *pdev)
223 } 233 }
224 234
225 ts_dev->input = input_dev; 235 ts_dev->input = input_dev;
236 ts_dev->bufferedmeasure = 0;
226 237
227 snprintf(ts_dev->phys, sizeof(ts_dev->phys), 238 snprintf(ts_dev->phys, sizeof(ts_dev->phys),
228 "%s/input0", pdev->dev.bus_id); 239 "%s/input0", pdev->dev.bus_id);
diff --git a/drivers/input/touchscreen/mainstone-wm97xx.c b/drivers/input/touchscreen/mainstone-wm97xx.c
index 37a555f37306..ba648750a8d9 100644
--- a/drivers/input/touchscreen/mainstone-wm97xx.c
+++ b/drivers/input/touchscreen/mainstone-wm97xx.c
@@ -3,8 +3,7 @@
3 * Wolfson WM97xx AC97 Codecs. 3 * Wolfson WM97xx AC97 Codecs.
4 * 4 *
5 * Copyright 2004, 2007 Wolfson Microelectronics PLC. 5 * Copyright 2004, 2007 Wolfson Microelectronics PLC.
6 * Author: Liam Girdwood 6 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
7 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
8 * Parts Copyright : Ian Molton <spyro@f2s.com> 7 * Parts Copyright : Ian Molton <spyro@f2s.com>
9 * Andrew Zabolotny <zap@homelink.ru> 8 * Andrew Zabolotny <zap@homelink.ru>
10 * 9 *
@@ -296,6 +295,6 @@ module_init(mainstone_wm97xx_init);
296module_exit(mainstone_wm97xx_exit); 295module_exit(mainstone_wm97xx_exit);
297 296
298/* Module information */ 297/* Module information */
299MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>"); 298MODULE_AUTHOR("Liam Girdwood <lrg@slimlogic.co.uk>");
300MODULE_DESCRIPTION("wm97xx continuous touch driver for mainstone"); 299MODULE_DESCRIPTION("wm97xx continuous touch driver for mainstone");
301MODULE_LICENSE("GPL"); 300MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/wm9705.c b/drivers/input/touchscreen/wm9705.c
index 372efbc694ff..6b5be742c27d 100644
--- a/drivers/input/touchscreen/wm9705.c
+++ b/drivers/input/touchscreen/wm9705.c
@@ -2,8 +2,7 @@
2 * wm9705.c -- Codec driver for Wolfson WM9705 AC97 Codec. 2 * wm9705.c -- Codec driver for Wolfson WM9705 AC97 Codec.
3 * 3 *
4 * Copyright 2003, 2004, 2005, 2006, 2007 Wolfson Microelectronics PLC. 4 * Copyright 2003, 2004, 2005, 2006, 2007 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood 5 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
6 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
7 * Parts Copyright : Ian Molton <spyro@f2s.com> 6 * Parts Copyright : Ian Molton <spyro@f2s.com>
8 * Andrew Zabolotny <zap@homelink.ru> 7 * Andrew Zabolotny <zap@homelink.ru>
9 * Russell King <rmk@arm.linux.org.uk> 8 * Russell King <rmk@arm.linux.org.uk>
@@ -347,6 +346,6 @@ struct wm97xx_codec_drv wm9705_codec = {
347EXPORT_SYMBOL_GPL(wm9705_codec); 346EXPORT_SYMBOL_GPL(wm9705_codec);
348 347
349/* Module information */ 348/* Module information */
350MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>"); 349MODULE_AUTHOR("Liam Girdwood <lrg@slimlogic.co.uk>");
351MODULE_DESCRIPTION("WM9705 Touch Screen Driver"); 350MODULE_DESCRIPTION("WM9705 Touch Screen Driver");
352MODULE_LICENSE("GPL"); 351MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/wm9712.c b/drivers/input/touchscreen/wm9712.c
index c8bb1e7335fc..7490b05c3566 100644
--- a/drivers/input/touchscreen/wm9712.c
+++ b/drivers/input/touchscreen/wm9712.c
@@ -2,8 +2,7 @@
2 * wm9712.c -- Codec driver for Wolfson WM9712 AC97 Codecs. 2 * wm9712.c -- Codec driver for Wolfson WM9712 AC97 Codecs.
3 * 3 *
4 * Copyright 2003, 2004, 2005, 2006, 2007 Wolfson Microelectronics PLC. 4 * Copyright 2003, 2004, 2005, 2006, 2007 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood 5 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
6 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
7 * Parts Copyright : Ian Molton <spyro@f2s.com> 6 * Parts Copyright : Ian Molton <spyro@f2s.com>
8 * Andrew Zabolotny <zap@homelink.ru> 7 * Andrew Zabolotny <zap@homelink.ru>
9 * Russell King <rmk@arm.linux.org.uk> 8 * Russell King <rmk@arm.linux.org.uk>
@@ -462,6 +461,6 @@ struct wm97xx_codec_drv wm9712_codec = {
462EXPORT_SYMBOL_GPL(wm9712_codec); 461EXPORT_SYMBOL_GPL(wm9712_codec);
463 462
464/* Module information */ 463/* Module information */
465MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>"); 464MODULE_AUTHOR("Liam Girdwood <lrg@slimlogic.co.uk>");
466MODULE_DESCRIPTION("WM9712 Touch Screen Driver"); 465MODULE_DESCRIPTION("WM9712 Touch Screen Driver");
467MODULE_LICENSE("GPL"); 466MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/wm9713.c b/drivers/input/touchscreen/wm9713.c
index 781ee83547e6..238b5132712e 100644
--- a/drivers/input/touchscreen/wm9713.c
+++ b/drivers/input/touchscreen/wm9713.c
@@ -2,8 +2,7 @@
2 * wm9713.c -- Codec touch driver for Wolfson WM9713 AC97 Codec. 2 * wm9713.c -- Codec touch driver for Wolfson WM9713 AC97 Codec.
3 * 3 *
4 * Copyright 2003, 2004, 2005, 2006, 2007, 2008 Wolfson Microelectronics PLC. 4 * Copyright 2003, 2004, 2005, 2006, 2007, 2008 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood 5 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
6 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
7 * Parts Copyright : Ian Molton <spyro@f2s.com> 6 * Parts Copyright : Ian Molton <spyro@f2s.com>
8 * Andrew Zabolotny <zap@homelink.ru> 7 * Andrew Zabolotny <zap@homelink.ru>
9 * Russell King <rmk@arm.linux.org.uk> 8 * Russell King <rmk@arm.linux.org.uk>
@@ -476,6 +475,6 @@ struct wm97xx_codec_drv wm9713_codec = {
476EXPORT_SYMBOL_GPL(wm9713_codec); 475EXPORT_SYMBOL_GPL(wm9713_codec);
477 476
478/* Module information */ 477/* Module information */
479MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>"); 478MODULE_AUTHOR("Liam Girdwood <lrg@slimlogic.co.uk>");
480MODULE_DESCRIPTION("WM9713 Touch Screen Driver"); 479MODULE_DESCRIPTION("WM9713 Touch Screen Driver");
481MODULE_LICENSE("GPL"); 480MODULE_LICENSE("GPL");
diff --git a/drivers/input/touchscreen/wm97xx-core.c b/drivers/input/touchscreen/wm97xx-core.c
index d589ab0e3adc..d15aa11d7056 100644
--- a/drivers/input/touchscreen/wm97xx-core.c
+++ b/drivers/input/touchscreen/wm97xx-core.c
@@ -3,8 +3,7 @@
3 * and WM9713 AC97 Codecs. 3 * and WM9713 AC97 Codecs.
4 * 4 *
5 * Copyright 2003, 2004, 2005, 2006, 2007, 2008 Wolfson Microelectronics PLC. 5 * Copyright 2003, 2004, 2005, 2006, 2007, 2008 Wolfson Microelectronics PLC.
6 * Author: Liam Girdwood 6 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
7 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
8 * Parts Copyright : Ian Molton <spyro@f2s.com> 7 * Parts Copyright : Ian Molton <spyro@f2s.com>
9 * Andrew Zabolotny <zap@homelink.ru> 8 * Andrew Zabolotny <zap@homelink.ru>
10 * Russell King <rmk@arm.linux.org.uk> 9 * Russell King <rmk@arm.linux.org.uk>
@@ -824,6 +823,6 @@ module_init(wm97xx_init);
824module_exit(wm97xx_exit); 823module_exit(wm97xx_exit);
825 824
826/* Module information */ 825/* Module information */
827MODULE_AUTHOR("Liam Girdwood <liam.girdwood@wolfsonmicro.com>"); 826MODULE_AUTHOR("Liam Girdwood <lrg@slimlogic.co.uk>");
828MODULE_DESCRIPTION("WM97xx Core - Touch Screen / AUX ADC / GPIO Driver"); 827MODULE_DESCRIPTION("WM97xx Core - Touch Screen / AUX ADC / GPIO Driver");
829MODULE_LICENSE("GPL"); 828MODULE_LICENSE("GPL");
diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
index 871b0cbca5e4..1b5bf87c4cf4 100644
--- a/drivers/isdn/capi/capi.c
+++ b/drivers/isdn/capi/capi.c
@@ -1231,7 +1231,7 @@ static int capinc_tty_ioctl(struct tty_struct *tty, struct file * file,
1231 int error = 0; 1231 int error = 0;
1232 switch (cmd) { 1232 switch (cmd) {
1233 default: 1233 default:
1234 error = n_tty_ioctl (tty, file, cmd, arg); 1234 error = n_tty_ioctl_helper(tty, file, cmd, arg);
1235 break; 1235 break;
1236 } 1236 }
1237 return error; 1237 return error;
@@ -1553,8 +1553,7 @@ static int __init capi_init(void)
1553 return PTR_ERR(capi_class); 1553 return PTR_ERR(capi_class);
1554 } 1554 }
1555 1555
1556 device_create_drvdata(capi_class, NULL, MKDEV(capi_major, 0), NULL, 1556 device_create(capi_class, NULL, MKDEV(capi_major, 0), NULL, "capi");
1557 "capi");
1558 1557
1559#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE 1558#ifdef CONFIG_ISDN_CAPI_MIDDLEWARE
1560 if (capinc_tty_init() < 0) { 1559 if (capinc_tty_init() < 0) {
diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
index 5e89fa177816..07052ed2a0c5 100644
--- a/drivers/isdn/gigaset/ser-gigaset.c
+++ b/drivers/isdn/gigaset/ser-gigaset.c
@@ -571,6 +571,7 @@ gigaset_tty_close(struct tty_struct *tty)
571 } 571 }
572 572
573 /* prevent other callers from entering ldisc methods */ 573 /* prevent other callers from entering ldisc methods */
574 /* FIXME: should use the tty state flags */
574 tty->disc_data = NULL; 575 tty->disc_data = NULL;
575 576
576 if (!cs->hw.ser) 577 if (!cs->hw.ser)
@@ -642,10 +643,11 @@ gigaset_tty_ioctl(struct tty_struct *tty, struct file *file,
642 return -ENXIO; 643 return -ENXIO;
643 644
644 switch (cmd) { 645 switch (cmd) {
645 case TCGETS: 646
646 case TCGETA: 647 case FIONREAD:
647 /* pass through to underlying serial device */ 648 /* unused, always return zero */
648 rc = n_tty_ioctl(tty, file, cmd, arg); 649 val = 0;
650 rc = put_user(val, p);
649 break; 651 break;
650 652
651 case TCFLSH: 653 case TCFLSH:
@@ -659,20 +661,13 @@ gigaset_tty_ioctl(struct tty_struct *tty, struct file *file,
659 flush_send_queue(cs); 661 flush_send_queue(cs);
660 break; 662 break;
661 } 663 }
662 /* flush the serial port's buffer */ 664 /* Pass through */
663 rc = n_tty_ioctl(tty, file, cmd, arg);
664 break;
665
666 case FIONREAD:
667 /* unused, always return zero */
668 val = 0;
669 rc = put_user(val, p);
670 break;
671 665
672 default: 666 default:
673 rc = -ENOIOCTLCMD; 667 /* pass through to underlying serial device */
668 rc = n_tty_ioctl_helper(tty, file, cmd, arg);
669 break;
674 } 670 }
675
676 cs_put(cs); 671 cs_put(cs);
677 return rc; 672 return rc;
678} 673}
@@ -680,6 +675,8 @@ gigaset_tty_ioctl(struct tty_struct *tty, struct file *file,
680/* 675/*
681 * Poll on the tty. 676 * Poll on the tty.
682 * Unused, always return zero. 677 * Unused, always return zero.
678 *
679 * FIXME: should probably return an exception - especially on hangup
683 */ 680 */
684static unsigned int 681static unsigned int
685gigaset_tty_poll(struct tty_struct *tty, struct file *file, poll_table *wait) 682gigaset_tty_poll(struct tty_struct *tty, struct file *file, poll_table *wait)
diff --git a/drivers/isdn/hardware/avm/avm_cs.c b/drivers/isdn/hardware/avm/avm_cs.c
index a5b941c327f7..c72565520e41 100644
--- a/drivers/isdn/hardware/avm/avm_cs.c
+++ b/drivers/isdn/hardware/avm/avm_cs.c
@@ -154,83 +154,50 @@ static void avmcs_detach(struct pcmcia_device *link)
154 154
155======================================================================*/ 155======================================================================*/
156 156
157static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, 157static int avmcs_configcheck(struct pcmcia_device *p_dev,
158 cisparse_t *parse) 158 cistpl_cftable_entry_t *cf,
159 cistpl_cftable_entry_t *dflt,
160 unsigned int vcc,
161 void *priv_data)
159{ 162{
160 int i = pcmcia_get_tuple_data(handle, tuple); 163 if (cf->io.nwin <= 0)
161 if (i != CS_SUCCESS) return i; 164 return -ENODEV;
162 return pcmcia_parse_tuple(handle, tuple, parse); 165
163} 166 p_dev->io.BasePort1 = cf->io.win[0].base;
164 167 p_dev->io.NumPorts1 = cf->io.win[0].len;
165static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, 168 p_dev->io.NumPorts2 = 0;
166 cisparse_t *parse) 169 printk(KERN_INFO "avm_cs: testing i/o %#x-%#x\n",
167{ 170 p_dev->io.BasePort1,
168 int i = pcmcia_get_first_tuple(handle, tuple); 171 p_dev->io.BasePort1+p_dev->io.NumPorts1-1);
169 if (i != CS_SUCCESS) return i; 172 return pcmcia_request_io(p_dev, &p_dev->io);
170 return get_tuple(handle, tuple, parse);
171}
172
173static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
174 cisparse_t *parse)
175{
176 int i = pcmcia_get_next_tuple(handle, tuple);
177 if (i != CS_SUCCESS) return i;
178 return get_tuple(handle, tuple, parse);
179} 173}
180 174
181static int avmcs_config(struct pcmcia_device *link) 175static int avmcs_config(struct pcmcia_device *link)
182{ 176{
183 tuple_t tuple;
184 cisparse_t parse;
185 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
186 local_info_t *dev; 177 local_info_t *dev;
187 int i; 178 int i;
188 u_char buf[64];
189 char devname[128]; 179 char devname[128];
190 int cardtype; 180 int cardtype;
191 int (*addcard)(unsigned int port, unsigned irq); 181 int (*addcard)(unsigned int port, unsigned irq);
192 182
193 dev = link->priv; 183 dev = link->priv;
194 184
195 do { 185 devname[0] = 0;
196 devname[0] = 0; 186 if (link->prod_id[1])
197 if (link->prod_id[1]) 187 strlcpy(devname, link->prod_id[1], sizeof(devname));
198 strlcpy(devname, link->prod_id[1], sizeof(devname));
199 188
200 /* 189 /*
201 * find IO port 190 * find IO port
202 */ 191 */
203 tuple.TupleData = (cisdata_t *)buf; 192 if (pcmcia_loop_config(link, avmcs_configcheck, NULL))
204 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 193 return -ENODEV;
205 tuple.Attributes = 0;
206 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
207 i = first_tuple(link, &tuple, &parse);
208 while (i == CS_SUCCESS) {
209 if (cf->io.nwin > 0) {
210 link->conf.ConfigIndex = cf->index;
211 link->io.BasePort1 = cf->io.win[0].base;
212 link->io.NumPorts1 = cf->io.win[0].len;
213 link->io.NumPorts2 = 0;
214 printk(KERN_INFO "avm_cs: testing i/o %#x-%#x\n",
215 link->io.BasePort1,
216 link->io.BasePort1+link->io.NumPorts1-1);
217 i = pcmcia_request_io(link, &link->io);
218 if (i == CS_SUCCESS) goto found_port;
219 }
220 i = next_tuple(link, &tuple, &parse);
221 }
222
223found_port:
224 if (i != CS_SUCCESS) {
225 cs_error(link, RequestIO, i);
226 break;
227 }
228 194
195 do {
229 /* 196 /*
230 * allocate an interrupt line 197 * allocate an interrupt line
231 */ 198 */
232 i = pcmcia_request_irq(link, &link->irq); 199 i = pcmcia_request_irq(link, &link->irq);
233 if (i != CS_SUCCESS) { 200 if (i != 0) {
234 cs_error(link, RequestIRQ, i); 201 cs_error(link, RequestIRQ, i);
235 /* undo */ 202 /* undo */
236 pcmcia_disable_device(link); 203 pcmcia_disable_device(link);
@@ -241,7 +208,7 @@ found_port:
241 * configure the PCMCIA socket 208 * configure the PCMCIA socket
242 */ 209 */
243 i = pcmcia_request_configuration(link, &link->conf); 210 i = pcmcia_request_configuration(link, &link->conf);
244 if (i != CS_SUCCESS) { 211 if (i != 0) {
245 cs_error(link, RequestConfiguration, i); 212 cs_error(link, RequestConfiguration, i);
246 pcmcia_disable_device(link); 213 pcmcia_disable_device(link);
247 break; 214 break;
diff --git a/drivers/isdn/hisax/avma1_cs.c b/drivers/isdn/hisax/avma1_cs.c
index fc6cc2c065b8..23560c897ec3 100644
--- a/drivers/isdn/hisax/avma1_cs.c
+++ b/drivers/isdn/hisax/avma1_cs.c
@@ -174,38 +174,29 @@ static void avma1cs_detach(struct pcmcia_device *link)
174 174
175======================================================================*/ 175======================================================================*/
176 176
177static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, 177static int avma1cs_configcheck(struct pcmcia_device *p_dev,
178 cisparse_t *parse) 178 cistpl_cftable_entry_t *cf,
179 cistpl_cftable_entry_t *dflt,
180 unsigned int vcc,
181 void *priv_data)
179{ 182{
180 int i = pcmcia_get_tuple_data(handle, tuple); 183 if (cf->io.nwin <= 0)
181 if (i != CS_SUCCESS) return i; 184 return -ENODEV;
182 return pcmcia_parse_tuple(handle, tuple, parse); 185
186 p_dev->io.BasePort1 = cf->io.win[0].base;
187 p_dev->io.NumPorts1 = cf->io.win[0].len;
188 p_dev->io.NumPorts2 = 0;
189 printk(KERN_INFO "avma1_cs: testing i/o %#x-%#x\n",
190 p_dev->io.BasePort1,
191 p_dev->io.BasePort1+p_dev->io.NumPorts1-1);
192 return pcmcia_request_io(p_dev, &p_dev->io);
183} 193}
184 194
185static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
186 cisparse_t *parse)
187{
188 int i = pcmcia_get_first_tuple(handle, tuple);
189 if (i != CS_SUCCESS) return i;
190 return get_tuple(handle, tuple, parse);
191}
192
193static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
194 cisparse_t *parse)
195{
196 int i = pcmcia_get_next_tuple(handle, tuple);
197 if (i != CS_SUCCESS) return i;
198 return get_tuple(handle, tuple, parse);
199}
200 195
201static int avma1cs_config(struct pcmcia_device *link) 196static int avma1cs_config(struct pcmcia_device *link)
202{ 197{
203 tuple_t tuple;
204 cisparse_t parse;
205 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
206 local_info_t *dev; 198 local_info_t *dev;
207 int i; 199 int i;
208 u_char buf[64];
209 char devname[128]; 200 char devname[128];
210 IsdnCard_t icard; 201 IsdnCard_t icard;
211 int busy = 0; 202 int busy = 0;
@@ -214,45 +205,19 @@ static int avma1cs_config(struct pcmcia_device *link)
214 205
215 DEBUG(0, "avma1cs_config(0x%p)\n", link); 206 DEBUG(0, "avma1cs_config(0x%p)\n", link);
216 207
217 do { 208 devname[0] = 0;
218 devname[0] = 0; 209 if (link->prod_id[1])
219 if (link->prod_id[1]) 210 strlcpy(devname, link->prod_id[1], sizeof(devname));
220 strlcpy(devname, link->prod_id[1], sizeof(devname));
221 211
222 /* 212 if (pcmcia_loop_config(link, avma1cs_configcheck, NULL))
223 * find IO port 213 return -ENODEV;
224 */
225 tuple.TupleData = (cisdata_t *)buf;
226 tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
227 tuple.Attributes = 0;
228 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
229 i = first_tuple(link, &tuple, &parse);
230 while (i == CS_SUCCESS) {
231 if (cf->io.nwin > 0) {
232 link->conf.ConfigIndex = cf->index;
233 link->io.BasePort1 = cf->io.win[0].base;
234 link->io.NumPorts1 = cf->io.win[0].len;
235 link->io.NumPorts2 = 0;
236 printk(KERN_INFO "avma1_cs: testing i/o %#x-%#x\n",
237 link->io.BasePort1,
238 link->io.BasePort1+link->io.NumPorts1 - 1);
239 i = pcmcia_request_io(link, &link->io);
240 if (i == CS_SUCCESS) goto found_port;
241 }
242 i = next_tuple(link, &tuple, &parse);
243 }
244 214
245found_port: 215 do {
246 if (i != CS_SUCCESS) {
247 cs_error(link, RequestIO, i);
248 break;
249 }
250
251 /* 216 /*
252 * allocate an interrupt line 217 * allocate an interrupt line
253 */ 218 */
254 i = pcmcia_request_irq(link, &link->irq); 219 i = pcmcia_request_irq(link, &link->irq);
255 if (i != CS_SUCCESS) { 220 if (i != 0) {
256 cs_error(link, RequestIRQ, i); 221 cs_error(link, RequestIRQ, i);
257 /* undo */ 222 /* undo */
258 pcmcia_disable_device(link); 223 pcmcia_disable_device(link);
@@ -263,7 +228,7 @@ found_port:
263 * configure the PCMCIA socket 228 * configure the PCMCIA socket
264 */ 229 */
265 i = pcmcia_request_configuration(link, &link->conf); 230 i = pcmcia_request_configuration(link, &link->conf);
266 if (i != CS_SUCCESS) { 231 if (i != 0) {
267 cs_error(link, RequestConfiguration, i); 232 cs_error(link, RequestConfiguration, i);
268 pcmcia_disable_device(link); 233 pcmcia_disable_device(link);
269 break; 234 break;
diff --git a/drivers/isdn/hisax/elsa_cs.c b/drivers/isdn/hisax/elsa_cs.c
index db7e64424afe..f4d0fe29bcf8 100644
--- a/drivers/isdn/hisax/elsa_cs.c
+++ b/drivers/isdn/hisax/elsa_cs.c
@@ -203,82 +203,55 @@ static void elsa_cs_detach(struct pcmcia_device *link)
203 device available to the system. 203 device available to the system.
204 204
205======================================================================*/ 205======================================================================*/
206static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
207 cisparse_t *parse)
208{
209 int i = pcmcia_get_tuple_data(handle, tuple);
210 if (i != CS_SUCCESS) return i;
211 return pcmcia_parse_tuple(handle, tuple, parse);
212}
213
214static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
215 cisparse_t *parse)
216{
217 int i = pcmcia_get_first_tuple(handle, tuple);
218 if (i != CS_SUCCESS) return i;
219 return get_tuple(handle, tuple, parse);
220}
221 206
222static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, 207static int elsa_cs_configcheck(struct pcmcia_device *p_dev,
223 cisparse_t *parse) 208 cistpl_cftable_entry_t *cf,
209 cistpl_cftable_entry_t *dflt,
210 unsigned int vcc,
211 void *priv_data)
224{ 212{
225 int i = pcmcia_get_next_tuple(handle, tuple); 213 int j;
226 if (i != CS_SUCCESS) return i; 214
227 return get_tuple(handle, tuple, parse); 215 if ((cf->io.nwin > 0) && cf->io.win[0].base) {
216 printk(KERN_INFO "(elsa_cs: looks like the 96 model)\n");
217 p_dev->io.BasePort1 = cf->io.win[0].base;
218 if (!pcmcia_request_io(p_dev, &p_dev->io))
219 return 0;
220 } else {
221 printk(KERN_INFO "(elsa_cs: looks like the 97 model)\n");
222 for (j = 0x2f0; j > 0x100; j -= 0x10) {
223 p_dev->io.BasePort1 = j;
224 if (!pcmcia_request_io(p_dev, &p_dev->io))
225 return 0;
226 }
227 }
228 return -ENODEV;
228} 229}
229 230
230static int elsa_cs_config(struct pcmcia_device *link) 231static int elsa_cs_config(struct pcmcia_device *link)
231{ 232{
232 tuple_t tuple;
233 cisparse_t parse;
234 local_info_t *dev; 233 local_info_t *dev;
235 int i, j, last_fn; 234 int i, last_fn;
236 u_short buf[128];
237 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
238 IsdnCard_t icard; 235 IsdnCard_t icard;
239 236
240 DEBUG(0, "elsa_config(0x%p)\n", link); 237 DEBUG(0, "elsa_config(0x%p)\n", link);
241 dev = link->priv; 238 dev = link->priv;
242 239
243 tuple.TupleData = (cisdata_t *)buf; 240 i = pcmcia_loop_config(link, elsa_cs_configcheck, NULL);
244 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 241 if (i != 0) {
245 tuple.Attributes = 0;
246 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
247 i = first_tuple(link, &tuple, &parse);
248 while (i == CS_SUCCESS) {
249 if ( (cf->io.nwin > 0) && cf->io.win[0].base) {
250 printk(KERN_INFO "(elsa_cs: looks like the 96 model)\n");
251 link->conf.ConfigIndex = cf->index;
252 link->io.BasePort1 = cf->io.win[0].base;
253 i = pcmcia_request_io(link, &link->io);
254 if (i == CS_SUCCESS) break;
255 } else {
256 printk(KERN_INFO "(elsa_cs: looks like the 97 model)\n");
257 link->conf.ConfigIndex = cf->index;
258 for (i = 0, j = 0x2f0; j > 0x100; j -= 0x10) {
259 link->io.BasePort1 = j;
260 i = pcmcia_request_io(link, &link->io);
261 if (i == CS_SUCCESS) break;
262 }
263 break;
264 }
265 i = next_tuple(link, &tuple, &parse);
266 }
267
268 if (i != CS_SUCCESS) {
269 last_fn = RequestIO; 242 last_fn = RequestIO;
270 goto cs_failed; 243 goto cs_failed;
271 } 244 }
272 245
273 i = pcmcia_request_irq(link, &link->irq); 246 i = pcmcia_request_irq(link, &link->irq);
274 if (i != CS_SUCCESS) { 247 if (i != 0) {
275 link->irq.AssignedIRQ = 0; 248 link->irq.AssignedIRQ = 0;
276 last_fn = RequestIRQ; 249 last_fn = RequestIRQ;
277 goto cs_failed; 250 goto cs_failed;
278 } 251 }
279 252
280 i = pcmcia_request_configuration(link, &link->conf); 253 i = pcmcia_request_configuration(link, &link->conf);
281 if (i != CS_SUCCESS) { 254 if (i != 0) {
282 last_fn = RequestConfiguration; 255 last_fn = RequestConfiguration;
283 goto cs_failed; 256 goto cs_failed;
284 } 257 }
diff --git a/drivers/isdn/hisax/sedlbauer_cs.c b/drivers/isdn/hisax/sedlbauer_cs.c
index 439cb530def8..9a3c9f5e4fe8 100644
--- a/drivers/isdn/hisax/sedlbauer_cs.c
+++ b/drivers/isdn/hisax/sedlbauer_cs.c
@@ -217,101 +217,61 @@ static void sedlbauer_detach(struct pcmcia_device *link)
217#define CS_CHECK(fn, ret) \ 217#define CS_CHECK(fn, ret) \
218do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 218do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
219 219
220static int sedlbauer_config(struct pcmcia_device *link) 220static int sedlbauer_config_check(struct pcmcia_device *p_dev,
221 cistpl_cftable_entry_t *cfg,
222 cistpl_cftable_entry_t *dflt,
223 unsigned int vcc,
224 void *priv_data)
221{ 225{
222 local_info_t *dev = link->priv; 226 win_req_t *req = priv_data;
223 tuple_t tuple;
224 cisparse_t parse;
225 int last_fn, last_ret;
226 u8 buf[64];
227 config_info_t conf;
228 win_req_t req;
229 memreq_t map;
230 IsdnCard_t icard;
231
232 DEBUG(0, "sedlbauer_config(0x%p)\n", link);
233
234 tuple.Attributes = 0;
235 tuple.TupleData = buf;
236 tuple.TupleDataMax = sizeof(buf);
237 tuple.TupleOffset = 0;
238 227
239 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &conf)); 228 if (cfg->index == 0)
229 return -ENODEV;
240 230
241 /*
242 In this loop, we scan the CIS for configuration table entries,
243 each of which describes a valid card configuration, including
244 voltage, IO window, memory window, and interrupt settings.
245
246 We make no assumptions about the card to be configured: we use
247 just the information available in the CIS. In an ideal world,
248 this would work for any PCMCIA card, but it requires a complete
249 and accurate CIS. In practice, a driver usually "knows" most of
250 these things without consulting the CIS, and most client drivers
251 will only use the CIS to fill in implementation-defined details.
252 */
253 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
254 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
255 while (1) {
256 cistpl_cftable_entry_t dflt = { 0 };
257 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
258 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
259 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
260 goto next_entry;
261
262 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
263 if (cfg->index == 0) goto next_entry;
264 link->conf.ConfigIndex = cfg->index;
265
266 /* Does this card need audio output? */ 231 /* Does this card need audio output? */
267 if (cfg->flags & CISTPL_CFTABLE_AUDIO) { 232 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
268 link->conf.Attributes |= CONF_ENABLE_SPKR; 233 p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
269 link->conf.Status = CCSR_AUDIO_ENA; 234 p_dev->conf.Status = CCSR_AUDIO_ENA;
270 } 235 }
271 236
272 /* Use power settings for Vcc and Vpp if present */ 237 /* Use power settings for Vcc and Vpp if present */
273 /* Note that the CIS values need to be rescaled */ 238 /* Note that the CIS values need to be rescaled */
274 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) { 239 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
275 if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000) 240 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000)
276 goto next_entry; 241 return -ENODEV;
277 } else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM)) { 242 } else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) {
278 if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM]/10000) 243 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM]/10000)
279 goto next_entry; 244 return -ENODEV;
280 } 245 }
281 246
282 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM)) 247 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
283 link->conf.Vpp = 248 p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
284 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000; 249 else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
285 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM)) 250 p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
286 link->conf.Vpp = 251
287 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
288
289 /* Do we need to allocate an interrupt? */ 252 /* Do we need to allocate an interrupt? */
290 if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) 253 if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
291 link->conf.Attributes |= CONF_ENABLE_IRQ; 254 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
292 255
293 /* IO window settings */ 256 /* IO window settings */
294 link->io.NumPorts1 = link->io.NumPorts2 = 0; 257 p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
295 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { 258 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
296 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; 259 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
297 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 260 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
298 if (!(io->flags & CISTPL_IO_8BIT)) 261 if (!(io->flags & CISTPL_IO_8BIT))
299 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; 262 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
300 if (!(io->flags & CISTPL_IO_16BIT)) 263 if (!(io->flags & CISTPL_IO_16BIT))
301 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 264 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
302/* new in dummy.cs 2001/01/28 MN 265 p_dev->io.BasePort1 = io->win[0].base;
303 link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; 266 p_dev->io.NumPorts1 = io->win[0].len;
304*/ 267 if (io->nwin > 1) {
305 link->io.BasePort1 = io->win[0].base; 268 p_dev->io.Attributes2 = p_dev->io.Attributes1;
306 link->io.NumPorts1 = io->win[0].len; 269 p_dev->io.BasePort2 = io->win[1].base;
307 if (io->nwin > 1) { 270 p_dev->io.NumPorts2 = io->win[1].len;
308 link->io.Attributes2 = link->io.Attributes1; 271 }
309 link->io.BasePort2 = io->win[1].base; 272 /* This reserves IO space but doesn't actually enable it */
310 link->io.NumPorts2 = io->win[1].len; 273 if (pcmcia_request_io(p_dev, &p_dev->io) != 0)
311 } 274 return -ENODEV;
312 /* This reserves IO space but doesn't actually enable it */
313 if (pcmcia_request_io(link, &link->io) != 0)
314 goto next_entry;
315 } 275 }
316 276
317 /* 277 /*
@@ -325,30 +285,54 @@ static int sedlbauer_config(struct pcmcia_device *link)
325 needs to be mapped to virtual space with ioremap() before it 285 needs to be mapped to virtual space with ioremap() before it
326 is used. 286 is used.
327 */ 287 */
328 if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) { 288 if ((cfg->mem.nwin > 0) || (dflt->mem.nwin > 0)) {
329 cistpl_mem_t *mem = 289 cistpl_mem_t *mem = (cfg->mem.nwin) ? &cfg->mem : &dflt->mem;
330 (cfg->mem.nwin) ? &cfg->mem : &dflt.mem; 290 memreq_t map;
331 req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM; 291 req->Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
332 req.Attributes |= WIN_ENABLE; 292 req->Attributes |= WIN_ENABLE;
333 req.Base = mem->win[0].host_addr; 293 req->Base = mem->win[0].host_addr;
334 req.Size = mem->win[0].len; 294 req->Size = mem->win[0].len;
335/* new in dummy.cs 2001/01/28 MN 295 req->AccessSpeed = 0;
336 if (req.Size < 0x1000) 296 if (pcmcia_request_window(&p_dev, req, &p_dev->win) != 0)
337 req.Size = 0x1000; 297 return -ENODEV;
338*/ 298 map.Page = 0;
339 req.AccessSpeed = 0; 299 map.CardOffset = mem->win[0].card_addr;
340 if (pcmcia_request_window(&link, &req, &link->win) != 0) 300 if (pcmcia_map_mem_page(p_dev->win, &map) != 0)
341 goto next_entry; 301 return -ENODEV;
342 map.Page = 0; map.CardOffset = mem->win[0].card_addr;
343 if (pcmcia_map_mem_page(link->win, &map) != 0)
344 goto next_entry;
345 } 302 }
346 /* If we got this far, we're cool! */ 303 return 0;
347 break; 304}
348 305
349 next_entry: 306
350 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple)); 307
351 } 308static int sedlbauer_config(struct pcmcia_device *link)
309{
310 local_info_t *dev = link->priv;
311 win_req_t *req;
312 int last_fn, last_ret;
313 IsdnCard_t icard;
314
315 DEBUG(0, "sedlbauer_config(0x%p)\n", link);
316
317 req = kzalloc(sizeof(win_req_t), GFP_KERNEL);
318 if (!req)
319 return -ENOMEM;
320
321 /*
322 In this loop, we scan the CIS for configuration table entries,
323 each of which describes a valid card configuration, including
324 voltage, IO window, memory window, and interrupt settings.
325
326 We make no assumptions about the card to be configured: we use
327 just the information available in the CIS. In an ideal world,
328 this would work for any PCMCIA card, but it requires a complete
329 and accurate CIS. In practice, a driver usually "knows" most of
330 these things without consulting the CIS, and most client drivers
331 will only use the CIS to fill in implementation-defined details.
332 */
333 last_ret = pcmcia_loop_config(link, sedlbauer_config_check, req);
334 if (last_ret)
335 goto failed;
352 336
353 /* 337 /*
354 Allocate an interrupt line. Note that this does not assign a 338 Allocate an interrupt line. Note that this does not assign a
@@ -387,8 +371,8 @@ static int sedlbauer_config(struct pcmcia_device *link)
387 printk(" & 0x%04x-0x%04x", link->io.BasePort2, 371 printk(" & 0x%04x-0x%04x", link->io.BasePort2,
388 link->io.BasePort2+link->io.NumPorts2-1); 372 link->io.BasePort2+link->io.NumPorts2-1);
389 if (link->win) 373 if (link->win)
390 printk(", mem 0x%06lx-0x%06lx", req.Base, 374 printk(", mem 0x%06lx-0x%06lx", req->Base,
391 req.Base+req.Size-1); 375 req->Base+req->Size-1);
392 printk("\n"); 376 printk("\n");
393 377
394 icard.para[0] = link->irq.AssignedIRQ; 378 icard.para[0] = link->irq.AssignedIRQ;
@@ -409,6 +393,7 @@ static int sedlbauer_config(struct pcmcia_device *link)
409 393
410cs_failed: 394cs_failed:
411 cs_error(link, last_fn, last_ret); 395 cs_error(link, last_fn, last_ret);
396failed:
412 sedlbauer_release(link); 397 sedlbauer_release(link);
413 return -ENODEV; 398 return -ENODEV;
414 399
diff --git a/drivers/isdn/hisax/teles_cs.c b/drivers/isdn/hisax/teles_cs.c
index ab4bd455450e..623d111544d4 100644
--- a/drivers/isdn/hisax/teles_cs.c
+++ b/drivers/isdn/hisax/teles_cs.c
@@ -193,82 +193,55 @@ static void teles_detach(struct pcmcia_device *link)
193 device available to the system. 193 device available to the system.
194 194
195======================================================================*/ 195======================================================================*/
196static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
197 cisparse_t *parse)
198{
199 int i = pcmcia_get_tuple_data(handle, tuple);
200 if (i != CS_SUCCESS) return i;
201 return pcmcia_parse_tuple(handle, tuple, parse);
202}
203
204static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
205 cisparse_t *parse)
206{
207 int i = pcmcia_get_first_tuple(handle, tuple);
208 if (i != CS_SUCCESS) return i;
209 return get_tuple(handle, tuple, parse);
210}
211 196
212static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, 197static int teles_cs_configcheck(struct pcmcia_device *p_dev,
213 cisparse_t *parse) 198 cistpl_cftable_entry_t *cf,
199 cistpl_cftable_entry_t *dflt,
200 unsigned int vcc,
201 void *priv_data)
214{ 202{
215 int i = pcmcia_get_next_tuple(handle, tuple); 203 int j;
216 if (i != CS_SUCCESS) return i; 204
217 return get_tuple(handle, tuple, parse); 205 if ((cf->io.nwin > 0) && cf->io.win[0].base) {
206 printk(KERN_INFO "(teles_cs: looks like the 96 model)\n");
207 p_dev->io.BasePort1 = cf->io.win[0].base;
208 if (!pcmcia_request_io(p_dev, &p_dev->io))
209 return 0;
210 } else {
211 printk(KERN_INFO "(teles_cs: looks like the 97 model)\n");
212 for (j = 0x2f0; j > 0x100; j -= 0x10) {
213 p_dev->io.BasePort1 = j;
214 if (!pcmcia_request_io(p_dev, &p_dev->io))
215 return 0;
216 }
217 }
218 return -ENODEV;
218} 219}
219 220
220static int teles_cs_config(struct pcmcia_device *link) 221static int teles_cs_config(struct pcmcia_device *link)
221{ 222{
222 tuple_t tuple;
223 cisparse_t parse;
224 local_info_t *dev; 223 local_info_t *dev;
225 int i, j, last_fn; 224 int i, last_fn;
226 u_short buf[128];
227 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
228 IsdnCard_t icard; 225 IsdnCard_t icard;
229 226
230 DEBUG(0, "teles_config(0x%p)\n", link); 227 DEBUG(0, "teles_config(0x%p)\n", link);
231 dev = link->priv; 228 dev = link->priv;
232 229
233 tuple.TupleData = (cisdata_t *)buf; 230 i = pcmcia_loop_config(link, teles_cs_configcheck, NULL);
234 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 231 if (i != 0) {
235 tuple.Attributes = 0;
236 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
237 i = first_tuple(link, &tuple, &parse);
238 while (i == CS_SUCCESS) {
239 if ( (cf->io.nwin > 0) && cf->io.win[0].base) {
240 printk(KERN_INFO "(teles_cs: looks like the 96 model)\n");
241 link->conf.ConfigIndex = cf->index;
242 link->io.BasePort1 = cf->io.win[0].base;
243 i = pcmcia_request_io(link, &link->io);
244 if (i == CS_SUCCESS) break;
245 } else {
246 printk(KERN_INFO "(teles_cs: looks like the 97 model)\n");
247 link->conf.ConfigIndex = cf->index;
248 for (i = 0, j = 0x2f0; j > 0x100; j -= 0x10) {
249 link->io.BasePort1 = j;
250 i = pcmcia_request_io(link, &link->io);
251 if (i == CS_SUCCESS) break;
252 }
253 break;
254 }
255 i = next_tuple(link, &tuple, &parse);
256 }
257
258 if (i != CS_SUCCESS) {
259 last_fn = RequestIO; 232 last_fn = RequestIO;
260 goto cs_failed; 233 goto cs_failed;
261 } 234 }
262 235
263 i = pcmcia_request_irq(link, &link->irq); 236 i = pcmcia_request_irq(link, &link->irq);
264 if (i != CS_SUCCESS) { 237 if (i != 0) {
265 link->irq.AssignedIRQ = 0; 238 link->irq.AssignedIRQ = 0;
266 last_fn = RequestIRQ; 239 last_fn = RequestIRQ;
267 goto cs_failed; 240 goto cs_failed;
268 } 241 }
269 242
270 i = pcmcia_request_configuration(link, &link->conf); 243 i = pcmcia_request_configuration(link, &link->conf);
271 if (i != CS_SUCCESS) { 244 if (i != 0) {
272 last_fn = RequestConfiguration; 245 last_fn = RequestConfiguration;
273 goto cs_failed; 246 goto cs_failed;
274 } 247 }
diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
index e92b1ba4b45e..c2f51cc50760 100644
--- a/drivers/isdn/mISDN/dsp_cmx.c
+++ b/drivers/isdn/mISDN/dsp_cmx.c
@@ -452,10 +452,10 @@ one_member:
452 if (finddsp->features.pcm_id == dsp->features.pcm_id) { 452 if (finddsp->features.pcm_id == dsp->features.pcm_id) {
453 if (finddsp->pcm_slot_rx >= 0 && 453 if (finddsp->pcm_slot_rx >= 0 &&
454 finddsp->pcm_slot_rx < sizeof(freeslots)) 454 finddsp->pcm_slot_rx < sizeof(freeslots))
455 freeslots[finddsp->pcm_slot_tx] = 0; 455 freeslots[finddsp->pcm_slot_rx] = 0;
456 if (finddsp->pcm_slot_tx >= 0 && 456 if (finddsp->pcm_slot_tx >= 0 &&
457 finddsp->pcm_slot_tx < sizeof(freeslots)) 457 finddsp->pcm_slot_tx < sizeof(freeslots))
458 freeslots[finddsp->pcm_slot_rx] = 0; 458 freeslots[finddsp->pcm_slot_tx] = 0;
459 } 459 }
460 } 460 }
461 i = 0; 461 i = 0;
diff --git a/drivers/isdn/mISDN/timerdev.c b/drivers/isdn/mISDN/timerdev.c
index e7462924b505..875fabe16e36 100644
--- a/drivers/isdn/mISDN/timerdev.c
+++ b/drivers/isdn/mISDN/timerdev.c
@@ -61,7 +61,7 @@ mISDN_open(struct inode *ino, struct file *filep)
61 init_waitqueue_head(&dev->wait); 61 init_waitqueue_head(&dev->wait);
62 filep->private_data = dev; 62 filep->private_data = dev;
63 __module_get(THIS_MODULE); 63 __module_get(THIS_MODULE);
64 return 0; 64 return nonseekable_open(ino, filep);
65} 65}
66 66
67static int 67static int
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 559a40861c39..ee74ee7b2acc 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -103,8 +103,8 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
103{ 103{
104 int rc; 104 int rc;
105 105
106 led_cdev->dev = device_create_drvdata(leds_class, parent, 0, led_cdev, 106 led_cdev->dev = device_create(leds_class, parent, 0, led_cdev,
107 "%s", led_cdev->name); 107 "%s", led_cdev->name);
108 if (IS_ERR(led_cdev->dev)) 108 if (IS_ERR(led_cdev->dev))
109 return PTR_ERR(led_cdev->dev); 109 return PTR_ERR(led_cdev->dev);
110 110
diff --git a/drivers/macintosh/adb.c b/drivers/macintosh/adb.c
index cae52485208a..23741cec45e3 100644
--- a/drivers/macintosh/adb.c
+++ b/drivers/macintosh/adb.c
@@ -862,8 +862,7 @@ adbdev_init(void)
862 adb_dev_class = class_create(THIS_MODULE, "adb"); 862 adb_dev_class = class_create(THIS_MODULE, "adb");
863 if (IS_ERR(adb_dev_class)) 863 if (IS_ERR(adb_dev_class))
864 return; 864 return;
865 device_create_drvdata(adb_dev_class, NULL, MKDEV(ADB_MAJOR, 0), NULL, 865 device_create(adb_dev_class, NULL, MKDEV(ADB_MAJOR, 0), NULL, "adb");
866 "adb");
867 866
868 platform_device_register(&adb_pfdev); 867 platform_device_register(&adb_pfdev);
869 platform_driver_probe(&adb_pfdrv, adb_dummy_probe); 868 platform_driver_probe(&adb_pfdrv, adb_dummy_probe);
diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig
index 07d92c11b5d8..2281b5098e95 100644
--- a/drivers/md/Kconfig
+++ b/drivers/md/Kconfig
@@ -30,6 +30,20 @@ config BLK_DEV_MD
30 30
31 If unsure, say N. 31 If unsure, say N.
32 32
33config MD_AUTODETECT
34 bool "Autodetect RAID arrays during kernel boot"
35 depends on BLK_DEV_MD=y
36 default y
37 ---help---
38 If you say Y here, then the kernel will try to autodetect raid
39 arrays as part of its boot process.
40
41 If you don't use raid and say Y, this autodetection can cause
42 a several-second delay in the boot time due to various
43 synchronisation steps that are part of this step.
44
45 If unsure, say Y.
46
33config MD_LINEAR 47config MD_LINEAR
34 tristate "Linear (append) mode" 48 tristate "Linear (append) mode"
35 depends on BLK_DEV_MD 49 depends on BLK_DEV_MD
diff --git a/drivers/md/faulty.c b/drivers/md/faulty.c
index 268547dbfbd3..f26c1f9a475b 100644
--- a/drivers/md/faulty.c
+++ b/drivers/md/faulty.c
@@ -287,6 +287,8 @@ static int run(mddev_t *mddev)
287 int i; 287 int i;
288 288
289 conf_t *conf = kmalloc(sizeof(*conf), GFP_KERNEL); 289 conf_t *conf = kmalloc(sizeof(*conf), GFP_KERNEL);
290 if (!conf)
291 return -ENOMEM;
290 292
291 for (i=0; i<Modes; i++) { 293 for (i=0; i<Modes; i++) {
292 atomic_set(&conf->counters[i], 0); 294 atomic_set(&conf->counters[i], 0);
diff --git a/drivers/md/linear.c b/drivers/md/linear.c
index b9cbee688fae..190147c79e79 100644
--- a/drivers/md/linear.c
+++ b/drivers/md/linear.c
@@ -16,16 +16,8 @@
16 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 16 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17*/ 17*/
18 18
19#include <linux/module.h>
20
21#include <linux/raid/md.h>
22#include <linux/slab.h>
23#include <linux/raid/linear.h> 19#include <linux/raid/linear.h>
24 20
25#define MAJOR_NR MD_MAJOR
26#define MD_DRIVER
27#define MD_PERSONALITY
28
29/* 21/*
30 * find which device holds a particular offset 22 * find which device holds a particular offset
31 */ 23 */
@@ -33,16 +25,15 @@ static inline dev_info_t *which_dev(mddev_t *mddev, sector_t sector)
33{ 25{
34 dev_info_t *hash; 26 dev_info_t *hash;
35 linear_conf_t *conf = mddev_to_conf(mddev); 27 linear_conf_t *conf = mddev_to_conf(mddev);
36 sector_t block = sector >> 1;
37 28
38 /* 29 /*
39 * sector_div(a,b) returns the remainer and sets a to a/b 30 * sector_div(a,b) returns the remainer and sets a to a/b
40 */ 31 */
41 block >>= conf->preshift; 32 sector >>= conf->sector_shift;
42 (void)sector_div(block, conf->hash_spacing); 33 (void)sector_div(sector, conf->spacing);
43 hash = conf->hash_table[block]; 34 hash = conf->hash_table[sector];
44 35
45 while ((sector>>1) >= (hash->size + hash->offset)) 36 while (sector >= hash->num_sectors + hash->start_sector)
46 hash++; 37 hash++;
47 return hash; 38 return hash;
48} 39}
@@ -65,7 +56,7 @@ static int linear_mergeable_bvec(struct request_queue *q,
65 sector_t sector = bvm->bi_sector + get_start_sect(bvm->bi_bdev); 56 sector_t sector = bvm->bi_sector + get_start_sect(bvm->bi_bdev);
66 57
67 dev0 = which_dev(mddev, sector); 58 dev0 = which_dev(mddev, sector);
68 maxsectors = (dev0->size << 1) - (sector - (dev0->offset<<1)); 59 maxsectors = dev0->num_sectors - (sector - dev0->start_sector);
69 60
70 if (maxsectors < bio_sectors) 61 if (maxsectors < bio_sectors)
71 maxsectors = 0; 62 maxsectors = 0;
@@ -112,8 +103,8 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
112 dev_info_t **table; 103 dev_info_t **table;
113 mdk_rdev_t *rdev; 104 mdk_rdev_t *rdev;
114 int i, nb_zone, cnt; 105 int i, nb_zone, cnt;
115 sector_t min_spacing; 106 sector_t min_sectors;
116 sector_t curr_offset; 107 sector_t curr_sector;
117 struct list_head *tmp; 108 struct list_head *tmp;
118 109
119 conf = kzalloc (sizeof (*conf) + raid_disks*sizeof(dev_info_t), 110 conf = kzalloc (sizeof (*conf) + raid_disks*sizeof(dev_info_t),
@@ -145,7 +136,7 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
145 mddev->queue->max_sectors > (PAGE_SIZE>>9)) 136 mddev->queue->max_sectors > (PAGE_SIZE>>9))
146 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9); 137 blk_queue_max_sectors(mddev->queue, PAGE_SIZE>>9);
147 138
148 disk->size = rdev->size; 139 disk->num_sectors = rdev->size * 2;
149 conf->array_sectors += rdev->size * 2; 140 conf->array_sectors += rdev->size * 2;
150 141
151 cnt++; 142 cnt++;
@@ -155,34 +146,34 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
155 goto out; 146 goto out;
156 } 147 }
157 148
158 min_spacing = conf->array_sectors / 2; 149 min_sectors = conf->array_sectors;
159 sector_div(min_spacing, PAGE_SIZE/sizeof(struct dev_info *)); 150 sector_div(min_sectors, PAGE_SIZE/sizeof(struct dev_info *));
160 151
161 /* min_spacing is the minimum spacing that will fit the hash 152 /* min_sectors is the minimum spacing that will fit the hash
162 * table in one PAGE. This may be much smaller than needed. 153 * table in one PAGE. This may be much smaller than needed.
163 * We find the smallest non-terminal set of consecutive devices 154 * We find the smallest non-terminal set of consecutive devices
164 * that is larger than min_spacing as use the size of that as 155 * that is larger than min_sectors and use the size of that as
165 * the actual spacing 156 * the actual spacing
166 */ 157 */
167 conf->hash_spacing = conf->array_sectors / 2; 158 conf->spacing = conf->array_sectors;
168 for (i=0; i < cnt-1 ; i++) { 159 for (i=0; i < cnt-1 ; i++) {
169 sector_t sz = 0; 160 sector_t tmp = 0;
170 int j; 161 int j;
171 for (j = i; j < cnt - 1 && sz < min_spacing; j++) 162 for (j = i; j < cnt - 1 && tmp < min_sectors; j++)
172 sz += conf->disks[j].size; 163 tmp += conf->disks[j].num_sectors;
173 if (sz >= min_spacing && sz < conf->hash_spacing) 164 if (tmp >= min_sectors && tmp < conf->spacing)
174 conf->hash_spacing = sz; 165 conf->spacing = tmp;
175 } 166 }
176 167
177 /* hash_spacing may be too large for sector_div to work with, 168 /* spacing may be too large for sector_div to work with,
178 * so we might need to pre-shift 169 * so we might need to pre-shift
179 */ 170 */
180 conf->preshift = 0; 171 conf->sector_shift = 0;
181 if (sizeof(sector_t) > sizeof(u32)) { 172 if (sizeof(sector_t) > sizeof(u32)) {
182 sector_t space = conf->hash_spacing; 173 sector_t space = conf->spacing;
183 while (space > (sector_t)(~(u32)0)) { 174 while (space > (sector_t)(~(u32)0)) {
184 space >>= 1; 175 space >>= 1;
185 conf->preshift++; 176 conf->sector_shift++;
186 } 177 }
187 } 178 }
188 /* 179 /*
@@ -194,9 +185,9 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
194 unsigned round; 185 unsigned round;
195 unsigned long base; 186 unsigned long base;
196 187
197 sz = conf->array_sectors >> (conf->preshift + 1); 188 sz = conf->array_sectors >> conf->sector_shift;
198 sz += 1; /* force round-up */ 189 sz += 1; /* force round-up */
199 base = conf->hash_spacing >> conf->preshift; 190 base = conf->spacing >> conf->sector_shift;
200 round = sector_div(sz, base); 191 round = sector_div(sz, base);
201 nb_zone = sz + (round ? 1 : 0); 192 nb_zone = sz + (round ? 1 : 0);
202 } 193 }
@@ -211,32 +202,31 @@ static linear_conf_t *linear_conf(mddev_t *mddev, int raid_disks)
211 * Here we generate the linear hash table 202 * Here we generate the linear hash table
212 * First calculate the device offsets. 203 * First calculate the device offsets.
213 */ 204 */
214 conf->disks[0].offset = 0; 205 conf->disks[0].start_sector = 0;
215 for (i = 1; i < raid_disks; i++) 206 for (i = 1; i < raid_disks; i++)
216 conf->disks[i].offset = 207 conf->disks[i].start_sector =
217 conf->disks[i-1].offset + 208 conf->disks[i-1].start_sector +
218 conf->disks[i-1].size; 209 conf->disks[i-1].num_sectors;
219 210
220 table = conf->hash_table; 211 table = conf->hash_table;
221 curr_offset = 0;
222 i = 0; 212 i = 0;
223 for (curr_offset = 0; 213 for (curr_sector = 0;
224 curr_offset < conf->array_sectors / 2; 214 curr_sector < conf->array_sectors;
225 curr_offset += conf->hash_spacing) { 215 curr_sector += conf->spacing) {
226 216
227 while (i < raid_disks-1 && 217 while (i < raid_disks-1 &&
228 curr_offset >= conf->disks[i+1].offset) 218 curr_sector >= conf->disks[i+1].start_sector)
229 i++; 219 i++;
230 220
231 *table ++ = conf->disks + i; 221 *table ++ = conf->disks + i;
232 } 222 }
233 223
234 if (conf->preshift) { 224 if (conf->sector_shift) {
235 conf->hash_spacing >>= conf->preshift; 225 conf->spacing >>= conf->sector_shift;
236 /* round hash_spacing up so that when we divide by it, 226 /* round spacing up so that when we divide by it,
237 * we err on the side of "too-low", which is safest. 227 * we err on the side of "too-low", which is safest.
238 */ 228 */
239 conf->hash_spacing++; 229 conf->spacing++;
240 } 230 }
241 231
242 BUG_ON(table - conf->hash_table > nb_zone); 232 BUG_ON(table - conf->hash_table > nb_zone);
@@ -317,7 +307,6 @@ static int linear_make_request (struct request_queue *q, struct bio *bio)
317 const int rw = bio_data_dir(bio); 307 const int rw = bio_data_dir(bio);
318 mddev_t *mddev = q->queuedata; 308 mddev_t *mddev = q->queuedata;
319 dev_info_t *tmp_dev; 309 dev_info_t *tmp_dev;
320 sector_t block;
321 int cpu; 310 int cpu;
322 311
323 if (unlikely(bio_barrier(bio))) { 312 if (unlikely(bio_barrier(bio))) {
@@ -332,29 +321,33 @@ static int linear_make_request (struct request_queue *q, struct bio *bio)
332 part_stat_unlock(); 321 part_stat_unlock();
333 322
334 tmp_dev = which_dev(mddev, bio->bi_sector); 323 tmp_dev = which_dev(mddev, bio->bi_sector);
335 block = bio->bi_sector >> 1;
336 324
337 if (unlikely(block >= (tmp_dev->size + tmp_dev->offset) 325 if (unlikely(bio->bi_sector >= (tmp_dev->num_sectors +
338 || block < tmp_dev->offset)) { 326 tmp_dev->start_sector)
327 || (bio->bi_sector <
328 tmp_dev->start_sector))) {
339 char b[BDEVNAME_SIZE]; 329 char b[BDEVNAME_SIZE];
340 330
341 printk("linear_make_request: Block %llu out of bounds on " 331 printk("linear_make_request: Sector %llu out of bounds on "
342 "dev %s size %llu offset %llu\n", 332 "dev %s: %llu sectors, offset %llu\n",
343 (unsigned long long)block, 333 (unsigned long long)bio->bi_sector,
344 bdevname(tmp_dev->rdev->bdev, b), 334 bdevname(tmp_dev->rdev->bdev, b),
345 (unsigned long long)tmp_dev->size, 335 (unsigned long long)tmp_dev->num_sectors,
346 (unsigned long long)tmp_dev->offset); 336 (unsigned long long)tmp_dev->start_sector);
347 bio_io_error(bio); 337 bio_io_error(bio);
348 return 0; 338 return 0;
349 } 339 }
350 if (unlikely(bio->bi_sector + (bio->bi_size >> 9) > 340 if (unlikely(bio->bi_sector + (bio->bi_size >> 9) >
351 (tmp_dev->offset + tmp_dev->size)<<1)) { 341 tmp_dev->start_sector + tmp_dev->num_sectors)) {
352 /* This bio crosses a device boundary, so we have to 342 /* This bio crosses a device boundary, so we have to
353 * split it. 343 * split it.
354 */ 344 */
355 struct bio_pair *bp; 345 struct bio_pair *bp;
346
356 bp = bio_split(bio, 347 bp = bio_split(bio,
357 ((tmp_dev->offset + tmp_dev->size)<<1) - bio->bi_sector); 348 tmp_dev->start_sector + tmp_dev->num_sectors
349 - bio->bi_sector);
350
358 if (linear_make_request(q, &bp->bio1)) 351 if (linear_make_request(q, &bp->bio1))
359 generic_make_request(&bp->bio1); 352 generic_make_request(&bp->bio1);
360 if (linear_make_request(q, &bp->bio2)) 353 if (linear_make_request(q, &bp->bio2))
@@ -364,7 +357,8 @@ static int linear_make_request (struct request_queue *q, struct bio *bio)
364 } 357 }
365 358
366 bio->bi_bdev = tmp_dev->rdev->bdev; 359 bio->bi_bdev = tmp_dev->rdev->bdev;
367 bio->bi_sector = bio->bi_sector - (tmp_dev->offset << 1) + tmp_dev->rdev->data_offset; 360 bio->bi_sector = bio->bi_sector - tmp_dev->start_sector
361 + tmp_dev->rdev->data_offset;
368 362
369 return 1; 363 return 1;
370} 364}
@@ -372,29 +366,6 @@ static int linear_make_request (struct request_queue *q, struct bio *bio)
372static void linear_status (struct seq_file *seq, mddev_t *mddev) 366static void linear_status (struct seq_file *seq, mddev_t *mddev)
373{ 367{
374 368
375#undef MD_DEBUG
376#ifdef MD_DEBUG
377 int j;
378 linear_conf_t *conf = mddev_to_conf(mddev);
379 sector_t s = 0;
380
381 seq_printf(seq, " ");
382 for (j = 0; j < mddev->raid_disks; j++)
383 {
384 char b[BDEVNAME_SIZE];
385 s += conf->smallest_size;
386 seq_printf(seq, "[%s",
387 bdevname(conf->hash_table[j][0].rdev->bdev,b));
388
389 while (s > conf->hash_table[j][0].offset +
390 conf->hash_table[j][0].size)
391 seq_printf(seq, "/%s] ",
392 bdevname(conf->hash_table[j][1].rdev->bdev,b));
393 else
394 seq_printf(seq, "] ");
395 }
396 seq_printf(seq, "\n");
397#endif
398 seq_printf(seq, " %dk rounding", mddev->chunk_size/1024); 369 seq_printf(seq, " %dk rounding", mddev->chunk_size/1024);
399} 370}
400 371
diff --git a/drivers/md/md.c b/drivers/md/md.c
index 0a3a4bdcd4af..aaa3d465de4e 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -32,31 +32,21 @@
32 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 32 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33*/ 33*/
34 34
35#include <linux/module.h>
36#include <linux/kernel.h>
37#include <linux/kthread.h> 35#include <linux/kthread.h>
38#include <linux/linkage.h>
39#include <linux/raid/md.h> 36#include <linux/raid/md.h>
40#include <linux/raid/bitmap.h> 37#include <linux/raid/bitmap.h>
41#include <linux/sysctl.h> 38#include <linux/sysctl.h>
42#include <linux/buffer_head.h> /* for invalidate_bdev */ 39#include <linux/buffer_head.h> /* for invalidate_bdev */
43#include <linux/poll.h> 40#include <linux/poll.h>
44#include <linux/mutex.h>
45#include <linux/ctype.h> 41#include <linux/ctype.h>
46#include <linux/freezer.h> 42#include <linux/hdreg.h>
47 43#include <linux/proc_fs.h>
48#include <linux/init.h> 44#include <linux/random.h>
49 45#include <linux/reboot.h>
50#include <linux/file.h> 46#include <linux/file.h>
51 47#include <linux/delay.h>
52#ifdef CONFIG_KMOD
53#include <linux/kmod.h>
54#endif
55
56#include <asm/unaligned.h>
57 48
58#define MAJOR_NR MD_MAJOR 49#define MAJOR_NR MD_MAJOR
59#define MD_DRIVER
60 50
61/* 63 partitions with the alternate major number (mdp) */ 51/* 63 partitions with the alternate major number (mdp) */
62#define MdpMinorShift 6 52#define MdpMinorShift 6
@@ -66,7 +56,7 @@
66 56
67 57
68#ifndef MODULE 58#ifndef MODULE
69static void autostart_arrays (int part); 59static void autostart_arrays(int part);
70#endif 60#endif
71 61
72static LIST_HEAD(pers_list); 62static LIST_HEAD(pers_list);
@@ -212,7 +202,7 @@ static DEFINE_SPINLOCK(all_mddevs_lock);
212 ) 202 )
213 203
214 204
215static int md_fail_request (struct request_queue *q, struct bio *bio) 205static int md_fail_request(struct request_queue *q, struct bio *bio)
216{ 206{
217 bio_io_error(bio); 207 bio_io_error(bio);
218 return 0; 208 return 0;
@@ -2106,8 +2096,6 @@ rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2106 2096
2107 if (strict_strtoull(buf, 10, &size) < 0) 2097 if (strict_strtoull(buf, 10, &size) < 0)
2108 return -EINVAL; 2098 return -EINVAL;
2109 if (size < my_mddev->size)
2110 return -EINVAL;
2111 if (my_mddev->pers && rdev->raid_disk >= 0) { 2099 if (my_mddev->pers && rdev->raid_disk >= 0) {
2112 if (my_mddev->persistent) { 2100 if (my_mddev->persistent) {
2113 size = super_types[my_mddev->major_version]. 2101 size = super_types[my_mddev->major_version].
@@ -2118,9 +2106,9 @@ rdev_size_store(mdk_rdev_t *rdev, const char *buf, size_t len)
2118 size = (rdev->bdev->bd_inode->i_size >> 10); 2106 size = (rdev->bdev->bd_inode->i_size >> 10);
2119 size -= rdev->data_offset/2; 2107 size -= rdev->data_offset/2;
2120 } 2108 }
2121 if (size < my_mddev->size)
2122 return -EINVAL; /* component must fit device */
2123 } 2109 }
2110 if (size < my_mddev->size)
2111 return -EINVAL; /* component must fit device */
2124 2112
2125 rdev->size = size; 2113 rdev->size = size;
2126 if (size > oldsize && my_mddev->external) { 2114 if (size > oldsize && my_mddev->external) {
@@ -2406,12 +2394,11 @@ safe_delay_store(mddev_t *mddev, const char *cbuf, size_t len)
2406 int i; 2394 int i;
2407 unsigned long msec; 2395 unsigned long msec;
2408 char buf[30]; 2396 char buf[30];
2409 char *e; 2397
2410 /* remove a period, and count digits after it */ 2398 /* remove a period, and count digits after it */
2411 if (len >= sizeof(buf)) 2399 if (len >= sizeof(buf))
2412 return -EINVAL; 2400 return -EINVAL;
2413 strlcpy(buf, cbuf, len); 2401 strlcpy(buf, cbuf, sizeof(buf));
2414 buf[len] = 0;
2415 for (i=0; i<len; i++) { 2402 for (i=0; i<len; i++) {
2416 if (dot) { 2403 if (dot) {
2417 if (isdigit(buf[i])) { 2404 if (isdigit(buf[i])) {
@@ -2424,8 +2411,7 @@ safe_delay_store(mddev_t *mddev, const char *cbuf, size_t len)
2424 buf[i] = 0; 2411 buf[i] = 0;
2425 } 2412 }
2426 } 2413 }
2427 msec = simple_strtoul(buf, &e, 10); 2414 if (strict_strtoul(buf, 10, &msec) < 0)
2428 if (e == buf || (*e && *e != '\n'))
2429 return -EINVAL; 2415 return -EINVAL;
2430 msec = (msec * 1000) / scale; 2416 msec = (msec * 1000) / scale;
2431 if (msec == 0) 2417 if (msec == 0)
@@ -2727,9 +2713,9 @@ array_state_store(mddev_t *mddev, const char *buf, size_t len)
2727 break; 2713 break;
2728 case read_auto: 2714 case read_auto:
2729 if (mddev->pers) { 2715 if (mddev->pers) {
2730 if (mddev->ro != 1) 2716 if (mddev->ro == 0)
2731 err = do_md_stop(mddev, 1, 0); 2717 err = do_md_stop(mddev, 1, 0);
2732 else 2718 else if (mddev->ro == 1)
2733 err = restart_array(mddev); 2719 err = restart_array(mddev);
2734 if (err == 0) { 2720 if (err == 0) {
2735 mddev->ro = 2; 2721 mddev->ro = 2;
@@ -2945,7 +2931,13 @@ metadata_store(mddev_t *mddev, const char *buf, size_t len)
2945{ 2931{
2946 int major, minor; 2932 int major, minor;
2947 char *e; 2933 char *e;
2948 if (!list_empty(&mddev->disks)) 2934 /* Changing the details of 'external' metadata is
2935 * always permitted. Otherwise there must be
2936 * no devices attached to the array.
2937 */
2938 if (mddev->external && strncmp(buf, "external:", 9) == 0)
2939 ;
2940 else if (!list_empty(&mddev->disks))
2949 return -EBUSY; 2941 return -EBUSY;
2950 2942
2951 if (cmd_match(buf, "none")) { 2943 if (cmd_match(buf, "none")) {
@@ -3527,17 +3519,12 @@ static int do_md_run(mddev_t * mddev)
3527 return -EINVAL; 3519 return -EINVAL;
3528 } 3520 }
3529 /* 3521 /*
3530 * chunk-size has to be a power of 2 and multiples of PAGE_SIZE 3522 * chunk-size has to be a power of 2
3531 */ 3523 */
3532 if ( (1 << ffz(~chunk_size)) != chunk_size) { 3524 if ( (1 << ffz(~chunk_size)) != chunk_size) {
3533 printk(KERN_ERR "chunk_size of %d not valid\n", chunk_size); 3525 printk(KERN_ERR "chunk_size of %d not valid\n", chunk_size);
3534 return -EINVAL; 3526 return -EINVAL;
3535 } 3527 }
3536 if (chunk_size < PAGE_SIZE) {
3537 printk(KERN_ERR "too small chunk_size: %d < %ld\n",
3538 chunk_size, PAGE_SIZE);
3539 return -EINVAL;
3540 }
3541 3528
3542 /* devices must have minimum size of one chunk */ 3529 /* devices must have minimum size of one chunk */
3543 rdev_for_each(rdev, tmp, mddev) { 3530 rdev_for_each(rdev, tmp, mddev) {
@@ -3555,12 +3542,10 @@ static int do_md_run(mddev_t * mddev)
3555 } 3542 }
3556 } 3543 }
3557 3544
3558#ifdef CONFIG_KMOD
3559 if (mddev->level != LEVEL_NONE) 3545 if (mddev->level != LEVEL_NONE)
3560 request_module("md-level-%d", mddev->level); 3546 request_module("md-level-%d", mddev->level);
3561 else if (mddev->clevel[0]) 3547 else if (mddev->clevel[0])
3562 request_module("md-%s", mddev->clevel); 3548 request_module("md-%s", mddev->clevel);
3563#endif
3564 3549
3565 /* 3550 /*
3566 * Drop all container device buffers, from now on 3551 * Drop all container device buffers, from now on
@@ -3971,10 +3956,10 @@ static void autorun_array(mddev_t *mddev)
3971 } 3956 }
3972 printk("\n"); 3957 printk("\n");
3973 3958
3974 err = do_md_run (mddev); 3959 err = do_md_run(mddev);
3975 if (err) { 3960 if (err) {
3976 printk(KERN_WARNING "md: do_md_run() returned %d\n", err); 3961 printk(KERN_WARNING "md: do_md_run() returned %d\n", err);
3977 do_md_stop (mddev, 0, 0); 3962 do_md_stop(mddev, 0, 0);
3978 } 3963 }
3979} 3964}
3980 3965
@@ -4333,7 +4318,7 @@ static int add_new_disk(mddev_t * mddev, mdu_disk_info_t *info)
4333 4318
4334 if (!(info->state & (1<<MD_DISK_FAULTY))) { 4319 if (!(info->state & (1<<MD_DISK_FAULTY))) {
4335 int err; 4320 int err;
4336 rdev = md_import_device (dev, -1, 0); 4321 rdev = md_import_device(dev, -1, 0);
4337 if (IS_ERR(rdev)) { 4322 if (IS_ERR(rdev)) {
4338 printk(KERN_WARNING 4323 printk(KERN_WARNING
4339 "md: error, md_import_device() returned %ld\n", 4324 "md: error, md_import_device() returned %ld\n",
@@ -4415,7 +4400,7 @@ static int hot_add_disk(mddev_t * mddev, dev_t dev)
4415 return -EINVAL; 4400 return -EINVAL;
4416 } 4401 }
4417 4402
4418 rdev = md_import_device (dev, -1, 0); 4403 rdev = md_import_device(dev, -1, 0);
4419 if (IS_ERR(rdev)) { 4404 if (IS_ERR(rdev)) {
4420 printk(KERN_WARNING 4405 printk(KERN_WARNING
4421 "md: error, md_import_device() returned %ld\n", 4406 "md: error, md_import_device() returned %ld\n",
@@ -4934,11 +4919,11 @@ static int md_ioctl(struct inode *inode, struct file *file,
4934 goto done_unlock; 4919 goto done_unlock;
4935 4920
4936 case STOP_ARRAY: 4921 case STOP_ARRAY:
4937 err = do_md_stop (mddev, 0, 1); 4922 err = do_md_stop(mddev, 0, 1);
4938 goto done_unlock; 4923 goto done_unlock;
4939 4924
4940 case STOP_ARRAY_RO: 4925 case STOP_ARRAY_RO:
4941 err = do_md_stop (mddev, 1, 1); 4926 err = do_md_stop(mddev, 1, 1);
4942 goto done_unlock; 4927 goto done_unlock;
4943 4928
4944 } 4929 }
@@ -4987,7 +4972,7 @@ static int md_ioctl(struct inode *inode, struct file *file,
4987 goto done_unlock; 4972 goto done_unlock;
4988 4973
4989 case RUN_ARRAY: 4974 case RUN_ARRAY:
4990 err = do_md_run (mddev); 4975 err = do_md_run(mddev);
4991 goto done_unlock; 4976 goto done_unlock;
4992 4977
4993 case SET_BITMAP_FILE: 4978 case SET_BITMAP_FILE:
@@ -5425,11 +5410,11 @@ static int md_seq_show(struct seq_file *seq, void *v)
5425 seq_printf(seq, " super non-persistent"); 5410 seq_printf(seq, " super non-persistent");
5426 5411
5427 if (mddev->pers) { 5412 if (mddev->pers) {
5428 mddev->pers->status (seq, mddev); 5413 mddev->pers->status(seq, mddev);
5429 seq_printf(seq, "\n "); 5414 seq_printf(seq, "\n ");
5430 if (mddev->pers->sync_request) { 5415 if (mddev->pers->sync_request) {
5431 if (mddev->curr_resync > 2) { 5416 if (mddev->curr_resync > 2) {
5432 status_resync (seq, mddev); 5417 status_resync(seq, mddev);
5433 seq_printf(seq, "\n "); 5418 seq_printf(seq, "\n ");
5434 } else if (mddev->curr_resync == 1 || mddev->curr_resync == 2) 5419 } else if (mddev->curr_resync == 1 || mddev->curr_resync == 2)
5435 seq_printf(seq, "\tresync=DELAYED\n "); 5420 seq_printf(seq, "\tresync=DELAYED\n ");
@@ -6260,7 +6245,7 @@ static int md_notify_reboot(struct notifier_block *this,
6260 * appears to still be in use. Hence 6245 * appears to still be in use. Hence
6261 * the '100'. 6246 * the '100'.
6262 */ 6247 */
6263 do_md_stop (mddev, 1, 100); 6248 do_md_stop(mddev, 1, 100);
6264 mddev_unlock(mddev); 6249 mddev_unlock(mddev);
6265 } 6250 }
6266 /* 6251 /*
@@ -6304,7 +6289,7 @@ static int __init md_init(void)
6304 raid_table_header = register_sysctl_table(raid_root_table); 6289 raid_table_header = register_sysctl_table(raid_root_table);
6305 6290
6306 md_geninit(); 6291 md_geninit();
6307 return (0); 6292 return 0;
6308} 6293}
6309 6294
6310 6295
diff --git a/drivers/md/multipath.c b/drivers/md/multipath.c
index 7ae33ebaf7ec..d4ac47d11279 100644
--- a/drivers/md/multipath.c
+++ b/drivers/md/multipath.c
@@ -19,16 +19,7 @@
19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */ 20 */
21 21
22#include <linux/module.h>
23#include <linux/slab.h>
24#include <linux/spinlock.h>
25#include <linux/raid/multipath.h> 22#include <linux/raid/multipath.h>
26#include <linux/buffer_head.h>
27#include <asm/atomic.h>
28
29#define MAJOR_NR MD_MAJOR
30#define MD_DRIVER
31#define MD_PERSONALITY
32 23
33#define MAX_WORK_PER_DISK 128 24#define MAX_WORK_PER_DISK 128
34 25
diff --git a/drivers/md/raid0.c b/drivers/md/raid0.c
index 53508a8a981d..8ac6488ad0dc 100644
--- a/drivers/md/raid0.c
+++ b/drivers/md/raid0.c
@@ -18,13 +18,8 @@
18 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 18 Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/ 19*/
20 20
21#include <linux/module.h>
22#include <linux/raid/raid0.h> 21#include <linux/raid/raid0.h>
23 22
24#define MAJOR_NR MD_MAJOR
25#define MD_DRIVER
26#define MD_PERSONALITY
27
28static void raid0_unplug(struct request_queue *q) 23static void raid0_unplug(struct request_queue *q)
29{ 24{
30 mddev_t *mddev = q->queuedata; 25 mddev_t *mddev = q->queuedata;
diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
index b9764429d856..9c788e2489b1 100644
--- a/drivers/md/raid1.c
+++ b/drivers/md/raid1.c
@@ -32,6 +32,7 @@
32 */ 32 */
33 33
34#include "dm-bio-list.h" 34#include "dm-bio-list.h"
35#include <linux/delay.h>
35#include <linux/raid/raid1.h> 36#include <linux/raid/raid1.h>
36#include <linux/raid/bitmap.h> 37#include <linux/raid/bitmap.h>
37 38
diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
index 8bdc9bfc2887..da5129a24b18 100644
--- a/drivers/md/raid10.c
+++ b/drivers/md/raid10.c
@@ -19,6 +19,7 @@
19 */ 19 */
20 20
21#include "dm-bio-list.h" 21#include "dm-bio-list.h"
22#include <linux/delay.h>
22#include <linux/raid/raid10.h> 23#include <linux/raid/raid10.h>
23#include <linux/raid/bitmap.h> 24#include <linux/raid/bitmap.h>
24 25
@@ -2028,8 +2029,9 @@ static int run(mddev_t *mddev)
2028 int nc, fc, fo; 2029 int nc, fc, fo;
2029 sector_t stride, size; 2030 sector_t stride, size;
2030 2031
2031 if (mddev->chunk_size == 0) { 2032 if (mddev->chunk_size < PAGE_SIZE) {
2032 printk(KERN_ERR "md/raid10: non-zero chunk size required.\n"); 2033 printk(KERN_ERR "md/raid10: chunk size must be "
2034 "at least PAGE_SIZE(%ld).\n", PAGE_SIZE);
2033 return -EINVAL; 2035 return -EINVAL;
2034 } 2036 }
2035 2037
diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
index ae16794bef20..a36a7435edf5 100644
--- a/drivers/md/raid5.c
+++ b/drivers/md/raid5.c
@@ -43,12 +43,7 @@
43 * miss any bits. 43 * miss any bits.
44 */ 44 */
45 45
46#include <linux/module.h>
47#include <linux/slab.h>
48#include <linux/highmem.h>
49#include <linux/bitops.h>
50#include <linux/kthread.h> 46#include <linux/kthread.h>
51#include <asm/atomic.h>
52#include "raid6.h" 47#include "raid6.h"
53 48
54#include <linux/raid/bitmap.h> 49#include <linux/raid/bitmap.h>
@@ -275,7 +270,7 @@ static int grow_buffers(struct stripe_head *sh, int num)
275 return 0; 270 return 0;
276} 271}
277 272
278static void raid5_build_block (struct stripe_head *sh, int i); 273static void raid5_build_block(struct stripe_head *sh, int i);
279 274
280static void init_stripe(struct stripe_head *sh, sector_t sector, int pd_idx, int disks) 275static void init_stripe(struct stripe_head *sh, sector_t sector, int pd_idx, int disks)
281{ 276{
@@ -1151,7 +1146,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
1151 release_stripe(sh); 1146 release_stripe(sh);
1152} 1147}
1153 1148
1154static void raid5_end_write_request (struct bio *bi, int error) 1149static void raid5_end_write_request(struct bio *bi, int error)
1155{ 1150{
1156 struct stripe_head *sh = bi->bi_private; 1151 struct stripe_head *sh = bi->bi_private;
1157 raid5_conf_t *conf = sh->raid_conf; 1152 raid5_conf_t *conf = sh->raid_conf;
@@ -1183,7 +1178,7 @@ static void raid5_end_write_request (struct bio *bi, int error)
1183 1178
1184static sector_t compute_blocknr(struct stripe_head *sh, int i); 1179static sector_t compute_blocknr(struct stripe_head *sh, int i);
1185 1180
1186static void raid5_build_block (struct stripe_head *sh, int i) 1181static void raid5_build_block(struct stripe_head *sh, int i)
1187{ 1182{
1188 struct r5dev *dev = &sh->dev[i]; 1183 struct r5dev *dev = &sh->dev[i];
1189 1184
@@ -1221,10 +1216,10 @@ static void error(mddev_t *mddev, mdk_rdev_t *rdev)
1221 set_bit(MD_RECOVERY_INTR, &mddev->recovery); 1216 set_bit(MD_RECOVERY_INTR, &mddev->recovery);
1222 } 1217 }
1223 set_bit(Faulty, &rdev->flags); 1218 set_bit(Faulty, &rdev->flags);
1224 printk (KERN_ALERT 1219 printk(KERN_ALERT
1225 "raid5: Disk failure on %s, disabling device.\n" 1220 "raid5: Disk failure on %s, disabling device.\n"
1226 "raid5: Operation continuing on %d devices.\n", 1221 "raid5: Operation continuing on %d devices.\n",
1227 bdevname(rdev->bdev,b), conf->raid_disks - mddev->degraded); 1222 bdevname(rdev->bdev,b), conf->raid_disks - mddev->degraded);
1228 } 1223 }
1229} 1224}
1230 1225
@@ -1320,8 +1315,8 @@ static sector_t raid5_compute_sector(sector_t r_sector, unsigned int raid_disks,
1320 *dd_idx = (*pd_idx + 2 + *dd_idx) % raid_disks; 1315 *dd_idx = (*pd_idx + 2 + *dd_idx) % raid_disks;
1321 break; 1316 break;
1322 default: 1317 default:
1323 printk (KERN_CRIT "raid6: unsupported algorithm %d\n", 1318 printk(KERN_CRIT "raid6: unsupported algorithm %d\n",
1324 conf->algorithm); 1319 conf->algorithm);
1325 } 1320 }
1326 break; 1321 break;
1327 } 1322 }
@@ -1396,8 +1391,8 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i)
1396 } 1391 }
1397 break; 1392 break;
1398 default: 1393 default:
1399 printk (KERN_CRIT "raid6: unsupported algorithm %d\n", 1394 printk(KERN_CRIT "raid6: unsupported algorithm %d\n",
1400 conf->algorithm); 1395 conf->algorithm);
1401 } 1396 }
1402 break; 1397 break;
1403 } 1398 }
@@ -1405,7 +1400,7 @@ static sector_t compute_blocknr(struct stripe_head *sh, int i)
1405 chunk_number = stripe * data_disks + i; 1400 chunk_number = stripe * data_disks + i;
1406 r_sector = (sector_t)chunk_number * sectors_per_chunk + chunk_offset; 1401 r_sector = (sector_t)chunk_number * sectors_per_chunk + chunk_offset;
1407 1402
1408 check = raid5_compute_sector (r_sector, raid_disks, data_disks, &dummy1, &dummy2, conf); 1403 check = raid5_compute_sector(r_sector, raid_disks, data_disks, &dummy1, &dummy2, conf);
1409 if (check != sh->sector || dummy1 != dd_idx || dummy2 != sh->pd_idx) { 1404 if (check != sh->sector || dummy1 != dd_idx || dummy2 != sh->pd_idx) {
1410 printk(KERN_ERR "compute_blocknr: map not correct\n"); 1405 printk(KERN_ERR "compute_blocknr: map not correct\n");
1411 return 0; 1406 return 0;
@@ -4012,6 +4007,13 @@ static int run(mddev_t *mddev)
4012 return -EIO; 4007 return -EIO;
4013 } 4008 }
4014 4009
4010 if (mddev->chunk_size < PAGE_SIZE) {
4011 printk(KERN_ERR "md/raid5: chunk_size must be at least "
4012 "PAGE_SIZE but %d < %ld\n",
4013 mddev->chunk_size, PAGE_SIZE);
4014 return -EINVAL;
4015 }
4016
4015 if (mddev->reshape_position != MaxSector) { 4017 if (mddev->reshape_position != MaxSector) {
4016 /* Check that we can continue the reshape. 4018 /* Check that we can continue the reshape.
4017 * Currently only disks can change, it must 4019 * Currently only disks can change, it must
@@ -4289,7 +4291,7 @@ static int stop(mddev_t *mddev)
4289} 4291}
4290 4292
4291#ifdef DEBUG 4293#ifdef DEBUG
4292static void print_sh (struct seq_file *seq, struct stripe_head *sh) 4294static void print_sh(struct seq_file *seq, struct stripe_head *sh)
4293{ 4295{
4294 int i; 4296 int i;
4295 4297
@@ -4305,7 +4307,7 @@ static void print_sh (struct seq_file *seq, struct stripe_head *sh)
4305 seq_printf(seq, "\n"); 4307 seq_printf(seq, "\n");
4306} 4308}
4307 4309
4308static void printall (struct seq_file *seq, raid5_conf_t *conf) 4310static void printall(struct seq_file *seq, raid5_conf_t *conf)
4309{ 4311{
4310 struct stripe_head *sh; 4312 struct stripe_head *sh;
4311 struct hlist_node *hn; 4313 struct hlist_node *hn;
@@ -4323,7 +4325,7 @@ static void printall (struct seq_file *seq, raid5_conf_t *conf)
4323} 4325}
4324#endif 4326#endif
4325 4327
4326static void status (struct seq_file *seq, mddev_t *mddev) 4328static void status(struct seq_file *seq, mddev_t *mddev)
4327{ 4329{
4328 raid5_conf_t *conf = (raid5_conf_t *) mddev->private; 4330 raid5_conf_t *conf = (raid5_conf_t *) mddev->private;
4329 int i; 4331 int i;
diff --git a/drivers/md/raid6.h b/drivers/md/raid6.h
index 31cbee71365f..98dcde88470e 100644
--- a/drivers/md/raid6.h
+++ b/drivers/md/raid6.h
@@ -18,15 +18,6 @@
18/* Set to 1 to use kernel-wide empty_zero_page */ 18/* Set to 1 to use kernel-wide empty_zero_page */
19#define RAID6_USE_EMPTY_ZERO_PAGE 0 19#define RAID6_USE_EMPTY_ZERO_PAGE 0
20 20
21#include <linux/module.h>
22#include <linux/stddef.h>
23#include <linux/compiler.h>
24#include <linux/types.h>
25#include <linux/kernel.h>
26#include <linux/errno.h>
27#include <linux/mempool.h>
28#include <linux/list.h>
29#include <linux/vmalloc.h>
30#include <linux/raid/md.h> 21#include <linux/raid/md.h>
31#include <linux/raid/raid5.h> 22#include <linux/raid/raid5.h>
32 23
diff --git a/drivers/media/common/ir-keymaps.c b/drivers/media/common/ir-keymaps.c
index 8fa91f846d59..4952aeb5dd80 100644
--- a/drivers/media/common/ir-keymaps.c
+++ b/drivers/media/common/ir-keymaps.c
@@ -103,6 +103,56 @@ IR_KEYTAB_TYPE ir_codes_avermedia_dvbt[IR_KEYTAB_SIZE] = {
103 103
104EXPORT_SYMBOL_GPL(ir_codes_avermedia_dvbt); 104EXPORT_SYMBOL_GPL(ir_codes_avermedia_dvbt);
105 105
106/* Mauro Carvalho Chehab <mchehab@infradead.org> */
107IR_KEYTAB_TYPE ir_codes_avermedia_m135a[IR_KEYTAB_SIZE] = {
108 [0x00] = KEY_POWER2,
109 [0x2e] = KEY_DOT, /* '.' */
110 [0x01] = KEY_MODE, /* TV/FM */
111
112 [0x05] = KEY_1,
113 [0x06] = KEY_2,
114 [0x07] = KEY_3,
115 [0x09] = KEY_4,
116 [0x0a] = KEY_5,
117 [0x0b] = KEY_6,
118 [0x0d] = KEY_7,
119 [0x0e] = KEY_8,
120 [0x0f] = KEY_9,
121 [0x11] = KEY_0,
122
123 [0x13] = KEY_RIGHT, /* -> */
124 [0x12] = KEY_LEFT, /* <- */
125
126 [0x17] = KEY_SLEEP, /* Capturar Imagem */
127 [0x10] = KEY_SHUFFLE, /* Amostra */
128
129 /* FIXME: The keys bellow aren't ok */
130
131 [0x43] = KEY_CHANNELUP,
132 [0x42] = KEY_CHANNELDOWN,
133 [0x1f] = KEY_VOLUMEUP,
134 [0x1e] = KEY_VOLUMEDOWN,
135 [0x0c] = KEY_ENTER,
136
137 [0x14] = KEY_MUTE,
138 [0x08] = KEY_AUDIO,
139
140 [0x03] = KEY_TEXT,
141 [0x04] = KEY_EPG,
142 [0x2b] = KEY_TV2, /* TV2 */
143
144 [0x1d] = KEY_RED,
145 [0x1c] = KEY_YELLOW,
146 [0x41] = KEY_GREEN,
147 [0x40] = KEY_BLUE,
148
149 [0x1a] = KEY_PLAYPAUSE,
150 [0x19] = KEY_RECORD,
151 [0x18] = KEY_PLAY,
152 [0x1b] = KEY_STOP,
153};
154EXPORT_SYMBOL_GPL(ir_codes_avermedia_m135a);
155
106/* Attila Kondoros <attila.kondoros@chello.hu> */ 156/* Attila Kondoros <attila.kondoros@chello.hu> */
107IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE] = { 157IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE] = {
108 158
@@ -467,7 +517,8 @@ EXPORT_SYMBOL_GPL(ir_codes_adstech_dvb_t_pci);
467 517
468/* ---------------------------------------------------------------------- */ 518/* ---------------------------------------------------------------------- */
469 519
470/* MSI TV@nywhere remote */ 520/* MSI TV@nywhere MASTER remote */
521
471IR_KEYTAB_TYPE ir_codes_msi_tvanywhere[IR_KEYTAB_SIZE] = { 522IR_KEYTAB_TYPE ir_codes_msi_tvanywhere[IR_KEYTAB_SIZE] = {
472 /* Keys 0 to 9 */ 523 /* Keys 0 to 9 */
473 [ 0x00 ] = KEY_0, 524 [ 0x00 ] = KEY_0,
@@ -501,6 +552,95 @@ EXPORT_SYMBOL_GPL(ir_codes_msi_tvanywhere);
501 552
502/* ---------------------------------------------------------------------- */ 553/* ---------------------------------------------------------------------- */
503 554
555/*
556 Keycodes for remote on the MSI TV@nywhere Plus. The controller IC on the card
557 is marked "KS003". The controller is I2C at address 0x30, but does not seem
558 to respond to probes until a read is performed from a valid device.
559 I don't know why...
560
561 Note: This remote may be of similar or identical design to the
562 Pixelview remote (?). The raw codes and duplicate button codes
563 appear to be the same.
564
565 Henry Wong <henry@stuffedcow.net>
566 Some changes to formatting and keycodes by Mark Schultz <n9xmj@yahoo.com>
567
568*/
569
570IR_KEYTAB_TYPE ir_codes_msi_tvanywhere_plus[IR_KEYTAB_SIZE] = {
571
572/* ---- Remote Button Layout ----
573
574 POWER SOURCE SCAN MUTE
575 TV/FM 1 2 3
576 |> 4 5 6
577 <| 7 8 9
578 ^^UP 0 + RECALL
579 vvDN RECORD STOP PLAY
580
581 MINIMIZE ZOOM
582
583 CH+
584 VOL- VOL+
585 CH-
586
587 SNAPSHOT MTS
588
589 << FUNC >> RESET
590*/
591
592 [0x01] = KEY_KP1, /* 1 */
593 [0x0b] = KEY_KP2, /* 2 */
594 [0x1b] = KEY_KP3, /* 3 */
595 [0x05] = KEY_KP4, /* 4 */
596 [0x09] = KEY_KP5, /* 5 */
597 [0x15] = KEY_KP6, /* 6 */
598 [0x06] = KEY_KP7, /* 7 */
599 [0x0a] = KEY_KP8, /* 8 */
600 [0x12] = KEY_KP9, /* 9 */
601 [0x02] = KEY_KP0, /* 0 */
602 [0x10] = KEY_KPPLUS, /* + */
603 [0x13] = KEY_AGAIN, /* Recall */
604
605 [0x1e] = KEY_POWER, /* Power */
606 [0x07] = KEY_TUNER, /* Source */
607 [0x1c] = KEY_SEARCH, /* Scan */
608 [0x18] = KEY_MUTE, /* Mute */
609
610 [0x03] = KEY_RADIO, /* TV/FM */
611 /* The next four keys are duplicates that appear to send the
612 same IR code as Ch+, Ch-, >>, and << . The raw code assigned
613 to them is the actual code + 0x20 - they will never be
614 detected as such unless some way is discovered to distinguish
615 these buttons from those that have the same code. */
616 [0x3f] = KEY_RIGHT, /* |> and Ch+ */
617 [0x37] = KEY_LEFT, /* <| and Ch- */
618 [0x2c] = KEY_UP, /* ^^Up and >> */
619 [0x24] = KEY_DOWN, /* vvDn and << */
620
621 [0x00] = KEY_RECORD, /* Record */
622 [0x08] = KEY_STOP, /* Stop */
623 [0x11] = KEY_PLAY, /* Play */
624
625 [0x0f] = KEY_CLOSE, /* Minimize */
626 [0x19] = KEY_ZOOM, /* Zoom */
627 [0x1a] = KEY_SHUFFLE, /* Snapshot */
628 [0x0d] = KEY_LANGUAGE, /* MTS */
629
630 [0x14] = KEY_VOLUMEDOWN, /* Vol- */
631 [0x16] = KEY_VOLUMEUP, /* Vol+ */
632 [0x17] = KEY_CHANNELDOWN, /* Ch- */
633 [0x1f] = KEY_CHANNELUP, /* Ch+ */
634
635 [0x04] = KEY_REWIND, /* << */
636 [0x0e] = KEY_MENU, /* Function */
637 [0x0c] = KEY_FASTFORWARD, /* >> */
638 [0x1d] = KEY_RESTART, /* Reset */
639};
640EXPORT_SYMBOL_GPL(ir_codes_msi_tvanywhere_plus);
641
642/* ---------------------------------------------------------------------- */
643
504/* Cinergy 1400 DVB-T */ 644/* Cinergy 1400 DVB-T */
505IR_KEYTAB_TYPE ir_codes_cinergy_1400[IR_KEYTAB_SIZE] = { 645IR_KEYTAB_TYPE ir_codes_cinergy_1400[IR_KEYTAB_SIZE] = {
506 [ 0x01 ] = KEY_POWER, 646 [ 0x01 ] = KEY_POWER,
@@ -1792,12 +1932,61 @@ IR_KEYTAB_TYPE ir_codes_encore_enltv[IR_KEYTAB_SIZE] = {
1792 [ 0x41 ] = KEY_GREEN, /* AP2 */ 1932 [ 0x41 ] = KEY_GREEN, /* AP2 */
1793 [ 0x47 ] = KEY_YELLOW, /* AP3 */ 1933 [ 0x47 ] = KEY_YELLOW, /* AP3 */
1794 [ 0x57 ] = KEY_BLUE, /* AP4 */ 1934 [ 0x57 ] = KEY_BLUE, /* AP4 */
1795
1796
1797}; 1935};
1798
1799EXPORT_SYMBOL_GPL(ir_codes_encore_enltv); 1936EXPORT_SYMBOL_GPL(ir_codes_encore_enltv);
1800 1937
1938/* Encore ENLTV2-FM - silver plastic - "Wand Media" written at the botton
1939 Mauro Carvalho Chehab <mchehab@infradead.org> */
1940IR_KEYTAB_TYPE ir_codes_encore_enltv2[IR_KEYTAB_SIZE] = {
1941 [0x4c] = KEY_POWER2,
1942 [0x4a] = KEY_TUNER,
1943 [0x40] = KEY_1,
1944 [0x60] = KEY_2,
1945 [0x50] = KEY_3,
1946 [0x70] = KEY_4,
1947 [0x48] = KEY_5,
1948 [0x68] = KEY_6,
1949 [0x58] = KEY_7,
1950 [0x78] = KEY_8,
1951 [0x44] = KEY_9,
1952 [0x54] = KEY_0,
1953
1954 [0x64] = KEY_LAST, /* +100 */
1955 [0x4e] = KEY_AGAIN, /* Recall */
1956
1957 [0x6c] = KEY_SWITCHVIDEOMODE, /* Video Source */
1958 [0x5e] = KEY_MENU,
1959 [0x56] = KEY_SCREEN,
1960 [0x7a] = KEY_SETUP,
1961
1962 [0x46] = KEY_MUTE,
1963 [0x5c] = KEY_MODE, /* Stereo */
1964 [0x74] = KEY_INFO,
1965 [0x7c] = KEY_CLEAR,
1966
1967 [0x55] = KEY_UP,
1968 [0x49] = KEY_DOWN,
1969 [0x7e] = KEY_LEFT,
1970 [0x59] = KEY_RIGHT,
1971 [0x6a] = KEY_ENTER,
1972
1973 [0x42] = KEY_VOLUMEUP,
1974 [0x62] = KEY_VOLUMEDOWN,
1975 [0x52] = KEY_CHANNELUP,
1976 [0x72] = KEY_CHANNELDOWN,
1977
1978 [0x41] = KEY_RECORD,
1979 [0x51] = KEY_SHUFFLE, /* Snapshot */
1980 [0x75] = KEY_TIME, /* Timeshift */
1981 [0x71] = KEY_TV2, /* PIP */
1982
1983 [0x45] = KEY_REWIND,
1984 [0x6f] = KEY_PAUSE,
1985 [0x7d] = KEY_FORWARD,
1986 [0x79] = KEY_STOP,
1987};
1988EXPORT_SYMBOL_GPL(ir_codes_encore_enltv2);
1989
1801/* for the Technotrend 1500 bundled remotes (grey and black): */ 1990/* for the Technotrend 1500 bundled remotes (grey and black): */
1802IR_KEYTAB_TYPE ir_codes_tt_1500[IR_KEYTAB_SIZE] = { 1991IR_KEYTAB_TYPE ir_codes_tt_1500[IR_KEYTAB_SIZE] = {
1803 [ 0x01 ] = KEY_POWER, 1992 [ 0x01 ] = KEY_POWER,
@@ -2239,3 +2428,86 @@ IR_KEYTAB_TYPE ir_codes_avermedia_a16d[IR_KEYTAB_SIZE] = {
2239 [0x2a] = KEY_MENU, 2428 [0x2a] = KEY_MENU,
2240}; 2429};
2241EXPORT_SYMBOL_GPL(ir_codes_avermedia_a16d); 2430EXPORT_SYMBOL_GPL(ir_codes_avermedia_a16d);
2431
2432/* Encore ENLTV-FM v5.3
2433 Mauro Carvalho Chehab <mchehab@infradead.org>
2434 */
2435IR_KEYTAB_TYPE ir_codes_encore_enltv_fm53[IR_KEYTAB_SIZE] = {
2436 [0x10] = KEY_POWER2,
2437 [0x06] = KEY_MUTE,
2438
2439 [0x09] = KEY_1,
2440 [0x1d] = KEY_2,
2441 [0x1f] = KEY_3,
2442 [0x19] = KEY_4,
2443 [0x1b] = KEY_5,
2444 [0x11] = KEY_6,
2445 [0x17] = KEY_7,
2446 [0x12] = KEY_8,
2447 [0x16] = KEY_9,
2448 [0x48] = KEY_0,
2449
2450 [0x04] = KEY_LIST, /* -/-- */
2451 [0x40] = KEY_LAST, /* recall */
2452
2453 [0x02] = KEY_MODE, /* TV/AV */
2454 [0x05] = KEY_SHUFFLE, /* SNAPSHOT */
2455
2456 [0x4c] = KEY_CHANNELUP, /* UP */
2457 [0x00] = KEY_CHANNELDOWN, /* DOWN */
2458 [0x0d] = KEY_VOLUMEUP, /* RIGHT */
2459 [0x15] = KEY_VOLUMEDOWN, /* LEFT */
2460 [0x49] = KEY_ENTER, /* OK */
2461
2462 [0x54] = KEY_RECORD,
2463 [0x4d] = KEY_PLAY, /* pause */
2464
2465 [0x1e] = KEY_UP, /* video setting */
2466 [0x0e] = KEY_RIGHT, /* <- */
2467 [0x1a] = KEY_LEFT, /* -> */
2468
2469 [0x0a] = KEY_DOWN, /* video default */
2470 [0x0c] = KEY_ZOOM, /* hide pannel */
2471 [0x47] = KEY_SLEEP, /* shutdown */
2472};
2473EXPORT_SYMBOL_GPL(ir_codes_encore_enltv_fm53);
2474
2475/* Zogis Real Audio 220 - 32 keys IR */
2476IR_KEYTAB_TYPE ir_codes_real_audio_220_32_keys[IR_KEYTAB_SIZE] = {
2477 [0x1c] = KEY_RADIO,
2478 [0x12] = KEY_POWER2,
2479
2480 [0x01] = KEY_1,
2481 [0x02] = KEY_2,
2482 [0x03] = KEY_3,
2483 [0x04] = KEY_4,
2484 [0x05] = KEY_5,
2485 [0x06] = KEY_6,
2486 [0x07] = KEY_7,
2487 [0x08] = KEY_8,
2488 [0x09] = KEY_9,
2489 [0x00] = KEY_0,
2490
2491 [0x0c] = KEY_VOLUMEUP,
2492 [0x18] = KEY_VOLUMEDOWN,
2493 [0x0b] = KEY_CHANNELUP,
2494 [0x15] = KEY_CHANNELDOWN,
2495 [0x16] = KEY_ENTER,
2496
2497 [0x11] = KEY_LIST, /* Source */
2498 [0x0d] = KEY_AUDIO, /* stereo */
2499
2500 [0x0f] = KEY_PREVIOUS, /* Prev */
2501 [0x1b] = KEY_PAUSE, /* Timeshift */
2502 [0x1a] = KEY_NEXT, /* Next */
2503
2504 [0x0e] = KEY_STOP,
2505 [0x1f] = KEY_PLAY,
2506 [0x1e] = KEY_PLAYPAUSE, /* Pause */
2507
2508 [0x1d] = KEY_RECORD,
2509 [0x13] = KEY_MUTE,
2510 [0x19] = KEY_SHUFFLE, /* Snapshot */
2511
2512};
2513EXPORT_SYMBOL_GPL(ir_codes_real_audio_220_32_keys);
diff --git a/drivers/media/common/saa7146_core.c b/drivers/media/common/saa7146_core.c
index d01965e96927..d599d360da3f 100644
--- a/drivers/media/common/saa7146_core.c
+++ b/drivers/media/common/saa7146_core.c
@@ -234,7 +234,7 @@ void saa7146_pgtable_free(struct pci_dev *pci, struct saa7146_pgtable *pt)
234int saa7146_pgtable_alloc(struct pci_dev *pci, struct saa7146_pgtable *pt) 234int saa7146_pgtable_alloc(struct pci_dev *pci, struct saa7146_pgtable *pt)
235{ 235{
236 __le32 *cpu; 236 __le32 *cpu;
237 dma_addr_t dma_addr; 237 dma_addr_t dma_addr = 0;
238 238
239 cpu = pci_alloc_consistent(pci, PAGE_SIZE, &dma_addr); 239 cpu = pci_alloc_consistent(pci, PAGE_SIZE, &dma_addr);
240 if (NULL == cpu) { 240 if (NULL == cpu) {
diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c
index cf6a817d5059..5b34c134aa25 100644
--- a/drivers/media/common/saa7146_fops.c
+++ b/drivers/media/common/saa7146_fops.c
@@ -533,7 +533,7 @@ int saa7146_register_device(struct video_device **vid, struct saa7146_dev* dev,
533 memcpy(vfd, &device_template, sizeof(struct video_device)); 533 memcpy(vfd, &device_template, sizeof(struct video_device));
534 strlcpy(vfd->name, name, sizeof(vfd->name)); 534 strlcpy(vfd->name, name, sizeof(vfd->name));
535 vfd->release = video_device_release; 535 vfd->release = video_device_release;
536 vfd->priv = dev; 536 video_set_drvdata(vfd, dev);
537 537
538 // fixme: -1 should be an insmod parameter *for the extension* (like "video_nr"); 538 // fixme: -1 should be an insmod parameter *for the extension* (like "video_nr");
539 if (video_register_device(vfd, type, -1) < 0) { 539 if (video_register_device(vfd, type, -1) < 0) {
diff --git a/drivers/media/common/tuners/mt2060.c b/drivers/media/common/tuners/mt2060.c
index 1305b0e63ce5..12206d75dd4e 100644
--- a/drivers/media/common/tuners/mt2060.c
+++ b/drivers/media/common/tuners/mt2060.c
@@ -170,6 +170,9 @@ static int mt2060_set_params(struct dvb_frontend *fe, struct dvb_frontend_parame
170 b[0] = REG_LO1B1; 170 b[0] = REG_LO1B1;
171 b[1] = 0xFF; 171 b[1] = 0xFF;
172 172
173 if (fe->ops.i2c_gate_ctrl)
174 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
175
173 mt2060_writeregs(priv,b,2); 176 mt2060_writeregs(priv,b,2);
174 177
175 freq = params->frequency / 1000; // Hz -> kHz 178 freq = params->frequency / 1000; // Hz -> kHz
@@ -233,6 +236,9 @@ static int mt2060_set_params(struct dvb_frontend *fe, struct dvb_frontend_parame
233 i++; 236 i++;
234 } while (i<10); 237 } while (i<10);
235 238
239 if (fe->ops.i2c_gate_ctrl)
240 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
241
236 return ret; 242 return ret;
237} 243}
238 244
@@ -296,13 +302,35 @@ static int mt2060_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
296static int mt2060_init(struct dvb_frontend *fe) 302static int mt2060_init(struct dvb_frontend *fe)
297{ 303{
298 struct mt2060_priv *priv = fe->tuner_priv; 304 struct mt2060_priv *priv = fe->tuner_priv;
299 return mt2060_writereg(priv, REG_VGAG, (priv->cfg->clock_out << 6) | 0x33); 305 int ret;
306
307 if (fe->ops.i2c_gate_ctrl)
308 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
309
310 ret = mt2060_writereg(priv, REG_VGAG,
311 (priv->cfg->clock_out << 6) | 0x33);
312
313 if (fe->ops.i2c_gate_ctrl)
314 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
315
316 return ret;
300} 317}
301 318
302static int mt2060_sleep(struct dvb_frontend *fe) 319static int mt2060_sleep(struct dvb_frontend *fe)
303{ 320{
304 struct mt2060_priv *priv = fe->tuner_priv; 321 struct mt2060_priv *priv = fe->tuner_priv;
305 return mt2060_writereg(priv, REG_VGAG, (priv->cfg->clock_out << 6) | 0x30); 322 int ret;
323
324 if (fe->ops.i2c_gate_ctrl)
325 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
326
327 ret = mt2060_writereg(priv, REG_VGAG,
328 (priv->cfg->clock_out << 6) | 0x30);
329
330 if (fe->ops.i2c_gate_ctrl)
331 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
332
333 return ret;
306} 334}
307 335
308static int mt2060_release(struct dvb_frontend *fe) 336static int mt2060_release(struct dvb_frontend *fe)
@@ -344,6 +372,9 @@ struct dvb_frontend * mt2060_attach(struct dvb_frontend *fe, struct i2c_adapter
344 priv->i2c = i2c; 372 priv->i2c = i2c;
345 priv->if1_freq = if1; 373 priv->if1_freq = if1;
346 374
375 if (fe->ops.i2c_gate_ctrl)
376 fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
377
347 if (mt2060_readreg(priv,REG_PART_REV,&id) != 0) { 378 if (mt2060_readreg(priv,REG_PART_REV,&id) != 0) {
348 kfree(priv); 379 kfree(priv);
349 return NULL; 380 return NULL;
@@ -360,6 +391,9 @@ struct dvb_frontend * mt2060_attach(struct dvb_frontend *fe, struct i2c_adapter
360 391
361 mt2060_calibrate(priv); 392 mt2060_calibrate(priv);
362 393
394 if (fe->ops.i2c_gate_ctrl)
395 fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
396
363 return fe; 397 return fe;
364} 398}
365EXPORT_SYMBOL(mt2060_attach); 399EXPORT_SYMBOL(mt2060_attach);
diff --git a/drivers/media/common/tuners/mxl5007t.c b/drivers/media/common/tuners/mxl5007t.c
index cb25e43502fe..64379f2bf237 100644
--- a/drivers/media/common/tuners/mxl5007t.c
+++ b/drivers/media/common/tuners/mxl5007t.c
@@ -979,7 +979,6 @@ struct dvb_frontend *mxl5007t_attach(struct dvb_frontend *fe,
979 switch (instance) { 979 switch (instance) {
980 case 0: 980 case 0:
981 goto fail; 981 goto fail;
982 break;
983 case 1: 982 case 1:
984 /* new tuner instance */ 983 /* new tuner instance */
985 state->config = cfg; 984 state->config = cfg;
diff --git a/drivers/media/common/tuners/tda18271-fe.c b/drivers/media/common/tuners/tda18271-fe.c
index 93063c6fbbf6..1b48b5d0bf1e 100644
--- a/drivers/media/common/tuners/tda18271-fe.c
+++ b/drivers/media/common/tuners/tda18271-fe.c
@@ -1155,7 +1155,6 @@ struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
1155 switch (instance) { 1155 switch (instance) {
1156 case 0: 1156 case 0:
1157 goto fail; 1157 goto fail;
1158 break;
1159 case 1: 1158 case 1:
1160 /* new tuner instance */ 1159 /* new tuner instance */
1161 priv->gate = (cfg) ? cfg->gate : TDA18271_GATE_AUTO; 1160 priv->gate = (cfg) ? cfg->gate : TDA18271_GATE_AUTO;
diff --git a/drivers/media/common/tuners/tda827x.c b/drivers/media/common/tuners/tda827x.c
index 8555d9cf9051..4a74f65e759a 100644
--- a/drivers/media/common/tuners/tda827x.c
+++ b/drivers/media/common/tuners/tda827x.c
@@ -447,17 +447,19 @@ static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
447 else 447 else
448 arg = 0; 448 arg = 0;
449 } 449 }
450 if (priv->cfg->tuner_callback) 450 if (fe->callback)
451 priv->cfg->tuner_callback(priv->i2c_adap->algo_data, 451 fe->callback(priv->i2c_adap->algo_data,
452 gp_func, arg); 452 DVB_FRONTEND_COMPONENT_TUNER,
453 gp_func, arg);
453 buf[1] = high ? 0 : 1; 454 buf[1] = high ? 0 : 1;
454 if (priv->cfg->config == 2) 455 if (priv->cfg->config == 2)
455 buf[1] = high ? 1 : 0; 456 buf[1] = high ? 1 : 0;
456 i2c_transfer(priv->i2c_adap, &msg, 1); 457 i2c_transfer(priv->i2c_adap, &msg, 1);
457 break; 458 break;
458 case 3: /* switch with GPIO of saa713x */ 459 case 3: /* switch with GPIO of saa713x */
459 if (priv->cfg->tuner_callback) 460 if (fe->callback)
460 priv->cfg->tuner_callback(priv->i2c_adap->algo_data, 0, high); 461 fe->callback(priv->i2c_adap->algo_data,
462 DVB_FRONTEND_COMPONENT_TUNER, 0, high);
461 break; 463 break;
462 } 464 }
463} 465}
diff --git a/drivers/media/common/tuners/tda827x.h b/drivers/media/common/tuners/tda827x.h
index 7850a9a1dc8f..7d72ce0a0c2d 100644
--- a/drivers/media/common/tuners/tda827x.h
+++ b/drivers/media/common/tuners/tda827x.h
@@ -36,7 +36,6 @@ struct tda827x_config
36 /* interface to tda829x driver */ 36 /* interface to tda829x driver */
37 unsigned int config; 37 unsigned int config;
38 int switch_addr; 38 int switch_addr;
39 int (*tuner_callback) (void *dev, int command, int arg);
40 39
41 void (*agcf)(struct dvb_frontend *fe); 40 void (*agcf)(struct dvb_frontend *fe);
42}; 41};
diff --git a/drivers/media/common/tuners/tda8290.c b/drivers/media/common/tuners/tda8290.c
index 91204d3f282d..c112bdd4e0f0 100644
--- a/drivers/media/common/tuners/tda8290.c
+++ b/drivers/media/common/tuners/tda8290.c
@@ -672,10 +672,8 @@ struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
672 priv->i2c_props.addr = i2c_addr; 672 priv->i2c_props.addr = i2c_addr;
673 priv->i2c_props.adap = i2c_adap; 673 priv->i2c_props.adap = i2c_adap;
674 priv->i2c_props.name = "tda829x"; 674 priv->i2c_props.name = "tda829x";
675 if (cfg) { 675 if (cfg)
676 priv->cfg.config = cfg->lna_cfg; 676 priv->cfg.config = cfg->lna_cfg;
677 priv->cfg.tuner_callback = cfg->tuner_callback;
678 }
679 677
680 if (tda8290_probe(&priv->i2c_props) == 0) { 678 if (tda8290_probe(&priv->i2c_props) == 0) {
681 priv->ver = TDA8290; 679 priv->ver = TDA8290;
diff --git a/drivers/media/common/tuners/tda8290.h b/drivers/media/common/tuners/tda8290.h
index aa074f3f0c07..7e288b26fcc3 100644
--- a/drivers/media/common/tuners/tda8290.h
+++ b/drivers/media/common/tuners/tda8290.h
@@ -22,7 +22,6 @@
22 22
23struct tda829x_config { 23struct tda829x_config {
24 unsigned int lna_cfg; 24 unsigned int lna_cfg;
25 int (*tuner_callback) (void *dev, int command, int arg);
26 25
27 unsigned int probe_tuner:1; 26 unsigned int probe_tuner:1;
28#define TDA829X_PROBE_TUNER 0 27#define TDA829X_PROBE_TUNER 0
diff --git a/drivers/media/common/tuners/tda9887.c b/drivers/media/common/tuners/tda9887.c
index 72abf0b73486..ff1788cc5d48 100644
--- a/drivers/media/common/tuners/tda9887.c
+++ b/drivers/media/common/tuners/tda9887.c
@@ -686,7 +686,6 @@ struct dvb_frontend *tda9887_attach(struct dvb_frontend *fe,
686 case 0: 686 case 0:
687 mutex_unlock(&tda9887_list_mutex); 687 mutex_unlock(&tda9887_list_mutex);
688 return NULL; 688 return NULL;
689 break;
690 case 1: 689 case 1:
691 fe->analog_demod_priv = priv; 690 fe->analog_demod_priv = priv;
692 priv->mode = T_STANDBY; 691 priv->mode = T_STANDBY;
diff --git a/drivers/media/common/tuners/tuner-simple.c b/drivers/media/common/tuners/tuner-simple.c
index aa773a658a2a..2a1aac1cc755 100644
--- a/drivers/media/common/tuners/tuner-simple.c
+++ b/drivers/media/common/tuners/tuner-simple.c
@@ -142,6 +142,7 @@ static inline int tuner_stereo(const int type, const int status)
142 case TUNER_PHILIPS_FM1236_MK3: 142 case TUNER_PHILIPS_FM1236_MK3:
143 case TUNER_PHILIPS_FM1256_IH3: 143 case TUNER_PHILIPS_FM1256_IH3:
144 case TUNER_LG_NTSC_TAPE: 144 case TUNER_LG_NTSC_TAPE:
145 case TUNER_TCL_MF02GIP_5N:
145 return ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3); 146 return ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3);
146 default: 147 default:
147 return status & TUNER_STEREO; 148 return status & TUNER_STEREO;
@@ -494,6 +495,7 @@ static int simple_radio_bandswitch(struct dvb_frontend *fe, u8 *buffer)
494 case TUNER_PHILIPS_FMD1216ME_MK3: 495 case TUNER_PHILIPS_FMD1216ME_MK3:
495 case TUNER_LG_NTSC_TAPE: 496 case TUNER_LG_NTSC_TAPE:
496 case TUNER_PHILIPS_FM1256_IH3: 497 case TUNER_PHILIPS_FM1256_IH3:
498 case TUNER_TCL_MF02GIP_5N:
497 buffer[3] = 0x19; 499 buffer[3] = 0x19;
498 break; 500 break;
499 case TUNER_TNF_5335MF: 501 case TUNER_TNF_5335MF:
@@ -1038,7 +1040,6 @@ struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe,
1038 case 0: 1040 case 0:
1039 mutex_unlock(&tuner_simple_list_mutex); 1041 mutex_unlock(&tuner_simple_list_mutex);
1040 return NULL; 1042 return NULL;
1041 break;
1042 case 1: 1043 case 1:
1043 fe->tuner_priv = priv; 1044 fe->tuner_priv = priv;
1044 1045
diff --git a/drivers/media/common/tuners/tuner-types.c b/drivers/media/common/tuners/tuner-types.c
index 10dddca8b5d1..04961a1f44be 100644
--- a/drivers/media/common/tuners/tuner-types.c
+++ b/drivers/media/common/tuners/tuner-types.c
@@ -1216,6 +1216,23 @@ static struct tuner_params tuner_samsung_tcpg_6121p30a_params[] = {
1216 }, 1216 },
1217}; 1217};
1218 1218
1219/* ------------ TUNER_TCL_MF02GIP-5N-E - TCL MF02GIP-5N ------------ */
1220
1221static struct tuner_range tuner_tcl_mf02gip_5n_ntsc_ranges[] = {
1222 { 16 * 172.00 /*MHz*/, 0x8e, 0x01, },
1223 { 16 * 448.00 /*MHz*/, 0x8e, 0x02, },
1224 { 16 * 999.99 , 0x8e, 0x04, },
1225};
1226
1227static struct tuner_params tuner_tcl_mf02gip_5n_params[] = {
1228 {
1229 .type = TUNER_PARAM_TYPE_NTSC,
1230 .ranges = tuner_tcl_mf02gip_5n_ntsc_ranges,
1231 .count = ARRAY_SIZE(tuner_tcl_mf02gip_5n_ntsc_ranges),
1232 .cb_first_if_lower_freq = 1,
1233 },
1234};
1235
1219/* --------------------------------------------------------------------- */ 1236/* --------------------------------------------------------------------- */
1220 1237
1221struct tunertype tuners[] = { 1238struct tunertype tuners[] = {
@@ -1641,6 +1658,11 @@ struct tunertype tuners[] = {
1641 .name = "Xceive 5000 tuner", 1658 .name = "Xceive 5000 tuner",
1642 /* see xc5000.c for details */ 1659 /* see xc5000.c for details */
1643 }, 1660 },
1661 [TUNER_TCL_MF02GIP_5N] = { /* TCL tuner MF02GIP-5N-E */
1662 .name = "TCL tuner MF02GIP-5N-E",
1663 .params = tuner_tcl_mf02gip_5n_params,
1664 .count = ARRAY_SIZE(tuner_tcl_mf02gip_5n_params),
1665 },
1644}; 1666};
1645EXPORT_SYMBOL(tuners); 1667EXPORT_SYMBOL(tuners);
1646 1668
diff --git a/drivers/media/common/tuners/tuner-xc2028.c b/drivers/media/common/tuners/tuner-xc2028.c
index 4dd1d2421cc5..b65e6803e6c6 100644
--- a/drivers/media/common/tuners/tuner-xc2028.c
+++ b/drivers/media/common/tuners/tuner-xc2028.c
@@ -71,9 +71,6 @@ struct firmware_properties {
71struct xc2028_data { 71struct xc2028_data {
72 struct list_head hybrid_tuner_instance_list; 72 struct list_head hybrid_tuner_instance_list;
73 struct tuner_i2c_props i2c_props; 73 struct tuner_i2c_props i2c_props;
74 int (*tuner_callback) (void *dev,
75 int command, int arg);
76 void *video_dev;
77 __u32 frequency; 74 __u32 frequency;
78 75
79 struct firmware_description *firm; 76 struct firmware_description *firm;
@@ -492,6 +489,23 @@ ret:
492 return i; 489 return i;
493} 490}
494 491
492static inline int do_tuner_callback(struct dvb_frontend *fe, int cmd, int arg)
493{
494 struct xc2028_data *priv = fe->tuner_priv;
495
496 /* analog side (tuner-core) uses i2c_adap->algo_data.
497 * digital side is not guaranteed to have algo_data defined.
498 *
499 * digital side will always have fe->dvb defined.
500 * analog side (tuner-core) doesn't (yet) define fe->dvb.
501 */
502
503 return (!fe->callback) ? -EINVAL :
504 fe->callback(((fe->dvb) && (fe->dvb->priv)) ?
505 fe->dvb->priv : priv->i2c_props.adap->algo_data,
506 DVB_FRONTEND_COMPONENT_TUNER, cmd, arg);
507}
508
495static int load_firmware(struct dvb_frontend *fe, unsigned int type, 509static int load_firmware(struct dvb_frontend *fe, unsigned int type,
496 v4l2_std_id *id) 510 v4l2_std_id *id)
497{ 511{
@@ -530,8 +544,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,
530 544
531 if (!size) { 545 if (!size) {
532 /* Special callback command received */ 546 /* Special callback command received */
533 rc = priv->tuner_callback(priv->video_dev, 547 rc = do_tuner_callback(fe, XC2028_TUNER_RESET, 0);
534 XC2028_TUNER_RESET, 0);
535 if (rc < 0) { 548 if (rc < 0) {
536 tuner_err("Error at RESET code %d\n", 549 tuner_err("Error at RESET code %d\n",
537 (*p) & 0x7f); 550 (*p) & 0x7f);
@@ -542,8 +555,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,
542 if (size >= 0xff00) { 555 if (size >= 0xff00) {
543 switch (size) { 556 switch (size) {
544 case 0xff00: 557 case 0xff00:
545 rc = priv->tuner_callback(priv->video_dev, 558 rc = do_tuner_callback(fe, XC2028_RESET_CLK, 0);
546 XC2028_RESET_CLK, 0);
547 if (rc < 0) { 559 if (rc < 0) {
548 tuner_err("Error at RESET code %d\n", 560 tuner_err("Error at RESET code %d\n",
549 (*p) & 0x7f); 561 (*p) & 0x7f);
@@ -715,8 +727,7 @@ retry:
715 memset(&priv->cur_fw, 0, sizeof(priv->cur_fw)); 727 memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
716 728
717 /* Reset is needed before loading firmware */ 729 /* Reset is needed before loading firmware */
718 rc = priv->tuner_callback(priv->video_dev, 730 rc = do_tuner_callback(fe, XC2028_TUNER_RESET, 0);
719 XC2028_TUNER_RESET, 0);
720 if (rc < 0) 731 if (rc < 0)
721 goto fail; 732 goto fail;
722 733
@@ -933,7 +944,7 @@ static int generic_set_freq(struct dvb_frontend *fe, u32 freq /* in HZ */,
933 The reset CLK is needed only with tm6000. 944 The reset CLK is needed only with tm6000.
934 Driver should work fine even if this fails. 945 Driver should work fine even if this fails.
935 */ 946 */
936 priv->tuner_callback(priv->video_dev, XC2028_RESET_CLK, 1); 947 do_tuner_callback(fe, XC2028_RESET_CLK, 1);
937 948
938 msleep(10); 949 msleep(10);
939 950
@@ -1002,11 +1013,6 @@ static int xc2028_set_params(struct dvb_frontend *fe,
1002 1013
1003 tuner_dbg("%s called\n", __func__); 1014 tuner_dbg("%s called\n", __func__);
1004 1015
1005 if (priv->ctrl.d2633)
1006 type |= D2633;
1007 else
1008 type |= D2620;
1009
1010 switch(fe->ops.info.type) { 1016 switch(fe->ops.info.type) {
1011 case FE_OFDM: 1017 case FE_OFDM:
1012 bw = p->u.ofdm.bandwidth; 1018 bw = p->u.ofdm.bandwidth;
@@ -1021,10 +1027,8 @@ static int xc2028_set_params(struct dvb_frontend *fe,
1021 break; 1027 break;
1022 case FE_ATSC: 1028 case FE_ATSC:
1023 bw = BANDWIDTH_6_MHZ; 1029 bw = BANDWIDTH_6_MHZ;
1024 /* The only ATSC firmware (at least on v2.7) is D2633, 1030 /* The only ATSC firmware (at least on v2.7) is D2633 */
1025 so overrides ctrl->d2633 */ 1031 type |= ATSC | D2633;
1026 type |= ATSC| D2633;
1027 type &= ~D2620;
1028 break; 1032 break;
1029 /* DVB-S is not supported */ 1033 /* DVB-S is not supported */
1030 default: 1034 default:
@@ -1057,6 +1061,28 @@ static int xc2028_set_params(struct dvb_frontend *fe,
1057 tuner_err("error: bandwidth not supported.\n"); 1061 tuner_err("error: bandwidth not supported.\n");
1058 }; 1062 };
1059 1063
1064 /*
1065 Selects between D2633 or D2620 firmware.
1066 It doesn't make sense for ATSC, since it should be D2633 on all cases
1067 */
1068 if (fe->ops.info.type != FE_ATSC) {
1069 switch (priv->ctrl.type) {
1070 case XC2028_D2633:
1071 type |= D2633;
1072 break;
1073 case XC2028_D2620:
1074 type |= D2620;
1075 break;
1076 case XC2028_AUTO:
1077 default:
1078 /* Zarlink seems to need D2633 */
1079 if (priv->ctrl.demod == XC3028_FE_ZARLINK456)
1080 type |= D2633;
1081 else
1082 type |= D2620;
1083 }
1084 }
1085
1060 /* All S-code tables need a 200kHz shift */ 1086 /* All S-code tables need a 200kHz shift */
1061 if (priv->ctrl.demod) 1087 if (priv->ctrl.demod)
1062 demod = priv->ctrl.demod + 200; 1088 demod = priv->ctrl.demod + 200;
@@ -1177,20 +1203,10 @@ struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe,
1177 break; 1203 break;
1178 case 1: 1204 case 1:
1179 /* new tuner instance */ 1205 /* new tuner instance */
1180 priv->tuner_callback = cfg->callback;
1181 priv->ctrl.max_len = 13; 1206 priv->ctrl.max_len = 13;
1182 1207
1183 mutex_init(&priv->lock); 1208 mutex_init(&priv->lock);
1184 1209
1185 /* analog side (tuner-core) uses i2c_adap->algo_data.
1186 * digital side is not guaranteed to have algo_data defined.
1187 *
1188 * digital side will always have fe->dvb defined.
1189 * analog side (tuner-core) doesn't (yet) define fe->dvb.
1190 */
1191 priv->video_dev = ((fe->dvb) && (fe->dvb->priv)) ?
1192 fe->dvb->priv : cfg->i2c_adap->algo_data;
1193
1194 fe->tuner_priv = priv; 1210 fe->tuner_priv = priv;
1195 break; 1211 break;
1196 case 2: 1212 case 2:
diff --git a/drivers/media/common/tuners/tuner-xc2028.h b/drivers/media/common/tuners/tuner-xc2028.h
index 2c5b6282b569..19de7928a74e 100644
--- a/drivers/media/common/tuners/tuner-xc2028.h
+++ b/drivers/media/common/tuners/tuner-xc2028.h
@@ -24,24 +24,28 @@
24#define XC3028_FE_ZARLINK456 4560 24#define XC3028_FE_ZARLINK456 4560
25#define XC3028_FE_CHINA 5200 25#define XC3028_FE_CHINA 5200
26 26
27enum firmware_type {
28 XC2028_AUTO = 0, /* By default, auto-detects */
29 XC2028_D2633,
30 XC2028_D2620,
31};
32
27struct xc2028_ctrl { 33struct xc2028_ctrl {
28 char *fname; 34 char *fname;
29 int max_len; 35 int max_len;
30 unsigned int scode_table; 36 unsigned int scode_table;
31 unsigned int mts :1; 37 unsigned int mts :1;
32 unsigned int d2633 :1;
33 unsigned int input1:1; 38 unsigned int input1:1;
34 unsigned int vhfbw7:1; 39 unsigned int vhfbw7:1;
35 unsigned int uhfbw8:1; 40 unsigned int uhfbw8:1;
36 unsigned int demod; 41 unsigned int demod;
42 enum firmware_type type:2;
37}; 43};
38 44
39struct xc2028_config { 45struct xc2028_config {
40 struct i2c_adapter *i2c_adap; 46 struct i2c_adapter *i2c_adap;
41 u8 i2c_addr; 47 u8 i2c_addr;
42 void *video_dev;
43 struct xc2028_ctrl *ctrl; 48 struct xc2028_ctrl *ctrl;
44 int (*callback) (void *dev, int command, int arg);
45}; 49};
46 50
47/* xc2028 commands for callback */ 51/* xc2028 commands for callback */
diff --git a/drivers/media/common/tuners/xc5000.c b/drivers/media/common/tuners/xc5000.c
index dcddfa803a75..f9c2bb917f54 100644
--- a/drivers/media/common/tuners/xc5000.c
+++ b/drivers/media/common/tuners/xc5000.c
@@ -30,7 +30,7 @@
30#include "dvb_frontend.h" 30#include "dvb_frontend.h"
31 31
32#include "xc5000.h" 32#include "xc5000.h"
33#include "xc5000_priv.h" 33#include "tuner-i2c.h"
34 34
35static int debug; 35static int debug;
36module_param(debug, int, 0644); 36module_param(debug, int, 0644);
@@ -40,12 +40,26 @@ static int xc5000_load_fw_on_attach;
40module_param_named(init_fw, xc5000_load_fw_on_attach, int, 0644); 40module_param_named(init_fw, xc5000_load_fw_on_attach, int, 0644);
41MODULE_PARM_DESC(init_fw, "Load firmware during driver initialization."); 41MODULE_PARM_DESC(init_fw, "Load firmware during driver initialization.");
42 42
43static DEFINE_MUTEX(xc5000_list_mutex);
44static LIST_HEAD(hybrid_tuner_instance_list);
45
43#define dprintk(level,fmt, arg...) if (debug >= level) \ 46#define dprintk(level,fmt, arg...) if (debug >= level) \
44 printk(KERN_INFO "%s: " fmt, "xc5000", ## arg) 47 printk(KERN_INFO "%s: " fmt, "xc5000", ## arg)
45 48
46#define XC5000_DEFAULT_FIRMWARE "dvb-fe-xc5000-1.1.fw" 49#define XC5000_DEFAULT_FIRMWARE "dvb-fe-xc5000-1.1.fw"
47#define XC5000_DEFAULT_FIRMWARE_SIZE 12332 50#define XC5000_DEFAULT_FIRMWARE_SIZE 12332
48 51
52struct xc5000_priv {
53 struct tuner_i2c_props i2c_props;
54 struct list_head hybrid_tuner_instance_list;
55
56 u32 if_khz;
57 u32 freq_hz;
58 u32 bandwidth;
59 u8 video_standard;
60 u8 rf_mode;
61};
62
49/* Misc Defines */ 63/* Misc Defines */
50#define MAX_TV_STANDARD 23 64#define MAX_TV_STANDARD 23
51#define XC_MAX_I2C_WRITE_LENGTH 64 65#define XC_MAX_I2C_WRITE_LENGTH 64
@@ -216,9 +230,12 @@ static void xc5000_TunerReset(struct dvb_frontend *fe)
216 230
217 dprintk(1, "%s()\n", __func__); 231 dprintk(1, "%s()\n", __func__);
218 232
219 if (priv->cfg->tuner_callback) { 233 if (fe->callback) {
220 ret = priv->cfg->tuner_callback(priv->devptr, 234 ret = fe->callback(((fe->dvb) && (fe->dvb->priv)) ?
221 XC5000_TUNER_RESET, 0); 235 fe->dvb->priv :
236 priv->i2c_props.adap->algo_data,
237 DVB_FRONTEND_COMPONENT_TUNER,
238 XC5000_TUNER_RESET, 0);
222 if (ret) 239 if (ret)
223 printk(KERN_ERR "xc5000: reset failed\n"); 240 printk(KERN_ERR "xc5000: reset failed\n");
224 } else 241 } else
@@ -509,13 +526,13 @@ static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val)
509 u8 buf[2] = { reg >> 8, reg & 0xff }; 526 u8 buf[2] = { reg >> 8, reg & 0xff };
510 u8 bval[2] = { 0, 0 }; 527 u8 bval[2] = { 0, 0 };
511 struct i2c_msg msg[2] = { 528 struct i2c_msg msg[2] = {
512 { .addr = priv->cfg->i2c_address, 529 { .addr = priv->i2c_props.addr,
513 .flags = 0, .buf = &buf[0], .len = 2 }, 530 .flags = 0, .buf = &buf[0], .len = 2 },
514 { .addr = priv->cfg->i2c_address, 531 { .addr = priv->i2c_props.addr,
515 .flags = I2C_M_RD, .buf = &bval[0], .len = 2 }, 532 .flags = I2C_M_RD, .buf = &bval[0], .len = 2 },
516 }; 533 };
517 534
518 if (i2c_transfer(priv->i2c, msg, 2) != 2) { 535 if (i2c_transfer(priv->i2c_props.adap, msg, 2) != 2) {
519 printk(KERN_WARNING "xc5000: I2C read failed\n"); 536 printk(KERN_WARNING "xc5000: I2C read failed\n");
520 return -EREMOTEIO; 537 return -EREMOTEIO;
521 } 538 }
@@ -526,10 +543,10 @@ static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val)
526 543
527static int xc5000_writeregs(struct xc5000_priv *priv, u8 *buf, u8 len) 544static int xc5000_writeregs(struct xc5000_priv *priv, u8 *buf, u8 len)
528{ 545{
529 struct i2c_msg msg = { .addr = priv->cfg->i2c_address, 546 struct i2c_msg msg = { .addr = priv->i2c_props.addr,
530 .flags = 0, .buf = buf, .len = len }; 547 .flags = 0, .buf = buf, .len = len };
531 548
532 if (i2c_transfer(priv->i2c, &msg, 1) != 1) { 549 if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {
533 printk(KERN_ERR "xc5000: I2C write failed (len=%i)\n", 550 printk(KERN_ERR "xc5000: I2C write failed (len=%i)\n",
534 (int)len); 551 (int)len);
535 return -EREMOTEIO; 552 return -EREMOTEIO;
@@ -539,10 +556,10 @@ static int xc5000_writeregs(struct xc5000_priv *priv, u8 *buf, u8 len)
539 556
540static int xc5000_readregs(struct xc5000_priv *priv, u8 *buf, u8 len) 557static int xc5000_readregs(struct xc5000_priv *priv, u8 *buf, u8 len)
541{ 558{
542 struct i2c_msg msg = { .addr = priv->cfg->i2c_address, 559 struct i2c_msg msg = { .addr = priv->i2c_props.addr,
543 .flags = I2C_M_RD, .buf = buf, .len = len }; 560 .flags = I2C_M_RD, .buf = buf, .len = len };
544 561
545 if (i2c_transfer(priv->i2c, &msg, 1) != 1) { 562 if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {
546 printk(KERN_ERR "xc5000 I2C read failed (len=%i)\n",(int)len); 563 printk(KERN_ERR "xc5000 I2C read failed (len=%i)\n",(int)len);
547 return -EREMOTEIO; 564 return -EREMOTEIO;
548 } 565 }
@@ -559,7 +576,7 @@ static int xc5000_fwupload(struct dvb_frontend* fe)
559 printk(KERN_INFO "xc5000: waiting for firmware upload (%s)...\n", 576 printk(KERN_INFO "xc5000: waiting for firmware upload (%s)...\n",
560 XC5000_DEFAULT_FIRMWARE); 577 XC5000_DEFAULT_FIRMWARE);
561 578
562 ret = request_firmware(&fw, XC5000_DEFAULT_FIRMWARE, &priv->i2c->dev); 579 ret = request_firmware(&fw, XC5000_DEFAULT_FIRMWARE, &priv->i2c_props.adap->dev);
563 if (ret) { 580 if (ret) {
564 printk(KERN_ERR "xc5000: Upload failed. (file not found?)\n"); 581 printk(KERN_ERR "xc5000: Upload failed. (file not found?)\n");
565 ret = XC_RESULT_RESET_FAILURE; 582 ret = XC_RESULT_RESET_FAILURE;
@@ -675,10 +692,10 @@ static int xc5000_set_params(struct dvb_frontend *fe,
675 return -EREMOTEIO; 692 return -EREMOTEIO;
676 } 693 }
677 694
678 ret = xc_set_IF_frequency(priv, priv->cfg->if_khz); 695 ret = xc_set_IF_frequency(priv, priv->if_khz);
679 if (ret != XC_RESULT_SUCCESS) { 696 if (ret != XC_RESULT_SUCCESS) {
680 printk(KERN_ERR "xc5000: xc_Set_IF_frequency(%d) failed\n", 697 printk(KERN_ERR "xc5000: xc_Set_IF_frequency(%d) failed\n",
681 priv->cfg->if_khz); 698 priv->if_khz);
682 return -EIO; 699 return -EIO;
683 } 700 }
684 701
@@ -897,9 +914,19 @@ static int xc5000_init(struct dvb_frontend *fe)
897 914
898static int xc5000_release(struct dvb_frontend *fe) 915static int xc5000_release(struct dvb_frontend *fe)
899{ 916{
917 struct xc5000_priv *priv = fe->tuner_priv;
918
900 dprintk(1, "%s()\n", __func__); 919 dprintk(1, "%s()\n", __func__);
901 kfree(fe->tuner_priv); 920
921 mutex_lock(&xc5000_list_mutex);
922
923 if (priv)
924 hybrid_tuner_release_state(priv);
925
926 mutex_unlock(&xc5000_list_mutex);
927
902 fe->tuner_priv = NULL; 928 fe->tuner_priv = NULL;
929
903 return 0; 930 return 0;
904} 931}
905 932
@@ -924,29 +951,43 @@ static const struct dvb_tuner_ops xc5000_tuner_ops = {
924 951
925struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe, 952struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,
926 struct i2c_adapter *i2c, 953 struct i2c_adapter *i2c,
927 struct xc5000_config *cfg, void *devptr) 954 struct xc5000_config *cfg)
928{ 955{
929 struct xc5000_priv *priv = NULL; 956 struct xc5000_priv *priv = NULL;
957 int instance;
930 u16 id = 0; 958 u16 id = 0;
931 959
932 dprintk(1, "%s()\n", __func__); 960 dprintk(1, "%s(%d-%04x)\n", __func__,
961 i2c ? i2c_adapter_id(i2c) : -1,
962 cfg ? cfg->i2c_address : -1);
933 963
934 priv = kzalloc(sizeof(struct xc5000_priv), GFP_KERNEL); 964 mutex_lock(&xc5000_list_mutex);
935 if (priv == NULL)
936 return NULL;
937 965
938 priv->cfg = cfg; 966 instance = hybrid_tuner_request_state(struct xc5000_priv, priv,
939 priv->bandwidth = BANDWIDTH_6_MHZ; 967 hybrid_tuner_instance_list,
940 priv->i2c = i2c; 968 i2c, cfg->i2c_address, "xc5000");
941 priv->devptr = devptr; 969 switch (instance) {
970 case 0:
971 goto fail;
972 break;
973 case 1:
974 /* new tuner instance */
975 priv->bandwidth = BANDWIDTH_6_MHZ;
976 priv->if_khz = cfg->if_khz;
977
978 fe->tuner_priv = priv;
979 break;
980 default:
981 /* existing tuner instance */
982 fe->tuner_priv = priv;
983 break;
984 }
942 985
943 /* Check if firmware has been loaded. It is possible that another 986 /* Check if firmware has been loaded. It is possible that another
944 instance of the driver has loaded the firmware. 987 instance of the driver has loaded the firmware.
945 */ 988 */
946 if (xc5000_readreg(priv, XREG_PRODUCT_ID, &id) != 0) { 989 if (xc5000_readreg(priv, XREG_PRODUCT_ID, &id) != 0)
947 kfree(priv); 990 goto fail;
948 return NULL;
949 }
950 991
951 switch(id) { 992 switch(id) {
952 case XC_PRODUCT_ID_FW_LOADED: 993 case XC_PRODUCT_ID_FW_LOADED:
@@ -967,19 +1008,23 @@ struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,
967 printk(KERN_ERR 1008 printk(KERN_ERR
968 "xc5000: Device not found at addr 0x%02x (0x%x)\n", 1009 "xc5000: Device not found at addr 0x%02x (0x%x)\n",
969 cfg->i2c_address, id); 1010 cfg->i2c_address, id);
970 kfree(priv); 1011 goto fail;
971 return NULL;
972 } 1012 }
973 1013
1014 mutex_unlock(&xc5000_list_mutex);
1015
974 memcpy(&fe->ops.tuner_ops, &xc5000_tuner_ops, 1016 memcpy(&fe->ops.tuner_ops, &xc5000_tuner_ops,
975 sizeof(struct dvb_tuner_ops)); 1017 sizeof(struct dvb_tuner_ops));
976 1018
977 fe->tuner_priv = priv;
978
979 if (xc5000_load_fw_on_attach) 1019 if (xc5000_load_fw_on_attach)
980 xc5000_init(fe); 1020 xc5000_init(fe);
981 1021
982 return fe; 1022 return fe;
1023fail:
1024 mutex_unlock(&xc5000_list_mutex);
1025
1026 xc5000_release(fe);
1027 return NULL;
983} 1028}
984EXPORT_SYMBOL(xc5000_attach); 1029EXPORT_SYMBOL(xc5000_attach);
985 1030
diff --git a/drivers/media/common/tuners/xc5000.h b/drivers/media/common/tuners/xc5000.h
index 5389f740945a..cf1a558e0e7f 100644
--- a/drivers/media/common/tuners/xc5000.h
+++ b/drivers/media/common/tuners/xc5000.h
@@ -30,8 +30,6 @@ struct i2c_adapter;
30struct xc5000_config { 30struct xc5000_config {
31 u8 i2c_address; 31 u8 i2c_address;
32 u32 if_khz; 32 u32 if_khz;
33
34 int (*tuner_callback) (void *priv, int command, int arg);
35}; 33};
36 34
37/* xc5000 callback command */ 35/* xc5000 callback command */
@@ -49,13 +47,11 @@ struct xc5000_config {
49 (defined(CONFIG_MEDIA_TUNER_XC5000_MODULE) && defined(MODULE)) 47 (defined(CONFIG_MEDIA_TUNER_XC5000_MODULE) && defined(MODULE))
50extern struct dvb_frontend* xc5000_attach(struct dvb_frontend *fe, 48extern struct dvb_frontend* xc5000_attach(struct dvb_frontend *fe,
51 struct i2c_adapter *i2c, 49 struct i2c_adapter *i2c,
52 struct xc5000_config *cfg, 50 struct xc5000_config *cfg);
53 void *devptr);
54#else 51#else
55static inline struct dvb_frontend* xc5000_attach(struct dvb_frontend *fe, 52static inline struct dvb_frontend* xc5000_attach(struct dvb_frontend *fe,
56 struct i2c_adapter *i2c, 53 struct i2c_adapter *i2c,
57 struct xc5000_config *cfg, 54 struct xc5000_config *cfg)
58 void *devptr)
59{ 55{
60 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 56 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
61 return NULL; 57 return NULL;
diff --git a/drivers/media/common/tuners/xc5000_priv.h b/drivers/media/common/tuners/xc5000_priv.h
deleted file mode 100644
index b2a0074c99c9..000000000000
--- a/drivers/media/common/tuners/xc5000_priv.h
+++ /dev/null
@@ -1,37 +0,0 @@
1/*
2 * Driver for Xceive XC5000 "QAM/8VSB single chip tuner"
3 *
4 * Copyright (c) 2007 Steven Toth <stoth@linuxtv.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#ifndef XC5000_PRIV_H
23#define XC5000_PRIV_H
24
25struct xc5000_priv {
26 struct xc5000_config *cfg;
27 struct i2c_adapter *i2c;
28
29 u32 freq_hz;
30 u32 bandwidth;
31 u8 video_standard;
32 u8 rf_mode;
33
34 void *devptr;
35};
36
37#endif
diff --git a/drivers/media/dvb/Kconfig b/drivers/media/dvb/Kconfig
index 8bc1445bd33b..0bcd852576d6 100644
--- a/drivers/media/dvb/Kconfig
+++ b/drivers/media/dvb/Kconfig
@@ -20,7 +20,6 @@ comment "Supported USB Adapters"
20source "drivers/media/dvb/dvb-usb/Kconfig" 20source "drivers/media/dvb/dvb-usb/Kconfig"
21source "drivers/media/dvb/ttusb-budget/Kconfig" 21source "drivers/media/dvb/ttusb-budget/Kconfig"
22source "drivers/media/dvb/ttusb-dec/Kconfig" 22source "drivers/media/dvb/ttusb-dec/Kconfig"
23source "drivers/media/dvb/cinergyT2/Kconfig"
24source "drivers/media/dvb/siano/Kconfig" 23source "drivers/media/dvb/siano/Kconfig"
25 24
26comment "Supported FlexCopII (B2C2) Adapters" 25comment "Supported FlexCopII (B2C2) Adapters"
@@ -35,6 +34,10 @@ comment "Supported Pluto2 Adapters"
35 depends on DVB_CORE && PCI && I2C 34 depends on DVB_CORE && PCI && I2C
36source "drivers/media/dvb/pluto2/Kconfig" 35source "drivers/media/dvb/pluto2/Kconfig"
37 36
37comment "Supported SDMC DM1105 Adapters"
38 depends on DVB_CORE && PCI && I2C
39source "drivers/media/dvb/dm1105/Kconfig"
40
38comment "Supported DVB Frontends" 41comment "Supported DVB Frontends"
39 depends on DVB_CORE 42 depends on DVB_CORE
40source "drivers/media/dvb/frontends/Kconfig" 43source "drivers/media/dvb/frontends/Kconfig"
diff --git a/drivers/media/dvb/Makefile b/drivers/media/dvb/Makefile
index d6ba4d195201..f91e9eb15e52 100644
--- a/drivers/media/dvb/Makefile
+++ b/drivers/media/dvb/Makefile
@@ -2,4 +2,4 @@
2# Makefile for the kernel multimedia device drivers. 2# Makefile for the kernel multimedia device drivers.
3# 3#
4 4
5obj-y := dvb-core/ frontends/ ttpci/ ttusb-dec/ ttusb-budget/ b2c2/ bt8xx/ cinergyT2/ dvb-usb/ pluto2/ siano/ 5obj-y := dvb-core/ frontends/ ttpci/ ttusb-dec/ ttusb-budget/ b2c2/ bt8xx/ dvb-usb/ pluto2/ siano/ dm1105/
diff --git a/drivers/media/dvb/b2c2/flexcop-dma.c b/drivers/media/dvb/b2c2/flexcop-dma.c
index a91ed28f03a4..26f0011a5078 100644
--- a/drivers/media/dvb/b2c2/flexcop-dma.c
+++ b/drivers/media/dvb/b2c2/flexcop-dma.c
@@ -10,7 +10,7 @@
10int flexcop_dma_allocate(struct pci_dev *pdev, struct flexcop_dma *dma, u32 size) 10int flexcop_dma_allocate(struct pci_dev *pdev, struct flexcop_dma *dma, u32 size)
11{ 11{
12 u8 *tcpu; 12 u8 *tcpu;
13 dma_addr_t tdma; 13 dma_addr_t tdma = 0;
14 14
15 if (size % 2) { 15 if (size % 2) {
16 err("dma buffersize has to be even."); 16 err("dma buffersize has to be even.");
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
index 6afbfbbef0ce..48762a2b9e42 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
@@ -702,7 +702,7 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
702 } 702 }
703 703
704 if (card->fe == NULL) 704 if (card->fe == NULL)
705 printk("dvb-bt8xx: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n", 705 printk("dvb-bt8xx: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
706 card->bt->dev->vendor, 706 card->bt->dev->vendor,
707 card->bt->dev->device, 707 card->bt->dev->device,
708 card->bt->dev->subsystem_vendor, 708 card->bt->dev->subsystem_vendor,
diff --git a/drivers/media/dvb/cinergyT2/Kconfig b/drivers/media/dvb/cinergyT2/Kconfig
deleted file mode 100644
index c03513b2ccae..000000000000
--- a/drivers/media/dvb/cinergyT2/Kconfig
+++ /dev/null
@@ -1,85 +0,0 @@
1config DVB_CINERGYT2
2 tristate "Terratec CinergyT2/qanu USB2 DVB-T receiver"
3 depends on DVB_CORE && USB && INPUT
4 help
5 Support for "TerraTec CinergyT2" USB2.0 Highspeed DVB Receivers
6
7 Say Y if you own such a device and want to use it.
8
9
10config DVB_CINERGYT2_TUNING
11 bool "sophisticated fine-tuning for CinergyT2 cards"
12 depends on DVB_CINERGYT2
13 help
14 Here you can fine-tune some parameters of the CinergyT2 driver.
15
16 Normally you don't need to touch this, but in exotic setups you
17 may fine-tune your setup and adjust e.g. DMA buffer sizes for
18 a particular application.
19
20
21config DVB_CINERGYT2_STREAM_URB_COUNT
22 int "Number of queued USB Request Blocks for Highspeed Stream Transfers"
23 depends on DVB_CINERGYT2_TUNING
24 default "32"
25 help
26 USB Request Blocks for Highspeed Stream transfers are scheduled in
27 a queue for the Host Controller.
28
29 Usually the default value is a safe choice.
30
31 You may increase this number if you are using this device in a
32 Server Environment with many high-traffic USB Highspeed devices
33 sharing the same USB bus.
34
35
36config DVB_CINERGYT2_STREAM_BUF_SIZE
37 int "Size of URB Stream Buffers for Highspeed Transfers"
38 depends on DVB_CINERGYT2_TUNING
39 default "512"
40 help
41 Should be a multiple of native buffer size of 512 bytes.
42 Default value is a safe choice.
43
44 You may increase this number if you are using this device in a
45 Server Environment with many high-traffic USB Highspeed devices
46 sharing the same USB bus.
47
48
49config DVB_CINERGYT2_QUERY_INTERVAL
50 int "Status update interval [milliseconds]"
51 depends on DVB_CINERGYT2_TUNING
52 default "250"
53 help
54 This is the interval for status readouts from the demodulator.
55 You may try lower values if you need more responsive signal quality
56 measurements.
57
58 Please keep in mind that these updates cause traffic on the tuner
59 control bus and thus may or may not affect reception sensitivity.
60
61 The default value should be a safe choice for common applications.
62
63
64config DVB_CINERGYT2_ENABLE_RC_INPUT_DEVICE
65 bool "Register the onboard IR Remote Control Receiver as Input Device"
66 depends on DVB_CINERGYT2_TUNING
67 default y
68 help
69 Enable this option if you want to use the onboard Infrared Remote
70 Control Receiver as Linux-Input device.
71
72 Right now only the keycode table for the default Remote Control
73 delivered with the device is supported, please see the driver
74 source code to find out how to add support for other controls.
75
76
77config DVB_CINERGYT2_RC_QUERY_INTERVAL
78 int "Infrared Remote Controller update interval [milliseconds]"
79 depends on DVB_CINERGYT2_TUNING && DVB_CINERGYT2_ENABLE_RC_INPUT_DEVICE
80 default "50"
81 help
82 If you have a very fast-repeating remote control you can try lower
83 values, for normal consumer receivers the default value should be
84 a safe choice.
85
diff --git a/drivers/media/dvb/cinergyT2/Makefile b/drivers/media/dvb/cinergyT2/Makefile
deleted file mode 100644
index d762d8cb0cf1..000000000000
--- a/drivers/media/dvb/cinergyT2/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
1obj-$(CONFIG_DVB_CINERGYT2) += cinergyT2.o
2
3EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/
diff --git a/drivers/media/dvb/cinergyT2/cinergyT2.c b/drivers/media/dvb/cinergyT2/cinergyT2.c
deleted file mode 100644
index a824f3719f81..000000000000
--- a/drivers/media/dvb/cinergyT2/cinergyT2.c
+++ /dev/null
@@ -1,1105 +0,0 @@
1/*
2 * TerraTec Cinergy T²/qanu USB2 DVB-T adapter.
3 *
4 * Copyright (C) 2004 Daniel Mack <daniel@qanu.de> and
5 * Holger Waechtler <holger@qanu.de>
6 *
7 * Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include <linux/init.h>
26#include <linux/module.h>
27#include <linux/slab.h>
28#include <linux/usb.h>
29#include <linux/input.h>
30#include <linux/dvb/frontend.h>
31#include <linux/mutex.h>
32#include <linux/mm.h>
33#include <asm/io.h>
34
35#include "dmxdev.h"
36#include "dvb_demux.h"
37#include "dvb_net.h"
38
39#ifdef CONFIG_DVB_CINERGYT2_TUNING
40 #define STREAM_URB_COUNT (CONFIG_DVB_CINERGYT2_STREAM_URB_COUNT)
41 #define STREAM_BUF_SIZE (CONFIG_DVB_CINERGYT2_STREAM_BUF_SIZE)
42 #define QUERY_INTERVAL (CONFIG_DVB_CINERGYT2_QUERY_INTERVAL)
43 #ifdef CONFIG_DVB_CINERGYT2_ENABLE_RC_INPUT_DEVICE
44 #define RC_QUERY_INTERVAL (CONFIG_DVB_CINERGYT2_RC_QUERY_INTERVAL)
45 #define ENABLE_RC (1)
46 #endif
47#else
48 #define STREAM_URB_COUNT (32)
49 #define STREAM_BUF_SIZE (512) /* bytes */
50 #define ENABLE_RC (1)
51 #define RC_QUERY_INTERVAL (50) /* milliseconds */
52 #define QUERY_INTERVAL (333) /* milliseconds */
53#endif
54
55#define DRIVER_NAME "TerraTec/qanu USB2.0 Highspeed DVB-T Receiver"
56
57static int debug;
58module_param_named(debug, debug, int, 0644);
59MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
60
61DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
62
63#define dprintk(level, args...) \
64do { \
65 if ((debug & level)) { \
66 printk("%s: %s(): ", KBUILD_MODNAME, \
67 __func__); \
68 printk(args); } \
69} while (0)
70
71enum cinergyt2_ep1_cmd {
72 CINERGYT2_EP1_PID_TABLE_RESET = 0x01,
73 CINERGYT2_EP1_PID_SETUP = 0x02,
74 CINERGYT2_EP1_CONTROL_STREAM_TRANSFER = 0x03,
75 CINERGYT2_EP1_SET_TUNER_PARAMETERS = 0x04,
76 CINERGYT2_EP1_GET_TUNER_STATUS = 0x05,
77 CINERGYT2_EP1_START_SCAN = 0x06,
78 CINERGYT2_EP1_CONTINUE_SCAN = 0x07,
79 CINERGYT2_EP1_GET_RC_EVENTS = 0x08,
80 CINERGYT2_EP1_SLEEP_MODE = 0x09
81};
82
83struct dvbt_set_parameters_msg {
84 uint8_t cmd;
85 __le32 freq;
86 uint8_t bandwidth;
87 __le16 tps;
88 uint8_t flags;
89} __attribute__((packed));
90
91struct dvbt_get_status_msg {
92 __le32 freq;
93 uint8_t bandwidth;
94 __le16 tps;
95 uint8_t flags;
96 __le16 gain;
97 uint8_t snr;
98 __le32 viterbi_error_rate;
99 __le32 rs_error_rate;
100 __le32 uncorrected_block_count;
101 uint8_t lock_bits;
102 uint8_t prev_lock_bits;
103} __attribute__((packed));
104
105static struct dvb_frontend_info cinergyt2_fe_info = {
106 .name = DRIVER_NAME,
107 .type = FE_OFDM,
108 .frequency_min = 174000000,
109 .frequency_max = 862000000,
110 .frequency_stepsize = 166667,
111 .caps = FE_CAN_INVERSION_AUTO | FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 |
112 FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |
113 FE_CAN_FEC_AUTO |
114 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
115 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
116 FE_CAN_HIERARCHY_AUTO | FE_CAN_RECOVER | FE_CAN_MUTE_TS
117};
118
119struct cinergyt2 {
120 struct dvb_demux demux;
121 struct usb_device *udev;
122 struct mutex sem;
123 struct mutex wq_sem;
124 struct dvb_adapter adapter;
125 struct dvb_device *fedev;
126 struct dmxdev dmxdev;
127 struct dvb_net dvbnet;
128
129 int streaming;
130 int sleeping;
131
132 struct dvbt_set_parameters_msg param;
133 struct dvbt_get_status_msg status;
134 struct delayed_work query_work;
135
136 wait_queue_head_t poll_wq;
137 int pending_fe_events;
138 int disconnect_pending;
139 unsigned int uncorrected_block_count;
140 atomic_t inuse;
141
142 void *streambuf;
143 dma_addr_t streambuf_dmahandle;
144 struct urb *stream_urb [STREAM_URB_COUNT];
145
146#ifdef ENABLE_RC
147 struct input_dev *rc_input_dev;
148 char phys[64];
149 struct delayed_work rc_query_work;
150 int rc_input_event;
151 __le32 rc_last_code;
152 unsigned long last_event_jiffies;
153#endif
154};
155
156enum {
157 CINERGYT2_RC_EVENT_TYPE_NONE = 0x00,
158 CINERGYT2_RC_EVENT_TYPE_NEC = 0x01,
159 CINERGYT2_RC_EVENT_TYPE_RC5 = 0x02
160};
161
162struct cinergyt2_rc_event {
163 char type;
164 __le32 value;
165} __attribute__((packed));
166
167static const uint32_t rc_keys[] = {
168 CINERGYT2_RC_EVENT_TYPE_NEC, 0xfe01eb04, KEY_POWER,
169 CINERGYT2_RC_EVENT_TYPE_NEC, 0xfd02eb04, KEY_1,
170 CINERGYT2_RC_EVENT_TYPE_NEC, 0xfc03eb04, KEY_2,
171 CINERGYT2_RC_EVENT_TYPE_NEC, 0xfb04eb04, KEY_3,
172 CINERGYT2_RC_EVENT_TYPE_NEC, 0xfa05eb04, KEY_4,
173 CINERGYT2_RC_EVENT_TYPE_NEC, 0xf906eb04, KEY_5,
174 CINERGYT2_RC_EVENT_TYPE_NEC, 0xf807eb04, KEY_6,
175 CINERGYT2_RC_EVENT_TYPE_NEC, 0xf708eb04, KEY_7,
176 CINERGYT2_RC_EVENT_TYPE_NEC, 0xf609eb04, KEY_8,
177 CINERGYT2_RC_EVENT_TYPE_NEC, 0xf50aeb04, KEY_9,
178 CINERGYT2_RC_EVENT_TYPE_NEC, 0xf30ceb04, KEY_0,
179 CINERGYT2_RC_EVENT_TYPE_NEC, 0xf40beb04, KEY_VIDEO,
180 CINERGYT2_RC_EVENT_TYPE_NEC, 0xf20deb04, KEY_REFRESH,
181 CINERGYT2_RC_EVENT_TYPE_NEC, 0xf10eeb04, KEY_SELECT,
182 CINERGYT2_RC_EVENT_TYPE_NEC, 0xf00feb04, KEY_EPG,
183 CINERGYT2_RC_EVENT_TYPE_NEC, 0xef10eb04, KEY_UP,
184 CINERGYT2_RC_EVENT_TYPE_NEC, 0xeb14eb04, KEY_DOWN,
185 CINERGYT2_RC_EVENT_TYPE_NEC, 0xee11eb04, KEY_LEFT,
186 CINERGYT2_RC_EVENT_TYPE_NEC, 0xec13eb04, KEY_RIGHT,
187 CINERGYT2_RC_EVENT_TYPE_NEC, 0xed12eb04, KEY_OK,
188 CINERGYT2_RC_EVENT_TYPE_NEC, 0xea15eb04, KEY_TEXT,
189 CINERGYT2_RC_EVENT_TYPE_NEC, 0xe916eb04, KEY_INFO,
190 CINERGYT2_RC_EVENT_TYPE_NEC, 0xe817eb04, KEY_RED,
191 CINERGYT2_RC_EVENT_TYPE_NEC, 0xe718eb04, KEY_GREEN,
192 CINERGYT2_RC_EVENT_TYPE_NEC, 0xe619eb04, KEY_YELLOW,
193 CINERGYT2_RC_EVENT_TYPE_NEC, 0xe51aeb04, KEY_BLUE,
194 CINERGYT2_RC_EVENT_TYPE_NEC, 0xe31ceb04, KEY_VOLUMEUP,
195 CINERGYT2_RC_EVENT_TYPE_NEC, 0xe11eeb04, KEY_VOLUMEDOWN,
196 CINERGYT2_RC_EVENT_TYPE_NEC, 0xe21deb04, KEY_MUTE,
197 CINERGYT2_RC_EVENT_TYPE_NEC, 0xe41beb04, KEY_CHANNELUP,
198 CINERGYT2_RC_EVENT_TYPE_NEC, 0xe01feb04, KEY_CHANNELDOWN,
199 CINERGYT2_RC_EVENT_TYPE_NEC, 0xbf40eb04, KEY_PAUSE,
200 CINERGYT2_RC_EVENT_TYPE_NEC, 0xb34ceb04, KEY_PLAY,
201 CINERGYT2_RC_EVENT_TYPE_NEC, 0xa758eb04, KEY_RECORD,
202 CINERGYT2_RC_EVENT_TYPE_NEC, 0xab54eb04, KEY_PREVIOUS,
203 CINERGYT2_RC_EVENT_TYPE_NEC, 0xb748eb04, KEY_STOP,
204 CINERGYT2_RC_EVENT_TYPE_NEC, 0xa35ceb04, KEY_NEXT
205};
206
207static int cinergyt2_command (struct cinergyt2 *cinergyt2,
208 char *send_buf, int send_buf_len,
209 char *recv_buf, int recv_buf_len)
210{
211 int actual_len;
212 char dummy;
213 int ret;
214
215 ret = usb_bulk_msg(cinergyt2->udev, usb_sndbulkpipe(cinergyt2->udev, 1),
216 send_buf, send_buf_len, &actual_len, 1000);
217
218 if (ret)
219 dprintk(1, "usb_bulk_msg (send) failed, err %i\n", ret);
220
221 if (!recv_buf)
222 recv_buf = &dummy;
223
224 ret = usb_bulk_msg(cinergyt2->udev, usb_rcvbulkpipe(cinergyt2->udev, 1),
225 recv_buf, recv_buf_len, &actual_len, 1000);
226
227 if (ret)
228 dprintk(1, "usb_bulk_msg (read) failed, err %i\n", ret);
229
230 return ret ? ret : actual_len;
231}
232
233static void cinergyt2_control_stream_transfer (struct cinergyt2 *cinergyt2, int enable)
234{
235 char buf [] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
236 cinergyt2_command(cinergyt2, buf, sizeof(buf), NULL, 0);
237}
238
239static void cinergyt2_sleep (struct cinergyt2 *cinergyt2, int sleep)
240{
241 char buf [] = { CINERGYT2_EP1_SLEEP_MODE, sleep ? 1 : 0 };
242 cinergyt2_command(cinergyt2, buf, sizeof(buf), NULL, 0);
243 cinergyt2->sleeping = sleep;
244}
245
246static void cinergyt2_stream_irq (struct urb *urb);
247
248static int cinergyt2_submit_stream_urb (struct cinergyt2 *cinergyt2, struct urb *urb)
249{
250 int err;
251
252 usb_fill_bulk_urb(urb,
253 cinergyt2->udev,
254 usb_rcvbulkpipe(cinergyt2->udev, 0x2),
255 urb->transfer_buffer,
256 STREAM_BUF_SIZE,
257 cinergyt2_stream_irq,
258 cinergyt2);
259
260 if ((err = usb_submit_urb(urb, GFP_ATOMIC)))
261 dprintk(1, "urb submission failed (err = %i)!\n", err);
262
263 return err;
264}
265
266static void cinergyt2_stream_irq (struct urb *urb)
267{
268 struct cinergyt2 *cinergyt2 = urb->context;
269
270 if (urb->actual_length > 0)
271 dvb_dmx_swfilter(&cinergyt2->demux,
272 urb->transfer_buffer, urb->actual_length);
273
274 if (cinergyt2->streaming)
275 cinergyt2_submit_stream_urb(cinergyt2, urb);
276}
277
278static void cinergyt2_free_stream_urbs (struct cinergyt2 *cinergyt2)
279{
280 int i;
281
282 for (i=0; i<STREAM_URB_COUNT; i++)
283 usb_free_urb(cinergyt2->stream_urb[i]);
284
285 usb_buffer_free(cinergyt2->udev, STREAM_URB_COUNT*STREAM_BUF_SIZE,
286 cinergyt2->streambuf, cinergyt2->streambuf_dmahandle);
287}
288
289static int cinergyt2_alloc_stream_urbs (struct cinergyt2 *cinergyt2)
290{
291 int i;
292
293 cinergyt2->streambuf = usb_buffer_alloc(cinergyt2->udev, STREAM_URB_COUNT*STREAM_BUF_SIZE,
294 GFP_KERNEL, &cinergyt2->streambuf_dmahandle);
295 if (!cinergyt2->streambuf) {
296 dprintk(1, "failed to alloc consistent stream memory area, bailing out!\n");
297 return -ENOMEM;
298 }
299
300 memset(cinergyt2->streambuf, 0, STREAM_URB_COUNT*STREAM_BUF_SIZE);
301
302 for (i=0; i<STREAM_URB_COUNT; i++) {
303 struct urb *urb;
304
305 if (!(urb = usb_alloc_urb(0, GFP_ATOMIC))) {
306 dprintk(1, "failed to alloc consistent stream urbs, bailing out!\n");
307 cinergyt2_free_stream_urbs(cinergyt2);
308 return -ENOMEM;
309 }
310
311 urb->transfer_buffer = cinergyt2->streambuf + i * STREAM_BUF_SIZE;
312 urb->transfer_buffer_length = STREAM_BUF_SIZE;
313
314 cinergyt2->stream_urb[i] = urb;
315 }
316
317 return 0;
318}
319
320static void cinergyt2_stop_stream_xfer (struct cinergyt2 *cinergyt2)
321{
322 int i;
323
324 cinergyt2_control_stream_transfer(cinergyt2, 0);
325
326 for (i=0; i<STREAM_URB_COUNT; i++)
327 usb_kill_urb(cinergyt2->stream_urb[i]);
328}
329
330static int cinergyt2_start_stream_xfer (struct cinergyt2 *cinergyt2)
331{
332 int i, err;
333
334 for (i=0; i<STREAM_URB_COUNT; i++) {
335 if ((err = cinergyt2_submit_stream_urb(cinergyt2, cinergyt2->stream_urb[i]))) {
336 cinergyt2_stop_stream_xfer(cinergyt2);
337 dprintk(1, "failed urb submission (%i: err = %i)!\n", i, err);
338 return err;
339 }
340 }
341
342 cinergyt2_control_stream_transfer(cinergyt2, 1);
343 return 0;
344}
345
346static int cinergyt2_start_feed(struct dvb_demux_feed *dvbdmxfeed)
347{
348 struct dvb_demux *demux = dvbdmxfeed->demux;
349 struct cinergyt2 *cinergyt2 = demux->priv;
350
351 if (cinergyt2->disconnect_pending)
352 return -EAGAIN;
353 if (mutex_lock_interruptible(&cinergyt2->sem))
354 return -ERESTARTSYS;
355
356 if (cinergyt2->streaming == 0)
357 cinergyt2_start_stream_xfer(cinergyt2);
358
359 cinergyt2->streaming++;
360 mutex_unlock(&cinergyt2->sem);
361 return 0;
362}
363
364static int cinergyt2_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
365{
366 struct dvb_demux *demux = dvbdmxfeed->demux;
367 struct cinergyt2 *cinergyt2 = demux->priv;
368
369 if (cinergyt2->disconnect_pending)
370 return -EAGAIN;
371 if (mutex_lock_interruptible(&cinergyt2->sem))
372 return -ERESTARTSYS;
373
374 if (--cinergyt2->streaming == 0)
375 cinergyt2_stop_stream_xfer(cinergyt2);
376
377 mutex_unlock(&cinergyt2->sem);
378 return 0;
379}
380
381/**
382 * convert linux-dvb frontend parameter set into TPS.
383 * See ETSI ETS-300744, section 4.6.2, table 9 for details.
384 *
385 * This function is probably reusable and may better get placed in a support
386 * library.
387 *
388 * We replace errornous fields by default TPS fields (the ones with value 0).
389 */
390static uint16_t compute_tps (struct dvb_frontend_parameters *p)
391{
392 struct dvb_ofdm_parameters *op = &p->u.ofdm;
393 uint16_t tps = 0;
394
395 switch (op->code_rate_HP) {
396 case FEC_2_3:
397 tps |= (1 << 7);
398 break;
399 case FEC_3_4:
400 tps |= (2 << 7);
401 break;
402 case FEC_5_6:
403 tps |= (3 << 7);
404 break;
405 case FEC_7_8:
406 tps |= (4 << 7);
407 break;
408 case FEC_1_2:
409 case FEC_AUTO:
410 default:
411 /* tps |= (0 << 7) */;
412 }
413
414 switch (op->code_rate_LP) {
415 case FEC_2_3:
416 tps |= (1 << 4);
417 break;
418 case FEC_3_4:
419 tps |= (2 << 4);
420 break;
421 case FEC_5_6:
422 tps |= (3 << 4);
423 break;
424 case FEC_7_8:
425 tps |= (4 << 4);
426 break;
427 case FEC_1_2:
428 case FEC_AUTO:
429 default:
430 /* tps |= (0 << 4) */;
431 }
432
433 switch (op->constellation) {
434 case QAM_16:
435 tps |= (1 << 13);
436 break;
437 case QAM_64:
438 tps |= (2 << 13);
439 break;
440 case QPSK:
441 default:
442 /* tps |= (0 << 13) */;
443 }
444
445 switch (op->transmission_mode) {
446 case TRANSMISSION_MODE_8K:
447 tps |= (1 << 0);
448 break;
449 case TRANSMISSION_MODE_2K:
450 default:
451 /* tps |= (0 << 0) */;
452 }
453
454 switch (op->guard_interval) {
455 case GUARD_INTERVAL_1_16:
456 tps |= (1 << 2);
457 break;
458 case GUARD_INTERVAL_1_8:
459 tps |= (2 << 2);
460 break;
461 case GUARD_INTERVAL_1_4:
462 tps |= (3 << 2);
463 break;
464 case GUARD_INTERVAL_1_32:
465 default:
466 /* tps |= (0 << 2) */;
467 }
468
469 switch (op->hierarchy_information) {
470 case HIERARCHY_1:
471 tps |= (1 << 10);
472 break;
473 case HIERARCHY_2:
474 tps |= (2 << 10);
475 break;
476 case HIERARCHY_4:
477 tps |= (3 << 10);
478 break;
479 case HIERARCHY_NONE:
480 default:
481 /* tps |= (0 << 10) */;
482 }
483
484 return tps;
485}
486
487static int cinergyt2_open (struct inode *inode, struct file *file)
488{
489 struct dvb_device *dvbdev = file->private_data;
490 struct cinergyt2 *cinergyt2 = dvbdev->priv;
491 int err = -EAGAIN;
492
493 if (cinergyt2->disconnect_pending)
494 goto out;
495 err = mutex_lock_interruptible(&cinergyt2->wq_sem);
496 if (err)
497 goto out;
498
499 err = mutex_lock_interruptible(&cinergyt2->sem);
500 if (err)
501 goto out_unlock1;
502
503 if ((err = dvb_generic_open(inode, file)))
504 goto out_unlock2;
505
506 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
507 cinergyt2_sleep(cinergyt2, 0);
508 schedule_delayed_work(&cinergyt2->query_work, HZ/2);
509 }
510
511 atomic_inc(&cinergyt2->inuse);
512
513out_unlock2:
514 mutex_unlock(&cinergyt2->sem);
515out_unlock1:
516 mutex_unlock(&cinergyt2->wq_sem);
517out:
518 return err;
519}
520
521static void cinergyt2_unregister(struct cinergyt2 *cinergyt2)
522{
523 dvb_net_release(&cinergyt2->dvbnet);
524 dvb_dmxdev_release(&cinergyt2->dmxdev);
525 dvb_dmx_release(&cinergyt2->demux);
526 dvb_unregister_device(cinergyt2->fedev);
527 dvb_unregister_adapter(&cinergyt2->adapter);
528
529 cinergyt2_free_stream_urbs(cinergyt2);
530 kfree(cinergyt2);
531}
532
533static int cinergyt2_release (struct inode *inode, struct file *file)
534{
535 struct dvb_device *dvbdev = file->private_data;
536 struct cinergyt2 *cinergyt2 = dvbdev->priv;
537
538 mutex_lock(&cinergyt2->wq_sem);
539
540 if (!cinergyt2->disconnect_pending && (file->f_flags & O_ACCMODE) != O_RDONLY) {
541 cancel_rearming_delayed_work(&cinergyt2->query_work);
542
543 mutex_lock(&cinergyt2->sem);
544 cinergyt2_sleep(cinergyt2, 1);
545 mutex_unlock(&cinergyt2->sem);
546 }
547
548 mutex_unlock(&cinergyt2->wq_sem);
549
550 if (atomic_dec_and_test(&cinergyt2->inuse) && cinergyt2->disconnect_pending) {
551 warn("delayed unregister in release");
552 cinergyt2_unregister(cinergyt2);
553 }
554
555 return dvb_generic_release(inode, file);
556}
557
558static unsigned int cinergyt2_poll (struct file *file, struct poll_table_struct *wait)
559{
560 struct dvb_device *dvbdev = file->private_data;
561 struct cinergyt2 *cinergyt2 = dvbdev->priv;
562 unsigned int mask = 0;
563
564 if (cinergyt2->disconnect_pending)
565 return -EAGAIN;
566 if (mutex_lock_interruptible(&cinergyt2->sem))
567 return -ERESTARTSYS;
568
569 poll_wait(file, &cinergyt2->poll_wq, wait);
570
571 if (cinergyt2->pending_fe_events != 0)
572 mask |= (POLLIN | POLLRDNORM | POLLPRI);
573
574 mutex_unlock(&cinergyt2->sem);
575
576 return mask;
577}
578
579
580static int cinergyt2_ioctl (struct inode *inode, struct file *file,
581 unsigned cmd, unsigned long arg)
582{
583 struct dvb_device *dvbdev = file->private_data;
584 struct cinergyt2 *cinergyt2 = dvbdev->priv;
585 struct dvbt_get_status_msg *stat = &cinergyt2->status;
586 fe_status_t status = 0;
587
588 switch (cmd) {
589 case FE_GET_INFO:
590 return copy_to_user((void __user*) arg, &cinergyt2_fe_info,
591 sizeof(struct dvb_frontend_info));
592
593 case FE_READ_STATUS:
594 if (0xffff - le16_to_cpu(stat->gain) > 30)
595 status |= FE_HAS_SIGNAL;
596 if (stat->lock_bits & (1 << 6))
597 status |= FE_HAS_LOCK;
598 if (stat->lock_bits & (1 << 5))
599 status |= FE_HAS_SYNC;
600 if (stat->lock_bits & (1 << 4))
601 status |= FE_HAS_CARRIER;
602 if (stat->lock_bits & (1 << 1))
603 status |= FE_HAS_VITERBI;
604
605 return copy_to_user((void __user*) arg, &status, sizeof(status));
606
607 case FE_READ_BER:
608 return put_user(le32_to_cpu(stat->viterbi_error_rate),
609 (__u32 __user *) arg);
610
611 case FE_READ_SIGNAL_STRENGTH:
612 return put_user(0xffff - le16_to_cpu(stat->gain),
613 (__u16 __user *) arg);
614
615 case FE_READ_SNR:
616 return put_user((stat->snr << 8) | stat->snr,
617 (__u16 __user *) arg);
618
619 case FE_READ_UNCORRECTED_BLOCKS:
620 {
621 uint32_t unc_count;
622
623 if (mutex_lock_interruptible(&cinergyt2->sem))
624 return -ERESTARTSYS;
625 unc_count = cinergyt2->uncorrected_block_count;
626 cinergyt2->uncorrected_block_count = 0;
627 mutex_unlock(&cinergyt2->sem);
628
629 /* UNC are already converted to host byte order... */
630 return put_user(unc_count,(__u32 __user *) arg);
631 }
632 case FE_SET_FRONTEND:
633 {
634 struct dvbt_set_parameters_msg *param = &cinergyt2->param;
635 struct dvb_frontend_parameters p;
636 int err;
637
638 if ((file->f_flags & O_ACCMODE) == O_RDONLY)
639 return -EPERM;
640
641 if (copy_from_user(&p, (void __user*) arg, sizeof(p)))
642 return -EFAULT;
643
644 if (cinergyt2->disconnect_pending)
645 return -EAGAIN;
646 if (mutex_lock_interruptible(&cinergyt2->sem))
647 return -ERESTARTSYS;
648
649 param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
650 param->tps = cpu_to_le16(compute_tps(&p));
651 param->freq = cpu_to_le32(p.frequency / 1000);
652 param->bandwidth = 8 - p.u.ofdm.bandwidth - BANDWIDTH_8_MHZ;
653
654 stat->lock_bits = 0;
655 cinergyt2->pending_fe_events++;
656 wake_up_interruptible(&cinergyt2->poll_wq);
657
658 err = cinergyt2_command(cinergyt2,
659 (char *) param, sizeof(*param),
660 NULL, 0);
661
662 mutex_unlock(&cinergyt2->sem);
663
664 return (err < 0) ? err : 0;
665 }
666
667 case FE_GET_FRONTEND:
668 /**
669 * trivial to implement (see struct dvbt_get_status_msg).
670 * equivalent to FE_READ ioctls, but needs
671 * TPS -> linux-dvb parameter set conversion. Feel free
672 * to implement this and send us a patch if you need this
673 * functionality.
674 */
675 break;
676
677 case FE_GET_EVENT:
678 {
679 /**
680 * for now we only fill the status field. the parameters
681 * are trivial to fill as soon FE_GET_FRONTEND is done.
682 */
683 struct dvb_frontend_event __user *e = (void __user *) arg;
684 if (cinergyt2->pending_fe_events == 0) {
685 if (file->f_flags & O_NONBLOCK)
686 return -EWOULDBLOCK;
687 wait_event_interruptible(cinergyt2->poll_wq,
688 cinergyt2->pending_fe_events > 0);
689 }
690 cinergyt2->pending_fe_events = 0;
691 return cinergyt2_ioctl(inode, file, FE_READ_STATUS,
692 (unsigned long) &e->status);
693 }
694
695 default:
696 ;
697 }
698
699 return -EINVAL;
700}
701
702static int cinergyt2_mmap(struct file *file, struct vm_area_struct *vma)
703{
704 struct dvb_device *dvbdev = file->private_data;
705 struct cinergyt2 *cinergyt2 = dvbdev->priv;
706 int ret = 0;
707
708 lock_kernel();
709
710 if (vma->vm_flags & (VM_WRITE | VM_EXEC)) {
711 ret = -EPERM;
712 goto bailout;
713 }
714
715 if (vma->vm_end > vma->vm_start + STREAM_URB_COUNT * STREAM_BUF_SIZE) {
716 ret = -EINVAL;
717 goto bailout;
718 }
719
720 vma->vm_flags |= (VM_IO | VM_DONTCOPY);
721 vma->vm_file = file;
722
723 ret = remap_pfn_range(vma, vma->vm_start,
724 virt_to_phys(cinergyt2->streambuf) >> PAGE_SHIFT,
725 vma->vm_end - vma->vm_start,
726 vma->vm_page_prot) ? -EAGAIN : 0;
727bailout:
728 unlock_kernel();
729 return ret;
730}
731
732static struct file_operations cinergyt2_fops = {
733 .owner = THIS_MODULE,
734 .ioctl = cinergyt2_ioctl,
735 .poll = cinergyt2_poll,
736 .open = cinergyt2_open,
737 .release = cinergyt2_release,
738 .mmap = cinergyt2_mmap
739};
740
741static struct dvb_device cinergyt2_fe_template = {
742 .users = ~0,
743 .writers = 1,
744 .readers = (~0)-1,
745 .fops = &cinergyt2_fops
746};
747
748#ifdef ENABLE_RC
749
750static void cinergyt2_query_rc (struct work_struct *work)
751{
752 struct cinergyt2 *cinergyt2 =
753 container_of(work, struct cinergyt2, rc_query_work.work);
754 char buf[1] = { CINERGYT2_EP1_GET_RC_EVENTS };
755 struct cinergyt2_rc_event rc_events[12];
756 int n, len, i;
757
758 if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem))
759 return;
760
761 len = cinergyt2_command(cinergyt2, buf, sizeof(buf),
762 (char *) rc_events, sizeof(rc_events));
763 if (len < 0)
764 goto out;
765 if (len == 0) {
766 if (time_after(jiffies, cinergyt2->last_event_jiffies +
767 msecs_to_jiffies(150))) {
768 /* stop key repeat */
769 if (cinergyt2->rc_input_event != KEY_MAX) {
770 dprintk(1, "rc_input_event=%d Up\n", cinergyt2->rc_input_event);
771 input_report_key(cinergyt2->rc_input_dev,
772 cinergyt2->rc_input_event, 0);
773 input_sync(cinergyt2->rc_input_dev);
774 cinergyt2->rc_input_event = KEY_MAX;
775 }
776 cinergyt2->rc_last_code = cpu_to_le32(~0);
777 }
778 goto out;
779 }
780 cinergyt2->last_event_jiffies = jiffies;
781
782 for (n = 0; n < (len / sizeof(rc_events[0])); n++) {
783 dprintk(1, "rc_events[%d].value = %x, type=%x\n",
784 n, le32_to_cpu(rc_events[n].value), rc_events[n].type);
785
786 if (rc_events[n].type == CINERGYT2_RC_EVENT_TYPE_NEC &&
787 rc_events[n].value == cpu_to_le32(~0)) {
788 /* keyrepeat bit -> just repeat last rc_input_event */
789 } else {
790 cinergyt2->rc_input_event = KEY_MAX;
791 for (i = 0; i < ARRAY_SIZE(rc_keys); i += 3) {
792 if (rc_keys[i + 0] == rc_events[n].type &&
793 rc_keys[i + 1] == le32_to_cpu(rc_events[n].value)) {
794 cinergyt2->rc_input_event = rc_keys[i + 2];
795 break;
796 }
797 }
798 }
799
800 if (cinergyt2->rc_input_event != KEY_MAX) {
801 if (rc_events[n].value == cinergyt2->rc_last_code &&
802 cinergyt2->rc_last_code != cpu_to_le32(~0)) {
803 /* emit a key-up so the double event is recognized */
804 dprintk(1, "rc_input_event=%d UP\n", cinergyt2->rc_input_event);
805 input_report_key(cinergyt2->rc_input_dev,
806 cinergyt2->rc_input_event, 0);
807 }
808 dprintk(1, "rc_input_event=%d\n", cinergyt2->rc_input_event);
809 input_report_key(cinergyt2->rc_input_dev,
810 cinergyt2->rc_input_event, 1);
811 input_sync(cinergyt2->rc_input_dev);
812 cinergyt2->rc_last_code = rc_events[n].value;
813 }
814 }
815
816out:
817 schedule_delayed_work(&cinergyt2->rc_query_work,
818 msecs_to_jiffies(RC_QUERY_INTERVAL));
819
820 mutex_unlock(&cinergyt2->sem);
821}
822
823static int cinergyt2_register_rc(struct cinergyt2 *cinergyt2)
824{
825 struct input_dev *input_dev;
826 int i;
827 int err;
828
829 input_dev = input_allocate_device();
830 if (!input_dev)
831 return -ENOMEM;
832
833 usb_make_path(cinergyt2->udev, cinergyt2->phys, sizeof(cinergyt2->phys));
834 strlcat(cinergyt2->phys, "/input0", sizeof(cinergyt2->phys));
835 cinergyt2->rc_input_event = KEY_MAX;
836 cinergyt2->rc_last_code = cpu_to_le32(~0);
837 INIT_DELAYED_WORK(&cinergyt2->rc_query_work, cinergyt2_query_rc);
838
839 input_dev->name = DRIVER_NAME " remote control";
840 input_dev->phys = cinergyt2->phys;
841 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
842 for (i = 0; i < ARRAY_SIZE(rc_keys); i += 3)
843 set_bit(rc_keys[i + 2], input_dev->keybit);
844 input_dev->keycodesize = 0;
845 input_dev->keycodemax = 0;
846 input_dev->id.bustype = BUS_USB;
847 input_dev->id.vendor = le16_to_cpu(cinergyt2->udev->descriptor.idVendor);
848 input_dev->id.product = le16_to_cpu(cinergyt2->udev->descriptor.idProduct);
849 input_dev->id.version = 1;
850 input_dev->dev.parent = &cinergyt2->udev->dev;
851
852 err = input_register_device(input_dev);
853 if (err) {
854 input_free_device(input_dev);
855 return err;
856 }
857
858 cinergyt2->rc_input_dev = input_dev;
859 schedule_delayed_work(&cinergyt2->rc_query_work, HZ/2);
860
861 return 0;
862}
863
864static void cinergyt2_unregister_rc(struct cinergyt2 *cinergyt2)
865{
866 cancel_rearming_delayed_work(&cinergyt2->rc_query_work);
867 input_unregister_device(cinergyt2->rc_input_dev);
868}
869
870static inline void cinergyt2_suspend_rc(struct cinergyt2 *cinergyt2)
871{
872 cancel_rearming_delayed_work(&cinergyt2->rc_query_work);
873}
874
875static inline void cinergyt2_resume_rc(struct cinergyt2 *cinergyt2)
876{
877 schedule_delayed_work(&cinergyt2->rc_query_work, HZ/2);
878}
879
880#else
881
882static inline int cinergyt2_register_rc(struct cinergyt2 *cinergyt2) { return 0; }
883static inline void cinergyt2_unregister_rc(struct cinergyt2 *cinergyt2) { }
884static inline void cinergyt2_suspend_rc(struct cinergyt2 *cinergyt2) { }
885static inline void cinergyt2_resume_rc(struct cinergyt2 *cinergyt2) { }
886
887#endif /* ENABLE_RC */
888
889static void cinergyt2_query (struct work_struct *work)
890{
891 struct cinergyt2 *cinergyt2 =
892 container_of(work, struct cinergyt2, query_work.work);
893 char cmd [] = { CINERGYT2_EP1_GET_TUNER_STATUS };
894 struct dvbt_get_status_msg *s = &cinergyt2->status;
895 uint8_t lock_bits;
896
897 if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem))
898 return;
899
900 lock_bits = s->lock_bits;
901
902 cinergyt2_command(cinergyt2, cmd, sizeof(cmd), (char *) s, sizeof(*s));
903
904 cinergyt2->uncorrected_block_count +=
905 le32_to_cpu(s->uncorrected_block_count);
906
907 if (lock_bits != s->lock_bits) {
908 wake_up_interruptible(&cinergyt2->poll_wq);
909 cinergyt2->pending_fe_events++;
910 }
911
912 schedule_delayed_work(&cinergyt2->query_work,
913 msecs_to_jiffies(QUERY_INTERVAL));
914
915 mutex_unlock(&cinergyt2->sem);
916}
917
918static int cinergyt2_probe (struct usb_interface *intf,
919 const struct usb_device_id *id)
920{
921 struct cinergyt2 *cinergyt2;
922 int err;
923
924 if (!(cinergyt2 = kzalloc (sizeof(struct cinergyt2), GFP_KERNEL))) {
925 dprintk(1, "out of memory?!?\n");
926 return -ENOMEM;
927 }
928
929 usb_set_intfdata (intf, (void *) cinergyt2);
930
931 mutex_init(&cinergyt2->sem);
932 mutex_init(&cinergyt2->wq_sem);
933 init_waitqueue_head (&cinergyt2->poll_wq);
934 INIT_DELAYED_WORK(&cinergyt2->query_work, cinergyt2_query);
935
936 cinergyt2->udev = interface_to_usbdev(intf);
937 cinergyt2->param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
938
939 if (cinergyt2_alloc_stream_urbs (cinergyt2) < 0) {
940 dprintk(1, "unable to allocate stream urbs\n");
941 kfree(cinergyt2);
942 return -ENOMEM;
943 }
944
945 err = dvb_register_adapter(&cinergyt2->adapter, DRIVER_NAME,
946 THIS_MODULE, &cinergyt2->udev->dev,
947 adapter_nr);
948 if (err < 0) {
949 kfree(cinergyt2);
950 return err;
951 }
952
953 cinergyt2->demux.priv = cinergyt2;
954 cinergyt2->demux.filternum = 256;
955 cinergyt2->demux.feednum = 256;
956 cinergyt2->demux.start_feed = cinergyt2_start_feed;
957 cinergyt2->demux.stop_feed = cinergyt2_stop_feed;
958 cinergyt2->demux.dmx.capabilities = DMX_TS_FILTERING |
959 DMX_SECTION_FILTERING |
960 DMX_MEMORY_BASED_FILTERING;
961
962 if ((err = dvb_dmx_init(&cinergyt2->demux)) < 0) {
963 dprintk(1, "dvb_dmx_init() failed (err = %d)\n", err);
964 goto bailout;
965 }
966
967 cinergyt2->dmxdev.filternum = cinergyt2->demux.filternum;
968 cinergyt2->dmxdev.demux = &cinergyt2->demux.dmx;
969 cinergyt2->dmxdev.capabilities = 0;
970
971 if ((err = dvb_dmxdev_init(&cinergyt2->dmxdev, &cinergyt2->adapter)) < 0) {
972 dprintk(1, "dvb_dmxdev_init() failed (err = %d)\n", err);
973 goto bailout;
974 }
975
976 if (dvb_net_init(&cinergyt2->adapter, &cinergyt2->dvbnet, &cinergyt2->demux.dmx))
977 dprintk(1, "dvb_net_init() failed!\n");
978
979 dvb_register_device(&cinergyt2->adapter, &cinergyt2->fedev,
980 &cinergyt2_fe_template, cinergyt2,
981 DVB_DEVICE_FRONTEND);
982
983 err = cinergyt2_register_rc(cinergyt2);
984 if (err)
985 goto bailout;
986
987 return 0;
988
989bailout:
990 dvb_net_release(&cinergyt2->dvbnet);
991 dvb_dmxdev_release(&cinergyt2->dmxdev);
992 dvb_dmx_release(&cinergyt2->demux);
993 dvb_unregister_adapter(&cinergyt2->adapter);
994 cinergyt2_free_stream_urbs(cinergyt2);
995 kfree(cinergyt2);
996 return -ENOMEM;
997}
998
999static void cinergyt2_disconnect (struct usb_interface *intf)
1000{
1001 struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf);
1002
1003 cinergyt2_unregister_rc(cinergyt2);
1004 cancel_rearming_delayed_work(&cinergyt2->query_work);
1005 wake_up_interruptible(&cinergyt2->poll_wq);
1006
1007 cinergyt2->demux.dmx.close(&cinergyt2->demux.dmx);
1008 cinergyt2->disconnect_pending = 1;
1009
1010 if (!atomic_read(&cinergyt2->inuse))
1011 cinergyt2_unregister(cinergyt2);
1012}
1013
1014static int cinergyt2_suspend (struct usb_interface *intf, pm_message_t state)
1015{
1016 struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf);
1017
1018 if (cinergyt2->disconnect_pending)
1019 return -EAGAIN;
1020 if (mutex_lock_interruptible(&cinergyt2->wq_sem))
1021 return -ERESTARTSYS;
1022
1023 cinergyt2_suspend_rc(cinergyt2);
1024 cancel_rearming_delayed_work(&cinergyt2->query_work);
1025
1026 mutex_lock(&cinergyt2->sem);
1027 if (cinergyt2->streaming)
1028 cinergyt2_stop_stream_xfer(cinergyt2);
1029 cinergyt2_sleep(cinergyt2, 1);
1030 mutex_unlock(&cinergyt2->sem);
1031
1032 mutex_unlock(&cinergyt2->wq_sem);
1033
1034 return 0;
1035}
1036
1037static int cinergyt2_resume (struct usb_interface *intf)
1038{
1039 struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf);
1040 struct dvbt_set_parameters_msg *param = &cinergyt2->param;
1041 int err = -EAGAIN;
1042
1043 if (cinergyt2->disconnect_pending)
1044 goto out;
1045 err = mutex_lock_interruptible(&cinergyt2->wq_sem);
1046 if (err)
1047 goto out;
1048
1049 err = mutex_lock_interruptible(&cinergyt2->sem);
1050 if (err)
1051 goto out_unlock1;
1052
1053 if (!cinergyt2->sleeping) {
1054 cinergyt2_sleep(cinergyt2, 0);
1055 cinergyt2_command(cinergyt2, (char *) param, sizeof(*param), NULL, 0);
1056 if (cinergyt2->streaming)
1057 cinergyt2_start_stream_xfer(cinergyt2);
1058 schedule_delayed_work(&cinergyt2->query_work, HZ/2);
1059 }
1060
1061 cinergyt2_resume_rc(cinergyt2);
1062
1063 mutex_unlock(&cinergyt2->sem);
1064out_unlock1:
1065 mutex_unlock(&cinergyt2->wq_sem);
1066out:
1067 return err;
1068}
1069
1070static const struct usb_device_id cinergyt2_table [] __devinitdata = {
1071 { USB_DEVICE(0x0ccd, 0x0038) },
1072 { 0 }
1073};
1074
1075MODULE_DEVICE_TABLE(usb, cinergyt2_table);
1076
1077static struct usb_driver cinergyt2_driver = {
1078 .name = "cinergyT2",
1079 .probe = cinergyt2_probe,
1080 .disconnect = cinergyt2_disconnect,
1081 .suspend = cinergyt2_suspend,
1082 .resume = cinergyt2_resume,
1083 .id_table = cinergyt2_table
1084};
1085
1086static int __init cinergyt2_init (void)
1087{
1088 int err;
1089
1090 if ((err = usb_register(&cinergyt2_driver)) < 0)
1091 dprintk(1, "usb_register() failed! (err %i)\n", err);
1092
1093 return err;
1094}
1095
1096static void __exit cinergyt2_exit (void)
1097{
1098 usb_deregister(&cinergyt2_driver);
1099}
1100
1101module_init (cinergyt2_init);
1102module_exit (cinergyt2_exit);
1103
1104MODULE_LICENSE("GPL");
1105MODULE_AUTHOR("Holger Waechtler, Daniel Mack");
diff --git a/drivers/media/dvb/dm1105/Kconfig b/drivers/media/dvb/dm1105/Kconfig
new file mode 100644
index 000000000000..1332301ef3ae
--- /dev/null
+++ b/drivers/media/dvb/dm1105/Kconfig
@@ -0,0 +1,18 @@
1config DVB_DM1105
2 tristate "SDMC DM1105 based PCI cards"
3 depends on DVB_CORE && PCI && I2C
4 select DVB_PLL if !DVB_FE_CUSTOMISE
5 select DVB_STV0299 if !DVB_FE_CUSTOMISE
6 select DVB_STV0288 if !DVB_FE_CUSTOMISE
7 select DVB_STB6000 if !DVB_FE_CUSTOMISE
8 select DVB_CX24116 if !DVB_FE_CUSTOMISE
9 select DVB_SI21XX if !DVB_FE_CUSTOMISE
10 help
11 Support for cards based on the SDMC DM1105 PCI chip like
12 DvbWorld 2002
13
14 Since these cards have no MPEG decoder onboard, they transmit
15 only compressed MPEG data over the PCI bus, so you need
16 an external software decoder to watch TV on your computer.
17
18 Say Y or M if you own such a device and want to use it.
diff --git a/drivers/media/dvb/dm1105/Makefile b/drivers/media/dvb/dm1105/Makefile
new file mode 100644
index 000000000000..8ac28b0546af
--- /dev/null
+++ b/drivers/media/dvb/dm1105/Makefile
@@ -0,0 +1,3 @@
1obj-$(CONFIG_DVB_DM1105) += dm1105.o
2
3EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends
diff --git a/drivers/media/dvb/dm1105/dm1105.c b/drivers/media/dvb/dm1105/dm1105.c
new file mode 100644
index 000000000000..f7321448b4b1
--- /dev/null
+++ b/drivers/media/dvb/dm1105/dm1105.c
@@ -0,0 +1,911 @@
1/*
2 * dm1105.c - driver for DVB cards based on SDMC DM1105 PCI chip
3 *
4 * Copyright (C) 2008 Igor M. Liplianin <liplianin@me.by>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 */
21
22#include <linux/version.h>
23#include <linux/i2c.h>
24#include <linux/init.h>
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/proc_fs.h>
28#include <linux/pci.h>
29#include <linux/dma-mapping.h>
30#include <linux/input.h>
31#include <media/ir-common.h>
32
33#include "demux.h"
34#include "dmxdev.h"
35#include "dvb_demux.h"
36#include "dvb_frontend.h"
37#include "dvb_net.h"
38#include "dvbdev.h"
39#include "dvb-pll.h"
40
41#include "stv0299.h"
42#include "stv0288.h"
43#include "stb6000.h"
44#include "si21xx.h"
45#include "cx24116.h"
46#include "z0194a.h"
47
48/* ----------------------------------------------- */
49/*
50 * PCI ID's
51 */
52#ifndef PCI_VENDOR_ID_TRIGEM
53#define PCI_VENDOR_ID_TRIGEM 0x109f
54#endif
55#ifndef PCI_DEVICE_ID_DM1105
56#define PCI_DEVICE_ID_DM1105 0x036f
57#endif
58#ifndef PCI_DEVICE_ID_DW2002
59#define PCI_DEVICE_ID_DW2002 0x2002
60#endif
61#ifndef PCI_DEVICE_ID_DW2004
62#define PCI_DEVICE_ID_DW2004 0x2004
63#endif
64/* ----------------------------------------------- */
65/* sdmc dm1105 registers */
66
67/* TS Control */
68#define DM1105_TSCTR 0x00
69#define DM1105_DTALENTH 0x04
70
71/* GPIO Interface */
72#define DM1105_GPIOVAL 0x08
73#define DM1105_GPIOCTR 0x0c
74
75/* PID serial number */
76#define DM1105_PIDN 0x10
77
78/* Odd-even secret key select */
79#define DM1105_CWSEL 0x14
80
81/* Host Command Interface */
82#define DM1105_HOST_CTR 0x18
83#define DM1105_HOST_AD 0x1c
84
85/* PCI Interface */
86#define DM1105_CR 0x30
87#define DM1105_RST 0x34
88#define DM1105_STADR 0x38
89#define DM1105_RLEN 0x3c
90#define DM1105_WRP 0x40
91#define DM1105_INTCNT 0x44
92#define DM1105_INTMAK 0x48
93#define DM1105_INTSTS 0x4c
94
95/* CW Value */
96#define DM1105_ODD 0x50
97#define DM1105_EVEN 0x58
98
99/* PID Value */
100#define DM1105_PID 0x60
101
102/* IR Control */
103#define DM1105_IRCTR 0x64
104#define DM1105_IRMODE 0x68
105#define DM1105_SYSTEMCODE 0x6c
106#define DM1105_IRCODE 0x70
107
108/* Unknown Values */
109#define DM1105_ENCRYPT 0x74
110#define DM1105_VER 0x7c
111
112/* I2C Interface */
113#define DM1105_I2CCTR 0x80
114#define DM1105_I2CSTS 0x81
115#define DM1105_I2CDAT 0x82
116#define DM1105_I2C_RA 0x83
117/* ----------------------------------------------- */
118/* Interrupt Mask Bits */
119
120#define INTMAK_TSIRQM 0x01
121#define INTMAK_HIRQM 0x04
122#define INTMAK_IRM 0x08
123#define INTMAK_ALLMASK (INTMAK_TSIRQM | \
124 INTMAK_HIRQM | \
125 INTMAK_IRM)
126#define INTMAK_NONEMASK 0x00
127
128/* Interrupt Status Bits */
129#define INTSTS_TSIRQ 0x01
130#define INTSTS_HIRQ 0x04
131#define INTSTS_IR 0x08
132
133/* IR Control Bits */
134#define DM1105_IR_EN 0x01
135#define DM1105_SYS_CHK 0x02
136#define DM1105_REP_FLG 0x08
137
138/* EEPROM addr */
139#define IIC_24C01_addr 0xa0
140/* Max board count */
141#define DM1105_MAX 0x04
142
143#define DRIVER_NAME "dm1105"
144
145#define DM1105_DMA_PACKETS 47
146#define DM1105_DMA_PACKET_LENGTH (128*4)
147#define DM1105_DMA_BYTES (128 * 4 * DM1105_DMA_PACKETS)
148
149/* GPIO's for LNB power control */
150#define DM1105_LNB_MASK 0x00000000
151#define DM1105_LNB_13V 0x00010100
152#define DM1105_LNB_18V 0x00000100
153
154static int ir_debug;
155module_param(ir_debug, int, 0644);
156MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding");
157
158DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
159
160static u16 ir_codes_dm1105_nec[128] = {
161 [0x0a] = KEY_Q, /*power*/
162 [0x0c] = KEY_M, /*mute*/
163 [0x11] = KEY_1,
164 [0x12] = KEY_2,
165 [0x13] = KEY_3,
166 [0x14] = KEY_4,
167 [0x15] = KEY_5,
168 [0x16] = KEY_6,
169 [0x17] = KEY_7,
170 [0x18] = KEY_8,
171 [0x19] = KEY_9,
172 [0x10] = KEY_0,
173 [0x1c] = KEY_PAGEUP, /*ch+*/
174 [0x0f] = KEY_PAGEDOWN, /*ch-*/
175 [0x1a] = KEY_O, /*vol+*/
176 [0x0e] = KEY_Z, /*vol-*/
177 [0x04] = KEY_R, /*rec*/
178 [0x09] = KEY_D, /*fav*/
179 [0x08] = KEY_BACKSPACE, /*rewind*/
180 [0x07] = KEY_A, /*fast*/
181 [0x0b] = KEY_P, /*pause*/
182 [0x02] = KEY_ESC, /*cancel*/
183 [0x03] = KEY_G, /*tab*/
184 [0x00] = KEY_UP, /*up*/
185 [0x1f] = KEY_ENTER, /*ok*/
186 [0x01] = KEY_DOWN, /*down*/
187 [0x05] = KEY_C, /*cap*/
188 [0x06] = KEY_S, /*stop*/
189 [0x40] = KEY_F, /*full*/
190 [0x1e] = KEY_W, /*tvmode*/
191 [0x1b] = KEY_B, /*recall*/
192};
193
194/* infrared remote control */
195struct infrared {
196 u16 key_map[128];
197 struct input_dev *input_dev;
198 char input_phys[32];
199 struct tasklet_struct ir_tasklet;
200 u32 ir_command;
201};
202
203struct dm1105dvb {
204 /* pci */
205 struct pci_dev *pdev;
206 u8 __iomem *io_mem;
207
208 /* ir */
209 struct infrared ir;
210
211 /* dvb */
212 struct dmx_frontend hw_frontend;
213 struct dmx_frontend mem_frontend;
214 struct dmxdev dmxdev;
215 struct dvb_adapter dvb_adapter;
216 struct dvb_demux demux;
217 struct dvb_frontend *fe;
218 struct dvb_net dvbnet;
219 unsigned int full_ts_users;
220
221 /* i2c */
222 struct i2c_adapter i2c_adap;
223
224 /* dma */
225 dma_addr_t dma_addr;
226 unsigned char *ts_buf;
227 u32 wrp;
228 u32 buffer_size;
229 unsigned int PacketErrorCount;
230 unsigned int dmarst;
231 spinlock_t lock;
232
233};
234
235#define dm_io_mem(reg) ((unsigned long)(&dm1105dvb->io_mem[reg]))
236
237static struct dm1105dvb *dm1105dvb_local;
238
239static int dm1105_i2c_xfer(struct i2c_adapter *i2c_adap,
240 struct i2c_msg *msgs, int num)
241{
242 struct dm1105dvb *dm1105dvb ;
243
244 int addr, rc, i, j, k, len, byte, data;
245 u8 status;
246
247 dm1105dvb = i2c_adap->algo_data;
248 for (i = 0; i < num; i++) {
249 outb(0x00, dm_io_mem(DM1105_I2CCTR));
250 if (msgs[i].flags & I2C_M_RD) {
251 /* read bytes */
252 addr = msgs[i].addr << 1;
253 addr |= 1;
254 outb(addr, dm_io_mem(DM1105_I2CDAT));
255 for (byte = 0; byte < msgs[i].len; byte++)
256 outb(0, dm_io_mem(DM1105_I2CDAT + byte + 1));
257
258 outb(0x81 + msgs[i].len, dm_io_mem(DM1105_I2CCTR));
259 for (j = 0; j < 55; j++) {
260 mdelay(10);
261 status = inb(dm_io_mem(DM1105_I2CSTS));
262 if ((status & 0xc0) == 0x40)
263 break;
264 }
265 if (j >= 55)
266 return -1;
267
268 for (byte = 0; byte < msgs[i].len; byte++) {
269 rc = inb(dm_io_mem(DM1105_I2CDAT + byte + 1));
270 if (rc < 0)
271 goto err;
272 msgs[i].buf[byte] = rc;
273 }
274 } else {
275 if ((msgs[i].buf[0] == 0xf7) && (msgs[i].addr == 0x55)) {
276 /* prepaired for cx24116 firmware */
277 /* Write in small blocks */
278 len = msgs[i].len - 1;
279 k = 1;
280 do {
281 outb(msgs[i].addr << 1, dm_io_mem(DM1105_I2CDAT));
282 outb(0xf7, dm_io_mem(DM1105_I2CDAT + 1));
283 for (byte = 0; byte < (len > 48 ? 48 : len); byte++) {
284 data = msgs[i].buf[k+byte];
285 outb(data, dm_io_mem(DM1105_I2CDAT + byte + 2));
286 }
287 outb(0x82 + (len > 48 ? 48 : len), dm_io_mem(DM1105_I2CCTR));
288 for (j = 0; j < 25; j++) {
289 mdelay(10);
290 status = inb(dm_io_mem(DM1105_I2CSTS));
291 if ((status & 0xc0) == 0x40)
292 break;
293 }
294
295 if (j >= 25)
296 return -1;
297
298 k += 48;
299 len -= 48;
300 } while (len > 0);
301 } else {
302 /* write bytes */
303 outb(msgs[i].addr<<1, dm_io_mem(DM1105_I2CDAT));
304 for (byte = 0; byte < msgs[i].len; byte++) {
305 data = msgs[i].buf[byte];
306 outb(data, dm_io_mem(DM1105_I2CDAT + byte + 1));
307 }
308 outb(0x81 + msgs[i].len, dm_io_mem(DM1105_I2CCTR));
309 for (j = 0; j < 25; j++) {
310 mdelay(10);
311 status = inb(dm_io_mem(DM1105_I2CSTS));
312 if ((status & 0xc0) == 0x40)
313 break;
314 }
315
316 if (j >= 25)
317 return -1;
318 }
319 }
320 }
321 return num;
322 err:
323 return rc;
324}
325
326static u32 functionality(struct i2c_adapter *adap)
327{
328 return I2C_FUNC_I2C;
329}
330
331static struct i2c_algorithm dm1105_algo = {
332 .master_xfer = dm1105_i2c_xfer,
333 .functionality = functionality,
334};
335
336static inline struct dm1105dvb *feed_to_dm1105dvb(struct dvb_demux_feed *feed)
337{
338 return container_of(feed->demux, struct dm1105dvb, demux);
339}
340
341static inline struct dm1105dvb *frontend_to_dm1105dvb(struct dvb_frontend *fe)
342{
343 return container_of(fe->dvb, struct dm1105dvb, dvb_adapter);
344}
345
346static int dm1105dvb_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
347{
348 struct dm1105dvb *dm1105dvb = frontend_to_dm1105dvb(fe);
349
350 if (voltage == SEC_VOLTAGE_18) {
351 outl(DM1105_LNB_MASK, dm_io_mem(DM1105_GPIOCTR));
352 outl(DM1105_LNB_18V, dm_io_mem(DM1105_GPIOVAL));
353 } else {
354 /*LNB ON-13V by default!*/
355 outl(DM1105_LNB_MASK, dm_io_mem(DM1105_GPIOCTR));
356 outl(DM1105_LNB_13V, dm_io_mem(DM1105_GPIOVAL));
357 }
358
359 return 0;
360}
361
362static void dm1105dvb_set_dma_addr(struct dm1105dvb *dm1105dvb)
363{
364 outl(cpu_to_le32(dm1105dvb->dma_addr), dm_io_mem(DM1105_STADR));
365}
366
367static int __devinit dm1105dvb_dma_map(struct dm1105dvb *dm1105dvb)
368{
369 dm1105dvb->ts_buf = pci_alloc_consistent(dm1105dvb->pdev, 6*DM1105_DMA_BYTES, &dm1105dvb->dma_addr);
370
371 return pci_dma_mapping_error(dm1105dvb->pdev, dm1105dvb->dma_addr);
372}
373
374static void dm1105dvb_dma_unmap(struct dm1105dvb *dm1105dvb)
375{
376 pci_free_consistent(dm1105dvb->pdev, 6*DM1105_DMA_BYTES, dm1105dvb->ts_buf, dm1105dvb->dma_addr);
377}
378
379static void __devinit dm1105dvb_enable_irqs(struct dm1105dvb *dm1105dvb)
380{
381 outb(INTMAK_ALLMASK, dm_io_mem(DM1105_INTMAK));
382 outb(1, dm_io_mem(DM1105_CR));
383}
384
385static void dm1105dvb_disable_irqs(struct dm1105dvb *dm1105dvb)
386{
387 outb(INTMAK_IRM, dm_io_mem(DM1105_INTMAK));
388 outb(0, dm_io_mem(DM1105_CR));
389}
390
391static int dm1105dvb_start_feed(struct dvb_demux_feed *f)
392{
393 struct dm1105dvb *dm1105dvb = feed_to_dm1105dvb(f);
394
395 if (dm1105dvb->full_ts_users++ == 0)
396 dm1105dvb_enable_irqs(dm1105dvb);
397
398 return 0;
399}
400
401static int dm1105dvb_stop_feed(struct dvb_demux_feed *f)
402{
403 struct dm1105dvb *dm1105dvb = feed_to_dm1105dvb(f);
404
405 if (--dm1105dvb->full_ts_users == 0)
406 dm1105dvb_disable_irqs(dm1105dvb);
407
408 return 0;
409}
410
411/* ir tasklet */
412static void dm1105_emit_key(unsigned long parm)
413{
414 struct infrared *ir = (struct infrared *) parm;
415 u32 ircom = ir->ir_command;
416 u8 data;
417 u16 keycode;
418
419 data = (ircom >> 8) & 0x7f;
420
421 input_event(ir->input_dev, EV_MSC, MSC_RAW, (0x0000f8 << 16) | data);
422 input_event(ir->input_dev, EV_MSC, MSC_SCAN, data);
423 keycode = ir->key_map[data];
424
425 if (!keycode)
426 return;
427
428 input_event(ir->input_dev, EV_KEY, keycode, 1);
429 input_sync(ir->input_dev);
430 input_event(ir->input_dev, EV_KEY, keycode, 0);
431 input_sync(ir->input_dev);
432
433}
434
435static irqreturn_t dm1105dvb_irq(int irq, void *dev_id)
436{
437 struct dm1105dvb *dm1105dvb = dev_id;
438 unsigned int piece;
439 unsigned int nbpackets;
440 u32 command;
441 u32 nextwrp;
442 u32 oldwrp;
443
444 /* Read-Write INSTS Ack's Interrupt for DM1105 chip 16.03.2008 */
445 unsigned int intsts = inb(dm_io_mem(DM1105_INTSTS));
446 outb(intsts, dm_io_mem(DM1105_INTSTS));
447
448 switch (intsts) {
449 case INTSTS_TSIRQ:
450 case (INTSTS_TSIRQ | INTSTS_IR):
451 nextwrp = inl(dm_io_mem(DM1105_WRP)) -
452 inl(dm_io_mem(DM1105_STADR)) ;
453 oldwrp = dm1105dvb->wrp;
454 spin_lock(&dm1105dvb->lock);
455 if (!((dm1105dvb->ts_buf[oldwrp] == 0x47) &&
456 (dm1105dvb->ts_buf[oldwrp + 188] == 0x47) &&
457 (dm1105dvb->ts_buf[oldwrp + 188 * 2] == 0x47))) {
458 dm1105dvb->PacketErrorCount++;
459 /* bad packet found */
460 if ((dm1105dvb->PacketErrorCount >= 2) &&
461 (dm1105dvb->dmarst == 0)) {
462 outb(1, dm_io_mem(DM1105_RST));
463 dm1105dvb->wrp = 0;
464 dm1105dvb->PacketErrorCount = 0;
465 dm1105dvb->dmarst = 0;
466 spin_unlock(&dm1105dvb->lock);
467 return IRQ_HANDLED;
468 }
469 }
470 if (nextwrp < oldwrp) {
471 piece = dm1105dvb->buffer_size - oldwrp;
472 memcpy(dm1105dvb->ts_buf + dm1105dvb->buffer_size, dm1105dvb->ts_buf, nextwrp);
473 nbpackets = (piece + nextwrp)/188;
474 } else {
475 nbpackets = (nextwrp - oldwrp)/188;
476 }
477 dvb_dmx_swfilter_packets(&dm1105dvb->demux, &dm1105dvb->ts_buf[oldwrp], nbpackets);
478 dm1105dvb->wrp = nextwrp;
479 spin_unlock(&dm1105dvb->lock);
480 break;
481 case INTSTS_IR:
482 command = inl(dm_io_mem(DM1105_IRCODE));
483 if (ir_debug)
484 printk("dm1105: received byte 0x%04x\n", command);
485
486 dm1105dvb->ir.ir_command = command;
487 tasklet_schedule(&dm1105dvb->ir.ir_tasklet);
488 break;
489 }
490 return IRQ_HANDLED;
491
492
493}
494
495/* register with input layer */
496static void input_register_keys(struct infrared *ir)
497{
498 int i;
499
500 memset(ir->input_dev->keybit, 0, sizeof(ir->input_dev->keybit));
501
502 for (i = 0; i < ARRAY_SIZE(ir->key_map); i++)
503 set_bit(ir->key_map[i], ir->input_dev->keybit);
504
505 ir->input_dev->keycode = ir->key_map;
506 ir->input_dev->keycodesize = sizeof(ir->key_map[0]);
507 ir->input_dev->keycodemax = ARRAY_SIZE(ir->key_map);
508}
509
510int __devinit dm1105_ir_init(struct dm1105dvb *dm1105)
511{
512 struct input_dev *input_dev;
513 int err;
514
515 dm1105dvb_local = dm1105;
516
517 input_dev = input_allocate_device();
518 if (!input_dev)
519 return -ENOMEM;
520
521 dm1105->ir.input_dev = input_dev;
522 snprintf(dm1105->ir.input_phys, sizeof(dm1105->ir.input_phys),
523 "pci-%s/ir0", pci_name(dm1105->pdev));
524
525 input_dev->evbit[0] = BIT(EV_KEY);
526 input_dev->name = "DVB on-card IR receiver";
527
528 input_dev->phys = dm1105->ir.input_phys;
529 input_dev->id.bustype = BUS_PCI;
530 input_dev->id.version = 2;
531 if (dm1105->pdev->subsystem_vendor) {
532 input_dev->id.vendor = dm1105->pdev->subsystem_vendor;
533 input_dev->id.product = dm1105->pdev->subsystem_device;
534 } else {
535 input_dev->id.vendor = dm1105->pdev->vendor;
536 input_dev->id.product = dm1105->pdev->device;
537 }
538 input_dev->dev.parent = &dm1105->pdev->dev;
539 /* initial keymap */
540 memcpy(dm1105->ir.key_map, ir_codes_dm1105_nec, sizeof dm1105->ir.key_map);
541 input_register_keys(&dm1105->ir);
542 err = input_register_device(input_dev);
543 if (err) {
544 input_free_device(input_dev);
545 return err;
546 }
547
548 tasklet_init(&dm1105->ir.ir_tasklet, dm1105_emit_key, (unsigned long) &dm1105->ir);
549
550 return 0;
551}
552
553
554void __devexit dm1105_ir_exit(struct dm1105dvb *dm1105)
555{
556 tasklet_kill(&dm1105->ir.ir_tasklet);
557 input_unregister_device(dm1105->ir.input_dev);
558
559}
560
561static int __devinit dm1105dvb_hw_init(struct dm1105dvb *dm1105dvb)
562{
563 dm1105dvb_disable_irqs(dm1105dvb);
564
565 outb(0, dm_io_mem(DM1105_HOST_CTR));
566
567 /*DATALEN 188,*/
568 outb(188, dm_io_mem(DM1105_DTALENTH));
569 /*TS_STRT TS_VALP MSBFIRST TS_MODE ALPAS TSPES*/
570 outw(0xc10a, dm_io_mem(DM1105_TSCTR));
571
572 /* map DMA and set address */
573 dm1105dvb_dma_map(dm1105dvb);
574 dm1105dvb_set_dma_addr(dm1105dvb);
575 /* big buffer */
576 outl(5*DM1105_DMA_BYTES, dm_io_mem(DM1105_RLEN));
577 outb(47, dm_io_mem(DM1105_INTCNT));
578
579 /* IR NEC mode enable */
580 outb((DM1105_IR_EN | DM1105_SYS_CHK), dm_io_mem(DM1105_IRCTR));
581 outb(0, dm_io_mem(DM1105_IRMODE));
582 outw(0, dm_io_mem(DM1105_SYSTEMCODE));
583
584 return 0;
585}
586
587static void dm1105dvb_hw_exit(struct dm1105dvb *dm1105dvb)
588{
589 dm1105dvb_disable_irqs(dm1105dvb);
590
591 /* IR disable */
592 outb(0, dm_io_mem(DM1105_IRCTR));
593 outb(INTMAK_NONEMASK, dm_io_mem(DM1105_INTMAK));
594
595 dm1105dvb_dma_unmap(dm1105dvb);
596}
597
598static struct stv0288_config earda_config = {
599 .demod_address = 0x68,
600 .min_delay_ms = 100,
601};
602
603static struct si21xx_config serit_config = {
604 .demod_address = 0x68,
605 .min_delay_ms = 100,
606
607};
608
609static struct cx24116_config serit_sp2633_config = {
610 .demod_address = 0x55,
611};
612
613static int __devinit frontend_init(struct dm1105dvb *dm1105dvb)
614{
615 int ret;
616
617 switch (dm1105dvb->pdev->subsystem_device) {
618 case PCI_DEVICE_ID_DW2002:
619 dm1105dvb->fe = dvb_attach(
620 stv0299_attach, &sharp_z0194a_config,
621 &dm1105dvb->i2c_adap);
622
623 if (dm1105dvb->fe) {
624 dm1105dvb->fe->ops.set_voltage =
625 dm1105dvb_set_voltage;
626 dvb_attach(dvb_pll_attach, dm1105dvb->fe, 0x60,
627 &dm1105dvb->i2c_adap, DVB_PLL_OPERA1);
628 }
629
630 if (!dm1105dvb->fe) {
631 dm1105dvb->fe = dvb_attach(
632 stv0288_attach, &earda_config,
633 &dm1105dvb->i2c_adap);
634 if (dm1105dvb->fe) {
635 dm1105dvb->fe->ops.set_voltage =
636 dm1105dvb_set_voltage;
637 dvb_attach(stb6000_attach, dm1105dvb->fe, 0x61,
638 &dm1105dvb->i2c_adap);
639 }
640 }
641
642 if (!dm1105dvb->fe) {
643 dm1105dvb->fe = dvb_attach(
644 si21xx_attach, &serit_config,
645 &dm1105dvb->i2c_adap);
646 if (dm1105dvb->fe)
647 dm1105dvb->fe->ops.set_voltage =
648 dm1105dvb_set_voltage;
649 }
650 break;
651 case PCI_DEVICE_ID_DW2004:
652 dm1105dvb->fe = dvb_attach(
653 cx24116_attach, &serit_sp2633_config,
654 &dm1105dvb->i2c_adap);
655 if (dm1105dvb->fe)
656 dm1105dvb->fe->ops.set_voltage = dm1105dvb_set_voltage;
657 break;
658 }
659
660 if (!dm1105dvb->fe) {
661 dev_err(&dm1105dvb->pdev->dev, "could not attach frontend\n");
662 return -ENODEV;
663 }
664
665 ret = dvb_register_frontend(&dm1105dvb->dvb_adapter, dm1105dvb->fe);
666 if (ret < 0) {
667 if (dm1105dvb->fe->ops.release)
668 dm1105dvb->fe->ops.release(dm1105dvb->fe);
669 dm1105dvb->fe = NULL;
670 return ret;
671 }
672
673 return 0;
674}
675
676static void __devinit dm1105dvb_read_mac(struct dm1105dvb *dm1105dvb, u8 *mac)
677{
678 static u8 command[1] = { 0x28 };
679
680 struct i2c_msg msg[] = {
681 { .addr = IIC_24C01_addr >> 1, .flags = 0,
682 .buf = command, .len = 1 },
683 { .addr = IIC_24C01_addr >> 1, .flags = I2C_M_RD,
684 .buf = mac, .len = 6 },
685 };
686
687 dm1105_i2c_xfer(&dm1105dvb->i2c_adap, msg , 2);
688 dev_info(&dm1105dvb->pdev->dev, "MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
689 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
690}
691
692static int __devinit dm1105_probe(struct pci_dev *pdev,
693 const struct pci_device_id *ent)
694{
695 struct dm1105dvb *dm1105dvb;
696 struct dvb_adapter *dvb_adapter;
697 struct dvb_demux *dvbdemux;
698 struct dmx_demux *dmx;
699 int ret = -ENOMEM;
700
701 dm1105dvb = kzalloc(sizeof(struct dm1105dvb), GFP_KERNEL);
702 if (!dm1105dvb)
703 goto out;
704
705 dm1105dvb->pdev = pdev;
706 dm1105dvb->buffer_size = 5 * DM1105_DMA_BYTES;
707 dm1105dvb->PacketErrorCount = 0;
708 dm1105dvb->dmarst = 0;
709
710 ret = pci_enable_device(pdev);
711 if (ret < 0)
712 goto err_kfree;
713
714 ret = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
715 if (ret < 0)
716 goto err_pci_disable_device;
717
718 pci_set_master(pdev);
719
720 ret = pci_request_regions(pdev, DRIVER_NAME);
721 if (ret < 0)
722 goto err_pci_disable_device;
723
724 dm1105dvb->io_mem = pci_iomap(pdev, 0, pci_resource_len(pdev, 0));
725 if (!dm1105dvb->io_mem) {
726 ret = -EIO;
727 goto err_pci_release_regions;
728 }
729
730 spin_lock_init(&dm1105dvb->lock);
731 pci_set_drvdata(pdev, dm1105dvb);
732
733 ret = request_irq(pdev->irq, dm1105dvb_irq, IRQF_SHARED, DRIVER_NAME, dm1105dvb);
734 if (ret < 0)
735 goto err_pci_iounmap;
736
737 ret = dm1105dvb_hw_init(dm1105dvb);
738 if (ret < 0)
739 goto err_free_irq;
740
741 /* i2c */
742 i2c_set_adapdata(&dm1105dvb->i2c_adap, dm1105dvb);
743 strcpy(dm1105dvb->i2c_adap.name, DRIVER_NAME);
744 dm1105dvb->i2c_adap.owner = THIS_MODULE;
745 dm1105dvb->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
746 dm1105dvb->i2c_adap.dev.parent = &pdev->dev;
747 dm1105dvb->i2c_adap.algo = &dm1105_algo;
748 dm1105dvb->i2c_adap.algo_data = dm1105dvb;
749 ret = i2c_add_adapter(&dm1105dvb->i2c_adap);
750
751 if (ret < 0)
752 goto err_dm1105dvb_hw_exit;
753
754 /* dvb */
755 ret = dvb_register_adapter(&dm1105dvb->dvb_adapter, DRIVER_NAME,
756 THIS_MODULE, &pdev->dev, adapter_nr);
757 if (ret < 0)
758 goto err_i2c_del_adapter;
759
760 dvb_adapter = &dm1105dvb->dvb_adapter;
761
762 dm1105dvb_read_mac(dm1105dvb, dvb_adapter->proposed_mac);
763
764 dvbdemux = &dm1105dvb->demux;
765 dvbdemux->filternum = 256;
766 dvbdemux->feednum = 256;
767 dvbdemux->start_feed = dm1105dvb_start_feed;
768 dvbdemux->stop_feed = dm1105dvb_stop_feed;
769 dvbdemux->dmx.capabilities = (DMX_TS_FILTERING |
770 DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING);
771 ret = dvb_dmx_init(dvbdemux);
772 if (ret < 0)
773 goto err_dvb_unregister_adapter;
774
775 dmx = &dvbdemux->dmx;
776 dm1105dvb->dmxdev.filternum = 256;
777 dm1105dvb->dmxdev.demux = dmx;
778 dm1105dvb->dmxdev.capabilities = 0;
779
780 ret = dvb_dmxdev_init(&dm1105dvb->dmxdev, dvb_adapter);
781 if (ret < 0)
782 goto err_dvb_dmx_release;
783
784 dm1105dvb->hw_frontend.source = DMX_FRONTEND_0;
785
786 ret = dmx->add_frontend(dmx, &dm1105dvb->hw_frontend);
787 if (ret < 0)
788 goto err_dvb_dmxdev_release;
789
790 dm1105dvb->mem_frontend.source = DMX_MEMORY_FE;
791
792 ret = dmx->add_frontend(dmx, &dm1105dvb->mem_frontend);
793 if (ret < 0)
794 goto err_remove_hw_frontend;
795
796 ret = dmx->connect_frontend(dmx, &dm1105dvb->hw_frontend);
797 if (ret < 0)
798 goto err_remove_mem_frontend;
799
800 ret = frontend_init(dm1105dvb);
801 if (ret < 0)
802 goto err_disconnect_frontend;
803
804 dvb_net_init(dvb_adapter, &dm1105dvb->dvbnet, dmx);
805 dm1105_ir_init(dm1105dvb);
806out:
807 return ret;
808
809err_disconnect_frontend:
810 dmx->disconnect_frontend(dmx);
811err_remove_mem_frontend:
812 dmx->remove_frontend(dmx, &dm1105dvb->mem_frontend);
813err_remove_hw_frontend:
814 dmx->remove_frontend(dmx, &dm1105dvb->hw_frontend);
815err_dvb_dmxdev_release:
816 dvb_dmxdev_release(&dm1105dvb->dmxdev);
817err_dvb_dmx_release:
818 dvb_dmx_release(dvbdemux);
819err_dvb_unregister_adapter:
820 dvb_unregister_adapter(dvb_adapter);
821err_i2c_del_adapter:
822 i2c_del_adapter(&dm1105dvb->i2c_adap);
823err_dm1105dvb_hw_exit:
824 dm1105dvb_hw_exit(dm1105dvb);
825err_free_irq:
826 free_irq(pdev->irq, dm1105dvb);
827err_pci_iounmap:
828 pci_iounmap(pdev, dm1105dvb->io_mem);
829err_pci_release_regions:
830 pci_release_regions(pdev);
831err_pci_disable_device:
832 pci_disable_device(pdev);
833err_kfree:
834 pci_set_drvdata(pdev, NULL);
835 kfree(dm1105dvb);
836 goto out;
837}
838
839static void __devexit dm1105_remove(struct pci_dev *pdev)
840{
841 struct dm1105dvb *dm1105dvb = pci_get_drvdata(pdev);
842 struct dvb_adapter *dvb_adapter = &dm1105dvb->dvb_adapter;
843 struct dvb_demux *dvbdemux = &dm1105dvb->demux;
844 struct dmx_demux *dmx = &dvbdemux->dmx;
845
846 dm1105_ir_exit(dm1105dvb);
847 dmx->close(dmx);
848 dvb_net_release(&dm1105dvb->dvbnet);
849 if (dm1105dvb->fe)
850 dvb_unregister_frontend(dm1105dvb->fe);
851
852 dmx->disconnect_frontend(dmx);
853 dmx->remove_frontend(dmx, &dm1105dvb->mem_frontend);
854 dmx->remove_frontend(dmx, &dm1105dvb->hw_frontend);
855 dvb_dmxdev_release(&dm1105dvb->dmxdev);
856 dvb_dmx_release(dvbdemux);
857 dvb_unregister_adapter(dvb_adapter);
858 if (&dm1105dvb->i2c_adap)
859 i2c_del_adapter(&dm1105dvb->i2c_adap);
860
861 dm1105dvb_hw_exit(dm1105dvb);
862 synchronize_irq(pdev->irq);
863 free_irq(pdev->irq, dm1105dvb);
864 pci_iounmap(pdev, dm1105dvb->io_mem);
865 pci_release_regions(pdev);
866 pci_disable_device(pdev);
867 pci_set_drvdata(pdev, NULL);
868 kfree(dm1105dvb);
869}
870
871static struct pci_device_id dm1105_id_table[] __devinitdata = {
872 {
873 .vendor = PCI_VENDOR_ID_TRIGEM,
874 .device = PCI_DEVICE_ID_DM1105,
875 .subvendor = PCI_ANY_ID,
876 .subdevice = PCI_DEVICE_ID_DW2002,
877 }, {
878 .vendor = PCI_VENDOR_ID_TRIGEM,
879 .device = PCI_DEVICE_ID_DM1105,
880 .subvendor = PCI_ANY_ID,
881 .subdevice = PCI_DEVICE_ID_DW2004,
882 }, {
883 /* empty */
884 },
885};
886
887MODULE_DEVICE_TABLE(pci, dm1105_id_table);
888
889static struct pci_driver dm1105_driver = {
890 .name = DRIVER_NAME,
891 .id_table = dm1105_id_table,
892 .probe = dm1105_probe,
893 .remove = __devexit_p(dm1105_remove),
894};
895
896static int __init dm1105_init(void)
897{
898 return pci_register_driver(&dm1105_driver);
899}
900
901static void __exit dm1105_exit(void)
902{
903 pci_unregister_driver(&dm1105_driver);
904}
905
906module_init(dm1105_init);
907module_exit(dm1105_exit);
908
909MODULE_AUTHOR("Igor M. Liplianin <liplianin@me.by>");
910MODULE_DESCRIPTION("SDMC DM1105 DVB driver");
911MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index 3526e3ee9487..f170e822fadc 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -40,6 +40,7 @@
40 40
41#include "dvb_frontend.h" 41#include "dvb_frontend.h"
42#include "dvbdev.h" 42#include "dvbdev.h"
43#include <linux/dvb/version.h>
43 44
44static int dvb_frontend_debug; 45static int dvb_frontend_debug;
45static int dvb_shutdown_timeout; 46static int dvb_shutdown_timeout;
@@ -755,6 +756,539 @@ static int dvb_frontend_check_parameters(struct dvb_frontend *fe,
755 return 0; 756 return 0;
756} 757}
757 758
759struct dtv_cmds_h dtv_cmds[] = {
760 [DTV_TUNE] = {
761 .name = "DTV_TUNE",
762 .cmd = DTV_TUNE,
763 .set = 1,
764 },
765 [DTV_CLEAR] = {
766 .name = "DTV_CLEAR",
767 .cmd = DTV_CLEAR,
768 .set = 1,
769 },
770
771 /* Set */
772 [DTV_FREQUENCY] = {
773 .name = "DTV_FREQUENCY",
774 .cmd = DTV_FREQUENCY,
775 .set = 1,
776 },
777 [DTV_BANDWIDTH_HZ] = {
778 .name = "DTV_BANDWIDTH_HZ",
779 .cmd = DTV_BANDWIDTH_HZ,
780 .set = 1,
781 },
782 [DTV_MODULATION] = {
783 .name = "DTV_MODULATION",
784 .cmd = DTV_MODULATION,
785 .set = 1,
786 },
787 [DTV_INVERSION] = {
788 .name = "DTV_INVERSION",
789 .cmd = DTV_INVERSION,
790 .set = 1,
791 },
792 [DTV_DISEQC_MASTER] = {
793 .name = "DTV_DISEQC_MASTER",
794 .cmd = DTV_DISEQC_MASTER,
795 .set = 1,
796 .buffer = 1,
797 },
798 [DTV_SYMBOL_RATE] = {
799 .name = "DTV_SYMBOL_RATE",
800 .cmd = DTV_SYMBOL_RATE,
801 .set = 1,
802 },
803 [DTV_INNER_FEC] = {
804 .name = "DTV_INNER_FEC",
805 .cmd = DTV_INNER_FEC,
806 .set = 1,
807 },
808 [DTV_VOLTAGE] = {
809 .name = "DTV_VOLTAGE",
810 .cmd = DTV_VOLTAGE,
811 .set = 1,
812 },
813 [DTV_TONE] = {
814 .name = "DTV_TONE",
815 .cmd = DTV_TONE,
816 .set = 1,
817 },
818 [DTV_PILOT] = {
819 .name = "DTV_PILOT",
820 .cmd = DTV_PILOT,
821 .set = 1,
822 },
823 [DTV_ROLLOFF] = {
824 .name = "DTV_ROLLOFF",
825 .cmd = DTV_ROLLOFF,
826 .set = 1,
827 },
828 [DTV_DELIVERY_SYSTEM] = {
829 .name = "DTV_DELIVERY_SYSTEM",
830 .cmd = DTV_DELIVERY_SYSTEM,
831 .set = 1,
832 },
833 [DTV_HIERARCHY] = {
834 .name = "DTV_HIERARCHY",
835 .cmd = DTV_HIERARCHY,
836 .set = 1,
837 },
838 [DTV_CODE_RATE_HP] = {
839 .name = "DTV_CODE_RATE_HP",
840 .cmd = DTV_CODE_RATE_HP,
841 .set = 1,
842 },
843 [DTV_CODE_RATE_LP] = {
844 .name = "DTV_CODE_RATE_LP",
845 .cmd = DTV_CODE_RATE_LP,
846 .set = 1,
847 },
848 [DTV_GUARD_INTERVAL] = {
849 .name = "DTV_GUARD_INTERVAL",
850 .cmd = DTV_GUARD_INTERVAL,
851 .set = 1,
852 },
853 [DTV_TRANSMISSION_MODE] = {
854 .name = "DTV_TRANSMISSION_MODE",
855 .cmd = DTV_TRANSMISSION_MODE,
856 .set = 1,
857 },
858 /* Get */
859 [DTV_DISEQC_SLAVE_REPLY] = {
860 .name = "DTV_DISEQC_SLAVE_REPLY",
861 .cmd = DTV_DISEQC_SLAVE_REPLY,
862 .set = 0,
863 .buffer = 1,
864 },
865 [DTV_API_VERSION] = {
866 .name = "DTV_API_VERSION",
867 .cmd = DTV_API_VERSION,
868 .set = 0,
869 },
870 [DTV_CODE_RATE_HP] = {
871 .name = "DTV_CODE_RATE_HP",
872 .cmd = DTV_CODE_RATE_HP,
873 .set = 0,
874 },
875 [DTV_CODE_RATE_LP] = {
876 .name = "DTV_CODE_RATE_LP",
877 .cmd = DTV_CODE_RATE_LP,
878 .set = 0,
879 },
880 [DTV_GUARD_INTERVAL] = {
881 .name = "DTV_GUARD_INTERVAL",
882 .cmd = DTV_GUARD_INTERVAL,
883 .set = 0,
884 },
885 [DTV_TRANSMISSION_MODE] = {
886 .name = "DTV_TRANSMISSION_MODE",
887 .cmd = DTV_TRANSMISSION_MODE,
888 .set = 0,
889 },
890 [DTV_HIERARCHY] = {
891 .name = "DTV_HIERARCHY",
892 .cmd = DTV_HIERARCHY,
893 .set = 0,
894 },
895};
896
897void dtv_property_dump(struct dtv_property *tvp)
898{
899 int i;
900
901 if (tvp->cmd <= 0 || tvp->cmd > DTV_MAX_COMMAND) {
902 printk("%s: tvp.cmd = 0x%08x (undefined/unknown/invalid)\n",
903 __func__, tvp->cmd);
904 return;
905 }
906
907 printk("%s() tvp.cmd = 0x%08x (%s)\n"
908 ,__FUNCTION__
909 ,tvp->cmd
910 ,dtv_cmds[ tvp->cmd ].name);
911
912 if(dtv_cmds[ tvp->cmd ].buffer) {
913
914 printk("%s() tvp.u.buffer.len = 0x%02x\n"
915 ,__FUNCTION__
916 ,tvp->u.buffer.len);
917
918 for(i = 0; i < tvp->u.buffer.len; i++)
919 printk("%s() tvp.u.buffer.data[0x%02x] = 0x%02x\n"
920 ,__FUNCTION__
921 ,i
922 ,tvp->u.buffer.data[i]);
923
924 } else
925 printk("%s() tvp.u.data = 0x%08x\n", __FUNCTION__, tvp->u.data);
926}
927
928int is_legacy_delivery_system(fe_delivery_system_t s)
929{
930 if((s == SYS_UNDEFINED) || (s == SYS_DVBC_ANNEX_AC) ||
931 (s == SYS_DVBC_ANNEX_B) || (s == SYS_DVBT) || (s == SYS_DVBS))
932 return 1;
933
934 return 0;
935}
936
937/* Synchronise the legacy tuning parameters into the cache, so that demodulator
938 * drivers can use a single set_frontend tuning function, regardless of whether
939 * it's being used for the legacy or new API, reducing code and complexity.
940 */
941void dtv_property_cache_sync(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
942{
943 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
944
945 printk("%s()\n", __FUNCTION__);
946
947 c->frequency = p->frequency;
948 c->inversion = p->inversion;
949
950 switch (fe->ops.info.type) {
951 case FE_QPSK:
952 c->modulation = QPSK; /* implied for DVB-S in legacy API */
953 c->rolloff = ROLLOFF_35;/* implied for DVB-S */
954 c->symbol_rate = p->u.qpsk.symbol_rate;
955 c->fec_inner = p->u.qpsk.fec_inner;
956 c->delivery_system = SYS_DVBS;
957 break;
958 case FE_QAM:
959 c->symbol_rate = p->u.qam.symbol_rate;
960 c->fec_inner = p->u.qam.fec_inner;
961 c->modulation = p->u.qam.modulation;
962 c->delivery_system = SYS_DVBC_ANNEX_AC;
963 break;
964 case FE_OFDM:
965 if (p->u.ofdm.bandwidth == BANDWIDTH_6_MHZ)
966 c->bandwidth_hz = 6000000;
967 else if (p->u.ofdm.bandwidth == BANDWIDTH_7_MHZ)
968 c->bandwidth_hz = 7000000;
969 else if (p->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
970 c->bandwidth_hz = 8000000;
971 else
972 /* Including BANDWIDTH_AUTO */
973 c->bandwidth_hz = 0;
974 c->code_rate_HP = p->u.ofdm.code_rate_HP;
975 c->code_rate_LP = p->u.ofdm.code_rate_LP;
976 c->modulation = p->u.ofdm.constellation;
977 c->transmission_mode = p->u.ofdm.transmission_mode;
978 c->guard_interval = p->u.ofdm.guard_interval;
979 c->hierarchy = p->u.ofdm.hierarchy_information;
980 c->delivery_system = SYS_DVBT;
981 break;
982 case FE_ATSC:
983 c->modulation = p->u.vsb.modulation;
984 if ((c->modulation == VSB_8) || (c->modulation == VSB_16))
985 c->delivery_system = SYS_ATSC;
986 else
987 c->delivery_system = SYS_DVBC_ANNEX_B;
988 break;
989 }
990}
991
992/* Ensure the cached values are set correctly in the frontend
993 * legacy tuning structures, for the advanced tuning API.
994 */
995void dtv_property_legacy_params_sync(struct dvb_frontend *fe)
996{
997 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
998 struct dvb_frontend_private *fepriv = fe->frontend_priv;
999 struct dvb_frontend_parameters *p = &fepriv->parameters;
1000
1001 printk("%s()\n", __FUNCTION__);
1002
1003 p->frequency = c->frequency;
1004 p->inversion = c->inversion;
1005
1006 switch (fe->ops.info.type) {
1007 case FE_QPSK:
1008 printk("%s() Preparing QPSK req\n", __FUNCTION__);
1009 p->u.qpsk.symbol_rate = c->symbol_rate;
1010 p->u.qpsk.fec_inner = c->fec_inner;
1011 c->delivery_system = SYS_DVBS;
1012 break;
1013 case FE_QAM:
1014 printk("%s() Preparing QAM req\n", __FUNCTION__);
1015 p->u.qam.symbol_rate = c->symbol_rate;
1016 p->u.qam.fec_inner = c->fec_inner;
1017 p->u.qam.modulation = c->modulation;
1018 c->delivery_system = SYS_DVBC_ANNEX_AC;
1019 break;
1020 case FE_OFDM:
1021 printk("%s() Preparing OFDM req\n", __FUNCTION__);
1022 if (c->bandwidth_hz == 6000000)
1023 p->u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
1024 else if (c->bandwidth_hz == 7000000)
1025 p->u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
1026 else if (c->bandwidth_hz == 8000000)
1027 p->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
1028 else
1029 p->u.ofdm.bandwidth = BANDWIDTH_AUTO;
1030 p->u.ofdm.code_rate_HP = c->code_rate_HP;
1031 p->u.ofdm.code_rate_LP = c->code_rate_LP;
1032 p->u.ofdm.constellation = c->modulation;
1033 p->u.ofdm.transmission_mode = c->transmission_mode;
1034 p->u.ofdm.guard_interval = c->guard_interval;
1035 p->u.ofdm.hierarchy_information = c->hierarchy;
1036 c->delivery_system = SYS_DVBT;
1037 break;
1038 case FE_ATSC:
1039 printk("%s() Preparing VSB req\n", __FUNCTION__);
1040 p->u.vsb.modulation = c->modulation;
1041 if ((c->modulation == VSB_8) || (c->modulation == VSB_16))
1042 c->delivery_system = SYS_ATSC;
1043 else
1044 c->delivery_system = SYS_DVBC_ANNEX_B;
1045 break;
1046 }
1047}
1048
1049/* Ensure the cached values are set correctly in the frontend
1050 * legacy tuning structures, for the legacy tuning API.
1051 */
1052void dtv_property_adv_params_sync(struct dvb_frontend *fe)
1053{
1054 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1055 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1056 struct dvb_frontend_parameters *p = &fepriv->parameters;
1057
1058 printk("%s()\n", __FUNCTION__);
1059
1060 p->frequency = c->frequency;
1061 p->inversion = c->inversion;
1062
1063 switch(c->modulation) {
1064 case PSK_8:
1065 case APSK_16:
1066 case QPSK:
1067 p->u.qpsk.symbol_rate = c->symbol_rate;
1068 p->u.qpsk.fec_inner = c->fec_inner;
1069 break;
1070 default:
1071 break;
1072 }
1073
1074 if(c->delivery_system == SYS_ISDBT) {
1075 /* Fake out a generic DVB-T request so we pass validation in the ioctl */
1076 p->frequency = c->frequency;
1077 p->inversion = INVERSION_AUTO;
1078 p->u.ofdm.constellation = QAM_AUTO;
1079 p->u.ofdm.code_rate_HP = FEC_AUTO;
1080 p->u.ofdm.code_rate_LP = FEC_AUTO;
1081 p->u.ofdm.bandwidth = BANDWIDTH_AUTO;
1082 p->u.ofdm.transmission_mode = TRANSMISSION_MODE_AUTO;
1083 p->u.ofdm.guard_interval = GUARD_INTERVAL_AUTO;
1084 p->u.ofdm.hierarchy_information = HIERARCHY_AUTO;
1085 }
1086}
1087
1088void dtv_property_cache_submit(struct dvb_frontend *fe)
1089{
1090 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1091
1092 printk("%s()\n", __FUNCTION__);
1093
1094 /* For legacy delivery systems we don't need the delivery_system to
1095 * be specified, but we populate the older structures from the cache
1096 * so we can call set_frontend on older drivers.
1097 */
1098 if(is_legacy_delivery_system(c->delivery_system)) {
1099
1100 printk("%s() legacy, modulation = %d\n", __FUNCTION__, c->modulation);
1101 dtv_property_legacy_params_sync(fe);
1102
1103 } else {
1104 printk("%s() adv, modulation = %d\n", __FUNCTION__, c->modulation);
1105
1106 /* For advanced delivery systems / modulation types ...
1107 * we seed the lecacy dvb_frontend_parameters structure
1108 * so that the sanity checking code later in the IOCTL processing
1109 * can validate our basic frequency ranges, symbolrates, modulation
1110 * etc.
1111 */
1112 dtv_property_adv_params_sync(fe);
1113 }
1114}
1115
1116static int dvb_frontend_ioctl_legacy(struct inode *inode, struct file *file,
1117 unsigned int cmd, void *parg);
1118static int dvb_frontend_ioctl_properties(struct inode *inode, struct file *file,
1119 unsigned int cmd, void *parg);
1120
1121int dtv_property_process_get(struct dvb_frontend *fe, struct dtv_property *tvp,
1122 struct inode *inode, struct file *file)
1123{
1124 int r = 0;
1125
1126 printk("%s()\n", __FUNCTION__);
1127
1128 dtv_property_dump(tvp);
1129
1130 /* Allow the frontend to validate incoming properties */
1131 if (fe->ops.get_property)
1132 r = fe->ops.get_property(fe, tvp);
1133
1134 if (r < 0)
1135 return r;
1136
1137 switch(tvp->cmd) {
1138 case DTV_FREQUENCY:
1139 tvp->u.data = fe->dtv_property_cache.frequency;
1140 break;
1141 case DTV_MODULATION:
1142 tvp->u.data = fe->dtv_property_cache.modulation;
1143 break;
1144 case DTV_BANDWIDTH_HZ:
1145 tvp->u.data = fe->dtv_property_cache.bandwidth_hz;
1146 break;
1147 case DTV_INVERSION:
1148 tvp->u.data = fe->dtv_property_cache.inversion;
1149 break;
1150 case DTV_SYMBOL_RATE:
1151 tvp->u.data = fe->dtv_property_cache.symbol_rate;
1152 break;
1153 case DTV_INNER_FEC:
1154 tvp->u.data = fe->dtv_property_cache.fec_inner;
1155 break;
1156 case DTV_PILOT:
1157 tvp->u.data = fe->dtv_property_cache.pilot;
1158 break;
1159 case DTV_ROLLOFF:
1160 tvp->u.data = fe->dtv_property_cache.rolloff;
1161 break;
1162 case DTV_DELIVERY_SYSTEM:
1163 tvp->u.data = fe->dtv_property_cache.delivery_system;
1164 break;
1165 case DTV_VOLTAGE:
1166 tvp->u.data = fe->dtv_property_cache.voltage;
1167 break;
1168 case DTV_TONE:
1169 tvp->u.data = fe->dtv_property_cache.sectone;
1170 break;
1171 case DTV_API_VERSION:
1172 tvp->u.data = (DVB_API_VERSION << 8) | DVB_API_VERSION_MINOR;
1173 break;
1174 case DTV_CODE_RATE_HP:
1175 tvp->u.data = fe->dtv_property_cache.code_rate_HP;
1176 break;
1177 case DTV_CODE_RATE_LP:
1178 tvp->u.data = fe->dtv_property_cache.code_rate_LP;
1179 break;
1180 case DTV_GUARD_INTERVAL:
1181 tvp->u.data = fe->dtv_property_cache.guard_interval;
1182 break;
1183 case DTV_TRANSMISSION_MODE:
1184 tvp->u.data = fe->dtv_property_cache.transmission_mode;
1185 break;
1186 case DTV_HIERARCHY:
1187 tvp->u.data = fe->dtv_property_cache.hierarchy;
1188 break;
1189 default:
1190 r = -1;
1191 }
1192
1193 return r;
1194}
1195
1196int dtv_property_process_set(struct dvb_frontend *fe, struct dtv_property *tvp,
1197 struct inode *inode, struct file *file)
1198{
1199 int r = 0;
1200 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1201 printk("%s()\n", __FUNCTION__);
1202 dtv_property_dump(tvp);
1203
1204 /* Allow the frontend to validate incoming properties */
1205 if (fe->ops.set_property)
1206 r = fe->ops.set_property(fe, tvp);
1207
1208 if (r < 0)
1209 return r;
1210
1211 switch(tvp->cmd) {
1212 case DTV_CLEAR:
1213 /* Reset a cache of data specific to the frontend here. This does
1214 * not effect hardware.
1215 */
1216 printk("%s() Flushing property cache\n", __FUNCTION__);
1217 memset(&fe->dtv_property_cache, 0, sizeof(struct dtv_frontend_properties));
1218 fe->dtv_property_cache.state = tvp->cmd;
1219 fe->dtv_property_cache.delivery_system = SYS_UNDEFINED;
1220 break;
1221 case DTV_TUNE:
1222 /* interpret the cache of data, build either a traditional frontend
1223 * tunerequest so we can pass validation in the FE_SET_FRONTEND
1224 * ioctl.
1225 */
1226 fe->dtv_property_cache.state = tvp->cmd;
1227 printk("%s() Finalised property cache\n", __FUNCTION__);
1228 dtv_property_cache_submit(fe);
1229
1230 r |= dvb_frontend_ioctl_legacy(inode, file, FE_SET_FRONTEND,
1231 &fepriv->parameters);
1232 break;
1233 case DTV_FREQUENCY:
1234 fe->dtv_property_cache.frequency = tvp->u.data;
1235 break;
1236 case DTV_MODULATION:
1237 fe->dtv_property_cache.modulation = tvp->u.data;
1238 break;
1239 case DTV_BANDWIDTH_HZ:
1240 fe->dtv_property_cache.bandwidth_hz = tvp->u.data;
1241 break;
1242 case DTV_INVERSION:
1243 fe->dtv_property_cache.inversion = tvp->u.data;
1244 break;
1245 case DTV_SYMBOL_RATE:
1246 fe->dtv_property_cache.symbol_rate = tvp->u.data;
1247 break;
1248 case DTV_INNER_FEC:
1249 fe->dtv_property_cache.fec_inner = tvp->u.data;
1250 break;
1251 case DTV_PILOT:
1252 fe->dtv_property_cache.pilot = tvp->u.data;
1253 break;
1254 case DTV_ROLLOFF:
1255 fe->dtv_property_cache.rolloff = tvp->u.data;
1256 break;
1257 case DTV_DELIVERY_SYSTEM:
1258 fe->dtv_property_cache.delivery_system = tvp->u.data;
1259 break;
1260 case DTV_VOLTAGE:
1261 fe->dtv_property_cache.voltage = tvp->u.data;
1262 r = dvb_frontend_ioctl_legacy(inode, file, FE_SET_VOLTAGE,
1263 (void *)fe->dtv_property_cache.voltage);
1264 break;
1265 case DTV_TONE:
1266 fe->dtv_property_cache.sectone = tvp->u.data;
1267 r = dvb_frontend_ioctl_legacy(inode, file, FE_SET_TONE,
1268 (void *)fe->dtv_property_cache.sectone);
1269 break;
1270 case DTV_CODE_RATE_HP:
1271 fe->dtv_property_cache.code_rate_HP = tvp->u.data;
1272 break;
1273 case DTV_CODE_RATE_LP:
1274 fe->dtv_property_cache.code_rate_LP = tvp->u.data;
1275 break;
1276 case DTV_GUARD_INTERVAL:
1277 fe->dtv_property_cache.guard_interval = tvp->u.data;
1278 break;
1279 case DTV_TRANSMISSION_MODE:
1280 fe->dtv_property_cache.transmission_mode = tvp->u.data;
1281 break;
1282 case DTV_HIERARCHY:
1283 fe->dtv_property_cache.hierarchy = tvp->u.data;
1284 break;
1285 default:
1286 r = -1;
1287 }
1288
1289 return r;
1290}
1291
758static int dvb_frontend_ioctl(struct inode *inode, struct file *file, 1292static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
759 unsigned int cmd, void *parg) 1293 unsigned int cmd, void *parg)
760{ 1294{
@@ -776,6 +1310,116 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
776 if (down_interruptible (&fepriv->sem)) 1310 if (down_interruptible (&fepriv->sem))
777 return -ERESTARTSYS; 1311 return -ERESTARTSYS;
778 1312
1313 if ((cmd == FE_SET_PROPERTY) || (cmd == FE_GET_PROPERTY))
1314 err = dvb_frontend_ioctl_properties(inode, file, cmd, parg);
1315 else {
1316 fe->dtv_property_cache.state = DTV_UNDEFINED;
1317 err = dvb_frontend_ioctl_legacy(inode, file, cmd, parg);
1318 }
1319
1320 up(&fepriv->sem);
1321 return err;
1322}
1323
1324static int dvb_frontend_ioctl_properties(struct inode *inode, struct file *file,
1325 unsigned int cmd, void *parg)
1326{
1327 struct dvb_device *dvbdev = file->private_data;
1328 struct dvb_frontend *fe = dvbdev->priv;
1329 int err = 0;
1330
1331 struct dtv_properties *tvps = NULL;
1332 struct dtv_property *tvp = NULL;
1333 int i;
1334
1335 dprintk("%s\n", __func__);
1336
1337 if(cmd == FE_SET_PROPERTY) {
1338 printk("%s() FE_SET_PROPERTY\n", __FUNCTION__);
1339
1340 tvps = (struct dtv_properties __user *)parg;
1341
1342 printk("%s() properties.num = %d\n", __FUNCTION__, tvps->num);
1343 printk("%s() properties.props = %p\n", __FUNCTION__, tvps->props);
1344
1345 /* Put an arbitrary limit on the number of messages that can
1346 * be sent at once */
1347 if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS))
1348 return -EINVAL;
1349
1350 tvp = (struct dtv_property *) kmalloc(tvps->num *
1351 sizeof(struct dtv_property), GFP_KERNEL);
1352 if (!tvp) {
1353 err = -ENOMEM;
1354 goto out;
1355 }
1356
1357 if (copy_from_user(tvp, tvps->props, tvps->num * sizeof(struct dtv_property))) {
1358 err = -EFAULT;
1359 goto out;
1360 }
1361
1362 for (i = 0; i < tvps->num; i++) {
1363 (tvp + i)->result = dtv_property_process_set(fe, tvp + i, inode, file);
1364 err |= (tvp + i)->result;
1365 }
1366
1367 if(fe->dtv_property_cache.state == DTV_TUNE) {
1368 printk("%s() Property cache is full, tuning\n", __FUNCTION__);
1369 }
1370
1371 } else
1372 if(cmd == FE_GET_PROPERTY) {
1373 printk("%s() FE_GET_PROPERTY\n", __FUNCTION__);
1374
1375 tvps = (struct dtv_properties __user *)parg;
1376
1377 printk("%s() properties.num = %d\n", __FUNCTION__, tvps->num);
1378 printk("%s() properties.props = %p\n", __FUNCTION__, tvps->props);
1379
1380 /* Put an arbitrary limit on the number of messages that can
1381 * be sent at once */
1382 if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS))
1383 return -EINVAL;
1384
1385 tvp = (struct dtv_property *) kmalloc(tvps->num *
1386 sizeof(struct dtv_property), GFP_KERNEL);
1387 if (!tvp) {
1388 err = -ENOMEM;
1389 goto out;
1390 }
1391
1392 if (copy_from_user(tvp, tvps->props, tvps->num * sizeof(struct dtv_property))) {
1393 err = -EFAULT;
1394 goto out;
1395 }
1396
1397 for (i = 0; i < tvps->num; i++) {
1398 (tvp + i)->result = dtv_property_process_get(fe, tvp + i, inode, file);
1399 err |= (tvp + i)->result;
1400 }
1401
1402 if (copy_to_user(tvps->props, tvp, tvps->num * sizeof(struct dtv_property))) {
1403 err = -EFAULT;
1404 goto out;
1405 }
1406
1407 } else
1408 err = -EOPNOTSUPP;
1409
1410out:
1411 kfree(tvp);
1412 return err;
1413}
1414
1415static int dvb_frontend_ioctl_legacy(struct inode *inode, struct file *file,
1416 unsigned int cmd, void *parg)
1417{
1418 struct dvb_device *dvbdev = file->private_data;
1419 struct dvb_frontend *fe = dvbdev->priv;
1420 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1421 int err = -EOPNOTSUPP;
1422
779 switch (cmd) { 1423 switch (cmd) {
780 case FE_GET_INFO: { 1424 case FE_GET_INFO: {
781 struct dvb_frontend_info* info = parg; 1425 struct dvb_frontend_info* info = parg;
@@ -942,13 +1586,21 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
942 case FE_SET_FRONTEND: { 1586 case FE_SET_FRONTEND: {
943 struct dvb_frontend_tune_settings fetunesettings; 1587 struct dvb_frontend_tune_settings fetunesettings;
944 1588
945 if (dvb_frontend_check_parameters(fe, parg) < 0) { 1589 if(fe->dtv_property_cache.state == DTV_TUNE) {
946 err = -EINVAL; 1590 if (dvb_frontend_check_parameters(fe, &fepriv->parameters) < 0) {
947 break; 1591 err = -EINVAL;
948 } 1592 break;
1593 }
1594 } else {
1595 if (dvb_frontend_check_parameters(fe, parg) < 0) {
1596 err = -EINVAL;
1597 break;
1598 }
949 1599
950 memcpy (&fepriv->parameters, parg, 1600 memcpy (&fepriv->parameters, parg,
951 sizeof (struct dvb_frontend_parameters)); 1601 sizeof (struct dvb_frontend_parameters));
1602 dtv_property_cache_sync(fe, &fepriv->parameters);
1603 }
952 1604
953 memset(&fetunesettings, 0, sizeof(struct dvb_frontend_tune_settings)); 1605 memset(&fetunesettings, 0, sizeof(struct dvb_frontend_tune_settings));
954 memcpy(&fetunesettings.parameters, parg, 1606 memcpy(&fetunesettings.parameters, parg,
@@ -1027,10 +1679,10 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
1027 break; 1679 break;
1028 }; 1680 };
1029 1681
1030 up (&fepriv->sem);
1031 return err; 1682 return err;
1032} 1683}
1033 1684
1685
1034static unsigned int dvb_frontend_poll(struct file *file, struct poll_table_struct *wait) 1686static unsigned int dvb_frontend_poll(struct file *file, struct poll_table_struct *wait)
1035{ 1687{
1036 struct dvb_device *dvbdev = file->private_data; 1688 struct dvb_device *dvbdev = file->private_data;
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.h b/drivers/media/dvb/dvb-core/dvb_frontend.h
index aa4133f0bd19..3055301ff3ca 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.h
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.h
@@ -169,6 +169,9 @@ struct dvb_frontend_ops {
169 169
170 struct dvb_tuner_ops tuner_ops; 170 struct dvb_tuner_ops tuner_ops;
171 struct analog_demod_ops analog_ops; 171 struct analog_demod_ops analog_ops;
172
173 int (*set_property)(struct dvb_frontend* fe, struct dtv_property* tvp);
174 int (*get_property)(struct dvb_frontend* fe, struct dtv_property* tvp);
172}; 175};
173 176
174#define MAX_EVENT 8 177#define MAX_EVENT 8
@@ -182,6 +185,32 @@ struct dvb_fe_events {
182 struct mutex mtx; 185 struct mutex mtx;
183}; 186};
184 187
188struct dtv_frontend_properties {
189
190 /* Cache State */
191 u32 state;
192
193 u32 frequency;
194 fe_modulation_t modulation;
195
196 fe_sec_voltage_t voltage;
197 fe_sec_tone_mode_t sectone;
198 fe_spectral_inversion_t inversion;
199 fe_code_rate_t fec_inner;
200 fe_transmit_mode_t transmission_mode;
201 u32 bandwidth_hz; /* 0 = AUTO */
202 fe_guard_interval_t guard_interval;
203 fe_hierarchy_t hierarchy;
204 u32 symbol_rate;
205 fe_code_rate_t code_rate_HP;
206 fe_code_rate_t code_rate_LP;
207
208 fe_pilot_t pilot;
209 fe_rolloff_t rolloff;
210
211 fe_delivery_system_t delivery_system;
212};
213
185struct dvb_frontend { 214struct dvb_frontend {
186 struct dvb_frontend_ops ops; 215 struct dvb_frontend_ops ops;
187 struct dvb_adapter *dvb; 216 struct dvb_adapter *dvb;
@@ -190,6 +219,9 @@ struct dvb_frontend {
190 void *frontend_priv; 219 void *frontend_priv;
191 void *sec_priv; 220 void *sec_priv;
192 void *analog_demod_priv; 221 void *analog_demod_priv;
222 struct dtv_frontend_properties dtv_property_cache;
223#define DVB_FRONTEND_COMPONENT_TUNER 0
224 int (*callback)(void *adapter_priv, int component, int cmd, int arg);
193}; 225};
194 226
195extern int dvb_register_frontend(struct dvb_adapter *dvb, 227extern int dvb_register_frontend(struct dvb_adapter *dvb,
diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
index e7132770a3bf..665776d72a48 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.c
+++ b/drivers/media/dvb/dvb-core/dvbdev.c
@@ -233,7 +233,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
233 233
234 mutex_unlock(&dvbdev_register_lock); 234 mutex_unlock(&dvbdev_register_lock);
235 235
236 clsdev = device_create_drvdata(dvb_class, adap->device, 236 clsdev = device_create(dvb_class, adap->device,
237 MKDEV(DVB_MAJOR, nums2minor(adap->num, type, id)), 237 MKDEV(DVB_MAJOR, nums2minor(adap->num, type, id)),
238 NULL, "dvb%d.%s%d", adap->num, dnames[type], id); 238 NULL, "dvb%d.%s%d", adap->num, dnames[type], id);
239 if (IS_ERR(clsdev)) { 239 if (IS_ERR(clsdev)) {
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index e84152b7576d..3c13bcfa6385 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -72,9 +72,11 @@ config DVB_USB_DIB0700
72 select DVB_DIB7000P 72 select DVB_DIB7000P
73 select DVB_DIB7000M 73 select DVB_DIB7000M
74 select DVB_DIB3000MC 74 select DVB_DIB3000MC
75 select DVB_S5H1411 if !DVB_FE_CUSTOMISE
75 select MEDIA_TUNER_MT2060 if !DVB_FE_CUSTOMISE 76 select MEDIA_TUNER_MT2060 if !DVB_FE_CUSTOMISE
76 select MEDIA_TUNER_MT2266 if !DVB_FE_CUSTOMISE 77 select MEDIA_TUNER_MT2266 if !DVB_FE_CUSTOMISE
77 select MEDIA_TUNER_XC2028 if !DVB_FE_CUSTOMISE 78 select MEDIA_TUNER_XC2028 if !DVB_FE_CUSTOMISE
79 select MEDIA_TUNER_XC5000 if !DVB_FE_CUSTOMIZE
78 select DVB_TUNER_DIB0070 80 select DVB_TUNER_DIB0070
79 help 81 help
80 Support for USB2.0/1.1 DVB receivers based on the DiB0700 USB bridge. The 82 Support for USB2.0/1.1 DVB receivers based on the DiB0700 USB bridge. The
@@ -108,6 +110,8 @@ config DVB_USB_CXUSB
108 select MEDIA_TUNER_SIMPLE if !DVB_FE_CUSTOMISE 110 select MEDIA_TUNER_SIMPLE if !DVB_FE_CUSTOMISE
109 select MEDIA_TUNER_XC2028 if !DVB_FE_CUSTOMISE 111 select MEDIA_TUNER_XC2028 if !DVB_FE_CUSTOMISE
110 select MEDIA_TUNER_MXL5005S if !DVB_FE_CUSTOMISE 112 select MEDIA_TUNER_MXL5005S if !DVB_FE_CUSTOMISE
113 select DVB_DIB7000P if !DVB_FE_CUSTOMISE
114 select DVB_TUNER_DIB0070 if !DVB_FE_CUSTOMISE
111 help 115 help
112 Say Y here to support the Conexant USB2.0 hybrid reference design. 116 Say Y here to support the Conexant USB2.0 hybrid reference design.
113 Currently, only DVB and ATSC modes are supported, analog mode 117 Currently, only DVB and ATSC modes are supported, analog mode
@@ -245,12 +249,25 @@ config DVB_USB_AF9005_REMOTE
245 Afatech AF9005 based receiver. 249 Afatech AF9005 based receiver.
246 250
247config DVB_USB_DW2102 251config DVB_USB_DW2102
248 tristate "DvbWorld 2102 DVB-S USB2.0 receiver" 252 tristate "DvbWorld DVB-S/S2 USB2.0 support"
249 depends on DVB_USB 253 depends on DVB_USB
250 select DVB_STV0299 if !DVB_FE_CUSTOMISE
251 select DVB_PLL if !DVB_FE_CUSTOMISE 254 select DVB_PLL if !DVB_FE_CUSTOMISE
255 select DVB_STV0299 if !DVB_FE_CUSTOMISE
256 select DVB_STV0288 if !DVB_FE_CUSTOMISE
257 select DVB_STB6000 if !DVB_FE_CUSTOMISE
258 select DVB_CX24116 if !DVB_FE_CUSTOMISE
259 select DVB_SI21XX if !DVB_FE_CUSTOMISE
252 help 260 help
253 Say Y here to support the DvbWorld 2102 DVB-S USB2.0 receiver. 261 Say Y here to support the DvbWorld DVB-S/S2 USB2.0 receivers
262 and the TeVii S650.
263
264config DVB_USB_CINERGY_T2
265 tristate "Terratec CinergyT2/qanu USB 2.0 DVB-T receiver"
266 depends on DVB_USB
267 help
268 Support for "TerraTec CinergyT2" USB2.0 Highspeed DVB Receivers
269
270 Say Y if you own such a device and want to use it.
254 271
255config DVB_USB_ANYSEE 272config DVB_USB_ANYSEE
256 tristate "Anysee DVB-T/C USB2.0 support" 273 tristate "Anysee DVB-T/C USB2.0 support"
@@ -262,3 +279,22 @@ config DVB_USB_ANYSEE
262 help 279 help
263 Say Y here to support the Anysee E30, Anysee E30 Plus or 280 Say Y here to support the Anysee E30, Anysee E30 Plus or
264 Anysee E30 C Plus DVB USB2.0 receiver. 281 Anysee E30 C Plus DVB USB2.0 receiver.
282
283config DVB_USB_DTV5100
284 tristate "AME DTV-5100 USB2.0 DVB-T support"
285 depends on DVB_USB
286 select MEDIA_TUNER_QT1010 if !DVB_FE_CUSTOMISE
287 help
288 Say Y here to support the AME DTV-5100 USB2.0 DVB-T receiver.
289
290config DVB_USB_AF9015
291 tristate "Afatech AF9015 DVB-T USB2.0 support"
292 depends on DVB_USB && EXPERIMENTAL
293 select DVB_AF9013
294 select DVB_PLL if !DVB_FE_CUSTOMISE
295 select MEDIA_TUNER_MT2060 if !DVB_FE_CUSTOMISE
296 select MEDIA_TUNER_QT1010 if !DVB_FE_CUSTOMISE
297 select MEDIA_TUNER_TDA18271 if !DVB_FE_CUSTOMISE
298 select MEDIA_TUNER_MXL5005S if !DVB_FE_CUSTOMISE
299 help
300 Say Y here to support the Afatech AF9015 based DVB-T USB2.0 receiver
diff --git a/drivers/media/dvb/dvb-usb/Makefile b/drivers/media/dvb/dvb-usb/Makefile
index e206f1ea0027..3122b7cc2c23 100644
--- a/drivers/media/dvb/dvb-usb/Makefile
+++ b/drivers/media/dvb/dvb-usb/Makefile
@@ -67,6 +67,16 @@ obj-$(CONFIG_DVB_USB_ANYSEE) += dvb-usb-anysee.o
67dvb-usb-dw2102-objs = dw2102.o 67dvb-usb-dw2102-objs = dw2102.o
68obj-$(CONFIG_DVB_USB_DW2102) += dvb-usb-dw2102.o 68obj-$(CONFIG_DVB_USB_DW2102) += dvb-usb-dw2102.o
69 69
70dvb-usb-dtv5100-objs = dtv5100.o
71obj-$(CONFIG_DVB_USB_DTV5100) += dvb-usb-dtv5100.o
72
73dvb-usb-af9015-objs = af9015.o
74obj-$(CONFIG_DVB_USB_AF9015) += dvb-usb-af9015.o
75
76dvb-usb-cinergyT2-objs = cinergyT2-core.o cinergyT2-fe.o
77obj-$(CONFIG_DVB_USB_CINERGY_T2) += dvb-usb-cinergyT2.o
78
79
70EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ 80EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
71# due to tuner-xc3028 81# due to tuner-xc3028
72EXTRA_CFLAGS += -Idrivers/media/common/tuners 82EXTRA_CFLAGS += -Idrivers/media/common/tuners
diff --git a/drivers/media/dvb/dvb-usb/af9005-remote.c b/drivers/media/dvb/dvb-usb/af9005-remote.c
index ff00c0e8f4a1..7c596f926764 100644
--- a/drivers/media/dvb/dvb-usb/af9005-remote.c
+++ b/drivers/media/dvb/dvb-usb/af9005-remote.c
@@ -25,7 +25,7 @@
25 */ 25 */
26#include "af9005.h" 26#include "af9005.h"
27/* debug */ 27/* debug */
28int dvb_usb_af9005_remote_debug; 28static int dvb_usb_af9005_remote_debug;
29module_param_named(debug, dvb_usb_af9005_remote_debug, int, 0644); 29module_param_named(debug, dvb_usb_af9005_remote_debug, int, 0644);
30MODULE_PARM_DESC(debug, 30MODULE_PARM_DESC(debug,
31 "enable (1) or disable (0) debug messages." 31 "enable (1) or disable (0) debug messages."
diff --git a/drivers/media/dvb/dvb-usb/af9005-script.h b/drivers/media/dvb/dvb-usb/af9005-script.h
index 6eeaae51b1ca..4d69045426dd 100644
--- a/drivers/media/dvb/dvb-usb/af9005-script.h
+++ b/drivers/media/dvb/dvb-usb/af9005-script.h
@@ -14,7 +14,7 @@ typedef struct {
14 u8 val; 14 u8 val;
15} RegDesc; 15} RegDesc;
16 16
17RegDesc script[] = { 17static RegDesc script[] = {
18 {0xa180, 0x0, 0x8, 0xa}, 18 {0xa180, 0x0, 0x8, 0xa},
19 {0xa181, 0x0, 0x8, 0xd7}, 19 {0xa181, 0x0, 0x8, 0xd7},
20 {0xa182, 0x0, 0x8, 0xa3}, 20 {0xa182, 0x0, 0x8, 0xa3},
diff --git a/drivers/media/dvb/dvb-usb/af9005.c b/drivers/media/dvb/dvb-usb/af9005.c
index cfe71feefcad..ca5a0a4d2a47 100644
--- a/drivers/media/dvb/dvb-usb/af9005.c
+++ b/drivers/media/dvb/dvb-usb/af9005.c
@@ -35,17 +35,17 @@ module_param_named(led, dvb_usb_af9005_led, bool, 0644);
35MODULE_PARM_DESC(led, "enable led (default: 1)."); 35MODULE_PARM_DESC(led, "enable led (default: 1).");
36 36
37/* eeprom dump */ 37/* eeprom dump */
38int dvb_usb_af9005_dump_eeprom = 0; 38static int dvb_usb_af9005_dump_eeprom;
39module_param_named(dump_eeprom, dvb_usb_af9005_dump_eeprom, int, 0); 39module_param_named(dump_eeprom, dvb_usb_af9005_dump_eeprom, int, 0);
40MODULE_PARM_DESC(dump_eeprom, "dump contents of the eeprom."); 40MODULE_PARM_DESC(dump_eeprom, "dump contents of the eeprom.");
41 41
42DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 42DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
43 43
44/* remote control decoder */ 44/* remote control decoder */
45int (*rc_decode) (struct dvb_usb_device * d, u8 * data, int len, u32 * event, 45static int (*rc_decode) (struct dvb_usb_device *d, u8 *data, int len,
46 int *state); 46 u32 *event, int *state);
47void *rc_keys; 47static void *rc_keys;
48int *rc_keys_size; 48static int *rc_keys_size;
49 49
50u8 regmask[8] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff }; 50u8 regmask[8] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
51 51
@@ -54,8 +54,8 @@ struct af9005_device_state {
54 int led_state; 54 int led_state;
55}; 55};
56 56
57int af9005_usb_generic_rw(struct dvb_usb_device *d, u8 * wbuf, u16 wlen, 57static int af9005_usb_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen,
58 u8 * rbuf, u16 rlen, int delay_ms) 58 u8 *rbuf, u16 rlen, int delay_ms)
59{ 59{
60 int actlen, ret = -ENOMEM; 60 int actlen, ret = -ENOMEM;
61 61
@@ -98,12 +98,7 @@ int af9005_usb_generic_rw(struct dvb_usb_device *d, u8 * wbuf, u16 wlen,
98 return ret; 98 return ret;
99} 99}
100 100
101int af9005_usb_generic_write(struct dvb_usb_device *d, u8 * buf, u16 len) 101static int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg,
102{
103 return af9005_usb_generic_rw(d, buf, len, NULL, 0, 0);
104}
105
106int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg,
107 int readwrite, int type, u8 * values, int len) 102 int readwrite, int type, u8 * values, int len)
108{ 103{
109 struct af9005_device_state *st = d->priv; 104 struct af9005_device_state *st = d->priv;
@@ -765,7 +760,7 @@ static int af9005_boot_packet(struct usb_device *udev, int type, u8 * reply)
765 return 0; 760 return 0;
766} 761}
767 762
768int af9005_download_firmware(struct usb_device *udev, const struct firmware *fw) 763static int af9005_download_firmware(struct usb_device *udev, const struct firmware *fw)
769{ 764{
770 int i, packets, ret, act_len; 765 int i, packets, ret, act_len;
771 766
diff --git a/drivers/media/dvb/dvb-usb/af9015.c b/drivers/media/dvb/dvb-usb/af9015.c
new file mode 100644
index 000000000000..cb0829c038ce
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/af9015.c
@@ -0,0 +1,1474 @@
1/*
2 * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver
3 *
4 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
5 *
6 * Thanks to Afatech who kindly provided information.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 */
23
24#include "af9015.h"
25#include "af9013.h"
26#include "mt2060.h"
27#include "qt1010.h"
28#include "tda18271.h"
29#include "mxl5005s.h"
30#if 0
31#include "mc44s80x.h"
32#endif
33
34int dvb_usb_af9015_debug;
35module_param_named(debug, dvb_usb_af9015_debug, int, 0644);
36MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
37int dvb_usb_af9015_remote;
38module_param_named(remote, dvb_usb_af9015_remote, int, 0644);
39MODULE_PARM_DESC(remote, "select remote");
40int dvb_usb_af9015_dual_mode;
41module_param_named(dual_mode, dvb_usb_af9015_dual_mode, int, 0644);
42MODULE_PARM_DESC(dual_mode, "enable dual mode");
43DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
44
45static DEFINE_MUTEX(af9015_usb_mutex);
46
47static struct af9015_config af9015_config;
48static struct dvb_usb_device_properties af9015_properties[2];
49int af9015_properties_count = ARRAY_SIZE(af9015_properties);
50
51static struct af9013_config af9015_af9013_config[] = {
52 {
53 .demod_address = AF9015_I2C_DEMOD,
54 .output_mode = AF9013_OUTPUT_MODE_USB,
55 .api_version = { 0, 1, 9, 0 },
56 .gpio[0] = AF9013_GPIO_HI,
57 .gpio[3] = AF9013_GPIO_TUNER_ON,
58
59 }, {
60 .output_mode = AF9013_OUTPUT_MODE_SERIAL,
61 .api_version = { 0, 1, 9, 0 },
62 .gpio[0] = AF9013_GPIO_TUNER_ON,
63 .gpio[1] = AF9013_GPIO_LO,
64 }
65};
66
67static int af9015_rw_udev(struct usb_device *udev, struct req_t *req)
68{
69 int act_len, ret;
70 u8 buf[64];
71 u8 write = 1;
72 u8 msg_len = 8;
73 static u8 seq; /* packet sequence number */
74
75 if (mutex_lock_interruptible(&af9015_usb_mutex) < 0)
76 return -EAGAIN;
77
78 buf[0] = req->cmd;
79 buf[1] = seq++;
80 buf[2] = req->i2c_addr;
81 buf[3] = req->addr >> 8;
82 buf[4] = req->addr & 0xff;
83 buf[5] = req->mbox;
84 buf[6] = req->addr_len;
85 buf[7] = req->data_len;
86
87 switch (req->cmd) {
88 case GET_CONFIG:
89 case BOOT:
90 case READ_MEMORY:
91 case RECONNECT_USB:
92 case GET_IR_CODE:
93 write = 0;
94 break;
95 case READ_I2C:
96 write = 0;
97 buf[2] |= 0x01; /* set I2C direction */
98 case WRITE_I2C:
99 buf[0] = READ_WRITE_I2C;
100 break;
101 case WRITE_MEMORY:
102 if (((req->addr & 0xff00) == 0xff00) ||
103 ((req->addr & 0xae00) == 0xae00))
104 buf[0] = WRITE_VIRTUAL_MEMORY;
105 case WRITE_VIRTUAL_MEMORY:
106 case COPY_FIRMWARE:
107 case DOWNLOAD_FIRMWARE:
108 break;
109 default:
110 err("unknown command:%d", req->cmd);
111 ret = -1;
112 goto error_unlock;
113 }
114
115 /* write requested */
116 if (write) {
117 memcpy(&buf[8], req->data, req->data_len);
118 msg_len += req->data_len;
119 }
120 deb_xfer(">>> ");
121 debug_dump(buf, msg_len, deb_xfer);
122
123 /* send req */
124 ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 0x02), buf, msg_len,
125 &act_len, AF9015_USB_TIMEOUT);
126 if (ret)
127 err("bulk message failed:%d (%d/%d)", ret, msg_len, act_len);
128 else
129 if (act_len != msg_len)
130 ret = -1; /* all data is not send */
131 if (ret)
132 goto error_unlock;
133
134 /* no ack for those packets */
135 if (req->cmd == DOWNLOAD_FIRMWARE || req->cmd == RECONNECT_USB)
136 goto exit_unlock;
137
138 /* receive ack and data if read req */
139 msg_len = 1 + 1 + req->data_len; /* seq + status + data len */
140 ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, 0x81), buf, msg_len,
141 &act_len, AF9015_USB_TIMEOUT);
142 if (ret) {
143 err("recv bulk message failed:%d", ret);
144 ret = -1;
145 goto error_unlock;
146 }
147
148 deb_xfer("<<< ");
149 debug_dump(buf, act_len, deb_xfer);
150
151 /* remote controller query status is 1 if remote code is not received */
152 if (req->cmd == GET_IR_CODE && buf[1] == 1) {
153 buf[1] = 0; /* clear command "error" status */
154 memset(&buf[2], 0, req->data_len);
155 buf[3] = 1; /* no remote code received mark */
156 }
157
158 /* check status */
159 if (buf[1]) {
160 err("command failed:%d", buf[1]);
161 ret = -1;
162 goto error_unlock;
163 }
164
165 /* read request, copy returned data to return buf */
166 if (!write)
167 memcpy(req->data, &buf[2], req->data_len);
168
169error_unlock:
170exit_unlock:
171 mutex_unlock(&af9015_usb_mutex);
172
173 return ret;
174}
175
176static int af9015_ctrl_msg(struct dvb_usb_device *d, struct req_t *req)
177{
178 return af9015_rw_udev(d->udev, req);
179}
180
181static int af9015_write_regs(struct dvb_usb_device *d, u16 addr, u8 *val,
182 u8 len)
183{
184 struct req_t req = {WRITE_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, len,
185 val};
186 return af9015_ctrl_msg(d, &req);
187}
188
189static int af9015_write_reg(struct dvb_usb_device *d, u16 addr, u8 val)
190{
191 return af9015_write_regs(d, addr, &val, 1);
192}
193
194static int af9015_read_reg(struct dvb_usb_device *d, u16 addr, u8 *val)
195{
196 struct req_t req = {READ_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, 1, val};
197 return af9015_ctrl_msg(d, &req);
198}
199
200static int af9015_write_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,
201 u8 val)
202{
203 struct req_t req = {WRITE_I2C, addr, reg, 1, 1, 1, &val};
204
205 if (addr == af9015_af9013_config[0].demod_address ||
206 addr == af9015_af9013_config[1].demod_address)
207 req.addr_len = 3;
208
209 return af9015_ctrl_msg(d, &req);
210}
211
212static int af9015_read_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,
213 u8 *val)
214{
215 struct req_t req = {READ_I2C, addr, reg, 0, 1, 1, val};
216
217 if (addr == af9015_af9013_config[0].demod_address ||
218 addr == af9015_af9013_config[1].demod_address)
219 req.addr_len = 3;
220
221 return af9015_ctrl_msg(d, &req);
222}
223
224static int af9015_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
225 int num)
226{
227 struct dvb_usb_device *d = i2c_get_adapdata(adap);
228 int ret = 0, i = 0;
229 u16 addr;
230 u8 mbox, addr_len;
231 struct req_t req;
232
233/* TODO: implement bus lock
234
235The bus lock is needed because there is two tuners both using same I2C-address.
236Due to that the only way to select correct tuner is use demodulator I2C-gate.
237
238................................................
239. AF9015 includes integrated AF9013 demodulator.
240. ____________ ____________ . ____________
241.| uC | | demod | . | tuner |
242.|------------| |------------| . |------------|
243.| AF9015 | | AF9013/5 | . | MXL5003 |
244.| |--+----I2C-------|-----/ -----|-.-----I2C-------| |
245.| | | | addr 0x38 | . | addr 0xc6 |
246.|____________| | |____________| . |____________|
247.................|..............................
248 | ____________ ____________
249 | | demod | | tuner |
250 | |------------| |------------|
251 | | AF9013 | | MXL5003 |
252 +----I2C-------|-----/ -----|-------I2C-------| |
253 | addr 0x3a | | addr 0xc6 |
254 |____________| |____________|
255*/
256 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
257 return -EAGAIN;
258
259 while (i < num) {
260 if (msg[i].addr == af9015_af9013_config[0].demod_address ||
261 msg[i].addr == af9015_af9013_config[1].demod_address) {
262 addr = msg[i].buf[0] << 8;
263 addr += msg[i].buf[1];
264 mbox = msg[i].buf[2];
265 addr_len = 3;
266 } else {
267 addr = msg[i].buf[0];
268 addr_len = 1;
269 mbox = 0;
270 }
271
272 if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
273 if (msg[i].addr ==
274 af9015_af9013_config[0].demod_address)
275 req.cmd = READ_MEMORY;
276 else
277 req.cmd = READ_I2C;
278 req.i2c_addr = msg[i].addr;
279 req.addr = addr;
280 req.mbox = mbox;
281 req.addr_len = addr_len;
282 req.data_len = msg[i+1].len;
283 req.data = &msg[i+1].buf[0];
284 ret = af9015_ctrl_msg(d, &req);
285 i += 2;
286 } else {
287 if (msg[i].addr ==
288 af9015_af9013_config[0].demod_address)
289 req.cmd = WRITE_MEMORY;
290 else
291 req.cmd = WRITE_I2C;
292 req.i2c_addr = msg[i].addr;
293 req.addr = addr;
294 req.mbox = mbox;
295 req.addr_len = addr_len;
296 req.data_len = msg[i].len-addr_len;
297 req.data = &msg[i].buf[addr_len];
298 ret = af9015_ctrl_msg(d, &req);
299 i += 1;
300 }
301 if (ret)
302 goto error;
303
304 }
305 ret = i;
306
307error:
308 mutex_unlock(&d->i2c_mutex);
309
310 return ret;
311}
312
313static u32 af9015_i2c_func(struct i2c_adapter *adapter)
314{
315 return I2C_FUNC_I2C;
316}
317
318static struct i2c_algorithm af9015_i2c_algo = {
319 .master_xfer = af9015_i2c_xfer,
320 .functionality = af9015_i2c_func,
321};
322
323static int af9015_do_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit, u8 op)
324{
325 int ret;
326 u8 val, mask = 0x01;
327
328 ret = af9015_read_reg(d, addr, &val);
329 if (ret)
330 return ret;
331
332 mask <<= bit;
333 if (op) {
334 /* set bit */
335 val |= mask;
336 } else {
337 /* clear bit */
338 mask ^= 0xff;
339 val &= mask;
340 }
341
342 return af9015_write_reg(d, addr, val);
343}
344
345static int af9015_set_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit)
346{
347 return af9015_do_reg_bit(d, addr, bit, 1);
348}
349
350static int af9015_clear_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit)
351{
352 return af9015_do_reg_bit(d, addr, bit, 0);
353}
354
355static int af9015_init_endpoint(struct dvb_usb_device *d)
356{
357 int ret;
358 u16 frame_size;
359 u8 packet_size;
360 deb_info("%s: USB speed:%d\n", __func__, d->udev->speed);
361
362#define TS_PACKET_SIZE 188
363
364#define TS_USB20_PACKET_COUNT 348
365#define TS_USB20_FRAME_SIZE (TS_PACKET_SIZE*TS_USB20_PACKET_COUNT)
366
367#define TS_USB11_PACKET_COUNT 21
368#define TS_USB11_FRAME_SIZE (TS_PACKET_SIZE*TS_USB11_PACKET_COUNT)
369
370#define TS_USB20_MAX_PACKET_SIZE 512
371#define TS_USB11_MAX_PACKET_SIZE 64
372
373 if (d->udev->speed == USB_SPEED_FULL) {
374 frame_size = TS_USB11_FRAME_SIZE/4;
375 packet_size = TS_USB11_MAX_PACKET_SIZE/4;
376 } else {
377 frame_size = TS_USB20_FRAME_SIZE/4;
378 packet_size = TS_USB20_MAX_PACKET_SIZE/4;
379 }
380
381 ret = af9015_set_reg_bit(d, 0xd507, 2); /* assert EP4 reset */
382 if (ret)
383 goto error;
384 ret = af9015_set_reg_bit(d, 0xd50b, 1); /* assert EP5 reset */
385 if (ret)
386 goto error;
387 ret = af9015_clear_reg_bit(d, 0xdd11, 5); /* disable EP4 */
388 if (ret)
389 goto error;
390 ret = af9015_clear_reg_bit(d, 0xdd11, 6); /* disable EP5 */
391 if (ret)
392 goto error;
393 ret = af9015_set_reg_bit(d, 0xdd11, 5); /* enable EP4 */
394 if (ret)
395 goto error;
396 if (af9015_config.dual_mode) {
397 ret = af9015_set_reg_bit(d, 0xdd11, 6); /* enable EP5 */
398 if (ret)
399 goto error;
400 }
401 ret = af9015_clear_reg_bit(d, 0xdd13, 5); /* disable EP4 NAK */
402 if (ret)
403 goto error;
404 if (af9015_config.dual_mode) {
405 ret = af9015_clear_reg_bit(d, 0xdd13, 6); /* disable EP5 NAK */
406 if (ret)
407 goto error;
408 }
409 /* EP4 xfer length */
410 ret = af9015_write_reg(d, 0xdd88, frame_size & 0xff);
411 if (ret)
412 goto error;
413 ret = af9015_write_reg(d, 0xdd89, frame_size >> 8);
414 if (ret)
415 goto error;
416 /* EP5 xfer length */
417 ret = af9015_write_reg(d, 0xdd8a, frame_size & 0xff);
418 if (ret)
419 goto error;
420 ret = af9015_write_reg(d, 0xdd8b, frame_size >> 8);
421 if (ret)
422 goto error;
423 ret = af9015_write_reg(d, 0xdd0c, packet_size); /* EP4 packet size */
424 if (ret)
425 goto error;
426 ret = af9015_write_reg(d, 0xdd0d, packet_size); /* EP5 packet size */
427 if (ret)
428 goto error;
429 ret = af9015_clear_reg_bit(d, 0xd507, 2); /* negate EP4 reset */
430 if (ret)
431 goto error;
432 if (af9015_config.dual_mode) {
433 ret = af9015_clear_reg_bit(d, 0xd50b, 1); /* negate EP5 reset */
434 if (ret)
435 goto error;
436 }
437
438 /* enable / disable mp2if2 */
439 if (af9015_config.dual_mode)
440 ret = af9015_set_reg_bit(d, 0xd50b, 0);
441 else
442 ret = af9015_clear_reg_bit(d, 0xd50b, 0);
443error:
444 if (ret)
445 err("endpoint init failed:%d", ret);
446 return ret;
447}
448
449static int af9015_copy_firmware(struct dvb_usb_device *d)
450{
451 int ret;
452 u8 fw_params[4];
453 u8 val, i;
454 struct req_t req = {COPY_FIRMWARE, 0, 0x5100, 0, 0, sizeof(fw_params),
455 fw_params };
456 deb_info("%s:\n", __func__);
457
458 fw_params[0] = af9015_config.firmware_size >> 8;
459 fw_params[1] = af9015_config.firmware_size & 0xff;
460 fw_params[2] = af9015_config.firmware_checksum >> 8;
461 fw_params[3] = af9015_config.firmware_checksum & 0xff;
462
463 /* wait 2nd demodulator ready */
464 msleep(100);
465
466 ret = af9015_read_reg_i2c(d, 0x3a, 0x98be, &val);
467 if (ret)
468 goto error;
469 else
470 deb_info("%s: firmware status:%02x\n", __func__, val);
471
472 if (val == 0x0c) /* fw is running, no need for download */
473 goto exit;
474
475 /* set I2C master clock to fast (to speed up firmware copy) */
476 ret = af9015_write_reg(d, 0xd416, 0x04); /* 0x04 * 400ns */
477 if (ret)
478 goto error;
479
480 msleep(50);
481
482 /* copy firmware */
483 ret = af9015_ctrl_msg(d, &req);
484 if (ret)
485 err("firmware copy cmd failed:%d", ret);
486 deb_info("%s: firmware copy done\n", __func__);
487
488 /* set I2C master clock back to normal */
489 ret = af9015_write_reg(d, 0xd416, 0x14); /* 0x14 * 400ns */
490 if (ret)
491 goto error;
492
493 /* request boot firmware */
494 ret = af9015_write_reg_i2c(d, af9015_af9013_config[1].demod_address,
495 0xe205, 1);
496 deb_info("%s: firmware boot cmd status:%d\n", __func__, ret);
497 if (ret)
498 goto error;
499
500 for (i = 0; i < 15; i++) {
501 msleep(100);
502
503 /* check firmware status */
504 ret = af9015_read_reg_i2c(d,
505 af9015_af9013_config[1].demod_address, 0x98be, &val);
506 deb_info("%s: firmware status cmd status:%d fw status:%02x\n",
507 __func__, ret, val);
508 if (ret)
509 goto error;
510
511 if (val == 0x0c || val == 0x04) /* success or fail */
512 break;
513 }
514
515 if (val == 0x04) {
516 err("firmware did not run");
517 ret = -1;
518 } else if (val != 0x0c) {
519 err("firmware boot timeout");
520 ret = -1;
521 }
522
523error:
524exit:
525 return ret;
526}
527
528/* dump eeprom */
529static int af9015_eeprom_dump(struct dvb_usb_device *d)
530{
531 char buf[52], buf2[4];
532 u8 reg, val;
533
534 for (reg = 0; ; reg++) {
535 if (reg % 16 == 0) {
536 if (reg)
537 deb_info("%s\n", buf);
538 sprintf(buf, "%02x: ", reg);
539 }
540 if (af9015_read_reg_i2c(d, AF9015_I2C_EEPROM, reg, &val) == 0)
541 sprintf(buf2, "%02x ", val);
542 else
543 strcpy(buf2, "-- ");
544 strcat(buf, buf2);
545 if (reg == 0xff)
546 break;
547 }
548 deb_info("%s\n", buf);
549 return 0;
550}
551
552int af9015_download_ir_table(struct dvb_usb_device *d)
553{
554 int i, packets = 0, ret;
555 u16 addr = 0x9a56; /* ir-table start address */
556 struct req_t req = {WRITE_MEMORY, 0, 0, 0, 0, 1, NULL};
557 u8 *data = NULL;
558 deb_info("%s:\n", __func__);
559
560 data = af9015_config.ir_table;
561 packets = af9015_config.ir_table_size;
562
563 /* no remote */
564 if (!packets)
565 goto exit;
566
567 /* load remote ir-table */
568 for (i = 0; i < packets; i++) {
569 req.addr = addr + i;
570 req.data = &data[i];
571 ret = af9015_ctrl_msg(d, &req);
572 if (ret) {
573 err("ir-table download failed at packet %d with " \
574 "code %d", i, ret);
575 return ret;
576 }
577 }
578
579exit:
580 return 0;
581}
582
583static int af9015_init(struct dvb_usb_device *d)
584{
585 int ret;
586 deb_info("%s:\n", __func__);
587
588 ret = af9015_init_endpoint(d);
589 if (ret)
590 goto error;
591
592 ret = af9015_download_ir_table(d);
593 if (ret)
594 goto error;
595
596error:
597 return ret;
598}
599
600static int af9015_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
601{
602 int ret;
603 deb_info("%s: onoff:%d\n", __func__, onoff);
604
605 if (onoff)
606 ret = af9015_set_reg_bit(adap->dev, 0xd503, 0);
607 else
608 ret = af9015_clear_reg_bit(adap->dev, 0xd503, 0);
609
610 return ret;
611}
612
613static int af9015_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
614 int onoff)
615{
616 int ret;
617 u8 idx;
618
619 deb_info("%s: set pid filter, index %d, pid %x, onoff %d\n",
620 __func__, index, pid, onoff);
621
622 ret = af9015_write_reg(adap->dev, 0xd505, (pid & 0xff));
623 if (ret)
624 goto error;
625
626 ret = af9015_write_reg(adap->dev, 0xd506, (pid >> 8));
627 if (ret)
628 goto error;
629
630 idx = ((index & 0x1f) | (1 << 5));
631 ret = af9015_write_reg(adap->dev, 0xd504, idx);
632
633error:
634 return ret;
635}
636
637static int af9015_download_firmware(struct usb_device *udev,
638 const struct firmware *fw)
639{
640 int i, len, packets, remainder, ret;
641 struct req_t req = {DOWNLOAD_FIRMWARE, 0, 0, 0, 0, 0, NULL};
642 u16 addr = 0x5100; /* firmware start address */
643 u16 checksum = 0;
644
645 deb_info("%s:\n", __func__);
646
647 /* calc checksum */
648 for (i = 0; i < fw->size; i++)
649 checksum += fw->data[i];
650
651 af9015_config.firmware_size = fw->size;
652 af9015_config.firmware_checksum = checksum;
653
654 #define FW_PACKET_MAX_DATA 55
655
656 packets = fw->size / FW_PACKET_MAX_DATA;
657 remainder = fw->size % FW_PACKET_MAX_DATA;
658 len = FW_PACKET_MAX_DATA;
659 for (i = 0; i <= packets; i++) {
660 if (i == packets) /* set size of the last packet */
661 len = remainder;
662
663 req.data_len = len;
664 req.data = (u8 *)(fw->data + i * FW_PACKET_MAX_DATA);
665 req.addr = addr;
666 addr += FW_PACKET_MAX_DATA;
667
668 ret = af9015_rw_udev(udev, &req);
669 if (ret) {
670 err("firmware download failed at packet %d with " \
671 "code %d", i, ret);
672 goto error;
673 }
674 }
675
676 /* firmware loaded, request boot */
677 req.cmd = BOOT;
678 ret = af9015_rw_udev(udev, &req);
679 if (ret) {
680 err("firmware boot failed:%d", ret);
681 goto error;
682 }
683
684 /* firmware is running, reconnect device in the usb bus */
685 req.cmd = RECONNECT_USB;
686 ret = af9015_rw_udev(udev, &req);
687 if (ret)
688 err("reconnect failed: %d", ret);
689
690error:
691 return ret;
692}
693
694static int af9015_read_config(struct usb_device *udev)
695{
696 int ret;
697 u8 val, i, offset = 0;
698 struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val};
699 char manufacturer[10];
700
701 /* IR remote controller */
702 req.addr = AF9015_EEPROM_IR_MODE;
703 ret = af9015_rw_udev(udev, &req);
704 if (ret)
705 goto error;
706 deb_info("%s: IR mode:%d\n", __func__, val);
707 for (i = 0; i < af9015_properties_count; i++) {
708 if (val == AF9015_IR_MODE_DISABLED || val == 0x04) {
709 af9015_properties[i].rc_key_map = NULL;
710 af9015_properties[i].rc_key_map_size = 0;
711 } else if (dvb_usb_af9015_remote) {
712 /* load remote defined as module param */
713 switch (dvb_usb_af9015_remote) {
714 case AF9015_REMOTE_A_LINK_DTU_M:
715 af9015_properties[i].rc_key_map =
716 af9015_rc_keys_a_link;
717 af9015_properties[i].rc_key_map_size =
718 ARRAY_SIZE(af9015_rc_keys_a_link);
719 af9015_config.ir_table = af9015_ir_table_a_link;
720 af9015_config.ir_table_size =
721 ARRAY_SIZE(af9015_ir_table_a_link);
722 break;
723 case AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3:
724 af9015_properties[i].rc_key_map =
725 af9015_rc_keys_msi;
726 af9015_properties[i].rc_key_map_size =
727 ARRAY_SIZE(af9015_rc_keys_msi);
728 af9015_config.ir_table = af9015_ir_table_msi;
729 af9015_config.ir_table_size =
730 ARRAY_SIZE(af9015_ir_table_msi);
731 break;
732 case AF9015_REMOTE_MYGICTV_U718:
733 af9015_properties[i].rc_key_map =
734 af9015_rc_keys_mygictv;
735 af9015_properties[i].rc_key_map_size =
736 ARRAY_SIZE(af9015_rc_keys_mygictv);
737 af9015_config.ir_table =
738 af9015_ir_table_mygictv;
739 af9015_config.ir_table_size =
740 ARRAY_SIZE(af9015_ir_table_mygictv);
741 break;
742 }
743 } else {
744 switch (udev->descriptor.idVendor) {
745 case USB_VID_LEADTEK:
746 af9015_properties[i].rc_key_map =
747 af9015_rc_keys_leadtek;
748 af9015_properties[i].rc_key_map_size =
749 ARRAY_SIZE(af9015_rc_keys_leadtek);
750 af9015_config.ir_table =
751 af9015_ir_table_leadtek;
752 af9015_config.ir_table_size =
753 ARRAY_SIZE(af9015_ir_table_leadtek);
754 break;
755 case USB_VID_VISIONPLUS:
756 if (udev->descriptor.idProduct ==
757 USB_PID_AZUREWAVE_AD_TU700) {
758 af9015_properties[i].rc_key_map =
759 af9015_rc_keys_twinhan;
760 af9015_properties[i].rc_key_map_size =
761 ARRAY_SIZE(af9015_rc_keys_twinhan);
762 af9015_config.ir_table =
763 af9015_ir_table_twinhan;
764 af9015_config.ir_table_size =
765 ARRAY_SIZE(af9015_ir_table_twinhan);
766 }
767 break;
768 case USB_VID_KWORLD_2:
769 /* TODO: use correct rc keys */
770 af9015_properties[i].rc_key_map =
771 af9015_rc_keys_twinhan;
772 af9015_properties[i].rc_key_map_size =
773 ARRAY_SIZE(af9015_rc_keys_twinhan);
774 af9015_config.ir_table = af9015_ir_table_kworld;
775 af9015_config.ir_table_size =
776 ARRAY_SIZE(af9015_ir_table_kworld);
777 break;
778 /* Check USB manufacturer and product strings and try
779 to determine correct remote in case of chip vendor
780 reference IDs are used. */
781 case USB_VID_AFATECH:
782 memset(manufacturer, 0, sizeof(manufacturer));
783 usb_string(udev, udev->descriptor.iManufacturer,
784 manufacturer, sizeof(manufacturer));
785 if (!strcmp("Geniatech", manufacturer)) {
786 /* iManufacturer 1 Geniatech
787 iProduct 2 AF9015 */
788 af9015_properties[i].rc_key_map =
789 af9015_rc_keys_mygictv;
790 af9015_properties[i].rc_key_map_size =
791 ARRAY_SIZE(af9015_rc_keys_mygictv);
792 af9015_config.ir_table =
793 af9015_ir_table_mygictv;
794 af9015_config.ir_table_size =
795 ARRAY_SIZE(af9015_ir_table_mygictv);
796 } else if (!strcmp("MSI", manufacturer)) {
797 /* iManufacturer 1 MSI
798 iProduct 2 MSI K-VOX */
799 af9015_properties[i].rc_key_map =
800 af9015_rc_keys_msi;
801 af9015_properties[i].rc_key_map_size =
802 ARRAY_SIZE(af9015_rc_keys_msi);
803 af9015_config.ir_table =
804 af9015_ir_table_msi;
805 af9015_config.ir_table_size =
806 ARRAY_SIZE(af9015_ir_table_msi);
807 }
808 break;
809 }
810 }
811 }
812
813 /* TS mode - one or two receivers */
814 req.addr = AF9015_EEPROM_TS_MODE;
815 ret = af9015_rw_udev(udev, &req);
816 if (ret)
817 goto error;
818 af9015_config.dual_mode = val;
819 deb_info("%s: TS mode:%d\n", __func__, af9015_config.dual_mode);
820 /* disable dual mode by default because it is buggy */
821 if (!dvb_usb_af9015_dual_mode)
822 af9015_config.dual_mode = 0;
823
824 /* set buffer size according to USB port speed */
825 for (i = 0; i < af9015_properties_count; i++) {
826 /* USB1.1 set smaller buffersize and disable 2nd adapter */
827 if (udev->speed == USB_SPEED_FULL) {
828 af9015_properties[i].adapter->stream.u.bulk.buffersize =
829 TS_USB11_MAX_PACKET_SIZE;
830 /* disable 2nd adapter because we don't have
831 PID-filters */
832 af9015_config.dual_mode = 0;
833 } else {
834 af9015_properties[i].adapter->stream.u.bulk.buffersize =
835 TS_USB20_MAX_PACKET_SIZE;
836 }
837 }
838
839 if (af9015_config.dual_mode) {
840 /* read 2nd demodulator I2C address */
841 req.addr = AF9015_EEPROM_DEMOD2_I2C;
842 ret = af9015_rw_udev(udev, &req);
843 if (ret)
844 goto error;
845 af9015_af9013_config[1].demod_address = val;
846
847 /* enable 2nd adapter */
848 for (i = 0; i < af9015_properties_count; i++)
849 af9015_properties[i].num_adapters = 2;
850
851 } else {
852 /* disable 2nd adapter */
853 for (i = 0; i < af9015_properties_count; i++)
854 af9015_properties[i].num_adapters = 1;
855 }
856
857 for (i = 0; i < af9015_properties[0].num_adapters; i++) {
858 if (i == 1)
859 offset = AF9015_EEPROM_OFFSET;
860 /* xtal */
861 req.addr = AF9015_EEPROM_XTAL_TYPE1 + offset;
862 ret = af9015_rw_udev(udev, &req);
863 if (ret)
864 goto error;
865 switch (val) {
866 case 0:
867 af9015_af9013_config[i].adc_clock = 28800;
868 break;
869 case 1:
870 af9015_af9013_config[i].adc_clock = 20480;
871 break;
872 case 2:
873 af9015_af9013_config[i].adc_clock = 28000;
874 break;
875 case 3:
876 af9015_af9013_config[i].adc_clock = 25000;
877 break;
878 };
879 deb_info("%s: [%d] xtal:%d set adc_clock:%d\n", __func__, i,
880 val, af9015_af9013_config[i].adc_clock);
881
882 /* tuner IF */
883 req.addr = AF9015_EEPROM_IF1H + offset;
884 ret = af9015_rw_udev(udev, &req);
885 if (ret)
886 goto error;
887 af9015_af9013_config[i].tuner_if = val << 8;
888 req.addr = AF9015_EEPROM_IF1L + offset;
889 ret = af9015_rw_udev(udev, &req);
890 if (ret)
891 goto error;
892 af9015_af9013_config[i].tuner_if += val;
893 deb_info("%s: [%d] IF1:%d\n", __func__, i,
894 af9015_af9013_config[0].tuner_if);
895
896 /* MT2060 IF1 */
897 req.addr = AF9015_EEPROM_MT2060_IF1H + offset;
898 ret = af9015_rw_udev(udev, &req);
899 if (ret)
900 goto error;
901 af9015_config.mt2060_if1[i] = val << 8;
902 req.addr = AF9015_EEPROM_MT2060_IF1L + offset;
903 ret = af9015_rw_udev(udev, &req);
904 if (ret)
905 goto error;
906 af9015_config.mt2060_if1[i] += val;
907 deb_info("%s: [%d] MT2060 IF1:%d\n", __func__, i,
908 af9015_config.mt2060_if1[i]);
909
910 /* tuner */
911 req.addr = AF9015_EEPROM_TUNER_ID1 + offset;
912 ret = af9015_rw_udev(udev, &req);
913 if (ret)
914 goto error;
915 switch (val) {
916 case AF9013_TUNER_ENV77H11D5:
917 case AF9013_TUNER_MT2060:
918 case AF9013_TUNER_MC44S803:
919 case AF9013_TUNER_QT1010:
920 case AF9013_TUNER_UNKNOWN:
921 case AF9013_TUNER_MT2060_2:
922 case AF9013_TUNER_TDA18271:
923 case AF9013_TUNER_QT1010A:
924 af9015_af9013_config[i].rf_spec_inv = 1;
925 break;
926 case AF9013_TUNER_MXL5003D:
927 case AF9013_TUNER_MXL5005D:
928 case AF9013_TUNER_MXL5005R:
929 af9015_af9013_config[i].rf_spec_inv = 0;
930 break;
931 default:
932 warn("tuner id:%d not supported, please report!", val);
933 return -ENODEV;
934 };
935
936 af9015_af9013_config[i].tuner = val;
937 deb_info("%s: [%d] tuner id:%d\n", __func__, i, val);
938 }
939
940error:
941 if (ret)
942 err("eeprom read failed:%d", ret);
943
944 return ret;
945}
946
947static int af9015_identify_state(struct usb_device *udev,
948 struct dvb_usb_device_properties *props,
949 struct dvb_usb_device_description **desc,
950 int *cold)
951{
952 int ret;
953 u8 reply;
954 struct req_t req = {GET_CONFIG, 0, 0, 0, 0, 1, &reply};
955
956 ret = af9015_rw_udev(udev, &req);
957 if (ret)
958 return ret;
959
960 deb_info("%s: reply:%02x\n", __func__, reply);
961 if (reply == 0x02)
962 *cold = 0;
963 else
964 *cold = 1;
965
966 return ret;
967}
968
969static int af9015_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
970{
971 u8 buf[8];
972 struct req_t req = {GET_IR_CODE, 0, 0, 0, 0, sizeof(buf), buf};
973 struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
974 int i, ret;
975
976 memset(buf, 0, sizeof(buf));
977
978 ret = af9015_ctrl_msg(d, &req);
979 if (ret)
980 return ret;
981
982 *event = 0;
983 *state = REMOTE_NO_KEY_PRESSED;
984
985 for (i = 0; i < d->props.rc_key_map_size; i++) {
986 if (!buf[1] && keymap[i].custom == buf[0] &&
987 keymap[i].data == buf[2]) {
988 *event = keymap[i].event;
989 *state = REMOTE_KEY_PRESSED;
990 break;
991 }
992 }
993 if (!buf[1])
994 deb_rc("%s: %02x %02x %02x %02x %02x %02x %02x %02x\n",
995 __func__, buf[0], buf[1], buf[2], buf[3], buf[4],
996 buf[5], buf[6], buf[7]);
997
998 return 0;
999}
1000
1001/* init 2nd I2C adapter */
1002int af9015_i2c_init(struct dvb_usb_device *d)
1003{
1004 int ret;
1005 struct af9015_state *state = d->priv;
1006 deb_info("%s:\n", __func__);
1007
1008 strncpy(state->i2c_adap.name, d->desc->name,
1009 sizeof(state->i2c_adap.name));
1010#ifdef I2C_ADAP_CLASS_TV_DIGITAL
1011 state->i2c_adap.class = I2C_ADAP_CLASS_TV_DIGITAL,
1012#else
1013 state->i2c_adap.class = I2C_CLASS_TV_DIGITAL,
1014#endif
1015 state->i2c_adap.algo = d->props.i2c_algo;
1016 state->i2c_adap.algo_data = NULL;
1017 state->i2c_adap.dev.parent = &d->udev->dev;
1018
1019 i2c_set_adapdata(&state->i2c_adap, d);
1020
1021 ret = i2c_add_adapter(&state->i2c_adap);
1022 if (ret < 0)
1023 err("could not add i2c adapter");
1024
1025 return ret;
1026}
1027
1028static int af9015_af9013_frontend_attach(struct dvb_usb_adapter *adap)
1029{
1030 int ret;
1031 struct af9015_state *state = adap->dev->priv;
1032 struct i2c_adapter *i2c_adap;
1033
1034 if (adap->id == 0) {
1035 /* select I2C adapter */
1036 i2c_adap = &adap->dev->i2c_adap;
1037
1038 deb_info("%s: init I2C\n", __func__);
1039 ret = af9015_i2c_init(adap->dev);
1040
1041 /* dump eeprom (debug) */
1042 ret = af9015_eeprom_dump(adap->dev);
1043 if (ret)
1044 return ret;
1045 } else {
1046 /* select I2C adapter */
1047 i2c_adap = &state->i2c_adap;
1048
1049 /* copy firmware to 2nd demodulator */
1050 if (af9015_config.dual_mode) {
1051 ret = af9015_copy_firmware(adap->dev);
1052 if (ret) {
1053 err("firmware copy to 2nd frontend " \
1054 "failed, will disable it");
1055 af9015_config.dual_mode = 0;
1056 return -ENODEV;
1057 }
1058 } else {
1059 return -ENODEV;
1060 }
1061 }
1062
1063 /* attach demodulator */
1064 adap->fe = dvb_attach(af9013_attach, &af9015_af9013_config[adap->id],
1065 i2c_adap);
1066
1067 return adap->fe == NULL ? -ENODEV : 0;
1068}
1069
1070static struct mt2060_config af9015_mt2060_config = {
1071 .i2c_address = 0xc0,
1072 .clock_out = 0,
1073};
1074
1075static struct qt1010_config af9015_qt1010_config = {
1076 .i2c_address = 0xc4,
1077};
1078
1079static struct tda18271_config af9015_tda18271_config = {
1080 .gate = TDA18271_GATE_DIGITAL,
1081 .small_i2c = 1,
1082};
1083
1084static struct mxl5005s_config af9015_mxl5003_config = {
1085 .i2c_address = 0xc6,
1086 .if_freq = IF_FREQ_4570000HZ,
1087 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
1088 .agc_mode = MXL_SINGLE_AGC,
1089 .tracking_filter = MXL_TF_DEFAULT,
1090 .rssi_enable = MXL_RSSI_ENABLE,
1091 .cap_select = MXL_CAP_SEL_ENABLE,
1092 .div_out = MXL_DIV_OUT_4,
1093 .clock_out = MXL_CLOCK_OUT_DISABLE,
1094 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
1095 .top = MXL5005S_TOP_25P2,
1096 .mod_mode = MXL_DIGITAL_MODE,
1097 .if_mode = MXL_ZERO_IF,
1098 .AgcMasterByte = 0x00,
1099};
1100
1101static struct mxl5005s_config af9015_mxl5005_config = {
1102 .i2c_address = 0xc6,
1103 .if_freq = IF_FREQ_4570000HZ,
1104 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
1105 .agc_mode = MXL_SINGLE_AGC,
1106 .tracking_filter = MXL_TF_OFF,
1107 .rssi_enable = MXL_RSSI_ENABLE,
1108 .cap_select = MXL_CAP_SEL_ENABLE,
1109 .div_out = MXL_DIV_OUT_4,
1110 .clock_out = MXL_CLOCK_OUT_DISABLE,
1111 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
1112 .top = MXL5005S_TOP_25P2,
1113 .mod_mode = MXL_DIGITAL_MODE,
1114 .if_mode = MXL_ZERO_IF,
1115 .AgcMasterByte = 0x00,
1116};
1117
1118static int af9015_tuner_attach(struct dvb_usb_adapter *adap)
1119{
1120 struct af9015_state *state = adap->dev->priv;
1121 struct i2c_adapter *i2c_adap;
1122 int ret;
1123 deb_info("%s: \n", __func__);
1124
1125 /* select I2C adapter */
1126 if (adap->id == 0)
1127 i2c_adap = &adap->dev->i2c_adap;
1128 else
1129 i2c_adap = &state->i2c_adap;
1130
1131 switch (af9015_af9013_config[adap->id].tuner) {
1132 case AF9013_TUNER_MT2060:
1133 case AF9013_TUNER_MT2060_2:
1134 ret = dvb_attach(mt2060_attach, adap->fe, i2c_adap,
1135 &af9015_mt2060_config,
1136 af9015_config.mt2060_if1[adap->id])
1137 == NULL ? -ENODEV : 0;
1138 break;
1139 case AF9013_TUNER_QT1010:
1140 case AF9013_TUNER_QT1010A:
1141 ret = dvb_attach(qt1010_attach, adap->fe, i2c_adap,
1142 &af9015_qt1010_config) == NULL ? -ENODEV : 0;
1143 break;
1144 case AF9013_TUNER_TDA18271:
1145 ret = dvb_attach(tda18271_attach, adap->fe, 0xc0, i2c_adap,
1146 &af9015_tda18271_config) == NULL ? -ENODEV : 0;
1147 break;
1148 case AF9013_TUNER_MXL5003D:
1149 ret = dvb_attach(mxl5005s_attach, adap->fe, i2c_adap,
1150 &af9015_mxl5003_config) == NULL ? -ENODEV : 0;
1151 break;
1152 case AF9013_TUNER_MXL5005D:
1153 case AF9013_TUNER_MXL5005R:
1154 ret = dvb_attach(mxl5005s_attach, adap->fe, i2c_adap,
1155 &af9015_mxl5005_config) == NULL ? -ENODEV : 0;
1156 break;
1157 case AF9013_TUNER_ENV77H11D5:
1158 ret = dvb_attach(dvb_pll_attach, adap->fe, 0xc0, i2c_adap,
1159 DVB_PLL_TDA665X) == NULL ? -ENODEV : 0;
1160 break;
1161 case AF9013_TUNER_MC44S803:
1162#if 0
1163 ret = dvb_attach(mc44s80x_attach, adap->fe, i2c_adap)
1164 == NULL ? -ENODEV : 0;
1165#else
1166 ret = -ENODEV;
1167 info("Freescale MC44S803 tuner found but no driver for that" \
1168 "tuner. Look at the Linuxtv.org for tuner driver" \
1169 "status.");
1170#endif
1171 break;
1172 case AF9013_TUNER_UNKNOWN:
1173 default:
1174 ret = -ENODEV;
1175 err("Unknown tuner id:%d",
1176 af9015_af9013_config[adap->id].tuner);
1177 }
1178 return ret;
1179}
1180
1181static struct usb_device_id af9015_usb_table[] = {
1182/* 0 */{USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9015)},
1183 {USB_DEVICE(USB_VID_AFATECH, USB_PID_AFATECH_AF9015_9016)},
1184 {USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_GOLD)},
1185 {USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV71E)},
1186 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_399U)},
1187/* 5 */{USB_DEVICE(USB_VID_VISIONPLUS,
1188 USB_PID_TINYTWIN)},
1189 {USB_DEVICE(USB_VID_VISIONPLUS,
1190 USB_PID_AZUREWAVE_AD_TU700)},
1191 {USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_USB_XE_REV2)},
1192 {USB_DEVICE(USB_VID_KWORLD_2, USB_PID_KWORLD_PC160_2T)},
1193 {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X)},
1194/* 10 */{USB_DEVICE(USB_VID_XTENSIONS, USB_PID_XTENSIONS_XD_380)},
1195 {USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGIVOX_DUO)},
1196 {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X_2)},
1197 {USB_DEVICE(USB_VID_TELESTAR, USB_PID_TELESTAR_STARSTICK_2)},
1198 {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A309)},
1199/* 15 */{USB_DEVICE(USB_VID_MSI_2, USB_PID_MSI_DIGI_VOX_MINI_III)},
1200 {0},
1201};
1202MODULE_DEVICE_TABLE(usb, af9015_usb_table);
1203
1204static struct dvb_usb_device_properties af9015_properties[] = {
1205 {
1206 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1207
1208 .usb_ctrl = DEVICE_SPECIFIC,
1209 .download_firmware = af9015_download_firmware,
1210 .firmware = "dvb-usb-af9015.fw",
1211
1212 .size_of_priv = sizeof(struct af9015_state), \
1213
1214 .num_adapters = 2,
1215 .adapter = {
1216 {
1217 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1218 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1219
1220 .pid_filter_count = 32,
1221 .pid_filter = af9015_pid_filter,
1222 .pid_filter_ctrl = af9015_pid_filter_ctrl,
1223
1224 .frontend_attach =
1225 af9015_af9013_frontend_attach,
1226 .tuner_attach = af9015_tuner_attach,
1227 .stream = {
1228 .type = USB_BULK,
1229 .count = 6,
1230 .endpoint = 0x84,
1231 },
1232 },
1233 {
1234 .frontend_attach =
1235 af9015_af9013_frontend_attach,
1236 .tuner_attach = af9015_tuner_attach,
1237 .stream = {
1238 .type = USB_BULK,
1239 .count = 6,
1240 .endpoint = 0x85,
1241 },
1242 }
1243 },
1244
1245 .identify_state = af9015_identify_state,
1246
1247 .rc_query = af9015_rc_query,
1248 .rc_interval = 150,
1249
1250 .i2c_algo = &af9015_i2c_algo,
1251
1252 .num_device_descs = 9,
1253 .devices = {
1254 {
1255 .name = "Afatech AF9015 DVB-T USB2.0 stick",
1256 .cold_ids = {&af9015_usb_table[0],
1257 &af9015_usb_table[1], NULL},
1258 .warm_ids = {NULL},
1259 },
1260 {
1261 .name = "Leadtek WinFast DTV Dongle Gold",
1262 .cold_ids = {&af9015_usb_table[2], NULL},
1263 .warm_ids = {NULL},
1264 },
1265 {
1266 .name = "Pinnacle PCTV 71e",
1267 .cold_ids = {&af9015_usb_table[3], NULL},
1268 .warm_ids = {NULL},
1269 },
1270 {
1271 .name = "KWorld PlusTV Dual DVB-T Stick " \
1272 "(DVB-T 399U)",
1273 .cold_ids = {&af9015_usb_table[4], NULL},
1274 .warm_ids = {NULL},
1275 },
1276 {
1277 .name = "DigitalNow TinyTwin DVB-T Receiver",
1278 .cold_ids = {&af9015_usb_table[5], NULL},
1279 .warm_ids = {NULL},
1280 },
1281 {
1282 .name = "TwinHan AzureWave AD-TU700(704J)",
1283 .cold_ids = {&af9015_usb_table[6], NULL},
1284 .warm_ids = {NULL},
1285 },
1286 {
1287 .name = "TerraTec Cinergy T USB XE",
1288 .cold_ids = {&af9015_usb_table[7], NULL},
1289 .warm_ids = {NULL},
1290 },
1291 {
1292 .name = "KWorld PlusTV Dual DVB-T PCI " \
1293 "(DVB-T PC160-2T)",
1294 .cold_ids = {&af9015_usb_table[8], NULL},
1295 .warm_ids = {NULL},
1296 },
1297 {
1298 .name = "AVerMedia AVerTV DVB-T Volar X",
1299 .cold_ids = {&af9015_usb_table[9], NULL},
1300 .warm_ids = {NULL},
1301 },
1302 }
1303 }, {
1304 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1305
1306 .usb_ctrl = DEVICE_SPECIFIC,
1307 .download_firmware = af9015_download_firmware,
1308 .firmware = "dvb-usb-af9015.fw",
1309
1310 .size_of_priv = sizeof(struct af9015_state), \
1311
1312 .num_adapters = 2,
1313 .adapter = {
1314 {
1315 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1316 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1317
1318 .pid_filter_count = 32,
1319 .pid_filter = af9015_pid_filter,
1320 .pid_filter_ctrl = af9015_pid_filter_ctrl,
1321
1322 .frontend_attach =
1323 af9015_af9013_frontend_attach,
1324 .tuner_attach = af9015_tuner_attach,
1325 .stream = {
1326 .type = USB_BULK,
1327 .count = 6,
1328 .endpoint = 0x84,
1329 },
1330 },
1331 {
1332 .frontend_attach =
1333 af9015_af9013_frontend_attach,
1334 .tuner_attach = af9015_tuner_attach,
1335 .stream = {
1336 .type = USB_BULK,
1337 .count = 6,
1338 .endpoint = 0x85,
1339 },
1340 }
1341 },
1342
1343 .identify_state = af9015_identify_state,
1344
1345 .rc_query = af9015_rc_query,
1346 .rc_interval = 150,
1347
1348 .i2c_algo = &af9015_i2c_algo,
1349
1350 .num_device_descs = 6,
1351 .devices = {
1352 {
1353 .name = "Xtensions XD-380",
1354 .cold_ids = {&af9015_usb_table[10], NULL},
1355 .warm_ids = {NULL},
1356 },
1357 {
1358 .name = "MSI DIGIVOX Duo",
1359 .cold_ids = {&af9015_usb_table[11], NULL},
1360 .warm_ids = {NULL},
1361 },
1362 {
1363 .name = "Fujitsu-Siemens Slim Mobile USB DVB-T",
1364 .cold_ids = {&af9015_usb_table[12], NULL},
1365 .warm_ids = {NULL},
1366 },
1367 {
1368 .name = "Telestar Starstick 2",
1369 .cold_ids = {&af9015_usb_table[13], NULL},
1370 .warm_ids = {NULL},
1371 },
1372 {
1373 .name = "AVerMedia A309",
1374 .cold_ids = {&af9015_usb_table[14], NULL},
1375 .warm_ids = {NULL},
1376 },
1377 {
1378 .name = "MSI Digi VOX mini III",
1379 .cold_ids = {&af9015_usb_table[15], NULL},
1380 .warm_ids = {NULL},
1381 },
1382 }
1383 }
1384};
1385
1386static int af9015_usb_probe(struct usb_interface *intf,
1387 const struct usb_device_id *id)
1388{
1389 int ret = 0;
1390 struct dvb_usb_device *d = NULL;
1391 struct usb_device *udev = interface_to_usbdev(intf);
1392 u8 i;
1393
1394 deb_info("%s: interface:%d\n", __func__,
1395 intf->cur_altsetting->desc.bInterfaceNumber);
1396
1397 /* interface 0 is used by DVB-T receiver and
1398 interface 1 is for remote controller (HID) */
1399 if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
1400 ret = af9015_read_config(udev);
1401 if (ret)
1402 return ret;
1403
1404 for (i = 0; i < af9015_properties_count; i++) {
1405 ret = dvb_usb_device_init(intf, &af9015_properties[i],
1406 THIS_MODULE, &d, adapter_nr);
1407 if (!ret)
1408 break;
1409 if (ret != -ENODEV)
1410 return ret;
1411 }
1412 if (ret)
1413 return ret;
1414
1415 if (d)
1416 ret = af9015_init(d);
1417 }
1418
1419 return ret;
1420}
1421
1422void af9015_i2c_exit(struct dvb_usb_device *d)
1423{
1424 struct af9015_state *state = d->priv;
1425 deb_info("%s: \n", __func__);
1426
1427 /* remove 2nd I2C adapter */
1428 if (d->state & DVB_USB_STATE_I2C)
1429 i2c_del_adapter(&state->i2c_adap);
1430}
1431
1432static void af9015_usb_device_exit(struct usb_interface *intf)
1433{
1434 struct dvb_usb_device *d = usb_get_intfdata(intf);
1435 deb_info("%s: \n", __func__);
1436
1437 /* remove 2nd I2C adapter */
1438 if (d != NULL && d->desc != NULL)
1439 af9015_i2c_exit(d);
1440
1441 dvb_usb_device_exit(intf);
1442}
1443
1444/* usb specific object needed to register this driver with the usb subsystem */
1445static struct usb_driver af9015_usb_driver = {
1446 .name = "dvb_usb_af9015",
1447 .probe = af9015_usb_probe,
1448 .disconnect = af9015_usb_device_exit,
1449 .id_table = af9015_usb_table,
1450};
1451
1452/* module stuff */
1453static int __init af9015_usb_module_init(void)
1454{
1455 int ret;
1456 ret = usb_register(&af9015_usb_driver);
1457 if (ret)
1458 err("module init failed:%d", ret);
1459
1460 return ret;
1461}
1462
1463static void __exit af9015_usb_module_exit(void)
1464{
1465 /* deregister this driver from the USB subsystem */
1466 usb_deregister(&af9015_usb_driver);
1467}
1468
1469module_init(af9015_usb_module_init);
1470module_exit(af9015_usb_module_exit);
1471
1472MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1473MODULE_DESCRIPTION("Driver for Afatech AF9015 DVB-T");
1474MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/af9015.h b/drivers/media/dvb/dvb-usb/af9015.h
new file mode 100644
index 000000000000..882e8a4b3681
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/af9015.h
@@ -0,0 +1,524 @@
1/*
2 * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver
3 *
4 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
5 *
6 * Thanks to Afatech who kindly provided information.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 */
23
24#ifndef _DVB_USB_AF9015_H_
25#define _DVB_USB_AF9015_H_
26
27#define DVB_USB_LOG_PREFIX "af9015"
28#include "dvb-usb.h"
29
30extern int dvb_usb_af9015_debug;
31#define deb_info(args...) dprintk(dvb_usb_af9015_debug, 0x01, args)
32#define deb_rc(args...) dprintk(dvb_usb_af9015_debug, 0x02, args)
33#define deb_xfer(args...) dprintk(dvb_usb_af9015_debug, 0x04, args)
34#define deb_reg(args...) dprintk(dvb_usb_af9015_debug, 0x08, args)
35#define deb_i2c(args...) dprintk(dvb_usb_af9015_debug, 0x10, args)
36#define deb_fw(args...) dprintk(dvb_usb_af9015_debug, 0x20, args)
37
38#define AF9015_I2C_EEPROM 0xa0
39#define AF9015_I2C_DEMOD 0x38
40#define AF9015_USB_TIMEOUT 2000
41
42/* EEPROM locations */
43#define AF9015_EEPROM_IR_MODE 0x18
44#define AF9015_EEPROM_IR_REMOTE_TYPE 0x34
45#define AF9015_EEPROM_TS_MODE 0x31
46#define AF9015_EEPROM_DEMOD2_I2C 0x32
47
48#define AF9015_EEPROM_SAW_BW1 0x35
49#define AF9015_EEPROM_XTAL_TYPE1 0x36
50#define AF9015_EEPROM_SPEC_INV1 0x37
51#define AF9015_EEPROM_IF1L 0x38
52#define AF9015_EEPROM_IF1H 0x39
53#define AF9015_EEPROM_MT2060_IF1L 0x3a
54#define AF9015_EEPROM_MT2060_IF1H 0x3b
55#define AF9015_EEPROM_TUNER_ID1 0x3c
56
57#define AF9015_EEPROM_SAW_BW2 0x45
58#define AF9015_EEPROM_XTAL_TYPE2 0x46
59#define AF9015_EEPROM_SPEC_INV2 0x47
60#define AF9015_EEPROM_IF2L 0x48
61#define AF9015_EEPROM_IF2H 0x49
62#define AF9015_EEPROM_MT2060_IF2L 0x4a
63#define AF9015_EEPROM_MT2060_IF2H 0x4b
64#define AF9015_EEPROM_TUNER_ID2 0x4c
65
66#define AF9015_EEPROM_OFFSET (AF9015_EEPROM_SAW_BW2 - AF9015_EEPROM_SAW_BW1)
67
68#define AF9015_GPIO_ON (1 << 0)
69#define AF9015_GPIO_EN (1 << 1)
70#define AF9015_GPIO_O (1 << 2)
71#define AF9015_GPIO_I (1 << 3)
72
73#define AF9015_GPIO_TUNER_ON (AF9015_GPIO_ON|AF9015_GPIO_EN)
74#define AF9015_GPIO_TUNER_OFF (AF9015_GPIO_ON|AF9015_GPIO_EN|AF9015_GPIO_O)
75
76struct req_t {
77 u8 cmd; /* [0] */
78 /* seq */ /* [1] */
79 u8 i2c_addr; /* [2] */
80 u16 addr; /* [3|4] */
81 u8 mbox; /* [5] */
82 u8 addr_len; /* [6] */
83 u8 data_len; /* [7] */
84 u8 *data;
85};
86
87enum af9015_cmd {
88 GET_CONFIG = 0x10,
89 DOWNLOAD_FIRMWARE = 0x11,
90 BOOT = 0x13,
91 READ_MEMORY = 0x20,
92 WRITE_MEMORY = 0x21,
93 READ_WRITE_I2C = 0x22,
94 COPY_FIRMWARE = 0x23,
95 RECONNECT_USB = 0x5a,
96 WRITE_VIRTUAL_MEMORY = 0x26,
97 GET_IR_CODE = 0x27,
98 READ_I2C,
99 WRITE_I2C,
100};
101
102enum af9015_ir_mode {
103 AF9015_IR_MODE_DISABLED = 0,
104 AF9015_IR_MODE_HID,
105 AF9015_IR_MODE_RLC,
106 AF9015_IR_MODE_RC6,
107};
108
109struct af9015_state {
110 struct i2c_adapter i2c_adap; /* I2C adapter for 2nd FE */
111};
112
113struct af9015_config {
114 u8 dual_mode:1;
115 u16 mt2060_if1[2];
116 u16 firmware_size;
117 u16 firmware_checksum;
118 u8 *ir_table;
119 u16 ir_table_size;
120};
121
122enum af9015_remote {
123 AF9015_REMOTE_NONE = 0,
124 AF9015_REMOTE_A_LINK_DTU_M,
125 AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3,
126 AF9015_REMOTE_MYGICTV_U718,
127};
128
129/* Leadtek WinFast DTV Dongle Gold */
130static struct dvb_usb_rc_key af9015_rc_keys_leadtek[] = {
131 { 0x00, 0x1e, KEY_1 },
132 { 0x00, 0x1f, KEY_2 },
133 { 0x00, 0x20, KEY_3 },
134 { 0x00, 0x21, KEY_4 },
135 { 0x00, 0x22, KEY_5 },
136 { 0x00, 0x23, KEY_6 },
137 { 0x00, 0x24, KEY_7 },
138 { 0x00, 0x25, KEY_8 },
139 { 0x00, 0x26, KEY_9 },
140 { 0x00, 0x27, KEY_0 },
141 { 0x00, 0x28, KEY_ENTER },
142 { 0x00, 0x4f, KEY_VOLUMEUP },
143 { 0x00, 0x50, KEY_VOLUMEDOWN },
144 { 0x00, 0x51, KEY_CHANNELDOWN },
145 { 0x00, 0x52, KEY_CHANNELUP },
146};
147
148static u8 af9015_ir_table_leadtek[] = {
149 0x03, 0xfc, 0x00, 0xff, 0x1a, 0x01, 0x00,
150 0x03, 0xfc, 0x56, 0xa9, 0x00, 0x00, 0x00,
151 0x03, 0xfc, 0x4b, 0xb4, 0x00, 0x00, 0x00,
152 0x03, 0xfc, 0x4c, 0xb3, 0xb2, 0x04, 0x00,
153 0x03, 0xfc, 0x4d, 0xb2, 0x00, 0x00, 0x00,
154 0x03, 0xfc, 0x4e, 0xb1, 0x00, 0x00, 0x00,
155 0x03, 0xfc, 0x1f, 0xe0, 0x3d, 0x00, 0x00,
156 0x03, 0xfc, 0x40, 0xbf, 0x13, 0x01, 0x00,
157 0x03, 0xfc, 0x14, 0xeb, 0x10, 0x00, 0x00,
158 0x03, 0xfc, 0x49, 0xb6, 0x05, 0x01, 0x00,
159 0x03, 0xfc, 0x50, 0xaf, 0x29, 0x00, 0x00,
160 0x03, 0xfc, 0x0c, 0xf3, 0x52, 0x00, 0x00,
161 0x03, 0xfc, 0x03, 0xfc, 0x09, 0x00, 0x00,
162 0x03, 0xfc, 0x08, 0xf7, 0x50, 0x00, 0x00,
163 0x03, 0xfc, 0x13, 0xec, 0x28, 0x00, 0x00,
164 0x03, 0xfc, 0x04, 0xfb, 0x4f, 0x00, 0x00,
165 0x03, 0xfc, 0x4f, 0xb0, 0x0f, 0x01, 0x00,
166 0x03, 0xfc, 0x10, 0xef, 0x51, 0x00, 0x00,
167 0x03, 0xfc, 0x51, 0xae, 0x3f, 0x00, 0x00,
168 0x03, 0xfc, 0x42, 0xbd, 0x13, 0x00, 0x00,
169 0x03, 0xfc, 0x43, 0xbc, 0x00, 0x00, 0x00,
170 0x03, 0xfc, 0x44, 0xbb, 0x11, 0x00, 0x00,
171 0x03, 0xfc, 0x52, 0xad, 0x19, 0x00, 0x00,
172 0x03, 0xfc, 0x54, 0xab, 0x05, 0x00, 0x00,
173 0x03, 0xfc, 0x46, 0xb9, 0x29, 0x00, 0x00,
174 0x03, 0xfc, 0x55, 0xaa, 0x2b, 0x00, 0x00,
175 0x03, 0xfc, 0x53, 0xac, 0x41, 0x00, 0x00,
176 0x03, 0xfc, 0x05, 0xfa, 0x1e, 0x00, 0x00,
177 0x03, 0xfc, 0x06, 0xf9, 0x1f, 0x00, 0x00,
178 0x03, 0xfc, 0x07, 0xf8, 0x20, 0x00, 0x00,
179 0x03, 0xfc, 0x1e, 0xe1, 0x19, 0x00, 0x00,
180 0x03, 0xfc, 0x09, 0xf6, 0x21, 0x00, 0x00,
181 0x03, 0xfc, 0x0a, 0xf5, 0x22, 0x00, 0x00,
182 0x03, 0xfc, 0x0b, 0xf4, 0x23, 0x00, 0x00,
183 0x03, 0xfc, 0x1b, 0xe4, 0x16, 0x00, 0x00,
184 0x03, 0xfc, 0x0d, 0xf2, 0x24, 0x00, 0x00,
185 0x03, 0xfc, 0x0e, 0xf1, 0x25, 0x00, 0x00,
186 0x03, 0xfc, 0x0f, 0xf0, 0x26, 0x00, 0x00,
187 0x03, 0xfc, 0x16, 0xe9, 0x28, 0x00, 0x00,
188 0x03, 0xfc, 0x41, 0xbe, 0x37, 0x00, 0x00,
189 0x03, 0xfc, 0x12, 0xed, 0x27, 0x00, 0x00,
190 0x03, 0xfc, 0x11, 0xee, 0x2a, 0x00, 0x00,
191 0x03, 0xfc, 0x48, 0xb7, 0x2c, 0x00, 0x00,
192 0x03, 0xfc, 0x4a, 0xb5, 0x3c, 0x00, 0x00,
193 0x03, 0xfc, 0x47, 0xb8, 0x15, 0x01, 0x00,
194 0x03, 0xfc, 0x45, 0xba, 0x0b, 0x01, 0x00,
195 0x03, 0xfc, 0x5e, 0xa1, 0x43, 0x00, 0x00,
196 0x03, 0xfc, 0x5a, 0xa5, 0x42, 0x00, 0x00,
197 0x03, 0xfc, 0x5b, 0xa4, 0x4b, 0x00, 0x00,
198 0x03, 0xfc, 0x5f, 0xa0, 0x4e, 0x00, 0x00,
199};
200
201/* TwinHan AzureWave AD-TU700(704J) */
202static struct dvb_usb_rc_key af9015_rc_keys_twinhan[] = {
203 { 0x05, 0x3f, KEY_POWER },
204 { 0x00, 0x19, KEY_FAVORITES }, /* Favorite List */
205 { 0x00, 0x04, KEY_TEXT }, /* Teletext */
206 { 0x00, 0x0e, KEY_POWER },
207 { 0x00, 0x0e, KEY_INFO }, /* Preview */
208 { 0x00, 0x08, KEY_EPG }, /* Info/EPG */
209 { 0x00, 0x0f, KEY_LIST }, /* Record List */
210 { 0x00, 0x1e, KEY_1 },
211 { 0x00, 0x1f, KEY_2 },
212 { 0x00, 0x20, KEY_3 },
213 { 0x00, 0x21, KEY_4 },
214 { 0x00, 0x22, KEY_5 },
215 { 0x00, 0x23, KEY_6 },
216 { 0x00, 0x24, KEY_7 },
217 { 0x00, 0x25, KEY_8 },
218 { 0x00, 0x26, KEY_9 },
219 { 0x00, 0x27, KEY_0 },
220 { 0x00, 0x29, KEY_CANCEL }, /* Cancel */
221 { 0x00, 0x4c, KEY_CLEAR }, /* Clear */
222 { 0x00, 0x2a, KEY_BACK }, /* Back */
223 { 0x00, 0x2b, KEY_TAB }, /* Tab */
224 { 0x00, 0x52, KEY_UP }, /* up arrow */
225 { 0x00, 0x51, KEY_DOWN }, /* down arrow */
226 { 0x00, 0x4f, KEY_RIGHT }, /* right arrow */
227 { 0x00, 0x50, KEY_LEFT }, /* left arrow */
228 { 0x00, 0x28, KEY_ENTER }, /* Enter / ok */
229 { 0x02, 0x52, KEY_VOLUMEUP },
230 { 0x02, 0x51, KEY_VOLUMEDOWN },
231 { 0x00, 0x4e, KEY_CHANNELDOWN },
232 { 0x00, 0x4b, KEY_CHANNELUP },
233 { 0x00, 0x4a, KEY_RECORD },
234 { 0x01, 0x11, KEY_PLAY },
235 { 0x00, 0x17, KEY_PAUSE },
236 { 0x00, 0x0c, KEY_REWIND }, /* FR << */
237 { 0x00, 0x11, KEY_FASTFORWARD }, /* FF >> */
238 { 0x01, 0x15, KEY_PREVIOUS }, /* Replay */
239 { 0x01, 0x0e, KEY_NEXT }, /* Skip */
240 { 0x00, 0x13, KEY_CAMERA }, /* Capture */
241 { 0x01, 0x0f, KEY_LANGUAGE }, /* SAP */
242 { 0x01, 0x13, KEY_TV2 }, /* PIP */
243 { 0x00, 0x1d, KEY_ZOOM }, /* Full Screen */
244 { 0x01, 0x17, KEY_SUBTITLE }, /* Subtitle / CC */
245 { 0x00, 0x10, KEY_MUTE },
246 { 0x01, 0x19, KEY_AUDIO }, /* L/R */ /* TODO better event */
247 { 0x01, 0x16, KEY_SLEEP }, /* Hibernate */
248 { 0x01, 0x16, KEY_SWITCHVIDEOMODE },
249 /* A/V */ /* TODO does not work */
250 { 0x00, 0x06, KEY_AGAIN }, /* Recall */
251 { 0x01, 0x16, KEY_KPPLUS }, /* Zoom+ */ /* TODO does not work */
252 { 0x01, 0x16, KEY_KPMINUS }, /* Zoom- */ /* TODO does not work */
253 { 0x02, 0x15, KEY_RED },
254 { 0x02, 0x0a, KEY_GREEN },
255 { 0x02, 0x1c, KEY_YELLOW },
256 { 0x02, 0x05, KEY_BLUE },
257};
258
259static u8 af9015_ir_table_twinhan[] = {
260 0x00, 0xff, 0x16, 0xe9, 0x3f, 0x05, 0x00,
261 0x00, 0xff, 0x07, 0xf8, 0x16, 0x01, 0x00,
262 0x00, 0xff, 0x14, 0xeb, 0x11, 0x01, 0x00,
263 0x00, 0xff, 0x1a, 0xe5, 0x4d, 0x00, 0x00,
264 0x00, 0xff, 0x4c, 0xb3, 0x17, 0x00, 0x00,
265 0x00, 0xff, 0x12, 0xed, 0x11, 0x00, 0x00,
266 0x00, 0xff, 0x40, 0xbf, 0x0c, 0x00, 0x00,
267 0x00, 0xff, 0x11, 0xee, 0x4a, 0x00, 0x00,
268 0x00, 0xff, 0x54, 0xab, 0x13, 0x00, 0x00,
269 0x00, 0xff, 0x41, 0xbe, 0x15, 0x01, 0x00,
270 0x00, 0xff, 0x42, 0xbd, 0x0e, 0x01, 0x00,
271 0x00, 0xff, 0x43, 0xbc, 0x17, 0x01, 0x00,
272 0x00, 0xff, 0x50, 0xaf, 0x0f, 0x01, 0x00,
273 0x00, 0xff, 0x4d, 0xb2, 0x1d, 0x00, 0x00,
274 0x00, 0xff, 0x47, 0xb8, 0x13, 0x01, 0x00,
275 0x00, 0xff, 0x05, 0xfa, 0x4b, 0x00, 0x00,
276 0x00, 0xff, 0x02, 0xfd, 0x4e, 0x00, 0x00,
277 0x00, 0xff, 0x0e, 0xf1, 0x06, 0x00, 0x00,
278 0x00, 0xff, 0x1e, 0xe1, 0x52, 0x02, 0x00,
279 0x00, 0xff, 0x0a, 0xf5, 0x51, 0x02, 0x00,
280 0x00, 0xff, 0x10, 0xef, 0x10, 0x00, 0x00,
281 0x00, 0xff, 0x49, 0xb6, 0x19, 0x01, 0x00,
282 0x00, 0xff, 0x15, 0xea, 0x27, 0x00, 0x00,
283 0x00, 0xff, 0x03, 0xfc, 0x1e, 0x00, 0x00,
284 0x00, 0xff, 0x01, 0xfe, 0x1f, 0x00, 0x00,
285 0x00, 0xff, 0x06, 0xf9, 0x20, 0x00, 0x00,
286 0x00, 0xff, 0x09, 0xf6, 0x21, 0x00, 0x00,
287 0x00, 0xff, 0x1d, 0xe2, 0x22, 0x00, 0x00,
288 0x00, 0xff, 0x1f, 0xe0, 0x23, 0x00, 0x00,
289 0x00, 0xff, 0x0d, 0xf2, 0x24, 0x00, 0x00,
290 0x00, 0xff, 0x19, 0xe6, 0x25, 0x00, 0x00,
291 0x00, 0xff, 0x1b, 0xe4, 0x26, 0x00, 0x00,
292 0x00, 0xff, 0x00, 0xff, 0x2b, 0x00, 0x00,
293 0x00, 0xff, 0x4a, 0xb5, 0x4c, 0x00, 0x00,
294 0x00, 0xff, 0x4b, 0xb4, 0x52, 0x00, 0x00,
295 0x00, 0xff, 0x51, 0xae, 0x51, 0x00, 0x00,
296 0x00, 0xff, 0x52, 0xad, 0x4f, 0x00, 0x00,
297 0x00, 0xff, 0x4e, 0xb1, 0x50, 0x00, 0x00,
298 0x00, 0xff, 0x0c, 0xf3, 0x29, 0x00, 0x00,
299 0x00, 0xff, 0x4f, 0xb0, 0x28, 0x00, 0x00,
300 0x00, 0xff, 0x13, 0xec, 0x2a, 0x00, 0x00,
301 0x00, 0xff, 0x17, 0xe8, 0x19, 0x00, 0x00,
302 0x00, 0xff, 0x04, 0xfb, 0x0f, 0x00, 0x00,
303 0x00, 0xff, 0x48, 0xb7, 0x0e, 0x00, 0x00,
304 0x00, 0xff, 0x0f, 0xf0, 0x04, 0x00, 0x00,
305 0x00, 0xff, 0x1c, 0xe3, 0x08, 0x00, 0x00,
306 0x00, 0xff, 0x18, 0xe7, 0x15, 0x02, 0x00,
307 0x00, 0xff, 0x53, 0xac, 0x0a, 0x02, 0x00,
308 0x00, 0xff, 0x5e, 0xa1, 0x1c, 0x02, 0x00,
309 0x00, 0xff, 0x5f, 0xa0, 0x05, 0x02, 0x00,
310};
311
312/* A-Link DTU(m) */
313static struct dvb_usb_rc_key af9015_rc_keys_a_link[] = {
314 { 0x00, 0x1e, KEY_1 },
315 { 0x00, 0x1f, KEY_2 },
316 { 0x00, 0x20, KEY_3 },
317 { 0x00, 0x21, KEY_4 },
318 { 0x00, 0x22, KEY_5 },
319 { 0x00, 0x23, KEY_6 },
320 { 0x00, 0x24, KEY_7 },
321 { 0x00, 0x25, KEY_8 },
322 { 0x00, 0x26, KEY_9 },
323 { 0x00, 0x27, KEY_0 },
324 { 0x00, 0x2e, KEY_CHANNELUP },
325 { 0x00, 0x2d, KEY_CHANNELDOWN },
326 { 0x04, 0x28, KEY_ZOOM },
327 { 0x00, 0x41, KEY_MUTE },
328 { 0x00, 0x42, KEY_VOLUMEDOWN },
329 { 0x00, 0x43, KEY_VOLUMEUP },
330 { 0x00, 0x44, KEY_GOTO }, /* jump */
331 { 0x05, 0x45, KEY_POWER },
332};
333
334static u8 af9015_ir_table_a_link[] = {
335 0x08, 0xf7, 0x12, 0xed, 0x45, 0x05, 0x00, /* power */
336 0x08, 0xf7, 0x1a, 0xe5, 0x41, 0x00, 0x00, /* mute */
337 0x08, 0xf7, 0x01, 0xfe, 0x1e, 0x00, 0x00, /* 1 */
338 0x08, 0xf7, 0x1c, 0xe3, 0x21, 0x00, 0x00, /* 4 */
339 0x08, 0xf7, 0x03, 0xfc, 0x24, 0x00, 0x00, /* 7 */
340 0x08, 0xf7, 0x05, 0xfa, 0x28, 0x04, 0x00, /* zoom */
341 0x08, 0xf7, 0x00, 0xff, 0x43, 0x00, 0x00, /* volume up */
342 0x08, 0xf7, 0x16, 0xe9, 0x42, 0x00, 0x00, /* volume down */
343 0x08, 0xf7, 0x0f, 0xf0, 0x1f, 0x00, 0x00, /* 2 */
344 0x08, 0xf7, 0x0d, 0xf2, 0x22, 0x00, 0x00, /* 5 */
345 0x08, 0xf7, 0x1b, 0xe4, 0x25, 0x00, 0x00, /* 8 */
346 0x08, 0xf7, 0x06, 0xf9, 0x27, 0x00, 0x00, /* 0 */
347 0x08, 0xf7, 0x14, 0xeb, 0x2e, 0x00, 0x00, /* channel up */
348 0x08, 0xf7, 0x1d, 0xe2, 0x2d, 0x00, 0x00, /* channel down */
349 0x08, 0xf7, 0x02, 0xfd, 0x20, 0x00, 0x00, /* 3 */
350 0x08, 0xf7, 0x18, 0xe7, 0x23, 0x00, 0x00, /* 6 */
351 0x08, 0xf7, 0x04, 0xfb, 0x26, 0x00, 0x00, /* 9 */
352 0x08, 0xf7, 0x07, 0xf8, 0x44, 0x00, 0x00, /* jump */
353};
354
355/* MSI DIGIVOX mini II V3.0 */
356static struct dvb_usb_rc_key af9015_rc_keys_msi[] = {
357 { 0x00, 0x1e, KEY_1 },
358 { 0x00, 0x1f, KEY_2 },
359 { 0x00, 0x20, KEY_3 },
360 { 0x00, 0x21, KEY_4 },
361 { 0x00, 0x22, KEY_5 },
362 { 0x00, 0x23, KEY_6 },
363 { 0x00, 0x24, KEY_7 },
364 { 0x00, 0x25, KEY_8 },
365 { 0x00, 0x26, KEY_9 },
366 { 0x00, 0x27, KEY_0 },
367 { 0x03, 0x0f, KEY_CHANNELUP },
368 { 0x03, 0x0e, KEY_CHANNELDOWN },
369 { 0x00, 0x42, KEY_VOLUMEDOWN },
370 { 0x00, 0x43, KEY_VOLUMEUP },
371 { 0x05, 0x45, KEY_POWER },
372 { 0x00, 0x52, KEY_UP }, /* up */
373 { 0x00, 0x51, KEY_DOWN }, /* down */
374 { 0x00, 0x28, KEY_ENTER },
375};
376
377static u8 af9015_ir_table_msi[] = {
378 0x03, 0xfc, 0x17, 0xe8, 0x45, 0x05, 0x00, /* power */
379 0x03, 0xfc, 0x0d, 0xf2, 0x51, 0x00, 0x00, /* down */
380 0x03, 0xfc, 0x03, 0xfc, 0x52, 0x00, 0x00, /* up */
381 0x03, 0xfc, 0x1a, 0xe5, 0x1e, 0x00, 0x00, /* 1 */
382 0x03, 0xfc, 0x02, 0xfd, 0x1f, 0x00, 0x00, /* 2 */
383 0x03, 0xfc, 0x04, 0xfb, 0x20, 0x00, 0x00, /* 3 */
384 0x03, 0xfc, 0x1c, 0xe3, 0x21, 0x00, 0x00, /* 4 */
385 0x03, 0xfc, 0x08, 0xf7, 0x22, 0x00, 0x00, /* 5 */
386 0x03, 0xfc, 0x1d, 0xe2, 0x23, 0x00, 0x00, /* 6 */
387 0x03, 0xfc, 0x11, 0xee, 0x24, 0x00, 0x00, /* 7 */
388 0x03, 0xfc, 0x0b, 0xf4, 0x25, 0x00, 0x00, /* 8 */
389 0x03, 0xfc, 0x10, 0xef, 0x26, 0x00, 0x00, /* 9 */
390 0x03, 0xfc, 0x09, 0xf6, 0x27, 0x00, 0x00, /* 0 */
391 0x03, 0xfc, 0x14, 0xeb, 0x43, 0x00, 0x00, /* volume up */
392 0x03, 0xfc, 0x1f, 0xe0, 0x42, 0x00, 0x00, /* volume down */
393 0x03, 0xfc, 0x15, 0xea, 0x0f, 0x03, 0x00, /* channel up */
394 0x03, 0xfc, 0x05, 0xfa, 0x0e, 0x03, 0x00, /* channel down */
395 0x03, 0xfc, 0x16, 0xe9, 0x28, 0x00, 0x00, /* enter */
396};
397
398/* MYGICTV U718 */
399static struct dvb_usb_rc_key af9015_rc_keys_mygictv[] = {
400 { 0x00, 0x3d, KEY_SWITCHVIDEOMODE },
401 /* TV / AV */
402 { 0x05, 0x45, KEY_POWER },
403 { 0x00, 0x1e, KEY_1 },
404 { 0x00, 0x1f, KEY_2 },
405 { 0x00, 0x20, KEY_3 },
406 { 0x00, 0x21, KEY_4 },
407 { 0x00, 0x22, KEY_5 },
408 { 0x00, 0x23, KEY_6 },
409 { 0x00, 0x24, KEY_7 },
410 { 0x00, 0x25, KEY_8 },
411 { 0x00, 0x26, KEY_9 },
412 { 0x00, 0x27, KEY_0 },
413 { 0x00, 0x41, KEY_MUTE },
414 { 0x00, 0x2a, KEY_ESC }, /* Esc */
415 { 0x00, 0x2e, KEY_CHANNELUP },
416 { 0x00, 0x2d, KEY_CHANNELDOWN },
417 { 0x00, 0x42, KEY_VOLUMEDOWN },
418 { 0x00, 0x43, KEY_VOLUMEUP },
419 { 0x00, 0x52, KEY_UP }, /* up arrow */
420 { 0x00, 0x51, KEY_DOWN }, /* down arrow */
421 { 0x00, 0x4f, KEY_RIGHT }, /* right arrow */
422 { 0x00, 0x50, KEY_LEFT }, /* left arrow */
423 { 0x00, 0x28, KEY_ENTER }, /* ok */
424 { 0x01, 0x15, KEY_RECORD },
425 { 0x03, 0x13, KEY_PLAY },
426 { 0x01, 0x13, KEY_PAUSE },
427 { 0x01, 0x16, KEY_STOP },
428 { 0x03, 0x07, KEY_REWIND }, /* FR << */
429 { 0x03, 0x09, KEY_FASTFORWARD }, /* FF >> */
430 { 0x00, 0x3b, KEY_TIME }, /* TimeShift */
431 { 0x00, 0x3e, KEY_CAMERA }, /* Snapshot */
432 { 0x03, 0x16, KEY_CYCLEWINDOWS }, /* yellow, min / max */
433 { 0x00, 0x00, KEY_ZOOM }, /* 'select' (?) */
434 { 0x03, 0x16, KEY_SHUFFLE }, /* Shuffle */
435 { 0x03, 0x45, KEY_POWER },
436};
437
438static u8 af9015_ir_table_mygictv[] = {
439 0x02, 0xbd, 0x0c, 0xf3, 0x3d, 0x00, 0x00, /* TV / AV */
440 0x02, 0xbd, 0x14, 0xeb, 0x45, 0x05, 0x00, /* power */
441 0x02, 0xbd, 0x00, 0xff, 0x1e, 0x00, 0x00, /* 1 */
442 0x02, 0xbd, 0x01, 0xfe, 0x1f, 0x00, 0x00, /* 2 */
443 0x02, 0xbd, 0x02, 0xfd, 0x20, 0x00, 0x00, /* 3 */
444 0x02, 0xbd, 0x03, 0xfc, 0x21, 0x00, 0x00, /* 4 */
445 0x02, 0xbd, 0x04, 0xfb, 0x22, 0x00, 0x00, /* 5 */
446 0x02, 0xbd, 0x05, 0xfa, 0x23, 0x00, 0x00, /* 6 */
447 0x02, 0xbd, 0x06, 0xf9, 0x24, 0x00, 0x00, /* 7 */
448 0x02, 0xbd, 0x07, 0xf8, 0x25, 0x00, 0x00, /* 8 */
449 0x02, 0xbd, 0x08, 0xf7, 0x26, 0x00, 0x00, /* 9 */
450 0x02, 0xbd, 0x09, 0xf6, 0x27, 0x00, 0x00, /* 0 */
451 0x02, 0xbd, 0x0a, 0xf5, 0x41, 0x00, 0x00, /* mute */
452 0x02, 0xbd, 0x1c, 0xe3, 0x2a, 0x00, 0x00, /* esc */
453 0x02, 0xbd, 0x1f, 0xe0, 0x43, 0x00, 0x00, /* volume up */
454 0x02, 0xbd, 0x12, 0xed, 0x52, 0x00, 0x00, /* up arrow */
455 0x02, 0xbd, 0x11, 0xee, 0x50, 0x00, 0x00, /* left arrow */
456 0x02, 0xbd, 0x15, 0xea, 0x28, 0x00, 0x00, /* ok */
457 0x02, 0xbd, 0x10, 0xef, 0x4f, 0x00, 0x00, /* right arrow */
458 0x02, 0xbd, 0x13, 0xec, 0x51, 0x00, 0x00, /* down arrow */
459 0x02, 0xbd, 0x0e, 0xf1, 0x42, 0x00, 0x00, /* volume down */
460 0x02, 0xbd, 0x19, 0xe6, 0x15, 0x01, 0x00, /* record */
461 0x02, 0xbd, 0x1e, 0xe1, 0x13, 0x03, 0x00, /* play */
462 0x02, 0xbd, 0x16, 0xe9, 0x16, 0x01, 0x00, /* stop */
463 0x02, 0xbd, 0x0b, 0xf4, 0x28, 0x04, 0x00, /* yellow, min / max */
464 0x02, 0xbd, 0x0f, 0xf0, 0x3b, 0x00, 0x00, /* time shift */
465 0x02, 0xbd, 0x18, 0xe7, 0x2e, 0x00, 0x00, /* channel up */
466 0x02, 0xbd, 0x1a, 0xe5, 0x2d, 0x00, 0x00, /* channel down */
467 0x02, 0xbd, 0x17, 0xe8, 0x3e, 0x00, 0x00, /* snapshot */
468 0x02, 0xbd, 0x40, 0xbf, 0x13, 0x01, 0x00, /* pause */
469 0x02, 0xbd, 0x41, 0xbe, 0x09, 0x03, 0x00, /* FF >> */
470 0x02, 0xbd, 0x42, 0xbd, 0x07, 0x03, 0x00, /* FR << */
471 0x02, 0xbd, 0x43, 0xbc, 0x00, 0x00, 0x00, /* 'select' (?) */
472 0x02, 0xbd, 0x44, 0xbb, 0x16, 0x03, 0x00, /* shuffle */
473 0x02, 0xbd, 0x45, 0xba, 0x45, 0x03, 0x00, /* power */
474};
475
476/* KWorld PlusTV Dual DVB-T Stick (DVB-T 399U) */
477static u8 af9015_ir_table_kworld[] = {
478 0x86, 0x6b, 0x0c, 0xf3, 0x2e, 0x07, 0x00,
479 0x86, 0x6b, 0x16, 0xe9, 0x2d, 0x07, 0x00,
480 0x86, 0x6b, 0x1d, 0xe2, 0x37, 0x07, 0x00,
481 0x86, 0x6b, 0x00, 0xff, 0x1e, 0x07, 0x00,
482 0x86, 0x6b, 0x01, 0xfe, 0x1f, 0x07, 0x00,
483 0x86, 0x6b, 0x02, 0xfd, 0x20, 0x07, 0x00,
484 0x86, 0x6b, 0x03, 0xfc, 0x21, 0x07, 0x00,
485 0x86, 0x6b, 0x04, 0xfb, 0x22, 0x07, 0x00,
486 0x86, 0x6b, 0x05, 0xfa, 0x23, 0x07, 0x00,
487 0x86, 0x6b, 0x06, 0xf9, 0x24, 0x07, 0x00,
488 0x86, 0x6b, 0x07, 0xf8, 0x25, 0x07, 0x00,
489 0x86, 0x6b, 0x08, 0xf7, 0x26, 0x07, 0x00,
490 0x86, 0x6b, 0x09, 0xf6, 0x4d, 0x07, 0x00,
491 0x86, 0x6b, 0x0a, 0xf5, 0x4e, 0x07, 0x00,
492 0x86, 0x6b, 0x14, 0xeb, 0x4f, 0x07, 0x00,
493 0x86, 0x6b, 0x1e, 0xe1, 0x50, 0x07, 0x00,
494 0x86, 0x6b, 0x17, 0xe8, 0x52, 0x07, 0x00,
495 0x86, 0x6b, 0x1f, 0xe0, 0x51, 0x07, 0x00,
496 0x86, 0x6b, 0x0e, 0xf1, 0x0b, 0x07, 0x00,
497 0x86, 0x6b, 0x20, 0xdf, 0x0c, 0x07, 0x00,
498 0x86, 0x6b, 0x42, 0xbd, 0x0d, 0x07, 0x00,
499 0x86, 0x6b, 0x0b, 0xf4, 0x0e, 0x07, 0x00,
500 0x86, 0x6b, 0x43, 0xbc, 0x0f, 0x07, 0x00,
501 0x86, 0x6b, 0x10, 0xef, 0x10, 0x07, 0x00,
502 0x86, 0x6b, 0x21, 0xde, 0x11, 0x07, 0x00,
503 0x86, 0x6b, 0x13, 0xec, 0x12, 0x07, 0x00,
504 0x86, 0x6b, 0x11, 0xee, 0x13, 0x07, 0x00,
505 0x86, 0x6b, 0x12, 0xed, 0x14, 0x07, 0x00,
506 0x86, 0x6b, 0x19, 0xe6, 0x15, 0x07, 0x00,
507 0x86, 0x6b, 0x1a, 0xe5, 0x16, 0x07, 0x00,
508 0x86, 0x6b, 0x1b, 0xe4, 0x17, 0x07, 0x00,
509 0x86, 0x6b, 0x4b, 0xb4, 0x18, 0x07, 0x00,
510 0x86, 0x6b, 0x40, 0xbf, 0x19, 0x07, 0x00,
511 0x86, 0x6b, 0x44, 0xbb, 0x1a, 0x07, 0x00,
512 0x86, 0x6b, 0x41, 0xbe, 0x1b, 0x07, 0x00,
513 0x86, 0x6b, 0x22, 0xdd, 0x1c, 0x07, 0x00,
514 0x86, 0x6b, 0x15, 0xea, 0x1d, 0x07, 0x00,
515 0x86, 0x6b, 0x0f, 0xf0, 0x3f, 0x07, 0x00,
516 0x86, 0x6b, 0x1c, 0xe3, 0x40, 0x07, 0x00,
517 0x86, 0x6b, 0x4a, 0xb5, 0x41, 0x07, 0x00,
518 0x86, 0x6b, 0x48, 0xb7, 0x42, 0x07, 0x00,
519 0x86, 0x6b, 0x49, 0xb6, 0x43, 0x07, 0x00,
520 0x86, 0x6b, 0x18, 0xe7, 0x44, 0x07, 0x00,
521 0x86, 0x6b, 0x23, 0xdc, 0x45, 0x07, 0x00,
522};
523
524#endif
diff --git a/drivers/media/dvb/dvb-usb/anysee.c b/drivers/media/dvb/dvb-usb/anysee.c
index 2f408d2e1ef3..c786359fba03 100644
--- a/drivers/media/dvb/dvb-usb/anysee.c
+++ b/drivers/media/dvb/dvb-usb/anysee.c
@@ -41,6 +41,9 @@
41static int dvb_usb_anysee_debug; 41static int dvb_usb_anysee_debug;
42module_param_named(debug, dvb_usb_anysee_debug, int, 0644); 42module_param_named(debug, dvb_usb_anysee_debug, int, 0644);
43MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS); 43MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
44int dvb_usb_anysee_delsys;
45module_param_named(delsys, dvb_usb_anysee_delsys, int, 0644);
46MODULE_PARM_DESC(delsys, "select delivery mode (0=DVB-C, 1=DVB-T)");
44DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 47DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
45 48
46static struct mutex anysee_usb_mutex; 49static struct mutex anysee_usb_mutex;
@@ -178,14 +181,14 @@ static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
178 inc = 1; 181 inc = 1;
179 } 182 }
180 if (ret) 183 if (ret)
181 return ret; 184 break;
182 185
183 i += inc; 186 i += inc;
184 } 187 }
185 188
186 mutex_unlock(&d->i2c_mutex); 189 mutex_unlock(&d->i2c_mutex);
187 190
188 return i; 191 return ret ? ret : i;
189} 192}
190 193
191static u32 anysee_i2c_func(struct i2c_adapter *adapter) 194static u32 anysee_i2c_func(struct i2c_adapter *adapter)
@@ -272,9 +275,11 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
272 model demod hw firmware 275 model demod hw firmware
273 1. E30 MT352 02 0.2.1 276 1. E30 MT352 02 0.2.1
274 2. E30 ZL10353 02 0.2.1 277 2. E30 ZL10353 02 0.2.1
275 3. E30 Plus ZL10353 06 0.1.0 278 3. E30 Combo ZL10353 0f 0.1.2 DVB-T/C combo
276 4. E30C Plus TDA10023 0a 0.1.0 rev 0.2 279 4. E30 Plus ZL10353 06 0.1.0
277 4. E30C Plus TDA10023 0f 0.1.2 rev 0.4 280 5. E30C Plus TDA10023 0a 0.1.0 rev 0.2
281 E30C Plus TDA10023 0f 0.1.2 rev 0.4
282 E30 Combo TDA10023 0f 0.1.2 DVB-T/C combo
278 */ 283 */
279 284
280 /* Zarlink MT352 DVB-T demod inside of Samsung DNOS404ZH102A NIM */ 285 /* Zarlink MT352 DVB-T demod inside of Samsung DNOS404ZH102A NIM */
@@ -293,6 +298,21 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
293 return 0; 298 return 0;
294 } 299 }
295 300
301 /* for E30 Combo Plus DVB-T demodulator */
302 if (dvb_usb_anysee_delsys) {
303 ret = anysee_write_reg(adap->dev, 0xb0, 0x01);
304 if (ret)
305 return ret;
306
307 /* Zarlink ZL10353 DVB-T demod */
308 adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
309 &adap->dev->i2c_adap);
310 if (adap->fe != NULL) {
311 state->tuner = DVB_PLL_SAMSUNG_DTOS403IH102A;
312 return 0;
313 }
314 }
315
296 /* connect demod on IO port D for TDA10023 & ZL10353 */ 316 /* connect demod on IO port D for TDA10023 & ZL10353 */
297 ret = anysee_write_reg(adap->dev, 0xb0, 0x25); 317 ret = anysee_write_reg(adap->dev, 0xb0, 0x25);
298 if (ret) 318 if (ret)
diff --git a/drivers/media/dvb/dvb-usb/cinergyT2-core.c b/drivers/media/dvb/dvb-usb/cinergyT2-core.c
new file mode 100644
index 000000000000..3ac9f74e9fbf
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/cinergyT2-core.c
@@ -0,0 +1,268 @@
1/*
2 * TerraTec Cinergy T2/qanu USB2 DVB-T adapter.
3 *
4 * Copyright (C) 2007 Tomi Orava (tomimo@ncircle.nullnet.fi)
5 *
6 * Based on the dvb-usb-framework code and the
7 * original Terratec Cinergy T2 driver by:
8 *
9 * Copyright (C) 2004 Daniel Mack <daniel@qanu.de> and
10 * Holger Waechtler <holger@qanu.de>
11 *
12 * Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 *
28 */
29
30#include "cinergyT2.h"
31
32
33/* debug */
34int dvb_usb_cinergyt2_debug;
35int disable_remote;
36
37module_param_named(debug, dvb_usb_cinergyt2_debug, int, 0644);
38MODULE_PARM_DESC(debug, "set debugging level (1=info, xfer=2, rc=4 "
39 "(or-able)).");
40
41DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
42
43struct cinergyt2_state {
44 u8 rc_counter;
45};
46
47/* We are missing a release hook with usb_device data */
48struct dvb_usb_device *cinergyt2_usb_device;
49
50static struct dvb_usb_device_properties cinergyt2_properties;
51
52static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
53{
54 char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
55 char result[64];
56 return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
57 sizeof(result), 0);
58}
59
60static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
61{
62 char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
63 char state[3];
64 return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
65}
66
67static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
68{
69 char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
70 char state[3];
71 int ret;
72
73 adap->fe = cinergyt2_fe_attach(adap->dev);
74
75 ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
76 sizeof(state), 0);
77 if (ret < 0) {
78 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
79 "state info\n");
80 }
81
82 /* Copy this pointer as we are gonna need it in the release phase */
83 cinergyt2_usb_device = adap->dev;
84
85 return 0;
86}
87
88static struct dvb_usb_rc_key cinergyt2_rc_keys[] = {
89 { 0x04, 0x01, KEY_POWER },
90 { 0x04, 0x02, KEY_1 },
91 { 0x04, 0x03, KEY_2 },
92 { 0x04, 0x04, KEY_3 },
93 { 0x04, 0x05, KEY_4 },
94 { 0x04, 0x06, KEY_5 },
95 { 0x04, 0x07, KEY_6 },
96 { 0x04, 0x08, KEY_7 },
97 { 0x04, 0x09, KEY_8 },
98 { 0x04, 0x0a, KEY_9 },
99 { 0x04, 0x0c, KEY_0 },
100 { 0x04, 0x0b, KEY_VIDEO },
101 { 0x04, 0x0d, KEY_REFRESH },
102 { 0x04, 0x0e, KEY_SELECT },
103 { 0x04, 0x0f, KEY_EPG },
104 { 0x04, 0x10, KEY_UP },
105 { 0x04, 0x14, KEY_DOWN },
106 { 0x04, 0x11, KEY_LEFT },
107 { 0x04, 0x13, KEY_RIGHT },
108 { 0x04, 0x12, KEY_OK },
109 { 0x04, 0x15, KEY_TEXT },
110 { 0x04, 0x16, KEY_INFO },
111 { 0x04, 0x17, KEY_RED },
112 { 0x04, 0x18, KEY_GREEN },
113 { 0x04, 0x19, KEY_YELLOW },
114 { 0x04, 0x1a, KEY_BLUE },
115 { 0x04, 0x1c, KEY_VOLUMEUP },
116 { 0x04, 0x1e, KEY_VOLUMEDOWN },
117 { 0x04, 0x1d, KEY_MUTE },
118 { 0x04, 0x1b, KEY_CHANNELUP },
119 { 0x04, 0x1f, KEY_CHANNELDOWN },
120 { 0x04, 0x40, KEY_PAUSE },
121 { 0x04, 0x4c, KEY_PLAY },
122 { 0x04, 0x58, KEY_RECORD },
123 { 0x04, 0x54, KEY_PREVIOUS },
124 { 0x04, 0x48, KEY_STOP },
125 { 0x04, 0x5c, KEY_NEXT }
126};
127
128/* Number of keypresses to ignore before detect repeating */
129#define RC_REPEAT_DELAY 3
130
131static int repeatable_keys[] = {
132 KEY_UP,
133 KEY_DOWN,
134 KEY_LEFT,
135 KEY_RIGHT,
136 KEY_VOLUMEUP,
137 KEY_VOLUMEDOWN,
138 KEY_CHANNELUP,
139 KEY_CHANNELDOWN
140};
141
142static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
143{
144 struct cinergyt2_state *st = d->priv;
145 u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
146 int i;
147
148 *state = REMOTE_NO_KEY_PRESSED;
149
150 dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
151 if (key[4] == 0xff) {
152 /* key repeat */
153 st->rc_counter++;
154 if (st->rc_counter > RC_REPEAT_DELAY) {
155 for (i = 0; i < ARRAY_SIZE(repeatable_keys); i++) {
156 if (d->last_event == repeatable_keys[i]) {
157 *state = REMOTE_KEY_REPEAT;
158 *event = d->last_event;
159 deb_rc("repeat key, event %x\n",
160 *event);
161 return 0;
162 }
163 }
164 deb_rc("repeated key (non repeatable)\n");
165 }
166 return 0;
167 }
168
169 /* hack to pass checksum on the custom field */
170 key[2] = ~key[1];
171 dvb_usb_nec_rc_key_to_event(d, key, event, state);
172 if (key[0] != 0) {
173 if (*event != d->last_event)
174 st->rc_counter = 0;
175
176 deb_rc("key: %x %x %x %x %x\n",
177 key[0], key[1], key[2], key[3], key[4]);
178 }
179 return 0;
180}
181
182static int cinergyt2_usb_probe(struct usb_interface *intf,
183 const struct usb_device_id *id)
184{
185 return dvb_usb_device_init(intf, &cinergyt2_properties,
186 THIS_MODULE, NULL, adapter_nr);
187}
188
189
190static struct usb_device_id cinergyt2_usb_table[] = {
191 { USB_DEVICE(USB_VID_TERRATEC, 0x0038) },
192 { 0 }
193};
194
195MODULE_DEVICE_TABLE(usb, cinergyt2_usb_table);
196
197static struct dvb_usb_device_properties cinergyt2_properties = {
198 .size_of_priv = sizeof(struct cinergyt2_state),
199 .num_adapters = 1,
200 .adapter = {
201 {
202 .streaming_ctrl = cinergyt2_streaming_ctrl,
203 .frontend_attach = cinergyt2_frontend_attach,
204
205 /* parameter for the MPEG2-data transfer */
206 .stream = {
207 .type = USB_BULK,
208 .count = 5,
209 .endpoint = 0x02,
210 .u = {
211 .bulk = {
212 .buffersize = 512,
213 }
214 }
215 },
216 }
217 },
218
219 .power_ctrl = cinergyt2_power_ctrl,
220
221 .rc_interval = 50,
222 .rc_key_map = cinergyt2_rc_keys,
223 .rc_key_map_size = ARRAY_SIZE(cinergyt2_rc_keys),
224 .rc_query = cinergyt2_rc_query,
225
226 .generic_bulk_ctrl_endpoint = 1,
227
228 .num_device_descs = 1,
229 .devices = {
230 { .name = "TerraTec/qanu USB2.0 Highspeed DVB-T Receiver",
231 .cold_ids = {NULL},
232 .warm_ids = { &cinergyt2_usb_table[0], NULL },
233 },
234 { NULL },
235 }
236};
237
238
239static struct usb_driver cinergyt2_driver = {
240 .name = "cinergyT2",
241 .probe = cinergyt2_usb_probe,
242 .disconnect = dvb_usb_device_exit,
243 .id_table = cinergyt2_usb_table
244};
245
246static int __init cinergyt2_usb_init(void)
247{
248 int err;
249
250 err = usb_register(&cinergyt2_driver);
251 if (err) {
252 err("usb_register() failed! (err %i)\n", err);
253 return err;
254 }
255 return 0;
256}
257
258static void __exit cinergyt2_usb_exit(void)
259{
260 usb_deregister(&cinergyt2_driver);
261}
262
263module_init(cinergyt2_usb_init);
264module_exit(cinergyt2_usb_exit);
265
266MODULE_DESCRIPTION("Terratec Cinergy T2 DVB-T driver");
267MODULE_LICENSE("GPL");
268MODULE_AUTHOR("Tomi Orava");
diff --git a/drivers/media/dvb/dvb-usb/cinergyT2-fe.c b/drivers/media/dvb/dvb-usb/cinergyT2-fe.c
new file mode 100644
index 000000000000..649f25cca49e
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/cinergyT2-fe.c
@@ -0,0 +1,351 @@
1/*
2 * TerraTec Cinergy T2/qanu USB2 DVB-T adapter.
3 *
4 * Copyright (C) 2007 Tomi Orava (tomimo@ncircle.nullnet.fi)
5 *
6 * Based on the dvb-usb-framework code and the
7 * original Terratec Cinergy T2 driver by:
8 *
9 * Copyright (C) 2004 Daniel Mack <daniel@qanu.de> and
10 * Holger Waechtler <holger@qanu.de>
11 *
12 * Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 *
28 */
29
30#include "cinergyT2.h"
31
32
33/**
34 * convert linux-dvb frontend parameter set into TPS.
35 * See ETSI ETS-300744, section 4.6.2, table 9 for details.
36 *
37 * This function is probably reusable and may better get placed in a support
38 * library.
39 *
40 * We replace errornous fields by default TPS fields (the ones with value 0).
41 */
42
43static uint16_t compute_tps(struct dvb_frontend_parameters *p)
44{
45 struct dvb_ofdm_parameters *op = &p->u.ofdm;
46 uint16_t tps = 0;
47
48 switch (op->code_rate_HP) {
49 case FEC_2_3:
50 tps |= (1 << 7);
51 break;
52 case FEC_3_4:
53 tps |= (2 << 7);
54 break;
55 case FEC_5_6:
56 tps |= (3 << 7);
57 break;
58 case FEC_7_8:
59 tps |= (4 << 7);
60 break;
61 case FEC_1_2:
62 case FEC_AUTO:
63 default:
64 /* tps |= (0 << 7) */;
65 }
66
67 switch (op->code_rate_LP) {
68 case FEC_2_3:
69 tps |= (1 << 4);
70 break;
71 case FEC_3_4:
72 tps |= (2 << 4);
73 break;
74 case FEC_5_6:
75 tps |= (3 << 4);
76 break;
77 case FEC_7_8:
78 tps |= (4 << 4);
79 break;
80 case FEC_1_2:
81 case FEC_AUTO:
82 default:
83 /* tps |= (0 << 4) */;
84 }
85
86 switch (op->constellation) {
87 case QAM_16:
88 tps |= (1 << 13);
89 break;
90 case QAM_64:
91 tps |= (2 << 13);
92 break;
93 case QPSK:
94 default:
95 /* tps |= (0 << 13) */;
96 }
97
98 switch (op->transmission_mode) {
99 case TRANSMISSION_MODE_8K:
100 tps |= (1 << 0);
101 break;
102 case TRANSMISSION_MODE_2K:
103 default:
104 /* tps |= (0 << 0) */;
105 }
106
107 switch (op->guard_interval) {
108 case GUARD_INTERVAL_1_16:
109 tps |= (1 << 2);
110 break;
111 case GUARD_INTERVAL_1_8:
112 tps |= (2 << 2);
113 break;
114 case GUARD_INTERVAL_1_4:
115 tps |= (3 << 2);
116 break;
117 case GUARD_INTERVAL_1_32:
118 default:
119 /* tps |= (0 << 2) */;
120 }
121
122 switch (op->hierarchy_information) {
123 case HIERARCHY_1:
124 tps |= (1 << 10);
125 break;
126 case HIERARCHY_2:
127 tps |= (2 << 10);
128 break;
129 case HIERARCHY_4:
130 tps |= (3 << 10);
131 break;
132 case HIERARCHY_NONE:
133 default:
134 /* tps |= (0 << 10) */;
135 }
136
137 return tps;
138}
139
140struct cinergyt2_fe_state {
141 struct dvb_frontend fe;
142 struct dvb_usb_device *d;
143};
144
145static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
146 fe_status_t *status)
147{
148 struct cinergyt2_fe_state *state = fe->demodulator_priv;
149 struct dvbt_get_status_msg result;
150 u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
151 int ret;
152
153 ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
154 sizeof(result), 0);
155 if (ret < 0)
156 return ret;
157
158 *status = 0;
159
160 if (0xffff - le16_to_cpu(result.gain) > 30)
161 *status |= FE_HAS_SIGNAL;
162 if (result.lock_bits & (1 << 6))
163 *status |= FE_HAS_LOCK;
164 if (result.lock_bits & (1 << 5))
165 *status |= FE_HAS_SYNC;
166 if (result.lock_bits & (1 << 4))
167 *status |= FE_HAS_CARRIER;
168 if (result.lock_bits & (1 << 1))
169 *status |= FE_HAS_VITERBI;
170
171 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
172 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
173 *status &= ~FE_HAS_LOCK;
174
175 return 0;
176}
177
178static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
179{
180 struct cinergyt2_fe_state *state = fe->demodulator_priv;
181 struct dvbt_get_status_msg status;
182 char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
183 int ret;
184
185 ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
186 sizeof(status), 0);
187 if (ret < 0)
188 return ret;
189
190 *ber = le32_to_cpu(status.viterbi_error_rate);
191 return 0;
192}
193
194static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
195{
196 struct cinergyt2_fe_state *state = fe->demodulator_priv;
197 struct dvbt_get_status_msg status;
198 u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
199 int ret;
200
201 ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
202 sizeof(status), 0);
203 if (ret < 0) {
204 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
205 ret);
206 return ret;
207 }
208 *unc = le32_to_cpu(status.uncorrected_block_count);
209 return 0;
210}
211
212static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
213 u16 *strength)
214{
215 struct cinergyt2_fe_state *state = fe->demodulator_priv;
216 struct dvbt_get_status_msg status;
217 char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
218 int ret;
219
220 ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
221 sizeof(status), 0);
222 if (ret < 0) {
223 err("cinergyt2_fe_read_signal_strength() Failed!"
224 " (Error=%d)\n", ret);
225 return ret;
226 }
227 *strength = (0xffff - le16_to_cpu(status.gain));
228 return 0;
229}
230
231static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
232{
233 struct cinergyt2_fe_state *state = fe->demodulator_priv;
234 struct dvbt_get_status_msg status;
235 char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
236 int ret;
237
238 ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
239 sizeof(status), 0);
240 if (ret < 0) {
241 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
242 return ret;
243 }
244 *snr = (status.snr << 8) | status.snr;
245 return 0;
246}
247
248static int cinergyt2_fe_init(struct dvb_frontend *fe)
249{
250 return 0;
251}
252
253static int cinergyt2_fe_sleep(struct dvb_frontend *fe)
254{
255 deb_info("cinergyt2_fe_sleep() Called\n");
256 return 0;
257}
258
259static int cinergyt2_fe_get_tune_settings(struct dvb_frontend *fe,
260 struct dvb_frontend_tune_settings *tune)
261{
262 tune->min_delay_ms = 800;
263 return 0;
264}
265
266static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe,
267 struct dvb_frontend_parameters *fep)
268{
269 struct cinergyt2_fe_state *state = fe->demodulator_priv;
270 struct dvbt_set_parameters_msg param;
271 char result[2];
272 int err;
273
274 param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
275 param.tps = cpu_to_le16(compute_tps(fep));
276 param.freq = cpu_to_le32(fep->frequency / 1000);
277 param.bandwidth = 8 - fep->u.ofdm.bandwidth - BANDWIDTH_8_MHZ;
278
279 err = dvb_usb_generic_rw(state->d,
280 (char *)&param, sizeof(param),
281 result, sizeof(result), 0);
282 if (err < 0)
283 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
284
285 return (err < 0) ? err : 0;
286}
287
288static int cinergyt2_fe_get_frontend(struct dvb_frontend *fe,
289 struct dvb_frontend_parameters *fep)
290{
291 return 0;
292}
293
294static void cinergyt2_fe_release(struct dvb_frontend *fe)
295{
296 struct cinergyt2_fe_state *state = fe->demodulator_priv;
297 if (state != NULL)
298 kfree(state);
299}
300
301static struct dvb_frontend_ops cinergyt2_fe_ops;
302
303struct dvb_frontend *cinergyt2_fe_attach(struct dvb_usb_device *d)
304{
305 struct cinergyt2_fe_state *s = kzalloc(sizeof(
306 struct cinergyt2_fe_state), GFP_KERNEL);
307 if (s == NULL)
308 return NULL;
309
310 s->d = d;
311 memcpy(&s->fe.ops, &cinergyt2_fe_ops, sizeof(struct dvb_frontend_ops));
312 s->fe.demodulator_priv = s;
313 return &s->fe;
314}
315
316
317static struct dvb_frontend_ops cinergyt2_fe_ops = {
318 .info = {
319 .name = DRIVER_NAME,
320 .type = FE_OFDM,
321 .frequency_min = 174000000,
322 .frequency_max = 862000000,
323 .frequency_stepsize = 166667,
324 .caps = FE_CAN_INVERSION_AUTO | FE_CAN_FEC_1_2
325 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4
326 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8
327 | FE_CAN_FEC_AUTO | FE_CAN_QPSK
328 | FE_CAN_QAM_16 | FE_CAN_QAM_64
329 | FE_CAN_QAM_AUTO
330 | FE_CAN_TRANSMISSION_MODE_AUTO
331 | FE_CAN_GUARD_INTERVAL_AUTO
332 | FE_CAN_HIERARCHY_AUTO
333 | FE_CAN_RECOVER
334 | FE_CAN_MUTE_TS
335 },
336
337 .release = cinergyt2_fe_release,
338
339 .init = cinergyt2_fe_init,
340 .sleep = cinergyt2_fe_sleep,
341
342 .set_frontend = cinergyt2_fe_set_frontend,
343 .get_frontend = cinergyt2_fe_get_frontend,
344 .get_tune_settings = cinergyt2_fe_get_tune_settings,
345
346 .read_status = cinergyt2_fe_read_status,
347 .read_ber = cinergyt2_fe_read_ber,
348 .read_signal_strength = cinergyt2_fe_read_signal_strength,
349 .read_snr = cinergyt2_fe_read_snr,
350 .read_ucblocks = cinergyt2_fe_read_unc_blocks,
351};
diff --git a/drivers/media/dvb/dvb-usb/cinergyT2.h b/drivers/media/dvb/dvb-usb/cinergyT2.h
new file mode 100644
index 000000000000..11d79eb384c8
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/cinergyT2.h
@@ -0,0 +1,95 @@
1/*
2 * TerraTec Cinergy T2/qanu USB2 DVB-T adapter.
3 *
4 * Copyright (C) 2007 Tomi Orava (tomimo@ncircle.nullnet.fi)
5 *
6 * Based on the dvb-usb-framework code and the
7 * original Terratec Cinergy T2 driver by:
8 *
9 * Copyright (C) 2004 Daniel Mack <daniel@qanu.de> and
10 * Holger Waechtler <holger@qanu.de>
11 *
12 * Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 *
28 */
29
30#ifndef _DVB_USB_CINERGYT2_H_
31#define _DVB_USB_CINERGYT2_H_
32
33#include <linux/usb/input.h>
34
35#define DVB_USB_LOG_PREFIX "cinergyT2"
36#include "dvb-usb.h"
37
38#define DRIVER_NAME "TerraTec/qanu USB2.0 Highspeed DVB-T Receiver"
39
40extern int dvb_usb_cinergyt2_debug;
41
42#define deb_info(args...) dprintk(dvb_usb_cinergyt2_debug, 0x001, args)
43#define deb_xfer(args...) dprintk(dvb_usb_cinergyt2_debug, 0x002, args)
44#define deb_pll(args...) dprintk(dvb_usb_cinergyt2_debug, 0x004, args)
45#define deb_ts(args...) dprintk(dvb_usb_cinergyt2_debug, 0x008, args)
46#define deb_err(args...) dprintk(dvb_usb_cinergyt2_debug, 0x010, args)
47#define deb_rc(args...) dprintk(dvb_usb_cinergyt2_debug, 0x020, args)
48#define deb_fw(args...) dprintk(dvb_usb_cinergyt2_debug, 0x040, args)
49#define deb_mem(args...) dprintk(dvb_usb_cinergyt2_debug, 0x080, args)
50#define deb_uxfer(args...) dprintk(dvb_usb_cinergyt2_debug, 0x100, args)
51
52
53
54enum cinergyt2_ep1_cmd {
55 CINERGYT2_EP1_PID_TABLE_RESET = 0x01,
56 CINERGYT2_EP1_PID_SETUP = 0x02,
57 CINERGYT2_EP1_CONTROL_STREAM_TRANSFER = 0x03,
58 CINERGYT2_EP1_SET_TUNER_PARAMETERS = 0x04,
59 CINERGYT2_EP1_GET_TUNER_STATUS = 0x05,
60 CINERGYT2_EP1_START_SCAN = 0x06,
61 CINERGYT2_EP1_CONTINUE_SCAN = 0x07,
62 CINERGYT2_EP1_GET_RC_EVENTS = 0x08,
63 CINERGYT2_EP1_SLEEP_MODE = 0x09,
64 CINERGYT2_EP1_GET_FIRMWARE_VERSION = 0x0A
65};
66
67
68struct dvbt_get_status_msg {
69 uint32_t freq;
70 uint8_t bandwidth;
71 uint16_t tps;
72 uint8_t flags;
73 uint16_t gain;
74 uint8_t snr;
75 uint32_t viterbi_error_rate;
76 uint32_t rs_error_rate;
77 uint32_t uncorrected_block_count;
78 uint8_t lock_bits;
79 uint8_t prev_lock_bits;
80} __attribute__((packed));
81
82
83struct dvbt_set_parameters_msg {
84 uint8_t cmd;
85 uint32_t freq;
86 uint8_t bandwidth;
87 uint16_t tps;
88 uint8_t flags;
89} __attribute__((packed));
90
91
92extern struct dvb_frontend *cinergyt2_fe_attach(struct dvb_usb_device *d);
93
94#endif /* _DVB_USB_CINERGYT2_H_ */
95
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
index 563400277a42..406d7fba369d 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.c
+++ b/drivers/media/dvb/dvb-usb/cxusb.c
@@ -36,6 +36,9 @@
36#include "tuner-xc2028.h" 36#include "tuner-xc2028.h"
37#include "tuner-simple.h" 37#include "tuner-simple.h"
38#include "mxl5005s.h" 38#include "mxl5005s.h"
39#include "dib7000p.h"
40#include "dib0070.h"
41#include "lgs8gl5.h"
39 42
40/* debug */ 43/* debug */
41static int dvb_usb_cxusb_debug; 44static int dvb_usb_cxusb_debug;
@@ -109,6 +112,25 @@ static void cxusb_nano2_led(struct dvb_usb_device *d, int onoff)
109 cxusb_bluebird_gpio_rw(d, 0x40, onoff ? 0 : 0x40); 112 cxusb_bluebird_gpio_rw(d, 0x40, onoff ? 0 : 0x40);
110} 113}
111 114
115static int cxusb_d680_dmb_gpio_tuner(struct dvb_usb_device *d,
116 u8 addr, int onoff)
117{
118 u8 o[2] = {addr, onoff};
119 u8 i;
120 int rc;
121
122 rc = cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);
123
124 if (rc < 0)
125 return rc;
126 if (i == 0x01)
127 return 0;
128 else {
129 deb_info("gpio_write failed.\n");
130 return -EIO;
131 }
132}
133
112/* I2C */ 134/* I2C */
113static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], 135static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
114 int num) 136 int num)
@@ -262,6 +284,20 @@ static int cxusb_nano2_power_ctrl(struct dvb_usb_device *d, int onoff)
262 return rc; 284 return rc;
263} 285}
264 286
287static int cxusb_d680_dmb_power_ctrl(struct dvb_usb_device *d, int onoff)
288{
289 int ret;
290 u8 b;
291 ret = cxusb_power_ctrl(d, onoff);
292 if (!onoff)
293 return ret;
294
295 msleep(128);
296 cxusb_ctrl_msg(d, CMD_DIGITAL, NULL, 0, &b, 1);
297 msleep(100);
298 return ret;
299}
300
265static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff) 301static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
266{ 302{
267 u8 buf[2] = { 0x03, 0x00 }; 303 u8 buf[2] = { 0x03, 0x00 };
@@ -283,6 +319,67 @@ static int cxusb_aver_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
283 return 0; 319 return 0;
284} 320}
285 321
322static void cxusb_d680_dmb_drain_message(struct dvb_usb_device *d)
323{
324 int ep = d->props.generic_bulk_ctrl_endpoint;
325 const int timeout = 100;
326 const int junk_len = 32;
327 u8 *junk;
328 int rd_count;
329
330 /* Discard remaining data in video pipe */
331 junk = kmalloc(junk_len, GFP_KERNEL);
332 if (!junk)
333 return;
334 while (1) {
335 if (usb_bulk_msg(d->udev,
336 usb_rcvbulkpipe(d->udev, ep),
337 junk, junk_len, &rd_count, timeout) < 0)
338 break;
339 if (!rd_count)
340 break;
341 }
342 kfree(junk);
343}
344
345static void cxusb_d680_dmb_drain_video(struct dvb_usb_device *d)
346{
347 struct usb_data_stream_properties *p = &d->props.adapter[0].stream;
348 const int timeout = 100;
349 const int junk_len = p->u.bulk.buffersize;
350 u8 *junk;
351 int rd_count;
352
353 /* Discard remaining data in video pipe */
354 junk = kmalloc(junk_len, GFP_KERNEL);
355 if (!junk)
356 return;
357 while (1) {
358 if (usb_bulk_msg(d->udev,
359 usb_rcvbulkpipe(d->udev, p->endpoint),
360 junk, junk_len, &rd_count, timeout) < 0)
361 break;
362 if (!rd_count)
363 break;
364 }
365 kfree(junk);
366}
367
368static int cxusb_d680_dmb_streaming_ctrl(
369 struct dvb_usb_adapter *adap, int onoff)
370{
371 if (onoff) {
372 u8 buf[2] = { 0x03, 0x00 };
373 cxusb_d680_dmb_drain_video(adap->dev);
374 return cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON,
375 buf, sizeof(buf), NULL, 0);
376 } else {
377 int ret = cxusb_ctrl_msg(adap->dev,
378 CMD_STREAMING_OFF, NULL, 0, NULL, 0);
379 return ret;
380 }
381}
382
286static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 383static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
287{ 384{
288 struct dvb_usb_rc_key *keymap = d->props.rc_key_map; 385 struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
@@ -335,6 +432,32 @@ static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d, u32 *event,
335 return 0; 432 return 0;
336} 433}
337 434
435static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d, u32 *event,
436 int *state)
437{
438 struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
439 u8 ircode[2];
440 int i;
441
442 *event = 0;
443 *state = REMOTE_NO_KEY_PRESSED;
444
445 if (cxusb_ctrl_msg(d, 0x10, NULL, 0, ircode, 2) < 0)
446 return 0;
447
448 for (i = 0; i < d->props.rc_key_map_size; i++) {
449 if (keymap[i].custom == ircode[0] &&
450 keymap[i].data == ircode[1]) {
451 *event = keymap[i].event;
452 *state = REMOTE_KEY_PRESSED;
453
454 return 0;
455 }
456 }
457
458 return 0;
459}
460
338static struct dvb_usb_rc_key dvico_mce_rc_keys[] = { 461static struct dvb_usb_rc_key dvico_mce_rc_keys[] = {
339 { 0xfe, 0x02, KEY_TV }, 462 { 0xfe, 0x02, KEY_TV },
340 { 0xfe, 0x0e, KEY_MP3 }, 463 { 0xfe, 0x0e, KEY_MP3 },
@@ -422,6 +545,44 @@ static struct dvb_usb_rc_key dvico_portable_rc_keys[] = {
422 { 0xfc, 0x00, KEY_UNKNOWN }, /* HD */ 545 { 0xfc, 0x00, KEY_UNKNOWN }, /* HD */
423}; 546};
424 547
548static struct dvb_usb_rc_key d680_dmb_rc_keys[] = {
549 { 0x00, 0x38, KEY_UNKNOWN }, /* TV/AV */
550 { 0x08, 0x0c, KEY_ZOOM },
551 { 0x08, 0x00, KEY_0 },
552 { 0x00, 0x01, KEY_1 },
553 { 0x08, 0x02, KEY_2 },
554 { 0x00, 0x03, KEY_3 },
555 { 0x08, 0x04, KEY_4 },
556 { 0x00, 0x05, KEY_5 },
557 { 0x08, 0x06, KEY_6 },
558 { 0x00, 0x07, KEY_7 },
559 { 0x08, 0x08, KEY_8 },
560 { 0x00, 0x09, KEY_9 },
561 { 0x00, 0x0a, KEY_MUTE },
562 { 0x08, 0x29, KEY_BACK },
563 { 0x00, 0x12, KEY_CHANNELUP },
564 { 0x08, 0x13, KEY_CHANNELDOWN },
565 { 0x00, 0x2b, KEY_VOLUMEUP },
566 { 0x08, 0x2c, KEY_VOLUMEDOWN },
567 { 0x00, 0x20, KEY_UP },
568 { 0x08, 0x21, KEY_DOWN },
569 { 0x00, 0x11, KEY_LEFT },
570 { 0x08, 0x10, KEY_RIGHT },
571 { 0x00, 0x0d, KEY_OK },
572 { 0x08, 0x1f, KEY_RECORD },
573 { 0x00, 0x17, KEY_PLAYPAUSE },
574 { 0x08, 0x16, KEY_PLAYPAUSE },
575 { 0x00, 0x0b, KEY_STOP },
576 { 0x08, 0x27, KEY_FASTFORWARD },
577 { 0x00, 0x26, KEY_REWIND },
578 { 0x08, 0x1e, KEY_UNKNOWN }, /* Time Shift */
579 { 0x00, 0x0e, KEY_UNKNOWN }, /* Snapshot */
580 { 0x08, 0x2d, KEY_UNKNOWN }, /* Mouse Cursor */
581 { 0x00, 0x0f, KEY_UNKNOWN }, /* Minimize/Maximize */
582 { 0x08, 0x14, KEY_UNKNOWN }, /* Shuffle */
583 { 0x00, 0x25, KEY_POWER },
584};
585
425static int cxusb_dee1601_demod_init(struct dvb_frontend* fe) 586static int cxusb_dee1601_demod_init(struct dvb_frontend* fe)
426{ 587{
427 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x28 }; 588 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x28 };
@@ -527,6 +688,24 @@ static struct mxl5005s_config aver_a868r_tuner = {
527 .AgcMasterByte = 0x00, 688 .AgcMasterByte = 0x00,
528}; 689};
529 690
691/* FIXME: needs tweaking */
692static struct mxl5005s_config d680_dmb_tuner = {
693 .i2c_address = 0x63,
694 .if_freq = 36125000UL,
695 .xtal_freq = CRYSTAL_FREQ_16000000HZ,
696 .agc_mode = MXL_SINGLE_AGC,
697 .tracking_filter = MXL_TF_C,
698 .rssi_enable = MXL_RSSI_ENABLE,
699 .cap_select = MXL_CAP_SEL_ENABLE,
700 .div_out = MXL_DIV_OUT_4,
701 .clock_out = MXL_CLOCK_OUT_DISABLE,
702 .output_load = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
703 .top = MXL5005S_TOP_25P2,
704 .mod_mode = MXL_DIGITAL_MODE,
705 .if_mode = MXL_ZERO_IF,
706 .AgcMasterByte = 0x00,
707};
708
530/* Callbacks for DVB USB */ 709/* Callbacks for DVB USB */
531static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap) 710static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
532{ 711{
@@ -563,7 +742,8 @@ static int cxusb_lgh064f_tuner_attach(struct dvb_usb_adapter *adap)
563 return 0; 742 return 0;
564} 743}
565 744
566static int dvico_bluebird_xc2028_callback(void *ptr, int command, int arg) 745static int dvico_bluebird_xc2028_callback(void *ptr, int component,
746 int command, int arg)
567{ 747{
568 struct dvb_usb_adapter *adap = ptr; 748 struct dvb_usb_adapter *adap = ptr;
569 struct dvb_usb_device *d = adap->dev; 749 struct dvb_usb_device *d = adap->dev;
@@ -591,14 +771,16 @@ static int cxusb_dvico_xc3028_tuner_attach(struct dvb_usb_adapter *adap)
591 struct xc2028_config cfg = { 771 struct xc2028_config cfg = {
592 .i2c_adap = &adap->dev->i2c_adap, 772 .i2c_adap = &adap->dev->i2c_adap,
593 .i2c_addr = 0x61, 773 .i2c_addr = 0x61,
594 .callback = dvico_bluebird_xc2028_callback,
595 }; 774 };
596 static struct xc2028_ctrl ctl = { 775 static struct xc2028_ctrl ctl = {
597 .fname = "xc3028-v27.fw", 776 .fname = XC2028_DEFAULT_FIRMWARE,
598 .max_len = 64, 777 .max_len = 64,
599 .demod = XC3028_FE_ZARLINK456, 778 .demod = XC3028_FE_ZARLINK456,
600 }; 779 };
601 780
781 /* FIXME: generalize & move to common area */
782 adap->fe->callback = dvico_bluebird_xc2028_callback;
783
602 fe = dvb_attach(xc2028_attach, adap->fe, &cfg); 784 fe = dvb_attach(xc2028_attach, adap->fe, &cfg);
603 if (fe == NULL || fe->ops.tuner_ops.set_config == NULL) 785 if (fe == NULL || fe->ops.tuner_ops.set_config == NULL)
604 return -EIO; 786 return -EIO;
@@ -615,6 +797,14 @@ static int cxusb_mxl5003s_tuner_attach(struct dvb_usb_adapter *adap)
615 return 0; 797 return 0;
616} 798}
617 799
800static int cxusb_d680_dmb_tuner_attach(struct dvb_usb_adapter *adap)
801{
802 struct dvb_frontend *fe;
803 fe = dvb_attach(mxl5005s_attach, adap->fe,
804 &adap->dev->i2c_adap, &d680_dmb_tuner);
805 return (fe == NULL) ? -EIO : 0;
806}
807
618static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap) 808static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap)
619{ 809{
620 u8 b; 810 u8 b;
@@ -726,6 +916,159 @@ no_IR:
726 return 0; 916 return 0;
727} 917}
728 918
919static struct dibx000_agc_config dib7070_agc_config = {
920 .band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
921
922 /*
923 * P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5,
924 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
925 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0
926 */
927 .setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) |
928 (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
929 .inv_gain = 600,
930 .time_stabiliz = 10,
931 .alpha_level = 0,
932 .thlock = 118,
933 .wbd_inv = 0,
934 .wbd_ref = 3530,
935 .wbd_sel = 1,
936 .wbd_alpha = 5,
937 .agc1_max = 65535,
938 .agc1_min = 0,
939 .agc2_max = 65535,
940 .agc2_min = 0,
941 .agc1_pt1 = 0,
942 .agc1_pt2 = 40,
943 .agc1_pt3 = 183,
944 .agc1_slope1 = 206,
945 .agc1_slope2 = 255,
946 .agc2_pt1 = 72,
947 .agc2_pt2 = 152,
948 .agc2_slope1 = 88,
949 .agc2_slope2 = 90,
950 .alpha_mant = 17,
951 .alpha_exp = 27,
952 .beta_mant = 23,
953 .beta_exp = 51,
954 .perform_agc_softsplit = 0,
955};
956
957static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
958 .internal = 60000,
959 .sampling = 15000,
960 .pll_prediv = 1,
961 .pll_ratio = 20,
962 .pll_range = 3,
963 .pll_reset = 1,
964 .pll_bypass = 0,
965 .enable_refdiv = 0,
966 .bypclk_div = 0,
967 .IO_CLK_en_core = 1,
968 .ADClkSrc = 1,
969 .modulo = 2,
970 /* refsel, sel, freq_15k */
971 .sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
972 .ifreq = (0 << 25) | 0,
973 .timf = 20452225,
974 .xtal_hz = 12000000,
975};
976
977static struct dib7000p_config cxusb_dualdig4_rev2_config = {
978 .output_mode = OUTMODE_MPEG2_PAR_GATED_CLK,
979 .output_mpeg2_in_188_bytes = 1,
980
981 .agc_config_count = 1,
982 .agc = &dib7070_agc_config,
983 .bw = &dib7070_bw_config_12_mhz,
984 .tuner_is_baseband = 1,
985 .spur_protect = 1,
986
987 .gpio_dir = 0xfcef,
988 .gpio_val = 0x0110,
989
990 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
991
992 .hostbus_diversity = 1,
993};
994
995static int cxusb_dualdig4_rev2_frontend_attach(struct dvb_usb_adapter *adap)
996{
997 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
998 err("set interface failed");
999
1000 cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
1001
1002 cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
1003
1004 dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1005 &cxusb_dualdig4_rev2_config);
1006
1007 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
1008 &cxusb_dualdig4_rev2_config);
1009 if (adap->fe == NULL)
1010 return -EIO;
1011
1012 return 0;
1013}
1014
1015static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
1016{
1017 return dib7000p_set_gpio(fe, 8, 0, !onoff);
1018}
1019
1020static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
1021{
1022 return 0;
1023}
1024
1025static struct dib0070_config dib7070p_dib0070_config = {
1026 .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
1027 .reset = dib7070_tuner_reset,
1028 .sleep = dib7070_tuner_sleep,
1029 .clock_khz = 12000,
1030};
1031
1032struct dib0700_adapter_state {
1033 int (*set_param_save) (struct dvb_frontend *,
1034 struct dvb_frontend_parameters *);
1035};
1036
1037static int dib7070_set_param_override(struct dvb_frontend *fe,
1038 struct dvb_frontend_parameters *fep)
1039{
1040 struct dvb_usb_adapter *adap = fe->dvb->priv;
1041 struct dib0700_adapter_state *state = adap->priv;
1042
1043 u16 offset;
1044 u8 band = BAND_OF_FREQUENCY(fep->frequency/1000);
1045 switch (band) {
1046 case BAND_VHF: offset = 950; break;
1047 default:
1048 case BAND_UHF: offset = 550; break;
1049 }
1050
1051 dib7000p_set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
1052
1053 return state->set_param_save(fe, fep);
1054}
1055
1056static int cxusb_dualdig4_rev2_tuner_attach(struct dvb_usb_adapter *adap)
1057{
1058 struct dib0700_adapter_state *st = adap->priv;
1059 struct i2c_adapter *tun_i2c =
1060 dib7000p_get_i2c_master(adap->fe,
1061 DIBX000_I2C_INTERFACE_TUNER, 1);
1062
1063 if (dvb_attach(dib0070_attach, adap->fe, tun_i2c,
1064 &dib7070p_dib0070_config) == NULL)
1065 return -ENODEV;
1066
1067 st->set_param_save = adap->fe->ops.tuner_ops.set_params;
1068 adap->fe->ops.tuner_ops.set_params = dib7070_set_param_override;
1069 return 0;
1070}
1071
729static int cxusb_nano2_frontend_attach(struct dvb_usb_adapter *adap) 1072static int cxusb_nano2_frontend_attach(struct dvb_usb_adapter *adap)
730{ 1073{
731 if (usb_set_interface(adap->dev->udev, 0, 1) < 0) 1074 if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
@@ -751,6 +1094,54 @@ static int cxusb_nano2_frontend_attach(struct dvb_usb_adapter *adap)
751 return -EIO; 1094 return -EIO;
752} 1095}
753 1096
1097static struct lgs8gl5_config lgs8gl5_cfg = {
1098 .demod_address = 0x19,
1099};
1100
1101static int cxusb_d680_dmb_frontend_attach(struct dvb_usb_adapter *adap)
1102{
1103 struct dvb_usb_device *d = adap->dev;
1104 int n;
1105
1106 /* Select required USB configuration */
1107 if (usb_set_interface(d->udev, 0, 0) < 0)
1108 err("set interface failed");
1109
1110 /* Unblock all USB pipes */
1111 usb_clear_halt(d->udev,
1112 usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
1113 usb_clear_halt(d->udev,
1114 usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
1115 usb_clear_halt(d->udev,
1116 usb_rcvbulkpipe(d->udev, d->props.adapter[0].stream.endpoint));
1117
1118 /* Drain USB pipes to avoid hang after reboot */
1119 for (n = 0; n < 5; n++) {
1120 cxusb_d680_dmb_drain_message(d);
1121 cxusb_d680_dmb_drain_video(d);
1122 msleep(200);
1123 }
1124
1125 /* Reset the tuner */
1126 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
1127 err("clear tuner gpio failed");
1128 return -EIO;
1129 }
1130 msleep(100);
1131 if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {
1132 err("set tuner gpio failed");
1133 return -EIO;
1134 }
1135 msleep(100);
1136
1137 /* Attach frontend */
1138 adap->fe = dvb_attach(lgs8gl5_attach, &lgs8gl5_cfg, &d->i2c_adap);
1139 if (adap->fe == NULL)
1140 return -EIO;
1141
1142 return 0;
1143}
1144
754/* 1145/*
755 * DViCO has shipped two devices with the same USB ID, but only one of them 1146 * DViCO has shipped two devices with the same USB ID, but only one of them
756 * needs a firmware download. Check the device class details to see if they 1147 * needs a firmware download. Check the device class details to see if they
@@ -826,9 +1217,11 @@ static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties;
826static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties; 1217static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties;
827static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties; 1218static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties;
828static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties; 1219static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties;
1220static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties;
829static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties; 1221static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties;
830static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties; 1222static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties;
831static struct dvb_usb_device_properties cxusb_aver_a868r_properties; 1223static struct dvb_usb_device_properties cxusb_aver_a868r_properties;
1224static struct dvb_usb_device_properties cxusb_d680_dmb_properties;
832 1225
833static int cxusb_probe(struct usb_interface *intf, 1226static int cxusb_probe(struct usb_interface *intf,
834 const struct usb_device_id *id) 1227 const struct usb_device_id *id)
@@ -852,6 +1245,11 @@ static int cxusb_probe(struct usb_interface *intf,
852 THIS_MODULE, NULL, adapter_nr) || 1245 THIS_MODULE, NULL, adapter_nr) ||
853 0 == dvb_usb_device_init(intf, &cxusb_aver_a868r_properties, 1246 0 == dvb_usb_device_init(intf, &cxusb_aver_a868r_properties,
854 THIS_MODULE, NULL, adapter_nr) || 1247 THIS_MODULE, NULL, adapter_nr) ||
1248 0 == dvb_usb_device_init(intf,
1249 &cxusb_bluebird_dualdig4_rev2_properties,
1250 THIS_MODULE, NULL, adapter_nr) ||
1251 0 == dvb_usb_device_init(intf, &cxusb_d680_dmb_properties,
1252 THIS_MODULE, NULL, adapter_nr) ||
855 0) 1253 0)
856 return 0; 1254 return 0;
857 1255
@@ -876,6 +1274,8 @@ static struct usb_device_id cxusb_table [] = {
876 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2) }, 1274 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2) },
877 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM) }, 1275 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM) },
878 { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_A868R) }, 1276 { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_A868R) },
1277 { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4_REV_2) },
1278 { USB_DEVICE(USB_VID_CONEXANT, USB_PID_CONEXANT_D680_DMB) },
879 {} /* Terminating entry */ 1279 {} /* Terminating entry */
880}; 1280};
881MODULE_DEVICE_TABLE (usb, cxusb_table); 1281MODULE_DEVICE_TABLE (usb, cxusb_table);
@@ -1321,6 +1721,104 @@ static struct dvb_usb_device_properties cxusb_aver_a868r_properties = {
1321 } 1721 }
1322}; 1722};
1323 1723
1724static
1725struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties = {
1726 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1727
1728 .usb_ctrl = CYPRESS_FX2,
1729
1730 .size_of_priv = sizeof(struct cxusb_state),
1731
1732 .num_adapters = 1,
1733 .adapter = {
1734 {
1735 .streaming_ctrl = cxusb_streaming_ctrl,
1736 .frontend_attach = cxusb_dualdig4_rev2_frontend_attach,
1737 .tuner_attach = cxusb_dualdig4_rev2_tuner_attach,
1738 .size_of_priv = sizeof(struct dib0700_adapter_state),
1739 /* parameter for the MPEG2-data transfer */
1740 .stream = {
1741 .type = USB_BULK,
1742 .count = 7,
1743 .endpoint = 0x02,
1744 .u = {
1745 .bulk = {
1746 .buffersize = 4096,
1747 }
1748 }
1749 },
1750 },
1751 },
1752
1753 .power_ctrl = cxusb_bluebird_power_ctrl,
1754
1755 .i2c_algo = &cxusb_i2c_algo,
1756
1757 .generic_bulk_ctrl_endpoint = 0x01,
1758
1759 .rc_interval = 100,
1760 .rc_key_map = dvico_mce_rc_keys,
1761 .rc_key_map_size = ARRAY_SIZE(dvico_mce_rc_keys),
1762 .rc_query = cxusb_rc_query,
1763
1764 .num_device_descs = 1,
1765 .devices = {
1766 { "DViCO FusionHDTV DVB-T Dual Digital 4 (rev 2)",
1767 { NULL },
1768 { &cxusb_table[17], NULL },
1769 },
1770 }
1771};
1772
1773static struct dvb_usb_device_properties cxusb_d680_dmb_properties = {
1774 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
1775
1776 .usb_ctrl = CYPRESS_FX2,
1777
1778 .size_of_priv = sizeof(struct cxusb_state),
1779
1780 .num_adapters = 1,
1781 .adapter = {
1782 {
1783 .streaming_ctrl = cxusb_d680_dmb_streaming_ctrl,
1784 .frontend_attach = cxusb_d680_dmb_frontend_attach,
1785 .tuner_attach = cxusb_d680_dmb_tuner_attach,
1786
1787 /* parameter for the MPEG2-data transfer */
1788 .stream = {
1789 .type = USB_BULK,
1790 .count = 5,
1791 .endpoint = 0x02,
1792 .u = {
1793 .bulk = {
1794 .buffersize = 8192,
1795 }
1796 }
1797 },
1798 },
1799 },
1800
1801 .power_ctrl = cxusb_d680_dmb_power_ctrl,
1802
1803 .i2c_algo = &cxusb_i2c_algo,
1804
1805 .generic_bulk_ctrl_endpoint = 0x01,
1806
1807 .rc_interval = 100,
1808 .rc_key_map = d680_dmb_rc_keys,
1809 .rc_key_map_size = ARRAY_SIZE(d680_dmb_rc_keys),
1810 .rc_query = cxusb_d680_dmb_rc_query,
1811
1812 .num_device_descs = 1,
1813 .devices = {
1814 {
1815 "Conexant DMB-TH Stick",
1816 { NULL },
1817 { &cxusb_table[18], NULL },
1818 },
1819 }
1820};
1821
1324static struct usb_driver cxusb_driver = { 1822static struct usb_driver cxusb_driver = {
1325 .name = "dvb_usb_cxusb", 1823 .name = "dvb_usb_cxusb",
1326 .probe = cxusb_probe, 1824 .probe = cxusb_probe,
diff --git a/drivers/media/dvb/dvb-usb/dib0700.h b/drivers/media/dvb/dvb-usb/dib0700.h
index 66d4dc6ba46f..739193943c17 100644
--- a/drivers/media/dvb/dvb-usb/dib0700.h
+++ b/drivers/media/dvb/dvb-usb/dib0700.h
@@ -31,6 +31,8 @@ extern int dvb_usb_dib0700_debug;
31 // 2 Byte: MPEG2 mode: 4MSB(1 = Master Mode, 0 = Slave Mode) 4LSB(Channel 1 = bit0, Channel 2 = bit1) 31 // 2 Byte: MPEG2 mode: 4MSB(1 = Master Mode, 0 = Slave Mode) 4LSB(Channel 1 = bit0, Channel 2 = bit1)
32 // 2 Byte: Analog mode: 4MSB(0 = 625 lines, 1 = 525 lines) 4LSB( " " ) 32 // 2 Byte: Analog mode: 4MSB(0 = 625 lines, 1 = 525 lines) 4LSB( " " )
33#define REQUEST_SET_RC 0x11 33#define REQUEST_SET_RC 0x11
34#define REQUEST_NEW_I2C_READ 0x12
35#define REQUEST_NEW_I2C_WRITE 0x13
34#define REQUEST_GET_VERSION 0x15 36#define REQUEST_GET_VERSION 0x15
35 37
36struct dib0700_state { 38struct dib0700_state {
@@ -39,6 +41,8 @@ struct dib0700_state {
39 u8 rc_toggle; 41 u8 rc_toggle;
40 u8 rc_counter; 42 u8 rc_counter;
41 u8 is_dib7000pc; 43 u8 is_dib7000pc;
44 u8 fw_use_new_i2c_api;
45 u8 disable_streaming_master_mode;
42}; 46};
43 47
44extern int dib0700_set_gpio(struct dvb_usb_device *, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val); 48extern int dib0700_set_gpio(struct dvb_usb_device *, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val);
diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
index 595a04696c87..dd53cee3896d 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_core.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
@@ -82,9 +82,98 @@ int dib0700_set_gpio(struct dvb_usb_device *d, enum dib07x0_gpios gpio, u8 gpio_
82} 82}
83 83
84/* 84/*
85 * I2C master xfer function 85 * I2C master xfer function (supported in 1.20 firmware)
86 */ 86 */
87static int dib0700_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg *msg,int num) 87static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, struct i2c_msg *msg,
88 int num)
89{
90 /* The new i2c firmware messages are more reliable and in particular
91 properly support i2c read calls not preceded by a write */
92
93 struct dvb_usb_device *d = i2c_get_adapdata(adap);
94 uint8_t bus_mode = 1; /* 0=eeprom bus, 1=frontend bus */
95 uint8_t gen_mode = 0; /* 0=master i2c, 1=gpio i2c */
96 uint8_t en_start = 0;
97 uint8_t en_stop = 0;
98 uint8_t buf[255]; /* TBV: malloc ? */
99 int result, i;
100
101 /* Ensure nobody else hits the i2c bus while we're sending our
102 sequence of messages, (such as the remote control thread) */
103 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
104 return -EAGAIN;
105
106 for (i = 0; i < num; i++) {
107 if (i == 0) {
108 /* First message in the transaction */
109 en_start = 1;
110 } else if (!(msg[i].flags & I2C_M_NOSTART)) {
111 /* Device supports repeated-start */
112 en_start = 1;
113 } else {
114 /* Not the first packet and device doesn't support
115 repeated start */
116 en_start = 0;
117 }
118 if (i == (num - 1)) {
119 /* Last message in the transaction */
120 en_stop = 1;
121 }
122
123 if (msg[i].flags & I2C_M_RD) {
124 /* Read request */
125 u16 index, value;
126 uint8_t i2c_dest;
127
128 i2c_dest = (msg[i].addr << 1);
129 value = ((en_start << 7) | (en_stop << 6) |
130 (msg[i].len & 0x3F)) << 8 | i2c_dest;
131 /* I2C ctrl + FE bus; */
132 index = ((gen_mode<<6)&0xC0) | ((bus_mode<<4)&0x30);
133
134 result = usb_control_msg(d->udev,
135 usb_rcvctrlpipe(d->udev, 0),
136 REQUEST_NEW_I2C_READ,
137 USB_TYPE_VENDOR | USB_DIR_IN,
138 value, index, msg[i].buf,
139 msg[i].len,
140 USB_CTRL_GET_TIMEOUT);
141 if (result < 0) {
142 err("i2c read error (status = %d)\n", result);
143 break;
144 }
145 } else {
146 /* Write request */
147 buf[0] = REQUEST_NEW_I2C_WRITE;
148 buf[1] = (msg[i].addr << 1);
149 buf[2] = (en_start << 7) | (en_stop << 6) |
150 (msg[i].len & 0x3F);
151 /* I2C ctrl + FE bus; */
152 buf[3] = ((gen_mode<<6)&0xC0) | ((bus_mode<<4)&0x30);
153 /* The Actual i2c payload */
154 memcpy(&buf[4], msg[i].buf, msg[i].len);
155
156 result = usb_control_msg(d->udev,
157 usb_sndctrlpipe(d->udev, 0),
158 REQUEST_NEW_I2C_WRITE,
159 USB_TYPE_VENDOR | USB_DIR_OUT,
160 0, 0, buf, msg[i].len + 4,
161 USB_CTRL_GET_TIMEOUT);
162 if (result < 0) {
163 err("i2c write error (status = %d)\n", result);
164 break;
165 }
166 }
167 }
168 mutex_unlock(&d->i2c_mutex);
169 return i;
170}
171
172/*
173 * I2C master xfer function (pre-1.20 firmware)
174 */
175static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap,
176 struct i2c_msg *msg, int num)
88{ 177{
89 struct dvb_usb_device *d = i2c_get_adapdata(adap); 178 struct dvb_usb_device *d = i2c_get_adapdata(adap);
90 int i,len; 179 int i,len;
@@ -124,6 +213,21 @@ static int dib0700_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg *msg,int num
124 return i; 213 return i;
125} 214}
126 215
216static int dib0700_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
217 int num)
218{
219 struct dvb_usb_device *d = i2c_get_adapdata(adap);
220 struct dib0700_state *st = d->priv;
221
222 if (st->fw_use_new_i2c_api == 1) {
223 /* User running at least fw 1.20 */
224 return dib0700_i2c_xfer_new(adap, msg, num);
225 } else {
226 /* Use legacy calls */
227 return dib0700_i2c_xfer_legacy(adap, msg, num);
228 }
229}
230
127static u32 dib0700_i2c_func(struct i2c_adapter *adapter) 231static u32 dib0700_i2c_func(struct i2c_adapter *adapter)
128{ 232{
129 return I2C_FUNC_I2C; 233 return I2C_FUNC_I2C;
@@ -246,7 +350,12 @@ int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
246 350
247 b[0] = REQUEST_ENABLE_VIDEO; 351 b[0] = REQUEST_ENABLE_VIDEO;
248 b[1] = (onoff << 4) | 0x00; /* this bit gives a kind of command, rather than enabling something or not */ 352 b[1] = (onoff << 4) | 0x00; /* this bit gives a kind of command, rather than enabling something or not */
249 b[2] = (0x01 << 4); /* Master mode */ 353
354 if (st->disable_streaming_master_mode == 1)
355 b[2] = 0x00;
356 else
357 b[2] = (0x01 << 4); /* Master mode */
358
250 b[3] = 0x00; 359 b[3] = 0x00;
251 360
252 deb_info("modifying (%d) streaming state for %d\n", onoff, adap->id); 361 deb_info("modifying (%d) streaming state for %d\n", onoff, adap->id);
diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
index 6c0e5c5f4362..0cfccc24b190 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
@@ -14,6 +14,8 @@
14#include "mt2060.h" 14#include "mt2060.h"
15#include "mt2266.h" 15#include "mt2266.h"
16#include "tuner-xc2028.h" 16#include "tuner-xc2028.h"
17#include "xc5000.h"
18#include "s5h1411.h"
17#include "dib0070.h" 19#include "dib0070.h"
18 20
19static int force_lna_activation; 21static int force_lna_activation;
@@ -366,7 +368,8 @@ static struct dib7000p_config stk7700ph_dib7700_xc3028_config = {
366 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS, 368 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
367}; 369};
368 370
369static int stk7700ph_xc3028_callback(void *ptr, int command, int arg) 371static int stk7700ph_xc3028_callback(void *ptr, int component,
372 int command, int arg)
370{ 373{
371 struct dvb_usb_adapter *adap = ptr; 374 struct dvb_usb_adapter *adap = ptr;
372 375
@@ -394,7 +397,6 @@ static struct xc2028_ctrl stk7700ph_xc3028_ctrl = {
394 397
395static struct xc2028_config stk7700ph_xc3028_config = { 398static struct xc2028_config stk7700ph_xc3028_config = {
396 .i2c_addr = 0x61, 399 .i2c_addr = 0x61,
397 .callback = stk7700ph_xc3028_callback,
398 .ctrl = &stk7700ph_xc3028_ctrl, 400 .ctrl = &stk7700ph_xc3028_ctrl,
399}; 401};
400 402
@@ -435,7 +437,9 @@ static int stk7700ph_tuner_attach(struct dvb_usb_adapter *adap)
435 DIBX000_I2C_INTERFACE_TUNER, 1); 437 DIBX000_I2C_INTERFACE_TUNER, 1);
436 438
437 stk7700ph_xc3028_config.i2c_adap = tun_i2c; 439 stk7700ph_xc3028_config.i2c_adap = tun_i2c;
438 stk7700ph_xc3028_config.video_dev = adap; 440
441 /* FIXME: generalize & move to common area */
442 adap->fe->callback = stk7700ph_xc3028_callback;
439 443
440 return dvb_attach(xc2028_attach, adap->fe, &stk7700ph_xc3028_config) 444 return dvb_attach(xc2028_attach, adap->fe, &stk7700ph_xc3028_config)
441 == NULL ? -ENODEV : 0; 445 == NULL ? -ENODEV : 0;
@@ -677,6 +681,43 @@ static struct dvb_usb_rc_key dib0700_rc_keys[] = {
677 { 0x01, 0x7d, KEY_VOLUMEDOWN }, 681 { 0x01, 0x7d, KEY_VOLUMEDOWN },
678 { 0x02, 0x42, KEY_CHANNELUP }, 682 { 0x02, 0x42, KEY_CHANNELUP },
679 { 0x00, 0x7d, KEY_CHANNELDOWN }, 683 { 0x00, 0x7d, KEY_CHANNELDOWN },
684
685 /* Key codes for Nova-TD "credit card" remote control. */
686 { 0x1d, 0x00, KEY_0 },
687 { 0x1d, 0x01, KEY_1 },
688 { 0x1d, 0x02, KEY_2 },
689 { 0x1d, 0x03, KEY_3 },
690 { 0x1d, 0x04, KEY_4 },
691 { 0x1d, 0x05, KEY_5 },
692 { 0x1d, 0x06, KEY_6 },
693 { 0x1d, 0x07, KEY_7 },
694 { 0x1d, 0x08, KEY_8 },
695 { 0x1d, 0x09, KEY_9 },
696 { 0x1d, 0x0a, KEY_TEXT },
697 { 0x1d, 0x0d, KEY_MENU },
698 { 0x1d, 0x0f, KEY_MUTE },
699 { 0x1d, 0x10, KEY_VOLUMEUP },
700 { 0x1d, 0x11, KEY_VOLUMEDOWN },
701 { 0x1d, 0x12, KEY_CHANNEL },
702 { 0x1d, 0x14, KEY_UP },
703 { 0x1d, 0x15, KEY_DOWN },
704 { 0x1d, 0x16, KEY_LEFT },
705 { 0x1d, 0x17, KEY_RIGHT },
706 { 0x1d, 0x1c, KEY_TV },
707 { 0x1d, 0x1e, KEY_NEXT },
708 { 0x1d, 0x1f, KEY_BACK },
709 { 0x1d, 0x20, KEY_CHANNELUP },
710 { 0x1d, 0x21, KEY_CHANNELDOWN },
711 { 0x1d, 0x24, KEY_LAST },
712 { 0x1d, 0x25, KEY_OK },
713 { 0x1d, 0x30, KEY_PAUSE },
714 { 0x1d, 0x32, KEY_REWIND },
715 { 0x1d, 0x34, KEY_FASTFORWARD },
716 { 0x1d, 0x35, KEY_PLAY },
717 { 0x1d, 0x36, KEY_STOP },
718 { 0x1d, 0x37, KEY_RECORD },
719 { 0x1d, 0x3b, KEY_GOTO },
720 { 0x1d, 0x3d, KEY_POWER },
680}; 721};
681 722
682/* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */ 723/* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */
@@ -1078,6 +1119,97 @@ static int stk7070pd_frontend_attach1(struct dvb_usb_adapter *adap)
1078 return adap->fe == NULL ? -ENODEV : 0; 1119 return adap->fe == NULL ? -ENODEV : 0;
1079} 1120}
1080 1121
1122/* S5H1411 */
1123static struct s5h1411_config pinnacle_801e_config = {
1124 .output_mode = S5H1411_PARALLEL_OUTPUT,
1125 .gpio = S5H1411_GPIO_OFF,
1126 .mpeg_timing = S5H1411_MPEGTIMING_NONCONTINOUS_NONINVERTING_CLOCK,
1127 .qam_if = S5H1411_IF_44000,
1128 .vsb_if = S5H1411_IF_44000,
1129 .inversion = S5H1411_INVERSION_OFF,
1130 .status_mode = S5H1411_DEMODLOCKING
1131};
1132
1133/* Pinnacle PCTV HD Pro 801e GPIOs map:
1134 GPIO0 - currently unknown
1135 GPIO1 - xc5000 tuner reset
1136 GPIO2 - CX25843 sleep
1137 GPIO3 - currently unknown
1138 GPIO4 - currently unknown
1139 GPIO6 - currently unknown
1140 GPIO7 - currently unknown
1141 GPIO9 - currently unknown
1142 GPIO10 - CX25843 reset
1143 */
1144static int s5h1411_frontend_attach(struct dvb_usb_adapter *adap)
1145{
1146 struct dib0700_state *st = adap->dev->priv;
1147
1148 /* Make use of the new i2c functions from FW 1.20 */
1149 st->fw_use_new_i2c_api = 1;
1150
1151 /* The s5h1411 requires the dib0700 to not be in master mode */
1152 st->disable_streaming_master_mode = 1;
1153
1154 /* All msleep values taken from Windows USB trace */
1155 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 0);
1156 dib0700_set_gpio(adap->dev, GPIO3, GPIO_OUT, 0);
1157 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
1158 msleep(400);
1159 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
1160 msleep(60);
1161 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
1162 msleep(30);
1163 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
1164 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
1165 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
1166 dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
1167 dib0700_set_gpio(adap->dev, GPIO2, GPIO_OUT, 0);
1168 msleep(30);
1169
1170 /* Put the CX25843 to sleep for now since we're in digital mode */
1171 dib0700_set_gpio(adap->dev, GPIO2, GPIO_OUT, 1);
1172
1173 /* GPIOs are initialized, do the attach */
1174 adap->fe = dvb_attach(s5h1411_attach, &pinnacle_801e_config,
1175 &adap->dev->i2c_adap);
1176 return adap->fe == NULL ? -ENODEV : 0;
1177}
1178
1179static int dib0700_xc5000_tuner_callback(void *priv, int component,
1180 int command, int arg)
1181{
1182 struct dvb_usb_adapter *adap = priv;
1183
1184 if (command == XC5000_TUNER_RESET) {
1185 /* Reset the tuner */
1186 dib0700_set_gpio(adap->dev, GPIO1, GPIO_OUT, 0);
1187 msleep(330); /* from Windows USB trace */
1188 dib0700_set_gpio(adap->dev, GPIO1, GPIO_OUT, 1);
1189 msleep(330); /* from Windows USB trace */
1190 } else {
1191 err("xc5000: unknown tuner callback command: %d\n", command);
1192 return -EINVAL;
1193 }
1194
1195 return 0;
1196}
1197
1198static struct xc5000_config s5h1411_xc5000_tunerconfig = {
1199 .i2c_address = 0x64,
1200 .if_khz = 5380,
1201};
1202
1203static int xc5000_tuner_attach(struct dvb_usb_adapter *adap)
1204{
1205 /* FIXME: generalize & move to common area */
1206 adap->fe->callback = dib0700_xc5000_tuner_callback;
1207
1208 return dvb_attach(xc5000_attach, adap->fe, &adap->dev->i2c_adap,
1209 &s5h1411_xc5000_tunerconfig)
1210 == NULL ? -ENODEV : 0;
1211}
1212
1081/* DVB-USB and USB stuff follows */ 1213/* DVB-USB and USB stuff follows */
1082struct usb_device_id dib0700_usb_id_table[] = { 1214struct usb_device_id dib0700_usb_id_table[] = {
1083/* 0 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P) }, 1215/* 0 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P) },
@@ -1119,6 +1251,11 @@ struct usb_device_id dib0700_usb_id_table[] = {
1119 { USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_STK7700P_2) }, 1251 { USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_STK7700P_2) },
1120/* 35 */{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_TD_STICK_52009) }, 1252/* 35 */{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_TD_STICK_52009) },
1121 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_3) }, 1253 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_3) },
1254 { USB_DEVICE(USB_VID_GIGABYTE, USB_PID_GIGABYTE_U8000) },
1255 { USB_DEVICE(USB_VID_YUAN, USB_PID_YUAN_STK7700PH) },
1256 { USB_DEVICE(USB_VID_ASUS, USB_PID_ASUS_U3000H) },
1257/* 40 */{ USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV801E) },
1258 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV801E_SE) },
1122 { 0 } /* Terminating entry */ 1259 { 0 } /* Terminating entry */
1123}; 1260};
1124MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table); 1261MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
@@ -1126,7 +1263,7 @@ MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
1126#define DIB0700_DEFAULT_DEVICE_PROPERTIES \ 1263#define DIB0700_DEFAULT_DEVICE_PROPERTIES \
1127 .caps = DVB_USB_IS_AN_I2C_ADAPTER, \ 1264 .caps = DVB_USB_IS_AN_I2C_ADAPTER, \
1128 .usb_ctrl = DEVICE_SPECIFIC, \ 1265 .usb_ctrl = DEVICE_SPECIFIC, \
1129 .firmware = "dvb-usb-dib0700-1.10.fw", \ 1266 .firmware = "dvb-usb-dib0700-1.20.fw", \
1130 .download_firmware = dib0700_download_firmware, \ 1267 .download_firmware = dib0700_download_firmware, \
1131 .no_reconnect = 1, \ 1268 .no_reconnect = 1, \
1132 .size_of_priv = sizeof(struct dib0700_state), \ 1269 .size_of_priv = sizeof(struct dib0700_state), \
@@ -1293,7 +1430,12 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1293 { &dib0700_usb_id_table[31], NULL }, 1430 { &dib0700_usb_id_table[31], NULL },
1294 { NULL }, 1431 { NULL },
1295 } 1432 }
1296 } 1433 },
1434
1435 .rc_interval = DEFAULT_RC_INTERVAL,
1436 .rc_key_map = dib0700_rc_keys,
1437 .rc_key_map_size = ARRAY_SIZE(dib0700_rc_keys),
1438 .rc_query = dib0700_rc_query
1297 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 1439 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
1298 1440
1299 .num_adapters = 1, 1441 .num_adapters = 1,
@@ -1408,7 +1550,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1408 }, 1550 },
1409 }, 1551 },
1410 1552
1411 .num_device_descs = 3, 1553 .num_device_descs = 5,
1412 .devices = { 1554 .devices = {
1413 { "Terratec Cinergy HT USB XE", 1555 { "Terratec Cinergy HT USB XE",
1414 { &dib0700_usb_id_table[27], NULL }, 1556 { &dib0700_usb_id_table[27], NULL },
@@ -1422,6 +1564,47 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1422 { &dib0700_usb_id_table[32], NULL }, 1564 { &dib0700_usb_id_table[32], NULL },
1423 { NULL }, 1565 { NULL },
1424 }, 1566 },
1567 { "Gigabyte U8000-RH",
1568 { &dib0700_usb_id_table[37], NULL },
1569 { NULL },
1570 },
1571 { "YUAN High-Tech STK7700PH",
1572 { &dib0700_usb_id_table[38], NULL },
1573 { NULL },
1574 },
1575 { "Asus My Cinema-U3000Hybrid",
1576 { &dib0700_usb_id_table[39], NULL },
1577 { NULL },
1578 },
1579 },
1580 .rc_interval = DEFAULT_RC_INTERVAL,
1581 .rc_key_map = dib0700_rc_keys,
1582 .rc_key_map_size = ARRAY_SIZE(dib0700_rc_keys),
1583 .rc_query = dib0700_rc_query
1584 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
1585 .num_adapters = 1,
1586 .adapter = {
1587 {
1588 .frontend_attach = s5h1411_frontend_attach,
1589 .tuner_attach = xc5000_tuner_attach,
1590
1591 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
1592
1593 .size_of_priv = sizeof(struct
1594 dib0700_adapter_state),
1595 },
1596 },
1597
1598 .num_device_descs = 2,
1599 .devices = {
1600 { "Pinnacle PCTV HD Pro USB Stick",
1601 { &dib0700_usb_id_table[40], NULL },
1602 { NULL },
1603 },
1604 { "Pinnacle PCTV HD USB Stick",
1605 { &dib0700_usb_id_table[41], NULL },
1606 { NULL },
1607 },
1425 }, 1608 },
1426 .rc_interval = DEFAULT_RC_INTERVAL, 1609 .rc_interval = DEFAULT_RC_INTERVAL,
1427 .rc_key_map = dib0700_rc_keys, 1610 .rc_key_map = dib0700_rc_keys,
diff --git a/drivers/media/dvb/dvb-usb/dtv5100.c b/drivers/media/dvb/dvb-usb/dtv5100.c
new file mode 100644
index 000000000000..078ce92ca436
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dtv5100.c
@@ -0,0 +1,240 @@
1/*
2 * DVB USB Linux driver for AME DTV-5100 USB2.0 DVB-T
3 *
4 * Copyright (C) 2008 Antoine Jacquet <royale@zerezo.com>
5 * http://royale.zerezo.com/dtv5100/
6 *
7 * Inspired by gl861.c and au6610.c drivers
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#include "dtv5100.h"
25#include "zl10353.h"
26#include "qt1010.h"
27
28/* debug */
29static int dvb_usb_dtv5100_debug;
30module_param_named(debug, dvb_usb_dtv5100_debug, int, 0644);
31MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
32DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
33
34static int dtv5100_i2c_msg(struct dvb_usb_device *d, u8 addr,
35 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
36{
37 u8 request;
38 u8 type;
39 u16 value;
40 u16 index;
41
42 switch (wlen) {
43 case 1:
44 /* write { reg }, read { value } */
45 request = (addr == DTV5100_DEMOD_ADDR ? DTV5100_DEMOD_READ :
46 DTV5100_TUNER_READ);
47 type = USB_TYPE_VENDOR | USB_DIR_IN;
48 value = 0;
49 break;
50 case 2:
51 /* write { reg, value } */
52 request = (addr == DTV5100_DEMOD_ADDR ? DTV5100_DEMOD_WRITE :
53 DTV5100_TUNER_WRITE);
54 type = USB_TYPE_VENDOR | USB_DIR_OUT;
55 value = wbuf[1];
56 break;
57 default:
58 warn("wlen = %x, aborting.", wlen);
59 return -EINVAL;
60 }
61 index = (addr << 8) + wbuf[0];
62
63 msleep(1); /* avoid I2C errors */
64 return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), request,
65 type, value, index, rbuf, rlen,
66 DTV5100_USB_TIMEOUT);
67}
68
69/* I2C */
70static int dtv5100_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
71 int num)
72{
73 struct dvb_usb_device *d = i2c_get_adapdata(adap);
74 int i;
75
76 if (num > 2)
77 return -EINVAL;
78
79 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
80 return -EAGAIN;
81
82 for (i = 0; i < num; i++) {
83 /* write/read request */
84 if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
85 if (dtv5100_i2c_msg(d, msg[i].addr, msg[i].buf,
86 msg[i].len, msg[i+1].buf,
87 msg[i+1].len) < 0)
88 break;
89 i++;
90 } else if (dtv5100_i2c_msg(d, msg[i].addr, msg[i].buf,
91 msg[i].len, NULL, 0) < 0)
92 break;
93 }
94
95 mutex_unlock(&d->i2c_mutex);
96 return i;
97}
98
99static u32 dtv5100_i2c_func(struct i2c_adapter *adapter)
100{
101 return I2C_FUNC_I2C;
102}
103
104static struct i2c_algorithm dtv5100_i2c_algo = {
105 .master_xfer = dtv5100_i2c_xfer,
106 .functionality = dtv5100_i2c_func,
107};
108
109/* Callbacks for DVB USB */
110static struct zl10353_config dtv5100_zl10353_config = {
111 .demod_address = DTV5100_DEMOD_ADDR,
112 .no_tuner = 1,
113 .parallel_ts = 1,
114};
115
116static int dtv5100_frontend_attach(struct dvb_usb_adapter *adap)
117{
118 adap->fe = dvb_attach(zl10353_attach, &dtv5100_zl10353_config,
119 &adap->dev->i2c_adap);
120 if (adap->fe == NULL)
121 return -EIO;
122
123 /* disable i2c gate, or it won't work... is this safe? */
124 adap->fe->ops.i2c_gate_ctrl = NULL;
125
126 return 0;
127}
128
129static struct qt1010_config dtv5100_qt1010_config = {
130 .i2c_address = DTV5100_TUNER_ADDR
131};
132
133static int dtv5100_tuner_attach(struct dvb_usb_adapter *adap)
134{
135 return dvb_attach(qt1010_attach,
136 adap->fe, &adap->dev->i2c_adap,
137 &dtv5100_qt1010_config) == NULL ? -ENODEV : 0;
138}
139
140/* DVB USB Driver stuff */
141static struct dvb_usb_device_properties dtv5100_properties;
142
143static int dtv5100_probe(struct usb_interface *intf,
144 const struct usb_device_id *id)
145{
146 int i, ret;
147 struct usb_device *udev = interface_to_usbdev(intf);
148
149 /* initialize non qt1010/zl10353 part? */
150 for (i = 0; dtv5100_init[i].request; i++) {
151 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
152 dtv5100_init[i].request,
153 USB_TYPE_VENDOR | USB_DIR_OUT,
154 dtv5100_init[i].value,
155 dtv5100_init[i].index, NULL, 0,
156 DTV5100_USB_TIMEOUT);
157 if (ret)
158 return ret;
159 }
160
161 ret = dvb_usb_device_init(intf, &dtv5100_properties,
162 THIS_MODULE, NULL, adapter_nr);
163 if (ret)
164 return ret;
165
166 return 0;
167}
168
169static struct usb_device_id dtv5100_table[] = {
170 { USB_DEVICE(0x06be, 0xa232) },
171 { } /* Terminating entry */
172};
173MODULE_DEVICE_TABLE(usb, dtv5100_table);
174
175static struct dvb_usb_device_properties dtv5100_properties = {
176 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
177 .usb_ctrl = DEVICE_SPECIFIC,
178
179 .size_of_priv = 0,
180
181 .num_adapters = 1,
182 .adapter = {{
183 .frontend_attach = dtv5100_frontend_attach,
184 .tuner_attach = dtv5100_tuner_attach,
185
186 .stream = {
187 .type = USB_BULK,
188 .count = 8,
189 .endpoint = 0x82,
190 .u = {
191 .bulk = {
192 .buffersize = 4096,
193 }
194 }
195 },
196 } },
197
198 .i2c_algo = &dtv5100_i2c_algo,
199
200 .num_device_descs = 1,
201 .devices = {
202 {
203 .name = "AME DTV-5100 USB2.0 DVB-T",
204 .cold_ids = { NULL },
205 .warm_ids = { &dtv5100_table[0], NULL },
206 },
207 }
208};
209
210static struct usb_driver dtv5100_driver = {
211 .name = "dvb_usb_dtv5100",
212 .probe = dtv5100_probe,
213 .disconnect = dvb_usb_device_exit,
214 .id_table = dtv5100_table,
215};
216
217/* module stuff */
218static int __init dtv5100_module_init(void)
219{
220 int ret;
221
222 ret = usb_register(&dtv5100_driver);
223 if (ret)
224 err("usb_register failed. Error number %d", ret);
225
226 return ret;
227}
228
229static void __exit dtv5100_module_exit(void)
230{
231 /* deregister this driver from the USB subsystem */
232 usb_deregister(&dtv5100_driver);
233}
234
235module_init(dtv5100_module_init);
236module_exit(dtv5100_module_exit);
237
238MODULE_AUTHOR(DRIVER_AUTHOR);
239MODULE_DESCRIPTION(DRIVER_DESC);
240MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/dtv5100.h b/drivers/media/dvb/dvb-usb/dtv5100.h
new file mode 100644
index 000000000000..93e96e04a82a
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dtv5100.h
@@ -0,0 +1,51 @@
1/*
2 * DVB USB Linux driver for AME DTV-5100 USB2.0 DVB-T
3 *
4 * Copyright (C) 2008 Antoine Jacquet <royale@zerezo.com>
5 * http://royale.zerezo.com/dtv5100/
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#ifndef _DVB_USB_DTV5100_H_
23#define _DVB_USB_DTV5100_H_
24
25#define DVB_USB_LOG_PREFIX "dtv5100"
26#include "dvb-usb.h"
27
28#define DTV5100_USB_TIMEOUT 500
29
30#define DTV5100_DEMOD_ADDR 0x00
31#define DTV5100_DEMOD_WRITE 0xc0
32#define DTV5100_DEMOD_READ 0xc1
33
34#define DTV5100_TUNER_ADDR 0xc4
35#define DTV5100_TUNER_WRITE 0xc7
36#define DTV5100_TUNER_READ 0xc8
37
38#define DRIVER_AUTHOR "Antoine Jacquet, http://royale.zerezo.com/"
39#define DRIVER_DESC "AME DTV-5100 USB2.0 DVB-T"
40
41static struct {
42 u8 request;
43 u8 value;
44 u16 index;
45} dtv5100_init[] = {
46 { 0x000000c5, 0x00000000, 0x00000001 },
47 { 0x000000c5, 0x00000001, 0x00000001 },
48 { } /* Terminating entry */
49};
50
51#endif
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index 03dfb9f2fe30..7380b94b3b36 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -22,6 +22,7 @@
22#define USB_VID_AVERMEDIA 0x07ca 22#define USB_VID_AVERMEDIA 0x07ca
23#define USB_VID_COMPRO 0x185b 23#define USB_VID_COMPRO 0x185b
24#define USB_VID_COMPRO_UNK 0x145f 24#define USB_VID_COMPRO_UNK 0x145f
25#define USB_VID_CONEXANT 0x0572
25#define USB_VID_CYPRESS 0x04b4 26#define USB_VID_CYPRESS 0x04b4
26#define USB_VID_DIBCOM 0x10b8 27#define USB_VID_DIBCOM 0x10b8
27#define USB_VID_DPOSH 0x1498 28#define USB_VID_DPOSH 0x1498
@@ -33,16 +34,19 @@
33#define USB_VID_HAUPPAUGE 0x2040 34#define USB_VID_HAUPPAUGE 0x2040
34#define USB_VID_HYPER_PALTEK 0x1025 35#define USB_VID_HYPER_PALTEK 0x1025
35#define USB_VID_KWORLD 0xeb2a 36#define USB_VID_KWORLD 0xeb2a
37#define USB_VID_KWORLD_2 0x1b80
36#define USB_VID_KYE 0x0458 38#define USB_VID_KYE 0x0458
37#define USB_VID_LEADTEK 0x0413 39#define USB_VID_LEADTEK 0x0413
38#define USB_VID_LITEON 0x04ca 40#define USB_VID_LITEON 0x04ca
39#define USB_VID_MEDION 0x1660 41#define USB_VID_MEDION 0x1660
40#define USB_VID_MIGLIA 0x18f3 42#define USB_VID_MIGLIA 0x18f3
41#define USB_VID_MSI 0x0db0 43#define USB_VID_MSI 0x0db0
44#define USB_VID_MSI_2 0x1462
42#define USB_VID_OPERA1 0x695c 45#define USB_VID_OPERA1 0x695c
43#define USB_VID_PINNACLE 0x2304 46#define USB_VID_PINNACLE 0x2304
44#define USB_VID_TECHNOTREND 0x0b48 47#define USB_VID_TECHNOTREND 0x0b48
45#define USB_VID_TERRATEC 0x0ccd 48#define USB_VID_TERRATEC 0x0ccd
49#define USB_VID_TELESTAR 0x10b9
46#define USB_VID_VISIONPLUS 0x13d3 50#define USB_VID_VISIONPLUS 0x13d3
47#define USB_VID_TWINHAN 0x1822 51#define USB_VID_TWINHAN 0x1822
48#define USB_VID_ULTIMA_ELECTRONIC 0x05d8 52#define USB_VID_ULTIMA_ELECTRONIC 0x05d8
@@ -50,15 +54,18 @@
50#define USB_VID_WIDEVIEW 0x14aa 54#define USB_VID_WIDEVIEW 0x14aa
51#define USB_VID_GIGABYTE 0x1044 55#define USB_VID_GIGABYTE 0x1044
52#define USB_VID_YUAN 0x1164 56#define USB_VID_YUAN 0x1164
53 57#define USB_VID_XTENSIONS 0x1ae7
54 58
55/* Product IDs */ 59/* Product IDs */
56#define USB_PID_ADSTECH_USB2_COLD 0xa333 60#define USB_PID_ADSTECH_USB2_COLD 0xa333
57#define USB_PID_ADSTECH_USB2_WARM 0xa334 61#define USB_PID_ADSTECH_USB2_WARM 0xa334
58#define USB_PID_AFATECH_AF9005 0x9020 62#define USB_PID_AFATECH_AF9005 0x9020
63#define USB_PID_AFATECH_AF9015_9015 0x9015
64#define USB_PID_AFATECH_AF9015_9016 0x9016
59#define USB_VID_ALINK_DTU 0xf170 65#define USB_VID_ALINK_DTU 0xf170
60#define USB_PID_ANSONIC_DVBT_USB 0x6000 66#define USB_PID_ANSONIC_DVBT_USB 0x6000
61#define USB_PID_ANYSEE 0x861f 67#define USB_PID_ANYSEE 0x861f
68#define USB_PID_AZUREWAVE_AD_TU700 0x3237
62#define USB_PID_AVERMEDIA_DVBT_USB_COLD 0x0001 69#define USB_PID_AVERMEDIA_DVBT_USB_COLD 0x0001
63#define USB_PID_AVERMEDIA_DVBT_USB_WARM 0x0002 70#define USB_PID_AVERMEDIA_DVBT_USB_WARM 0x0002
64#define USB_PID_AVERMEDIA_DVBT_USB2_COLD 0xa800 71#define USB_PID_AVERMEDIA_DVBT_USB2_COLD 0xa800
@@ -69,6 +76,7 @@
69#define USB_PID_COMPRO_DVBU2000_UNK_WARM 0x010d 76#define USB_PID_COMPRO_DVBU2000_UNK_WARM 0x010d
70#define USB_PID_COMPRO_VIDEOMATE_U500 0x1e78 77#define USB_PID_COMPRO_VIDEOMATE_U500 0x1e78
71#define USB_PID_COMPRO_VIDEOMATE_U500_PC 0x1e80 78#define USB_PID_COMPRO_VIDEOMATE_U500_PC 0x1e80
79#define USB_PID_CONEXANT_D680_DMB 0x86d6
72#define USB_PID_DIBCOM_HOOK_DEFAULT 0x0064 80#define USB_PID_DIBCOM_HOOK_DEFAULT 0x0064
73#define USB_PID_DIBCOM_HOOK_DEFAULT_REENUM 0x0065 81#define USB_PID_DIBCOM_HOOK_DEFAULT_REENUM 0x0065
74#define USB_PID_DIBCOM_MOD3000_COLD 0x0bb8 82#define USB_PID_DIBCOM_MOD3000_COLD 0x0bb8
@@ -87,9 +95,12 @@
87#define USB_PID_UNIWILL_STK7700P 0x6003 95#define USB_PID_UNIWILL_STK7700P 0x6003
88#define USB_PID_GRANDTEC_DVBT_USB_COLD 0x0fa0 96#define USB_PID_GRANDTEC_DVBT_USB_COLD 0x0fa0
89#define USB_PID_GRANDTEC_DVBT_USB_WARM 0x0fa1 97#define USB_PID_GRANDTEC_DVBT_USB_WARM 0x0fa1
98#define USB_PID_KWORLD_399U 0xe399
99#define USB_PID_KWORLD_PC160_2T 0xc160
90#define USB_PID_KWORLD_VSTREAM_COLD 0x17de 100#define USB_PID_KWORLD_VSTREAM_COLD 0x17de
91#define USB_PID_KWORLD_VSTREAM_WARM 0x17df 101#define USB_PID_KWORLD_VSTREAM_WARM 0x17df
92#define USB_PID_TERRATEC_CINERGY_T_USB_XE 0x0055 102#define USB_PID_TERRATEC_CINERGY_T_USB_XE 0x0055
103#define USB_PID_TERRATEC_CINERGY_T_USB_XE_REV2 0x0069
93#define USB_PID_TWINHAN_VP7041_COLD 0x3201 104#define USB_PID_TWINHAN_VP7041_COLD 0x3201
94#define USB_PID_TWINHAN_VP7041_WARM 0x3202 105#define USB_PID_TWINHAN_VP7041_WARM 0x3202
95#define USB_PID_TWINHAN_VP7020_COLD 0x3203 106#define USB_PID_TWINHAN_VP7020_COLD 0x3203
@@ -98,6 +109,7 @@
98#define USB_PID_TWINHAN_VP7045_WARM 0x3206 109#define USB_PID_TWINHAN_VP7045_WARM 0x3206
99#define USB_PID_TWINHAN_VP7021_COLD 0x3207 110#define USB_PID_TWINHAN_VP7021_COLD 0x3207
100#define USB_PID_TWINHAN_VP7021_WARM 0x3208 111#define USB_PID_TWINHAN_VP7021_WARM 0x3208
112#define USB_PID_TINYTWIN 0x3226
101#define USB_PID_DNTV_TINYUSB2_COLD 0x3223 113#define USB_PID_DNTV_TINYUSB2_COLD 0x3223
102#define USB_PID_DNTV_TINYUSB2_WARM 0x3224 114#define USB_PID_DNTV_TINYUSB2_WARM 0x3224
103#define USB_PID_ULTIMA_TVBOX_COLD 0x8105 115#define USB_PID_ULTIMA_TVBOX_COLD 0x8105
@@ -144,6 +156,9 @@
144#define USB_PID_AVERMEDIA_HYBRID_ULTRA_USB_M039R 0x0039 156#define USB_PID_AVERMEDIA_HYBRID_ULTRA_USB_M039R 0x0039
145#define USB_PID_AVERMEDIA_HYBRID_ULTRA_USB_M039R_ATSC 0x1039 157#define USB_PID_AVERMEDIA_HYBRID_ULTRA_USB_M039R_ATSC 0x1039
146#define USB_PID_AVERMEDIA_HYBRID_ULTRA_USB_M039R_DVBT 0x2039 158#define USB_PID_AVERMEDIA_HYBRID_ULTRA_USB_M039R_DVBT 0x2039
159#define USB_PID_AVERMEDIA_VOLAR_X 0xa815
160#define USB_PID_AVERMEDIA_VOLAR_X_2 0x8150
161#define USB_PID_AVERMEDIA_A309 0xa309
147#define USB_PID_TECHNOTREND_CONNECT_S2400 0x3006 162#define USB_PID_TECHNOTREND_CONNECT_S2400 0x3006
148#define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY 0x005a 163#define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY 0x005a
149#define USB_PID_TERRATEC_CINERGY_HT_USB_XE 0x0058 164#define USB_PID_TERRATEC_CINERGY_HT_USB_XE 0x0058
@@ -153,8 +168,11 @@
153#define USB_PID_PINNACLE_PCTV2000E 0x022c 168#define USB_PID_PINNACLE_PCTV2000E 0x022c
154#define USB_PID_PINNACLE_PCTV_DVB_T_FLASH 0x0228 169#define USB_PID_PINNACLE_PCTV_DVB_T_FLASH 0x0228
155#define USB_PID_PINNACLE_PCTV_DUAL_DIVERSITY_DVB_T 0x0229 170#define USB_PID_PINNACLE_PCTV_DUAL_DIVERSITY_DVB_T 0x0229
171#define USB_PID_PINNACLE_PCTV71E 0x022b
156#define USB_PID_PINNACLE_PCTV72E 0x0236 172#define USB_PID_PINNACLE_PCTV72E 0x0236
157#define USB_PID_PINNACLE_PCTV73E 0x0237 173#define USB_PID_PINNACLE_PCTV73E 0x0237
174#define USB_PID_PINNACLE_PCTV801E 0x023a
175#define USB_PID_PINNACLE_PCTV801E_SE 0x023b
158#define USB_PID_PCTV_200E 0x020e 176#define USB_PID_PCTV_200E 0x020e
159#define USB_PID_PCTV_400E 0x020f 177#define USB_PID_PCTV_400E 0x020f
160#define USB_PID_PCTV_450E 0x0222 178#define USB_PID_PCTV_450E 0x0222
@@ -171,6 +189,7 @@
171#define USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD 0xdb58 189#define USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD 0xdb58
172#define USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM 0xdb59 190#define USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM 0xdb59
173#define USB_PID_DVICO_BLUEBIRD_DUAL_4 0xdb78 191#define USB_PID_DVICO_BLUEBIRD_DUAL_4 0xdb78
192#define USB_PID_DVICO_BLUEBIRD_DUAL_4_REV_2 0xdb98
174#define USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2 0xdb70 193#define USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2 0xdb70
175#define USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM 0xdb71 194#define USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM 0xdb71
176#define USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD 0xdb54 195#define USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD 0xdb54
@@ -190,6 +209,7 @@
190#define USB_PID_WINFAST_DTV_DONGLE_WARM 0x6026 209#define USB_PID_WINFAST_DTV_DONGLE_WARM 0x6026
191#define USB_PID_WINFAST_DTV_DONGLE_STK7700P 0x6f00 210#define USB_PID_WINFAST_DTV_DONGLE_STK7700P 0x6f00
192#define USB_PID_WINFAST_DTV_DONGLE_STK7700P_2 0x6f01 211#define USB_PID_WINFAST_DTV_DONGLE_STK7700P_2 0x6f01
212#define USB_PID_WINFAST_DTV_DONGLE_GOLD 0x6029
193#define USB_PID_GENPIX_8PSK_REV_1_COLD 0x0200 213#define USB_PID_GENPIX_8PSK_REV_1_COLD 0x0200
194#define USB_PID_GENPIX_8PSK_REV_1_WARM 0x0201 214#define USB_PID_GENPIX_8PSK_REV_1_WARM 0x0201
195#define USB_PID_GENPIX_8PSK_REV_2 0x0202 215#define USB_PID_GENPIX_8PSK_REV_2 0x0202
@@ -197,14 +217,21 @@
197#define USB_PID_GENPIX_SKYWALKER_CW3K 0x0204 217#define USB_PID_GENPIX_SKYWALKER_CW3K 0x0204
198#define USB_PID_SIGMATEK_DVB_110 0x6610 218#define USB_PID_SIGMATEK_DVB_110 0x6610
199#define USB_PID_MSI_DIGI_VOX_MINI_II 0x1513 219#define USB_PID_MSI_DIGI_VOX_MINI_II 0x1513
220#define USB_PID_MSI_DIGIVOX_DUO 0x8801
200#define USB_PID_OPERA1_COLD 0x2830 221#define USB_PID_OPERA1_COLD 0x2830
201#define USB_PID_OPERA1_WARM 0x3829 222#define USB_PID_OPERA1_WARM 0x3829
202#define USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD 0x0514 223#define USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD 0x0514
203#define USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM 0x0513 224#define USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM 0x0513
204#define USB_PID_GIGABYTE_U7000 0x7001 225#define USB_PID_GIGABYTE_U7000 0x7001
226#define USB_PID_GIGABYTE_U8000 0x7002
205#define USB_PID_ASUS_U3000 0x171f 227#define USB_PID_ASUS_U3000 0x171f
228#define USB_PID_ASUS_U3000H 0x1736
206#define USB_PID_ASUS_U3100 0x173f 229#define USB_PID_ASUS_U3100 0x173f
207#define USB_PID_YUAN_EC372S 0x1edc 230#define USB_PID_YUAN_EC372S 0x1edc
231#define USB_PID_YUAN_STK7700PH 0x1f08
208#define USB_PID_DW2102 0x2102 232#define USB_PID_DW2102 0x2102
233#define USB_PID_XTENSIONS_XD_380 0x0381
234#define USB_PID_TELESTAR_STARSTICK_2 0x8000
235#define USB_PID_MSI_DIGI_VOX_MINI_III 0x8807
209 236
210#endif 237#endif
diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
index a4d898b44e55..ca53df61caa8 100644
--- a/drivers/media/dvb/dvb-usb/dw2102.c
+++ b/drivers/media/dvb/dvb-usb/dw2102.c
@@ -1,4 +1,5 @@
1/* DVB USB framework compliant Linux driver for the DVBWorld DVB-S 2102 Card 1/* DVB USB framework compliant Linux driver for the
2* DVBWorld DVB-S 2101, 2102, DVB-S2 2104 Card
2* 3*
3* Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by) 4* Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by)
4* 5*
@@ -10,62 +11,74 @@
10*/ 11*/
11#include <linux/version.h> 12#include <linux/version.h>
12#include "dw2102.h" 13#include "dw2102.h"
14#include "si21xx.h"
13#include "stv0299.h" 15#include "stv0299.h"
14#include "z0194a.h" 16#include "z0194a.h"
17#include "stv0288.h"
18#include "stb6000.h"
19#include "eds1547.h"
20#include "cx24116.h"
15 21
16#ifndef USB_PID_DW2102 22#ifndef USB_PID_DW2102
17#define USB_PID_DW2102 0x2102 23#define USB_PID_DW2102 0x2102
18#endif 24#endif
19 25
20#define DW2102_READ_MSG 0 26#ifndef USB_PID_DW2104
21#define DW2102_WRITE_MSG 1 27#define USB_PID_DW2104 0x2104
28#endif
29
30#define DW210X_READ_MSG 0
31#define DW210X_WRITE_MSG 1
22 32
23#define REG_1F_SYMBOLRATE_BYTE0 0x1f 33#define REG_1F_SYMBOLRATE_BYTE0 0x1f
24#define REG_20_SYMBOLRATE_BYTE1 0x20 34#define REG_20_SYMBOLRATE_BYTE1 0x20
25#define REG_21_SYMBOLRATE_BYTE2 0x21 35#define REG_21_SYMBOLRATE_BYTE2 0x21
26 36/* on my own*/
27#define DW2102_VOLTAGE_CTRL (0x1800) 37#define DW2102_VOLTAGE_CTRL (0x1800)
28#define DW2102_RC_QUERY (0x1a00) 38#define DW2102_RC_QUERY (0x1a00)
29 39
30struct dw2102_state { 40struct dw210x_state {
31 u32 last_key_pressed; 41 u32 last_key_pressed;
32}; 42};
33struct dw2102_rc_keys { 43struct dw210x_rc_keys {
34 u32 keycode; 44 u32 keycode;
35 u32 event; 45 u32 event;
36}; 46};
37 47
48/* debug */
49static int dvb_usb_dw2102_debug;
50module_param_named(debug, dvb_usb_dw2102_debug, int, 0644);
51MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer (or-able))." DVB_USB_DEBUG_STATUS);
52
38DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 53DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
39 54
40static int dw2102_op_rw(struct usb_device *dev, u8 request, u16 value, 55static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
41 u8 *data, u16 len, int flags) 56 u16 index, u8 * data, u16 len, int flags)
42{ 57{
43 int ret; 58 int ret;
44 u8 u8buf[len]; 59 u8 u8buf[len];
45 60
46 unsigned int pipe = (flags == DW2102_READ_MSG) ? 61 unsigned int pipe = (flags == DW210X_READ_MSG) ?
47 usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0); 62 usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
48 u8 request_type = (flags == DW2102_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT; 63 u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
49 64
50 if (flags == DW2102_WRITE_MSG) 65 if (flags == DW210X_WRITE_MSG)
51 memcpy(u8buf, data, len); 66 memcpy(u8buf, data, len);
52 ret = usb_control_msg(dev, pipe, request, 67 ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR,
53 request_type | USB_TYPE_VENDOR, value, 0 , u8buf, len, 2000); 68 value, index , u8buf, len, 2000);
54 69
55 if (flags == DW2102_READ_MSG) 70 if (flags == DW210X_READ_MSG)
56 memcpy(data, u8buf, len); 71 memcpy(data, u8buf, len);
57 return ret; 72 return ret;
58} 73}
59 74
60/* I2C */ 75/* I2C */
61
62static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], 76static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
63 int num) 77 int num)
64{ 78{
65struct dvb_usb_device *d = i2c_get_adapdata(adap); 79struct dvb_usb_device *d = i2c_get_adapdata(adap);
66 int i = 0, ret = 0; 80 int i = 0, ret = 0;
67 u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0}; 81 u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
68 u8 request;
69 u16 value; 82 u16 value;
70 83
71 if (!d) 84 if (!d)
@@ -76,14 +89,12 @@ struct dvb_usb_device *d = i2c_get_adapdata(adap);
76 switch (num) { 89 switch (num) {
77 case 2: 90 case 2:
78 /* read stv0299 register */ 91 /* read stv0299 register */
79 request = 0xb5;
80 value = msg[0].buf[0];/* register */ 92 value = msg[0].buf[0];/* register */
81 for (i = 0; i < msg[1].len; i++) { 93 for (i = 0; i < msg[1].len; i++) {
82 value = value + i; 94 value = value + i;
83 ret = dw2102_op_rw(d->udev, 0xb5, 95 ret = dw210x_op_rw(d->udev, 0xb5, value, 0,
84 value, buf6, 2, DW2102_READ_MSG); 96 buf6, 2, DW210X_READ_MSG);
85 msg[1].buf[i] = buf6[0]; 97 msg[1].buf[i] = buf6[0];
86
87 } 98 }
88 break; 99 break;
89 case 1: 100 case 1:
@@ -93,8 +104,8 @@ struct dvb_usb_device *d = i2c_get_adapdata(adap);
93 buf6[0] = 0x2a; 104 buf6[0] = 0x2a;
94 buf6[1] = msg[0].buf[0]; 105 buf6[1] = msg[0].buf[0];
95 buf6[2] = msg[0].buf[1]; 106 buf6[2] = msg[0].buf[1];
96 ret = dw2102_op_rw(d->udev, 0xb2, 107 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
97 0, buf6, 3, DW2102_WRITE_MSG); 108 buf6, 3, DW210X_WRITE_MSG);
98 break; 109 break;
99 case 0x60: 110 case 0x60:
100 if (msg[0].flags == 0) { 111 if (msg[0].flags == 0) {
@@ -106,26 +117,26 @@ struct dvb_usb_device *d = i2c_get_adapdata(adap);
106 buf6[4] = msg[0].buf[1]; 117 buf6[4] = msg[0].buf[1];
107 buf6[5] = msg[0].buf[2]; 118 buf6[5] = msg[0].buf[2];
108 buf6[6] = msg[0].buf[3]; 119 buf6[6] = msg[0].buf[3];
109 ret = dw2102_op_rw(d->udev, 0xb2, 120 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
110 0, buf6, 7, DW2102_WRITE_MSG); 121 buf6, 7, DW210X_WRITE_MSG);
111 } else { 122 } else {
112 /* write to tuner pll */ 123 /* read from tuner */
113 ret = dw2102_op_rw(d->udev, 0xb5, 124 ret = dw210x_op_rw(d->udev, 0xb5, 0, 0,
114 0, buf6, 1, DW2102_READ_MSG); 125 buf6, 1, DW210X_READ_MSG);
115 msg[0].buf[0] = buf6[0]; 126 msg[0].buf[0] = buf6[0];
116 } 127 }
117 break; 128 break;
118 case (DW2102_RC_QUERY): 129 case (DW2102_RC_QUERY):
119 ret = dw2102_op_rw(d->udev, 0xb8, 130 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
120 0, buf6, 2, DW2102_READ_MSG); 131 buf6, 2, DW210X_READ_MSG);
121 msg[0].buf[0] = buf6[0]; 132 msg[0].buf[0] = buf6[0];
122 msg[0].buf[1] = buf6[1]; 133 msg[0].buf[1] = buf6[1];
123 break; 134 break;
124 case (DW2102_VOLTAGE_CTRL): 135 case (DW2102_VOLTAGE_CTRL):
125 buf6[0] = 0x30; 136 buf6[0] = 0x30;
126 buf6[1] = msg[0].buf[0]; 137 buf6[1] = msg[0].buf[0];
127 ret = dw2102_op_rw(d->udev, 0xb2, 138 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
128 0, buf6, 2, DW2102_WRITE_MSG); 139 buf6, 2, DW210X_WRITE_MSG);
129 break; 140 break;
130 } 141 }
131 142
@@ -136,17 +147,265 @@ struct dvb_usb_device *d = i2c_get_adapdata(adap);
136 return num; 147 return num;
137} 148}
138 149
139static u32 dw2102_i2c_func(struct i2c_adapter *adapter) 150static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
151 struct i2c_msg msg[], int num)
152{
153 struct dvb_usb_device *d = i2c_get_adapdata(adap);
154 int ret = 0;
155 u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
156
157 if (!d)
158 return -ENODEV;
159 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
160 return -EAGAIN;
161
162 switch (num) {
163 case 2:
164 /* read si2109 register by number */
165 buf6[0] = 0xd0;
166 buf6[1] = msg[0].len;
167 buf6[2] = msg[0].buf[0];
168 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
169 buf6, msg[0].len + 2, DW210X_WRITE_MSG);
170 /* read si2109 register */
171 ret = dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
172 buf6, msg[1].len + 2, DW210X_READ_MSG);
173 memcpy(msg[1].buf, buf6 + 2, msg[1].len);
174
175 break;
176 case 1:
177 switch (msg[0].addr) {
178 case 0x68:
179 /* write to si2109 register */
180 buf6[0] = 0xd0;
181 buf6[1] = msg[0].len;
182 memcpy(buf6 + 2, msg[0].buf, msg[0].len);
183 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
184 msg[0].len + 2, DW210X_WRITE_MSG);
185 break;
186 case(DW2102_RC_QUERY):
187 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
188 buf6, 2, DW210X_READ_MSG);
189 msg[0].buf[0] = buf6[0];
190 msg[0].buf[1] = buf6[1];
191 break;
192 case(DW2102_VOLTAGE_CTRL):
193 buf6[0] = 0x30;
194 buf6[1] = msg[0].buf[0];
195 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
196 buf6, 2, DW210X_WRITE_MSG);
197 break;
198 }
199 break;
200 }
201
202 mutex_unlock(&d->i2c_mutex);
203 return num;
204}
205static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
206{
207 struct dvb_usb_device *d = i2c_get_adapdata(adap);
208 int ret = 0;
209
210 if (!d)
211 return -ENODEV;
212 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
213 return -EAGAIN;
214
215 switch (num) {
216 case 2: {
217 /* read */
218 /* first write first register number */
219 u8 ibuf [msg[1].len + 2], obuf[3];
220 obuf[0] = 0xd0;
221 obuf[1] = msg[0].len;
222 obuf[2] = msg[0].buf[0];
223 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
224 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
225 /* second read registers */
226 ret = dw210x_op_rw(d->udev, 0xc3, 0xd1 , 0,
227 ibuf, msg[1].len + 2, DW210X_READ_MSG);
228 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
229
230 break;
231 }
232 case 1:
233 switch (msg[0].addr) {
234 case 0x68: {
235 /* write to register */
236 u8 obuf[msg[0].len + 2];
237 obuf[0] = 0xd0;
238 obuf[1] = msg[0].len;
239 memcpy(obuf + 2, msg[0].buf, msg[0].len);
240 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
241 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
242 break;
243 }
244 case 0x61: {
245 /* write to tuner */
246 u8 obuf[msg[0].len + 2];
247 obuf[0] = 0xc2;
248 obuf[1] = msg[0].len;
249 memcpy(obuf + 2, msg[0].buf, msg[0].len);
250 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
251 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
252 break;
253 }
254 case(DW2102_RC_QUERY): {
255 u8 ibuf[2];
256 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
257 ibuf, 2, DW210X_READ_MSG);
258 memcpy(msg[0].buf, ibuf , 2);
259 break;
260 }
261 case(DW2102_VOLTAGE_CTRL): {
262 u8 obuf[2];
263 obuf[0] = 0x30;
264 obuf[1] = msg[0].buf[0];
265 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
266 obuf, 2, DW210X_WRITE_MSG);
267 break;
268 }
269 }
270
271 break;
272 }
273
274 mutex_unlock(&d->i2c_mutex);
275 return num;
276}
277
278static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
279{
280 struct dvb_usb_device *d = i2c_get_adapdata(adap);
281 int ret = 0;
282 int len, i;
283
284 if (!d)
285 return -ENODEV;
286 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
287 return -EAGAIN;
288
289 switch (num) {
290 case 2: {
291 /* read */
292 /* first write first register number */
293 u8 ibuf [msg[1].len + 2], obuf[3];
294 obuf[0] = 0xaa;
295 obuf[1] = msg[0].len;
296 obuf[2] = msg[0].buf[0];
297 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
298 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
299 /* second read registers */
300 ret = dw210x_op_rw(d->udev, 0xc3, 0xab , 0,
301 ibuf, msg[1].len + 2, DW210X_READ_MSG);
302 memcpy(msg[1].buf, ibuf + 2, msg[1].len);
303
304 break;
305 }
306 case 1:
307 switch (msg[0].addr) {
308 case 0x55: {
309 if (msg[0].buf[0] == 0xf7) {
310 /* firmware */
311 /* Write in small blocks */
312 u8 obuf[19];
313 obuf[0] = 0xaa;
314 obuf[1] = 0x11;
315 obuf[2] = 0xf7;
316 len = msg[0].len - 1;
317 i = 1;
318 do {
319 memcpy(obuf + 3, msg[0].buf + i, (len > 16 ? 16 : len));
320 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
321 obuf, (len > 16 ? 16 : len) + 3, DW210X_WRITE_MSG);
322 i += 16;
323 len -= 16;
324 } while (len > 0);
325 } else {
326 /* write to register */
327 u8 obuf[msg[0].len + 2];
328 obuf[0] = 0xaa;
329 obuf[1] = msg[0].len;
330 memcpy(obuf + 2, msg[0].buf, msg[0].len);
331 ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
332 obuf, msg[0].len + 2, DW210X_WRITE_MSG);
333 }
334 break;
335 }
336 case(DW2102_RC_QUERY): {
337 u8 ibuf[2];
338 ret = dw210x_op_rw(d->udev, 0xb8, 0, 0,
339 ibuf, 2, DW210X_READ_MSG);
340 memcpy(msg[0].buf, ibuf , 2);
341 break;
342 }
343 case(DW2102_VOLTAGE_CTRL): {
344 u8 obuf[2];
345 obuf[0] = 0x30;
346 obuf[1] = msg[0].buf[0];
347 ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
348 obuf, 2, DW210X_WRITE_MSG);
349 break;
350 }
351 }
352
353 break;
354 }
355
356 mutex_unlock(&d->i2c_mutex);
357 return num;
358}
359
360static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
140{ 361{
141 return I2C_FUNC_I2C; 362 return I2C_FUNC_I2C;
142} 363}
143 364
144static struct i2c_algorithm dw2102_i2c_algo = { 365static struct i2c_algorithm dw2102_i2c_algo = {
145 .master_xfer = dw2102_i2c_transfer, 366 .master_xfer = dw2102_i2c_transfer,
146 .functionality = dw2102_i2c_func, 367 .functionality = dw210x_i2c_func,
368};
369
370static struct i2c_algorithm dw2102_serit_i2c_algo = {
371 .master_xfer = dw2102_serit_i2c_transfer,
372 .functionality = dw210x_i2c_func,
373};
374
375static struct i2c_algorithm dw2102_earda_i2c_algo = {
376 .master_xfer = dw2102_earda_i2c_transfer,
377 .functionality = dw210x_i2c_func,
378};
379
380static struct i2c_algorithm dw2104_i2c_algo = {
381 .master_xfer = dw2104_i2c_transfer,
382 .functionality = dw210x_i2c_func,
147}; 383};
148 384
149static int dw2102_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage) 385static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
386{
387 int i;
388 u8 ibuf[] = {0, 0};
389 u8 eeprom[256], eepromline[16];
390
391 for (i = 0; i < 256; i++) {
392 if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) {
393 err("read eeprom failed.");
394 return -1;
395 } else {
396 eepromline[i%16] = ibuf[0];
397 eeprom[i] = ibuf[0];
398 }
399 if ((i % 16) == 15) {
400 deb_xfer("%02x: ", i - 15);
401 debug_dump(eepromline, 16, deb_xfer);
402 }
403 }
404 memcpy(mac, eeprom + 8, 6);
405 return 0;
406};
407
408static int dw210x_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
150{ 409{
151 static u8 command_13v[1] = {0x00}; 410 static u8 command_13v[1] = {0x00};
152 static u8 command_18v[1] = {0x01}; 411 static u8 command_18v[1] = {0x01};
@@ -163,18 +422,66 @@ static int dw2102_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
163 return 0; 422 return 0;
164} 423}
165 424
166static int dw2102_frontend_attach(struct dvb_usb_adapter *d) 425static struct cx24116_config dw2104_config = {
426 .demod_address = 0x55,
427 .mpg_clk_pos_pol = 0x01,
428};
429
430static struct si21xx_config serit_sp1511lhb_config = {
431 .demod_address = 0x68,
432 .min_delay_ms = 100,
433
434};
435
436static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
167{ 437{
168 d->fe = dvb_attach(stv0299_attach, &sharp_z0194a_config, 438 if ((d->fe = dvb_attach(cx24116_attach, &dw2104_config,
169 &d->dev->i2c_adap); 439 &d->dev->i2c_adap)) != NULL) {
170 if (d->fe != NULL) { 440 d->fe->ops.set_voltage = dw210x_set_voltage;
171 d->fe->ops.set_voltage = dw2102_set_voltage; 441 info("Attached cx24116!\n");
172 info("Attached stv0299!\n");
173 return 0; 442 return 0;
174 } 443 }
175 return -EIO; 444 return -EIO;
176} 445}
177 446
447static struct dvb_usb_device_properties dw2102_properties;
448
449static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
450{
451 if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
452 /*dw2102_properties.adapter->tuner_attach = NULL;*/
453 d->fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
454 &d->dev->i2c_adap);
455 if (d->fe != NULL) {
456 d->fe->ops.set_voltage = dw210x_set_voltage;
457 info("Attached si21xx!\n");
458 return 0;
459 }
460 }
461 if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
462 /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
463 d->fe = dvb_attach(stv0288_attach, &earda_config,
464 &d->dev->i2c_adap);
465 if (d->fe != NULL) {
466 d->fe->ops.set_voltage = dw210x_set_voltage;
467 info("Attached stv0288!\n");
468 return 0;
469 }
470 }
471
472 if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
473 /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
474 d->fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
475 &d->dev->i2c_adap);
476 if (d->fe != NULL) {
477 d->fe->ops.set_voltage = dw210x_set_voltage;
478 info("Attached stv0299!\n");
479 return 0;
480 }
481 }
482 return -EIO;
483}
484
178static int dw2102_tuner_attach(struct dvb_usb_adapter *adap) 485static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
179{ 486{
180 dvb_attach(dvb_pll_attach, adap->fe, 0x60, 487 dvb_attach(dvb_pll_attach, adap->fe, 0x60,
@@ -182,7 +489,15 @@ static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
182 return 0; 489 return 0;
183} 490}
184 491
185static struct dvb_usb_rc_key dw2102_rc_keys[] = { 492static int dw2102_earda_tuner_attach(struct dvb_usb_adapter *adap)
493{
494 dvb_attach(stb6000_attach, adap->fe, 0x61,
495 &adap->dev->i2c_adap);
496
497 return 0;
498}
499
500static struct dvb_usb_rc_key dw210x_rc_keys[] = {
186 { 0xf8, 0x0a, KEY_Q }, /*power*/ 501 { 0xf8, 0x0a, KEY_Q }, /*power*/
187 { 0xf8, 0x0c, KEY_M }, /*mute*/ 502 { 0xf8, 0x0c, KEY_M }, /*mute*/
188 { 0xf8, 0x11, KEY_1 }, 503 { 0xf8, 0x11, KEY_1 },
@@ -221,7 +536,7 @@ static struct dvb_usb_rc_key dw2102_rc_keys[] = {
221 536
222static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 537static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
223{ 538{
224 struct dw2102_state *st = d->priv; 539 struct dw210x_state *st = d->priv;
225 u8 key[2]; 540 u8 key[2];
226 struct i2c_msg msg[] = { 541 struct i2c_msg msg[] = {
227 {.addr = DW2102_RC_QUERY, .flags = I2C_M_RD, .buf = key, 542 {.addr = DW2102_RC_QUERY, .flags = I2C_M_RD, .buf = key,
@@ -231,12 +546,12 @@ static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
231 546
232 *state = REMOTE_NO_KEY_PRESSED; 547 *state = REMOTE_NO_KEY_PRESSED;
233 if (dw2102_i2c_transfer(&d->i2c_adap, msg, 1) == 1) { 548 if (dw2102_i2c_transfer(&d->i2c_adap, msg, 1) == 1) {
234 for (i = 0; i < ARRAY_SIZE(dw2102_rc_keys); i++) { 549 for (i = 0; i < ARRAY_SIZE(dw210x_rc_keys); i++) {
235 if (dw2102_rc_keys[i].data == msg[0].buf[0]) { 550 if (dw210x_rc_keys[i].data == msg[0].buf[0]) {
236 *state = REMOTE_KEY_PRESSED; 551 *state = REMOTE_KEY_PRESSED;
237 *event = dw2102_rc_keys[i].event; 552 *event = dw210x_rc_keys[i].event;
238 st->last_key_pressed = 553 st->last_key_pressed =
239 dw2102_rc_keys[i].event; 554 dw210x_rc_keys[i].event;
240 break; 555 break;
241 } 556 }
242 st->last_key_pressed = 0; 557 st->last_key_pressed = 0;
@@ -249,6 +564,8 @@ static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
249static struct usb_device_id dw2102_table[] = { 564static struct usb_device_id dw2102_table[] = {
250 {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)}, 565 {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
251 {USB_DEVICE(USB_VID_CYPRESS, 0x2101)}, 566 {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
567 {USB_DEVICE(USB_VID_CYPRESS, 0x2104)},
568 {USB_DEVICE(0x9022, 0xd650)},
252 { } 569 { }
253}; 570};
254 571
@@ -260,7 +577,7 @@ static int dw2102_load_firmware(struct usb_device *dev,
260 u8 *b, *p; 577 u8 *b, *p;
261 int ret = 0, i; 578 int ret = 0, i;
262 u8 reset; 579 u8 reset;
263 u8 reset16 [] = {0, 0, 0, 0, 0, 0, 0}; 580 u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
264 const struct firmware *fw; 581 const struct firmware *fw;
265 const char *filename = "dvb-usb-dw2101.fw"; 582 const char *filename = "dvb-usb-dw2101.fw";
266 switch (dev->descriptor.idProduct) { 583 switch (dev->descriptor.idProduct) {
@@ -273,25 +590,23 @@ static int dw2102_load_firmware(struct usb_device *dev,
273 return ret; 590 return ret;
274 } 591 }
275 break; 592 break;
276 case USB_PID_DW2102: 593 default:
277 fw = frmwr; 594 fw = frmwr;
278 break; 595 break;
279 } 596 }
280 info("start downloading DW2102 firmware"); 597 info("start downloading DW210X firmware");
281 p = kmalloc(fw->size, GFP_KERNEL); 598 p = kmalloc(fw->size, GFP_KERNEL);
282 reset = 1; 599 reset = 1;
283 /*stop the CPU*/ 600 /*stop the CPU*/
284 dw2102_op_rw(dev, 0xa0, 0x7f92, &reset, 1, DW2102_WRITE_MSG); 601 dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
285 dw2102_op_rw(dev, 0xa0, 0xe600, &reset, 1, DW2102_WRITE_MSG); 602 dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
286 603
287 if (p != NULL) { 604 if (p != NULL) {
288 memcpy(p, fw->data, fw->size); 605 memcpy(p, fw->data, fw->size);
289 for (i = 0; i < fw->size; i += 0x40) { 606 for (i = 0; i < fw->size; i += 0x40) {
290 b = (u8 *) p + i; 607 b = (u8 *) p + i;
291 if (dw2102_op_rw 608 if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
292 (dev, 0xa0, i, b , 0x40, 609 DW210X_WRITE_MSG) != 0x40) {
293 DW2102_WRITE_MSG) != 0x40
294 ) {
295 err("error while transferring firmware"); 610 err("error while transferring firmware");
296 ret = -EINVAL; 611 ret = -EINVAL;
297 break; 612 break;
@@ -299,43 +614,66 @@ static int dw2102_load_firmware(struct usb_device *dev,
299 } 614 }
300 /* restart the CPU */ 615 /* restart the CPU */
301 reset = 0; 616 reset = 0;
302 if (ret || dw2102_op_rw 617 if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
303 (dev, 0xa0, 0x7f92, &reset, 1, 618 DW210X_WRITE_MSG) != 1) {
304 DW2102_WRITE_MSG) != 1) {
305 err("could not restart the USB controller CPU."); 619 err("could not restart the USB controller CPU.");
306 ret = -EINVAL; 620 ret = -EINVAL;
307 } 621 }
308 if (ret || dw2102_op_rw 622 if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
309 (dev, 0xa0, 0xe600, &reset, 1, 623 DW210X_WRITE_MSG) != 1) {
310 DW2102_WRITE_MSG) != 1) {
311 err("could not restart the USB controller CPU."); 624 err("could not restart the USB controller CPU.");
312 ret = -EINVAL; 625 ret = -EINVAL;
313 } 626 }
314 /* init registers */ 627 /* init registers */
315 switch (dev->descriptor.idProduct) { 628 switch (dev->descriptor.idProduct) {
316 case USB_PID_DW2102: 629 case USB_PID_DW2104:
317 dw2102_op_rw 630 case 0xd650:
318 (dev, 0xbf, 0x0040, &reset, 0, 631 reset = 1;
319 DW2102_WRITE_MSG); 632 dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
320 dw2102_op_rw 633 DW210X_WRITE_MSG);
321 (dev, 0xb9, 0x0000, &reset16[0], 2, 634 reset = 0;
322 DW2102_READ_MSG); 635 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
636 DW210X_WRITE_MSG);
323 break; 637 break;
638 case USB_PID_DW2102:
639 dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
640 DW210X_WRITE_MSG);
641 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
642 DW210X_READ_MSG);
643 /* check STV0299 frontend */
644 dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
645 DW210X_READ_MSG);
646 if (reset16[0] == 0xa1) {
647 dw2102_properties.i2c_algo = &dw2102_i2c_algo;
648 dw2102_properties.adapter->tuner_attach = &dw2102_tuner_attach;
649 break;
650 } else {
651 /* check STV0288 frontend */
652 reset16[0] = 0xd0;
653 reset16[1] = 1;
654 reset16[2] = 0;
655 dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
656 DW210X_WRITE_MSG);
657 dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
658 DW210X_READ_MSG);
659 if (reset16[2] == 0x11) {
660 dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
661 dw2102_properties.adapter->tuner_attach = &dw2102_earda_tuner_attach;
662 break;
663 }
664 }
324 case 0x2101: 665 case 0x2101:
325 dw2102_op_rw 666 dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
326 (dev, 0xbc, 0x0030, &reset16[0], 2, 667 DW210X_READ_MSG);
327 DW2102_READ_MSG); 668 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
328 dw2102_op_rw 669 DW210X_READ_MSG);
329 (dev, 0xba, 0x0000, &reset16[0], 7, 670 dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
330 DW2102_READ_MSG); 671 DW210X_READ_MSG);
331 dw2102_op_rw 672 dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
332 (dev, 0xba, 0x0000, &reset16[0], 7, 673 DW210X_READ_MSG);
333 DW2102_READ_MSG);
334 dw2102_op_rw
335 (dev, 0xb9, 0x0000, &reset16[0], 2,
336 DW2102_READ_MSG);
337 break; 674 break;
338 } 675 }
676 msleep(100);
339 kfree(p); 677 kfree(p);
340 } 678 }
341 return ret; 679 return ret;
@@ -345,12 +683,12 @@ static struct dvb_usb_device_properties dw2102_properties = {
345 .caps = DVB_USB_IS_AN_I2C_ADAPTER, 683 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
346 .usb_ctrl = DEVICE_SPECIFIC, 684 .usb_ctrl = DEVICE_SPECIFIC,
347 .firmware = "dvb-usb-dw2102.fw", 685 .firmware = "dvb-usb-dw2102.fw",
348 .size_of_priv = sizeof(struct dw2102_state), 686 .size_of_priv = sizeof(struct dw210x_state),
349 .no_reconnect = 1, 687 .no_reconnect = 1,
350 688
351 .i2c_algo = &dw2102_i2c_algo, 689 .i2c_algo = &dw2102_serit_i2c_algo,
352 .rc_key_map = dw2102_rc_keys, 690 .rc_key_map = dw210x_rc_keys,
353 .rc_key_map_size = ARRAY_SIZE(dw2102_rc_keys), 691 .rc_key_map_size = ARRAY_SIZE(dw210x_rc_keys),
354 .rc_interval = 150, 692 .rc_interval = 150,
355 .rc_query = dw2102_rc_query, 693 .rc_query = dw2102_rc_query,
356 694
@@ -358,11 +696,12 @@ static struct dvb_usb_device_properties dw2102_properties = {
358 /* parameter for the MPEG2-data transfer */ 696 /* parameter for the MPEG2-data transfer */
359 .num_adapters = 1, 697 .num_adapters = 1,
360 .download_firmware = dw2102_load_firmware, 698 .download_firmware = dw2102_load_firmware,
361 .adapter = { 699 .read_mac_address = dw210x_read_mac_address,
700 .adapter = {
362 { 701 {
363 .frontend_attach = dw2102_frontend_attach, 702 .frontend_attach = dw2102_frontend_attach,
364 .streaming_ctrl = NULL, 703 .streaming_ctrl = NULL,
365 .tuner_attach = dw2102_tuner_attach, 704 .tuner_attach = NULL,
366 .stream = { 705 .stream = {
367 .type = USB_BULK, 706 .type = USB_BULK,
368 .count = 8, 707 .count = 8,
@@ -388,11 +727,64 @@ static struct dvb_usb_device_properties dw2102_properties = {
388 } 727 }
389}; 728};
390 729
730static struct dvb_usb_device_properties dw2104_properties = {
731 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
732 .usb_ctrl = DEVICE_SPECIFIC,
733 .firmware = "dvb-usb-dw2104.fw",
734 .size_of_priv = sizeof(struct dw210x_state),
735 .no_reconnect = 1,
736
737 .i2c_algo = &dw2104_i2c_algo,
738 .rc_key_map = dw210x_rc_keys,
739 .rc_key_map_size = ARRAY_SIZE(dw210x_rc_keys),
740 .rc_interval = 150,
741 .rc_query = dw2102_rc_query,
742
743 .generic_bulk_ctrl_endpoint = 0x81,
744 /* parameter for the MPEG2-data transfer */
745 .num_adapters = 1,
746 .download_firmware = dw2102_load_firmware,
747 .read_mac_address = dw210x_read_mac_address,
748 .adapter = {
749 {
750 .frontend_attach = dw2104_frontend_attach,
751 .streaming_ctrl = NULL,
752 /*.tuner_attach = dw2104_tuner_attach,*/
753 .stream = {
754 .type = USB_BULK,
755 .count = 8,
756 .endpoint = 0x82,
757 .u = {
758 .bulk = {
759 .buffersize = 4096,
760 }
761 }
762 },
763 }
764 },
765 .num_device_descs = 2,
766 .devices = {
767 { "DVBWorld DW2104 USB2.0",
768 {&dw2102_table[2], NULL},
769 {NULL},
770 },
771 { "TeVii S650 USB2.0",
772 {&dw2102_table[3], NULL},
773 {NULL},
774 },
775 }
776};
777
391static int dw2102_probe(struct usb_interface *intf, 778static int dw2102_probe(struct usb_interface *intf,
392 const struct usb_device_id *id) 779 const struct usb_device_id *id)
393{ 780{
394 return dvb_usb_device_init(intf, &dw2102_properties, 781 if (0 == dvb_usb_device_init(intf, &dw2102_properties,
395 THIS_MODULE, NULL, adapter_nr); 782 THIS_MODULE, NULL, adapter_nr) ||
783 0 == dvb_usb_device_init(intf, &dw2104_properties,
784 THIS_MODULE, NULL, adapter_nr)) {
785 return 0;
786 }
787 return -ENODEV;
396} 788}
397 789
398static struct usb_driver dw2102_driver = { 790static struct usb_driver dw2102_driver = {
@@ -420,6 +812,6 @@ module_init(dw2102_module_init);
420module_exit(dw2102_module_exit); 812module_exit(dw2102_module_exit);
421 813
422MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by"); 814MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
423MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101 2102 USB2.0 device"); 815MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104 USB2.0 device");
424MODULE_VERSION("0.1"); 816MODULE_VERSION("0.1");
425MODULE_LICENSE("GPL"); 817MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/dw2102.h b/drivers/media/dvb/dvb-usb/dw2102.h
index 7a310f906837..e3370734e95a 100644
--- a/drivers/media/dvb/dvb-usb/dw2102.h
+++ b/drivers/media/dvb/dvb-usb/dw2102.h
@@ -4,6 +4,5 @@
4#define DVB_USB_LOG_PREFIX "dw2102" 4#define DVB_USB_LOG_PREFIX "dw2102"
5#include "dvb-usb.h" 5#include "dvb-usb.h"
6 6
7extern int dvb_usb_dw2102_debug;
8#define deb_xfer(args...) dprintk(dvb_usb_dw2102_debug, 0x02, args) 7#define deb_xfer(args...) dprintk(dvb_usb_dw2102_debug, 0x02, args)
9#endif 8#endif
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index 7dbb4a223c99..96b93e21a84b 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -43,6 +43,20 @@ config DVB_S5H1420
43 help 43 help
44 A DVB-S tuner module. Say Y when you want to support this frontend. 44 A DVB-S tuner module. Say Y when you want to support this frontend.
45 45
46config DVB_STV0288
47 tristate "ST STV0288 based"
48 depends on DVB_CORE && I2C
49 default m if DVB_FE_CUSTOMISE
50 help
51 A DVB-S tuner module. Say Y when you want to support this frontend.
52
53config DVB_STB6000
54 tristate "ST STB6000 silicon tuner"
55 depends on DVB_CORE && I2C
56 default m if DVB_FE_CUSTOMISE
57 help
58 A DVB-S silicon tuner module. Say Y when you want to support this tuner.
59
46config DVB_STV0299 60config DVB_STV0299
47 tristate "ST STV0299 based" 61 tristate "ST STV0299 based"
48 depends on DVB_CORE && I2C 62 depends on DVB_CORE && I2C
@@ -92,6 +106,20 @@ config DVB_TUA6100
92 help 106 help
93 A DVB-S PLL chip. 107 A DVB-S PLL chip.
94 108
109config DVB_CX24116
110 tristate "Conexant CX24116 based"
111 depends on DVB_CORE && I2C
112 default m if DVB_FE_CUSTOMISE
113 help
114 A DVB-S/S2 tuner module. Say Y when you want to support this frontend.
115
116config DVB_SI21XX
117 tristate "Silicon Labs SI21XX based"
118 depends on DVB_CORE && I2C
119 default m if DVB_FE_CUSTOMISE
120 help
121 A DVB-S tuner module. Say Y when you want to support this frontend.
122
95comment "DVB-T (terrestrial) frontends" 123comment "DVB-T (terrestrial) frontends"
96 depends on DVB_CORE 124 depends on DVB_CORE
97 125
@@ -385,4 +413,23 @@ config DVB_ISL6421
385 help 413 help
386 An SEC control chip. 414 An SEC control chip.
387 415
416config DVB_LGS8GL5
417 tristate "Silicon Legend LGS-8GL5 demodulator (OFDM)"
418 depends on DVB_CORE && I2C
419 default m if DVB_FE_CUSTOMISE
420 help
421 A DMB-TH tuner module. Say Y when you want to support this frontend.
422
423comment "Tools to develop new frontends"
424
425config DVB_DUMMY_FE
426 tristate "Dummy frontend driver"
427 default n
428
429config DVB_AF9013
430 tristate "Afatech AF9013 demodulator"
431 depends on DVB_CORE && I2C
432 default m if DVB_FE_CUSTOMISE
433 help
434 Say Y when you want to support this frontend.
388endmenu 435endmenu
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index 028da55611c0..aba79f4a63a7 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -48,3 +48,10 @@ obj-$(CONFIG_DVB_TUNER_ITD1000) += itd1000.o
48obj-$(CONFIG_DVB_AU8522) += au8522.o 48obj-$(CONFIG_DVB_AU8522) += au8522.o
49obj-$(CONFIG_DVB_TDA10048) += tda10048.o 49obj-$(CONFIG_DVB_TDA10048) += tda10048.o
50obj-$(CONFIG_DVB_S5H1411) += s5h1411.o 50obj-$(CONFIG_DVB_S5H1411) += s5h1411.o
51obj-$(CONFIG_DVB_LGS8GL5) += lgs8gl5.o
52obj-$(CONFIG_DVB_DUMMY_FE) += dvb_dummy_fe.o
53obj-$(CONFIG_DVB_AF9013) += af9013.o
54obj-$(CONFIG_DVB_CX24116) += cx24116.o
55obj-$(CONFIG_DVB_SI21XX) += si21xx.o
56obj-$(CONFIG_DVB_STV0288) += stv0288.o
57obj-$(CONFIG_DVB_STB6000) += stb6000.o
diff --git a/drivers/media/dvb/frontends/af9013.c b/drivers/media/dvb/frontends/af9013.c
new file mode 100644
index 000000000000..21c1060cf10e
--- /dev/null
+++ b/drivers/media/dvb/frontends/af9013.c
@@ -0,0 +1,1685 @@
1/*
2 * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver
3 *
4 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
5 *
6 * Thanks to Afatech who kindly provided information.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 */
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/init.h>
28#include <linux/delay.h>
29#include <linux/string.h>
30#include <linux/slab.h>
31#include <linux/firmware.h>
32
33#include "dvb_frontend.h"
34#include "af9013_priv.h"
35#include "af9013.h"
36
37int af9013_debug;
38
39struct af9013_state {
40 struct i2c_adapter *i2c;
41 struct dvb_frontend frontend;
42
43 struct af9013_config config;
44
45 u16 signal_strength;
46 u32 ber;
47 u32 ucblocks;
48 u16 snr;
49 u32 frequency;
50 unsigned long next_statistics_check;
51};
52
53static u8 regmask[8] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
54
55static int af9013_write_regs(struct af9013_state *state, u8 mbox, u16 reg,
56 u8 *val, u8 len)
57{
58 u8 buf[3+len];
59 struct i2c_msg msg = {
60 .addr = state->config.demod_address,
61 .flags = 0,
62 .len = sizeof(buf),
63 .buf = buf };
64
65 buf[0] = reg >> 8;
66 buf[1] = reg & 0xff;
67 buf[2] = mbox;
68 memcpy(&buf[3], val, len);
69
70 if (i2c_transfer(state->i2c, &msg, 1) != 1) {
71 warn("I2C write failed reg:%04x len:%d", reg, len);
72 return -EREMOTEIO;
73 }
74 return 0;
75}
76
77static int af9013_write_ofdm_regs(struct af9013_state *state, u16 reg, u8 *val,
78 u8 len)
79{
80 u8 mbox = (1 << 0)|(1 << 1)|((len - 1) << 2)|(0 << 6)|(0 << 7);
81 return af9013_write_regs(state, mbox, reg, val, len);
82}
83
84static int af9013_write_ofsm_regs(struct af9013_state *state, u16 reg, u8 *val,
85 u8 len)
86{
87 u8 mbox = (1 << 0)|(1 << 1)|((len - 1) << 2)|(1 << 6)|(1 << 7);
88 return af9013_write_regs(state, mbox, reg, val, len);
89}
90
91/* write single register */
92static int af9013_write_reg(struct af9013_state *state, u16 reg, u8 val)
93{
94 return af9013_write_ofdm_regs(state, reg, &val, 1);
95}
96
97/* read single register */
98static int af9013_read_reg(struct af9013_state *state, u16 reg, u8 *val)
99{
100 u8 obuf[3] = { reg >> 8, reg & 0xff, 0 };
101 u8 ibuf[1];
102 struct i2c_msg msg[2] = {
103 {
104 .addr = state->config.demod_address,
105 .flags = 0,
106 .len = sizeof(obuf),
107 .buf = obuf
108 }, {
109 .addr = state->config.demod_address,
110 .flags = I2C_M_RD,
111 .len = sizeof(ibuf),
112 .buf = ibuf
113 }
114 };
115
116 if (i2c_transfer(state->i2c, msg, 2) != 2) {
117 warn("I2C read failed reg:%04x", reg);
118 return -EREMOTEIO;
119 }
120 *val = ibuf[0];
121 return 0;
122}
123
124static int af9013_write_reg_bits(struct af9013_state *state, u16 reg, u8 pos,
125 u8 len, u8 val)
126{
127 int ret;
128 u8 tmp, mask;
129
130 ret = af9013_read_reg(state, reg, &tmp);
131 if (ret)
132 return ret;
133
134 mask = regmask[len - 1] << pos;
135 tmp = (tmp & ~mask) | ((val << pos) & mask);
136
137 return af9013_write_reg(state, reg, tmp);
138}
139
140static int af9013_read_reg_bits(struct af9013_state *state, u16 reg, u8 pos,
141 u8 len, u8 *val)
142{
143 int ret;
144 u8 tmp;
145
146 ret = af9013_read_reg(state, reg, &tmp);
147 if (ret)
148 return ret;
149 *val = (tmp >> pos) & regmask[len - 1];
150 return 0;
151}
152
153static int af9013_set_gpio(struct af9013_state *state, u8 gpio, u8 gpioval)
154{
155 int ret;
156 u8 pos;
157 u16 addr;
158 deb_info("%s: gpio:%d gpioval:%02x\n", __func__, gpio, gpioval);
159
160/* GPIO0 & GPIO1 0xd735
161 GPIO2 & GPIO3 0xd736 */
162
163 switch (gpio) {
164 case 0:
165 case 1:
166 addr = 0xd735;
167 break;
168 case 2:
169 case 3:
170 addr = 0xd736;
171 break;
172
173 default:
174 err("invalid gpio:%d\n", gpio);
175 ret = -EINVAL;
176 goto error;
177 };
178
179 switch (gpio) {
180 case 0:
181 case 2:
182 pos = 0;
183 break;
184 case 1:
185 case 3:
186 default:
187 pos = 4;
188 break;
189 };
190
191 ret = af9013_write_reg_bits(state, addr, pos, 4, gpioval);
192
193error:
194 return ret;
195}
196
197static u32 af913_div(u32 a, u32 b, u32 x)
198{
199 u32 r = 0, c = 0, i;
200 deb_info("%s: a:%d b:%d x:%d\n", __func__, a, b, x);
201
202 if (a > b) {
203 c = a / b;
204 a = a - c * b;
205 }
206
207 for (i = 0; i < x; i++) {
208 if (a >= b) {
209 r += 1;
210 a -= b;
211 }
212 a <<= 1;
213 r <<= 1;
214 }
215 r = (c << (u32)x) + r;
216
217 deb_info("%s: a:%d b:%d x:%d r:%d r:%x\n", __func__, a, b, x, r, r);
218 return r;
219}
220
221static int af9013_set_coeff(struct af9013_state *state, fe_bandwidth_t bw)
222{
223 int ret = 0;
224 u8 i = 0;
225 u8 buf[24];
226 u32 ns_coeff1_2048nu;
227 u32 ns_coeff1_8191nu;
228 u32 ns_coeff1_8192nu;
229 u32 ns_coeff1_8193nu;
230 u32 ns_coeff2_2k;
231 u32 ns_coeff2_8k;
232
233 deb_info("%s: adc_clock:%d bw:%d\n", __func__,
234 state->config.adc_clock, bw);
235
236 switch (state->config.adc_clock) {
237 case 28800: /* 28.800 MHz */
238 switch (bw) {
239 case BANDWIDTH_6_MHZ:
240 ns_coeff1_2048nu = 0x01e79e7a;
241 ns_coeff1_8191nu = 0x0079eb6e;
242 ns_coeff1_8192nu = 0x0079e79e;
243 ns_coeff1_8193nu = 0x0079e3cf;
244 ns_coeff2_2k = 0x00f3cf3d;
245 ns_coeff2_8k = 0x003cf3cf;
246 break;
247 case BANDWIDTH_7_MHZ:
248 ns_coeff1_2048nu = 0x0238e38e;
249 ns_coeff1_8191nu = 0x008e3d55;
250 ns_coeff1_8192nu = 0x008e38e4;
251 ns_coeff1_8193nu = 0x008e3472;
252 ns_coeff2_2k = 0x011c71c7;
253 ns_coeff2_8k = 0x00471c72;
254 break;
255 case BANDWIDTH_8_MHZ:
256 ns_coeff1_2048nu = 0x028a28a3;
257 ns_coeff1_8191nu = 0x00a28f3d;
258 ns_coeff1_8192nu = 0x00a28a29;
259 ns_coeff1_8193nu = 0x00a28514;
260 ns_coeff2_2k = 0x01451451;
261 ns_coeff2_8k = 0x00514514;
262 break;
263 default:
264 ret = -EINVAL;
265 }
266 break;
267 case 20480: /* 20.480 MHz */
268 switch (bw) {
269 case BANDWIDTH_6_MHZ:
270 ns_coeff1_2048nu = 0x02adb6dc;
271 ns_coeff1_8191nu = 0x00ab7313;
272 ns_coeff1_8192nu = 0x00ab6db7;
273 ns_coeff1_8193nu = 0x00ab685c;
274 ns_coeff2_2k = 0x0156db6e;
275 ns_coeff2_8k = 0x0055b6dc;
276 break;
277 case BANDWIDTH_7_MHZ:
278 ns_coeff1_2048nu = 0x03200001;
279 ns_coeff1_8191nu = 0x00c80640;
280 ns_coeff1_8192nu = 0x00c80000;
281 ns_coeff1_8193nu = 0x00c7f9c0;
282 ns_coeff2_2k = 0x01900000;
283 ns_coeff2_8k = 0x00640000;
284 break;
285 case BANDWIDTH_8_MHZ:
286 ns_coeff1_2048nu = 0x03924926;
287 ns_coeff1_8191nu = 0x00e4996e;
288 ns_coeff1_8192nu = 0x00e49249;
289 ns_coeff1_8193nu = 0x00e48b25;
290 ns_coeff2_2k = 0x01c92493;
291 ns_coeff2_8k = 0x00724925;
292 break;
293 default:
294 ret = -EINVAL;
295 }
296 break;
297 case 28000: /* 28.000 MHz */
298 switch (bw) {
299 case BANDWIDTH_6_MHZ:
300 ns_coeff1_2048nu = 0x01f58d10;
301 ns_coeff1_8191nu = 0x007d672f;
302 ns_coeff1_8192nu = 0x007d6344;
303 ns_coeff1_8193nu = 0x007d5f59;
304 ns_coeff2_2k = 0x00fac688;
305 ns_coeff2_8k = 0x003eb1a2;
306 break;
307 case BANDWIDTH_7_MHZ:
308 ns_coeff1_2048nu = 0x02492492;
309 ns_coeff1_8191nu = 0x00924db7;
310 ns_coeff1_8192nu = 0x00924925;
311 ns_coeff1_8193nu = 0x00924492;
312 ns_coeff2_2k = 0x01249249;
313 ns_coeff2_8k = 0x00492492;
314 break;
315 case BANDWIDTH_8_MHZ:
316 ns_coeff1_2048nu = 0x029cbc15;
317 ns_coeff1_8191nu = 0x00a7343f;
318 ns_coeff1_8192nu = 0x00a72f05;
319 ns_coeff1_8193nu = 0x00a729cc;
320 ns_coeff2_2k = 0x014e5e0a;
321 ns_coeff2_8k = 0x00539783;
322 break;
323 default:
324 ret = -EINVAL;
325 }
326 break;
327 case 25000: /* 25.000 MHz */
328 switch (bw) {
329 case BANDWIDTH_6_MHZ:
330 ns_coeff1_2048nu = 0x0231bcb5;
331 ns_coeff1_8191nu = 0x008c7391;
332 ns_coeff1_8192nu = 0x008c6f2d;
333 ns_coeff1_8193nu = 0x008c6aca;
334 ns_coeff2_2k = 0x0118de5b;
335 ns_coeff2_8k = 0x00463797;
336 break;
337 case BANDWIDTH_7_MHZ:
338 ns_coeff1_2048nu = 0x028f5c29;
339 ns_coeff1_8191nu = 0x00a3dc29;
340 ns_coeff1_8192nu = 0x00a3d70a;
341 ns_coeff1_8193nu = 0x00a3d1ec;
342 ns_coeff2_2k = 0x0147ae14;
343 ns_coeff2_8k = 0x0051eb85;
344 break;
345 case BANDWIDTH_8_MHZ:
346 ns_coeff1_2048nu = 0x02ecfb9d;
347 ns_coeff1_8191nu = 0x00bb44c1;
348 ns_coeff1_8192nu = 0x00bb3ee7;
349 ns_coeff1_8193nu = 0x00bb390d;
350 ns_coeff2_2k = 0x01767dce;
351 ns_coeff2_8k = 0x005d9f74;
352 break;
353 default:
354 ret = -EINVAL;
355 }
356 break;
357 default:
358 err("invalid xtal");
359 return -EINVAL;
360 }
361 if (ret) {
362 err("invalid bandwidth");
363 return ret;
364 }
365
366 buf[i++] = (u8) ((ns_coeff1_2048nu & 0x03000000) >> 24);
367 buf[i++] = (u8) ((ns_coeff1_2048nu & 0x00ff0000) >> 16);
368 buf[i++] = (u8) ((ns_coeff1_2048nu & 0x0000ff00) >> 8);
369 buf[i++] = (u8) ((ns_coeff1_2048nu & 0x000000ff));
370 buf[i++] = (u8) ((ns_coeff2_2k & 0x01c00000) >> 22);
371 buf[i++] = (u8) ((ns_coeff2_2k & 0x003fc000) >> 14);
372 buf[i++] = (u8) ((ns_coeff2_2k & 0x00003fc0) >> 6);
373 buf[i++] = (u8) ((ns_coeff2_2k & 0x0000003f));
374 buf[i++] = (u8) ((ns_coeff1_8191nu & 0x03000000) >> 24);
375 buf[i++] = (u8) ((ns_coeff1_8191nu & 0x00ffc000) >> 16);
376 buf[i++] = (u8) ((ns_coeff1_8191nu & 0x0000ff00) >> 8);
377 buf[i++] = (u8) ((ns_coeff1_8191nu & 0x000000ff));
378 buf[i++] = (u8) ((ns_coeff1_8192nu & 0x03000000) >> 24);
379 buf[i++] = (u8) ((ns_coeff1_8192nu & 0x00ffc000) >> 16);
380 buf[i++] = (u8) ((ns_coeff1_8192nu & 0x0000ff00) >> 8);
381 buf[i++] = (u8) ((ns_coeff1_8192nu & 0x000000ff));
382 buf[i++] = (u8) ((ns_coeff1_8193nu & 0x03000000) >> 24);
383 buf[i++] = (u8) ((ns_coeff1_8193nu & 0x00ffc000) >> 16);
384 buf[i++] = (u8) ((ns_coeff1_8193nu & 0x0000ff00) >> 8);
385 buf[i++] = (u8) ((ns_coeff1_8193nu & 0x000000ff));
386 buf[i++] = (u8) ((ns_coeff2_8k & 0x01c00000) >> 22);
387 buf[i++] = (u8) ((ns_coeff2_8k & 0x003fc000) >> 14);
388 buf[i++] = (u8) ((ns_coeff2_8k & 0x00003fc0) >> 6);
389 buf[i++] = (u8) ((ns_coeff2_8k & 0x0000003f));
390
391 deb_info("%s: coeff:", __func__);
392 debug_dump(buf, sizeof(buf), deb_info);
393
394 /* program */
395 for (i = 0; i < sizeof(buf); i++) {
396 ret = af9013_write_reg(state, 0xae00 + i, buf[i]);
397 if (ret)
398 break;
399 }
400
401 return ret;
402}
403
404static int af9013_set_adc_ctrl(struct af9013_state *state)
405{
406 int ret;
407 u8 buf[3], tmp, i;
408 u32 adc_cw;
409
410 deb_info("%s: adc_clock:%d\n", __func__, state->config.adc_clock);
411
412 /* adc frequency type */
413 switch (state->config.adc_clock) {
414 case 28800: /* 28.800 MHz */
415 tmp = 0;
416 break;
417 case 20480: /* 20.480 MHz */
418 tmp = 1;
419 break;
420 case 28000: /* 28.000 MHz */
421 tmp = 2;
422 break;
423 case 25000: /* 25.000 MHz */
424 tmp = 3;
425 break;
426 default:
427 err("invalid xtal");
428 return -EINVAL;
429 }
430
431 adc_cw = af913_div(state->config.adc_clock*1000, 1000000ul, 19ul);
432
433 buf[0] = (u8) ((adc_cw & 0x000000ff));
434 buf[1] = (u8) ((adc_cw & 0x0000ff00) >> 8);
435 buf[2] = (u8) ((adc_cw & 0x00ff0000) >> 16);
436
437 deb_info("%s: adc_cw:", __func__);
438 debug_dump(buf, sizeof(buf), deb_info);
439
440 /* program */
441 for (i = 0; i < sizeof(buf); i++) {
442 ret = af9013_write_reg(state, 0xd180 + i, buf[i]);
443 if (ret)
444 goto error;
445 }
446 ret = af9013_write_reg_bits(state, 0x9bd2, 0, 4, tmp);
447error:
448 return ret;
449}
450
451static int af9013_set_freq_ctrl(struct af9013_state *state, fe_bandwidth_t bw)
452{
453 int ret;
454 u16 addr;
455 u8 buf[3], i, j;
456 u32 adc_freq, freq_cw;
457 s8 bfs_spec_inv;
458 int if_sample_freq;
459
460 for (j = 0; j < 3; j++) {
461 if (j == 0) {
462 addr = 0xd140; /* fcw normal */
463 bfs_spec_inv = state->config.rf_spec_inv ? -1 : 1;
464 } else if (j == 1) {
465 addr = 0x9be7; /* fcw dummy ram */
466 bfs_spec_inv = state->config.rf_spec_inv ? -1 : 1;
467 } else {
468 addr = 0x9bea; /* fcw inverted */
469 bfs_spec_inv = state->config.rf_spec_inv ? 1 : -1;
470 }
471
472 adc_freq = state->config.adc_clock * 1000;
473 if_sample_freq = state->config.tuner_if * 1000;
474
475 /* TDA18271 uses different sampling freq for every bw */
476 if (state->config.tuner == AF9013_TUNER_TDA18271) {
477 switch (bw) {
478 case BANDWIDTH_6_MHZ:
479 if_sample_freq = 3300000; /* 3.3 MHz */
480 break;
481 case BANDWIDTH_7_MHZ:
482 if_sample_freq = 3800000; /* 3.8 MHz */
483 break;
484 case BANDWIDTH_8_MHZ:
485 default:
486 if_sample_freq = 4300000; /* 4.3 MHz */
487 break;
488 }
489 }
490
491 while (if_sample_freq > (adc_freq / 2))
492 if_sample_freq = if_sample_freq - adc_freq;
493
494 if (if_sample_freq >= 0)
495 bfs_spec_inv = bfs_spec_inv * (-1);
496 else
497 if_sample_freq = if_sample_freq * (-1);
498
499 freq_cw = af913_div(if_sample_freq, adc_freq, 23ul);
500
501 if (bfs_spec_inv == -1)
502 freq_cw = 0x00800000 - freq_cw;
503
504 buf[0] = (u8) ((freq_cw & 0x000000ff));
505 buf[1] = (u8) ((freq_cw & 0x0000ff00) >> 8);
506 buf[2] = (u8) ((freq_cw & 0x007f0000) >> 16);
507
508
509 deb_info("%s: freq_cw:", __func__);
510 debug_dump(buf, sizeof(buf), deb_info);
511
512 /* program */
513 for (i = 0; i < sizeof(buf); i++) {
514 ret = af9013_write_reg(state, addr++, buf[i]);
515 if (ret)
516 goto error;
517 }
518 }
519error:
520 return ret;
521}
522
523static int af9013_set_ofdm_params(struct af9013_state *state,
524 struct dvb_ofdm_parameters *params, u8 *auto_mode)
525{
526 int ret;
527 u8 i, buf[3] = {0, 0, 0};
528 *auto_mode = 0; /* set if parameters are requested to auto set */
529
530 switch (params->transmission_mode) {
531 case TRANSMISSION_MODE_AUTO:
532 *auto_mode = 1;
533 case TRANSMISSION_MODE_2K:
534 break;
535 case TRANSMISSION_MODE_8K:
536 buf[0] |= (1 << 0);
537 break;
538 default:
539 return -EINVAL;
540 }
541
542 switch (params->guard_interval) {
543 case GUARD_INTERVAL_AUTO:
544 *auto_mode = 1;
545 case GUARD_INTERVAL_1_32:
546 break;
547 case GUARD_INTERVAL_1_16:
548 buf[0] |= (1 << 2);
549 break;
550 case GUARD_INTERVAL_1_8:
551 buf[0] |= (2 << 2);
552 break;
553 case GUARD_INTERVAL_1_4:
554 buf[0] |= (3 << 2);
555 break;
556 default:
557 return -EINVAL;
558 }
559
560 switch (params->hierarchy_information) {
561 case HIERARCHY_AUTO:
562 *auto_mode = 1;
563 case HIERARCHY_NONE:
564 break;
565 case HIERARCHY_1:
566 buf[0] |= (1 << 4);
567 break;
568 case HIERARCHY_2:
569 buf[0] |= (2 << 4);
570 break;
571 case HIERARCHY_4:
572 buf[0] |= (3 << 4);
573 break;
574 default:
575 return -EINVAL;
576 };
577
578 switch (params->constellation) {
579 case QAM_AUTO:
580 *auto_mode = 1;
581 case QPSK:
582 break;
583 case QAM_16:
584 buf[1] |= (1 << 6);
585 break;
586 case QAM_64:
587 buf[1] |= (2 << 6);
588 break;
589 default:
590 return -EINVAL;
591 }
592
593 /* Use HP. How and which case we can switch to LP? */
594 buf[1] |= (1 << 4);
595
596 switch (params->code_rate_HP) {
597 case FEC_AUTO:
598 *auto_mode = 1;
599 case FEC_1_2:
600 break;
601 case FEC_2_3:
602 buf[2] |= (1 << 0);
603 break;
604 case FEC_3_4:
605 buf[2] |= (2 << 0);
606 break;
607 case FEC_5_6:
608 buf[2] |= (3 << 0);
609 break;
610 case FEC_7_8:
611 buf[2] |= (4 << 0);
612 break;
613 default:
614 return -EINVAL;
615 }
616
617 switch (params->code_rate_LP) {
618 case FEC_AUTO:
619 /* if HIERARCHY_NONE and FEC_NONE then LP FEC is set to FEC_AUTO
620 by dvb_frontend.c for compatibility */
621 if (params->hierarchy_information != HIERARCHY_NONE)
622 *auto_mode = 1;
623 case FEC_1_2:
624 break;
625 case FEC_2_3:
626 buf[2] |= (1 << 3);
627 break;
628 case FEC_3_4:
629 buf[2] |= (2 << 3);
630 break;
631 case FEC_5_6:
632 buf[2] |= (3 << 3);
633 break;
634 case FEC_7_8:
635 buf[2] |= (4 << 3);
636 break;
637 case FEC_NONE:
638 if (params->hierarchy_information == HIERARCHY_AUTO)
639 break;
640 default:
641 return -EINVAL;
642 }
643
644 switch (params->bandwidth) {
645 case BANDWIDTH_6_MHZ:
646 break;
647 case BANDWIDTH_7_MHZ:
648 buf[1] |= (1 << 2);
649 break;
650 case BANDWIDTH_8_MHZ:
651 buf[1] |= (2 << 2);
652 break;
653 default:
654 return -EINVAL;
655 }
656
657 /* program */
658 for (i = 0; i < sizeof(buf); i++) {
659 ret = af9013_write_reg(state, 0xd3c0 + i, buf[i]);
660 if (ret)
661 break;
662 }
663
664 return ret;
665}
666
667static int af9013_reset(struct af9013_state *state, u8 sleep)
668{
669 int ret;
670 u8 tmp, i;
671 deb_info("%s\n", __func__);
672
673 /* enable OFDM reset */
674 ret = af9013_write_reg_bits(state, 0xd417, 4, 1, 1);
675 if (ret)
676 goto error;
677
678 /* start reset mechanism */
679 ret = af9013_write_reg(state, 0xaeff, 1);
680 if (ret)
681 goto error;
682
683 /* reset is done when bit 1 is set */
684 for (i = 0; i < 150; i++) {
685 ret = af9013_read_reg_bits(state, 0xd417, 1, 1, &tmp);
686 if (ret)
687 goto error;
688 if (tmp)
689 break; /* reset done */
690 msleep(10);
691 }
692 if (!tmp)
693 return -ETIMEDOUT;
694
695 /* don't clear reset when going to sleep */
696 if (!sleep) {
697 /* clear OFDM reset */
698 ret = af9013_write_reg_bits(state, 0xd417, 1, 1, 0);
699 if (ret)
700 goto error;
701
702 /* disable OFDM reset */
703 ret = af9013_write_reg_bits(state, 0xd417, 4, 1, 0);
704 }
705error:
706 return ret;
707}
708
709static int af9013_power_ctrl(struct af9013_state *state, u8 onoff)
710{
711 int ret;
712 deb_info("%s: onoff:%d\n", __func__, onoff);
713
714 if (onoff) {
715 /* power on */
716 ret = af9013_write_reg_bits(state, 0xd73a, 3, 1, 0);
717 if (ret)
718 goto error;
719 ret = af9013_write_reg_bits(state, 0xd417, 1, 1, 0);
720 if (ret)
721 goto error;
722 ret = af9013_write_reg_bits(state, 0xd417, 4, 1, 0);
723 } else {
724 /* power off */
725 ret = af9013_reset(state, 1);
726 if (ret)
727 goto error;
728 ret = af9013_write_reg_bits(state, 0xd73a, 3, 1, 1);
729 }
730error:
731 return ret;
732}
733
734static int af9013_lock_led(struct af9013_state *state, u8 onoff)
735{
736 deb_info("%s: onoff:%d\n", __func__, onoff);
737
738 return af9013_write_reg_bits(state, 0xd730, 0, 1, onoff);
739}
740
741static int af9013_set_frontend(struct dvb_frontend *fe,
742 struct dvb_frontend_parameters *params)
743{
744 struct af9013_state *state = fe->demodulator_priv;
745 int ret;
746 u8 auto_mode; /* auto set TPS */
747
748 deb_info("%s: freq:%d bw:%d\n", __func__, params->frequency,
749 params->u.ofdm.bandwidth);
750
751 state->frequency = params->frequency;
752
753 /* program CFOE coefficients */
754 ret = af9013_set_coeff(state, params->u.ofdm.bandwidth);
755 if (ret)
756 goto error;
757
758 /* program frequency control */
759 ret = af9013_set_freq_ctrl(state, params->u.ofdm.bandwidth);
760 if (ret)
761 goto error;
762
763 /* clear TPS lock flag (inverted flag) */
764 ret = af9013_write_reg_bits(state, 0xd330, 3, 1, 1);
765 if (ret)
766 goto error;
767
768 /* clear MPEG2 lock flag */
769 ret = af9013_write_reg_bits(state, 0xd507, 6, 1, 0);
770 if (ret)
771 goto error;
772
773 /* empty channel function */
774 ret = af9013_write_reg_bits(state, 0x9bfe, 0, 1, 0);
775 if (ret)
776 goto error;
777
778 /* empty DVB-T channel function */
779 ret = af9013_write_reg_bits(state, 0x9bc2, 0, 1, 0);
780 if (ret)
781 goto error;
782
783 /* program tuner */
784 if (fe->ops.tuner_ops.set_params)
785 fe->ops.tuner_ops.set_params(fe, params);
786
787 /* program TPS and bandwidth, check if auto mode needed */
788 ret = af9013_set_ofdm_params(state, &params->u.ofdm, &auto_mode);
789 if (ret)
790 goto error;
791
792 if (auto_mode) {
793 /* clear easy mode flag */
794 ret = af9013_write_reg(state, 0xaefd, 0);
795 deb_info("%s: auto TPS\n", __func__);
796 } else {
797 /* set easy mode flag */
798 ret = af9013_write_reg(state, 0xaefd, 1);
799 if (ret)
800 goto error;
801 ret = af9013_write_reg(state, 0xaefe, 0);
802 deb_info("%s: manual TPS\n", __func__);
803 }
804 if (ret)
805 goto error;
806
807 /* everything is set, lets try to receive channel - OFSM GO! */
808 ret = af9013_write_reg(state, 0xffff, 0);
809 if (ret)
810 goto error;
811
812error:
813 return ret;
814}
815
816static int af9013_get_frontend(struct dvb_frontend *fe,
817 struct dvb_frontend_parameters *p)
818{
819 struct af9013_state *state = fe->demodulator_priv;
820 int ret;
821 u8 i, buf[3];
822 deb_info("%s\n", __func__);
823
824 /* read TPS registers */
825 for (i = 0; i < 3; i++) {
826 ret = af9013_read_reg(state, 0xd3c0 + i, &buf[i]);
827 if (ret)
828 goto error;
829 }
830
831 switch ((buf[1] >> 6) & 3) {
832 case 0:
833 p->u.ofdm.constellation = QPSK;
834 break;
835 case 1:
836 p->u.ofdm.constellation = QAM_16;
837 break;
838 case 2:
839 p->u.ofdm.constellation = QAM_64;
840 break;
841 }
842
843 switch ((buf[0] >> 0) & 3) {
844 case 0:
845 p->u.ofdm.transmission_mode = TRANSMISSION_MODE_2K;
846 break;
847 case 1:
848 p->u.ofdm.transmission_mode = TRANSMISSION_MODE_8K;
849 }
850
851 switch ((buf[0] >> 2) & 3) {
852 case 0:
853 p->u.ofdm.guard_interval = GUARD_INTERVAL_1_32;
854 break;
855 case 1:
856 p->u.ofdm.guard_interval = GUARD_INTERVAL_1_16;
857 break;
858 case 2:
859 p->u.ofdm.guard_interval = GUARD_INTERVAL_1_8;
860 break;
861 case 3:
862 p->u.ofdm.guard_interval = GUARD_INTERVAL_1_4;
863 break;
864 }
865
866 switch ((buf[0] >> 4) & 7) {
867 case 0:
868 p->u.ofdm.hierarchy_information = HIERARCHY_NONE;
869 break;
870 case 1:
871 p->u.ofdm.hierarchy_information = HIERARCHY_1;
872 break;
873 case 2:
874 p->u.ofdm.hierarchy_information = HIERARCHY_2;
875 break;
876 case 3:
877 p->u.ofdm.hierarchy_information = HIERARCHY_4;
878 break;
879 }
880
881 switch ((buf[2] >> 0) & 7) {
882 case 0:
883 p->u.ofdm.code_rate_HP = FEC_1_2;
884 break;
885 case 1:
886 p->u.ofdm.code_rate_HP = FEC_2_3;
887 break;
888 case 2:
889 p->u.ofdm.code_rate_HP = FEC_3_4;
890 break;
891 case 3:
892 p->u.ofdm.code_rate_HP = FEC_5_6;
893 break;
894 case 4:
895 p->u.ofdm.code_rate_HP = FEC_7_8;
896 break;
897 }
898
899 switch ((buf[2] >> 3) & 7) {
900 case 0:
901 p->u.ofdm.code_rate_LP = FEC_1_2;
902 break;
903 case 1:
904 p->u.ofdm.code_rate_LP = FEC_2_3;
905 break;
906 case 2:
907 p->u.ofdm.code_rate_LP = FEC_3_4;
908 break;
909 case 3:
910 p->u.ofdm.code_rate_LP = FEC_5_6;
911 break;
912 case 4:
913 p->u.ofdm.code_rate_LP = FEC_7_8;
914 break;
915 }
916
917 switch ((buf[1] >> 2) & 3) {
918 case 0:
919 p->u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
920 break;
921 case 1:
922 p->u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
923 break;
924 case 2:
925 p->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
926 break;
927 }
928
929 p->inversion = INVERSION_AUTO;
930 p->frequency = state->frequency;
931
932error:
933 return ret;
934}
935
936static int af9013_update_ber_unc(struct dvb_frontend *fe)
937{
938 struct af9013_state *state = fe->demodulator_priv;
939 int ret;
940 u8 buf[3], i;
941 u32 error_bit_count = 0;
942 u32 total_bit_count = 0;
943 u32 abort_packet_count = 0;
944
945 state->ber = 0;
946
947 /* check if error bit count is ready */
948 ret = af9013_read_reg_bits(state, 0xd391, 4, 1, &buf[0]);
949 if (ret)
950 goto error;
951 if (!buf[0])
952 goto exit;
953
954 /* get RSD packet abort count */
955 for (i = 0; i < 2; i++) {
956 ret = af9013_read_reg(state, 0xd38a + i, &buf[i]);
957 if (ret)
958 goto error;
959 }
960 abort_packet_count = (buf[1] << 8) + buf[0];
961
962 /* get error bit count */
963 for (i = 0; i < 3; i++) {
964 ret = af9013_read_reg(state, 0xd387 + i, &buf[i]);
965 if (ret)
966 goto error;
967 }
968 error_bit_count = (buf[2] << 16) + (buf[1] << 8) + buf[0];
969 error_bit_count = error_bit_count - abort_packet_count * 8 * 8;
970
971 /* get used RSD counting period (10000 RSD packets used) */
972 for (i = 0; i < 2; i++) {
973 ret = af9013_read_reg(state, 0xd385 + i, &buf[i]);
974 if (ret)
975 goto error;
976 }
977 total_bit_count = (buf[1] << 8) + buf[0];
978 total_bit_count = total_bit_count - abort_packet_count;
979 total_bit_count = total_bit_count * 204 * 8;
980
981 if (total_bit_count)
982 state->ber = error_bit_count * 1000000000 / total_bit_count;
983
984 state->ucblocks += abort_packet_count;
985
986 deb_info("%s: err bits:%d total bits:%d abort count:%d\n", __func__,
987 error_bit_count, total_bit_count, abort_packet_count);
988
989 /* set BER counting range */
990 ret = af9013_write_reg(state, 0xd385, 10000 & 0xff);
991 if (ret)
992 goto error;
993 ret = af9013_write_reg(state, 0xd386, 10000 >> 8);
994 if (ret)
995 goto error;
996 /* reset and start BER counter */
997 ret = af9013_write_reg_bits(state, 0xd391, 4, 1, 1);
998 if (ret)
999 goto error;
1000
1001exit:
1002error:
1003 return ret;
1004}
1005
1006static int af9013_update_snr(struct dvb_frontend *fe)
1007{
1008 struct af9013_state *state = fe->demodulator_priv;
1009 int ret;
1010 u8 buf[3], i, len;
1011 u32 quant = 0;
1012 struct snr_table *snr_table;
1013
1014 /* check if quantizer ready (for snr) */
1015 ret = af9013_read_reg_bits(state, 0xd2e1, 3, 1, &buf[0]);
1016 if (ret)
1017 goto error;
1018 if (buf[0]) {
1019 /* quantizer ready - read it */
1020 for (i = 0; i < 3; i++) {
1021 ret = af9013_read_reg(state, 0xd2e3 + i, &buf[i]);
1022 if (ret)
1023 goto error;
1024 }
1025 quant = (buf[2] << 16) + (buf[1] << 8) + buf[0];
1026
1027 /* read current constellation */
1028 ret = af9013_read_reg(state, 0xd3c1, &buf[0]);
1029 if (ret)
1030 goto error;
1031
1032 switch ((buf[0] >> 6) & 3) {
1033 case 0:
1034 len = ARRAY_SIZE(qpsk_snr_table);
1035 snr_table = qpsk_snr_table;
1036 break;
1037 case 1:
1038 len = ARRAY_SIZE(qam16_snr_table);
1039 snr_table = qam16_snr_table;
1040 break;
1041 case 2:
1042 len = ARRAY_SIZE(qam64_snr_table);
1043 snr_table = qam64_snr_table;
1044 break;
1045 default:
1046 len = 0;
1047 break;
1048 }
1049
1050 if (len) {
1051 for (i = 0; i < len; i++) {
1052 if (quant < snr_table[i].val) {
1053 state->snr = snr_table[i].snr * 10;
1054 break;
1055 }
1056 }
1057 }
1058
1059 /* set quantizer super frame count */
1060 ret = af9013_write_reg(state, 0xd2e2, 1);
1061 if (ret)
1062 goto error;
1063
1064 /* check quantizer availability */
1065 for (i = 0; i < 10; i++) {
1066 msleep(10);
1067 ret = af9013_read_reg_bits(state, 0xd2e6, 0, 1,
1068 &buf[0]);
1069 if (ret)
1070 goto error;
1071 if (!buf[0])
1072 break;
1073 }
1074
1075 /* reset quantizer */
1076 ret = af9013_write_reg_bits(state, 0xd2e1, 3, 1, 1);
1077 if (ret)
1078 goto error;
1079 }
1080
1081error:
1082 return ret;
1083}
1084
1085static int af9013_update_signal_strength(struct dvb_frontend *fe)
1086{
1087 struct af9013_state *state = fe->demodulator_priv;
1088 int ret;
1089 u8 tmp0;
1090 u8 rf_gain, rf_50, rf_80, if_gain, if_50, if_80;
1091 int signal_strength;
1092
1093 deb_info("%s\n", __func__);
1094
1095 state->signal_strength = 0;
1096
1097 ret = af9013_read_reg_bits(state, 0x9bee, 0, 1, &tmp0);
1098 if (ret)
1099 goto error;
1100 if (tmp0) {
1101 ret = af9013_read_reg(state, 0x9bbd, &rf_50);
1102 if (ret)
1103 goto error;
1104 ret = af9013_read_reg(state, 0x9bd0, &rf_80);
1105 if (ret)
1106 goto error;
1107 ret = af9013_read_reg(state, 0x9be2, &if_50);
1108 if (ret)
1109 goto error;
1110 ret = af9013_read_reg(state, 0x9be4, &if_80);
1111 if (ret)
1112 goto error;
1113 ret = af9013_read_reg(state, 0xd07c, &rf_gain);
1114 if (ret)
1115 goto error;
1116 ret = af9013_read_reg(state, 0xd07d, &if_gain);
1117 if (ret)
1118 goto error;
1119 signal_strength = (0xffff / (9 * (rf_50 + if_50) - \
1120 11 * (rf_80 + if_80))) * (10 * (rf_gain + if_gain) - \
1121 11 * (rf_80 + if_80));
1122 if (signal_strength < 0)
1123 signal_strength = 0;
1124 else if (signal_strength > 0xffff)
1125 signal_strength = 0xffff;
1126
1127 state->signal_strength = signal_strength;
1128 }
1129
1130error:
1131 return ret;
1132}
1133
1134static int af9013_update_statistics(struct dvb_frontend *fe)
1135{
1136 struct af9013_state *state = fe->demodulator_priv;
1137 int ret;
1138
1139 if (time_before(jiffies, state->next_statistics_check))
1140 return 0;
1141
1142 /* set minimum statistic update interval */
1143 state->next_statistics_check = jiffies + msecs_to_jiffies(1200);
1144
1145 ret = af9013_update_signal_strength(fe);
1146 if (ret)
1147 goto error;
1148 ret = af9013_update_snr(fe);
1149 if (ret)
1150 goto error;
1151 ret = af9013_update_ber_unc(fe);
1152 if (ret)
1153 goto error;
1154
1155error:
1156 return ret;
1157}
1158
1159static int af9013_get_tune_settings(struct dvb_frontend *fe,
1160 struct dvb_frontend_tune_settings *fesettings)
1161{
1162 fesettings->min_delay_ms = 800;
1163 fesettings->step_size = 0;
1164 fesettings->max_drift = 0;
1165
1166 return 0;
1167}
1168
1169static int af9013_read_status(struct dvb_frontend *fe, fe_status_t *status)
1170{
1171 struct af9013_state *state = fe->demodulator_priv;
1172 int ret = 0;
1173 u8 tmp;
1174 *status = 0;
1175
1176 /* TPS lock */
1177 ret = af9013_read_reg_bits(state, 0xd330, 3, 1, &tmp);
1178 if (ret)
1179 goto error;
1180 if (tmp)
1181 *status |= FE_HAS_VITERBI | FE_HAS_CARRIER | FE_HAS_SIGNAL;
1182
1183 /* MPEG2 lock */
1184 ret = af9013_read_reg_bits(state, 0xd507, 6, 1, &tmp);
1185 if (ret)
1186 goto error;
1187 if (tmp)
1188 *status |= FE_HAS_SYNC | FE_HAS_LOCK;
1189
1190 if (!*status & FE_HAS_SIGNAL) {
1191 /* AGC lock */
1192 ret = af9013_read_reg_bits(state, 0xd1a0, 6, 1, &tmp);
1193 if (ret)
1194 goto error;
1195 if (tmp)
1196 *status |= FE_HAS_SIGNAL;
1197 }
1198
1199 if (!*status & FE_HAS_CARRIER) {
1200 /* CFO lock */
1201 ret = af9013_read_reg_bits(state, 0xd333, 7, 1, &tmp);
1202 if (ret)
1203 goto error;
1204 if (tmp)
1205 *status |= FE_HAS_CARRIER;
1206 }
1207
1208 if (!*status & FE_HAS_CARRIER) {
1209 /* SFOE lock */
1210 ret = af9013_read_reg_bits(state, 0xd334, 6, 1, &tmp);
1211 if (ret)
1212 goto error;
1213 if (tmp)
1214 *status |= FE_HAS_CARRIER;
1215 }
1216
1217 ret = af9013_update_statistics(fe);
1218
1219error:
1220 return ret;
1221}
1222
1223
1224static int af9013_read_ber(struct dvb_frontend *fe, u32 *ber)
1225{
1226 struct af9013_state *state = fe->demodulator_priv;
1227 int ret;
1228 ret = af9013_update_statistics(fe);
1229 *ber = state->ber;
1230 return ret;
1231}
1232
1233static int af9013_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
1234{
1235 struct af9013_state *state = fe->demodulator_priv;
1236 int ret;
1237 ret = af9013_update_statistics(fe);
1238 *strength = state->signal_strength;
1239 return ret;
1240}
1241
1242static int af9013_read_snr(struct dvb_frontend *fe, u16 *snr)
1243{
1244 struct af9013_state *state = fe->demodulator_priv;
1245 int ret;
1246 ret = af9013_update_statistics(fe);
1247 *snr = state->snr;
1248 return ret;
1249}
1250
1251static int af9013_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
1252{
1253 struct af9013_state *state = fe->demodulator_priv;
1254 int ret;
1255 ret = af9013_update_statistics(fe);
1256 *ucblocks = state->ucblocks;
1257 return ret;
1258}
1259
1260static int af9013_sleep(struct dvb_frontend *fe)
1261{
1262 struct af9013_state *state = fe->demodulator_priv;
1263 int ret;
1264 deb_info("%s\n", __func__);
1265
1266 ret = af9013_lock_led(state, 0);
1267 if (ret)
1268 goto error;
1269
1270 ret = af9013_power_ctrl(state, 0);
1271error:
1272 return ret;
1273}
1274
1275static int af9013_init(struct dvb_frontend *fe)
1276{
1277 struct af9013_state *state = fe->demodulator_priv;
1278 int ret, i, len;
1279 u8 tmp0, tmp1;
1280 struct regdesc *init;
1281 deb_info("%s\n", __func__);
1282
1283 /* reset OFDM */
1284 ret = af9013_reset(state, 0);
1285 if (ret)
1286 goto error;
1287
1288 /* power on */
1289 ret = af9013_power_ctrl(state, 1);
1290 if (ret)
1291 goto error;
1292
1293 /* enable ADC */
1294 ret = af9013_write_reg(state, 0xd73a, 0xa4);
1295 if (ret)
1296 goto error;
1297
1298 /* write API version to firmware */
1299 for (i = 0; i < sizeof(state->config.api_version); i++) {
1300 ret = af9013_write_reg(state, 0x9bf2 + i,
1301 state->config.api_version[i]);
1302 if (ret)
1303 goto error;
1304 }
1305
1306 /* program ADC control */
1307 ret = af9013_set_adc_ctrl(state);
1308 if (ret)
1309 goto error;
1310
1311 /* set I2C master clock */
1312 ret = af9013_write_reg(state, 0xd416, 0x14);
1313 if (ret)
1314 goto error;
1315
1316 /* set 16 embx */
1317 ret = af9013_write_reg_bits(state, 0xd700, 1, 1, 1);
1318 if (ret)
1319 goto error;
1320
1321 /* set no trigger */
1322 ret = af9013_write_reg_bits(state, 0xd700, 2, 1, 0);
1323 if (ret)
1324 goto error;
1325
1326 /* set read-update bit for constellation */
1327 ret = af9013_write_reg_bits(state, 0xd371, 1, 1, 1);
1328 if (ret)
1329 goto error;
1330
1331 /* enable FEC monitor */
1332 ret = af9013_write_reg_bits(state, 0xd392, 1, 1, 1);
1333 if (ret)
1334 goto error;
1335
1336 /* load OFSM settings */
1337 deb_info("%s: load ofsm settings\n", __func__);
1338 len = ARRAY_SIZE(ofsm_init);
1339 init = ofsm_init;
1340 for (i = 0; i < len; i++) {
1341 ret = af9013_write_reg_bits(state, init[i].addr, init[i].pos,
1342 init[i].len, init[i].val);
1343 if (ret)
1344 goto error;
1345 }
1346
1347 /* load tuner specific settings */
1348 deb_info("%s: load tuner specific settings\n", __func__);
1349 switch (state->config.tuner) {
1350 case AF9013_TUNER_MXL5003D:
1351 len = ARRAY_SIZE(tuner_init_mxl5003d);
1352 init = tuner_init_mxl5003d;
1353 break;
1354 case AF9013_TUNER_MXL5005D:
1355 case AF9013_TUNER_MXL5005R:
1356 len = ARRAY_SIZE(tuner_init_mxl5005);
1357 init = tuner_init_mxl5005;
1358 break;
1359 case AF9013_TUNER_ENV77H11D5:
1360 len = ARRAY_SIZE(tuner_init_env77h11d5);
1361 init = tuner_init_env77h11d5;
1362 break;
1363 case AF9013_TUNER_MT2060:
1364 len = ARRAY_SIZE(tuner_init_mt2060);
1365 init = tuner_init_mt2060;
1366 break;
1367 case AF9013_TUNER_MC44S803:
1368 len = ARRAY_SIZE(tuner_init_mc44s803);
1369 init = tuner_init_mc44s803;
1370 break;
1371 case AF9013_TUNER_QT1010:
1372 case AF9013_TUNER_QT1010A:
1373 len = ARRAY_SIZE(tuner_init_qt1010);
1374 init = tuner_init_qt1010;
1375 break;
1376 case AF9013_TUNER_MT2060_2:
1377 len = ARRAY_SIZE(tuner_init_mt2060_2);
1378 init = tuner_init_mt2060_2;
1379 break;
1380 case AF9013_TUNER_TDA18271:
1381 len = ARRAY_SIZE(tuner_init_tda18271);
1382 init = tuner_init_tda18271;
1383 break;
1384 case AF9013_TUNER_UNKNOWN:
1385 default:
1386 len = ARRAY_SIZE(tuner_init_unknown);
1387 init = tuner_init_unknown;
1388 break;
1389 }
1390
1391 for (i = 0; i < len; i++) {
1392 ret = af9013_write_reg_bits(state, init[i].addr, init[i].pos,
1393 init[i].len, init[i].val);
1394 if (ret)
1395 goto error;
1396 }
1397
1398 /* set TS mode */
1399 deb_info("%s: setting ts mode\n", __func__);
1400 tmp0 = 0; /* parallel mode */
1401 tmp1 = 0; /* serial mode */
1402 switch (state->config.output_mode) {
1403 case AF9013_OUTPUT_MODE_PARALLEL:
1404 tmp0 = 1;
1405 break;
1406 case AF9013_OUTPUT_MODE_SERIAL:
1407 tmp1 = 1;
1408 break;
1409 case AF9013_OUTPUT_MODE_USB:
1410 /* usb mode for AF9015 */
1411 default:
1412 break;
1413 }
1414 ret = af9013_write_reg_bits(state, 0xd500, 1, 1, tmp0); /* parallel */
1415 if (ret)
1416 goto error;
1417 ret = af9013_write_reg_bits(state, 0xd500, 2, 1, tmp1); /* serial */
1418 if (ret)
1419 goto error;
1420
1421 /* enable lock led */
1422 ret = af9013_lock_led(state, 1);
1423 if (ret)
1424 goto error;
1425
1426error:
1427 return ret;
1428}
1429
1430static struct dvb_frontend_ops af9013_ops;
1431
1432static int af9013_download_firmware(struct af9013_state *state)
1433{
1434 int i, len, packets, remainder, ret;
1435 const struct firmware *fw;
1436 u16 addr = 0x5100; /* firmware start address */
1437 u16 checksum = 0;
1438 u8 val;
1439 u8 fw_params[4];
1440 u8 *data;
1441 u8 *fw_file = AF9013_DEFAULT_FIRMWARE;
1442
1443 msleep(100);
1444 /* check whether firmware is already running */
1445 ret = af9013_read_reg(state, 0x98be, &val);
1446 if (ret)
1447 goto error;
1448 else
1449 deb_info("%s: firmware status:%02x\n", __func__, val);
1450
1451 if (val == 0x0c) /* fw is running, no need for download */
1452 goto exit;
1453
1454 info("found a '%s' in cold state, will try to load a firmware",
1455 af9013_ops.info.name);
1456
1457 /* request the firmware, this will block and timeout */
1458 ret = request_firmware(&fw, fw_file, &state->i2c->dev);
1459 if (ret) {
1460 err("did not find the firmware file. (%s) "
1461 "Please see linux/Documentation/dvb/ for more details" \
1462 " on firmware-problems. (%d)",
1463 fw_file, ret);
1464 goto error;
1465 }
1466
1467 info("downloading firmware from file '%s'", fw_file);
1468
1469 /* calc checksum */
1470 for (i = 0; i < fw->size; i++)
1471 checksum += fw->data[i];
1472
1473 fw_params[0] = checksum >> 8;
1474 fw_params[1] = checksum & 0xff;
1475 fw_params[2] = fw->size >> 8;
1476 fw_params[3] = fw->size & 0xff;
1477
1478 /* write fw checksum & size */
1479 ret = af9013_write_ofsm_regs(state, 0x50fc,
1480 fw_params, sizeof(fw_params));
1481 if (ret)
1482 goto error_release;
1483
1484 #define FW_PACKET_MAX_DATA 16
1485
1486 packets = fw->size / FW_PACKET_MAX_DATA;
1487 remainder = fw->size % FW_PACKET_MAX_DATA;
1488 len = FW_PACKET_MAX_DATA;
1489 for (i = 0; i <= packets; i++) {
1490 if (i == packets) /* set size of the last packet */
1491 len = remainder;
1492
1493 data = (u8 *)(fw->data + i * FW_PACKET_MAX_DATA);
1494 ret = af9013_write_ofsm_regs(state, addr, data, len);
1495 addr += FW_PACKET_MAX_DATA;
1496
1497 if (ret) {
1498 err("firmware download failed at %d with %d", i, ret);
1499 goto error_release;
1500 }
1501 }
1502
1503 /* request boot firmware */
1504 ret = af9013_write_reg(state, 0xe205, 1);
1505 if (ret)
1506 goto error_release;
1507
1508 for (i = 0; i < 15; i++) {
1509 msleep(100);
1510
1511 /* check firmware status */
1512 ret = af9013_read_reg(state, 0x98be, &val);
1513 if (ret)
1514 goto error_release;
1515
1516 deb_info("%s: firmware status:%02x\n", __func__, val);
1517
1518 if (val == 0x0c || val == 0x04) /* success or fail */
1519 break;
1520 }
1521
1522 if (val == 0x04) {
1523 err("firmware did not run");
1524 ret = -1;
1525 } else if (val != 0x0c) {
1526 err("firmware boot timeout");
1527 ret = -1;
1528 }
1529
1530error_release:
1531 release_firmware(fw);
1532error:
1533exit:
1534 if (!ret)
1535 info("found a '%s' in warm state.", af9013_ops.info.name);
1536 return ret;
1537}
1538
1539static int af9013_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
1540{
1541 int ret;
1542 struct af9013_state *state = fe->demodulator_priv;
1543 deb_info("%s: enable:%d\n", __func__, enable);
1544
1545 if (state->config.output_mode == AF9013_OUTPUT_MODE_USB)
1546 ret = af9013_write_reg_bits(state, 0xd417, 3, 1, enable);
1547 else
1548 ret = af9013_write_reg_bits(state, 0xd607, 2, 1, enable);
1549
1550 return ret;
1551}
1552
1553static void af9013_release(struct dvb_frontend *fe)
1554{
1555 struct af9013_state *state = fe->demodulator_priv;
1556 kfree(state);
1557}
1558
1559static struct dvb_frontend_ops af9013_ops;
1560
1561struct dvb_frontend *af9013_attach(const struct af9013_config *config,
1562 struct i2c_adapter *i2c)
1563{
1564 int ret;
1565 struct af9013_state *state = NULL;
1566 u8 buf[3], i;
1567
1568 /* allocate memory for the internal state */
1569 state = kzalloc(sizeof(struct af9013_state), GFP_KERNEL);
1570 if (state == NULL)
1571 goto error;
1572
1573 /* setup the state */
1574 state->i2c = i2c;
1575 memcpy(&state->config, config, sizeof(struct af9013_config));
1576
1577 /* chip version */
1578 ret = af9013_read_reg_bits(state, 0xd733, 4, 4, &buf[2]);
1579 if (ret)
1580 goto error;
1581
1582 /* ROM version */
1583 for (i = 0; i < 2; i++) {
1584 ret = af9013_read_reg(state, 0x116b + i, &buf[i]);
1585 if (ret)
1586 goto error;
1587 }
1588 deb_info("%s: chip version:%d ROM version:%d.%d\n", __func__,
1589 buf[2], buf[0], buf[1]);
1590
1591 /* download firmware */
1592 if (state->config.output_mode != AF9013_OUTPUT_MODE_USB) {
1593 ret = af9013_download_firmware(state);
1594 if (ret)
1595 goto error;
1596 }
1597
1598 /* firmware version */
1599 for (i = 0; i < 3; i++) {
1600 ret = af9013_read_reg(state, 0x5103 + i, &buf[i]);
1601 if (ret)
1602 goto error;
1603 }
1604 info("firmware version:%d.%d.%d", buf[0], buf[1], buf[2]);
1605
1606 /* settings for mp2if */
1607 if (state->config.output_mode == AF9013_OUTPUT_MODE_USB) {
1608 /* AF9015 split PSB to 1.5k + 0.5k */
1609 ret = af9013_write_reg_bits(state, 0xd50b, 2, 1, 1);
1610 } else {
1611 /* AF9013 change the output bit to data7 */
1612 ret = af9013_write_reg_bits(state, 0xd500, 3, 1, 1);
1613 if (ret)
1614 goto error;
1615 /* AF9013 set mpeg to full speed */
1616 ret = af9013_write_reg_bits(state, 0xd502, 4, 1, 1);
1617 }
1618 if (ret)
1619 goto error;
1620 ret = af9013_write_reg_bits(state, 0xd520, 4, 1, 1);
1621 if (ret)
1622 goto error;
1623
1624 /* set GPIOs */
1625 for (i = 0; i < sizeof(state->config.gpio); i++) {
1626 ret = af9013_set_gpio(state, i, state->config.gpio[i]);
1627 if (ret)
1628 goto error;
1629 }
1630
1631 /* create dvb_frontend */
1632 memcpy(&state->frontend.ops, &af9013_ops,
1633 sizeof(struct dvb_frontend_ops));
1634 state->frontend.demodulator_priv = state;
1635
1636 return &state->frontend;
1637error:
1638 kfree(state);
1639 return NULL;
1640}
1641EXPORT_SYMBOL(af9013_attach);
1642
1643static struct dvb_frontend_ops af9013_ops = {
1644 .info = {
1645 .name = "Afatech AF9013 DVB-T",
1646 .type = FE_OFDM,
1647 .frequency_min = 174000000,
1648 .frequency_max = 862000000,
1649 .frequency_stepsize = 250000,
1650 .frequency_tolerance = 0,
1651 .caps =
1652 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
1653 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
1654 FE_CAN_QPSK | FE_CAN_QAM_16 |
1655 FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
1656 FE_CAN_TRANSMISSION_MODE_AUTO |
1657 FE_CAN_GUARD_INTERVAL_AUTO |
1658 FE_CAN_HIERARCHY_AUTO |
1659 FE_CAN_RECOVER |
1660 FE_CAN_MUTE_TS
1661 },
1662
1663 .release = af9013_release,
1664 .init = af9013_init,
1665 .sleep = af9013_sleep,
1666 .i2c_gate_ctrl = af9013_i2c_gate_ctrl,
1667
1668 .set_frontend = af9013_set_frontend,
1669 .get_frontend = af9013_get_frontend,
1670
1671 .get_tune_settings = af9013_get_tune_settings,
1672
1673 .read_status = af9013_read_status,
1674 .read_ber = af9013_read_ber,
1675 .read_signal_strength = af9013_read_signal_strength,
1676 .read_snr = af9013_read_snr,
1677 .read_ucblocks = af9013_read_ucblocks,
1678};
1679
1680module_param_named(debug, af9013_debug, int, 0644);
1681MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
1682
1683MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1684MODULE_DESCRIPTION("Afatech AF9013 DVB-T demodulator driver");
1685MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/af9013.h b/drivers/media/dvb/frontends/af9013.h
new file mode 100644
index 000000000000..28b90c91c766
--- /dev/null
+++ b/drivers/media/dvb/frontends/af9013.h
@@ -0,0 +1,107 @@
1/*
2 * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver
3 *
4 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
5 *
6 * Thanks to Afatech who kindly provided information.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 */
23
24#ifndef _AF9013_H_
25#define _AF9013_H_
26
27#include <linux/dvb/frontend.h>
28
29enum af9013_ts_mode {
30 AF9013_OUTPUT_MODE_PARALLEL,
31 AF9013_OUTPUT_MODE_SERIAL,
32 AF9013_OUTPUT_MODE_USB, /* only for AF9015 */
33};
34
35enum af9013_tuner {
36 AF9013_TUNER_MXL5003D = 3, /* MaxLinear */
37 AF9013_TUNER_MXL5005D = 13, /* MaxLinear */
38 AF9013_TUNER_MXL5005R = 30, /* MaxLinear */
39 AF9013_TUNER_ENV77H11D5 = 129, /* Panasonic */
40 AF9013_TUNER_MT2060 = 130, /* Microtune */
41 AF9013_TUNER_MC44S803 = 133, /* Freescale */
42 AF9013_TUNER_QT1010 = 134, /* Quantek */
43 AF9013_TUNER_UNKNOWN = 140, /* for can tuners ? */
44 AF9013_TUNER_MT2060_2 = 147, /* Microtune */
45 AF9013_TUNER_TDA18271 = 156, /* NXP */
46 AF9013_TUNER_QT1010A = 162, /* Quantek */
47};
48
49/* AF9013/5 GPIOs (mostly guessed)
50 demod#1-gpio#0 - set demod#2 i2c-addr for dual devices
51 demod#1-gpio#1 - xtal setting (?)
52 demod#1-gpio#3 - tuner#1
53 demod#2-gpio#0 - tuner#2
54 demod#2-gpio#1 - xtal setting (?)
55*/
56#define AF9013_GPIO_ON (1 << 0)
57#define AF9013_GPIO_EN (1 << 1)
58#define AF9013_GPIO_O (1 << 2)
59#define AF9013_GPIO_I (1 << 3)
60
61#define AF9013_GPIO_LO (AF9013_GPIO_ON|AF9013_GPIO_EN)
62#define AF9013_GPIO_HI (AF9013_GPIO_ON|AF9013_GPIO_EN|AF9013_GPIO_O)
63
64#define AF9013_GPIO_TUNER_ON (AF9013_GPIO_ON|AF9013_GPIO_EN)
65#define AF9013_GPIO_TUNER_OFF (AF9013_GPIO_ON|AF9013_GPIO_EN|AF9013_GPIO_O)
66
67struct af9013_config {
68 /* demodulator's I2C address */
69 u8 demod_address;
70
71 /* frequencies in kHz */
72 u32 adc_clock;
73
74 /* tuner ID */
75 u8 tuner;
76
77 /* tuner IF */
78 u16 tuner_if;
79
80 /* TS data output mode */
81 u8 output_mode:2;
82
83 /* RF spectrum inversion */
84 u8 rf_spec_inv:1;
85
86 /* API version */
87 u8 api_version[4];
88
89 /* GPIOs */
90 u8 gpio[4];
91};
92
93
94#if defined(CONFIG_DVB_AF9013) || \
95 (defined(CONFIG_DVB_AF9013_MODULE) && defined(MODULE))
96extern struct dvb_frontend *af9013_attach(const struct af9013_config *config,
97 struct i2c_adapter *i2c);
98#else
99static inline struct dvb_frontend *af9013_attach(
100const struct af9013_config *config, struct i2c_adapter *i2c)
101{
102 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
103 return NULL;
104}
105#endif /* CONFIG_DVB_AF9013 */
106
107#endif /* _AF9013_H_ */
diff --git a/drivers/media/dvb/frontends/af9013_priv.h b/drivers/media/dvb/frontends/af9013_priv.h
new file mode 100644
index 000000000000..163e251d0b73
--- /dev/null
+++ b/drivers/media/dvb/frontends/af9013_priv.h
@@ -0,0 +1,869 @@
1/*
2 * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver
3 *
4 * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
5 *
6 * Thanks to Afatech who kindly provided information.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 */
23
24#ifndef _AF9013_PRIV_
25#define _AF9013_PRIV_
26
27#define LOG_PREFIX "af9013"
28extern int af9013_debug;
29
30#define dprintk(var, level, args...) \
31 do { if ((var & level)) printk(args); } while (0)
32
33#define debug_dump(b, l, func) {\
34 int loop_; \
35 for (loop_ = 0; loop_ < l; loop_++) \
36 func("%02x ", b[loop_]); \
37 func("\n");\
38}
39
40#define deb_info(args...) dprintk(af9013_debug, 0x01, args)
41
42#undef err
43#define err(f, arg...) printk(KERN_ERR LOG_PREFIX": " f "\n" , ## arg)
44#undef info
45#define info(f, arg...) printk(KERN_INFO LOG_PREFIX": " f "\n" , ## arg)
46#undef warn
47#define warn(f, arg...) printk(KERN_WARNING LOG_PREFIX": " f "\n" , ## arg)
48
49#define AF9013_DEFAULT_FIRMWARE "dvb-fe-af9013.fw"
50
51struct regdesc {
52 u16 addr;
53 u8 pos:4;
54 u8 len:4;
55 u8 val;
56};
57
58struct snr_table {
59 u32 val;
60 u8 snr;
61};
62
63/* QPSK SNR lookup table */
64static struct snr_table qpsk_snr_table[] = {
65 { 0x0b4771, 0 },
66 { 0x0c1aed, 1 },
67 { 0x0d0d27, 2 },
68 { 0x0e4d19, 3 },
69 { 0x0e5da8, 4 },
70 { 0x107097, 5 },
71 { 0x116975, 6 },
72 { 0x1252d9, 7 },
73 { 0x131fa4, 8 },
74 { 0x13d5e1, 9 },
75 { 0x148e53, 10 },
76 { 0x15358b, 11 },
77 { 0x15dd29, 12 },
78 { 0x168112, 13 },
79 { 0x170b61, 14 },
80 { 0xffffff, 15 },
81};
82
83/* QAM16 SNR lookup table */
84static struct snr_table qam16_snr_table[] = {
85 { 0x05eb62, 5 },
86 { 0x05fecf, 6 },
87 { 0x060b80, 7 },
88 { 0x062501, 8 },
89 { 0x064865, 9 },
90 { 0x069604, 10 },
91 { 0x06f356, 11 },
92 { 0x07706a, 12 },
93 { 0x0804d3, 13 },
94 { 0x089d1a, 14 },
95 { 0x093e3d, 15 },
96 { 0x09e35d, 16 },
97 { 0x0a7c3c, 17 },
98 { 0x0afaf8, 18 },
99 { 0x0b719d, 19 },
100 { 0xffffff, 20 },
101};
102
103/* QAM64 SNR lookup table */
104static struct snr_table qam64_snr_table[] = {
105 { 0x03109b, 12 },
106 { 0x0310d4, 13 },
107 { 0x031920, 14 },
108 { 0x0322d0, 15 },
109 { 0x0339fc, 16 },
110 { 0x0364a1, 17 },
111 { 0x038bcc, 18 },
112 { 0x03c7d3, 19 },
113 { 0x0408cc, 20 },
114 { 0x043bed, 21 },
115 { 0x048061, 22 },
116 { 0x04be95, 23 },
117 { 0x04fa7d, 24 },
118 { 0x052405, 25 },
119 { 0x05570d, 26 },
120 { 0xffffff, 27 },
121};
122
123static struct regdesc ofsm_init[] = {
124 { 0xd73a, 0, 8, 0xa1 },
125 { 0xd73b, 0, 8, 0x1f },
126 { 0xd73c, 4, 4, 0x0a },
127 { 0xd732, 3, 1, 0x00 },
128 { 0xd731, 4, 2, 0x03 },
129 { 0xd73d, 7, 1, 0x01 },
130 { 0xd740, 0, 1, 0x00 },
131 { 0xd740, 1, 1, 0x00 },
132 { 0xd740, 2, 1, 0x00 },
133 { 0xd740, 3, 1, 0x01 },
134 { 0xd3c1, 4, 1, 0x01 },
135 { 0xd3a2, 0, 8, 0x00 },
136 { 0xd3a3, 0, 8, 0x04 },
137 { 0xd305, 0, 8, 0x32 },
138 { 0xd306, 0, 8, 0x10 },
139 { 0xd304, 0, 8, 0x04 },
140 { 0x9112, 0, 1, 0x01 },
141 { 0x911d, 0, 1, 0x01 },
142 { 0x911a, 0, 1, 0x01 },
143 { 0x911b, 0, 1, 0x01 },
144 { 0x9bce, 0, 4, 0x02 },
145 { 0x9116, 0, 1, 0x01 },
146 { 0x9bd1, 0, 1, 0x01 },
147 { 0xd2e0, 0, 8, 0xd0 },
148 { 0xd2e9, 0, 4, 0x0d },
149 { 0xd38c, 0, 8, 0xfc },
150 { 0xd38d, 0, 8, 0x00 },
151 { 0xd38e, 0, 8, 0x7e },
152 { 0xd38f, 0, 8, 0x00 },
153 { 0xd390, 0, 8, 0x2f },
154 { 0xd145, 4, 1, 0x01 },
155 { 0xd1a9, 4, 1, 0x01 },
156 { 0xd158, 5, 3, 0x01 },
157 { 0xd159, 0, 6, 0x06 },
158 { 0xd167, 0, 8, 0x00 },
159 { 0xd168, 0, 4, 0x07 },
160 { 0xd1c3, 5, 3, 0x00 },
161 { 0xd1c4, 0, 6, 0x00 },
162 { 0xd1c5, 0, 7, 0x10 },
163 { 0xd1c6, 0, 3, 0x02 },
164 { 0xd080, 2, 5, 0x03 },
165 { 0xd081, 4, 4, 0x09 },
166 { 0xd098, 4, 4, 0x0f },
167 { 0xd098, 0, 4, 0x03 },
168 { 0xdbc0, 3, 1, 0x01 },
169 { 0xdbc0, 4, 1, 0x01 },
170 { 0xdbc7, 0, 8, 0x08 },
171 { 0xdbc8, 4, 4, 0x00 },
172 { 0xdbc9, 0, 5, 0x01 },
173 { 0xd280, 0, 8, 0xe0 },
174 { 0xd281, 0, 8, 0xff },
175 { 0xd282, 0, 8, 0xff },
176 { 0xd283, 0, 8, 0xc3 },
177 { 0xd284, 0, 8, 0xff },
178 { 0xd285, 0, 4, 0x01 },
179 { 0xd0f0, 0, 7, 0x1a },
180 { 0xd0f1, 4, 1, 0x01 },
181 { 0xd0f2, 0, 8, 0x0c },
182 { 0xd103, 0, 4, 0x08 },
183 { 0xd0f8, 0, 7, 0x20 },
184 { 0xd111, 5, 1, 0x00 },
185 { 0xd111, 6, 1, 0x00 },
186 { 0x910b, 0, 8, 0x0a },
187 { 0x9115, 0, 8, 0x02 },
188 { 0x910c, 0, 8, 0x02 },
189 { 0x910d, 0, 8, 0x08 },
190 { 0x910e, 0, 8, 0x0a },
191 { 0x9bf6, 0, 8, 0x06 },
192 { 0x9bf8, 0, 8, 0x02 },
193 { 0x9bf7, 0, 8, 0x05 },
194 { 0x9bf9, 0, 8, 0x0f },
195 { 0x9bfc, 0, 8, 0x13 },
196 { 0x9bd3, 0, 8, 0xff },
197 { 0x9bbe, 0, 1, 0x01 },
198 { 0x9bcc, 0, 1, 0x01 },
199};
200
201/* Panasonic ENV77H11D5 tuner init
202 AF9013_TUNER_ENV77H11D5 = 129 */
203static struct regdesc tuner_init_env77h11d5[] = {
204 { 0x9bd5, 0, 8, 0x01 },
205 { 0x9bd6, 0, 8, 0x03 },
206 { 0x9bbe, 0, 8, 0x01 },
207 { 0xd1a0, 1, 1, 0x01 },
208 { 0xd000, 0, 1, 0x01 },
209 { 0xd000, 1, 1, 0x00 },
210 { 0xd001, 1, 1, 0x01 },
211 { 0xd001, 0, 1, 0x00 },
212 { 0xd001, 5, 1, 0x00 },
213 { 0xd002, 0, 5, 0x19 },
214 { 0xd003, 0, 5, 0x1a },
215 { 0xd004, 0, 5, 0x19 },
216 { 0xd005, 0, 5, 0x1a },
217 { 0xd00e, 0, 5, 0x10 },
218 { 0xd00f, 0, 3, 0x04 },
219 { 0xd00f, 3, 3, 0x05 },
220 { 0xd010, 0, 3, 0x04 },
221 { 0xd010, 3, 3, 0x05 },
222 { 0xd016, 4, 4, 0x03 },
223 { 0xd01f, 0, 6, 0x0a },
224 { 0xd020, 0, 6, 0x0a },
225 { 0x9bda, 0, 8, 0x00 },
226 { 0x9be3, 0, 8, 0x00 },
227 { 0xd015, 0, 8, 0x50 },
228 { 0xd016, 0, 1, 0x00 },
229 { 0xd044, 0, 8, 0x46 },
230 { 0xd045, 0, 1, 0x00 },
231 { 0xd008, 0, 8, 0xdf },
232 { 0xd009, 0, 2, 0x02 },
233 { 0xd006, 0, 8, 0x44 },
234 { 0xd007, 0, 2, 0x01 },
235 { 0xd00c, 0, 8, 0xeb },
236 { 0xd00d, 0, 2, 0x02 },
237 { 0xd00a, 0, 8, 0xf4 },
238 { 0xd00b, 0, 2, 0x01 },
239 { 0x9bba, 0, 8, 0xf9 },
240 { 0x9bc3, 0, 8, 0xdf },
241 { 0x9bc4, 0, 8, 0x02 },
242 { 0x9bc5, 0, 8, 0xeb },
243 { 0x9bc6, 0, 8, 0x02 },
244 { 0x9bc9, 0, 8, 0x52 },
245 { 0xd011, 0, 8, 0x3c },
246 { 0xd012, 0, 2, 0x01 },
247 { 0xd013, 0, 8, 0xf7 },
248 { 0xd014, 0, 2, 0x02 },
249 { 0xd040, 0, 8, 0x0b },
250 { 0xd041, 0, 2, 0x02 },
251 { 0xd042, 0, 8, 0x4d },
252 { 0xd043, 0, 2, 0x00 },
253 { 0xd045, 1, 1, 0x00 },
254 { 0x9bcf, 0, 1, 0x01 },
255 { 0xd045, 2, 1, 0x01 },
256 { 0xd04f, 0, 8, 0x9a },
257 { 0xd050, 0, 1, 0x01 },
258 { 0xd051, 0, 8, 0x5a },
259 { 0xd052, 0, 1, 0x01 },
260 { 0xd053, 0, 8, 0x50 },
261 { 0xd054, 0, 8, 0x46 },
262 { 0x9bd7, 0, 8, 0x0a },
263 { 0x9bd8, 0, 8, 0x14 },
264 { 0x9bd9, 0, 8, 0x08 },
265};
266
267/* Microtune MT2060 tuner init
268 AF9013_TUNER_MT2060 = 130 */
269static struct regdesc tuner_init_mt2060[] = {
270 { 0x9bd5, 0, 8, 0x01 },
271 { 0x9bd6, 0, 8, 0x07 },
272 { 0xd1a0, 1, 1, 0x01 },
273 { 0xd000, 0, 1, 0x01 },
274 { 0xd000, 1, 1, 0x00 },
275 { 0xd001, 1, 1, 0x01 },
276 { 0xd001, 0, 1, 0x00 },
277 { 0xd001, 5, 1, 0x00 },
278 { 0xd002, 0, 5, 0x19 },
279 { 0xd003, 0, 5, 0x1a },
280 { 0xd004, 0, 5, 0x19 },
281 { 0xd005, 0, 5, 0x1a },
282 { 0xd00e, 0, 5, 0x10 },
283 { 0xd00f, 0, 3, 0x04 },
284 { 0xd00f, 3, 3, 0x05 },
285 { 0xd010, 0, 3, 0x04 },
286 { 0xd010, 3, 3, 0x05 },
287 { 0xd016, 4, 4, 0x03 },
288 { 0xd01f, 0, 6, 0x0a },
289 { 0xd020, 0, 6, 0x0a },
290 { 0x9bda, 0, 8, 0x00 },
291 { 0x9be3, 0, 8, 0x00 },
292 { 0x9bbe, 0, 1, 0x00 },
293 { 0x9bcc, 0, 1, 0x00 },
294 { 0x9bb9, 0, 8, 0x75 },
295 { 0x9bcd, 0, 8, 0x24 },
296 { 0x9bff, 0, 8, 0x30 },
297 { 0xd015, 0, 8, 0x46 },
298 { 0xd016, 0, 1, 0x00 },
299 { 0xd044, 0, 8, 0x46 },
300 { 0xd045, 0, 1, 0x00 },
301 { 0xd008, 0, 8, 0x0f },
302 { 0xd009, 0, 2, 0x02 },
303 { 0xd006, 0, 8, 0x32 },
304 { 0xd007, 0, 2, 0x01 },
305 { 0xd00c, 0, 8, 0x36 },
306 { 0xd00d, 0, 2, 0x03 },
307 { 0xd00a, 0, 8, 0x35 },
308 { 0xd00b, 0, 2, 0x01 },
309 { 0x9bc7, 0, 8, 0x07 },
310 { 0x9bc8, 0, 8, 0x90 },
311 { 0x9bc3, 0, 8, 0x0f },
312 { 0x9bc4, 0, 8, 0x02 },
313 { 0x9bc5, 0, 8, 0x36 },
314 { 0x9bc6, 0, 8, 0x03 },
315 { 0x9bba, 0, 8, 0xc9 },
316 { 0x9bc9, 0, 8, 0x79 },
317 { 0xd011, 0, 8, 0x10 },
318 { 0xd012, 0, 2, 0x01 },
319 { 0xd013, 0, 8, 0x45 },
320 { 0xd014, 0, 2, 0x03 },
321 { 0xd040, 0, 8, 0x98 },
322 { 0xd041, 0, 2, 0x00 },
323 { 0xd042, 0, 8, 0xcf },
324 { 0xd043, 0, 2, 0x03 },
325 { 0xd045, 1, 1, 0x00 },
326 { 0x9bcf, 0, 1, 0x01 },
327 { 0xd045, 2, 1, 0x01 },
328 { 0xd04f, 0, 8, 0x9a },
329 { 0xd050, 0, 1, 0x01 },
330 { 0xd051, 0, 8, 0x5a },
331 { 0xd052, 0, 1, 0x01 },
332 { 0xd053, 0, 8, 0x50 },
333 { 0xd054, 0, 8, 0x46 },
334 { 0x9bd7, 0, 8, 0x0a },
335 { 0x9bd8, 0, 8, 0x14 },
336 { 0x9bd9, 0, 8, 0x08 },
337 { 0x9bd0, 0, 8, 0xcc },
338 { 0x9be4, 0, 8, 0xa0 },
339 { 0x9bbd, 0, 8, 0x8e },
340 { 0x9be2, 0, 8, 0x4d },
341 { 0x9bee, 0, 1, 0x01 },
342};
343
344/* Microtune MT2060 tuner init
345 AF9013_TUNER_MT2060_2 = 147 */
346static struct regdesc tuner_init_mt2060_2[] = {
347 { 0x9bd5, 0, 8, 0x01 },
348 { 0x9bd6, 0, 8, 0x06 },
349 { 0x9bbe, 0, 8, 0x01 },
350 { 0xd1a0, 1, 1, 0x01 },
351 { 0xd000, 0, 1, 0x01 },
352 { 0xd000, 1, 1, 0x00 },
353 { 0xd001, 1, 1, 0x01 },
354 { 0xd001, 0, 1, 0x00 },
355 { 0xd001, 5, 1, 0x00 },
356 { 0xd002, 0, 5, 0x19 },
357 { 0xd003, 0, 5, 0x1a },
358 { 0xd004, 0, 5, 0x19 },
359 { 0xd005, 0, 5, 0x1a },
360 { 0xd00e, 0, 5, 0x10 },
361 { 0xd00f, 0, 3, 0x04 },
362 { 0xd00f, 3, 3, 0x05 },
363 { 0xd010, 0, 3, 0x04 },
364 { 0xd010, 3, 3, 0x05 },
365 { 0xd016, 4, 4, 0x03 },
366 { 0xd01f, 0, 6, 0x0a },
367 { 0xd020, 0, 6, 0x0a },
368 { 0xd015, 0, 8, 0x46 },
369 { 0xd016, 0, 1, 0x00 },
370 { 0xd044, 0, 8, 0x46 },
371 { 0xd045, 0, 1, 0x00 },
372 { 0xd008, 0, 8, 0x0f },
373 { 0xd009, 0, 2, 0x02 },
374 { 0xd006, 0, 8, 0x32 },
375 { 0xd007, 0, 2, 0x01 },
376 { 0xd00c, 0, 8, 0x36 },
377 { 0xd00d, 0, 2, 0x03 },
378 { 0xd00a, 0, 8, 0x35 },
379 { 0xd00b, 0, 2, 0x01 },
380 { 0x9bc7, 0, 8, 0x07 },
381 { 0x9bc8, 0, 8, 0x90 },
382 { 0x9bc3, 0, 8, 0x0f },
383 { 0x9bc4, 0, 8, 0x02 },
384 { 0x9bc5, 0, 8, 0x36 },
385 { 0x9bc6, 0, 8, 0x03 },
386 { 0x9bba, 0, 8, 0xc9 },
387 { 0x9bc9, 0, 8, 0x79 },
388 { 0xd011, 0, 8, 0x10 },
389 { 0xd012, 0, 2, 0x01 },
390 { 0xd013, 0, 8, 0x45 },
391 { 0xd014, 0, 2, 0x03 },
392 { 0xd040, 0, 8, 0x98 },
393 { 0xd041, 0, 2, 0x00 },
394 { 0xd042, 0, 8, 0xcf },
395 { 0xd043, 0, 2, 0x03 },
396 { 0xd045, 1, 1, 0x00 },
397 { 0x9bcf, 0, 8, 0x01 },
398 { 0xd045, 2, 1, 0x01 },
399 { 0xd04f, 0, 8, 0x9a },
400 { 0xd050, 0, 1, 0x01 },
401 { 0xd051, 0, 8, 0x5a },
402 { 0xd052, 0, 1, 0x01 },
403 { 0xd053, 0, 8, 0x96 },
404 { 0xd054, 0, 8, 0x46 },
405 { 0xd045, 7, 1, 0x00 },
406 { 0x9bd7, 0, 8, 0x0a },
407 { 0x9bd8, 0, 8, 0x14 },
408 { 0x9bd9, 0, 8, 0x08 },
409};
410
411/* MaxLinear MXL5003 tuner init
412 AF9013_TUNER_MXL5003D = 3 */
413static struct regdesc tuner_init_mxl5003d[] = {
414 { 0x9bd5, 0, 8, 0x01 },
415 { 0x9bd6, 0, 8, 0x09 },
416 { 0xd1a0, 1, 1, 0x01 },
417 { 0xd000, 0, 1, 0x01 },
418 { 0xd000, 1, 1, 0x00 },
419 { 0xd001, 1, 1, 0x01 },
420 { 0xd001, 0, 1, 0x00 },
421 { 0xd001, 5, 1, 0x00 },
422 { 0xd002, 0, 5, 0x19 },
423 { 0xd003, 0, 5, 0x1a },
424 { 0xd004, 0, 5, 0x19 },
425 { 0xd005, 0, 5, 0x1a },
426 { 0xd00e, 0, 5, 0x10 },
427 { 0xd00f, 0, 3, 0x04 },
428 { 0xd00f, 3, 3, 0x05 },
429 { 0xd010, 0, 3, 0x04 },
430 { 0xd010, 3, 3, 0x05 },
431 { 0xd016, 4, 4, 0x03 },
432 { 0xd01f, 0, 6, 0x0a },
433 { 0xd020, 0, 6, 0x0a },
434 { 0x9bda, 0, 8, 0x00 },
435 { 0x9be3, 0, 8, 0x00 },
436 { 0x9bfc, 0, 8, 0x0f },
437 { 0x9bf6, 0, 8, 0x01 },
438 { 0x9bbe, 0, 1, 0x01 },
439 { 0xd015, 0, 8, 0x33 },
440 { 0xd016, 0, 1, 0x00 },
441 { 0xd044, 0, 8, 0x40 },
442 { 0xd045, 0, 1, 0x00 },
443 { 0xd008, 0, 8, 0x0f },
444 { 0xd009, 0, 2, 0x02 },
445 { 0xd006, 0, 8, 0x6c },
446 { 0xd007, 0, 2, 0x00 },
447 { 0xd00c, 0, 8, 0x3d },
448 { 0xd00d, 0, 2, 0x00 },
449 { 0xd00a, 0, 8, 0x45 },
450 { 0xd00b, 0, 2, 0x01 },
451 { 0x9bc7, 0, 8, 0x07 },
452 { 0x9bc8, 0, 8, 0x52 },
453 { 0x9bc3, 0, 8, 0x0f },
454 { 0x9bc4, 0, 8, 0x02 },
455 { 0x9bc5, 0, 8, 0x3d },
456 { 0x9bc6, 0, 8, 0x00 },
457 { 0x9bba, 0, 8, 0xa2 },
458 { 0x9bc9, 0, 8, 0xa0 },
459 { 0xd011, 0, 8, 0x56 },
460 { 0xd012, 0, 2, 0x00 },
461 { 0xd013, 0, 8, 0x50 },
462 { 0xd014, 0, 2, 0x00 },
463 { 0xd040, 0, 8, 0x56 },
464 { 0xd041, 0, 2, 0x00 },
465 { 0xd042, 0, 8, 0x50 },
466 { 0xd043, 0, 2, 0x00 },
467 { 0xd045, 1, 1, 0x00 },
468 { 0x9bcf, 0, 8, 0x01 },
469 { 0xd045, 2, 1, 0x01 },
470 { 0xd04f, 0, 8, 0x9a },
471 { 0xd050, 0, 1, 0x01 },
472 { 0xd051, 0, 8, 0x5a },
473 { 0xd052, 0, 1, 0x01 },
474 { 0xd053, 0, 8, 0x50 },
475 { 0xd054, 0, 8, 0x46 },
476 { 0x9bd7, 0, 8, 0x0a },
477 { 0x9bd8, 0, 8, 0x14 },
478 { 0x9bd9, 0, 8, 0x08 },
479};
480
481/* MaxLinear MXL5005 tuner init
482 AF9013_TUNER_MXL5005D = 13
483 AF9013_TUNER_MXL5005R = 30 */
484static struct regdesc tuner_init_mxl5005[] = {
485 { 0x9bd5, 0, 8, 0x01 },
486 { 0x9bd6, 0, 8, 0x07 },
487 { 0xd1a0, 1, 1, 0x01 },
488 { 0xd000, 0, 1, 0x01 },
489 { 0xd000, 1, 1, 0x00 },
490 { 0xd001, 1, 1, 0x01 },
491 { 0xd001, 0, 1, 0x00 },
492 { 0xd001, 5, 1, 0x00 },
493 { 0xd002, 0, 5, 0x19 },
494 { 0xd003, 0, 5, 0x1a },
495 { 0xd004, 0, 5, 0x19 },
496 { 0xd005, 0, 5, 0x1a },
497 { 0xd00e, 0, 5, 0x10 },
498 { 0xd00f, 0, 3, 0x04 },
499 { 0xd00f, 3, 3, 0x05 },
500 { 0xd010, 0, 3, 0x04 },
501 { 0xd010, 3, 3, 0x05 },
502 { 0xd016, 4, 4, 0x03 },
503 { 0xd01f, 0, 6, 0x0a },
504 { 0xd020, 0, 6, 0x0a },
505 { 0x9bda, 0, 8, 0x01 },
506 { 0x9be3, 0, 8, 0x01 },
507 { 0x9bbe, 0, 1, 0x01 },
508 { 0x9bcc, 0, 1, 0x01 },
509 { 0x9bb9, 0, 8, 0x00 },
510 { 0x9bcd, 0, 8, 0x28 },
511 { 0x9bff, 0, 8, 0x24 },
512 { 0xd015, 0, 8, 0x40 },
513 { 0xd016, 0, 1, 0x00 },
514 { 0xd044, 0, 8, 0x40 },
515 { 0xd045, 0, 1, 0x00 },
516 { 0xd008, 0, 8, 0x0f },
517 { 0xd009, 0, 2, 0x02 },
518 { 0xd006, 0, 8, 0x73 },
519 { 0xd007, 0, 2, 0x01 },
520 { 0xd00c, 0, 8, 0xfa },
521 { 0xd00d, 0, 2, 0x01 },
522 { 0xd00a, 0, 8, 0xff },
523 { 0xd00b, 0, 2, 0x01 },
524 { 0x9bc7, 0, 8, 0x23 },
525 { 0x9bc8, 0, 8, 0x55 },
526 { 0x9bc3, 0, 8, 0x01 },
527 { 0x9bc4, 0, 8, 0x02 },
528 { 0x9bc5, 0, 8, 0xfa },
529 { 0x9bc6, 0, 8, 0x01 },
530 { 0x9bba, 0, 8, 0xff },
531 { 0x9bc9, 0, 8, 0xff },
532 { 0x9bd3, 0, 8, 0x95 },
533 { 0xd011, 0, 8, 0x70 },
534 { 0xd012, 0, 2, 0x01 },
535 { 0xd013, 0, 8, 0xfb },
536 { 0xd014, 0, 2, 0x01 },
537 { 0xd040, 0, 8, 0x70 },
538 { 0xd041, 0, 2, 0x01 },
539 { 0xd042, 0, 8, 0xfb },
540 { 0xd043, 0, 2, 0x01 },
541 { 0xd045, 1, 1, 0x00 },
542 { 0x9bcf, 0, 1, 0x01 },
543 { 0xd045, 2, 1, 0x01 },
544 { 0xd04f, 0, 8, 0x9a },
545 { 0xd050, 0, 1, 0x01 },
546 { 0xd051, 0, 8, 0x5a },
547 { 0xd052, 0, 1, 0x01 },
548 { 0xd053, 0, 8, 0x50 },
549 { 0xd054, 0, 8, 0x46 },
550 { 0x9bd7, 0, 8, 0x0a },
551 { 0x9bd8, 0, 8, 0x14 },
552 { 0x9bd9, 0, 8, 0x08 },
553 { 0x9bd0, 0, 8, 0x93 },
554 { 0x9be4, 0, 8, 0xfe },
555 { 0x9bbd, 0, 8, 0x63 },
556 { 0x9be2, 0, 8, 0xfe },
557 { 0x9bee, 0, 1, 0x01 },
558};
559
560/* Quantek QT1010 tuner init
561 AF9013_TUNER_QT1010 = 134
562 AF9013_TUNER_QT1010A = 162 */
563static struct regdesc tuner_init_qt1010[] = {
564 { 0x9bd5, 0, 8, 0x01 },
565 { 0x9bd6, 0, 8, 0x09 },
566 { 0xd1a0, 1, 1, 0x01 },
567 { 0xd000, 0, 1, 0x01 },
568 { 0xd000, 1, 1, 0x00 },
569 { 0xd001, 1, 1, 0x01 },
570 { 0xd001, 0, 1, 0x00 },
571 { 0xd001, 5, 1, 0x00 },
572 { 0xd002, 0, 5, 0x19 },
573 { 0xd003, 0, 5, 0x1a },
574 { 0xd004, 0, 5, 0x19 },
575 { 0xd005, 0, 5, 0x1a },
576 { 0xd00e, 0, 5, 0x10 },
577 { 0xd00f, 0, 3, 0x04 },
578 { 0xd00f, 3, 3, 0x05 },
579 { 0xd010, 0, 3, 0x04 },
580 { 0xd010, 3, 3, 0x05 },
581 { 0xd016, 4, 4, 0x03 },
582 { 0xd01f, 0, 6, 0x0a },
583 { 0xd020, 0, 6, 0x0a },
584 { 0x9bda, 0, 8, 0x01 },
585 { 0x9be3, 0, 8, 0x01 },
586 { 0xd015, 0, 8, 0x46 },
587 { 0xd016, 0, 1, 0x00 },
588 { 0xd044, 0, 8, 0x46 },
589 { 0xd045, 0, 1, 0x00 },
590 { 0x9bbe, 0, 1, 0x01 },
591 { 0x9bcc, 0, 1, 0x01 },
592 { 0x9bb9, 0, 8, 0x00 },
593 { 0x9bcd, 0, 8, 0x28 },
594 { 0x9bff, 0, 8, 0x20 },
595 { 0xd008, 0, 8, 0x0f },
596 { 0xd009, 0, 2, 0x02 },
597 { 0xd006, 0, 8, 0x99 },
598 { 0xd007, 0, 2, 0x01 },
599 { 0xd00c, 0, 8, 0x0f },
600 { 0xd00d, 0, 2, 0x02 },
601 { 0xd00a, 0, 8, 0x50 },
602 { 0xd00b, 0, 2, 0x01 },
603 { 0x9bc7, 0, 8, 0x00 },
604 { 0x9bc8, 0, 8, 0x00 },
605 { 0x9bc3, 0, 8, 0x0f },
606 { 0x9bc4, 0, 8, 0x02 },
607 { 0x9bc5, 0, 8, 0x0f },
608 { 0x9bc6, 0, 8, 0x02 },
609 { 0x9bba, 0, 8, 0xc5 },
610 { 0x9bc9, 0, 8, 0xff },
611 { 0xd011, 0, 8, 0x58 },
612 { 0xd012, 0, 2, 0x02 },
613 { 0xd013, 0, 8, 0x89 },
614 { 0xd014, 0, 2, 0x01 },
615 { 0xd040, 0, 8, 0x58 },
616 { 0xd041, 0, 2, 0x02 },
617 { 0xd042, 0, 8, 0x89 },
618 { 0xd043, 0, 2, 0x01 },
619 { 0xd045, 1, 1, 0x00 },
620 { 0x9bcf, 0, 1, 0x01 },
621 { 0xd045, 2, 1, 0x01 },
622 { 0xd04f, 0, 8, 0x9a },
623 { 0xd050, 0, 1, 0x01 },
624 { 0xd051, 0, 8, 0x5a },
625 { 0xd052, 0, 1, 0x01 },
626 { 0xd053, 0, 8, 0x50 },
627 { 0xd054, 0, 8, 0x46 },
628 { 0x9bd7, 0, 8, 0x0a },
629 { 0x9bd8, 0, 8, 0x14 },
630 { 0x9bd9, 0, 8, 0x08 },
631 { 0x9bd0, 0, 8, 0xcd },
632 { 0x9be4, 0, 8, 0xbb },
633 { 0x9bbd, 0, 8, 0x93 },
634 { 0x9be2, 0, 8, 0x80 },
635 { 0x9bee, 0, 1, 0x01 },
636};
637
638/* Freescale MC44S803 tuner init
639 AF9013_TUNER_MC44S803 = 133 */
640static struct regdesc tuner_init_mc44s803[] = {
641 { 0x9bd5, 0, 8, 0x01 },
642 { 0x9bd6, 0, 8, 0x06 },
643 { 0xd1a0, 1, 1, 0x01 },
644 { 0xd000, 0, 1, 0x01 },
645 { 0xd000, 1, 1, 0x00 },
646 { 0xd001, 1, 1, 0x01 },
647 { 0xd001, 0, 1, 0x00 },
648 { 0xd001, 5, 1, 0x00 },
649 { 0xd002, 0, 5, 0x19 },
650 { 0xd003, 0, 5, 0x1a },
651 { 0xd004, 0, 5, 0x19 },
652 { 0xd005, 0, 5, 0x1a },
653 { 0xd00e, 0, 5, 0x10 },
654 { 0xd00f, 0, 3, 0x04 },
655 { 0xd00f, 3, 3, 0x05 },
656 { 0xd010, 0, 3, 0x04 },
657 { 0xd010, 3, 3, 0x05 },
658 { 0xd016, 4, 4, 0x03 },
659 { 0xd01f, 0, 6, 0x0a },
660 { 0xd020, 0, 6, 0x0a },
661 { 0x9bda, 0, 8, 0x00 },
662 { 0x9be3, 0, 8, 0x00 },
663 { 0x9bf6, 0, 8, 0x01 },
664 { 0x9bf8, 0, 8, 0x02 },
665 { 0x9bf9, 0, 8, 0x02 },
666 { 0x9bfc, 0, 8, 0x1f },
667 { 0x9bbe, 0, 1, 0x01 },
668 { 0x9bcc, 0, 1, 0x01 },
669 { 0x9bb9, 0, 8, 0x00 },
670 { 0x9bcd, 0, 8, 0x24 },
671 { 0x9bff, 0, 8, 0x24 },
672 { 0xd015, 0, 8, 0x46 },
673 { 0xd016, 0, 1, 0x00 },
674 { 0xd044, 0, 8, 0x46 },
675 { 0xd045, 0, 1, 0x00 },
676 { 0xd008, 0, 8, 0x01 },
677 { 0xd009, 0, 2, 0x02 },
678 { 0xd006, 0, 8, 0x7b },
679 { 0xd007, 0, 2, 0x00 },
680 { 0xd00c, 0, 8, 0x7c },
681 { 0xd00d, 0, 2, 0x02 },
682 { 0xd00a, 0, 8, 0xfe },
683 { 0xd00b, 0, 2, 0x01 },
684 { 0x9bc7, 0, 8, 0x08 },
685 { 0x9bc8, 0, 8, 0x9a },
686 { 0x9bc3, 0, 8, 0x01 },
687 { 0x9bc4, 0, 8, 0x02 },
688 { 0x9bc5, 0, 8, 0x7c },
689 { 0x9bc6, 0, 8, 0x02 },
690 { 0x9bba, 0, 8, 0xfc },
691 { 0x9bc9, 0, 8, 0xaa },
692 { 0xd011, 0, 8, 0x6b },
693 { 0xd012, 0, 2, 0x00 },
694 { 0xd013, 0, 8, 0x88 },
695 { 0xd014, 0, 2, 0x02 },
696 { 0xd040, 0, 8, 0x6b },
697 { 0xd041, 0, 2, 0x00 },
698 { 0xd042, 0, 8, 0x7c },
699 { 0xd043, 0, 2, 0x02 },
700 { 0xd045, 1, 1, 0x00 },
701 { 0x9bcf, 0, 1, 0x01 },
702 { 0xd045, 2, 1, 0x01 },
703 { 0xd04f, 0, 8, 0x9a },
704 { 0xd050, 0, 1, 0x01 },
705 { 0xd051, 0, 8, 0x5a },
706 { 0xd052, 0, 1, 0x01 },
707 { 0xd053, 0, 8, 0x50 },
708 { 0xd054, 0, 8, 0x46 },
709 { 0x9bd7, 0, 8, 0x0a },
710 { 0x9bd8, 0, 8, 0x14 },
711 { 0x9bd9, 0, 8, 0x08 },
712 { 0x9bd0, 0, 8, 0x9e },
713 { 0x9be4, 0, 8, 0xff },
714 { 0x9bbd, 0, 8, 0x9e },
715 { 0x9be2, 0, 8, 0x25 },
716 { 0x9bee, 0, 1, 0x01 },
717 { 0xd73b, 3, 1, 0x00 },
718};
719
720/* unknown, probably for tin can tuner, tuner init
721 AF9013_TUNER_UNKNOWN = 140 */
722static struct regdesc tuner_init_unknown[] = {
723 { 0x9bd5, 0, 8, 0x01 },
724 { 0x9bd6, 0, 8, 0x02 },
725 { 0xd1a0, 1, 1, 0x01 },
726 { 0xd000, 0, 1, 0x01 },
727 { 0xd000, 1, 1, 0x00 },
728 { 0xd001, 1, 1, 0x01 },
729 { 0xd001, 0, 1, 0x00 },
730 { 0xd001, 5, 1, 0x00 },
731 { 0xd002, 0, 5, 0x19 },
732 { 0xd003, 0, 5, 0x1a },
733 { 0xd004, 0, 5, 0x19 },
734 { 0xd005, 0, 5, 0x1a },
735 { 0xd00e, 0, 5, 0x10 },
736 { 0xd00f, 0, 3, 0x04 },
737 { 0xd00f, 3, 3, 0x05 },
738 { 0xd010, 0, 3, 0x04 },
739 { 0xd010, 3, 3, 0x05 },
740 { 0xd016, 4, 4, 0x03 },
741 { 0xd01f, 0, 6, 0x0a },
742 { 0xd020, 0, 6, 0x0a },
743 { 0x9bda, 0, 8, 0x01 },
744 { 0x9be3, 0, 8, 0x01 },
745 { 0xd1a0, 1, 1, 0x00 },
746 { 0x9bbe, 0, 1, 0x01 },
747 { 0x9bcc, 0, 1, 0x01 },
748 { 0x9bb9, 0, 8, 0x00 },
749 { 0x9bcd, 0, 8, 0x18 },
750 { 0x9bff, 0, 8, 0x2c },
751 { 0xd015, 0, 8, 0x46 },
752 { 0xd016, 0, 1, 0x00 },
753 { 0xd044, 0, 8, 0x46 },
754 { 0xd045, 0, 1, 0x00 },
755 { 0xd008, 0, 8, 0xdf },
756 { 0xd009, 0, 2, 0x02 },
757 { 0xd006, 0, 8, 0x44 },
758 { 0xd007, 0, 2, 0x01 },
759 { 0xd00c, 0, 8, 0x00 },
760 { 0xd00d, 0, 2, 0x02 },
761 { 0xd00a, 0, 8, 0xf6 },
762 { 0xd00b, 0, 2, 0x01 },
763 { 0x9bba, 0, 8, 0xf9 },
764 { 0x9bc8, 0, 8, 0xaa },
765 { 0x9bc3, 0, 8, 0xdf },
766 { 0x9bc4, 0, 8, 0x02 },
767 { 0x9bc5, 0, 8, 0x00 },
768 { 0x9bc6, 0, 8, 0x02 },
769 { 0x9bc9, 0, 8, 0xf0 },
770 { 0xd011, 0, 8, 0x3c },
771 { 0xd012, 0, 2, 0x01 },
772 { 0xd013, 0, 8, 0xf7 },
773 { 0xd014, 0, 2, 0x02 },
774 { 0xd040, 0, 8, 0x0b },
775 { 0xd041, 0, 2, 0x02 },
776 { 0xd042, 0, 8, 0x4d },
777 { 0xd043, 0, 2, 0x00 },
778 { 0xd045, 1, 1, 0x00 },
779 { 0x9bcf, 0, 1, 0x01 },
780 { 0xd045, 2, 1, 0x01 },
781 { 0xd04f, 0, 8, 0x9a },
782 { 0xd050, 0, 1, 0x01 },
783 { 0xd051, 0, 8, 0x5a },
784 { 0xd052, 0, 1, 0x01 },
785 { 0xd053, 0, 8, 0x50 },
786 { 0xd054, 0, 8, 0x46 },
787 { 0x9bd7, 0, 8, 0x0a },
788 { 0x9bd8, 0, 8, 0x14 },
789 { 0x9bd9, 0, 8, 0x08 },
790};
791
792/* NXP TDA18271 tuner init
793 AF9013_TUNER_TDA18271 = 156 */
794static struct regdesc tuner_init_tda18271[] = {
795 { 0x9bd5, 0, 8, 0x01 },
796 { 0x9bd6, 0, 8, 0x04 },
797 { 0xd1a0, 1, 1, 0x01 },
798 { 0xd000, 0, 1, 0x01 },
799 { 0xd000, 1, 1, 0x00 },
800 { 0xd001, 1, 1, 0x01 },
801 { 0xd001, 0, 1, 0x00 },
802 { 0xd001, 5, 1, 0x00 },
803 { 0xd002, 0, 5, 0x19 },
804 { 0xd003, 0, 5, 0x1a },
805 { 0xd004, 0, 5, 0x19 },
806 { 0xd005, 0, 5, 0x1a },
807 { 0xd00e, 0, 5, 0x10 },
808 { 0xd00f, 0, 3, 0x04 },
809 { 0xd00f, 3, 3, 0x05 },
810 { 0xd010, 0, 3, 0x04 },
811 { 0xd010, 3, 3, 0x05 },
812 { 0xd016, 4, 4, 0x03 },
813 { 0xd01f, 0, 6, 0x0a },
814 { 0xd020, 0, 6, 0x0a },
815 { 0x9bda, 0, 8, 0x01 },
816 { 0x9be3, 0, 8, 0x01 },
817 { 0xd1a0, 1, 1, 0x00 },
818 { 0x9bbe, 0, 1, 0x01 },
819 { 0x9bcc, 0, 1, 0x01 },
820 { 0x9bb9, 0, 8, 0x00 },
821 { 0x9bcd, 0, 8, 0x18 },
822 { 0x9bff, 0, 8, 0x2c },
823 { 0xd015, 0, 8, 0x46 },
824 { 0xd016, 0, 1, 0x00 },
825 { 0xd044, 0, 8, 0x46 },
826 { 0xd045, 0, 1, 0x00 },
827 { 0xd008, 0, 8, 0xdf },
828 { 0xd009, 0, 2, 0x02 },
829 { 0xd006, 0, 8, 0x44 },
830 { 0xd007, 0, 2, 0x01 },
831 { 0xd00c, 0, 8, 0x00 },
832 { 0xd00d, 0, 2, 0x02 },
833 { 0xd00a, 0, 8, 0xf6 },
834 { 0xd00b, 0, 2, 0x01 },
835 { 0x9bba, 0, 8, 0xf9 },
836 { 0x9bc8, 0, 8, 0xaa },
837 { 0x9bc3, 0, 8, 0xdf },
838 { 0x9bc4, 0, 8, 0x02 },
839 { 0x9bc5, 0, 8, 0x00 },
840 { 0x9bc6, 0, 8, 0x02 },
841 { 0x9bc9, 0, 8, 0xf0 },
842 { 0xd011, 0, 8, 0x3c },
843 { 0xd012, 0, 2, 0x01 },
844 { 0xd013, 0, 8, 0xf7 },
845 { 0xd014, 0, 2, 0x02 },
846 { 0xd040, 0, 8, 0x0b },
847 { 0xd041, 0, 2, 0x02 },
848 { 0xd042, 0, 8, 0x4d },
849 { 0xd043, 0, 2, 0x00 },
850 { 0xd045, 1, 1, 0x00 },
851 { 0x9bcf, 0, 1, 0x01 },
852 { 0xd045, 2, 1, 0x01 },
853 { 0xd04f, 0, 8, 0x9a },
854 { 0xd050, 0, 1, 0x01 },
855 { 0xd051, 0, 8, 0x5a },
856 { 0xd052, 0, 1, 0x01 },
857 { 0xd053, 0, 8, 0x50 },
858 { 0xd054, 0, 8, 0x46 },
859 { 0x9bd7, 0, 8, 0x0a },
860 { 0x9bd8, 0, 8, 0x14 },
861 { 0x9bd9, 0, 8, 0x08 },
862 { 0x9bd0, 0, 8, 0xa8 },
863 { 0x9be4, 0, 8, 0x7f },
864 { 0x9bbd, 0, 8, 0xa8 },
865 { 0x9be2, 0, 8, 0x20 },
866 { 0x9bee, 0, 1, 0x01 },
867};
868
869#endif /* _AF9013_PRIV_ */
diff --git a/drivers/media/dvb/frontends/au8522.c b/drivers/media/dvb/frontends/au8522.c
index 0b82cc2a1e16..eabf9a68e7ec 100644
--- a/drivers/media/dvb/frontends/au8522.c
+++ b/drivers/media/dvb/frontends/au8522.c
@@ -40,6 +40,8 @@ struct au8522_state {
40 u32 current_frequency; 40 u32 current_frequency;
41 fe_modulation_t current_modulation; 41 fe_modulation_t current_modulation;
42 42
43 u32 fe_status;
44 unsigned int led_state;
43}; 45};
44 46
45static int debug; 47static int debug;
@@ -538,11 +540,98 @@ static int au8522_init(struct dvb_frontend *fe)
538 return 0; 540 return 0;
539} 541}
540 542
543static int au8522_led_gpio_enable(struct au8522_state *state, int onoff)
544{
545 struct au8522_led_config *led_config = state->config->led_cfg;
546 u8 val;
547
548 /* bail out if we cant control an LED */
549 if (!led_config || !led_config->gpio_output ||
550 !led_config->gpio_output_enable || !led_config->gpio_output_disable)
551 return 0;
552
553 val = au8522_readreg(state, 0x4000 |
554 (led_config->gpio_output & ~0xc000));
555 if (onoff) {
556 /* enable GPIO output */
557 val &= ~((led_config->gpio_output_enable >> 8) & 0xff);
558 val |= (led_config->gpio_output_enable & 0xff);
559 } else {
560 /* disable GPIO output */
561 val &= ~((led_config->gpio_output_disable >> 8) & 0xff);
562 val |= (led_config->gpio_output_disable & 0xff);
563 }
564 return au8522_writereg(state, 0x8000 |
565 (led_config->gpio_output & ~0xc000), val);
566}
567
568/* led = 0 | off
569 * led = 1 | signal ok
570 * led = 2 | signal strong
571 * led < 0 | only light led if leds are currently off
572 */
573static int au8522_led_ctrl(struct au8522_state *state, int led)
574{
575 struct au8522_led_config *led_config = state->config->led_cfg;
576 int i, ret = 0;
577
578 /* bail out if we cant control an LED */
579 if (!led_config || !led_config->gpio_leds ||
580 !led_config->num_led_states || !led_config->led_states)
581 return 0;
582
583 if (led < 0) {
584 /* if LED is already lit, then leave it as-is */
585 if (state->led_state)
586 return 0;
587 else
588 led *= -1;
589 }
590
591 /* toggle LED if changing state */
592 if (state->led_state != led) {
593 u8 val;
594
595 dprintk("%s: %d\n", __func__, led);
596
597 au8522_led_gpio_enable(state, 1);
598
599 val = au8522_readreg(state, 0x4000 |
600 (led_config->gpio_leds & ~0xc000));
601
602 /* start with all leds off */
603 for (i = 0; i < led_config->num_led_states; i++)
604 val &= ~led_config->led_states[i];
605
606 /* set selected LED state */
607 if (led < led_config->num_led_states)
608 val |= led_config->led_states[led];
609 else if (led_config->num_led_states)
610 val |=
611 led_config->led_states[led_config->num_led_states - 1];
612
613 ret = au8522_writereg(state, 0x8000 |
614 (led_config->gpio_leds & ~0xc000), val);
615 if (ret < 0)
616 return ret;
617
618 state->led_state = led;
619
620 if (led == 0)
621 au8522_led_gpio_enable(state, 0);
622 }
623
624 return 0;
625}
626
541static int au8522_sleep(struct dvb_frontend *fe) 627static int au8522_sleep(struct dvb_frontend *fe)
542{ 628{
543 struct au8522_state *state = fe->demodulator_priv; 629 struct au8522_state *state = fe->demodulator_priv;
544 dprintk("%s()\n", __func__); 630 dprintk("%s()\n", __func__);
545 631
632 /* turn off led */
633 au8522_led_ctrl(state, 0);
634
546 state->current_frequency = 0; 635 state->current_frequency = 0;
547 636
548 return 0; 637 return 0;
@@ -592,12 +681,53 @@ static int au8522_read_status(struct dvb_frontend *fe, fe_status_t *status)
592 *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL; 681 *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL;
593 break; 682 break;
594 } 683 }
684 state->fe_status = *status;
685
686 if (*status & FE_HAS_LOCK)
687 /* turn on LED, if it isn't on already */
688 au8522_led_ctrl(state, -1);
689 else
690 /* turn off LED */
691 au8522_led_ctrl(state, 0);
595 692
596 dprintk("%s() status 0x%08x\n", __func__, *status); 693 dprintk("%s() status 0x%08x\n", __func__, *status);
597 694
598 return 0; 695 return 0;
599} 696}
600 697
698static int au8522_led_status(struct au8522_state *state, const u16 *snr)
699{
700 struct au8522_led_config *led_config = state->config->led_cfg;
701 int led;
702 u16 strong;
703
704 /* bail out if we cant control an LED */
705 if (!led_config)
706 return 0;
707
708 if (0 == (state->fe_status & FE_HAS_LOCK))
709 return au8522_led_ctrl(state, 0);
710 else if (state->current_modulation == QAM_256)
711 strong = led_config->qam256_strong;
712 else if (state->current_modulation == QAM_64)
713 strong = led_config->qam64_strong;
714 else /* (state->current_modulation == VSB_8) */
715 strong = led_config->vsb8_strong;
716
717 if (*snr >= strong)
718 led = 2;
719 else
720 led = 1;
721
722 if ((state->led_state) &&
723 (((strong < *snr) ? (*snr - strong) : (strong - *snr)) <= 10))
724 /* snr didn't change enough to bother
725 * changing the color of the led */
726 return 0;
727
728 return au8522_led_ctrl(state, led);
729}
730
601static int au8522_read_snr(struct dvb_frontend *fe, u16 *snr) 731static int au8522_read_snr(struct dvb_frontend *fe, u16 *snr)
602{ 732{
603 struct au8522_state *state = fe->demodulator_priv; 733 struct au8522_state *state = fe->demodulator_priv;
@@ -621,6 +751,9 @@ static int au8522_read_snr(struct dvb_frontend *fe, u16 *snr)
621 au8522_readreg(state, 0x4311), 751 au8522_readreg(state, 0x4311),
622 snr); 752 snr);
623 753
754 if (state->config->led_cfg)
755 au8522_led_status(state, snr);
756
624 return ret; 757 return ret;
625} 758}
626 759
diff --git a/drivers/media/dvb/frontends/au8522.h b/drivers/media/dvb/frontends/au8522.h
index 595915ade8c3..7b94f554a093 100644
--- a/drivers/media/dvb/frontends/au8522.h
+++ b/drivers/media/dvb/frontends/au8522.h
@@ -30,6 +30,21 @@ enum au8522_if_freq {
30 AU8522_IF_3_25MHZ, 30 AU8522_IF_3_25MHZ,
31}; 31};
32 32
33struct au8522_led_config {
34 u16 vsb8_strong;
35 u16 qam64_strong;
36 u16 qam256_strong;
37
38 u16 gpio_output;
39 /* unset hi bits, set low bits */
40 u16 gpio_output_enable;
41 u16 gpio_output_disable;
42
43 u16 gpio_leds;
44 u8 *led_states;
45 unsigned int num_led_states;
46};
47
33struct au8522_config { 48struct au8522_config {
34 /* the demodulator's i2c address */ 49 /* the demodulator's i2c address */
35 u8 demod_address; 50 u8 demod_address;
@@ -39,6 +54,8 @@ struct au8522_config {
39#define AU8522_DEMODLOCKING 1 54#define AU8522_DEMODLOCKING 1
40 u8 status_mode; 55 u8 status_mode;
41 56
57 struct au8522_led_config *led_cfg;
58
42 enum au8522_if_freq vsb_if; 59 enum au8522_if_freq vsb_if;
43 enum au8522_if_freq qam_if; 60 enum au8522_if_freq qam_if;
44}; 61};
diff --git a/drivers/media/dvb/frontends/cx24110.h b/drivers/media/dvb/frontends/cx24110.h
index 1792adb23c4d..fdcceee91f3a 100644
--- a/drivers/media/dvb/frontends/cx24110.h
+++ b/drivers/media/dvb/frontends/cx24110.h
@@ -33,12 +33,17 @@ struct cx24110_config
33 u8 demod_address; 33 u8 demod_address;
34}; 34};
35 35
36static inline int cx24110_pll_write(struct dvb_frontend *fe, u32 val) { 36static inline int cx24110_pll_write(struct dvb_frontend *fe, u32 val)
37 int r = 0; 37{
38 u8 buf[] = {(u8) (val>>24), (u8) (val>>16), (u8) (val>>8)}; 38 u8 buf[] = {
39 (u8)((val >> 24) & 0xff),
40 (u8)((val >> 16) & 0xff),
41 (u8)((val >> 8) & 0xff)
42 };
43
39 if (fe->ops.write) 44 if (fe->ops.write)
40 r = fe->ops.write(fe, buf, 3); 45 return fe->ops.write(fe, buf, 3);
41 return r; 46 return 0;
42} 47}
43 48
44#if defined(CONFIG_DVB_CX24110) || (defined(CONFIG_DVB_CX24110_MODULE) && defined(MODULE)) 49#if defined(CONFIG_DVB_CX24110) || (defined(CONFIG_DVB_CX24110_MODULE) && defined(MODULE))
diff --git a/drivers/media/dvb/frontends/cx24116.c b/drivers/media/dvb/frontends/cx24116.c
new file mode 100644
index 000000000000..deb36f469ada
--- /dev/null
+++ b/drivers/media/dvb/frontends/cx24116.c
@@ -0,0 +1,1423 @@
1/*
2 Conexant cx24116/cx24118 - DVBS/S2 Satellite demod/tuner driver
3
4 Copyright (C) 2006-2008 Steven Toth <stoth@hauppauge.com>
5 Copyright (C) 2006-2007 Georg Acher
6 Copyright (C) 2007-2008 Darron Broad
7 March 2007
8 Fixed some bugs.
9 Added diseqc support.
10 Added corrected signal strength support.
11 August 2007
12 Sync with legacy version.
13 Some clean ups.
14 Copyright (C) 2008 Igor Liplianin
15 September, 9th 2008
16 Fixed locking on high symbol rates (>30000).
17 Implement MPEG initialization parameter.
18
19 This program is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by
21 the Free Software Foundation; either version 2 of the License, or
22 (at your option) any later version.
23
24 This program is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 GNU General Public License for more details.
28
29 You should have received a copy of the GNU General Public License
30 along with this program; if not, write to the Free Software
31 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32*/
33
34#include <linux/slab.h>
35#include <linux/kernel.h>
36#include <linux/module.h>
37#include <linux/moduleparam.h>
38#include <linux/init.h>
39#include <linux/firmware.h>
40
41#include "dvb_frontend.h"
42#include "cx24116.h"
43
44static int debug = 0;
45#define dprintk(args...) \
46 do { \
47 if (debug) printk ("cx24116: " args); \
48 } while (0)
49
50#define CX24116_DEFAULT_FIRMWARE "dvb-fe-cx24116.fw"
51#define CX24116_SEARCH_RANGE_KHZ 5000
52
53/* known registers */
54#define CX24116_REG_COMMAND (0x00) /* command args 0x00..0x1e */
55#define CX24116_REG_EXECUTE (0x1f) /* execute command */
56#define CX24116_REG_MAILBOX (0x96) /* FW or multipurpose mailbox? */
57#define CX24116_REG_RESET (0x20) /* reset status > 0 */
58#define CX24116_REG_SIGNAL (0x9e) /* signal low */
59#define CX24116_REG_SSTATUS (0x9d) /* signal high / status */
60#define CX24116_REG_QUALITY8 (0xa3)
61#define CX24116_REG_QSTATUS (0xbc)
62#define CX24116_REG_QUALITY0 (0xd5)
63#define CX24116_REG_BER0 (0xc9)
64#define CX24116_REG_BER8 (0xc8)
65#define CX24116_REG_BER16 (0xc7)
66#define CX24116_REG_BER24 (0xc6)
67#define CX24116_REG_UCB0 (0xcb)
68#define CX24116_REG_UCB8 (0xca)
69#define CX24116_REG_CLKDIV (0xf3)
70#define CX24116_REG_RATEDIV (0xf9)
71#define CX24116_REG_FECSTATUS (0x9c) /* configured fec (not tuned) or actual FEC (tuned) 1=1/2 2=2/3 etc */
72
73/* FECSTATUS bits */
74#define CX24116_FEC_FECMASK (0x1f) /* mask to determine configured fec (not tuned) or actual fec (tuned) */
75#define CX24116_FEC_DVBS (0x20) /* Select DVB-S demodulator, else DVB-S2 */
76#define CX24116_FEC_UNKNOWN (0x40) /* Unknown/unused */
77#define CX24116_FEC_PILOT (0x80) /* Pilot mode requested when tuning else always reset when tuned */
78
79/* arg buffer size */
80#define CX24116_ARGLEN (0x1e)
81
82/* rolloff */
83#define CX24116_ROLLOFF_020 (0x00)
84#define CX24116_ROLLOFF_025 (0x01)
85#define CX24116_ROLLOFF_035 (0x02)
86
87/* pilot bit */
88#define CX24116_PILOT_OFF (0x00)
89#define CX24116_PILOT_ON (0x40)
90
91/* signal status */
92#define CX24116_HAS_SIGNAL (0x01)
93#define CX24116_HAS_CARRIER (0x02)
94#define CX24116_HAS_VITERBI (0x04)
95#define CX24116_HAS_SYNCLOCK (0x08)
96#define CX24116_HAS_UNKNOWN1 (0x10)
97#define CX24116_HAS_UNKNOWN2 (0x20)
98#define CX24116_STATUS_MASK (0x3f)
99#define CX24116_SIGNAL_MASK (0xc0)
100
101#define CX24116_DISEQC_TONEOFF (0) /* toneburst never sent */
102#define CX24116_DISEQC_TONECACHE (1) /* toneburst cached */
103#define CX24116_DISEQC_MESGCACHE (2) /* message cached */
104
105/* arg offset for DiSEqC */
106#define CX24116_DISEQC_BURST (1)
107#define CX24116_DISEQC_ARG2_2 (2) /* unknown value=2 */
108#define CX24116_DISEQC_ARG3_0 (3) /* unknown value=0 */
109#define CX24116_DISEQC_ARG4_0 (4) /* unknown value=0 */
110#define CX24116_DISEQC_MSGLEN (5)
111#define CX24116_DISEQC_MSGOFS (6)
112
113/* DiSEqC burst */
114#define CX24116_DISEQC_MINI_A (0)
115#define CX24116_DISEQC_MINI_B (1)
116
117/* DiSEqC tone burst */
118static int toneburst = 1;
119
120/* SNR measurements */
121static int esno_snr = 0;
122
123enum cmds
124{
125 CMD_SET_VCO = 0x10,
126 CMD_TUNEREQUEST = 0x11,
127 CMD_MPEGCONFIG = 0x13,
128 CMD_TUNERINIT = 0x14,
129 CMD_BANDWIDTH = 0x15,
130 CMD_GETAGC = 0x19,
131 CMD_LNBCONFIG = 0x20,
132 CMD_LNBSEND = 0x21, /* Formerly CMD_SEND_DISEQC */
133 CMD_SET_TONEPRE = 0x22,
134 CMD_SET_TONE = 0x23,
135 CMD_UPDFWVERS = 0x35,
136 CMD_TUNERSLEEP = 0x36,
137 CMD_AGCCONTROL = 0x3b, /* Unknown */
138};
139
140/* The Demod/Tuner can't easily provide these, we cache them */
141struct cx24116_tuning
142{
143 u32 frequency;
144 u32 symbol_rate;
145 fe_spectral_inversion_t inversion;
146 fe_code_rate_t fec;
147
148 fe_modulation_t modulation;
149 fe_pilot_t pilot;
150 fe_rolloff_t rolloff;
151
152 /* Demod values */
153 u8 fec_val;
154 u8 fec_mask;
155 u8 inversion_val;
156 u8 pilot_val;
157 u8 rolloff_val;
158};
159
160/* Basic commands that are sent to the firmware */
161struct cx24116_cmd
162{
163 u8 len;
164 u8 args[CX24116_ARGLEN];
165};
166
167struct cx24116_state
168{
169 struct i2c_adapter* i2c;
170 const struct cx24116_config* config;
171
172 struct dvb_frontend frontend;
173
174 struct cx24116_tuning dcur;
175 struct cx24116_tuning dnxt;
176
177 u8 skip_fw_load;
178 u8 burst;
179 struct cx24116_cmd dsec_cmd;
180};
181
182static int cx24116_writereg(struct cx24116_state* state, int reg, int data)
183{
184 u8 buf[] = { reg, data };
185 struct i2c_msg msg = { .addr = state->config->demod_address,
186 .flags = 0, .buf = buf, .len = 2 };
187 int err;
188
189 if (debug>1)
190 printk("cx24116: %s: write reg 0x%02x, value 0x%02x\n",
191 __func__,reg, data);
192
193 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
194 printk("%s: writereg error(err == %i, reg == 0x%02x,"
195 " value == 0x%02x)\n", __func__, err, reg, data);
196 return -EREMOTEIO;
197 }
198
199 return 0;
200}
201
202/* Bulk byte writes to a single I2C address, for 32k firmware load */
203static int cx24116_writeregN(struct cx24116_state* state, int reg, u8 *data, u16 len)
204{
205 int ret = -EREMOTEIO;
206 struct i2c_msg msg;
207 u8 *buf;
208
209 buf = kmalloc(len + 1, GFP_KERNEL);
210 if (buf == NULL) {
211 printk("Unable to kmalloc\n");
212 ret = -ENOMEM;
213 goto error;
214 }
215
216 *(buf) = reg;
217 memcpy(buf + 1, data, len);
218
219 msg.addr = state->config->demod_address;
220 msg.flags = 0;
221 msg.buf = buf;
222 msg.len = len + 1;
223
224 if (debug>1)
225 printk("cx24116: %s: write regN 0x%02x, len = %d\n",
226 __func__,reg, len);
227
228 if ((ret = i2c_transfer(state->i2c, &msg, 1)) != 1) {
229 printk("%s: writereg error(err == %i, reg == 0x%02x\n",
230 __func__, ret, reg);
231 ret = -EREMOTEIO;
232 }
233
234error:
235 kfree(buf);
236
237 return ret;
238}
239
240static int cx24116_readreg(struct cx24116_state* state, u8 reg)
241{
242 int ret;
243 u8 b0[] = { reg };
244 u8 b1[] = { 0 };
245 struct i2c_msg msg[] = {
246 { .addr = state->config->demod_address, .flags = 0, .buf = b0, .len = 1 },
247 { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 1 }
248 };
249
250 ret = i2c_transfer(state->i2c, msg, 2);
251
252 if (ret != 2) {
253 printk("%s: reg=0x%x (error=%d)\n", __func__, reg, ret);
254 return ret;
255 }
256
257 if (debug>1)
258 printk("cx24116: read reg 0x%02x, value 0x%02x\n",reg, b1[0]);
259
260 return b1[0];
261}
262
263static int cx24116_set_inversion(struct cx24116_state* state, fe_spectral_inversion_t inversion)
264{
265 dprintk("%s(%d)\n", __func__, inversion);
266
267 switch (inversion) {
268 case INVERSION_OFF:
269 state->dnxt.inversion_val = 0x00;
270 break;
271 case INVERSION_ON:
272 state->dnxt.inversion_val = 0x04;
273 break;
274 case INVERSION_AUTO:
275 state->dnxt.inversion_val = 0x0C;
276 break;
277 default:
278 return -EINVAL;
279 }
280
281 state->dnxt.inversion = inversion;
282
283 return 0;
284}
285
286/*
287 * modfec (modulation and FEC)
288 * ===========================
289 *
290 * MOD FEC mask/val standard
291 * ---- -------- ----------- --------
292 * QPSK FEC_1_2 0x02 0x02+X DVB-S
293 * QPSK FEC_2_3 0x04 0x02+X DVB-S
294 * QPSK FEC_3_4 0x08 0x02+X DVB-S
295 * QPSK FEC_4_5 0x10 0x02+X DVB-S (?)
296 * QPSK FEC_5_6 0x20 0x02+X DVB-S
297 * QPSK FEC_6_7 0x40 0x02+X DVB-S
298 * QPSK FEC_7_8 0x80 0x02+X DVB-S
299 * QPSK FEC_8_9 0x01 0x02+X DVB-S (?) (NOT SUPPORTED?)
300 * QPSK AUTO 0xff 0x02+X DVB-S
301 *
302 * For DVB-S high byte probably represents FEC
303 * and low byte selects the modulator. The high
304 * byte is search range mask. Bit 5 may turn
305 * on DVB-S and remaining bits represent some
306 * kind of calibration (how/what i do not know).
307 *
308 * Eg.(2/3) szap "Zone Horror"
309 *
310 * mask/val = 0x04, 0x20
311 * status 1f | signal c3c0 | snr a333 | ber 00000098 | unc 00000000 | FE_HAS_LOCK
312 *
313 * mask/val = 0x04, 0x30
314 * status 1f | signal c3c0 | snr a333 | ber 00000000 | unc 00000000 | FE_HAS_LOCK
315 *
316 * After tuning FECSTATUS contains actual FEC
317 * in use numbered 1 through to 8 for 1/2 .. 2/3 etc
318 *
319 * NBC=NOT/NON BACKWARD COMPATIBLE WITH DVB-S (DVB-S2 only)
320 *
321 * NBC-QPSK FEC_1_2 0x00, 0x04 DVB-S2
322 * NBC-QPSK FEC_3_5 0x00, 0x05 DVB-S2
323 * NBC-QPSK FEC_2_3 0x00, 0x06 DVB-S2
324 * NBC-QPSK FEC_3_4 0x00, 0x07 DVB-S2
325 * NBC-QPSK FEC_4_5 0x00, 0x08 DVB-S2
326 * NBC-QPSK FEC_5_6 0x00, 0x09 DVB-S2
327 * NBC-QPSK FEC_8_9 0x00, 0x0a DVB-S2
328 * NBC-QPSK FEC_9_10 0x00, 0x0b DVB-S2
329 *
330 * NBC-8PSK FEC_3_5 0x00, 0x0c DVB-S2
331 * NBC-8PSK FEC_2_3 0x00, 0x0d DVB-S2
332 * NBC-8PSK FEC_3_4 0x00, 0x0e DVB-S2
333 * NBC-8PSK FEC_5_6 0x00, 0x0f DVB-S2
334 * NBC-8PSK FEC_8_9 0x00, 0x10 DVB-S2
335 * NBC-8PSK FEC_9_10 0x00, 0x11 DVB-S2
336 *
337 * For DVB-S2 low bytes selects both modulator
338 * and FEC. High byte is meaningless here. To
339 * set pilot, bit 6 (0x40) is set. When inspecting
340 * FECSTATUS bit 7 (0x80) represents the pilot
341 * selection whilst not tuned. When tuned, actual FEC
342 * in use is found in FECSTATUS as per above. Pilot
343 * value is reset.
344 */
345
346/* A table of modulation, fec and configuration bytes for the demod.
347 * Not all S2 mmodulation schemes are support and not all rates with
348 * a scheme are support. Especially, no auto detect when in S2 mode.
349 */
350struct cx24116_modfec {
351 fe_delivery_system_t delivery_system;
352 fe_modulation_t modulation;
353 fe_code_rate_t fec;
354 u8 mask; /* In DVBS mode this is used to autodetect */
355 u8 val; /* Passed to the firmware to indicate mode selection */
356} CX24116_MODFEC_MODES[] = {
357 /* QPSK. For unknown rates we set hardware to auto detect 0xfe 0x30 */
358
359 /*mod fec mask val */
360 { SYS_DVBS, QPSK, FEC_NONE, 0xfe, 0x30 },
361 { SYS_DVBS, QPSK, FEC_1_2, 0x02, 0x2e }, /* 00000010 00101110 */
362 { SYS_DVBS, QPSK, FEC_2_3, 0x04, 0x2f }, /* 00000100 00101111 */
363 { SYS_DVBS, QPSK, FEC_3_4, 0x08, 0x30 }, /* 00001000 00110000 */
364 { SYS_DVBS, QPSK, FEC_4_5, 0xfe, 0x30 }, /* 000?0000 ? */
365 { SYS_DVBS, QPSK, FEC_5_6, 0x20, 0x31 }, /* 00100000 00110001 */
366 { SYS_DVBS, QPSK, FEC_6_7, 0xfe, 0x30 }, /* 0?000000 ? */
367 { SYS_DVBS, QPSK, FEC_7_8, 0x80, 0x32 }, /* 10000000 00110010 */
368 { SYS_DVBS, QPSK, FEC_8_9, 0xfe, 0x30 }, /* 0000000? ? */
369 { SYS_DVBS, QPSK, FEC_AUTO, 0xfe, 0x30 },
370 /* NBC-QPSK */
371 { SYS_DVBS2, QPSK, FEC_1_2, 0x00, 0x04 },
372 { SYS_DVBS2, QPSK, FEC_3_5, 0x00, 0x05 },
373 { SYS_DVBS2, QPSK, FEC_2_3, 0x00, 0x06 },
374 { SYS_DVBS2, QPSK, FEC_3_4, 0x00, 0x07 },
375 { SYS_DVBS2, QPSK, FEC_4_5, 0x00, 0x08 },
376 { SYS_DVBS2, QPSK, FEC_5_6, 0x00, 0x09 },
377 { SYS_DVBS2, QPSK, FEC_8_9, 0x00, 0x0a },
378 { SYS_DVBS2, QPSK, FEC_9_10, 0x00, 0x0b },
379 /* 8PSK */
380 { SYS_DVBS2, PSK_8, FEC_3_5, 0x00, 0x0c },
381 { SYS_DVBS2, PSK_8, FEC_2_3, 0x00, 0x0d },
382 { SYS_DVBS2, PSK_8, FEC_3_4, 0x00, 0x0e },
383 { SYS_DVBS2, PSK_8, FEC_5_6, 0x00, 0x0f },
384 { SYS_DVBS2, PSK_8, FEC_8_9, 0x00, 0x10 },
385 { SYS_DVBS2, PSK_8, FEC_9_10, 0x00, 0x11 },
386 /*
387 * `val' can be found in the FECSTATUS register when tuning.
388 * FECSTATUS will give the actual FEC in use if tuning was successful.
389 */
390};
391
392static int cx24116_lookup_fecmod(struct cx24116_state* state,
393 fe_modulation_t m, fe_code_rate_t f)
394{
395 int i, ret = -EOPNOTSUPP;
396
397 dprintk("%s(0x%02x,0x%02x)\n", __func__, m, f);
398
399 for(i=0 ; i < sizeof(CX24116_MODFEC_MODES) / sizeof(struct cx24116_modfec) ; i++)
400 {
401 if( (m == CX24116_MODFEC_MODES[i].modulation) &&
402 (f == CX24116_MODFEC_MODES[i].fec) )
403 {
404 ret = i;
405 break;
406 }
407 }
408
409 return ret;
410}
411
412static int cx24116_set_fec(struct cx24116_state* state, fe_modulation_t mod, fe_code_rate_t fec)
413{
414 int ret = 0;
415
416 dprintk("%s(0x%02x,0x%02x)\n", __func__, mod, fec);
417
418 ret = cx24116_lookup_fecmod(state, mod, fec);
419
420 if(ret < 0)
421 return ret;
422
423 state->dnxt.fec = fec;
424 state->dnxt.fec_val = CX24116_MODFEC_MODES[ret].val;
425 state->dnxt.fec_mask = CX24116_MODFEC_MODES[ret].mask;
426 dprintk("%s() mask/val = 0x%02x/0x%02x\n", __func__,
427 state->dnxt.fec_mask, state->dnxt.fec_val);
428
429 return 0;
430}
431
432static int cx24116_set_symbolrate(struct cx24116_state* state, u32 rate)
433{
434 dprintk("%s(%d)\n", __func__, rate);
435
436 /* check if symbol rate is within limits */
437 if ((rate > state->frontend.ops.info.symbol_rate_max) ||
438 (rate < state->frontend.ops.info.symbol_rate_min)) {
439 dprintk("%s() unsupported symbol_rate = %d\n", __func__, rate);
440 return -EOPNOTSUPP;
441 }
442
443 state->dnxt.symbol_rate = rate;
444 dprintk("%s() symbol_rate = %d\n", __func__, rate);
445
446 return 0;
447}
448
449static int cx24116_load_firmware (struct dvb_frontend* fe, const struct firmware *fw);
450
451static int cx24116_firmware_ondemand(struct dvb_frontend* fe)
452{
453 struct cx24116_state *state = fe->demodulator_priv;
454 const struct firmware *fw;
455 int ret = 0;
456
457 dprintk("%s()\n",__func__);
458
459 if (cx24116_readreg(state, 0x20) > 0)
460 {
461
462 if (state->skip_fw_load)
463 return 0;
464
465 /* Load firmware */
466 /* request the firmware, this will block until someone uploads it */
467 printk("%s: Waiting for firmware upload (%s)...\n", __func__, CX24116_DEFAULT_FIRMWARE);
468 ret = request_firmware(&fw, CX24116_DEFAULT_FIRMWARE, &state->i2c->dev);
469 printk("%s: Waiting for firmware upload(2)...\n", __func__);
470 if (ret) {
471 printk("%s: No firmware uploaded (timeout or file not found?)\n", __func__);
472 return ret;
473 }
474
475 /* Make sure we don't recurse back through here during loading */
476 state->skip_fw_load = 1;
477
478 ret = cx24116_load_firmware(fe, fw);
479 if (ret)
480 printk("%s: Writing firmware to device failed\n", __func__);
481
482 release_firmware(fw);
483
484 printk("%s: Firmware upload %s\n", __func__, ret == 0 ? "complete" : "failed");
485
486 /* Ensure firmware is always loaded if required */
487 state->skip_fw_load = 0;
488 }
489
490 return ret;
491}
492
493/* Take a basic firmware command structure, format it and forward it for processing */
494static int cx24116_cmd_execute(struct dvb_frontend* fe, struct cx24116_cmd *cmd)
495{
496 struct cx24116_state *state = fe->demodulator_priv;
497 int i, ret;
498
499 dprintk("%s()\n", __func__);
500
501 /* Load the firmware if required */
502 if ( (ret = cx24116_firmware_ondemand(fe)) != 0)
503 {
504 printk("%s(): Unable initialise the firmware\n", __func__);
505 return ret;
506 }
507
508 /* Write the command */
509 for(i = 0; i < cmd->len ; i++)
510 {
511 dprintk("%s: 0x%02x == 0x%02x\n", __func__, i, cmd->args[i]);
512 cx24116_writereg(state, i, cmd->args[i]);
513 }
514
515 /* Start execution and wait for cmd to terminate */
516 cx24116_writereg(state, CX24116_REG_EXECUTE, 0x01);
517 while( cx24116_readreg(state, CX24116_REG_EXECUTE) )
518 {
519 msleep(10);
520 if(i++ > 64)
521 {
522 /* Avoid looping forever if the firmware does no respond */
523 printk("%s() Firmware not responding\n", __func__);
524 return -EREMOTEIO;
525 }
526 }
527 return 0;
528}
529
530static int cx24116_load_firmware (struct dvb_frontend* fe, const struct firmware *fw)
531{
532 struct cx24116_state* state = fe->demodulator_priv;
533 struct cx24116_cmd cmd;
534 int i, ret;
535 unsigned char vers[4];
536
537 dprintk("%s\n", __func__);
538 dprintk("Firmware is %zu bytes (%02x %02x .. %02x %02x)\n"
539 ,fw->size
540 ,fw->data[0]
541 ,fw->data[1]
542 ,fw->data[ fw->size-2 ]
543 ,fw->data[ fw->size-1 ]
544 );
545
546 /* Toggle 88x SRST pin to reset demod */
547 if (state->config->reset_device)
548 state->config->reset_device(fe);
549
550 /* Begin the firmware load process */
551 /* Prepare the demod, load the firmware, cleanup after load */
552
553 /* Init PLL */
554 cx24116_writereg(state, 0xE5, 0x00);
555 cx24116_writereg(state, 0xF1, 0x08);
556 cx24116_writereg(state, 0xF2, 0x13);
557
558 /* Start PLL */
559 cx24116_writereg(state, 0xe0, 0x03);
560 cx24116_writereg(state, 0xe0, 0x00);
561
562 /* Unknown */
563 cx24116_writereg(state, CX24116_REG_CLKDIV, 0x46);
564 cx24116_writereg(state, CX24116_REG_RATEDIV, 0x00);
565
566 /* Unknown */
567 cx24116_writereg(state, 0xF0, 0x03);
568 cx24116_writereg(state, 0xF4, 0x81);
569 cx24116_writereg(state, 0xF5, 0x00);
570 cx24116_writereg(state, 0xF6, 0x00);
571
572 /* write the entire firmware as one transaction */
573 cx24116_writeregN(state, 0xF7, fw->data, fw->size);
574
575 cx24116_writereg(state, 0xF4, 0x10);
576 cx24116_writereg(state, 0xF0, 0x00);
577 cx24116_writereg(state, 0xF8, 0x06);
578
579 /* Firmware CMD 10: VCO config */
580 cmd.args[0x00] = CMD_SET_VCO;
581 cmd.args[0x01] = 0x05;
582 cmd.args[0x02] = 0xdc;
583 cmd.args[0x03] = 0xda;
584 cmd.args[0x04] = 0xae;
585 cmd.args[0x05] = 0xaa;
586 cmd.args[0x06] = 0x04;
587 cmd.args[0x07] = 0x9d;
588 cmd.args[0x08] = 0xfc;
589 cmd.args[0x09] = 0x06;
590 cmd.len= 0x0a;
591 ret = cx24116_cmd_execute(fe, &cmd);
592 if (ret != 0)
593 return ret;
594
595 cx24116_writereg(state, CX24116_REG_SSTATUS, 0x00);
596
597 /* Firmware CMD 14: Tuner config */
598 cmd.args[0x00] = CMD_TUNERINIT;
599 cmd.args[0x01] = 0x00;
600 cmd.args[0x02] = 0x00;
601 cmd.len= 0x03;
602 ret = cx24116_cmd_execute(fe, &cmd);
603 if (ret != 0)
604 return ret;
605
606 cx24116_writereg(state, 0xe5, 0x00);
607
608 /* Firmware CMD 13: MPEG config */
609 cmd.args[0x00] = CMD_MPEGCONFIG;
610 cmd.args[0x01] = 0x01;
611 cmd.args[0x02] = 0x75;
612 cmd.args[0x03] = 0x00;
613 if (state->config->mpg_clk_pos_pol)
614 cmd.args[0x04] = state->config->mpg_clk_pos_pol;
615 else
616 cmd.args[0x04] = 0x02;
617 cmd.args[0x05] = 0x00;
618 cmd.len= 0x06;
619 ret = cx24116_cmd_execute(fe, &cmd);
620 if (ret != 0)
621 return ret;
622
623 /* Firmware CMD 35: Get firmware version */
624 cmd.args[0x00] = CMD_UPDFWVERS;
625 cmd.len= 0x02;
626 for(i=0; i<4; i++) {
627 cmd.args[0x01] = i;
628 ret = cx24116_cmd_execute(fe, &cmd);
629 if (ret != 0)
630 return ret;
631 vers[i]= cx24116_readreg(state, CX24116_REG_MAILBOX);
632 }
633 printk("%s: FW version %i.%i.%i.%i\n", __func__,
634 vers[0], vers[1], vers[2], vers[3]);
635
636 return 0;
637}
638
639static int cx24116_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
640{
641 /* The isl6421 module will override this function in the fops. */
642 dprintk("%s() This should never appear if the isl6421 module is loaded correctly\n",__func__);
643
644 return -EOPNOTSUPP;
645}
646
647static int cx24116_read_status(struct dvb_frontend* fe, fe_status_t* status)
648{
649 struct cx24116_state *state = fe->demodulator_priv;
650
651 int lock = cx24116_readreg(state, CX24116_REG_SSTATUS);
652
653 dprintk("%s: status = 0x%02x\n", __func__, lock);
654
655 *status = 0;
656
657 if (lock & CX24116_HAS_SIGNAL)
658 *status |= FE_HAS_SIGNAL;
659 if (lock & CX24116_HAS_CARRIER)
660 *status |= FE_HAS_CARRIER;
661 if (lock & CX24116_HAS_VITERBI)
662 *status |= FE_HAS_VITERBI;
663 if (lock & CX24116_HAS_SYNCLOCK)
664 *status |= FE_HAS_SYNC | FE_HAS_LOCK;
665
666 return 0;
667}
668
669static int cx24116_read_ber(struct dvb_frontend* fe, u32* ber)
670{
671 struct cx24116_state *state = fe->demodulator_priv;
672
673 dprintk("%s()\n", __func__);
674
675 *ber = ( cx24116_readreg(state, CX24116_REG_BER24) << 24 ) |
676 ( cx24116_readreg(state, CX24116_REG_BER16) << 16 ) |
677 ( cx24116_readreg(state, CX24116_REG_BER8 ) << 8 ) |
678 cx24116_readreg(state, CX24116_REG_BER0 );
679
680 return 0;
681}
682
683/* TODO Determine function and scale appropriately */
684static int cx24116_read_signal_strength(struct dvb_frontend* fe, u16* signal_strength)
685{
686 struct cx24116_state *state = fe->demodulator_priv;
687 struct cx24116_cmd cmd;
688 int ret;
689 u16 sig_reading;
690
691 dprintk("%s()\n", __func__);
692
693 /* Firmware CMD 19: Get AGC */
694 cmd.args[0x00] = CMD_GETAGC;
695 cmd.len= 0x01;
696 ret = cx24116_cmd_execute(fe, &cmd);
697 if (ret != 0)
698 return ret;
699
700 sig_reading = ( cx24116_readreg(state, CX24116_REG_SSTATUS) & CX24116_SIGNAL_MASK ) |
701 ( cx24116_readreg(state, CX24116_REG_SIGNAL) << 6 );
702 *signal_strength= 0 - sig_reading;
703
704 dprintk("%s: raw / cooked = 0x%04x / 0x%04x\n", __func__, sig_reading, *signal_strength);
705
706 return 0;
707}
708
709/* SNR (0..100)% = (sig & 0xf0) * 10 + (sig & 0x0f) * 10 / 16 */
710static int cx24116_read_snr_pct(struct dvb_frontend* fe, u16* snr)
711{
712 struct cx24116_state *state = fe->demodulator_priv;
713 u8 snr_reading;
714 static const u32 snr_tab[] = { /* 10 x Table (rounded up) */
715 0x00000,0x0199A,0x03333,0x04ccD,0x06667,
716 0x08000,0x0999A,0x0b333,0x0cccD,0x0e667,
717 0x10000,0x1199A,0x13333,0x14ccD,0x16667,0x18000 };
718
719 dprintk("%s()\n", __func__);
720
721 snr_reading = cx24116_readreg(state, CX24116_REG_QUALITY0);
722
723 if(snr_reading >= 0xa0 /* 100% */)
724 *snr = 0xffff;
725 else
726 *snr = snr_tab [ ( snr_reading & 0xf0 ) >> 4 ] +
727 ( snr_tab [ ( snr_reading & 0x0f ) ] >> 4 );
728
729 dprintk("%s: raw / cooked = 0x%02x / 0x%04x\n", __func__,
730 snr_reading, *snr);
731
732 return 0;
733}
734
735/* The reelbox patches show the value in the registers represents
736 * ESNO, from 0->30db (values 0->300). We provide this value by
737 * default.
738 */
739static int cx24116_read_snr_esno(struct dvb_frontend* fe, u16* snr)
740{
741 struct cx24116_state *state = fe->demodulator_priv;
742
743 dprintk("%s()\n", __func__);
744
745 *snr = cx24116_readreg(state, CX24116_REG_QUALITY8) << 8 |
746 cx24116_readreg(state, CX24116_REG_QUALITY0);
747
748 dprintk("%s: raw 0x%04x\n", __func__, *snr);
749
750 return 0;
751}
752
753static int cx24116_read_snr(struct dvb_frontend* fe, u16* snr)
754{
755 if (esno_snr == 1)
756 return cx24116_read_snr_esno(fe, snr);
757 else
758 return cx24116_read_snr_pct(fe, snr);
759}
760
761static int cx24116_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
762{
763 struct cx24116_state *state = fe->demodulator_priv;
764
765 dprintk("%s()\n", __func__);
766
767 *ucblocks = ( cx24116_readreg(state, CX24116_REG_UCB8) << 8 ) |
768 cx24116_readreg(state, CX24116_REG_UCB0);
769
770 return 0;
771}
772
773/* Overwrite the current tuning params, we are about to tune */
774static void cx24116_clone_params(struct dvb_frontend* fe)
775{
776 struct cx24116_state *state = fe->demodulator_priv;
777 memcpy(&state->dcur, &state->dnxt, sizeof(state->dcur));
778}
779
780/* Wait for LNB */
781static int cx24116_wait_for_lnb(struct dvb_frontend* fe)
782{
783 struct cx24116_state *state = fe->demodulator_priv;
784 int i;
785
786 dprintk("%s() qstatus = 0x%02x\n", __func__,
787 cx24116_readreg(state, CX24116_REG_QSTATUS));
788
789 /* Wait for up to 300 ms */
790 for(i = 0; i < 30 ; i++) {
791 if (cx24116_readreg(state, CX24116_REG_QSTATUS) & 0x20)
792 return 0;
793 msleep(10);
794 }
795
796 dprintk("%s(): LNB not ready\n", __func__);
797
798 return -ETIMEDOUT; /* -EBUSY ? */
799}
800
801static int cx24116_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
802{
803 struct cx24116_cmd cmd;
804 int ret;
805
806 dprintk("%s(%d)\n", __func__, tone);
807 if ( (tone != SEC_TONE_ON) && (tone != SEC_TONE_OFF) ) {
808 printk("%s: Invalid, tone=%d\n", __func__, tone);
809 return -EINVAL;
810 }
811
812 /* Wait for LNB ready */
813 ret = cx24116_wait_for_lnb(fe);
814 if(ret != 0)
815 return ret;
816
817 /* Min delay time after DiSEqC send */
818 msleep(15); /* XXX determine is FW does this, see send_diseqc/burst */
819
820 /* This is always done before the tone is set */
821 cmd.args[0x00] = CMD_SET_TONEPRE;
822 cmd.args[0x01] = 0x00;
823 cmd.len= 0x02;
824 ret = cx24116_cmd_execute(fe, &cmd);
825 if (ret != 0)
826 return ret;
827
828 /* Now we set the tone */
829 cmd.args[0x00] = CMD_SET_TONE;
830 cmd.args[0x01] = 0x00;
831 cmd.args[0x02] = 0x00;
832
833 switch (tone) {
834 case SEC_TONE_ON:
835 dprintk("%s: setting tone on\n", __func__);
836 cmd.args[0x03] = 0x01;
837 break;
838 case SEC_TONE_OFF:
839 dprintk("%s: setting tone off\n",__func__);
840 cmd.args[0x03] = 0x00;
841 break;
842 }
843 cmd.len= 0x04;
844
845 /* Min delay time before DiSEqC send */
846 msleep(15); /* XXX determine is FW does this, see send_diseqc/burst */
847
848 return cx24116_cmd_execute(fe, &cmd);
849}
850
851/* Initialise DiSEqC */
852static int cx24116_diseqc_init(struct dvb_frontend* fe)
853{
854 struct cx24116_state *state = fe->demodulator_priv;
855 struct cx24116_cmd cmd;
856 int ret;
857
858 /* Firmware CMD 20: LNB/DiSEqC config */
859 cmd.args[0x00] = CMD_LNBCONFIG;
860 cmd.args[0x01] = 0x00;
861 cmd.args[0x02] = 0x10;
862 cmd.args[0x03] = 0x00;
863 cmd.args[0x04] = 0x8f;
864 cmd.args[0x05] = 0x28;
865 cmd.args[0x06] = (toneburst == CX24116_DISEQC_TONEOFF) ? 0x00 : 0x01;
866 cmd.args[0x07] = 0x01;
867 cmd.len= 0x08;
868 ret = cx24116_cmd_execute(fe, &cmd);
869 if (ret != 0)
870 return ret;
871
872 /* Prepare a DiSEqC command */
873 state->dsec_cmd.args[0x00] = CMD_LNBSEND;
874
875 /* DiSEqC burst */
876 state->dsec_cmd.args[CX24116_DISEQC_BURST] = CX24116_DISEQC_MINI_A;
877
878 /* Unknown */
879 state->dsec_cmd.args[CX24116_DISEQC_ARG2_2] = 0x02;
880 state->dsec_cmd.args[CX24116_DISEQC_ARG3_0] = 0x00;
881 state->dsec_cmd.args[CX24116_DISEQC_ARG4_0] = 0x00; /* Continuation flag? */
882
883 /* DiSEqC message length */
884 state->dsec_cmd.args[CX24116_DISEQC_MSGLEN] = 0x00;
885
886 /* Command length */
887 state->dsec_cmd.len= CX24116_DISEQC_MSGOFS;
888
889 return 0;
890}
891
892/* Send DiSEqC message with derived burst (hack) || previous burst */
893static int cx24116_send_diseqc_msg(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *d)
894{
895 struct cx24116_state *state = fe->demodulator_priv;
896 int i, ret;
897
898 /* Dump DiSEqC message */
899 if (debug) {
900 printk("cx24116: %s(", __func__);
901 for(i = 0 ; i < d->msg_len ;) {
902 printk("0x%02x", d->msg[i]);
903 if(++i < d->msg_len)
904 printk(", ");
905 }
906 printk(") toneburst=%d\n", toneburst);
907 }
908
909 /* Validate length */
910 if(d->msg_len > (CX24116_ARGLEN - CX24116_DISEQC_MSGOFS))
911 return -EINVAL;
912
913 /* DiSEqC message */
914 for (i = 0; i < d->msg_len; i++)
915 state->dsec_cmd.args[CX24116_DISEQC_MSGOFS + i] = d->msg[i];
916
917 /* DiSEqC message length */
918 state->dsec_cmd.args[CX24116_DISEQC_MSGLEN] = d->msg_len;
919
920 /* Command length */
921 state->dsec_cmd.len= CX24116_DISEQC_MSGOFS + state->dsec_cmd.args[CX24116_DISEQC_MSGLEN];
922
923 /* DiSEqC toneburst */
924 if(toneburst == CX24116_DISEQC_MESGCACHE)
925 /* Message is cached */
926 return 0;
927
928 else if(toneburst == CX24116_DISEQC_TONEOFF)
929 /* Message is sent without burst */
930 state->dsec_cmd.args[CX24116_DISEQC_BURST] = 0;
931
932 else if(toneburst == CX24116_DISEQC_TONECACHE) {
933 /*
934 * Message is sent with derived else cached burst
935 *
936 * WRITE PORT GROUP COMMAND 38
937 *
938 * 0/A/A: E0 10 38 F0..F3
939 * 1/B/B: E0 10 38 F4..F7
940 * 2/C/A: E0 10 38 F8..FB
941 * 3/D/B: E0 10 38 FC..FF
942 *
943 * databyte[3]= 8421:8421
944 * ABCD:WXYZ
945 * CLR :SET
946 *
947 * WX= PORT SELECT 0..3 (X=TONEBURST)
948 * Y = VOLTAGE (0=13V, 1=18V)
949 * Z = BAND (0=LOW, 1=HIGH(22K))
950 */
951 if(d->msg_len >= 4 && d->msg[2] == 0x38)
952 state->dsec_cmd.args[CX24116_DISEQC_BURST] = ((d->msg[3] & 4) >> 2);
953 if(debug)
954 dprintk("%s burst=%d\n", __func__, state->dsec_cmd.args[CX24116_DISEQC_BURST]);
955 }
956
957 /* Wait for LNB ready */
958 ret = cx24116_wait_for_lnb(fe);
959 if(ret != 0)
960 return ret;
961
962 /* Wait for voltage/min repeat delay */
963 msleep(100);
964
965 /* Command */
966 ret = cx24116_cmd_execute(fe, &state->dsec_cmd);
967 if(ret != 0)
968 return ret;
969 /*
970 * Wait for send
971 *
972 * Eutelsat spec:
973 * >15ms delay + (XXX determine if FW does this, see set_tone)
974 * 13.5ms per byte +
975 * >15ms delay +
976 * 12.5ms burst +
977 * >15ms delay (XXX determine if FW does this, see set_tone)
978 */
979 msleep( (state->dsec_cmd.args[CX24116_DISEQC_MSGLEN] << 4) + ((toneburst == CX24116_DISEQC_TONEOFF) ? 30 : 60) );
980
981 return 0;
982}
983
984/* Send DiSEqC burst */
985static int cx24116_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t burst)
986{
987 struct cx24116_state *state = fe->demodulator_priv;
988 int ret;
989
990 dprintk("%s(%d) toneburst=%d\n",__func__, burst, toneburst);
991
992 /* DiSEqC burst */
993 if (burst == SEC_MINI_A)
994 state->dsec_cmd.args[CX24116_DISEQC_BURST] = CX24116_DISEQC_MINI_A;
995 else if(burst == SEC_MINI_B)
996 state->dsec_cmd.args[CX24116_DISEQC_BURST] = CX24116_DISEQC_MINI_B;
997 else
998 return -EINVAL;
999
1000 /* DiSEqC toneburst */
1001 if(toneburst != CX24116_DISEQC_MESGCACHE)
1002 /* Burst is cached */
1003 return 0;
1004
1005 /* Burst is to be sent with cached message */
1006
1007 /* Wait for LNB ready */
1008 ret = cx24116_wait_for_lnb(fe);
1009 if(ret != 0)
1010 return ret;
1011
1012 /* Wait for voltage/min repeat delay */
1013 msleep(100);
1014
1015 /* Command */
1016 ret = cx24116_cmd_execute(fe, &state->dsec_cmd);
1017 if(ret != 0)
1018 return ret;
1019
1020 /*
1021 * Wait for send
1022 *
1023 * Eutelsat spec:
1024 * >15ms delay + (XXX determine if FW does this, see set_tone)
1025 * 13.5ms per byte +
1026 * >15ms delay +
1027 * 12.5ms burst +
1028 * >15ms delay (XXX determine if FW does this, see set_tone)
1029 */
1030 msleep( (state->dsec_cmd.args[CX24116_DISEQC_MSGLEN] << 4) + 60 );
1031
1032 return 0;
1033}
1034
1035static void cx24116_release(struct dvb_frontend* fe)
1036{
1037 struct cx24116_state* state = fe->demodulator_priv;
1038 dprintk("%s\n",__func__);
1039 kfree(state);
1040}
1041
1042static struct dvb_frontend_ops cx24116_ops;
1043
1044struct dvb_frontend* cx24116_attach(const struct cx24116_config* config,
1045 struct i2c_adapter* i2c)
1046{
1047 struct cx24116_state* state = NULL;
1048 int ret;
1049
1050 dprintk("%s\n",__func__);
1051
1052 /* allocate memory for the internal state */
1053 state = kmalloc(sizeof(struct cx24116_state), GFP_KERNEL);
1054 if (state == NULL) {
1055 printk("Unable to kmalloc\n");
1056 goto error1;
1057 }
1058
1059 /* setup the state */
1060 memset(state, 0, sizeof(struct cx24116_state));
1061
1062 state->config = config;
1063 state->i2c = i2c;
1064
1065 /* check if the demod is present */
1066 ret = (cx24116_readreg(state, 0xFF) << 8) | cx24116_readreg(state, 0xFE);
1067 if (ret != 0x0501) {
1068 printk("Invalid probe, probably not a CX24116 device\n");
1069 goto error2;
1070 }
1071
1072 /* create dvb_frontend */
1073 memcpy(&state->frontend.ops, &cx24116_ops, sizeof(struct dvb_frontend_ops));
1074 state->frontend.demodulator_priv = state;
1075 return &state->frontend;
1076
1077error2: kfree(state);
1078error1: return NULL;
1079}
1080/*
1081 * Initialise or wake up device
1082 *
1083 * Power config will reset and load initial firmware if required
1084 */
1085static int cx24116_initfe(struct dvb_frontend* fe)
1086{
1087 struct cx24116_state* state = fe->demodulator_priv;
1088 struct cx24116_cmd cmd;
1089 int ret;
1090
1091 dprintk("%s()\n",__func__);
1092
1093 /* Power on */
1094 cx24116_writereg(state, 0xe0, 0);
1095 cx24116_writereg(state, 0xe1, 0);
1096 cx24116_writereg(state, 0xea, 0);
1097
1098 /* Firmware CMD 36: Power config */
1099 cmd.args[0x00] = CMD_TUNERSLEEP;
1100 cmd.args[0x01] = 0;
1101 cmd.len= 0x02;
1102 ret = cx24116_cmd_execute(fe, &cmd);
1103 if(ret != 0)
1104 return ret;
1105
1106 return cx24116_diseqc_init(fe);
1107}
1108
1109/*
1110 * Put device to sleep
1111 */
1112static int cx24116_sleep(struct dvb_frontend* fe)
1113{
1114 struct cx24116_state* state = fe->demodulator_priv;
1115 struct cx24116_cmd cmd;
1116 int ret;
1117
1118 dprintk("%s()\n",__func__);
1119
1120 /* Firmware CMD 36: Power config */
1121 cmd.args[0x00] = CMD_TUNERSLEEP;
1122 cmd.args[0x01] = 1;
1123 cmd.len= 0x02;
1124 ret = cx24116_cmd_execute(fe, &cmd);
1125 if(ret != 0)
1126 return ret;
1127
1128 /* Power off (Shutdown clocks) */
1129 cx24116_writereg(state, 0xea, 0xff);
1130 cx24116_writereg(state, 0xe1, 1);
1131 cx24116_writereg(state, 0xe0, 1);
1132
1133 return 0;
1134}
1135
1136static int cx24116_set_property(struct dvb_frontend *fe, struct dtv_property* tvp)
1137{
1138 dprintk("%s(..)\n", __func__);
1139 return 0;
1140}
1141
1142static int cx24116_get_property(struct dvb_frontend *fe, struct dtv_property* tvp)
1143{
1144 dprintk("%s(..)\n", __func__);
1145 return 0;
1146}
1147
1148/* dvb-core told us to tune, the tv property cache will be complete,
1149 * it's safe for is to pull values and use them for tuning purposes.
1150 */
1151static int cx24116_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
1152{
1153 struct cx24116_state *state = fe->demodulator_priv;
1154 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1155 struct cx24116_cmd cmd;
1156 fe_status_t tunerstat;
1157 int i, status, ret, retune;
1158
1159 dprintk("%s()\n",__func__);
1160
1161 switch(c->delivery_system) {
1162 case SYS_DVBS:
1163 dprintk("%s: DVB-S delivery system selected\n",__func__);
1164
1165 /* Only QPSK is supported for DVB-S */
1166 if(c->modulation != QPSK) {
1167 dprintk("%s: unsupported modulation selected (%d)\n",
1168 __func__, c->modulation);
1169 return -EOPNOTSUPP;
1170 }
1171
1172 /* Pilot doesn't exist in DVB-S, turn bit off */
1173 state->dnxt.pilot_val = CX24116_PILOT_OFF;
1174 retune = 1;
1175
1176 /* DVB-S only supports 0.35 */
1177 if(c->rolloff != ROLLOFF_35) {
1178 dprintk("%s: unsupported rolloff selected (%d)\n",
1179 __func__, c->rolloff);
1180 return -EOPNOTSUPP;
1181 }
1182 state->dnxt.rolloff_val = CX24116_ROLLOFF_035;
1183 break;
1184
1185 case SYS_DVBS2:
1186 dprintk("%s: DVB-S2 delivery system selected\n",__func__);
1187
1188 /*
1189 * NBC 8PSK/QPSK with DVB-S is supported for DVB-S2,
1190 * but not hardware auto detection
1191 */
1192 if(c->modulation != PSK_8 && c->modulation != QPSK) {
1193 dprintk("%s: unsupported modulation selected (%d)\n",
1194 __func__, c->modulation);
1195 return -EOPNOTSUPP;
1196 }
1197
1198 switch(c->pilot) {
1199 case PILOT_AUTO: /* Not supported but emulated */
1200 retune = 2; /* Fall-through */
1201 case PILOT_OFF:
1202 state->dnxt.pilot_val = CX24116_PILOT_OFF;
1203 break;
1204 case PILOT_ON:
1205 state->dnxt.pilot_val = CX24116_PILOT_ON;
1206 break;
1207 default:
1208 dprintk("%s: unsupported pilot mode selected (%d)\n",
1209 __func__, c->pilot);
1210 return -EOPNOTSUPP;
1211 }
1212
1213 switch(c->rolloff) {
1214 case ROLLOFF_20:
1215 state->dnxt.rolloff_val= CX24116_ROLLOFF_020;
1216 break;
1217 case ROLLOFF_25:
1218 state->dnxt.rolloff_val= CX24116_ROLLOFF_025;
1219 break;
1220 case ROLLOFF_35:
1221 state->dnxt.rolloff_val= CX24116_ROLLOFF_035;
1222 break;
1223 case ROLLOFF_AUTO: /* Rolloff must be explicit */
1224 default:
1225 dprintk("%s: unsupported rolloff selected (%d)\n",
1226 __func__, c->rolloff);
1227 return -EOPNOTSUPP;
1228 }
1229 break;
1230
1231 default:
1232 dprintk("%s: unsupported delivery system selected (%d)\n",
1233 __func__, c->delivery_system);
1234 return -EOPNOTSUPP;
1235 }
1236 state->dnxt.modulation = c->modulation;
1237 state->dnxt.frequency = c->frequency;
1238 state->dnxt.pilot = c->pilot;
1239 state->dnxt.rolloff = c->rolloff;
1240
1241 if ((ret = cx24116_set_inversion(state, c->inversion)) != 0)
1242 return ret;
1243
1244 /* FEC_NONE/AUTO for DVB-S2 is not supported and detected here */
1245 if ((ret = cx24116_set_fec(state, c->modulation, c->fec_inner)) != 0)
1246 return ret;
1247
1248 if ((ret = cx24116_set_symbolrate(state, c->symbol_rate)) != 0)
1249 return ret;
1250
1251 /* discard the 'current' tuning parameters and prepare to tune */
1252 cx24116_clone_params(fe);
1253
1254 dprintk("%s: modulation = %d\n", __func__, state->dcur.modulation);
1255 dprintk("%s: frequency = %d\n", __func__, state->dcur.frequency);
1256 dprintk("%s: pilot = %d (val = 0x%02x)\n", __func__,
1257 state->dcur.pilot, state->dcur.pilot_val);
1258 dprintk("%s: retune = %d\n", __func__, retune);
1259 dprintk("%s: rolloff = %d (val = 0x%02x)\n", __func__,
1260 state->dcur.rolloff, state->dcur.rolloff_val);
1261 dprintk("%s: symbol_rate = %d\n", __func__, state->dcur.symbol_rate);
1262 dprintk("%s: FEC = %d (mask/val = 0x%02x/0x%02x)\n", __func__,
1263 state->dcur.fec, state->dcur.fec_mask, state->dcur.fec_val);
1264 dprintk("%s: Inversion = %d (val = 0x%02x)\n", __func__,
1265 state->dcur.inversion, state->dcur.inversion_val);
1266
1267 /* This is also done in advise/acquire on HVR4000 but not on LITE */
1268 if (state->config->set_ts_params)
1269 state->config->set_ts_params(fe, 0);
1270
1271 /* Set/Reset B/W */
1272 cmd.args[0x00] = CMD_BANDWIDTH;
1273 cmd.args[0x01] = 0x01;
1274 cmd.len= 0x02;
1275 ret = cx24116_cmd_execute(fe, &cmd);
1276 if (ret != 0)
1277 return ret;
1278
1279 /* Prepare a tune request */
1280 cmd.args[0x00] = CMD_TUNEREQUEST;
1281
1282 /* Frequency */
1283 cmd.args[0x01] = (state->dcur.frequency & 0xff0000) >> 16;
1284 cmd.args[0x02] = (state->dcur.frequency & 0x00ff00) >> 8;
1285 cmd.args[0x03] = (state->dcur.frequency & 0x0000ff);
1286
1287 /* Symbol Rate */
1288 cmd.args[0x04] = ((state->dcur.symbol_rate / 1000) & 0xff00) >> 8;
1289 cmd.args[0x05] = ((state->dcur.symbol_rate / 1000) & 0x00ff);
1290
1291 /* Automatic Inversion */
1292 cmd.args[0x06] = state->dcur.inversion_val;
1293
1294 /* Modulation / FEC / Pilot */
1295 cmd.args[0x07] = state->dcur.fec_val | state->dcur.pilot_val;
1296
1297 cmd.args[0x08] = CX24116_SEARCH_RANGE_KHZ >> 8;
1298 cmd.args[0x09] = CX24116_SEARCH_RANGE_KHZ & 0xff;
1299 cmd.args[0x0a] = 0x00;
1300 cmd.args[0x0b] = 0x00;
1301 cmd.args[0x0c] = state->dcur.rolloff_val;
1302 cmd.args[0x0d] = state->dcur.fec_mask;
1303
1304 if (state->dcur.symbol_rate > 30000000) {
1305 cmd.args[0x0e] = 0x04;
1306 cmd.args[0x0f] = 0x00;
1307 cmd.args[0x10] = 0x01;
1308 cmd.args[0x11] = 0x77;
1309 cmd.args[0x12] = 0x36;
1310 cx24116_writereg(state, CX24116_REG_CLKDIV, 0x44);
1311 cx24116_writereg(state, CX24116_REG_RATEDIV, 0x01);
1312 } else {
1313 cmd.args[0x0e] = 0x06;
1314 cmd.args[0x0f] = 0x00;
1315 cmd.args[0x10] = 0x00;
1316 cmd.args[0x11] = 0xFA;
1317 cmd.args[0x12] = 0x24;
1318 cx24116_writereg(state, CX24116_REG_CLKDIV, 0x46);
1319 cx24116_writereg(state, CX24116_REG_RATEDIV, 0x00);
1320 }
1321
1322 cmd.len= 0x13;
1323
1324 /* We need to support pilot and non-pilot tuning in the
1325 * driver automatically. This is a workaround for because
1326 * the demod does not support autodetect.
1327 */
1328 do {
1329 /* Reset status register */
1330 status = cx24116_readreg(state, CX24116_REG_SSTATUS) & CX24116_SIGNAL_MASK;
1331 cx24116_writereg(state, CX24116_REG_SSTATUS, status);
1332
1333 /* Tune */
1334 ret = cx24116_cmd_execute(fe, &cmd);
1335 if( ret != 0 )
1336 break;
1337
1338 /*
1339 * Wait for up to 500 ms before retrying
1340 *
1341 * If we are able to tune then generally it occurs within 100ms.
1342 * If it takes longer, try a different toneburst setting.
1343 */
1344 for(i = 0; i < 50 ; i++) {
1345 cx24116_read_status(fe, &tunerstat);
1346 status = tunerstat & (FE_HAS_SIGNAL | FE_HAS_SYNC);
1347 if(status == (FE_HAS_SIGNAL | FE_HAS_SYNC)) {
1348 dprintk("%s: Tuned\n",__func__);
1349 goto tuned;
1350 }
1351 msleep(10);
1352 }
1353
1354 dprintk("%s: Not tuned\n",__func__);
1355
1356 /* Toggle pilot bit when in auto-pilot */
1357 if(state->dcur.pilot == PILOT_AUTO)
1358 cmd.args[0x07] ^= CX24116_PILOT_ON;
1359 }
1360 while(--retune);
1361
1362tuned: /* Set/Reset B/W */
1363 cmd.args[0x00] = CMD_BANDWIDTH;
1364 cmd.args[0x01] = 0x00;
1365 cmd.len= 0x02;
1366 ret = cx24116_cmd_execute(fe, &cmd);
1367 if (ret != 0)
1368 return ret;
1369
1370 return ret;
1371}
1372
1373static struct dvb_frontend_ops cx24116_ops = {
1374
1375 .info = {
1376 .name = "Conexant CX24116/CX24118",
1377 .type = FE_QPSK,
1378 .frequency_min = 950000,
1379 .frequency_max = 2150000,
1380 .frequency_stepsize = 1011, /* kHz for QPSK frontends */
1381 .frequency_tolerance = 5000,
1382 .symbol_rate_min = 1000000,
1383 .symbol_rate_max = 45000000,
1384 .caps = FE_CAN_INVERSION_AUTO |
1385 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
1386 FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 |
1387 FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
1388 FE_CAN_QPSK | FE_CAN_RECOVER
1389 },
1390
1391 .release = cx24116_release,
1392
1393 .init = cx24116_initfe,
1394 .sleep = cx24116_sleep,
1395 .read_status = cx24116_read_status,
1396 .read_ber = cx24116_read_ber,
1397 .read_signal_strength = cx24116_read_signal_strength,
1398 .read_snr = cx24116_read_snr,
1399 .read_ucblocks = cx24116_read_ucblocks,
1400 .set_tone = cx24116_set_tone,
1401 .set_voltage = cx24116_set_voltage,
1402 .diseqc_send_master_cmd = cx24116_send_diseqc_msg,
1403 .diseqc_send_burst = cx24116_diseqc_send_burst,
1404
1405 .set_property = cx24116_set_property,
1406 .get_property = cx24116_get_property,
1407 .set_frontend = cx24116_set_frontend,
1408};
1409
1410module_param(debug, int, 0644);
1411MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)");
1412
1413module_param(toneburst, int, 0644);
1414MODULE_PARM_DESC(toneburst, "DiSEqC toneburst 0=OFF, 1=TONE CACHE, 2=MESSAGE CACHE (default:1)");
1415
1416module_param(esno_snr, int, 0644);
1417MODULE_PARM_DESC(debug, "SNR return units, 0=PERCENTAGE 0-100, 1=ESNO(db * 10) (default:0)");
1418
1419MODULE_DESCRIPTION("DVB Frontend module for Conexant cx24116/cx24118 hardware");
1420MODULE_AUTHOR("Steven Toth");
1421MODULE_LICENSE("GPL");
1422
1423EXPORT_SYMBOL(cx24116_attach);
diff --git a/drivers/media/dvb/frontends/cx24116.h b/drivers/media/dvb/frontends/cx24116.h
new file mode 100644
index 000000000000..8dbcec268394
--- /dev/null
+++ b/drivers/media/dvb/frontends/cx24116.h
@@ -0,0 +1,53 @@
1/*
2 Conexant cx24116/cx24118 - DVBS/S2 Satellite demod/tuner driver
3
4 Copyright (C) 2006 Steven Toth <stoth@linuxtv.com>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef CX24116_H
22#define CX24116_H
23
24#include <linux/dvb/frontend.h>
25
26struct cx24116_config
27{
28 /* the demodulator's i2c address */
29 u8 demod_address;
30
31 /* Need to set device param for start_dma */
32 int (*set_ts_params)(struct dvb_frontend* fe, int is_punctured);
33
34 /* Need to reset device during firmware loading */
35 int (*reset_device)(struct dvb_frontend* fe);
36
37 /* Need to set MPEG parameters */
38 u8 mpg_clk_pos_pol:0x02;
39};
40
41#if defined(CONFIG_DVB_CX24116) || defined(CONFIG_DVB_CX24116_MODULE)
42extern struct dvb_frontend* cx24116_attach(const struct cx24116_config* config,
43 struct i2c_adapter* i2c);
44#else
45static inline struct dvb_frontend* cx24116_attach(const struct cx24116_config* config,
46 struct i2c_adapter* i2c)
47{
48 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
49 return NULL;
50}
51#endif // CONFIG_DVB_CX24116
52
53#endif /* CX24116_H */
diff --git a/drivers/media/dvb/frontends/dib0070.h b/drivers/media/dvb/frontends/dib0070.h
index 3eedfdf505bc..21f2c5161af4 100644
--- a/drivers/media/dvb/frontends/dib0070.h
+++ b/drivers/media/dvb/frontends/dib0070.h
@@ -41,6 +41,7 @@ struct dib0070_config {
41extern struct dvb_frontend *dib0070_attach(struct dvb_frontend *fe, 41extern struct dvb_frontend *dib0070_attach(struct dvb_frontend *fe,
42 struct i2c_adapter *i2c, 42 struct i2c_adapter *i2c,
43 struct dib0070_config *cfg); 43 struct dib0070_config *cfg);
44extern u16 dib0070_wbd_offset(struct dvb_frontend *);
44#else 45#else
45static inline struct dvb_frontend *dib0070_attach(struct dvb_frontend *fe, 46static inline struct dvb_frontend *dib0070_attach(struct dvb_frontend *fe,
46 struct i2c_adapter *i2c, 47 struct i2c_adapter *i2c,
@@ -49,9 +50,14 @@ static inline struct dvb_frontend *dib0070_attach(struct dvb_frontend *fe,
49 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 50 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
50 return NULL; 51 return NULL;
51} 52}
53
54static inline u16 dib0070_wbd_offset(struct dvb_frontend *fe)
55{
56 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
57 return -ENODEV;
58}
52#endif 59#endif
53 60
54extern void dib0070_ctrl_agc_filter(struct dvb_frontend *, uint8_t open); 61extern void dib0070_ctrl_agc_filter(struct dvb_frontend *, uint8_t open);
55extern u16 dib0070_wbd_offset(struct dvb_frontend *);
56 62
57#endif 63#endif
diff --git a/drivers/media/dvb/frontends/dib7000m.c b/drivers/media/dvb/frontends/dib7000m.c
index 5f1375e30dfc..0109720353bd 100644
--- a/drivers/media/dvb/frontends/dib7000m.c
+++ b/drivers/media/dvb/frontends/dib7000m.c
@@ -1284,7 +1284,10 @@ struct i2c_adapter * dib7000m_get_i2c_master(struct dvb_frontend *demod, enum di
1284} 1284}
1285EXPORT_SYMBOL(dib7000m_get_i2c_master); 1285EXPORT_SYMBOL(dib7000m_get_i2c_master);
1286 1286
1287int dib7000m_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib7000m_config cfg[]) 1287#if 0
1288/* used with some prototype boards */
1289int dib7000m_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods,
1290 u8 default_addr, struct dib7000m_config cfg[])
1288{ 1291{
1289 struct dib7000m_state st = { .i2c_adap = i2c }; 1292 struct dib7000m_state st = { .i2c_adap = i2c };
1290 int k = 0; 1293 int k = 0;
@@ -1329,6 +1332,7 @@ int dib7000m_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 defau
1329 return 0; 1332 return 0;
1330} 1333}
1331EXPORT_SYMBOL(dib7000m_i2c_enumeration); 1334EXPORT_SYMBOL(dib7000m_i2c_enumeration);
1335#endif
1332 1336
1333static struct dvb_frontend_ops dib7000m_ops; 1337static struct dvb_frontend_ops dib7000m_ops;
1334struct dvb_frontend * dib7000m_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000m_config *cfg) 1338struct dvb_frontend * dib7000m_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000m_config *cfg)
diff --git a/drivers/media/dvb/frontends/dib7000p.c b/drivers/media/dvb/frontends/dib7000p.c
index 1a0142e0d741..8217e5b38f47 100644
--- a/drivers/media/dvb/frontends/dib7000p.c
+++ b/drivers/media/dvb/frontends/dib7000p.c
@@ -1333,7 +1333,8 @@ struct dvb_frontend * dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr,
1333 /* Ensure the output mode remains at the previous default if it's 1333 /* Ensure the output mode remains at the previous default if it's
1334 * not specifically set by the caller. 1334 * not specifically set by the caller.
1335 */ 1335 */
1336 if (st->cfg.output_mode != OUTMODE_MPEG2_SERIAL) 1336 if ((st->cfg.output_mode != OUTMODE_MPEG2_SERIAL) &&
1337 (st->cfg.output_mode != OUTMODE_MPEG2_PAR_GATED_CLK))
1337 st->cfg.output_mode = OUTMODE_MPEG2_FIFO; 1338 st->cfg.output_mode = OUTMODE_MPEG2_FIFO;
1338 1339
1339 demod = &st->demod; 1340 demod = &st->demod;
diff --git a/drivers/media/dvb/frontends/dib7000p.h b/drivers/media/dvb/frontends/dib7000p.h
index 07c4d12ed5b7..3e8126857127 100644
--- a/drivers/media/dvb/frontends/dib7000p.h
+++ b/drivers/media/dvb/frontends/dib7000p.h
@@ -41,6 +41,14 @@ struct dib7000p_config {
41extern struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap, 41extern struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap,
42 u8 i2c_addr, 42 u8 i2c_addr,
43 struct dib7000p_config *cfg); 43 struct dib7000p_config *cfg);
44extern struct i2c_adapter *dib7000p_get_i2c_master(struct dvb_frontend *,
45 enum dibx000_i2c_interface,
46 int);
47extern int dib7000p_i2c_enumeration(struct i2c_adapter *i2c,
48 int no_of_demods, u8 default_addr,
49 struct dib7000p_config cfg[]);
50extern int dib7000p_set_gpio(struct dvb_frontend *, u8 num, u8 dir, u8 val);
51extern int dib7000p_set_wbd_ref(struct dvb_frontend *, u16 value);
44#else 52#else
45static inline struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap, 53static inline struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap,
46 u8 i2c_addr, 54 u8 i2c_addr,
@@ -49,13 +57,36 @@ static inline struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap,
49 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 57 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
50 return NULL; 58 return NULL;
51} 59}
52#endif
53 60
54extern int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib7000p_config cfg[]); 61static inline
62struct i2c_adapter *dib7000p_get_i2c_master(struct dvb_frontend *fe,
63 enum dibx000_i2c_interface i, int x)
64{
65 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
66 return NULL;
67}
68
69extern int dib7000p_i2c_enumeration(struct i2c_adapter *i2c,
70 int no_of_demods, u8 default_addr,
71 struct dib7000p_config cfg[])
72{
73 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
74 return -ENODEV;
75}
76
77extern int dib7000p_set_gpio(struct dvb_frontend *fe, u8 num, u8 dir, u8 val)
78{
79 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
80 return -ENODEV;
81}
82
83extern int dib7000p_set_wbd_ref(struct dvb_frontend *fe, u16 value)
84{
85 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
86 return -ENODEV;
87}
88#endif
55 89
56extern struct i2c_adapter * dib7000p_get_i2c_master(struct dvb_frontend *, enum dibx000_i2c_interface, int);
57extern int dib7000pc_detection(struct i2c_adapter *i2c_adap); 90extern int dib7000pc_detection(struct i2c_adapter *i2c_adap);
58extern int dib7000p_set_gpio(struct dvb_frontend *, u8 num, u8 dir, u8 val);
59extern int dib7000p_set_wbd_ref(struct dvb_frontend *, u16 value);
60 91
61#endif 92#endif
diff --git a/drivers/media/dvb/frontends/drx397xD.c b/drivers/media/dvb/frontends/drx397xD.c
index 3cbed874a6f8..b9ca5c8d2dd9 100644
--- a/drivers/media/dvb/frontends/drx397xD.c
+++ b/drivers/media/dvb/frontends/drx397xD.c
@@ -38,35 +38,32 @@ static const char mod_name[] = "drx397xD";
38#define F_SET_0D0h 1 38#define F_SET_0D0h 1
39#define F_SET_0D4h 2 39#define F_SET_0D4h 2
40 40
41typedef enum fw_ix { 41enum fw_ix {
42#define _FW_ENTRY(a, b) b 42#define _FW_ENTRY(a, b) b
43#include "drx397xD_fw.h" 43#include "drx397xD_fw.h"
44} fw_ix_t; 44};
45 45
46/* chip specifics */ 46/* chip specifics */
47struct drx397xD_state { 47struct drx397xD_state {
48 struct i2c_adapter *i2c; 48 struct i2c_adapter *i2c;
49 struct dvb_frontend frontend; 49 struct dvb_frontend frontend;
50 struct drx397xD_config config; 50 struct drx397xD_config config;
51 fw_ix_t chip_rev; 51 enum fw_ix chip_rev;
52 int flags; 52 int flags;
53 u32 bandwidth_parm; /* internal bandwidth conversions */ 53 u32 bandwidth_parm; /* internal bandwidth conversions */
54 u32 f_osc; /* w90: actual osc frequency [Hz] */ 54 u32 f_osc; /* w90: actual osc frequency [Hz] */
55}; 55};
56 56
57/******************************************************************************* 57/* Firmware */
58 * Firmware
59 ******************************************************************************/
60
61static const char *blob_name[] = { 58static const char *blob_name[] = {
62#define _BLOB_ENTRY(a, b) a 59#define _BLOB_ENTRY(a, b) a
63#include "drx397xD_fw.h" 60#include "drx397xD_fw.h"
64}; 61};
65 62
66typedef enum blob_ix { 63enum blob_ix {
67#define _BLOB_ENTRY(a, b) b 64#define _BLOB_ENTRY(a, b) b
68#include "drx397xD_fw.h" 65#include "drx397xD_fw.h"
69} blob_ix_t; 66};
70 67
71static struct { 68static struct {
72 const char *name; 69 const char *name;
@@ -85,7 +82,7 @@ static struct {
85}; 82};
86 83
87/* use only with writer lock aquired */ 84/* use only with writer lock aquired */
88static void _drx_release_fw(struct drx397xD_state *s, fw_ix_t ix) 85static void _drx_release_fw(struct drx397xD_state *s, enum fw_ix ix)
89{ 86{
90 memset(&fw[ix].data[0], 0, sizeof(fw[0].data)); 87 memset(&fw[ix].data[0], 0, sizeof(fw[0].data));
91 if (fw[ix].file) 88 if (fw[ix].file)
@@ -94,9 +91,9 @@ static void _drx_release_fw(struct drx397xD_state *s, fw_ix_t ix)
94 91
95static void drx_release_fw(struct drx397xD_state *s) 92static void drx_release_fw(struct drx397xD_state *s)
96{ 93{
97 fw_ix_t ix = s->chip_rev; 94 enum fw_ix ix = s->chip_rev;
98 95
99 pr_debug("%s\n", __FUNCTION__); 96 pr_debug("%s\n", __func__);
100 97
101 write_lock(&fw[ix].lock); 98 write_lock(&fw[ix].lock);
102 if (fw[ix].refcnt) { 99 if (fw[ix].refcnt) {
@@ -107,13 +104,13 @@ static void drx_release_fw(struct drx397xD_state *s)
107 write_unlock(&fw[ix].lock); 104 write_unlock(&fw[ix].lock);
108} 105}
109 106
110static int drx_load_fw(struct drx397xD_state *s, fw_ix_t ix) 107static int drx_load_fw(struct drx397xD_state *s, enum fw_ix ix)
111{ 108{
112 const u8 *data; 109 const u8 *data;
113 size_t size, len; 110 size_t size, len;
114 int i = 0, j, rc = -EINVAL; 111 int i = 0, j, rc = -EINVAL;
115 112
116 pr_debug("%s\n", __FUNCTION__); 113 pr_debug("%s\n", __func__);
117 114
118 if (ix < 0 || ix >= ARRAY_SIZE(fw)) 115 if (ix < 0 || ix >= ARRAY_SIZE(fw))
119 return -EINVAL; 116 return -EINVAL;
@@ -175,32 +172,34 @@ static int drx_load_fw(struct drx397xD_state *s, fw_ix_t ix)
175 goto exit_corrupt; 172 goto exit_corrupt;
176 } 173 }
177 } while (i < size); 174 } while (i < size);
178 exit_corrupt: 175
176exit_corrupt:
179 printk(KERN_ERR "%s: Firmware is corrupt\n", mod_name); 177 printk(KERN_ERR "%s: Firmware is corrupt\n", mod_name);
180 exit_err: 178exit_err:
181 _drx_release_fw(s, ix); 179 _drx_release_fw(s, ix);
182 fw[ix].refcnt--; 180 fw[ix].refcnt--;
183 exit_ok: 181exit_ok:
184 fw[ix].refcnt++; 182 fw[ix].refcnt++;
185 write_unlock(&fw[ix].lock); 183 write_unlock(&fw[ix].lock);
184
186 return rc; 185 return rc;
187} 186}
188 187
189/******************************************************************************* 188/* i2c bus IO */
190 * i2c bus IO 189static int write_fw(struct drx397xD_state *s, enum blob_ix ix)
191 ******************************************************************************/
192
193static int write_fw(struct drx397xD_state *s, blob_ix_t ix)
194{ 190{
195 struct i2c_msg msg = {.addr = s->config.demod_address,.flags = 0 };
196 const u8 *data; 191 const u8 *data;
197 int len, rc = 0, i = 0; 192 int len, rc = 0, i = 0;
193 struct i2c_msg msg = {
194 .addr = s->config.demod_address,
195 .flags = 0
196 };
198 197
199 if (ix < 0 || ix >= ARRAY_SIZE(blob_name)) { 198 if (ix < 0 || ix >= ARRAY_SIZE(blob_name)) {
200 pr_debug("%s drx_fw_ix_t out of range\n", __FUNCTION__); 199 pr_debug("%s drx_fw_ix_t out of range\n", __func__);
201 return -EINVAL; 200 return -EINVAL;
202 } 201 }
203 pr_debug("%s %s\n", __FUNCTION__, blob_name[ix]); 202 pr_debug("%s %s\n", __func__, blob_name[ix]);
204 203
205 read_lock(&fw[s->chip_rev].lock); 204 read_lock(&fw[s->chip_rev].lock);
206 data = fw[s->chip_rev].data[ix]; 205 data = fw[s->chip_rev].data[ix];
@@ -229,33 +228,33 @@ static int write_fw(struct drx397xD_state *s, blob_ix_t ix)
229 goto exit_rc; 228 goto exit_rc;
230 } 229 }
231 } 230 }
232 exit_rc: 231exit_rc:
233 read_unlock(&fw[s->chip_rev].lock); 232 read_unlock(&fw[s->chip_rev].lock);
233
234 return 0; 234 return 0;
235} 235}
236 236
237/* Function is not endian safe, use the RD16 wrapper below */ 237/* Function is not endian safe, use the RD16 wrapper below */
238static int _read16(struct drx397xD_state *s, u32 i2c_adr) 238static int _read16(struct drx397xD_state *s, __le32 i2c_adr)
239{ 239{
240 int rc; 240 int rc;
241 u8 a[4]; 241 u8 a[4];
242 u16 v; 242 __le16 v;
243 struct i2c_msg msg[2] = { 243 struct i2c_msg msg[2] = {
244 { 244 {
245 .addr = s->config.demod_address, 245 .addr = s->config.demod_address,
246 .flags = 0, 246 .flags = 0,
247 .buf = a, 247 .buf = a,
248 .len = sizeof(a) 248 .len = sizeof(a)
249 } 249 }, {
250 , { 250 .addr = s->config.demod_address,
251 .addr = s->config.demod_address, 251 .flags = I2C_M_RD,
252 .flags = I2C_M_RD, 252 .buf = (u8 *)&v,
253 .buf = (u8 *) & v, 253 .len = sizeof(v)
254 .len = sizeof(v) 254 }
255 }
256 }; 255 };
257 256
258 *(u32 *) a = i2c_adr; 257 *(__le32 *) a = i2c_adr;
259 258
260 rc = i2c_transfer(s->i2c, msg, 2); 259 rc = i2c_transfer(s->i2c, msg, 2);
261 if (rc != 2) 260 if (rc != 2)
@@ -265,7 +264,7 @@ static int _read16(struct drx397xD_state *s, u32 i2c_adr)
265} 264}
266 265
267/* Function is not endian safe, use the WR16.. wrappers below */ 266/* Function is not endian safe, use the WR16.. wrappers below */
268static int _write16(struct drx397xD_state *s, u32 i2c_adr, u16 val) 267static int _write16(struct drx397xD_state *s, __le32 i2c_adr, __le16 val)
269{ 268{
270 u8 a[6]; 269 u8 a[6];
271 int rc; 270 int rc;
@@ -276,28 +275,28 @@ static int _write16(struct drx397xD_state *s, u32 i2c_adr, u16 val)
276 .len = sizeof(a) 275 .len = sizeof(a)
277 }; 276 };
278 277
279 *(u32 *) a = i2c_adr; 278 *(__le32 *)a = i2c_adr;
280 *(u16 *) & a[4] = val; 279 *(__le16 *)&a[4] = val;
281 280
282 rc = i2c_transfer(s->i2c, &msg, 1); 281 rc = i2c_transfer(s->i2c, &msg, 1);
283 if (rc != 1) 282 if (rc != 1)
284 return -EIO; 283 return -EIO;
284
285 return 0; 285 return 0;
286} 286}
287 287
288#define WR16(ss,adr, val) \ 288#define WR16(ss, adr, val) \
289 _write16(ss, I2C_ADR_C0(adr), cpu_to_le16(val)) 289 _write16(ss, I2C_ADR_C0(adr), cpu_to_le16(val))
290#define WR16_E0(ss,adr, val) \ 290#define WR16_E0(ss, adr, val) \
291 _write16(ss, I2C_ADR_E0(adr), cpu_to_le16(val)) 291 _write16(ss, I2C_ADR_E0(adr), cpu_to_le16(val))
292#define RD16(ss,adr) \ 292#define RD16(ss, adr) \
293 _read16(ss, I2C_ADR_C0(adr)) 293 _read16(ss, I2C_ADR_C0(adr))
294 294
295#define EXIT_RC( cmd ) if ( (rc = (cmd)) < 0) goto exit_rc 295#define EXIT_RC(cmd) \
296 296 if ((rc = (cmd)) < 0) \
297/******************************************************************************* 297 goto exit_rc
298 * Tuner callback
299 ******************************************************************************/
300 298
299/* Tuner callback */
301static int PLL_Set(struct drx397xD_state *s, 300static int PLL_Set(struct drx397xD_state *s,
302 struct dvb_frontend_parameters *fep, int *df_tuner) 301 struct dvb_frontend_parameters *fep, int *df_tuner)
303{ 302{
@@ -305,7 +304,7 @@ static int PLL_Set(struct drx397xD_state *s,
305 u32 f_tuner, f = fep->frequency; 304 u32 f_tuner, f = fep->frequency;
306 int rc; 305 int rc;
307 306
308 pr_debug("%s\n", __FUNCTION__); 307 pr_debug("%s\n", __func__);
309 308
310 if ((f > s->frontend.ops.tuner_ops.info.frequency_max) || 309 if ((f > s->frontend.ops.tuner_ops.info.frequency_max) ||
311 (f < s->frontend.ops.tuner_ops.info.frequency_min)) 310 (f < s->frontend.ops.tuner_ops.info.frequency_min))
@@ -325,28 +324,26 @@ static int PLL_Set(struct drx397xD_state *s,
325 return rc; 324 return rc;
326 325
327 *df_tuner = f_tuner - f; 326 *df_tuner = f_tuner - f;
328 pr_debug("%s requested %d [Hz] tuner %d [Hz]\n", __FUNCTION__, f, 327 pr_debug("%s requested %d [Hz] tuner %d [Hz]\n", __func__, f,
329 f_tuner); 328 f_tuner);
330 329
331 return 0; 330 return 0;
332} 331}
333 332
334/******************************************************************************* 333/* Demodulator helper functions */
335 * Demodulator helper functions
336 ******************************************************************************/
337
338static int SC_WaitForReady(struct drx397xD_state *s) 334static int SC_WaitForReady(struct drx397xD_state *s)
339{ 335{
340 int cnt = 1000; 336 int cnt = 1000;
341 int rc; 337 int rc;
342 338
343 pr_debug("%s\n", __FUNCTION__); 339 pr_debug("%s\n", __func__);
344 340
345 while (cnt--) { 341 while (cnt--) {
346 rc = RD16(s, 0x820043); 342 rc = RD16(s, 0x820043);
347 if (rc == 0) 343 if (rc == 0)
348 return 0; 344 return 0;
349 } 345 }
346
350 return -1; 347 return -1;
351} 348}
352 349
@@ -354,13 +351,14 @@ static int SC_SendCommand(struct drx397xD_state *s, int cmd)
354{ 351{
355 int rc; 352 int rc;
356 353
357 pr_debug("%s\n", __FUNCTION__); 354 pr_debug("%s\n", __func__);
358 355
359 WR16(s, 0x820043, cmd); 356 WR16(s, 0x820043, cmd);
360 SC_WaitForReady(s); 357 SC_WaitForReady(s);
361 rc = RD16(s, 0x820042); 358 rc = RD16(s, 0x820042);
362 if ((rc & 0xffff) == 0xffff) 359 if ((rc & 0xffff) == 0xffff)
363 return -1; 360 return -1;
361
364 return 0; 362 return 0;
365} 363}
366 364
@@ -368,7 +366,7 @@ static int HI_Command(struct drx397xD_state *s, u16 cmd)
368{ 366{
369 int rc, cnt = 1000; 367 int rc, cnt = 1000;
370 368
371 pr_debug("%s\n", __FUNCTION__); 369 pr_debug("%s\n", __func__);
372 370
373 rc = WR16(s, 0x420032, cmd); 371 rc = WR16(s, 0x420032, cmd);
374 if (rc < 0) 372 if (rc < 0)
@@ -383,22 +381,24 @@ static int HI_Command(struct drx397xD_state *s, u16 cmd)
383 if (rc < 0) 381 if (rc < 0)
384 return rc; 382 return rc;
385 } while (--cnt); 383 } while (--cnt);
384
386 return rc; 385 return rc;
387} 386}
388 387
389static int HI_CfgCommand(struct drx397xD_state *s) 388static int HI_CfgCommand(struct drx397xD_state *s)
390{ 389{
391 390
392 pr_debug("%s\n", __FUNCTION__); 391 pr_debug("%s\n", __func__);
393 392
394 WR16(s, 0x420033, 0x3973); 393 WR16(s, 0x420033, 0x3973);
395 WR16(s, 0x420034, s->config.w50); // code 4, log 4 394 WR16(s, 0x420034, s->config.w50); /* code 4, log 4 */
396 WR16(s, 0x420035, s->config.w52); // code 15, log 9 395 WR16(s, 0x420035, s->config.w52); /* code 15, log 9 */
397 WR16(s, 0x420036, s->config.demod_address << 1); 396 WR16(s, 0x420036, s->config.demod_address << 1);
398 WR16(s, 0x420037, s->config.w56); // code (set_i2c ?? initX 1 ), log 1 397 WR16(s, 0x420037, s->config.w56); /* code (set_i2c ?? initX 1 ), log 1 */
399// WR16(s, 0x420033, 0x3973); 398 /* WR16(s, 0x420033, 0x3973); */
400 if ((s->config.w56 & 8) == 0) 399 if ((s->config.w56 & 8) == 0)
401 return HI_Command(s, 3); 400 return HI_Command(s, 3);
401
402 return WR16(s, 0x420032, 0x3); 402 return WR16(s, 0x420032, 0x3);
403} 403}
404 404
@@ -419,7 +419,7 @@ static int SetCfgIfAgc(struct drx397xD_state *s, struct drx397xD_CfgIfAgc *agc)
419 u16 w0C = agc->w0C; 419 u16 w0C = agc->w0C;
420 int quot, rem, i, rc = -EINVAL; 420 int quot, rem, i, rc = -EINVAL;
421 421
422 pr_debug("%s\n", __FUNCTION__); 422 pr_debug("%s\n", __func__);
423 423
424 if (agc->w04 > 0x3ff) 424 if (agc->w04 > 0x3ff)
425 goto exit_rc; 425 goto exit_rc;
@@ -468,7 +468,7 @@ static int SetCfgIfAgc(struct drx397xD_state *s, struct drx397xD_CfgIfAgc *agc)
468 i = slowIncrDecLUT_15272[rem / 28]; 468 i = slowIncrDecLUT_15272[rem / 28];
469 EXIT_RC(WR16(s, 0x0c2002b, i)); 469 EXIT_RC(WR16(s, 0x0c2002b, i));
470 rc = WR16(s, 0x0c2002c, i); 470 rc = WR16(s, 0x0c2002c, i);
471 exit_rc: 471exit_rc:
472 return rc; 472 return rc;
473} 473}
474 474
@@ -478,7 +478,7 @@ static int SetCfgRfAgc(struct drx397xD_state *s, struct drx397xD_CfgRfAgc *agc)
478 u16 w06 = agc->w06; 478 u16 w06 = agc->w06;
479 int rc = -1; 479 int rc = -1;
480 480
481 pr_debug("%s %d 0x%x 0x%x\n", __FUNCTION__, agc->d00, w04, w06); 481 pr_debug("%s %d 0x%x 0x%x\n", __func__, agc->d00, w04, w06);
482 482
483 if (w04 > 0x3ff) 483 if (w04 > 0x3ff)
484 goto exit_rc; 484 goto exit_rc;
@@ -498,7 +498,7 @@ static int SetCfgRfAgc(struct drx397xD_state *s, struct drx397xD_CfgRfAgc *agc)
498 rc &= ~2; 498 rc &= ~2;
499 break; 499 break;
500 case 0: 500 case 0:
501 // loc_8000659 501 /* loc_8000659 */
502 s->config.w9C &= ~2; 502 s->config.w9C &= ~2;
503 EXIT_RC(WR16(s, 0x0c20015, s->config.w9C)); 503 EXIT_RC(WR16(s, 0x0c20015, s->config.w9C));
504 EXIT_RC(RD16(s, 0x0c20010)); 504 EXIT_RC(RD16(s, 0x0c20010));
@@ -522,7 +522,8 @@ static int SetCfgRfAgc(struct drx397xD_state *s, struct drx397xD_CfgRfAgc *agc)
522 rc |= 2; 522 rc |= 2;
523 } 523 }
524 rc = WR16(s, 0x0c20013, rc); 524 rc = WR16(s, 0x0c20013, rc);
525 exit_rc: 525
526exit_rc:
526 return rc; 527 return rc;
527} 528}
528 529
@@ -554,7 +555,7 @@ static int CorrectSysClockDeviation(struct drx397xD_state *s)
554 int lockstat; 555 int lockstat;
555 u32 clk, clk_limit; 556 u32 clk, clk_limit;
556 557
557 pr_debug("%s\n", __FUNCTION__); 558 pr_debug("%s\n", __func__);
558 559
559 if (s->config.d5C == 0) { 560 if (s->config.d5C == 0) {
560 EXIT_RC(WR16(s, 0x08200e8, 0x010)); 561 EXIT_RC(WR16(s, 0x08200e8, 0x010));
@@ -598,11 +599,12 @@ static int CorrectSysClockDeviation(struct drx397xD_state *s)
598 599
599 if (clk - s->config.f_osc * 1000 + clk_limit <= 2 * clk_limit) { 600 if (clk - s->config.f_osc * 1000 + clk_limit <= 2 * clk_limit) {
600 s->f_osc = clk; 601 s->f_osc = clk;
601 pr_debug("%s: osc %d %d [Hz]\n", __FUNCTION__, 602 pr_debug("%s: osc %d %d [Hz]\n", __func__,
602 s->config.f_osc * 1000, clk - s->config.f_osc * 1000); 603 s->config.f_osc * 1000, clk - s->config.f_osc * 1000);
603 } 604 }
604 rc = WR16(s, 0x08200e8, 0); 605 rc = WR16(s, 0x08200e8, 0);
605 exit_rc: 606
607exit_rc:
606 return rc; 608 return rc;
607} 609}
608 610
@@ -610,7 +612,7 @@ static int ConfigureMPEGOutput(struct drx397xD_state *s, int type)
610{ 612{
611 int rc, si, bp; 613 int rc, si, bp;
612 614
613 pr_debug("%s\n", __FUNCTION__); 615 pr_debug("%s\n", __func__);
614 616
615 si = s->config.wA0; 617 si = s->config.wA0;
616 if (s->config.w98 == 0) { 618 if (s->config.w98 == 0) {
@@ -620,17 +622,17 @@ static int ConfigureMPEGOutput(struct drx397xD_state *s, int type)
620 si &= ~1; 622 si &= ~1;
621 bp = 0x200; 623 bp = 0x200;
622 } 624 }
623 if (s->config.w9A == 0) { 625 if (s->config.w9A == 0)
624 si |= 0x80; 626 si |= 0x80;
625 } else { 627 else
626 si &= ~0x80; 628 si &= ~0x80;
627 }
628 629
629 EXIT_RC(WR16(s, 0x2150045, 0)); 630 EXIT_RC(WR16(s, 0x2150045, 0));
630 EXIT_RC(WR16(s, 0x2150010, si)); 631 EXIT_RC(WR16(s, 0x2150010, si));
631 EXIT_RC(WR16(s, 0x2150011, bp)); 632 EXIT_RC(WR16(s, 0x2150011, bp));
632 rc = WR16(s, 0x2150012, (type == 0 ? 0xfff : 0)); 633 rc = WR16(s, 0x2150012, (type == 0 ? 0xfff : 0));
633 exit_rc: 634
635exit_rc:
634 return rc; 636 return rc;
635} 637}
636 638
@@ -646,7 +648,7 @@ static int drx_tune(struct drx397xD_state *s,
646 648
647 int rc, df_tuner; 649 int rc, df_tuner;
648 int a, b, c, d; 650 int a, b, c, d;
649 pr_debug("%s %d\n", __FUNCTION__, s->config.d60); 651 pr_debug("%s %d\n", __func__, s->config.d60);
650 652
651 if (s->config.d60 != 2) 653 if (s->config.d60 != 2)
652 goto set_tuner; 654 goto set_tuner;
@@ -658,7 +660,7 @@ static int drx_tune(struct drx397xD_state *s,
658 rc = ConfigureMPEGOutput(s, 0); 660 rc = ConfigureMPEGOutput(s, 0);
659 if (rc < 0) 661 if (rc < 0)
660 goto set_tuner; 662 goto set_tuner;
661 set_tuner: 663set_tuner:
662 664
663 rc = PLL_Set(s, fep, &df_tuner); 665 rc = PLL_Set(s, fep, &df_tuner);
664 if (rc < 0) { 666 if (rc < 0) {
@@ -835,16 +837,16 @@ static int drx_tune(struct drx397xD_state *s,
835 rc = WR16(s, 0x2010012, 0); 837 rc = WR16(s, 0x2010012, 0);
836 if (rc < 0) 838 if (rc < 0)
837 goto exit_rc; 839 goto exit_rc;
838 // QPSK QAM16 QAM64 840 /* QPSK QAM16 QAM64 */
839 ebx = 0x19f; // 62 841 ebx = 0x19f; /* 62 */
840 ebp = 0x1fb; // 15 842 ebp = 0x1fb; /* 15 */
841 v20 = 0x16a; // 62 843 v20 = 0x16a; /* 62 */
842 v1E = 0x195; // 62 844 v1E = 0x195; /* 62 */
843 v16 = 0x1bb; // 15 845 v16 = 0x1bb; /* 15 */
844 v14 = 0x1ef; // 15 846 v14 = 0x1ef; /* 15 */
845 v12 = 5; // 16 847 v12 = 5; /* 16 */
846 v10 = 5; // 16 848 v10 = 5; /* 16 */
847 v0E = 5; // 16 849 v0E = 5; /* 16 */
848 } 850 }
849 851
850 switch (fep->u.ofdm.constellation) { 852 switch (fep->u.ofdm.constellation) {
@@ -997,17 +999,17 @@ static int drx_tune(struct drx397xD_state *s,
997 case BANDWIDTH_8_MHZ: /* 0 */ 999 case BANDWIDTH_8_MHZ: /* 0 */
998 case BANDWIDTH_AUTO: 1000 case BANDWIDTH_AUTO:
999 rc = WR16(s, 0x0c2003f, 0x32); 1001 rc = WR16(s, 0x0c2003f, 0x32);
1000 s->bandwidth_parm = ebx = 0x8b8249; // 9142857 1002 s->bandwidth_parm = ebx = 0x8b8249;
1001 edx = 0; 1003 edx = 0;
1002 break; 1004 break;
1003 case BANDWIDTH_7_MHZ: 1005 case BANDWIDTH_7_MHZ:
1004 rc = WR16(s, 0x0c2003f, 0x3b); 1006 rc = WR16(s, 0x0c2003f, 0x3b);
1005 s->bandwidth_parm = ebx = 0x7a1200; // 8000000 1007 s->bandwidth_parm = ebx = 0x7a1200;
1006 edx = 0x4807; 1008 edx = 0x4807;
1007 break; 1009 break;
1008 case BANDWIDTH_6_MHZ: 1010 case BANDWIDTH_6_MHZ:
1009 rc = WR16(s, 0x0c2003f, 0x47); 1011 rc = WR16(s, 0x0c2003f, 0x47);
1010 s->bandwidth_parm = ebx = 0x68a1b6; // 6857142 1012 s->bandwidth_parm = ebx = 0x68a1b6;
1011 edx = 0x0f07; 1013 edx = 0x0f07;
1012 break; 1014 break;
1013 }; 1015 };
@@ -1060,8 +1062,6 @@ static int drx_tune(struct drx397xD_state *s,
1060 WR16(s, 0x0820040, 1); 1062 WR16(s, 0x0820040, 1);
1061 SC_SendCommand(s, 1); 1063 SC_SendCommand(s, 1);
1062 1064
1063// rc = WR16(s, 0x2150000, 1);
1064// if (rc < 0) goto exit_rc;
1065 1065
1066 rc = WR16(s, 0x2150000, 2); 1066 rc = WR16(s, 0x2150000, 2);
1067 rc = WR16(s, 0x2150016, a); 1067 rc = WR16(s, 0x2150016, a);
@@ -1069,7 +1069,8 @@ static int drx_tune(struct drx397xD_state *s,
1069 rc = WR16(s, 0x2150036, 0); 1069 rc = WR16(s, 0x2150036, 0);
1070 rc = WR16(s, 0x2150000, 1); 1070 rc = WR16(s, 0x2150000, 1);
1071 s->config.d60 = 2; 1071 s->config.d60 = 2;
1072 exit_rc: 1072
1073exit_rc:
1073 return rc; 1074 return rc;
1074} 1075}
1075 1076
@@ -1082,7 +1083,7 @@ static int drx397x_init(struct dvb_frontend *fe)
1082 struct drx397xD_state *s = fe->demodulator_priv; 1083 struct drx397xD_state *s = fe->demodulator_priv;
1083 int rc; 1084 int rc;
1084 1085
1085 pr_debug("%s\n", __FUNCTION__); 1086 pr_debug("%s\n", __func__);
1086 1087
1087 s->config.rfagc.d00 = 2; /* 0x7c */ 1088 s->config.rfagc.d00 = 2; /* 0x7c */
1088 s->config.rfagc.w04 = 0; 1089 s->config.rfagc.w04 = 0;
@@ -1102,18 +1103,18 @@ static int drx397x_init(struct dvb_frontend *fe)
1102 1103
1103 /* HI_CfgCommand */ 1104 /* HI_CfgCommand */
1104 s->config.w50 = 4; 1105 s->config.w50 = 4;
1105 s->config.w52 = 9; // 0xf; 1106 s->config.w52 = 9;
1106 1107
1107 s->config.f_if = 42800000; /* d14: intermediate frequency [Hz] */ 1108 s->config.f_if = 42800000; /* d14: intermediate frequency [Hz] */
1108 s->config.f_osc = 48000; /* s66 : oscillator frequency [kHz] */ 1109 s->config.f_osc = 48000; /* s66 : oscillator frequency [kHz] */
1109 s->config.w92 = 12000; // 20000; 1110 s->config.w92 = 12000;
1110 1111
1111 s->config.w9C = 0x000e; 1112 s->config.w9C = 0x000e;
1112 s->config.w9E = 0x0000; 1113 s->config.w9E = 0x0000;
1113 1114
1114 /* ConfigureMPEGOutput params */ 1115 /* ConfigureMPEGOutput params */
1115 s->config.wA0 = 4; 1116 s->config.wA0 = 4;
1116 s->config.w98 = 1; // 0; 1117 s->config.w98 = 1;
1117 s->config.w9A = 1; 1118 s->config.w9A = 1;
1118 1119
1119 /* get chip revision */ 1120 /* get chip revision */
@@ -1248,7 +1249,7 @@ static int drx397x_init(struct dvb_frontend *fe)
1248 rc = WR16(s, 0x0c20012, 1); 1249 rc = WR16(s, 0x0c20012, 1);
1249 } 1250 }
1250 1251
1251 write_DRXD_InitFE_1: 1252write_DRXD_InitFE_1:
1252 1253
1253 rc = write_fw(s, DRXD_InitFE_1); 1254 rc = write_fw(s, DRXD_InitFE_1);
1254 if (rc < 0) 1255 if (rc < 0)
@@ -1311,7 +1312,8 @@ static int drx397x_init(struct dvb_frontend *fe)
1311 s->config.d5C = 0; 1312 s->config.d5C = 0;
1312 s->config.d60 = 1; 1313 s->config.d60 = 1;
1313 s->config.d48 = 1; 1314 s->config.d48 = 1;
1314 error: 1315
1316error:
1315 return rc; 1317 return rc;
1316} 1318}
1317 1319
@@ -1326,7 +1328,8 @@ static int drx397x_set_frontend(struct dvb_frontend *fe,
1326{ 1328{
1327 struct drx397xD_state *s = fe->demodulator_priv; 1329 struct drx397xD_state *s = fe->demodulator_priv;
1328 1330
1329 s->config.s20d24 = 1; // 0; 1331 s->config.s20d24 = 1;
1332
1330 return drx_tune(s, params); 1333 return drx_tune(s, params);
1331} 1334}
1332 1335
@@ -1337,18 +1340,16 @@ static int drx397x_get_tune_settings(struct dvb_frontend *fe,
1337 fe_tune_settings->min_delay_ms = 10000; 1340 fe_tune_settings->min_delay_ms = 10000;
1338 fe_tune_settings->step_size = 0; 1341 fe_tune_settings->step_size = 0;
1339 fe_tune_settings->max_drift = 0; 1342 fe_tune_settings->max_drift = 0;
1343
1340 return 0; 1344 return 0;
1341} 1345}
1342 1346
1343static int drx397x_read_status(struct dvb_frontend *fe, fe_status_t * status) 1347static int drx397x_read_status(struct dvb_frontend *fe, fe_status_t *status)
1344{ 1348{
1345 struct drx397xD_state *s = fe->demodulator_priv; 1349 struct drx397xD_state *s = fe->demodulator_priv;
1346 int lockstat; 1350 int lockstat;
1347 1351
1348 GetLockStatus(s, &lockstat); 1352 GetLockStatus(s, &lockstat);
1349 /* TODO */
1350// if (lockstat & 1)
1351// CorrectSysClockDeviation(s);
1352 1353
1353 *status = 0; 1354 *status = 0;
1354 if (lockstat & 2) { 1355 if (lockstat & 2) {
@@ -1356,9 +1357,8 @@ static int drx397x_read_status(struct dvb_frontend *fe, fe_status_t * status)
1356 ConfigureMPEGOutput(s, 1); 1357 ConfigureMPEGOutput(s, 1);
1357 *status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI; 1358 *status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI;
1358 } 1359 }
1359 if (lockstat & 4) { 1360 if (lockstat & 4)
1360 *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL; 1361 *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL;
1361 }
1362 1362
1363 return 0; 1363 return 0;
1364} 1364}
@@ -1366,16 +1366,18 @@ static int drx397x_read_status(struct dvb_frontend *fe, fe_status_t * status)
1366static int drx397x_read_ber(struct dvb_frontend *fe, unsigned int *ber) 1366static int drx397x_read_ber(struct dvb_frontend *fe, unsigned int *ber)
1367{ 1367{
1368 *ber = 0; 1368 *ber = 0;
1369
1369 return 0; 1370 return 0;
1370} 1371}
1371 1372
1372static int drx397x_read_snr(struct dvb_frontend *fe, u16 * snr) 1373static int drx397x_read_snr(struct dvb_frontend *fe, u16 *snr)
1373{ 1374{
1374 *snr = 0; 1375 *snr = 0;
1376
1375 return 0; 1377 return 0;
1376} 1378}
1377 1379
1378static int drx397x_read_signal_strength(struct dvb_frontend *fe, u16 * strength) 1380static int drx397x_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
1379{ 1381{
1380 struct drx397xD_state *s = fe->demodulator_priv; 1382 struct drx397xD_state *s = fe->demodulator_priv;
1381 int rc; 1383 int rc;
@@ -1401,6 +1403,7 @@ static int drx397x_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
1401 * The following does the same but with less rounding errors: 1403 * The following does the same but with less rounding errors:
1402 */ 1404 */
1403 *strength = ~(7720 + (rc * 30744 >> 10)); 1405 *strength = ~(7720 + (rc * 30744 >> 10));
1406
1404 return 0; 1407 return 0;
1405} 1408}
1406 1409
@@ -1408,6 +1411,7 @@ static int drx397x_read_ucblocks(struct dvb_frontend *fe,
1408 unsigned int *ucblocks) 1411 unsigned int *ucblocks)
1409{ 1412{
1410 *ucblocks = 0; 1413 *ucblocks = 0;
1414
1411 return 0; 1415 return 0;
1412} 1416}
1413 1417
@@ -1436,22 +1440,22 @@ static struct dvb_frontend_ops drx397x_ops = {
1436 .frequency_max = 855250000, 1440 .frequency_max = 855250000,
1437 .frequency_stepsize = 166667, 1441 .frequency_stepsize = 166667,
1438 .frequency_tolerance = 0, 1442 .frequency_tolerance = 0,
1439 .caps = /* 0x0C01B2EAE */ 1443 .caps = /* 0x0C01B2EAE */
1440 FE_CAN_FEC_1_2 | // = 0x2, 1444 FE_CAN_FEC_1_2 | /* = 0x2, */
1441 FE_CAN_FEC_2_3 | // = 0x4, 1445 FE_CAN_FEC_2_3 | /* = 0x4, */
1442 FE_CAN_FEC_3_4 | // = 0x8, 1446 FE_CAN_FEC_3_4 | /* = 0x8, */
1443 FE_CAN_FEC_5_6 | // = 0x20, 1447 FE_CAN_FEC_5_6 | /* = 0x20, */
1444 FE_CAN_FEC_7_8 | // = 0x80, 1448 FE_CAN_FEC_7_8 | /* = 0x80, */
1445 FE_CAN_FEC_AUTO | // = 0x200, 1449 FE_CAN_FEC_AUTO | /* = 0x200, */
1446 FE_CAN_QPSK | // = 0x400, 1450 FE_CAN_QPSK | /* = 0x400, */
1447 FE_CAN_QAM_16 | // = 0x800, 1451 FE_CAN_QAM_16 | /* = 0x800, */
1448 FE_CAN_QAM_64 | // = 0x2000, 1452 FE_CAN_QAM_64 | /* = 0x2000, */
1449 FE_CAN_QAM_AUTO | // = 0x10000, 1453 FE_CAN_QAM_AUTO | /* = 0x10000, */
1450 FE_CAN_TRANSMISSION_MODE_AUTO | // = 0x20000, 1454 FE_CAN_TRANSMISSION_MODE_AUTO | /* = 0x20000, */
1451 FE_CAN_GUARD_INTERVAL_AUTO | // = 0x80000, 1455 FE_CAN_GUARD_INTERVAL_AUTO | /* = 0x80000, */
1452 FE_CAN_HIERARCHY_AUTO | // = 0x100000, 1456 FE_CAN_HIERARCHY_AUTO | /* = 0x100000, */
1453 FE_CAN_RECOVER | // = 0x40000000, 1457 FE_CAN_RECOVER | /* = 0x40000000, */
1454 FE_CAN_MUTE_TS // = 0x80000000 1458 FE_CAN_MUTE_TS /* = 0x80000000 */
1455 }, 1459 },
1456 1460
1457 .release = drx397x_release, 1461 .release = drx397x_release,
@@ -1472,33 +1476,35 @@ static struct dvb_frontend_ops drx397x_ops = {
1472struct dvb_frontend *drx397xD_attach(const struct drx397xD_config *config, 1476struct dvb_frontend *drx397xD_attach(const struct drx397xD_config *config,
1473 struct i2c_adapter *i2c) 1477 struct i2c_adapter *i2c)
1474{ 1478{
1475 struct drx397xD_state *s = NULL; 1479 struct drx397xD_state *state;
1476 1480
1477 /* allocate memory for the internal state */ 1481 /* allocate memory for the internal state */
1478 s = kzalloc(sizeof(struct drx397xD_state), GFP_KERNEL); 1482 state = kzalloc(sizeof(struct drx397xD_state), GFP_KERNEL);
1479 if (s == NULL) 1483 if (!state)
1480 goto error; 1484 goto error;
1481 1485
1482 /* setup the state */ 1486 /* setup the state */
1483 s->i2c = i2c; 1487 state->i2c = i2c;
1484 memcpy(&s->config, config, sizeof(struct drx397xD_config)); 1488 memcpy(&state->config, config, sizeof(struct drx397xD_config));
1485 1489
1486 /* check if the demod is there */ 1490 /* check if the demod is there */
1487 if (RD16(s, 0x2410019) < 0) 1491 if (RD16(state, 0x2410019) < 0)
1488 goto error; 1492 goto error;
1489 1493
1490 /* create dvb_frontend */ 1494 /* create dvb_frontend */
1491 memcpy(&s->frontend.ops, &drx397x_ops, sizeof(struct dvb_frontend_ops)); 1495 memcpy(&state->frontend.ops, &drx397x_ops,
1492 s->frontend.demodulator_priv = s; 1496 sizeof(struct dvb_frontend_ops));
1497 state->frontend.demodulator_priv = state;
1498
1499 return &state->frontend;
1500error:
1501 kfree(state);
1493 1502
1494 return &s->frontend;
1495 error:
1496 kfree(s);
1497 return NULL; 1503 return NULL;
1498} 1504}
1505EXPORT_SYMBOL(drx397xD_attach);
1499 1506
1500MODULE_DESCRIPTION("Micronas DRX397xD DVB-T Frontend"); 1507MODULE_DESCRIPTION("Micronas DRX397xD DVB-T Frontend");
1501MODULE_AUTHOR("Henk Vergonet"); 1508MODULE_AUTHOR("Henk Vergonet");
1502MODULE_LICENSE("GPL"); 1509MODULE_LICENSE("GPL");
1503 1510
1504EXPORT_SYMBOL(drx397xD_attach);
diff --git a/drivers/media/dvb/frontends/drx397xD.h b/drivers/media/dvb/frontends/drx397xD.h
index ddc7a07971b7..ba05d17290c6 100644
--- a/drivers/media/dvb/frontends/drx397xD.h
+++ b/drivers/media/dvb/frontends/drx397xD.h
@@ -28,7 +28,7 @@
28#define DRX_F_OFFSET 36000000 28#define DRX_F_OFFSET 36000000
29 29
30#define I2C_ADR_C0(x) \ 30#define I2C_ADR_C0(x) \
31( (u32)cpu_to_le32( \ 31( cpu_to_le32( \
32 (u32)( \ 32 (u32)( \
33 (((u32)(x) & (u32)0x000000ffUL) ) | \ 33 (((u32)(x) & (u32)0x000000ffUL) ) | \
34 (((u32)(x) & (u32)0x0000ff00UL) << 16) | \ 34 (((u32)(x) & (u32)0x0000ff00UL) << 16) | \
@@ -38,7 +38,7 @@
38) 38)
39 39
40#define I2C_ADR_E0(x) \ 40#define I2C_ADR_E0(x) \
41( (u32)cpu_to_le32( \ 41( cpu_to_le32( \
42 (u32)( \ 42 (u32)( \
43 (((u32)(x) & (u32)0x000000ffUL) ) | \ 43 (((u32)(x) & (u32)0x000000ffUL) ) | \
44 (((u32)(x) & (u32)0x0000ff00UL) << 16) | \ 44 (((u32)(x) & (u32)0x0000ff00UL) << 16) | \
@@ -122,7 +122,7 @@ extern struct dvb_frontend* drx397xD_attach(const struct drx397xD_config *config
122static inline struct dvb_frontend* drx397xD_attach(const struct drx397xD_config *config, 122static inline struct dvb_frontend* drx397xD_attach(const struct drx397xD_config *config,
123 struct i2c_adapter *i2c) 123 struct i2c_adapter *i2c)
124{ 124{
125 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 125 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
126 return NULL; 126 return NULL;
127} 127}
128#endif /* CONFIG_DVB_DRX397XD */ 128#endif /* CONFIG_DVB_DRX397XD */
diff --git a/drivers/media/dvb/frontends/dvb_dummy_fe.c b/drivers/media/dvb/frontends/dvb_dummy_fe.c
index fed09dfb2b7c..db8a937cc630 100644
--- a/drivers/media/dvb/frontends/dvb_dummy_fe.c
+++ b/drivers/media/dvb/frontends/dvb_dummy_fe.c
@@ -75,9 +75,10 @@ static int dvb_dummy_fe_get_frontend(struct dvb_frontend* fe, struct dvb_fronten
75 75
76static int dvb_dummy_fe_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 76static int dvb_dummy_fe_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
77{ 77{
78 if (fe->ops->tuner_ops->set_params) { 78 if (fe->ops.tuner_ops.set_params) {
79 fe->ops->tuner_ops->set_params(fe, p); 79 fe->ops.tuner_ops.set_params(fe, p);
80 if (fe->ops->i2c_gate_ctrl) fe->ops->i2c_gate_ctrl(fe, 0); 80 if (fe->ops.i2c_gate_ctrl)
81 fe->ops.i2c_gate_ctrl(fe, 0);
81 } 82 }
82 83
83 return 0; 84 return 0;
@@ -131,7 +132,7 @@ error:
131 132
132static struct dvb_frontend_ops dvb_dummy_fe_qpsk_ops; 133static struct dvb_frontend_ops dvb_dummy_fe_qpsk_ops;
133 134
134struct dvb_frontend* dvb_dummy_fe_qpsk_attach() 135struct dvb_frontend *dvb_dummy_fe_qpsk_attach(void)
135{ 136{
136 struct dvb_dummy_fe_state* state = NULL; 137 struct dvb_dummy_fe_state* state = NULL;
137 138
@@ -151,7 +152,7 @@ error:
151 152
152static struct dvb_frontend_ops dvb_dummy_fe_qam_ops; 153static struct dvb_frontend_ops dvb_dummy_fe_qam_ops;
153 154
154struct dvb_frontend* dvb_dummy_fe_qam_attach() 155struct dvb_frontend *dvb_dummy_fe_qam_attach(void)
155{ 156{
156 struct dvb_dummy_fe_state* state = NULL; 157 struct dvb_dummy_fe_state* state = NULL;
157 158
diff --git a/drivers/media/dvb/frontends/eds1547.h b/drivers/media/dvb/frontends/eds1547.h
new file mode 100644
index 000000000000..fa79b7c83dd2
--- /dev/null
+++ b/drivers/media/dvb/frontends/eds1547.h
@@ -0,0 +1,133 @@
1/* eds1547.h Earda EDS-1547 tuner support
2*
3* Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by)
4*
5* This program is free software; you can redistribute it and/or modify it
6* under the terms of the GNU General Public License as published by the
7* Free Software Foundation, version 2.
8*
9* see Documentation/dvb/README.dvb-usb for more information
10*/
11
12#ifndef EDS1547
13#define EDS1547
14
15static u8 stv0288_earda_inittab[] = {
16 0x01, 0x57,
17 0x02, 0x20,
18 0x03, 0x8e,
19 0x04, 0x8e,
20 0x05, 0x12,
21 0x06, 0x00,
22 0x07, 0x00,
23 0x09, 0x00,
24 0x0a, 0x04,
25 0x0b, 0x00,
26 0x0c, 0x00,
27 0x0d, 0x00,
28 0x0e, 0xd4,
29 0x0f, 0x30,
30 0x11, 0x44,
31 0x12, 0x03,
32 0x13, 0x48,
33 0x14, 0x84,
34 0x15, 0x45,
35 0x16, 0xb7,
36 0x17, 0x9c,
37 0x18, 0x00,
38 0x19, 0xa6,
39 0x1a, 0x88,
40 0x1b, 0x8f,
41 0x1c, 0xf0,
42 0x20, 0x0b,
43 0x21, 0x54,
44 0x22, 0x00,
45 0x23, 0x00,
46 0x2b, 0xff,
47 0x2c, 0xf7,
48 0x30, 0x00,
49 0x31, 0x1e,
50 0x32, 0x14,
51 0x33, 0x0f,
52 0x34, 0x09,
53 0x35, 0x0c,
54 0x36, 0x05,
55 0x37, 0x2f,
56 0x38, 0x16,
57 0x39, 0xbd,
58 0x3a, 0x00,
59 0x3b, 0x13,
60 0x3c, 0x11,
61 0x3d, 0x30,
62 0x40, 0x63,
63 0x41, 0x04,
64 0x42, 0x60,
65 0x43, 0x00,
66 0x44, 0x00,
67 0x45, 0x00,
68 0x46, 0x00,
69 0x47, 0x00,
70 0x4a, 0x00,
71 0x50, 0x10,
72 0x51, 0x36,
73 0x52, 0x09,
74 0x53, 0x94,
75 0x54, 0x62,
76 0x55, 0x29,
77 0x56, 0x64,
78 0x57, 0x2b,
79 0x58, 0x54,
80 0x59, 0x86,
81 0x5a, 0x00,
82 0x5b, 0x9b,
83 0x5c, 0x08,
84 0x5d, 0x7f,
85 0x5e, 0x00,
86 0x5f, 0xff,
87 0x70, 0x00,
88 0x71, 0x00,
89 0x72, 0x00,
90 0x74, 0x00,
91 0x75, 0x00,
92 0x76, 0x00,
93 0x81, 0x00,
94 0x82, 0x3f,
95 0x83, 0x3f,
96 0x84, 0x00,
97 0x85, 0x00,
98 0x88, 0x00,
99 0x89, 0x00,
100 0x8a, 0x00,
101 0x8b, 0x00,
102 0x8c, 0x00,
103 0x90, 0x00,
104 0x91, 0x00,
105 0x92, 0x00,
106 0x93, 0x00,
107 0x94, 0x1c,
108 0x97, 0x00,
109 0xa0, 0x48,
110 0xa1, 0x00,
111 0xb0, 0xb8,
112 0xb1, 0x3a,
113 0xb2, 0x10,
114 0xb3, 0x82,
115 0xb4, 0x80,
116 0xb5, 0x82,
117 0xb6, 0x82,
118 0xb7, 0x82,
119 0xb8, 0x20,
120 0xb9, 0x00,
121 0xf0, 0x00,
122 0xf1, 0x00,
123 0xf2, 0xc0,
124 0xff,0xff,
125};
126
127static struct stv0288_config earda_config = {
128 .demod_address = 0x68,
129 .min_delay_ms = 100,
130 .inittab = stv0288_earda_inittab,
131};
132
133#endif
diff --git a/drivers/media/dvb/frontends/lgs8gl5.c b/drivers/media/dvb/frontends/lgs8gl5.c
new file mode 100644
index 000000000000..855852fddf22
--- /dev/null
+++ b/drivers/media/dvb/frontends/lgs8gl5.c
@@ -0,0 +1,454 @@
1/*
2 Legend Silicon LGS-8GL5 DMB-TH OFDM demodulator driver
3
4 Copyright (C) 2008 Sirius International (Hong Kong) Limited
5 Timothy Lee <timothy.lee@siriushk.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21*/
22
23#include <linux/kernel.h>
24#include <linux/init.h>
25#include <linux/module.h>
26#include <linux/string.h>
27#include <linux/slab.h>
28#include "dvb_frontend.h"
29#include "lgs8gl5.h"
30
31
32#define REG_RESET 0x02
33#define REG_RESET_OFF 0x01
34#define REG_03 0x03
35#define REG_04 0x04
36#define REG_07 0x07
37#define REG_09 0x09
38#define REG_0A 0x0a
39#define REG_0B 0x0b
40#define REG_0C 0x0c
41#define REG_37 0x37
42#define REG_STRENGTH 0x4b
43#define REG_STRENGTH_MASK 0x7f
44#define REG_STRENGTH_CARRIER 0x80
45#define REG_INVERSION 0x7c
46#define REG_INVERSION_ON 0x80
47#define REG_7D 0x7d
48#define REG_7E 0x7e
49#define REG_A2 0xa2
50#define REG_STATUS 0xa4
51#define REG_STATUS_SYNC 0x04
52#define REG_STATUS_LOCK 0x01
53
54
55struct lgs8gl5_state {
56 struct i2c_adapter *i2c;
57 const struct lgs8gl5_config *config;
58 struct dvb_frontend frontend;
59};
60
61
62static int debug;
63#define dprintk(args...) \
64 do { \
65 if (debug) \
66 printk(KERN_DEBUG "lgs8gl5: " args); \
67 } while (0)
68
69
70/* Writes into demod's register */
71static int
72lgs8gl5_write_reg(struct lgs8gl5_state *state, u8 reg, u8 data)
73{
74 int ret;
75 u8 buf[] = {reg, data};
76 struct i2c_msg msg = {
77 .addr = state->config->demod_address,
78 .flags = 0,
79 .buf = buf,
80 .len = 2
81 };
82
83 ret = i2c_transfer(state->i2c, &msg, 1);
84 if (ret != 1)
85 dprintk("%s: error (reg=0x%02x, val=0x%02x, ret=%i)\n",
86 __func__, reg, data, ret);
87 return (ret != 1) ? -1 : 0;
88}
89
90
91/* Reads from demod's register */
92static int
93lgs8gl5_read_reg(struct lgs8gl5_state *state, u8 reg)
94{
95 int ret;
96 u8 b0[] = {reg};
97 u8 b1[] = {0};
98 struct i2c_msg msg[2] = {
99 {
100 .addr = state->config->demod_address,
101 .flags = 0,
102 .buf = b0,
103 .len = 1
104 },
105 {
106 .addr = state->config->demod_address,
107 .flags = I2C_M_RD,
108 .buf = b1,
109 .len = 1
110 }
111 };
112
113 ret = i2c_transfer(state->i2c, msg, 2);
114 if (ret != 2)
115 return -EIO;
116
117 return b1[0];
118}
119
120
121static int
122lgs8gl5_update_reg(struct lgs8gl5_state *state, u8 reg, u8 data)
123{
124 lgs8gl5_read_reg(state, reg);
125 lgs8gl5_write_reg(state, reg, data);
126 return 0;
127}
128
129
130/* Writes into alternate device's register */
131/* TODO: Find out what that device is for! */
132static int
133lgs8gl5_update_alt_reg(struct lgs8gl5_state *state, u8 reg, u8 data)
134{
135 int ret;
136 u8 b0[] = {reg};
137 u8 b1[] = {0};
138 u8 b2[] = {reg, data};
139 struct i2c_msg msg[3] = {
140 {
141 .addr = state->config->demod_address + 2,
142 .flags = 0,
143 .buf = b0,
144 .len = 1
145 },
146 {
147 .addr = state->config->demod_address + 2,
148 .flags = I2C_M_RD,
149 .buf = b1,
150 .len = 1
151 },
152 {
153 .addr = state->config->demod_address + 2,
154 .flags = 0,
155 .buf = b2,
156 .len = 2
157 },
158 };
159
160 ret = i2c_transfer(state->i2c, msg, 3);
161 return (ret != 3) ? -1 : 0;
162}
163
164
165static void
166lgs8gl5_soft_reset(struct lgs8gl5_state *state)
167{
168 u8 val;
169
170 dprintk("%s\n", __func__);
171
172 val = lgs8gl5_read_reg(state, REG_RESET);
173 lgs8gl5_write_reg(state, REG_RESET, val & ~REG_RESET_OFF);
174 lgs8gl5_write_reg(state, REG_RESET, val | REG_RESET_OFF);
175 msleep(5);
176}
177
178
179/* Starts demodulation */
180static void
181lgs8gl5_start_demod(struct lgs8gl5_state *state)
182{
183 u8 val;
184 int n;
185
186 dprintk("%s\n", __func__);
187
188 lgs8gl5_update_alt_reg(state, 0xc2, 0x28);
189 lgs8gl5_soft_reset(state);
190 lgs8gl5_update_reg(state, REG_07, 0x10);
191 lgs8gl5_update_reg(state, REG_07, 0x10);
192 lgs8gl5_write_reg(state, REG_09, 0x0e);
193 lgs8gl5_write_reg(state, REG_0A, 0xe5);
194 lgs8gl5_write_reg(state, REG_0B, 0x35);
195 lgs8gl5_write_reg(state, REG_0C, 0x30);
196
197 lgs8gl5_update_reg(state, REG_03, 0x00);
198 lgs8gl5_update_reg(state, REG_7E, 0x01);
199 lgs8gl5_update_alt_reg(state, 0xc5, 0x00);
200 lgs8gl5_update_reg(state, REG_04, 0x02);
201 lgs8gl5_update_reg(state, REG_37, 0x01);
202 lgs8gl5_soft_reset(state);
203
204 /* Wait for carrier */
205 for (n = 0; n < 10; n++) {
206 val = lgs8gl5_read_reg(state, REG_STRENGTH);
207 dprintk("Wait for carrier[%d] 0x%02X\n", n, val);
208 if (val & REG_STRENGTH_CARRIER)
209 break;
210 msleep(4);
211 }
212 if (!(val & REG_STRENGTH_CARRIER))
213 return;
214
215 /* Wait for lock */
216 for (n = 0; n < 20; n++) {
217 val = lgs8gl5_read_reg(state, REG_STATUS);
218 dprintk("Wait for lock[%d] 0x%02X\n", n, val);
219 if (val & REG_STATUS_LOCK)
220 break;
221 msleep(12);
222 }
223 if (!(val & REG_STATUS_LOCK))
224 return;
225
226 lgs8gl5_write_reg(state, REG_7D, lgs8gl5_read_reg(state, REG_A2));
227 lgs8gl5_soft_reset(state);
228}
229
230
231static int
232lgs8gl5_init(struct dvb_frontend *fe)
233{
234 struct lgs8gl5_state *state = fe->demodulator_priv;
235
236 dprintk("%s\n", __func__);
237
238 lgs8gl5_update_alt_reg(state, 0xc2, 0x28);
239 lgs8gl5_soft_reset(state);
240 lgs8gl5_update_reg(state, REG_07, 0x10);
241 lgs8gl5_update_reg(state, REG_07, 0x10);
242 lgs8gl5_write_reg(state, REG_09, 0x0e);
243 lgs8gl5_write_reg(state, REG_0A, 0xe5);
244 lgs8gl5_write_reg(state, REG_0B, 0x35);
245 lgs8gl5_write_reg(state, REG_0C, 0x30);
246
247 return 0;
248}
249
250
251static int
252lgs8gl5_read_status(struct dvb_frontend *fe, fe_status_t *status)
253{
254 struct lgs8gl5_state *state = fe->demodulator_priv;
255 u8 level = lgs8gl5_read_reg(state, REG_STRENGTH);
256 u8 flags = lgs8gl5_read_reg(state, REG_STATUS);
257
258 *status = 0;
259
260 if ((level & REG_STRENGTH_MASK) > 0)
261 *status |= FE_HAS_SIGNAL;
262 if (level & REG_STRENGTH_CARRIER)
263 *status |= FE_HAS_CARRIER;
264 if (flags & REG_STATUS_SYNC)
265 *status |= FE_HAS_SYNC;
266 if (flags & REG_STATUS_LOCK)
267 *status |= FE_HAS_LOCK;
268
269 return 0;
270}
271
272
273static int
274lgs8gl5_read_ber(struct dvb_frontend *fe, u32 *ber)
275{
276 *ber = 0;
277
278 return 0;
279}
280
281
282static int
283lgs8gl5_read_signal_strength(struct dvb_frontend *fe, u16 *signal_strength)
284{
285 struct lgs8gl5_state *state = fe->demodulator_priv;
286 u8 level = lgs8gl5_read_reg(state, REG_STRENGTH);
287 *signal_strength = (level & REG_STRENGTH_MASK) << 8;
288
289 return 0;
290}
291
292
293static int
294lgs8gl5_read_snr(struct dvb_frontend *fe, u16 *snr)
295{
296 struct lgs8gl5_state *state = fe->demodulator_priv;
297 u8 level = lgs8gl5_read_reg(state, REG_STRENGTH);
298 *snr = (level & REG_STRENGTH_MASK) << 8;
299
300 return 0;
301}
302
303
304static int
305lgs8gl5_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
306{
307 *ucblocks = 0;
308
309 return 0;
310}
311
312
313static int
314lgs8gl5_set_frontend(struct dvb_frontend *fe,
315 struct dvb_frontend_parameters *p)
316{
317 struct lgs8gl5_state *state = fe->demodulator_priv;
318
319 dprintk("%s\n", __func__);
320
321 if (p->u.ofdm.bandwidth != BANDWIDTH_8_MHZ)
322 return -EINVAL;
323
324 if (fe->ops.tuner_ops.set_params) {
325 fe->ops.tuner_ops.set_params(fe, p);
326 if (fe->ops.i2c_gate_ctrl)
327 fe->ops.i2c_gate_ctrl(fe, 0);
328 }
329
330 /* lgs8gl5_set_inversion(state, p->inversion); */
331
332 lgs8gl5_start_demod(state);
333
334 return 0;
335}
336
337
338static int
339lgs8gl5_get_frontend(struct dvb_frontend *fe,
340 struct dvb_frontend_parameters *p)
341{
342 struct lgs8gl5_state *state = fe->demodulator_priv;
343 u8 inv = lgs8gl5_read_reg(state, REG_INVERSION);
344 struct dvb_ofdm_parameters *o = &p->u.ofdm;
345
346 p->inversion = (inv & REG_INVERSION_ON) ? INVERSION_ON : INVERSION_OFF;
347
348 o->code_rate_HP = FEC_1_2;
349 o->code_rate_LP = FEC_7_8;
350 o->guard_interval = GUARD_INTERVAL_1_32;
351 o->transmission_mode = TRANSMISSION_MODE_2K;
352 o->constellation = QAM_64;
353 o->hierarchy_information = HIERARCHY_NONE;
354 o->bandwidth = BANDWIDTH_8_MHZ;
355
356 return 0;
357}
358
359
360static int
361lgs8gl5_get_tune_settings(struct dvb_frontend *fe,
362 struct dvb_frontend_tune_settings *fesettings)
363{
364 fesettings->min_delay_ms = 240;
365 fesettings->step_size = 0;
366 fesettings->max_drift = 0;
367 return 0;
368}
369
370
371static void
372lgs8gl5_release(struct dvb_frontend *fe)
373{
374 struct lgs8gl5_state *state = fe->demodulator_priv;
375 kfree(state);
376}
377
378
379static struct dvb_frontend_ops lgs8gl5_ops;
380
381
382struct dvb_frontend*
383lgs8gl5_attach(const struct lgs8gl5_config *config, struct i2c_adapter *i2c)
384{
385 struct lgs8gl5_state *state = NULL;
386
387 dprintk("%s\n", __func__);
388
389 /* Allocate memory for the internal state */
390 state = kmalloc(sizeof(struct lgs8gl5_state), GFP_KERNEL);
391 if (state == NULL)
392 goto error;
393
394 /* Setup the state */
395 state->config = config;
396 state->i2c = i2c;
397
398 /* Check if the demod is there */
399 if (lgs8gl5_read_reg(state, REG_RESET) < 0)
400 goto error;
401
402 /* Create dvb_frontend */
403 memcpy(&state->frontend.ops, &lgs8gl5_ops,
404 sizeof(struct dvb_frontend_ops));
405 state->frontend.demodulator_priv = state;
406 return &state->frontend;
407
408error:
409 kfree(state);
410 return NULL;
411}
412EXPORT_SYMBOL(lgs8gl5_attach);
413
414
415static struct dvb_frontend_ops lgs8gl5_ops = {
416 .info = {
417 .name = "Legend Silicon LGS-8GL5 DMB-TH",
418 .type = FE_OFDM,
419 .frequency_min = 474000000,
420 .frequency_max = 858000000,
421 .frequency_stepsize = 10000,
422 .frequency_tolerance = 0,
423 .caps = FE_CAN_FEC_AUTO |
424 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_32 |
425 FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
426 FE_CAN_TRANSMISSION_MODE_AUTO |
427 FE_CAN_BANDWIDTH_AUTO |
428 FE_CAN_GUARD_INTERVAL_AUTO |
429 FE_CAN_HIERARCHY_AUTO |
430 FE_CAN_RECOVER
431 },
432
433 .release = lgs8gl5_release,
434
435 .init = lgs8gl5_init,
436
437 .set_frontend = lgs8gl5_set_frontend,
438 .get_frontend = lgs8gl5_get_frontend,
439 .get_tune_settings = lgs8gl5_get_tune_settings,
440
441 .read_status = lgs8gl5_read_status,
442 .read_ber = lgs8gl5_read_ber,
443 .read_signal_strength = lgs8gl5_read_signal_strength,
444 .read_snr = lgs8gl5_read_snr,
445 .read_ucblocks = lgs8gl5_read_ucblocks,
446};
447
448
449module_param(debug, int, 0644);
450MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
451
452MODULE_DESCRIPTION("Legend Silicon LGS-8GL5 DMB-TH Demodulator driver");
453MODULE_AUTHOR("Timothy Lee");
454MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/lgs8gl5.h b/drivers/media/dvb/frontends/lgs8gl5.h
new file mode 100644
index 000000000000..d14176787a7d
--- /dev/null
+++ b/drivers/media/dvb/frontends/lgs8gl5.h
@@ -0,0 +1,45 @@
1/*
2 Legend Silicon LGS-8GL5 DMB-TH OFDM demodulator driver
3
4 Copyright (C) 2008 Sirius International (Hong Kong) Limited
5 Timothy Lee <timothy.lee@siriushk.com>
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21*/
22
23#ifndef LGS8GL5_H
24#define LGS8GL5_H
25
26#include <linux/dvb/frontend.h>
27
28struct lgs8gl5_config {
29 /* the demodulator's i2c address */
30 u8 demod_address;
31};
32
33#if defined(CONFIG_DVB_LGS8GL5) || \
34 (defined(CONFIG_DVB_LGS8GL5_MODULE) && defined(MODULE))
35extern struct dvb_frontend *lgs8gl5_attach(
36 const struct lgs8gl5_config *config, struct i2c_adapter *i2c);
37#else
38static inline struct dvb_frontend *lgs8gl5_attach(
39 const struct lgs8gl5_config *config, struct i2c_adapter *i2c) {
40 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
41 return NULL;
42}
43#endif /* CONFIG_DVB_LGS8GL5 */
44
45#endif /* LGS8GL5_H */
diff --git a/drivers/media/dvb/frontends/nxt200x.c b/drivers/media/dvb/frontends/nxt200x.c
index af298358e822..a8429ebfa8a2 100644
--- a/drivers/media/dvb/frontends/nxt200x.c
+++ b/drivers/media/dvb/frontends/nxt200x.c
@@ -80,7 +80,7 @@ static int i2c_writebytes (struct nxt200x_state* state, u8 addr, u8 *buf, u8 len
80 return 0; 80 return 0;
81} 81}
82 82
83static u8 i2c_readbytes (struct nxt200x_state* state, u8 addr, u8* buf, u8 len) 83static int i2c_readbytes(struct nxt200x_state *state, u8 addr, u8 *buf, u8 len)
84{ 84{
85 int err; 85 int err;
86 struct i2c_msg msg = { .addr = addr, .flags = I2C_M_RD, .buf = buf, .len = len }; 86 struct i2c_msg msg = { .addr = addr, .flags = I2C_M_RD, .buf = buf, .len = len };
@@ -111,7 +111,7 @@ static int nxt200x_writebytes (struct nxt200x_state* state, u8 reg,
111 return 0; 111 return 0;
112} 112}
113 113
114static u8 nxt200x_readbytes (struct nxt200x_state* state, u8 reg, u8* buf, u8 len) 114static int nxt200x_readbytes(struct nxt200x_state *state, u8 reg, u8 *buf, u8 len)
115{ 115{
116 u8 reg2 [] = { reg }; 116 u8 reg2 [] = { reg };
117 117
diff --git a/drivers/media/dvb/frontends/or51211.c b/drivers/media/dvb/frontends/or51211.c
index 6afe12aaca4e..16cf2fdd5d7d 100644
--- a/drivers/media/dvb/frontends/or51211.c
+++ b/drivers/media/dvb/frontends/or51211.c
@@ -88,7 +88,7 @@ static int i2c_writebytes (struct or51211_state* state, u8 reg, const u8 *buf,
88 return 0; 88 return 0;
89} 89}
90 90
91static u8 i2c_readbytes (struct or51211_state* state, u8 reg, u8* buf, int len) 91static int i2c_readbytes(struct or51211_state *state, u8 reg, u8 *buf, int len)
92{ 92{
93 int err; 93 int err;
94 struct i2c_msg msg; 94 struct i2c_msg msg;
diff --git a/drivers/media/dvb/frontends/si21xx.c b/drivers/media/dvb/frontends/si21xx.c
new file mode 100644
index 000000000000..3ddbe69c45ce
--- /dev/null
+++ b/drivers/media/dvb/frontends/si21xx.c
@@ -0,0 +1,974 @@
1/* DVB compliant Linux driver for the DVB-S si2109/2110 demodulator
2*
3* Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by)
4*
5* This program is free software; you can redistribute it and/or modify
6* it under the terms of the GNU General Public License as published by
7* the Free Software Foundation; either version 2 of the License, or
8* (at your option) any later version.
9*
10*/
11#include <linux/version.h>
12#include <linux/init.h>
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/string.h>
16#include <linux/slab.h>
17#include <linux/jiffies.h>
18#include <asm/div64.h>
19
20#include "dvb_frontend.h"
21#include "si21xx.h"
22
23#define REVISION_REG 0x00
24#define SYSTEM_MODE_REG 0x01
25#define TS_CTRL_REG_1 0x02
26#define TS_CTRL_REG_2 0x03
27#define PIN_CTRL_REG_1 0x04
28#define PIN_CTRL_REG_2 0x05
29#define LOCK_STATUS_REG_1 0x0f
30#define LOCK_STATUS_REG_2 0x10
31#define ACQ_STATUS_REG 0x11
32#define ACQ_CTRL_REG_1 0x13
33#define ACQ_CTRL_REG_2 0x14
34#define PLL_DIVISOR_REG 0x15
35#define COARSE_TUNE_REG 0x16
36#define FINE_TUNE_REG_L 0x17
37#define FINE_TUNE_REG_H 0x18
38
39#define ANALOG_AGC_POWER_LEVEL_REG 0x28
40#define CFO_ESTIMATOR_CTRL_REG_1 0x29
41#define CFO_ESTIMATOR_CTRL_REG_2 0x2a
42#define CFO_ESTIMATOR_CTRL_REG_3 0x2b
43
44#define SYM_RATE_ESTIMATE_REG_L 0x31
45#define SYM_RATE_ESTIMATE_REG_M 0x32
46#define SYM_RATE_ESTIMATE_REG_H 0x33
47
48#define CFO_ESTIMATOR_OFFSET_REG_L 0x36
49#define CFO_ESTIMATOR_OFFSET_REG_H 0x37
50#define CFO_ERROR_REG_L 0x38
51#define CFO_ERROR_REG_H 0x39
52#define SYM_RATE_ESTIMATOR_CTRL_REG 0x3a
53
54#define SYM_RATE_REG_L 0x3f
55#define SYM_RATE_REG_M 0x40
56#define SYM_RATE_REG_H 0x41
57#define SYM_RATE_ESTIMATOR_MAXIMUM_REG 0x42
58#define SYM_RATE_ESTIMATOR_MINIMUM_REG 0x43
59
60#define C_N_ESTIMATOR_CTRL_REG 0x7c
61#define C_N_ESTIMATOR_THRSHLD_REG 0x7d
62#define C_N_ESTIMATOR_LEVEL_REG_L 0x7e
63#define C_N_ESTIMATOR_LEVEL_REG_H 0x7f
64
65#define BLIND_SCAN_CTRL_REG 0x80
66
67#define LSA_CTRL_REG_1 0x8D
68#define SPCTRM_TILT_CORR_THRSHLD_REG 0x8f
69#define ONE_DB_BNDWDTH_THRSHLD_REG 0x90
70#define TWO_DB_BNDWDTH_THRSHLD_REG 0x91
71#define THREE_DB_BNDWDTH_THRSHLD_REG 0x92
72#define INBAND_POWER_THRSHLD_REG 0x93
73#define REF_NOISE_LVL_MRGN_THRSHLD_REG 0x94
74
75#define VIT_SRCH_CTRL_REG_1 0xa0
76#define VIT_SRCH_CTRL_REG_2 0xa1
77#define VIT_SRCH_CTRL_REG_3 0xa2
78#define VIT_SRCH_STATUS_REG 0xa3
79#define VITERBI_BER_COUNT_REG_L 0xab
80#define REED_SOLOMON_CTRL_REG 0xb0
81#define REED_SOLOMON_ERROR_COUNT_REG_L 0xb1
82#define PRBS_CTRL_REG 0xb5
83
84#define LNB_CTRL_REG_1 0xc0
85#define LNB_CTRL_REG_2 0xc1
86#define LNB_CTRL_REG_3 0xc2
87#define LNB_CTRL_REG_4 0xc3
88#define LNB_CTRL_STATUS_REG 0xc4
89#define LNB_FIFO_REGS_0 0xc5
90#define LNB_FIFO_REGS_1 0xc6
91#define LNB_FIFO_REGS_2 0xc7
92#define LNB_FIFO_REGS_3 0xc8
93#define LNB_FIFO_REGS_4 0xc9
94#define LNB_FIFO_REGS_5 0xca
95#define LNB_SUPPLY_CTRL_REG_1 0xcb
96#define LNB_SUPPLY_CTRL_REG_2 0xcc
97#define LNB_SUPPLY_CTRL_REG_3 0xcd
98#define LNB_SUPPLY_CTRL_REG_4 0xce
99#define LNB_SUPPLY_STATUS_REG 0xcf
100
101#define FALSE 0
102#define TRUE 1
103#define FAIL -1
104#define PASS 0
105
106#define ALLOWABLE_FS_COUNT 10
107#define STATUS_BER 0
108#define STATUS_UCBLOCKS 1
109
110static int debug;
111#define dprintk(args...) \
112 do { \
113 if (debug) \
114 printk(KERN_DEBUG "si21xx: " args); \
115 } while (0)
116
117enum {
118 ACTIVE_HIGH,
119 ACTIVE_LOW
120};
121enum {
122 BYTE_WIDE,
123 BIT_WIDE
124};
125enum {
126 CLK_GAPPED_MODE,
127 CLK_CONTINUOUS_MODE
128};
129enum {
130 RISING_EDGE,
131 FALLING_EDGE
132};
133enum {
134 MSB_FIRST,
135 LSB_FIRST
136};
137enum {
138 SERIAL,
139 PARALLEL
140};
141
142struct si21xx_state {
143 struct i2c_adapter *i2c;
144 const struct si21xx_config *config;
145 struct dvb_frontend frontend;
146 u8 initialised:1;
147 int errmode;
148 int fs; /*Sampling rate of the ADC in MHz*/
149};
150
151/* register default initialization */
152static u8 serit_sp1511lhb_inittab[] = {
153 0x01, 0x28, /* set i2c_inc_disable */
154 0x20, 0x03,
155 0x27, 0x20,
156 0xe0, 0x45,
157 0xe1, 0x08,
158 0xfe, 0x01,
159 0x01, 0x28,
160 0x89, 0x09,
161 0x04, 0x80,
162 0x05, 0x01,
163 0x06, 0x00,
164 0x20, 0x03,
165 0x24, 0x88,
166 0x29, 0x09,
167 0x2a, 0x0f,
168 0x2c, 0x10,
169 0x2d, 0x19,
170 0x2e, 0x08,
171 0x2f, 0x10,
172 0x30, 0x19,
173 0x34, 0x20,
174 0x35, 0x03,
175 0x45, 0x02,
176 0x46, 0x45,
177 0x47, 0xd0,
178 0x48, 0x00,
179 0x49, 0x40,
180 0x4a, 0x03,
181 0x4c, 0xfd,
182 0x4f, 0x2e,
183 0x50, 0x2e,
184 0x51, 0x10,
185 0x52, 0x10,
186 0x56, 0x92,
187 0x59, 0x00,
188 0x5a, 0x2d,
189 0x5b, 0x33,
190 0x5c, 0x1f,
191 0x5f, 0x76,
192 0x62, 0xc0,
193 0x63, 0xc0,
194 0x64, 0xf3,
195 0x65, 0xf3,
196 0x79, 0x40,
197 0x6a, 0x40,
198 0x6b, 0x0a,
199 0x6c, 0x80,
200 0x6d, 0x27,
201 0x71, 0x06,
202 0x75, 0x60,
203 0x78, 0x00,
204 0x79, 0xb5,
205 0x7c, 0x05,
206 0x7d, 0x1a,
207 0x87, 0x55,
208 0x88, 0x72,
209 0x8f, 0x08,
210 0x90, 0xe0,
211 0x94, 0x40,
212 0xa0, 0x3f,
213 0xa1, 0xc0,
214 0xa4, 0xcc,
215 0xa5, 0x66,
216 0xa6, 0x66,
217 0xa7, 0x7b,
218 0xa8, 0x7b,
219 0xa9, 0x7b,
220 0xaa, 0x9a,
221 0xed, 0x04,
222 0xad, 0x00,
223 0xae, 0x03,
224 0xcc, 0xab,
225 0x01, 0x08,
226 0xff, 0xff
227};
228
229/* low level read/writes */
230static int si21_writeregs(struct si21xx_state *state, u8 reg1,
231 u8 *data, int len)
232{
233 int ret;
234 u8 buf[60];/* = { reg1, data };*/
235 struct i2c_msg msg = {
236 .addr = state->config->demod_address,
237 .flags = 0,
238 .buf = buf,
239 .len = len + 1
240 };
241
242 msg.buf[0] = reg1;
243 memcpy(msg.buf + 1, data, len);
244
245 ret = i2c_transfer(state->i2c, &msg, 1);
246
247 if (ret != 1)
248 dprintk("%s: writereg error (reg1 == 0x%02x, data == 0x%02x, "
249 "ret == %i)\n", __func__, reg1, data[0], ret);
250
251 return (ret != 1) ? -EREMOTEIO : 0;
252}
253
254static int si21_writereg(struct si21xx_state *state, u8 reg, u8 data)
255{
256 int ret;
257 u8 buf[] = { reg, data };
258 struct i2c_msg msg = {
259 .addr = state->config->demod_address,
260 .flags = 0,
261 .buf = buf,
262 .len = 2
263 };
264
265 ret = i2c_transfer(state->i2c, &msg, 1);
266
267 if (ret != 1)
268 dprintk("%s: writereg error (reg == 0x%02x, data == 0x%02x, "
269 "ret == %i)\n", __func__, reg, data, ret);
270
271 return (ret != 1) ? -EREMOTEIO : 0;
272}
273
274static int si21_write(struct dvb_frontend *fe, u8 *buf, int len)
275{
276 struct si21xx_state *state = fe->demodulator_priv;
277
278 if (len != 2)
279 return -EINVAL;
280
281 return si21_writereg(state, buf[0], buf[1]);
282}
283
284static u8 si21_readreg(struct si21xx_state *state, u8 reg)
285{
286 int ret;
287 u8 b0[] = { reg };
288 u8 b1[] = { 0 };
289 struct i2c_msg msg[] = {
290 {
291 .addr = state->config->demod_address,
292 .flags = 0,
293 .buf = b0,
294 .len = 1
295 }, {
296 .addr = state->config->demod_address,
297 .flags = I2C_M_RD,
298 .buf = b1,
299 .len = 1
300 }
301 };
302
303 ret = i2c_transfer(state->i2c, msg, 2);
304
305 if (ret != 2)
306 dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n",
307 __func__, reg, ret);
308
309 return b1[0];
310}
311
312static int si21_readregs(struct si21xx_state *state, u8 reg1, u8 *b, u8 len)
313{
314 int ret;
315 struct i2c_msg msg[] = {
316 {
317 .addr = state->config->demod_address,
318 .flags = 0,
319 .buf = &reg1,
320 .len = 1
321 }, {
322 .addr = state->config->demod_address,
323 .flags = I2C_M_RD,
324 .buf = b,
325 .len = len
326 }
327 };
328
329 ret = i2c_transfer(state->i2c, msg, 2);
330
331 if (ret != 2)
332 dprintk("%s: readreg error (ret == %i)\n", __func__, ret);
333
334 return ret == 2 ? 0 : -1;
335}
336
337static int si21xx_wait_diseqc_idle(struct si21xx_state *state, int timeout)
338{
339 unsigned long start = jiffies;
340
341 dprintk("%s\n", __func__);
342
343 while ((si21_readreg(state, LNB_CTRL_REG_1) & 0x8) == 8) {
344 if (jiffies - start > timeout) {
345 dprintk("%s: timeout!!\n", __func__);
346 return -ETIMEDOUT;
347 }
348 msleep(10);
349 };
350
351 return 0;
352}
353
354static int si21xx_set_symbolrate(struct dvb_frontend *fe, u32 srate)
355{
356 struct si21xx_state *state = fe->demodulator_priv;
357 u32 sym_rate, data_rate;
358 int i;
359 u8 sym_rate_bytes[3];
360
361 dprintk("%s : srate = %i\n", __func__ , srate);
362
363 if ((srate < 1000000) || (srate > 45000000))
364 return -EINVAL;
365
366 data_rate = srate;
367 sym_rate = 0;
368
369 for (i = 0; i < 4; ++i) {
370 sym_rate /= 100;
371 sym_rate = sym_rate + ((data_rate % 100) * 0x800000) /
372 state->fs;
373 data_rate /= 100;
374 }
375 for (i = 0; i < 3; ++i)
376 sym_rate_bytes[i] = (u8)((sym_rate >> (i * 8)) & 0xff);
377
378 si21_writeregs(state, SYM_RATE_REG_L, sym_rate_bytes, 0x03);
379
380 return 0;
381}
382
383static int si21xx_send_diseqc_msg(struct dvb_frontend *fe,
384 struct dvb_diseqc_master_cmd *m)
385{
386 struct si21xx_state *state = fe->demodulator_priv;
387 u8 lnb_status;
388 u8 LNB_CTRL_1;
389 int status;
390
391 dprintk("%s\n", __func__);
392
393 status = PASS;
394 LNB_CTRL_1 = 0;
395
396 status |= si21_readregs(state, LNB_CTRL_STATUS_REG, &lnb_status, 0x01);
397 status |= si21_readregs(state, LNB_CTRL_REG_1, &lnb_status, 0x01);
398
399 /*fill the FIFO*/
400 status |= si21_writeregs(state, LNB_FIFO_REGS_0, m->msg, m->msg_len);
401
402 LNB_CTRL_1 = (lnb_status & 0x70);
403 LNB_CTRL_1 |= m->msg_len;
404
405 LNB_CTRL_1 |= 0x80; /* begin LNB signaling */
406
407 status |= si21_writeregs(state, LNB_CTRL_REG_1, &LNB_CTRL_1, 0x01);
408
409 return status;
410}
411
412static int si21xx_send_diseqc_burst(struct dvb_frontend *fe,
413 fe_sec_mini_cmd_t burst)
414{
415 struct si21xx_state *state = fe->demodulator_priv;
416 u8 val;
417
418 dprintk("%s\n", __func__);
419
420 if (si21xx_wait_diseqc_idle(state, 100) < 0)
421 return -ETIMEDOUT;
422
423 val = (0x80 | si21_readreg(state, 0xc1));
424 if (si21_writereg(state, LNB_CTRL_REG_1,
425 burst == SEC_MINI_A ? (val & ~0x10) : (val | 0x10)))
426 return -EREMOTEIO;
427
428 if (si21xx_wait_diseqc_idle(state, 100) < 0)
429 return -ETIMEDOUT;
430
431 if (si21_writereg(state, LNB_CTRL_REG_1, val))
432 return -EREMOTEIO;
433
434 return 0;
435}
436/* 30.06.2008 */
437static int si21xx_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
438{
439 struct si21xx_state *state = fe->demodulator_priv;
440 u8 val;
441
442 dprintk("%s\n", __func__);
443 val = (0x80 | si21_readreg(state, LNB_CTRL_REG_1));
444
445 switch (tone) {
446 case SEC_TONE_ON:
447 return si21_writereg(state, LNB_CTRL_REG_1, val | 0x20);
448
449 case SEC_TONE_OFF:
450 return si21_writereg(state, LNB_CTRL_REG_1, (val & ~0x20));
451
452 default:
453 return -EINVAL;
454 }
455}
456
457static int si21xx_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t volt)
458{
459 struct si21xx_state *state = fe->demodulator_priv;
460
461 u8 val;
462 dprintk("%s: %s\n", __func__,
463 volt == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" :
464 volt == SEC_VOLTAGE_18 ? "SEC_VOLTAGE_18" : "??");
465
466
467 val = (0x80 | si21_readreg(state, LNB_CTRL_REG_1));
468
469 switch (volt) {
470 case SEC_VOLTAGE_18:
471 return si21_writereg(state, LNB_CTRL_REG_1, val | 0x40);
472 break;
473 case SEC_VOLTAGE_13:
474 return si21_writereg(state, LNB_CTRL_REG_1, (val & ~0x40));
475 break;
476 default:
477 return -EINVAL;
478 };
479}
480
481static int si21xx_init(struct dvb_frontend *fe)
482{
483 struct si21xx_state *state = fe->demodulator_priv;
484 int i;
485 int status = 0;
486 u8 reg1;
487 u8 val;
488 u8 reg2[2];
489
490 dprintk("%s\n", __func__);
491
492 for (i = 0; ; i += 2) {
493 reg1 = serit_sp1511lhb_inittab[i];
494 val = serit_sp1511lhb_inittab[i+1];
495 if (reg1 == 0xff && val == 0xff)
496 break;
497 si21_writeregs(state, reg1, &val, 1);
498 }
499
500 /*DVB QPSK SYSTEM MODE REG*/
501 reg1 = 0x08;
502 si21_writeregs(state, SYSTEM_MODE_REG, &reg1, 0x01);
503
504 /*transport stream config*/
505 /*
506 mode = PARALLEL;
507 sdata_form = LSB_FIRST;
508 clk_edge = FALLING_EDGE;
509 clk_mode = CLK_GAPPED_MODE;
510 strt_len = BYTE_WIDE;
511 sync_pol = ACTIVE_HIGH;
512 val_pol = ACTIVE_HIGH;
513 err_pol = ACTIVE_HIGH;
514 sclk_rate = 0x00;
515 parity = 0x00 ;
516 data_delay = 0x00;
517 clk_delay = 0x00;
518 pclk_smooth = 0x00;
519 */
520 reg2[0] =
521 PARALLEL + (LSB_FIRST << 1)
522 + (FALLING_EDGE << 2) + (CLK_GAPPED_MODE << 3)
523 + (BYTE_WIDE << 4) + (ACTIVE_HIGH << 5)
524 + (ACTIVE_HIGH << 6) + (ACTIVE_HIGH << 7);
525
526 reg2[1] = 0;
527 /* sclk_rate + (parity << 2)
528 + (data_delay << 3) + (clk_delay << 4)
529 + (pclk_smooth << 5);
530 */
531 status |= si21_writeregs(state, TS_CTRL_REG_1, reg2, 0x02);
532 if (status != 0)
533 dprintk(" %s : TS Set Error\n", __func__);
534
535 return 0;
536
537}
538
539static int si21_read_status(struct dvb_frontend *fe, fe_status_t *status)
540{
541 struct si21xx_state *state = fe->demodulator_priv;
542 u8 regs_read[2];
543 u8 reg_read;
544 u8 i;
545 u8 lock;
546 u8 signal = si21_readreg(state, ANALOG_AGC_POWER_LEVEL_REG);
547
548 si21_readregs(state, LOCK_STATUS_REG_1, regs_read, 0x02);
549 reg_read = 0;
550
551 for (i = 0; i < 7; ++i)
552 reg_read |= ((regs_read[0] >> i) & 0x01) << (6 - i);
553
554 lock = ((reg_read & 0x7f) | (regs_read[1] & 0x80));
555
556 dprintk("%s : FE_READ_STATUS : VSTATUS: 0x%02x\n", __func__, lock);
557 *status = 0;
558
559 if (signal > 10)
560 *status |= FE_HAS_SIGNAL;
561
562 if (lock & 0x2)
563 *status |= FE_HAS_CARRIER;
564
565 if (lock & 0x20)
566 *status |= FE_HAS_VITERBI;
567
568 if (lock & 0x40)
569 *status |= FE_HAS_SYNC;
570
571 if ((lock & 0x7b) == 0x7b)
572 *status |= FE_HAS_LOCK;
573
574 return 0;
575}
576
577static int si21_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
578{
579 struct si21xx_state *state = fe->demodulator_priv;
580
581 /*status = si21_readreg(state, ANALOG_AGC_POWER_LEVEL_REG,
582 (u8*)agclevel, 0x01);*/
583
584 u16 signal = (3 * si21_readreg(state, 0x27) *
585 si21_readreg(state, 0x28));
586
587 dprintk("%s : AGCPWR: 0x%02x%02x, signal=0x%04x\n", __func__,
588 si21_readreg(state, 0x27),
589 si21_readreg(state, 0x28), (int) signal);
590
591 signal <<= 4;
592 *strength = signal;
593
594 return 0;
595}
596
597static int si21_read_ber(struct dvb_frontend *fe, u32 *ber)
598{
599 struct si21xx_state *state = fe->demodulator_priv;
600
601 dprintk("%s\n", __func__);
602
603 if (state->errmode != STATUS_BER)
604 return 0;
605
606 *ber = (si21_readreg(state, 0x1d) << 8) |
607 si21_readreg(state, 0x1e);
608
609 return 0;
610}
611
612static int si21_read_snr(struct dvb_frontend *fe, u16 *snr)
613{
614 struct si21xx_state *state = fe->demodulator_priv;
615
616 s32 xsnr = 0xffff - ((si21_readreg(state, 0x24) << 8) |
617 si21_readreg(state, 0x25));
618 xsnr = 3 * (xsnr - 0xa100);
619 *snr = (xsnr > 0xffff) ? 0xffff : (xsnr < 0) ? 0 : xsnr;
620
621 dprintk("%s\n", __func__);
622
623 return 0;
624}
625
626static int si21_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
627{
628 struct si21xx_state *state = fe->demodulator_priv;
629
630 dprintk("%s\n", __func__);
631
632 if (state->errmode != STATUS_UCBLOCKS)
633 *ucblocks = 0;
634 else
635 *ucblocks = (si21_readreg(state, 0x1d) << 8) |
636 si21_readreg(state, 0x1e);
637
638 return 0;
639}
640
641/* initiates a channel acquisition sequence
642 using the specified symbol rate and code rate */
643static int si21xx_setacquire(struct dvb_frontend *fe, int symbrate,
644 fe_code_rate_t crate)
645{
646
647 struct si21xx_state *state = fe->demodulator_priv;
648 u8 coderates[] = {
649 0x0, 0x01, 0x02, 0x04, 0x00,
650 0x8, 0x10, 0x20, 0x00, 0x3f
651 };
652
653 u8 coderate_ptr;
654 int status;
655 u8 start_acq = 0x80;
656 u8 reg, regs[3];
657
658 dprintk("%s\n", __func__);
659
660 status = PASS;
661 coderate_ptr = coderates[crate];
662
663 si21xx_set_symbolrate(fe, symbrate);
664
665 /* write code rates to use in the Viterbi search */
666 status |= si21_writeregs(state,
667 VIT_SRCH_CTRL_REG_1,
668 &coderate_ptr, 0x01);
669
670 /* clear acq_start bit */
671 status |= si21_readregs(state, ACQ_CTRL_REG_2, &reg, 0x01);
672 reg &= ~start_acq;
673 status |= si21_writeregs(state, ACQ_CTRL_REG_2, &reg, 0x01);
674
675 /* use new Carrier Frequency Offset Estimator (QuickLock) */
676 regs[0] = 0xCB;
677 regs[1] = 0x40;
678 regs[2] = 0xCB;
679
680 status |= si21_writeregs(state,
681 TWO_DB_BNDWDTH_THRSHLD_REG,
682 &regs[0], 0x03);
683 reg = 0x56;
684 status |= si21_writeregs(state,
685 LSA_CTRL_REG_1, &reg, 1);
686 reg = 0x05;
687 status |= si21_writeregs(state,
688 BLIND_SCAN_CTRL_REG, &reg, 1);
689 /* start automatic acq */
690 status |= si21_writeregs(state,
691 ACQ_CTRL_REG_2, &start_acq, 0x01);
692
693 return status;
694}
695
696static int si21xx_set_property(struct dvb_frontend *fe, struct dtv_property *p)
697{
698 dprintk("%s(..)\n", __func__);
699 return 0;
700}
701
702static int si21xx_get_property(struct dvb_frontend *fe, struct dtv_property *p)
703{
704 dprintk("%s(..)\n", __func__);
705 return 0;
706}
707
708static int si21xx_set_frontend(struct dvb_frontend *fe,
709 struct dvb_frontend_parameters *dfp)
710{
711 struct si21xx_state *state = fe->demodulator_priv;
712 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
713
714 /* freq Channel carrier frequency in KHz (i.e. 1550000 KHz)
715 datarate Channel symbol rate in Sps (i.e. 22500000 Sps)*/
716
717 /* in MHz */
718 unsigned char coarse_tune_freq;
719 int fine_tune_freq;
720 unsigned char sample_rate = 0;
721 /* boolean */
722 unsigned int inband_interferer_ind;
723
724 /* INTERMEDIATE VALUES */
725 int icoarse_tune_freq; /* MHz */
726 int ifine_tune_freq; /* MHz */
727 unsigned int band_high;
728 unsigned int band_low;
729 unsigned int x1;
730 unsigned int x2;
731 int i;
732 unsigned int inband_interferer_div2[ALLOWABLE_FS_COUNT] = {
733 FALSE, FALSE, FALSE, FALSE, FALSE,
734 FALSE, FALSE, FALSE, FALSE, FALSE
735 };
736 unsigned int inband_interferer_div4[ALLOWABLE_FS_COUNT] = {
737 FALSE, FALSE, FALSE, FALSE, FALSE,
738 FALSE, FALSE, FALSE, FALSE, FALSE
739 };
740
741 int status;
742
743 /* allowable sample rates for ADC in MHz */
744 int afs[ALLOWABLE_FS_COUNT] = { 200, 192, 193, 194, 195,
745 196, 204, 205, 206, 207
746 };
747 /* in MHz */
748 int if_limit_high;
749 int if_limit_low;
750 int lnb_lo;
751 int lnb_uncertanity;
752
753 int rf_freq;
754 int data_rate;
755 unsigned char regs[4];
756
757 dprintk("%s : FE_SET_FRONTEND\n", __func__);
758
759 if (c->delivery_system != SYS_DVBS) {
760 dprintk("%s: unsupported delivery system selected (%d)\n",
761 __func__, c->delivery_system);
762 return -EOPNOTSUPP;
763 }
764
765 for (i = 0; i < ALLOWABLE_FS_COUNT; ++i)
766 inband_interferer_div2[i] = inband_interferer_div4[i] = FALSE;
767
768 if_limit_high = -700000;
769 if_limit_low = -100000;
770 /* in MHz */
771 lnb_lo = 0;
772 lnb_uncertanity = 0;
773
774 rf_freq = 10 * c->frequency ;
775 data_rate = c->symbol_rate / 100;
776
777 status = PASS;
778
779 band_low = (rf_freq - lnb_lo) - ((lnb_uncertanity * 200)
780 + (data_rate * 135)) / 200;
781
782 band_high = (rf_freq - lnb_lo) + ((lnb_uncertanity * 200)
783 + (data_rate * 135)) / 200;
784
785
786 icoarse_tune_freq = 100000 *
787 (((rf_freq - lnb_lo) -
788 (if_limit_low + if_limit_high) / 2)
789 / 100000);
790
791 ifine_tune_freq = (rf_freq - lnb_lo) - icoarse_tune_freq ;
792
793 for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) {
794 x1 = ((rf_freq - lnb_lo) / (afs[i] * 2500)) *
795 (afs[i] * 2500) + afs[i] * 2500;
796
797 x2 = ((rf_freq - lnb_lo) / (afs[i] * 2500)) *
798 (afs[i] * 2500);
799
800 if (((band_low < x1) && (x1 < band_high)) ||
801 ((band_low < x2) && (x2 < band_high)))
802 inband_interferer_div4[i] = TRUE;
803
804 }
805
806 for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) {
807 x1 = ((rf_freq - lnb_lo) / (afs[i] * 5000)) *
808 (afs[i] * 5000) + afs[i] * 5000;
809
810 x2 = ((rf_freq - lnb_lo) / (afs[i] * 5000)) *
811 (afs[i] * 5000);
812
813 if (((band_low < x1) && (x1 < band_high)) ||
814 ((band_low < x2) && (x2 < band_high)))
815 inband_interferer_div2[i] = TRUE;
816 }
817
818 inband_interferer_ind = TRUE;
819 for (i = 0; i < ALLOWABLE_FS_COUNT; ++i)
820 inband_interferer_ind &= inband_interferer_div2[i] |
821 inband_interferer_div4[i];
822
823 if (inband_interferer_ind) {
824 for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) {
825 if (inband_interferer_div2[i] == FALSE) {
826 sample_rate = (u8) afs[i];
827 break;
828 }
829 }
830 } else {
831 for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) {
832 if ((inband_interferer_div2[i] |
833 inband_interferer_div4[i]) == FALSE) {
834 sample_rate = (u8) afs[i];
835 break;
836 }
837 }
838
839 }
840
841 if (sample_rate > 207 || sample_rate < 192)
842 sample_rate = 200;
843
844 fine_tune_freq = ((0x4000 * (ifine_tune_freq / 10)) /
845 ((sample_rate) * 1000));
846
847 coarse_tune_freq = (u8)(icoarse_tune_freq / 100000);
848
849 regs[0] = sample_rate;
850 regs[1] = coarse_tune_freq;
851 regs[2] = fine_tune_freq & 0xFF;
852 regs[3] = fine_tune_freq >> 8 & 0xFF;
853
854 status |= si21_writeregs(state, PLL_DIVISOR_REG, &regs[0], 0x04);
855
856 state->fs = sample_rate;/*ADC MHz*/
857 si21xx_setacquire(fe, c->symbol_rate, c->fec_inner);
858
859 return 0;
860}
861
862static int si21xx_sleep(struct dvb_frontend *fe)
863{
864 struct si21xx_state *state = fe->demodulator_priv;
865 u8 regdata;
866
867 dprintk("%s\n", __func__);
868
869 si21_readregs(state, SYSTEM_MODE_REG, &regdata, 0x01);
870 regdata |= 1 << 6;
871 si21_writeregs(state, SYSTEM_MODE_REG, &regdata, 0x01);
872 state->initialised = 0;
873
874 return 0;
875}
876
877static void si21xx_release(struct dvb_frontend *fe)
878{
879 struct si21xx_state *state = fe->demodulator_priv;
880
881 dprintk("%s\n", __func__);
882
883 kfree(state);
884}
885
886static struct dvb_frontend_ops si21xx_ops = {
887
888 .info = {
889 .name = "SL SI21XX DVB-S",
890 .type = FE_QPSK,
891 .frequency_min = 950000,
892 .frequency_max = 2150000,
893 .frequency_stepsize = 125, /* kHz for QPSK frontends */
894 .frequency_tolerance = 0,
895 .symbol_rate_min = 1000000,
896 .symbol_rate_max = 45000000,
897 .symbol_rate_tolerance = 500, /* ppm */
898 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
899 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |
900 FE_CAN_QPSK |
901 FE_CAN_FEC_AUTO
902 },
903
904 .release = si21xx_release,
905 .init = si21xx_init,
906 .sleep = si21xx_sleep,
907 .write = si21_write,
908 .read_status = si21_read_status,
909 .read_ber = si21_read_ber,
910 .read_signal_strength = si21_read_signal_strength,
911 .read_snr = si21_read_snr,
912 .read_ucblocks = si21_read_ucblocks,
913 .diseqc_send_master_cmd = si21xx_send_diseqc_msg,
914 .diseqc_send_burst = si21xx_send_diseqc_burst,
915 .set_tone = si21xx_set_tone,
916 .set_voltage = si21xx_set_voltage,
917
918 .set_property = si21xx_set_property,
919 .get_property = si21xx_get_property,
920 .set_frontend = si21xx_set_frontend,
921};
922
923struct dvb_frontend *si21xx_attach(const struct si21xx_config *config,
924 struct i2c_adapter *i2c)
925{
926 struct si21xx_state *state = NULL;
927 int id;
928
929 dprintk("%s\n", __func__);
930
931 /* allocate memory for the internal state */
932 state = kmalloc(sizeof(struct si21xx_state), GFP_KERNEL);
933 if (state == NULL)
934 goto error;
935
936 /* setup the state */
937 state->config = config;
938 state->i2c = i2c;
939 state->initialised = 0;
940 state->errmode = STATUS_BER;
941
942 /* check if the demod is there */
943 id = si21_readreg(state, SYSTEM_MODE_REG);
944 si21_writereg(state, SYSTEM_MODE_REG, id | 0x40); /* standby off */
945 msleep(200);
946 id = si21_readreg(state, 0x00);
947
948 /* register 0x00 contains:
949 0x34 for SI2107
950 0x24 for SI2108
951 0x14 for SI2109
952 0x04 for SI2110
953 */
954 if (id != 0x04 && id != 0x14)
955 goto error;
956
957 /* create dvb_frontend */
958 memcpy(&state->frontend.ops, &si21xx_ops,
959 sizeof(struct dvb_frontend_ops));
960 state->frontend.demodulator_priv = state;
961 return &state->frontend;
962
963error:
964 kfree(state);
965 return NULL;
966}
967EXPORT_SYMBOL(si21xx_attach);
968
969module_param(debug, int, 0644);
970MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
971
972MODULE_DESCRIPTION("SL SI21XX DVB Demodulator driver");
973MODULE_AUTHOR("Igor M. Liplianin");
974MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/si21xx.h b/drivers/media/dvb/frontends/si21xx.h
new file mode 100644
index 000000000000..141b5b8a5f63
--- /dev/null
+++ b/drivers/media/dvb/frontends/si21xx.h
@@ -0,0 +1,37 @@
1#ifndef SI21XX_H
2#define SI21XX_H
3
4#include <linux/dvb/frontend.h>
5#include "dvb_frontend.h"
6
7struct si21xx_config {
8 /* the demodulator's i2c address */
9 u8 demod_address;
10
11 /* minimum delay before retuning */
12 int min_delay_ms;
13};
14
15#if defined(CONFIG_DVB_SI21XX) || \
16 (defined(CONFIG_DVB_SI21XX_MODULE) && defined(MODULE))
17extern struct dvb_frontend *si21xx_attach(const struct si21xx_config *config,
18 struct i2c_adapter *i2c);
19#else
20static inline struct dvb_frontend *si21xx_attach(
21 const struct si21xx_config *config, struct i2c_adapter *i2c)
22{
23 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
24 return NULL;
25}
26#endif
27
28static inline int si21xx_writeregister(struct dvb_frontend *fe, u8 reg, u8 val)
29{
30 int r = 0;
31 u8 buf[] = {reg, val};
32 if (fe->ops.write)
33 r = fe->ops.write(fe, buf, 2);
34 return r;
35}
36
37#endif
diff --git a/drivers/media/dvb/frontends/sp887x.c b/drivers/media/dvb/frontends/sp887x.c
index 4543609e1816..559509ab4dab 100644
--- a/drivers/media/dvb/frontends/sp887x.c
+++ b/drivers/media/dvb/frontends/sp887x.c
@@ -337,7 +337,8 @@ static int sp887x_setup_frontend_parameters (struct dvb_frontend* fe,
337 struct dvb_frontend_parameters *p) 337 struct dvb_frontend_parameters *p)
338{ 338{
339 struct sp887x_state* state = fe->demodulator_priv; 339 struct sp887x_state* state = fe->demodulator_priv;
340 int actual_freq, err; 340 unsigned actual_freq;
341 int err;
341 u16 val, reg0xc05; 342 u16 val, reg0xc05;
342 343
343 if (p->u.ofdm.bandwidth != BANDWIDTH_8_MHZ && 344 if (p->u.ofdm.bandwidth != BANDWIDTH_8_MHZ &&
diff --git a/drivers/media/dvb/frontends/stb6000.c b/drivers/media/dvb/frontends/stb6000.c
new file mode 100644
index 000000000000..0e2cb0df1441
--- /dev/null
+++ b/drivers/media/dvb/frontends/stb6000.c
@@ -0,0 +1,255 @@
1 /*
2 Driver for ST STB6000 DVBS Silicon tuner
3
4 Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 */
22
23#include <linux/module.h>
24#include <linux/dvb/frontend.h>
25#include <asm/types.h>
26
27#include "stb6000.h"
28
29static int debug;
30#define dprintk(args...) \
31 do { \
32 if (debug) \
33 printk(KERN_DEBUG "stb6000: " args); \
34 } while (0)
35
36struct stb6000_priv {
37 /* i2c details */
38 int i2c_address;
39 struct i2c_adapter *i2c;
40 u32 frequency;
41};
42
43static int stb6000_release(struct dvb_frontend *fe)
44{
45 kfree(fe->tuner_priv);
46 fe->tuner_priv = NULL;
47 return 0;
48}
49
50static int stb6000_sleep(struct dvb_frontend *fe)
51{
52 struct stb6000_priv *priv = fe->tuner_priv;
53 int ret;
54 u8 buf[] = { 10, 0 };
55 struct i2c_msg msg = {
56 .addr = priv->i2c_address,
57 .flags = 0,
58 .buf = buf,
59 .len = 2
60 };
61
62 dprintk("%s:\n", __func__);
63
64 if (fe->ops.i2c_gate_ctrl)
65 fe->ops.i2c_gate_ctrl(fe, 1);
66
67 ret = i2c_transfer(priv->i2c, &msg, 1);
68 if (ret != 1)
69 dprintk("%s: i2c error\n", __func__);
70
71 if (fe->ops.i2c_gate_ctrl)
72 fe->ops.i2c_gate_ctrl(fe, 0);
73
74 return (ret == 1) ? 0 : ret;
75}
76
77static int stb6000_set_params(struct dvb_frontend *fe,
78 struct dvb_frontend_parameters *params)
79{
80 struct stb6000_priv *priv = fe->tuner_priv;
81 unsigned int n, m;
82 int ret;
83 u32 freq_mhz;
84 int bandwidth;
85 u8 buf[12];
86 struct i2c_msg msg = {
87 .addr = priv->i2c_address,
88 .flags = 0,
89 .buf = buf,
90 .len = 12
91 };
92
93 dprintk("%s:\n", __func__);
94
95 freq_mhz = params->frequency / 1000;
96 bandwidth = params->u.qpsk.symbol_rate / 1000000;
97
98 if (bandwidth > 31)
99 bandwidth = 31;
100
101 if ((freq_mhz > 949) && (freq_mhz < 2151)) {
102 buf[0] = 0x01;
103 buf[1] = 0xac;
104 if (freq_mhz < 1950)
105 buf[1] = 0xaa;
106 if (freq_mhz < 1800)
107 buf[1] = 0xa8;
108 if (freq_mhz < 1650)
109 buf[1] = 0xa6;
110 if (freq_mhz < 1530)
111 buf[1] = 0xa5;
112 if (freq_mhz < 1470)
113 buf[1] = 0xa4;
114 if (freq_mhz < 1370)
115 buf[1] = 0xa2;
116 if (freq_mhz < 1300)
117 buf[1] = 0xa1;
118 if (freq_mhz < 1200)
119 buf[1] = 0xa0;
120 if (freq_mhz < 1075)
121 buf[1] = 0xbc;
122 if (freq_mhz < 1000)
123 buf[1] = 0xba;
124 if (freq_mhz < 1075) {
125 n = freq_mhz / 8; /* vco=lo*4 */
126 m = 2;
127 } else {
128 n = freq_mhz / 16; /* vco=lo*2 */
129 m = 1;
130 }
131 buf[2] = n >> 1;
132 buf[3] = (unsigned char)(((n & 1) << 7) |
133 (m * freq_mhz - n * 16) | 0x60);
134 buf[4] = 0x04;
135 buf[5] = 0x0e;
136
137 buf[6] = (unsigned char)(bandwidth);
138
139 buf[7] = 0xd8;
140 buf[8] = 0xd0;
141 buf[9] = 0x50;
142 buf[10] = 0xeb;
143 buf[11] = 0x4f;
144
145 if (fe->ops.i2c_gate_ctrl)
146 fe->ops.i2c_gate_ctrl(fe, 1);
147
148 ret = i2c_transfer(priv->i2c, &msg, 1);
149 if (ret != 1)
150 dprintk("%s: i2c error\n", __func__);
151
152 udelay(10);
153 if (fe->ops.i2c_gate_ctrl)
154 fe->ops.i2c_gate_ctrl(fe, 0);
155
156 buf[0] = 0x07;
157 buf[1] = 0xdf;
158 buf[2] = 0xd0;
159 buf[3] = 0x50;
160 buf[4] = 0xfb;
161 msg.len = 5;
162
163 if (fe->ops.i2c_gate_ctrl)
164 fe->ops.i2c_gate_ctrl(fe, 1);
165
166 ret = i2c_transfer(priv->i2c, &msg, 1);
167 if (ret != 1)
168 dprintk("%s: i2c error\n", __func__);
169
170 udelay(10);
171 if (fe->ops.i2c_gate_ctrl)
172 fe->ops.i2c_gate_ctrl(fe, 0);
173
174 priv->frequency = freq_mhz * 1000;
175
176 return (ret == 1) ? 0 : ret;
177 }
178 return -1;
179}
180
181static int stb6000_get_frequency(struct dvb_frontend *fe, u32 *frequency)
182{
183 struct stb6000_priv *priv = fe->tuner_priv;
184 *frequency = priv->frequency;
185 return 0;
186}
187
188static struct dvb_tuner_ops stb6000_tuner_ops = {
189 .info = {
190 .name = "ST STB6000",
191 .frequency_min = 950000,
192 .frequency_max = 2150000
193 },
194 .release = stb6000_release,
195 .sleep = stb6000_sleep,
196 .set_params = stb6000_set_params,
197 .get_frequency = stb6000_get_frequency,
198};
199
200struct dvb_frontend *stb6000_attach(struct dvb_frontend *fe, int addr,
201 struct i2c_adapter *i2c)
202{
203 struct stb6000_priv *priv = NULL;
204 u8 b0[] = { 0 };
205 u8 b1[] = { 0, 0 };
206 struct i2c_msg msg[2] = {
207 {
208 .addr = addr,
209 .flags = 0,
210 .buf = b0,
211 .len = 0
212 }, {
213 .addr = addr,
214 .flags = I2C_M_RD,
215 .buf = b1,
216 .len = 2
217 }
218 };
219 int ret;
220
221 dprintk("%s:\n", __func__);
222
223 if (fe->ops.i2c_gate_ctrl)
224 fe->ops.i2c_gate_ctrl(fe, 1);
225
226 /* is some i2c device here ? */
227 ret = i2c_transfer(i2c, msg, 2);
228 if (fe->ops.i2c_gate_ctrl)
229 fe->ops.i2c_gate_ctrl(fe, 0);
230
231 if (ret != 2)
232 return NULL;
233
234 priv = kzalloc(sizeof(struct stb6000_priv), GFP_KERNEL);
235 if (priv == NULL)
236 return NULL;
237
238 priv->i2c_address = addr;
239 priv->i2c = i2c;
240
241 memcpy(&fe->ops.tuner_ops, &stb6000_tuner_ops,
242 sizeof(struct dvb_tuner_ops));
243
244 fe->tuner_priv = priv;
245
246 return fe;
247}
248EXPORT_SYMBOL(stb6000_attach);
249
250module_param(debug, int, 0644);
251MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
252
253MODULE_DESCRIPTION("DVB STB6000 driver");
254MODULE_AUTHOR("Igor M. Liplianin <liplianin@me.by>");
255MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/stb6000.h b/drivers/media/dvb/frontends/stb6000.h
new file mode 100644
index 000000000000..7be479c22d5b
--- /dev/null
+++ b/drivers/media/dvb/frontends/stb6000.h
@@ -0,0 +1,51 @@
1 /*
2 Driver for ST stb6000 DVBS Silicon tuner
3
4 Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 */
22
23#ifndef __DVB_STB6000_H__
24#define __DVB_STB6000_H__
25
26#include <linux/i2c.h>
27#include "dvb_frontend.h"
28
29/**
30 * Attach a stb6000 tuner to the supplied frontend structure.
31 *
32 * @param fe Frontend to attach to.
33 * @param addr i2c address of the tuner.
34 * @param i2c i2c adapter to use.
35 * @return FE pointer on success, NULL on failure.
36 */
37#if defined(CONFIG_DVB_STB6000) || (defined(CONFIG_DVB_STB6000_MODULE) \
38 && defined(MODULE))
39extern struct dvb_frontend *stb6000_attach(struct dvb_frontend *fe, int addr,
40 struct i2c_adapter *i2c);
41#else
42static inline struct dvb_frontend *stb6000_attach(struct dvb_frontend *fe,
43 int addr,
44 struct i2c_adapter *i2c)
45{
46 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
47 return NULL;
48}
49#endif /* CONFIG_DVB_STB6000 */
50
51#endif /* __DVB_STB6000_H__ */
diff --git a/drivers/media/dvb/frontends/stv0288.c b/drivers/media/dvb/frontends/stv0288.c
new file mode 100644
index 000000000000..ff1194de34c0
--- /dev/null
+++ b/drivers/media/dvb/frontends/stv0288.c
@@ -0,0 +1,618 @@
1/*
2 Driver for ST STV0288 demodulator
3 Copyright (C) 2006 Georg Acher, BayCom GmbH, acher (at) baycom (dot) de
4 for Reel Multimedia
5 Copyright (C) 2008 TurboSight.com, Bob Liu <bob@turbosight.com>
6 Copyright (C) 2008 Igor M. Liplianin <liplianin@me.by>
7 Removed stb6000 specific tuner code and revised some
8 procedures.
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
24*/
25
26#include <linux/init.h>
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/string.h>
30#include <linux/slab.h>
31#include <linux/jiffies.h>
32#include <asm/div64.h>
33
34#include "dvb_frontend.h"
35#include "stv0288.h"
36
37struct stv0288_state {
38 struct i2c_adapter *i2c;
39 const struct stv0288_config *config;
40 struct dvb_frontend frontend;
41
42 u8 initialised:1;
43 u32 tuner_frequency;
44 u32 symbol_rate;
45 fe_code_rate_t fec_inner;
46 int errmode;
47};
48
49#define STATUS_BER 0
50#define STATUS_UCBLOCKS 1
51
52static int debug;
53static int debug_legacy_dish_switch;
54#define dprintk(args...) \
55 do { \
56 if (debug) \
57 printk(KERN_DEBUG "stv0288: " args); \
58 } while (0)
59
60
61static int stv0288_writeregI(struct stv0288_state *state, u8 reg, u8 data)
62{
63 int ret;
64 u8 buf[] = { reg, data };
65 struct i2c_msg msg = {
66 .addr = state->config->demod_address,
67 .flags = 0,
68 .buf = buf,
69 .len = 2
70 };
71
72 ret = i2c_transfer(state->i2c, &msg, 1);
73
74 if (ret != 1)
75 dprintk("%s: writereg error (reg == 0x%02x, val == 0x%02x, "
76 "ret == %i)\n", __func__, reg, data, ret);
77
78 return (ret != 1) ? -EREMOTEIO : 0;
79}
80
81static int stv0288_write(struct dvb_frontend *fe, u8 *buf, int len)
82{
83 struct stv0288_state *state = fe->demodulator_priv;
84
85 if (len != 2)
86 return -EINVAL;
87
88 return stv0288_writeregI(state, buf[0], buf[1]);
89}
90
91static u8 stv0288_readreg(struct stv0288_state *state, u8 reg)
92{
93 int ret;
94 u8 b0[] = { reg };
95 u8 b1[] = { 0 };
96 struct i2c_msg msg[] = {
97 {
98 .addr = state->config->demod_address,
99 .flags = 0,
100 .buf = b0,
101 .len = 1
102 }, {
103 .addr = state->config->demod_address,
104 .flags = I2C_M_RD,
105 .buf = b1,
106 .len = 1
107 }
108 };
109
110 ret = i2c_transfer(state->i2c, msg, 2);
111
112 if (ret != 2)
113 dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n",
114 __func__, reg, ret);
115
116 return b1[0];
117}
118
119static int stv0288_set_symbolrate(struct dvb_frontend *fe, u32 srate)
120{
121 struct stv0288_state *state = fe->demodulator_priv;
122 unsigned int temp;
123 unsigned char b[3];
124
125 if ((srate < 1000000) || (srate > 45000000))
126 return -EINVAL;
127
128 temp = (unsigned int)srate / 1000;
129
130 temp = temp * 32768;
131 temp = temp / 25;
132 temp = temp / 125;
133 b[0] = (unsigned char)((temp >> 12) & 0xff);
134 b[1] = (unsigned char)((temp >> 4) & 0xff);
135 b[2] = (unsigned char)((temp << 4) & 0xf0);
136 stv0288_writeregI(state, 0x28, 0x80); /* SFRH */
137 stv0288_writeregI(state, 0x29, 0); /* SFRM */
138 stv0288_writeregI(state, 0x2a, 0); /* SFRL */
139
140 stv0288_writeregI(state, 0x28, b[0]);
141 stv0288_writeregI(state, 0x29, b[1]);
142 stv0288_writeregI(state, 0x2a, b[2]);
143 dprintk("stv0288: stv0288_set_symbolrate\n");
144
145 return 0;
146}
147
148static int stv0288_send_diseqc_msg(struct dvb_frontend *fe,
149 struct dvb_diseqc_master_cmd *m)
150{
151 struct stv0288_state *state = fe->demodulator_priv;
152
153 int i;
154
155 dprintk("%s\n", __func__);
156
157 stv0288_writeregI(state, 0x09, 0);
158 msleep(30);
159 stv0288_writeregI(state, 0x05, 0x16);
160
161 for (i = 0; i < m->msg_len; i++) {
162 if (stv0288_writeregI(state, 0x06, m->msg[i]))
163 return -EREMOTEIO;
164 msleep(12);
165 }
166
167 return 0;
168}
169
170static int stv0288_send_diseqc_burst(struct dvb_frontend *fe,
171 fe_sec_mini_cmd_t burst)
172{
173 struct stv0288_state *state = fe->demodulator_priv;
174
175 dprintk("%s\n", __func__);
176
177 if (stv0288_writeregI(state, 0x05, 0x16))/* burst mode */
178 return -EREMOTEIO;
179
180 if (stv0288_writeregI(state, 0x06, burst == SEC_MINI_A ? 0x00 : 0xff))
181 return -EREMOTEIO;
182
183 if (stv0288_writeregI(state, 0x06, 0x12))
184 return -EREMOTEIO;
185
186 return 0;
187}
188
189static int stv0288_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
190{
191 struct stv0288_state *state = fe->demodulator_priv;
192
193 switch (tone) {
194 case SEC_TONE_ON:
195 if (stv0288_writeregI(state, 0x05, 0x10))/* burst mode */
196 return -EREMOTEIO;
197 return stv0288_writeregI(state, 0x06, 0xff);
198
199 case SEC_TONE_OFF:
200 if (stv0288_writeregI(state, 0x05, 0x13))/* burst mode */
201 return -EREMOTEIO;
202 return stv0288_writeregI(state, 0x06, 0x00);
203
204 default:
205 return -EINVAL;
206 }
207}
208
209static u8 stv0288_inittab[] = {
210 0x01, 0x15,
211 0x02, 0x20,
212 0x09, 0x0,
213 0x0a, 0x4,
214 0x0b, 0x0,
215 0x0c, 0x0,
216 0x0d, 0x0,
217 0x0e, 0xd4,
218 0x0f, 0x30,
219 0x11, 0x80,
220 0x12, 0x03,
221 0x13, 0x48,
222 0x14, 0x84,
223 0x15, 0x45,
224 0x16, 0xb7,
225 0x17, 0x9c,
226 0x18, 0x0,
227 0x19, 0xa6,
228 0x1a, 0x88,
229 0x1b, 0x8f,
230 0x1c, 0xf0,
231 0x20, 0x0b,
232 0x21, 0x54,
233 0x22, 0x0,
234 0x23, 0x0,
235 0x2b, 0xff,
236 0x2c, 0xf7,
237 0x30, 0x0,
238 0x31, 0x1e,
239 0x32, 0x14,
240 0x33, 0x0f,
241 0x34, 0x09,
242 0x35, 0x0c,
243 0x36, 0x05,
244 0x37, 0x2f,
245 0x38, 0x16,
246 0x39, 0xbe,
247 0x3a, 0x0,
248 0x3b, 0x13,
249 0x3c, 0x11,
250 0x3d, 0x30,
251 0x40, 0x63,
252 0x41, 0x04,
253 0x42, 0x60,
254 0x43, 0x00,
255 0x44, 0x00,
256 0x45, 0x00,
257 0x46, 0x00,
258 0x47, 0x00,
259 0x4a, 0x00,
260 0x50, 0x10,
261 0x51, 0x38,
262 0x52, 0x21,
263 0x58, 0x54,
264 0x59, 0x86,
265 0x5a, 0x0,
266 0x5b, 0x9b,
267 0x5c, 0x08,
268 0x5d, 0x7f,
269 0x5e, 0x0,
270 0x5f, 0xff,
271 0x70, 0x0,
272 0x71, 0x0,
273 0x72, 0x0,
274 0x74, 0x0,
275 0x75, 0x0,
276 0x76, 0x0,
277 0x81, 0x0,
278 0x82, 0x3f,
279 0x83, 0x3f,
280 0x84, 0x0,
281 0x85, 0x0,
282 0x88, 0x0,
283 0x89, 0x0,
284 0x8a, 0x0,
285 0x8b, 0x0,
286 0x8c, 0x0,
287 0x90, 0x0,
288 0x91, 0x0,
289 0x92, 0x0,
290 0x93, 0x0,
291 0x94, 0x1c,
292 0x97, 0x0,
293 0xa0, 0x48,
294 0xa1, 0x0,
295 0xb0, 0xb8,
296 0xb1, 0x3a,
297 0xb2, 0x10,
298 0xb3, 0x82,
299 0xb4, 0x80,
300 0xb5, 0x82,
301 0xb6, 0x82,
302 0xb7, 0x82,
303 0xb8, 0x20,
304 0xb9, 0x0,
305 0xf0, 0x0,
306 0xf1, 0x0,
307 0xf2, 0xc0,
308 0x51, 0x36,
309 0x52, 0x09,
310 0x53, 0x94,
311 0x54, 0x62,
312 0x55, 0x29,
313 0x56, 0x64,
314 0x57, 0x2b,
315 0xff, 0xff,
316};
317
318static int stv0288_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t volt)
319{
320 dprintk("%s: %s\n", __func__,
321 volt == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" :
322 volt == SEC_VOLTAGE_18 ? "SEC_VOLTAGE_18" : "??");
323
324 return 0;
325}
326
327static int stv0288_init(struct dvb_frontend *fe)
328{
329 struct stv0288_state *state = fe->demodulator_priv;
330 int i;
331 u8 reg;
332 u8 val;
333
334 dprintk("stv0288: init chip\n");
335 stv0288_writeregI(state, 0x41, 0x04);
336 msleep(50);
337
338 /* we have default inittab */
339 if (state->config->inittab == NULL) {
340 for (i = 0; !(stv0288_inittab[i] == 0xff &&
341 stv0288_inittab[i + 1] == 0xff); i += 2)
342 stv0288_writeregI(state, stv0288_inittab[i],
343 stv0288_inittab[i + 1]);
344 } else {
345 for (i = 0; ; i += 2) {
346 reg = state->config->inittab[i];
347 val = state->config->inittab[i+1];
348 if (reg == 0xff && val == 0xff)
349 break;
350 stv0288_writeregI(state, reg, val);
351 }
352 }
353 return 0;
354}
355
356static int stv0288_read_status(struct dvb_frontend *fe, fe_status_t *status)
357{
358 struct stv0288_state *state = fe->demodulator_priv;
359
360 u8 sync = stv0288_readreg(state, 0x24);
361 if (sync == 255)
362 sync = 0;
363
364 dprintk("%s : FE_READ_STATUS : VSTATUS: 0x%02x\n", __func__, sync);
365
366 *status = 0;
367
368 if ((sync & 0x08) == 0x08) {
369 *status |= FE_HAS_LOCK;
370 dprintk("stv0288 has locked\n");
371 }
372
373 return 0;
374}
375
376static int stv0288_read_ber(struct dvb_frontend *fe, u32 *ber)
377{
378 struct stv0288_state *state = fe->demodulator_priv;
379
380 if (state->errmode != STATUS_BER)
381 return 0;
382 *ber = (stv0288_readreg(state, 0x26) << 8) |
383 stv0288_readreg(state, 0x27);
384 dprintk("stv0288_read_ber %d\n", *ber);
385
386 return 0;
387}
388
389
390static int stv0288_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
391{
392 struct stv0288_state *state = fe->demodulator_priv;
393
394 s32 signal = 0xffff - ((stv0288_readreg(state, 0x10) << 8));
395
396
397 signal = signal * 5 / 4;
398 *strength = (signal > 0xffff) ? 0xffff : (signal < 0) ? 0 : signal;
399 dprintk("stv0288_read_signal_strength %d\n", *strength);
400
401 return 0;
402}
403static int stv0288_sleep(struct dvb_frontend *fe)
404{
405 struct stv0288_state *state = fe->demodulator_priv;
406
407 stv0288_writeregI(state, 0x41, 0x84);
408 state->initialised = 0;
409
410 return 0;
411}
412static int stv0288_read_snr(struct dvb_frontend *fe, u16 *snr)
413{
414 struct stv0288_state *state = fe->demodulator_priv;
415
416 s32 xsnr = 0xffff - ((stv0288_readreg(state, 0x2d) << 8)
417 | stv0288_readreg(state, 0x2e));
418 xsnr = 3 * (xsnr - 0xa100);
419 *snr = (xsnr > 0xffff) ? 0xffff : (xsnr < 0) ? 0 : xsnr;
420 dprintk("stv0288_read_snr %d\n", *snr);
421
422 return 0;
423}
424
425static int stv0288_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
426{
427 struct stv0288_state *state = fe->demodulator_priv;
428
429 if (state->errmode != STATUS_BER)
430 return 0;
431 *ucblocks = (stv0288_readreg(state, 0x26) << 8) |
432 stv0288_readreg(state, 0x27);
433 dprintk("stv0288_read_ber %d\n", *ucblocks);
434
435 return 0;
436}
437
438static int stv0288_set_property(struct dvb_frontend *fe, struct dtv_property *p)
439{
440 dprintk("%s(..)\n", __func__);
441 return 0;
442}
443
444static int stv0288_get_property(struct dvb_frontend *fe, struct dtv_property *p)
445{
446 dprintk("%s(..)\n", __func__);
447 return 0;
448}
449
450static int stv0288_set_frontend(struct dvb_frontend *fe,
451 struct dvb_frontend_parameters *dfp)
452{
453 struct stv0288_state *state = fe->demodulator_priv;
454 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
455
456 char tm;
457 unsigned char tda[3];
458
459 dprintk("%s : FE_SET_FRONTEND\n", __func__);
460
461 if (c->delivery_system != SYS_DVBS) {
462 dprintk("%s: unsupported delivery "
463 "system selected (%d)\n",
464 __func__, c->delivery_system);
465 return -EOPNOTSUPP;
466 }
467
468 if (state->config->set_ts_params)
469 state->config->set_ts_params(fe, 0);
470
471 /* only frequency & symbol_rate are used for tuner*/
472 dfp->frequency = c->frequency;
473 dfp->u.qpsk.symbol_rate = c->symbol_rate;
474 if (fe->ops.tuner_ops.set_params) {
475 fe->ops.tuner_ops.set_params(fe, dfp);
476 if (fe->ops.i2c_gate_ctrl)
477 fe->ops.i2c_gate_ctrl(fe, 0);
478 }
479
480 udelay(10);
481 stv0288_set_symbolrate(fe, c->symbol_rate);
482 /* Carrier lock control register */
483 stv0288_writeregI(state, 0x15, 0xc5);
484
485 tda[0] = 0x2b; /* CFRM */
486 tda[2] = 0x0; /* CFRL */
487 for (tm = -6; tm < 7;) {
488 /* Viterbi status */
489 if (stv0288_readreg(state, 0x24) & 0x80)
490 break;
491
492 tda[2] += 40;
493 if (tda[2] < 40)
494 tm++;
495 tda[1] = (unsigned char)tm;
496 stv0288_writeregI(state, 0x2b, tda[1]);
497 stv0288_writeregI(state, 0x2c, tda[2]);
498 udelay(30);
499 }
500
501 state->tuner_frequency = c->frequency;
502 state->fec_inner = FEC_AUTO;
503 state->symbol_rate = c->symbol_rate;
504
505 return 0;
506}
507
508static int stv0288_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
509{
510 struct stv0288_state *state = fe->demodulator_priv;
511
512 if (enable)
513 stv0288_writeregI(state, 0x01, 0xb5);
514 else
515 stv0288_writeregI(state, 0x01, 0x35);
516
517 udelay(1);
518
519 return 0;
520}
521
522static void stv0288_release(struct dvb_frontend *fe)
523{
524 struct stv0288_state *state = fe->demodulator_priv;
525 kfree(state);
526}
527
528static struct dvb_frontend_ops stv0288_ops = {
529
530 .info = {
531 .name = "ST STV0288 DVB-S",
532 .type = FE_QPSK,
533 .frequency_min = 950000,
534 .frequency_max = 2150000,
535 .frequency_stepsize = 1000, /* kHz for QPSK frontends */
536 .frequency_tolerance = 0,
537 .symbol_rate_min = 1000000,
538 .symbol_rate_max = 45000000,
539 .symbol_rate_tolerance = 500, /* ppm */
540 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
541 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |
542 FE_CAN_QPSK |
543 FE_CAN_FEC_AUTO
544 },
545
546 .release = stv0288_release,
547 .init = stv0288_init,
548 .sleep = stv0288_sleep,
549 .write = stv0288_write,
550 .i2c_gate_ctrl = stv0288_i2c_gate_ctrl,
551 .read_status = stv0288_read_status,
552 .read_ber = stv0288_read_ber,
553 .read_signal_strength = stv0288_read_signal_strength,
554 .read_snr = stv0288_read_snr,
555 .read_ucblocks = stv0288_read_ucblocks,
556 .diseqc_send_master_cmd = stv0288_send_diseqc_msg,
557 .diseqc_send_burst = stv0288_send_diseqc_burst,
558 .set_tone = stv0288_set_tone,
559 .set_voltage = stv0288_set_voltage,
560
561 .set_property = stv0288_set_property,
562 .get_property = stv0288_get_property,
563 .set_frontend = stv0288_set_frontend,
564};
565
566struct dvb_frontend *stv0288_attach(const struct stv0288_config *config,
567 struct i2c_adapter *i2c)
568{
569 struct stv0288_state *state = NULL;
570 int id;
571
572 /* allocate memory for the internal state */
573 state = kmalloc(sizeof(struct stv0288_state), GFP_KERNEL);
574 if (state == NULL)
575 goto error;
576
577 /* setup the state */
578 state->config = config;
579 state->i2c = i2c;
580 state->initialised = 0;
581 state->tuner_frequency = 0;
582 state->symbol_rate = 0;
583 state->fec_inner = 0;
584 state->errmode = STATUS_BER;
585
586 stv0288_writeregI(state, 0x41, 0x04);
587 msleep(200);
588 id = stv0288_readreg(state, 0x00);
589 dprintk("stv0288 id %x\n", id);
590
591 /* register 0x00 contains 0x11 for STV0288 */
592 if (id != 0x11)
593 goto error;
594
595 /* create dvb_frontend */
596 memcpy(&state->frontend.ops, &stv0288_ops,
597 sizeof(struct dvb_frontend_ops));
598 state->frontend.demodulator_priv = state;
599 return &state->frontend;
600
601error:
602 kfree(state);
603
604 return NULL;
605}
606EXPORT_SYMBOL(stv0288_attach);
607
608module_param(debug_legacy_dish_switch, int, 0444);
609MODULE_PARM_DESC(debug_legacy_dish_switch,
610 "Enable timing analysis for Dish Network legacy switches");
611
612module_param(debug, int, 0644);
613MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
614
615MODULE_DESCRIPTION("ST STV0288 DVB Demodulator driver");
616MODULE_AUTHOR("Georg Acher, Bob Liu, Igor liplianin");
617MODULE_LICENSE("GPL");
618
diff --git a/drivers/media/dvb/frontends/stv0288.h b/drivers/media/dvb/frontends/stv0288.h
new file mode 100644
index 000000000000..f2b53db0606d
--- /dev/null
+++ b/drivers/media/dvb/frontends/stv0288.h
@@ -0,0 +1,67 @@
1/*
2 Driver for ST STV0288 demodulator
3
4 Copyright (C) 2006 Georg Acher, BayCom GmbH, acher (at) baycom (dot) de
5 for Reel Multimedia
6 Copyright (C) 2008 TurboSight.com, <bob@turbosight.com>
7 Copyright (C) 2008 Igor M. Liplianin <liplianin@me.by>
8 Removed stb6000 specific tuner code and revised some
9 procedures.
10
11 This program is free software; you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation; either version 2 of the License, or
14 (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
25*/
26
27#ifndef STV0288_H
28#define STV0288_H
29
30#include <linux/dvb/frontend.h>
31#include "dvb_frontend.h"
32
33struct stv0288_config {
34 /* the demodulator's i2c address */
35 u8 demod_address;
36
37 u8* inittab;
38
39 /* minimum delay before retuning */
40 int min_delay_ms;
41
42 int (*set_ts_params)(struct dvb_frontend *fe, int is_punctured);
43};
44
45#if defined(CONFIG_DVB_STV0288) || (defined(CONFIG_DVB_STV0288_MODULE) && \
46 defined(MODULE))
47extern struct dvb_frontend *stv0288_attach(const struct stv0288_config *config,
48 struct i2c_adapter *i2c);
49#else
50static inline struct dvb_frontend *stv0288_attach(const struct stv0288_config *config,
51 struct i2c_adapter *i2c)
52{
53 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
54 return NULL;
55}
56#endif /* CONFIG_DVB_STV0288 */
57
58static inline int stv0288_writereg(struct dvb_frontend *fe, u8 reg, u8 val)
59{
60 int r = 0;
61 u8 buf[] = { reg, val };
62 if (fe->ops.write)
63 r = fe->ops.write(fe, buf, 2);
64 return r;
65}
66
67#endif /* STV0288_H */
diff --git a/drivers/media/dvb/frontends/stv0299.c b/drivers/media/dvb/frontends/stv0299.c
index 35435bef8e79..6c1cb1973c6e 100644
--- a/drivers/media/dvb/frontends/stv0299.c
+++ b/drivers/media/dvb/frontends/stv0299.c
@@ -559,6 +559,8 @@ static int stv0299_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
559 int invval = 0; 559 int invval = 0;
560 560
561 dprintk ("%s : FE_SET_FRONTEND\n", __func__); 561 dprintk ("%s : FE_SET_FRONTEND\n", __func__);
562 if (state->config->set_ts_params)
563 state->config->set_ts_params(fe, 0);
562 564
563 // set the inversion 565 // set the inversion
564 if (p->inversion == INVERSION_OFF) invval = 0; 566 if (p->inversion == INVERSION_OFF) invval = 0;
diff --git a/drivers/media/dvb/frontends/stv0299.h b/drivers/media/dvb/frontends/stv0299.h
index 3282f43022f5..0fd96e22b650 100644
--- a/drivers/media/dvb/frontends/stv0299.h
+++ b/drivers/media/dvb/frontends/stv0299.h
@@ -89,15 +89,18 @@ struct stv0299_config
89 int min_delay_ms; 89 int min_delay_ms;
90 90
91 /* Set the symbol rate */ 91 /* Set the symbol rate */
92 int (*set_symbol_rate)(struct dvb_frontend* fe, u32 srate, u32 ratio); 92 int (*set_symbol_rate)(struct dvb_frontend *fe, u32 srate, u32 ratio);
93
94 /* Set device param to start dma */
95 int (*set_ts_params)(struct dvb_frontend *fe, int is_punctured);
93}; 96};
94 97
95#if defined(CONFIG_DVB_STV0299) || (defined(CONFIG_DVB_STV0299_MODULE) && defined(MODULE)) 98#if defined(CONFIG_DVB_STV0299) || (defined(CONFIG_DVB_STV0299_MODULE) && defined(MODULE))
96extern struct dvb_frontend* stv0299_attach(const struct stv0299_config* config, 99extern struct dvb_frontend *stv0299_attach(const struct stv0299_config *config,
97 struct i2c_adapter* i2c); 100 struct i2c_adapter *i2c);
98#else 101#else
99static inline struct dvb_frontend* stv0299_attach(const struct stv0299_config* config, 102static inline struct dvb_frontend *stv0299_attach(const struct stv0299_config *config,
100 struct i2c_adapter* i2c) 103 struct i2c_adapter *i2c)
101{ 104{
102 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__); 105 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
103 return NULL; 106 return NULL;
diff --git a/drivers/media/dvb/frontends/tdhd1.h b/drivers/media/dvb/frontends/tdhd1.h
new file mode 100644
index 000000000000..51f170678650
--- /dev/null
+++ b/drivers/media/dvb/frontends/tdhd1.h
@@ -0,0 +1,73 @@
1/*
2 * tdhd1.h - ALPS TDHD1-204A tuner support
3 *
4 * Copyright (C) 2008 Oliver Endriss <o.endriss@gmx.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
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
21 *
22 *
23 * The project's page is at http://www.linuxtv.org
24 */
25
26#ifndef TDHD1_H
27#define TDHD1_H
28
29#include "tda1004x.h"
30
31static int alps_tdhd1_204_request_firmware(struct dvb_frontend *fe, const struct firmware **fw, char *name);
32
33static struct tda1004x_config alps_tdhd1_204a_config = {
34 .demod_address = 0x8,
35 .invert = 1,
36 .invert_oclk = 0,
37 .xtal_freq = TDA10046_XTAL_4M,
38 .agc_config = TDA10046_AGC_DEFAULT,
39 .if_freq = TDA10046_FREQ_3617,
40 .request_firmware = alps_tdhd1_204_request_firmware
41};
42
43static int alps_tdhd1_204a_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
44{
45 struct i2c_adapter *i2c = fe->tuner_priv;
46 u8 data[4];
47 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
48 u32 div;
49
50 div = (params->frequency + 36166666) / 166666;
51
52 data[0] = (div >> 8) & 0x7f;
53 data[1] = div & 0xff;
54 data[2] = 0x85;
55
56 if (params->frequency >= 174000000 && params->frequency <= 230000000)
57 data[3] = 0x02;
58 else if (params->frequency >= 470000000 && params->frequency <= 823000000)
59 data[3] = 0x0C;
60 else if (params->frequency > 823000000 && params->frequency <= 862000000)
61 data[3] = 0x8C;
62 else
63 return -EINVAL;
64
65 if (fe->ops.i2c_gate_ctrl)
66 fe->ops.i2c_gate_ctrl(fe, 1);
67 if (i2c_transfer(i2c, &msg, 1) != 1)
68 return -EIO;
69
70 return 0;
71}
72
73#endif /* TDHD1_H */
diff --git a/drivers/media/dvb/ttpci/Kconfig b/drivers/media/dvb/ttpci/Kconfig
index 41b5a988b619..867027ceab3e 100644
--- a/drivers/media/dvb/ttpci/Kconfig
+++ b/drivers/media/dvb/ttpci/Kconfig
@@ -86,6 +86,7 @@ config DVB_BUDGET
86 select DVB_TDA10086 if !DVB_FE_CUSTOMISE 86 select DVB_TDA10086 if !DVB_FE_CUSTOMISE
87 select DVB_TDA826X if !DVB_FE_CUSTOMISE 87 select DVB_TDA826X if !DVB_FE_CUSTOMISE
88 select DVB_LNBP21 if !DVB_FE_CUSTOMISE 88 select DVB_LNBP21 if !DVB_FE_CUSTOMISE
89 select DVB_TDA1004X if !DVB_FE_CUSTOMISE
89 help 90 help
90 Support for simple SAA7146 based DVB cards (so called Budget- 91 Support for simple SAA7146 based DVB cards (so called Budget-
91 or Nova-PCI cards) without onboard MPEG2 decoder, and without 92 or Nova-PCI cards) without onboard MPEG2 decoder, and without
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index 0777e8f9544b..c7c770c28988 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -88,6 +88,7 @@ static int budgetpatch;
88static int wss_cfg_4_3 = 0x4008; 88static int wss_cfg_4_3 = 0x4008;
89static int wss_cfg_16_9 = 0x0007; 89static int wss_cfg_16_9 = 0x0007;
90static int tv_standard; 90static int tv_standard;
91static int full_ts;
91 92
92module_param_named(debug, av7110_debug, int, 0644); 93module_param_named(debug, av7110_debug, int, 0644);
93MODULE_PARM_DESC(debug, "debug level (bitmask, default 0)"); 94MODULE_PARM_DESC(debug, "debug level (bitmask, default 0)");
@@ -106,6 +107,8 @@ module_param(volume, int, 0444);
106MODULE_PARM_DESC(volume, "initial volume: default 255 (range 0-255)"); 107MODULE_PARM_DESC(volume, "initial volume: default 255 (range 0-255)");
107module_param(budgetpatch, int, 0444); 108module_param(budgetpatch, int, 0444);
108MODULE_PARM_DESC(budgetpatch, "use budget-patch hardware modification: default 0 (0 no, 1 autodetect, 2 always)"); 109MODULE_PARM_DESC(budgetpatch, "use budget-patch hardware modification: default 0 (0 no, 1 autodetect, 2 always)");
110module_param(full_ts, int, 0444);
111MODULE_PARM_DESC(full_ts, "enable code for full-ts hardware modification: 0 disable (default), 1 enable");
109module_param(wss_cfg_4_3, int, 0444); 112module_param(wss_cfg_4_3, int, 0444);
110MODULE_PARM_DESC(wss_cfg_4_3, "WSS 4:3 - default 0x4008 - bit 15: disable, 14: burst mode, 13..0: wss data"); 113MODULE_PARM_DESC(wss_cfg_4_3, "WSS 4:3 - default 0x4008 - bit 15: disable, 14: burst mode, 13..0: wss data");
111module_param(wss_cfg_16_9, int, 0444); 114module_param(wss_cfg_16_9, int, 0444);
@@ -116,6 +119,8 @@ MODULE_PARM_DESC(tv_standard, "TV standard: 0 PAL (default), 1 NTSC");
116DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 119DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
117 120
118static void restart_feeds(struct av7110 *av7110); 121static void restart_feeds(struct av7110 *av7110);
122static int budget_start_feed(struct dvb_demux_feed *feed);
123static int budget_stop_feed(struct dvb_demux_feed *feed);
119 124
120static int av7110_num; 125static int av7110_num;
121 126
@@ -376,9 +381,9 @@ static inline void start_debi_dma(struct av7110 *av7110, int dir,
376 irdebi(av7110, DEBISWAB, addr, 0, len); 381 irdebi(av7110, DEBISWAB, addr, 0, len);
377} 382}
378 383
379static void debiirq(unsigned long data) 384static void debiirq(unsigned long cookie)
380{ 385{
381 struct av7110 *av7110 = (struct av7110 *) data; 386 struct av7110 *av7110 = (struct av7110 *)cookie;
382 int type = av7110->debitype; 387 int type = av7110->debitype;
383 int handle = (type >> 8) & 0x1f; 388 int handle = (type >> 8) & 0x1f;
384 unsigned int xfer = 0; 389 unsigned int xfer = 0;
@@ -487,9 +492,9 @@ debi_done:
487} 492}
488 493
489/* irq from av7110 firmware writing the mailbox register in the DPRAM */ 494/* irq from av7110 firmware writing the mailbox register in the DPRAM */
490static void gpioirq(unsigned long data) 495static void gpioirq(unsigned long cookie)
491{ 496{
492 struct av7110 *av7110 = (struct av7110 *) data; 497 struct av7110 *av7110 = (struct av7110 *)cookie;
493 u32 rxbuf, txbuf; 498 u32 rxbuf, txbuf;
494 int len; 499 int len;
495 500
@@ -806,6 +811,9 @@ static int StartHWFilter(struct dvb_demux_filter *dvbdmxfilter)
806 811
807 dprintk(4, "%p\n", av7110); 812 dprintk(4, "%p\n", av7110);
808 813
814 if (av7110->full_ts)
815 return 0;
816
809 if (dvbdmxfilter->type == DMX_TYPE_SEC) { 817 if (dvbdmxfilter->type == DMX_TYPE_SEC) {
810 if (hw_sections) { 818 if (hw_sections) {
811 buf[4] = (dvbdmxfilter->filter.filter_value[0] << 8) | 819 buf[4] = (dvbdmxfilter->filter.filter_value[0] << 8) |
@@ -854,6 +862,9 @@ static int StopHWFilter(struct dvb_demux_filter *dvbdmxfilter)
854 862
855 dprintk(4, "%p\n", av7110); 863 dprintk(4, "%p\n", av7110);
856 864
865 if (av7110->full_ts)
866 return 0;
867
857 handle = dvbdmxfilter->hw_handle; 868 handle = dvbdmxfilter->hw_handle;
858 if (handle >= 32) { 869 if (handle >= 32) {
859 printk("%s tried to stop invalid filter %04x, filter type = %x\n", 870 printk("%s tried to stop invalid filter %04x, filter type = %x\n",
@@ -913,7 +924,7 @@ static int dvb_feed_start_pid(struct dvb_demux_feed *dvbdmxfeed)
913 return ret; 924 return ret;
914 } 925 }
915 926
916 if ((dvbdmxfeed->ts_type & TS_PACKET)) { 927 if ((dvbdmxfeed->ts_type & TS_PACKET) && !av7110->full_ts) {
917 if (dvbdmxfeed->pes_type == 0 && !(dvbdmx->pids[0] & 0x8000)) 928 if (dvbdmxfeed->pes_type == 0 && !(dvbdmx->pids[0] & 0x8000))
918 ret = av7110_av_start_record(av7110, RP_AUDIO, dvbdmxfeed); 929 ret = av7110_av_start_record(av7110, RP_AUDIO, dvbdmxfeed);
919 if (dvbdmxfeed->pes_type == 1 && !(dvbdmx->pids[1] & 0x8000)) 930 if (dvbdmxfeed->pes_type == 1 && !(dvbdmx->pids[1] & 0x8000))
@@ -974,7 +985,7 @@ static int av7110_start_feed(struct dvb_demux_feed *feed)
974 if (!demux->dmx.frontend) 985 if (!demux->dmx.frontend)
975 return -EINVAL; 986 return -EINVAL;
976 987
977 if (feed->pid > 0x1fff) 988 if (!av7110->full_ts && feed->pid > 0x1fff)
978 return -EINVAL; 989 return -EINVAL;
979 990
980 if (feed->type == DMX_TYPE_TS) { 991 if (feed->type == DMX_TYPE_TS) {
@@ -1003,7 +1014,12 @@ static int av7110_start_feed(struct dvb_demux_feed *feed)
1003 } 1014 }
1004 } 1015 }
1005 1016
1006 else if (feed->type == DMX_TYPE_SEC) { 1017 if (av7110->full_ts) {
1018 budget_start_feed(feed);
1019 return ret;
1020 }
1021
1022 if (feed->type == DMX_TYPE_SEC) {
1007 int i; 1023 int i;
1008 1024
1009 for (i = 0; i < demux->filternum; i++) { 1025 for (i = 0; i < demux->filternum; i++) {
@@ -1050,7 +1066,12 @@ static int av7110_stop_feed(struct dvb_demux_feed *feed)
1050 ret = StopHWFilter(feed->filter); 1066 ret = StopHWFilter(feed->filter);
1051 } 1067 }
1052 1068
1053 if (!ret && feed->type == DMX_TYPE_SEC) { 1069 if (av7110->full_ts) {
1070 budget_stop_feed(feed);
1071 return ret;
1072 }
1073
1074 if (feed->type == DMX_TYPE_SEC) {
1054 for (i = 0; i<demux->filternum; i++) { 1075 for (i = 0; i<demux->filternum; i++) {
1055 if (demux->filter[i].state == DMX_STATE_GO && 1076 if (demux->filter[i].state == DMX_STATE_GO &&
1056 demux->filter[i].filter.parent == &feed->feed.sec) { 1077 demux->filter[i].filter.parent == &feed->feed.sec) {
@@ -1074,6 +1095,7 @@ static void restart_feeds(struct av7110 *av7110)
1074 struct dvb_demux *dvbdmx = &av7110->demux; 1095 struct dvb_demux *dvbdmx = &av7110->demux;
1075 struct dvb_demux_feed *feed; 1096 struct dvb_demux_feed *feed;
1076 int mode; 1097 int mode;
1098 int feeding;
1077 int i, j; 1099 int i, j;
1078 1100
1079 dprintk(4, "%p\n", av7110); 1101 dprintk(4, "%p\n", av7110);
@@ -1082,6 +1104,8 @@ static void restart_feeds(struct av7110 *av7110)
1082 av7110->playing = 0; 1104 av7110->playing = 0;
1083 av7110->rec_mode = 0; 1105 av7110->rec_mode = 0;
1084 1106
1107 feeding = av7110->feeding1; /* full_ts mod */
1108
1085 for (i = 0; i < dvbdmx->feednum; i++) { 1109 for (i = 0; i < dvbdmx->feednum; i++) {
1086 feed = &dvbdmx->feed[i]; 1110 feed = &dvbdmx->feed[i];
1087 if (feed->state == DMX_STATE_GO) { 1111 if (feed->state == DMX_STATE_GO) {
@@ -1099,6 +1123,8 @@ static void restart_feeds(struct av7110 *av7110)
1099 } 1123 }
1100 } 1124 }
1101 1125
1126 av7110->feeding1 = feeding; /* full_ts mod */
1127
1102 if (mode) 1128 if (mode)
1103 av7110_av_start_play(av7110, mode); 1129 av7110_av_start_play(av7110, mode);
1104} 1130}
@@ -1197,8 +1223,9 @@ static int start_ts_capture(struct av7110 *budget)
1197 1223
1198 if (budget->feeding1) 1224 if (budget->feeding1)
1199 return ++budget->feeding1; 1225 return ++budget->feeding1;
1200 memset(budget->grabbing, 0x00, TS_HEIGHT * TS_WIDTH); 1226 memset(budget->grabbing, 0x00, TS_BUFLEN);
1201 budget->ttbp = 0; 1227 budget->ttbp = 0;
1228 SAA7146_ISR_CLEAR(budget->dev, MASK_10); /* VPE */
1202 SAA7146_IER_ENABLE(budget->dev, MASK_10); /* VPE */ 1229 SAA7146_IER_ENABLE(budget->dev, MASK_10); /* VPE */
1203 saa7146_write(budget->dev, MC1, (MASK_04 | MASK_20)); /* DMA3 on */ 1230 saa7146_write(budget->dev, MC1, (MASK_04 | MASK_20)); /* DMA3 on */
1204 return ++budget->feeding1; 1231 return ++budget->feeding1;
@@ -1233,18 +1260,14 @@ static int budget_stop_feed(struct dvb_demux_feed *feed)
1233 return status; 1260 return status;
1234} 1261}
1235 1262
1236static void vpeirq(unsigned long data) 1263static void vpeirq(unsigned long cookie)
1237{ 1264{
1238 struct av7110 *budget = (struct av7110 *) data; 1265 struct av7110 *budget = (struct av7110 *)cookie;
1239 u8 *mem = (u8 *) (budget->grabbing); 1266 u8 *mem = (u8 *) (budget->grabbing);
1240 u32 olddma = budget->ttbp; 1267 u32 olddma = budget->ttbp;
1241 u32 newdma = saa7146_read(budget->dev, PCI_VDP3); 1268 u32 newdma = saa7146_read(budget->dev, PCI_VDP3);
1269 struct dvb_demux *demux = budget->full_ts ? &budget->demux : &budget->demux1;
1242 1270
1243 if (!budgetpatch) {
1244 printk("av7110.c: vpeirq() called while budgetpatch disabled!"
1245 " check saa7146 IER register\n");
1246 BUG();
1247 }
1248 /* nearest lower position divisible by 188 */ 1271 /* nearest lower position divisible by 188 */
1249 newdma -= newdma % 188; 1272 newdma -= newdma % 188;
1250 1273
@@ -1268,11 +1291,11 @@ static void vpeirq(unsigned long data)
1268 1291
1269 if (newdma > olddma) 1292 if (newdma > olddma)
1270 /* no wraparound, dump olddma..newdma */ 1293 /* no wraparound, dump olddma..newdma */
1271 dvb_dmx_swfilter_packets(&budget->demux1, mem + olddma, (newdma - olddma) / 188); 1294 dvb_dmx_swfilter_packets(demux, mem + olddma, (newdma - olddma) / 188);
1272 else { 1295 else {
1273 /* wraparound, dump olddma..buflen and 0..newdma */ 1296 /* wraparound, dump olddma..buflen and 0..newdma */
1274 dvb_dmx_swfilter_packets(&budget->demux1, mem + olddma, (TS_BUFLEN - olddma) / 188); 1297 dvb_dmx_swfilter_packets(demux, mem + olddma, (TS_BUFLEN - olddma) / 188);
1275 dvb_dmx_swfilter_packets(&budget->demux1, mem, newdma / 188); 1298 dvb_dmx_swfilter_packets(demux, mem, newdma / 188);
1276 } 1299 }
1277} 1300}
1278 1301
@@ -1294,8 +1317,8 @@ static int av7110_register(struct av7110 *av7110)
1294 for (i = 0; i < 32; i++) 1317 for (i = 0; i < 32; i++)
1295 av7110->handle2filter[i] = NULL; 1318 av7110->handle2filter[i] = NULL;
1296 1319
1297 dvbdemux->filternum = 32; 1320 dvbdemux->filternum = (av7110->full_ts) ? 256 : 32;
1298 dvbdemux->feednum = 32; 1321 dvbdemux->feednum = (av7110->full_ts) ? 256 : 32;
1299 dvbdemux->start_feed = av7110_start_feed; 1322 dvbdemux->start_feed = av7110_start_feed;
1300 dvbdemux->stop_feed = av7110_stop_feed; 1323 dvbdemux->stop_feed = av7110_stop_feed;
1301 dvbdemux->write_to_decoder = av7110_write_to_decoder; 1324 dvbdemux->write_to_decoder = av7110_write_to_decoder;
@@ -1305,7 +1328,7 @@ static int av7110_register(struct av7110 *av7110)
1305 dvb_dmx_init(&av7110->demux); 1328 dvb_dmx_init(&av7110->demux);
1306 av7110->demux.dmx.get_stc = dvb_get_stc; 1329 av7110->demux.dmx.get_stc = dvb_get_stc;
1307 1330
1308 av7110->dmxdev.filternum = 32; 1331 av7110->dmxdev.filternum = (av7110->full_ts) ? 256 : 32;
1309 av7110->dmxdev.demux = &dvbdemux->dmx; 1332 av7110->dmxdev.demux = &dvbdemux->dmx;
1310 av7110->dmxdev.capabilities = 0; 1333 av7110->dmxdev.capabilities = 0;
1311 1334
@@ -1422,7 +1445,6 @@ int i2c_writereg(struct av7110 *av7110, u8 id, u8 reg, u8 val)
1422 return i2c_transfer(&av7110->i2c_adap, &msgs, 1); 1445 return i2c_transfer(&av7110->i2c_adap, &msgs, 1);
1423} 1446}
1424 1447
1425#if 0
1426u8 i2c_readreg(struct av7110 *av7110, u8 id, u8 reg) 1448u8 i2c_readreg(struct av7110 *av7110, u8 id, u8 reg)
1427{ 1449{
1428 u8 mm1[] = {0x00}; 1450 u8 mm1[] = {0x00};
@@ -1439,7 +1461,6 @@ u8 i2c_readreg(struct av7110 *av7110, u8 id, u8 reg)
1439 1461
1440 return mm2[0]; 1462 return mm2[0];
1441} 1463}
1442#endif
1443 1464
1444/**************************************************************************** 1465/****************************************************************************
1445 * INITIALIZATION 1466 * INITIALIZATION
@@ -2256,7 +2277,7 @@ static int frontend_init(struct av7110 *av7110)
2256 if (!av7110->fe) { 2277 if (!av7110->fe) {
2257 /* FIXME: propagate the failure code from the lower layers */ 2278 /* FIXME: propagate the failure code from the lower layers */
2258 ret = -ENOMEM; 2279 ret = -ENOMEM;
2259 printk("dvb-ttpci: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n", 2280 printk("dvb-ttpci: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
2260 av7110->dev->pci->vendor, 2281 av7110->dev->pci->vendor,
2261 av7110->dev->pci->device, 2282 av7110->dev->pci->device,
2262 av7110->dev->pci->subsystem_vendor, 2283 av7110->dev->pci->subsystem_vendor,
@@ -2484,7 +2505,47 @@ static int __devinit av7110_attach(struct saa7146_dev* dev,
2484 av7110->dvb_adapter.proposed_mac); 2505 av7110->dvb_adapter.proposed_mac);
2485 ret = -ENOMEM; 2506 ret = -ENOMEM;
2486 2507
2487 if (budgetpatch) { 2508 /* full-ts mod? */
2509 if (full_ts)
2510 av7110->full_ts = true;
2511
2512 /* check for full-ts flag in eeprom */
2513 if (i2c_readreg(av7110, 0xaa, 0) == 0x4f && i2c_readreg(av7110, 0xaa, 1) == 0x45) {
2514 u8 flags = i2c_readreg(av7110, 0xaa, 2);
2515 if (flags != 0xff && (flags & 0x01))
2516 av7110->full_ts = true;
2517 }
2518
2519 if (av7110->full_ts) {
2520 printk(KERN_INFO "dvb-ttpci: full-ts mode enabled for saa7146 port B\n");
2521 spin_lock_init(&av7110->feedlock1);
2522 av7110->grabbing = saa7146_vmalloc_build_pgtable(pdev, length,
2523 &av7110->pt);
2524 if (!av7110->grabbing)
2525 goto err_i2c_del_3;
2526
2527 saa7146_write(dev, DD1_STREAM_B, 0x00000000);
2528 saa7146_write(dev, MC2, (MASK_10 | MASK_26));
2529
2530 saa7146_write(dev, DD1_INIT, 0x00000600);
2531 saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
2532
2533 saa7146_write(dev, BRS_CTRL, 0x60000000);
2534 saa7146_write(dev, MC2, MASK_08 | MASK_24);
2535
2536 /* dma3 */
2537 saa7146_write(dev, PCI_BT_V1, 0x001c0000 | (saa7146_read(dev, PCI_BT_V1) & ~0x001f0000));
2538 saa7146_write(dev, BASE_ODD3, 0);
2539 saa7146_write(dev, BASE_EVEN3, 0);
2540 saa7146_write(dev, PROT_ADDR3, TS_WIDTH * TS_HEIGHT);
2541 saa7146_write(dev, PITCH3, TS_WIDTH);
2542 saa7146_write(dev, BASE_PAGE3, av7110->pt.dma | ME1 | 0x90);
2543 saa7146_write(dev, NUM_LINE_BYTE3, (TS_HEIGHT << 16) | TS_WIDTH);
2544 saa7146_write(dev, MC2, MASK_04 | MASK_20);
2545
2546 tasklet_init(&av7110->vpe_tasklet, vpeirq, (unsigned long) av7110);
2547
2548 } else if (budgetpatch) {
2488 spin_lock_init(&av7110->feedlock1); 2549 spin_lock_init(&av7110->feedlock1);
2489 av7110->grabbing = saa7146_vmalloc_build_pgtable(pdev, length, 2550 av7110->grabbing = saa7146_vmalloc_build_pgtable(pdev, length,
2490 &av7110->pt); 2551 &av7110->pt);
@@ -2710,11 +2771,13 @@ static int __devexit av7110_detach(struct saa7146_dev* saa)
2710#if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE) 2771#if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE)
2711 av7110_ir_exit(av7110); 2772 av7110_ir_exit(av7110);
2712#endif 2773#endif
2713 if (budgetpatch) { 2774 if (budgetpatch || av7110->full_ts) {
2714 /* Disable RPS1 */ 2775 if (budgetpatch) {
2715 saa7146_write(saa, MC1, MASK_29); 2776 /* Disable RPS1 */
2716 /* VSYNC LOW (inactive) */ 2777 saa7146_write(saa, MC1, MASK_29);
2717 saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTLO); 2778 /* VSYNC LOW (inactive) */
2779 saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTLO);
2780 }
2718 saa7146_write(saa, MC1, MASK_20); /* DMA3 off */ 2781 saa7146_write(saa, MC1, MASK_20); /* DMA3 off */
2719 SAA7146_IER_DISABLE(saa, MASK_10); 2782 SAA7146_IER_DISABLE(saa, MASK_10);
2720 SAA7146_ISR_CLEAR(saa, MASK_10); 2783 SAA7146_ISR_CLEAR(saa, MASK_10);
@@ -2794,7 +2857,7 @@ static void av7110_irq(struct saa7146_dev* dev, u32 *isr)
2794 tasklet_schedule(&av7110->gpio_tasklet); 2857 tasklet_schedule(&av7110->gpio_tasklet);
2795 } 2858 }
2796 2859
2797 if ((*isr & MASK_10) && budgetpatch) 2860 if (*isr & MASK_10)
2798 tasklet_schedule(&av7110->vpe_tasklet); 2861 tasklet_schedule(&av7110->vpe_tasklet);
2799} 2862}
2800 2863
diff --git a/drivers/media/dvb/ttpci/av7110.h b/drivers/media/dvb/ttpci/av7110.h
index 55f23ddcb994..d85b8512ac30 100644
--- a/drivers/media/dvb/ttpci/av7110.h
+++ b/drivers/media/dvb/ttpci/av7110.h
@@ -192,6 +192,7 @@ struct av7110 {
192 unsigned char *grabbing; 192 unsigned char *grabbing;
193 struct saa7146_pgtable pt; 193 struct saa7146_pgtable pt;
194 struct tasklet_struct vpe_tasklet; 194 struct tasklet_struct vpe_tasklet;
195 bool full_ts;
195 196
196 int fe_synced; 197 int fe_synced;
197 struct mutex pid_mutex; 198 struct mutex pid_mutex;
diff --git a/drivers/media/dvb/ttpci/av7110_av.c b/drivers/media/dvb/ttpci/av7110_av.c
index 184647ad1c7c..bdc62acf2099 100644
--- a/drivers/media/dvb/ttpci/av7110_av.c
+++ b/drivers/media/dvb/ttpci/av7110_av.c
@@ -788,6 +788,9 @@ int av7110_write_to_decoder(struct dvb_demux_feed *feed, const u8 *buf, size_t l
788 788
789 dprintk(2, "av7110:%p, \n", av7110); 789 dprintk(2, "av7110:%p, \n", av7110);
790 790
791 if (av7110->full_ts && demux->dmx.frontend->source != DMX_MEMORY_FE)
792 return 0;
793
791 switch (feed->pes_type) { 794 switch (feed->pes_type) {
792 case 0: 795 case 0:
793 if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY) 796 if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY)
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
index b7d1f2f18d3a..1032ea77837e 100644
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ b/drivers/media/dvb/ttpci/budget-av.c
@@ -57,6 +57,8 @@
57#define SLOTSTATUS_READY 8 57#define SLOTSTATUS_READY 8
58#define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY) 58#define SLOTSTATUS_OCCUPIED (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
59 59
60DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
61
60struct budget_av { 62struct budget_av {
61 struct budget budget; 63 struct budget budget;
62 struct video_device *vd; 64 struct video_device *vd;
@@ -1049,7 +1051,7 @@ static void frontend_init(struct budget_av *budget_av)
1049 1051
1050 if (fe == NULL) { 1052 if (fe == NULL) {
1051 printk(KERN_ERR "budget-av: A frontend driver was not found " 1053 printk(KERN_ERR "budget-av: A frontend driver was not found "
1052 "for device %04x/%04x subsystem %04x/%04x\n", 1054 "for device [%04x:%04x] subsystem [%04x:%04x]\n",
1053 saa->pci->vendor, 1055 saa->pci->vendor,
1054 saa->pci->device, 1056 saa->pci->device,
1055 saa->pci->subsystem_vendor, 1057 saa->pci->subsystem_vendor,
@@ -1127,7 +1129,9 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
1127 1129
1128 dev->ext_priv = budget_av; 1130 dev->ext_priv = budget_av;
1129 1131
1130 if ((err = ttpci_budget_init(&budget_av->budget, dev, info, THIS_MODULE))) { 1132 err = ttpci_budget_init(&budget_av->budget, dev, info, THIS_MODULE,
1133 adapter_nr);
1134 if (err) {
1131 kfree(budget_av); 1135 kfree(budget_av);
1132 return err; 1136 return err;
1133 } 1137 }
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
index 060e7c785326..0a5aad45435d 100644
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ b/drivers/media/dvb/ttpci/budget-ci.c
@@ -92,6 +92,8 @@ static int ir_debug;
92module_param(ir_debug, int, 0644); 92module_param(ir_debug, int, 0644);
93MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding"); 93MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding");
94 94
95DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
96
95struct budget_ci_ir { 97struct budget_ci_ir {
96 struct input_dev *dev; 98 struct input_dev *dev;
97 struct tasklet_struct msp430_irq_tasklet; 99 struct tasklet_struct msp430_irq_tasklet;
@@ -1153,7 +1155,7 @@ static void frontend_init(struct budget_ci *budget_ci)
1153 } 1155 }
1154 1156
1155 if (budget_ci->budget.dvb_frontend == NULL) { 1157 if (budget_ci->budget.dvb_frontend == NULL) {
1156 printk("budget-ci: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n", 1158 printk("budget-ci: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
1157 budget_ci->budget.dev->pci->vendor, 1159 budget_ci->budget.dev->pci->vendor,
1158 budget_ci->budget.dev->pci->device, 1160 budget_ci->budget.dev->pci->device,
1159 budget_ci->budget.dev->pci->subsystem_vendor, 1161 budget_ci->budget.dev->pci->subsystem_vendor,
@@ -1183,7 +1185,8 @@ static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
1183 1185
1184 dev->ext_priv = budget_ci; 1186 dev->ext_priv = budget_ci;
1185 1187
1186 err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE); 1188 err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE,
1189 adapter_nr);
1187 if (err) 1190 if (err)
1188 goto out2; 1191 goto out2;
1189 1192
diff --git a/drivers/media/dvb/ttpci/budget-core.c b/drivers/media/dvb/ttpci/budget-core.c
index 6f4ddb643fee..ba18e56d5f11 100644
--- a/drivers/media/dvb/ttpci/budget-core.c
+++ b/drivers/media/dvb/ttpci/budget-core.c
@@ -57,8 +57,6 @@ module_param_named(bufsize, dma_buffer_size, int, 0444);
57MODULE_PARM_DESC(debug, "Turn on/off budget debugging (default:off)."); 57MODULE_PARM_DESC(debug, "Turn on/off budget debugging (default:off).");
58MODULE_PARM_DESC(bufsize, "DMA buffer size in KB, default: 188, min: 188, max: 1410 (Activy: 564)"); 58MODULE_PARM_DESC(bufsize, "DMA buffer size in KB, default: 188, min: 188, max: 1410 (Activy: 564)");
59 59
60DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
61
62/**************************************************************************** 60/****************************************************************************
63 * TT budget / WinTV Nova 61 * TT budget / WinTV Nova
64 ****************************************************************************/ 62 ****************************************************************************/
@@ -411,7 +409,7 @@ static void budget_unregister(struct budget *budget)
411 409
412int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev, 410int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
413 struct saa7146_pci_extension_data *info, 411 struct saa7146_pci_extension_data *info,
414 struct module *owner) 412 struct module *owner, short *adapter_nums)
415{ 413{
416 int ret = 0; 414 int ret = 0;
417 struct budget_info *bi = info->ext_priv; 415 struct budget_info *bi = info->ext_priv;
@@ -474,7 +472,7 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
474 printk("%s: dma buffer size %u\n", budget->dev->name, budget->buffer_size); 472 printk("%s: dma buffer size %u\n", budget->dev->name, budget->buffer_size);
475 473
476 ret = dvb_register_adapter(&budget->dvb_adapter, budget->card->name, 474 ret = dvb_register_adapter(&budget->dvb_adapter, budget->card->name,
477 owner, &budget->dev->pci->dev, adapter_nr); 475 owner, &budget->dev->pci->dev, adapter_nums);
478 if (ret < 0) 476 if (ret < 0)
479 return ret; 477 return ret;
480 478
diff --git a/drivers/media/dvb/ttpci/budget-patch.c b/drivers/media/dvb/ttpci/budget-patch.c
index aa5ed4ef19f2..60136688a9a4 100644
--- a/drivers/media/dvb/ttpci/budget-patch.c
+++ b/drivers/media/dvb/ttpci/budget-patch.c
@@ -39,6 +39,8 @@
39 39
40#include "bsru6.h" 40#include "bsru6.h"
41 41
42DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
43
42#define budget_patch budget 44#define budget_patch budget
43 45
44static struct saa7146_extension budget_extension; 46static struct saa7146_extension budget_extension;
@@ -360,7 +362,7 @@ static void frontend_init(struct budget_patch* budget)
360 } 362 }
361 363
362 if (budget->dvb_frontend == NULL) { 364 if (budget->dvb_frontend == NULL) {
363 printk("dvb-ttpci: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n", 365 printk("dvb-ttpci: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
364 budget->dev->pci->vendor, 366 budget->dev->pci->vendor,
365 budget->dev->pci->device, 367 budget->dev->pci->device,
366 budget->dev->pci->subsystem_vendor, 368 budget->dev->pci->subsystem_vendor,
@@ -592,8 +594,9 @@ static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_exte
592 594
593 dprintk(2, "budget: %p\n", budget); 595 dprintk(2, "budget: %p\n", budget);
594 596
595 if ((err = ttpci_budget_init (budget, dev, info, THIS_MODULE))) { 597 err = ttpci_budget_init(budget, dev, info, THIS_MODULE, adapter_nr);
596 kfree (budget); 598 if (err) {
599 kfree(budget);
597 return err; 600 return err;
598 } 601 }
599 602
diff --git a/drivers/media/dvb/ttpci/budget.c b/drivers/media/dvb/ttpci/budget.c
index f0068996ac07..1638e1d9f538 100644
--- a/drivers/media/dvb/ttpci/budget.c
+++ b/drivers/media/dvb/ttpci/budget.c
@@ -46,11 +46,14 @@
46#include "lnbp21.h" 46#include "lnbp21.h"
47#include "bsru6.h" 47#include "bsru6.h"
48#include "bsbe1.h" 48#include "bsbe1.h"
49#include "tdhd1.h"
49 50
50static int diseqc_method; 51static int diseqc_method;
51module_param(diseqc_method, int, 0444); 52module_param(diseqc_method, int, 0444);
52MODULE_PARM_DESC(diseqc_method, "Select DiSEqC method for subsystem id 13c2:1003, 0: default, 1: more reliable (for newer revisions only)"); 53MODULE_PARM_DESC(diseqc_method, "Select DiSEqC method for subsystem id 13c2:1003, 0: default, 1: more reliable (for newer revisions only)");
53 54
55DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
56
54static void Set22K (struct budget *budget, int state) 57static void Set22K (struct budget *budget, int state)
55{ 58{
56 struct saa7146_dev *dev=budget->dev; 59 struct saa7146_dev *dev=budget->dev;
@@ -390,6 +393,13 @@ static struct stv0299_config alps_bsbe1_config_activy = {
390 .set_symbol_rate = alps_bsbe1_set_symbol_rate, 393 .set_symbol_rate = alps_bsbe1_set_symbol_rate,
391}; 394};
392 395
396static int alps_tdhd1_204_request_firmware(struct dvb_frontend *fe, const struct firmware **fw, char *name)
397{
398 struct budget *budget = (struct budget *)fe->dvb->priv;
399
400 return request_firmware(fw, name, &budget->dev->pci->dev);
401}
402
393 403
394static int i2c_readreg(struct i2c_adapter *i2c, u8 adr, u8 reg) 404static int i2c_readreg(struct i2c_adapter *i2c, u8 adr, u8 reg)
395{ 405{
@@ -511,6 +521,14 @@ static void frontend_init(struct budget *budget)
511 } 521 }
512 break; 522 break;
513 523
524 case 0x5f60: /* Fujitsu Siemens Activy Budget-T PCI rev AL (tda10046/ALPS TDHD1-204A) */
525 budget->dvb_frontend = dvb_attach(tda10046_attach, &alps_tdhd1_204a_config, &budget->i2c_adap);
526 if (budget->dvb_frontend) {
527 budget->dvb_frontend->ops.tuner_ops.set_params = alps_tdhd1_204a_tuner_set_params;
528 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
529 }
530 break;
531
514 case 0x5f61: /* Fujitsu Siemens Activy Budget-T PCI rev GR (L64781/Grundig 29504-401(tsa5060)) */ 532 case 0x5f61: /* Fujitsu Siemens Activy Budget-T PCI rev GR (L64781/Grundig 29504-401(tsa5060)) */
515 budget->dvb_frontend = dvb_attach(l64781_attach, &grundig_29504_401_config_activy, &budget->i2c_adap); 533 budget->dvb_frontend = dvb_attach(l64781_attach, &grundig_29504_401_config_activy, &budget->i2c_adap);
516 if (budget->dvb_frontend) { 534 if (budget->dvb_frontend) {
@@ -550,7 +568,7 @@ static void frontend_init(struct budget *budget)
550 } 568 }
551 569
552 if (budget->dvb_frontend == NULL) { 570 if (budget->dvb_frontend == NULL) {
553 printk("budget: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n", 571 printk("budget: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
554 budget->dev->pci->vendor, 572 budget->dev->pci->vendor,
555 budget->dev->pci->device, 573 budget->dev->pci->device,
556 budget->dev->pci->subsystem_vendor, 574 budget->dev->pci->subsystem_vendor,
@@ -582,7 +600,8 @@ static int budget_attach (struct saa7146_dev* dev, struct saa7146_pci_extension_
582 600
583 dev->ext_priv = budget; 601 dev->ext_priv = budget;
584 602
585 if ((err = ttpci_budget_init (budget, dev, info, THIS_MODULE))) { 603 err = ttpci_budget_init(budget, dev, info, THIS_MODULE, adapter_nr);
604 if (err) {
586 printk("==> failed\n"); 605 printk("==> failed\n");
587 kfree (budget); 606 kfree (budget);
588 return err; 607 return err;
@@ -624,6 +643,7 @@ MAKE_BUDGET_INFO(ttbs1401, "TT-Budget-S-1401 PCI", BUDGET_TT);
624MAKE_BUDGET_INFO(fsacs0, "Fujitsu Siemens Activy Budget-S PCI (rev GR/grundig frontend)", BUDGET_FS_ACTIVY); 643MAKE_BUDGET_INFO(fsacs0, "Fujitsu Siemens Activy Budget-S PCI (rev GR/grundig frontend)", BUDGET_FS_ACTIVY);
625MAKE_BUDGET_INFO(fsacs1, "Fujitsu Siemens Activy Budget-S PCI (rev AL/alps frontend)", BUDGET_FS_ACTIVY); 644MAKE_BUDGET_INFO(fsacs1, "Fujitsu Siemens Activy Budget-S PCI (rev AL/alps frontend)", BUDGET_FS_ACTIVY);
626MAKE_BUDGET_INFO(fsact, "Fujitsu Siemens Activy Budget-T PCI (rev GR/Grundig frontend)", BUDGET_FS_ACTIVY); 645MAKE_BUDGET_INFO(fsact, "Fujitsu Siemens Activy Budget-T PCI (rev GR/Grundig frontend)", BUDGET_FS_ACTIVY);
646MAKE_BUDGET_INFO(fsact1, "Fujitsu Siemens Activy Budget-T PCI (rev AL/ALPS TDHD1-204A)", BUDGET_FS_ACTIVY);
627 647
628static struct pci_device_id pci_tbl[] = { 648static struct pci_device_id pci_tbl[] = {
629 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1003), 649 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1003),
@@ -634,6 +654,7 @@ static struct pci_device_id pci_tbl[] = {
634 MAKE_EXTENSION_PCI(ttbs1401, 0x13c2, 0x1018), 654 MAKE_EXTENSION_PCI(ttbs1401, 0x13c2, 0x1018),
635 MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60), 655 MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60),
636 MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61), 656 MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61),
657 MAKE_EXTENSION_PCI(fsact1, 0x1131, 0x5f60),
637 MAKE_EXTENSION_PCI(fsact, 0x1131, 0x5f61), 658 MAKE_EXTENSION_PCI(fsact, 0x1131, 0x5f61),
638 { 659 {
639 .vendor = 0, 660 .vendor = 0,
diff --git a/drivers/media/dvb/ttpci/budget.h b/drivers/media/dvb/ttpci/budget.h
index dd450b739bff..86435bf16260 100644
--- a/drivers/media/dvb/ttpci/budget.h
+++ b/drivers/media/dvb/ttpci/budget.h
@@ -109,7 +109,7 @@ static struct saa7146_pci_extension_data x_var = { \
109 109
110extern int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev, 110extern int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
111 struct saa7146_pci_extension_data *info, 111 struct saa7146_pci_extension_data *info,
112 struct module *owner); 112 struct module *owner, short *adapter_nums);
113extern void ttpci_budget_init_hooks(struct budget *budget); 113extern void ttpci_budget_init_hooks(struct budget *budget);
114extern int ttpci_budget_deinit(struct budget *budget); 114extern int ttpci_budget_deinit(struct budget *budget);
115extern void ttpci_budget_irq10_handler(struct saa7146_dev *dev, u32 * isr); 115extern void ttpci_budget_irq10_handler(struct saa7146_dev *dev, u32 * isr);
diff --git a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
index e6c9cd2e3b94..66ab0c6e9783 100644
--- a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
@@ -1614,7 +1614,7 @@ static void frontend_init(struct ttusb* ttusb)
1614 } 1614 }
1615 1615
1616 if (ttusb->fe == NULL) { 1616 if (ttusb->fe == NULL) {
1617 printk("dvb-ttusb-budget: A frontend driver was not found for device %04x/%04x\n", 1617 printk("dvb-ttusb-budget: A frontend driver was not found for device [%04x:%04x]\n",
1618 le16_to_cpu(ttusb->dev->descriptor.idVendor), 1618 le16_to_cpu(ttusb->dev->descriptor.idVendor),
1619 le16_to_cpu(ttusb->dev->descriptor.idProduct)); 1619 le16_to_cpu(ttusb->dev->descriptor.idProduct));
1620 } else { 1620 } else {
diff --git a/drivers/media/dvb/ttusb-dec/ttusb_dec.c b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
index de5829b863fd..ab33fec8a19f 100644
--- a/drivers/media/dvb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
@@ -1665,7 +1665,7 @@ static int ttusb_dec_probe(struct usb_interface *intf,
1665 } 1665 }
1666 1666
1667 if (dec->fe == NULL) { 1667 if (dec->fe == NULL) {
1668 printk("dvb-ttusb-dec: A frontend driver was not found for device %04x/%04x\n", 1668 printk("dvb-ttusb-dec: A frontend driver was not found for device [%04x:%04x]\n",
1669 le16_to_cpu(dec->udev->descriptor.idVendor), 1669 le16_to_cpu(dec->udev->descriptor.idVendor),
1670 le16_to_cpu(dec->udev->descriptor.idProduct)); 1670 le16_to_cpu(dec->udev->descriptor.idProduct));
1671 } else { 1671 } else {
diff --git a/drivers/media/dvb/ttusb-dec/ttusbdecfe.c b/drivers/media/dvb/ttusb-dec/ttusbdecfe.c
index 443af24097f3..21260aad1e54 100644
--- a/drivers/media/dvb/ttusb-dec/ttusbdecfe.c
+++ b/drivers/media/dvb/ttusb-dec/ttusbdecfe.c
@@ -38,7 +38,17 @@ struct ttusbdecfe_state {
38}; 38};
39 39
40 40
41static int ttusbdecfe_read_status(struct dvb_frontend* fe, fe_status_t* status) 41static int ttusbdecfe_dvbs_read_status(struct dvb_frontend *fe,
42 fe_status_t *status)
43{
44 *status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
45 FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
46 return 0;
47}
48
49
50static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
51 fe_status_t *status)
42{ 52{
43 struct ttusbdecfe_state* state = fe->demodulator_priv; 53 struct ttusbdecfe_state* state = fe->demodulator_priv;
44 u8 b[] = { 0x00, 0x00, 0x00, 0x00, 54 u8 b[] = { 0x00, 0x00, 0x00, 0x00,
@@ -251,7 +261,7 @@ static struct dvb_frontend_ops ttusbdecfe_dvbt_ops = {
251 261
252 .get_tune_settings = ttusbdecfe_dvbt_get_tune_settings, 262 .get_tune_settings = ttusbdecfe_dvbt_get_tune_settings,
253 263
254 .read_status = ttusbdecfe_read_status, 264 .read_status = ttusbdecfe_dvbt_read_status,
255}; 265};
256 266
257static struct dvb_frontend_ops ttusbdecfe_dvbs_ops = { 267static struct dvb_frontend_ops ttusbdecfe_dvbs_ops = {
@@ -273,7 +283,7 @@ static struct dvb_frontend_ops ttusbdecfe_dvbs_ops = {
273 283
274 .set_frontend = ttusbdecfe_dvbs_set_frontend, 284 .set_frontend = ttusbdecfe_dvbs_set_frontend,
275 285
276 .read_status = ttusbdecfe_read_status, 286 .read_status = ttusbdecfe_dvbs_read_status,
277 287
278 .diseqc_send_master_cmd = ttusbdecfe_dvbs_diseqc_send_master_cmd, 288 .diseqc_send_master_cmd = ttusbdecfe_dvbs_diseqc_send_master_cmd,
279 .set_voltage = ttusbdecfe_dvbs_set_voltage, 289 .set_voltage = ttusbdecfe_dvbs_set_voltage,
diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig
index 1b41b3f77cf9..e51d707e58d3 100644
--- a/drivers/media/radio/Kconfig
+++ b/drivers/media/radio/Kconfig
@@ -361,4 +361,16 @@ config USB_SI470X
361 To compile this driver as a module, choose M here: the 361 To compile this driver as a module, choose M here: the
362 module will be called radio-silabs. 362 module will be called radio-silabs.
363 363
364config USB_MR800
365 tristate "AverMedia MR 800 USB FM radio support"
366 depends on USB && VIDEO_V4L2
367 ---help---
368 Say Y here if you want to connect this type of radio to your
369 computer's USB port. Note that the audio is not digital, and
370 you must connect the line out connector to a sound card or a
371 set of speakers.
372
373 To compile this driver as a module, choose M here: the
374 module will be called radio-mr800.
375
364endif # RADIO_ADAPTERS 376endif # RADIO_ADAPTERS
diff --git a/drivers/media/radio/Makefile b/drivers/media/radio/Makefile
index 7ca71ab96b43..240ec63cdafc 100644
--- a/drivers/media/radio/Makefile
+++ b/drivers/media/radio/Makefile
@@ -18,5 +18,6 @@ obj-$(CONFIG_RADIO_TRUST) += radio-trust.o
18obj-$(CONFIG_RADIO_MAESTRO) += radio-maestro.o 18obj-$(CONFIG_RADIO_MAESTRO) += radio-maestro.o
19obj-$(CONFIG_USB_DSBR) += dsbr100.o 19obj-$(CONFIG_USB_DSBR) += dsbr100.o
20obj-$(CONFIG_USB_SI470X) += radio-si470x.o 20obj-$(CONFIG_USB_SI470X) += radio-si470x.o
21obj-$(CONFIG_USB_MR800) += radio-mr800.o
21 22
22EXTRA_CFLAGS += -Isound 23EXTRA_CFLAGS += -Isound
diff --git a/drivers/media/radio/dsbr100.c b/drivers/media/radio/dsbr100.c
index 70c65a745923..66783fffe4c1 100644
--- a/drivers/media/radio/dsbr100.c
+++ b/drivers/media/radio/dsbr100.c
@@ -274,7 +274,7 @@ static int vidioc_querycap(struct file *file, void *priv,
274static int vidioc_g_tuner(struct file *file, void *priv, 274static int vidioc_g_tuner(struct file *file, void *priv,
275 struct v4l2_tuner *v) 275 struct v4l2_tuner *v)
276{ 276{
277 struct dsbr100_device *radio = video_get_drvdata(video_devdata(file)); 277 struct dsbr100_device *radio = video_drvdata(file);
278 278
279 if (v->index > 0) 279 if (v->index > 0)
280 return -EINVAL; 280 return -EINVAL;
@@ -306,7 +306,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
306static int vidioc_s_frequency(struct file *file, void *priv, 306static int vidioc_s_frequency(struct file *file, void *priv,
307 struct v4l2_frequency *f) 307 struct v4l2_frequency *f)
308{ 308{
309 struct dsbr100_device *radio = video_get_drvdata(video_devdata(file)); 309 struct dsbr100_device *radio = video_drvdata(file);
310 310
311 radio->curfreq = f->frequency; 311 radio->curfreq = f->frequency;
312 if (dsbr100_setfreq(radio, radio->curfreq)==-1) 312 if (dsbr100_setfreq(radio, radio->curfreq)==-1)
@@ -317,7 +317,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
317static int vidioc_g_frequency(struct file *file, void *priv, 317static int vidioc_g_frequency(struct file *file, void *priv,
318 struct v4l2_frequency *f) 318 struct v4l2_frequency *f)
319{ 319{
320 struct dsbr100_device *radio = video_get_drvdata(video_devdata(file)); 320 struct dsbr100_device *radio = video_drvdata(file);
321 321
322 f->type = V4L2_TUNER_RADIO; 322 f->type = V4L2_TUNER_RADIO;
323 f->frequency = radio->curfreq; 323 f->frequency = radio->curfreq;
@@ -342,7 +342,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
342static int vidioc_g_ctrl(struct file *file, void *priv, 342static int vidioc_g_ctrl(struct file *file, void *priv,
343 struct v4l2_control *ctrl) 343 struct v4l2_control *ctrl)
344{ 344{
345 struct dsbr100_device *radio = video_get_drvdata(video_devdata(file)); 345 struct dsbr100_device *radio = video_drvdata(file);
346 346
347 switch (ctrl->id) { 347 switch (ctrl->id) {
348 case V4L2_CID_AUDIO_MUTE: 348 case V4L2_CID_AUDIO_MUTE:
@@ -355,16 +355,20 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
355static int vidioc_s_ctrl(struct file *file, void *priv, 355static int vidioc_s_ctrl(struct file *file, void *priv,
356 struct v4l2_control *ctrl) 356 struct v4l2_control *ctrl)
357{ 357{
358 struct dsbr100_device *radio = video_get_drvdata(video_devdata(file)); 358 struct dsbr100_device *radio = video_drvdata(file);
359 359
360 switch (ctrl->id) { 360 switch (ctrl->id) {
361 case V4L2_CID_AUDIO_MUTE: 361 case V4L2_CID_AUDIO_MUTE:
362 if (ctrl->value) { 362 if (ctrl->value) {
363 if (dsbr100_stop(radio)==-1) 363 if (dsbr100_stop(radio) == -1) {
364 warn("Radio did not respond properly"); 364 warn("Radio did not respond properly");
365 return -EBUSY;
366 }
365 } else { 367 } else {
366 if (dsbr100_start(radio)==-1) 368 if (dsbr100_start(radio) == -1) {
367 warn("Radio did not respond properly"); 369 warn("Radio did not respond properly");
370 return -EBUSY;
371 }
368 } 372 }
369 return 0; 373 return 0;
370 } 374 }
@@ -405,23 +409,26 @@ static int vidioc_s_audio(struct file *file, void *priv,
405 409
406static int usb_dsbr100_open(struct inode *inode, struct file *file) 410static int usb_dsbr100_open(struct inode *inode, struct file *file)
407{ 411{
408 struct dsbr100_device *radio=video_get_drvdata(video_devdata(file)); 412 struct dsbr100_device *radio = video_drvdata(file);
409 413
414 lock_kernel();
410 radio->users = 1; 415 radio->users = 1;
411 radio->muted = 1; 416 radio->muted = 1;
412 417
413 if (dsbr100_start(radio)<0) { 418 if (dsbr100_start(radio)<0) {
414 warn("Radio did not start up properly"); 419 warn("Radio did not start up properly");
415 radio->users = 0; 420 radio->users = 0;
421 unlock_kernel();
416 return -EIO; 422 return -EIO;
417 } 423 }
418 dsbr100_setfreq(radio, radio->curfreq); 424 dsbr100_setfreq(radio, radio->curfreq);
425 unlock_kernel();
419 return 0; 426 return 0;
420} 427}
421 428
422static int usb_dsbr100_close(struct inode *inode, struct file *file) 429static int usb_dsbr100_close(struct inode *inode, struct file *file)
423{ 430{
424 struct dsbr100_device *radio=video_get_drvdata(video_devdata(file)); 431 struct dsbr100_device *radio = video_drvdata(file);
425 432
426 if (!radio) 433 if (!radio)
427 return -ENODEV; 434 return -ENODEV;
@@ -507,7 +514,8 @@ static int usb_dsbr100_probe(struct usb_interface *intf,
507static int __init dsbr100_init(void) 514static int __init dsbr100_init(void)
508{ 515{
509 int retval = usb_register(&usb_dsbr100_driver); 516 int retval = usb_register(&usb_dsbr100_driver);
510 info(DRIVER_VERSION ":" DRIVER_DESC); 517 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
518 DRIVER_DESC "\n");
511 return retval; 519 return retval;
512} 520}
513 521
diff --git a/drivers/media/radio/radio-aimslab.c b/drivers/media/radio/radio-aimslab.c
index 1f064f4b32df..9305e958fc66 100644
--- a/drivers/media/radio/radio-aimslab.c
+++ b/drivers/media/radio/radio-aimslab.c
@@ -51,6 +51,7 @@ static struct mutex lock;
51 51
52struct rt_device 52struct rt_device
53{ 53{
54 unsigned long in_use;
54 int port; 55 int port;
55 int curvol; 56 int curvol;
56 unsigned long curfreq; 57 unsigned long curfreq;
@@ -245,8 +246,7 @@ static int vidioc_querycap(struct file *file, void *priv,
245static int vidioc_g_tuner(struct file *file, void *priv, 246static int vidioc_g_tuner(struct file *file, void *priv,
246 struct v4l2_tuner *v) 247 struct v4l2_tuner *v)
247{ 248{
248 struct video_device *dev = video_devdata(file); 249 struct rt_device *rt = video_drvdata(file);
249 struct rt_device *rt = dev->priv;
250 250
251 if (v->index > 0) 251 if (v->index > 0)
252 return -EINVAL; 252 return -EINVAL;
@@ -273,8 +273,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
273static int vidioc_s_frequency(struct file *file, void *priv, 273static int vidioc_s_frequency(struct file *file, void *priv,
274 struct v4l2_frequency *f) 274 struct v4l2_frequency *f)
275{ 275{
276 struct video_device *dev = video_devdata(file); 276 struct rt_device *rt = video_drvdata(file);
277 struct rt_device *rt = dev->priv;
278 277
279 rt->curfreq = f->frequency; 278 rt->curfreq = f->frequency;
280 rt_setfreq(rt, rt->curfreq); 279 rt_setfreq(rt, rt->curfreq);
@@ -284,8 +283,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
284static int vidioc_g_frequency(struct file *file, void *priv, 283static int vidioc_g_frequency(struct file *file, void *priv,
285 struct v4l2_frequency *f) 284 struct v4l2_frequency *f)
286{ 285{
287 struct video_device *dev = video_devdata(file); 286 struct rt_device *rt = video_drvdata(file);
288 struct rt_device *rt = dev->priv;
289 287
290 f->type = V4L2_TUNER_RADIO; 288 f->type = V4L2_TUNER_RADIO;
291 f->frequency = rt->curfreq; 289 f->frequency = rt->curfreq;
@@ -310,8 +308,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
310static int vidioc_g_ctrl(struct file *file, void *priv, 308static int vidioc_g_ctrl(struct file *file, void *priv,
311 struct v4l2_control *ctrl) 309 struct v4l2_control *ctrl)
312{ 310{
313 struct video_device *dev = video_devdata(file); 311 struct rt_device *rt = video_drvdata(file);
314 struct rt_device *rt = dev->priv;
315 312
316 switch (ctrl->id) { 313 switch (ctrl->id) {
317 case V4L2_CID_AUDIO_MUTE: 314 case V4L2_CID_AUDIO_MUTE:
@@ -327,8 +324,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
327static int vidioc_s_ctrl(struct file *file, void *priv, 324static int vidioc_s_ctrl(struct file *file, void *priv,
328 struct v4l2_control *ctrl) 325 struct v4l2_control *ctrl)
329{ 326{
330 struct video_device *dev = video_devdata(file); 327 struct rt_device *rt = video_drvdata(file);
331 struct rt_device *rt = dev->priv;
332 328
333 switch (ctrl->id) { 329 switch (ctrl->id) {
334 case V4L2_CID_AUDIO_MUTE: 330 case V4L2_CID_AUDIO_MUTE:
@@ -378,10 +374,21 @@ static int vidioc_s_audio(struct file *file, void *priv,
378 374
379static struct rt_device rtrack_unit; 375static struct rt_device rtrack_unit;
380 376
377static int rtrack_exclusive_open(struct inode *inode, struct file *file)
378{
379 return test_and_set_bit(0, &rtrack_unit.in_use) ? -EBUSY : 0;
380}
381
382static int rtrack_exclusive_release(struct inode *inode, struct file *file)
383{
384 clear_bit(0, &rtrack_unit.in_use);
385 return 0;
386}
387
381static const struct file_operations rtrack_fops = { 388static const struct file_operations rtrack_fops = {
382 .owner = THIS_MODULE, 389 .owner = THIS_MODULE,
383 .open = video_exclusive_open, 390 .open = rtrack_exclusive_open,
384 .release = video_exclusive_release, 391 .release = rtrack_exclusive_release,
385 .ioctl = video_ioctl2, 392 .ioctl = video_ioctl2,
386#ifdef CONFIG_COMPAT 393#ifdef CONFIG_COMPAT
387 .compat_ioctl = v4l_compat_ioctl32, 394 .compat_ioctl = v4l_compat_ioctl32,
@@ -408,6 +415,7 @@ static struct video_device rtrack_radio = {
408 .name = "RadioTrack radio", 415 .name = "RadioTrack radio",
409 .fops = &rtrack_fops, 416 .fops = &rtrack_fops,
410 .ioctl_ops = &rtrack_ioctl_ops, 417 .ioctl_ops = &rtrack_ioctl_ops,
418 .release = video_device_release_empty,
411}; 419};
412 420
413static int __init rtrack_init(void) 421static int __init rtrack_init(void)
@@ -424,7 +432,7 @@ static int __init rtrack_init(void)
424 return -EBUSY; 432 return -EBUSY;
425 } 433 }
426 434
427 rtrack_radio.priv=&rtrack_unit; 435 video_set_drvdata(&rtrack_radio, &rtrack_unit);
428 436
429 if (video_register_device(&rtrack_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 437 if (video_register_device(&rtrack_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
430 release_region(io, 2); 438 release_region(io, 2);
diff --git a/drivers/media/radio/radio-aztech.c b/drivers/media/radio/radio-aztech.c
index 628c689e3ffe..d78489573230 100644
--- a/drivers/media/radio/radio-aztech.c
+++ b/drivers/media/radio/radio-aztech.c
@@ -70,6 +70,7 @@ static struct mutex lock;
70 70
71struct az_device 71struct az_device
72{ 72{
73 unsigned long in_use;
73 int curvol; 74 int curvol;
74 unsigned long curfreq; 75 unsigned long curfreq;
75 int stereo; 76 int stereo;
@@ -195,8 +196,7 @@ static int vidioc_querycap (struct file *file, void *priv,
195static int vidioc_g_tuner (struct file *file, void *priv, 196static int vidioc_g_tuner (struct file *file, void *priv,
196 struct v4l2_tuner *v) 197 struct v4l2_tuner *v)
197{ 198{
198 struct video_device *dev = video_devdata(file); 199 struct az_device *az = video_drvdata(file);
199 struct az_device *az = dev->priv;
200 200
201 if (v->index > 0) 201 if (v->index > 0)
202 return -EINVAL; 202 return -EINVAL;
@@ -264,8 +264,7 @@ static int vidioc_s_audio (struct file *file, void *priv,
264static int vidioc_s_frequency (struct file *file, void *priv, 264static int vidioc_s_frequency (struct file *file, void *priv,
265 struct v4l2_frequency *f) 265 struct v4l2_frequency *f)
266{ 266{
267 struct video_device *dev = video_devdata(file); 267 struct az_device *az = video_drvdata(file);
268 struct az_device *az = dev->priv;
269 268
270 az->curfreq = f->frequency; 269 az->curfreq = f->frequency;
271 az_setfreq(az, az->curfreq); 270 az_setfreq(az, az->curfreq);
@@ -275,8 +274,7 @@ static int vidioc_s_frequency (struct file *file, void *priv,
275static int vidioc_g_frequency (struct file *file, void *priv, 274static int vidioc_g_frequency (struct file *file, void *priv,
276 struct v4l2_frequency *f) 275 struct v4l2_frequency *f)
277{ 276{
278 struct video_device *dev = video_devdata(file); 277 struct az_device *az = video_drvdata(file);
279 struct az_device *az = dev->priv;
280 278
281 f->type = V4L2_TUNER_RADIO; 279 f->type = V4L2_TUNER_RADIO;
282 f->frequency = az->curfreq; 280 f->frequency = az->curfreq;
@@ -302,8 +300,7 @@ static int vidioc_queryctrl (struct file *file, void *priv,
302static int vidioc_g_ctrl (struct file *file, void *priv, 300static int vidioc_g_ctrl (struct file *file, void *priv,
303 struct v4l2_control *ctrl) 301 struct v4l2_control *ctrl)
304{ 302{
305 struct video_device *dev = video_devdata(file); 303 struct az_device *az = video_drvdata(file);
306 struct az_device *az = dev->priv;
307 304
308 switch (ctrl->id) { 305 switch (ctrl->id) {
309 case V4L2_CID_AUDIO_MUTE: 306 case V4L2_CID_AUDIO_MUTE:
@@ -322,8 +319,7 @@ static int vidioc_g_ctrl (struct file *file, void *priv,
322static int vidioc_s_ctrl (struct file *file, void *priv, 319static int vidioc_s_ctrl (struct file *file, void *priv,
323 struct v4l2_control *ctrl) 320 struct v4l2_control *ctrl)
324{ 321{
325 struct video_device *dev = video_devdata(file); 322 struct az_device *az = video_drvdata(file);
326 struct az_device *az = dev->priv;
327 323
328 switch (ctrl->id) { 324 switch (ctrl->id) {
329 case V4L2_CID_AUDIO_MUTE: 325 case V4L2_CID_AUDIO_MUTE:
@@ -342,10 +338,21 @@ static int vidioc_s_ctrl (struct file *file, void *priv,
342 338
343static struct az_device aztech_unit; 339static struct az_device aztech_unit;
344 340
341static int aztech_exclusive_open(struct inode *inode, struct file *file)
342{
343 return test_and_set_bit(0, &aztech_unit.in_use) ? -EBUSY : 0;
344}
345
346static int aztech_exclusive_release(struct inode *inode, struct file *file)
347{
348 clear_bit(0, &aztech_unit.in_use);
349 return 0;
350}
351
345static const struct file_operations aztech_fops = { 352static const struct file_operations aztech_fops = {
346 .owner = THIS_MODULE, 353 .owner = THIS_MODULE,
347 .open = video_exclusive_open, 354 .open = aztech_exclusive_open,
348 .release = video_exclusive_release, 355 .release = aztech_exclusive_release,
349 .ioctl = video_ioctl2, 356 .ioctl = video_ioctl2,
350#ifdef CONFIG_COMPAT 357#ifdef CONFIG_COMPAT
351 .compat_ioctl = v4l_compat_ioctl32, 358 .compat_ioctl = v4l_compat_ioctl32,
@@ -369,9 +376,10 @@ static const struct v4l2_ioctl_ops aztech_ioctl_ops = {
369}; 376};
370 377
371static struct video_device aztech_radio = { 378static struct video_device aztech_radio = {
372 .name = "Aztech radio", 379 .name = "Aztech radio",
373 .fops = &aztech_fops, 380 .fops = &aztech_fops,
374 .ioctl_ops = &aztech_ioctl_ops, 381 .ioctl_ops = &aztech_ioctl_ops,
382 .release = video_device_release_empty,
375}; 383};
376 384
377module_param_named(debug,aztech_radio.debug, int, 0644); 385module_param_named(debug,aztech_radio.debug, int, 0644);
@@ -392,7 +400,7 @@ static int __init aztech_init(void)
392 } 400 }
393 401
394 mutex_init(&lock); 402 mutex_init(&lock);
395 aztech_radio.priv=&aztech_unit; 403 video_set_drvdata(&aztech_radio, &aztech_unit);
396 404
397 if (video_register_device(&aztech_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 405 if (video_register_device(&aztech_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
398 release_region(io,2); 406 release_region(io,2);
diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
index 04c3698d32e4..0490a1fa999d 100644
--- a/drivers/media/radio/radio-cadet.c
+++ b/drivers/media/radio/radio-cadet.c
@@ -589,6 +589,7 @@ static struct video_device cadet_radio = {
589 .name = "Cadet radio", 589 .name = "Cadet radio",
590 .fops = &cadet_fops, 590 .fops = &cadet_fops,
591 .ioctl_ops = &cadet_ioctl_ops, 591 .ioctl_ops = &cadet_ioctl_ops,
592 .release = video_device_release_empty,
592}; 593};
593 594
594#ifdef CONFIG_PNP 595#ifdef CONFIG_PNP
diff --git a/drivers/media/radio/radio-gemtek-pci.c b/drivers/media/radio/radio-gemtek-pci.c
index 5cd7f032298d..e15bee6d7cfc 100644
--- a/drivers/media/radio/radio-gemtek-pci.c
+++ b/drivers/media/radio/radio-gemtek-pci.c
@@ -100,9 +100,8 @@ struct gemtek_pci_card {
100 u8 mute; 100 u8 mute;
101}; 101};
102 102
103static const char rcsid[] = "$Id: radio-gemtek-pci.c,v 1.1 2001/07/23 08:08:16 ted Exp ted $";
104
105static int nr_radio = -1; 103static int nr_radio = -1;
104static unsigned long in_use;
106 105
107static inline u8 gemtek_pci_out( u16 value, u32 port ) 106static inline u8 gemtek_pci_out( u16 value, u32 port )
108{ 107{
@@ -205,8 +204,7 @@ static int vidioc_querycap(struct file *file, void *priv,
205static int vidioc_g_tuner(struct file *file, void *priv, 204static int vidioc_g_tuner(struct file *file, void *priv,
206 struct v4l2_tuner *v) 205 struct v4l2_tuner *v)
207{ 206{
208 struct video_device *dev = video_devdata(file); 207 struct gemtek_pci_card *card = video_drvdata(file);
209 struct gemtek_pci_card *card = dev->priv;
210 208
211 if (v->index > 0) 209 if (v->index > 0)
212 return -EINVAL; 210 return -EINVAL;
@@ -233,8 +231,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
233static int vidioc_s_frequency(struct file *file, void *priv, 231static int vidioc_s_frequency(struct file *file, void *priv,
234 struct v4l2_frequency *f) 232 struct v4l2_frequency *f)
235{ 233{
236 struct video_device *dev = video_devdata(file); 234 struct gemtek_pci_card *card = video_drvdata(file);
237 struct gemtek_pci_card *card = dev->priv;
238 235
239 if ( (f->frequency < GEMTEK_PCI_RANGE_LOW) || 236 if ( (f->frequency < GEMTEK_PCI_RANGE_LOW) ||
240 (f->frequency > GEMTEK_PCI_RANGE_HIGH) ) 237 (f->frequency > GEMTEK_PCI_RANGE_HIGH) )
@@ -248,8 +245,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
248static int vidioc_g_frequency(struct file *file, void *priv, 245static int vidioc_g_frequency(struct file *file, void *priv,
249 struct v4l2_frequency *f) 246 struct v4l2_frequency *f)
250{ 247{
251 struct video_device *dev = video_devdata(file); 248 struct gemtek_pci_card *card = video_drvdata(file);
252 struct gemtek_pci_card *card = dev->priv;
253 249
254 f->type = V4L2_TUNER_RADIO; 250 f->type = V4L2_TUNER_RADIO;
255 f->frequency = card->current_frequency; 251 f->frequency = card->current_frequency;
@@ -273,8 +269,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
273static int vidioc_g_ctrl(struct file *file, void *priv, 269static int vidioc_g_ctrl(struct file *file, void *priv,
274 struct v4l2_control *ctrl) 270 struct v4l2_control *ctrl)
275{ 271{
276 struct video_device *dev = video_devdata(file); 272 struct gemtek_pci_card *card = video_drvdata(file);
277 struct gemtek_pci_card *card = dev->priv;
278 273
279 switch (ctrl->id) { 274 switch (ctrl->id) {
280 case V4L2_CID_AUDIO_MUTE: 275 case V4L2_CID_AUDIO_MUTE:
@@ -293,8 +288,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
293static int vidioc_s_ctrl(struct file *file, void *priv, 288static int vidioc_s_ctrl(struct file *file, void *priv,
294 struct v4l2_control *ctrl) 289 struct v4l2_control *ctrl)
295{ 290{
296 struct video_device *dev = video_devdata(file); 291 struct gemtek_pci_card *card = video_drvdata(file);
297 struct gemtek_pci_card *card = dev->priv;
298 292
299 switch (ctrl->id) { 293 switch (ctrl->id) {
300 case V4L2_CID_AUDIO_MUTE: 294 case V4L2_CID_AUDIO_MUTE:
@@ -364,10 +358,21 @@ MODULE_DEVICE_TABLE( pci, gemtek_pci_id );
364 358
365static int mx = 1; 359static int mx = 1;
366 360
361static int gemtek_pci_exclusive_open(struct inode *inode, struct file *file)
362{
363 return test_and_set_bit(0, &in_use) ? -EBUSY : 0;
364}
365
366static int gemtek_pci_exclusive_release(struct inode *inode, struct file *file)
367{
368 clear_bit(0, &in_use);
369 return 0;
370}
371
367static const struct file_operations gemtek_pci_fops = { 372static const struct file_operations gemtek_pci_fops = {
368 .owner = THIS_MODULE, 373 .owner = THIS_MODULE,
369 .open = video_exclusive_open, 374 .open = gemtek_pci_exclusive_open,
370 .release = video_exclusive_release, 375 .release = gemtek_pci_exclusive_release,
371 .ioctl = video_ioctl2, 376 .ioctl = video_ioctl2,
372#ifdef CONFIG_COMPAT 377#ifdef CONFIG_COMPAT
373 .compat_ioctl = v4l_compat_ioctl32, 378 .compat_ioctl = v4l_compat_ioctl32,
@@ -391,9 +396,10 @@ static const struct v4l2_ioctl_ops gemtek_pci_ioctl_ops = {
391}; 396};
392 397
393static struct video_device vdev_template = { 398static struct video_device vdev_template = {
394 .name = "Gemtek PCI Radio", 399 .name = "Gemtek PCI Radio",
395 .fops = &gemtek_pci_fops, 400 .fops = &gemtek_pci_fops,
396 .ioctl_ops = &gemtek_pci_ioctl_ops, 401 .ioctl_ops = &gemtek_pci_ioctl_ops,
402 .release = video_device_release_empty,
397}; 403};
398 404
399static int __devinit gemtek_pci_probe( struct pci_dev *pci_dev, const struct pci_device_id *pci_id ) 405static int __devinit gemtek_pci_probe( struct pci_dev *pci_dev, const struct pci_device_id *pci_id )
@@ -431,7 +437,7 @@ static int __devinit gemtek_pci_probe( struct pci_dev *pci_dev, const struct pci
431 } 437 }
432 438
433 card->videodev = devradio; 439 card->videodev = devradio;
434 devradio->priv = card; 440 video_set_drvdata(devradio, card);
435 gemtek_pci_mute( card ); 441 gemtek_pci_mute( card );
436 442
437 printk( KERN_INFO "Gemtek PCI Radio (rev. %d) found at 0x%04x-0x%04x.\n", 443 printk( KERN_INFO "Gemtek PCI Radio (rev. %d) found at 0x%04x-0x%04x.\n",
diff --git a/drivers/media/radio/radio-gemtek.c b/drivers/media/radio/radio-gemtek.c
index 0a0f956bb308..d131a5d38128 100644
--- a/drivers/media/radio/radio-gemtek.c
+++ b/drivers/media/radio/radio-gemtek.c
@@ -57,6 +57,7 @@ static int shutdown = 1;
57static int keepmuted = 1; 57static int keepmuted = 1;
58static int initmute = 1; 58static int initmute = 1;
59static int radio_nr = -1; 59static int radio_nr = -1;
60static unsigned long in_use;
60 61
61module_param(io, int, 0444); 62module_param(io, int, 0444);
62MODULE_PARM_DESC(io, "Force I/O port for the GemTek Radio card if automatic " 63MODULE_PARM_DESC(io, "Force I/O port for the GemTek Radio card if automatic "
@@ -393,10 +394,21 @@ static struct v4l2_queryctrl radio_qctrl[] = {
393 } 394 }
394}; 395};
395 396
397static int gemtek_exclusive_open(struct inode *inode, struct file *file)
398{
399 return test_and_set_bit(0, &in_use) ? -EBUSY : 0;
400}
401
402static int gemtek_exclusive_release(struct inode *inode, struct file *file)
403{
404 clear_bit(0, &in_use);
405 return 0;
406}
407
396static const struct file_operations gemtek_fops = { 408static const struct file_operations gemtek_fops = {
397 .owner = THIS_MODULE, 409 .owner = THIS_MODULE,
398 .open = video_exclusive_open, 410 .open = gemtek_exclusive_open,
399 .release = video_exclusive_release, 411 .release = gemtek_exclusive_release,
400 .ioctl = video_ioctl2, 412 .ioctl = video_ioctl2,
401#ifdef CONFIG_COMPAT 413#ifdef CONFIG_COMPAT
402 .compat_ioctl = v4l_compat_ioctl32, 414 .compat_ioctl = v4l_compat_ioctl32,
@@ -447,8 +459,7 @@ static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
447static int vidioc_s_frequency(struct file *file, void *priv, 459static int vidioc_s_frequency(struct file *file, void *priv,
448 struct v4l2_frequency *f) 460 struct v4l2_frequency *f)
449{ 461{
450 struct video_device *dev = video_devdata(file); 462 struct gemtek_device *rt = video_drvdata(file);
451 struct gemtek_device *rt = dev->priv;
452 463
453 gemtek_setfreq(rt, f->frequency); 464 gemtek_setfreq(rt, f->frequency);
454 465
@@ -458,8 +469,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
458static int vidioc_g_frequency(struct file *file, void *priv, 469static int vidioc_g_frequency(struct file *file, void *priv,
459 struct v4l2_frequency *f) 470 struct v4l2_frequency *f)
460{ 471{
461 struct video_device *dev = video_devdata(file); 472 struct gemtek_device *rt = video_drvdata(file);
462 struct gemtek_device *rt = dev->priv;
463 473
464 f->type = V4L2_TUNER_RADIO; 474 f->type = V4L2_TUNER_RADIO;
465 f->frequency = rt->lastfreq; 475 f->frequency = rt->lastfreq;
@@ -483,8 +493,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
483static int vidioc_g_ctrl(struct file *file, void *priv, 493static int vidioc_g_ctrl(struct file *file, void *priv,
484 struct v4l2_control *ctrl) 494 struct v4l2_control *ctrl)
485{ 495{
486 struct video_device *dev = video_devdata(file); 496 struct gemtek_device *rt = video_drvdata(file);
487 struct gemtek_device *rt = dev->priv;
488 497
489 switch (ctrl->id) { 498 switch (ctrl->id) {
490 case V4L2_CID_AUDIO_MUTE: 499 case V4L2_CID_AUDIO_MUTE:
@@ -503,8 +512,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
503static int vidioc_s_ctrl(struct file *file, void *priv, 512static int vidioc_s_ctrl(struct file *file, void *priv,
504 struct v4l2_control *ctrl) 513 struct v4l2_control *ctrl)
505{ 514{
506 struct video_device *dev = video_devdata(file); 515 struct gemtek_device *rt = video_drvdata(file);
507 struct gemtek_device *rt = dev->priv;
508 516
509 switch (ctrl->id) { 517 switch (ctrl->id) {
510 case V4L2_CID_AUDIO_MUTE: 518 case V4L2_CID_AUDIO_MUTE:
@@ -569,9 +577,10 @@ static const struct v4l2_ioctl_ops gemtek_ioctl_ops = {
569}; 577};
570 578
571static struct video_device gemtek_radio = { 579static struct video_device gemtek_radio = {
572 .name = "GemTek Radio card", 580 .name = "GemTek Radio card",
573 .fops = &gemtek_fops, 581 .fops = &gemtek_fops,
574 .ioctl_ops = &gemtek_ioctl_ops, 582 .ioctl_ops = &gemtek_ioctl_ops,
583 .release = video_device_release_empty,
575}; 584};
576 585
577/* 586/*
@@ -610,7 +619,7 @@ static int __init gemtek_init(void)
610 return -EINVAL; 619 return -EINVAL;
611 } 620 }
612 621
613 gemtek_radio.priv = &gemtek_unit; 622 video_set_drvdata(&gemtek_radio, &gemtek_unit);
614 623
615 if (video_register_device(&gemtek_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 624 if (video_register_device(&gemtek_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
616 release_region(io, 1); 625 release_region(io, 1);
diff --git a/drivers/media/radio/radio-maestro.c b/drivers/media/radio/radio-maestro.c
index 9ef0a763eeb7..4bf4d007bcfa 100644
--- a/drivers/media/radio/radio-maestro.c
+++ b/drivers/media/radio/radio-maestro.c
@@ -75,7 +75,21 @@ static struct v4l2_queryctrl radio_qctrl[] = {
75static int radio_nr = -1; 75static int radio_nr = -1;
76module_param(radio_nr, int, 0); 76module_param(radio_nr, int, 0);
77 77
78static unsigned long in_use;
79
78static int maestro_probe(struct pci_dev *pdev, const struct pci_device_id *ent); 80static int maestro_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
81
82static int maestro_exclusive_open(struct inode *inode, struct file *file)
83{
84 return test_and_set_bit(0, &in_use) ? -EBUSY : 0;
85}
86
87static int maestro_exclusive_release(struct inode *inode, struct file *file)
88{
89 clear_bit(0, &in_use);
90 return 0;
91}
92
79static void maestro_remove(struct pci_dev *pdev); 93static void maestro_remove(struct pci_dev *pdev);
80 94
81static struct pci_device_id maestro_r_pci_tbl[] = { 95static struct pci_device_id maestro_r_pci_tbl[] = {
@@ -98,8 +112,8 @@ static struct pci_driver maestro_r_driver = {
98 112
99static const struct file_operations maestro_fops = { 113static const struct file_operations maestro_fops = {
100 .owner = THIS_MODULE, 114 .owner = THIS_MODULE,
101 .open = video_exclusive_open, 115 .open = maestro_exclusive_open,
102 .release = video_exclusive_release, 116 .release = maestro_exclusive_release,
103 .ioctl = video_ioctl2, 117 .ioctl = video_ioctl2,
104#ifdef CONFIG_COMPAT 118#ifdef CONFIG_COMPAT
105 .compat_ioctl = v4l_compat_ioctl32, 119 .compat_ioctl = v4l_compat_ioctl32,
@@ -196,8 +210,7 @@ static int vidioc_querycap(struct file *file, void *priv,
196static int vidioc_g_tuner(struct file *file, void *priv, 210static int vidioc_g_tuner(struct file *file, void *priv,
197 struct v4l2_tuner *v) 211 struct v4l2_tuner *v)
198{ 212{
199 struct video_device *dev = video_devdata(file); 213 struct radio_device *card = video_drvdata(file);
200 struct radio_device *card = video_get_drvdata(dev);
201 214
202 if (v->index > 0) 215 if (v->index > 0)
203 return -EINVAL; 216 return -EINVAL;
@@ -229,8 +242,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
229static int vidioc_s_frequency(struct file *file, void *priv, 242static int vidioc_s_frequency(struct file *file, void *priv,
230 struct v4l2_frequency *f) 243 struct v4l2_frequency *f)
231{ 244{
232 struct video_device *dev = video_devdata(file); 245 struct radio_device *card = video_drvdata(file);
233 struct radio_device *card = video_get_drvdata(dev);
234 246
235 if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) 247 if (f->frequency < FREQ_LO || f->frequency > FREQ_HI)
236 return -EINVAL; 248 return -EINVAL;
@@ -241,8 +253,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
241static int vidioc_g_frequency(struct file *file, void *priv, 253static int vidioc_g_frequency(struct file *file, void *priv,
242 struct v4l2_frequency *f) 254 struct v4l2_frequency *f)
243{ 255{
244 struct video_device *dev = video_devdata(file); 256 struct radio_device *card = video_drvdata(file);
245 struct radio_device *card = video_get_drvdata(dev);
246 257
247 f->type = V4L2_TUNER_RADIO; 258 f->type = V4L2_TUNER_RADIO;
248 f->frequency = BITS2FREQ(radio_bits_get(card)); 259 f->frequency = BITS2FREQ(radio_bits_get(card));
@@ -267,8 +278,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
267static int vidioc_g_ctrl(struct file *file, void *priv, 278static int vidioc_g_ctrl(struct file *file, void *priv,
268 struct v4l2_control *ctrl) 279 struct v4l2_control *ctrl)
269{ 280{
270 struct video_device *dev = video_devdata(file); 281 struct radio_device *card = video_drvdata(file);
271 struct radio_device *card = video_get_drvdata(dev);
272 282
273 switch (ctrl->id) { 283 switch (ctrl->id) {
274 case V4L2_CID_AUDIO_MUTE: 284 case V4L2_CID_AUDIO_MUTE:
@@ -281,8 +291,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
281static int vidioc_s_ctrl(struct file *file, void *priv, 291static int vidioc_s_ctrl(struct file *file, void *priv,
282 struct v4l2_control *ctrl) 292 struct v4l2_control *ctrl)
283{ 293{
284 struct video_device *dev = video_devdata(file); 294 struct radio_device *card = video_drvdata(file);
285 struct radio_device *card = video_get_drvdata(dev);
286 register u16 io = card->io; 295 register u16 io = card->io;
287 register u16 omask = inw(io + IO_MASK); 296 register u16 omask = inw(io + IO_MASK);
288 297
@@ -374,6 +383,7 @@ static struct video_device maestro_radio = {
374 .name = "Maestro radio", 383 .name = "Maestro radio",
375 .fops = &maestro_fops, 384 .fops = &maestro_fops,
376 .ioctl_ops = &maestro_ioctl_ops, 385 .ioctl_ops = &maestro_ioctl_ops,
386 .release = video_device_release,
377}; 387};
378 388
379static int __devinit maestro_probe(struct pci_dev *pdev, 389static int __devinit maestro_probe(struct pci_dev *pdev,
diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
index 0cc6fcb041fd..c777a17b00bc 100644
--- a/drivers/media/radio/radio-maxiradio.c
+++ b/drivers/media/radio/radio-maxiradio.c
@@ -85,6 +85,7 @@ static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16 ;
85static int radio_nr = -1; 85static int radio_nr = -1;
86module_param(radio_nr, int, 0); 86module_param(radio_nr, int, 0);
87 87
88static unsigned long in_use;
88 89
89#define FREQ_LO 50*16000 90#define FREQ_LO 50*16000
90#define FREQ_HI 150*16000 91#define FREQ_HI 150*16000
@@ -99,10 +100,21 @@ module_param(radio_nr, int, 0);
99#define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF) 100#define BITS2FREQ(x) ((x) * FREQ_STEP - FREQ_IF)
100 101
101 102
103static int maxiradio_exclusive_open(struct inode *inode, struct file *file)
104{
105 return test_and_set_bit(0, &in_use) ? -EBUSY : 0;
106}
107
108static int maxiradio_exclusive_release(struct inode *inode, struct file *file)
109{
110 clear_bit(0, &in_use);
111 return 0;
112}
113
102static const struct file_operations maxiradio_fops = { 114static const struct file_operations maxiradio_fops = {
103 .owner = THIS_MODULE, 115 .owner = THIS_MODULE,
104 .open = video_exclusive_open, 116 .open = maxiradio_exclusive_open,
105 .release = video_exclusive_release, 117 .release = maxiradio_exclusive_release,
106 .ioctl = video_ioctl2, 118 .ioctl = video_ioctl2,
107#ifdef CONFIG_COMPAT 119#ifdef CONFIG_COMPAT
108 .compat_ioctl = v4l_compat_ioctl32, 120 .compat_ioctl = v4l_compat_ioctl32,
@@ -219,8 +231,7 @@ static int vidioc_querycap (struct file *file, void *priv,
219static int vidioc_g_tuner (struct file *file, void *priv, 231static int vidioc_g_tuner (struct file *file, void *priv,
220 struct v4l2_tuner *v) 232 struct v4l2_tuner *v)
221{ 233{
222 struct video_device *dev = video_devdata(file); 234 struct radio_device *card = video_drvdata(file);
223 struct radio_device *card=dev->priv;
224 235
225 if (v->index > 0) 236 if (v->index > 0)
226 return -EINVAL; 237 return -EINVAL;
@@ -290,8 +301,7 @@ static int vidioc_s_audio (struct file *file, void *priv,
290static int vidioc_s_frequency (struct file *file, void *priv, 301static int vidioc_s_frequency (struct file *file, void *priv,
291 struct v4l2_frequency *f) 302 struct v4l2_frequency *f)
292{ 303{
293 struct video_device *dev = video_devdata(file); 304 struct radio_device *card = video_drvdata(file);
294 struct radio_device *card=dev->priv;
295 305
296 if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) { 306 if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) {
297 dprintk(1, "radio freq (%d.%02d MHz) out of range (%d-%d)\n", 307 dprintk(1, "radio freq (%d.%02d MHz) out of range (%d-%d)\n",
@@ -312,8 +322,7 @@ static int vidioc_s_frequency (struct file *file, void *priv,
312static int vidioc_g_frequency (struct file *file, void *priv, 322static int vidioc_g_frequency (struct file *file, void *priv,
313 struct v4l2_frequency *f) 323 struct v4l2_frequency *f)
314{ 324{
315 struct video_device *dev = video_devdata(file); 325 struct radio_device *card = video_drvdata(file);
316 struct radio_device *card=dev->priv;
317 326
318 f->type = V4L2_TUNER_RADIO; 327 f->type = V4L2_TUNER_RADIO;
319 f->frequency = card->freq; 328 f->frequency = card->freq;
@@ -343,8 +352,7 @@ static int vidioc_queryctrl (struct file *file, void *priv,
343static int vidioc_g_ctrl (struct file *file, void *priv, 352static int vidioc_g_ctrl (struct file *file, void *priv,
344 struct v4l2_control *ctrl) 353 struct v4l2_control *ctrl)
345{ 354{
346 struct video_device *dev = video_devdata(file); 355 struct radio_device *card = video_drvdata(file);
347 struct radio_device *card=dev->priv;
348 356
349 switch (ctrl->id) { 357 switch (ctrl->id) {
350 case V4L2_CID_AUDIO_MUTE: 358 case V4L2_CID_AUDIO_MUTE:
@@ -358,8 +366,7 @@ static int vidioc_g_ctrl (struct file *file, void *priv,
358static int vidioc_s_ctrl (struct file *file, void *priv, 366static int vidioc_s_ctrl (struct file *file, void *priv,
359 struct v4l2_control *ctrl) 367 struct v4l2_control *ctrl)
360{ 368{
361 struct video_device *dev = video_devdata(file); 369 struct radio_device *card = video_drvdata(file);
362 struct radio_device *card=dev->priv;
363 370
364 switch (ctrl->id) { 371 switch (ctrl->id) {
365 case V4L2_CID_AUDIO_MUTE: 372 case V4L2_CID_AUDIO_MUTE:
@@ -390,9 +397,10 @@ static const struct v4l2_ioctl_ops maxiradio_ioctl_ops = {
390}; 397};
391 398
392static struct video_device maxiradio_radio = { 399static struct video_device maxiradio_radio = {
393 .name = "Maxi Radio FM2000 radio", 400 .name = "Maxi Radio FM2000 radio",
394 .fops = &maxiradio_fops, 401 .fops = &maxiradio_fops,
395 .ioctl_ops = &maxiradio_ioctl_ops, 402 .ioctl_ops = &maxiradio_ioctl_ops,
403 .release = video_device_release_empty,
396}; 404};
397 405
398static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 406static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
@@ -408,7 +416,7 @@ static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_d
408 416
409 radio_unit.io = pci_resource_start(pdev, 0); 417 radio_unit.io = pci_resource_start(pdev, 0);
410 mutex_init(&radio_unit.lock); 418 mutex_init(&radio_unit.lock);
411 maxiradio_radio.priv = &radio_unit; 419 video_set_drvdata(&maxiradio_radio, &radio_unit);
412 420
413 if (video_register_device(&maxiradio_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 421 if (video_register_device(&maxiradio_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
414 printk("radio-maxiradio: can't register device!"); 422 printk("radio-maxiradio: can't register device!");
diff --git a/drivers/media/radio/radio-mr800.c b/drivers/media/radio/radio-mr800.c
new file mode 100644
index 000000000000..a33717c48003
--- /dev/null
+++ b/drivers/media/radio/radio-mr800.c
@@ -0,0 +1,628 @@
1/*
2 * A driver for the AverMedia MR 800 USB FM radio. This device plugs
3 * into both the USB and an analog audio input, so this thing
4 * only deals with initialization and frequency setting, the
5 * audio data has to be handled by a sound driver.
6 *
7 * Copyright (c) 2008 Alexey Klimov <klimov.linux@gmail.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24/*
25 * Big thanks to authors of dsbr100.c and radio-si470x.c
26 *
27 * When work was looked pretty good, i discover this:
28 * http://av-usbradio.sourceforge.net/index.php
29 * http://sourceforge.net/projects/av-usbradio/
30 * Latest release of theirs project was in 2005.
31 * Probably, this driver could be improved trough using their
32 * achievements (specifications given).
33 * So, we have smth to begin with.
34 *
35 * History:
36 * Version 0.01: First working version.
37 * It's required to blacklist AverMedia USB Radio
38 * in usbhid/hid-quirks.c
39 *
40 * Many things to do:
41 * - Correct power managment of device (suspend & resume)
42 * - Make x86 independance (little-endian and big-endian stuff)
43 * - Add code for scanning and smooth tuning
44 * - Checked and add stereo&mono stuff
45 * - Add code for sensitivity value
46 * - Correct mistakes
47 * - In Japan another FREQ_MIN and FREQ_MAX
48 */
49
50/* kernel includes */
51#include <linux/kernel.h>
52#include <linux/module.h>
53#include <linux/init.h>
54#include <linux/slab.h>
55#include <linux/input.h>
56#include <linux/videodev2.h>
57#include <media/v4l2-common.h>
58#include <media/v4l2-ioctl.h>
59#include <linux/usb.h>
60#include <linux/version.h> /* for KERNEL_VERSION MACRO */
61
62/* driver and module definitions */
63#define DRIVER_AUTHOR "Alexey Klimov <klimov.linux@gmail.com>"
64#define DRIVER_DESC "AverMedia MR 800 USB FM radio driver"
65#define DRIVER_VERSION "0.01"
66#define RADIO_VERSION KERNEL_VERSION(0, 0, 1)
67
68MODULE_AUTHOR(DRIVER_AUTHOR);
69MODULE_DESCRIPTION(DRIVER_DESC);
70MODULE_LICENSE("GPL");
71
72#define USB_AMRADIO_VENDOR 0x07ca
73#define USB_AMRADIO_PRODUCT 0xb800
74
75/* Probably USB_TIMEOUT should be modified in module parameter */
76#define BUFFER_LENGTH 8
77#define USB_TIMEOUT 500
78
79/* Frequency limits in MHz -- these are European values. For Japanese
80devices, that would be 76 and 91. */
81#define FREQ_MIN 87.5
82#define FREQ_MAX 108.0
83#define FREQ_MUL 16000
84
85/* module parameter */
86static int radio_nr = -1;
87module_param(radio_nr, int, 0);
88MODULE_PARM_DESC(radio_nr, "Radio Nr");
89
90static struct v4l2_queryctrl radio_qctrl[] = {
91 {
92 .id = V4L2_CID_AUDIO_MUTE,
93 .name = "Mute",
94 .minimum = 0,
95 .maximum = 1,
96 .step = 1,
97 .default_value = 1,
98 .type = V4L2_CTRL_TYPE_BOOLEAN,
99 },
100/* HINT: the disabled controls are only here to satify kradio and such apps */
101 { .id = V4L2_CID_AUDIO_VOLUME,
102 .flags = V4L2_CTRL_FLAG_DISABLED,
103 },
104 {
105 .id = V4L2_CID_AUDIO_BALANCE,
106 .flags = V4L2_CTRL_FLAG_DISABLED,
107 },
108 {
109 .id = V4L2_CID_AUDIO_BASS,
110 .flags = V4L2_CTRL_FLAG_DISABLED,
111 },
112 {
113 .id = V4L2_CID_AUDIO_TREBLE,
114 .flags = V4L2_CTRL_FLAG_DISABLED,
115 },
116 {
117 .id = V4L2_CID_AUDIO_LOUDNESS,
118 .flags = V4L2_CTRL_FLAG_DISABLED,
119 },
120};
121
122static int usb_amradio_probe(struct usb_interface *intf,
123 const struct usb_device_id *id);
124static void usb_amradio_disconnect(struct usb_interface *intf);
125static int usb_amradio_open(struct inode *inode, struct file *file);
126static int usb_amradio_close(struct inode *inode, struct file *file);
127static int usb_amradio_suspend(struct usb_interface *intf,
128 pm_message_t message);
129static int usb_amradio_resume(struct usb_interface *intf);
130
131/* Data for one (physical) device */
132struct amradio_device {
133 /* reference to USB and video device */
134 struct usb_device *usbdev;
135 struct video_device *videodev;
136
137 unsigned char *buffer;
138 struct mutex lock; /* buffer locking */
139 int curfreq;
140 int stereo;
141 int users;
142 int removed;
143 int muted;
144};
145
146/* USB Device ID List */
147static struct usb_device_id usb_amradio_device_table[] = {
148 {USB_DEVICE_AND_INTERFACE_INFO(USB_AMRADIO_VENDOR, USB_AMRADIO_PRODUCT,
149 USB_CLASS_HID, 0, 0) },
150 { } /* Terminating entry */
151};
152
153MODULE_DEVICE_TABLE(usb, usb_amradio_device_table);
154
155/* USB subsystem interface */
156static struct usb_driver usb_amradio_driver = {
157 .name = "radio-mr800",
158 .probe = usb_amradio_probe,
159 .disconnect = usb_amradio_disconnect,
160 .suspend = usb_amradio_suspend,
161 .resume = usb_amradio_resume,
162 .reset_resume = usb_amradio_resume,
163 .id_table = usb_amradio_device_table,
164 .supports_autosuspend = 1,
165};
166
167/* switch on radio. Send 8 bytes to device. */
168static int amradio_start(struct amradio_device *radio)
169{
170 int retval;
171 int size;
172
173 mutex_lock(&radio->lock);
174
175 radio->buffer[0] = 0x00;
176 radio->buffer[1] = 0x55;
177 radio->buffer[2] = 0xaa;
178 radio->buffer[3] = 0x00;
179 radio->buffer[4] = 0xab;
180 radio->buffer[5] = 0x00;
181 radio->buffer[6] = 0x00;
182 radio->buffer[7] = 0x00;
183
184 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
185 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
186
187 if (retval) {
188 mutex_unlock(&radio->lock);
189 return retval;
190 }
191
192 mutex_unlock(&radio->lock);
193
194 radio->muted = 0;
195
196 return retval;
197}
198
199/* switch off radio */
200static int amradio_stop(struct amradio_device *radio)
201{
202 int retval;
203 int size;
204
205 mutex_lock(&radio->lock);
206
207 radio->buffer[0] = 0x00;
208 radio->buffer[1] = 0x55;
209 radio->buffer[2] = 0xaa;
210 radio->buffer[3] = 0x00;
211 radio->buffer[4] = 0xab;
212 radio->buffer[5] = 0x01;
213 radio->buffer[6] = 0x00;
214 radio->buffer[7] = 0x00;
215
216 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
217 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
218
219 if (retval) {
220 mutex_unlock(&radio->lock);
221 return retval;
222 }
223
224 mutex_unlock(&radio->lock);
225
226 radio->muted = 1;
227
228 return retval;
229}
230
231/* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */
232static int amradio_setfreq(struct amradio_device *radio, int freq)
233{
234 int retval;
235 int size;
236 unsigned short freq_send = 0x13 + (freq >> 3) / 25;
237
238 mutex_lock(&radio->lock);
239
240 radio->buffer[0] = 0x00;
241 radio->buffer[1] = 0x55;
242 radio->buffer[2] = 0xaa;
243 radio->buffer[3] = 0x03;
244 radio->buffer[4] = 0xa4;
245 radio->buffer[5] = 0x00;
246 radio->buffer[6] = 0x00;
247 radio->buffer[7] = 0x08;
248
249 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
250 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
251
252 if (retval) {
253 mutex_unlock(&radio->lock);
254 return retval;
255 }
256
257 /* frequency is calculated from freq_send and placed in first 2 bytes */
258 radio->buffer[0] = (freq_send >> 8) & 0xff;
259 radio->buffer[1] = freq_send & 0xff;
260 radio->buffer[2] = 0x01;
261 radio->buffer[3] = 0x00;
262 radio->buffer[4] = 0x00;
263 /* 5 and 6 bytes of buffer already = 0x00 */
264 radio->buffer[7] = 0x00;
265
266 retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
267 (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
268
269 if (retval) {
270 mutex_unlock(&radio->lock);
271 return retval;
272 }
273
274 mutex_unlock(&radio->lock);
275
276 radio->stereo = 0;
277
278 return retval;
279}
280
281/* USB subsystem interface begins here */
282
283/* handle unplugging of the device, release data structures
284if nothing keeps us from doing it. If something is still
285keeping us busy, the release callback of v4l will take care
286of releasing it. */
287static void usb_amradio_disconnect(struct usb_interface *intf)
288{
289 struct amradio_device *radio = usb_get_intfdata(intf);
290
291 usb_set_intfdata(intf, NULL);
292
293 if (radio) {
294 video_unregister_device(radio->videodev);
295 radio->videodev = NULL;
296 if (radio->users) {
297 kfree(radio->buffer);
298 kfree(radio);
299 } else {
300 radio->removed = 1;
301 }
302 }
303}
304
305/* vidioc_querycap - query device capabilities */
306static int vidioc_querycap(struct file *file, void *priv,
307 struct v4l2_capability *v)
308{
309 strlcpy(v->driver, "radio-mr800", sizeof(v->driver));
310 strlcpy(v->card, "AverMedia MR 800 USB FM Radio", sizeof(v->card));
311 sprintf(v->bus_info, "USB");
312 v->version = RADIO_VERSION;
313 v->capabilities = V4L2_CAP_TUNER;
314 return 0;
315}
316
317/* vidioc_g_tuner - get tuner attributes */
318static int vidioc_g_tuner(struct file *file, void *priv,
319 struct v4l2_tuner *v)
320{
321 struct amradio_device *radio = video_get_drvdata(video_devdata(file));
322
323 if (v->index > 0)
324 return -EINVAL;
325
326/* TODO: Add function which look is signal stereo or not
327 * amradio_getstat(radio);
328 */
329 radio->stereo = -1;
330 strcpy(v->name, "FM");
331 v->type = V4L2_TUNER_RADIO;
332 v->rangelow = FREQ_MIN * FREQ_MUL;
333 v->rangehigh = FREQ_MAX * FREQ_MUL;
334 v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
335 v->capability = V4L2_TUNER_CAP_LOW;
336 if (radio->stereo)
337 v->audmode = V4L2_TUNER_MODE_STEREO;
338 else
339 v->audmode = V4L2_TUNER_MODE_MONO;
340 v->signal = 0xffff; /* Can't get the signal strength, sad.. */
341 v->afc = 0; /* Don't know what is this */
342 return 0;
343}
344
345/* vidioc_s_tuner - set tuner attributes */
346static int vidioc_s_tuner(struct file *file, void *priv,
347 struct v4l2_tuner *v)
348{
349 if (v->index > 0)
350 return -EINVAL;
351 return 0;
352}
353
354/* vidioc_s_frequency - set tuner radio frequency */
355static int vidioc_s_frequency(struct file *file, void *priv,
356 struct v4l2_frequency *f)
357{
358 struct amradio_device *radio = video_get_drvdata(video_devdata(file));
359
360 radio->curfreq = f->frequency;
361 if (amradio_setfreq(radio, radio->curfreq) < 0)
362 warn("Set frequency failed");
363 return 0;
364}
365
366/* vidioc_g_frequency - get tuner radio frequency */
367static int vidioc_g_frequency(struct file *file, void *priv,
368 struct v4l2_frequency *f)
369{
370 struct amradio_device *radio = video_get_drvdata(video_devdata(file));
371
372 f->type = V4L2_TUNER_RADIO;
373 f->frequency = radio->curfreq;
374 return 0;
375}
376
377/* vidioc_queryctrl - enumerate control items */
378static int vidioc_queryctrl(struct file *file, void *priv,
379 struct v4l2_queryctrl *qc)
380{
381 int i;
382
383 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
384 if (qc->id && qc->id == radio_qctrl[i].id) {
385 memcpy(qc, &(radio_qctrl[i]),
386 sizeof(*qc));
387 return 0;
388 }
389 }
390 return -EINVAL;
391}
392
393/* vidioc_g_ctrl - get the value of a control */
394static int vidioc_g_ctrl(struct file *file, void *priv,
395 struct v4l2_control *ctrl)
396{
397 struct amradio_device *radio = video_get_drvdata(video_devdata(file));
398
399 switch (ctrl->id) {
400 case V4L2_CID_AUDIO_MUTE:
401 ctrl->value = radio->muted;
402 return 0;
403 }
404 return -EINVAL;
405}
406
407/* vidioc_s_ctrl - set the value of a control */
408static int vidioc_s_ctrl(struct file *file, void *priv,
409 struct v4l2_control *ctrl)
410{
411 struct amradio_device *radio = video_get_drvdata(video_devdata(file));
412
413 switch (ctrl->id) {
414 case V4L2_CID_AUDIO_MUTE:
415 if (ctrl->value) {
416 if (amradio_stop(radio) < 0) {
417 warn("amradio_stop() failed");
418 return -1;
419 }
420 } else {
421 if (amradio_start(radio) < 0) {
422 warn("amradio_start() failed");
423 return -1;
424 }
425 }
426 return 0;
427 }
428 return -EINVAL;
429}
430
431/* vidioc_g_audio - get audio attributes */
432static int vidioc_g_audio(struct file *file, void *priv,
433 struct v4l2_audio *a)
434{
435 if (a->index > 1)
436 return -EINVAL;
437
438 strcpy(a->name, "Radio");
439 a->capability = V4L2_AUDCAP_STEREO;
440 return 0;
441}
442
443/* vidioc_s_audio - set audio attributes */
444static int vidioc_s_audio(struct file *file, void *priv,
445 struct v4l2_audio *a)
446{
447 if (a->index != 0)
448 return -EINVAL;
449 return 0;
450}
451
452/* vidioc_g_input - get input */
453static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
454{
455 *i = 0;
456 return 0;
457}
458
459/* vidioc_s_input - set input */
460static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
461{
462 if (i != 0)
463 return -EINVAL;
464 return 0;
465}
466
467/* open device - amradio_start() and amradio_setfreq() */
468static int usb_amradio_open(struct inode *inode, struct file *file)
469{
470 struct amradio_device *radio = video_get_drvdata(video_devdata(file));
471
472 radio->users = 1;
473 radio->muted = 1;
474
475 if (amradio_start(radio) < 0) {
476 warn("Radio did not start up properly");
477 radio->users = 0;
478 return -EIO;
479 }
480 if (amradio_setfreq(radio, radio->curfreq) < 0)
481 warn("Set frequency failed");
482 return 0;
483}
484
485/*close device - free driver structures */
486static int usb_amradio_close(struct inode *inode, struct file *file)
487{
488 struct amradio_device *radio = video_get_drvdata(video_devdata(file));
489
490 if (!radio)
491 return -ENODEV;
492 radio->users = 0;
493 if (radio->removed) {
494 kfree(radio->buffer);
495 kfree(radio);
496 }
497 return 0;
498}
499
500/* Suspend device - stop device. Need to be checked and fixed */
501static int usb_amradio_suspend(struct usb_interface *intf, pm_message_t message)
502{
503 struct amradio_device *radio = usb_get_intfdata(intf);
504
505 if (amradio_stop(radio) < 0)
506 warn("amradio_stop() failed");
507
508 info("radio-mr800: Going into suspend..");
509
510 return 0;
511}
512
513/* Resume device - start device. Need to be checked and fixed */
514static int usb_amradio_resume(struct usb_interface *intf)
515{
516 struct amradio_device *radio = usb_get_intfdata(intf);
517
518 if (amradio_start(radio) < 0)
519 warn("amradio_start() failed");
520
521 info("radio-mr800: Coming out of suspend..");
522
523 return 0;
524}
525
526/* File system interface */
527static const struct file_operations usb_amradio_fops = {
528 .owner = THIS_MODULE,
529 .open = usb_amradio_open,
530 .release = usb_amradio_close,
531 .ioctl = video_ioctl2,
532#ifdef CONFIG_COMPAT
533 .compat_ioctl = v4l_compat_ioctl32,
534#endif
535 .llseek = no_llseek,
536};
537
538static const struct v4l2_ioctl_ops usb_amradio_ioctl_ops = {
539 .vidioc_querycap = vidioc_querycap,
540 .vidioc_g_tuner = vidioc_g_tuner,
541 .vidioc_s_tuner = vidioc_s_tuner,
542 .vidioc_g_frequency = vidioc_g_frequency,
543 .vidioc_s_frequency = vidioc_s_frequency,
544 .vidioc_queryctrl = vidioc_queryctrl,
545 .vidioc_g_ctrl = vidioc_g_ctrl,
546 .vidioc_s_ctrl = vidioc_s_ctrl,
547 .vidioc_g_audio = vidioc_g_audio,
548 .vidioc_s_audio = vidioc_s_audio,
549 .vidioc_g_input = vidioc_g_input,
550 .vidioc_s_input = vidioc_s_input,
551};
552
553/* V4L2 interface */
554static struct video_device amradio_videodev_template = {
555 .name = "AverMedia MR 800 USB FM Radio",
556 .fops = &usb_amradio_fops,
557 .ioctl_ops = &usb_amradio_ioctl_ops,
558 .release = video_device_release,
559};
560
561/* check if the device is present and register with v4l and
562usb if it is */
563static int usb_amradio_probe(struct usb_interface *intf,
564 const struct usb_device_id *id)
565{
566 struct amradio_device *radio;
567
568 radio = kmalloc(sizeof(struct amradio_device), GFP_KERNEL);
569
570 if (!(radio))
571 return -ENOMEM;
572
573 radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL);
574
575 if (!(radio->buffer)) {
576 kfree(radio);
577 return -ENOMEM;
578 }
579
580 radio->videodev = video_device_alloc();
581
582 if (!(radio->videodev)) {
583 kfree(radio->buffer);
584 kfree(radio);
585 return -ENOMEM;
586 }
587
588 memcpy(radio->videodev, &amradio_videodev_template,
589 sizeof(amradio_videodev_template));
590
591 radio->removed = 0;
592 radio->users = 0;
593 radio->usbdev = interface_to_usbdev(intf);
594 radio->curfreq = 95.16 * FREQ_MUL;
595
596 mutex_init(&radio->lock);
597
598 video_set_drvdata(radio->videodev, radio);
599 if (video_register_device(radio->videodev, VFL_TYPE_RADIO, radio_nr)) {
600 warn("Could not register video device");
601 video_device_release(radio->videodev);
602 kfree(radio->buffer);
603 kfree(radio);
604 return -EIO;
605 }
606
607 usb_set_intfdata(intf, radio);
608 return 0;
609}
610
611static int __init amradio_init(void)
612{
613 int retval = usb_register(&usb_amradio_driver);
614
615 info(DRIVER_VERSION " " DRIVER_DESC);
616 if (retval)
617 err("usb_register failed. Error number %d", retval);
618 return retval;
619}
620
621static void __exit amradio_exit(void)
622{
623 usb_deregister(&usb_amradio_driver);
624}
625
626module_init(amradio_init);
627module_exit(amradio_exit);
628
diff --git a/drivers/media/radio/radio-rtrack2.c b/drivers/media/radio/radio-rtrack2.c
index 6d820e2481e7..a67079777419 100644
--- a/drivers/media/radio/radio-rtrack2.c
+++ b/drivers/media/radio/radio-rtrack2.c
@@ -52,6 +52,7 @@ static spinlock_t lock;
52 52
53struct rt_device 53struct rt_device
54{ 54{
55 unsigned long in_use;
55 int port; 56 int port;
56 unsigned long curfreq; 57 unsigned long curfreq;
57 int muted; 58 int muted;
@@ -153,8 +154,7 @@ static int rt_getsigstr(struct rt_device *dev)
153static int vidioc_g_tuner(struct file *file, void *priv, 154static int vidioc_g_tuner(struct file *file, void *priv,
154 struct v4l2_tuner *v) 155 struct v4l2_tuner *v)
155{ 156{
156 struct video_device *dev = video_devdata(file); 157 struct rt_device *rt = video_drvdata(file);
157 struct rt_device *rt = dev->priv;
158 158
159 if (v->index > 0) 159 if (v->index > 0)
160 return -EINVAL; 160 return -EINVAL;
@@ -173,8 +173,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
173static int vidioc_s_frequency(struct file *file, void *priv, 173static int vidioc_s_frequency(struct file *file, void *priv,
174 struct v4l2_frequency *f) 174 struct v4l2_frequency *f)
175{ 175{
176 struct video_device *dev = video_devdata(file); 176 struct rt_device *rt = video_drvdata(file);
177 struct rt_device *rt = dev->priv;
178 177
179 rt->curfreq = f->frequency; 178 rt->curfreq = f->frequency;
180 rt_setfreq(rt, rt->curfreq); 179 rt_setfreq(rt, rt->curfreq);
@@ -184,8 +183,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
184static int vidioc_g_frequency(struct file *file, void *priv, 183static int vidioc_g_frequency(struct file *file, void *priv,
185 struct v4l2_frequency *f) 184 struct v4l2_frequency *f)
186{ 185{
187 struct video_device *dev = video_devdata(file); 186 struct rt_device *rt = video_drvdata(file);
188 struct rt_device *rt = dev->priv;
189 187
190 f->type = V4L2_TUNER_RADIO; 188 f->type = V4L2_TUNER_RADIO;
191 f->frequency = rt->curfreq; 189 f->frequency = rt->curfreq;
@@ -210,8 +208,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
210static int vidioc_g_ctrl(struct file *file, void *priv, 208static int vidioc_g_ctrl(struct file *file, void *priv,
211 struct v4l2_control *ctrl) 209 struct v4l2_control *ctrl)
212{ 210{
213 struct video_device *dev = video_devdata(file); 211 struct rt_device *rt = video_drvdata(file);
214 struct rt_device *rt = dev->priv;
215 212
216 switch (ctrl->id) { 213 switch (ctrl->id) {
217 case V4L2_CID_AUDIO_MUTE: 214 case V4L2_CID_AUDIO_MUTE:
@@ -230,8 +227,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
230static int vidioc_s_ctrl(struct file *file, void *priv, 227static int vidioc_s_ctrl(struct file *file, void *priv,
231 struct v4l2_control *ctrl) 228 struct v4l2_control *ctrl)
232{ 229{
233 struct video_device *dev = video_devdata(file); 230 struct rt_device *rt = video_drvdata(file);
234 struct rt_device *rt = dev->priv;
235 231
236 switch (ctrl->id) { 232 switch (ctrl->id) {
237 case V4L2_CID_AUDIO_MUTE: 233 case V4L2_CID_AUDIO_MUTE:
@@ -284,10 +280,21 @@ static int vidioc_s_audio(struct file *file, void *priv,
284 280
285static struct rt_device rtrack2_unit; 281static struct rt_device rtrack2_unit;
286 282
283static int rtrack2_exclusive_open(struct inode *inode, struct file *file)
284{
285 return test_and_set_bit(0, &rtrack2_unit.in_use) ? -EBUSY : 0;
286}
287
288static int rtrack2_exclusive_release(struct inode *inode, struct file *file)
289{
290 clear_bit(0, &rtrack2_unit.in_use);
291 return 0;
292}
293
287static const struct file_operations rtrack2_fops = { 294static const struct file_operations rtrack2_fops = {
288 .owner = THIS_MODULE, 295 .owner = THIS_MODULE,
289 .open = video_exclusive_open, 296 .open = rtrack2_exclusive_open,
290 .release = video_exclusive_release, 297 .release = rtrack2_exclusive_release,
291 .ioctl = video_ioctl2, 298 .ioctl = video_ioctl2,
292#ifdef CONFIG_COMPAT 299#ifdef CONFIG_COMPAT
293 .compat_ioctl = v4l_compat_ioctl32, 300 .compat_ioctl = v4l_compat_ioctl32,
@@ -314,6 +321,7 @@ static struct video_device rtrack2_radio = {
314 .name = "RadioTrack II radio", 321 .name = "RadioTrack II radio",
315 .fops = &rtrack2_fops, 322 .fops = &rtrack2_fops,
316 .ioctl_ops = &rtrack2_ioctl_ops, 323 .ioctl_ops = &rtrack2_ioctl_ops,
324 .release = video_device_release_empty,
317}; 325};
318 326
319static int __init rtrack2_init(void) 327static int __init rtrack2_init(void)
@@ -329,7 +337,7 @@ static int __init rtrack2_init(void)
329 return -EBUSY; 337 return -EBUSY;
330 } 338 }
331 339
332 rtrack2_radio.priv=&rtrack2_unit; 340 video_set_drvdata(&rtrack2_radio, &rtrack2_unit);
333 341
334 spin_lock_init(&lock); 342 spin_lock_init(&lock);
335 if (video_register_device(&rtrack2_radio, VFL_TYPE_RADIO, radio_nr) < 0) { 343 if (video_register_device(&rtrack2_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
diff --git a/drivers/media/radio/radio-sf16fmi.c b/drivers/media/radio/radio-sf16fmi.c
index 0d478f54a907..329c90bddadd 100644
--- a/drivers/media/radio/radio-sf16fmi.c
+++ b/drivers/media/radio/radio-sf16fmi.c
@@ -45,6 +45,7 @@ static struct v4l2_queryctrl radio_qctrl[] = {
45 45
46struct fmi_device 46struct fmi_device
47{ 47{
48 unsigned long in_use;
48 int port; 49 int port;
49 int curvol; /* 1 or 0 */ 50 int curvol; /* 1 or 0 */
50 unsigned long curfreq; /* freq in kHz */ 51 unsigned long curfreq; /* freq in kHz */
@@ -146,8 +147,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
146 struct v4l2_tuner *v) 147 struct v4l2_tuner *v)
147{ 148{
148 int mult; 149 int mult;
149 struct video_device *dev = video_devdata(file); 150 struct fmi_device *fmi = video_drvdata(file);
150 struct fmi_device *fmi = dev->priv;
151 151
152 if (v->index > 0) 152 if (v->index > 0)
153 return -EINVAL; 153 return -EINVAL;
@@ -175,8 +175,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
175static int vidioc_s_frequency(struct file *file, void *priv, 175static int vidioc_s_frequency(struct file *file, void *priv,
176 struct v4l2_frequency *f) 176 struct v4l2_frequency *f)
177{ 177{
178 struct video_device *dev = video_devdata(file); 178 struct fmi_device *fmi = video_drvdata(file);
179 struct fmi_device *fmi = dev->priv;
180 179
181 if (!(fmi->flags & V4L2_TUNER_CAP_LOW)) 180 if (!(fmi->flags & V4L2_TUNER_CAP_LOW))
182 f->frequency *= 1000; 181 f->frequency *= 1000;
@@ -193,8 +192,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
193static int vidioc_g_frequency(struct file *file, void *priv, 192static int vidioc_g_frequency(struct file *file, void *priv,
194 struct v4l2_frequency *f) 193 struct v4l2_frequency *f)
195{ 194{
196 struct video_device *dev = video_devdata(file); 195 struct fmi_device *fmi = video_drvdata(file);
197 struct fmi_device *fmi = dev->priv;
198 196
199 f->type = V4L2_TUNER_RADIO; 197 f->type = V4L2_TUNER_RADIO;
200 f->frequency = fmi->curfreq; 198 f->frequency = fmi->curfreq;
@@ -221,8 +219,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
221static int vidioc_g_ctrl(struct file *file, void *priv, 219static int vidioc_g_ctrl(struct file *file, void *priv,
222 struct v4l2_control *ctrl) 220 struct v4l2_control *ctrl)
223{ 221{
224 struct video_device *dev = video_devdata(file); 222 struct fmi_device *fmi = video_drvdata(file);
225 struct fmi_device *fmi = dev->priv;
226 223
227 switch (ctrl->id) { 224 switch (ctrl->id) {
228 case V4L2_CID_AUDIO_MUTE: 225 case V4L2_CID_AUDIO_MUTE:
@@ -235,8 +232,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
235static int vidioc_s_ctrl(struct file *file, void *priv, 232static int vidioc_s_ctrl(struct file *file, void *priv,
236 struct v4l2_control *ctrl) 233 struct v4l2_control *ctrl)
237{ 234{
238 struct video_device *dev = video_devdata(file); 235 struct fmi_device *fmi = video_drvdata(file);
239 struct fmi_device *fmi = dev->priv;
240 236
241 switch (ctrl->id) { 237 switch (ctrl->id) {
242 case V4L2_CID_AUDIO_MUTE: 238 case V4L2_CID_AUDIO_MUTE:
@@ -284,10 +280,21 @@ static int vidioc_s_audio(struct file *file, void *priv,
284 280
285static struct fmi_device fmi_unit; 281static struct fmi_device fmi_unit;
286 282
283static int fmi_exclusive_open(struct inode *inode, struct file *file)
284{
285 return test_and_set_bit(0, &fmi_unit.in_use) ? -EBUSY : 0;
286}
287
288static int fmi_exclusive_release(struct inode *inode, struct file *file)
289{
290 clear_bit(0, &fmi_unit.in_use);
291 return 0;
292}
293
287static const struct file_operations fmi_fops = { 294static const struct file_operations fmi_fops = {
288 .owner = THIS_MODULE, 295 .owner = THIS_MODULE,
289 .open = video_exclusive_open, 296 .open = fmi_exclusive_open,
290 .release = video_exclusive_release, 297 .release = fmi_exclusive_release,
291 .ioctl = video_ioctl2, 298 .ioctl = video_ioctl2,
292#ifdef CONFIG_COMPAT 299#ifdef CONFIG_COMPAT
293 .compat_ioctl = v4l_compat_ioctl32, 300 .compat_ioctl = v4l_compat_ioctl32,
@@ -314,6 +321,7 @@ static struct video_device fmi_radio = {
314 .name = "SF16FMx radio", 321 .name = "SF16FMx radio",
315 .fops = &fmi_fops, 322 .fops = &fmi_fops,
316 .ioctl_ops = &fmi_ioctl_ops, 323 .ioctl_ops = &fmi_ioctl_ops,
324 .release = video_device_release_empty,
317}; 325};
318 326
319/* ladis: this is my card. does any other types exist? */ 327/* ladis: this is my card. does any other types exist? */
@@ -373,7 +381,7 @@ static int __init fmi_init(void)
373 fmi_unit.curvol = 0; 381 fmi_unit.curvol = 0;
374 fmi_unit.curfreq = 0; 382 fmi_unit.curfreq = 0;
375 fmi_unit.flags = V4L2_TUNER_CAP_LOW; 383 fmi_unit.flags = V4L2_TUNER_CAP_LOW;
376 fmi_radio.priv = &fmi_unit; 384 video_set_drvdata(&fmi_radio, &fmi_unit);
377 385
378 mutex_init(&lock); 386 mutex_init(&lock);
379 387
diff --git a/drivers/media/radio/radio-sf16fmr2.c b/drivers/media/radio/radio-sf16fmr2.c
index 6290553d24be..b1f47c322e02 100644
--- a/drivers/media/radio/radio-sf16fmr2.c
+++ b/drivers/media/radio/radio-sf16fmr2.c
@@ -64,6 +64,7 @@ static struct v4l2_queryctrl radio_qctrl[] = {
64/* this should be static vars for module size */ 64/* this should be static vars for module size */
65struct fmr2_device 65struct fmr2_device
66{ 66{
67 unsigned long in_use;
67 int port; 68 int port;
68 int curvol; /* 0-15 */ 69 int curvol; /* 0-15 */
69 int mute; 70 int mute;
@@ -229,8 +230,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
229 struct v4l2_tuner *v) 230 struct v4l2_tuner *v)
230{ 231{
231 int mult; 232 int mult;
232 struct video_device *dev = video_devdata(file); 233 struct fmr2_device *fmr2 = video_drvdata(file);
233 struct fmr2_device *fmr2 = dev->priv;
234 234
235 if (v->index > 0) 235 if (v->index > 0)
236 return -EINVAL; 236 return -EINVAL;
@@ -262,8 +262,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
262static int vidioc_s_frequency(struct file *file, void *priv, 262static int vidioc_s_frequency(struct file *file, void *priv,
263 struct v4l2_frequency *f) 263 struct v4l2_frequency *f)
264{ 264{
265 struct video_device *dev = video_devdata(file); 265 struct fmr2_device *fmr2 = video_drvdata(file);
266 struct fmr2_device *fmr2 = dev->priv;
267 266
268 if (!(fmr2->flags & V4L2_TUNER_CAP_LOW)) 267 if (!(fmr2->flags & V4L2_TUNER_CAP_LOW))
269 f->frequency *= 1000; 268 f->frequency *= 1000;
@@ -286,8 +285,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
286static int vidioc_g_frequency(struct file *file, void *priv, 285static int vidioc_g_frequency(struct file *file, void *priv,
287 struct v4l2_frequency *f) 286 struct v4l2_frequency *f)
288{ 287{
289 struct video_device *dev = video_devdata(file); 288 struct fmr2_device *fmr2 = video_drvdata(file);
290 struct fmr2_device *fmr2 = dev->priv;
291 289
292 f->type = V4L2_TUNER_RADIO; 290 f->type = V4L2_TUNER_RADIO;
293 f->frequency = fmr2->curfreq; 291 f->frequency = fmr2->curfreq;
@@ -313,8 +311,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
313static int vidioc_g_ctrl(struct file *file, void *priv, 311static int vidioc_g_ctrl(struct file *file, void *priv,
314 struct v4l2_control *ctrl) 312 struct v4l2_control *ctrl)
315{ 313{
316 struct video_device *dev = video_devdata(file); 314 struct fmr2_device *fmr2 = video_drvdata(file);
317 struct fmr2_device *fmr2 = dev->priv;
318 315
319 switch (ctrl->id) { 316 switch (ctrl->id) {
320 case V4L2_CID_AUDIO_MUTE: 317 case V4L2_CID_AUDIO_MUTE:
@@ -330,8 +327,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
330static int vidioc_s_ctrl(struct file *file, void *priv, 327static int vidioc_s_ctrl(struct file *file, void *priv,
331 struct v4l2_control *ctrl) 328 struct v4l2_control *ctrl)
332{ 329{
333 struct video_device *dev = video_devdata(file); 330 struct fmr2_device *fmr2 = video_drvdata(file);
334 struct fmr2_device *fmr2 = dev->priv;
335 331
336 switch (ctrl->id) { 332 switch (ctrl->id) {
337 case V4L2_CID_AUDIO_MUTE: 333 case V4L2_CID_AUDIO_MUTE:
@@ -400,10 +396,21 @@ static int vidioc_s_audio(struct file *file, void *priv,
400 396
401static struct fmr2_device fmr2_unit; 397static struct fmr2_device fmr2_unit;
402 398
399static int fmr2_exclusive_open(struct inode *inode, struct file *file)
400{
401 return test_and_set_bit(0, &fmr2_unit.in_use) ? -EBUSY : 0;
402}
403
404static int fmr2_exclusive_release(struct inode *inode, struct file *file)
405{
406 clear_bit(0, &fmr2_unit.in_use);
407 return 0;
408}
409
403static const struct file_operations fmr2_fops = { 410static const struct file_operations fmr2_fops = {
404 .owner = THIS_MODULE, 411 .owner = THIS_MODULE,
405 .open = video_exclusive_open, 412 .open = fmr2_exclusive_open,
406 .release = video_exclusive_release, 413 .release = fmr2_exclusive_release,
407 .ioctl = video_ioctl2, 414 .ioctl = video_ioctl2,
408#ifdef CONFIG_COMPAT 415#ifdef CONFIG_COMPAT
409 .compat_ioctl = v4l_compat_ioctl32, 416 .compat_ioctl = v4l_compat_ioctl32,
@@ -430,6 +437,7 @@ static struct video_device fmr2_radio = {
430 .name = "SF16FMR2 radio", 437 .name = "SF16FMR2 radio",
431 .fops = &fmr2_fops, 438 .fops = &fmr2_fops,
432 .ioctl_ops = &fmr2_ioctl_ops, 439 .ioctl_ops = &fmr2_ioctl_ops,
440 .release = video_device_release_empty,
433}; 441};
434 442
435static int __init fmr2_init(void) 443static int __init fmr2_init(void)
@@ -441,7 +449,7 @@ static int __init fmr2_init(void)
441 fmr2_unit.stereo = 1; 449 fmr2_unit.stereo = 1;
442 fmr2_unit.flags = V4L2_TUNER_CAP_LOW; 450 fmr2_unit.flags = V4L2_TUNER_CAP_LOW;
443 fmr2_unit.card_type = 0; 451 fmr2_unit.card_type = 0;
444 fmr2_radio.priv = &fmr2_unit; 452 video_set_drvdata(&fmr2_radio, &fmr2_unit);
445 453
446 mutex_init(&lock); 454 mutex_init(&lock);
447 455
diff --git a/drivers/media/radio/radio-si470x.c b/drivers/media/radio/radio-si470x.c
index 16c7ef20265c..f6cedcd3ab97 100644
--- a/drivers/media/radio/radio-si470x.c
+++ b/drivers/media/radio/radio-si470x.c
@@ -986,7 +986,7 @@ static void si470x_work(struct work_struct *work)
986static ssize_t si470x_fops_read(struct file *file, char __user *buf, 986static ssize_t si470x_fops_read(struct file *file, char __user *buf,
987 size_t count, loff_t *ppos) 987 size_t count, loff_t *ppos)
988{ 988{
989 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 989 struct si470x_device *radio = video_drvdata(file);
990 int retval = 0; 990 int retval = 0;
991 unsigned int block_count = 0; 991 unsigned int block_count = 0;
992 992
@@ -1047,7 +1047,7 @@ done:
1047static unsigned int si470x_fops_poll(struct file *file, 1047static unsigned int si470x_fops_poll(struct file *file,
1048 struct poll_table_struct *pts) 1048 struct poll_table_struct *pts)
1049{ 1049{
1050 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 1050 struct si470x_device *radio = video_drvdata(file);
1051 int retval = 0; 1051 int retval = 0;
1052 1052
1053 /* switch on rds reception */ 1053 /* switch on rds reception */
@@ -1071,9 +1071,10 @@ static unsigned int si470x_fops_poll(struct file *file,
1071 */ 1071 */
1072static int si470x_fops_open(struct inode *inode, struct file *file) 1072static int si470x_fops_open(struct inode *inode, struct file *file)
1073{ 1073{
1074 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 1074 struct si470x_device *radio = video_drvdata(file);
1075 int retval; 1075 int retval;
1076 1076
1077 lock_kernel();
1077 radio->users++; 1078 radio->users++;
1078 1079
1079 retval = usb_autopm_get_interface(radio->intf); 1080 retval = usb_autopm_get_interface(radio->intf);
@@ -1090,6 +1091,7 @@ static int si470x_fops_open(struct inode *inode, struct file *file)
1090 } 1091 }
1091 1092
1092done: 1093done:
1094 unlock_kernel();
1093 return retval; 1095 return retval;
1094} 1096}
1095 1097
@@ -1099,7 +1101,7 @@ done:
1099 */ 1101 */
1100static int si470x_fops_release(struct inode *inode, struct file *file) 1102static int si470x_fops_release(struct inode *inode, struct file *file)
1101{ 1103{
1102 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 1104 struct si470x_device *radio = video_drvdata(file);
1103 int retval = 0; 1105 int retval = 0;
1104 1106
1105 /* safety check */ 1107 /* safety check */
@@ -1282,7 +1284,7 @@ done:
1282static int si470x_vidioc_g_ctrl(struct file *file, void *priv, 1284static int si470x_vidioc_g_ctrl(struct file *file, void *priv,
1283 struct v4l2_control *ctrl) 1285 struct v4l2_control *ctrl)
1284{ 1286{
1285 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 1287 struct si470x_device *radio = video_drvdata(file);
1286 int retval = 0; 1288 int retval = 0;
1287 1289
1288 /* safety checks */ 1290 /* safety checks */
@@ -1318,7 +1320,7 @@ done:
1318static int si470x_vidioc_s_ctrl(struct file *file, void *priv, 1320static int si470x_vidioc_s_ctrl(struct file *file, void *priv,
1319 struct v4l2_control *ctrl) 1321 struct v4l2_control *ctrl)
1320{ 1322{
1321 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 1323 struct si470x_device *radio = video_drvdata(file);
1322 int retval = 0; 1324 int retval = 0;
1323 1325
1324 /* safety checks */ 1326 /* safety checks */
@@ -1405,7 +1407,7 @@ done:
1405static int si470x_vidioc_g_tuner(struct file *file, void *priv, 1407static int si470x_vidioc_g_tuner(struct file *file, void *priv,
1406 struct v4l2_tuner *tuner) 1408 struct v4l2_tuner *tuner)
1407{ 1409{
1408 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 1410 struct si470x_device *radio = video_drvdata(file);
1409 int retval = 0; 1411 int retval = 0;
1410 1412
1411 /* safety checks */ 1413 /* safety checks */
@@ -1471,7 +1473,7 @@ done:
1471static int si470x_vidioc_s_tuner(struct file *file, void *priv, 1473static int si470x_vidioc_s_tuner(struct file *file, void *priv,
1472 struct v4l2_tuner *tuner) 1474 struct v4l2_tuner *tuner)
1473{ 1475{
1474 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 1476 struct si470x_device *radio = video_drvdata(file);
1475 int retval = 0; 1477 int retval = 0;
1476 1478
1477 /* safety checks */ 1479 /* safety checks */
@@ -1505,7 +1507,7 @@ done:
1505static int si470x_vidioc_g_frequency(struct file *file, void *priv, 1507static int si470x_vidioc_g_frequency(struct file *file, void *priv,
1506 struct v4l2_frequency *freq) 1508 struct v4l2_frequency *freq)
1507{ 1509{
1508 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 1510 struct si470x_device *radio = video_drvdata(file);
1509 int retval = 0; 1511 int retval = 0;
1510 1512
1511 /* safety checks */ 1513 /* safety checks */
@@ -1534,7 +1536,7 @@ done:
1534static int si470x_vidioc_s_frequency(struct file *file, void *priv, 1536static int si470x_vidioc_s_frequency(struct file *file, void *priv,
1535 struct v4l2_frequency *freq) 1537 struct v4l2_frequency *freq)
1536{ 1538{
1537 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 1539 struct si470x_device *radio = video_drvdata(file);
1538 int retval = 0; 1540 int retval = 0;
1539 1541
1540 /* safety checks */ 1542 /* safety checks */
@@ -1563,7 +1565,7 @@ done:
1563static int si470x_vidioc_s_hw_freq_seek(struct file *file, void *priv, 1565static int si470x_vidioc_s_hw_freq_seek(struct file *file, void *priv,
1564 struct v4l2_hw_freq_seek *seek) 1566 struct v4l2_hw_freq_seek *seek)
1565{ 1567{
1566 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 1568 struct si470x_device *radio = video_drvdata(file);
1567 int retval = 0; 1569 int retval = 0;
1568 1570
1569 /* safety checks */ 1571 /* safety checks */
diff --git a/drivers/media/radio/radio-terratec.c b/drivers/media/radio/radio-terratec.c
index 0876fecc5f27..0abb186a9473 100644
--- a/drivers/media/radio/radio-terratec.c
+++ b/drivers/media/radio/radio-terratec.c
@@ -79,6 +79,7 @@ static spinlock_t lock;
79 79
80struct tt_device 80struct tt_device
81{ 81{
82 unsigned long in_use;
82 int port; 83 int port;
83 int curvol; 84 int curvol;
84 unsigned long curfreq; 85 unsigned long curfreq;
@@ -220,8 +221,7 @@ static int vidioc_querycap(struct file *file, void *priv,
220static int vidioc_g_tuner(struct file *file, void *priv, 221static int vidioc_g_tuner(struct file *file, void *priv,
221 struct v4l2_tuner *v) 222 struct v4l2_tuner *v)
222{ 223{
223 struct video_device *dev = video_devdata(file); 224 struct tt_device *tt = video_drvdata(file);
224 struct tt_device *tt = dev->priv;
225 225
226 if (v->index > 0) 226 if (v->index > 0)
227 return -EINVAL; 227 return -EINVAL;
@@ -248,8 +248,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
248static int vidioc_s_frequency(struct file *file, void *priv, 248static int vidioc_s_frequency(struct file *file, void *priv,
249 struct v4l2_frequency *f) 249 struct v4l2_frequency *f)
250{ 250{
251 struct video_device *dev = video_devdata(file); 251 struct tt_device *tt = video_drvdata(file);
252 struct tt_device *tt = dev->priv;
253 252
254 tt->curfreq = f->frequency; 253 tt->curfreq = f->frequency;
255 tt_setfreq(tt, tt->curfreq); 254 tt_setfreq(tt, tt->curfreq);
@@ -259,8 +258,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
259static int vidioc_g_frequency(struct file *file, void *priv, 258static int vidioc_g_frequency(struct file *file, void *priv,
260 struct v4l2_frequency *f) 259 struct v4l2_frequency *f)
261{ 260{
262 struct video_device *dev = video_devdata(file); 261 struct tt_device *tt = video_drvdata(file);
263 struct tt_device *tt = dev->priv;
264 262
265 f->type = V4L2_TUNER_RADIO; 263 f->type = V4L2_TUNER_RADIO;
266 f->frequency = tt->curfreq; 264 f->frequency = tt->curfreq;
@@ -285,8 +283,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
285static int vidioc_g_ctrl(struct file *file, void *priv, 283static int vidioc_g_ctrl(struct file *file, void *priv,
286 struct v4l2_control *ctrl) 284 struct v4l2_control *ctrl)
287{ 285{
288 struct video_device *dev = video_devdata(file); 286 struct tt_device *tt = video_drvdata(file);
289 struct tt_device *tt = dev->priv;
290 287
291 switch (ctrl->id) { 288 switch (ctrl->id) {
292 case V4L2_CID_AUDIO_MUTE: 289 case V4L2_CID_AUDIO_MUTE:
@@ -305,8 +302,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
305static int vidioc_s_ctrl(struct file *file, void *priv, 302static int vidioc_s_ctrl(struct file *file, void *priv,
306 struct v4l2_control *ctrl) 303 struct v4l2_control *ctrl)
307{ 304{
308 struct video_device *dev = video_devdata(file); 305 struct tt_device *tt = video_drvdata(file);
309 struct tt_device *tt = dev->priv;
310 306
311 switch (ctrl->id) { 307 switch (ctrl->id) {
312 case V4L2_CID_AUDIO_MUTE: 308 case V4L2_CID_AUDIO_MUTE:
@@ -356,10 +352,21 @@ static int vidioc_s_audio(struct file *file, void *priv,
356 352
357static struct tt_device terratec_unit; 353static struct tt_device terratec_unit;
358 354
355static int terratec_exclusive_open(struct inode *inode, struct file *file)
356{
357 return test_and_set_bit(0, &terratec_unit.in_use) ? -EBUSY : 0;
358}
359
360static int terratec_exclusive_release(struct inode *inode, struct file *file)
361{
362 clear_bit(0, &terratec_unit.in_use);
363 return 0;
364}
365
359static const struct file_operations terratec_fops = { 366static const struct file_operations terratec_fops = {
360 .owner = THIS_MODULE, 367 .owner = THIS_MODULE,
361 .open = video_exclusive_open, 368 .open = terratec_exclusive_open,
362 .release = video_exclusive_release, 369 .release = terratec_exclusive_release,
363 .ioctl = video_ioctl2, 370 .ioctl = video_ioctl2,
364#ifdef CONFIG_COMPAT 371#ifdef CONFIG_COMPAT
365 .compat_ioctl = v4l_compat_ioctl32, 372 .compat_ioctl = v4l_compat_ioctl32,
@@ -386,6 +393,7 @@ static struct video_device terratec_radio = {
386 .name = "TerraTec ActiveRadio", 393 .name = "TerraTec ActiveRadio",
387 .fops = &terratec_fops, 394 .fops = &terratec_fops,
388 .ioctl_ops = &terratec_ioctl_ops, 395 .ioctl_ops = &terratec_ioctl_ops,
396 .release = video_device_release_empty,
389}; 397};
390 398
391static int __init terratec_init(void) 399static int __init terratec_init(void)
@@ -401,7 +409,7 @@ static int __init terratec_init(void)
401 return -EBUSY; 409 return -EBUSY;
402 } 410 }
403 411
404 terratec_radio.priv=&terratec_unit; 412 video_set_drvdata(&terratec_radio, &terratec_unit);
405 413
406 spin_lock_init(&lock); 414 spin_lock_init(&lock);
407 415
diff --git a/drivers/media/radio/radio-trust.c b/drivers/media/radio/radio-trust.c
index 193161956253..e7b111fcd105 100644
--- a/drivers/media/radio/radio-trust.c
+++ b/drivers/media/radio/radio-trust.c
@@ -78,6 +78,7 @@ static __u16 curtreble;
78static unsigned long curfreq; 78static unsigned long curfreq;
79static int curstereo; 79static int curstereo;
80static int curmute; 80static int curmute;
81static unsigned long in_use;
81 82
82/* i2c addresses */ 83/* i2c addresses */
83#define TDA7318_ADDR 0x88 84#define TDA7318_ADDR 0x88
@@ -336,10 +337,21 @@ static int vidioc_s_audio(struct file *file, void *priv,
336 return 0; 337 return 0;
337} 338}
338 339
340static int trust_exclusive_open(struct inode *inode, struct file *file)
341{
342 return test_and_set_bit(0, &in_use) ? -EBUSY : 0;
343}
344
345static int trust_exclusive_release(struct inode *inode, struct file *file)
346{
347 clear_bit(0, &in_use);
348 return 0;
349}
350
339static const struct file_operations trust_fops = { 351static const struct file_operations trust_fops = {
340 .owner = THIS_MODULE, 352 .owner = THIS_MODULE,
341 .open = video_exclusive_open, 353 .open = trust_exclusive_open,
342 .release = video_exclusive_release, 354 .release = trust_exclusive_release,
343 .ioctl = video_ioctl2, 355 .ioctl = video_ioctl2,
344#ifdef CONFIG_COMPAT 356#ifdef CONFIG_COMPAT
345 .compat_ioctl = v4l_compat_ioctl32, 357 .compat_ioctl = v4l_compat_ioctl32,
@@ -366,6 +378,7 @@ static struct video_device trust_radio = {
366 .name = "Trust FM Radio", 378 .name = "Trust FM Radio",
367 .fops = &trust_fops, 379 .fops = &trust_fops,
368 .ioctl_ops = &trust_ioctl_ops, 380 .ioctl_ops = &trust_ioctl_ops,
381 .release = video_device_release_empty,
369}; 382};
370 383
371static int __init trust_init(void) 384static int __init trust_init(void)
diff --git a/drivers/media/radio/radio-typhoon.c b/drivers/media/radio/radio-typhoon.c
index f8d62cfea774..952ec35a8415 100644
--- a/drivers/media/radio/radio-typhoon.c
+++ b/drivers/media/radio/radio-typhoon.c
@@ -79,7 +79,7 @@ static struct v4l2_queryctrl radio_qctrl[] = {
79#endif 79#endif
80 80
81struct typhoon_device { 81struct typhoon_device {
82 int users; 82 unsigned long in_use;
83 int iobase; 83 int iobase;
84 int curvol; 84 int curvol;
85 int muted; 85 int muted;
@@ -223,8 +223,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
223static int vidioc_s_frequency(struct file *file, void *priv, 223static int vidioc_s_frequency(struct file *file, void *priv,
224 struct v4l2_frequency *f) 224 struct v4l2_frequency *f)
225{ 225{
226 struct video_device *dev = video_devdata(file); 226 struct typhoon_device *typhoon = video_drvdata(file);
227 struct typhoon_device *typhoon = dev->priv;
228 227
229 typhoon->curfreq = f->frequency; 228 typhoon->curfreq = f->frequency;
230 typhoon_setfreq(typhoon, typhoon->curfreq); 229 typhoon_setfreq(typhoon, typhoon->curfreq);
@@ -234,8 +233,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
234static int vidioc_g_frequency(struct file *file, void *priv, 233static int vidioc_g_frequency(struct file *file, void *priv,
235 struct v4l2_frequency *f) 234 struct v4l2_frequency *f)
236{ 235{
237 struct video_device *dev = video_devdata(file); 236 struct typhoon_device *typhoon = video_drvdata(file);
238 struct typhoon_device *typhoon = dev->priv;
239 237
240 f->type = V4L2_TUNER_RADIO; 238 f->type = V4L2_TUNER_RADIO;
241 f->frequency = typhoon->curfreq; 239 f->frequency = typhoon->curfreq;
@@ -261,8 +259,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
261static int vidioc_g_ctrl(struct file *file, void *priv, 259static int vidioc_g_ctrl(struct file *file, void *priv,
262 struct v4l2_control *ctrl) 260 struct v4l2_control *ctrl)
263{ 261{
264 struct video_device *dev = video_devdata(file); 262 struct typhoon_device *typhoon = video_drvdata(file);
265 struct typhoon_device *typhoon = dev->priv;
266 263
267 switch (ctrl->id) { 264 switch (ctrl->id) {
268 case V4L2_CID_AUDIO_MUTE: 265 case V4L2_CID_AUDIO_MUTE:
@@ -278,8 +275,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
278static int vidioc_s_ctrl (struct file *file, void *priv, 275static int vidioc_s_ctrl (struct file *file, void *priv,
279 struct v4l2_control *ctrl) 276 struct v4l2_control *ctrl)
280{ 277{
281 struct video_device *dev = video_devdata(file); 278 struct typhoon_device *typhoon = video_drvdata(file);
282 struct typhoon_device *typhoon = dev->priv;
283 279
284 switch (ctrl->id) { 280 switch (ctrl->id) {
285 case V4L2_CID_AUDIO_MUTE: 281 case V4L2_CID_AUDIO_MUTE:
@@ -334,10 +330,21 @@ static struct typhoon_device typhoon_unit =
334 .mutefreq = CONFIG_RADIO_TYPHOON_MUTEFREQ, 330 .mutefreq = CONFIG_RADIO_TYPHOON_MUTEFREQ,
335}; 331};
336 332
333static int typhoon_exclusive_open(struct inode *inode, struct file *file)
334{
335 return test_and_set_bit(0, &typhoon_unit.in_use) ? -EBUSY : 0;
336}
337
338static int typhoon_exclusive_release(struct inode *inode, struct file *file)
339{
340 clear_bit(0, &typhoon_unit.in_use);
341 return 0;
342}
343
337static const struct file_operations typhoon_fops = { 344static const struct file_operations typhoon_fops = {
338 .owner = THIS_MODULE, 345 .owner = THIS_MODULE,
339 .open = video_exclusive_open, 346 .open = typhoon_exclusive_open,
340 .release = video_exclusive_release, 347 .release = typhoon_exclusive_release,
341 .ioctl = video_ioctl2, 348 .ioctl = video_ioctl2,
342#ifdef CONFIG_COMPAT 349#ifdef CONFIG_COMPAT
343 .compat_ioctl = v4l_compat_ioctl32, 350 .compat_ioctl = v4l_compat_ioctl32,
@@ -364,6 +371,7 @@ static struct video_device typhoon_radio = {
364 .name = "Typhoon Radio", 371 .name = "Typhoon Radio",
365 .fops = &typhoon_fops, 372 .fops = &typhoon_fops,
366 .ioctl_ops = &typhoon_ioctl_ops, 373 .ioctl_ops = &typhoon_ioctl_ops,
374 .release = video_device_release_empty,
367}; 375};
368 376
369#ifdef CONFIG_RADIO_TYPHOON_PROC_FS 377#ifdef CONFIG_RADIO_TYPHOON_PROC_FS
@@ -446,9 +454,8 @@ static int __init typhoon_init(void)
446 return -EBUSY; 454 return -EBUSY;
447 } 455 }
448 456
449 typhoon_radio.priv = &typhoon_unit; 457 video_set_drvdata(&typhoon_radio, &typhoon_unit);
450 if (video_register_device(&typhoon_radio, VFL_TYPE_RADIO, radio_nr) == -1) 458 if (video_register_device(&typhoon_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
451 {
452 release_region(io, 8); 459 release_region(io, 8);
453 return -EINVAL; 460 return -EINVAL;
454 } 461 }
diff --git a/drivers/media/radio/radio-zoltrix.c b/drivers/media/radio/radio-zoltrix.c
index 51d57ed3b3e1..15b10bad6796 100644
--- a/drivers/media/radio/radio-zoltrix.c
+++ b/drivers/media/radio/radio-zoltrix.c
@@ -69,6 +69,7 @@ static int io = CONFIG_RADIO_ZOLTRIX_PORT;
69static int radio_nr = -1; 69static int radio_nr = -1;
70 70
71struct zol_device { 71struct zol_device {
72 unsigned long in_use;
72 int port; 73 int port;
73 int curvol; 74 int curvol;
74 unsigned long curfreq; 75 unsigned long curfreq;
@@ -122,8 +123,11 @@ static int zol_setfreq(struct zol_device *dev, unsigned long freq)
122 unsigned int stereo = dev->stereo; 123 unsigned int stereo = dev->stereo;
123 int i; 124 int i;
124 125
125 if (freq == 0) 126 if (freq == 0) {
126 return 1; 127 printk(KERN_WARNING "zoltrix: received zero freq. Failed to set.\n");
128 return -EINVAL;
129 }
130
127 m = (freq / 160 - 8800) * 2; 131 m = (freq / 160 - 8800) * 2;
128 f = (unsigned long long) m + 0x4d1c; 132 f = (unsigned long long) m + 0x4d1c;
129 133
@@ -245,8 +249,7 @@ static int vidioc_querycap(struct file *file, void *priv,
245static int vidioc_g_tuner(struct file *file, void *priv, 249static int vidioc_g_tuner(struct file *file, void *priv,
246 struct v4l2_tuner *v) 250 struct v4l2_tuner *v)
247{ 251{
248 struct video_device *dev = video_devdata(file); 252 struct zol_device *zol = video_drvdata(file);
249 struct zol_device *zol = dev->priv;
250 253
251 if (v->index > 0) 254 if (v->index > 0)
252 return -EINVAL; 255 return -EINVAL;
@@ -276,19 +279,20 @@ static int vidioc_s_tuner(struct file *file, void *priv,
276static int vidioc_s_frequency(struct file *file, void *priv, 279static int vidioc_s_frequency(struct file *file, void *priv,
277 struct v4l2_frequency *f) 280 struct v4l2_frequency *f)
278{ 281{
279 struct video_device *dev = video_devdata(file); 282 struct zol_device *zol = video_drvdata(file);
280 struct zol_device *zol = dev->priv;
281 283
282 zol->curfreq = f->frequency; 284 zol->curfreq = f->frequency;
283 zol_setfreq(zol, zol->curfreq); 285 if (zol_setfreq(zol, zol->curfreq) != 0) {
286 printk(KERN_WARNING "zoltrix: Set frequency failed.\n");
287 return -EINVAL;
288 }
284 return 0; 289 return 0;
285} 290}
286 291
287static int vidioc_g_frequency(struct file *file, void *priv, 292static int vidioc_g_frequency(struct file *file, void *priv,
288 struct v4l2_frequency *f) 293 struct v4l2_frequency *f)
289{ 294{
290 struct video_device *dev = video_devdata(file); 295 struct zol_device *zol = video_drvdata(file);
291 struct zol_device *zol = dev->priv;
292 296
293 f->type = V4L2_TUNER_RADIO; 297 f->type = V4L2_TUNER_RADIO;
294 f->frequency = zol->curfreq; 298 f->frequency = zol->curfreq;
@@ -313,8 +317,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
313static int vidioc_g_ctrl(struct file *file, void *priv, 317static int vidioc_g_ctrl(struct file *file, void *priv,
314 struct v4l2_control *ctrl) 318 struct v4l2_control *ctrl)
315{ 319{
316 struct video_device *dev = video_devdata(file); 320 struct zol_device *zol = video_drvdata(file);
317 struct zol_device *zol = dev->priv;
318 321
319 switch (ctrl->id) { 322 switch (ctrl->id) {
320 case V4L2_CID_AUDIO_MUTE: 323 case V4L2_CID_AUDIO_MUTE:
@@ -330,8 +333,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
330static int vidioc_s_ctrl(struct file *file, void *priv, 333static int vidioc_s_ctrl(struct file *file, void *priv,
331 struct v4l2_control *ctrl) 334 struct v4l2_control *ctrl)
332{ 335{
333 struct video_device *dev = video_devdata(file); 336 struct zol_device *zol = video_drvdata(file);
334 struct zol_device *zol = dev->priv;
335 337
336 switch (ctrl->id) { 338 switch (ctrl->id) {
337 case V4L2_CID_AUDIO_MUTE: 339 case V4L2_CID_AUDIO_MUTE:
@@ -347,7 +349,10 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
347 return 0; 349 return 0;
348 } 350 }
349 zol->stereo = 1; 351 zol->stereo = 1;
350 zol_setfreq(zol, zol->curfreq); 352 if (zol_setfreq(zol, zol->curfreq) != 0) {
353 printk(KERN_WARNING "zoltrix: Set frequency failed.\n");
354 return -EINVAL;
355 }
351#if 0 356#if 0
352/* FIXME: Implement stereo/mono switch on V4L2 */ 357/* FIXME: Implement stereo/mono switch on V4L2 */
353 if (v->mode & VIDEO_SOUND_STEREO) { 358 if (v->mode & VIDEO_SOUND_STEREO) {
@@ -396,11 +401,22 @@ static int vidioc_s_audio(struct file *file, void *priv,
396 401
397static struct zol_device zoltrix_unit; 402static struct zol_device zoltrix_unit;
398 403
404static int zoltrix_exclusive_open(struct inode *inode, struct file *file)
405{
406 return test_and_set_bit(0, &zoltrix_unit.in_use) ? -EBUSY : 0;
407}
408
409static int zoltrix_exclusive_release(struct inode *inode, struct file *file)
410{
411 clear_bit(0, &zoltrix_unit.in_use);
412 return 0;
413}
414
399static const struct file_operations zoltrix_fops = 415static const struct file_operations zoltrix_fops =
400{ 416{
401 .owner = THIS_MODULE, 417 .owner = THIS_MODULE,
402 .open = video_exclusive_open, 418 .open = zoltrix_exclusive_open,
403 .release = video_exclusive_release, 419 .release = zoltrix_exclusive_release,
404 .ioctl = video_ioctl2, 420 .ioctl = video_ioctl2,
405#ifdef CONFIG_COMPAT 421#ifdef CONFIG_COMPAT
406 .compat_ioctl = v4l_compat_ioctl32, 422 .compat_ioctl = v4l_compat_ioctl32,
@@ -427,6 +443,7 @@ static struct video_device zoltrix_radio = {
427 .name = "Zoltrix Radio Plus", 443 .name = "Zoltrix Radio Plus",
428 .fops = &zoltrix_fops, 444 .fops = &zoltrix_fops,
429 .ioctl_ops = &zoltrix_ioctl_ops, 445 .ioctl_ops = &zoltrix_ioctl_ops,
446 .release = video_device_release_empty,
430}; 447};
431 448
432static int __init zoltrix_init(void) 449static int __init zoltrix_init(void)
@@ -440,7 +457,7 @@ static int __init zoltrix_init(void)
440 return -ENXIO; 457 return -ENXIO;
441 } 458 }
442 459
443 zoltrix_radio.priv = &zoltrix_unit; 460 video_set_drvdata(&zoltrix_radio, &zoltrix_unit);
444 if (!request_region(io, 2, "zoltrix")) { 461 if (!request_region(io, 2, "zoltrix")) {
445 printk(KERN_ERR "zoltrix: port 0x%x already in use\n", io); 462 printk(KERN_ERR "zoltrix: port 0x%x already in use\n", io);
446 return -EBUSY; 463 return -EBUSY;
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 3e9e0dcd217e..47102c2c8250 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -34,6 +34,7 @@ config VIDEOBUF_DVB
34 select VIDEOBUF_GEN 34 select VIDEOBUF_GEN
35 35
36config VIDEO_BTCX 36config VIDEO_BTCX
37 depends on PCI
37 tristate 38 tristate
38 39
39config VIDEO_IR 40config VIDEO_IR
@@ -71,6 +72,15 @@ config VIDEO_ADV_DEBUG
71 V4L devices. 72 V4L devices.
72 In doubt, say N. 73 In doubt, say N.
73 74
75config VIDEO_FIXED_MINOR_RANGES
76 bool "Enable old-style fixed minor ranges for video devices"
77 default n
78 ---help---
79 Say Y here to enable the old-style fixed-range minor assignments.
80 Only useful if you rely on the old behavior and use mknod instead of udev.
81
82 When in doubt, say N.
83
74config VIDEO_HELPER_CHIPS_AUTO 84config VIDEO_HELPER_CHIPS_AUTO
75 bool "Autoselect pertinent encoders/decoders and other helper chips" 85 bool "Autoselect pertinent encoders/decoders and other helper chips"
76 default y 86 default y
@@ -578,13 +588,6 @@ config VIDEO_SAA5249
578 To compile this driver as a module, choose M here: the 588 To compile this driver as a module, choose M here: the
579 module will be called saa5249. 589 module will be called saa5249.
580 590
581config TUNER_3036
582 tristate "SAB3036 tuner"
583 depends on I2C && VIDEO_V4L1
584 help
585 Say Y here to include support for Philips SAB3036 compatible tuners.
586 If in doubt, say N.
587
588config VIDEO_VINO 591config VIDEO_VINO
589 tristate "SGI Vino Video For Linux (EXPERIMENTAL)" 592 tristate "SGI Vino Video For Linux (EXPERIMENTAL)"
590 depends on I2C && SGI_IP22 && EXPERIMENTAL && VIDEO_V4L2 593 depends on I2C && SGI_IP22 && EXPERIMENTAL && VIDEO_V4L2
@@ -602,79 +605,7 @@ config VIDEO_STRADIS
602 driver for PCI. There is a product page at 605 driver for PCI. There is a product page at
603 <http://www.stradis.com/>. 606 <http://www.stradis.com/>.
604 607
605config VIDEO_ZORAN 608source "drivers/media/video/zoran/Kconfig"
606 tristate "Zoran ZR36057/36067 Video For Linux"
607 depends on PCI && I2C_ALGOBIT && VIDEO_V4L1 && VIRT_TO_BUS
608 help
609 Say Y for support for MJPEG capture cards based on the Zoran
610 36057/36067 PCI controller chipset. This includes the Iomega
611 Buz, Pinnacle DC10+ and the Linux Media Labs LML33. There is
612 a driver homepage at <http://mjpeg.sf.net/driver-zoran/>. For
613 more information, check <file:Documentation/video4linux/Zoran>.
614
615 To compile this driver as a module, choose M here: the
616 module will be called zr36067.
617
618config VIDEO_ZORAN_DC30
619 tristate "Pinnacle/Miro DC30(+) support"
620 depends on VIDEO_ZORAN
621 select VIDEO_ADV7175 if VIDEO_HELPER_CHIPS_AUTO
622 select VIDEO_VPX3220 if VIDEO_HELPER_CHIPS_AUTO
623 help
624 Support for the Pinnacle/Miro DC30(+) MJPEG capture/playback
625 card. This also supports really old DC10 cards based on the
626 zr36050 MJPEG codec and zr36016 VFE.
627
628config VIDEO_ZORAN_ZR36060
629 tristate "Zoran ZR36060"
630 depends on VIDEO_ZORAN
631 help
632 Say Y to support Zoran boards based on 36060 chips.
633 This includes Iomega Buz, Pinnacle DC10, Linux media Labs 33
634 and 33 R10 and AverMedia 6 boards.
635
636config VIDEO_ZORAN_BUZ
637 tristate "Iomega Buz support"
638 depends on VIDEO_ZORAN_ZR36060
639 select VIDEO_SAA7111 if VIDEO_HELPER_CHIPS_AUTO
640 select VIDEO_SAA7185 if VIDEO_HELPER_CHIPS_AUTO
641 help
642 Support for the Iomega Buz MJPEG capture/playback card.
643
644config VIDEO_ZORAN_DC10
645 tristate "Pinnacle/Miro DC10(+) support"
646 depends on VIDEO_ZORAN_ZR36060
647 select VIDEO_SAA7110 if VIDEO_HELPER_CHIPS_AUTO
648 select VIDEO_ADV7175 if VIDEO_HELPER_CHIPS_AUTO
649 help
650 Support for the Pinnacle/Miro DC10(+) MJPEG capture/playback
651 card.
652
653config VIDEO_ZORAN_LML33
654 tristate "Linux Media Labs LML33 support"
655 depends on VIDEO_ZORAN_ZR36060
656 select VIDEO_BT819 if VIDEO_HELPER_CHIPS_AUTO
657 select VIDEO_BT856 if VIDEO_HELPER_CHIPS_AUTO
658 help
659 Support for the Linux Media Labs LML33 MJPEG capture/playback
660 card.
661
662config VIDEO_ZORAN_LML33R10
663 tristate "Linux Media Labs LML33R10 support"
664 depends on VIDEO_ZORAN_ZR36060
665 select VIDEO_SAA7114 if VIDEO_HELPER_CHIPS_AUTO
666 select VIDEO_ADV7170 if VIDEO_HELPER_CHIPS_AUTO
667 help
668 support for the Linux Media Labs LML33R10 MJPEG capture/playback
669 card.
670
671config VIDEO_ZORAN_AVS6EYES
672 tristate "AverMedia 6 Eyes support (EXPERIMENTAL)"
673 depends on VIDEO_ZORAN_ZR36060 && EXPERIMENTAL && VIDEO_V4L1
674 select VIDEO_BT856 if VIDEO_HELPER_CHIPS_AUTO
675 select VIDEO_KS0127 if VIDEO_HELPER_CHIPS_AUTO
676 help
677 Support for the AverMedia 6 Eyes video surveillance card.
678 609
679config VIDEO_MEYE 610config VIDEO_MEYE
680 tristate "Sony Vaio Picturebook Motion Eye Video For Linux" 611 tristate "Sony Vaio Picturebook Motion Eye Video For Linux"
@@ -697,7 +628,7 @@ config VIDEO_MXB
697 depends on PCI && VIDEO_V4L1 && I2C 628 depends on PCI && VIDEO_V4L1 && I2C
698 select VIDEO_SAA7146_VV 629 select VIDEO_SAA7146_VV
699 select VIDEO_TUNER 630 select VIDEO_TUNER
700 select VIDEO_SAA7111 if VIDEO_HELPER_CHIPS_AUTO 631 select VIDEO_SAA7115 if VIDEO_HELPER_CHIPS_AUTO
701 select VIDEO_TDA9840 if VIDEO_HELPER_CHIPS_AUTO 632 select VIDEO_TDA9840 if VIDEO_HELPER_CHIPS_AUTO
702 select VIDEO_TEA6415C if VIDEO_HELPER_CHIPS_AUTO 633 select VIDEO_TEA6415C if VIDEO_HELPER_CHIPS_AUTO
703 select VIDEO_TEA6420 if VIDEO_HELPER_CHIPS_AUTO 634 select VIDEO_TEA6420 if VIDEO_HELPER_CHIPS_AUTO
@@ -708,21 +639,6 @@ config VIDEO_MXB
708 To compile this driver as a module, choose M here: the 639 To compile this driver as a module, choose M here: the
709 module will be called mxb. 640 module will be called mxb.
710 641
711config VIDEO_DPC
712 tristate "Philips-Semiconductors 'dpc7146 demonstration board'"
713 depends on PCI && VIDEO_V4L1 && I2C
714 select VIDEO_SAA7146_VV
715 select VIDEO_SAA7111 if VIDEO_HELPER_CHIPS_AUTO
716 ---help---
717 This is a video4linux driver for the 'dpc7146 demonstration
718 board' by Philips-Semiconductors. It's the reference design
719 for SAA7146 bases boards, so if you have some unsupported
720 saa7146 based, analog video card, chances are good that it
721 will work with this skeleton driver.
722
723 To compile this driver as a module, choose M here: the
724 module will be called dpc7146.
725
726config VIDEO_HEXIUM_ORION 642config VIDEO_HEXIUM_ORION
727 tristate "Hexium HV-PCI6 and Orion frame grabber" 643 tristate "Hexium HV-PCI6 and Orion frame grabber"
728 depends on PCI && VIDEO_V4L2 && I2C 644 depends on PCI && VIDEO_V4L2 && I2C
@@ -784,6 +700,70 @@ config VIDEO_CAFE_CCIC
784 CMOS camera controller. This is the controller found on first- 700 CMOS camera controller. This is the controller found on first-
785 generation OLPC systems. 701 generation OLPC systems.
786 702
703config SOC_CAMERA
704 tristate "SoC camera support"
705 depends on VIDEO_V4L2 && HAS_DMA
706 select VIDEOBUF_GEN
707 help
708 SoC Camera is a common API to several cameras, not connecting
709 over a bus like PCI or USB. For example some i2c camera connected
710 directly to the data bus of an SoC.
711
712config SOC_CAMERA_MT9M001
713 tristate "mt9m001 support"
714 depends on SOC_CAMERA && I2C
715 select GPIO_PCA953X if MT9M001_PCA9536_SWITCH
716 help
717 This driver supports MT9M001 cameras from Micron, monochrome
718 and colour models.
719
720config MT9M001_PCA9536_SWITCH
721 bool "pca9536 datawidth switch for mt9m001"
722 depends on SOC_CAMERA_MT9M001 && GENERIC_GPIO
723 help
724 Select this if your MT9M001 camera uses a PCA9536 I2C GPIO
725 extender to switch between 8 and 10 bit datawidth modes
726
727config SOC_CAMERA_MT9M111
728 tristate "mt9m111 support"
729 depends on SOC_CAMERA && I2C
730 help
731 This driver supports MT9M111 cameras from Micron
732
733config SOC_CAMERA_MT9V022
734 tristate "mt9v022 support"
735 depends on SOC_CAMERA && I2C
736 select GPIO_PCA953X if MT9V022_PCA9536_SWITCH
737 help
738 This driver supports MT9V022 cameras from Micron
739
740config MT9V022_PCA9536_SWITCH
741 bool "pca9536 datawidth switch for mt9v022"
742 depends on SOC_CAMERA_MT9V022 && GENERIC_GPIO
743 help
744 Select this if your MT9V022 camera uses a PCA9536 I2C GPIO
745 extender to switch between 8 and 10 bit datawidth modes
746
747config SOC_CAMERA_PLATFORM
748 tristate "platform camera support"
749 depends on SOC_CAMERA
750 help
751 This is a generic SoC camera platform driver, useful for testing
752
753config VIDEO_PXA27x
754 tristate "PXA27x Quick Capture Interface driver"
755 depends on VIDEO_DEV && PXA27x && SOC_CAMERA
756 select VIDEOBUF_DMA_SG
757 ---help---
758 This is a v4l2 driver for the PXA27x Quick Capture Interface
759
760config VIDEO_SH_MOBILE_CEU
761 tristate "SuperH Mobile CEU Interface driver"
762 depends on VIDEO_DEV && SOC_CAMERA && HAS_DMA
763 select VIDEOBUF_DMA_CONTIG
764 ---help---
765 This is a v4l2 driver for the SuperH Mobile CEU Interface
766
787# 767#
788# USB Multimedia device configuration 768# USB Multimedia device configuration
789# 769#
@@ -822,8 +802,7 @@ config VIDEO_OVCAMCHIP
822 802
823config USB_W9968CF 803config USB_W9968CF
824 tristate "USB W996[87]CF JPEG Dual Mode Camera support" 804 tristate "USB W996[87]CF JPEG Dual Mode Camera support"
825 depends on VIDEO_V4L1 && I2C 805 depends on VIDEO_V4L1 && I2C && VIDEO_OVCAMCHIP
826 select VIDEO_OVCAMCHIP
827 ---help--- 806 ---help---
828 Say Y here if you want support for cameras based on OV681 or 807 Say Y here if you want support for cameras based on OV681 or
829 Winbond W9967CF/W9968CF JPEG USB Dual Mode Camera Chips. 808 Winbond W9967CF/W9968CF JPEG USB Dual Mode Camera Chips.
@@ -914,64 +893,4 @@ config USB_S2255
914 893
915endif # V4L_USB_DRIVERS 894endif # V4L_USB_DRIVERS
916 895
917config SOC_CAMERA
918 tristate "SoC camera support"
919 depends on VIDEO_V4L2 && HAS_DMA
920 select VIDEOBUF_GEN
921 help
922 SoC Camera is a common API to several cameras, not connecting
923 over a bus like PCI or USB. For example some i2c camera connected
924 directly to the data bus of an SoC.
925
926config SOC_CAMERA_MT9M001
927 tristate "mt9m001 support"
928 depends on SOC_CAMERA && I2C
929 select GPIO_PCA953X if MT9M001_PCA9536_SWITCH
930 help
931 This driver supports MT9M001 cameras from Micron, monochrome
932 and colour models.
933
934config MT9M001_PCA9536_SWITCH
935 bool "pca9536 datawidth switch for mt9m001"
936 depends on SOC_CAMERA_MT9M001 && GENERIC_GPIO
937 help
938 Select this if your MT9M001 camera uses a PCA9536 I2C GPIO
939 extender to switch between 8 and 10 bit datawidth modes
940
941config SOC_CAMERA_MT9V022
942 tristate "mt9v022 support"
943 depends on SOC_CAMERA && I2C
944 select GPIO_PCA953X if MT9V022_PCA9536_SWITCH
945 help
946 This driver supports MT9V022 cameras from Micron
947
948config MT9V022_PCA9536_SWITCH
949 bool "pca9536 datawidth switch for mt9v022"
950 depends on SOC_CAMERA_MT9V022 && GENERIC_GPIO
951 help
952 Select this if your MT9V022 camera uses a PCA9536 I2C GPIO
953 extender to switch between 8 and 10 bit datawidth modes
954
955config SOC_CAMERA_PLATFORM
956 tristate "platform camera support"
957 depends on SOC_CAMERA
958 help
959 This is a generic SoC camera platform driver, useful for testing
960
961config VIDEO_PXA27x
962 tristate "PXA27x Quick Capture Interface driver"
963 depends on VIDEO_DEV && PXA27x
964 select SOC_CAMERA
965 select VIDEOBUF_DMA_SG
966 ---help---
967 This is a v4l2 driver for the PXA27x Quick Capture Interface
968
969config VIDEO_SH_MOBILE_CEU
970 tristate "SuperH Mobile CEU Interface driver"
971 depends on VIDEO_DEV && HAS_DMA
972 select SOC_CAMERA
973 select VIDEOBUF_DMA_CONTIG
974 ---help---
975 This is a v4l2 driver for the SuperH Mobile CEU Interface
976
977endif # VIDEO_CAPTURE_DRIVERS 896endif # VIDEO_CAPTURE_DRIVERS
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index ef7c8d3ffb18..16962f3aa157 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -2,8 +2,6 @@
2# Makefile for the video capture/playback device drivers. 2# Makefile for the video capture/playback device drivers.
3# 3#
4 4
5zr36067-objs := zoran_procfs.o zoran_device.o \
6 zoran_driver.o zoran_card.o
7tuner-objs := tuner-core.o 5tuner-objs := tuner-core.o
8 6
9msp3400-objs := msp3400-driver.o msp3400-kthreads.o 7msp3400-objs := msp3400-driver.o msp3400-kthreads.o
@@ -54,9 +52,7 @@ obj-$(CONFIG_VIDEO_BT856) += bt856.o
54obj-$(CONFIG_VIDEO_BT866) += bt866.o 52obj-$(CONFIG_VIDEO_BT866) += bt866.o
55obj-$(CONFIG_VIDEO_KS0127) += ks0127.o 53obj-$(CONFIG_VIDEO_KS0127) += ks0127.o
56 54
57obj-$(CONFIG_VIDEO_ZORAN) += zr36067.o videocodec.o 55obj-$(CONFIG_VIDEO_ZORAN) += zoran/
58obj-$(CONFIG_VIDEO_ZORAN_DC30) += zr36050.o zr36016.o
59obj-$(CONFIG_VIDEO_ZORAN_ZR36060) += zr36060.o
60 56
61obj-$(CONFIG_VIDEO_PMS) += pms.o 57obj-$(CONFIG_VIDEO_PMS) += pms.o
62obj-$(CONFIG_VIDEO_VINO) += vino.o indycam.o 58obj-$(CONFIG_VIDEO_VINO) += vino.o indycam.o
@@ -84,8 +80,6 @@ obj-$(CONFIG_VIDEO_CPIA2) += cpia2/
84obj-$(CONFIG_VIDEO_MXB) += mxb.o 80obj-$(CONFIG_VIDEO_MXB) += mxb.o
85obj-$(CONFIG_VIDEO_HEXIUM_ORION) += hexium_orion.o 81obj-$(CONFIG_VIDEO_HEXIUM_ORION) += hexium_orion.o
86obj-$(CONFIG_VIDEO_HEXIUM_GEMINI) += hexium_gemini.o 82obj-$(CONFIG_VIDEO_HEXIUM_GEMINI) += hexium_gemini.o
87obj-$(CONFIG_VIDEO_DPC) += dpc7146.o
88obj-$(CONFIG_TUNER_3036) += tuner-3036.o
89 83
90obj-$(CONFIG_VIDEOBUF_GEN) += videobuf-core.o 84obj-$(CONFIG_VIDEOBUF_GEN) += videobuf-core.o
91obj-$(CONFIG_VIDEOBUF_DMA_SG) += videobuf-dma-sg.o 85obj-$(CONFIG_VIDEOBUF_DMA_SG) += videobuf-dma-sg.o
@@ -137,6 +131,7 @@ obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o
137obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o 131obj-$(CONFIG_VIDEO_SH_MOBILE_CEU) += sh_mobile_ceu_camera.o
138obj-$(CONFIG_SOC_CAMERA) += soc_camera.o 132obj-$(CONFIG_SOC_CAMERA) += soc_camera.o
139obj-$(CONFIG_SOC_CAMERA_MT9M001) += mt9m001.o 133obj-$(CONFIG_SOC_CAMERA_MT9M001) += mt9m001.o
134obj-$(CONFIG_SOC_CAMERA_MT9M111) += mt9m111.o
140obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o 135obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o
141obj-$(CONFIG_SOC_CAMERA_PLATFORM) += soc_camera_platform.o 136obj-$(CONFIG_SOC_CAMERA_PLATFORM) += soc_camera_platform.o
142 137
diff --git a/drivers/media/video/arv.c b/drivers/media/video/arv.c
index 9e436ad3d34b..218754b4906a 100644
--- a/drivers/media/video/arv.c
+++ b/drivers/media/video/arv.c
@@ -116,6 +116,7 @@ struct ar_device {
116 int width, height; 116 int width, height;
117 int frame_bytes, line_bytes; 117 int frame_bytes, line_bytes;
118 wait_queue_head_t wait; 118 wait_queue_head_t wait;
119 unsigned long in_use;
119 struct mutex lock; 120 struct mutex lock;
120}; 121};
121 122
@@ -269,7 +270,7 @@ static inline void wait_for_vertical_sync(int exp_line)
269static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos) 270static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos)
270{ 271{
271 struct video_device *v = video_devdata(file); 272 struct video_device *v = video_devdata(file);
272 struct ar_device *ar = v->priv; 273 struct ar_device *ar = video_get_drvdata(v);
273 long ret = ar->frame_bytes; /* return read bytes */ 274 long ret = ar->frame_bytes; /* return read bytes */
274 unsigned long arvcr1 = 0; 275 unsigned long arvcr1 = 0;
275 unsigned long flags; 276 unsigned long flags;
@@ -399,7 +400,7 @@ static int ar_do_ioctl(struct inode *inode, struct file *file,
399 unsigned int cmd, void *arg) 400 unsigned int cmd, void *arg)
400{ 401{
401 struct video_device *dev = video_devdata(file); 402 struct video_device *dev = video_devdata(file);
402 struct ar_device *ar = dev->priv; 403 struct ar_device *ar = video_get_drvdata(dev);
403 404
404 DEBUG(1, "ar_ioctl()\n"); 405 DEBUG(1, "ar_ioctl()\n");
405 switch(cmd) { 406 switch(cmd) {
@@ -625,7 +626,7 @@ static void ar_interrupt(int irq, void *dev)
625 */ 626 */
626static int ar_initialize(struct video_device *dev) 627static int ar_initialize(struct video_device *dev)
627{ 628{
628 struct ar_device *ar = dev->priv; 629 struct ar_device *ar = video_get_drvdata(dev);
629 unsigned long cr = 0; 630 unsigned long cr = 0;
630 int i,found=0; 631 int i,found=0;
631 632
@@ -732,7 +733,7 @@ static int ar_initialize(struct video_device *dev)
732 733
733void ar_release(struct video_device *vfd) 734void ar_release(struct video_device *vfd)
734{ 735{
735 struct ar_device *ar = vfd->priv; 736 struct ar_device *ar = video_get_drvdata(vfd);
736 mutex_lock(&ar->lock); 737 mutex_lock(&ar->lock);
737 video_device_release(vfd); 738 video_device_release(vfd);
738} 739}
@@ -742,10 +743,23 @@ void ar_release(struct video_device *vfd)
742 * Video4Linux Module functions 743 * Video4Linux Module functions
743 * 744 *
744 ****************************************************************************/ 745 ****************************************************************************/
746static struct ar_device ardev;
747
748static int ar_exclusive_open(struct inode *inode, struct file *file)
749{
750 return test_and_set_bit(0, &ardev.in_use) ? -EBUSY : 0;
751}
752
753static int ar_exclusive_release(struct inode *inode, struct file *file)
754{
755 clear_bit(0, &ardev.in_use);
756 return 0;
757}
758
745static const struct file_operations ar_fops = { 759static const struct file_operations ar_fops = {
746 .owner = THIS_MODULE, 760 .owner = THIS_MODULE,
747 .open = video_exclusive_open, 761 .open = ar_exclusive_open,
748 .release = video_exclusive_release, 762 .release = ar_exclusive_release,
749 .read = ar_read, 763 .read = ar_read,
750 .ioctl = ar_ioctl, 764 .ioctl = ar_ioctl,
751#ifdef CONFIG_COMPAT 765#ifdef CONFIG_COMPAT
@@ -762,7 +776,6 @@ static struct video_device ar_template = {
762}; 776};
763 777
764#define ALIGN4(x) ((((int)(x)) & 0x3) == 0) 778#define ALIGN4(x) ((((int)(x)) & 0x3) == 0)
765static struct ar_device ardev;
766 779
767static int __init ar_init(void) 780static int __init ar_init(void)
768{ 781{
@@ -802,7 +815,7 @@ static int __init ar_init(void)
802 return -ENOMEM; 815 return -ENOMEM;
803 } 816 }
804 memcpy(ar->vdev, &ar_template, sizeof(ar_template)); 817 memcpy(ar->vdev, &ar_template, sizeof(ar_template));
805 ar->vdev->priv = ar; 818 video_set_drvdata(ar->vdev, ar);
806 819
807 if (vga) { 820 if (vga) {
808 ar->width = AR_WIDTH_VGA; 821 ar->width = AR_WIDTH_VGA;
diff --git a/drivers/media/video/au0828/au0828-cards.c b/drivers/media/video/au0828/au0828-cards.c
index ed48908a9034..5f07a8a072b6 100644
--- a/drivers/media/video/au0828/au0828-cards.c
+++ b/drivers/media/video/au0828/au0828-cards.c
@@ -46,7 +46,7 @@ struct au0828_board au0828_boards[] = {
46/* Tuner callback function for au0828 boards. Currently only needed 46/* Tuner callback function for au0828 boards. Currently only needed
47 * for HVR1500Q, which has an xc5000 tuner. 47 * for HVR1500Q, which has an xc5000 tuner.
48 */ 48 */
49int au0828_tuner_callback(void *priv, int command, int arg) 49int au0828_tuner_callback(void *priv, int component, int command, int arg)
50{ 50{
51 struct au0828_dev *dev = priv; 51 struct au0828_dev *dev = priv;
52 52
diff --git a/drivers/media/video/au0828/au0828-dvb.c b/drivers/media/video/au0828/au0828-dvb.c
index ba94be7e0ac1..f0fcdb4769d7 100644
--- a/drivers/media/video/au0828/au0828-dvb.c
+++ b/drivers/media/video/au0828/au0828-dvb.c
@@ -36,11 +36,39 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
36#define _AU0828_BULKPIPE 0x83 36#define _AU0828_BULKPIPE 0x83
37#define _BULKPIPESIZE 0xe522 37#define _BULKPIPESIZE 0xe522
38 38
39static u8 hauppauge_hvr950q_led_states[] = {
40 0x00, /* off */
41 0x02, /* yellow */
42 0x04, /* green */
43};
44
45static struct au8522_led_config hauppauge_hvr950q_led_cfg = {
46 .gpio_output = 0x00e0,
47 .gpio_output_enable = 0x6006,
48 .gpio_output_disable = 0x0660,
49
50 .gpio_leds = 0x00e2,
51 .led_states = hauppauge_hvr950q_led_states,
52 .num_led_states = sizeof(hauppauge_hvr950q_led_states),
53
54 .vsb8_strong = 20 /* dB */ * 10,
55 .qam64_strong = 25 /* dB */ * 10,
56 .qam256_strong = 32 /* dB */ * 10,
57};
58
39static struct au8522_config hauppauge_hvr950q_config = { 59static struct au8522_config hauppauge_hvr950q_config = {
40 .demod_address = 0x8e >> 1, 60 .demod_address = 0x8e >> 1,
41 .status_mode = AU8522_DEMODLOCKING, 61 .status_mode = AU8522_DEMODLOCKING,
42 .qam_if = AU8522_IF_6MHZ, 62 .qam_if = AU8522_IF_6MHZ,
43 .vsb_if = AU8522_IF_6MHZ, 63 .vsb_if = AU8522_IF_6MHZ,
64 .led_cfg = &hauppauge_hvr950q_led_cfg,
65};
66
67static struct au8522_config fusionhdtv7usb_config = {
68 .demod_address = 0x8e >> 1,
69 .status_mode = AU8522_DEMODLOCKING,
70 .qam_if = AU8522_IF_6MHZ,
71 .vsb_if = AU8522_IF_6MHZ,
44}; 72};
45 73
46static struct au8522_config hauppauge_woodbury_config = { 74static struct au8522_config hauppauge_woodbury_config = {
@@ -53,7 +81,6 @@ static struct au8522_config hauppauge_woodbury_config = {
53static struct xc5000_config hauppauge_hvr950q_tunerconfig = { 81static struct xc5000_config hauppauge_hvr950q_tunerconfig = {
54 .i2c_address = 0x61, 82 .i2c_address = 0x61,
55 .if_khz = 6000, 83 .if_khz = 6000,
56 .tuner_callback = au0828_tuner_callback
57}; 84};
58 85
59static struct mxl5007t_config mxl5007t_hvr950q_config = { 86static struct mxl5007t_config mxl5007t_hvr950q_config = {
@@ -353,14 +380,12 @@ int au0828_dvb_register(struct au0828_dev *dev)
353 switch (dev->board) { 380 switch (dev->board) {
354 case AU0828_BOARD_HAUPPAUGE_HVR850: 381 case AU0828_BOARD_HAUPPAUGE_HVR850:
355 case AU0828_BOARD_HAUPPAUGE_HVR950Q: 382 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
356 case AU0828_BOARD_DVICO_FUSIONHDTV7:
357 dvb->frontend = dvb_attach(au8522_attach, 383 dvb->frontend = dvb_attach(au8522_attach,
358 &hauppauge_hvr950q_config, 384 &hauppauge_hvr950q_config,
359 &dev->i2c_adap); 385 &dev->i2c_adap);
360 if (dvb->frontend != NULL) 386 if (dvb->frontend != NULL)
361 dvb_attach(xc5000_attach, dvb->frontend, 387 dvb_attach(xc5000_attach, dvb->frontend, &dev->i2c_adap,
362 &dev->i2c_adap, 388 &hauppauge_hvr950q_tunerconfig);
363 &hauppauge_hvr950q_tunerconfig, dev);
364 break; 389 break;
365 case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL: 390 case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
366 dvb->frontend = dvb_attach(au8522_attach, 391 dvb->frontend = dvb_attach(au8522_attach,
@@ -380,6 +405,16 @@ int au0828_dvb_register(struct au0828_dev *dev)
380 0x60, &dev->i2c_adap, 405 0x60, &dev->i2c_adap,
381 &hauppauge_woodbury_tunerconfig); 406 &hauppauge_woodbury_tunerconfig);
382 break; 407 break;
408 case AU0828_BOARD_DVICO_FUSIONHDTV7:
409 dvb->frontend = dvb_attach(au8522_attach,
410 &fusionhdtv7usb_config,
411 &dev->i2c_adap);
412 if (dvb->frontend != NULL) {
413 dvb_attach(xc5000_attach, dvb->frontend,
414 &dev->i2c_adap,
415 &hauppauge_hvr950q_tunerconfig);
416 }
417 break;
383 default: 418 default:
384 printk(KERN_WARNING "The frontend of your DVB/ATSC card " 419 printk(KERN_WARNING "The frontend of your DVB/ATSC card "
385 "isn't supported yet\n"); 420 "isn't supported yet\n");
@@ -390,6 +425,8 @@ int au0828_dvb_register(struct au0828_dev *dev)
390 __func__); 425 __func__);
391 return -1; 426 return -1;
392 } 427 }
428 /* define general-purpose callback pointer */
429 dvb->frontend->callback = au0828_tuner_callback;
393 430
394 /* register everything */ 431 /* register everything */
395 ret = dvb_register(dev); 432 ret = dvb_register(dev);
diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
index 4f10ff300135..9d6a1161dc98 100644
--- a/drivers/media/video/au0828/au0828.h
+++ b/drivers/media/video/au0828/au0828.h
@@ -103,7 +103,8 @@ extern int au0828_debug;
103extern struct au0828_board au0828_boards[]; 103extern struct au0828_board au0828_boards[];
104extern struct usb_device_id au0828_usb_id_table[]; 104extern struct usb_device_id au0828_usb_id_table[];
105extern void au0828_gpio_setup(struct au0828_dev *dev); 105extern void au0828_gpio_setup(struct au0828_dev *dev);
106extern int au0828_tuner_callback(void *priv, int command, int arg); 106extern int au0828_tuner_callback(void *priv, int component,
107 int command, int arg);
107extern void au0828_card_setup(struct au0828_dev *dev); 108extern void au0828_card_setup(struct au0828_dev *dev);
108 109
109/* ----------------------------------------------------------- */ 110/* ----------------------------------------------------------- */
diff --git a/drivers/media/video/bt856.c b/drivers/media/video/bt856.c
index 98ee2d8feb34..ab2ce4d7b5de 100644
--- a/drivers/media/video/bt856.c
+++ b/drivers/media/video/bt856.c
@@ -68,8 +68,8 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
68 68
69/* ----------------------------------------------------------------------- */ 69/* ----------------------------------------------------------------------- */
70 70
71#define REG_OFFSET 0xDA 71#define BT856_REG_OFFSET 0xDA
72#define BT856_NR_REG 6 72#define BT856_NR_REG 6
73 73
74struct bt856 { 74struct bt856 {
75 unsigned char reg[BT856_NR_REG]; 75 unsigned char reg[BT856_NR_REG];
@@ -89,7 +89,7 @@ bt856_write (struct i2c_client *client,
89{ 89{
90 struct bt856 *encoder = i2c_get_clientdata(client); 90 struct bt856 *encoder = i2c_get_clientdata(client);
91 91
92 encoder->reg[reg - REG_OFFSET] = value; 92 encoder->reg[reg - BT856_REG_OFFSET] = value;
93 return i2c_smbus_write_byte_data(client, reg, value); 93 return i2c_smbus_write_byte_data(client, reg, value);
94} 94}
95 95
@@ -103,7 +103,7 @@ bt856_setbit (struct i2c_client *client,
103 103
104 return bt856_write(client, reg, 104 return bt856_write(client, reg,
105 (encoder-> 105 (encoder->
106 reg[reg - REG_OFFSET] & ~(1 << bit)) | 106 reg[reg - BT856_REG_OFFSET] & ~(1 << bit)) |
107 (value ? (1 << bit) : 0)); 107 (value ? (1 << bit) : 0));
108} 108}
109 109
diff --git a/drivers/media/video/bt8xx/bttv-cards.c b/drivers/media/video/bt8xx/bttv-cards.c
index 6081edc362df..13742b0bbe3e 100644
--- a/drivers/media/video/bt8xx/bttv-cards.c
+++ b/drivers/media/video/bt8xx/bttv-cards.c
@@ -305,7 +305,7 @@ static struct CARD {
305 { 0x00261822, BTTV_BOARD_TWINHAN_DST, "DNTV Live! Mini "}, 305 { 0x00261822, BTTV_BOARD_TWINHAN_DST, "DNTV Live! Mini "},
306 { 0xd200dbc0, BTTV_BOARD_DVICO_FUSIONHDTV_2, "DViCO FusionHDTV 2" }, 306 { 0xd200dbc0, BTTV_BOARD_DVICO_FUSIONHDTV_2, "DViCO FusionHDTV 2" },
307 { 0x763c008a, BTTV_BOARD_GEOVISION_GV600, "GeoVision GV-600" }, 307 { 0x763c008a, BTTV_BOARD_GEOVISION_GV600, "GeoVision GV-600" },
308 308 { 0x18011000, BTTV_BOARD_ENLTV_FM_2, "Encore ENL TV-FM-2" },
309 { 0, -1, NULL } 309 { 0, -1, NULL }
310}; 310};
311 311
@@ -3037,6 +3037,31 @@ struct tvcard bttv_tvcards[] = {
3037 .has_radio = 1, 3037 .has_radio = 1,
3038 .has_remote = 1, 3038 .has_remote = 1,
3039 }, 3039 },
3040 [BTTV_BOARD_ENLTV_FM_2] = {
3041 /* Encore TV Tuner Pro ENL TV-FM-2
3042 Mauro Carvalho Chehab <mchehab@infradead.org */
3043 .name = "Encore ENL TV-FM-2",
3044 .video_inputs = 3,
3045 .audio_inputs = 1,
3046 .tuner = 0,
3047 .svhs = 2,
3048 /* bit 6 -> IR disabled
3049 bit 18/17 = 00 -> mute
3050 01 -> enable external audio input
3051 10 -> internal audio input (mono?)
3052 11 -> internal audio input
3053 */
3054 .gpiomask = 0x060040,
3055 .muxsel = { 2, 3, 3 },
3056 .gpiomux = { 0x60000, 0x60000, 0x20000, 0x20000 },
3057 .gpiomute = 0,
3058 .tuner_type = TUNER_TCL_MF02GIP_5N,
3059 .tuner_addr = ADDR_UNSET,
3060 .radio_addr = ADDR_UNSET,
3061 .pll = PLL_28,
3062 .has_radio = 1,
3063 .has_remote = 1,
3064 }
3040}; 3065};
3041 3066
3042static const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards); 3067static const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards);
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index 933eaef41ead..5858bf5ff41c 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -76,9 +76,9 @@ static unsigned int gbuffers = 8;
76static unsigned int gbufsize = 0x208000; 76static unsigned int gbufsize = 0x208000;
77static unsigned int reset_crop = 1; 77static unsigned int reset_crop = 1;
78 78
79static int video_nr = -1; 79static int video_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
80static int radio_nr = -1; 80static int radio_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
81static int vbi_nr = -1; 81static int vbi_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
82static int debug_latency; 82static int debug_latency;
83 83
84static unsigned int fdsr; 84static unsigned int fdsr;
@@ -108,9 +108,6 @@ module_param(irq_debug, int, 0644);
108module_param(debug_latency, int, 0644); 108module_param(debug_latency, int, 0644);
109 109
110module_param(fdsr, int, 0444); 110module_param(fdsr, int, 0444);
111module_param(video_nr, int, 0444);
112module_param(radio_nr, int, 0444);
113module_param(vbi_nr, int, 0444);
114module_param(gbuffers, int, 0444); 111module_param(gbuffers, int, 0444);
115module_param(gbufsize, int, 0444); 112module_param(gbufsize, int, 0444);
116module_param(reset_crop, int, 0444); 113module_param(reset_crop, int, 0444);
@@ -130,7 +127,10 @@ module_param(uv_ratio, int, 0444);
130module_param(full_luma_range, int, 0444); 127module_param(full_luma_range, int, 0444);
131module_param(coring, int, 0444); 128module_param(coring, int, 0444);
132 129
133module_param_array(radio, int, NULL, 0444); 130module_param_array(radio, int, NULL, 0444);
131module_param_array(video_nr, int, NULL, 0444);
132module_param_array(radio_nr, int, NULL, 0444);
133module_param_array(vbi_nr, int, NULL, 0444);
134 134
135MODULE_PARM_DESC(radio,"The TV card supports radio, default is 0 (no)"); 135MODULE_PARM_DESC(radio,"The TV card supports radio, default is 0 (no)");
136MODULE_PARM_DESC(bigendian,"byte order of the framebuffer, default is native endian"); 136MODULE_PARM_DESC(bigendian,"byte order of the framebuffer, default is native endian");
@@ -152,6 +152,9 @@ MODULE_PARM_DESC(irq_iswitch,"switch inputs in irq handler");
152MODULE_PARM_DESC(uv_ratio,"ratio between u and v gains, default is 50"); 152MODULE_PARM_DESC(uv_ratio,"ratio between u and v gains, default is 50");
153MODULE_PARM_DESC(full_luma_range,"use the full luma range, default is 0 (no)"); 153MODULE_PARM_DESC(full_luma_range,"use the full luma range, default is 0 (no)");
154MODULE_PARM_DESC(coring,"set the luma coring level, default is 0 (no)"); 154MODULE_PARM_DESC(coring,"set the luma coring level, default is 0 (no)");
155MODULE_PARM_DESC(video_nr, "video device numbers");
156MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
157MODULE_PARM_DESC(radio_nr, "radio device numbers");
155 158
156MODULE_DESCRIPTION("bttv - v4l/v4l2 driver module for bt848/878 based cards"); 159MODULE_DESCRIPTION("bttv - v4l/v4l2 driver module for bt848/878 based cards");
157MODULE_AUTHOR("Ralph Metzler & Marcus Metzler & Gerd Knorr"); 160MODULE_AUTHOR("Ralph Metzler & Marcus Metzler & Gerd Knorr");
@@ -1367,7 +1370,7 @@ static void init_irqreg(struct bttv *btv)
1367 (btv->gpioirq ? BT848_INT_GPINT : 0) | 1370 (btv->gpioirq ? BT848_INT_GPINT : 0) |
1368 BT848_INT_SCERR | 1371 BT848_INT_SCERR |
1369 (fdsr ? BT848_INT_FDSR : 0) | 1372 (fdsr ? BT848_INT_FDSR : 0) |
1370 BT848_INT_RISCI|BT848_INT_OCERR|BT848_INT_VPRES| 1373 BT848_INT_RISCI | BT848_INT_OCERR |
1371 BT848_INT_FMTCHG|BT848_INT_HLOCK| 1374 BT848_INT_FMTCHG|BT848_INT_HLOCK|
1372 BT848_INT_I2CDONE, 1375 BT848_INT_I2CDONE,
1373 BT848_INT_MASK); 1376 BT848_INT_MASK);
@@ -2661,18 +2664,6 @@ static int bttv_querycap(struct file *file, void *priv,
2661 return 0; 2664 return 0;
2662} 2665}
2663 2666
2664static int bttv_enum_fmt_vbi_cap(struct file *file, void *priv,
2665 struct v4l2_fmtdesc *f)
2666{
2667 if (0 != f->index)
2668 return -EINVAL;
2669
2670 f->pixelformat = V4L2_PIX_FMT_GREY;
2671 strcpy(f->description, "vbi data");
2672
2673 return 0;
2674}
2675
2676static int bttv_enum_fmt_cap_ovr(struct v4l2_fmtdesc *f) 2667static int bttv_enum_fmt_cap_ovr(struct v4l2_fmtdesc *f)
2677{ 2668{
2678 int index = -1, i; 2669 int index = -1, i;
@@ -3227,6 +3218,7 @@ static int bttv_open(struct inode *inode, struct file *file)
3227 3218
3228 dprintk(KERN_DEBUG "bttv: open minor=%d\n",minor); 3219 dprintk(KERN_DEBUG "bttv: open minor=%d\n",minor);
3229 3220
3221 lock_kernel();
3230 for (i = 0; i < bttv_num; i++) { 3222 for (i = 0; i < bttv_num; i++) {
3231 if (bttvs[i].video_dev && 3223 if (bttvs[i].video_dev &&
3232 bttvs[i].video_dev->minor == minor) { 3224 bttvs[i].video_dev->minor == minor) {
@@ -3241,16 +3233,20 @@ static int bttv_open(struct inode *inode, struct file *file)
3241 break; 3233 break;
3242 } 3234 }
3243 } 3235 }
3244 if (NULL == btv) 3236 if (NULL == btv) {
3237 unlock_kernel();
3245 return -ENODEV; 3238 return -ENODEV;
3239 }
3246 3240
3247 dprintk(KERN_DEBUG "bttv%d: open called (type=%s)\n", 3241 dprintk(KERN_DEBUG "bttv%d: open called (type=%s)\n",
3248 btv->c.nr,v4l2_type_names[type]); 3242 btv->c.nr,v4l2_type_names[type]);
3249 3243
3250 /* allocate per filehandle data */ 3244 /* allocate per filehandle data */
3251 fh = kmalloc(sizeof(*fh),GFP_KERNEL); 3245 fh = kmalloc(sizeof(*fh),GFP_KERNEL);
3252 if (NULL == fh) 3246 if (NULL == fh) {
3247 unlock_kernel();
3253 return -ENOMEM; 3248 return -ENOMEM;
3249 }
3254 file->private_data = fh; 3250 file->private_data = fh;
3255 *fh = btv->init; 3251 *fh = btv->init;
3256 fh->type = type; 3252 fh->type = type;
@@ -3270,6 +3266,7 @@ static int bttv_open(struct inode *inode, struct file *file)
3270 sizeof(struct bttv_buffer), 3266 sizeof(struct bttv_buffer),
3271 fh); 3267 fh);
3272 set_tvnorm(btv,btv->tvnorm); 3268 set_tvnorm(btv,btv->tvnorm);
3269 set_input(btv, btv->input, btv->tvnorm);
3273 3270
3274 btv->users++; 3271 btv->users++;
3275 3272
@@ -3290,6 +3287,7 @@ static int bttv_open(struct inode *inode, struct file *file)
3290 bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm); 3287 bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm);
3291 3288
3292 bttv_field_count(btv); 3289 bttv_field_count(btv);
3290 unlock_kernel();
3293 return 0; 3291 return 0;
3294} 3292}
3295 3293
@@ -3330,6 +3328,10 @@ static int bttv_release(struct inode *inode, struct file *file)
3330 3328
3331 btv->users--; 3329 btv->users--;
3332 bttv_field_count(btv); 3330 bttv_field_count(btv);
3331
3332 if (!btv->users)
3333 audio_mute(btv, 1);
3334
3333 return 0; 3335 return 0;
3334} 3336}
3335 3337
@@ -3367,7 +3369,6 @@ static const struct v4l2_ioctl_ops bttv_ioctl_ops = {
3367 .vidioc_g_fmt_vid_overlay = bttv_g_fmt_vid_overlay, 3369 .vidioc_g_fmt_vid_overlay = bttv_g_fmt_vid_overlay,
3368 .vidioc_try_fmt_vid_overlay = bttv_try_fmt_vid_overlay, 3370 .vidioc_try_fmt_vid_overlay = bttv_try_fmt_vid_overlay,
3369 .vidioc_s_fmt_vid_overlay = bttv_s_fmt_vid_overlay, 3371 .vidioc_s_fmt_vid_overlay = bttv_s_fmt_vid_overlay,
3370 .vidioc_enum_fmt_vbi_cap = bttv_enum_fmt_vbi_cap,
3371 .vidioc_g_fmt_vbi_cap = bttv_g_fmt_vbi_cap, 3372 .vidioc_g_fmt_vbi_cap = bttv_g_fmt_vbi_cap,
3372 .vidioc_try_fmt_vbi_cap = bttv_try_fmt_vbi_cap, 3373 .vidioc_try_fmt_vbi_cap = bttv_try_fmt_vbi_cap,
3373 .vidioc_s_fmt_vbi_cap = bttv_s_fmt_vbi_cap, 3374 .vidioc_s_fmt_vbi_cap = bttv_s_fmt_vbi_cap,
@@ -3430,21 +3431,26 @@ static int radio_open(struct inode *inode, struct file *file)
3430 3431
3431 dprintk("bttv: open minor=%d\n",minor); 3432 dprintk("bttv: open minor=%d\n",minor);
3432 3433
3434 lock_kernel();
3433 for (i = 0; i < bttv_num; i++) { 3435 for (i = 0; i < bttv_num; i++) {
3434 if (bttvs[i].radio_dev && bttvs[i].radio_dev->minor == minor) { 3436 if (bttvs[i].radio_dev && bttvs[i].radio_dev->minor == minor) {
3435 btv = &bttvs[i]; 3437 btv = &bttvs[i];
3436 break; 3438 break;
3437 } 3439 }
3438 } 3440 }
3439 if (NULL == btv) 3441 if (NULL == btv) {
3442 unlock_kernel();
3440 return -ENODEV; 3443 return -ENODEV;
3444 }
3441 3445
3442 dprintk("bttv%d: open called (radio)\n",btv->c.nr); 3446 dprintk("bttv%d: open called (radio)\n",btv->c.nr);
3443 3447
3444 /* allocate per filehandle data */ 3448 /* allocate per filehandle data */
3445 fh = kmalloc(sizeof(*fh), GFP_KERNEL); 3449 fh = kmalloc(sizeof(*fh), GFP_KERNEL);
3446 if (NULL == fh) 3450 if (NULL == fh) {
3451 unlock_kernel();
3447 return -ENOMEM; 3452 return -ENOMEM;
3453 }
3448 file->private_data = fh; 3454 file->private_data = fh;
3449 *fh = btv->init; 3455 *fh = btv->init;
3450 v4l2_prio_open(&btv->prio, &fh->prio); 3456 v4l2_prio_open(&btv->prio, &fh->prio);
@@ -3457,6 +3463,7 @@ static int radio_open(struct inode *inode, struct file *file)
3457 audio_input(btv,TVAUDIO_INPUT_RADIO); 3463 audio_input(btv,TVAUDIO_INPUT_RADIO);
3458 3464
3459 mutex_unlock(&btv->lock); 3465 mutex_unlock(&btv->lock);
3466 unlock_kernel();
3460 return 0; 3467 return 0;
3461} 3468}
3462 3469
@@ -4235,7 +4242,8 @@ static int __devinit bttv_register_video(struct bttv *btv)
4235 4242
4236 if (NULL == btv->video_dev) 4243 if (NULL == btv->video_dev)
4237 goto err; 4244 goto err;
4238 if (video_register_device(btv->video_dev,VFL_TYPE_GRABBER,video_nr)<0) 4245 if (video_register_device(btv->video_dev, VFL_TYPE_GRABBER,
4246 video_nr[btv->c.nr]) < 0)
4239 goto err; 4247 goto err;
4240 printk(KERN_INFO "bttv%d: registered device video%d\n", 4248 printk(KERN_INFO "bttv%d: registered device video%d\n",
4241 btv->c.nr,btv->video_dev->minor & 0x1f); 4249 btv->c.nr,btv->video_dev->minor & 0x1f);
@@ -4251,7 +4259,8 @@ static int __devinit bttv_register_video(struct bttv *btv)
4251 4259
4252 if (NULL == btv->vbi_dev) 4260 if (NULL == btv->vbi_dev)
4253 goto err; 4261 goto err;
4254 if (video_register_device(btv->vbi_dev,VFL_TYPE_VBI,vbi_nr)<0) 4262 if (video_register_device(btv->vbi_dev, VFL_TYPE_VBI,
4263 vbi_nr[btv->c.nr]) < 0)
4255 goto err; 4264 goto err;
4256 printk(KERN_INFO "bttv%d: registered device vbi%d\n", 4265 printk(KERN_INFO "bttv%d: registered device vbi%d\n",
4257 btv->c.nr,btv->vbi_dev->minor & 0x1f); 4266 btv->c.nr,btv->vbi_dev->minor & 0x1f);
@@ -4262,7 +4271,8 @@ static int __devinit bttv_register_video(struct bttv *btv)
4262 btv->radio_dev = vdev_init(btv, &radio_template, "radio"); 4271 btv->radio_dev = vdev_init(btv, &radio_template, "radio");
4263 if (NULL == btv->radio_dev) 4272 if (NULL == btv->radio_dev)
4264 goto err; 4273 goto err;
4265 if (video_register_device(btv->radio_dev, VFL_TYPE_RADIO,radio_nr)<0) 4274 if (video_register_device(btv->radio_dev, VFL_TYPE_RADIO,
4275 radio_nr[btv->c.nr]) < 0)
4266 goto err; 4276 goto err;
4267 printk(KERN_INFO "bttv%d: registered device radio%d\n", 4277 printk(KERN_INFO "bttv%d: registered device radio%d\n",
4268 btv->c.nr,btv->radio_dev->minor & 0x1f); 4278 btv->c.nr,btv->radio_dev->minor & 0x1f);
diff --git a/drivers/media/video/bt8xx/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c
index a38af98f4cae..2f289d981fe6 100644
--- a/drivers/media/video/bt8xx/bttv-input.c
+++ b/drivers/media/video/bt8xx/bttv-input.c
@@ -28,8 +28,8 @@
28#include "bttvp.h" 28#include "bttvp.h"
29 29
30 30
31static int debug; 31static int ir_debug;
32module_param(debug, int, 0644); /* debug level (0,1,2) */ 32module_param(ir_debug, int, 0644);
33static int repeat_delay = 500; 33static int repeat_delay = 500;
34module_param(repeat_delay, int, 0644); 34module_param(repeat_delay, int, 0644);
35static int repeat_period = 33; 35static int repeat_period = 33;
@@ -40,6 +40,12 @@ module_param(ir_rc5_remote_gap, int, 0644);
40static int ir_rc5_key_timeout = 200; 40static int ir_rc5_key_timeout = 200;
41module_param(ir_rc5_key_timeout, int, 0644); 41module_param(ir_rc5_key_timeout, int, 0644);
42 42
43#undef dprintk
44#define dprintk(arg...) do { \
45 if (ir_debug >= 1) \
46 printk(arg); \
47} while (0)
48
43#define DEVNAME "bttv-input" 49#define DEVNAME "bttv-input"
44 50
45/* ---------------------------------------------------------------------- */ 51/* ---------------------------------------------------------------------- */
@@ -79,6 +85,45 @@ static void ir_handle_key(struct bttv *btv)
79 85
80} 86}
81 87
88static void ir_enltv_handle_key(struct bttv *btv)
89{
90 struct card_ir *ir = btv->remote;
91 u32 gpio, data, keyup;
92
93 /* read gpio value */
94 gpio = bttv_gpio_read(&btv->c);
95
96 /* extract data */
97 data = ir_extract_bits(gpio, ir->mask_keycode);
98
99 /* Check if it is keyup */
100 keyup = (gpio & ir->mask_keyup) ? 1 << 31 : 0;
101
102 if ((ir->last_gpio & 0x7f) != data) {
103 dprintk(KERN_INFO DEVNAME ": gpio=0x%x code=%d | %s\n",
104 gpio, data,
105 (gpio & ir->mask_keyup) ? " up" : "up/down");
106
107 ir_input_keydown(ir->dev, &ir->ir, data, data);
108 if (keyup)
109 ir_input_nokey(ir->dev, &ir->ir);
110 } else {
111 if ((ir->last_gpio & 1 << 31) == keyup)
112 return;
113
114 dprintk(KERN_INFO DEVNAME ":(cnt) gpio=0x%x code=%d | %s\n",
115 gpio, data,
116 (gpio & ir->mask_keyup) ? " up" : "down");
117
118 if (keyup)
119 ir_input_nokey(ir->dev, &ir->ir);
120 else
121 ir_input_keydown(ir->dev, &ir->ir, data, data);
122 }
123
124 ir->last_gpio = data | keyup;
125}
126
82void bttv_input_irq(struct bttv *btv) 127void bttv_input_irq(struct bttv *btv)
83{ 128{
84 struct card_ir *ir = btv->remote; 129 struct card_ir *ir = btv->remote;
@@ -92,7 +137,10 @@ static void bttv_input_timer(unsigned long data)
92 struct bttv *btv = (struct bttv*)data; 137 struct bttv *btv = (struct bttv*)data;
93 struct card_ir *ir = btv->remote; 138 struct card_ir *ir = btv->remote;
94 139
95 ir_handle_key(btv); 140 if (btv->c.type == BTTV_BOARD_ENLTV_FM_2)
141 ir_enltv_handle_key(btv);
142 else
143 ir_handle_key(btv);
96 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling)); 144 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
97} 145}
98 146
@@ -284,6 +332,14 @@ int bttv_input_init(struct bttv *btv)
284 ir->mask_keyup = 0x006000; 332 ir->mask_keyup = 0x006000;
285 ir->polling = 50; /* ms */ 333 ir->polling = 50; /* ms */
286 break; 334 break;
335 case BTTV_BOARD_ENLTV_FM_2:
336 ir_codes = ir_codes_encore_enltv2;
337 ir->mask_keycode = 0x00fd00;
338 ir->mask_keyup = 0x000080;
339 ir->polling = 1; /* ms */
340 ir->last_gpio = ir_extract_bits(bttv_gpio_read(&btv->c),
341 ir->mask_keycode);
342 break;
287 } 343 }
288 if (NULL == ir_codes) { 344 if (NULL == ir_codes) {
289 dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n", btv->c.type); 345 dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n", btv->c.type);
diff --git a/drivers/media/video/bt8xx/bttv.h b/drivers/media/video/bt8xx/bttv.h
index 6d93d16c96e4..46cb90e0985b 100644
--- a/drivers/media/video/bt8xx/bttv.h
+++ b/drivers/media/video/bt8xx/bttv.h
@@ -176,7 +176,7 @@
176#define BTTV_BOARD_TYPHOON_TVTUNERPCI 0x95 176#define BTTV_BOARD_TYPHOON_TVTUNERPCI 0x95
177#define BTTV_BOARD_GEOVISION_GV600 0x96 177#define BTTV_BOARD_GEOVISION_GV600 0x96
178#define BTTV_BOARD_KOZUMI_KTV_01C 0x97 178#define BTTV_BOARD_KOZUMI_KTV_01C 0x97
179 179#define BTTV_BOARD_ENLTV_FM_2 0x98
180 180
181/* more card-specific defines */ 181/* more card-specific defines */
182#define PT2254_L_CHANNEL 0x10 182#define PT2254_L_CHANNEL 0x10
diff --git a/drivers/media/video/btcx-risc.c b/drivers/media/video/btcx-risc.c
index 3324ab38f58c..ac1b2687a20d 100644
--- a/drivers/media/video/btcx-risc.c
+++ b/drivers/media/video/btcx-risc.c
@@ -64,7 +64,7 @@ int btcx_riscmem_alloc(struct pci_dev *pci,
64 unsigned int size) 64 unsigned int size)
65{ 65{
66 __le32 *cpu; 66 __le32 *cpu;
67 dma_addr_t dma; 67 dma_addr_t dma = 0;
68 68
69 if (NULL != risc->cpu && risc->size < size) 69 if (NULL != risc->cpu && risc->size < size)
70 btcx_riscmem_free(pci,risc); 70 btcx_riscmem_free(pci,risc);
diff --git a/drivers/media/video/bw-qcam.c b/drivers/media/video/bw-qcam.c
index 6e39e253ce53..ace4ff9ea023 100644
--- a/drivers/media/video/bw-qcam.c
+++ b/drivers/media/video/bw-qcam.c
@@ -495,7 +495,7 @@ static void qc_set(struct qcam_device *q)
495 val2 = (((q->port_mode & QC_MODE_MASK) == QC_BIDIR) ? 24 : 8) * 495 val2 = (((q->port_mode & QC_MODE_MASK) == QC_BIDIR) ? 24 : 8) *
496 q->transfer_scale; 496 q->transfer_scale;
497 } 497 }
498 val = (val + val2 - 1) / val2; 498 val = DIV_ROUND_UP(val, val2);
499 qc_command(q, 0x13); 499 qc_command(q, 0x13);
500 qc_command(q, val); 500 qc_command(q, val);
501 501
@@ -651,7 +651,7 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
651 transperline = q->width * q->bpp; 651 transperline = q->width * q->bpp;
652 divisor = (((q->port_mode & QC_MODE_MASK) == QC_BIDIR) ? 24 : 8) * 652 divisor = (((q->port_mode & QC_MODE_MASK) == QC_BIDIR) ? 24 : 8) *
653 q->transfer_scale; 653 q->transfer_scale;
654 transperline = (transperline + divisor - 1) / divisor; 654 transperline = DIV_ROUND_UP(transperline, divisor);
655 655
656 for (i = 0, yield = yieldlines; i < linestotrans; i++) 656 for (i = 0, yield = yieldlines; i < linestotrans; i++)
657 { 657 {
@@ -894,10 +894,27 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
894 return len; 894 return len;
895} 895}
896 896
897static int qcam_exclusive_open(struct inode *inode, struct file *file)
898{
899 struct video_device *dev = video_devdata(file);
900 struct qcam_device *qcam = (struct qcam_device *)dev;
901
902 return test_and_set_bit(0, &qcam->in_use) ? -EBUSY : 0;
903}
904
905static int qcam_exclusive_release(struct inode *inode, struct file *file)
906{
907 struct video_device *dev = video_devdata(file);
908 struct qcam_device *qcam = (struct qcam_device *)dev;
909
910 clear_bit(0, &qcam->in_use);
911 return 0;
912}
913
897static const struct file_operations qcam_fops = { 914static const struct file_operations qcam_fops = {
898 .owner = THIS_MODULE, 915 .owner = THIS_MODULE,
899 .open = video_exclusive_open, 916 .open = qcam_exclusive_open,
900 .release = video_exclusive_release, 917 .release = qcam_exclusive_release,
901 .ioctl = qcam_ioctl, 918 .ioctl = qcam_ioctl,
902#ifdef CONFIG_COMPAT 919#ifdef CONFIG_COMPAT
903 .compat_ioctl = v4l_compat_ioctl32, 920 .compat_ioctl = v4l_compat_ioctl32,
@@ -909,6 +926,7 @@ static struct video_device qcam_template=
909{ 926{
910 .name = "Connectix Quickcam", 927 .name = "Connectix Quickcam",
911 .fops = &qcam_fops, 928 .fops = &qcam_fops,
929 .release = video_device_release_empty,
912}; 930};
913 931
914#define MAX_CAMS 4 932#define MAX_CAMS 4
diff --git a/drivers/media/video/bw-qcam.h b/drivers/media/video/bw-qcam.h
index 6701dafbc0da..8a60c5de0935 100644
--- a/drivers/media/video/bw-qcam.h
+++ b/drivers/media/video/bw-qcam.h
@@ -65,4 +65,5 @@ struct qcam_device {
65 int top, left; 65 int top, left;
66 int status; 66 int status;
67 unsigned int saved_bits; 67 unsigned int saved_bits;
68 unsigned long in_use;
68}; 69};
diff --git a/drivers/media/video/c-qcam.c b/drivers/media/video/c-qcam.c
index 7f6c6b4bec10..17aa0adb3467 100644
--- a/drivers/media/video/c-qcam.c
+++ b/drivers/media/video/c-qcam.c
@@ -51,6 +51,7 @@ struct qcam_device {
51 int contrast, brightness, whitebal; 51 int contrast, brightness, whitebal;
52 int top, left; 52 int top, left;
53 unsigned int bidirectional; 53 unsigned int bidirectional;
54 unsigned long in_use;
54 struct mutex lock; 55 struct mutex lock;
55}; 56};
56 57
@@ -687,11 +688,28 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
687 return len; 688 return len;
688} 689}
689 690
691static int qcam_exclusive_open(struct inode *inode, struct file *file)
692{
693 struct video_device *dev = video_devdata(file);
694 struct qcam_device *qcam = (struct qcam_device *)dev;
695
696 return test_and_set_bit(0, &qcam->in_use) ? -EBUSY : 0;
697}
698
699static int qcam_exclusive_release(struct inode *inode, struct file *file)
700{
701 struct video_device *dev = video_devdata(file);
702 struct qcam_device *qcam = (struct qcam_device *)dev;
703
704 clear_bit(0, &qcam->in_use);
705 return 0;
706}
707
690/* video device template */ 708/* video device template */
691static const struct file_operations qcam_fops = { 709static const struct file_operations qcam_fops = {
692 .owner = THIS_MODULE, 710 .owner = THIS_MODULE,
693 .open = video_exclusive_open, 711 .open = qcam_exclusive_open,
694 .release = video_exclusive_release, 712 .release = qcam_exclusive_release,
695 .ioctl = qcam_ioctl, 713 .ioctl = qcam_ioctl,
696#ifdef CONFIG_COMPAT 714#ifdef CONFIG_COMPAT
697 .compat_ioctl = v4l_compat_ioctl32, 715 .compat_ioctl = v4l_compat_ioctl32,
@@ -704,6 +722,7 @@ static struct video_device qcam_template=
704{ 722{
705 .name = "Colour QuickCam", 723 .name = "Colour QuickCam",
706 .fops = &qcam_fops, 724 .fops = &qcam_fops,
725 .release = video_device_release_empty,
707}; 726};
708 727
709/* Initialize the QuickCam driver control structure. */ 728/* Initialize the QuickCam driver control structure. */
diff --git a/drivers/media/video/cafe_ccic.c b/drivers/media/video/cafe_ccic.c
index 5405c30dbb04..fc9497bdd322 100644
--- a/drivers/media/video/cafe_ccic.c
+++ b/drivers/media/video/cafe_ccic.c
@@ -1476,9 +1476,12 @@ static int cafe_v4l_open(struct inode *inode, struct file *filp)
1476{ 1476{
1477 struct cafe_camera *cam; 1477 struct cafe_camera *cam;
1478 1478
1479 lock_kernel();
1479 cam = cafe_find_dev(iminor(inode)); 1480 cam = cafe_find_dev(iminor(inode));
1480 if (cam == NULL) 1481 if (cam == NULL) {
1482 unlock_kernel();
1481 return -ENODEV; 1483 return -ENODEV;
1484 }
1482 filp->private_data = cam; 1485 filp->private_data = cam;
1483 1486
1484 mutex_lock(&cam->s_mutex); 1487 mutex_lock(&cam->s_mutex);
@@ -1490,6 +1493,7 @@ static int cafe_v4l_open(struct inode *inode, struct file *filp)
1490 } 1493 }
1491 (cam->users)++; 1494 (cam->users)++;
1492 mutex_unlock(&cam->s_mutex); 1495 mutex_unlock(&cam->s_mutex);
1496 unlock_kernel();
1493 return 0; 1497 return 0;
1494} 1498}
1495 1499
@@ -2092,15 +2096,8 @@ static int cafe_pci_probe(struct pci_dev *pdev,
2092 const struct pci_device_id *id) 2096 const struct pci_device_id *id)
2093{ 2097{
2094 int ret; 2098 int ret;
2095 u16 classword;
2096 struct cafe_camera *cam; 2099 struct cafe_camera *cam;
2097 /* 2100
2098 * Make sure we have a camera here - we'll get calls for
2099 * the other cafe devices as well.
2100 */
2101 pci_read_config_word(pdev, PCI_CLASS_DEVICE, &classword);
2102 if (classword != PCI_CLASS_MULTIMEDIA_VIDEO)
2103 return -ENODEV;
2104 /* 2101 /*
2105 * Start putting together one of our big camera structures. 2102 * Start putting together one of our big camera structures.
2106 */ 2103 */
@@ -2288,8 +2285,8 @@ static int cafe_pci_resume(struct pci_dev *pdev)
2288 2285
2289 2286
2290static struct pci_device_id cafe_ids[] = { 2287static struct pci_device_id cafe_ids[] = {
2291 { PCI_DEVICE(0x11ab, 0x4100) }, /* Eventual real ID */ 2288 { PCI_DEVICE(PCI_VENDOR_ID_MARVELL,
2292 { PCI_DEVICE(0x11ab, 0x4102) }, /* Really eventual real ID */ 2289 PCI_DEVICE_ID_MARVELL_88ALP01_CCIC) },
2293 { 0, } 2290 { 0, }
2294}; 2291};
2295 2292
diff --git a/drivers/media/video/cpia.c b/drivers/media/video/cpia.c
index a661800b0e69..1798b779a25a 100644
--- a/drivers/media/video/cpia.c
+++ b/drivers/media/video/cpia.c
@@ -39,10 +39,6 @@
39#include <asm/io.h> 39#include <asm/io.h>
40#include <linux/mutex.h> 40#include <linux/mutex.h>
41 41
42#ifdef CONFIG_KMOD
43#include <linux/kmod.h>
44#endif
45
46#include "cpia.h" 42#include "cpia.h"
47 43
48static int video_nr = -1; 44static int video_nr = -1;
@@ -3155,7 +3151,7 @@ static void put_cam(struct cpia_camera_ops* ops)
3155static int cpia_open(struct inode *inode, struct file *file) 3151static int cpia_open(struct inode *inode, struct file *file)
3156{ 3152{
3157 struct video_device *dev = video_devdata(file); 3153 struct video_device *dev = video_devdata(file);
3158 struct cam_data *cam = dev->priv; 3154 struct cam_data *cam = video_get_drvdata(dev);
3159 int err; 3155 int err;
3160 3156
3161 if (!cam) { 3157 if (!cam) {
@@ -3202,7 +3198,7 @@ static int cpia_open(struct inode *inode, struct file *file)
3202 3198
3203 /* Set ownership of /proc/cpia/videoX to current user */ 3199 /* Set ownership of /proc/cpia/videoX to current user */
3204 if(cam->proc_entry) 3200 if(cam->proc_entry)
3205 cam->proc_entry->uid = current->uid; 3201 cam->proc_entry->uid = current_uid();
3206 3202
3207 /* set mark for loading first frame uncompressed */ 3203 /* set mark for loading first frame uncompressed */
3208 cam->first_frame = 1; 3204 cam->first_frame = 1;
@@ -3232,7 +3228,7 @@ static int cpia_open(struct inode *inode, struct file *file)
3232static int cpia_close(struct inode *inode, struct file *file) 3228static int cpia_close(struct inode *inode, struct file *file)
3233{ 3229{
3234 struct video_device *dev = file->private_data; 3230 struct video_device *dev = file->private_data;
3235 struct cam_data *cam = dev->priv; 3231 struct cam_data *cam = video_get_drvdata(dev);
3236 3232
3237 if (cam->ops) { 3233 if (cam->ops) {
3238 /* Return ownership of /proc/cpia/videoX to root */ 3234 /* Return ownership of /proc/cpia/videoX to root */
@@ -3284,7 +3280,7 @@ static ssize_t cpia_read(struct file *file, char __user *buf,
3284 size_t count, loff_t *ppos) 3280 size_t count, loff_t *ppos)
3285{ 3281{
3286 struct video_device *dev = file->private_data; 3282 struct video_device *dev = file->private_data;
3287 struct cam_data *cam = dev->priv; 3283 struct cam_data *cam = video_get_drvdata(dev);
3288 int err; 3284 int err;
3289 3285
3290 /* make this _really_ smp and multithread-safe */ 3286 /* make this _really_ smp and multithread-safe */
@@ -3341,7 +3337,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
3341 unsigned int ioctlnr, void *arg) 3337 unsigned int ioctlnr, void *arg)
3342{ 3338{
3343 struct video_device *dev = file->private_data; 3339 struct video_device *dev = file->private_data;
3344 struct cam_data *cam = dev->priv; 3340 struct cam_data *cam = video_get_drvdata(dev);
3345 int retval = 0; 3341 int retval = 0;
3346 3342
3347 if (!cam || !cam->ops) 3343 if (!cam || !cam->ops)
@@ -3739,7 +3735,7 @@ static int cpia_mmap(struct file *file, struct vm_area_struct *vma)
3739 unsigned long start = vma->vm_start; 3735 unsigned long start = vma->vm_start;
3740 unsigned long size = vma->vm_end - vma->vm_start; 3736 unsigned long size = vma->vm_end - vma->vm_start;
3741 unsigned long page, pos; 3737 unsigned long page, pos;
3742 struct cam_data *cam = dev->priv; 3738 struct cam_data *cam = video_get_drvdata(dev);
3743 int retval; 3739 int retval;
3744 3740
3745 if (!cam || !cam->ops) 3741 if (!cam || !cam->ops)
@@ -3801,6 +3797,7 @@ static const struct file_operations cpia_fops = {
3801static struct video_device cpia_template = { 3797static struct video_device cpia_template = {
3802 .name = "CPiA Camera", 3798 .name = "CPiA Camera",
3803 .fops = &cpia_fops, 3799 .fops = &cpia_fops,
3800 .release = video_device_release_empty,
3804}; 3801};
3805 3802
3806/* initialise cam_data structure */ 3803/* initialise cam_data structure */
@@ -3928,7 +3925,7 @@ static void init_camera_struct(struct cam_data *cam,
3928 cam->proc_entry = NULL; 3925 cam->proc_entry = NULL;
3929 3926
3930 memcpy(&cam->vdev, &cpia_template, sizeof(cpia_template)); 3927 memcpy(&cam->vdev, &cpia_template, sizeof(cpia_template));
3931 cam->vdev.priv = cam; 3928 video_set_drvdata(&cam->vdev, cam);
3932 3929
3933 cam->curframe = 0; 3930 cam->curframe = 0;
3934 for (i = 0; i < FRAME_NUM; i++) { 3931 for (i = 0; i < FRAME_NUM; i++) {
diff --git a/drivers/media/video/cpia2/cpia2_core.c b/drivers/media/video/cpia2/cpia2_core.c
index af8b9ec8e358..7e791b6923f9 100644
--- a/drivers/media/video/cpia2/cpia2_core.c
+++ b/drivers/media/video/cpia2/cpia2_core.c
@@ -1537,7 +1537,7 @@ static int config_sensor_500(struct camera_data *cam,
1537 * 1537 *
1538 * This sets all user changeable properties to the values in cam->params. 1538 * This sets all user changeable properties to the values in cam->params.
1539 *****************************************************************************/ 1539 *****************************************************************************/
1540int set_all_properties(struct camera_data *cam) 1540static int set_all_properties(struct camera_data *cam)
1541{ 1541{
1542 /** 1542 /**
1543 * Don't set target_kb here, it will be set later. 1543 * Don't set target_kb here, it will be set later.
@@ -1588,7 +1588,7 @@ void cpia2_save_camera_state(struct camera_data *cam)
1588 * get_color_params 1588 * get_color_params
1589 * 1589 *
1590 *****************************************************************************/ 1590 *****************************************************************************/
1591void get_color_params(struct camera_data *cam) 1591static void get_color_params(struct camera_data *cam)
1592{ 1592{
1593 cpia2_do_command(cam, CPIA2_CMD_GET_VP_BRIGHTNESS, TRANSFER_READ, 0); 1593 cpia2_do_command(cam, CPIA2_CMD_GET_VP_BRIGHTNESS, TRANSFER_READ, 0);
1594 cpia2_do_command(cam, CPIA2_CMD_GET_VP_SATURATION, TRANSFER_READ, 0); 1594 cpia2_do_command(cam, CPIA2_CMD_GET_VP_SATURATION, TRANSFER_READ, 0);
@@ -1881,7 +1881,7 @@ void cpia2_set_saturation(struct camera_data *cam, unsigned char value)
1881 * wake_system 1881 * wake_system
1882 * 1882 *
1883 *****************************************************************************/ 1883 *****************************************************************************/
1884void wake_system(struct camera_data *cam) 1884static void wake_system(struct camera_data *cam)
1885{ 1885{
1886 cpia2_do_command(cam, CPIA2_CMD_SET_WAKEUP, TRANSFER_WRITE, 0); 1886 cpia2_do_command(cam, CPIA2_CMD_SET_WAKEUP, TRANSFER_WRITE, 0);
1887} 1887}
@@ -1892,7 +1892,7 @@ void wake_system(struct camera_data *cam)
1892 * 1892 *
1893 * Valid for STV500 sensor only 1893 * Valid for STV500 sensor only
1894 *****************************************************************************/ 1894 *****************************************************************************/
1895void set_lowlight_boost(struct camera_data *cam) 1895static void set_lowlight_boost(struct camera_data *cam)
1896{ 1896{
1897 struct cpia2_command cmd; 1897 struct cpia2_command cmd;
1898 1898
@@ -2169,7 +2169,7 @@ void cpia2_dbg_dump_registers(struct camera_data *cam)
2169 * 2169 *
2170 * Sets all values to the defaults 2170 * Sets all values to the defaults
2171 *****************************************************************************/ 2171 *****************************************************************************/
2172void reset_camera_struct(struct camera_data *cam) 2172static void reset_camera_struct(struct camera_data *cam)
2173{ 2173{
2174 /*** 2174 /***
2175 * The following parameter values are the defaults from the register map. 2175 * The following parameter values are the defaults from the register map.
diff --git a/drivers/media/video/cpia2/cpia2_usb.c b/drivers/media/video/cpia2/cpia2_usb.c
index a8a199047cbd..73511a542077 100644
--- a/drivers/media/video/cpia2/cpia2_usb.c
+++ b/drivers/media/video/cpia2/cpia2_usb.c
@@ -478,7 +478,7 @@ int cpia2_usb_change_streaming_alternate(struct camera_data *cam,
478 * set_alternate 478 * set_alternate
479 * 479 *
480 *****************************************************************************/ 480 *****************************************************************************/
481int set_alternate(struct camera_data *cam, unsigned int alt) 481static int set_alternate(struct camera_data *cam, unsigned int alt)
482{ 482{
483 int ret = 0; 483 int ret = 0;
484 484
diff --git a/drivers/media/video/cpia2/cpia2_v4l.c b/drivers/media/video/cpia2/cpia2_v4l.c
index eb9f15cd4c45..897e8d1a5c3c 100644
--- a/drivers/media/video/cpia2/cpia2_v4l.c
+++ b/drivers/media/video/cpia2/cpia2_v4l.c
@@ -241,8 +241,7 @@ static struct v4l2_queryctrl controls[] = {
241 *****************************************************************************/ 241 *****************************************************************************/
242static int cpia2_open(struct inode *inode, struct file *file) 242static int cpia2_open(struct inode *inode, struct file *file)
243{ 243{
244 struct video_device *dev = video_devdata(file); 244 struct camera_data *cam = video_drvdata(file);
245 struct camera_data *cam = video_get_drvdata(dev);
246 int retval = 0; 245 int retval = 0;
247 246
248 if (!cam) { 247 if (!cam) {
@@ -357,8 +356,7 @@ static int cpia2_close(struct inode *inode, struct file *file)
357static ssize_t cpia2_v4l_read(struct file *file, char __user *buf, size_t count, 356static ssize_t cpia2_v4l_read(struct file *file, char __user *buf, size_t count,
358 loff_t *off) 357 loff_t *off)
359{ 358{
360 struct video_device *dev = video_devdata(file); 359 struct camera_data *cam = video_drvdata(file);
361 struct camera_data *cam = video_get_drvdata(dev);
362 int noblock = file->f_flags&O_NONBLOCK; 360 int noblock = file->f_flags&O_NONBLOCK;
363 361
364 struct cpia2_fh *fh = file->private_data; 362 struct cpia2_fh *fh = file->private_data;
@@ -382,9 +380,7 @@ static ssize_t cpia2_v4l_read(struct file *file, char __user *buf, size_t count,
382 *****************************************************************************/ 380 *****************************************************************************/
383static unsigned int cpia2_v4l_poll(struct file *filp, struct poll_table_struct *wait) 381static unsigned int cpia2_v4l_poll(struct file *filp, struct poll_table_struct *wait)
384{ 382{
385 struct video_device *dev = video_devdata(filp); 383 struct camera_data *cam = video_drvdata(filp);
386 struct camera_data *cam = video_get_drvdata(dev);
387
388 struct cpia2_fh *fh = filp->private_data; 384 struct cpia2_fh *fh = filp->private_data;
389 385
390 if(!cam) 386 if(!cam)
@@ -1579,8 +1575,7 @@ static int ioctl_dqbuf(void *arg,struct camera_data *cam, struct file *file)
1579static int cpia2_do_ioctl(struct inode *inode, struct file *file, 1575static int cpia2_do_ioctl(struct inode *inode, struct file *file,
1580 unsigned int ioctl_nr, void *arg) 1576 unsigned int ioctl_nr, void *arg)
1581{ 1577{
1582 struct video_device *dev = video_devdata(file); 1578 struct camera_data *cam = video_drvdata(file);
1583 struct camera_data *cam = video_get_drvdata(dev);
1584 int retval = 0; 1579 int retval = 0;
1585 1580
1586 if (!cam) 1581 if (!cam)
@@ -1860,9 +1855,8 @@ static int cpia2_ioctl(struct inode *inode, struct file *file,
1860 *****************************************************************************/ 1855 *****************************************************************************/
1861static int cpia2_mmap(struct file *file, struct vm_area_struct *area) 1856static int cpia2_mmap(struct file *file, struct vm_area_struct *area)
1862{ 1857{
1858 struct camera_data *cam = video_drvdata(file);
1863 int retval; 1859 int retval;
1864 struct video_device *dev = video_devdata(file);
1865 struct camera_data *cam = video_get_drvdata(dev);
1866 1860
1867 /* Priority check */ 1861 /* Priority check */
1868 struct cpia2_fh *fh = file->private_data; 1862 struct cpia2_fh *fh = file->private_data;
diff --git a/drivers/media/video/cx18/Makefile b/drivers/media/video/cx18/Makefile
index b23d2e26120f..f7bf0edf93f9 100644
--- a/drivers/media/video/cx18/Makefile
+++ b/drivers/media/video/cx18/Makefile
@@ -2,7 +2,7 @@ cx18-objs := cx18-driver.o cx18-cards.o cx18-i2c.o cx18-firmware.o cx18-gpio.
2 cx18-queue.o cx18-streams.o cx18-fileops.o cx18-ioctl.o cx18-controls.o \ 2 cx18-queue.o cx18-streams.o cx18-fileops.o cx18-ioctl.o cx18-controls.o \
3 cx18-mailbox.o cx18-vbi.o cx18-audio.o cx18-video.o cx18-irq.o \ 3 cx18-mailbox.o cx18-vbi.o cx18-audio.o cx18-video.o cx18-irq.o \
4 cx18-av-core.o cx18-av-audio.o cx18-av-firmware.o cx18-av-vbi.o cx18-scb.o \ 4 cx18-av-core.o cx18-av-audio.o cx18-av-firmware.o cx18-av-vbi.o cx18-scb.o \
5 cx18-dvb.o 5 cx18-dvb.o cx18-io.o
6 6
7obj-$(CONFIG_VIDEO_CX18) += cx18.o 7obj-$(CONFIG_VIDEO_CX18) += cx18.o
8 8
diff --git a/drivers/media/video/cx18/cx18-audio.c b/drivers/media/video/cx18/cx18-audio.c
index 6d5b94fc7087..57beddf0af4d 100644
--- a/drivers/media/video/cx18/cx18-audio.c
+++ b/drivers/media/video/cx18/cx18-audio.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include "cx18-driver.h" 24#include "cx18-driver.h"
25#include "cx18-io.h"
25#include "cx18-i2c.h" 26#include "cx18-i2c.h"
26#include "cx18-cards.h" 27#include "cx18-cards.h"
27#include "cx18-audio.h" 28#include "cx18-audio.h"
@@ -60,10 +61,10 @@ int cx18_audio_set_io(struct cx18 *cx)
60 if (err) 61 if (err)
61 return err; 62 return err;
62 63
63 val = read_reg(CX18_AUDIO_ENABLE) & ~0x30; 64 val = cx18_read_reg(cx, CX18_AUDIO_ENABLE) & ~0x30;
64 val |= (audio_input > CX18_AV_AUDIO_SERIAL2) ? 0x20 : 65 val |= (audio_input > CX18_AV_AUDIO_SERIAL2) ? 0x20 :
65 (audio_input << 4); 66 (audio_input << 4);
66 write_reg(val | 0xb00, CX18_AUDIO_ENABLE); 67 cx18_write_reg(cx, val | 0xb00, CX18_AUDIO_ENABLE);
67 cx18_vapi(cx, CX18_APU_RESETAI, 1, 0); 68 cx18_vapi(cx, CX18_APU_RESETAI, 1, 0);
68 return 0; 69 return 0;
69} 70}
diff --git a/drivers/media/video/cx18/cx18-av-core.c b/drivers/media/video/cx18/cx18-av-core.c
index 3b0a2c450605..73f5141a42d1 100644
--- a/drivers/media/video/cx18/cx18-av-core.c
+++ b/drivers/media/video/cx18/cx18-av-core.c
@@ -22,27 +22,35 @@
22 */ 22 */
23 23
24#include "cx18-driver.h" 24#include "cx18-driver.h"
25#include "cx18-io.h"
25 26
26int cx18_av_write(struct cx18 *cx, u16 addr, u8 value) 27int cx18_av_write(struct cx18 *cx, u16 addr, u8 value)
27{ 28{
28 u32 x = readl(cx->reg_mem + 0xc40000 + (addr & ~3)); 29 u32 reg = 0xc40000 + (addr & ~3);
29 u32 mask = 0xff; 30 u32 mask = 0xff;
30 int shift = (addr & 3) * 8; 31 int shift = (addr & 3) * 8;
32 u32 x = cx18_read_reg(cx, reg);
31 33
32 x = (x & ~(mask << shift)) | ((u32)value << shift); 34 x = (x & ~(mask << shift)) | ((u32)value << shift);
33 writel(x, cx->reg_mem + 0xc40000 + (addr & ~3)); 35 cx18_write_reg(cx, x, reg);
34 return 0; 36 return 0;
35} 37}
36 38
37int cx18_av_write4(struct cx18 *cx, u16 addr, u32 value) 39int cx18_av_write4(struct cx18 *cx, u16 addr, u32 value)
38{ 40{
39 writel(value, cx->reg_mem + 0xc40000 + addr); 41 cx18_write_reg(cx, value, 0xc40000 + addr);
42 return 0;
43}
44
45int cx18_av_write4_noretry(struct cx18 *cx, u16 addr, u32 value)
46{
47 cx18_write_reg_noretry(cx, value, 0xc40000 + addr);
40 return 0; 48 return 0;
41} 49}
42 50
43u8 cx18_av_read(struct cx18 *cx, u16 addr) 51u8 cx18_av_read(struct cx18 *cx, u16 addr)
44{ 52{
45 u32 x = readl(cx->reg_mem + 0xc40000 + (addr & ~3)); 53 u32 x = cx18_read_reg(cx, 0xc40000 + (addr & ~3));
46 int shift = (addr & 3) * 8; 54 int shift = (addr & 3) * 8;
47 55
48 return (x >> shift) & 0xff; 56 return (x >> shift) & 0xff;
@@ -50,7 +58,12 @@ u8 cx18_av_read(struct cx18 *cx, u16 addr)
50 58
51u32 cx18_av_read4(struct cx18 *cx, u16 addr) 59u32 cx18_av_read4(struct cx18 *cx, u16 addr)
52{ 60{
53 return readl(cx->reg_mem + 0xc40000 + addr); 61 return cx18_read_reg(cx, 0xc40000 + addr);
62}
63
64u32 cx18_av_read4_noretry(struct cx18 *cx, u16 addr)
65{
66 return cx18_read_reg_noretry(cx, 0xc40000 + addr);
54} 67}
55 68
56int cx18_av_and_or(struct cx18 *cx, u16 addr, unsigned and_mask, 69int cx18_av_and_or(struct cx18 *cx, u16 addr, unsigned and_mask,
diff --git a/drivers/media/video/cx18/cx18-av-core.h b/drivers/media/video/cx18/cx18-av-core.h
index eb61fa1e0965..b67d8df20cc6 100644
--- a/drivers/media/video/cx18/cx18-av-core.h
+++ b/drivers/media/video/cx18/cx18-av-core.h
@@ -301,8 +301,10 @@ struct cx18_av_state {
301/* cx18_av-core.c */ 301/* cx18_av-core.c */
302int cx18_av_write(struct cx18 *cx, u16 addr, u8 value); 302int cx18_av_write(struct cx18 *cx, u16 addr, u8 value);
303int cx18_av_write4(struct cx18 *cx, u16 addr, u32 value); 303int cx18_av_write4(struct cx18 *cx, u16 addr, u32 value);
304int cx18_av_write4_noretry(struct cx18 *cx, u16 addr, u32 value);
304u8 cx18_av_read(struct cx18 *cx, u16 addr); 305u8 cx18_av_read(struct cx18 *cx, u16 addr);
305u32 cx18_av_read4(struct cx18 *cx, u16 addr); 306u32 cx18_av_read4(struct cx18 *cx, u16 addr);
307u32 cx18_av_read4_noretry(struct cx18 *cx, u16 addr);
306int cx18_av_and_or(struct cx18 *cx, u16 addr, unsigned mask, u8 value); 308int cx18_av_and_or(struct cx18 *cx, u16 addr, unsigned mask, u8 value);
307int cx18_av_and_or4(struct cx18 *cx, u16 addr, u32 mask, u32 value); 309int cx18_av_and_or4(struct cx18 *cx, u16 addr, u32 mask, u32 value);
308int cx18_av_cmd(struct cx18 *cx, unsigned int cmd, void *arg); 310int cx18_av_cmd(struct cx18 *cx, unsigned int cmd, void *arg);
diff --git a/drivers/media/video/cx18/cx18-av-firmware.c b/drivers/media/video/cx18/cx18-av-firmware.c
index e996a4e3123a..522a035b2e8f 100644
--- a/drivers/media/video/cx18/cx18-av-firmware.c
+++ b/drivers/media/video/cx18/cx18-av-firmware.c
@@ -20,6 +20,7 @@
20 */ 20 */
21 21
22#include "cx18-driver.h" 22#include "cx18-driver.h"
23#include "cx18-io.h"
23#include <linux/firmware.h> 24#include <linux/firmware.h>
24 25
25#define CX18_AUDIO_ENABLE 0xc72014 26#define CX18_AUDIO_ENABLE 0xc72014
@@ -49,7 +50,7 @@ int cx18_av_loadfw(struct cx18 *cx)
49 cx18_av_write4(cx, 0x8100, 0x00010000); 50 cx18_av_write4(cx, 0x8100, 0x00010000);
50 51
51 /* Put the 8051 in reset and enable firmware upload */ 52 /* Put the 8051 in reset and enable firmware upload */
52 cx18_av_write4(cx, CXADEC_DL_CTL, 0x0F000000); 53 cx18_av_write4_noretry(cx, CXADEC_DL_CTL, 0x0F000000);
53 54
54 ptr = fw->data; 55 ptr = fw->data;
55 size = fw->size; 56 size = fw->size;
@@ -58,22 +59,28 @@ int cx18_av_loadfw(struct cx18 *cx)
58 u32 dl_control = 0x0F000000 | i | ((u32)ptr[i] << 16); 59 u32 dl_control = 0x0F000000 | i | ((u32)ptr[i] << 16);
59 u32 value = 0; 60 u32 value = 0;
60 int retries2; 61 int retries2;
62 int unrec_err = 0;
61 63
62 for (retries2 = 0; retries2 < 5; retries2++) { 64 for (retries2 = 0; retries2 < CX18_MAX_MMIO_RETRIES;
63 cx18_av_write4(cx, CXADEC_DL_CTL, dl_control); 65 retries2++) {
66 cx18_av_write4_noretry(cx, CXADEC_DL_CTL,
67 dl_control);
64 udelay(10); 68 udelay(10);
65 value = cx18_av_read4(cx, CXADEC_DL_CTL); 69 value = cx18_av_read4_noretry(cx,
70 CXADEC_DL_CTL);
66 if (value == dl_control) 71 if (value == dl_control)
67 break; 72 break;
68 /* Check if we can correct the byte by changing 73 /* Check if we can correct the byte by changing
69 the address. We can only write the lower 74 the address. We can only write the lower
70 address byte of the address. */ 75 address byte of the address. */
71 if ((value & 0x3F00) != (dl_control & 0x3F00)) { 76 if ((value & 0x3F00) != (dl_control & 0x3F00)) {
72 retries2 = 5; 77 unrec_err = 1;
73 break; 78 break;
74 } 79 }
75 } 80 }
76 if (retries2 >= 5) 81 cx18_log_write_retries(cx, retries2,
82 cx->reg_mem + 0xc40000 + CXADEC_DL_CTL);
83 if (unrec_err || retries2 >= CX18_MAX_MMIO_RETRIES)
77 break; 84 break;
78 } 85 }
79 if (i == size) 86 if (i == size)
@@ -119,10 +126,10 @@ int cx18_av_loadfw(struct cx18 *cx)
119 have a name in the spec. */ 126 have a name in the spec. */
120 cx18_av_write4(cx, 0x09CC, 1); 127 cx18_av_write4(cx, 0x09CC, 1);
121 128
122 v = read_reg(CX18_AUDIO_ENABLE); 129 v = cx18_read_reg(cx, CX18_AUDIO_ENABLE);
123 /* If bit 11 is 1 */ 130 /* If bit 11 is 1, clear bit 10 */
124 if (v & 0x800) 131 if (v & 0x800)
125 write_reg(v & 0xFFFFFBFF, CX18_AUDIO_ENABLE); /* Clear bit 10 */ 132 cx18_write_reg(cx, v & 0xFFFFFBFF, CX18_AUDIO_ENABLE);
126 133
127 /* Enable WW auto audio standard detection */ 134 /* Enable WW auto audio standard detection */
128 v = cx18_av_read4(cx, CXADEC_STD_DET_CTL); 135 v = cx18_av_read4(cx, CXADEC_STD_DET_CTL);
diff --git a/drivers/media/video/cx18/cx18-cards.c b/drivers/media/video/cx18/cx18-cards.c
index 3cb9734ec07b..5efe01ebe9db 100644
--- a/drivers/media/video/cx18/cx18-cards.c
+++ b/drivers/media/video/cx18/cx18-cards.c
@@ -292,12 +292,111 @@ static const struct cx18_card cx18_card_cnxt_raptor_pal = {
292 292
293/* ------------------------------------------------------------------------- */ 293/* ------------------------------------------------------------------------- */
294 294
295/* Toshiba Qosmio laptop internal DVB-T/Analog Hybrid Tuner */
296
297static const struct cx18_card_pci_info cx18_pci_toshiba_qosmio_dvbt[] = {
298 { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_TOSHIBA, 0x0110 },
299 { 0, 0, 0 }
300};
301
302static const struct cx18_card cx18_card_toshiba_qosmio_dvbt = {
303 .type = CX18_CARD_TOSHIBA_QOSMIO_DVBT,
304 .name = "Toshiba Qosmio DVB-T/Analog",
305 .comment = "Experimenters and photos needed for device to work well.\n"
306 "\tTo help, mail the ivtv-devel list (www.ivtvdriver.org).\n",
307 .v4l2_capabilities = CX18_CAP_ENCODER,
308 .hw_audio_ctrl = CX18_HW_CX23418,
309 .hw_all = CX18_HW_TUNER,
310 .video_inputs = {
311 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE6 },
312 { CX18_CARD_INPUT_SVIDEO1, 1,
313 CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
314 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE1 },
315 },
316 .audio_inputs = {
317 { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5, 0 },
318 { CX18_CARD_INPUT_LINE_IN1, CX18_AV_AUDIO_SERIAL1, 1 },
319 },
320 .tuners = {
321 { .std = V4L2_STD_ALL, .tuner = TUNER_XC2028 },
322 },
323 .ddr = {
324 .chip_config = 0x202,
325 .refresh = 0x3bb,
326 .timing1 = 0x33320a63,
327 .timing2 = 0x0a,
328 .tune_lane = 0,
329 .initial_emrs = 0x42,
330 },
331 .xceive_pin = 15,
332 .pci_list = cx18_pci_toshiba_qosmio_dvbt,
333 .i2c = &cx18_i2c_std,
334};
335
336/* ------------------------------------------------------------------------- */
337
338/* Leadtek WinFast PVR2100 */
339
340static const struct cx18_card_pci_info cx18_pci_leadtek_pvr2100[] = {
341 { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_LEADTEK, 0x6f27 },
342 { 0, 0, 0 }
343};
344
345static const struct cx18_card cx18_card_leadtek_pvr2100 = {
346 .type = CX18_CARD_LEADTEK_PVR2100,
347 .name = "Leadtek WinFast PVR2100",
348 .comment = "Experimenters and photos needed for device to work well.\n"
349 "\tTo help, mail the ivtv-devel list (www.ivtvdriver.org).\n",
350 .v4l2_capabilities = CX18_CAP_ENCODER,
351 .hw_audio_ctrl = CX18_HW_CX23418,
352 .hw_muxer = CX18_HW_GPIO,
353 .hw_all = CX18_HW_TUNER | CX18_HW_GPIO,
354 .video_inputs = {
355 { CX18_CARD_INPUT_VID_TUNER, 0, CX18_AV_COMPOSITE2 },
356 { CX18_CARD_INPUT_SVIDEO1, 1,
357 CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
358 { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE7 },
359 },
360 .audio_inputs = {
361 { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5, 0 },
362 { CX18_CARD_INPUT_LINE_IN1, CX18_AV_AUDIO_SERIAL1, 1 },
363 },
364 .tuners = {
365 /* XC3028 tuner */
366 { .std = V4L2_STD_ALL, .tuner = TUNER_XC2028 },
367 },
368 .radio_input = { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5, 2 },
369 .ddr = {
370 /*
371 * Pointer to proper DDR config values provided by
372 * Terry Wu <terrywu at leadtek.com.tw>
373 */
374 .chip_config = 0x303,
375 .refresh = 0x3bb,
376 .timing1 = 0x24220e83,
377 .timing2 = 0x1f,
378 .tune_lane = 0,
379 .initial_emrs = 0x2,
380 },
381 .gpio_init.initial_value = 0x6,
382 .gpio_init.direction = 0x7,
383 .gpio_audio_input = { .mask = 0x7,
384 .tuner = 0x6, .linein = 0x2, .radio = 0x2 },
385 .xceive_pin = 15,
386 .pci_list = cx18_pci_leadtek_pvr2100,
387 .i2c = &cx18_i2c_std,
388};
389
390/* ------------------------------------------------------------------------- */
391
295static const struct cx18_card *cx18_card_list[] = { 392static const struct cx18_card *cx18_card_list[] = {
296 &cx18_card_hvr1600_esmt, 393 &cx18_card_hvr1600_esmt,
297 &cx18_card_hvr1600_samsung, 394 &cx18_card_hvr1600_samsung,
298 &cx18_card_h900, 395 &cx18_card_h900,
299 &cx18_card_mpc718, 396 &cx18_card_mpc718,
300 &cx18_card_cnxt_raptor_pal, 397 &cx18_card_cnxt_raptor_pal,
398 &cx18_card_toshiba_qosmio_dvbt,
399 &cx18_card_leadtek_pvr2100,
301}; 400};
302 401
303const struct cx18_card *cx18_get_card(u16 index) 402const struct cx18_card *cx18_get_card(u16 index)
diff --git a/drivers/media/video/cx18/cx18-driver.c b/drivers/media/video/cx18/cx18-driver.c
index bd18afebbf86..085121c2b47f 100644
--- a/drivers/media/video/cx18/cx18-driver.c
+++ b/drivers/media/video/cx18/cx18-driver.c
@@ -4,6 +4,7 @@
4 * Derived from ivtv-driver.c 4 * Derived from ivtv-driver.c
5 * 5 *
6 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl> 6 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
7 * Copyright (C) 2008 Andy Walls <awalls@radix.net>
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify 9 * 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 * it under the terms of the GNU General Public License as published by
@@ -22,6 +23,7 @@
22 */ 23 */
23 24
24#include "cx18-driver.h" 25#include "cx18-driver.h"
26#include "cx18-io.h"
25#include "cx18-version.h" 27#include "cx18-version.h"
26#include "cx18-cards.h" 28#include "cx18-cards.h"
27#include "cx18-i2c.h" 29#include "cx18-i2c.h"
@@ -73,10 +75,14 @@ static int radio[CX18_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1,
73 -1, -1, -1, -1, -1, -1, -1, -1, 75 -1, -1, -1, -1, -1, -1, -1, -1,
74 -1, -1, -1, -1, -1, -1, -1, -1, 76 -1, -1, -1, -1, -1, -1, -1, -1,
75 -1, -1, -1, -1, -1, -1, -1, -1 }; 77 -1, -1, -1, -1, -1, -1, -1, -1 };
76 78static int mmio_ndelay[CX18_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1,
79 -1, -1, -1, -1, -1, -1, -1, -1,
80 -1, -1, -1, -1, -1, -1, -1, -1,
81 -1, -1, -1, -1, -1, -1, -1, -1 };
77static unsigned cardtype_c = 1; 82static unsigned cardtype_c = 1;
78static unsigned tuner_c = 1; 83static unsigned tuner_c = 1;
79static unsigned radio_c = 1; 84static unsigned radio_c = 1;
85static unsigned mmio_ndelay_c = 1;
80static char pal[] = "--"; 86static char pal[] = "--";
81static char secam[] = "--"; 87static char secam[] = "--";
82static char ntsc[] = "-"; 88static char ntsc[] = "-";
@@ -90,15 +96,18 @@ static int enc_pcm_buffers = CX18_DEFAULT_ENC_PCM_BUFFERS;
90 96
91static int cx18_pci_latency = 1; 97static int cx18_pci_latency = 1;
92 98
99int cx18_retry_mmio = 1;
93int cx18_debug; 100int cx18_debug;
94 101
95module_param_array(tuner, int, &tuner_c, 0644); 102module_param_array(tuner, int, &tuner_c, 0644);
96module_param_array(radio, bool, &radio_c, 0644); 103module_param_array(radio, bool, &radio_c, 0644);
97module_param_array(cardtype, int, &cardtype_c, 0644); 104module_param_array(cardtype, int, &cardtype_c, 0644);
105module_param_array(mmio_ndelay, int, &mmio_ndelay_c, 0644);
98module_param_string(pal, pal, sizeof(pal), 0644); 106module_param_string(pal, pal, sizeof(pal), 0644);
99module_param_string(secam, secam, sizeof(secam), 0644); 107module_param_string(secam, secam, sizeof(secam), 0644);
100module_param_string(ntsc, ntsc, sizeof(ntsc), 0644); 108module_param_string(ntsc, ntsc, sizeof(ntsc), 0644);
101module_param_named(debug, cx18_debug, int, 0644); 109module_param_named(debug, cx18_debug, int, 0644);
110module_param_named(retry_mmio, cx18_retry_mmio, int, 0644);
102module_param(cx18_pci_latency, int, 0644); 111module_param(cx18_pci_latency, int, 0644);
103module_param(cx18_first_minor, int, 0644); 112module_param(cx18_first_minor, int, 0644);
104 113
@@ -121,6 +130,8 @@ MODULE_PARM_DESC(cardtype,
121 "\t\t\t 3 = Compro VideoMate H900\n" 130 "\t\t\t 3 = Compro VideoMate H900\n"
122 "\t\t\t 4 = Yuan MPC718\n" 131 "\t\t\t 4 = Yuan MPC718\n"
123 "\t\t\t 5 = Conexant Raptor PAL/SECAM\n" 132 "\t\t\t 5 = Conexant Raptor PAL/SECAM\n"
133 "\t\t\t 6 = Toshiba Qosmio DVB-T/Analog\n"
134 "\t\t\t 7 = Leadtek WinFast PVR2100\n"
124 "\t\t\t 0 = Autodetect (default)\n" 135 "\t\t\t 0 = Autodetect (default)\n"
125 "\t\t\t-1 = Ignore this card\n\t\t"); 136 "\t\t\t-1 = Ignore this card\n\t\t");
126MODULE_PARM_DESC(pal, "Set PAL standard: B, G, H, D, K, I, M, N, Nc, 60"); 137MODULE_PARM_DESC(pal, "Set PAL standard: B, G, H, D, K, I, M, N, Nc, 60");
@@ -140,6 +151,14 @@ MODULE_PARM_DESC(debug,
140MODULE_PARM_DESC(cx18_pci_latency, 151MODULE_PARM_DESC(cx18_pci_latency,
141 "Change the PCI latency to 64 if lower: 0 = No, 1 = Yes,\n" 152 "Change the PCI latency to 64 if lower: 0 = No, 1 = Yes,\n"
142 "\t\t\tDefault: Yes"); 153 "\t\t\tDefault: Yes");
154MODULE_PARM_DESC(retry_mmio,
155 "Check and retry memory mapped IO accesses\n"
156 "\t\t\tDefault: 1 [Yes]");
157MODULE_PARM_DESC(mmio_ndelay,
158 "Delay (ns) for each CX23418 memory mapped IO access.\n"
159 "\t\t\tTry larger values that are close to a multiple of the\n"
160 "\t\t\tPCI clock period, 30.3 ns, if your card doesn't work.\n"
161 "\t\t\tDefault: " __stringify(CX18_DEFAULT_MMIO_NDELAY));
143MODULE_PARM_DESC(enc_mpg_buffers, 162MODULE_PARM_DESC(enc_mpg_buffers,
144 "Encoder MPG Buffers (in MB)\n" 163 "Encoder MPG Buffers (in MB)\n"
145 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_MPG_BUFFERS)); 164 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_MPG_BUFFERS));
@@ -156,7 +175,7 @@ MODULE_PARM_DESC(enc_pcm_buffers,
156 "Encoder PCM buffers (in MB)\n" 175 "Encoder PCM buffers (in MB)\n"
157 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_PCM_BUFFERS)); 176 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_PCM_BUFFERS));
158 177
159MODULE_PARM_DESC(cx18_first_minor, "Set minor assigned to first card"); 178MODULE_PARM_DESC(cx18_first_minor, "Set kernel number assigned to first card");
160 179
161MODULE_AUTHOR("Hans Verkuil"); 180MODULE_AUTHOR("Hans Verkuil");
162MODULE_DESCRIPTION("CX23418 driver"); 181MODULE_DESCRIPTION("CX23418 driver");
@@ -356,6 +375,11 @@ static void cx18_process_options(struct cx18 *cx)
356 cx->options.tuner = tuner[cx->num]; 375 cx->options.tuner = tuner[cx->num];
357 cx->options.radio = radio[cx->num]; 376 cx->options.radio = radio[cx->num];
358 377
378 if (mmio_ndelay[cx->num] < 0)
379 cx->options.mmio_ndelay = CX18_DEFAULT_MMIO_NDELAY;
380 else
381 cx->options.mmio_ndelay = mmio_ndelay[cx->num];
382
359 cx->std = cx18_parse_std(cx); 383 cx->std = cx18_parse_std(cx);
360 if (cx->options.cardtype == -1) { 384 if (cx->options.cardtype == -1) {
361 CX18_INFO("Ignore card\n"); 385 CX18_INFO("Ignore card\n");
@@ -395,9 +419,9 @@ done:
395 419
396 if (cx->card == NULL) { 420 if (cx->card == NULL) {
397 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT); 421 cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
398 CX18_ERR("Unknown card: vendor/device: %04x/%04x\n", 422 CX18_ERR("Unknown card: vendor/device: [%04x:%04x]\n",
399 cx->dev->vendor, cx->dev->device); 423 cx->dev->vendor, cx->dev->device);
400 CX18_ERR(" subsystem vendor/device: %04x/%04x\n", 424 CX18_ERR(" subsystem vendor/device: [%04x:%04x]\n",
401 cx->dev->subsystem_vendor, cx->dev->subsystem_device); 425 cx->dev->subsystem_vendor, cx->dev->subsystem_device);
402 CX18_ERR("Defaulting to %s card\n", cx->card->name); 426 CX18_ERR("Defaulting to %s card\n", cx->card->name);
403 CX18_ERR("Please mail the vendor/device and subsystem vendor/device IDs and what kind of\n"); 427 CX18_ERR("Please mail the vendor/device and subsystem vendor/device IDs and what kind of\n");
@@ -511,9 +535,9 @@ static int cx18_setup_pci(struct cx18 *cx, struct pci_dev *dev,
511 return -EIO; 535 return -EIO;
512 } 536 }
513 537
514 /* Check for bus mastering */ 538 /* Enable bus mastering and memory mapped IO for the CX23418 */
515 pci_read_config_word(dev, PCI_COMMAND, &cmd); 539 pci_read_config_word(dev, PCI_COMMAND, &cmd);
516 cmd |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER; 540 cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
517 pci_write_config_word(dev, PCI_COMMAND, cmd); 541 pci_write_config_word(dev, PCI_COMMAND, cmd);
518 542
519 pci_read_config_byte(dev, PCI_CLASS_REVISION, &cx->card_rev); 543 pci_read_config_byte(dev, PCI_CLASS_REVISION, &cx->card_rev);
@@ -525,11 +549,6 @@ static int cx18_setup_pci(struct cx18 *cx, struct pci_dev *dev,
525 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64); 549 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64);
526 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &pci_latency); 550 pci_read_config_byte(dev, PCI_LATENCY_TIMER, &pci_latency);
527 } 551 }
528 /* This config space value relates to DMA latencies. The
529 default value 0x8080 is too low however and will lead
530 to DMA errors. 0xffff is the max value which solves
531 these problems. */
532 pci_write_config_dword(dev, 0x40, 0xffff);
533 552
534 CX18_DEBUG_INFO("cx%d (rev %d) at %02x:%02x.%x, " 553 CX18_DEBUG_INFO("cx%d (rev %d) at %02x:%02x.%x, "
535 "irq: %d, latency: %d, memory: 0x%lx\n", 554 "irq: %d, latency: %d, memory: 0x%lx\n",
@@ -656,7 +675,7 @@ static int __devinit cx18_probe(struct pci_dev *dev,
656 goto free_mem; 675 goto free_mem;
657 } 676 }
658 cx->reg_mem = cx->enc_mem + CX18_REG_OFFSET; 677 cx->reg_mem = cx->enc_mem + CX18_REG_OFFSET;
659 devtype = read_reg(0xC72028); 678 devtype = cx18_read_reg(cx, 0xC72028);
660 switch (devtype & 0xff000000) { 679 switch (devtype & 0xff000000) {
661 case 0xff000000: 680 case 0xff000000:
662 CX18_INFO("cx23418 revision %08x (A)\n", devtype); 681 CX18_INFO("cx23418 revision %08x (A)\n", devtype);
@@ -815,6 +834,7 @@ err:
815 if (retval == 0) 834 if (retval == 0)
816 retval = -ENODEV; 835 retval = -ENODEV;
817 CX18_ERR("Error %d on initialization\n", retval); 836 CX18_ERR("Error %d on initialization\n", retval);
837 cx18_log_statistics(cx);
818 838
819 kfree(cx18_cards[cx18_cards_active]); 839 kfree(cx18_cards[cx18_cards_active]);
820 cx18_cards[cx18_cards_active] = NULL; 840 cx18_cards[cx18_cards_active] = NULL;
@@ -902,8 +922,8 @@ static void cx18_remove(struct pci_dev *pci_dev)
902 cx18_stop_all_captures(cx); 922 cx18_stop_all_captures(cx);
903 923
904 /* Interrupts */ 924 /* Interrupts */
905 sw1_irq_disable(IRQ_CPU_TO_EPU | IRQ_APU_TO_EPU); 925 cx18_sw1_irq_disable(cx, IRQ_CPU_TO_EPU | IRQ_APU_TO_EPU);
906 sw2_irq_disable(IRQ_CPU_TO_EPU_ACK | IRQ_APU_TO_EPU_ACK); 926 cx18_sw2_irq_disable(cx, IRQ_CPU_TO_EPU_ACK | IRQ_APU_TO_EPU_ACK);
907 927
908 cx18_halt_firmware(cx); 928 cx18_halt_firmware(cx);
909 929
@@ -919,6 +939,7 @@ static void cx18_remove(struct pci_dev *pci_dev)
919 939
920 pci_disable_device(cx->dev); 940 pci_disable_device(cx->dev);
921 941
942 cx18_log_statistics(cx);
922 CX18_INFO("Removed %s, card #%d\n", cx->card_name, cx->num); 943 CX18_INFO("Removed %s, card #%d\n", cx->card_name, cx->num);
923} 944}
924 945
@@ -938,7 +959,7 @@ static int module_start(void)
938 959
939 /* Validate parameters */ 960 /* Validate parameters */
940 if (cx18_first_minor < 0 || cx18_first_minor >= CX18_MAX_CARDS) { 961 if (cx18_first_minor < 0 || cx18_first_minor >= CX18_MAX_CARDS) {
941 printk(KERN_ERR "cx18: Exiting, ivtv_first_minor must be between 0 and %d\n", 962 printk(KERN_ERR "cx18: Exiting, cx18_first_minor must be between 0 and %d\n",
942 CX18_MAX_CARDS - 1); 963 CX18_MAX_CARDS - 1);
943 return -1; 964 return -1;
944 } 965 }
diff --git a/drivers/media/video/cx18/cx18-driver.h b/drivers/media/video/cx18/cx18-driver.h
index 4801bc7fb5b2..fa8be0731a3f 100644
--- a/drivers/media/video/cx18/cx18-driver.h
+++ b/drivers/media/video/cx18/cx18-driver.h
@@ -38,7 +38,6 @@
38#include <linux/i2c-algo-bit.h> 38#include <linux/i2c-algo-bit.h>
39#include <linux/list.h> 39#include <linux/list.h>
40#include <linux/unistd.h> 40#include <linux/unistd.h>
41#include <linux/byteorder/swab.h>
42#include <linux/pagemap.h> 41#include <linux/pagemap.h>
43#include <linux/workqueue.h> 42#include <linux/workqueue.h>
44#include <linux/mutex.h> 43#include <linux/mutex.h>
@@ -64,6 +63,9 @@
64# error "This driver requires kernel PCI support." 63# error "This driver requires kernel PCI support."
65#endif 64#endif
66 65
66/* Default delay to throttle mmio access to the CX23418 */
67#define CX18_DEFAULT_MMIO_NDELAY 0 /* 0 ns = 0 PCI clock(s) / 33 MHz */
68
67#define CX18_MEM_OFFSET 0x00000000 69#define CX18_MEM_OFFSET 0x00000000
68#define CX18_MEM_SIZE 0x04000000 70#define CX18_MEM_SIZE 0x04000000
69#define CX18_REG_OFFSET 0x02000000 71#define CX18_REG_OFFSET 0x02000000
@@ -77,7 +79,9 @@
77#define CX18_CARD_COMPRO_H900 2 /* Compro VideoMate H900 */ 79#define CX18_CARD_COMPRO_H900 2 /* Compro VideoMate H900 */
78#define CX18_CARD_YUAN_MPC718 3 /* Yuan MPC718 */ 80#define CX18_CARD_YUAN_MPC718 3 /* Yuan MPC718 */
79#define CX18_CARD_CNXT_RAPTOR_PAL 4 /* Conexant Raptor PAL */ 81#define CX18_CARD_CNXT_RAPTOR_PAL 4 /* Conexant Raptor PAL */
80#define CX18_CARD_LAST 4 82#define CX18_CARD_TOSHIBA_QOSMIO_DVBT 5 /* Toshiba Qosmio Interal DVB-T/Analog*/
83#define CX18_CARD_LEADTEK_PVR2100 6 /* Leadtek WinFast PVR2100 */
84#define CX18_CARD_LAST 6
81 85
82#define CX18_ENC_STREAM_TYPE_MPG 0 86#define CX18_ENC_STREAM_TYPE_MPG 0
83#define CX18_ENC_STREAM_TYPE_TS 1 87#define CX18_ENC_STREAM_TYPE_TS 1
@@ -97,6 +101,8 @@
97#define CX18_PCI_ID_COMPRO 0x185b 101#define CX18_PCI_ID_COMPRO 0x185b
98#define CX18_PCI_ID_YUAN 0x12ab 102#define CX18_PCI_ID_YUAN 0x12ab
99#define CX18_PCI_ID_CONEXANT 0x14f1 103#define CX18_PCI_ID_CONEXANT 0x14f1
104#define CX18_PCI_ID_TOSHIBA 0x1179
105#define CX18_PCI_ID_LEADTEK 0x107D
100 106
101/* ======================================================================== */ 107/* ======================================================================== */
102/* ========================== START USER SETTABLE DMA VARIABLES =========== */ 108/* ========================== START USER SETTABLE DMA VARIABLES =========== */
@@ -169,6 +175,7 @@
169 175
170#define CX18_MAX_PGM_INDEX (400) 176#define CX18_MAX_PGM_INDEX (400)
171 177
178extern int cx18_retry_mmio; /* enable check & retry of mmio accesses */
172extern int cx18_debug; 179extern int cx18_debug;
173 180
174 181
@@ -177,6 +184,7 @@ struct cx18_options {
177 int cardtype; /* force card type on load */ 184 int cardtype; /* force card type on load */
178 int tuner; /* set tuner on load */ 185 int tuner; /* set tuner on load */
179 int radio; /* enable/disable radio */ 186 int radio; /* enable/disable radio */
187 unsigned long mmio_ndelay; /* delay in ns after every PCI mmio access */
180}; 188};
181 189
182/* per-buffer bit flags */ 190/* per-buffer bit flags */
@@ -216,8 +224,7 @@ struct cx18_buffer {
216 224
217struct cx18_queue { 225struct cx18_queue {
218 struct list_head list; 226 struct list_head list;
219 u32 buffers; 227 atomic_t buffers;
220 u32 length;
221 u32 bytesused; 228 u32 bytesused;
222}; 229};
223 230
@@ -237,6 +244,8 @@ struct cx18_dvb {
237struct cx18; /* forward reference */ 244struct cx18; /* forward reference */
238struct cx18_scb; /* forward reference */ 245struct cx18_scb; /* forward reference */
239 246
247#define CX18_INVALID_TASK_HANDLE 0xffffffff
248
240struct cx18_stream { 249struct cx18_stream {
241 /* These first four fields are always set, even if the stream 250 /* These first four fields are always set, even if the stream
242 is not actually created. */ 251 is not actually created. */
@@ -259,7 +268,6 @@ struct cx18_stream {
259 /* Buffer Stats */ 268 /* Buffer Stats */
260 u32 buffers; 269 u32 buffers;
261 u32 buf_size; 270 u32 buf_size;
262 u32 buffers_stolen;
263 271
264 /* Buffer Queues */ 272 /* Buffer Queues */
265 struct cx18_queue q_free; /* free buffers */ 273 struct cx18_queue q_free; /* free buffers */
@@ -341,6 +349,13 @@ struct cx18_i2c_algo_callback_data {
341 int bus_index; /* 0 or 1 for the cx23418's 1st or 2nd I2C bus */ 349 int bus_index; /* 0 or 1 for the cx23418's 1st or 2nd I2C bus */
342}; 350};
343 351
352#define CX18_MAX_MMIO_RETRIES 10
353
354struct cx18_mmio_stats {
355 atomic_t retried_write[CX18_MAX_MMIO_RETRIES+1];
356 atomic_t retried_read[CX18_MAX_MMIO_RETRIES+1];
357};
358
344/* Struct to hold info about cx18 cards */ 359/* Struct to hold info about cx18 cards */
345struct cx18 { 360struct cx18 {
346 int num; /* board number, -1 during init! */ 361 int num; /* board number, -1 during init! */
@@ -430,6 +445,9 @@ struct cx18 {
430 u32 gpio_val; 445 u32 gpio_val;
431 struct mutex gpio_lock; 446 struct mutex gpio_lock;
432 447
448 /* Statistics */
449 struct cx18_mmio_stats mmio_stats;
450
433 /* v4l2 and User settings */ 451 /* v4l2 and User settings */
434 452
435 /* codec settings */ 453 /* codec settings */
@@ -458,47 +476,4 @@ void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv);
458/* First-open initialization: load firmware, etc. */ 476/* First-open initialization: load firmware, etc. */
459int cx18_init_on_first_open(struct cx18 *cx); 477int cx18_init_on_first_open(struct cx18 *cx);
460 478
461/* This is a PCI post thing, where if the pci register is not read, then
462 the write doesn't always take effect right away. By reading back the
463 register any pending PCI writes will be performed (in order), and so
464 you can be sure that the writes are guaranteed to be done.
465
466 Rarely needed, only in some timing sensitive cases.
467 Apparently if this is not done some motherboards seem
468 to kill the firmware and get into the broken state until computer is
469 rebooted. */
470#define write_sync(val, reg) \
471 do { writel(val, reg); readl(reg); } while (0)
472
473#define read_reg(reg) readl(cx->reg_mem + (reg))
474#define write_reg(val, reg) writel(val, cx->reg_mem + (reg))
475#define write_reg_sync(val, reg) \
476 do { write_reg(val, reg); read_reg(reg); } while (0)
477
478#define read_enc(addr) readl(cx->enc_mem + (u32)(addr))
479#define write_enc(val, addr) writel(val, cx->enc_mem + (u32)(addr))
480#define write_enc_sync(val, addr) \
481 do { write_enc(val, addr); read_enc(addr); } while (0)
482
483#define sw1_irq_enable(val) do { \
484 write_reg(val, SW1_INT_STATUS); \
485 write_reg(read_reg(SW1_INT_ENABLE_PCI) | (val), SW1_INT_ENABLE_PCI); \
486} while (0)
487
488#define sw1_irq_disable(val) \
489 write_reg(read_reg(SW1_INT_ENABLE_PCI) & ~(val), SW1_INT_ENABLE_PCI);
490
491#define sw2_irq_enable(val) do { \
492 write_reg(val, SW2_INT_STATUS); \
493 write_reg(read_reg(SW2_INT_ENABLE_PCI) | (val), SW2_INT_ENABLE_PCI); \
494} while (0)
495
496#define sw2_irq_disable(val) \
497 write_reg(read_reg(SW2_INT_ENABLE_PCI) & ~(val), SW2_INT_ENABLE_PCI);
498
499#define setup_page(addr) do { \
500 u32 val = read_reg(0xD000F8) & ~0x1f00; \
501 write_reg(val | (((addr) >> 17) & 0x1f00), 0xD000F8); \
502} while (0)
503
504#endif /* CX18_DRIVER_H */ 479#endif /* CX18_DRIVER_H */
diff --git a/drivers/media/video/cx18/cx18-dvb.c b/drivers/media/video/cx18/cx18-dvb.c
index 1e420a804fc9..afc694e7bdb2 100644
--- a/drivers/media/video/cx18/cx18-dvb.c
+++ b/drivers/media/video/cx18/cx18-dvb.c
@@ -21,6 +21,7 @@
21 21
22#include "cx18-version.h" 22#include "cx18-version.h"
23#include "cx18-dvb.h" 23#include "cx18-dvb.h"
24#include "cx18-io.h"
24#include "cx18-streams.h" 25#include "cx18-streams.h"
25#include "cx18-cards.h" 26#include "cx18-cards.h"
26#include "s5h1409.h" 27#include "s5h1409.h"
@@ -87,13 +88,13 @@ static int cx18_dvb_start_feed(struct dvb_demux_feed *feed)
87 switch (cx->card->type) { 88 switch (cx->card->type) {
88 case CX18_CARD_HVR_1600_ESMT: 89 case CX18_CARD_HVR_1600_ESMT:
89 case CX18_CARD_HVR_1600_SAMSUNG: 90 case CX18_CARD_HVR_1600_SAMSUNG:
90 v = read_reg(CX18_REG_DMUX_NUM_PORT_0_CONTROL); 91 v = cx18_read_reg(cx, CX18_REG_DMUX_NUM_PORT_0_CONTROL);
91 v |= 0x00400000; /* Serial Mode */ 92 v |= 0x00400000; /* Serial Mode */
92 v |= 0x00002000; /* Data Length - Byte */ 93 v |= 0x00002000; /* Data Length - Byte */
93 v |= 0x00010000; /* Error - Polarity */ 94 v |= 0x00010000; /* Error - Polarity */
94 v |= 0x00020000; /* Error - Passthru */ 95 v |= 0x00020000; /* Error - Passthru */
95 v |= 0x000c0000; /* Error - Ignore */ 96 v |= 0x000c0000; /* Error - Ignore */
96 write_reg(v, CX18_REG_DMUX_NUM_PORT_0_CONTROL); 97 cx18_write_reg(cx, v, CX18_REG_DMUX_NUM_PORT_0_CONTROL);
97 break; 98 break;
98 99
99 default: 100 default:
diff --git a/drivers/media/video/cx18/cx18-fileops.c b/drivers/media/video/cx18/cx18-fileops.c
index 1e537fe04a23..5f9089907544 100644
--- a/drivers/media/video/cx18/cx18-fileops.c
+++ b/drivers/media/video/cx18/cx18-fileops.c
@@ -132,6 +132,7 @@ static void cx18_dualwatch(struct cx18 *cx)
132 u16 new_stereo_mode; 132 u16 new_stereo_mode;
133 const u16 stereo_mask = 0x0300; 133 const u16 stereo_mask = 0x0300;
134 const u16 dual = 0x0200; 134 const u16 dual = 0x0200;
135 u32 h;
135 136
136 new_stereo_mode = cx->params.audio_properties & stereo_mask; 137 new_stereo_mode = cx->params.audio_properties & stereo_mask;
137 memset(&vt, 0, sizeof(vt)); 138 memset(&vt, 0, sizeof(vt));
@@ -143,13 +144,21 @@ static void cx18_dualwatch(struct cx18 *cx)
143 if (new_stereo_mode == cx->dualwatch_stereo_mode) 144 if (new_stereo_mode == cx->dualwatch_stereo_mode)
144 return; 145 return;
145 146
146 new_bitmap = new_stereo_mode | (cx->params.audio_properties & ~stereo_mask); 147 new_bitmap = new_stereo_mode
148 | (cx->params.audio_properties & ~stereo_mask);
147 149
148 CX18_DEBUG_INFO("dualwatch: change stereo flag from 0x%x to 0x%x. new audio_bitmask=0x%ux\n", 150 CX18_DEBUG_INFO("dualwatch: change stereo flag from 0x%x to 0x%x. "
149 cx->dualwatch_stereo_mode, new_stereo_mode, new_bitmap); 151 "new audio_bitmask=0x%ux\n",
152 cx->dualwatch_stereo_mode, new_stereo_mode, new_bitmap);
150 153
151 if (cx18_vapi(cx, CX18_CPU_SET_AUDIO_PARAMETERS, 2, 154 h = cx18_find_handle(cx);
152 cx18_find_handle(cx), new_bitmap) == 0) { 155 if (h == CX18_INVALID_TASK_HANDLE) {
156 CX18_DEBUG_INFO("dualwatch: can't find valid task handle\n");
157 return;
158 }
159
160 if (cx18_vapi(cx,
161 CX18_CPU_SET_AUDIO_PARAMETERS, 2, h, new_bitmap) == 0) {
153 cx->dualwatch_stereo_mode = new_stereo_mode; 162 cx->dualwatch_stereo_mode = new_stereo_mode;
154 return; 163 return;
155 } 164 }
@@ -223,7 +232,7 @@ static struct cx18_buffer *cx18_get_buffer(struct cx18_stream *s, int non_block,
223 prepare_to_wait(&s->waitq, &wait, TASK_INTERRUPTIBLE); 232 prepare_to_wait(&s->waitq, &wait, TASK_INTERRUPTIBLE);
224 /* New buffers might have become available before we were added 233 /* New buffers might have become available before we were added
225 to the waitqueue */ 234 to the waitqueue */
226 if (!s->q_full.buffers) 235 if (!atomic_read(&s->q_full.buffers))
227 schedule(); 236 schedule();
228 finish_wait(&s->waitq, &wait); 237 finish_wait(&s->waitq, &wait);
229 if (signal_pending(current)) { 238 if (signal_pending(current)) {
@@ -509,7 +518,7 @@ unsigned int cx18_v4l2_enc_poll(struct file *filp, poll_table *wait)
509 CX18_DEBUG_HI_FILE("Encoder poll\n"); 518 CX18_DEBUG_HI_FILE("Encoder poll\n");
510 poll_wait(filp, &s->waitq, wait); 519 poll_wait(filp, &s->waitq, wait);
511 520
512 if (s->q_full.length || s->q_io.length) 521 if (atomic_read(&s->q_full.buffers) || atomic_read(&s->q_io.buffers))
513 return POLLIN | POLLRDNORM; 522 return POLLIN | POLLRDNORM;
514 if (eof) 523 if (eof)
515 return POLLHUP; 524 return POLLHUP;
@@ -695,20 +704,28 @@ int cx18_v4l2_open(struct inode *inode, struct file *filp)
695 704
696void cx18_mute(struct cx18 *cx) 705void cx18_mute(struct cx18 *cx)
697{ 706{
698 if (atomic_read(&cx->ana_capturing)) 707 u32 h;
699 cx18_vapi(cx, CX18_CPU_SET_AUDIO_MUTE, 2, 708 if (atomic_read(&cx->ana_capturing)) {
700 cx18_find_handle(cx), 1); 709 h = cx18_find_handle(cx);
710 if (h != CX18_INVALID_TASK_HANDLE)
711 cx18_vapi(cx, CX18_CPU_SET_AUDIO_MUTE, 2, h, 1);
712 else
713 CX18_ERR("Can't find valid task handle for mute\n");
714 }
701 CX18_DEBUG_INFO("Mute\n"); 715 CX18_DEBUG_INFO("Mute\n");
702} 716}
703 717
704void cx18_unmute(struct cx18 *cx) 718void cx18_unmute(struct cx18 *cx)
705{ 719{
720 u32 h;
706 if (atomic_read(&cx->ana_capturing)) { 721 if (atomic_read(&cx->ana_capturing)) {
707 cx18_msleep_timeout(100, 0); 722 h = cx18_find_handle(cx);
708 cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 2, 723 if (h != CX18_INVALID_TASK_HANDLE) {
709 cx18_find_handle(cx), 12); 724 cx18_msleep_timeout(100, 0);
710 cx18_vapi(cx, CX18_CPU_SET_AUDIO_MUTE, 2, 725 cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 2, h, 12);
711 cx18_find_handle(cx), 0); 726 cx18_vapi(cx, CX18_CPU_SET_AUDIO_MUTE, 2, h, 0);
727 } else
728 CX18_ERR("Can't find valid task handle for unmute\n");
712 } 729 }
713 CX18_DEBUG_INFO("Unmute\n"); 730 CX18_DEBUG_INFO("Unmute\n");
714} 731}
diff --git a/drivers/media/video/cx18/cx18-firmware.c b/drivers/media/video/cx18/cx18-firmware.c
index 78fadd2ada5d..51534428cd00 100644
--- a/drivers/media/video/cx18/cx18-firmware.c
+++ b/drivers/media/video/cx18/cx18-firmware.c
@@ -20,6 +20,7 @@
20 */ 20 */
21 21
22#include "cx18-driver.h" 22#include "cx18-driver.h"
23#include "cx18-io.h"
23#include "cx18-scb.h" 24#include "cx18-scb.h"
24#include "cx18-irq.h" 25#include "cx18-irq.h"
25#include "cx18-firmware.h" 26#include "cx18-firmware.h"
@@ -113,11 +114,11 @@ static int load_cpu_fw_direct(const char *fn, u8 __iomem *mem, struct cx18 *cx)
113 src = (const u32 *)fw->data; 114 src = (const u32 *)fw->data;
114 115
115 for (i = 0; i < fw->size; i += 4096) { 116 for (i = 0; i < fw->size; i += 4096) {
116 setup_page(i); 117 cx18_setup_page(cx, i);
117 for (j = i; j < fw->size && j < i + 4096; j += 4) { 118 for (j = i; j < fw->size && j < i + 4096; j += 4) {
118 /* no need for endianness conversion on the ppc */ 119 /* no need for endianness conversion on the ppc */
119 __raw_writel(*src, dst); 120 cx18_raw_writel(cx, *src, dst);
120 if (__raw_readl(dst) != *src) { 121 if (cx18_raw_readl(cx, dst) != *src) {
121 CX18_ERR("Mismatch at offset %x\n", i); 122 CX18_ERR("Mismatch at offset %x\n", i);
122 release_firmware(fw); 123 release_firmware(fw);
123 return -EIO; 124 return -EIO;
@@ -170,12 +171,15 @@ static int load_apu_fw_direct(const char *fn, u8 __iomem *dst, struct cx18 *cx)
170 if (offset + seghdr.size > sz) 171 if (offset + seghdr.size > sz)
171 break; 172 break;
172 for (i = 0; i < seghdr.size; i += 4096) { 173 for (i = 0; i < seghdr.size; i += 4096) {
173 setup_page(offset + i); 174 cx18_setup_page(cx, offset + i);
174 for (j = i; j < seghdr.size && j < i + 4096; j += 4) { 175 for (j = i; j < seghdr.size && j < i + 4096; j += 4) {
175 /* no need for endianness conversion on the ppc */ 176 /* no need for endianness conversion on the ppc */
176 __raw_writel(src[(offset + j) / 4], dst + seghdr.addr + j); 177 cx18_raw_writel(cx, src[(offset + j) / 4],
177 if (__raw_readl(dst + seghdr.addr + j) != src[(offset + j) / 4]) { 178 dst + seghdr.addr + j);
178 CX18_ERR("Mismatch at offset %x\n", offset + j); 179 if (cx18_raw_readl(cx, dst + seghdr.addr + j)
180 != src[(offset + j) / 4]) {
181 CX18_ERR("Mismatch at offset %x\n",
182 offset + j);
179 release_firmware(fw); 183 release_firmware(fw);
180 return -EIO; 184 return -EIO;
181 } 185 }
@@ -189,43 +193,45 @@ static int load_apu_fw_direct(const char *fn, u8 __iomem *dst, struct cx18 *cx)
189 size = fw->size; 193 size = fw->size;
190 release_firmware(fw); 194 release_firmware(fw);
191 /* Clear bit0 for APU to start from 0 */ 195 /* Clear bit0 for APU to start from 0 */
192 write_reg(read_reg(0xc72030) & ~1, 0xc72030); 196 cx18_write_reg(cx, cx18_read_reg(cx, 0xc72030) & ~1, 0xc72030);
193 return size; 197 return size;
194} 198}
195 199
196void cx18_halt_firmware(struct cx18 *cx) 200void cx18_halt_firmware(struct cx18 *cx)
197{ 201{
198 CX18_DEBUG_INFO("Preparing for firmware halt.\n"); 202 CX18_DEBUG_INFO("Preparing for firmware halt.\n");
199 write_reg(0x000F000F, CX18_PROC_SOFT_RESET); /* stop the fw */ 203 cx18_write_reg(cx, 0x000F000F, CX18_PROC_SOFT_RESET); /* stop the fw */
200 write_reg(0x00020002, CX18_ADEC_CONTROL); 204 cx18_write_reg(cx, 0x00020002, CX18_ADEC_CONTROL);
201} 205}
202 206
203void cx18_init_power(struct cx18 *cx, int lowpwr) 207void cx18_init_power(struct cx18 *cx, int lowpwr)
204{ 208{
205 /* power-down Spare and AOM PLLs */ 209 /* power-down Spare and AOM PLLs */
206 /* power-up fast, slow and mpeg PLLs */ 210 /* power-up fast, slow and mpeg PLLs */
207 write_reg(0x00000008, CX18_PLL_POWER_DOWN); 211 cx18_write_reg(cx, 0x00000008, CX18_PLL_POWER_DOWN);
208 212
209 /* ADEC out of sleep */ 213 /* ADEC out of sleep */
210 write_reg(0x00020000, CX18_ADEC_CONTROL); 214 cx18_write_reg(cx, 0x00020000, CX18_ADEC_CONTROL);
211 215
212 /* The fast clock is at 200/245 MHz */ 216 /* The fast clock is at 200/245 MHz */
213 write_reg(lowpwr ? 0xD : 0x11, CX18_FAST_CLOCK_PLL_INT); 217 cx18_write_reg(cx, lowpwr ? 0xD : 0x11, CX18_FAST_CLOCK_PLL_INT);
214 write_reg(lowpwr ? 0x1EFBF37 : 0x038E3D7, CX18_FAST_CLOCK_PLL_FRAC); 218 cx18_write_reg(cx, lowpwr ? 0x1EFBF37 : 0x038E3D7,
219 CX18_FAST_CLOCK_PLL_FRAC);
215 220
216 write_reg(2, CX18_FAST_CLOCK_PLL_POST); 221 cx18_write_reg(cx, 2, CX18_FAST_CLOCK_PLL_POST);
217 write_reg(1, CX18_FAST_CLOCK_PLL_PRESCALE); 222 cx18_write_reg(cx, 1, CX18_FAST_CLOCK_PLL_PRESCALE);
218 write_reg(4, CX18_FAST_CLOCK_PLL_ADJUST_BANDWIDTH); 223 cx18_write_reg(cx, 4, CX18_FAST_CLOCK_PLL_ADJUST_BANDWIDTH);
219 224
220 /* set slow clock to 125/120 MHz */ 225 /* set slow clock to 125/120 MHz */
221 write_reg(lowpwr ? 0x11 : 0x10, CX18_SLOW_CLOCK_PLL_INT); 226 cx18_write_reg(cx, lowpwr ? 0x11 : 0x10, CX18_SLOW_CLOCK_PLL_INT);
222 write_reg(lowpwr ? 0xEBAF05 : 0x18618A8, CX18_SLOW_CLOCK_PLL_FRAC); 227 cx18_write_reg(cx, lowpwr ? 0xEBAF05 : 0x18618A8,
223 write_reg(4, CX18_SLOW_CLOCK_PLL_POST); 228 CX18_SLOW_CLOCK_PLL_FRAC);
229 cx18_write_reg(cx, 4, CX18_SLOW_CLOCK_PLL_POST);
224 230
225 /* mpeg clock pll 54MHz */ 231 /* mpeg clock pll 54MHz */
226 write_reg(0xF, CX18_MPEG_CLOCK_PLL_INT); 232 cx18_write_reg(cx, 0xF, CX18_MPEG_CLOCK_PLL_INT);
227 write_reg(0x2BCFEF, CX18_MPEG_CLOCK_PLL_FRAC); 233 cx18_write_reg(cx, 0x2BCFEF, CX18_MPEG_CLOCK_PLL_FRAC);
228 write_reg(8, CX18_MPEG_CLOCK_PLL_POST); 234 cx18_write_reg(cx, 8, CX18_MPEG_CLOCK_PLL_POST);
229 235
230 /* Defaults */ 236 /* Defaults */
231 /* APU = SC or SC/2 = 125/62.5 */ 237 /* APU = SC or SC/2 = 125/62.5 */
@@ -242,81 +248,84 @@ void cx18_init_power(struct cx18 *cx, int lowpwr)
242 /* VFC = disabled */ 248 /* VFC = disabled */
243 /* USB = disabled */ 249 /* USB = disabled */
244 250
245 write_reg(lowpwr ? 0xFFFF0020 : 0x00060004, CX18_CLOCK_SELECT1); 251 cx18_write_reg(cx, lowpwr ? 0xFFFF0020 : 0x00060004,
246 write_reg(lowpwr ? 0xFFFF0004 : 0x00060006, CX18_CLOCK_SELECT2); 252 CX18_CLOCK_SELECT1);
253 cx18_write_reg(cx, lowpwr ? 0xFFFF0004 : 0x00060006,
254 CX18_CLOCK_SELECT2);
247 255
248 write_reg(0xFFFF0002, CX18_HALF_CLOCK_SELECT1); 256 cx18_write_reg(cx, 0xFFFF0002, CX18_HALF_CLOCK_SELECT1);
249 write_reg(0xFFFF0104, CX18_HALF_CLOCK_SELECT2); 257 cx18_write_reg(cx, 0xFFFF0104, CX18_HALF_CLOCK_SELECT2);
250 258
251 write_reg(0xFFFF9026, CX18_CLOCK_ENABLE1); 259 cx18_write_reg(cx, 0xFFFF9026, CX18_CLOCK_ENABLE1);
252 write_reg(0xFFFF3105, CX18_CLOCK_ENABLE2); 260 cx18_write_reg(cx, 0xFFFF3105, CX18_CLOCK_ENABLE2);
253} 261}
254 262
255void cx18_init_memory(struct cx18 *cx) 263void cx18_init_memory(struct cx18 *cx)
256{ 264{
257 cx18_msleep_timeout(10, 0); 265 cx18_msleep_timeout(10, 0);
258 write_reg(0x10000, CX18_DDR_SOFT_RESET); 266 cx18_write_reg(cx, 0x10000, CX18_DDR_SOFT_RESET);
259 cx18_msleep_timeout(10, 0); 267 cx18_msleep_timeout(10, 0);
260 268
261 write_reg(cx->card->ddr.chip_config, CX18_DDR_CHIP_CONFIG); 269 cx18_write_reg(cx, cx->card->ddr.chip_config, CX18_DDR_CHIP_CONFIG);
262 270
263 cx18_msleep_timeout(10, 0); 271 cx18_msleep_timeout(10, 0);
264 272
265 write_reg(cx->card->ddr.refresh, CX18_DDR_REFRESH); 273 cx18_write_reg(cx, cx->card->ddr.refresh, CX18_DDR_REFRESH);
266 write_reg(cx->card->ddr.timing1, CX18_DDR_TIMING1); 274 cx18_write_reg(cx, cx->card->ddr.timing1, CX18_DDR_TIMING1);
267 write_reg(cx->card->ddr.timing2, CX18_DDR_TIMING2); 275 cx18_write_reg(cx, cx->card->ddr.timing2, CX18_DDR_TIMING2);
268 276
269 cx18_msleep_timeout(10, 0); 277 cx18_msleep_timeout(10, 0);
270 278
271 /* Initialize DQS pad time */ 279 /* Initialize DQS pad time */
272 write_reg(cx->card->ddr.tune_lane, CX18_DDR_TUNE_LANE); 280 cx18_write_reg(cx, cx->card->ddr.tune_lane, CX18_DDR_TUNE_LANE);
273 write_reg(cx->card->ddr.initial_emrs, CX18_DDR_INITIAL_EMRS); 281 cx18_write_reg(cx, cx->card->ddr.initial_emrs, CX18_DDR_INITIAL_EMRS);
274 282
275 cx18_msleep_timeout(10, 0); 283 cx18_msleep_timeout(10, 0);
276 284
277 write_reg(0x20000, CX18_DDR_SOFT_RESET); 285 cx18_write_reg(cx, 0x20000, CX18_DDR_SOFT_RESET);
278 cx18_msleep_timeout(10, 0); 286 cx18_msleep_timeout(10, 0);
279 287
280 /* use power-down mode when idle */ 288 /* use power-down mode when idle */
281 write_reg(0x00000010, CX18_DDR_POWER_REG); 289 cx18_write_reg(cx, 0x00000010, CX18_DDR_POWER_REG);
282 290
283 write_reg(0x10001, CX18_REG_BUS_TIMEOUT_EN); 291 cx18_write_reg(cx, 0x10001, CX18_REG_BUS_TIMEOUT_EN);
284 292
285 write_reg(0x48, CX18_DDR_MB_PER_ROW_7); 293 cx18_write_reg(cx, 0x48, CX18_DDR_MB_PER_ROW_7);
286 write_reg(0xE0000, CX18_DDR_BASE_63_ADDR); 294 cx18_write_reg(cx, 0xE0000, CX18_DDR_BASE_63_ADDR);
287 295
288 write_reg(0x00000101, CX18_WMB_CLIENT02); /* AO */ 296 cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT02); /* AO */
289 write_reg(0x00000101, CX18_WMB_CLIENT09); /* AI2 */ 297 cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT09); /* AI2 */
290 write_reg(0x00000101, CX18_WMB_CLIENT05); /* VIM1 */ 298 cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT05); /* VIM1 */
291 write_reg(0x00000101, CX18_WMB_CLIENT06); /* AI1 */ 299 cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT06); /* AI1 */
292 write_reg(0x00000101, CX18_WMB_CLIENT07); /* 3D comb */ 300 cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT07); /* 3D comb */
293 write_reg(0x00000101, CX18_WMB_CLIENT10); /* ME */ 301 cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT10); /* ME */
294 write_reg(0x00000101, CX18_WMB_CLIENT12); /* ENC */ 302 cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT12); /* ENC */
295 write_reg(0x00000101, CX18_WMB_CLIENT13); /* PK */ 303 cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT13); /* PK */
296 write_reg(0x00000101, CX18_WMB_CLIENT11); /* RC */ 304 cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT11); /* RC */
297 write_reg(0x00000101, CX18_WMB_CLIENT14); /* AVO */ 305 cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT14); /* AVO */
298} 306}
299 307
300int cx18_firmware_init(struct cx18 *cx) 308int cx18_firmware_init(struct cx18 *cx)
301{ 309{
302 /* Allow chip to control CLKRUN */ 310 /* Allow chip to control CLKRUN */
303 write_reg(0x5, CX18_DSP0_INTERRUPT_MASK); 311 cx18_write_reg(cx, 0x5, CX18_DSP0_INTERRUPT_MASK);
304 312
305 write_reg(0x000F000F, CX18_PROC_SOFT_RESET); /* stop the fw */ 313 cx18_write_reg(cx, 0x000F000F, CX18_PROC_SOFT_RESET); /* stop the fw */
306 314
307 cx18_msleep_timeout(1, 0); 315 cx18_msleep_timeout(1, 0);
308 316
309 sw1_irq_enable(IRQ_CPU_TO_EPU | IRQ_APU_TO_EPU); 317 cx18_sw1_irq_enable(cx, IRQ_CPU_TO_EPU | IRQ_APU_TO_EPU);
310 sw2_irq_enable(IRQ_CPU_TO_EPU_ACK | IRQ_APU_TO_EPU_ACK); 318 cx18_sw2_irq_enable(cx, IRQ_CPU_TO_EPU_ACK | IRQ_APU_TO_EPU_ACK);
311 319
312 /* Only if the processor is not running */ 320 /* Only if the processor is not running */
313 if (read_reg(CX18_PROC_SOFT_RESET) & 8) { 321 if (cx18_read_reg(cx, CX18_PROC_SOFT_RESET) & 8) {
314 int sz = load_apu_fw_direct("v4l-cx23418-apu.fw", 322 int sz = load_apu_fw_direct("v4l-cx23418-apu.fw",
315 cx->enc_mem, cx); 323 cx->enc_mem, cx);
316 324
317 write_enc(0xE51FF004, 0); 325 cx18_write_enc(cx, 0xE51FF004, 0);
318 write_enc(0xa00000, 4); /* todo: not hardcoded */ 326 cx18_write_enc(cx, 0xa00000, 4); /* todo: not hardcoded */
319 write_reg(0x00010000, CX18_PROC_SOFT_RESET); /* Start APU */ 327 /* Start APU */
328 cx18_write_reg(cx, 0x00010000, CX18_PROC_SOFT_RESET);
320 cx18_msleep_timeout(500, 0); 329 cx18_msleep_timeout(500, 0);
321 330
322 sz = sz <= 0 ? sz : load_cpu_fw_direct("v4l-cx23418-cpu.fw", 331 sz = sz <= 0 ? sz : load_cpu_fw_direct("v4l-cx23418-cpu.fw",
@@ -326,9 +335,10 @@ int cx18_firmware_init(struct cx18 *cx)
326 int retries = 0; 335 int retries = 0;
327 336
328 /* start the CPU */ 337 /* start the CPU */
329 write_reg(0x00080000, CX18_PROC_SOFT_RESET); 338 cx18_write_reg(cx, 0x00080000, CX18_PROC_SOFT_RESET);
330 while (retries++ < 50) { /* Loop for max 500mS */ 339 while (retries++ < 50) { /* Loop for max 500mS */
331 if ((read_reg(CX18_PROC_SOFT_RESET) & 1) == 0) 340 if ((cx18_read_reg(cx, CX18_PROC_SOFT_RESET)
341 & 1) == 0)
332 break; 342 break;
333 cx18_msleep_timeout(10, 0); 343 cx18_msleep_timeout(10, 0);
334 } 344 }
@@ -342,6 +352,6 @@ int cx18_firmware_init(struct cx18 *cx)
342 return -EIO; 352 return -EIO;
343 } 353 }
344 /* initialize GPIO */ 354 /* initialize GPIO */
345 write_reg(0x14001400, 0xC78110); 355 cx18_write_reg(cx, 0x14001400, 0xC78110);
346 return 0; 356 return 0;
347} 357}
diff --git a/drivers/media/video/cx18/cx18-gpio.c b/drivers/media/video/cx18/cx18-gpio.c
index 3d495dba4983..0e560421989e 100644
--- a/drivers/media/video/cx18/cx18-gpio.c
+++ b/drivers/media/video/cx18/cx18-gpio.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include "cx18-driver.h" 24#include "cx18-driver.h"
25#include "cx18-io.h"
25#include "cx18-cards.h" 26#include "cx18-cards.h"
26#include "cx18-gpio.h" 27#include "cx18-gpio.h"
27#include "tuner-xc2028.h" 28#include "tuner-xc2028.h"
@@ -49,11 +50,11 @@ static void gpio_write(struct cx18 *cx)
49 u32 dir = cx->gpio_dir; 50 u32 dir = cx->gpio_dir;
50 u32 val = cx->gpio_val; 51 u32 val = cx->gpio_val;
51 52
52 write_reg((dir & 0xffff) << 16, CX18_REG_GPIO_DIR1); 53 cx18_write_reg(cx, (dir & 0xffff) << 16, CX18_REG_GPIO_DIR1);
53 write_reg(((dir & 0xffff) << 16) | (val & 0xffff), 54 cx18_write_reg(cx, ((dir & 0xffff) << 16) | (val & 0xffff),
54 CX18_REG_GPIO_OUT1); 55 CX18_REG_GPIO_OUT1);
55 write_reg(dir & 0xffff0000, CX18_REG_GPIO_DIR2); 56 cx18_write_reg(cx, dir & 0xffff0000, CX18_REG_GPIO_DIR2);
56 write_reg_sync((dir & 0xffff0000) | ((val & 0xffff0000) >> 16), 57 cx18_write_reg_sync(cx, (dir & 0xffff0000) | ((val & 0xffff0000) >> 16),
57 CX18_REG_GPIO_OUT2); 58 CX18_REG_GPIO_OUT2);
58} 59}
59 60
@@ -141,15 +142,17 @@ void cx18_gpio_init(struct cx18 *cx)
141 } 142 }
142 143
143 CX18_DEBUG_INFO("GPIO initial dir: %08x/%08x out: %08x/%08x\n", 144 CX18_DEBUG_INFO("GPIO initial dir: %08x/%08x out: %08x/%08x\n",
144 read_reg(CX18_REG_GPIO_DIR1), read_reg(CX18_REG_GPIO_DIR2), 145 cx18_read_reg(cx, CX18_REG_GPIO_DIR1),
145 read_reg(CX18_REG_GPIO_OUT1), read_reg(CX18_REG_GPIO_OUT2)); 146 cx18_read_reg(cx, CX18_REG_GPIO_DIR2),
147 cx18_read_reg(cx, CX18_REG_GPIO_OUT1),
148 cx18_read_reg(cx, CX18_REG_GPIO_OUT2));
146 149
147 gpio_write(cx); 150 gpio_write(cx);
148 mutex_unlock(&cx->gpio_lock); 151 mutex_unlock(&cx->gpio_lock);
149} 152}
150 153
151/* Xceive tuner reset function */ 154/* Xceive tuner reset function */
152int cx18_reset_tuner_gpio(void *dev, int cmd, int value) 155int cx18_reset_tuner_gpio(void *dev, int component, int cmd, int value)
153{ 156{
154 struct i2c_algo_bit_data *algo = dev; 157 struct i2c_algo_bit_data *algo = dev;
155 struct cx18_i2c_algo_callback_data *cb_data = algo->data; 158 struct cx18_i2c_algo_callback_data *cb_data = algo->data;
diff --git a/drivers/media/video/cx18/cx18-gpio.h b/drivers/media/video/cx18/cx18-gpio.h
index 22cd7ddf8554..beb7424b9944 100644
--- a/drivers/media/video/cx18/cx18-gpio.h
+++ b/drivers/media/video/cx18/cx18-gpio.h
@@ -23,5 +23,5 @@
23void cx18_gpio_init(struct cx18 *cx); 23void cx18_gpio_init(struct cx18 *cx);
24void cx18_reset_i2c_slaves_gpio(struct cx18 *cx); 24void cx18_reset_i2c_slaves_gpio(struct cx18 *cx);
25void cx18_reset_ir_gpio(void *data); 25void cx18_reset_ir_gpio(void *data);
26int cx18_reset_tuner_gpio(void *dev, int cmd, int value); 26int cx18_reset_tuner_gpio(void *dev, int component, int cmd, int value);
27int cx18_gpio(struct cx18 *cx, unsigned int command, void *arg); 27int cx18_gpio(struct cx18 *cx, unsigned int command, void *arg);
diff --git a/drivers/media/video/cx18/cx18-i2c.c b/drivers/media/video/cx18/cx18-i2c.c
index 6023ba3bd3a6..aa09e557b195 100644
--- a/drivers/media/video/cx18/cx18-i2c.c
+++ b/drivers/media/video/cx18/cx18-i2c.c
@@ -22,13 +22,12 @@
22 */ 22 */
23 23
24#include "cx18-driver.h" 24#include "cx18-driver.h"
25#include "cx18-io.h"
25#include "cx18-cards.h" 26#include "cx18-cards.h"
26#include "cx18-gpio.h" 27#include "cx18-gpio.h"
27#include "cx18-av-core.h" 28#include "cx18-av-core.h"
28#include "cx18-i2c.h" 29#include "cx18-i2c.h"
29 30
30#include <media/ir-kbd-i2c.h>
31
32#define CX18_REG_I2C_1_WR 0xf15000 31#define CX18_REG_I2C_1_WR 0xf15000
33#define CX18_REG_I2C_1_RD 0xf15008 32#define CX18_REG_I2C_1_RD 0xf15008
34#define CX18_REG_I2C_2_WR 0xf25100 33#define CX18_REG_I2C_2_WR 0xf25100
@@ -158,12 +157,12 @@ static void cx18_setscl(void *data, int state)
158 struct cx18 *cx = ((struct cx18_i2c_algo_callback_data *)data)->cx; 157 struct cx18 *cx = ((struct cx18_i2c_algo_callback_data *)data)->cx;
159 int bus_index = ((struct cx18_i2c_algo_callback_data *)data)->bus_index; 158 int bus_index = ((struct cx18_i2c_algo_callback_data *)data)->bus_index;
160 u32 addr = bus_index ? CX18_REG_I2C_2_WR : CX18_REG_I2C_1_WR; 159 u32 addr = bus_index ? CX18_REG_I2C_2_WR : CX18_REG_I2C_1_WR;
161 u32 r = read_reg(addr); 160 u32 r = cx18_read_reg(cx, addr);
162 161
163 if (state) 162 if (state)
164 write_reg_sync(r | SETSCL_BIT, addr); 163 cx18_write_reg_sync(cx, r | SETSCL_BIT, addr);
165 else 164 else
166 write_reg_sync(r & ~SETSCL_BIT, addr); 165 cx18_write_reg_sync(cx, r & ~SETSCL_BIT, addr);
167} 166}
168 167
169static void cx18_setsda(void *data, int state) 168static void cx18_setsda(void *data, int state)
@@ -171,12 +170,12 @@ static void cx18_setsda(void *data, int state)
171 struct cx18 *cx = ((struct cx18_i2c_algo_callback_data *)data)->cx; 170 struct cx18 *cx = ((struct cx18_i2c_algo_callback_data *)data)->cx;
172 int bus_index = ((struct cx18_i2c_algo_callback_data *)data)->bus_index; 171 int bus_index = ((struct cx18_i2c_algo_callback_data *)data)->bus_index;
173 u32 addr = bus_index ? CX18_REG_I2C_2_WR : CX18_REG_I2C_1_WR; 172 u32 addr = bus_index ? CX18_REG_I2C_2_WR : CX18_REG_I2C_1_WR;
174 u32 r = read_reg(addr); 173 u32 r = cx18_read_reg(cx, addr);
175 174
176 if (state) 175 if (state)
177 write_reg_sync(r | SETSDL_BIT, addr); 176 cx18_write_reg_sync(cx, r | SETSDL_BIT, addr);
178 else 177 else
179 write_reg_sync(r & ~SETSDL_BIT, addr); 178 cx18_write_reg_sync(cx, r & ~SETSDL_BIT, addr);
180} 179}
181 180
182static int cx18_getscl(void *data) 181static int cx18_getscl(void *data)
@@ -185,7 +184,7 @@ static int cx18_getscl(void *data)
185 int bus_index = ((struct cx18_i2c_algo_callback_data *)data)->bus_index; 184 int bus_index = ((struct cx18_i2c_algo_callback_data *)data)->bus_index;
186 u32 addr = bus_index ? CX18_REG_I2C_2_RD : CX18_REG_I2C_1_RD; 185 u32 addr = bus_index ? CX18_REG_I2C_2_RD : CX18_REG_I2C_1_RD;
187 186
188 return read_reg(addr) & GETSCL_BIT; 187 return cx18_read_reg(cx, addr) & GETSCL_BIT;
189} 188}
190 189
191static int cx18_getsda(void *data) 190static int cx18_getsda(void *data)
@@ -194,7 +193,7 @@ static int cx18_getsda(void *data)
194 int bus_index = ((struct cx18_i2c_algo_callback_data *)data)->bus_index; 193 int bus_index = ((struct cx18_i2c_algo_callback_data *)data)->bus_index;
195 u32 addr = bus_index ? CX18_REG_I2C_2_RD : CX18_REG_I2C_1_RD; 194 u32 addr = bus_index ? CX18_REG_I2C_2_RD : CX18_REG_I2C_1_RD;
196 195
197 return read_reg(addr) & GETSDL_BIT; 196 return cx18_read_reg(cx, addr) & GETSDL_BIT;
198} 197}
199 198
200/* template for i2c-bit-algo */ 199/* template for i2c-bit-algo */
@@ -394,29 +393,33 @@ int init_cx18_i2c(struct cx18 *cx)
394 cx->i2c_adap[i].dev.parent = &cx->dev->dev; 393 cx->i2c_adap[i].dev.parent = &cx->dev->dev;
395 } 394 }
396 395
397 if (read_reg(CX18_REG_I2C_2_WR) != 0x0003c02f) { 396 if (cx18_read_reg(cx, CX18_REG_I2C_2_WR) != 0x0003c02f) {
398 /* Reset/Unreset I2C hardware block */ 397 /* Reset/Unreset I2C hardware block */
399 write_reg(0x10000000, 0xc71004); /* Clock select 220MHz */ 398 /* Clock select 220MHz */
400 write_reg_sync(0x10001000, 0xc71024); /* Clock Enable */ 399 cx18_write_reg(cx, 0x10000000, 0xc71004);
400 /* Clock Enable */
401 cx18_write_reg_sync(cx, 0x10001000, 0xc71024);
401 } 402 }
402 /* courtesy of Steven Toth <stoth@hauppauge.com> */ 403 /* courtesy of Steven Toth <stoth@hauppauge.com> */
403 write_reg_sync(0x00c00000, 0xc7001c); 404 cx18_write_reg_sync(cx, 0x00c00000, 0xc7001c);
404 mdelay(10); 405 mdelay(10);
405 write_reg_sync(0x00c000c0, 0xc7001c); 406 cx18_write_reg_sync(cx, 0x00c000c0, 0xc7001c);
406 mdelay(10); 407 mdelay(10);
407 write_reg_sync(0x00c00000, 0xc7001c); 408 cx18_write_reg_sync(cx, 0x00c00000, 0xc7001c);
408 mdelay(10); 409 mdelay(10);
409 410
410 write_reg_sync(0x00c00000, 0xc730c8); /* Set to edge-triggered intrs. */ 411 /* Set to edge-triggered intrs. */
411 write_reg_sync(0x00c00000, 0xc730c4); /* Clear any stale intrs */ 412 cx18_write_reg_sync(cx, 0x00c00000, 0xc730c8);
413 /* Clear any stale intrs */
414 cx18_write_reg_sync(cx, 0x00c00000, 0xc730c4);
412 415
413 /* Hw I2C1 Clock Freq ~100kHz */ 416 /* Hw I2C1 Clock Freq ~100kHz */
414 write_reg_sync(0x00021c0f & ~4, CX18_REG_I2C_1_WR); 417 cx18_write_reg_sync(cx, 0x00021c0f & ~4, CX18_REG_I2C_1_WR);
415 cx18_setscl(&cx->i2c_algo_cb_data[0], 1); 418 cx18_setscl(&cx->i2c_algo_cb_data[0], 1);
416 cx18_setsda(&cx->i2c_algo_cb_data[0], 1); 419 cx18_setsda(&cx->i2c_algo_cb_data[0], 1);
417 420
418 /* Hw I2C2 Clock Freq ~100kHz */ 421 /* Hw I2C2 Clock Freq ~100kHz */
419 write_reg_sync(0x00021c0f & ~4, CX18_REG_I2C_2_WR); 422 cx18_write_reg_sync(cx, 0x00021c0f & ~4, CX18_REG_I2C_2_WR);
420 cx18_setscl(&cx->i2c_algo_cb_data[1], 1); 423 cx18_setscl(&cx->i2c_algo_cb_data[1], 1);
421 cx18_setsda(&cx->i2c_algo_cb_data[1], 1); 424 cx18_setsda(&cx->i2c_algo_cb_data[1], 1);
422 425
@@ -430,8 +433,10 @@ void exit_cx18_i2c(struct cx18 *cx)
430{ 433{
431 int i; 434 int i;
432 CX18_DEBUG_I2C("i2c exit\n"); 435 CX18_DEBUG_I2C("i2c exit\n");
433 write_reg(read_reg(CX18_REG_I2C_1_WR) | 4, CX18_REG_I2C_1_WR); 436 cx18_write_reg(cx, cx18_read_reg(cx, CX18_REG_I2C_1_WR) | 4,
434 write_reg(read_reg(CX18_REG_I2C_2_WR) | 4, CX18_REG_I2C_2_WR); 437 CX18_REG_I2C_1_WR);
438 cx18_write_reg(cx, cx18_read_reg(cx, CX18_REG_I2C_2_WR) | 4,
439 CX18_REG_I2C_2_WR);
435 440
436 for (i = 0; i < 2; i++) { 441 for (i = 0; i < 2; i++) {
437 i2c_del_adapter(&cx->i2c_adap[i]); 442 i2c_del_adapter(&cx->i2c_adap[i]);
diff --git a/drivers/media/video/cx18/cx18-io.c b/drivers/media/video/cx18/cx18-io.c
new file mode 100644
index 000000000000..700ab9439c16
--- /dev/null
+++ b/drivers/media/video/cx18/cx18-io.c
@@ -0,0 +1,254 @@
1/*
2 * cx18 driver PCI memory mapped IO access routines
3 *
4 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
5 * Copyright (C) 2008 Andy Walls <awalls@radix.net>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 * 02111-1307 USA
21 */
22
23#include "cx18-driver.h"
24#include "cx18-io.h"
25#include "cx18-irq.h"
26
27void cx18_log_statistics(struct cx18 *cx)
28{
29 int i;
30
31 if (!(cx18_debug & CX18_DBGFLG_INFO))
32 return;
33
34 for (i = 0; i <= CX18_MAX_MMIO_RETRIES; i++)
35 CX18_DEBUG_INFO("retried_write[%d] = %d\n", i,
36 atomic_read(&cx->mmio_stats.retried_write[i]));
37 for (i = 0; i <= CX18_MAX_MMIO_RETRIES; i++)
38 CX18_DEBUG_INFO("retried_read[%d] = %d\n", i,
39 atomic_read(&cx->mmio_stats.retried_read[i]));
40 return;
41}
42
43void cx18_raw_writel_retry(struct cx18 *cx, u32 val, void __iomem *addr)
44{
45 int i;
46 for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
47 cx18_raw_writel_noretry(cx, val, addr);
48 if (val == cx18_raw_readl_noretry(cx, addr))
49 break;
50 }
51 cx18_log_write_retries(cx, i, addr);
52}
53
54u32 cx18_raw_readl_retry(struct cx18 *cx, const void __iomem *addr)
55{
56 int i;
57 u32 val;
58 for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
59 val = cx18_raw_readl_noretry(cx, addr);
60 if (val != 0xffffffff) /* PCI bus read error */
61 break;
62 }
63 cx18_log_read_retries(cx, i, addr);
64 return val;
65}
66
67u16 cx18_raw_readw_retry(struct cx18 *cx, const void __iomem *addr)
68{
69 int i;
70 u16 val;
71 for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
72 val = cx18_raw_readw_noretry(cx, addr);
73 if (val != 0xffff) /* PCI bus read error */
74 break;
75 }
76 cx18_log_read_retries(cx, i, addr);
77 return val;
78}
79
80void cx18_writel_retry(struct cx18 *cx, u32 val, void __iomem *addr)
81{
82 int i;
83 for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
84 cx18_writel_noretry(cx, val, addr);
85 if (val == cx18_readl_noretry(cx, addr))
86 break;
87 }
88 cx18_log_write_retries(cx, i, addr);
89}
90
91void cx18_writew_retry(struct cx18 *cx, u16 val, void __iomem *addr)
92{
93 int i;
94 for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
95 cx18_writew_noretry(cx, val, addr);
96 if (val == cx18_readw_noretry(cx, addr))
97 break;
98 }
99 cx18_log_write_retries(cx, i, addr);
100}
101
102void cx18_writeb_retry(struct cx18 *cx, u8 val, void __iomem *addr)
103{
104 int i;
105 for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
106 cx18_writeb_noretry(cx, val, addr);
107 if (val == cx18_readb_noretry(cx, addr))
108 break;
109 }
110 cx18_log_write_retries(cx, i, addr);
111}
112
113u32 cx18_readl_retry(struct cx18 *cx, const void __iomem *addr)
114{
115 int i;
116 u32 val;
117 for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
118 val = cx18_readl_noretry(cx, addr);
119 if (val != 0xffffffff) /* PCI bus read error */
120 break;
121 }
122 cx18_log_read_retries(cx, i, addr);
123 return val;
124}
125
126u16 cx18_readw_retry(struct cx18 *cx, const void __iomem *addr)
127{
128 int i;
129 u16 val;
130 for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
131 val = cx18_readw_noretry(cx, addr);
132 if (val != 0xffff) /* PCI bus read error */
133 break;
134 }
135 cx18_log_read_retries(cx, i, addr);
136 return val;
137}
138
139u8 cx18_readb_retry(struct cx18 *cx, const void __iomem *addr)
140{
141 int i;
142 u8 val;
143 for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
144 val = cx18_readb_noretry(cx, addr);
145 if (val != 0xff) /* PCI bus read error */
146 break;
147 }
148 cx18_log_read_retries(cx, i, addr);
149 return val;
150}
151
152void cx18_memcpy_fromio(struct cx18 *cx, void *to,
153 const void __iomem *from, unsigned int len)
154{
155 const u8 __iomem *src = from;
156 u8 *dst = to;
157
158 /* Align reads on the CX23418's addresses */
159 if ((len > 0) && ((unsigned long) src & 1)) {
160 *dst = cx18_readb(cx, src);
161 len--;
162 dst++;
163 src++;
164 }
165 if ((len > 1) && ((unsigned long) src & 2)) {
166 *((u16 *)dst) = cx18_raw_readw(cx, src);
167 len -= 2;
168 dst += 2;
169 src += 2;
170 }
171 while (len > 3) {
172 *((u32 *)dst) = cx18_raw_readl(cx, src);
173 len -= 4;
174 dst += 4;
175 src += 4;
176 }
177 if (len > 1) {
178 *((u16 *)dst) = cx18_raw_readw(cx, src);
179 len -= 2;
180 dst += 2;
181 src += 2;
182 }
183 if (len > 0)
184 *dst = cx18_readb(cx, src);
185}
186
187void cx18_memset_io(struct cx18 *cx, void __iomem *addr, int val, size_t count)
188{
189 u8 __iomem *dst = addr;
190 u16 val2 = val | (val << 8);
191 u32 val4 = val2 | (val2 << 16);
192
193 /* Align writes on the CX23418's addresses */
194 if ((count > 0) && ((unsigned long)dst & 1)) {
195 cx18_writeb(cx, (u8) val, dst);
196 count--;
197 dst++;
198 }
199 if ((count > 1) && ((unsigned long)dst & 2)) {
200 cx18_writew(cx, val2, dst);
201 count -= 2;
202 dst += 2;
203 }
204 while (count > 3) {
205 cx18_writel(cx, val4, dst);
206 count -= 4;
207 dst += 4;
208 }
209 if (count > 1) {
210 cx18_writew(cx, val2, dst);
211 count -= 2;
212 dst += 2;
213 }
214 if (count > 0)
215 cx18_writeb(cx, (u8) val, dst);
216}
217
218void cx18_sw1_irq_enable(struct cx18 *cx, u32 val)
219{
220 u32 r;
221 cx18_write_reg(cx, val, SW1_INT_STATUS);
222 r = cx18_read_reg(cx, SW1_INT_ENABLE_PCI);
223 cx18_write_reg(cx, r | val, SW1_INT_ENABLE_PCI);
224}
225
226void cx18_sw1_irq_disable(struct cx18 *cx, u32 val)
227{
228 u32 r;
229 r = cx18_read_reg(cx, SW1_INT_ENABLE_PCI);
230 cx18_write_reg(cx, r & ~val, SW1_INT_ENABLE_PCI);
231}
232
233void cx18_sw2_irq_enable(struct cx18 *cx, u32 val)
234{
235 u32 r;
236 cx18_write_reg(cx, val, SW2_INT_STATUS);
237 r = cx18_read_reg(cx, SW2_INT_ENABLE_PCI);
238 cx18_write_reg(cx, r | val, SW2_INT_ENABLE_PCI);
239}
240
241void cx18_sw2_irq_disable(struct cx18 *cx, u32 val)
242{
243 u32 r;
244 r = cx18_read_reg(cx, SW2_INT_ENABLE_PCI);
245 cx18_write_reg(cx, r & ~val, SW2_INT_ENABLE_PCI);
246}
247
248void cx18_setup_page(struct cx18 *cx, u32 addr)
249{
250 u32 val;
251 val = cx18_read_reg(cx, 0xD000F8);
252 val = (val & ~0x1f00) | ((addr >> 17) & 0x1f00);
253 cx18_write_reg(cx, val, 0xD000F8);
254}
diff --git a/drivers/media/video/cx18/cx18-io.h b/drivers/media/video/cx18/cx18-io.h
new file mode 100644
index 000000000000..197d4fbd9f95
--- /dev/null
+++ b/drivers/media/video/cx18/cx18-io.h
@@ -0,0 +1,378 @@
1/*
2 * cx18 driver PCI memory mapped IO access routines
3 *
4 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
5 * Copyright (C) 2008 Andy Walls <awalls@radix.net>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20 * 02111-1307 USA
21 */
22
23#ifndef CX18_IO_H
24#define CX18_IO_H
25
26#include "cx18-driver.h"
27
28static inline void cx18_io_delay(struct cx18 *cx)
29{
30 if (cx->options.mmio_ndelay)
31 ndelay(cx->options.mmio_ndelay);
32}
33
34/*
35 * Readback and retry of MMIO access for reliability:
36 * The concept was suggested by Steve Toth <stoth@linuxtv.org>.
37 * The implmentation is the fault of Andy Walls <awalls@radix.net>.
38 */
39
40/* Statistics gathering */
41static inline
42void cx18_log_write_retries(struct cx18 *cx, int i, const void *addr)
43{
44 if (i > CX18_MAX_MMIO_RETRIES)
45 i = CX18_MAX_MMIO_RETRIES;
46 atomic_inc(&cx->mmio_stats.retried_write[i]);
47 return;
48}
49
50static inline
51void cx18_log_read_retries(struct cx18 *cx, int i, const void *addr)
52{
53 if (i > CX18_MAX_MMIO_RETRIES)
54 i = CX18_MAX_MMIO_RETRIES;
55 atomic_inc(&cx->mmio_stats.retried_read[i]);
56 return;
57}
58
59void cx18_log_statistics(struct cx18 *cx);
60
61/* Non byteswapping memory mapped IO */
62static inline
63void cx18_raw_writel_noretry(struct cx18 *cx, u32 val, void __iomem *addr)
64{
65 __raw_writel(val, addr);
66 cx18_io_delay(cx);
67}
68
69void cx18_raw_writel_retry(struct cx18 *cx, u32 val, void __iomem *addr);
70
71static inline void cx18_raw_writel(struct cx18 *cx, u32 val, void __iomem *addr)
72{
73 if (cx18_retry_mmio)
74 cx18_raw_writel_retry(cx, val, addr);
75 else
76 cx18_raw_writel_noretry(cx, val, addr);
77}
78
79
80static inline
81u32 cx18_raw_readl_noretry(struct cx18 *cx, const void __iomem *addr)
82{
83 u32 ret = __raw_readl(addr);
84 cx18_io_delay(cx);
85 return ret;
86}
87
88u32 cx18_raw_readl_retry(struct cx18 *cx, const void __iomem *addr);
89
90static inline u32 cx18_raw_readl(struct cx18 *cx, const void __iomem *addr)
91{
92 if (cx18_retry_mmio)
93 return cx18_raw_readl_retry(cx, addr);
94
95 return cx18_raw_readl_noretry(cx, addr);
96}
97
98
99static inline
100u16 cx18_raw_readw_noretry(struct cx18 *cx, const void __iomem *addr)
101{
102 u16 ret = __raw_readw(addr);
103 cx18_io_delay(cx);
104 return ret;
105}
106
107u16 cx18_raw_readw_retry(struct cx18 *cx, const void __iomem *addr);
108
109static inline u16 cx18_raw_readw(struct cx18 *cx, const void __iomem *addr)
110{
111 if (cx18_retry_mmio)
112 return cx18_raw_readw_retry(cx, addr);
113
114 return cx18_raw_readw_noretry(cx, addr);
115}
116
117
118/* Normal memory mapped IO */
119static inline
120void cx18_writel_noretry(struct cx18 *cx, u32 val, void __iomem *addr)
121{
122 writel(val, addr);
123 cx18_io_delay(cx);
124}
125
126void cx18_writel_retry(struct cx18 *cx, u32 val, void __iomem *addr);
127
128static inline void cx18_writel(struct cx18 *cx, u32 val, void __iomem *addr)
129{
130 if (cx18_retry_mmio)
131 cx18_writel_retry(cx, val, addr);
132 else
133 cx18_writel_noretry(cx, val, addr);
134}
135
136
137static inline
138void cx18_writew_noretry(struct cx18 *cx, u16 val, void __iomem *addr)
139{
140 writew(val, addr);
141 cx18_io_delay(cx);
142}
143
144void cx18_writew_retry(struct cx18 *cx, u16 val, void __iomem *addr);
145
146static inline void cx18_writew(struct cx18 *cx, u16 val, void __iomem *addr)
147{
148 if (cx18_retry_mmio)
149 cx18_writew_retry(cx, val, addr);
150 else
151 cx18_writew_noretry(cx, val, addr);
152}
153
154
155static inline
156void cx18_writeb_noretry(struct cx18 *cx, u8 val, void __iomem *addr)
157{
158 writeb(val, addr);
159 cx18_io_delay(cx);
160}
161
162void cx18_writeb_retry(struct cx18 *cx, u8 val, void __iomem *addr);
163
164static inline void cx18_writeb(struct cx18 *cx, u8 val, void __iomem *addr)
165{
166 if (cx18_retry_mmio)
167 cx18_writeb_retry(cx, val, addr);
168 else
169 cx18_writeb_noretry(cx, val, addr);
170}
171
172
173static inline u32 cx18_readl_noretry(struct cx18 *cx, const void __iomem *addr)
174{
175 u32 ret = readl(addr);
176 cx18_io_delay(cx);
177 return ret;
178}
179
180u32 cx18_readl_retry(struct cx18 *cx, const void __iomem *addr);
181
182static inline u32 cx18_readl(struct cx18 *cx, const void __iomem *addr)
183{
184 if (cx18_retry_mmio)
185 return cx18_readl_retry(cx, addr);
186
187 return cx18_readl_noretry(cx, addr);
188}
189
190
191static inline u16 cx18_readw_noretry(struct cx18 *cx, const void __iomem *addr)
192{
193 u16 ret = readw(addr);
194 cx18_io_delay(cx);
195 return ret;
196}
197
198u16 cx18_readw_retry(struct cx18 *cx, const void __iomem *addr);
199
200static inline u16 cx18_readw(struct cx18 *cx, const void __iomem *addr)
201{
202 if (cx18_retry_mmio)
203 return cx18_readw_retry(cx, addr);
204
205 return cx18_readw_noretry(cx, addr);
206}
207
208
209static inline u8 cx18_readb_noretry(struct cx18 *cx, const void __iomem *addr)
210{
211 u8 ret = readb(addr);
212 cx18_io_delay(cx);
213 return ret;
214}
215
216u8 cx18_readb_retry(struct cx18 *cx, const void __iomem *addr);
217
218static inline u8 cx18_readb(struct cx18 *cx, const void __iomem *addr)
219{
220 if (cx18_retry_mmio)
221 return cx18_readb_retry(cx, addr);
222
223 return cx18_readb_noretry(cx, addr);
224}
225
226
227static inline
228u32 cx18_write_sync_noretry(struct cx18 *cx, u32 val, void __iomem *addr)
229{
230 cx18_writel_noretry(cx, val, addr);
231 return cx18_readl_noretry(cx, addr);
232}
233
234static inline
235u32 cx18_write_sync_retry(struct cx18 *cx, u32 val, void __iomem *addr)
236{
237 cx18_writel_retry(cx, val, addr);
238 return cx18_readl_retry(cx, addr);
239}
240
241static inline u32 cx18_write_sync(struct cx18 *cx, u32 val, void __iomem *addr)
242{
243 if (cx18_retry_mmio)
244 return cx18_write_sync_retry(cx, val, addr);
245
246 return cx18_write_sync_noretry(cx, val, addr);
247}
248
249
250void cx18_memcpy_fromio(struct cx18 *cx, void *to,
251 const void __iomem *from, unsigned int len);
252void cx18_memset_io(struct cx18 *cx, void __iomem *addr, int val, size_t count);
253
254
255/* Access "register" region of CX23418 memory mapped I/O */
256static inline void cx18_write_reg_noretry(struct cx18 *cx, u32 val, u32 reg)
257{
258 cx18_writel_noretry(cx, val, cx->reg_mem + reg);
259}
260
261static inline void cx18_write_reg_retry(struct cx18 *cx, u32 val, u32 reg)
262{
263 cx18_writel_retry(cx, val, cx->reg_mem + reg);
264}
265
266static inline void cx18_write_reg(struct cx18 *cx, u32 val, u32 reg)
267{
268 if (cx18_retry_mmio)
269 cx18_write_reg_retry(cx, val, reg);
270 else
271 cx18_write_reg_noretry(cx, val, reg);
272}
273
274
275static inline u32 cx18_read_reg_noretry(struct cx18 *cx, u32 reg)
276{
277 return cx18_readl_noretry(cx, cx->reg_mem + reg);
278}
279
280static inline u32 cx18_read_reg_retry(struct cx18 *cx, u32 reg)
281{
282 return cx18_readl_retry(cx, cx->reg_mem + reg);
283}
284
285static inline u32 cx18_read_reg(struct cx18 *cx, u32 reg)
286{
287 if (cx18_retry_mmio)
288 return cx18_read_reg_retry(cx, reg);
289
290 return cx18_read_reg_noretry(cx, reg);
291}
292
293
294static inline u32 cx18_write_reg_sync_noretry(struct cx18 *cx, u32 val, u32 reg)
295{
296 return cx18_write_sync_noretry(cx, val, cx->reg_mem + reg);
297}
298
299static inline u32 cx18_write_reg_sync_retry(struct cx18 *cx, u32 val, u32 reg)
300{
301 return cx18_write_sync_retry(cx, val, cx->reg_mem + reg);
302}
303
304static inline u32 cx18_write_reg_sync(struct cx18 *cx, u32 val, u32 reg)
305{
306 if (cx18_retry_mmio)
307 return cx18_write_reg_sync_retry(cx, val, reg);
308
309 return cx18_write_reg_sync_noretry(cx, val, reg);
310}
311
312
313/* Access "encoder memory" region of CX23418 memory mapped I/O */
314static inline void cx18_write_enc_noretry(struct cx18 *cx, u32 val, u32 addr)
315{
316 cx18_writel_noretry(cx, val, cx->enc_mem + addr);
317}
318
319static inline void cx18_write_enc_retry(struct cx18 *cx, u32 val, u32 addr)
320{
321 cx18_writel_retry(cx, val, cx->enc_mem + addr);
322}
323
324static inline void cx18_write_enc(struct cx18 *cx, u32 val, u32 addr)
325{
326 if (cx18_retry_mmio)
327 cx18_write_enc_retry(cx, val, addr);
328 else
329 cx18_write_enc_noretry(cx, val, addr);
330}
331
332
333static inline u32 cx18_read_enc_noretry(struct cx18 *cx, u32 addr)
334{
335 return cx18_readl_noretry(cx, cx->enc_mem + addr);
336}
337
338static inline u32 cx18_read_enc_retry(struct cx18 *cx, u32 addr)
339{
340 return cx18_readl_retry(cx, cx->enc_mem + addr);
341}
342
343static inline u32 cx18_read_enc(struct cx18 *cx, u32 addr)
344{
345 if (cx18_retry_mmio)
346 return cx18_read_enc_retry(cx, addr);
347
348 return cx18_read_enc_noretry(cx, addr);
349}
350
351static inline
352u32 cx18_write_enc_sync_noretry(struct cx18 *cx, u32 val, u32 addr)
353{
354 return cx18_write_sync_noretry(cx, val, cx->enc_mem + addr);
355}
356
357static inline
358u32 cx18_write_enc_sync_retry(struct cx18 *cx, u32 val, u32 addr)
359{
360 return cx18_write_sync_retry(cx, val, cx->enc_mem + addr);
361}
362
363static inline
364u32 cx18_write_enc_sync(struct cx18 *cx, u32 val, u32 addr)
365{
366 if (cx18_retry_mmio)
367 return cx18_write_enc_sync_retry(cx, val, addr);
368
369 return cx18_write_enc_sync_noretry(cx, val, addr);
370}
371
372void cx18_sw1_irq_enable(struct cx18 *cx, u32 val);
373void cx18_sw1_irq_disable(struct cx18 *cx, u32 val);
374void cx18_sw2_irq_enable(struct cx18 *cx, u32 val);
375void cx18_sw2_irq_disable(struct cx18 *cx, u32 val);
376void cx18_setup_page(struct cx18 *cx, u32 addr);
377
378#endif /* CX18_IO_H */
diff --git a/drivers/media/video/cx18/cx18-ioctl.c b/drivers/media/video/cx18/cx18-ioctl.c
index a7f839631d6a..f0ca50f5fdde 100644
--- a/drivers/media/video/cx18/cx18-ioctl.c
+++ b/drivers/media/video/cx18/cx18-ioctl.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include "cx18-driver.h" 24#include "cx18-driver.h"
25#include "cx18-io.h"
25#include "cx18-version.h" 26#include "cx18-version.h"
26#include "cx18-mailbox.h" 27#include "cx18-mailbox.h"
27#include "cx18-i2c.h" 28#include "cx18-i2c.h"
@@ -170,7 +171,6 @@ static int cx18_try_fmt_vid_cap(struct file *file, void *fh,
170{ 171{
171 struct cx18_open_id *id = fh; 172 struct cx18_open_id *id = fh;
172 struct cx18 *cx = id->cx; 173 struct cx18 *cx = id->cx;
173
174 int w = fmt->fmt.pix.width; 174 int w = fmt->fmt.pix.width;
175 int h = fmt->fmt.pix.height; 175 int h = fmt->fmt.pix.height;
176 176
@@ -202,8 +202,7 @@ static int cx18_s_fmt_vid_cap(struct file *file, void *fh,
202 struct cx18_open_id *id = fh; 202 struct cx18_open_id *id = fh;
203 struct cx18 *cx = id->cx; 203 struct cx18 *cx = id->cx;
204 int ret; 204 int ret;
205 int w = fmt->fmt.pix.width; 205 int w, h;
206 int h = fmt->fmt.pix.height;
207 206
208 ret = v4l2_prio_check(&cx->prio, &id->prio); 207 ret = v4l2_prio_check(&cx->prio, &id->prio);
209 if (ret) 208 if (ret)
@@ -212,6 +211,8 @@ static int cx18_s_fmt_vid_cap(struct file *file, void *fh,
212 ret = cx18_try_fmt_vid_cap(file, fh, fmt); 211 ret = cx18_try_fmt_vid_cap(file, fh, fmt);
213 if (ret) 212 if (ret)
214 return ret; 213 return ret;
214 w = fmt->fmt.pix.width;
215 h = fmt->fmt.pix.height;
215 216
216 if (cx->params.width == w && cx->params.height == h) 217 if (cx->params.width == w && cx->params.height == h)
217 return 0; 218 return 0;
@@ -286,9 +287,9 @@ static int cx18_cxc(struct cx18 *cx, unsigned int cmd, void *arg)
286 287
287 spin_lock_irqsave(&cx18_cards_lock, flags); 288 spin_lock_irqsave(&cx18_cards_lock, flags);
288 if (cmd == VIDIOC_DBG_G_REGISTER) 289 if (cmd == VIDIOC_DBG_G_REGISTER)
289 regs->val = read_enc(regs->reg); 290 regs->val = cx18_read_enc(cx, regs->reg);
290 else 291 else
291 write_enc(regs->val, regs->reg); 292 cx18_write_enc(cx, regs->val, regs->reg);
292 spin_unlock_irqrestore(&cx18_cards_lock, flags); 293 spin_unlock_irqrestore(&cx18_cards_lock, flags);
293 return 0; 294 return 0;
294} 295}
@@ -345,7 +346,7 @@ static int cx18_querycap(struct file *file, void *fh,
345 346
346 strlcpy(vcap->driver, CX18_DRIVER_NAME, sizeof(vcap->driver)); 347 strlcpy(vcap->driver, CX18_DRIVER_NAME, sizeof(vcap->driver));
347 strlcpy(vcap->card, cx->card_name, sizeof(vcap->card)); 348 strlcpy(vcap->card, cx->card_name, sizeof(vcap->card));
348 strlcpy(vcap->bus_info, pci_name(cx->dev), sizeof(vcap->bus_info)); 349 snprintf(vcap->bus_info, sizeof(vcap->bus_info), "PCI:%s", pci_name(cx->dev));
349 vcap->version = CX18_DRIVER_VERSION; /* version */ 350 vcap->version = CX18_DRIVER_VERSION; /* version */
350 vcap->capabilities = cx->v4l2_cap; /* capabilities */ 351 vcap->capabilities = cx->v4l2_cap; /* capabilities */
351 return 0; 352 return 0;
@@ -622,6 +623,7 @@ static int cx18_encoder_cmd(struct file *file, void *fh,
622{ 623{
623 struct cx18_open_id *id = fh; 624 struct cx18_open_id *id = fh;
624 struct cx18 *cx = id->cx; 625 struct cx18 *cx = id->cx;
626 u32 h;
625 627
626 switch (enc->cmd) { 628 switch (enc->cmd) {
627 case V4L2_ENC_CMD_START: 629 case V4L2_ENC_CMD_START:
@@ -643,8 +645,14 @@ static int cx18_encoder_cmd(struct file *file, void *fh,
643 return -EPERM; 645 return -EPERM;
644 if (test_and_set_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags)) 646 if (test_and_set_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
645 return 0; 647 return 0;
648 h = cx18_find_handle(cx);
649 if (h == CX18_INVALID_TASK_HANDLE) {
650 CX18_ERR("Can't find valid task handle for "
651 "V4L2_ENC_CMD_PAUSE\n");
652 return -EBADFD;
653 }
646 cx18_mute(cx); 654 cx18_mute(cx);
647 cx18_vapi(cx, CX18_CPU_CAPTURE_PAUSE, 1, cx18_find_handle(cx)); 655 cx18_vapi(cx, CX18_CPU_CAPTURE_PAUSE, 1, h);
648 break; 656 break;
649 657
650 case V4L2_ENC_CMD_RESUME: 658 case V4L2_ENC_CMD_RESUME:
@@ -654,7 +662,13 @@ static int cx18_encoder_cmd(struct file *file, void *fh,
654 return -EPERM; 662 return -EPERM;
655 if (!test_and_clear_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags)) 663 if (!test_and_clear_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
656 return 0; 664 return 0;
657 cx18_vapi(cx, CX18_CPU_CAPTURE_RESUME, 1, cx18_find_handle(cx)); 665 h = cx18_find_handle(cx);
666 if (h == CX18_INVALID_TASK_HANDLE) {
667 CX18_ERR("Can't find valid task handle for "
668 "V4L2_ENC_CMD_RESUME\n");
669 return -EBADFD;
670 }
671 cx18_vapi(cx, CX18_CPU_CAPTURE_RESUME, 1, h);
658 cx18_unmute(cx); 672 cx18_unmute(cx);
659 break; 673 break;
660 674
@@ -731,12 +745,14 @@ static int cx18_log_status(struct file *file, void *fh)
731 continue; 745 continue;
732 CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n", 746 CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n",
733 s->name, s->s_flags, 747 s->name, s->s_flags,
734 (s->buffers - s->q_free.buffers) * 100 / s->buffers, 748 (s->buffers - atomic_read(&s->q_free.buffers))
749 * 100 / s->buffers,
735 (s->buffers * s->buf_size) / 1024, s->buffers); 750 (s->buffers * s->buf_size) / 1024, s->buffers);
736 } 751 }
737 CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n", 752 CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n",
738 (long long)cx->mpg_data_received, 753 (long long)cx->mpg_data_received,
739 (long long)cx->vbi_data_inserted); 754 (long long)cx->vbi_data_inserted);
755 cx18_log_statistics(cx);
740 CX18_INFO("================== END STATUS CARD #%d ==================\n", cx->num); 756 CX18_INFO("================== END STATUS CARD #%d ==================\n", cx->num);
741 return 0; 757 return 0;
742} 758}
diff --git a/drivers/media/video/cx18/cx18-irq.c b/drivers/media/video/cx18/cx18-irq.c
index ab218315c84b..360330f5463f 100644
--- a/drivers/media/video/cx18/cx18-irq.c
+++ b/drivers/media/video/cx18/cx18-irq.c
@@ -20,6 +20,7 @@
20 */ 20 */
21 21
22#include "cx18-driver.h" 22#include "cx18-driver.h"
23#include "cx18-io.h"
23#include "cx18-firmware.h" 24#include "cx18-firmware.h"
24#include "cx18-fileops.h" 25#include "cx18-fileops.h"
25#include "cx18-queue.h" 26#include "cx18-queue.h"
@@ -48,8 +49,8 @@ static void epu_dma_done(struct cx18 *cx, struct cx18_mailbox *mb)
48 break; 49 break;
49 } 50 }
50 if (i == CX18_MAX_STREAMS) { 51 if (i == CX18_MAX_STREAMS) {
51 CX18_WARN("DMA done for unknown handle %d for stream %s\n", 52 CX18_WARN("Got DMA done notification for unknown/inactive"
52 handle, s->name); 53 " handle %d\n", handle);
53 mb->error = CXERR_NOT_OPEN; 54 mb->error = CXERR_NOT_OPEN;
54 mb->cmd = 0; 55 mb->cmd = 0;
55 cx18_mb_ack(cx, mb); 56 cx18_mb_ack(cx, mb);
@@ -60,8 +61,8 @@ static void epu_dma_done(struct cx18 *cx, struct cx18_mailbox *mb)
60 if (mb->args[2] != 1) 61 if (mb->args[2] != 1)
61 CX18_WARN("Ack struct = %d for %s\n", 62 CX18_WARN("Ack struct = %d for %s\n",
62 mb->args[2], s->name); 63 mb->args[2], s->name);
63 id = read_enc(off); 64 id = cx18_read_enc(cx, off);
64 buf = cx18_queue_get_buf_irq(s, id, read_enc(off + 4)); 65 buf = cx18_queue_get_buf_irq(s, id, cx18_read_enc(cx, off + 4));
65 CX18_DEBUG_HI_DMA("DMA DONE for %s (buffer %d)\n", s->name, id); 66 CX18_DEBUG_HI_DMA("DMA DONE for %s (buffer %d)\n", s->name, id);
66 if (buf) { 67 if (buf) {
67 cx18_buf_sync_for_cpu(s, buf); 68 cx18_buf_sync_for_cpu(s, buf);
@@ -81,7 +82,7 @@ static void epu_dma_done(struct cx18 *cx, struct cx18_mailbox *mb)
81 set_bit(CX18_F_B_NEED_BUF_SWAP, &buf->b_flags); 82 set_bit(CX18_F_B_NEED_BUF_SWAP, &buf->b_flags);
82 } else { 83 } else {
83 CX18_WARN("Could not find buf %d for stream %s\n", 84 CX18_WARN("Could not find buf %d for stream %s\n",
84 read_enc(off), s->name); 85 cx18_read_enc(cx, off), s->name);
85 } 86 }
86 mb->error = 0; 87 mb->error = 0;
87 mb->cmd = 0; 88 mb->cmd = 0;
@@ -97,8 +98,8 @@ static void epu_debug(struct cx18 *cx, struct cx18_mailbox *mb)
97 char *p; 98 char *p;
98 99
99 if (mb->args[1]) { 100 if (mb->args[1]) {
100 setup_page(mb->args[1]); 101 cx18_setup_page(cx, mb->args[1]);
101 memcpy_fromio(str, cx->enc_mem + mb->args[1], 252); 102 cx18_memcpy_fromio(cx, str, cx->enc_mem + mb->args[1], 252);
102 str[252] = 0; 103 str[252] = 0;
103 } 104 }
104 cx18_mb_ack(cx, mb); 105 cx18_mb_ack(cx, mb);
@@ -113,7 +114,7 @@ static void hpu_cmd(struct cx18 *cx, u32 sw1)
113 struct cx18_mailbox mb; 114 struct cx18_mailbox mb;
114 115
115 if (sw1 & IRQ_CPU_TO_EPU) { 116 if (sw1 & IRQ_CPU_TO_EPU) {
116 memcpy_fromio(&mb, &cx->scb->cpu2epu_mb, sizeof(mb)); 117 cx18_memcpy_fromio(cx, &mb, &cx->scb->cpu2epu_mb, sizeof(mb));
117 mb.error = 0; 118 mb.error = 0;
118 119
119 switch (mb.cmd) { 120 switch (mb.cmd) {
@@ -141,16 +142,16 @@ irqreturn_t cx18_irq_handler(int irq, void *dev_id)
141 142
142 spin_lock(&cx->dma_reg_lock); 143 spin_lock(&cx->dma_reg_lock);
143 144
144 hw2_mask = read_reg(HW2_INT_MASK5_PCI); 145 hw2_mask = cx18_read_reg(cx, HW2_INT_MASK5_PCI);
145 hw2 = read_reg(HW2_INT_CLR_STATUS) & hw2_mask; 146 hw2 = cx18_read_reg(cx, HW2_INT_CLR_STATUS) & hw2_mask;
146 sw2_mask = read_reg(SW2_INT_ENABLE_PCI) | IRQ_EPU_TO_HPU_ACK; 147 sw2_mask = cx18_read_reg(cx, SW2_INT_ENABLE_PCI) | IRQ_EPU_TO_HPU_ACK;
147 sw2 = read_reg(SW2_INT_STATUS) & sw2_mask; 148 sw2 = cx18_read_reg(cx, SW2_INT_STATUS) & sw2_mask;
148 sw1_mask = read_reg(SW1_INT_ENABLE_PCI) | IRQ_EPU_TO_HPU; 149 sw1_mask = cx18_read_reg(cx, SW1_INT_ENABLE_PCI) | IRQ_EPU_TO_HPU;
149 sw1 = read_reg(SW1_INT_STATUS) & sw1_mask; 150 sw1 = cx18_read_reg(cx, SW1_INT_STATUS) & sw1_mask;
150 151
151 write_reg(sw2&sw2_mask, SW2_INT_STATUS); 152 cx18_write_reg(cx, sw2&sw2_mask, SW2_INT_STATUS);
152 write_reg(sw1&sw1_mask, SW1_INT_STATUS); 153 cx18_write_reg(cx, sw1&sw1_mask, SW1_INT_STATUS);
153 write_reg(hw2&hw2_mask, HW2_INT_CLR_STATUS); 154 cx18_write_reg(cx, hw2&hw2_mask, HW2_INT_CLR_STATUS);
154 155
155 if (sw1 || sw2 || hw2) 156 if (sw1 || sw2 || hw2)
156 CX18_DEBUG_HI_IRQ("SW1: %x SW2: %x HW2: %x\n", sw1, sw2, hw2); 157 CX18_DEBUG_HI_IRQ("SW1: %x SW2: %x HW2: %x\n", sw1, sw2, hw2);
@@ -161,15 +162,15 @@ irqreturn_t cx18_irq_handler(int irq, void *dev_id)
161 */ 162 */
162 163
163 if (sw2) { 164 if (sw2) {
164 if (sw2 & (readl(&cx->scb->cpu2hpu_irq_ack) | 165 if (sw2 & (cx18_readl(cx, &cx->scb->cpu2hpu_irq_ack) |
165 readl(&cx->scb->cpu2epu_irq_ack))) 166 cx18_readl(cx, &cx->scb->cpu2epu_irq_ack)))
166 wake_up(&cx->mb_cpu_waitq); 167 wake_up(&cx->mb_cpu_waitq);
167 if (sw2 & (readl(&cx->scb->apu2hpu_irq_ack) | 168 if (sw2 & (cx18_readl(cx, &cx->scb->apu2hpu_irq_ack) |
168 readl(&cx->scb->apu2epu_irq_ack))) 169 cx18_readl(cx, &cx->scb->apu2epu_irq_ack)))
169 wake_up(&cx->mb_apu_waitq); 170 wake_up(&cx->mb_apu_waitq);
170 if (sw2 & readl(&cx->scb->epu2hpu_irq_ack)) 171 if (sw2 & cx18_readl(cx, &cx->scb->epu2hpu_irq_ack))
171 wake_up(&cx->mb_epu_waitq); 172 wake_up(&cx->mb_epu_waitq);
172 if (sw2 & readl(&cx->scb->hpu2epu_irq_ack)) 173 if (sw2 & cx18_readl(cx, &cx->scb->hpu2epu_irq_ack))
173 wake_up(&cx->mb_hpu_waitq); 174 wake_up(&cx->mb_hpu_waitq);
174 } 175 }
175 176
diff --git a/drivers/media/video/cx18/cx18-mailbox.c b/drivers/media/video/cx18/cx18-mailbox.c
index 93177514e846..9d18dd22de76 100644
--- a/drivers/media/video/cx18/cx18-mailbox.c
+++ b/drivers/media/video/cx18/cx18-mailbox.c
@@ -22,6 +22,7 @@
22#include <stdarg.h> 22#include <stdarg.h>
23 23
24#include "cx18-driver.h" 24#include "cx18-driver.h"
25#include "cx18-io.h"
25#include "cx18-scb.h" 26#include "cx18-scb.h"
26#include "cx18-irq.h" 27#include "cx18-irq.h"
27#include "cx18-mailbox.h" 28#include "cx18-mailbox.h"
@@ -82,6 +83,7 @@ static const struct cx18_api_info api_info[] = {
82 API_ENTRY(CPU, CX18_CPU_DE_SET_MDL_ACK, 0), 83 API_ENTRY(CPU, CX18_CPU_DE_SET_MDL_ACK, 0),
83 API_ENTRY(CPU, CX18_CPU_DE_SET_MDL, API_FAST), 84 API_ENTRY(CPU, CX18_CPU_DE_SET_MDL, API_FAST),
84 API_ENTRY(CPU, CX18_APU_RESETAI, API_FAST), 85 API_ENTRY(CPU, CX18_APU_RESETAI, API_FAST),
86 API_ENTRY(CPU, CX18_CPU_DE_RELEASE_MDL, 0),
85 API_ENTRY(0, 0, 0), 87 API_ENTRY(0, 0, 0),
86}; 88};
87 89
@@ -105,20 +107,20 @@ static struct cx18_mailbox __iomem *cx18_mb_is_complete(struct cx18 *cx, int rpu
105 switch (rpu) { 107 switch (rpu) {
106 case APU: 108 case APU:
107 mb = &cx->scb->epu2apu_mb; 109 mb = &cx->scb->epu2apu_mb;
108 *state = readl(&cx->scb->apu_state); 110 *state = cx18_readl(cx, &cx->scb->apu_state);
109 *irq = readl(&cx->scb->epu2apu_irq); 111 *irq = cx18_readl(cx, &cx->scb->epu2apu_irq);
110 break; 112 break;
111 113
112 case CPU: 114 case CPU:
113 mb = &cx->scb->epu2cpu_mb; 115 mb = &cx->scb->epu2cpu_mb;
114 *state = readl(&cx->scb->cpu_state); 116 *state = cx18_readl(cx, &cx->scb->cpu_state);
115 *irq = readl(&cx->scb->epu2cpu_irq); 117 *irq = cx18_readl(cx, &cx->scb->epu2cpu_irq);
116 break; 118 break;
117 119
118 case HPU: 120 case HPU:
119 mb = &cx->scb->epu2hpu_mb; 121 mb = &cx->scb->epu2hpu_mb;
120 *state = readl(&cx->scb->hpu_state); 122 *state = cx18_readl(cx, &cx->scb->hpu_state);
121 *irq = readl(&cx->scb->epu2hpu_irq); 123 *irq = cx18_readl(cx, &cx->scb->epu2hpu_irq);
122 break; 124 break;
123 } 125 }
124 126
@@ -126,8 +128,8 @@ static struct cx18_mailbox __iomem *cx18_mb_is_complete(struct cx18 *cx, int rpu
126 return mb; 128 return mb;
127 129
128 do { 130 do {
129 *req = readl(&mb->request); 131 *req = cx18_readl(cx, &mb->request);
130 ack = readl(&mb->ack); 132 ack = cx18_readl(cx, &mb->ack);
131 wait_count++; 133 wait_count++;
132 } while (*req != ack && wait_count < 600); 134 } while (*req != ack && wait_count < 600);
133 135
@@ -172,9 +174,9 @@ long cx18_mb_ack(struct cx18 *cx, const struct cx18_mailbox *mb)
172 return -EINVAL; 174 return -EINVAL;
173 } 175 }
174 176
175 setup_page(SCB_OFFSET); 177 cx18_setup_page(cx, SCB_OFFSET);
176 write_sync(mb->request, &ack_mb->ack); 178 cx18_write_sync(cx, mb->request, &ack_mb->ack);
177 write_reg(ack_irq, SW2_INT_SET); 179 cx18_write_reg(cx, ack_irq, SW2_INT_SET);
178 return 0; 180 return 0;
179} 181}
180 182
@@ -199,7 +201,7 @@ static int cx18_api_call(struct cx18 *cx, u32 cmd, int args, u32 data[])
199 CX18_DEBUG_HI_API("%s\n", info->name); 201 CX18_DEBUG_HI_API("%s\n", info->name);
200 else 202 else
201 CX18_DEBUG_API("%s\n", info->name); 203 CX18_DEBUG_API("%s\n", info->name);
202 setup_page(SCB_OFFSET); 204 cx18_setup_page(cx, SCB_OFFSET);
203 mb = cx18_mb_is_complete(cx, info->rpu, &state, &irq, &req); 205 mb = cx18_mb_is_complete(cx, info->rpu, &state, &irq, &req);
204 206
205 if (mb == NULL) { 207 if (mb == NULL) {
@@ -208,11 +210,11 @@ static int cx18_api_call(struct cx18 *cx, u32 cmd, int args, u32 data[])
208 } 210 }
209 211
210 oldreq = req - 1; 212 oldreq = req - 1;
211 writel(cmd, &mb->cmd); 213 cx18_writel(cx, cmd, &mb->cmd);
212 for (i = 0; i < args; i++) 214 for (i = 0; i < args; i++)
213 writel(data[i], &mb->args[i]); 215 cx18_writel(cx, data[i], &mb->args[i]);
214 writel(0, &mb->error); 216 cx18_writel(cx, 0, &mb->error);
215 writel(req, &mb->request); 217 cx18_writel(cx, req, &mb->request);
216 218
217 switch (info->rpu) { 219 switch (info->rpu) {
218 case APU: waitq = &cx->mb_apu_waitq; break; 220 case APU: waitq = &cx->mb_apu_waitq; break;
@@ -223,9 +225,10 @@ static int cx18_api_call(struct cx18 *cx, u32 cmd, int args, u32 data[])
223 } 225 }
224 if (info->flags & API_FAST) 226 if (info->flags & API_FAST)
225 timeout /= 2; 227 timeout /= 2;
226 write_reg(irq, SW1_INT_SET); 228 cx18_write_reg(cx, irq, SW1_INT_SET);
227 229
228 while (!sig && readl(&mb->ack) != readl(&mb->request) && cnt < 660) { 230 while (!sig && cx18_readl(cx, &mb->ack) != cx18_readl(cx, &mb->request)
231 && cnt < 660) {
229 if (cnt > 200 && !in_atomic()) 232 if (cnt > 200 && !in_atomic())
230 sig = cx18_msleep_timeout(10, 1); 233 sig = cx18_msleep_timeout(10, 1);
231 cnt++; 234 cnt++;
@@ -233,13 +236,13 @@ static int cx18_api_call(struct cx18 *cx, u32 cmd, int args, u32 data[])
233 if (sig) 236 if (sig)
234 return -EINTR; 237 return -EINTR;
235 if (cnt == 660) { 238 if (cnt == 660) {
236 writel(oldreq, &mb->request); 239 cx18_writel(cx, oldreq, &mb->request);
237 CX18_ERR("mb %s failed\n", info->name); 240 CX18_ERR("mb %s failed\n", info->name);
238 return -EINVAL; 241 return -EINVAL;
239 } 242 }
240 for (i = 0; i < MAX_MB_ARGUMENTS; i++) 243 for (i = 0; i < MAX_MB_ARGUMENTS; i++)
241 data[i] = readl(&mb->args[i]); 244 data[i] = cx18_readl(cx, &mb->args[i]);
242 err = readl(&mb->error); 245 err = cx18_readl(cx, &mb->error);
243 if (!in_atomic() && (info->flags & API_SLOW)) 246 if (!in_atomic() && (info->flags & API_SLOW))
244 cx18_msleep_timeout(300, 0); 247 cx18_msleep_timeout(300, 0);
245 if (err) 248 if (err)
diff --git a/drivers/media/video/cx18/cx18-queue.c b/drivers/media/video/cx18/cx18-queue.c
index dbe792ac3001..a33ba04a2686 100644
--- a/drivers/media/video/cx18/cx18-queue.c
+++ b/drivers/media/video/cx18/cx18-queue.c
@@ -37,8 +37,7 @@ void cx18_buf_swap(struct cx18_buffer *buf)
37void cx18_queue_init(struct cx18_queue *q) 37void cx18_queue_init(struct cx18_queue *q)
38{ 38{
39 INIT_LIST_HEAD(&q->list); 39 INIT_LIST_HEAD(&q->list);
40 q->buffers = 0; 40 atomic_set(&q->buffers, 0);
41 q->length = 0;
42 q->bytesused = 0; 41 q->bytesused = 0;
43} 42}
44 43
@@ -55,8 +54,7 @@ void cx18_enqueue(struct cx18_stream *s, struct cx18_buffer *buf,
55 } 54 }
56 spin_lock_irqsave(&s->qlock, flags); 55 spin_lock_irqsave(&s->qlock, flags);
57 list_add_tail(&buf->list, &q->list); 56 list_add_tail(&buf->list, &q->list);
58 q->buffers++; 57 atomic_inc(&q->buffers);
59 q->length += s->buf_size;
60 q->bytesused += buf->bytesused - buf->readpos; 58 q->bytesused += buf->bytesused - buf->readpos;
61 spin_unlock_irqrestore(&s->qlock, flags); 59 spin_unlock_irqrestore(&s->qlock, flags);
62} 60}
@@ -70,8 +68,7 @@ struct cx18_buffer *cx18_dequeue(struct cx18_stream *s, struct cx18_queue *q)
70 if (!list_empty(&q->list)) { 68 if (!list_empty(&q->list)) {
71 buf = list_entry(q->list.next, struct cx18_buffer, list); 69 buf = list_entry(q->list.next, struct cx18_buffer, list);
72 list_del_init(q->list.next); 70 list_del_init(q->list.next);
73 q->buffers--; 71 atomic_dec(&q->buffers);
74 q->length -= s->buf_size;
75 q->bytesused -= buf->bytesused - buf->readpos; 72 q->bytesused -= buf->bytesused - buf->readpos;
76 } 73 }
77 spin_unlock_irqrestore(&s->qlock, flags); 74 spin_unlock_irqrestore(&s->qlock, flags);
@@ -95,10 +92,8 @@ struct cx18_buffer *cx18_queue_get_buf_irq(struct cx18_stream *s, u32 id,
95 /* the transport buffers are handled differently, 92 /* the transport buffers are handled differently,
96 they are not moved to the full queue */ 93 they are not moved to the full queue */
97 if (s->type != CX18_ENC_STREAM_TYPE_TS) { 94 if (s->type != CX18_ENC_STREAM_TYPE_TS) {
98 s->q_free.buffers--; 95 atomic_dec(&s->q_free.buffers);
99 s->q_free.length -= s->buf_size; 96 atomic_inc(&s->q_full.buffers);
100 s->q_full.buffers++;
101 s->q_full.length += s->buf_size;
102 s->q_full.bytesused += buf->bytesused; 97 s->q_full.bytesused += buf->bytesused;
103 list_move_tail(&buf->list, &s->q_full.list); 98 list_move_tail(&buf->list, &s->q_full.list);
104 } 99 }
@@ -124,8 +119,7 @@ static void cx18_queue_flush(struct cx18_stream *s, struct cx18_queue *q)
124 buf = list_entry(q->list.next, struct cx18_buffer, list); 119 buf = list_entry(q->list.next, struct cx18_buffer, list);
125 list_move_tail(q->list.next, &s->q_free.list); 120 list_move_tail(q->list.next, &s->q_free.list);
126 buf->bytesused = buf->readpos = buf->b_flags = 0; 121 buf->bytesused = buf->readpos = buf->b_flags = 0;
127 s->q_free.buffers++; 122 atomic_inc(&s->q_free.buffers);
128 s->q_free.length += s->buf_size;
129 } 123 }
130 cx18_queue_init(q); 124 cx18_queue_init(q);
131 spin_unlock_irqrestore(&s->qlock, flags); 125 spin_unlock_irqrestore(&s->qlock, flags);
diff --git a/drivers/media/video/cx18/cx18-scb.c b/drivers/media/video/cx18/cx18-scb.c
index 30bc803e30da..f56d3772aa67 100644
--- a/drivers/media/video/cx18/cx18-scb.c
+++ b/drivers/media/video/cx18/cx18-scb.c
@@ -20,102 +20,103 @@
20 */ 20 */
21 21
22#include "cx18-driver.h" 22#include "cx18-driver.h"
23#include "cx18-io.h"
23#include "cx18-scb.h" 24#include "cx18-scb.h"
24 25
25void cx18_init_scb(struct cx18 *cx) 26void cx18_init_scb(struct cx18 *cx)
26{ 27{
27 setup_page(SCB_OFFSET); 28 cx18_setup_page(cx, SCB_OFFSET);
28 memset_io(cx->scb, 0, 0x10000); 29 cx18_memset_io(cx, cx->scb, 0, 0x10000);
29 30
30 writel(IRQ_APU_TO_CPU, &cx->scb->apu2cpu_irq); 31 cx18_writel(cx, IRQ_APU_TO_CPU, &cx->scb->apu2cpu_irq);
31 writel(IRQ_CPU_TO_APU_ACK, &cx->scb->cpu2apu_irq_ack); 32 cx18_writel(cx, IRQ_CPU_TO_APU_ACK, &cx->scb->cpu2apu_irq_ack);
32 writel(IRQ_HPU_TO_CPU, &cx->scb->hpu2cpu_irq); 33 cx18_writel(cx, IRQ_HPU_TO_CPU, &cx->scb->hpu2cpu_irq);
33 writel(IRQ_CPU_TO_HPU_ACK, &cx->scb->cpu2hpu_irq_ack); 34 cx18_writel(cx, IRQ_CPU_TO_HPU_ACK, &cx->scb->cpu2hpu_irq_ack);
34 writel(IRQ_PPU_TO_CPU, &cx->scb->ppu2cpu_irq); 35 cx18_writel(cx, IRQ_PPU_TO_CPU, &cx->scb->ppu2cpu_irq);
35 writel(IRQ_CPU_TO_PPU_ACK, &cx->scb->cpu2ppu_irq_ack); 36 cx18_writel(cx, IRQ_CPU_TO_PPU_ACK, &cx->scb->cpu2ppu_irq_ack);
36 writel(IRQ_EPU_TO_CPU, &cx->scb->epu2cpu_irq); 37 cx18_writel(cx, IRQ_EPU_TO_CPU, &cx->scb->epu2cpu_irq);
37 writel(IRQ_CPU_TO_EPU_ACK, &cx->scb->cpu2epu_irq_ack); 38 cx18_writel(cx, IRQ_CPU_TO_EPU_ACK, &cx->scb->cpu2epu_irq_ack);
38 39
39 writel(IRQ_CPU_TO_APU, &cx->scb->cpu2apu_irq); 40 cx18_writel(cx, IRQ_CPU_TO_APU, &cx->scb->cpu2apu_irq);
40 writel(IRQ_APU_TO_CPU_ACK, &cx->scb->apu2cpu_irq_ack); 41 cx18_writel(cx, IRQ_APU_TO_CPU_ACK, &cx->scb->apu2cpu_irq_ack);
41 writel(IRQ_HPU_TO_APU, &cx->scb->hpu2apu_irq); 42 cx18_writel(cx, IRQ_HPU_TO_APU, &cx->scb->hpu2apu_irq);
42 writel(IRQ_APU_TO_HPU_ACK, &cx->scb->apu2hpu_irq_ack); 43 cx18_writel(cx, IRQ_APU_TO_HPU_ACK, &cx->scb->apu2hpu_irq_ack);
43 writel(IRQ_PPU_TO_APU, &cx->scb->ppu2apu_irq); 44 cx18_writel(cx, IRQ_PPU_TO_APU, &cx->scb->ppu2apu_irq);
44 writel(IRQ_APU_TO_PPU_ACK, &cx->scb->apu2ppu_irq_ack); 45 cx18_writel(cx, IRQ_APU_TO_PPU_ACK, &cx->scb->apu2ppu_irq_ack);
45 writel(IRQ_EPU_TO_APU, &cx->scb->epu2apu_irq); 46 cx18_writel(cx, IRQ_EPU_TO_APU, &cx->scb->epu2apu_irq);
46 writel(IRQ_APU_TO_EPU_ACK, &cx->scb->apu2epu_irq_ack); 47 cx18_writel(cx, IRQ_APU_TO_EPU_ACK, &cx->scb->apu2epu_irq_ack);
47 48
48 writel(IRQ_CPU_TO_HPU, &cx->scb->cpu2hpu_irq); 49 cx18_writel(cx, IRQ_CPU_TO_HPU, &cx->scb->cpu2hpu_irq);
49 writel(IRQ_HPU_TO_CPU_ACK, &cx->scb->hpu2cpu_irq_ack); 50 cx18_writel(cx, IRQ_HPU_TO_CPU_ACK, &cx->scb->hpu2cpu_irq_ack);
50 writel(IRQ_APU_TO_HPU, &cx->scb->apu2hpu_irq); 51 cx18_writel(cx, IRQ_APU_TO_HPU, &cx->scb->apu2hpu_irq);
51 writel(IRQ_HPU_TO_APU_ACK, &cx->scb->hpu2apu_irq_ack); 52 cx18_writel(cx, IRQ_HPU_TO_APU_ACK, &cx->scb->hpu2apu_irq_ack);
52 writel(IRQ_PPU_TO_HPU, &cx->scb->ppu2hpu_irq); 53 cx18_writel(cx, IRQ_PPU_TO_HPU, &cx->scb->ppu2hpu_irq);
53 writel(IRQ_HPU_TO_PPU_ACK, &cx->scb->hpu2ppu_irq_ack); 54 cx18_writel(cx, IRQ_HPU_TO_PPU_ACK, &cx->scb->hpu2ppu_irq_ack);
54 writel(IRQ_EPU_TO_HPU, &cx->scb->epu2hpu_irq); 55 cx18_writel(cx, IRQ_EPU_TO_HPU, &cx->scb->epu2hpu_irq);
55 writel(IRQ_HPU_TO_EPU_ACK, &cx->scb->hpu2epu_irq_ack); 56 cx18_writel(cx, IRQ_HPU_TO_EPU_ACK, &cx->scb->hpu2epu_irq_ack);
56 57
57 writel(IRQ_CPU_TO_PPU, &cx->scb->cpu2ppu_irq); 58 cx18_writel(cx, IRQ_CPU_TO_PPU, &cx->scb->cpu2ppu_irq);
58 writel(IRQ_PPU_TO_CPU_ACK, &cx->scb->ppu2cpu_irq_ack); 59 cx18_writel(cx, IRQ_PPU_TO_CPU_ACK, &cx->scb->ppu2cpu_irq_ack);
59 writel(IRQ_APU_TO_PPU, &cx->scb->apu2ppu_irq); 60 cx18_writel(cx, IRQ_APU_TO_PPU, &cx->scb->apu2ppu_irq);
60 writel(IRQ_PPU_TO_APU_ACK, &cx->scb->ppu2apu_irq_ack); 61 cx18_writel(cx, IRQ_PPU_TO_APU_ACK, &cx->scb->ppu2apu_irq_ack);
61 writel(IRQ_HPU_TO_PPU, &cx->scb->hpu2ppu_irq); 62 cx18_writel(cx, IRQ_HPU_TO_PPU, &cx->scb->hpu2ppu_irq);
62 writel(IRQ_PPU_TO_HPU_ACK, &cx->scb->ppu2hpu_irq_ack); 63 cx18_writel(cx, IRQ_PPU_TO_HPU_ACK, &cx->scb->ppu2hpu_irq_ack);
63 writel(IRQ_EPU_TO_PPU, &cx->scb->epu2ppu_irq); 64 cx18_writel(cx, IRQ_EPU_TO_PPU, &cx->scb->epu2ppu_irq);
64 writel(IRQ_PPU_TO_EPU_ACK, &cx->scb->ppu2epu_irq_ack); 65 cx18_writel(cx, IRQ_PPU_TO_EPU_ACK, &cx->scb->ppu2epu_irq_ack);
65 66
66 writel(IRQ_CPU_TO_EPU, &cx->scb->cpu2epu_irq); 67 cx18_writel(cx, IRQ_CPU_TO_EPU, &cx->scb->cpu2epu_irq);
67 writel(IRQ_EPU_TO_CPU_ACK, &cx->scb->epu2cpu_irq_ack); 68 cx18_writel(cx, IRQ_EPU_TO_CPU_ACK, &cx->scb->epu2cpu_irq_ack);
68 writel(IRQ_APU_TO_EPU, &cx->scb->apu2epu_irq); 69 cx18_writel(cx, IRQ_APU_TO_EPU, &cx->scb->apu2epu_irq);
69 writel(IRQ_EPU_TO_APU_ACK, &cx->scb->epu2apu_irq_ack); 70 cx18_writel(cx, IRQ_EPU_TO_APU_ACK, &cx->scb->epu2apu_irq_ack);
70 writel(IRQ_HPU_TO_EPU, &cx->scb->hpu2epu_irq); 71 cx18_writel(cx, IRQ_HPU_TO_EPU, &cx->scb->hpu2epu_irq);
71 writel(IRQ_EPU_TO_HPU_ACK, &cx->scb->epu2hpu_irq_ack); 72 cx18_writel(cx, IRQ_EPU_TO_HPU_ACK, &cx->scb->epu2hpu_irq_ack);
72 writel(IRQ_PPU_TO_EPU, &cx->scb->ppu2epu_irq); 73 cx18_writel(cx, IRQ_PPU_TO_EPU, &cx->scb->ppu2epu_irq);
73 writel(IRQ_EPU_TO_PPU_ACK, &cx->scb->epu2ppu_irq_ack); 74 cx18_writel(cx, IRQ_EPU_TO_PPU_ACK, &cx->scb->epu2ppu_irq_ack);
74 75
75 writel(SCB_OFFSET + offsetof(struct cx18_scb, apu2cpu_mb), 76 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, apu2cpu_mb),
76 &cx->scb->apu2cpu_mb_offset); 77 &cx->scb->apu2cpu_mb_offset);
77 writel(SCB_OFFSET + offsetof(struct cx18_scb, hpu2cpu_mb), 78 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, hpu2cpu_mb),
78 &cx->scb->hpu2cpu_mb_offset); 79 &cx->scb->hpu2cpu_mb_offset);
79 writel(SCB_OFFSET + offsetof(struct cx18_scb, ppu2cpu_mb), 80 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, ppu2cpu_mb),
80 &cx->scb->ppu2cpu_mb_offset); 81 &cx->scb->ppu2cpu_mb_offset);
81 writel(SCB_OFFSET + offsetof(struct cx18_scb, epu2cpu_mb), 82 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, epu2cpu_mb),
82 &cx->scb->epu2cpu_mb_offset); 83 &cx->scb->epu2cpu_mb_offset);
83 writel(SCB_OFFSET + offsetof(struct cx18_scb, cpu2apu_mb), 84 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, cpu2apu_mb),
84 &cx->scb->cpu2apu_mb_offset); 85 &cx->scb->cpu2apu_mb_offset);
85 writel(SCB_OFFSET + offsetof(struct cx18_scb, hpu2apu_mb), 86 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, hpu2apu_mb),
86 &cx->scb->hpu2apu_mb_offset); 87 &cx->scb->hpu2apu_mb_offset);
87 writel(SCB_OFFSET + offsetof(struct cx18_scb, ppu2apu_mb), 88 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, ppu2apu_mb),
88 &cx->scb->ppu2apu_mb_offset); 89 &cx->scb->ppu2apu_mb_offset);
89 writel(SCB_OFFSET + offsetof(struct cx18_scb, epu2apu_mb), 90 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, epu2apu_mb),
90 &cx->scb->epu2apu_mb_offset); 91 &cx->scb->epu2apu_mb_offset);
91 writel(SCB_OFFSET + offsetof(struct cx18_scb, cpu2hpu_mb), 92 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, cpu2hpu_mb),
92 &cx->scb->cpu2hpu_mb_offset); 93 &cx->scb->cpu2hpu_mb_offset);
93 writel(SCB_OFFSET + offsetof(struct cx18_scb, apu2hpu_mb), 94 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, apu2hpu_mb),
94 &cx->scb->apu2hpu_mb_offset); 95 &cx->scb->apu2hpu_mb_offset);
95 writel(SCB_OFFSET + offsetof(struct cx18_scb, ppu2hpu_mb), 96 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, ppu2hpu_mb),
96 &cx->scb->ppu2hpu_mb_offset); 97 &cx->scb->ppu2hpu_mb_offset);
97 writel(SCB_OFFSET + offsetof(struct cx18_scb, epu2hpu_mb), 98 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, epu2hpu_mb),
98 &cx->scb->epu2hpu_mb_offset); 99 &cx->scb->epu2hpu_mb_offset);
99 writel(SCB_OFFSET + offsetof(struct cx18_scb, cpu2ppu_mb), 100 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, cpu2ppu_mb),
100 &cx->scb->cpu2ppu_mb_offset); 101 &cx->scb->cpu2ppu_mb_offset);
101 writel(SCB_OFFSET + offsetof(struct cx18_scb, apu2ppu_mb), 102 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, apu2ppu_mb),
102 &cx->scb->apu2ppu_mb_offset); 103 &cx->scb->apu2ppu_mb_offset);
103 writel(SCB_OFFSET + offsetof(struct cx18_scb, hpu2ppu_mb), 104 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, hpu2ppu_mb),
104 &cx->scb->hpu2ppu_mb_offset); 105 &cx->scb->hpu2ppu_mb_offset);
105 writel(SCB_OFFSET + offsetof(struct cx18_scb, epu2ppu_mb), 106 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, epu2ppu_mb),
106 &cx->scb->epu2ppu_mb_offset); 107 &cx->scb->epu2ppu_mb_offset);
107 writel(SCB_OFFSET + offsetof(struct cx18_scb, cpu2epu_mb), 108 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, cpu2epu_mb),
108 &cx->scb->cpu2epu_mb_offset); 109 &cx->scb->cpu2epu_mb_offset);
109 writel(SCB_OFFSET + offsetof(struct cx18_scb, apu2epu_mb), 110 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, apu2epu_mb),
110 &cx->scb->apu2epu_mb_offset); 111 &cx->scb->apu2epu_mb_offset);
111 writel(SCB_OFFSET + offsetof(struct cx18_scb, hpu2epu_mb), 112 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, hpu2epu_mb),
112 &cx->scb->hpu2epu_mb_offset); 113 &cx->scb->hpu2epu_mb_offset);
113 writel(SCB_OFFSET + offsetof(struct cx18_scb, ppu2epu_mb), 114 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, ppu2epu_mb),
114 &cx->scb->ppu2epu_mb_offset); 115 &cx->scb->ppu2epu_mb_offset);
115 116
116 writel(SCB_OFFSET + offsetof(struct cx18_scb, cpu_state), 117 cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, cpu_state),
117 &cx->scb->ipc_offset); 118 &cx->scb->ipc_offset);
118 119
119 writel(1, &cx->scb->hpu_state); 120 cx18_writel(cx, 1, &cx->scb->hpu_state);
120 writel(1, &cx->scb->epu_state); 121 cx18_writel(cx, 1, &cx->scb->epu_state);
121} 122}
diff --git a/drivers/media/video/cx18/cx18-streams.c b/drivers/media/video/cx18/cx18-streams.c
index 0da57f583bf7..0c8e7542cf60 100644
--- a/drivers/media/video/cx18/cx18-streams.c
+++ b/drivers/media/video/cx18/cx18-streams.c
@@ -22,6 +22,7 @@
22 */ 22 */
23 23
24#include "cx18-driver.h" 24#include "cx18-driver.h"
25#include "cx18-io.h"
25#include "cx18-fileops.h" 26#include "cx18-fileops.h"
26#include "cx18-mailbox.h" 27#include "cx18-mailbox.h"
27#include "cx18-i2c.h" 28#include "cx18-i2c.h"
@@ -56,7 +57,7 @@ static struct file_operations cx18_v4l2_enc_fops = {
56static struct { 57static struct {
57 const char *name; 58 const char *name;
58 int vfl_type; 59 int vfl_type;
59 int minor_offset; 60 int num_offset;
60 int dma; 61 int dma;
61 enum v4l2_buf_type buf_type; 62 enum v4l2_buf_type buf_type;
62 struct file_operations *fops; 63 struct file_operations *fops;
@@ -119,7 +120,7 @@ static void cx18_stream_init(struct cx18 *cx, int type)
119 s->cx = cx; 120 s->cx = cx;
120 s->type = type; 121 s->type = type;
121 s->name = cx18_stream_info[type].name; 122 s->name = cx18_stream_info[type].name;
122 s->handle = 0xffffffff; 123 s->handle = CX18_INVALID_TASK_HANDLE;
123 124
124 s->dma = cx18_stream_info[type].dma; 125 s->dma = cx18_stream_info[type].dma;
125 s->buf_size = cx->stream_buf_size[type]; 126 s->buf_size = cx->stream_buf_size[type];
@@ -143,8 +144,8 @@ static int cx18_prep_dev(struct cx18 *cx, int type)
143{ 144{
144 struct cx18_stream *s = &cx->streams[type]; 145 struct cx18_stream *s = &cx->streams[type];
145 u32 cap = cx->v4l2_cap; 146 u32 cap = cx->v4l2_cap;
146 int minor_offset = cx18_stream_info[type].minor_offset; 147 int num_offset = cx18_stream_info[type].num_offset;
147 int minor; 148 int num = cx->num + cx18_first_minor + num_offset;
148 149
149 /* These four fields are always initialized. If v4l2dev == NULL, then 150 /* These four fields are always initialized. If v4l2dev == NULL, then
150 this stream is not in use. In that case no other fields but these 151 this stream is not in use. In that case no other fields but these
@@ -163,9 +164,6 @@ static int cx18_prep_dev(struct cx18 *cx, int type)
163 !(cap & (V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_CAPTURE))) 164 !(cap & (V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_CAPTURE)))
164 return 0; 165 return 0;
165 166
166 /* card number + user defined offset + device offset */
167 minor = cx->num + cx18_first_minor + minor_offset;
168
169 /* User explicitly selected 0 buffers for these streams, so don't 167 /* User explicitly selected 0 buffers for these streams, so don't
170 create them. */ 168 create them. */
171 if (cx18_stream_info[type].dma != PCI_DMA_NONE && 169 if (cx18_stream_info[type].dma != PCI_DMA_NONE &&
@@ -176,7 +174,7 @@ static int cx18_prep_dev(struct cx18 *cx, int type)
176 174
177 cx18_stream_init(cx, type); 175 cx18_stream_init(cx, type);
178 176
179 if (minor_offset == -1) 177 if (num_offset == -1)
180 return 0; 178 return 0;
181 179
182 /* allocate and initialize the v4l2 video device structure */ 180 /* allocate and initialize the v4l2 video device structure */
@@ -190,7 +188,7 @@ static int cx18_prep_dev(struct cx18 *cx, int type)
190 snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "cx18-%d", 188 snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "cx18-%d",
191 cx->num); 189 cx->num);
192 190
193 s->v4l2dev->minor = minor; 191 s->v4l2dev->num = num;
194 s->v4l2dev->parent = &cx->dev->dev; 192 s->v4l2dev->parent = &cx->dev->dev;
195 s->v4l2dev->fops = cx18_stream_info[type].fops; 193 s->v4l2dev->fops = cx18_stream_info[type].fops;
196 s->v4l2dev->release = video_device_release; 194 s->v4l2dev->release = video_device_release;
@@ -226,7 +224,7 @@ static int cx18_reg_dev(struct cx18 *cx, int type)
226{ 224{
227 struct cx18_stream *s = &cx->streams[type]; 225 struct cx18_stream *s = &cx->streams[type];
228 int vfl_type = cx18_stream_info[type].vfl_type; 226 int vfl_type = cx18_stream_info[type].vfl_type;
229 int minor; 227 int num;
230 228
231 /* TODO: Shouldn't this be a VFL_TYPE_TRANSPORT or something? 229 /* TODO: Shouldn't this be a VFL_TYPE_TRANSPORT or something?
232 * We need a VFL_TYPE_TS defined. 230 * We need a VFL_TYPE_TS defined.
@@ -244,38 +242,44 @@ static int cx18_reg_dev(struct cx18 *cx, int type)
244 if (s->v4l2dev == NULL) 242 if (s->v4l2dev == NULL)
245 return 0; 243 return 0;
246 244
247 minor = s->v4l2dev->minor; 245 num = s->v4l2dev->num;
246 /* card number + user defined offset + device offset */
247 if (type != CX18_ENC_STREAM_TYPE_MPG) {
248 struct cx18_stream *s_mpg = &cx->streams[CX18_ENC_STREAM_TYPE_MPG];
249
250 if (s_mpg->v4l2dev)
251 num = s_mpg->v4l2dev->num + cx18_stream_info[type].num_offset;
252 }
248 253
249 /* Register device. First try the desired minor, then any free one. */ 254 /* Register device. First try the desired minor, then any free one. */
250 if (video_register_device(s->v4l2dev, vfl_type, minor) && 255 if (video_register_device(s->v4l2dev, vfl_type, num)) {
251 video_register_device(s->v4l2dev, vfl_type, -1)) { 256 CX18_ERR("Couldn't register v4l2 device for %s kernel number %d\n",
252 CX18_ERR("Couldn't register v4l2 device for %s minor %d\n", 257 s->name, num);
253 s->name, minor);
254 video_device_release(s->v4l2dev); 258 video_device_release(s->v4l2dev);
255 s->v4l2dev = NULL; 259 s->v4l2dev = NULL;
256 return -ENOMEM; 260 return -ENOMEM;
257 } 261 }
258 minor = s->v4l2dev->minor; 262 num = s->v4l2dev->num;
259 263
260 switch (vfl_type) { 264 switch (vfl_type) {
261 case VFL_TYPE_GRABBER: 265 case VFL_TYPE_GRABBER:
262 CX18_INFO("Registered device video%d for %s (%d MB)\n", 266 CX18_INFO("Registered device video%d for %s (%d MB)\n",
263 minor, s->name, cx->options.megabytes[type]); 267 num, s->name, cx->options.megabytes[type]);
264 break; 268 break;
265 269
266 case VFL_TYPE_RADIO: 270 case VFL_TYPE_RADIO:
267 CX18_INFO("Registered device radio%d for %s\n", 271 CX18_INFO("Registered device radio%d for %s\n",
268 minor - MINOR_VFL_TYPE_RADIO_MIN, s->name); 272 num, s->name);
269 break; 273 break;
270 274
271 case VFL_TYPE_VBI: 275 case VFL_TYPE_VBI:
272 if (cx->options.megabytes[type]) 276 if (cx->options.megabytes[type])
273 CX18_INFO("Registered device vbi%d for %s (%d MB)\n", 277 CX18_INFO("Registered device vbi%d for %s (%d MB)\n",
274 minor - MINOR_VFL_TYPE_VBI_MIN, 278 num,
275 s->name, cx->options.megabytes[type]); 279 s->name, cx->options.megabytes[type]);
276 else 280 else
277 CX18_INFO("Registered device vbi%d for %s\n", 281 CX18_INFO("Registered device vbi%d for %s\n",
278 minor - MINOR_VFL_TYPE_VBI_MIN, s->name); 282 num, s->name);
279 break; 283 break;
280 } 284 }
281 285
@@ -432,7 +436,6 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
432 default: 436 default:
433 return -EINVAL; 437 return -EINVAL;
434 } 438 }
435 s->buffers_stolen = 0;
436 439
437 /* mute/unmute video */ 440 /* mute/unmute video */
438 cx18_vapi(cx, CX18_CPU_SET_VIDEO_MUTE, 2, 441 cx18_vapi(cx, CX18_CPU_SET_VIDEO_MUTE, 2,
@@ -470,7 +473,7 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
470 473
471 if (atomic_read(&cx->tot_capturing) == 0) { 474 if (atomic_read(&cx->tot_capturing) == 0) {
472 clear_bit(CX18_F_I_EOS, &cx->i_flags); 475 clear_bit(CX18_F_I_EOS, &cx->i_flags);
473 write_reg(7, CX18_DSP0_INTERRUPT_MASK); 476 cx18_write_reg(cx, 7, CX18_DSP0_INTERRUPT_MASK);
474 } 477 }
475 478
476 cx18_vapi(cx, CX18_CPU_DE_SET_MDL_ACK, 3, s->handle, 479 cx18_vapi(cx, CX18_CPU_DE_SET_MDL_ACK, 3, s->handle,
@@ -480,8 +483,9 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
480 list_for_each(p, &s->q_free.list) { 483 list_for_each(p, &s->q_free.list) {
481 struct cx18_buffer *buf = list_entry(p, struct cx18_buffer, list); 484 struct cx18_buffer *buf = list_entry(p, struct cx18_buffer, list);
482 485
483 writel(buf->dma_handle, &cx->scb->cpu_mdl[buf->id].paddr); 486 cx18_writel(cx, buf->dma_handle,
484 writel(s->buf_size, &cx->scb->cpu_mdl[buf->id].length); 487 &cx->scb->cpu_mdl[buf->id].paddr);
488 cx18_writel(cx, s->buf_size, &cx->scb->cpu_mdl[buf->id].length);
485 cx18_vapi(cx, CX18_CPU_DE_SET_MDL, 5, s->handle, 489 cx18_vapi(cx, CX18_CPU_DE_SET_MDL, 5, s->handle,
486 (void __iomem *)&cx->scb->cpu_mdl[buf->id] - cx->enc_mem, 490 (void __iomem *)&cx->scb->cpu_mdl[buf->id] - cx->enc_mem,
487 1, buf->id, s->buf_size); 491 1, buf->id, s->buf_size);
@@ -489,7 +493,14 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
489 /* begin_capture */ 493 /* begin_capture */
490 if (cx18_vapi(cx, CX18_CPU_CAPTURE_START, 1, s->handle)) { 494 if (cx18_vapi(cx, CX18_CPU_CAPTURE_START, 1, s->handle)) {
491 CX18_DEBUG_WARN("Error starting capture!\n"); 495 CX18_DEBUG_WARN("Error starting capture!\n");
496 /* Ensure we're really not capturing before releasing MDLs */
497 if (s->type == CX18_ENC_STREAM_TYPE_MPG)
498 cx18_vapi(cx, CX18_CPU_CAPTURE_STOP, 2, s->handle, 1);
499 else
500 cx18_vapi(cx, CX18_CPU_CAPTURE_STOP, 1, s->handle);
501 cx18_vapi(cx, CX18_CPU_DE_RELEASE_MDL, 1, s->handle);
492 cx18_vapi(cx, CX18_DESTROY_TASK, 1, s->handle); 502 cx18_vapi(cx, CX18_DESTROY_TASK, 1, s->handle);
503 /* FIXME - clean-up DSP0_INT mask, i_flags, s_flags, etc. */
493 return -EINVAL; 504 return -EINVAL;
494 } 505 }
495 506
@@ -541,6 +552,9 @@ int cx18_stop_v4l2_encode_stream(struct cx18_stream *s, int gop_end)
541 CX18_INFO("ignoring gop_end: not (yet?) supported by the firmware\n"); 552 CX18_INFO("ignoring gop_end: not (yet?) supported by the firmware\n");
542 } 553 }
543 554
555 /* Tell the CX23418 it can't use our buffers anymore */
556 cx18_vapi(cx, CX18_CPU_DE_RELEASE_MDL, 1, s->handle);
557
544 if (s->type != CX18_ENC_STREAM_TYPE_TS) 558 if (s->type != CX18_ENC_STREAM_TYPE_TS)
545 atomic_dec(&cx->ana_capturing); 559 atomic_dec(&cx->ana_capturing);
546 atomic_dec(&cx->tot_capturing); 560 atomic_dec(&cx->tot_capturing);
@@ -549,12 +563,12 @@ int cx18_stop_v4l2_encode_stream(struct cx18_stream *s, int gop_end)
549 clear_bit(CX18_F_S_STREAMING, &s->s_flags); 563 clear_bit(CX18_F_S_STREAMING, &s->s_flags);
550 564
551 cx18_vapi(cx, CX18_DESTROY_TASK, 1, s->handle); 565 cx18_vapi(cx, CX18_DESTROY_TASK, 1, s->handle);
552 s->handle = 0xffffffff; 566 s->handle = CX18_INVALID_TASK_HANDLE;
553 567
554 if (atomic_read(&cx->tot_capturing) > 0) 568 if (atomic_read(&cx->tot_capturing) > 0)
555 return 0; 569 return 0;
556 570
557 write_reg(5, CX18_DSP0_INTERRUPT_MASK); 571 cx18_write_reg(cx, 5, CX18_DSP0_INTERRUPT_MASK);
558 wake_up(&s->waitq); 572 wake_up(&s->waitq);
559 573
560 return 0; 574 return 0;
@@ -568,8 +582,8 @@ u32 cx18_find_handle(struct cx18 *cx)
568 for (i = 0; i < CX18_MAX_STREAMS; i++) { 582 for (i = 0; i < CX18_MAX_STREAMS; i++) {
569 struct cx18_stream *s = &cx->streams[i]; 583 struct cx18_stream *s = &cx->streams[i];
570 584
571 if (s->v4l2dev && s->handle) 585 if (s->v4l2dev && (s->handle != CX18_INVALID_TASK_HANDLE))
572 return s->handle; 586 return s->handle;
573 } 587 }
574 return 0; 588 return CX18_INVALID_TASK_HANDLE;
575} 589}
diff --git a/drivers/media/video/cx18/cx18-version.h b/drivers/media/video/cx18/cx18-version.h
index d5c7a6f968dd..9f6be2d457fb 100644
--- a/drivers/media/video/cx18/cx18-version.h
+++ b/drivers/media/video/cx18/cx18-version.h
@@ -25,7 +25,7 @@
25#define CX18_DRIVER_NAME "cx18" 25#define CX18_DRIVER_NAME "cx18"
26#define CX18_DRIVER_VERSION_MAJOR 1 26#define CX18_DRIVER_VERSION_MAJOR 1
27#define CX18_DRIVER_VERSION_MINOR 0 27#define CX18_DRIVER_VERSION_MINOR 0
28#define CX18_DRIVER_VERSION_PATCHLEVEL 0 28#define CX18_DRIVER_VERSION_PATCHLEVEL 1
29 29
30#define CX18_VERSION __stringify(CX18_DRIVER_VERSION_MAJOR) "." __stringify(CX18_DRIVER_VERSION_MINOR) "." __stringify(CX18_DRIVER_VERSION_PATCHLEVEL) 30#define CX18_VERSION __stringify(CX18_DRIVER_VERSION_MAJOR) "." __stringify(CX18_DRIVER_VERSION_MINOR) "." __stringify(CX18_DRIVER_VERSION_PATCHLEVEL)
31#define CX18_DRIVER_VERSION KERNEL_VERSION(CX18_DRIVER_VERSION_MAJOR, \ 31#define CX18_DRIVER_VERSION KERNEL_VERSION(CX18_DRIVER_VERSION_MAJOR, \
diff --git a/drivers/media/video/cx18/cx23418.h b/drivers/media/video/cx18/cx23418.h
index e7ed053059a8..668f968d7761 100644
--- a/drivers/media/video/cx18/cx23418.h
+++ b/drivers/media/video/cx18/cx23418.h
@@ -351,7 +351,7 @@
351 Descriptor Lists to the driver 351 Descriptor Lists to the driver
352 IN[0] - Task handle. Handle of the task to start 352 IN[0] - Task handle. Handle of the task to start
353 ReturnCode - One of the ERR_DE_... */ 353 ReturnCode - One of the ERR_DE_... */
354/* #define CX18_CPU_DE_ReleaseMDL (CPU_CMD_MASK_DE | 0x0006) */ 354#define CX18_CPU_DE_RELEASE_MDL (CPU_CMD_MASK_DE | 0x0006)
355 355
356/* Description: This command signals the cpu that the dat buffer has been 356/* Description: This command signals the cpu that the dat buffer has been
357 consumed and ready for re-use. 357 consumed and ready for re-use.
diff --git a/drivers/media/video/cx2341x.c b/drivers/media/video/cx2341x.c
index 22847a0444f5..cbbe47fb87b7 100644
--- a/drivers/media/video/cx2341x.c
+++ b/drivers/media/video/cx2341x.c
@@ -508,7 +508,10 @@ int cx2341x_ctrl_query(const struct cx2341x_mpeg_params *params,
508 /* this setting is read-only for the cx2341x since the 508 /* this setting is read-only for the cx2341x since the
509 V4L2_CID_MPEG_STREAM_TYPE really determines the 509 V4L2_CID_MPEG_STREAM_TYPE really determines the
510 MPEG-1/2 setting */ 510 MPEG-1/2 setting */
511 err = v4l2_ctrl_query_fill_std(qctrl); 511 err = v4l2_ctrl_query_fill(qctrl,
512 V4L2_MPEG_VIDEO_ENCODING_MPEG_1,
513 V4L2_MPEG_VIDEO_ENCODING_MPEG_2, 1,
514 V4L2_MPEG_VIDEO_ENCODING_MPEG_2);
512 if (err == 0) 515 if (err == 0)
513 qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY; 516 qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
514 return err; 517 return err;
diff --git a/drivers/media/video/cx23885/Kconfig b/drivers/media/video/cx23885/Kconfig
index e60bd31b51a3..8c1b7fa47a41 100644
--- a/drivers/media/video/cx23885/Kconfig
+++ b/drivers/media/video/cx23885/Kconfig
@@ -15,6 +15,7 @@ config VIDEO_CX23885
15 select DVB_S5H1409 if !DVB_FE_CUSTOMISE 15 select DVB_S5H1409 if !DVB_FE_CUSTOMISE
16 select DVB_S5H1411 if !DVB_FE_CUSTOMISE 16 select DVB_S5H1411 if !DVB_FE_CUSTOMISE
17 select DVB_LGDT330X if !DVB_FE_CUSTOMISE 17 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
18 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
18 select MEDIA_TUNER_XC2028 if !DVB_FE_CUSTOMIZE 19 select MEDIA_TUNER_XC2028 if !DVB_FE_CUSTOMIZE
19 select MEDIA_TUNER_TDA8290 if !DVB_FE_CUSTOMIZE 20 select MEDIA_TUNER_TDA8290 if !DVB_FE_CUSTOMIZE
20 select MEDIA_TUNER_TDA18271 if !DVB_FE_CUSTOMIZE 21 select MEDIA_TUNER_TDA18271 if !DVB_FE_CUSTOMIZE
diff --git a/drivers/media/video/cx23885/cx23885-417.c b/drivers/media/video/cx23885/cx23885-417.c
index 7b0e8c01692e..395c11fa47ce 100644
--- a/drivers/media/video/cx23885/cx23885-417.c
+++ b/drivers/media/video/cx23885/cx23885-417.c
@@ -36,7 +36,6 @@
36#include <media/cx2341x.h> 36#include <media/cx2341x.h>
37 37
38#include "cx23885.h" 38#include "cx23885.h"
39#include "media/cx2341x.h"
40 39
41#define CX23885_FIRM_IMAGE_SIZE 376836 40#define CX23885_FIRM_IMAGE_SIZE 376836
42#define CX23885_FIRM_IMAGE_NAME "v4l-cx23885-enc.fw" 41#define CX23885_FIRM_IMAGE_NAME "v4l-cx23885-enc.fw"
@@ -632,7 +631,7 @@ int mc417_memory_read(struct cx23885_dev *dev, u32 address, u32 *value)
632/* ------------------------------------------------------------------ */ 631/* ------------------------------------------------------------------ */
633 632
634/* MPEG encoder API */ 633/* MPEG encoder API */
635char *cmd_to_str(int cmd) 634static char *cmd_to_str(int cmd)
636{ 635{
637 switch (cmd) { 636 switch (cmd) {
638 case CX2341X_ENC_PING_FW: 637 case CX2341X_ENC_PING_FW:
@@ -1583,6 +1582,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
1583 1582
1584 dprintk(2, "%s()\n", __func__); 1583 dprintk(2, "%s()\n", __func__);
1585 1584
1585 lock_kernel();
1586 list_for_each(list, &cx23885_devlist) { 1586 list_for_each(list, &cx23885_devlist) {
1587 h = list_entry(list, struct cx23885_dev, devlist); 1587 h = list_entry(list, struct cx23885_dev, devlist);
1588 if (h->v4l_device->minor == minor) { 1588 if (h->v4l_device->minor == minor) {
@@ -1591,13 +1591,17 @@ static int mpeg_open(struct inode *inode, struct file *file)
1591 } 1591 }
1592 } 1592 }
1593 1593
1594 if (dev == NULL) 1594 if (dev == NULL) {
1595 unlock_kernel();
1595 return -ENODEV; 1596 return -ENODEV;
1597 }
1596 1598
1597 /* allocate + initialize per filehandle data */ 1599 /* allocate + initialize per filehandle data */
1598 fh = kzalloc(sizeof(*fh), GFP_KERNEL); 1600 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
1599 if (NULL == fh) 1601 if (NULL == fh) {
1602 unlock_kernel();
1600 return -ENOMEM; 1603 return -ENOMEM;
1604 }
1601 1605
1602 file->private_data = fh; 1606 file->private_data = fh;
1603 fh->dev = dev; 1607 fh->dev = dev;
@@ -1608,6 +1612,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
1608 V4L2_FIELD_INTERLACED, 1612 V4L2_FIELD_INTERLACED,
1609 sizeof(struct cx23885_buffer), 1613 sizeof(struct cx23885_buffer),
1610 fh); 1614 fh);
1615 unlock_kernel();
1611 1616
1612 return 0; 1617 return 0;
1613} 1618}
diff --git a/drivers/media/video/cx23885/cx23885-cards.c b/drivers/media/video/cx23885/cx23885-cards.c
index c36d3f632104..2cda15f829fd 100644
--- a/drivers/media/video/cx23885/cx23885-cards.c
+++ b/drivers/media/video/cx23885/cx23885-cards.c
@@ -26,6 +26,7 @@
26#include <media/cx25840.h> 26#include <media/cx25840.h>
27 27
28#include "cx23885.h" 28#include "cx23885.h"
29#include "tuner-xc2028.h"
29 30
30/* ------------------------------------------------------------------ */ 31/* ------------------------------------------------------------------ */
31/* board config info */ 32/* board config info */
@@ -148,6 +149,15 @@ struct cx23885_board cx23885_boards[] = {
148 .portb = CX23885_MPEG_DVB, 149 .portb = CX23885_MPEG_DVB,
149 .portc = CX23885_MPEG_DVB, 150 .portc = CX23885_MPEG_DVB,
150 }, 151 },
152 [CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP] = {
153 .name = "DViCO FusionHDTV DVB-T Dual Express",
154 .portb = CX23885_MPEG_DVB,
155 .portc = CX23885_MPEG_DVB,
156 },
157 [CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H] = {
158 .name = "Leadtek Winfast PxDVR3200 H",
159 .portc = CX23885_MPEG_DVB,
160 },
151}; 161};
152const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards); 162const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards);
153 163
@@ -219,6 +229,14 @@ struct cx23885_subid cx23885_subids[] = {
219 .subvendor = 0x18ac, 229 .subvendor = 0x18ac,
220 .subdevice = 0xd618, 230 .subdevice = 0xd618,
221 .card = CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP, 231 .card = CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP,
232 },{
233 .subvendor = 0x18ac,
234 .subdevice = 0xdb78,
235 .card = CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP,
236 }, {
237 .subvendor = 0x107d,
238 .subdevice = 0x6681,
239 .card = CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H,
222 }, 240 },
223}; 241};
224const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids); 242const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids);
@@ -319,15 +337,15 @@ static void hauppauge_eeprom(struct cx23885_dev *dev, u8 *eeprom_data)
319 dev->name, tv.model); 337 dev->name, tv.model);
320} 338}
321 339
322/* Tuner callback function for cx23885 boards. Currently only needed 340int cx23885_tuner_callback(void *priv, int component, int command, int arg)
323 * for HVR1500Q, which has an xc5000 tuner.
324 */
325int cx23885_tuner_callback(void *priv, int command, int arg)
326{ 341{
327 struct cx23885_i2c *bus = priv; 342 struct cx23885_tsport *port = priv;
328 struct cx23885_dev *dev = bus->dev; 343 struct cx23885_dev *dev = port->dev;
329 u32 bitmask = 0; 344 u32 bitmask = 0;
330 345
346 if (command == XC2028_RESET_CLK)
347 return 0;
348
331 if (command != 0) { 349 if (command != 0) {
332 printk(KERN_ERR "%s(): Unknown command 0x%x.\n", 350 printk(KERN_ERR "%s(): Unknown command 0x%x.\n",
333 __func__, command); 351 __func__, command);
@@ -335,21 +353,21 @@ int cx23885_tuner_callback(void *priv, int command, int arg)
335 } 353 }
336 354
337 switch(dev->board) { 355 switch(dev->board) {
356 case CX23885_BOARD_HAUPPAUGE_HVR1400:
357 case CX23885_BOARD_HAUPPAUGE_HVR1500:
338 case CX23885_BOARD_HAUPPAUGE_HVR1500Q: 358 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
339 /* Tuner Reset Command from xc5000 */ 359 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
340 if (command == 0) 360 /* Tuner Reset Command */
341 bitmask = 0x04; 361 bitmask = 0x04;
342 break; 362 break;
343 case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP: 363 case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
344 if (command == 0) { 364 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP:
345 365 /* Two identical tuners on two different i2c buses,
346 /* Two identical tuners on two different i2c buses, 366 * we need to reset the correct gpio. */
347 * we need to reset the correct gpio. */ 367 if (port->nr == 0)
348 if (bus->nr == 0) 368 bitmask = 0x01;
349 bitmask = 0x01; 369 else if (port->nr == 1)
350 else if (bus->nr == 1) 370 bitmask = 0x04;
351 bitmask = 0x04;
352 }
353 break; 371 break;
354 } 372 }
355 373
@@ -465,6 +483,32 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
465 mdelay(20); 483 mdelay(20);
466 cx_set(GP0_IO, 0x000f000f); 484 cx_set(GP0_IO, 0x000f000f);
467 break; 485 break;
486 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP:
487 /* GPIO-0 portb xc3028 reset */
488 /* GPIO-1 portb zl10353 reset */
489 /* GPIO-2 portc xc3028 reset */
490 /* GPIO-3 portc zl10353 reset */
491
492 /* Put the parts into reset and back */
493 cx_set(GP0_IO, 0x000f0000);
494 mdelay(20);
495 cx_clear(GP0_IO, 0x0000000f);
496 mdelay(20);
497 cx_set(GP0_IO, 0x000f000f);
498 break;
499 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
500 /* GPIO-2 xc3028 tuner reset */
501
502 /* The following GPIO's are on the internal AVCore (cx25840) */
503 /* GPIO-? zl10353 demod reset */
504
505 /* Put the parts into reset and back */
506 cx_set(GP0_IO, 0x00040000);
507 mdelay(20);
508 cx_clear(GP0_IO, 0x00000004);
509 mdelay(20);
510 cx_set(GP0_IO, 0x00040004);
511 break;
468 } 512 }
469} 513}
470 514
@@ -479,6 +523,9 @@ int cx23885_ir_init(struct cx23885_dev *dev)
479 case CX23885_BOARD_HAUPPAUGE_HVR1400: 523 case CX23885_BOARD_HAUPPAUGE_HVR1400:
480 /* FIXME: Implement me */ 524 /* FIXME: Implement me */
481 break; 525 break;
526 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP:
527 request_module("ir-kbd-i2c");
528 break;
482 } 529 }
483 530
484 return 0; 531 return 0;
@@ -516,6 +563,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
516 563
517 switch (dev->board) { 564 switch (dev->board) {
518 case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP: 565 case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
566 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP:
519 ts2->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */ 567 ts2->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */
520 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */ 568 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
521 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO; 569 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
@@ -548,6 +596,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
548 case CX23885_BOARD_HAUPPAUGE_HVR1200: 596 case CX23885_BOARD_HAUPPAUGE_HVR1200:
549 case CX23885_BOARD_HAUPPAUGE_HVR1700: 597 case CX23885_BOARD_HAUPPAUGE_HVR1700:
550 case CX23885_BOARD_HAUPPAUGE_HVR1400: 598 case CX23885_BOARD_HAUPPAUGE_HVR1400:
599 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
551 default: 600 default:
552 ts2->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */ 601 ts2->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */
553 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */ 602 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
@@ -561,6 +610,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
561 case CX23885_BOARD_HAUPPAUGE_HVR1800: 610 case CX23885_BOARD_HAUPPAUGE_HVR1800:
562 case CX23885_BOARD_HAUPPAUGE_HVR1800lp: 611 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
563 case CX23885_BOARD_HAUPPAUGE_HVR1700: 612 case CX23885_BOARD_HAUPPAUGE_HVR1700:
613 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
564 request_module("cx25840"); 614 request_module("cx25840");
565 break; 615 break;
566 } 616 }
diff --git a/drivers/media/video/cx23885/cx23885-core.c b/drivers/media/video/cx23885/cx23885-core.c
index 25fb09938744..beb3e61669a3 100644
--- a/drivers/media/video/cx23885/cx23885-core.c
+++ b/drivers/media/video/cx23885/cx23885-core.c
@@ -1442,7 +1442,7 @@ void cx23885_cancel_buffers(struct cx23885_tsport *port)
1442 struct cx23885_dev *dev = port->dev; 1442 struct cx23885_dev *dev = port->dev;
1443 struct cx23885_dmaqueue *q = &port->mpegq; 1443 struct cx23885_dmaqueue *q = &port->mpegq;
1444 1444
1445 dprintk(1, "%s()\n", __FUNCTION__); 1445 dprintk(1, "%s()\n", __func__);
1446 del_timer_sync(&q->timeout); 1446 del_timer_sync(&q->timeout);
1447 cx23885_stop_dma(port); 1447 cx23885_stop_dma(port);
1448 do_cancel_buffers(port, "cancel", 0); 1448 do_cancel_buffers(port, "cancel", 0);
diff --git a/drivers/media/video/cx23885/cx23885-dvb.c b/drivers/media/video/cx23885/cx23885-dvb.c
index 291b9d008da8..24bd18327aa0 100644
--- a/drivers/media/video/cx23885/cx23885-dvb.c
+++ b/drivers/media/video/cx23885/cx23885-dvb.c
@@ -42,6 +42,7 @@
42#include "tuner-simple.h" 42#include "tuner-simple.h"
43#include "dib7000p.h" 43#include "dib7000p.h"
44#include "dibx000_common.h" 44#include "dibx000_common.h"
45#include "zl10353.h"
45 46
46static unsigned int debug; 47static unsigned int debug;
47 48
@@ -188,13 +189,11 @@ static struct s5h1411_config dvico_s5h1411_config = {
188static struct xc5000_config hauppauge_hvr1500q_tunerconfig = { 189static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
189 .i2c_address = 0x61, 190 .i2c_address = 0x61,
190 .if_khz = 5380, 191 .if_khz = 5380,
191 .tuner_callback = cx23885_tuner_callback
192}; 192};
193 193
194static struct xc5000_config dvico_xc5000_tunerconfig = { 194static struct xc5000_config dvico_xc5000_tunerconfig = {
195 .i2c_address = 0x64, 195 .i2c_address = 0x64,
196 .if_khz = 5380, 196 .if_khz = 5380,
197 .tuner_callback = cx23885_tuner_callback
198}; 197};
199 198
200static struct tda829x_config tda829x_no_probe = { 199static struct tda829x_config tda829x_no_probe = {
@@ -303,35 +302,11 @@ static struct dib7000p_config hauppauge_hvr1400_dib7000_config = {
303 .output_mode = OUTMODE_MPEG2_SERIAL, 302 .output_mode = OUTMODE_MPEG2_SERIAL,
304}; 303};
305 304
306static int cx23885_hvr1500_xc3028_callback(void *ptr, int command, int arg) 305static struct zl10353_config dvico_fusionhdtv_xc3028 = {
307{ 306 .demod_address = 0x0f,
308 struct cx23885_tsport *port = ptr; 307 .if2 = 45600,
309 struct cx23885_dev *dev = port->dev; 308 .no_tuner = 1,
310 309};
311 switch (command) {
312 case XC2028_TUNER_RESET:
313 /* Send the tuner in then out of reset */
314 /* GPIO-2 xc3028 tuner */
315 dprintk(1, "%s: XC2028_TUNER_RESET %d\n", __func__, arg);
316
317 cx_set(GP0_IO, 0x00040000);
318 cx_clear(GP0_IO, 0x00000004);
319 msleep(5);
320
321 cx_set(GP0_IO, 0x00040004);
322 msleep(5);
323 break;
324 case XC2028_RESET_CLK:
325 dprintk(1, "%s: XC2028_RESET_CLK %d\n", __func__, arg);
326 break;
327 default:
328 dprintk(1, "%s: unknown command %d, arg %d\n", __func__,
329 command, arg);
330 return -EINVAL;
331 }
332
333 return 0;
334}
335 310
336static int dvb_register(struct cx23885_tsport *port) 311static int dvb_register(struct cx23885_tsport *port)
337{ 312{
@@ -413,8 +388,8 @@ static int dvb_register(struct cx23885_tsport *port)
413 &dev->i2c_bus[0].i2c_adap); 388 &dev->i2c_bus[0].i2c_adap);
414 if (port->dvb.frontend != NULL) 389 if (port->dvb.frontend != NULL)
415 dvb_attach(xc5000_attach, port->dvb.frontend, 390 dvb_attach(xc5000_attach, port->dvb.frontend,
416 &i2c_bus->i2c_adap, 391 &i2c_bus->i2c_adap,
417 &hauppauge_hvr1500q_tunerconfig, i2c_bus); 392 &hauppauge_hvr1500q_tunerconfig);
418 break; 393 break;
419 case CX23885_BOARD_HAUPPAUGE_HVR1500: 394 case CX23885_BOARD_HAUPPAUGE_HVR1500:
420 i2c_bus = &dev->i2c_bus[1]; 395 i2c_bus = &dev->i2c_bus[1];
@@ -426,10 +401,9 @@ static int dvb_register(struct cx23885_tsport *port)
426 struct xc2028_config cfg = { 401 struct xc2028_config cfg = {
427 .i2c_adap = &i2c_bus->i2c_adap, 402 .i2c_adap = &i2c_bus->i2c_adap,
428 .i2c_addr = 0x61, 403 .i2c_addr = 0x61,
429 .callback = cx23885_hvr1500_xc3028_callback,
430 }; 404 };
431 static struct xc2028_ctrl ctl = { 405 static struct xc2028_ctrl ctl = {
432 .fname = "xc3028-v27.fw", 406 .fname = XC2028_DEFAULT_FIRMWARE,
433 .max_len = 64, 407 .max_len = 64,
434 .scode_table = XC3028_FE_OREN538, 408 .scode_table = XC3028_FE_OREN538,
435 }; 409 };
@@ -465,13 +439,13 @@ static int dvb_register(struct cx23885_tsport *port)
465 struct xc2028_config cfg = { 439 struct xc2028_config cfg = {
466 .i2c_adap = &dev->i2c_bus[1].i2c_adap, 440 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
467 .i2c_addr = 0x64, 441 .i2c_addr = 0x64,
468 .callback = cx23885_hvr1500_xc3028_callback,
469 }; 442 };
470 static struct xc2028_ctrl ctl = { 443 static struct xc2028_ctrl ctl = {
471 .fname = "xc3028L-v36.fw", 444 .fname = XC3028L_DEFAULT_FIRMWARE,
472 .max_len = 64, 445 .max_len = 64,
473 .demod = 5000, 446 .demod = 5000,
474 .d2633 = 1 447 /* This is true for all demods with v36 firmware? */
448 .type = XC2028_D2633,
475 }; 449 };
476 450
477 fe = dvb_attach(xc2028_attach, 451 fe = dvb_attach(xc2028_attach,
@@ -492,8 +466,57 @@ static int dvb_register(struct cx23885_tsport *port)
492 &i2c_bus->i2c_adap); 466 &i2c_bus->i2c_adap);
493 if (port->dvb.frontend != NULL) 467 if (port->dvb.frontend != NULL)
494 dvb_attach(xc5000_attach, port->dvb.frontend, 468 dvb_attach(xc5000_attach, port->dvb.frontend,
495 &i2c_bus->i2c_adap, 469 &i2c_bus->i2c_adap,
496 &dvico_xc5000_tunerconfig, i2c_bus); 470 &dvico_xc5000_tunerconfig);
471 break;
472 case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: {
473 i2c_bus = &dev->i2c_bus[port->nr - 1];
474
475 port->dvb.frontend = dvb_attach(zl10353_attach,
476 &dvico_fusionhdtv_xc3028,
477 &i2c_bus->i2c_adap);
478 if (port->dvb.frontend != NULL) {
479 struct dvb_frontend *fe;
480 struct xc2028_config cfg = {
481 .i2c_adap = &i2c_bus->i2c_adap,
482 .i2c_addr = 0x61,
483 };
484 static struct xc2028_ctrl ctl = {
485 .fname = XC2028_DEFAULT_FIRMWARE,
486 .max_len = 64,
487 .demod = XC3028_FE_ZARLINK456,
488 };
489
490 fe = dvb_attach(xc2028_attach, port->dvb.frontend,
491 &cfg);
492 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
493 fe->ops.tuner_ops.set_config(fe, &ctl);
494 }
495 break;
496 }
497 case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
498 i2c_bus = &dev->i2c_bus[0];
499
500 port->dvb.frontend = dvb_attach(zl10353_attach,
501 &dvico_fusionhdtv_xc3028,
502 &i2c_bus->i2c_adap);
503 if (port->dvb.frontend != NULL) {
504 struct dvb_frontend *fe;
505 struct xc2028_config cfg = {
506 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
507 .i2c_addr = 0x61,
508 };
509 static struct xc2028_ctrl ctl = {
510 .fname = XC2028_DEFAULT_FIRMWARE,
511 .max_len = 64,
512 .demod = XC3028_FE_ZARLINK456,
513 };
514
515 fe = dvb_attach(xc2028_attach, port->dvb.frontend,
516 &cfg);
517 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
518 fe->ops.tuner_ops.set_config(fe, &ctl);
519 }
497 break; 520 break;
498 default: 521 default:
499 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n", 522 printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
@@ -504,6 +527,8 @@ static int dvb_register(struct cx23885_tsport *port)
504 printk("%s: frontend initialization failed\n", dev->name); 527 printk("%s: frontend initialization failed\n", dev->name);
505 return -1; 528 return -1;
506 } 529 }
530 /* define general-purpose callback pointer */
531 port->dvb.frontend->callback = cx23885_tuner_callback;
507 532
508 /* Put the analog decoder in standby to keep it quiet */ 533 /* Put the analog decoder in standby to keep it quiet */
509 cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL); 534 cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL);
diff --git a/drivers/media/video/cx23885/cx23885-vbi.c b/drivers/media/video/cx23885/cx23885-vbi.c
index 35e61cd112fc..5b297f0323b6 100644
--- a/drivers/media/video/cx23885/cx23885-vbi.c
+++ b/drivers/media/video/cx23885/cx23885-vbi.c
@@ -85,18 +85,8 @@ static int cx23885_start_vbi_dma(struct cx23885_dev *dev,
85 return 0; 85 return 0;
86} 86}
87 87
88int cx23885_stop_vbi_dma(struct cx23885_dev *dev)
89{
90 /* stop dma */
91 cx_clear(VID_A_DMA_CTL, 0x00000022);
92
93 /* disable irqs */
94 cx_clear(PCI_INT_MSK, 0x000001);
95 cx_clear(VID_A_INT_MSK, 0x00000022);
96 return 0;
97}
98 88
99int cx23885_restart_vbi_queue(struct cx23885_dev *dev, 89static int cx23885_restart_vbi_queue(struct cx23885_dev *dev,
100 struct cx23885_dmaqueue *q) 90 struct cx23885_dmaqueue *q)
101{ 91{
102 struct cx23885_buffer *buf; 92 struct cx23885_buffer *buf;
diff --git a/drivers/media/video/cx23885/cx23885-video.c b/drivers/media/video/cx23885/cx23885-video.c
index 6047c78d84bf..f75ed1c9b71a 100644
--- a/drivers/media/video/cx23885/cx23885-video.c
+++ b/drivers/media/video/cx23885/cx23885-video.c
@@ -244,7 +244,7 @@ static struct cx23885_ctrl cx23885_ctls[] = {
244}; 244};
245static const int CX23885_CTLS = ARRAY_SIZE(cx23885_ctls); 245static const int CX23885_CTLS = ARRAY_SIZE(cx23885_ctls);
246 246
247const u32 cx23885_user_ctrls[] = { 247static const u32 cx23885_user_ctrls[] = {
248 V4L2_CID_USER_CLASS, 248 V4L2_CID_USER_CLASS,
249 V4L2_CID_BRIGHTNESS, 249 V4L2_CID_BRIGHTNESS,
250 V4L2_CID_CONTRAST, 250 V4L2_CID_CONTRAST,
@@ -254,14 +254,13 @@ const u32 cx23885_user_ctrls[] = {
254 V4L2_CID_AUDIO_MUTE, 254 V4L2_CID_AUDIO_MUTE,
255 0 255 0
256}; 256};
257EXPORT_SYMBOL(cx23885_user_ctrls);
258 257
259static const u32 *ctrl_classes[] = { 258static const u32 *ctrl_classes[] = {
260 cx23885_user_ctrls, 259 cx23885_user_ctrls,
261 NULL 260 NULL
262}; 261};
263 262
264void cx23885_video_wakeup(struct cx23885_dev *dev, 263static void cx23885_video_wakeup(struct cx23885_dev *dev,
265 struct cx23885_dmaqueue *q, u32 count) 264 struct cx23885_dmaqueue *q, u32 count)
266{ 265{
267 struct cx23885_buffer *buf; 266 struct cx23885_buffer *buf;
@@ -296,7 +295,7 @@ void cx23885_video_wakeup(struct cx23885_dev *dev,
296 __func__, bc); 295 __func__, bc);
297} 296}
298 297
299int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm) 298static int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm)
300{ 299{
301 dprintk(1, "%s(norm = 0x%08x) name: [%s]\n", 300 dprintk(1, "%s(norm = 0x%08x) name: [%s]\n",
302 __func__, 301 __func__,
@@ -314,7 +313,7 @@ int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm)
314 return 0; 313 return 0;
315} 314}
316 315
317struct video_device *cx23885_vdev_init(struct cx23885_dev *dev, 316static struct video_device *cx23885_vdev_init(struct cx23885_dev *dev,
318 struct pci_dev *pci, 317 struct pci_dev *pci,
319 struct video_device *template, 318 struct video_device *template,
320 char *type) 319 char *type)
@@ -334,7 +333,7 @@ struct video_device *cx23885_vdev_init(struct cx23885_dev *dev,
334 return vfd; 333 return vfd;
335} 334}
336 335
337int cx23885_ctrl_query(struct v4l2_queryctrl *qctrl) 336static int cx23885_ctrl_query(struct v4l2_queryctrl *qctrl)
338{ 337{
339 int i; 338 int i;
340 339
@@ -351,7 +350,6 @@ int cx23885_ctrl_query(struct v4l2_queryctrl *qctrl)
351 *qctrl = cx23885_ctls[i].v; 350 *qctrl = cx23885_ctls[i].v;
352 return 0; 351 return 0;
353} 352}
354EXPORT_SYMBOL(cx23885_ctrl_query);
355 353
356/* ------------------------------------------------------------------- */ 354/* ------------------------------------------------------------------- */
357/* resource management */ 355/* resource management */
@@ -402,7 +400,7 @@ static void res_free(struct cx23885_dev *dev, struct cx23885_fh *fh,
402 mutex_unlock(&dev->lock); 400 mutex_unlock(&dev->lock);
403} 401}
404 402
405int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input) 403static int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input)
406{ 404{
407 struct v4l2_routing route; 405 struct v4l2_routing route;
408 memset(&route, 0, sizeof(route)); 406 memset(&route, 0, sizeof(route));
@@ -422,10 +420,9 @@ int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input)
422 420
423 return 0; 421 return 0;
424} 422}
425EXPORT_SYMBOL(cx23885_video_mux);
426 423
427/* ------------------------------------------------------------------ */ 424/* ------------------------------------------------------------------ */
428int cx23885_set_scale(struct cx23885_dev *dev, unsigned int width, 425static int cx23885_set_scale(struct cx23885_dev *dev, unsigned int width,
429 unsigned int height, enum v4l2_field field) 426 unsigned int height, enum v4l2_field field)
430{ 427{
431 dprintk(1, "%s()\n", __func__); 428 dprintk(1, "%s()\n", __func__);
@@ -731,6 +728,7 @@ static int video_open(struct inode *inode, struct file *file)
731 enum v4l2_buf_type type = 0; 728 enum v4l2_buf_type type = 0;
732 int radio = 0; 729 int radio = 0;
733 730
731 lock_kernel();
734 list_for_each(list, &cx23885_devlist) { 732 list_for_each(list, &cx23885_devlist) {
735 h = list_entry(list, struct cx23885_dev, devlist); 733 h = list_entry(list, struct cx23885_dev, devlist);
736 if (h->video_dev->minor == minor) { 734 if (h->video_dev->minor == minor) {
@@ -748,16 +746,20 @@ static int video_open(struct inode *inode, struct file *file)
748 dev = h; 746 dev = h;
749 } 747 }
750 } 748 }
751 if (NULL == dev) 749 if (NULL == dev) {
750 unlock_kernel();
752 return -ENODEV; 751 return -ENODEV;
752 }
753 753
754 dprintk(1, "open minor=%d radio=%d type=%s\n", 754 dprintk(1, "open minor=%d radio=%d type=%s\n",
755 minor, radio, v4l2_type_names[type]); 755 minor, radio, v4l2_type_names[type]);
756 756
757 /* allocate + initialize per filehandle data */ 757 /* allocate + initialize per filehandle data */
758 fh = kzalloc(sizeof(*fh), GFP_KERNEL); 758 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
759 if (NULL == fh) 759 if (NULL == fh) {
760 unlock_kernel();
760 return -ENOMEM; 761 return -ENOMEM;
762 }
761 file->private_data = fh; 763 file->private_data = fh;
762 fh->dev = dev; 764 fh->dev = dev;
763 fh->radio = radio; 765 fh->radio = radio;
@@ -775,6 +777,7 @@ static int video_open(struct inode *inode, struct file *file)
775 777
776 dprintk(1, "post videobuf_queue_init()\n"); 778 dprintk(1, "post videobuf_queue_init()\n");
777 779
780 unlock_kernel();
778 781
779 return 0; 782 return 0;
780} 783}
@@ -884,21 +887,19 @@ static int video_mmap(struct file *file, struct vm_area_struct *vma)
884/* ------------------------------------------------------------------ */ 887/* ------------------------------------------------------------------ */
885/* VIDEO CTRL IOCTLS */ 888/* VIDEO CTRL IOCTLS */
886 889
887int cx23885_get_control(struct cx23885_dev *dev, struct v4l2_control *ctl) 890static int cx23885_get_control(struct cx23885_dev *dev, struct v4l2_control *ctl)
888{ 891{
889 dprintk(1, "%s() calling cx25840(VIDIOC_G_CTRL)\n", __func__); 892 dprintk(1, "%s() calling cx25840(VIDIOC_G_CTRL)\n", __func__);
890 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_G_CTRL, ctl); 893 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_G_CTRL, ctl);
891 return 0; 894 return 0;
892} 895}
893EXPORT_SYMBOL(cx23885_get_control);
894 896
895int cx23885_set_control(struct cx23885_dev *dev, struct v4l2_control *ctl) 897static int cx23885_set_control(struct cx23885_dev *dev, struct v4l2_control *ctl)
896{ 898{
897 dprintk(1, "%s() calling cx25840(VIDIOC_S_CTRL)" 899 dprintk(1, "%s() calling cx25840(VIDIOC_S_CTRL)"
898 " (disabled - no action)\n", __func__); 900 " (disabled - no action)\n", __func__);
899 return 0; 901 return 0;
900} 902}
901EXPORT_SYMBOL(cx23885_set_control);
902 903
903static void init_controls(struct cx23885_dev *dev) 904static void init_controls(struct cx23885_dev *dev)
904{ 905{
@@ -1146,7 +1147,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *tvnorms)
1146 return 0; 1147 return 0;
1147} 1148}
1148 1149
1149int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i) 1150static int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i)
1150{ 1151{
1151 static const char *iname[] = { 1152 static const char *iname[] = {
1152 [CX23885_VMUX_COMPOSITE1] = "Composite1", 1153 [CX23885_VMUX_COMPOSITE1] = "Composite1",
@@ -1179,7 +1180,6 @@ int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i)
1179 i->std = CX23885_NORMS; 1180 i->std = CX23885_NORMS;
1180 return 0; 1181 return 0;
1181} 1182}
1182EXPORT_SYMBOL(cx23885_enum_input);
1183 1183
1184static int vidioc_enum_input(struct file *file, void *priv, 1184static int vidioc_enum_input(struct file *file, void *priv,
1185 struct v4l2_input *i) 1185 struct v4l2_input *i)
@@ -1288,7 +1288,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
1288 return 0; 1288 return 0;
1289} 1289}
1290 1290
1291int cx23885_set_freq(struct cx23885_dev *dev, struct v4l2_frequency *f) 1291static int cx23885_set_freq(struct cx23885_dev *dev, struct v4l2_frequency *f)
1292{ 1292{
1293 if (unlikely(UNSET == dev->tuner_type)) 1293 if (unlikely(UNSET == dev->tuner_type))
1294 return -EINVAL; 1294 return -EINVAL;
@@ -1307,7 +1307,6 @@ int cx23885_set_freq(struct cx23885_dev *dev, struct v4l2_frequency *f)
1307 1307
1308 return 0; 1308 return 0;
1309} 1309}
1310EXPORT_SYMBOL(cx23885_set_freq);
1311 1310
1312static int vidioc_s_frequency(struct file *file, void *priv, 1311static int vidioc_s_frequency(struct file *file, void *priv,
1313 struct v4l2_frequency *f) 1312 struct v4l2_frequency *f)
diff --git a/drivers/media/video/cx23885/cx23885.h b/drivers/media/video/cx23885/cx23885.h
index e23d97c071e0..ba4e0aaed463 100644
--- a/drivers/media/video/cx23885/cx23885.h
+++ b/drivers/media/video/cx23885/cx23885.h
@@ -64,6 +64,8 @@
64#define CX23885_BOARD_HAUPPAUGE_HVR1700 8 64#define CX23885_BOARD_HAUPPAUGE_HVR1700 8
65#define CX23885_BOARD_HAUPPAUGE_HVR1400 9 65#define CX23885_BOARD_HAUPPAUGE_HVR1400 9
66#define CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP 10 66#define CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP 10
67#define CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP 11
68#define CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H 12
67 69
68/* Currently unsupported by the driver: PAL/H, NTSC/Kr, SECAM B/G/H/LC */ 70/* Currently unsupported by the driver: PAL/H, NTSC/Kr, SECAM B/G/H/LC */
69#define CX23885_NORMS (\ 71#define CX23885_NORMS (\
@@ -409,7 +411,7 @@ extern const unsigned int cx23885_bcount;
409extern struct cx23885_subid cx23885_subids[]; 411extern struct cx23885_subid cx23885_subids[];
410extern const unsigned int cx23885_idcount; 412extern const unsigned int cx23885_idcount;
411 413
412extern int cx23885_tuner_callback(void *priv, int command, int arg); 414extern int cx23885_tuner_callback(void *priv, int component, int command, int arg);
413extern void cx23885_card_list(struct cx23885_dev *dev); 415extern void cx23885_card_list(struct cx23885_dev *dev);
414extern int cx23885_ir_init(struct cx23885_dev *dev); 416extern int cx23885_ir_init(struct cx23885_dev *dev);
415extern void cx23885_gpio_setup(struct cx23885_dev *dev); 417extern void cx23885_gpio_setup(struct cx23885_dev *dev);
diff --git a/drivers/media/video/cx25840/cx25840-vbi.c b/drivers/media/video/cx25840/cx25840-vbi.c
index 69f2bbdbb929..58e6ef1c28a0 100644
--- a/drivers/media/video/cx25840/cx25840-vbi.c
+++ b/drivers/media/video/cx25840/cx25840-vbi.c
@@ -141,10 +141,11 @@ int cx25840_vbi(struct i2c_client *client, unsigned int cmd, void *arg)
141 u8 lcr[24]; 141 u8 lcr[24];
142 142
143 fmt = arg; 143 fmt = arg;
144 if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) 144 if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE &&
145 fmt->type != V4L2_BUF_TYPE_VBI_CAPTURE)
145 return -EINVAL; 146 return -EINVAL;
146 svbi = &fmt->fmt.sliced; 147 svbi = &fmt->fmt.sliced;
147 if (svbi->service_set == 0) { 148 if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
148 /* raw VBI */ 149 /* raw VBI */
149 memset(svbi, 0, sizeof(*svbi)); 150 memset(svbi, 0, sizeof(*svbi));
150 151
diff --git a/drivers/media/video/cx88/Kconfig b/drivers/media/video/cx88/Kconfig
index 9dd7bdf659b9..0b9e5fac6239 100644
--- a/drivers/media/video/cx88/Kconfig
+++ b/drivers/media/video/cx88/Kconfig
@@ -58,6 +58,10 @@ config VIDEO_CX88_DVB
58 select DVB_ISL6421 if !DVB_FE_CUSTOMISE 58 select DVB_ISL6421 if !DVB_FE_CUSTOMISE
59 select MEDIA_TUNER_SIMPLE if !DVB_FE_CUSTOMISE 59 select MEDIA_TUNER_SIMPLE if !DVB_FE_CUSTOMISE
60 select DVB_S5H1411 if !DVB_FE_CUSTOMISE 60 select DVB_S5H1411 if !DVB_FE_CUSTOMISE
61 select DVB_CX24116 if !DVB_FE_CUSTOMISE
62 select DVB_STV0299 if !DVB_FE_CUSTOMISE
63 select DVB_STV0288 if !DVB_FE_CUSTOMISE
64 select DVB_STB6000 if !DVB_FE_CUSTOMISE
61 ---help--- 65 ---help---
62 This adds support for DVB/ATSC cards based on the 66 This adds support for DVB/ATSC cards based on the
63 Conexant 2388x chip. 67 Conexant 2388x chip.
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index 9a1374a38ec7..e71369754305 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -1057,12 +1057,15 @@ static int mpeg_open(struct inode *inode, struct file *file)
1057 struct cx8802_driver *drv = NULL; 1057 struct cx8802_driver *drv = NULL;
1058 int err; 1058 int err;
1059 1059
1060 lock_kernel();
1060 dev = cx8802_get_device(inode); 1061 dev = cx8802_get_device(inode);
1061 1062
1062 dprintk( 1, "%s\n", __func__); 1063 dprintk( 1, "%s\n", __func__);
1063 1064
1064 if (dev == NULL) 1065 if (dev == NULL) {
1066 unlock_kernel();
1065 return -ENODEV; 1067 return -ENODEV;
1068 }
1066 1069
1067 /* Make sure we can acquire the hardware */ 1070 /* Make sure we can acquire the hardware */
1068 drv = cx8802_get_driver(dev, CX88_MPEG_BLACKBIRD); 1071 drv = cx8802_get_driver(dev, CX88_MPEG_BLACKBIRD);
@@ -1070,6 +1073,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
1070 err = drv->request_acquire(drv); 1073 err = drv->request_acquire(drv);
1071 if(err != 0) { 1074 if(err != 0) {
1072 dprintk(1,"%s: Unable to acquire hardware, %d\n", __func__, err); 1075 dprintk(1,"%s: Unable to acquire hardware, %d\n", __func__, err);
1076 unlock_kernel();
1073 return err; 1077 return err;
1074 } 1078 }
1075 } 1079 }
@@ -1077,6 +1081,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
1077 if (blackbird_initialize_codec(dev) < 0) { 1081 if (blackbird_initialize_codec(dev) < 0) {
1078 if (drv) 1082 if (drv)
1079 drv->request_release(drv); 1083 drv->request_release(drv);
1084 unlock_kernel();
1080 return -EINVAL; 1085 return -EINVAL;
1081 } 1086 }
1082 dprintk(1,"open minor=%d\n",minor); 1087 dprintk(1,"open minor=%d\n",minor);
@@ -1086,6 +1091,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
1086 if (NULL == fh) { 1091 if (NULL == fh) {
1087 if (drv) 1092 if (drv)
1088 drv->request_release(drv); 1093 drv->request_release(drv);
1094 unlock_kernel();
1089 return -ENOMEM; 1095 return -ENOMEM;
1090 } 1096 }
1091 file->private_data = fh; 1097 file->private_data = fh;
@@ -1101,6 +1107,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
1101 /* FIXME: locking against other video device */ 1107 /* FIXME: locking against other video device */
1102 cx88_set_scale(dev->core, dev->width, dev->height, 1108 cx88_set_scale(dev->core, dev->width, dev->height,
1103 fh->mpegq.field); 1109 fh->mpegq.field);
1110 unlock_kernel();
1104 1111
1105 return 0; 1112 return 0;
1106} 1113}
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index de199a206a15..5da04e811ca2 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -1349,27 +1349,30 @@ static const struct cx88_board cx88_boards[] = {
1349 .radio_addr = ADDR_UNSET, 1349 .radio_addr = ADDR_UNSET,
1350 .tda9887_conf = TDA9887_PRESENT, 1350 .tda9887_conf = TDA9887_PRESENT,
1351 .audio_chip = V4L2_IDENT_WM8775, 1351 .audio_chip = V4L2_IDENT_WM8775,
1352 /*
1353 * gpio0 as reported by Mike Crash <mike AT mikecrash.com>
1354 */
1352 .input = {{ 1355 .input = {{
1353 .type = CX88_VMUX_TELEVISION, 1356 .type = CX88_VMUX_TELEVISION,
1354 .vmux = 0, 1357 .vmux = 0,
1355 .gpio0 = 0xe780, 1358 .gpio0 = 0xef88,
1356 .audioroute = 1, 1359 .audioroute = 1,
1357 },{ 1360 },{
1358 .type = CX88_VMUX_COMPOSITE1, 1361 .type = CX88_VMUX_COMPOSITE1,
1359 .vmux = 1, 1362 .vmux = 1,
1360 .gpio0 = 0xe780, 1363 .gpio0 = 0xef88,
1361 .audioroute = 2, 1364 .audioroute = 2,
1362 },{ 1365 },{
1363 .type = CX88_VMUX_SVIDEO, 1366 .type = CX88_VMUX_SVIDEO,
1364 .vmux = 2, 1367 .vmux = 2,
1365 .gpio0 = 0xe780, 1368 .gpio0 = 0xef88,
1366 .audioroute = 2, 1369 .audioroute = 2,
1367 }}, 1370 }},
1368 /* fixme: Add radio support */ 1371 /* fixme: Add radio support */
1369 .mpeg = CX88_MPEG_DVB | CX88_MPEG_BLACKBIRD, 1372 .mpeg = CX88_MPEG_DVB | CX88_MPEG_BLACKBIRD,
1370 .radio = { 1373 .radio = {
1371 .type = CX88_RADIO, 1374 .type = CX88_RADIO,
1372 .gpio0 = 0xe780, 1375 .gpio0 = 0xef88,
1373 }, 1376 },
1374 }, 1377 },
1375 [CX88_BOARD_ADSTECH_PTV_390] = { 1378 [CX88_BOARD_ADSTECH_PTV_390] = {
@@ -1446,15 +1449,26 @@ static const struct cx88_board cx88_boards[] = {
1446 .name = "Pinnacle Hybrid PCTV", 1449 .name = "Pinnacle Hybrid PCTV",
1447 .tuner_type = TUNER_XC2028, 1450 .tuner_type = TUNER_XC2028,
1448 .tuner_addr = 0x61, 1451 .tuner_addr = 0x61,
1452 .radio_type = TUNER_XC2028,
1453 .radio_addr = 0x61,
1449 .input = { { 1454 .input = { {
1450 .type = CX88_VMUX_TELEVISION, 1455 .type = CX88_VMUX_TELEVISION,
1451 .vmux = 0, 1456 .vmux = 0,
1457 .gpio0 = 0x004ff,
1458 .gpio1 = 0x010ff,
1459 .gpio2 = 0x00001,
1452 }, { 1460 }, {
1453 .type = CX88_VMUX_COMPOSITE1, 1461 .type = CX88_VMUX_COMPOSITE1,
1454 .vmux = 1, 1462 .vmux = 1,
1463 .gpio0 = 0x004fb,
1464 .gpio1 = 0x010ef,
1465 .audioroute = 1,
1455 }, { 1466 }, {
1456 .type = CX88_VMUX_SVIDEO, 1467 .type = CX88_VMUX_SVIDEO,
1457 .vmux = 2, 1468 .vmux = 2,
1469 .gpio0 = 0x004fb,
1470 .gpio1 = 0x010ef,
1471 .audioroute = 1,
1458 } }, 1472 } },
1459 .radio = { 1473 .radio = {
1460 .type = CX88_RADIO, 1474 .type = CX88_RADIO,
@@ -1462,6 +1476,7 @@ static const struct cx88_board cx88_boards[] = {
1462 .gpio1 = 0x010ff, 1476 .gpio1 = 0x010ff,
1463 .gpio2 = 0x0ff, 1477 .gpio2 = 0x0ff,
1464 }, 1478 },
1479 .mpeg = CX88_MPEG_DVB,
1465 }, 1480 },
1466 [CX88_BOARD_WINFAST_TV2000_XP_GLOBAL] = { 1481 [CX88_BOARD_WINFAST_TV2000_XP_GLOBAL] = {
1467 .name = "Winfast TV2000 XP Global", 1482 .name = "Winfast TV2000 XP Global",
@@ -1566,9 +1581,9 @@ static const struct cx88_board cx88_boards[] = {
1566 }, 1581 },
1567 [CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO] = { 1582 [CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO] = {
1568 .name = "DViCO FusionHDTV DVB-T PRO", 1583 .name = "DViCO FusionHDTV DVB-T PRO",
1569 .tuner_type = TUNER_ABSENT, /* XXX: Has XC3028 */ 1584 .tuner_type = TUNER_XC2028,
1585 .tuner_addr = 0x61,
1570 .radio_type = UNSET, 1586 .radio_type = UNSET,
1571 .tuner_addr = ADDR_UNSET,
1572 .radio_addr = ADDR_UNSET, 1587 .radio_addr = ADDR_UNSET,
1573 .input = { { 1588 .input = { {
1574 .type = CX88_VMUX_COMPOSITE1, 1589 .type = CX88_VMUX_COMPOSITE1,
@@ -1625,6 +1640,36 @@ static const struct cx88_board cx88_boards[] = {
1625 .gpio2 = 0x0cfb, 1640 .gpio2 = 0x0cfb,
1626 }, 1641 },
1627 }, 1642 },
1643 [CX88_BOARD_PROLINK_PV_GLOBAL_XTREME] = {
1644 .name = "Prolink Pixelview Global Extreme",
1645 .tuner_type = TUNER_XC2028,
1646 .tuner_addr = 0x61,
1647 .input = { {
1648 .type = CX88_VMUX_TELEVISION,
1649 .vmux = 0,
1650 .gpio0 = 0x04fb,
1651 .gpio1 = 0x04080,
1652 .gpio2 = 0x0cf7,
1653 }, {
1654 .type = CX88_VMUX_COMPOSITE1,
1655 .vmux = 1,
1656 .gpio0 = 0x04fb,
1657 .gpio1 = 0x04080,
1658 .gpio2 = 0x0cfb,
1659 }, {
1660 .type = CX88_VMUX_SVIDEO,
1661 .vmux = 2,
1662 .gpio0 = 0x04fb,
1663 .gpio1 = 0x04080,
1664 .gpio2 = 0x0cfb,
1665 } },
1666 .radio = {
1667 .type = CX88_RADIO,
1668 .gpio0 = 0x04ff,
1669 .gpio1 = 0x04080,
1670 .gpio2 = 0x0cf7,
1671 },
1672 },
1628 /* Both radio, analog and ATSC work with this board. 1673 /* Both radio, analog and ATSC work with this board.
1629 However, for analog to work, s5h1409 gate should be open, 1674 However, for analog to work, s5h1409 gate should be open,
1630 otherwise, tuner-xc3028 won't be detected. 1675 otherwise, tuner-xc3028 won't be detected.
@@ -1664,6 +1709,131 @@ static const struct cx88_board cx88_boards[] = {
1664 }, 1709 },
1665 .mpeg = CX88_MPEG_DVB, 1710 .mpeg = CX88_MPEG_DVB,
1666 }, 1711 },
1712 [CX88_BOARD_HAUPPAUGE_HVR4000] = {
1713 .name = "Hauppauge WinTV-HVR4000 DVB-S/S2/T/Hybrid",
1714 .tuner_type = TUNER_PHILIPS_FMD1216ME_MK3,
1715 .radio_type = UNSET,
1716 .tuner_addr = ADDR_UNSET,
1717 .radio_addr = ADDR_UNSET,
1718 .tda9887_conf = TDA9887_PRESENT,
1719 /*
1720 * GPIO0 (WINTV2000)
1721 *
1722 * Analogue SAT DVB-T
1723 * Antenna 0xc4bf 0xc4bb
1724 * Composite 0xc4bf 0xc4bb
1725 * S-Video 0xc4bf 0xc4bb
1726 * Composite1 0xc4ff 0xc4fb
1727 * S-Video1 0xc4ff 0xc4fb
1728 *
1729 * BIT VALUE FUNCTION GP{x}_IO
1730 * 0 1 I:?
1731 * 1 1 I:?
1732 * 2 1 O:DVB-T DEMOD ENABLE LOW/ANALOG DEMOD ENABLE HIGH
1733 * 3 1 I:?
1734 * 4 1 I:?
1735 * 5 1 I:?
1736 * 6 0 O:INPUT SELECTOR 0=INTERNAL 1=EXPANSION
1737 * 7 1 O:DVB-T DEMOD RESET LOW
1738 *
1739 * BIT VALUE FUNCTION GP{x}_OE
1740 * 8 0 I
1741 * 9 0 I
1742 * a 1 O
1743 * b 0 I
1744 * c 0 I
1745 * d 0 I
1746 * e 1 O
1747 * f 1 O
1748 */
1749 .input = {{
1750 .type = CX88_VMUX_TELEVISION,
1751 .vmux = 0,
1752 .gpio0 = 0xc4bf,
1753 }, {
1754 .type = CX88_VMUX_COMPOSITE1,
1755 .vmux = 1,
1756 .gpio0 = 0xc4bf,
1757 }, {
1758 .type = CX88_VMUX_SVIDEO,
1759 .vmux = 2,
1760 .gpio0 = 0xc4bf,
1761 } },
1762 /* fixme: Add radio support */
1763 .mpeg = CX88_MPEG_DVB,
1764 },
1765 [CX88_BOARD_HAUPPAUGE_HVR4000LITE] = {
1766 .name = "Hauppauge WinTV-HVR4000(Lite) DVB-S/S2",
1767 .tuner_type = UNSET,
1768 .radio_type = UNSET,
1769 .tuner_addr = ADDR_UNSET,
1770 .radio_addr = ADDR_UNSET,
1771 .input = {{
1772 .type = CX88_VMUX_DVB,
1773 .vmux = 0,
1774 } },
1775 .mpeg = CX88_MPEG_DVB,
1776 },
1777 [CX88_BOARD_TEVII_S420] = {
1778 .name = "TeVii S420 DVB-S",
1779 .tuner_type = UNSET,
1780 .radio_type = UNSET,
1781 .tuner_addr = ADDR_UNSET,
1782 .radio_addr = ADDR_UNSET,
1783 .input = {{
1784 .type = CX88_VMUX_DVB,
1785 .vmux = 0,
1786 } },
1787 .mpeg = CX88_MPEG_DVB,
1788 },
1789 [CX88_BOARD_TEVII_S460] = {
1790 .name = "TeVii S460 DVB-S/S2",
1791 .tuner_type = UNSET,
1792 .radio_type = UNSET,
1793 .tuner_addr = ADDR_UNSET,
1794 .radio_addr = ADDR_UNSET,
1795 .input = {{
1796 .type = CX88_VMUX_DVB,
1797 .vmux = 0,
1798 } },
1799 .mpeg = CX88_MPEG_DVB,
1800 },
1801 [CX88_BOARD_OMICOM_SS4_PCI] = {
1802 .name = "Omicom SS4 DVB-S/S2 PCI",
1803 .tuner_type = UNSET,
1804 .radio_type = UNSET,
1805 .tuner_addr = ADDR_UNSET,
1806 .radio_addr = ADDR_UNSET,
1807 .input = {{
1808 .type = CX88_VMUX_DVB,
1809 .vmux = 0,
1810 } },
1811 .mpeg = CX88_MPEG_DVB,
1812 },
1813 [CX88_BOARD_TBS_8920] = {
1814 .name = "TBS 8920 DVB-S/S2",
1815 .tuner_type = TUNER_ABSENT,
1816 .radio_type = UNSET,
1817 .tuner_addr = ADDR_UNSET,
1818 .radio_addr = ADDR_UNSET,
1819 .input = {{
1820 .type = CX88_VMUX_DVB,
1821 .vmux = 1,
1822 } },
1823 .mpeg = CX88_MPEG_DVB,
1824 },
1825 [CX88_BOARD_PROF_7300] = {
1826 .name = "PROF 7300 DVB-S/S2",
1827 .tuner_type = UNSET,
1828 .radio_type = UNSET,
1829 .tuner_addr = ADDR_UNSET,
1830 .radio_addr = ADDR_UNSET,
1831 .input = {{
1832 .type = CX88_VMUX_DVB,
1833 .vmux = 0,
1834 } },
1835 .mpeg = CX88_MPEG_DVB,
1836 },
1667}; 1837};
1668 1838
1669/* ------------------------------------------------------------------ */ 1839/* ------------------------------------------------------------------ */
@@ -2010,9 +2180,53 @@ static const struct cx88_subid cx88_subids[] = {
2010 .subdevice = 0x4935, 2180 .subdevice = 0x4935,
2011 .card = CX88_BOARD_PROLINK_PV_8000GT, 2181 .card = CX88_BOARD_PROLINK_PV_8000GT,
2012 }, { 2182 }, {
2183 .subvendor = 0x1554,
2184 .subdevice = 0x4976,
2185 .card = CX88_BOARD_PROLINK_PV_GLOBAL_XTREME,
2186 }, {
2013 .subvendor = 0x17de, 2187 .subvendor = 0x17de,
2014 .subdevice = 0x08c1, 2188 .subdevice = 0x08c1,
2015 .card = CX88_BOARD_KWORLD_ATSC_120, 2189 .card = CX88_BOARD_KWORLD_ATSC_120,
2190 }, {
2191 .subvendor = 0x0070,
2192 .subdevice = 0x6900,
2193 .card = CX88_BOARD_HAUPPAUGE_HVR4000,
2194 }, {
2195 .subvendor = 0x0070,
2196 .subdevice = 0x6904,
2197 .card = CX88_BOARD_HAUPPAUGE_HVR4000,
2198 }, {
2199 .subvendor = 0x0070,
2200 .subdevice = 0x6902,
2201 .card = CX88_BOARD_HAUPPAUGE_HVR4000,
2202 }, {
2203 .subvendor = 0x0070,
2204 .subdevice = 0x6905,
2205 .card = CX88_BOARD_HAUPPAUGE_HVR4000LITE,
2206 }, {
2207 .subvendor = 0x0070,
2208 .subdevice = 0x6906,
2209 .card = CX88_BOARD_HAUPPAUGE_HVR4000LITE,
2210 }, {
2211 .subvendor = 0xd420,
2212 .subdevice = 0x9022,
2213 .card = CX88_BOARD_TEVII_S420,
2214 }, {
2215 .subvendor = 0xd460,
2216 .subdevice = 0x9022,
2217 .card = CX88_BOARD_TEVII_S460,
2218 }, {
2219 .subvendor = 0xA044,
2220 .subdevice = 0x2011,
2221 .card = CX88_BOARD_OMICOM_SS4_PCI,
2222 }, {
2223 .subvendor = 0x8920,
2224 .subdevice = 0x8888,
2225 .card = CX88_BOARD_TBS_8920,
2226 }, {
2227 .subvendor = 0xB033,
2228 .subdevice = 0x3033,
2229 .card = CX88_BOARD_PROF_7300,
2016 }, 2230 },
2017}; 2231};
2018 2232
@@ -2065,6 +2279,13 @@ static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data)
2065 case 14669: /* WinTV-HVR3000 (OEM, no IR, no b/panel video - Low profile) */ 2279 case 14669: /* WinTV-HVR3000 (OEM, no IR, no b/panel video - Low profile) */
2066 case 28552: /* WinTV-PVR 'Roslyn' (No IR) */ 2280 case 28552: /* WinTV-PVR 'Roslyn' (No IR) */
2067 case 34519: /* WinTV-PCI-FM */ 2281 case 34519: /* WinTV-PCI-FM */
2282 case 69009:
2283 /* WinTV-HVR4000 (DVBS/S2/T, Video and IR, back panel inputs) */
2284 case 69100: /* WinTV-HVR4000LITE (DVBS/S2, IR) */
2285 case 69500: /* WinTV-HVR4000LITE (DVBS/S2, No IR) */
2286 case 69559:
2287 /* WinTV-HVR4000 (DVBS/S2/T, Video no IR, back panel inputs) */
2288 case 69569: /* WinTV-HVR4000 (DVBS/S2/T, Video no IR) */
2068 case 90002: /* Nova-T-PCI (9002) */ 2289 case 90002: /* Nova-T-PCI (9002) */
2069 case 92001: /* Nova-S-Plus (Video and IR) */ 2290 case 92001: /* Nova-S-Plus (Video and IR) */
2070 case 92002: /* Nova-S-Plus (Video and IR) */ 2291 case 92002: /* Nova-S-Plus (Video and IR) */
@@ -2149,9 +2370,21 @@ static int cx88_dvico_xc2028_callback(struct cx88_core *core,
2149{ 2370{
2150 switch (command) { 2371 switch (command) {
2151 case XC2028_TUNER_RESET: 2372 case XC2028_TUNER_RESET:
2152 cx_write(MO_GP0_IO, 0x101000); 2373 switch (core->boardnr) {
2153 mdelay(5); 2374 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
2154 cx_set(MO_GP0_IO, 0x101010); 2375 /* GPIO-4 xc3028 tuner */
2376
2377 cx_set(MO_GP0_IO, 0x00001000);
2378 cx_clear(MO_GP0_IO, 0x00000010);
2379 msleep(100);
2380 cx_set(MO_GP0_IO, 0x00000010);
2381 msleep(100);
2382 break;
2383 default:
2384 cx_write(MO_GP0_IO, 0x101000);
2385 mdelay(5);
2386 cx_set(MO_GP0_IO, 0x101010);
2387 }
2155 break; 2388 break;
2156 default: 2389 default:
2157 return -EINVAL; 2390 return -EINVAL;
@@ -2258,8 +2491,10 @@ static int cx88_xc2028_tuner_callback(struct cx88_core *core,
2258 return cx88_xc3028_geniatech_tuner_callback(core, 2491 return cx88_xc3028_geniatech_tuner_callback(core,
2259 command, arg); 2492 command, arg);
2260 case CX88_BOARD_PROLINK_PV_8000GT: 2493 case CX88_BOARD_PROLINK_PV_8000GT:
2494 case CX88_BOARD_PROLINK_PV_GLOBAL_XTREME:
2261 return cx88_pv_8000gt_callback(core, command, arg); 2495 return cx88_pv_8000gt_callback(core, command, arg);
2262 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO: 2496 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO:
2497 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
2263 return cx88_dvico_xc2028_callback(core, command, arg); 2498 return cx88_dvico_xc2028_callback(core, command, arg);
2264 } 2499 }
2265 2500
@@ -2327,7 +2562,7 @@ static int cx88_xc5000_tuner_callback(struct cx88_core *core,
2327 return 0; /* Should never be here */ 2562 return 0; /* Should never be here */
2328} 2563}
2329 2564
2330int cx88_tuner_callback(void *priv, int command, int arg) 2565int cx88_tuner_callback(void *priv, int component, int command, int arg)
2331{ 2566{
2332 struct i2c_algo_bit_data *i2c_algo = priv; 2567 struct i2c_algo_bit_data *i2c_algo = priv;
2333 struct cx88_core *core; 2568 struct cx88_core *core;
@@ -2344,6 +2579,9 @@ int cx88_tuner_callback(void *priv, int command, int arg)
2344 return -EINVAL; 2579 return -EINVAL;
2345 } 2580 }
2346 2581
2582 if (component != DVB_FRONTEND_COMPONENT_TUNER)
2583 return -EINVAL;
2584
2347 switch (core->board.tuner_type) { 2585 switch (core->board.tuner_type) {
2348 case TUNER_XC2028: 2586 case TUNER_XC2028:
2349 info_printk(core, "Calling XC2028/3028 callback\n"); 2587 info_printk(core, "Calling XC2028/3028 callback\n");
@@ -2392,16 +2630,22 @@ static void cx88_card_setup_pre_i2c(struct cx88_core *core)
2392{ 2630{
2393 switch (core->boardnr) { 2631 switch (core->boardnr) {
2394 case CX88_BOARD_HAUPPAUGE_HVR1300: 2632 case CX88_BOARD_HAUPPAUGE_HVR1300:
2395 /* Bring the 702 demod up before i2c scanning/attach or devices are hidden */ 2633 /*
2396 /* We leave here with the 702 on the bus */ 2634 * Bring the 702 demod up before i2c scanning/attach or devices are hidden
2397 cx_write(MO_GP0_IO, 0x0000e780); 2635 * We leave here with the 702 on the bus
2636 *
2637 * "reset the IR receiver on GPIO[3]"
2638 * Reported by Mike Crash <mike AT mikecrash.com>
2639 */
2640 cx_write(MO_GP0_IO, 0x0000ef88);
2398 udelay(1000); 2641 udelay(1000);
2399 cx_clear(MO_GP0_IO, 0x00000080); 2642 cx_clear(MO_GP0_IO, 0x00000088);
2400 udelay(50); 2643 udelay(50);
2401 cx_set(MO_GP0_IO, 0x00000080); /* 702 out of reset */ 2644 cx_set(MO_GP0_IO, 0x00000088); /* 702 out of reset */
2402 udelay(1000); 2645 udelay(1000);
2403 break; 2646 break;
2404 2647
2648 case CX88_BOARD_PROLINK_PV_GLOBAL_XTREME:
2405 case CX88_BOARD_PROLINK_PV_8000GT: 2649 case CX88_BOARD_PROLINK_PV_8000GT:
2406 cx_write(MO_GP2_IO, 0xcf7); 2650 cx_write(MO_GP2_IO, 0xcf7);
2407 mdelay(50); 2651 mdelay(50);
@@ -2411,10 +2655,18 @@ static void cx88_card_setup_pre_i2c(struct cx88_core *core)
2411 msleep(10); 2655 msleep(10);
2412 break; 2656 break;
2413 2657
2414 case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD: 2658 case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD:
2415 /* Enable the xc5000 tuner */ 2659 /* Enable the xc5000 tuner */
2416 cx_set(MO_GP0_IO, 0x00001010); 2660 cx_set(MO_GP0_IO, 0x00001010);
2417 break; 2661 break;
2662
2663 case CX88_BOARD_HAUPPAUGE_HVR3000:
2664 case CX88_BOARD_HAUPPAUGE_HVR4000:
2665 case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
2666 /* Init GPIO */
2667 cx_write(MO_GP0_IO, core->board.input[0].gpio0);
2668 udelay(1000);
2669 break;
2418 } 2670 }
2419} 2671}
2420 2672
@@ -2435,17 +2687,22 @@ void cx88_setup_xc3028(struct cx88_core *core, struct xc2028_ctrl *ctl)
2435 core->i2c_algo.udelay = 16; 2687 core->i2c_algo.udelay = 16;
2436 break; 2688 break;
2437 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO: 2689 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO:
2438 ctl->scode_table = XC3028_FE_ZARLINK456; 2690 ctl->demod = XC3028_FE_ZARLINK456;
2439 break; 2691 break;
2440 case CX88_BOARD_KWORLD_ATSC_120: 2692 case CX88_BOARD_KWORLD_ATSC_120:
2441 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO: 2693 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
2442 ctl->demod = XC3028_FE_OREN538; 2694 ctl->demod = XC3028_FE_OREN538;
2443 break; 2695 break;
2696 case CX88_BOARD_PROLINK_PV_GLOBAL_XTREME:
2444 case CX88_BOARD_PROLINK_PV_8000GT: 2697 case CX88_BOARD_PROLINK_PV_8000GT:
2445 /* 2698 /*
2446 * This board uses non-MTS firmware 2699 * Those boards uses non-MTS firmware
2447 */ 2700 */
2448 break; 2701 break;
2702 case CX88_BOARD_PINNACLE_HYBRID_PCTV:
2703 ctl->demod = XC3028_FE_ZARLINK456;
2704 ctl->mts = 1;
2705 break;
2449 default: 2706 default:
2450 ctl->demod = XC3028_FE_OREN538; 2707 ctl->demod = XC3028_FE_OREN538;
2451 ctl->mts = 1; 2708 ctl->mts = 1;
@@ -2489,6 +2746,8 @@ static void cx88_card_setup(struct cx88_core *core)
2489 case CX88_BOARD_HAUPPAUGE_HVR1100LP: 2746 case CX88_BOARD_HAUPPAUGE_HVR1100LP:
2490 case CX88_BOARD_HAUPPAUGE_HVR3000: 2747 case CX88_BOARD_HAUPPAUGE_HVR3000:
2491 case CX88_BOARD_HAUPPAUGE_HVR1300: 2748 case CX88_BOARD_HAUPPAUGE_HVR1300:
2749 case CX88_BOARD_HAUPPAUGE_HVR4000:
2750 case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
2492 if (0 == core->i2c_rc) 2751 if (0 == core->i2c_rc)
2493 hauppauge_eeprom(core, eeprom); 2752 hauppauge_eeprom(core, eeprom);
2494 break; 2753 break;
@@ -2570,7 +2829,18 @@ static void cx88_card_setup(struct cx88_core *core)
2570 tea5767_cfg.priv = &ctl; 2829 tea5767_cfg.priv = &ctl;
2571 2830
2572 cx88_call_i2c_clients(core, TUNER_SET_CONFIG, &tea5767_cfg); 2831 cx88_call_i2c_clients(core, TUNER_SET_CONFIG, &tea5767_cfg);
2832 break;
2573 } 2833 }
2834 case CX88_BOARD_TEVII_S420:
2835 case CX88_BOARD_TEVII_S460:
2836 case CX88_BOARD_OMICOM_SS4_PCI:
2837 case CX88_BOARD_TBS_8920:
2838 case CX88_BOARD_PROF_7300:
2839 cx_write(MO_SRST_IO, 0);
2840 msleep(100);
2841 cx_write(MO_SRST_IO, 1);
2842 msleep(100);
2843 break;
2574 } /*end switch() */ 2844 } /*end switch() */
2575 2845
2576 2846
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index d96173ff1dba..344ed2626e59 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -48,6 +48,11 @@
48#include "tuner-simple.h" 48#include "tuner-simple.h"
49#include "tda9887.h" 49#include "tda9887.h"
50#include "s5h1411.h" 50#include "s5h1411.h"
51#include "stv0299.h"
52#include "z0194a.h"
53#include "stv0288.h"
54#include "stb6000.h"
55#include "cx24116.h"
51 56
52MODULE_DESCRIPTION("driver for cx2388x based DVB cards"); 57MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
53MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>"); 58MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
@@ -375,37 +380,28 @@ static int geniatech_dvbs_set_voltage(struct dvb_frontend *fe,
375 return 0; 380 return 0;
376} 381}
377 382
378static int cx88_pci_nano_callback(void *ptr, int command, int arg) 383static int tevii_dvbs_set_voltage(struct dvb_frontend *fe,
384 fe_sec_voltage_t voltage)
379{ 385{
380 struct cx88_core *core = ptr; 386 struct cx8802_dev *dev= fe->dvb->priv;
381 387 struct cx88_core *core = dev->core;
382 switch (command) {
383 case XC2028_TUNER_RESET:
384 /* Send the tuner in then out of reset */
385 dprintk(1, "%s: XC2028_TUNER_RESET %d\n", __func__, arg);
386
387 switch (core->boardnr) {
388 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
389 /* GPIO-4 xc3028 tuner */
390
391 cx_set(MO_GP0_IO, 0x00001000);
392 cx_clear(MO_GP0_IO, 0x00000010);
393 msleep(100);
394 cx_set(MO_GP0_IO, 0x00000010);
395 msleep(100);
396 break;
397 }
398 388
399 break; 389 switch (voltage) {
400 case XC2028_RESET_CLK: 390 case SEC_VOLTAGE_13:
401 dprintk(1, "%s: XC2028_RESET_CLK %d\n", __func__, arg); 391 printk("LNB Voltage SEC_VOLTAGE_13\n");
402 break; 392 cx_write(MO_GP0_IO, 0x00006040);
403 default: 393 break;
404 dprintk(1, "%s: unknown command %d, arg %d\n", __func__, 394 case SEC_VOLTAGE_18:
405 command, arg); 395 printk("LNB Voltage SEC_VOLTAGE_18\n");
406 return -EINVAL; 396 cx_write(MO_GP0_IO, 0x00006060);
397 break;
398 case SEC_VOLTAGE_OFF:
399 printk("LNB Voltage SEC_VOLTAGE_off\n");
400 break;
407 } 401 }
408 402
403 if (core->prev_set_voltage)
404 return core->prev_set_voltage(fe, voltage);
409 return 0; 405 return 0;
410} 406}
411 407
@@ -456,7 +452,12 @@ static struct s5h1409_config kworld_atsc_120_config = {
456static struct xc5000_config pinnacle_pctv_hd_800i_tuner_config = { 452static struct xc5000_config pinnacle_pctv_hd_800i_tuner_config = {
457 .i2c_address = 0x64, 453 .i2c_address = 0x64,
458 .if_khz = 5380, 454 .if_khz = 5380,
459 .tuner_callback = cx88_tuner_callback, 455};
456
457static struct zl10353_config cx88_pinnacle_hybrid_pctv = {
458 .demod_address = (0x1e >> 1),
459 .no_tuner = 1,
460 .if2 = 45600,
460}; 461};
461 462
462static struct zl10353_config cx88_geniatech_x8000_mt = { 463static struct zl10353_config cx88_geniatech_x8000_mt = {
@@ -477,7 +478,6 @@ static struct s5h1411_config dvico_fusionhdtv7_config = {
477static struct xc5000_config dvico_fusionhdtv7_tuner_config = { 478static struct xc5000_config dvico_fusionhdtv7_tuner_config = {
478 .i2c_address = 0xc2 >> 1, 479 .i2c_address = 0xc2 >> 1,
479 .if_khz = 5380, 480 .if_khz = 5380,
480 .tuner_callback = cx88_tuner_callback,
481}; 481};
482 482
483static int attach_xc3028(u8 addr, struct cx8802_dev *dev) 483static int attach_xc3028(u8 addr, struct cx8802_dev *dev)
@@ -488,7 +488,6 @@ static int attach_xc3028(u8 addr, struct cx8802_dev *dev)
488 .i2c_adap = &dev->core->i2c_adap, 488 .i2c_adap = &dev->core->i2c_adap,
489 .i2c_addr = addr, 489 .i2c_addr = addr,
490 .ctrl = &ctl, 490 .ctrl = &ctl,
491 .callback = cx88_tuner_callback,
492 }; 491 };
493 492
494 if (!dev->dvb.frontend) { 493 if (!dev->dvb.frontend) {
@@ -518,6 +517,60 @@ static int attach_xc3028(u8 addr, struct cx8802_dev *dev)
518 return 0; 517 return 0;
519} 518}
520 519
520static int cx24116_set_ts_param(struct dvb_frontend *fe,
521 int is_punctured)
522{
523 struct cx8802_dev *dev = fe->dvb->priv;
524 dev->ts_gen_cntrl = 0x2;
525
526 return 0;
527}
528
529static int cx24116_reset_device(struct dvb_frontend *fe)
530{
531 struct cx8802_dev *dev = fe->dvb->priv;
532 struct cx88_core *core = dev->core;
533
534 /* Reset the part */
535 cx_write(MO_SRST_IO, 0);
536 msleep(10);
537 cx_write(MO_SRST_IO, 1);
538 msleep(10);
539
540 return 0;
541}
542
543static struct cx24116_config hauppauge_hvr4000_config = {
544 .demod_address = 0x05,
545 .set_ts_params = cx24116_set_ts_param,
546 .reset_device = cx24116_reset_device,
547};
548
549static struct cx24116_config tevii_s460_config = {
550 .demod_address = 0x55,
551 .set_ts_params = cx24116_set_ts_param,
552 .reset_device = cx24116_reset_device,
553};
554
555static struct stv0299_config tevii_tuner_sharp_config = {
556 .demod_address = 0x68,
557 .inittab = sharp_z0194a__inittab,
558 .mclk = 88000000UL,
559 .invert = 1,
560 .skip_reinit = 0,
561 .lock_output = 1,
562 .volt13_op0_op1 = STV0299_VOLT13_OP1,
563 .min_delay_ms = 100,
564 .set_symbol_rate = sharp_z0194a__set_symbol_rate,
565 .set_ts_params = cx24116_set_ts_param,
566};
567
568static struct stv0288_config tevii_tuner_earda_config = {
569 .demod_address = 0x68,
570 .min_delay_ms = 100,
571 .set_ts_params = cx24116_set_ts_param,
572};
573
521static int dvb_register(struct cx8802_dev *dev) 574static int dvb_register(struct cx8802_dev *dev)
522{ 575{
523 struct cx88_core *core = dev->core; 576 struct cx88_core *core = dev->core;
@@ -786,7 +839,7 @@ static int dvb_register(struct cx8802_dev *dev)
786 &core->i2c_adap); 839 &core->i2c_adap);
787 if (dev->dvb.frontend) { 840 if (dev->dvb.frontend) {
788 if (!dvb_attach(isl6421_attach, dev->dvb.frontend, 841 if (!dvb_attach(isl6421_attach, dev->dvb.frontend,
789 &core->i2c_adap, 0x08, 0x00, 0x00)) 842 &core->i2c_adap, 0x08, ISL6421_DCL, 0x00))
790 goto frontend_detach; 843 goto frontend_detach;
791 } 844 }
792 break; 845 break;
@@ -813,13 +866,9 @@ static int dvb_register(struct cx8802_dev *dev)
813 &pinnacle_pctv_hd_800i_config, 866 &pinnacle_pctv_hd_800i_config,
814 &core->i2c_adap); 867 &core->i2c_adap);
815 if (dev->dvb.frontend != NULL) { 868 if (dev->dvb.frontend != NULL) {
816 /* tuner_config.video_dev must point to
817 * i2c_adap.algo_data
818 */
819 if (!dvb_attach(xc5000_attach, dev->dvb.frontend, 869 if (!dvb_attach(xc5000_attach, dev->dvb.frontend,
820 &core->i2c_adap, 870 &core->i2c_adap,
821 &pinnacle_pctv_hd_800i_tuner_config, 871 &pinnacle_pctv_hd_800i_tuner_config))
822 core->i2c_adap.algo_data))
823 goto frontend_detach; 872 goto frontend_detach;
824 } 873 }
825 break; 874 break;
@@ -832,10 +881,9 @@ static int dvb_register(struct cx8802_dev *dev)
832 struct xc2028_config cfg = { 881 struct xc2028_config cfg = {
833 .i2c_adap = &core->i2c_adap, 882 .i2c_adap = &core->i2c_adap,
834 .i2c_addr = 0x61, 883 .i2c_addr = 0x61,
835 .callback = cx88_pci_nano_callback,
836 }; 884 };
837 static struct xc2028_ctrl ctl = { 885 static struct xc2028_ctrl ctl = {
838 .fname = "xc3028-v27.fw", 886 .fname = XC2028_DEFAULT_FIRMWARE,
839 .max_len = 64, 887 .max_len = 64,
840 .scode_table = XC3028_FE_OREN538, 888 .scode_table = XC3028_FE_OREN538,
841 }; 889 };
@@ -848,10 +896,13 @@ static int dvb_register(struct cx8802_dev *dev)
848 break; 896 break;
849 case CX88_BOARD_PINNACLE_HYBRID_PCTV: 897 case CX88_BOARD_PINNACLE_HYBRID_PCTV:
850 dev->dvb.frontend = dvb_attach(zl10353_attach, 898 dev->dvb.frontend = dvb_attach(zl10353_attach,
851 &cx88_geniatech_x8000_mt, 899 &cx88_pinnacle_hybrid_pctv,
852 &core->i2c_adap); 900 &core->i2c_adap);
853 if (attach_xc3028(0x61, dev) < 0) 901 if (dev->dvb.frontend) {
854 goto frontend_detach; 902 dev->dvb.frontend->ops.i2c_gate_ctrl = NULL;
903 if (attach_xc3028(0x61, dev) < 0)
904 goto frontend_detach;
905 }
855 break; 906 break;
856 case CX88_BOARD_GENIATECH_X8000_MT: 907 case CX88_BOARD_GENIATECH_X8000_MT:
857 dev->ts_gen_cntrl = 0x00; 908 dev->ts_gen_cntrl = 0x00;
@@ -874,16 +925,69 @@ static int dvb_register(struct cx8802_dev *dev)
874 &dvico_fusionhdtv7_config, 925 &dvico_fusionhdtv7_config,
875 &core->i2c_adap); 926 &core->i2c_adap);
876 if (dev->dvb.frontend != NULL) { 927 if (dev->dvb.frontend != NULL) {
877 /* tuner_config.video_dev must point to
878 * i2c_adap.algo_data
879 */
880 if (!dvb_attach(xc5000_attach, dev->dvb.frontend, 928 if (!dvb_attach(xc5000_attach, dev->dvb.frontend,
881 &core->i2c_adap, 929 &core->i2c_adap,
882 &dvico_fusionhdtv7_tuner_config, 930 &dvico_fusionhdtv7_tuner_config))
883 core->i2c_adap.algo_data))
884 goto frontend_detach; 931 goto frontend_detach;
885 } 932 }
886 break; 933 break;
934 case CX88_BOARD_HAUPPAUGE_HVR4000:
935 case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
936 /* Support for DVB-S only, not DVB-T support */
937 dev->dvb.frontend = dvb_attach(cx24116_attach,
938 &hauppauge_hvr4000_config,
939 &dev->core->i2c_adap);
940 if (dev->dvb.frontend) {
941 dvb_attach(isl6421_attach, dev->dvb.frontend,
942 &dev->core->i2c_adap,
943 0x08, ISL6421_DCL, 0x00);
944 }
945 break;
946 case CX88_BOARD_TEVII_S420:
947 dev->dvb.frontend = dvb_attach(stv0299_attach,
948 &tevii_tuner_sharp_config,
949 &core->i2c_adap);
950 if (dev->dvb.frontend != NULL) {
951 if (!dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
952 &core->i2c_adap, DVB_PLL_OPERA1))
953 goto frontend_detach;
954 core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
955 dev->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
956
957 } else {
958 dev->dvb.frontend = dvb_attach(stv0288_attach,
959 &tevii_tuner_earda_config,
960 &core->i2c_adap);
961 if (dev->dvb.frontend != NULL) {
962 if (!dvb_attach(stb6000_attach, dev->dvb.frontend, 0x61,
963 &core->i2c_adap))
964 goto frontend_detach;
965 core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
966 dev->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
967
968 }
969 }
970 break;
971 case CX88_BOARD_TEVII_S460:
972 dev->dvb.frontend = dvb_attach(cx24116_attach,
973 &tevii_s460_config,
974 &core->i2c_adap);
975 if (dev->dvb.frontend != NULL) {
976 core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
977 dev->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
978 }
979 break;
980 case CX88_BOARD_OMICOM_SS4_PCI:
981 case CX88_BOARD_TBS_8920:
982 case CX88_BOARD_PROF_7300:
983 dev->dvb.frontend = dvb_attach(cx24116_attach,
984 &hauppauge_hvr4000_config,
985 &core->i2c_adap);
986 if (dev->dvb.frontend != NULL) {
987 core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
988 dev->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
989 }
990 break;
887 default: 991 default:
888 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n", 992 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n",
889 core->name); 993 core->name);
@@ -895,6 +999,8 @@ static int dvb_register(struct cx8802_dev *dev)
895 core->name); 999 core->name);
896 return -EINVAL; 1000 return -EINVAL;
897 } 1001 }
1002 /* define general-purpose callback pointer */
1003 dev->dvb.frontend->callback = cx88_tuner_callback;
898 1004
899 /* Ensure all frontends negotiate bus access */ 1005 /* Ensure all frontends negotiate bus access */
900 dev->dvb.frontend->ops.ts_bus_ctrl = cx88_dvb_bus_ctrl; 1006 dev->dvb.frontend->ops.ts_bus_ctrl = cx88_dvb_bus_ctrl;
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index d7406a994f09..8e74d64fdcd2 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -201,7 +201,23 @@ int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci)
201 201
202 core->i2c_rc = i2c_bit_add_bus(&core->i2c_adap); 202 core->i2c_rc = i2c_bit_add_bus(&core->i2c_adap);
203 if (0 == core->i2c_rc) { 203 if (0 == core->i2c_rc) {
204 static u8 tuner_data[] =
205 { 0x0b, 0xdc, 0x86, 0x52 };
206 static struct i2c_msg tuner_msg =
207 { .flags = 0, .addr = 0xc2 >> 1, .buf = tuner_data, .len = 4 };
208
204 dprintk(1, "i2c register ok\n"); 209 dprintk(1, "i2c register ok\n");
210 switch( core->boardnr ) {
211 case CX88_BOARD_HAUPPAUGE_HVR1300:
212 case CX88_BOARD_HAUPPAUGE_HVR3000:
213 case CX88_BOARD_HAUPPAUGE_HVR4000:
214 printk("%s: i2c init: enabling analog demod on HVR1300/3000/4000 tuner\n",
215 core->name);
216 i2c_transfer(core->i2c_client.adapter, &tuner_msg, 1);
217 break;
218 default:
219 break;
220 }
205 if (i2c_scan) 221 if (i2c_scan)
206 do_i2c_scan(core->name,&core->i2c_client); 222 do_i2c_scan(core->name,&core->i2c_client);
207 } else 223 } else
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index 53526d997a4e..8683d104de72 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -224,6 +224,8 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
224 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1: 224 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
225 case CX88_BOARD_HAUPPAUGE_HVR1100: 225 case CX88_BOARD_HAUPPAUGE_HVR1100:
226 case CX88_BOARD_HAUPPAUGE_HVR3000: 226 case CX88_BOARD_HAUPPAUGE_HVR3000:
227 case CX88_BOARD_HAUPPAUGE_HVR4000:
228 case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
227 ir_codes = ir_codes_hauppauge_new; 229 ir_codes = ir_codes_hauppauge_new;
228 ir_type = IR_TYPE_RC5; 230 ir_type = IR_TYPE_RC5;
229 ir->sampling = 1; 231 ir->sampling = 1;
@@ -259,6 +261,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
259 ir->polling = 1; /* ms */ 261 ir->polling = 1; /* ms */
260 break; 262 break;
261 case CX88_BOARD_PROLINK_PV_8000GT: 263 case CX88_BOARD_PROLINK_PV_8000GT:
264 case CX88_BOARD_PROLINK_PV_GLOBAL_XTREME:
262 ir_codes = ir_codes_pixelview_new; 265 ir_codes = ir_codes_pixelview_new;
263 ir->gpio_addr = MO_GP1_IO; 266 ir->gpio_addr = MO_GP1_IO;
264 ir->mask_keycode = 0x3f; 267 ir->mask_keycode = 0x3f;
@@ -392,7 +395,7 @@ void cx88_ir_irq(struct cx88_core *core)
392{ 395{
393 struct cx88_IR *ir = core->ir; 396 struct cx88_IR *ir = core->ir;
394 u32 samples, ircode; 397 u32 samples, ircode;
395 int i; 398 int i, start, range, toggle, dev, code;
396 399
397 if (NULL == ir) 400 if (NULL == ir)
398 return; 401 return;
@@ -461,6 +464,34 @@ void cx88_ir_irq(struct cx88_core *core)
461 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1: 464 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
462 case CX88_BOARD_HAUPPAUGE_HVR1100: 465 case CX88_BOARD_HAUPPAUGE_HVR1100:
463 case CX88_BOARD_HAUPPAUGE_HVR3000: 466 case CX88_BOARD_HAUPPAUGE_HVR3000:
467 case CX88_BOARD_HAUPPAUGE_HVR4000:
468 case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
469 ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
470 ir_dprintk("biphase decoded: %x\n", ircode);
471 /*
472 * RC5 has an extension bit which adds a new range
473 * of available codes, this is detected here. Also
474 * hauppauge remotes (black/silver) always use
475 * specific device ids. If we do not filter the
476 * device ids then messages destined for devices
477 * such as TVs (id=0) will get through to the
478 * device causing mis-fired events.
479 */
480 /* split rc5 data block ... */
481 start = (ircode & 0x2000) >> 13;
482 range = (ircode & 0x1000) >> 12;
483 toggle= (ircode & 0x0800) >> 11;
484 dev = (ircode & 0x07c0) >> 6;
485 code = (ircode & 0x003f) | ((range << 6) ^ 0x0040);
486 if( start != 1)
487 /* no key pressed */
488 break;
489 if ( dev != 0x1e && dev != 0x1f )
490 /* not a hauppauge remote */
491 break;
492 ir_input_keydown(ir->input, &ir->ir, code, ircode);
493 ir->release = jiffies + msecs_to_jiffies(120);
494 break;
464 case CX88_BOARD_PINNACLE_PCTV_HD_800i: 495 case CX88_BOARD_PINNACLE_PCTV_HD_800i:
465 ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7); 496 ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
466 ir_dprintk("biphase decoded: %x\n", ircode); 497 ir_dprintk("biphase decoded: %x\n", ircode);
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index ef4d56ea0027..be45955dff68 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -773,6 +773,7 @@ static int video_open(struct inode *inode, struct file *file)
773 enum v4l2_buf_type type = 0; 773 enum v4l2_buf_type type = 0;
774 int radio = 0; 774 int radio = 0;
775 775
776 lock_kernel();
776 list_for_each_entry(h, &cx8800_devlist, devlist) { 777 list_for_each_entry(h, &cx8800_devlist, devlist) {
777 if (h->video_dev->minor == minor) { 778 if (h->video_dev->minor == minor) {
778 dev = h; 779 dev = h;
@@ -788,8 +789,10 @@ static int video_open(struct inode *inode, struct file *file)
788 dev = h; 789 dev = h;
789 } 790 }
790 } 791 }
791 if (NULL == dev) 792 if (NULL == dev) {
793 unlock_kernel();
792 return -ENODEV; 794 return -ENODEV;
795 }
793 796
794 core = dev->core; 797 core = dev->core;
795 798
@@ -798,8 +801,10 @@ static int video_open(struct inode *inode, struct file *file)
798 801
799 /* allocate + initialize per filehandle data */ 802 /* allocate + initialize per filehandle data */
800 fh = kzalloc(sizeof(*fh),GFP_KERNEL); 803 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
801 if (NULL == fh) 804 if (NULL == fh) {
805 unlock_kernel();
802 return -ENOMEM; 806 return -ENOMEM;
807 }
803 file->private_data = fh; 808 file->private_data = fh;
804 fh->dev = dev; 809 fh->dev = dev;
805 fh->radio = radio; 810 fh->radio = radio;
@@ -832,6 +837,9 @@ static int video_open(struct inode *inode, struct file *file)
832 cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1); 837 cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1);
833 cx88_call_i2c_clients(core,AUDC_SET_RADIO,NULL); 838 cx88_call_i2c_clients(core,AUDC_SET_RADIO,NULL);
834 } 839 }
840 unlock_kernel();
841
842 atomic_inc(&core->users);
835 843
836 return 0; 844 return 0;
837} 845}
@@ -920,7 +928,8 @@ static int video_release(struct inode *inode, struct file *file)
920 file->private_data = NULL; 928 file->private_data = NULL;
921 kfree(fh); 929 kfree(fh);
922 930
923 cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL); 931 if(atomic_dec_and_test(&dev->core->users))
932 cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
924 933
925 return 0; 934 return 0;
926} 935}
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index 54fe65094711..dbf01b8b57a5 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -221,6 +221,14 @@ extern struct sram_channel cx88_sram_channels[];
221#define CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD 65 221#define CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD 65
222#define CX88_BOARD_PROLINK_PV_8000GT 66 222#define CX88_BOARD_PROLINK_PV_8000GT 66
223#define CX88_BOARD_KWORLD_ATSC_120 67 223#define CX88_BOARD_KWORLD_ATSC_120 67
224#define CX88_BOARD_HAUPPAUGE_HVR4000 68
225#define CX88_BOARD_HAUPPAUGE_HVR4000LITE 69
226#define CX88_BOARD_TEVII_S460 70
227#define CX88_BOARD_OMICOM_SS4_PCI 71
228#define CX88_BOARD_TBS_8920 72
229#define CX88_BOARD_TEVII_S420 73
230#define CX88_BOARD_PROLINK_PV_GLOBAL_XTREME 74
231#define CX88_BOARD_PROF_7300 75
224 232
225enum cx88_itype { 233enum cx88_itype {
226 CX88_VMUX_COMPOSITE1 = 1, 234 CX88_VMUX_COMPOSITE1 = 1,
@@ -342,6 +350,7 @@ struct cx88_core {
342 struct mutex lock; 350 struct mutex lock;
343 /* various v4l controls */ 351 /* various v4l controls */
344 u32 freq; 352 u32 freq;
353 atomic_t users;
345 354
346 /* cx88-video needs to access cx8802 for hybrid tuner pll access. */ 355 /* cx88-video needs to access cx8802 for hybrid tuner pll access. */
347 struct cx8802_dev *dvbdev; 356 struct cx8802_dev *dvbdev;
@@ -601,7 +610,7 @@ extern void cx88_call_i2c_clients(struct cx88_core *core,
601/* ----------------------------------------------------------- */ 610/* ----------------------------------------------------------- */
602/* cx88-cards.c */ 611/* cx88-cards.c */
603 612
604extern int cx88_tuner_callback(void *dev, int command, int arg); 613extern int cx88_tuner_callback(void *dev, int component, int command, int arg);
605extern int cx88_get_resources(const struct cx88_core *core, 614extern int cx88_get_resources(const struct cx88_core *core,
606 struct pci_dev *pci); 615 struct pci_dev *pci);
607extern struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr); 616extern struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr);
diff --git a/drivers/media/video/dabusb.c b/drivers/media/video/dabusb.c
index 79faedf58521..3aa538afcc0b 100644
--- a/drivers/media/video/dabusb.c
+++ b/drivers/media/video/dabusb.c
@@ -866,7 +866,8 @@ static int __init dabusb_init (void)
866 866
867 dbg("dabusb_init: driver registered"); 867 dbg("dabusb_init: driver registered");
868 868
869 info(DRIVER_VERSION ":" DRIVER_DESC); 869 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
870 DRIVER_DESC "\n");
870 871
871out: 872out:
872 return retval; 873 return retval;
diff --git a/drivers/media/video/dpc7146.c b/drivers/media/video/dpc7146.c
deleted file mode 100644
index 88d6df71d051..000000000000
--- a/drivers/media/video/dpc7146.c
+++ /dev/null
@@ -1,408 +0,0 @@
1/*
2 dpc7146.c - v4l2 driver for the dpc7146 demonstration board
3
4 Copyright (C) 2000-2003 Michael Hunold <michael@mihu.de>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#define DEBUG_VARIABLE debug
22
23#include <media/saa7146_vv.h>
24#include <linux/video_decoder.h> /* for saa7111a */
25
26#define I2C_SAA7111A 0x24
27
28/* All unused bytes are reserverd. */
29#define SAA711X_CHIP_VERSION 0x00
30#define SAA711X_ANALOG_INPUT_CONTROL_1 0x02
31#define SAA711X_ANALOG_INPUT_CONTROL_2 0x03
32#define SAA711X_ANALOG_INPUT_CONTROL_3 0x04
33#define SAA711X_ANALOG_INPUT_CONTROL_4 0x05
34#define SAA711X_HORIZONTAL_SYNC_START 0x06
35#define SAA711X_HORIZONTAL_SYNC_STOP 0x07
36#define SAA711X_SYNC_CONTROL 0x08
37#define SAA711X_LUMINANCE_CONTROL 0x09
38#define SAA711X_LUMINANCE_BRIGHTNESS 0x0A
39#define SAA711X_LUMINANCE_CONTRAST 0x0B
40#define SAA711X_CHROMA_SATURATION 0x0C
41#define SAA711X_CHROMA_HUE_CONTROL 0x0D
42#define SAA711X_CHROMA_CONTROL 0x0E
43#define SAA711X_FORMAT_DELAY_CONTROL 0x10
44#define SAA711X_OUTPUT_CONTROL_1 0x11
45#define SAA711X_OUTPUT_CONTROL_2 0x12
46#define SAA711X_OUTPUT_CONTROL_3 0x13
47#define SAA711X_V_GATE_1_START 0x15
48#define SAA711X_V_GATE_1_STOP 0x16
49#define SAA711X_V_GATE_1_MSB 0x17
50#define SAA711X_TEXT_SLICER_STATUS 0x1A
51#define SAA711X_DECODED_BYTES_OF_TS_1 0x1B
52#define SAA711X_DECODED_BYTES_OF_TS_2 0x1C
53#define SAA711X_STATUS_BYTE 0x1F
54
55#define DPC_BOARD_CAN_DO_VBI(dev) (dev->revision != 0)
56
57static int debug;
58module_param(debug, int, 0);
59MODULE_PARM_DESC(debug, "debug verbosity");
60
61static int dpc_num;
62
63#define DPC_INPUTS 2
64static struct v4l2_input dpc_inputs[DPC_INPUTS] = {
65 { 0, "Port A", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 },
66 { 1, "Port B", V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 },
67};
68
69#define DPC_AUDIOS 0
70
71static struct saa7146_extension_ioctls ioctls[] = {
72 { VIDIOC_G_INPUT, SAA7146_EXCLUSIVE },
73 { VIDIOC_S_INPUT, SAA7146_EXCLUSIVE },
74 { VIDIOC_ENUMINPUT, SAA7146_EXCLUSIVE },
75 { VIDIOC_S_STD, SAA7146_AFTER },
76 { 0, 0 }
77};
78
79struct dpc
80{
81 struct video_device *video_dev;
82 struct video_device *vbi_dev;
83
84 struct i2c_adapter i2c_adapter;
85 struct i2c_client *saa7111a;
86
87 int cur_input; /* current input */
88};
89
90static int dpc_check_clients(struct device *dev, void *data)
91{
92 struct dpc* dpc = data;
93 struct i2c_client *client = i2c_verify_client(dev);
94
95 if( !client )
96 return 0;
97
98 if( I2C_SAA7111A == client->addr )
99 dpc->saa7111a = client;
100
101 return 0;
102}
103
104/* fixme: add vbi stuff here */
105static int dpc_probe(struct saa7146_dev* dev)
106{
107 struct dpc* dpc = NULL;
108
109 dpc = kzalloc(sizeof(struct dpc), GFP_KERNEL);
110 if( NULL == dpc ) {
111 printk("dpc_v4l2.o: dpc_probe: not enough kernel memory.\n");
112 return -ENOMEM;
113 }
114
115 /* FIXME: enable i2c-port pins, video-port-pins
116 video port pins should be enabled here ?! */
117 saa7146_write(dev, MC1, (MASK_08 | MASK_24 | MASK_10 | MASK_26));
118
119 dpc->i2c_adapter = (struct i2c_adapter) {
120 .class = I2C_CLASS_TV_ANALOG,
121 .name = "dpc7146",
122 };
123 saa7146_i2c_adapter_prepare(dev, &dpc->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
124 if(i2c_add_adapter(&dpc->i2c_adapter) < 0) {
125 DEB_S(("cannot register i2c-device. skipping.\n"));
126 kfree(dpc);
127 return -EFAULT;
128 }
129
130 /* loop through all i2c-devices on the bus and look who is there */
131 device_for_each_child(&dpc->i2c_adapter.dev, dpc, dpc_check_clients);
132
133 /* check if all devices are present */
134 if (!dpc->saa7111a) {
135 DEB_D(("dpc_v4l2.o: dpc_attach failed for this device.\n"));
136 i2c_del_adapter(&dpc->i2c_adapter);
137 kfree(dpc);
138 return -ENODEV;
139 }
140
141 /* all devices are present, probe was successful */
142 DEB_D(("dpc_v4l2.o: dpc_probe succeeded for this device.\n"));
143
144 /* we store the pointer in our private data field */
145 dev->ext_priv = dpc;
146
147 return 0;
148}
149
150/* bring hardware to a sane state. this has to be done, just in case someone
151 wants to capture from this device before it has been properly initialized.
152 the capture engine would badly fail, because no valid signal arrives on the
153 saa7146, thus leading to timeouts and stuff. */
154static int dpc_init_done(struct saa7146_dev* dev)
155{
156 struct dpc* dpc = (struct dpc*)dev->ext_priv;
157
158 DEB_D(("dpc_v4l2.o: dpc_init_done called.\n"));
159
160 /* initialize the helper ics to useful values */
161 i2c_smbus_write_byte_data(dpc->saa7111a, 0x00, 0x11);
162
163 i2c_smbus_write_byte_data(dpc->saa7111a, 0x02, 0xc0);
164 i2c_smbus_write_byte_data(dpc->saa7111a, 0x03, 0x30);
165 i2c_smbus_write_byte_data(dpc->saa7111a, 0x04, 0x00);
166 i2c_smbus_write_byte_data(dpc->saa7111a, 0x05, 0x00);
167 i2c_smbus_write_byte_data(dpc->saa7111a, 0x06, 0xde);
168 i2c_smbus_write_byte_data(dpc->saa7111a, 0x07, 0xad);
169 i2c_smbus_write_byte_data(dpc->saa7111a, 0x08, 0xa8);
170 i2c_smbus_write_byte_data(dpc->saa7111a, 0x09, 0x00);
171 i2c_smbus_write_byte_data(dpc->saa7111a, 0x0a, 0x80);
172 i2c_smbus_write_byte_data(dpc->saa7111a, 0x0b, 0x47);
173 i2c_smbus_write_byte_data(dpc->saa7111a, 0x0c, 0x40);
174 i2c_smbus_write_byte_data(dpc->saa7111a, 0x0d, 0x00);
175 i2c_smbus_write_byte_data(dpc->saa7111a, 0x0e, 0x03);
176
177 i2c_smbus_write_byte_data(dpc->saa7111a, 0x10, 0xd0);
178 i2c_smbus_write_byte_data(dpc->saa7111a, 0x11, 0x1c);
179 i2c_smbus_write_byte_data(dpc->saa7111a, 0x12, 0xc1);
180 i2c_smbus_write_byte_data(dpc->saa7111a, 0x13, 0x30);
181
182 i2c_smbus_write_byte_data(dpc->saa7111a, 0x1f, 0x81);
183
184 return 0;
185}
186
187static struct saa7146_ext_vv vv_data;
188
189/* this function only gets called when the probing was successful */
190static int dpc_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_data *info)
191{
192 struct dpc* dpc = (struct dpc*)dev->ext_priv;
193
194 DEB_D(("dpc_v4l2.o: dpc_attach called.\n"));
195
196 /* checking for i2c-devices can be omitted here, because we
197 already did this in "dpc_vl42_probe" */
198
199 saa7146_vv_init(dev,&vv_data);
200 if( 0 != saa7146_register_device(&dpc->video_dev, dev, "dpc", VFL_TYPE_GRABBER)) {
201 ERR(("cannot register capture v4l2 device. skipping.\n"));
202 return -1;
203 }
204
205 /* initialization stuff (vbi) (only for revision > 0 and for extensions which want it)*/
206 if( 0 != DPC_BOARD_CAN_DO_VBI(dev)) {
207 if( 0 != saa7146_register_device(&dpc->vbi_dev, dev, "dpc", VFL_TYPE_VBI)) {
208 ERR(("cannot register vbi v4l2 device. skipping.\n"));
209 }
210 }
211
212 i2c_use_client(dpc->saa7111a);
213
214 printk("dpc: found 'dpc7146 demonstration board'-%d.\n",dpc_num);
215 dpc_num++;
216
217 /* the rest */
218 dpc->cur_input = 0;
219 dpc_init_done(dev);
220
221 return 0;
222}
223
224static int dpc_detach(struct saa7146_dev* dev)
225{
226 struct dpc* dpc = (struct dpc*)dev->ext_priv;
227
228 DEB_EE(("dev:%p\n",dev));
229
230 i2c_release_client(dpc->saa7111a);
231
232 saa7146_unregister_device(&dpc->video_dev,dev);
233 if( 0 != DPC_BOARD_CAN_DO_VBI(dev)) {
234 saa7146_unregister_device(&dpc->vbi_dev,dev);
235 }
236 saa7146_vv_release(dev);
237
238 dpc_num--;
239
240 i2c_del_adapter(&dpc->i2c_adapter);
241 kfree(dpc);
242 return 0;
243}
244
245#ifdef axa
246int dpc_vbi_bypass(struct saa7146_dev* dev)
247{
248 struct dpc* dpc = (struct dpc*)dev->ext_priv;
249
250 int i = 1;
251
252 /* switch bypass in saa7111a */
253 if ( 0 != dpc->saa7111a->driver->command(dpc->saa7111a,SAA711X_VBI_BYPASS, &i)) {
254 printk("dpc_v4l2.o: VBI_BYPASS: could not address saa7111a.\n");
255 return -1;
256 }
257
258 return 0;
259}
260#endif
261
262static int dpc_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
263{
264 struct saa7146_dev *dev = fh->dev;
265 struct dpc* dpc = (struct dpc*)dev->ext_priv;
266/*
267 struct saa7146_vv *vv = dev->vv_data;
268*/
269 switch(cmd)
270 {
271 case VIDIOC_ENUMINPUT:
272 {
273 struct v4l2_input *i = arg;
274 DEB_EE(("VIDIOC_ENUMINPUT %d.\n",i->index));
275
276 if( i->index < 0 || i->index >= DPC_INPUTS) {
277 return -EINVAL;
278 }
279
280 memcpy(i, &dpc_inputs[i->index], sizeof(struct v4l2_input));
281
282 DEB_D(("dpc_v4l2.o: v4l2_ioctl: VIDIOC_ENUMINPUT %d.\n",i->index));
283 return 0;
284 }
285 case VIDIOC_G_INPUT:
286 {
287 int *input = (int *)arg;
288 *input = dpc->cur_input;
289
290 DEB_D(("dpc_v4l2.o: VIDIOC_G_INPUT: %d\n",*input));
291 return 0;
292 }
293 case VIDIOC_S_INPUT:
294 {
295 int input = *(int *)arg;
296
297 if (input < 0 || input >= DPC_INPUTS) {
298 return -EINVAL;
299 }
300
301 dpc->cur_input = input;
302
303 /* fixme: switch input here, switch audio, too! */
304// saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source, input_port_selection[input].hps_sync);
305 printk("dpc_v4l2.o: VIDIOC_S_INPUT: fixme switch input.\n");
306
307 return 0;
308 }
309 default:
310/*
311 DEB_D(("dpc_v4l2.o: v4l2_ioctl does not handle this ioctl.\n"));
312*/
313 return -ENOIOCTLCMD;
314 }
315 return 0;
316}
317
318static int std_callback(struct saa7146_dev* dev, struct saa7146_standard *std)
319{
320 return 0;
321}
322
323static struct saa7146_standard standard[] = {
324 {
325 .name = "PAL", .id = V4L2_STD_PAL,
326 .v_offset = 0x17, .v_field = 288,
327 .h_offset = 0x14, .h_pixels = 680,
328 .v_max_out = 576, .h_max_out = 768,
329 }, {
330 .name = "NTSC", .id = V4L2_STD_NTSC,
331 .v_offset = 0x16, .v_field = 240,
332 .h_offset = 0x06, .h_pixels = 708,
333 .v_max_out = 480, .h_max_out = 640,
334 }, {
335 .name = "SECAM", .id = V4L2_STD_SECAM,
336 .v_offset = 0x14, .v_field = 288,
337 .h_offset = 0x14, .h_pixels = 720,
338 .v_max_out = 576, .h_max_out = 768,
339 }
340};
341
342static struct saa7146_extension extension;
343
344static struct saa7146_pci_extension_data dpc = {
345 .ext_priv = "Multimedia eXtension Board",
346 .ext = &extension,
347};
348
349static struct pci_device_id pci_tbl[] = {
350 {
351 .vendor = PCI_VENDOR_ID_PHILIPS,
352 .device = PCI_DEVICE_ID_PHILIPS_SAA7146,
353 .subvendor = 0x0000,
354 .subdevice = 0x0000,
355 .driver_data = (unsigned long)&dpc,
356 }, {
357 .vendor = 0,
358 }
359};
360
361MODULE_DEVICE_TABLE(pci, pci_tbl);
362
363static struct saa7146_ext_vv vv_data = {
364 .inputs = DPC_INPUTS,
365 .capabilities = V4L2_CAP_VBI_CAPTURE,
366 .stds = &standard[0],
367 .num_stds = sizeof(standard)/sizeof(struct saa7146_standard),
368 .std_callback = &std_callback,
369 .ioctls = &ioctls[0],
370 .ioctl = dpc_ioctl,
371};
372
373static struct saa7146_extension extension = {
374 .name = "dpc7146 demonstration board",
375 .flags = SAA7146_USE_I2C_IRQ,
376
377 .pci_tbl = &pci_tbl[0],
378 .module = THIS_MODULE,
379
380 .probe = dpc_probe,
381 .attach = dpc_attach,
382 .detach = dpc_detach,
383
384 .irq_mask = 0,
385 .irq_func = NULL,
386};
387
388static int __init dpc_init_module(void)
389{
390 if( 0 != saa7146_register_extension(&extension)) {
391 DEB_S(("failed to register extension.\n"));
392 return -ENODEV;
393 }
394
395 return 0;
396}
397
398static void __exit dpc_cleanup_module(void)
399{
400 saa7146_unregister_extension(&extension);
401}
402
403module_init(dpc_init_module);
404module_exit(dpc_cleanup_module);
405
406MODULE_DESCRIPTION("video4linux-2 driver for the 'dpc7146 demonstration board'");
407MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
408MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index de943cf6c169..d65d0572403b 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -1101,7 +1101,7 @@ struct usb_device_id em28xx_id_table [] = {
1101 { USB_DEVICE(0xeb1a, 0x2820), 1101 { USB_DEVICE(0xeb1a, 0x2820),
1102 .driver_info = EM2820_BOARD_UNKNOWN }, 1102 .driver_info = EM2820_BOARD_UNKNOWN },
1103 { USB_DEVICE(0xeb1a, 0x2821), 1103 { USB_DEVICE(0xeb1a, 0x2821),
1104 .driver_info = EM2820_BOARD_UNKNOWN }, 1104 .driver_info = EM2820_BOARD_PROLINK_PLAYTV_USB2 },
1105 { USB_DEVICE(0xeb1a, 0x2860), 1105 { USB_DEVICE(0xeb1a, 0x2860),
1106 .driver_info = EM2820_BOARD_UNKNOWN }, 1106 .driver_info = EM2820_BOARD_UNKNOWN },
1107 { USB_DEVICE(0xeb1a, 0x2861), 1107 { USB_DEVICE(0xeb1a, 0x2861),
@@ -1271,7 +1271,7 @@ static struct em28xx_hash_table em28xx_i2c_hash[] = {
1271 {0x1ba50080, EM2860_BOARD_POINTNIX_INTRAORAL_CAMERA, TUNER_ABSENT}, 1271 {0x1ba50080, EM2860_BOARD_POINTNIX_INTRAORAL_CAMERA, TUNER_ABSENT},
1272}; 1272};
1273 1273
1274int em28xx_tuner_callback(void *ptr, int command, int arg) 1274int em28xx_tuner_callback(void *ptr, int component, int command, int arg)
1275{ 1275{
1276 int rc = 0; 1276 int rc = 0;
1277 struct em28xx *dev = ptr; 1277 struct em28xx *dev = ptr;
diff --git a/drivers/media/video/em28xx/em28xx-dvb.c b/drivers/media/video/em28xx/em28xx-dvb.c
index d2b1a1a52689..c99e2383b7ec 100644
--- a/drivers/media/video/em28xx/em28xx-dvb.c
+++ b/drivers/media/video/em28xx/em28xx-dvb.c
@@ -249,7 +249,6 @@ static int attach_xc3028(u8 addr, struct em28xx *dev)
249 memset(&cfg, 0, sizeof(cfg)); 249 memset(&cfg, 0, sizeof(cfg));
250 cfg.i2c_adap = &dev->i2c_adap; 250 cfg.i2c_adap = &dev->i2c_adap;
251 cfg.i2c_addr = addr; 251 cfg.i2c_addr = addr;
252 cfg.callback = em28xx_tuner_callback;
253 252
254 if (!dev->dvb->frontend) { 253 if (!dev->dvb->frontend) {
255 printk(KERN_ERR "%s/2: dvb frontend not attached. " 254 printk(KERN_ERR "%s/2: dvb frontend not attached. "
@@ -274,7 +273,7 @@ static int attach_xc3028(u8 addr, struct em28xx *dev)
274 273
275/* ------------------------------------------------------------------ */ 274/* ------------------------------------------------------------------ */
276 275
277int register_dvb(struct em28xx_dvb *dvb, 276static int register_dvb(struct em28xx_dvb *dvb,
278 struct module *module, 277 struct module *module,
279 struct em28xx *dev, 278 struct em28xx *dev,
280 struct device *device) 279 struct device *device)
@@ -422,6 +421,8 @@ static int dvb_init(struct em28xx *dev)
422 } 421 }
423 break; 422 break;
424 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: 423 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
424 case EM2880_BOARD_TERRATEC_HYBRID_XS:
425 case EM2880_BOARD_KWORLD_DVB_310U:
425 dvb->frontend = dvb_attach(zl10353_attach, 426 dvb->frontend = dvb_attach(zl10353_attach,
426 &em28xx_zl10353_with_xc3028, 427 &em28xx_zl10353_with_xc3028,
427 &dev->i2c_adap); 428 &dev->i2c_adap);
@@ -443,24 +444,6 @@ static int dvb_init(struct em28xx *dev)
443 } 444 }
444 break; 445 break;
445#endif 446#endif
446 case EM2880_BOARD_TERRATEC_HYBRID_XS:
447 dvb->frontend = dvb_attach(zl10353_attach,
448 &em28xx_zl10353_with_xc3028,
449 &dev->i2c_adap);
450 if (attach_xc3028(0x61, dev) < 0) {
451 result = -EINVAL;
452 goto out_free;
453 }
454 break;
455 case EM2880_BOARD_KWORLD_DVB_310U:
456 dvb->frontend = dvb_attach(zl10353_attach,
457 &em28xx_zl10353_with_xc3028,
458 &dev->i2c_adap);
459 if (attach_xc3028(0x61, dev) < 0) {
460 result = -EINVAL;
461 goto out_free;
462 }
463 break;
464 default: 447 default:
465 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card" 448 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card"
466 " isn't supported yet\n", 449 " isn't supported yet\n",
@@ -474,6 +457,8 @@ static int dvb_init(struct em28xx *dev)
474 result = -EINVAL; 457 result = -EINVAL;
475 goto out_free; 458 goto out_free;
476 } 459 }
460 /* define general-purpose callback pointer */
461 dvb->frontend->callback = em28xx_tuner_callback;
477 462
478 /* register everything */ 463 /* register everything */
479 result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev); 464 result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
diff --git a/drivers/media/video/em28xx/em28xx-i2c.c b/drivers/media/video/em28xx/em28xx-i2c.c
index 97853384c943..3bab56b997fc 100644
--- a/drivers/media/video/em28xx/em28xx-i2c.c
+++ b/drivers/media/video/em28xx/em28xx-i2c.c
@@ -143,10 +143,11 @@ static int em2800_i2c_check_for_device(struct em28xx *dev, unsigned char addr)
143 } 143 }
144 for (write_timeout = EM2800_I2C_WRITE_TIMEOUT; write_timeout > 0; 144 for (write_timeout = EM2800_I2C_WRITE_TIMEOUT; write_timeout > 0;
145 write_timeout -= 5) { 145 write_timeout -= 5) {
146 unsigned msg = dev->em28xx_read_reg(dev, 0x5); 146 unsigned reg = dev->em28xx_read_reg(dev, 0x5);
147 if (msg == 0x94) 147
148 if (reg == 0x94)
148 return -ENODEV; 149 return -ENODEV;
149 else if (msg == 0x84) 150 else if (reg == 0x84)
150 return 0; 151 return 0;
151 msleep(5); 152 msleep(5);
152 } 153 }
@@ -335,8 +336,11 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
335 336
336 /* Check if board has eeprom */ 337 /* Check if board has eeprom */
337 err = i2c_master_recv(&dev->i2c_client, &buf, 0); 338 err = i2c_master_recv(&dev->i2c_client, &buf, 0);
338 if (err < 0) 339 if (err < 0) {
339 return -1; 340 em28xx_errdev("%s: i2c_master_recv failed! err [%d]\n",
341 __func__, err);
342 return err;
343 }
340 344
341 buf = 0; 345 buf = 0;
342 346
@@ -344,7 +348,7 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
344 if (err != 1) { 348 if (err != 1) {
345 printk(KERN_INFO "%s: Huh, no eeprom present (err=%d)?\n", 349 printk(KERN_INFO "%s: Huh, no eeprom present (err=%d)?\n",
346 dev->name, err); 350 dev->name, err);
347 return -1; 351 return err;
348 } 352 }
349 while (size > 0) { 353 while (size > 0) {
350 if (size > 16) 354 if (size > 16)
@@ -357,7 +361,7 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
357 printk(KERN_WARNING 361 printk(KERN_WARNING
358 "%s: i2c eeprom read error (err=%d)\n", 362 "%s: i2c eeprom read error (err=%d)\n",
359 dev->name, err); 363 dev->name, err);
360 return -1; 364 return err;
361 } 365 }
362 size -= block; 366 size -= block;
363 p += block; 367 p += block;
@@ -585,18 +589,31 @@ void em28xx_i2c_call_clients(struct em28xx *dev, unsigned int cmd, void *arg)
585 */ 589 */
586int em28xx_i2c_register(struct em28xx *dev) 590int em28xx_i2c_register(struct em28xx *dev)
587{ 591{
592 int retval;
593
588 BUG_ON(!dev->em28xx_write_regs || !dev->em28xx_read_reg); 594 BUG_ON(!dev->em28xx_write_regs || !dev->em28xx_read_reg);
589 BUG_ON(!dev->em28xx_write_regs_req || !dev->em28xx_read_reg_req); 595 BUG_ON(!dev->em28xx_write_regs_req || !dev->em28xx_read_reg_req);
590 dev->i2c_adap = em28xx_adap_template; 596 dev->i2c_adap = em28xx_adap_template;
591 dev->i2c_adap.dev.parent = &dev->udev->dev; 597 dev->i2c_adap.dev.parent = &dev->udev->dev;
592 strcpy(dev->i2c_adap.name, dev->name); 598 strcpy(dev->i2c_adap.name, dev->name);
593 dev->i2c_adap.algo_data = dev; 599 dev->i2c_adap.algo_data = dev;
594 i2c_add_adapter(&dev->i2c_adap); 600
601 retval = i2c_add_adapter(&dev->i2c_adap);
602 if (retval < 0) {
603 em28xx_errdev("%s: i2c_add_adapter failed! retval [%d]\n",
604 __func__, retval);
605 return retval;
606 }
595 607
596 dev->i2c_client = em28xx_client_template; 608 dev->i2c_client = em28xx_client_template;
597 dev->i2c_client.adapter = &dev->i2c_adap; 609 dev->i2c_client.adapter = &dev->i2c_adap;
598 610
599 em28xx_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata)); 611 retval = em28xx_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata));
612 if (retval < 0) {
613 em28xx_errdev("%s: em28xx_i2_eeprom failed! retval [%d]\n",
614 __func__, retval);
615 return retval;
616 }
600 617
601 if (i2c_scan) 618 if (i2c_scan)
602 em28xx_do_i2c_scan(dev); 619 em28xx_do_i2c_scan(dev);
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 49ab0629702e..c53649e5315b 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -513,10 +513,17 @@ static struct videobuf_queue_ops em28xx_video_qops = {
513 */ 513 */
514static int em28xx_config(struct em28xx *dev) 514static int em28xx_config(struct em28xx *dev)
515{ 515{
516 int retval;
516 517
517 /* Sets I2C speed to 100 KHz */ 518 /* Sets I2C speed to 100 KHz */
518 if (!dev->is_em2800) 519 if (!dev->is_em2800) {
519 em28xx_write_regs_req(dev, 0x00, 0x06, "\x40", 1); 520 retval = em28xx_write_regs_req(dev, 0x00, 0x06, "\x40", 1);
521 if (retval < 0) {
522 em28xx_errdev("%s: em28xx_write_regs_req failed! retval [%d]\n",
523 __func__, retval);
524 return retval;
525 }
526 }
520 527
521 /* enable vbi capturing */ 528 /* enable vbi capturing */
522 529
@@ -1512,6 +1519,7 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
1512 struct em28xx_fh *fh; 1519 struct em28xx_fh *fh;
1513 enum v4l2_buf_type fh_type = 0; 1520 enum v4l2_buf_type fh_type = 0;
1514 1521
1522 lock_kernel();
1515 list_for_each_entry(h, &em28xx_devlist, devlist) { 1523 list_for_each_entry(h, &em28xx_devlist, devlist) {
1516 if (h->vdev->minor == minor) { 1524 if (h->vdev->minor == minor) {
1517 dev = h; 1525 dev = h;
@@ -1527,8 +1535,10 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
1527 dev = h; 1535 dev = h;
1528 } 1536 }
1529 } 1537 }
1530 if (NULL == dev) 1538 if (NULL == dev) {
1539 unlock_kernel();
1531 return -ENODEV; 1540 return -ENODEV;
1541 }
1532 1542
1533 em28xx_videodbg("open minor=%d type=%s users=%d\n", 1543 em28xx_videodbg("open minor=%d type=%s users=%d\n",
1534 minor, v4l2_type_names[fh_type], dev->users); 1544 minor, v4l2_type_names[fh_type], dev->users);
@@ -1537,6 +1547,7 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
1537 fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL); 1547 fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL);
1538 if (!fh) { 1548 if (!fh) {
1539 em28xx_errdev("em28xx-video.c: Out of memory?!\n"); 1549 em28xx_errdev("em28xx-video.c: Out of memory?!\n");
1550 unlock_kernel();
1540 return -ENOMEM; 1551 return -ENOMEM;
1541 } 1552 }
1542 mutex_lock(&dev->lock); 1553 mutex_lock(&dev->lock);
@@ -1573,6 +1584,7 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
1573 sizeof(struct em28xx_buffer), fh); 1584 sizeof(struct em28xx_buffer), fh);
1574 1585
1575 mutex_unlock(&dev->lock); 1586 mutex_unlock(&dev->lock);
1587 unlock_kernel();
1576 1588
1577 return errCode; 1589 return errCode;
1578} 1590}
@@ -1588,8 +1600,7 @@ static void em28xx_release_resources(struct em28xx *dev)
1588 /*FIXME: I2C IR should be disconnected */ 1600 /*FIXME: I2C IR should be disconnected */
1589 1601
1590 em28xx_info("V4L2 devices /dev/video%d and /dev/vbi%d deregistered\n", 1602 em28xx_info("V4L2 devices /dev/video%d and /dev/vbi%d deregistered\n",
1591 dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN, 1603 dev->vdev->num, dev->vbi_dev->num);
1592 dev->vbi_dev->minor-MINOR_VFL_TYPE_VBI_MIN);
1593 list_del(&dev->devlist); 1604 list_del(&dev->devlist);
1594 if (dev->sbutton_input_dev) 1605 if (dev->sbutton_input_dev)
1595 em28xx_deregister_snapshot_button(dev); 1606 em28xx_deregister_snapshot_button(dev);
@@ -1948,13 +1959,23 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1948 } 1959 }
1949 1960
1950 /* register i2c bus */ 1961 /* register i2c bus */
1951 em28xx_i2c_register(dev); 1962 errCode = em28xx_i2c_register(dev);
1963 if (errCode < 0) {
1964 em28xx_errdev("%s: em28xx_i2c_register - errCode [%d]!\n",
1965 __func__, errCode);
1966 return errCode;
1967 }
1952 1968
1953 /* Do board specific init and eeprom reading */ 1969 /* Do board specific init and eeprom reading */
1954 em28xx_card_setup(dev); 1970 em28xx_card_setup(dev);
1955 1971
1956 /* Configure audio */ 1972 /* Configure audio */
1957 em28xx_audio_analog_set(dev); 1973 errCode = em28xx_audio_analog_set(dev);
1974 if (errCode < 0) {
1975 em28xx_errdev("%s: em28xx_audio_analog_set - errCode [%d]!\n",
1976 __func__, errCode);
1977 return errCode;
1978 }
1958 1979
1959 /* configure the device */ 1980 /* configure the device */
1960 em28xx_config_i2c(dev); 1981 em28xx_config_i2c(dev);
@@ -1974,6 +1995,11 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1974 dev->ctl_input = 2; 1995 dev->ctl_input = 2;
1975 1996
1976 errCode = em28xx_config(dev); 1997 errCode = em28xx_config(dev);
1998 if (errCode < 0) {
1999 em28xx_errdev("%s: em28xx_config - errCode [%d]!\n",
2000 __func__, errCode);
2001 return errCode;
2002 }
1977 2003
1978 list_add_tail(&dev->devlist, &em28xx_devlist); 2004 list_add_tail(&dev->devlist, &em28xx_devlist);
1979 2005
@@ -2026,17 +2052,27 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
2026 2052
2027 if (dev->has_msp34xx) { 2053 if (dev->has_msp34xx) {
2028 /* Send a reset to other chips via gpio */ 2054 /* Send a reset to other chips via gpio */
2029 em28xx_write_regs_req(dev, 0x00, 0x08, "\xf7", 1); 2055 errCode = em28xx_write_regs_req(dev, 0x00, 0x08, "\xf7", 1);
2056 if (errCode < 0) {
2057 em28xx_errdev("%s: em28xx_write_regs_req - msp34xx(1) failed! errCode [%d]\n",
2058 __func__, errCode);
2059 return errCode;
2060 }
2030 msleep(3); 2061 msleep(3);
2031 em28xx_write_regs_req(dev, 0x00, 0x08, "\xff", 1); 2062
2063 errCode = em28xx_write_regs_req(dev, 0x00, 0x08, "\xff", 1);
2064 if (errCode < 0) {
2065 em28xx_errdev("%s: em28xx_write_regs_req - msp34xx(2) failed! errCode [%d]\n",
2066 __func__, errCode);
2067 return errCode;
2068 }
2032 msleep(3); 2069 msleep(3);
2033 } 2070 }
2034 2071
2035 video_mux(dev, 0); 2072 video_mux(dev, 0);
2036 2073
2037 em28xx_info("V4L2 device registered as /dev/video%d and /dev/vbi%d\n", 2074 em28xx_info("V4L2 device registered as /dev/video%d and /dev/vbi%d\n",
2038 dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN, 2075 dev->vdev->num, dev->vbi_dev->num);
2039 dev->vbi_dev->minor-MINOR_VFL_TYPE_VBI_MIN);
2040 2076
2041 mutex_lock(&em28xx_extension_devlist_lock); 2077 mutex_lock(&em28xx_extension_devlist_lock);
2042 if (!list_empty(&em28xx_extension_devlist)) { 2078 if (!list_empty(&em28xx_extension_devlist)) {
@@ -2236,7 +2272,7 @@ static void em28xx_usb_disconnect(struct usb_interface *interface)
2236 em28xx_warn 2272 em28xx_warn
2237 ("device /dev/video%d is open! Deregistration and memory " 2273 ("device /dev/video%d is open! Deregistration and memory "
2238 "deallocation are deferred on close.\n", 2274 "deallocation are deferred on close.\n",
2239 dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN); 2275 dev->vdev->num);
2240 2276
2241 dev->state |= DEV_MISCONFIGURED; 2277 dev->state |= DEV_MISCONFIGURED;
2242 em28xx_uninit_isoc(dev); 2278 em28xx_uninit_isoc(dev);
diff --git a/drivers/media/video/em28xx/em28xx.h b/drivers/media/video/em28xx/em28xx.h
index 9a3310748685..82781178e0a3 100644
--- a/drivers/media/video/em28xx/em28xx.h
+++ b/drivers/media/video/em28xx/em28xx.h
@@ -411,8 +411,8 @@ struct em28xx {
411 /* frame properties */ 411 /* frame properties */
412 int width; /* current frame width */ 412 int width; /* current frame width */
413 int height; /* current frame height */ 413 int height; /* current frame height */
414 int hscale; /* horizontal scale factor (see datasheet) */ 414 unsigned hscale; /* horizontal scale factor (see datasheet) */
415 int vscale; /* vertical scale factor (see datasheet) */ 415 unsigned vscale; /* vertical scale factor (see datasheet) */
416 int interlaced; /* 1=interlace fileds, 0=just top fileds */ 416 int interlaced; /* 1=interlace fileds, 0=just top fileds */
417 unsigned int video_bytesread; /* Number of bytes read */ 417 unsigned int video_bytesread; /* Number of bytes read */
418 418
@@ -528,7 +528,7 @@ extern struct em28xx_board em28xx_boards[];
528extern struct usb_device_id em28xx_id_table[]; 528extern struct usb_device_id em28xx_id_table[];
529extern const unsigned int em28xx_bcount; 529extern const unsigned int em28xx_bcount;
530void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir); 530void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir);
531int em28xx_tuner_callback(void *ptr, int command, int arg); 531int em28xx_tuner_callback(void *ptr, int component, int command, int arg);
532 532
533/* Provided by em28xx-input.c */ 533/* Provided by em28xx-input.c */
534/* TODO: Check if the standard get_key handlers on ir-common can be used */ 534/* TODO: Check if the standard get_key handlers on ir-common can be used */
diff --git a/drivers/media/video/et61x251/et61x251_core.c b/drivers/media/video/et61x251/et61x251_core.c
index 8db2a05bf9c5..7a85c41b0eea 100644
--- a/drivers/media/video/et61x251/et61x251_core.c
+++ b/drivers/media/video/et61x251/et61x251_core.c
@@ -1214,7 +1214,7 @@ static int et61x251_open(struct inode* inode, struct file* filp)
1214 if (!down_read_trylock(&et61x251_dev_lock)) 1214 if (!down_read_trylock(&et61x251_dev_lock))
1215 return -ERESTARTSYS; 1215 return -ERESTARTSYS;
1216 1216
1217 cam = video_get_drvdata(video_devdata(filp)); 1217 cam = video_drvdata(filp);
1218 1218
1219 if (wait_for_completion_interruptible(&cam->probe)) { 1219 if (wait_for_completion_interruptible(&cam->probe)) {
1220 up_read(&et61x251_dev_lock); 1220 up_read(&et61x251_dev_lock);
@@ -1297,7 +1297,7 @@ static int et61x251_release(struct inode* inode, struct file* filp)
1297 1297
1298 down_write(&et61x251_dev_lock); 1298 down_write(&et61x251_dev_lock);
1299 1299
1300 cam = video_get_drvdata(video_devdata(filp)); 1300 cam = video_drvdata(filp);
1301 1301
1302 et61x251_stop_transfer(cam); 1302 et61x251_stop_transfer(cam);
1303 et61x251_release_buffers(cam); 1303 et61x251_release_buffers(cam);
@@ -1318,7 +1318,7 @@ static ssize_t
1318et61x251_read(struct file* filp, char __user * buf, 1318et61x251_read(struct file* filp, char __user * buf,
1319 size_t count, loff_t* f_pos) 1319 size_t count, loff_t* f_pos)
1320{ 1320{
1321 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp)); 1321 struct et61x251_device *cam = video_drvdata(filp);
1322 struct et61x251_frame_t* f, * i; 1322 struct et61x251_frame_t* f, * i;
1323 unsigned long lock_flags; 1323 unsigned long lock_flags;
1324 long timeout; 1324 long timeout;
@@ -1426,7 +1426,7 @@ exit:
1426 1426
1427static unsigned int et61x251_poll(struct file *filp, poll_table *wait) 1427static unsigned int et61x251_poll(struct file *filp, poll_table *wait)
1428{ 1428{
1429 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp)); 1429 struct et61x251_device *cam = video_drvdata(filp);
1430 struct et61x251_frame_t* f; 1430 struct et61x251_frame_t* f;
1431 unsigned long lock_flags; 1431 unsigned long lock_flags;
1432 unsigned int mask = 0; 1432 unsigned int mask = 0;
@@ -1502,7 +1502,7 @@ static struct vm_operations_struct et61x251_vm_ops = {
1502 1502
1503static int et61x251_mmap(struct file* filp, struct vm_area_struct *vma) 1503static int et61x251_mmap(struct file* filp, struct vm_area_struct *vma)
1504{ 1504{
1505 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp)); 1505 struct et61x251_device *cam = video_drvdata(filp);
1506 unsigned long size = vma->vm_end - vma->vm_start, 1506 unsigned long size = vma->vm_end - vma->vm_start,
1507 start = vma->vm_start; 1507 start = vma->vm_start;
1508 void *pos; 1508 void *pos;
@@ -2395,7 +2395,7 @@ et61x251_vidioc_s_parm(struct et61x251_device* cam, void __user * arg)
2395static int et61x251_ioctl_v4l2(struct inode* inode, struct file* filp, 2395static int et61x251_ioctl_v4l2(struct inode* inode, struct file* filp,
2396 unsigned int cmd, void __user * arg) 2396 unsigned int cmd, void __user * arg)
2397{ 2397{
2398 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp)); 2398 struct et61x251_device *cam = video_drvdata(filp);
2399 2399
2400 switch (cmd) { 2400 switch (cmd) {
2401 2401
@@ -2490,7 +2490,7 @@ static int et61x251_ioctl_v4l2(struct inode* inode, struct file* filp,
2490static int et61x251_ioctl(struct inode* inode, struct file* filp, 2490static int et61x251_ioctl(struct inode* inode, struct file* filp,
2491 unsigned int cmd, unsigned long arg) 2491 unsigned int cmd, unsigned long arg)
2492{ 2492{
2493 struct et61x251_device* cam = video_get_drvdata(video_devdata(filp)); 2493 struct et61x251_device *cam = video_drvdata(filp);
2494 int err = 0; 2494 int err = 0;
2495 2495
2496 if (mutex_lock_interruptible(&cam->fileop_mutex)) 2496 if (mutex_lock_interruptible(&cam->fileop_mutex))
diff --git a/drivers/media/video/gspca/Kconfig b/drivers/media/video/gspca/Kconfig
index 42b90742b40b..4d0817471c9f 100644
--- a/drivers/media/video/gspca/Kconfig
+++ b/drivers/media/video/gspca/Kconfig
@@ -1,13 +1,212 @@
1config USB_GSPCA 1menuconfig USB_GSPCA
2 tristate "USB GSPCA driver" 2 tristate "GSPCA based webcams"
3 depends on VIDEO_V4L2 3 depends on VIDEO_V4L2
4 default m
4 ---help--- 5 ---help---
5 Say Y here if you want support for various USB webcams. 6 Say Y here if you want to enable selecting webcams based
7 on the GSPCA framework.
6 8
7 See <file:Documentation/video4linux/gspca.txt> for more info. 9 See <file:Documentation/video4linux/gspca.txt> for more info.
8 10
9 This driver uses the Video For Linux API. You must say Y or M to 11 This driver uses the Video For Linux API. You must say Y or M to
10 "Video For Linux" to use this driver. 12 "Video For Linux" to use this driver.
11 13
12 To compile this driver as modules, choose M here: the 14 To compile this driver as modules, choose M here: the
13 modules will be called gspca_xxxx. 15 modules will be called gspca_main.
16
17
18if USB_GSPCA && VIDEO_V4L2
19
20source "drivers/media/video/gspca/m5602/Kconfig"
21
22config USB_GSPCA_CONEX
23 tristate "Conexant Camera Driver"
24 depends on VIDEO_V4L2 && USB_GSPCA
25 help
26 Say Y here if you want support for cameras based on the Conexant chip.
27
28 To compile this driver as a module, choose M here: the
29 module will be called gspca_conex.
30
31config USB_GSPCA_ETOMS
32 tristate "Etoms USB Camera Driver"
33 depends on VIDEO_V4L2 && USB_GSPCA
34 help
35 Say Y here if you want support for cameras based on the Etoms chip.
36
37 To compile this driver as a module, choose M here: the
38 module will be called gspca_etoms.
39
40config USB_GSPCA_FINEPIX
41 tristate "Fujifilm FinePix USB V4L2 driver"
42 depends on VIDEO_V4L2 && USB_GSPCA
43 help
44 Say Y here if you want support for cameras based on the FinePix chip.
45
46 To compile this driver as a module, choose M here: the
47 module will be called gspca_finepix.
48
49config USB_GSPCA_MARS
50 tristate "Mars USB Camera Driver"
51 depends on VIDEO_V4L2 && USB_GSPCA
52 help
53 Say Y here if you want support for cameras based on the Mars chip.
54
55 To compile this driver as a module, choose M here: the
56 module will be called gspca_mars.
57
58config USB_GSPCA_OV519
59 tristate "OV519 USB Camera Driver"
60 depends on VIDEO_V4L2 && USB_GSPCA
61 help
62 Say Y here if you want support for cameras based on the OV519 chip.
63
64 To compile this driver as a module, choose M here: the
65 module will be called gspca_ov519.
66
67config USB_GSPCA_PAC207
68 tristate "Pixart PAC207 USB Camera Driver"
69 depends on VIDEO_V4L2 && USB_GSPCA
70 help
71 Say Y here if you want support for cameras based on the PAC207 chip.
72
73 To compile this driver as a module, choose M here: the
74 module will be called gspca_pac207.
75
76config USB_GSPCA_PAC7311
77 tristate "Pixart PAC7311 USB Camera Driver"
78 depends on VIDEO_V4L2 && USB_GSPCA
79 help
80 Say Y here if you want support for cameras based on the PAC7311 chip.
81
82 To compile this driver as a module, choose M here: the
83 module will be called gspca_pac7311.
84
85config USB_GSPCA_SONIXB
86 tristate "SN9C102 USB Camera Driver"
87 depends on VIDEO_V4L2 && USB_GSPCA
88 help
89 Say Y here if you want support for cameras based on the SONIXB chip.
90
91 To compile this driver as a module, choose M here: the
92 module will be called gspca_sonixb.
93
94config USB_GSPCA_SONIXJ
95 tristate "SONIX JPEG USB Camera Driver"
96 depends on VIDEO_V4L2 && USB_GSPCA
97 help
98 Say Y here if you want support for cameras based on the SONIXJ chip.
99
100 To compile this driver as a module, choose M here: the
101 module will be called gspca_sonixj
102
103config USB_GSPCA_SPCA500
104 tristate "SPCA500 USB Camera Driver"
105 depends on VIDEO_V4L2 && USB_GSPCA
106 help
107 Say Y here if you want support for cameras based on the SPCA500 chip.
108
109 To compile this driver as a module, choose M here: the
110 module will be called gspca_spca500.
111
112config USB_GSPCA_SPCA501
113 tristate "SPCA501 USB Camera Driver"
114 depends on VIDEO_V4L2 && USB_GSPCA
115 help
116 Say Y here if you want support for cameras based on the SPCA501 chip.
117
118 To compile this driver as a module, choose M here: the
119 module will be called gspca_spca501.
120
121config USB_GSPCA_SPCA505
122 tristate "SPCA505 USB Camera Driver"
123 depends on VIDEO_V4L2 && USB_GSPCA
124 help
125 Say Y here if you want support for cameras based on the SPCA505 chip.
126
127 To compile this driver as a module, choose M here: the
128 module will be called gspca_spca505.
129
130config USB_GSPCA_SPCA506
131 tristate "SPCA506 USB Camera Driver"
132 depends on VIDEO_V4L2 && USB_GSPCA
133 help
134 Say Y here if you want support for cameras based on the SPCA506 chip.
135
136 To compile this driver as a module, choose M here: the
137 module will be called gspca_spca506.
138
139config USB_GSPCA_SPCA508
140 tristate "SPCA508 USB Camera Driver"
141 depends on VIDEO_V4L2 && USB_GSPCA
142 help
143 Say Y here if you want support for cameras based on the SPCA508 chip.
144
145 To compile this driver as a module, choose M here: the
146 module will be called gspca_spca508.
147
148config USB_GSPCA_SPCA561
149 tristate "SPCA561 USB Camera Driver"
150 depends on VIDEO_V4L2 && USB_GSPCA
151 help
152 Say Y here if you want support for cameras based on the SPCA561 chip.
153
154 To compile this driver as a module, choose M here: the
155 module will be called gspca_spca561.
156
157config USB_GSPCA_STK014
158 tristate "Syntek DV4000 (STK014) USB Camera Driver"
159 depends on VIDEO_V4L2 && USB_GSPCA
160 help
161 Say Y here if you want support for cameras based on the STK014 chip.
162
163 To compile this driver as a module, choose M here: the
164 module will be called gspca_stk014.
165
166config USB_GSPCA_SUNPLUS
167 tristate "SUNPLUS USB Camera Driver"
168 depends on VIDEO_V4L2 && USB_GSPCA
169 help
170 Say Y here if you want support for cameras based on the Sunplus
171 SPCA504(abc) SPCA533 SPCA536 chips.
172
173 To compile this driver as a module, choose M here: the
174 module will be called gspca_spca5xx.
175
176config USB_GSPCA_T613
177 tristate "T613 (JPEG Compliance) USB Camera Driver"
178 depends on VIDEO_V4L2 && USB_GSPCA
179 help
180 Say Y here if you want support for cameras based on the T613 chip.
181
182 To compile this driver as a module, choose M here: the
183 module will be called gspca_t613.
184
185config USB_GSPCA_TV8532
186 tristate "TV8532 USB Camera Driver"
187 depends on VIDEO_V4L2 && USB_GSPCA
188 help
189 Say Y here if you want support for cameras based on the TV8531 chip.
190
191 To compile this driver as a module, choose M here: the
192 module will be called gspca_tv8532.
193
194config USB_GSPCA_VC032X
195 tristate "VC032X USB Camera Driver"
196 depends on VIDEO_V4L2 && USB_GSPCA
197 help
198 Say Y here if you want support for cameras based on the VC032X chip.
199
200 To compile this driver as a module, choose M here: the
201 module will be called gspca_vc032x.
202
203config USB_GSPCA_ZC3XX
204 tristate "VC3xx USB Camera Driver"
205 depends on VIDEO_V4L2 && USB_GSPCA
206 help
207 Say Y here if you want support for cameras based on the ZC3XX chip.
208
209 To compile this driver as a module, choose M here: the
210 module will be called gspca_zc3xx.
211
212endif
diff --git a/drivers/media/video/gspca/Makefile b/drivers/media/video/gspca/Makefile
index e68a8965297a..22734f5a6c32 100644
--- a/drivers/media/video/gspca/Makefile
+++ b/drivers/media/video/gspca/Makefile
@@ -1,29 +1,48 @@
1obj-$(CONFIG_USB_GSPCA) += gspca_main.o \ 1obj-$(CONFIG_USB_GSPCA) += gspca_main.o
2 gspca_conex.o gspca_etoms.o gspca_mars.o \ 2obj-$(CONFIG_USB_GSPCA_CONEX) += gspca_conex.o
3 gspca_ov519.o gspca_pac207.o gspca_pac7311.o \ 3obj-$(CONFIG_USB_GSPCA_ETOMS) += gspca_etoms.o
4 gspca_sonixb.o gspca_sonixj.o gspca_spca500.o gspca_spca501.o \ 4obj-$(CONFIG_USB_GSPCA_FINEPIX) += gspca_finepix.o
5 gspca_spca505.o gspca_spca506.o gspca_spca508.o gspca_spca561.o \ 5obj-$(CONFIG_USB_GSPCA_MARS) += gspca_mars.o
6 gspca_sunplus.o gspca_stk014.o gspca_t613.o gspca_tv8532.o \ 6obj-$(CONFIG_USB_GSPCA_OV519) += gspca_ov519.o
7 gspca_vc032x.o gspca_zc3xx.o 7obj-$(CONFIG_USB_GSPCA_PAC207) += gspca_pac207.o
8obj-$(CONFIG_USB_GSPCA_PAC7311) += gspca_pac7311.o
9obj-$(CONFIG_USB_GSPCA_SONIXB) += gspca_sonixb.o
10obj-$(CONFIG_USB_GSPCA_SONIXJ) += gspca_sonixj.o
11obj-$(CONFIG_USB_GSPCA_SPCA500) += gspca_spca500.o
12obj-$(CONFIG_USB_GSPCA_SPCA501) += gspca_spca501.o
13obj-$(CONFIG_USB_GSPCA_SPCA505) += gspca_spca505.o
14obj-$(CONFIG_USB_GSPCA_SPCA506) += gspca_spca506.o
15obj-$(CONFIG_USB_GSPCA_SPCA508) += gspca_spca508.o
16obj-$(CONFIG_USB_GSPCA_SPCA561) += gspca_spca561.o
17obj-$(CONFIG_USB_GSPCA_SUNPLUS) += gspca_sunplus.o
18obj-$(CONFIG_USB_GSPCA_STK014) += gspca_stk014.o
19obj-$(CONFIG_USB_GSPCA_T613) += gspca_t613.o
20obj-$(CONFIG_USB_GSPCA_TV8532) += gspca_tv8532.o
21obj-$(CONFIG_USB_GSPCA_VC032X) += gspca_vc032x.o
22obj-$(CONFIG_USB_GSPCA_ZC3XX) += gspca_zc3xx.o
23
24gspca_main-objs := gspca.o
25gspca_conex-objs := conex.o
26gspca_etoms-objs := etoms.o
27gspca_finepix-objs := finepix.o
28gspca_mars-objs := mars.o
29gspca_ov519-objs := ov519.o
30gspca_pac207-objs := pac207.o
31gspca_pac7311-objs := pac7311.o
32gspca_sonixb-objs := sonixb.o
33gspca_sonixj-objs := sonixj.o
34gspca_spca500-objs := spca500.o
35gspca_spca501-objs := spca501.o
36gspca_spca505-objs := spca505.o
37gspca_spca506-objs := spca506.o
38gspca_spca508-objs := spca508.o
39gspca_spca561-objs := spca561.o
40gspca_stk014-objs := stk014.o
41gspca_sunplus-objs := sunplus.o
42gspca_t613-objs := t613.o
43gspca_tv8532-objs := tv8532.o
44gspca_vc032x-objs := vc032x.o
45gspca_zc3xx-objs := zc3xx.o
46
47obj-$(CONFIG_USB_M5602) += m5602/
8 48
9gspca_main-objs := gspca.o
10gspca_conex-objs := conex.o
11gspca_etoms-objs := etoms.o
12gspca_mars-objs := mars.o
13gspca_ov519-objs := ov519.o
14gspca_pac207-objs := pac207.o
15gspca_pac7311-objs := pac7311.o
16gspca_sonixb-objs := sonixb.o
17gspca_sonixj-objs := sonixj.o
18gspca_spca500-objs := spca500.o
19gspca_spca501-objs := spca501.o
20gspca_spca505-objs := spca505.o
21gspca_spca506-objs := spca506.o
22gspca_spca508-objs := spca508.o
23gspca_spca561-objs := spca561.o
24gspca_stk014-objs := stk014.o
25gspca_sunplus-objs := sunplus.o
26gspca_t613-objs := t613.o
27gspca_tv8532-objs := tv8532.o
28gspca_vc032x-objs := vc032x.o
29gspca_zc3xx-objs := zc3xx.o
diff --git a/drivers/media/video/gspca/conex.c b/drivers/media/video/gspca/conex.c
index 4d9f4cc255a9..a9d51ba7c57c 100644
--- a/drivers/media/video/gspca/conex.c
+++ b/drivers/media/video/gspca/conex.c
@@ -837,12 +837,13 @@ static int sd_init(struct gspca_dev *gspca_dev)
837 return 0; 837 return 0;
838} 838}
839 839
840static void sd_start(struct gspca_dev *gspca_dev) 840static int sd_start(struct gspca_dev *gspca_dev)
841{ 841{
842 cx11646_initsize(gspca_dev); 842 cx11646_initsize(gspca_dev);
843 cx11646_fw(gspca_dev); 843 cx11646_fw(gspca_dev);
844 cx_sensor(gspca_dev); 844 cx_sensor(gspca_dev);
845 cx11646_jpeg(gspca_dev); 845 cx11646_jpeg(gspca_dev);
846 return 0;
846} 847}
847 848
848static void sd_stop0(struct gspca_dev *gspca_dev) 849static void sd_stop0(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/etoms.c b/drivers/media/video/gspca/etoms.c
index 4ff0e386914b..3be30b420a26 100644
--- a/drivers/media/video/gspca/etoms.c
+++ b/drivers/media/video/gspca/etoms.c
@@ -691,7 +691,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
691} 691}
692 692
693/* -- start the camera -- */ 693/* -- start the camera -- */
694static void sd_start(struct gspca_dev *gspca_dev) 694static int sd_start(struct gspca_dev *gspca_dev)
695{ 695{
696 struct sd *sd = (struct sd *) gspca_dev; 696 struct sd *sd = (struct sd *) gspca_dev;
697 697
@@ -704,6 +704,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
704 704
705 reg_w_val(gspca_dev, ET_RESET_ALL, 0x08); 705 reg_w_val(gspca_dev, ET_RESET_ALL, 0x08);
706 et_video(gspca_dev, 1); /* video on */ 706 et_video(gspca_dev, 1); /* video on */
707 return 0;
707} 708}
708 709
709static void sd_stopN(struct gspca_dev *gspca_dev) 710static void sd_stopN(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/finepix.c b/drivers/media/video/gspca/finepix.c
new file mode 100644
index 000000000000..65d3cbfe6b27
--- /dev/null
+++ b/drivers/media/video/gspca/finepix.c
@@ -0,0 +1,466 @@
1/*
2 * Fujifilm Finepix subdriver
3 *
4 * Copyright (C) 2008 Frank Zago
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#define MODULE_NAME "finepix"
22
23#include "gspca.h"
24
25MODULE_AUTHOR("Frank Zago <frank@zago.net>");
26MODULE_DESCRIPTION("Fujifilm FinePix USB V4L2 driver");
27MODULE_LICENSE("GPL");
28
29/* Default timeout, in ms */
30#define FPIX_TIMEOUT (HZ / 10)
31
32/* Maximum transfer size to use. The windows driver reads by chunks of
33 * 0x2000 bytes, so do the same. Note: reading more seems to work
34 * too. */
35#define FPIX_MAX_TRANSFER 0x2000
36
37/* Structure to hold all of our device specific stuff */
38struct usb_fpix {
39 struct gspca_dev gspca_dev; /* !! must be the first item */
40
41 /*
42 * USB stuff
43 */
44 struct usb_ctrlrequest ctrlreq;
45 struct urb *control_urb;
46 struct timer_list bulk_timer;
47
48 enum {
49 FPIX_NOP, /* inactive, else streaming */
50 FPIX_RESET, /* must reset */
51 FPIX_REQ_FRAME, /* requesting a frame */
52 FPIX_READ_FRAME, /* reading frame */
53 } state;
54
55 /*
56 * Driver stuff
57 */
58 struct delayed_work wqe;
59 struct completion can_close;
60 int streaming;
61};
62
63/* Delay after which claim the next frame. If the delay is too small,
64 * the camera will return old frames. On the 4800Z, 20ms is bad, 25ms
65 * will fail every 4 or 5 frames, but 30ms is perfect. */
66#define NEXT_FRAME_DELAY (((HZ * 30) + 999) / 1000)
67
68#define dev_new_state(new_state) { \
69 PDEBUG(D_STREAM, "new state from %d to %d at %s:%d", \
70 dev->state, new_state, __func__, __LINE__); \
71 dev->state = new_state; \
72}
73
74/* These cameras only support 320x200. */
75static struct v4l2_pix_format fpix_mode[1] = {
76 { 320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
77 .bytesperline = 320,
78 .sizeimage = 320 * 240 * 3 / 8 + 590,
79 .colorspace = V4L2_COLORSPACE_SRGB,
80 .priv = 0}
81};
82
83/* Reads part of a frame */
84static void read_frame_part(struct usb_fpix *dev)
85{
86 int ret;
87
88 PDEBUG(D_STREAM, "read_frame_part");
89
90 /* Reads part of a frame */
91 ret = usb_submit_urb(dev->gspca_dev.urb[0], GFP_ATOMIC);
92 if (ret) {
93 dev_new_state(FPIX_RESET);
94 schedule_delayed_work(&dev->wqe, 1);
95 PDEBUG(D_STREAM, "usb_submit_urb failed with %d",
96 ret);
97 } else {
98 /* Sometimes we never get a callback, so use a timer.
99 * Is this masking a bug somewhere else? */
100 dev->bulk_timer.expires = jiffies + msecs_to_jiffies(150);
101 add_timer(&dev->bulk_timer);
102 }
103}
104
105/* Callback for URBs. */
106static void urb_callback(struct urb *urb)
107{
108 struct gspca_dev *gspca_dev = urb->context;
109 struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
110
111 PDEBUG(D_PACK,
112 "enter urb_callback - status=%d, length=%d",
113 urb->status, urb->actual_length);
114
115 if (dev->state == FPIX_READ_FRAME)
116 del_timer(&dev->bulk_timer);
117
118 if (urb->status != 0) {
119 /* We kill a stuck urb every 50 frames on average, so don't
120 * display a log message for that. */
121 if (urb->status != -ECONNRESET)
122 PDEBUG(D_STREAM, "bad URB status %d", urb->status);
123 dev_new_state(FPIX_RESET);
124 schedule_delayed_work(&dev->wqe, 1);
125 }
126
127 switch (dev->state) {
128 case FPIX_REQ_FRAME:
129 dev_new_state(FPIX_READ_FRAME);
130 read_frame_part(dev);
131 break;
132
133 case FPIX_READ_FRAME: {
134 unsigned char *data = urb->transfer_buffer;
135 struct gspca_frame *frame;
136
137 frame = gspca_get_i_frame(&dev->gspca_dev);
138 if (frame == NULL)
139 gspca_dev->last_packet_type = DISCARD_PACKET;
140 if (urb->actual_length < FPIX_MAX_TRANSFER ||
141 (data[urb->actual_length-2] == 0xff &&
142 data[urb->actual_length-1] == 0xd9)) {
143
144 /* If the result is less than what was asked
145 * for, then it's the end of the
146 * frame. Sometime the jpeg is not complete,
147 * but there's nothing we can do. We also end
148 * here if the the jpeg ends right at the end
149 * of the frame. */
150 if (frame)
151 gspca_frame_add(gspca_dev, LAST_PACKET,
152 frame,
153 data, urb->actual_length);
154 dev_new_state(FPIX_REQ_FRAME);
155 schedule_delayed_work(&dev->wqe, NEXT_FRAME_DELAY);
156 } else {
157
158 /* got a partial image */
159 if (frame)
160 gspca_frame_add(gspca_dev,
161 gspca_dev->last_packet_type
162 == LAST_PACKET
163 ? FIRST_PACKET : INTER_PACKET,
164 frame,
165 data, urb->actual_length);
166 read_frame_part(dev);
167 }
168 break;
169 }
170
171 case FPIX_NOP:
172 case FPIX_RESET:
173 PDEBUG(D_STREAM, "invalid state %d", dev->state);
174 break;
175 }
176}
177
178/* Request a new frame */
179static void request_frame(struct usb_fpix *dev)
180{
181 int ret;
182 struct gspca_dev *gspca_dev = &dev->gspca_dev;
183
184 /* Setup command packet */
185 memset(gspca_dev->usb_buf, 0, 12);
186 gspca_dev->usb_buf[0] = 0xd3;
187 gspca_dev->usb_buf[7] = 0x01;
188
189 /* Request a frame */
190 dev->ctrlreq.bRequestType =
191 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
192 dev->ctrlreq.bRequest = USB_REQ_GET_STATUS;
193 dev->ctrlreq.wValue = 0;
194 dev->ctrlreq.wIndex = 0;
195 dev->ctrlreq.wLength = cpu_to_le16(12);
196
197 usb_fill_control_urb(dev->control_urb,
198 gspca_dev->dev,
199 usb_sndctrlpipe(gspca_dev->dev, 0),
200 (unsigned char *) &dev->ctrlreq,
201 gspca_dev->usb_buf,
202 12, urb_callback, gspca_dev);
203
204 ret = usb_submit_urb(dev->control_urb, GFP_ATOMIC);
205 if (ret) {
206 dev_new_state(FPIX_RESET);
207 schedule_delayed_work(&dev->wqe, 1);
208 PDEBUG(D_STREAM, "usb_submit_urb failed with %d", ret);
209 }
210}
211
212/*--------------------------------------------------------------------------*/
213
214/* State machine. */
215static void fpix_sm(struct work_struct *work)
216{
217 struct usb_fpix *dev = container_of(work, struct usb_fpix, wqe.work);
218
219 PDEBUG(D_STREAM, "fpix_sm state %d", dev->state);
220
221 /* verify that the device wasn't unplugged */
222 if (!dev->gspca_dev.present) {
223 PDEBUG(D_STREAM, "device is gone");
224 dev_new_state(FPIX_NOP);
225 complete(&dev->can_close);
226 return;
227 }
228
229 if (!dev->streaming) {
230 PDEBUG(D_STREAM, "stopping state machine");
231 dev_new_state(FPIX_NOP);
232 complete(&dev->can_close);
233 return;
234 }
235
236 switch (dev->state) {
237 case FPIX_RESET:
238 dev_new_state(FPIX_REQ_FRAME);
239 schedule_delayed_work(&dev->wqe, HZ / 10);
240 break;
241
242 case FPIX_REQ_FRAME:
243 /* get an image */
244 request_frame(dev);
245 break;
246
247 case FPIX_NOP:
248 case FPIX_READ_FRAME:
249 PDEBUG(D_STREAM, "invalid state %d", dev->state);
250 break;
251 }
252}
253
254/* this function is called at probe time */
255static int sd_config(struct gspca_dev *gspca_dev,
256 const struct usb_device_id *id)
257{
258 struct cam *cam = &gspca_dev->cam;
259
260 cam->cam_mode = fpix_mode;
261 cam->nmodes = 1;
262 cam->epaddr = 0x01; /* todo: correct for all cams? */
263 cam->bulk_size = FPIX_MAX_TRANSFER;
264
265/* gspca_dev->nbalt = 1; * use bulk transfer */
266 return 0;
267}
268
269/* Stop streaming and free the ressources allocated by sd_start. */
270static void sd_stopN(struct gspca_dev *gspca_dev)
271{
272 struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
273
274 dev->streaming = 0;
275
276 /* Stop the state machine */
277 if (dev->state != FPIX_NOP)
278 wait_for_completion(&dev->can_close);
279
280 usb_free_urb(dev->control_urb);
281 dev->control_urb = NULL;
282}
283
284/* Kill an URB that hasn't completed. */
285static void timeout_kill(unsigned long data)
286{
287 struct urb *urb = (struct urb *) data;
288
289 usb_unlink_urb(urb);
290}
291
292/* this function is called at probe and resume time */
293static int sd_init(struct gspca_dev *gspca_dev)
294{
295 struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
296
297 INIT_DELAYED_WORK(&dev->wqe, fpix_sm);
298
299 init_timer(&dev->bulk_timer);
300 dev->bulk_timer.function = timeout_kill;
301
302 return 0;
303}
304
305static int sd_start(struct gspca_dev *gspca_dev)
306{
307 struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
308 int ret;
309 int size_ret;
310
311 /* Reset bulk in endpoint */
312 usb_clear_halt(gspca_dev->dev, gspca_dev->cam.epaddr);
313
314 /* Init the device */
315 memset(gspca_dev->usb_buf, 0, 12);
316 gspca_dev->usb_buf[0] = 0xc6;
317 gspca_dev->usb_buf[8] = 0x20;
318
319 ret = usb_control_msg(gspca_dev->dev,
320 usb_sndctrlpipe(gspca_dev->dev, 0),
321 USB_REQ_GET_STATUS,
322 USB_DIR_OUT | USB_TYPE_CLASS |
323 USB_RECIP_INTERFACE, 0, 0, gspca_dev->usb_buf,
324 12, FPIX_TIMEOUT);
325
326 if (ret != 12) {
327 PDEBUG(D_STREAM, "usb_control_msg failed (%d)", ret);
328 ret = -EIO;
329 goto error;
330 }
331
332 /* Read the result of the command. Ignore the result, for it
333 * varies with the device. */
334 ret = usb_bulk_msg(gspca_dev->dev,
335 usb_rcvbulkpipe(gspca_dev->dev,
336 gspca_dev->cam.epaddr),
337 gspca_dev->usb_buf, FPIX_MAX_TRANSFER, &size_ret,
338 FPIX_TIMEOUT);
339 if (ret != 0) {
340 PDEBUG(D_STREAM, "usb_bulk_msg failed (%d)", ret);
341 ret = -EIO;
342 goto error;
343 }
344
345 /* Request a frame, but don't read it */
346 memset(gspca_dev->usb_buf, 0, 12);
347 gspca_dev->usb_buf[0] = 0xd3;
348 gspca_dev->usb_buf[7] = 0x01;
349
350 ret = usb_control_msg(gspca_dev->dev,
351 usb_sndctrlpipe(gspca_dev->dev, 0),
352 USB_REQ_GET_STATUS,
353 USB_DIR_OUT | USB_TYPE_CLASS |
354 USB_RECIP_INTERFACE, 0, 0, gspca_dev->usb_buf,
355 12, FPIX_TIMEOUT);
356 if (ret != 12) {
357 PDEBUG(D_STREAM, "usb_control_msg failed (%d)", ret);
358 ret = -EIO;
359 goto error;
360 }
361
362 /* Again, reset bulk in endpoint */
363 usb_clear_halt(gspca_dev->dev, gspca_dev->cam.epaddr);
364
365 /* Allocate a control URB */
366 dev->control_urb = usb_alloc_urb(0, GFP_KERNEL);
367 if (!dev->control_urb) {
368 PDEBUG(D_STREAM, "No free urbs available");
369 ret = -EIO;
370 goto error;
371 }
372
373 /* Various initializations. */
374 init_completion(&dev->can_close);
375 dev->bulk_timer.data = (unsigned long)dev->gspca_dev.urb[0];
376 dev->gspca_dev.urb[0]->complete = urb_callback;
377 dev->streaming = 1;
378
379 /* Schedule a frame request. */
380 dev_new_state(FPIX_REQ_FRAME);
381 schedule_delayed_work(&dev->wqe, 1);
382
383 return 0;
384
385error:
386 /* Free the ressources */
387 sd_stopN(gspca_dev);
388 return ret;
389}
390
391/* Table of supported USB devices */
392static const __devinitdata struct usb_device_id device_table[] = {
393 {USB_DEVICE(0x04cb, 0x0104)},
394 {USB_DEVICE(0x04cb, 0x0109)},
395 {USB_DEVICE(0x04cb, 0x010b)},
396 {USB_DEVICE(0x04cb, 0x010f)},
397 {USB_DEVICE(0x04cb, 0x0111)},
398 {USB_DEVICE(0x04cb, 0x0113)},
399 {USB_DEVICE(0x04cb, 0x0115)},
400 {USB_DEVICE(0x04cb, 0x0117)},
401 {USB_DEVICE(0x04cb, 0x0119)},
402 {USB_DEVICE(0x04cb, 0x011b)},
403 {USB_DEVICE(0x04cb, 0x011d)},
404 {USB_DEVICE(0x04cb, 0x0121)},
405 {USB_DEVICE(0x04cb, 0x0123)},
406 {USB_DEVICE(0x04cb, 0x0125)},
407 {USB_DEVICE(0x04cb, 0x0127)},
408 {USB_DEVICE(0x04cb, 0x0129)},
409 {USB_DEVICE(0x04cb, 0x012b)},
410 {USB_DEVICE(0x04cb, 0x012d)},
411 {USB_DEVICE(0x04cb, 0x012f)},
412 {USB_DEVICE(0x04cb, 0x0131)},
413 {USB_DEVICE(0x04cb, 0x013b)},
414 {USB_DEVICE(0x04cb, 0x013d)},
415 {USB_DEVICE(0x04cb, 0x013f)},
416 {}
417};
418
419MODULE_DEVICE_TABLE(usb, device_table);
420
421/* sub-driver description */
422static const struct sd_desc sd_desc = {
423 .name = MODULE_NAME,
424 .config = sd_config,
425 .init = sd_init,
426 .start = sd_start,
427 .stopN = sd_stopN,
428};
429
430/* -- device connect -- */
431static int sd_probe(struct usb_interface *intf,
432 const struct usb_device_id *id)
433{
434 return gspca_dev_probe(intf, id,
435 &sd_desc,
436 sizeof(struct usb_fpix),
437 THIS_MODULE);
438}
439
440static struct usb_driver sd_driver = {
441 .name = MODULE_NAME,
442 .id_table = device_table,
443 .probe = sd_probe,
444 .disconnect = gspca_disconnect,
445#ifdef CONFIG_PM
446 .suspend = gspca_suspend,
447 .resume = gspca_resume,
448#endif
449};
450
451/* -- module insert / remove -- */
452static int __init sd_mod_init(void)
453{
454 if (usb_register(&sd_driver) < 0)
455 return -1;
456 PDEBUG(D_PROBE, "registered");
457 return 0;
458}
459static void __exit sd_mod_exit(void)
460{
461 usb_deregister(&sd_driver);
462 PDEBUG(D_PROBE, "deregistered");
463}
464
465module_init(sd_mod_init);
466module_exit(sd_mod_exit);
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index ac95c55887df..c21af312ee7c 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -29,6 +29,7 @@
29#include <linux/string.h> 29#include <linux/string.h>
30#include <linux/pagemap.h> 30#include <linux/pagemap.h>
31#include <linux/io.h> 31#include <linux/io.h>
32#include <linux/kref.h>
32#include <asm/page.h> 33#include <asm/page.h>
33#include <linux/uaccess.h> 34#include <linux/uaccess.h>
34#include <linux/jiffies.h> 35#include <linux/jiffies.h>
@@ -43,7 +44,7 @@ MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
43MODULE_DESCRIPTION("GSPCA USB Camera Driver"); 44MODULE_DESCRIPTION("GSPCA USB Camera Driver");
44MODULE_LICENSE("GPL"); 45MODULE_LICENSE("GPL");
45 46
46#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 2, 0) 47#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 3, 0)
47 48
48static int video_nr = -1; 49static int video_nr = -1;
49 50
@@ -102,6 +103,22 @@ static struct vm_operations_struct gspca_vm_ops = {
102 .close = gspca_vm_close, 103 .close = gspca_vm_close,
103}; 104};
104 105
106/* get the current input frame buffer */
107struct gspca_frame *gspca_get_i_frame(struct gspca_dev *gspca_dev)
108{
109 struct gspca_frame *frame;
110 int i;
111
112 i = gspca_dev->fr_i;
113 i = gspca_dev->fr_queue[i];
114 frame = &gspca_dev->frame[i];
115 if ((frame->v4l2_buf.flags & BUF_ALL_FLAGS)
116 != V4L2_BUF_FLAG_QUEUED)
117 return NULL;
118 return frame;
119}
120EXPORT_SYMBOL(gspca_get_i_frame);
121
105/* 122/*
106 * fill a video frame from an URB and resubmit 123 * fill a video frame from an URB and resubmit
107 */ 124 */
@@ -110,7 +127,7 @@ static void fill_frame(struct gspca_dev *gspca_dev,
110{ 127{
111 struct gspca_frame *frame; 128 struct gspca_frame *frame;
112 __u8 *data; /* address of data in the iso message */ 129 __u8 *data; /* address of data in the iso message */
113 int i, j, len, st; 130 int i, len, st;
114 cam_pkt_op pkt_scan; 131 cam_pkt_op pkt_scan;
115 132
116 if (urb->status != 0) { 133 if (urb->status != 0) {
@@ -124,11 +141,8 @@ static void fill_frame(struct gspca_dev *gspca_dev,
124 for (i = 0; i < urb->number_of_packets; i++) { 141 for (i = 0; i < urb->number_of_packets; i++) {
125 142
126 /* check the availability of the frame buffer */ 143 /* check the availability of the frame buffer */
127 j = gspca_dev->fr_i; 144 frame = gspca_get_i_frame(gspca_dev);
128 j = gspca_dev->fr_queue[j]; 145 if (!frame) {
129 frame = &gspca_dev->frame[j];
130 if ((frame->v4l2_buf.flags & BUF_ALL_FLAGS)
131 != V4L2_BUF_FLAG_QUEUED) {
132 gspca_dev->last_packet_type = DISCARD_PACKET; 146 gspca_dev->last_packet_type = DISCARD_PACKET;
133 break; 147 break;
134 } 148 }
@@ -178,6 +192,39 @@ static void isoc_irq(struct urb *urb
178} 192}
179 193
180/* 194/*
195 * bulk message interrupt from the USB device
196 */
197static void bulk_irq(struct urb *urb
198)
199{
200 struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context;
201 struct gspca_frame *frame;
202
203 PDEBUG(D_PACK, "bulk irq");
204 if (!gspca_dev->streaming)
205 return;
206 if (urb->status != 0 && urb->status != -ECONNRESET) {
207#ifdef CONFIG_PM
208 if (!gspca_dev->frozen)
209#endif
210 PDEBUG(D_ERR|D_PACK, "urb status: %d", urb->status);
211 return; /* disconnection ? */
212 }
213
214 /* check the availability of the frame buffer */
215 frame = gspca_get_i_frame(gspca_dev);
216 if (!frame) {
217 gspca_dev->last_packet_type = DISCARD_PACKET;
218 } else {
219 PDEBUG(D_PACK, "packet l:%d", urb->actual_length);
220 gspca_dev->sd_desc->pkt_scan(gspca_dev,
221 frame,
222 urb->transfer_buffer,
223 urb->actual_length);
224 }
225}
226
227/*
181 * add data to the current frame 228 * add data to the current frame
182 * 229 *
183 * This function is called by the subdrivers at interrupt level. 230 * This function is called by the subdrivers at interrupt level.
@@ -190,7 +237,7 @@ static void isoc_irq(struct urb *urb
190 * On LAST_PACKET, a new frame is returned. 237 * On LAST_PACKET, a new frame is returned.
191 */ 238 */
192struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev, 239struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
193 int packet_type, 240 enum gspca_packet_type packet_type,
194 struct gspca_frame *frame, 241 struct gspca_frame *frame,
195 const __u8 *data, 242 const __u8 *data,
196 int len) 243 int len)
@@ -232,7 +279,7 @@ struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
232 } 279 }
233 gspca_dev->last_packet_type = packet_type; 280 gspca_dev->last_packet_type = packet_type;
234 281
235 /* if last packet, wake the application and advance in the queue */ 282 /* if last packet, wake up the application and advance in the queue */
236 if (packet_type == LAST_PACKET) { 283 if (packet_type == LAST_PACKET) {
237 frame->v4l2_buf.bytesused = frame->data_end - frame->data; 284 frame->v4l2_buf.bytesused = frame->data_end - frame->data;
238 frame->v4l2_buf.flags &= ~V4L2_BUF_FLAG_QUEUED; 285 frame->v4l2_buf.flags &= ~V4L2_BUF_FLAG_QUEUED;
@@ -270,7 +317,6 @@ static void *rvmalloc(unsigned long size)
270 void *mem; 317 void *mem;
271 unsigned long adr; 318 unsigned long adr;
272 319
273/* size = PAGE_ALIGN(size); (already done) */
274 mem = vmalloc_32(size); 320 mem = vmalloc_32(size);
275 if (mem != NULL) { 321 if (mem != NULL) {
276 adr = (unsigned long) mem; 322 adr = (unsigned long) mem;
@@ -374,10 +420,11 @@ static void destroy_urbs(struct gspca_dev *gspca_dev)
374} 420}
375 421
376/* 422/*
377 * search an input isochronous endpoint in an alternate setting 423 * look for an input transfer endpoint in an alternate setting
378 */ 424 */
379static struct usb_host_endpoint *alt_isoc(struct usb_host_interface *alt, 425static struct usb_host_endpoint *alt_xfer(struct usb_host_interface *alt,
380 __u8 epaddr) 426 __u8 epaddr,
427 __u8 xfer)
381{ 428{
382 struct usb_host_endpoint *ep; 429 struct usb_host_endpoint *ep;
383 int i, attr; 430 int i, attr;
@@ -388,7 +435,7 @@ static struct usb_host_endpoint *alt_isoc(struct usb_host_interface *alt,
388 if (ep->desc.bEndpointAddress == epaddr) { 435 if (ep->desc.bEndpointAddress == epaddr) {
389 attr = ep->desc.bmAttributes 436 attr = ep->desc.bmAttributes
390 & USB_ENDPOINT_XFERTYPE_MASK; 437 & USB_ENDPOINT_XFERTYPE_MASK;
391 if (attr == USB_ENDPOINT_XFER_ISOC) 438 if (attr == xfer)
392 return ep; 439 return ep;
393 break; 440 break;
394 } 441 }
@@ -397,14 +444,14 @@ static struct usb_host_endpoint *alt_isoc(struct usb_host_interface *alt,
397} 444}
398 445
399/* 446/*
400 * search an input isochronous endpoint 447 * look for an input (isoc or bulk) endpoint
401 * 448 *
402 * The endpoint is defined by the subdriver. 449 * The endpoint is defined by the subdriver.
403 * Use only the first isoc (some Zoran - 0x0572:0x0001 - have two such ep). 450 * Use only the first isoc (some Zoran - 0x0572:0x0001 - have two such ep).
404 * This routine may be called many times when the bandwidth is too small 451 * This routine may be called many times when the bandwidth is too small
405 * (the bandwidth is checked on urb submit). 452 * (the bandwidth is checked on urb submit).
406 */ 453 */
407static struct usb_host_endpoint *get_isoc_ep(struct gspca_dev *gspca_dev) 454static struct usb_host_endpoint *get_ep(struct gspca_dev *gspca_dev)
408{ 455{
409 struct usb_interface *intf; 456 struct usb_interface *intf;
410 struct usb_host_endpoint *ep; 457 struct usb_host_endpoint *ep;
@@ -413,28 +460,41 @@ static struct usb_host_endpoint *get_isoc_ep(struct gspca_dev *gspca_dev)
413 intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface); 460 intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface);
414 ep = NULL; 461 ep = NULL;
415 i = gspca_dev->alt; /* previous alt setting */ 462 i = gspca_dev->alt; /* previous alt setting */
463
464 /* try isoc */
416 while (--i > 0) { /* alt 0 is unusable */ 465 while (--i > 0) { /* alt 0 is unusable */
417 ep = alt_isoc(&intf->altsetting[i], gspca_dev->cam.epaddr); 466 ep = alt_xfer(&intf->altsetting[i],
467 gspca_dev->cam.epaddr,
468 USB_ENDPOINT_XFER_ISOC);
418 if (ep) 469 if (ep)
419 break; 470 break;
420 } 471 }
472
473 /* if no isoc, try bulk */
421 if (ep == NULL) { 474 if (ep == NULL) {
422 err("no ISOC endpoint found"); 475 ep = alt_xfer(&intf->altsetting[0],
423 return NULL; 476 gspca_dev->cam.epaddr,
477 USB_ENDPOINT_XFER_BULK);
478 if (ep == NULL) {
479 err("no transfer endpoint found");
480 return NULL;
481 }
424 } 482 }
425 PDEBUG(D_STREAM, "use ISOC alt %d ep 0x%02x", 483 PDEBUG(D_STREAM, "use alt %d ep 0x%02x",
426 i, ep->desc.bEndpointAddress); 484 i, ep->desc.bEndpointAddress);
427 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, i); 485 if (i > 0) {
428 if (ret < 0) { 486 ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, i);
429 err("set interface err %d", ret); 487 if (ret < 0) {
430 return NULL; 488 err("set interface err %d", ret);
489 return NULL;
490 }
431 } 491 }
432 gspca_dev->alt = i; /* memorize the current alt setting */ 492 gspca_dev->alt = i; /* memorize the current alt setting */
433 return ep; 493 return ep;
434} 494}
435 495
436/* 496/*
437 * create the isochronous URBs 497 * create the URBs for image transfer
438 */ 498 */
439static int create_urbs(struct gspca_dev *gspca_dev, 499static int create_urbs(struct gspca_dev *gspca_dev,
440 struct usb_host_endpoint *ep) 500 struct usb_host_endpoint *ep)
@@ -445,15 +505,27 @@ static int create_urbs(struct gspca_dev *gspca_dev,
445 /* calculate the packet size and the number of packets */ 505 /* calculate the packet size and the number of packets */
446 psize = le16_to_cpu(ep->desc.wMaxPacketSize); 506 psize = le16_to_cpu(ep->desc.wMaxPacketSize);
447 507
448 /* See paragraph 5.9 / table 5-11 of the usb 2.0 spec. */ 508 if (gspca_dev->alt != 0) { /* isoc */
449 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3)); 509
450 npkt = ISO_MAX_SIZE / psize; 510 /* See paragraph 5.9 / table 5-11 of the usb 2.0 spec. */
451 if (npkt > ISO_MAX_PKT) 511 psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
452 npkt = ISO_MAX_PKT; 512 npkt = ISO_MAX_SIZE / psize;
453 bsize = psize * npkt; 513 if (npkt > ISO_MAX_PKT)
454 PDEBUG(D_STREAM, 514 npkt = ISO_MAX_PKT;
455 "isoc %d pkts size %d (bsize:%d)", npkt, psize, bsize); 515 bsize = psize * npkt;
456 nurbs = DEF_NURBS; 516 PDEBUG(D_STREAM,
517 "isoc %d pkts size %d = bsize:%d",
518 npkt, psize, bsize);
519 nurbs = DEF_NURBS;
520 } else { /* bulk */
521 npkt = 0;
522 bsize = gspca_dev->cam. bulk_size;
523 if (bsize == 0)
524 bsize = psize;
525 PDEBUG(D_STREAM, "bulk bsize:%d", bsize);
526 nurbs = 1;
527 }
528
457 gspca_dev->nurbs = nurbs; 529 gspca_dev->nurbs = nurbs;
458 for (n = 0; n < nurbs; n++) { 530 for (n = 0; n < nurbs; n++) {
459 urb = usb_alloc_urb(npkt, GFP_KERNEL); 531 urb = usb_alloc_urb(npkt, GFP_KERNEL);
@@ -476,17 +548,24 @@ static int create_urbs(struct gspca_dev *gspca_dev,
476 gspca_dev->urb[n] = urb; 548 gspca_dev->urb[n] = urb;
477 urb->dev = gspca_dev->dev; 549 urb->dev = gspca_dev->dev;
478 urb->context = gspca_dev; 550 urb->context = gspca_dev;
479 urb->pipe = usb_rcvisocpipe(gspca_dev->dev,
480 ep->desc.bEndpointAddress);
481 urb->transfer_flags = URB_ISO_ASAP
482 | URB_NO_TRANSFER_DMA_MAP;
483 urb->interval = ep->desc.bInterval;
484 urb->complete = isoc_irq;
485 urb->number_of_packets = npkt;
486 urb->transfer_buffer_length = bsize; 551 urb->transfer_buffer_length = bsize;
487 for (i = 0; i < npkt; i++) { 552 if (npkt != 0) { /* ISOC */
488 urb->iso_frame_desc[i].length = psize; 553 urb->pipe = usb_rcvisocpipe(gspca_dev->dev,
489 urb->iso_frame_desc[i].offset = psize * i; 554 ep->desc.bEndpointAddress);
555 urb->transfer_flags = URB_ISO_ASAP
556 | URB_NO_TRANSFER_DMA_MAP;
557 urb->interval = ep->desc.bInterval;
558 urb->complete = isoc_irq;
559 urb->number_of_packets = npkt;
560 for (i = 0; i < npkt; i++) {
561 urb->iso_frame_desc[i].length = psize;
562 urb->iso_frame_desc[i].offset = psize * i;
563 }
564 } else { /* bulk */
565 urb->pipe = usb_rcvbulkpipe(gspca_dev->dev,
566 ep->desc.bEndpointAddress),
567 urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
568 urb->complete = bulk_irq;
490 } 569 }
491 } 570 }
492 return 0; 571 return 0;
@@ -508,7 +587,7 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
508 gspca_dev->alt = gspca_dev->nbalt; 587 gspca_dev->alt = gspca_dev->nbalt;
509 for (;;) { 588 for (;;) {
510 PDEBUG(D_STREAM, "init transfer alt %d", gspca_dev->alt); 589 PDEBUG(D_STREAM, "init transfer alt %d", gspca_dev->alt);
511 ep = get_isoc_ep(gspca_dev); 590 ep = get_ep(gspca_dev);
512 if (ep == NULL) { 591 if (ep == NULL) {
513 ret = -EIO; 592 ret = -EIO;
514 goto out; 593 goto out;
@@ -518,10 +597,18 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
518 goto out; 597 goto out;
519 598
520 /* start the cam */ 599 /* start the cam */
521 gspca_dev->sd_desc->start(gspca_dev); 600 ret = gspca_dev->sd_desc->start(gspca_dev);
601 if (ret < 0) {
602 destroy_urbs(gspca_dev);
603 goto out;
604 }
522 gspca_dev->streaming = 1; 605 gspca_dev->streaming = 1;
523 atomic_set(&gspca_dev->nevent, 0); 606 atomic_set(&gspca_dev->nevent, 0);
524 607
608 /* bulk transfers are started by the subdriver */
609 if (gspca_dev->alt == 0)
610 break;
611
525 /* submit the URBs */ 612 /* submit the URBs */
526 for (n = 0; n < gspca_dev->nurbs; n++) { 613 for (n = 0; n < gspca_dev->nurbs; n++) {
527 ret = usb_submit_urb(gspca_dev->urb[n], GFP_KERNEL); 614 ret = usb_submit_urb(gspca_dev->urb[n], GFP_KERNEL);
@@ -553,7 +640,7 @@ static int gspca_set_alt0(struct gspca_dev *gspca_dev)
553 return ret; 640 return ret;
554} 641}
555 642
556/* Note both the queue and the usb lock should be hold when calling this */ 643/* Note: both the queue and the usb locks should be held when calling this */
557static void gspca_stream_off(struct gspca_dev *gspca_dev) 644static void gspca_stream_off(struct gspca_dev *gspca_dev)
558{ 645{
559 gspca_dev->streaming = 0; 646 gspca_dev->streaming = 0;
@@ -759,6 +846,16 @@ out:
759 return ret; 846 return ret;
760} 847}
761 848
849static void gspca_delete(struct kref *kref)
850{
851 struct gspca_dev *gspca_dev = container_of(kref, struct gspca_dev, kref);
852
853 PDEBUG(D_STREAM, "device deleted");
854
855 kfree(gspca_dev->usb_buf);
856 kfree(gspca_dev);
857}
858
762static int dev_open(struct inode *inode, struct file *file) 859static int dev_open(struct inode *inode, struct file *file)
763{ 860{
764 struct gspca_dev *gspca_dev; 861 struct gspca_dev *gspca_dev;
@@ -778,13 +875,19 @@ static int dev_open(struct inode *inode, struct file *file)
778 goto out; 875 goto out;
779 } 876 }
780 gspca_dev->users++; 877 gspca_dev->users++;
878
879 /* one more user */
880 kref_get(&gspca_dev->kref);
881
781 file->private_data = gspca_dev; 882 file->private_data = gspca_dev;
782#ifdef GSPCA_DEBUG 883#ifdef GSPCA_DEBUG
783 /* activate the v4l2 debug */ 884 /* activate the v4l2 debug */
784 if (gspca_debug & D_V4L2) 885 if (gspca_debug & D_V4L2)
785 gspca_dev->vdev.debug |= 3; 886 gspca_dev->vdev.debug |= V4L2_DEBUG_IOCTL
887 | V4L2_DEBUG_IOCTL_ARG;
786 else 888 else
787 gspca_dev->vdev.debug &= ~3; 889 gspca_dev->vdev.debug &= ~(V4L2_DEBUG_IOCTL
890 | V4L2_DEBUG_IOCTL_ARG);
788#endif 891#endif
789 ret = 0; 892 ret = 0;
790out: 893out:
@@ -818,7 +921,11 @@ static int dev_close(struct inode *inode, struct file *file)
818 } 921 }
819 file->private_data = NULL; 922 file->private_data = NULL;
820 mutex_unlock(&gspca_dev->queue_lock); 923 mutex_unlock(&gspca_dev->queue_lock);
924
821 PDEBUG(D_STREAM, "close done"); 925 PDEBUG(D_STREAM, "close done");
926
927 kref_put(&gspca_dev->kref, gspca_delete);
928
822 return 0; 929 return 0;
823} 930}
824 931
@@ -829,7 +936,6 @@ static int vidioc_querycap(struct file *file, void *priv,
829 936
830 memset(cap, 0, sizeof *cap); 937 memset(cap, 0, sizeof *cap);
831 strncpy(cap->driver, gspca_dev->sd_desc->name, sizeof cap->driver); 938 strncpy(cap->driver, gspca_dev->sd_desc->name, sizeof cap->driver);
832/* strncpy(cap->card, gspca_dev->cam.dev_name, sizeof cap->card); */
833 if (gspca_dev->dev->product != NULL) { 939 if (gspca_dev->dev->product != NULL) {
834 strncpy(cap->card, gspca_dev->dev->product, 940 strncpy(cap->card, gspca_dev->dev->product,
835 sizeof cap->card); 941 sizeof cap->card);
@@ -1463,7 +1569,6 @@ static int vidioc_qbuf(struct file *file, void *priv,
1463 } 1569 }
1464 1570
1465 frame->v4l2_buf.flags |= V4L2_BUF_FLAG_QUEUED; 1571 frame->v4l2_buf.flags |= V4L2_BUF_FLAG_QUEUED;
1466/* frame->v4l2_buf.flags &= ~V4L2_BUF_FLAG_DONE; */
1467 1572
1468 if (frame->v4l2_buf.memory == V4L2_MEMORY_USERPTR) { 1573 if (frame->v4l2_buf.memory == V4L2_MEMORY_USERPTR) {
1469 frame->v4l2_buf.m.userptr = v4l2_buf->m.userptr; 1574 frame->v4l2_buf.m.userptr = v4l2_buf->m.userptr;
@@ -1610,7 +1715,7 @@ static ssize_t dev_read(struct file *file, char __user *data,
1610 } 1715 }
1611 1716
1612 /* if the process slept for more than 1 second, 1717 /* if the process slept for more than 1 second,
1613 * get anewer frame */ 1718 * get a newer frame */
1614 frame = &gspca_dev->frame[v4l2_buf.index]; 1719 frame = &gspca_dev->frame[v4l2_buf.index];
1615 if (--n < 0) 1720 if (--n < 0)
1616 break; /* avoid infinite loop */ 1721 break; /* avoid infinite loop */
@@ -1728,21 +1833,21 @@ int gspca_dev_probe(struct usb_interface *intf,
1728 if (dev_size < sizeof *gspca_dev) 1833 if (dev_size < sizeof *gspca_dev)
1729 dev_size = sizeof *gspca_dev; 1834 dev_size = sizeof *gspca_dev;
1730 gspca_dev = kzalloc(dev_size, GFP_KERNEL); 1835 gspca_dev = kzalloc(dev_size, GFP_KERNEL);
1731 if (gspca_dev == NULL) { 1836 if (!gspca_dev) {
1732 err("couldn't kzalloc gspca struct"); 1837 err("couldn't kzalloc gspca struct");
1733 return -EIO; 1838 return -ENOMEM;
1734 } 1839 }
1840 kref_init(&gspca_dev->kref);
1735 gspca_dev->usb_buf = kmalloc(USB_BUF_SZ, GFP_KERNEL); 1841 gspca_dev->usb_buf = kmalloc(USB_BUF_SZ, GFP_KERNEL);
1736 if (!gspca_dev->usb_buf) { 1842 if (!gspca_dev->usb_buf) {
1737 err("out of memory"); 1843 err("out of memory");
1738 ret = -EIO; 1844 ret = -ENOMEM;
1739 goto out; 1845 goto out;
1740 } 1846 }
1741 gspca_dev->dev = dev; 1847 gspca_dev->dev = dev;
1742 gspca_dev->iface = interface->bInterfaceNumber; 1848 gspca_dev->iface = interface->bInterfaceNumber;
1743 gspca_dev->nbalt = intf->num_altsetting; 1849 gspca_dev->nbalt = intf->num_altsetting;
1744 gspca_dev->sd_desc = sd_desc; 1850 gspca_dev->sd_desc = sd_desc;
1745/* gspca_dev->users = 0; (done by kzalloc) */
1746 gspca_dev->nbufread = 2; 1851 gspca_dev->nbufread = 2;
1747 1852
1748 /* configure the subdriver and initialize the USB device */ 1853 /* configure the subdriver and initialize the USB device */
@@ -1781,8 +1886,7 @@ int gspca_dev_probe(struct usb_interface *intf,
1781 PDEBUG(D_PROBE, "probe ok"); 1886 PDEBUG(D_PROBE, "probe ok");
1782 return 0; 1887 return 0;
1783out: 1888out:
1784 kfree(gspca_dev->usb_buf); 1889 kref_put(&gspca_dev->kref, gspca_delete);
1785 kfree(gspca_dev);
1786 return ret; 1890 return ret;
1787} 1891}
1788EXPORT_SYMBOL(gspca_dev_probe); 1892EXPORT_SYMBOL(gspca_dev_probe);
@@ -1797,25 +1901,16 @@ void gspca_disconnect(struct usb_interface *intf)
1797{ 1901{
1798 struct gspca_dev *gspca_dev = usb_get_intfdata(intf); 1902 struct gspca_dev *gspca_dev = usb_get_intfdata(intf);
1799 1903
1800 if (!gspca_dev) 1904 usb_set_intfdata(intf, NULL);
1801 return; 1905
1802 gspca_dev->present = 0;
1803 mutex_lock(&gspca_dev->queue_lock);
1804 mutex_lock(&gspca_dev->usb_lock);
1805 gspca_dev->streaming = 0;
1806 destroy_urbs(gspca_dev);
1807 mutex_unlock(&gspca_dev->usb_lock);
1808 mutex_unlock(&gspca_dev->queue_lock);
1809 while (gspca_dev->users != 0) { /* wait until fully closed */
1810 atomic_inc(&gspca_dev->nevent);
1811 wake_up_interruptible(&gspca_dev->wq); /* wake processes */
1812 schedule();
1813 }
1814/* We don't want people trying to open up the device */ 1906/* We don't want people trying to open up the device */
1815 video_unregister_device(&gspca_dev->vdev); 1907 video_unregister_device(&gspca_dev->vdev);
1816/* Free the memory */ 1908
1817 kfree(gspca_dev->usb_buf); 1909 gspca_dev->present = 0;
1818 kfree(gspca_dev); 1910 gspca_dev->streaming = 0;
1911
1912 kref_put(&gspca_dev->kref, gspca_delete);
1913
1819 PDEBUG(D_PROBE, "disconnect complete"); 1914 PDEBUG(D_PROBE, "disconnect complete");
1820} 1915}
1821EXPORT_SYMBOL(gspca_disconnect); 1916EXPORT_SYMBOL(gspca_disconnect);
diff --git a/drivers/media/video/gspca/gspca.h b/drivers/media/video/gspca/gspca.h
index c17625cff9ba..4779dd0b06da 100644
--- a/drivers/media/video/gspca/gspca.h
+++ b/drivers/media/video/gspca/gspca.h
@@ -49,13 +49,14 @@ extern int gspca_debug;
49 } while (0) 49 } while (0)
50 50
51#define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */ 51#define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */
52/* ISOC transfers */ 52/* image transfers */
53#define MAX_NURBS 16 /* max number of URBs */ 53#define MAX_NURBS 4 /* max number of URBs */
54#define ISO_MAX_PKT 32 /* max number of packets in an ISOC transfer */ 54#define ISO_MAX_PKT 32 /* max number of packets in an ISOC transfer */
55#define ISO_MAX_SIZE 0x8000 /* max size of one URB buffer (32 Kb) */ 55#define ISO_MAX_SIZE 0x8000 /* max size of one URB buffer (32 Kb) */
56 56
57/* device information - set at probe time */ 57/* device information - set at probe time */
58struct cam { 58struct cam {
59 int bulk_size; /* buffer size when image transfer by bulk */
59 struct v4l2_pix_format *cam_mode; /* size nmodes */ 60 struct v4l2_pix_format *cam_mode; /* size nmodes */
60 char nmodes; 61 char nmodes;
61 __u8 epaddr; 62 __u8 epaddr;
@@ -93,7 +94,7 @@ struct sd_desc {
93/* mandatory operations */ 94/* mandatory operations */
94 cam_cf_op config; /* called on probe */ 95 cam_cf_op config; /* called on probe */
95 cam_op init; /* called on probe and resume */ 96 cam_op init; /* called on probe and resume */
96 cam_v_op start; /* called on stream on */ 97 cam_op start; /* called on stream on */
97 cam_pkt_op pkt_scan; 98 cam_pkt_op pkt_scan;
98/* optional operations */ 99/* optional operations */
99 cam_v_op stopN; /* called on stream off - main alt */ 100 cam_v_op stopN; /* called on stream off - main alt */
@@ -105,10 +106,12 @@ struct sd_desc {
105}; 106};
106 107
107/* packet types when moving from iso buf to frame buf */ 108/* packet types when moving from iso buf to frame buf */
108#define DISCARD_PACKET 0 109enum gspca_packet_type {
109#define FIRST_PACKET 1 110 DISCARD_PACKET,
110#define INTER_PACKET 2 111 FIRST_PACKET,
111#define LAST_PACKET 3 112 INTER_PACKET,
113 LAST_PACKET
114};
112 115
113struct gspca_frame { 116struct gspca_frame {
114 __u8 *data; /* frame buffer */ 117 __u8 *data; /* frame buffer */
@@ -121,6 +124,7 @@ struct gspca_dev {
121 struct video_device vdev; /* !! must be the first item */ 124 struct video_device vdev; /* !! must be the first item */
122 struct file_operations fops; 125 struct file_operations fops;
123 struct usb_device *dev; 126 struct usb_device *dev;
127 struct kref kref;
124 struct file *capt_file; /* file doing video capture */ 128 struct file *capt_file; /* file doing video capture */
125 129
126 struct cam cam; /* device information */ 130 struct cam cam; /* device information */
@@ -173,10 +177,11 @@ int gspca_dev_probe(struct usb_interface *intf,
173 struct module *module); 177 struct module *module);
174void gspca_disconnect(struct usb_interface *intf); 178void gspca_disconnect(struct usb_interface *intf);
175struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev, 179struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
176 int packet_type, 180 enum gspca_packet_type packet_type,
177 struct gspca_frame *frame, 181 struct gspca_frame *frame,
178 const __u8 *data, 182 const __u8 *data,
179 int len); 183 int len);
184struct gspca_frame *gspca_get_i_frame(struct gspca_dev *gspca_dev);
180#ifdef CONFIG_PM 185#ifdef CONFIG_PM
181int gspca_suspend(struct usb_interface *intf, pm_message_t message); 186int gspca_suspend(struct usb_interface *intf, pm_message_t message);
182int gspca_resume(struct usb_interface *intf); 187int gspca_resume(struct usb_interface *intf);
diff --git a/drivers/media/video/gspca/m5602/Kconfig b/drivers/media/video/gspca/m5602/Kconfig
new file mode 100644
index 000000000000..5a69016ed75f
--- /dev/null
+++ b/drivers/media/video/gspca/m5602/Kconfig
@@ -0,0 +1,11 @@
1config USB_M5602
2 tristate "ALi USB m5602 Camera Driver"
3 depends on VIDEO_V4L2 && USB_GSPCA
4 help
5 Say Y here if you want support for cameras based on the
6 ALi m5602 connected to various image sensors.
7
8 See <file:Documentation/video4linux/m5602.txt> for more info.
9
10 To compile this driver as a module, choose M here: the
11 module will be called gspca_m5602.
diff --git a/drivers/media/video/gspca/m5602/Makefile b/drivers/media/video/gspca/m5602/Makefile
new file mode 100644
index 000000000000..226ab4fc9d60
--- /dev/null
+++ b/drivers/media/video/gspca/m5602/Makefile
@@ -0,0 +1,11 @@
1obj-$(CONFIG_USB_M5602) += gspca_m5602.o
2
3gspca_m5602-objs := m5602_core.o \
4 m5602_ov9650.o \
5 m5602_mt9m111.o \
6 m5602_po1030.o \
7 m5602_s5k83a.o \
8 m5602_s5k4aa.o
9
10EXTRA_CFLAGS += -Idrivers/media/video/gspca
11
diff --git a/drivers/media/video/gspca/m5602/m5602_bridge.h b/drivers/media/video/gspca/m5602/m5602_bridge.h
new file mode 100644
index 000000000000..c786d7d3d44a
--- /dev/null
+++ b/drivers/media/video/gspca/m5602/m5602_bridge.h
@@ -0,0 +1,170 @@
1/*
2 * USB Driver for ALi m5602 based webcams
3 *
4 * Copyright (C) 2008 Erik Andren
5 * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
6 * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
7 *
8 * Portions of code to USB interface and ALi driver software,
9 * Copyright (c) 2006 Willem Duinker
10 * v4l2 interface modeled after the V4L2 driver
11 * for SN9C10x PC Camera Controllers
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation, version 2.
16 *
17 */
18
19#ifndef M5602_BRIDGE_H_
20#define M5602_BRIDGE_H_
21
22#include "gspca.h"
23
24#define MODULE_NAME "ALi m5602"
25
26/*****************************************************************************/
27
28#undef PDEBUG
29#undef info
30#undef err
31
32#define err(format, arg...) printk(KERN_ERR KBUILD_MODNAME ": " \
33 format "\n" , ## arg)
34#define info(format, arg...) printk(KERN_INFO KBUILD_MODNAME ": " \
35 format "\n" , ## arg)
36
37/* Debug parameters */
38#define DBG_INIT 0x1
39#define DBG_PROBE 0x2
40#define DBG_V4L2 0x4
41#define DBG_TRACE 0x8
42#define DBG_DATA 0x10
43#define DBG_V4L2_CID 0x20
44#define DBG_GSPCA 0x40
45
46#define PDEBUG(level, fmt, args...) \
47 do { \
48 if (m5602_debug & level) \
49 info("[%s:%d] " fmt, __func__, __LINE__ , \
50 ## args); \
51 } while (0)
52
53/*****************************************************************************/
54
55#define M5602_XB_SENSOR_TYPE 0x00
56#define M5602_XB_SENSOR_CTRL 0x01
57#define M5602_XB_LINE_OF_FRAME_H 0x02
58#define M5602_XB_LINE_OF_FRAME_L 0x03
59#define M5602_XB_PIX_OF_LINE_H 0x04
60#define M5602_XB_PIX_OF_LINE_L 0x05
61#define M5602_XB_VSYNC_PARA 0x06
62#define M5602_XB_HSYNC_PARA 0x07
63#define M5602_XB_TEST_MODE_1 0x08
64#define M5602_XB_TEST_MODE_2 0x09
65#define M5602_XB_SIG_INI 0x0a
66#define M5602_XB_DS_PARA 0x0e
67#define M5602_XB_TRIG_PARA 0x0f
68#define M5602_XB_CLK_PD 0x10
69#define M5602_XB_MCU_CLK_CTRL 0x12
70#define M5602_XB_MCU_CLK_DIV 0x13
71#define M5602_XB_SEN_CLK_CTRL 0x14
72#define M5602_XB_SEN_CLK_DIV 0x15
73#define M5602_XB_AUD_CLK_CTRL 0x16
74#define M5602_XB_AUD_CLK_DIV 0x17
75#define M5602_XB_DEVCTR1 0x41
76#define M5602_XB_EPSETR0 0x42
77#define M5602_XB_EPAFCTR 0x47
78#define M5602_XB_EPBFCTR 0x49
79#define M5602_XB_EPEFCTR 0x4f
80#define M5602_XB_TEST_REG 0x53
81#define M5602_XB_ALT2SIZE 0x54
82#define M5602_XB_ALT3SIZE 0x55
83#define M5602_XB_OBSFRAME 0x56
84#define M5602_XB_PWR_CTL 0x59
85#define M5602_XB_ADC_CTRL 0x60
86#define M5602_XB_ADC_DATA 0x61
87#define M5602_XB_MISC_CTRL 0x62
88#define M5602_XB_SNAPSHOT 0x63
89#define M5602_XB_SCRATCH_1 0x64
90#define M5602_XB_SCRATCH_2 0x65
91#define M5602_XB_SCRATCH_3 0x66
92#define M5602_XB_SCRATCH_4 0x67
93#define M5602_XB_I2C_CTRL 0x68
94#define M5602_XB_I2C_CLK_DIV 0x69
95#define M5602_XB_I2C_DEV_ADDR 0x6a
96#define M5602_XB_I2C_REG_ADDR 0x6b
97#define M5602_XB_I2C_DATA 0x6c
98#define M5602_XB_I2C_STATUS 0x6d
99#define M5602_XB_GPIO_DAT_H 0x70
100#define M5602_XB_GPIO_DAT_L 0x71
101#define M5602_XB_GPIO_DIR_H 0x72
102#define M5602_XB_GPIO_DIR_L 0x73
103#define M5602_XB_GPIO_EN_H 0x74
104#define M5602_XB_GPIO_EN_L 0x75
105#define M5602_XB_GPIO_DAT 0x76
106#define M5602_XB_GPIO_DIR 0x77
107#define M5602_XB_MISC_CTL 0x70
108
109#define I2C_BUSY 0x80
110
111/*****************************************************************************/
112
113/* Driver info */
114#define DRIVER_AUTHOR "ALi m5602 Linux Driver Project"
115#define DRIVER_DESC "ALi m5602 webcam driver"
116
117#define M5602_ISOC_ENDPOINT_ADDR 0x81
118#define M5602_INTR_ENDPOINT_ADDR 0x82
119
120#define M5602_MAX_FRAMES 32
121#define M5602_URBS 2
122#define M5602_ISOC_PACKETS 14
123
124#define M5602_URB_TIMEOUT msecs_to_jiffies(2 * M5602_ISOC_PACKETS)
125#define M5602_URB_MSG_TIMEOUT 5000
126#define M5602_FRAME_TIMEOUT 2
127
128/*****************************************************************************/
129
130/* A skeleton used for sending messages to the m5602 bridge */
131static const unsigned char bridge_urb_skeleton[] = {
132 0x13, 0x00, 0x81, 0x00
133};
134
135/* A skeleton used for sending messages to the sensor */
136static const unsigned char sensor_urb_skeleton[] = {
137 0x23, M5602_XB_GPIO_EN_H, 0x81, 0x06,
138 0x23, M5602_XB_MISC_CTRL, 0x81, 0x80,
139 0x13, M5602_XB_I2C_DEV_ADDR, 0x81, 0x00,
140 0x13, M5602_XB_I2C_REG_ADDR, 0x81, 0x00,
141 0x13, M5602_XB_I2C_DATA, 0x81, 0x00,
142 0x13, M5602_XB_I2C_CTRL, 0x81, 0x11
143};
144
145/* m5602 device descriptor, currently it just wraps the m5602_camera struct */
146struct sd {
147 struct gspca_dev gspca_dev;
148
149 /* The name of the m5602 camera */
150 char *name;
151
152 /* A pointer to the currently connected sensor */
153 struct m5602_sensor *sensor;
154
155 struct sd_desc *desc;
156
157 /* The current frame's id, used to detect frame boundaries */
158 u8 frame_id;
159
160 /* The current frame count */
161 u32 frame_count;
162};
163
164int m5602_read_bridge(
165 struct sd *sd, u8 address, u8 *i2c_data);
166
167int m5602_write_bridge(
168 struct sd *sd, u8 address, u8 i2c_data);
169
170#endif
diff --git a/drivers/media/video/gspca/m5602/m5602_core.c b/drivers/media/video/gspca/m5602/m5602_core.c
new file mode 100644
index 000000000000..19d5e351ccc1
--- /dev/null
+++ b/drivers/media/video/gspca/m5602/m5602_core.c
@@ -0,0 +1,313 @@
1/*
2 * USB Driver for ALi m5602 based webcams
3 *
4 * Copyright (C) 2008 Erik Andren
5 * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
6 * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
7 *
8 * Portions of code to USB interface and ALi driver software,
9 * Copyright (c) 2006 Willem Duinker
10 * v4l2 interface modeled after the V4L2 driver
11 * for SN9C10x PC Camera Controllers
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation, version 2.
16 *
17 */
18
19#include "m5602_ov9650.h"
20#include "m5602_mt9m111.h"
21#include "m5602_po1030.h"
22#include "m5602_s5k83a.h"
23#include "m5602_s5k4aa.h"
24
25/* Kernel module parameters */
26int force_sensor;
27int dump_bridge;
28int dump_sensor;
29unsigned int m5602_debug;
30
31static const __devinitdata struct usb_device_id m5602_table[] = {
32 {USB_DEVICE(0x0402, 0x5602)},
33 {}
34};
35
36MODULE_DEVICE_TABLE(usb, m5602_table);
37
38/* Reads a byte from the m5602 */
39int m5602_read_bridge(struct sd *sd, u8 address, u8 *i2c_data)
40{
41 int err;
42 struct usb_device *udev = sd->gspca_dev.dev;
43 __u8 *buf = sd->gspca_dev.usb_buf;
44
45 err = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
46 0x04, 0xc0, 0x14,
47 0x8100 + address, buf,
48 1, M5602_URB_MSG_TIMEOUT);
49 *i2c_data = buf[0];
50
51 PDEBUG(DBG_TRACE, "Reading bridge register 0x%x containing 0x%x",
52 address, *i2c_data);
53
54 /* usb_control_msg(...) returns the number of bytes sent upon success,
55 mask that and return zero upon success instead*/
56 return (err < 0) ? err : 0;
57}
58
59/* Writes a byte to to the m5602 */
60int m5602_write_bridge(struct sd *sd, u8 address, u8 i2c_data)
61{
62 int err;
63 struct usb_device *udev = sd->gspca_dev.dev;
64 __u8 *buf = sd->gspca_dev.usb_buf;
65
66 PDEBUG(DBG_TRACE, "Writing bridge register 0x%x with 0x%x",
67 address, i2c_data);
68
69 memcpy(buf, bridge_urb_skeleton,
70 sizeof(bridge_urb_skeleton));
71 buf[1] = address;
72 buf[3] = i2c_data;
73
74 err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
75 0x04, 0x40, 0x19,
76 0x0000, buf,
77 4, M5602_URB_MSG_TIMEOUT);
78
79 /* usb_control_msg(...) returns the number of bytes sent upon success,
80 mask that and return zero upon success instead */
81 return (err < 0) ? err : 0;
82}
83
84/* Dump all the registers of the m5602 bridge,
85 unfortunately this breaks the camera until it's power cycled */
86static void m5602_dump_bridge(struct sd *sd)
87{
88 int i;
89 for (i = 0; i < 0x80; i++) {
90 unsigned char val = 0;
91 m5602_read_bridge(sd, i, &val);
92 info("ALi m5602 address 0x%x contains 0x%x", i, val);
93 }
94 info("Warning: The camera probably won't work until it's power cycled");
95}
96
97static int m5602_probe_sensor(struct sd *sd)
98{
99 /* Try the po1030 */
100 sd->sensor = &po1030;
101 if (!sd->sensor->probe(sd))
102 return 0;
103
104 /* Try the mt9m111 sensor */
105 sd->sensor = &mt9m111;
106 if (!sd->sensor->probe(sd))
107 return 0;
108
109 /* Try the s5k4aa */
110 sd->sensor = &s5k4aa;
111 if (!sd->sensor->probe(sd))
112 return 0;
113
114 /* Try the ov9650 */
115 sd->sensor = &ov9650;
116 if (!sd->sensor->probe(sd))
117 return 0;
118
119 /* Try the s5k83a */
120 sd->sensor = &s5k83a;
121 if (!sd->sensor->probe(sd))
122 return 0;
123
124 /* More sensor probe function goes here */
125 info("Failed to find a sensor");
126 sd->sensor = NULL;
127 return -ENODEV;
128}
129
130static int m5602_configure(struct gspca_dev *gspca_dev,
131 const struct usb_device_id *id);
132
133static int m5602_init(struct gspca_dev *gspca_dev)
134{
135 struct sd *sd = (struct sd *) gspca_dev;
136 int err;
137
138 PDEBUG(DBG_TRACE, "Initializing ALi m5602 webcam");
139 /* Run the init sequence */
140 err = sd->sensor->init(sd);
141
142 return err;
143}
144
145static int m5602_start_transfer(struct gspca_dev *gspca_dev)
146{
147 struct sd *sd = (struct sd *) gspca_dev;
148 __u8 *buf = sd->gspca_dev.usb_buf;
149
150 /* Send start command to the camera */
151 const u8 buffer[4] = {0x13, 0xf9, 0x0f, 0x01};
152 memcpy(buf, buffer, sizeof(buffer));
153 usb_control_msg(gspca_dev->dev, usb_sndctrlpipe(gspca_dev->dev, 0),
154 0x04, 0x40, 0x19, 0x0000, buf,
155 4, M5602_URB_MSG_TIMEOUT);
156
157 PDEBUG(DBG_V4L2, "Transfer started");
158 return 0;
159}
160
161static void m5602_urb_complete(struct gspca_dev *gspca_dev,
162 struct gspca_frame *frame,
163 __u8 *data, int len)
164{
165 struct sd *sd = (struct sd *) gspca_dev;
166
167 if (len < 6) {
168 PDEBUG(DBG_DATA, "Packet is less than 6 bytes");
169 return;
170 }
171
172 /* Frame delimiter: ff xx xx xx ff ff */
173 if (data[0] == 0xff && data[4] == 0xff && data[5] == 0xff &&
174 data[2] != sd->frame_id) {
175 PDEBUG(DBG_DATA, "Frame delimiter detected");
176 sd->frame_id = data[2];
177
178 /* Remove the extra fluff appended on each header */
179 data += 6;
180 len -= 6;
181
182 /* Complete the last frame (if any) */
183 frame = gspca_frame_add(gspca_dev, LAST_PACKET,
184 frame, data, 0);
185 sd->frame_count++;
186
187 /* Create a new frame */
188 gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, len);
189
190 PDEBUG(DBG_V4L2, "Starting new frame %d",
191 sd->frame_count);
192
193 } else {
194 int cur_frame_len = frame->data_end - frame->data;
195
196 /* Remove urb header */
197 data += 4;
198 len -= 4;
199
200 if (cur_frame_len + len <= frame->v4l2_buf.length) {
201 PDEBUG(DBG_DATA, "Continuing frame %d copying %d bytes",
202 sd->frame_count, len);
203
204 gspca_frame_add(gspca_dev, INTER_PACKET, frame,
205 data, len);
206 } else if (frame->v4l2_buf.length - cur_frame_len > 0) {
207 /* Add the remaining data up to frame size */
208 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data,
209 frame->v4l2_buf.length - cur_frame_len);
210 }
211 }
212}
213
214static void m5602_stop_transfer(struct gspca_dev *gspca_dev)
215{
216 /* Is there are a command to stop a data transfer? */
217}
218
219/* sub-driver description, the ctrl and nctrl is filled at probe time */
220static struct sd_desc sd_desc = {
221 .name = MODULE_NAME,
222 .config = m5602_configure,
223 .init = m5602_init,
224 .start = m5602_start_transfer,
225 .stopN = m5602_stop_transfer,
226 .pkt_scan = m5602_urb_complete
227};
228
229/* this function is called at probe time */
230static int m5602_configure(struct gspca_dev *gspca_dev,
231 const struct usb_device_id *id)
232{
233 struct sd *sd = (struct sd *) gspca_dev;
234 struct cam *cam;
235 int err;
236
237 PDEBUG(DBG_GSPCA, "m5602_configure start");
238
239 cam = &gspca_dev->cam;
240 cam->epaddr = M5602_ISOC_ENDPOINT_ADDR;
241 sd->desc = &sd_desc;
242
243 if (dump_bridge)
244 m5602_dump_bridge(sd);
245
246 /* Probe sensor */
247 err = m5602_probe_sensor(sd);
248 if (err)
249 goto fail;
250
251 PDEBUG(DBG_GSPCA, "m5602_configure end");
252 return 0;
253
254fail:
255 PDEBUG(DBG_GSPCA, "m5602_configure failed");
256 cam->cam_mode = NULL;
257 cam->nmodes = 0;
258
259 return err;
260}
261
262static int m5602_probe(struct usb_interface *intf,
263 const struct usb_device_id *id)
264{
265 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
266 THIS_MODULE);
267}
268
269static struct usb_driver sd_driver = {
270 .name = MODULE_NAME,
271 .id_table = m5602_table,
272 .probe = m5602_probe,
273#ifdef CONFIG_PM
274 .suspend = gspca_suspend,
275 .resume = gspca_resume,
276#endif
277 .disconnect = gspca_disconnect
278};
279
280/* -- module insert / remove -- */
281static int __init mod_m5602_init(void)
282{
283 if (usb_register(&sd_driver) < 0)
284 return -1;
285 PDEBUG(D_PROBE, "m5602 module registered");
286 return 0;
287}
288static void __exit mod_m5602_exit(void)
289{
290 usb_deregister(&sd_driver);
291 PDEBUG(D_PROBE, "m5602 module deregistered");
292}
293
294module_init(mod_m5602_init);
295module_exit(mod_m5602_exit);
296
297MODULE_AUTHOR(DRIVER_AUTHOR);
298MODULE_DESCRIPTION(DRIVER_DESC);
299MODULE_LICENSE("GPL");
300module_param_named(debug, m5602_debug, int, S_IRUGO | S_IWUSR);
301MODULE_PARM_DESC(debug, "toggles debug on/off");
302
303module_param(force_sensor, int, S_IRUGO | S_IWUSR);
304MODULE_PARM_DESC(force_sensor,
305 "force detection of sensor, "
306 "1 = OV9650, 2 = S5K83A, 3 = S5K4AA, 4 = MT9M111, 5 = PO1030");
307
308module_param(dump_bridge, bool, S_IRUGO | S_IWUSR);
309MODULE_PARM_DESC(dump_bridge, "Dumps all usb bridge registers at startup");
310
311module_param(dump_sensor, bool, S_IRUGO | S_IWUSR);
312MODULE_PARM_DESC(dump_sensor, "Dumps all usb sensor registers "
313 "at startup providing a sensor is found");
diff --git a/drivers/media/video/gspca/m5602/m5602_mt9m111.c b/drivers/media/video/gspca/m5602/m5602_mt9m111.c
new file mode 100644
index 000000000000..566d4925a0e8
--- /dev/null
+++ b/drivers/media/video/gspca/m5602/m5602_mt9m111.c
@@ -0,0 +1,345 @@
1/*
2 * Driver for the mt9m111 sensor
3 *
4 * Copyright (C) 2008 Erik Andren
5 * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
6 * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
7 *
8 * Portions of code to USB interface and ALi driver software,
9 * Copyright (c) 2006 Willem Duinker
10 * v4l2 interface modeled after the V4L2 driver
11 * for SN9C10x PC Camera Controllers
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation, version 2.
16 *
17 */
18
19#include "m5602_mt9m111.h"
20
21int mt9m111_probe(struct sd *sd)
22{
23 u8 data[2] = {0x00, 0x00};
24 int i;
25
26 if (force_sensor) {
27 if (force_sensor == MT9M111_SENSOR) {
28 info("Forcing a %s sensor", mt9m111.name);
29 goto sensor_found;
30 }
31 /* If we want to force another sensor, don't try to probe this
32 * one */
33 return -ENODEV;
34 }
35
36 info("Probing for a mt9m111 sensor");
37
38 /* Do the preinit */
39 for (i = 0; i < ARRAY_SIZE(preinit_mt9m111); i++) {
40 if (preinit_mt9m111[i][0] == BRIDGE) {
41 m5602_write_bridge(sd,
42 preinit_mt9m111[i][1],
43 preinit_mt9m111[i][2]);
44 } else {
45 data[0] = preinit_mt9m111[i][2];
46 data[1] = preinit_mt9m111[i][3];
47 mt9m111_write_sensor(sd,
48 preinit_mt9m111[i][1], data, 2);
49 }
50 }
51
52 if (mt9m111_read_sensor(sd, MT9M111_SC_CHIPVER, data, 2))
53 return -ENODEV;
54
55 if ((data[0] == 0x14) && (data[1] == 0x3a)) {
56 info("Detected a mt9m111 sensor");
57 goto sensor_found;
58 }
59
60 return -ENODEV;
61
62sensor_found:
63 sd->gspca_dev.cam.cam_mode = mt9m111.modes;
64 sd->gspca_dev.cam.nmodes = mt9m111.nmodes;
65 sd->desc->ctrls = mt9m111.ctrls;
66 sd->desc->nctrls = mt9m111.nctrls;
67 return 0;
68}
69
70int mt9m111_init(struct sd *sd)
71{
72 int i, err = 0;
73
74 /* Init the sensor */
75 for (i = 0; i < ARRAY_SIZE(init_mt9m111); i++) {
76 u8 data[2];
77
78 if (init_mt9m111[i][0] == BRIDGE) {
79 err = m5602_write_bridge(sd,
80 init_mt9m111[i][1],
81 init_mt9m111[i][2]);
82 } else {
83 data[0] = init_mt9m111[i][2];
84 data[1] = init_mt9m111[i][3];
85 err = mt9m111_write_sensor(sd,
86 init_mt9m111[i][1], data, 2);
87 }
88 }
89
90 if (dump_sensor)
91 mt9m111_dump_registers(sd);
92
93 return (err < 0) ? err : 0;
94}
95
96int mt9m111_power_down(struct sd *sd)
97{
98 return 0;
99}
100
101int mt9m111_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
102{
103 int err;
104 u8 data[2] = {0x00, 0x00};
105 struct sd *sd = (struct sd *) gspca_dev;
106
107 err = mt9m111_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B,
108 data, 2);
109 *val = data[0] & MT9M111_RMB_MIRROR_ROWS;
110 PDEBUG(DBG_V4L2_CID, "Read vertical flip %d", *val);
111
112 return (err < 0) ? err : 0;
113}
114
115int mt9m111_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
116{
117 int err;
118 u8 data[2] = {0x00, 0x00};
119 struct sd *sd = (struct sd *) gspca_dev;
120
121 PDEBUG(DBG_V4L2_CID, "Set vertical flip to %d", val);
122
123 /* Set the correct page map */
124 err = mt9m111_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
125 if (err < 0)
126 goto out;
127
128 err = mt9m111_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2);
129 if (err < 0)
130 goto out;
131
132 data[0] = (data[0] & 0xfe) | val;
133 err = mt9m111_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B,
134 data, 2);
135out:
136 return (err < 0) ? err : 0;
137}
138
139int mt9m111_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
140{
141 int err;
142 u8 data[2] = {0x00, 0x00};
143 struct sd *sd = (struct sd *) gspca_dev;
144
145 err = mt9m111_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B,
146 data, 2);
147 *val = data[0] & MT9M111_RMB_MIRROR_COLS;
148 PDEBUG(DBG_V4L2_CID, "Read horizontal flip %d", *val);
149
150 return (err < 0) ? err : 0;
151}
152
153int mt9m111_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
154{
155 int err;
156 u8 data[2] = {0x00, 0x00};
157 struct sd *sd = (struct sd *) gspca_dev;
158
159 PDEBUG(DBG_V4L2_CID, "Set horizontal flip to %d", val);
160
161 /* Set the correct page map */
162 err = mt9m111_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
163 if (err < 0)
164 goto out;
165
166 err = mt9m111_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2);
167 if (err < 0)
168 goto out;
169
170 data[0] = (data[0] & 0xfd) | ((val << 1) & 0x02);
171 err = mt9m111_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B,
172 data, 2);
173out:
174 return (err < 0) ? err : 0;
175}
176
177int mt9m111_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
178{
179 int err, tmp;
180 u8 data[2] = {0x00, 0x00};
181 struct sd *sd = (struct sd *) gspca_dev;
182
183 err = mt9m111_read_sensor(sd, MT9M111_SC_GLOBAL_GAIN, data, 2);
184 tmp = ((data[1] << 8) | data[0]);
185
186 *val = ((tmp & (1 << 10)) * 2) |
187 ((tmp & (1 << 9)) * 2) |
188 ((tmp & (1 << 8)) * 2) |
189 (tmp & 0x7f);
190
191 PDEBUG(DBG_V4L2_CID, "Read gain %d", *val);
192
193 return (err < 0) ? err : 0;
194}
195
196int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val)
197{
198 int err, tmp;
199 u8 data[2] = {0x00, 0x00};
200 struct sd *sd = (struct sd *) gspca_dev;
201
202 /* Set the correct page map */
203 err = mt9m111_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
204 if (err < 0)
205 goto out;
206
207 if (val >= INITIAL_MAX_GAIN * 2 * 2 * 2)
208 return -EINVAL;
209
210 if ((val >= INITIAL_MAX_GAIN * 2 * 2) &&
211 (val < (INITIAL_MAX_GAIN - 1) * 2 * 2 * 2))
212 tmp = (1 << 10) | (val << 9) |
213 (val << 8) | (val / 8);
214 else if ((val >= INITIAL_MAX_GAIN * 2) &&
215 (val < INITIAL_MAX_GAIN * 2 * 2))
216 tmp = (1 << 9) | (1 << 8) | (val / 4);
217 else if ((val >= INITIAL_MAX_GAIN) &&
218 (val < INITIAL_MAX_GAIN * 2))
219 tmp = (1 << 8) | (val / 2);
220 else
221 tmp = val;
222
223 data[1] = (tmp & 0xff00) >> 8;
224 data[0] = (tmp & 0xff);
225 PDEBUG(DBG_V4L2_CID, "tmp=%d, data[1]=%d, data[0]=%d", tmp,
226 data[1], data[0]);
227
228 err = mt9m111_write_sensor(sd, MT9M111_SC_GLOBAL_GAIN,
229 data, 2);
230out:
231 return (err < 0) ? err : 0;
232}
233
234int mt9m111_read_sensor(struct sd *sd, const u8 address,
235 u8 *i2c_data, const u8 len) {
236 int err, i;
237
238 do {
239 err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data);
240 } while ((*i2c_data & I2C_BUSY) && !err);
241 if (err < 0)
242 goto out;
243
244 err = m5602_write_bridge(sd, M5602_XB_I2C_DEV_ADDR,
245 sd->sensor->i2c_slave_id);
246 if (err < 0)
247 goto out;
248
249 err = m5602_write_bridge(sd, M5602_XB_I2C_REG_ADDR, address);
250 if (err < 0)
251 goto out;
252
253 err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x1a);
254 if (err < 0)
255 goto out;
256
257 for (i = 0; i < len && !err; i++) {
258 err = m5602_read_bridge(sd, M5602_XB_I2C_DATA, &(i2c_data[i]));
259
260 PDEBUG(DBG_TRACE, "Reading sensor register "
261 "0x%x contains 0x%x ", address, *i2c_data);
262 }
263out:
264 return (err < 0) ? err : 0;
265}
266
267int mt9m111_write_sensor(struct sd *sd, const u8 address,
268 u8 *i2c_data, const u8 len)
269{
270 int err, i;
271 u8 *p;
272 struct usb_device *udev = sd->gspca_dev.dev;
273 __u8 *buf = sd->gspca_dev.usb_buf;
274
275 /* No sensor with a data width larger
276 than 16 bits has yet been seen, nor with 0 :p*/
277 if (len > 2 || !len)
278 return -EINVAL;
279
280 memcpy(buf, sensor_urb_skeleton,
281 sizeof(sensor_urb_skeleton));
282
283 buf[11] = sd->sensor->i2c_slave_id;
284 buf[15] = address;
285
286 p = buf + 16;
287
288 /* Copy a four byte write sequence for each byte to be written to */
289 for (i = 0; i < len; i++) {
290 memcpy(p, sensor_urb_skeleton + 16, 4);
291 p[3] = i2c_data[i];
292 p += 4;
293 PDEBUG(DBG_TRACE, "Writing sensor register 0x%x with 0x%x",
294 address, i2c_data[i]);
295 }
296
297 /* Copy the tailer */
298 memcpy(p, sensor_urb_skeleton + 20, 4);
299
300 /* Set the total length */
301 p[3] = 0x10 + len;
302
303 err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
304 0x04, 0x40, 0x19,
305 0x0000, buf,
306 20 + len * 4, M5602_URB_MSG_TIMEOUT);
307
308 return (err < 0) ? err : 0;
309}
310
311void mt9m111_dump_registers(struct sd *sd)
312{
313 u8 address, value[2] = {0x00, 0x00};
314
315 info("Dumping the mt9m111 register state");
316
317 info("Dumping the mt9m111 sensor core registers");
318 value[1] = MT9M111_SENSOR_CORE;
319 mt9m111_write_sensor(sd, MT9M111_PAGE_MAP, value, 2);
320 for (address = 0; address < 0xff; address++) {
321 mt9m111_read_sensor(sd, address, value, 2);
322 info("register 0x%x contains 0x%x%x",
323 address, value[0], value[1]);
324 }
325
326 info("Dumping the mt9m111 color pipeline registers");
327 value[1] = MT9M111_COLORPIPE;
328 mt9m111_write_sensor(sd, MT9M111_PAGE_MAP, value, 2);
329 for (address = 0; address < 0xff; address++) {
330 mt9m111_read_sensor(sd, address, value, 2);
331 info("register 0x%x contains 0x%x%x",
332 address, value[0], value[1]);
333 }
334
335 info("Dumping the mt9m111 camera control registers");
336 value[1] = MT9M111_CAMERA_CONTROL;
337 mt9m111_write_sensor(sd, MT9M111_PAGE_MAP, value, 2);
338 for (address = 0; address < 0xff; address++) {
339 mt9m111_read_sensor(sd, address, value, 2);
340 info("register 0x%x contains 0x%x%x",
341 address, value[0], value[1]);
342 }
343
344 info("mt9m111 register state dump complete");
345}
diff --git a/drivers/media/video/gspca/m5602/m5602_mt9m111.h b/drivers/media/video/gspca/m5602/m5602_mt9m111.h
new file mode 100644
index 000000000000..79a5d8878190
--- /dev/null
+++ b/drivers/media/video/gspca/m5602/m5602_mt9m111.h
@@ -0,0 +1,1020 @@
1/*
2 * Driver for the mt9m111 sensor
3 *
4 * Copyright (C) 2008 Erik Andren
5 * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
6 * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
7 *
8 * Portions of code to USB interface and ALi driver software,
9 * Copyright (c) 2006 Willem Duinker
10 * v4l2 interface modeled after the V4L2 driver
11 * for SN9C10x PC Camera Controllers
12 *
13 * Some defines taken from the mt9m111 sensor driver
14 * Copyright (C) 2008, Robert Jarzmik <robert.jarzmik@free.fr>
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation, version 2.
19 *
20 */
21
22#ifndef M5602_MT9M111_H_
23#define M5602_MT9M111_H_
24
25#include "m5602_sensor.h"
26
27/*****************************************************************************/
28
29#define MT9M111_SC_CHIPVER 0x00
30#define MT9M111_SC_ROWSTART 0x01
31#define MT9M111_SC_COLSTART 0x02
32#define MT9M111_SC_WINDOW_HEIGHT 0x03
33#define MT9M111_SC_WINDOW_WIDTH 0x04
34#define MT9M111_SC_HBLANK_CONTEXT_B 0x05
35#define MT9M111_SC_VBLANK_CONTEXT_B 0x06
36#define MT9M111_SC_HBLANK_CONTEXT_A 0x07
37#define MT9M111_SC_VBLANK_CONTEXT_A 0x08
38#define MT9M111_SC_SHUTTER_WIDTH 0x09
39#define MT9M111_SC_ROW_SPEED 0x0a
40
41#define MT9M111_SC_EXTRA_DELAY 0x0b
42#define MT9M111_SC_SHUTTER_DELAY 0x0c
43#define MT9M111_SC_RESET 0x0d
44#define MT9M111_SC_R_MODE_CONTEXT_B 0x20
45#define MT9M111_SC_R_MODE_CONTEXT_A 0x21
46#define MT9M111_SC_FLASH_CONTROL 0x23
47#define MT9M111_SC_GREEN_1_GAIN 0x2b
48#define MT9M111_SC_BLUE_GAIN 0x2c
49#define MT9M111_SC_RED_GAIN 0x2d
50#define MT9M111_SC_GREEN_2_GAIN 0x2e
51#define MT9M111_SC_GLOBAL_GAIN 0x2f
52
53#define MT9M111_RMB_MIRROR_ROWS (1 << 0)
54#define MT9M111_RMB_MIRROR_COLS (1 << 1)
55
56#define MT9M111_CONTEXT_CONTROL 0xc8
57#define MT9M111_PAGE_MAP 0xf0
58#define MT9M111_BYTEWISE_ADDRESS 0xf1
59
60#define MT9M111_CP_OPERATING_MODE_CTL 0x06
61#define MT9M111_CP_LUMA_OFFSET 0x34
62#define MT9M111_CP_LUMA_CLIP 0x35
63#define MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_A 0x3a
64#define MT9M111_CP_LENS_CORRECTION_1 0x3b
65#define MT9M111_CP_DEFECT_CORR_CONTEXT_A 0x4c
66#define MT9M111_CP_DEFECT_CORR_CONTEXT_B 0x4d
67#define MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_B 0x9b
68#define MT9M111_CP_GLOBAL_CLK_CONTROL 0xb3
69
70#define MT9M111_CC_AUTO_EXPOSURE_PARAMETER_18 0x65
71#define MT9M111_CC_AWB_PARAMETER_7 0x28
72
73#define MT9M111_SENSOR_CORE 0x00
74#define MT9M111_COLORPIPE 0x01
75#define MT9M111_CAMERA_CONTROL 0x02
76
77#define INITIAL_MAX_GAIN 64
78#define DEFAULT_GAIN 283
79
80/*****************************************************************************/
81
82/* Kernel module parameters */
83extern int force_sensor;
84extern int dump_sensor;
85extern unsigned int m5602_debug;
86
87int mt9m111_probe(struct sd *sd);
88int mt9m111_init(struct sd *sd);
89int mt9m111_power_down(struct sd *sd);
90
91int mt9m111_read_sensor(struct sd *sd, const u8 address,
92 u8 *i2c_data, const u8 len);
93
94int mt9m111_write_sensor(struct sd *sd, const u8 address,
95 u8 *i2c_data, const u8 len);
96
97void mt9m111_dump_registers(struct sd *sd);
98
99int mt9m111_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
100int mt9m111_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
101int mt9m111_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
102int mt9m111_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
103int mt9m111_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
104int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val);
105
106static struct m5602_sensor mt9m111 = {
107 .name = "MT9M111",
108
109 .i2c_slave_id = 0xba,
110
111 .probe = mt9m111_probe,
112 .init = mt9m111_init,
113 .power_down = mt9m111_power_down,
114
115 .read_sensor = mt9m111_read_sensor,
116 .write_sensor = mt9m111_write_sensor,
117
118 .nctrls = 3,
119 .ctrls = {
120 {
121 {
122 .id = V4L2_CID_VFLIP,
123 .type = V4L2_CTRL_TYPE_BOOLEAN,
124 .name = "vertical flip",
125 .minimum = 0,
126 .maximum = 1,
127 .step = 1,
128 .default_value = 0
129 },
130 .set = mt9m111_set_vflip,
131 .get = mt9m111_get_vflip
132 }, {
133 {
134 .id = V4L2_CID_HFLIP,
135 .type = V4L2_CTRL_TYPE_BOOLEAN,
136 .name = "horizontal flip",
137 .minimum = 0,
138 .maximum = 1,
139 .step = 1,
140 .default_value = 0
141 },
142 .set = mt9m111_set_hflip,
143 .get = mt9m111_get_hflip
144 }, {
145 {
146 .id = V4L2_CID_GAIN,
147 .type = V4L2_CTRL_TYPE_INTEGER,
148 .name = "gain",
149 .minimum = 0,
150 .maximum = (INITIAL_MAX_GAIN - 1) * 2 * 2 * 2,
151 .step = 1,
152 .default_value = DEFAULT_GAIN,
153 .flags = V4L2_CTRL_FLAG_SLIDER
154 },
155 .set = mt9m111_set_hflip,
156 .get = mt9m111_get_hflip
157 }
158 },
159
160 .nmodes = 1,
161 .modes = {
162 {
163 M5602_DEFAULT_FRAME_WIDTH,
164 M5602_DEFAULT_FRAME_HEIGHT,
165 V4L2_PIX_FMT_SBGGR8,
166 V4L2_FIELD_NONE,
167 .sizeimage =
168 M5602_DEFAULT_FRAME_WIDTH * M5602_DEFAULT_FRAME_HEIGHT,
169 .bytesperline = M5602_DEFAULT_FRAME_WIDTH,
170 .colorspace = V4L2_COLORSPACE_SRGB,
171 .priv = 1
172 }
173 }
174};
175
176static const unsigned char preinit_mt9m111[][4] =
177{
178 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
179 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
180 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
181 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
182 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
183 {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
184 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
185 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
186
187 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
188 {SENSOR, MT9M111_SC_RESET, 0xff, 0xf7},
189
190 {BRIDGE, M5602_XB_GPIO_DIR, 0x05, 0x00},
191 {BRIDGE, M5602_XB_GPIO_DAT, 0x04, 0x00},
192 {BRIDGE, M5602_XB_GPIO_EN_H, 0x3e, 0x00},
193 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3e, 0x00},
194 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02, 0x00},
195 {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
196 {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
197 {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
198
199 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
200 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
201 {BRIDGE, M5602_XB_GPIO_DIR, 0x07, 0x00},
202 {BRIDGE, M5602_XB_GPIO_DAT, 0x0b, 0x00},
203 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
204 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
205
206 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a, 0x00}
207};
208
209static const unsigned char init_mt9m111[][4] =
210{
211 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
212 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
213 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
214 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
215 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
216 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
217 {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
218 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
219 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
220 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
221 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
222
223 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
224 {SENSOR, MT9M111_SC_RESET, 0xff, 0xff},
225 {SENSOR, MT9M111_SC_RESET, 0xff, 0xff},
226 {SENSOR, MT9M111_SC_RESET, 0xff, 0xde},
227 {SENSOR, MT9M111_SC_RESET, 0xff, 0xff},
228 {SENSOR, MT9M111_SC_RESET, 0xff, 0xf7},
229 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
230
231 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xb3, 0x00},
232
233 {SENSOR, MT9M111_CP_GLOBAL_CLK_CONTROL, 0xff, 0xff},
234
235 {BRIDGE, M5602_XB_GPIO_DIR, 0x05, 0x00},
236 {BRIDGE, M5602_XB_GPIO_DAT, 0x04, 0x00},
237 {BRIDGE, M5602_XB_GPIO_EN_H, 0x3e, 0x00},
238 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3e, 0x00},
239 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02, 0x00},
240 {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
241 {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
242 {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
243 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04, 0x00},
244 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
245 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
246 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
247 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
248 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
249 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
250 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
251 {BRIDGE, M5602_XB_GPIO_DIR, 0x07, 0x00},
252 {BRIDGE, M5602_XB_GPIO_DAT, 0x0b, 0x00},
253 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
254 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
255 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a, 0x00},
256
257 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
258 {SENSOR, MT9M111_SC_RESET, 0x00, 0x05},
259 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
260 {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
261 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
262 {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
263 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
264 {SENSOR, MT9M111_CP_OPERATING_MODE_CTL, 0x00, 0x10},
265 {SENSOR, MT9M111_CP_LENS_CORRECTION_1, 0x04, 0x2a},
266 {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_A, 0x00, 0x01},
267 {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_B, 0x00, 0x01},
268 {SENSOR, MT9M111_CP_LUMA_OFFSET, 0x00, 0x00},
269 {SENSOR, MT9M111_CP_LUMA_CLIP, 0xff, 0x00},
270 {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_A, 0x14, 0x00},
271 {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_B, 0x14, 0x00},
272 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xcd, 0x00},
273
274 {SENSOR, 0xcd, 0x00, 0x0e},
275 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xd0, 0x00},
276 {SENSOR, 0xd0, 0x00, 0x40},
277 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x02},
278 {SENSOR, MT9M111_CC_AUTO_EXPOSURE_PARAMETER_18, 0x00, 0x00},
279 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
280 {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x07},
281 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
282 {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x03},
283 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
284 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
285 {SENSOR, 0x33, 0x03, 0x49},
286 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
287
288 {SENSOR, 0x33, 0x03, 0x49},
289 {SENSOR, 0x34, 0xc0, 0x19},
290 {SENSOR, 0x3f, 0x20, 0x20},
291 {SENSOR, 0x40, 0x20, 0x20},
292 {SENSOR, 0x5a, 0xc0, 0x0a},
293 {SENSOR, 0x70, 0x7b, 0x0a},
294 {SENSOR, 0x71, 0xff, 0x00},
295 {SENSOR, 0x72, 0x19, 0x0e},
296 {SENSOR, 0x73, 0x18, 0x0f},
297 {SENSOR, 0x74, 0x57, 0x32},
298 {SENSOR, 0x75, 0x56, 0x34},
299 {SENSOR, 0x76, 0x73, 0x35},
300 {SENSOR, 0x77, 0x30, 0x12},
301 {SENSOR, 0x78, 0x79, 0x02},
302 {SENSOR, 0x79, 0x75, 0x06},
303 {SENSOR, 0x7a, 0x77, 0x0a},
304 {SENSOR, 0x7b, 0x78, 0x09},
305 {SENSOR, 0x7c, 0x7d, 0x06},
306 {SENSOR, 0x7d, 0x31, 0x10},
307 {SENSOR, 0x7e, 0x00, 0x7e},
308 {SENSOR, 0x80, 0x59, 0x04},
309 {SENSOR, 0x81, 0x59, 0x04},
310 {SENSOR, 0x82, 0x57, 0x0a},
311 {SENSOR, 0x83, 0x58, 0x0b},
312 {SENSOR, 0x84, 0x47, 0x0c},
313 {SENSOR, 0x85, 0x48, 0x0e},
314 {SENSOR, 0x86, 0x5b, 0x02},
315 {SENSOR, 0x87, 0x00, 0x5c},
316 {SENSOR, MT9M111_CONTEXT_CONTROL, 0x00, 0x08},
317 {SENSOR, 0x60, 0x00, 0x80},
318 {SENSOR, 0x61, 0x00, 0x00},
319 {SENSOR, 0x62, 0x00, 0x00},
320 {SENSOR, 0x63, 0x00, 0x00},
321 {SENSOR, 0x64, 0x00, 0x00},
322
323 {SENSOR, MT9M111_SC_ROWSTART, 0x00, 0x0d},
324 {SENSOR, MT9M111_SC_COLSTART, 0x00, 0x18},
325 {SENSOR, MT9M111_SC_WINDOW_HEIGHT, 0x04, 0x04},
326 {SENSOR, MT9M111_SC_WINDOW_WIDTH, 0x05, 0x08},
327 {SENSOR, MT9M111_SC_HBLANK_CONTEXT_B, 0x01, 0x38},
328 {SENSOR, MT9M111_SC_VBLANK_CONTEXT_B, 0x00, 0x11},
329 {SENSOR, MT9M111_SC_HBLANK_CONTEXT_A, 0x01, 0x38},
330 {SENSOR, MT9M111_SC_VBLANK_CONTEXT_A, 0x00, 0x11},
331 {SENSOR, MT9M111_SC_R_MODE_CONTEXT_B, 0x01, 0x03},
332 {SENSOR, MT9M111_SC_R_MODE_CONTEXT_A, 0x01, 0x03},
333 {SENSOR, 0x30, 0x04, 0x00},
334
335 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
336 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
337 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
338 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
339 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
340 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
341 {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
342 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
343 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
344 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
345 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
346 {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
347 {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
348 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
349 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
350 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
351 {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
352 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
353 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
354 {BRIDGE, M5602_XB_HSYNC_PARA, 0x05, 0x00},
355 {BRIDGE, M5602_XB_HSYNC_PARA, 0x07, 0x00},
356 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
357 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
358 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00},
359 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
360 {SENSOR, MT9M111_SC_SHUTTER_WIDTH, 0x01, 0xf4},
361 {SENSOR, MT9M111_SC_GLOBAL_GAIN, 0x00, 0xea},
362
363 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
364 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
365 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
366 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
367 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
368 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
369 {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
370 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
371 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
372 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
373 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
374 {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
375 {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
376 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
377 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
378 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
379 {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
380 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
381 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
382 {BRIDGE, M5602_XB_HSYNC_PARA, 0x05, 0x00},
383 {BRIDGE, M5602_XB_HSYNC_PARA, 0x07, 0x00},
384 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
385 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
386 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
387
388 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
389 {SENSOR, MT9M111_SC_RESET, 0x00, 0x09},
390 {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
391 {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
392 {SENSOR, MT9M111_SC_RESET, 0x00, 0x0c},
393 {SENSOR, MT9M111_SC_RESET, 0x00, 0x04},
394 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
395 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xb3, 0x00},
396 {SENSOR, MT9M111_CP_GLOBAL_CLK_CONTROL, 0x00, 0x03},
397 {BRIDGE, M5602_XB_GPIO_DIR, 0x05, 0x00},
398 {BRIDGE, M5602_XB_GPIO_DAT, 0x04, 0x00},
399 {BRIDGE, M5602_XB_GPIO_EN_H, 0x3e, 0x00},
400 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3e, 0x00},
401 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02, 0x00},
402 {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
403 {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
404 {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
405 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04, 0x00},
406 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
407 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
408 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
409 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
410 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
411 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
412 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
413 {BRIDGE, M5602_XB_GPIO_DIR, 0x07, 0x00},
414 {BRIDGE, M5602_XB_GPIO_DAT, 0x0b, 0x00},
415 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
416 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
417 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a, 0x00},
418
419 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
420 {SENSOR, MT9M111_SC_RESET, 0x00, 0x05},
421 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
422 {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
423 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
424 {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
425 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
426 {SENSOR, MT9M111_CP_OPERATING_MODE_CTL, 0x00, 0x10},
427 {SENSOR, MT9M111_CP_LENS_CORRECTION_1, 0x04, 0x2a},
428 {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_A, 0x00, 0x01},
429 {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_B, 0x00, 0x01},
430 {SENSOR, MT9M111_CP_LUMA_OFFSET, 0x00, 0x00},
431 {SENSOR, MT9M111_CP_LUMA_CLIP, 0xff, 0x00},
432 {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_A, 0x14, 0x00},
433 {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_B, 0x14, 0x00},
434
435 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xcd, 0x00},
436 {SENSOR, 0xcd, 0x00, 0x0e},
437 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xd0, 0x00},
438 {SENSOR, 0xd0, 0x00, 0x40},
439 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x02},
440 {SENSOR, MT9M111_CC_AUTO_EXPOSURE_PARAMETER_18, 0x00, 0x00},
441 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
442 {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x07},
443 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
444 {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x03},
445 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
446 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
447 {SENSOR, 0x33, 0x03, 0x49},
448 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
449
450 {SENSOR, 0x33, 0x03, 0x49},
451 {SENSOR, 0x34, 0xc0, 0x19},
452 {SENSOR, 0x3f, 0x20, 0x20},
453 {SENSOR, 0x40, 0x20, 0x20},
454 {SENSOR, 0x5a, 0xc0, 0x0a},
455 {SENSOR, 0x70, 0x7b, 0x0a},
456 {SENSOR, 0x71, 0xff, 0x00},
457 {SENSOR, 0x72, 0x19, 0x0e},
458 {SENSOR, 0x73, 0x18, 0x0f},
459 {SENSOR, 0x74, 0x57, 0x32},
460 {SENSOR, 0x75, 0x56, 0x34},
461 {SENSOR, 0x76, 0x73, 0x35},
462 {SENSOR, 0x77, 0x30, 0x12},
463 {SENSOR, 0x78, 0x79, 0x02},
464 {SENSOR, 0x79, 0x75, 0x06},
465 {SENSOR, 0x7a, 0x77, 0x0a},
466 {SENSOR, 0x7b, 0x78, 0x09},
467 {SENSOR, 0x7c, 0x7d, 0x06},
468 {SENSOR, 0x7d, 0x31, 0x10},
469 {SENSOR, 0x7e, 0x00, 0x7e},
470 {SENSOR, 0x80, 0x59, 0x04},
471 {SENSOR, 0x81, 0x59, 0x04},
472 {SENSOR, 0x82, 0x57, 0x0a},
473 {SENSOR, 0x83, 0x58, 0x0b},
474 {SENSOR, 0x84, 0x47, 0x0c},
475 {SENSOR, 0x85, 0x48, 0x0e},
476 {SENSOR, 0x86, 0x5b, 0x02},
477 {SENSOR, 0x87, 0x00, 0x5c},
478 {SENSOR, MT9M111_CONTEXT_CONTROL, 0x00, 0x08},
479 {SENSOR, 0x60, 0x00, 0x80},
480 {SENSOR, 0x61, 0x00, 0x00},
481 {SENSOR, 0x62, 0x00, 0x00},
482 {SENSOR, 0x63, 0x00, 0x00},
483 {SENSOR, 0x64, 0x00, 0x00},
484
485 {SENSOR, MT9M111_SC_ROWSTART, 0x00, 0x0d},
486 {SENSOR, MT9M111_SC_COLSTART, 0x00, 0x18},
487 {SENSOR, MT9M111_SC_WINDOW_HEIGHT, 0x04, 0x04},
488 {SENSOR, MT9M111_SC_WINDOW_WIDTH, 0x05, 0x08},
489 {SENSOR, MT9M111_SC_HBLANK_CONTEXT_B, 0x01, 0x38},
490 {SENSOR, MT9M111_SC_VBLANK_CONTEXT_B, 0x00, 0x11},
491 {SENSOR, MT9M111_SC_HBLANK_CONTEXT_A, 0x01, 0x38},
492 {SENSOR, MT9M111_SC_VBLANK_CONTEXT_A, 0x00, 0x11},
493 {SENSOR, MT9M111_SC_R_MODE_CONTEXT_B, 0x01, 0x03},
494 {SENSOR, MT9M111_SC_R_MODE_CONTEXT_A, 0x01, 0x03},
495 {SENSOR, 0x30, 0x04, 0x00},
496
497 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
498 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
499 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
500 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
501 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
502 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
503 {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
504 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
505 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
506 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
507 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
508 {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
509 {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
510 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
511 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
512 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
513 {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
514 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
515 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
516 {BRIDGE, M5602_XB_HSYNC_PARA, 0x05, 0x00},
517 {BRIDGE, M5602_XB_HSYNC_PARA, 0x07, 0x00},
518 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
519 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
520 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00},
521 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
522 {SENSOR, MT9M111_SC_SHUTTER_WIDTH, 0x01, 0xf4},
523 {SENSOR, MT9M111_SC_GLOBAL_GAIN, 0x00, 0xea},
524 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
525 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
526
527 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
528 {SENSOR, MT9M111_SC_RESET, 0x00, 0x09},
529 {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
530 {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
531 {SENSOR, MT9M111_SC_RESET, 0x00, 0x0c},
532 {SENSOR, MT9M111_SC_RESET, 0x00, 0x04},
533 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
534
535 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xb3, 0x00},
536 {SENSOR, MT9M111_CP_GLOBAL_CLK_CONTROL, 0x00, 0x03},
537 {BRIDGE, M5602_XB_GPIO_DIR, 0x05, 0x00},
538 {BRIDGE, M5602_XB_GPIO_DAT, 0x04, 0x00},
539 {BRIDGE, M5602_XB_GPIO_EN_H, 0x3e, 0x00},
540 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3e, 0x00},
541 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02, 0x00},
542 {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
543 {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
544 {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
545 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04, 0x00},
546 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
547 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
548 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
549 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
550 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
551 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
552 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
553 {BRIDGE, M5602_XB_GPIO_DIR, 0x07, 0x00},
554 {BRIDGE, M5602_XB_GPIO_DAT, 0x0b, 0x00},
555 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
556 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
557 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a, 0x00},
558
559 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
560 {SENSOR, MT9M111_SC_RESET, 0x00, 0x05},
561 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
562 {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
563 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
564 {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
565 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
566 {SENSOR, MT9M111_CP_OPERATING_MODE_CTL, 0x00, 0x10},
567 {SENSOR, MT9M111_CP_LENS_CORRECTION_1, 0x04, 0x2a},
568 {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_A, 0x00, 0x01},
569 {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_B, 0x00, 0x01},
570 {SENSOR, MT9M111_CP_LUMA_OFFSET, 0x00, 0x00},
571 {SENSOR, MT9M111_CP_LUMA_CLIP, 0xff, 0x00},
572 {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_A, 0x14, 0x00},
573 {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_B, 0x14, 0x00},
574
575 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xcd, 0x00},
576 {SENSOR, 0xcd, 0x00, 0x0e},
577 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xd0, 0x00},
578 {SENSOR, 0xd0, 0x00, 0x40},
579 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x02},
580 {SENSOR, MT9M111_CC_AUTO_EXPOSURE_PARAMETER_18, 0x00, 0x00},
581 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
582 {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x07},
583 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
584 {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x03},
585 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
586 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
587 {SENSOR, 0x33, 0x03, 0x49},
588 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
589
590 {SENSOR, 0x33, 0x03, 0x49},
591 {SENSOR, 0x34, 0xc0, 0x19},
592 {SENSOR, 0x3f, 0x20, 0x20},
593 {SENSOR, 0x40, 0x20, 0x20},
594 {SENSOR, 0x5a, 0xc0, 0x0a},
595 {SENSOR, 0x70, 0x7b, 0x0a},
596 {SENSOR, 0x71, 0xff, 0x00},
597 {SENSOR, 0x72, 0x19, 0x0e},
598 {SENSOR, 0x73, 0x18, 0x0f},
599 {SENSOR, 0x74, 0x57, 0x32},
600 {SENSOR, 0x75, 0x56, 0x34},
601 {SENSOR, 0x76, 0x73, 0x35},
602 {SENSOR, 0x77, 0x30, 0x12},
603 {SENSOR, 0x78, 0x79, 0x02},
604 {SENSOR, 0x79, 0x75, 0x06},
605 {SENSOR, 0x7a, 0x77, 0x0a},
606 {SENSOR, 0x7b, 0x78, 0x09},
607 {SENSOR, 0x7c, 0x7d, 0x06},
608 {SENSOR, 0x7d, 0x31, 0x10},
609 {SENSOR, 0x7e, 0x00, 0x7e},
610 {SENSOR, 0x80, 0x59, 0x04},
611 {SENSOR, 0x81, 0x59, 0x04},
612 {SENSOR, 0x82, 0x57, 0x0a},
613 {SENSOR, 0x83, 0x58, 0x0b},
614 {SENSOR, 0x84, 0x47, 0x0c},
615 {SENSOR, 0x85, 0x48, 0x0e},
616 {SENSOR, 0x86, 0x5b, 0x02},
617 {SENSOR, 0x87, 0x00, 0x5c},
618 {SENSOR, MT9M111_CONTEXT_CONTROL, 0x00, 0x08},
619 {SENSOR, 0x60, 0x00, 0x80},
620 {SENSOR, 0x61, 0x00, 0x00},
621 {SENSOR, 0x62, 0x00, 0x00},
622 {SENSOR, 0x63, 0x00, 0x00},
623 {SENSOR, 0x64, 0x00, 0x00},
624
625 {SENSOR, MT9M111_SC_ROWSTART, 0x00, 0x0d},
626 {SENSOR, MT9M111_SC_COLSTART, 0x00, 0x18},
627 {SENSOR, MT9M111_SC_WINDOW_HEIGHT, 0x04, 0x04},
628 {SENSOR, MT9M111_SC_WINDOW_WIDTH, 0x05, 0x08},
629 {SENSOR, MT9M111_SC_HBLANK_CONTEXT_B, 0x01, 0x38},
630 {SENSOR, MT9M111_SC_VBLANK_CONTEXT_B, 0x00, 0x11},
631 {SENSOR, MT9M111_SC_HBLANK_CONTEXT_A, 0x01, 0x38},
632 {SENSOR, MT9M111_SC_VBLANK_CONTEXT_A, 0x00, 0x11},
633 {SENSOR, MT9M111_SC_R_MODE_CONTEXT_B, 0x01, 0x03},
634 {SENSOR, MT9M111_SC_R_MODE_CONTEXT_A, 0x01, 0x03},
635 {SENSOR, 0x30, 0x04, 0x00},
636
637 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
638 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
639 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
640 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
641 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
642 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
643 {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
644 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
645 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
646 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
647 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
648 {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
649 {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
650 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
651 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
652 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
653 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
654 {BRIDGE, M5602_XB_HSYNC_PARA, 0x05, 0x00},
655 {BRIDGE, M5602_XB_HSYNC_PARA, 0x07, 0x00},
656 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
657 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
658 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00},
659 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
660 {SENSOR, MT9M111_SC_SHUTTER_WIDTH, 0x01, 0xf4},
661 {SENSOR, MT9M111_SC_GLOBAL_GAIN, 0x00, 0xea},
662 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
663 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
664 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
665 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
666 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
667 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
668 {SENSOR, MT9M111_SC_RESET, 0x00, 0x09},
669 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
670 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
671 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
672 {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
673 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
674 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
675 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
676 {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
677 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
678 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
679 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
680 {SENSOR, MT9M111_SC_RESET, 0x00, 0x0c},
681 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
682 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
683 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
684 {SENSOR, MT9M111_SC_RESET, 0x00, 0x04},
685 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
686 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
687 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xb3, 0x00},
688 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
689 {SENSOR, MT9M111_CP_GLOBAL_CLK_CONTROL, 0x00, 0x03},
690 {BRIDGE, M5602_XB_GPIO_DIR, 0x05, 0x00},
691 {BRIDGE, M5602_XB_GPIO_DAT, 0x04, 0x00},
692 {BRIDGE, M5602_XB_GPIO_EN_H, 0x3e, 0x00},
693 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3e, 0x00},
694 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02, 0x00},
695 {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
696 {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
697 {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
698 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04, 0x00},
699 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
700 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
701 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
702 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
703 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
704 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
705 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
706 {BRIDGE, M5602_XB_GPIO_DIR, 0x07, 0x00},
707 {BRIDGE, M5602_XB_GPIO_DAT, 0x0b, 0x00},
708 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
709 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
710 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a, 0x00},
711 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
712 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
713 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
714 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
715 {SENSOR, MT9M111_SC_RESET, 0x00, 0x05},
716 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
717 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
718 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
719 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
720 {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
721 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
722 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
723 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
724 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
725
726 {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
727 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
728 {SENSOR, MT9M111_CP_OPERATING_MODE_CTL, 0x00, 0x10},
729 {SENSOR, MT9M111_CP_LENS_CORRECTION_1, 0x04, 0x2a},
730 {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_A, 0x00, 0x01},
731 {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_B, 0x00, 0x01},
732 {SENSOR, MT9M111_CP_LUMA_OFFSET, 0x00, 0x00},
733 {SENSOR, MT9M111_CP_LUMA_CLIP, 0xff, 0x00},
734 {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_A, 0x14, 0x00},
735 {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_B, 0x14, 0x00},
736
737 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
738 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xcd, 0x00},
739 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
740 {SENSOR, 0xcd, 0x00, 0x0e},
741 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
742 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xd0, 0x00},
743 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
744 {SENSOR, 0xd0, 0x00, 0x40},
745 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x02},
746 {SENSOR, MT9M111_CC_AUTO_EXPOSURE_PARAMETER_18, 0x00, 0x00},
747 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
748 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
749 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
750 {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x07},
751 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
752 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
753 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
754 {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x03},
755 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
756 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
757 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
758 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
759 {SENSOR, 0x33, 0x03, 0x49},
760 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
761 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
762 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
763
764 {SENSOR, 0x33, 0x03, 0x49},
765 {SENSOR, 0x34, 0xc0, 0x19},
766 {SENSOR, 0x3f, 0x20, 0x20},
767 {SENSOR, 0x40, 0x20, 0x20},
768 {SENSOR, 0x5a, 0xc0, 0x0a},
769 {SENSOR, 0x70, 0x7b, 0x0a},
770 {SENSOR, 0x71, 0xff, 0x00},
771 {SENSOR, 0x72, 0x19, 0x0e},
772 {SENSOR, 0x73, 0x18, 0x0f},
773 {SENSOR, 0x74, 0x57, 0x32},
774 {SENSOR, 0x75, 0x56, 0x34},
775 {SENSOR, 0x76, 0x73, 0x35},
776 {SENSOR, 0x77, 0x30, 0x12},
777 {SENSOR, 0x78, 0x79, 0x02},
778 {SENSOR, 0x79, 0x75, 0x06},
779 {SENSOR, 0x7a, 0x77, 0x0a},
780 {SENSOR, 0x7b, 0x78, 0x09},
781 {SENSOR, 0x7c, 0x7d, 0x06},
782 {SENSOR, 0x7d, 0x31, 0x10},
783 {SENSOR, 0x7e, 0x00, 0x7e},
784 {SENSOR, 0x80, 0x59, 0x04},
785 {SENSOR, 0x81, 0x59, 0x04},
786 {SENSOR, 0x82, 0x57, 0x0a},
787 {SENSOR, 0x83, 0x58, 0x0b},
788 {SENSOR, 0x84, 0x47, 0x0c},
789 {SENSOR, 0x85, 0x48, 0x0e},
790 {SENSOR, 0x86, 0x5b, 0x02},
791 {SENSOR, 0x87, 0x00, 0x5c},
792 {SENSOR, MT9M111_CONTEXT_CONTROL, 0x00, 0x08},
793 {SENSOR, 0x60, 0x00, 0x80},
794 {SENSOR, 0x61, 0x00, 0x00},
795 {SENSOR, 0x62, 0x00, 0x00},
796 {SENSOR, 0x63, 0x00, 0x00},
797 {SENSOR, 0x64, 0x00, 0x00},
798 {SENSOR, MT9M111_SC_ROWSTART, 0x00, 0x0d},
799 {SENSOR, MT9M111_SC_COLSTART, 0x00, 0x12},
800 {SENSOR, MT9M111_SC_WINDOW_HEIGHT, 0x04, 0x00},
801 {SENSOR, MT9M111_SC_WINDOW_WIDTH, 0x05, 0x10},
802 {SENSOR, MT9M111_SC_HBLANK_CONTEXT_B, 0x01, 0x60},
803 {SENSOR, MT9M111_SC_VBLANK_CONTEXT_B, 0x00, 0x11},
804 {SENSOR, MT9M111_SC_HBLANK_CONTEXT_A, 0x01, 0x60},
805 {SENSOR, MT9M111_SC_VBLANK_CONTEXT_A, 0x00, 0x11},
806 {SENSOR, MT9M111_SC_R_MODE_CONTEXT_B, 0x01, 0x0f},
807 {SENSOR, MT9M111_SC_R_MODE_CONTEXT_A, 0x01, 0x0f},
808 {SENSOR, 0x30, 0x04, 0x00},
809
810 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
811 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
812 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
813 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
814 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
815 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
816 {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
817 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
818 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
819 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
820 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
821 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
822 {BRIDGE, M5602_XB_VSYNC_PARA, 0xe3, 0x00},
823 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
824 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
825 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
826 {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
827 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
828 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
829 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
830 {BRIDGE, M5602_XB_HSYNC_PARA, 0x87, 0x00},
831 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
832 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
833 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
834
835 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
836 {SENSOR, MT9M111_SC_SHUTTER_WIDTH, 0x01, 0x90},
837 {SENSOR, MT9M111_SC_GLOBAL_GAIN, 0x00, 0xe6},
838 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
839 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
840 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
841 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
842 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
843 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
844 {SENSOR, MT9M111_SC_RESET, 0x00, 0x09},
845 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
846 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
847 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
848 {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
849 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
850 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
851 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
852 {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
853 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
854 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
855 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
856 {SENSOR, MT9M111_SC_RESET, 0x00, 0x0c},
857 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
858 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
859 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
860 {SENSOR, MT9M111_SC_RESET, 0x00, 0x04},
861 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
862 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
863 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xb3, 0x00},
864 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
865 {SENSOR, MT9M111_CP_GLOBAL_CLK_CONTROL, 0x00, 0x03},
866
867 {BRIDGE, M5602_XB_GPIO_DIR, 0x05, 0x00},
868 {BRIDGE, M5602_XB_GPIO_DAT, 0x04, 0x00},
869 {BRIDGE, M5602_XB_GPIO_EN_H, 0x3e, 0x00},
870 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3e, 0x00},
871 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02, 0x00},
872 {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
873 {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
874 {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
875 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04, 0x00},
876 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
877 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
878 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
879 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
880 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
881 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
882 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
883 {BRIDGE, M5602_XB_GPIO_DIR, 0x07, 0x00},
884 {BRIDGE, M5602_XB_GPIO_DAT, 0x0b, 0x00},
885 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
886 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
887 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a, 0x00},
888 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
889 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
890 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
891 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
892 {SENSOR, MT9M111_SC_RESET, 0x00, 0x05},
893 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
894 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
895 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
896 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
897 {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
898 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
899 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
900 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
901 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
902 {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
903 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
904 {SENSOR, MT9M111_CP_OPERATING_MODE_CTL, 0x00, 0x10},
905 {SENSOR, MT9M111_CP_LENS_CORRECTION_1, 0x04, 0x2a},
906 {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_A, 0x00, 0x01},
907 {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_B, 0x00, 0x01},
908 {SENSOR, MT9M111_CP_LUMA_OFFSET, 0x00, 0x00},
909 {SENSOR, MT9M111_CP_LUMA_CLIP, 0xff, 0x00},
910 {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_A, 0x14, 0x00},
911 {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_B, 0x14, 0x00},
912
913 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
914 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xcd, 0x00},
915 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
916 {SENSOR, 0xcd, 0x00, 0x0e},
917 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
918 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xd0, 0x00},
919 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
920 {SENSOR, 0xd0, 0x00, 0x40},
921 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x02},
922 {SENSOR, MT9M111_CC_AUTO_EXPOSURE_PARAMETER_18, 0x00, 0x00},
923 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
924 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
925 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
926 {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x07},
927 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
928 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
929 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
930 {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x03},
931 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
932
933 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
934 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
935 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
936 {SENSOR, 0x33, 0x03, 0x49},
937 {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
938 {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
939 {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
940
941 {SENSOR, 0x33, 0x03, 0x49},
942 {SENSOR, 0x34, 0xc0, 0x19},
943 {SENSOR, 0x3f, 0x20, 0x20},
944 {SENSOR, 0x40, 0x20, 0x20},
945 {SENSOR, 0x5a, 0xc0, 0x0a},
946 {SENSOR, 0x70, 0x7b, 0x0a},
947 {SENSOR, 0x71, 0xff, 0x00},
948 {SENSOR, 0x72, 0x19, 0x0e},
949 {SENSOR, 0x73, 0x18, 0x0f},
950 {SENSOR, 0x74, 0x57, 0x32},
951 {SENSOR, 0x75, 0x56, 0x34},
952 {SENSOR, 0x76, 0x73, 0x35},
953 {SENSOR, 0x77, 0x30, 0x12},
954 {SENSOR, 0x78, 0x79, 0x02},
955 {SENSOR, 0x79, 0x75, 0x06},
956 {SENSOR, 0x7a, 0x77, 0x0a},
957 {SENSOR, 0x7b, 0x78, 0x09},
958 {SENSOR, 0x7c, 0x7d, 0x06},
959 {SENSOR, 0x7d, 0x31, 0x10},
960 {SENSOR, 0x7e, 0x00, 0x7e},
961 {SENSOR, 0x80, 0x59, 0x04},
962 {SENSOR, 0x81, 0x59, 0x04},
963 {SENSOR, 0x82, 0x57, 0x0a},
964 {SENSOR, 0x83, 0x58, 0x0b},
965 {SENSOR, 0x84, 0x47, 0x0c},
966 {SENSOR, 0x85, 0x48, 0x0e},
967 {SENSOR, 0x86, 0x5b, 0x02},
968 {SENSOR, 0x87, 0x00, 0x5c},
969 {SENSOR, MT9M111_CONTEXT_CONTROL, 0x00, 0x08},
970 {SENSOR, 0x60, 0x00, 0x80},
971 {SENSOR, 0x61, 0x00, 0x00},
972 {SENSOR, 0x62, 0x00, 0x00},
973 {SENSOR, 0x63, 0x00, 0x00},
974 {SENSOR, 0x64, 0x00, 0x00},
975
976 {SENSOR, MT9M111_SC_ROWSTART, 0x00, 0x0d},
977 {SENSOR, MT9M111_SC_COLSTART, 0x00, 0x12},
978 {SENSOR, MT9M111_SC_WINDOW_HEIGHT, 0x04, 0x00},
979 {SENSOR, MT9M111_SC_WINDOW_WIDTH, 0x05, 0x10},
980 {SENSOR, MT9M111_SC_HBLANK_CONTEXT_B, 0x01, 0x60},
981 {SENSOR, MT9M111_SC_VBLANK_CONTEXT_B, 0x00, 0x11},
982 {SENSOR, MT9M111_SC_HBLANK_CONTEXT_A, 0x01, 0x60},
983 {SENSOR, MT9M111_SC_VBLANK_CONTEXT_A, 0x00, 0x11},
984 {SENSOR, MT9M111_SC_R_MODE_CONTEXT_B, 0x01, 0x0f},
985 {SENSOR, MT9M111_SC_R_MODE_CONTEXT_A, 0x01, 0x0f},
986 {SENSOR, 0x30, 0x04, 0x00},
987
988 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
989 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
990 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
991 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
992 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
993 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
994 {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
995 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
996 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
997 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
998 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
999 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
1000 {BRIDGE, M5602_XB_VSYNC_PARA, 0xe0, 0x00},
1001 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
1002 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
1003 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
1004 {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
1005 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
1006 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
1007 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
1008 {BRIDGE, M5602_XB_HSYNC_PARA, 0x7f, 0x00},
1009 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
1010 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
1011 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
1012
1013 {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
1014 /* Set number of blank rows chosen to 400 */
1015 {SENSOR, MT9M111_SC_SHUTTER_WIDTH, 0x01, 0x90},
1016 /* Set the global gain to 283 (of 512) */
1017 {SENSOR, MT9M111_SC_GLOBAL_GAIN, 0x03, 0x63}
1018};
1019
1020#endif
diff --git a/drivers/media/video/gspca/m5602/m5602_ov9650.c b/drivers/media/video/gspca/m5602/m5602_ov9650.c
new file mode 100644
index 000000000000..31c5896250e7
--- /dev/null
+++ b/drivers/media/video/gspca/m5602/m5602_ov9650.c
@@ -0,0 +1,546 @@
1/*
2 * Driver for the ov9650 sensor
3 *
4 * Copyright (C) 2008 Erik Andren
5 * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
6 * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
7 *
8 * Portions of code to USB interface and ALi driver software,
9 * Copyright (c) 2006 Willem Duinker
10 * v4l2 interface modeled after the V4L2 driver
11 * for SN9C10x PC Camera Controllers
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation, version 2.
16 *
17 */
18
19#include "m5602_ov9650.h"
20
21int ov9650_read_sensor(struct sd *sd, const u8 address,
22 u8 *i2c_data, const u8 len)
23{
24 int err, i;
25
26 /* The ov9650 registers have a max depth of one byte */
27 if (len > 1 || !len)
28 return -EINVAL;
29
30 do {
31 err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data);
32 } while ((*i2c_data & I2C_BUSY) && !err);
33
34 m5602_write_bridge(sd, M5602_XB_I2C_DEV_ADDR,
35 ov9650.i2c_slave_id);
36 m5602_write_bridge(sd, M5602_XB_I2C_REG_ADDR, address);
37 m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x10 + len);
38 m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x08);
39
40 for (i = 0; i < len; i++) {
41 err = m5602_read_bridge(sd, M5602_XB_I2C_DATA, &(i2c_data[i]));
42
43 PDEBUG(DBG_TRACE, "Reading sensor register "
44 "0x%x containing 0x%x ", address, *i2c_data);
45 }
46 return (err < 0) ? err : 0;
47}
48
49int ov9650_write_sensor(struct sd *sd, const u8 address,
50 u8 *i2c_data, const u8 len)
51{
52 int err, i;
53 u8 *p;
54 struct usb_device *udev = sd->gspca_dev.dev;
55 __u8 *buf = sd->gspca_dev.usb_buf;
56
57 /* The ov9650 only supports one byte writes */
58 if (len > 1 || !len)
59 return -EINVAL;
60
61 memcpy(buf, sensor_urb_skeleton,
62 sizeof(sensor_urb_skeleton));
63
64 buf[11] = sd->sensor->i2c_slave_id;
65 buf[15] = address;
66
67 /* Special case larger sensor writes */
68 p = buf + 16;
69
70 /* Copy a four byte write sequence for each byte to be written to */
71 for (i = 0; i < len; i++) {
72 memcpy(p, sensor_urb_skeleton + 16, 4);
73 p[3] = i2c_data[i];
74 p += 4;
75 PDEBUG(DBG_TRACE, "Writing sensor register 0x%x with 0x%x",
76 address, i2c_data[i]);
77 }
78
79 /* Copy the tailer */
80 memcpy(p, sensor_urb_skeleton + 20, 4);
81
82 /* Set the total length */
83 p[3] = 0x10 + len;
84
85 err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
86 0x04, 0x40, 0x19,
87 0x0000, buf,
88 20 + len * 4, M5602_URB_MSG_TIMEOUT);
89
90 return (err < 0) ? err : 0;
91}
92
93int ov9650_probe(struct sd *sd)
94{
95 u8 prod_id = 0, ver_id = 0, i;
96
97 if (force_sensor) {
98 if (force_sensor == OV9650_SENSOR) {
99 info("Forcing an %s sensor", ov9650.name);
100 goto sensor_found;
101 }
102 /* If we want to force another sensor,
103 don't try to probe this one */
104 return -ENODEV;
105 }
106
107 info("Probing for an ov9650 sensor");
108
109 /* Run the pre-init to actually probe the unit */
110 for (i = 0; i < ARRAY_SIZE(preinit_ov9650); i++) {
111 u8 data = preinit_ov9650[i][2];
112 if (preinit_ov9650[i][0] == SENSOR)
113 ov9650_write_sensor(sd,
114 preinit_ov9650[i][1], &data, 1);
115 else
116 m5602_write_bridge(sd, preinit_ov9650[i][1], data);
117 }
118
119 if (ov9650_read_sensor(sd, OV9650_PID, &prod_id, 1))
120 return -ENODEV;
121
122 if (ov9650_read_sensor(sd, OV9650_VER, &ver_id, 1))
123 return -ENODEV;
124
125 if ((prod_id == 0x96) && (ver_id == 0x52)) {
126 info("Detected an ov9650 sensor");
127 goto sensor_found;
128 }
129
130 return -ENODEV;
131
132sensor_found:
133 sd->gspca_dev.cam.cam_mode = ov9650.modes;
134 sd->gspca_dev.cam.nmodes = ov9650.nmodes;
135 sd->desc->ctrls = ov9650.ctrls;
136 sd->desc->nctrls = ov9650.nctrls;
137 return 0;
138}
139
140int ov9650_init(struct sd *sd)
141{
142 int i, err = 0;
143 u8 data;
144
145 if (dump_sensor)
146 ov9650_dump_registers(sd);
147
148 for (i = 0; i < ARRAY_SIZE(init_ov9650) && !err; i++) {
149 data = init_ov9650[i][2];
150 if (init_ov9650[i][0] == SENSOR)
151 err = ov9650_write_sensor(sd, init_ov9650[i][1],
152 &data, 1);
153 else
154 err = m5602_write_bridge(sd, init_ov9650[i][1], data);
155 }
156
157 if (!err && dmi_check_system(ov9650_flip_dmi_table)) {
158 info("vflip quirk active");
159 data = 0x30;
160 err = ov9650_write_sensor(sd, OV9650_MVFP, &data, 1);
161 }
162
163 return (err < 0) ? err : 0;
164}
165
166int ov9650_power_down(struct sd *sd)
167{
168 int i;
169 for (i = 0; i < ARRAY_SIZE(power_down_ov9650); i++) {
170 u8 data = power_down_ov9650[i][2];
171 if (power_down_ov9650[i][0] == SENSOR)
172 ov9650_write_sensor(sd,
173 power_down_ov9650[i][1], &data, 1);
174 else
175 m5602_write_bridge(sd, power_down_ov9650[i][1], data);
176 }
177
178 return 0;
179}
180
181int ov9650_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
182{
183 struct sd *sd = (struct sd *) gspca_dev;
184 u8 i2c_data;
185 int err;
186
187 err = ov9650_read_sensor(sd, OV9650_COM1, &i2c_data, 1);
188 if (err < 0)
189 goto out;
190 *val = i2c_data & 0x03;
191
192 err = ov9650_read_sensor(sd, OV9650_AECH, &i2c_data, 1);
193 if (err < 0)
194 goto out;
195 *val |= (i2c_data << 2);
196
197 err = ov9650_read_sensor(sd, OV9650_AECHM, &i2c_data, 1);
198 if (err < 0)
199 goto out;
200 *val |= (i2c_data & 0x3f) << 10;
201
202 PDEBUG(DBG_V4L2_CID, "Read exposure %d", *val);
203out:
204 return (err < 0) ? err : 0;
205}
206
207int ov9650_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
208{
209 struct sd *sd = (struct sd *) gspca_dev;
210 u8 i2c_data;
211 int err;
212
213 PDEBUG(DBG_V4L2_CID, "Set exposure to %d",
214 val & 0xffff);
215
216 /* The 6 MSBs */
217 i2c_data = (val >> 10) & 0x3f;
218 err = ov9650_write_sensor(sd, OV9650_AECHM,
219 &i2c_data, 1);
220 if (err < 0)
221 goto out;
222
223 /* The 8 middle bits */
224 i2c_data = (val >> 2) & 0xff;
225 err = ov9650_write_sensor(sd, OV9650_AECH,
226 &i2c_data, 1);
227 if (err < 0)
228 goto out;
229
230 /* The 2 LSBs */
231 i2c_data = val & 0x03;
232 err = ov9650_write_sensor(sd, OV9650_COM1, &i2c_data, 1);
233
234out:
235 return (err < 0) ? err : 0;
236}
237
238int ov9650_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
239{
240 int err;
241 u8 i2c_data;
242 struct sd *sd = (struct sd *) gspca_dev;
243
244 ov9650_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
245 *val = (i2c_data & 0x03) << 8;
246
247 err = ov9650_read_sensor(sd, OV9650_GAIN, &i2c_data, 1);
248 *val |= i2c_data;
249 PDEBUG(DBG_V4L2_CID, "Read gain %d", *val);
250 return (err < 0) ? err : 0;
251}
252
253int ov9650_set_gain(struct gspca_dev *gspca_dev, __s32 val)
254{
255 int err;
256 u8 i2c_data;
257 struct sd *sd = (struct sd *) gspca_dev;
258
259 /* The 2 MSB */
260 /* Read the OV9650_VREF register first to avoid
261 corrupting the VREF high and low bits */
262 ov9650_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
263 /* Mask away all uninteresting bits */
264 i2c_data = ((val & 0x0300) >> 2) |
265 (i2c_data & 0x3F);
266 err = ov9650_write_sensor(sd, OV9650_VREF, &i2c_data, 1);
267
268 /* The 8 LSBs */
269 i2c_data = val & 0xff;
270 err = ov9650_write_sensor(sd, OV9650_GAIN, &i2c_data, 1);
271 return (err < 0) ? err : 0;
272}
273
274int ov9650_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val)
275{
276 int err;
277 u8 i2c_data;
278 struct sd *sd = (struct sd *) gspca_dev;
279
280 err = ov9650_read_sensor(sd, OV9650_RED, &i2c_data, 1);
281 *val = i2c_data;
282
283 PDEBUG(DBG_V4L2_CID, "Read red gain %d", *val);
284
285 return (err < 0) ? err : 0;
286}
287
288int ov9650_set_red_balance(struct gspca_dev *gspca_dev, __s32 val)
289{
290 int err;
291 u8 i2c_data;
292 struct sd *sd = (struct sd *) gspca_dev;
293
294 PDEBUG(DBG_V4L2_CID, "Set red gain to %d",
295 val & 0xff);
296
297 i2c_data = val & 0xff;
298 err = ov9650_write_sensor(sd, OV9650_RED, &i2c_data, 1);
299
300 return (err < 0) ? err : 0;
301}
302
303int ov9650_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val)
304{
305 int err;
306 u8 i2c_data;
307 struct sd *sd = (struct sd *) gspca_dev;
308
309 err = ov9650_read_sensor(sd, OV9650_BLUE, &i2c_data, 1);
310 *val = i2c_data;
311
312 PDEBUG(DBG_V4L2_CID, "Read blue gain %d", *val);
313
314 return (err < 0) ? err : 0;
315}
316
317int ov9650_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val)
318{
319 int err;
320 u8 i2c_data;
321 struct sd *sd = (struct sd *) gspca_dev;
322
323 PDEBUG(DBG_V4L2_CID, "Set blue gain to %d",
324 val & 0xff);
325
326 i2c_data = val & 0xff;
327 err = ov9650_write_sensor(sd, OV9650_BLUE, &i2c_data, 1);
328
329 return (err < 0) ? err : 0;
330}
331
332int ov9650_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
333{
334 int err;
335 u8 i2c_data;
336 struct sd *sd = (struct sd *) gspca_dev;
337
338 err = ov9650_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
339 if (dmi_check_system(ov9650_flip_dmi_table))
340 *val = ((i2c_data & OV9650_HFLIP) >> 5) ? 0 : 1;
341 else
342 *val = (i2c_data & OV9650_HFLIP) >> 5;
343 PDEBUG(DBG_V4L2_CID, "Read horizontal flip %d", *val);
344
345 return (err < 0) ? err : 0;
346}
347
348int ov9650_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
349{
350 int err;
351 u8 i2c_data;
352 struct sd *sd = (struct sd *) gspca_dev;
353
354 PDEBUG(DBG_V4L2_CID, "Set horizontal flip to %d", val);
355 err = ov9650_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
356 if (err < 0)
357 goto out;
358
359 if (dmi_check_system(ov9650_flip_dmi_table))
360 i2c_data = ((i2c_data & 0xdf) |
361 (((val ? 0 : 1) & 0x01) << 5));
362 else
363 i2c_data = ((i2c_data & 0xdf) |
364 ((val & 0x01) << 5));
365
366 err = ov9650_write_sensor(sd, OV9650_MVFP, &i2c_data, 1);
367out:
368 return (err < 0) ? err : 0;
369}
370
371int ov9650_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
372{
373 int err;
374 u8 i2c_data;
375 struct sd *sd = (struct sd *) gspca_dev;
376
377 err = ov9650_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
378 if (dmi_check_system(ov9650_flip_dmi_table))
379 *val = ((i2c_data & 0x10) >> 4) ? 0 : 1;
380 else
381 *val = (i2c_data & 0x10) >> 4;
382 PDEBUG(DBG_V4L2_CID, "Read vertical flip %d", *val);
383
384 return (err < 0) ? err : 0;
385}
386
387int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
388{
389 int err;
390 u8 i2c_data;
391 struct sd *sd = (struct sd *) gspca_dev;
392
393 PDEBUG(DBG_V4L2_CID, "Set vertical flip to %d", val);
394 err = ov9650_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
395 if (err < 0)
396 goto out;
397
398 if (dmi_check_system(ov9650_flip_dmi_table))
399 i2c_data = ((i2c_data & 0xef) |
400 (((val ? 0 : 1) & 0x01) << 4));
401 else
402 i2c_data = ((i2c_data & 0xef) |
403 ((val & 0x01) << 4));
404
405 err = ov9650_write_sensor(sd, OV9650_MVFP, &i2c_data, 1);
406out:
407 return (err < 0) ? err : 0;
408}
409
410int ov9650_get_brightness(struct gspca_dev *gspca_dev, __s32 *val)
411{
412 int err;
413 u8 i2c_data;
414 struct sd *sd = (struct sd *) gspca_dev;
415
416 err = ov9650_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
417 if (err < 0)
418 goto out;
419 *val = (i2c_data & 0x03) << 8;
420
421 err = ov9650_read_sensor(sd, OV9650_GAIN, &i2c_data, 1);
422 *val |= i2c_data;
423 PDEBUG(DBG_V4L2_CID, "Read gain %d", *val);
424out:
425 return (err < 0) ? err : 0;
426}
427
428int ov9650_set_brightness(struct gspca_dev *gspca_dev, __s32 val)
429{
430 int err;
431 u8 i2c_data;
432 struct sd *sd = (struct sd *) gspca_dev;
433
434 PDEBUG(DBG_V4L2_CID, "Set gain to %d", val & 0x3ff);
435
436 /* Read the OV9650_VREF register first to avoid
437 corrupting the VREF high and low bits */
438 err = ov9650_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
439 if (err < 0)
440 goto out;
441
442 /* Mask away all uninteresting bits */
443 i2c_data = ((val & 0x0300) >> 2) | (i2c_data & 0x3F);
444 err = ov9650_write_sensor(sd, OV9650_VREF, &i2c_data, 1);
445 if (err < 0)
446 goto out;
447
448 /* The 8 LSBs */
449 i2c_data = val & 0xff;
450 err = ov9650_write_sensor(sd, OV9650_GAIN, &i2c_data, 1);
451
452out:
453 return (err < 0) ? err : 0;
454}
455
456int ov9650_get_auto_white_balance(struct gspca_dev *gspca_dev, __s32 *val)
457{
458 int err;
459 u8 i2c_data;
460 struct sd *sd = (struct sd *) gspca_dev;
461
462 err = ov9650_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
463 *val = (i2c_data & OV9650_AWB_EN) >> 1;
464 PDEBUG(DBG_V4L2_CID, "Read auto white balance %d", *val);
465
466 return (err < 0) ? err : 0;
467}
468
469int ov9650_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val)
470{
471 int err;
472 u8 i2c_data;
473 struct sd *sd = (struct sd *) gspca_dev;
474
475 PDEBUG(DBG_V4L2_CID, "Set auto white balance to %d", val);
476 err = ov9650_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
477 if (err < 0)
478 goto out;
479
480 i2c_data = ((i2c_data & 0xfd) | ((val & 0x01) << 1));
481 err = ov9650_write_sensor(sd, OV9650_COM8, &i2c_data, 1);
482out:
483 return (err < 0) ? err : 0;
484}
485
486int ov9650_get_auto_gain(struct gspca_dev *gspca_dev, __s32 *val)
487{
488 int err;
489 u8 i2c_data;
490 struct sd *sd = (struct sd *) gspca_dev;
491
492 err = ov9650_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
493 *val = (i2c_data & OV9650_AGC_EN) >> 2;
494 PDEBUG(DBG_V4L2_CID, "Read auto gain control %d", *val);
495
496 return (err < 0) ? err : 0;
497}
498
499int ov9650_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val)
500{
501 int err;
502 u8 i2c_data;
503 struct sd *sd = (struct sd *) gspca_dev;
504
505 PDEBUG(DBG_V4L2_CID, "Set auto gain control to %d", val);
506 err = ov9650_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
507 if (err < 0)
508 goto out;
509
510 i2c_data = ((i2c_data & 0xfb) | ((val & 0x01) << 2));
511 err = ov9650_write_sensor(sd, OV9650_COM8, &i2c_data, 1);
512out:
513 return (err < 0) ? err : 0;
514}
515
516void ov9650_dump_registers(struct sd *sd)
517{
518 int address;
519 info("Dumping the ov9650 register state");
520 for (address = 0; address < 0xa9; address++) {
521 u8 value;
522 ov9650_read_sensor(sd, address, &value, 1);
523 info("register 0x%x contains 0x%x",
524 address, value);
525 }
526
527 info("ov9650 register state dump complete");
528
529 info("Probing for which registers that are read/write");
530 for (address = 0; address < 0xff; address++) {
531 u8 old_value, ctrl_value;
532 u8 test_value[2] = {0xff, 0xff};
533
534 ov9650_read_sensor(sd, address, &old_value, 1);
535 ov9650_write_sensor(sd, address, test_value, 1);
536 ov9650_read_sensor(sd, address, &ctrl_value, 1);
537
538 if (ctrl_value == test_value[0])
539 info("register 0x%x is writeable", address);
540 else
541 info("register 0x%x is read only", address);
542
543 /* Restore original value */
544 ov9650_write_sensor(sd, address, &old_value, 1);
545 }
546}
diff --git a/drivers/media/video/gspca/m5602/m5602_ov9650.h b/drivers/media/video/gspca/m5602/m5602_ov9650.h
new file mode 100644
index 000000000000..2f29cb056f30
--- /dev/null
+++ b/drivers/media/video/gspca/m5602/m5602_ov9650.h
@@ -0,0 +1,503 @@
1/*
2 * Driver for the ov9650 sensor
3 *
4 * Copyright (C) 2008 Erik Andren
5 * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
6 * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
7 *
8 * Portions of code to USB interface and ALi driver software,
9 * Copyright (c) 2006 Willem Duinker
10 * v4l2 interface modeled after the V4L2 driver
11 * for SN9C10x PC Camera Controllers
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation, version 2.
16 *
17 */
18
19#ifndef M5602_OV9650_H_
20#define M5602_OV9650_H_
21
22#include <linux/dmi.h>
23
24#include "m5602_sensor.h"
25
26/*****************************************************************************/
27
28#define OV9650_GAIN 0x00
29#define OV9650_BLUE 0x01
30#define OV9650_RED 0x02
31#define OV9650_VREF 0x03
32#define OV9650_COM1 0x04
33#define OV9650_BAVE 0x05
34#define OV9650_GEAVE 0x06
35#define OV9650_RSVD7 0x07
36#define OV9650_PID 0x0a
37#define OV9650_VER 0x0b
38#define OV9650_COM3 0x0c
39#define OV9650_COM5 0x0e
40#define OV9650_COM6 0x0f
41#define OV9650_AECH 0x10
42#define OV9650_CLKRC 0x11
43#define OV9650_COM7 0x12
44#define OV9650_COM8 0x13
45#define OV9650_COM9 0x14
46#define OV9650_COM10 0x15
47#define OV9650_RSVD16 0x16
48#define OV9650_HSTART 0x17
49#define OV9650_HSTOP 0x18
50#define OV9650_VSTRT 0x19
51#define OV9650_VSTOP 0x1a
52#define OV9650_PSHFT 0x1b
53#define OV9650_MVFP 0x1e
54#define OV9650_AEW 0x24
55#define OV9650_AEB 0x25
56#define OV9650_VPT 0x26
57#define OV9650_BBIAS 0x27
58#define OV9650_GbBIAS 0x28
59#define OV9650_Gr_COM 0x29
60#define OV9650_RBIAS 0x2c
61#define OV9650_HREF 0x32
62#define OV9650_CHLF 0x33
63#define OV9650_ARBLM 0x34
64#define OV9650_RSVD35 0x35
65#define OV9650_RSVD36 0x36
66#define OV9650_ADC 0x37
67#define OV9650_ACOM38 0x38
68#define OV9650_OFON 0x39
69#define OV9650_TSLB 0x3a
70#define OV9650_COM12 0x3c
71#define OV9650_COM13 0x3d
72#define OV9650_COM15 0x40
73#define OV9650_COM16 0x41
74#define OV9650_LCC1 0x62
75#define OV9650_LCC2 0x63
76#define OV9650_LCC3 0x64
77#define OV9650_LCC4 0x65
78#define OV9650_LCC5 0x66
79#define OV9650_HV 0x69
80#define OV9650_DBLV 0x6b
81#define OV9650_COM21 0x8b
82#define OV9650_COM22 0x8c
83#define OV9650_COM24 0x8e
84#define OV9650_DBLC1 0x8f
85#define OV9650_RSVD94 0x94
86#define OV9650_RSVD95 0x95
87#define OV9650_RSVD96 0x96
88#define OV9650_LCCFB 0x9d
89#define OV9650_LCCFR 0x9e
90#define OV9650_AECHM 0xa1
91#define OV9650_COM26 0xa5
92#define OV9650_ACOMA8 0xa8
93#define OV9650_ACOMA9 0xa9
94
95#define OV9650_REGISTER_RESET (1 << 7)
96#define OV9650_VGA_SELECT (1 << 6)
97#define OV9650_RGB_SELECT (1 << 2)
98#define OV9650_RAW_RGB_SELECT (1 << 0)
99
100#define OV9650_FAST_AGC_AEC (1 << 7)
101#define OV9650_AEC_UNLIM_STEP_SIZE (1 << 6)
102#define OV9650_BANDING (1 << 5)
103#define OV9650_AGC_EN (1 << 2)
104#define OV9650_AWB_EN (1 << 1)
105#define OV9650_AEC_EN (1 << 0)
106
107#define OV9650_VARIOPIXEL (1 << 2)
108#define OV9650_SYSTEM_CLK_SEL (1 << 7)
109#define OV9650_SLAM_MODE (1 << 4)
110
111#define OV9650_VFLIP (1 << 4)
112#define OV9650_HFLIP (1 << 5)
113
114#define GAIN_DEFAULT 0x14
115#define RED_GAIN_DEFAULT 0x70
116#define BLUE_GAIN_DEFAULT 0x20
117#define EXPOSURE_DEFAULT 0x5003
118
119/*****************************************************************************/
120
121/* Kernel module parameters */
122extern int force_sensor;
123extern int dump_sensor;
124extern unsigned int m5602_debug;
125
126int ov9650_probe(struct sd *sd);
127int ov9650_init(struct sd *sd);
128int ov9650_power_down(struct sd *sd);
129
130int ov9650_read_sensor(struct sd *sd, const u8 address,
131 u8 *i2c_data, const u8 len);
132int ov9650_write_sensor(struct sd *sd, const u8 address,
133 u8 *i2c_data, const u8 len);
134
135void ov9650_dump_registers(struct sd *sd);
136
137int ov9650_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
138int ov9650_get_exposure(struct gspca_dev *gspca_dev, __s32 *val);
139int ov9650_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
140int ov9650_set_gain(struct gspca_dev *gspca_dev, __s32 val);
141int ov9650_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val);
142int ov9650_set_red_balance(struct gspca_dev *gspca_dev, __s32 val);
143int ov9650_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val);
144int ov9650_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val);
145int ov9650_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
146int ov9650_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
147int ov9650_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
148int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
149int ov9650_get_brightness(struct gspca_dev *gspca_dev, __s32 *val);
150int ov9650_set_brightness(struct gspca_dev *gspca_dev, __s32 val);
151int ov9650_get_auto_white_balance(struct gspca_dev *gspca_dev, __s32 *val);
152int ov9650_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val);
153int ov9650_get_auto_gain(struct gspca_dev *gspca_dev, __s32 *val);
154int ov9650_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val);
155
156static struct m5602_sensor ov9650 = {
157 .name = "OV9650",
158 .i2c_slave_id = 0x60,
159 .probe = ov9650_probe,
160 .init = ov9650_init,
161 .power_down = ov9650_power_down,
162 .read_sensor = ov9650_read_sensor,
163 .write_sensor = ov9650_write_sensor,
164
165 .nctrls = 8,
166 .ctrls = {
167 {
168 {
169 .id = V4L2_CID_EXPOSURE,
170 .type = V4L2_CTRL_TYPE_INTEGER,
171 .name = "exposure",
172 .minimum = 0x00,
173 .maximum = 0xffff,
174 .step = 0x1,
175 .default_value = EXPOSURE_DEFAULT,
176 .flags = V4L2_CTRL_FLAG_SLIDER
177 },
178 .set = ov9650_set_exposure,
179 .get = ov9650_get_exposure
180 }, {
181 {
182 .id = V4L2_CID_GAIN,
183 .type = V4L2_CTRL_TYPE_INTEGER,
184 .name = "gain",
185 .minimum = 0x00,
186 .maximum = 0x3ff,
187 .step = 0x1,
188 .default_value = GAIN_DEFAULT,
189 .flags = V4L2_CTRL_FLAG_SLIDER
190 },
191 .set = ov9650_set_gain,
192 .get = ov9650_get_gain
193 }, {
194 {
195 .type = V4L2_CTRL_TYPE_INTEGER,
196 .name = "red balance",
197 .minimum = 0x00,
198 .maximum = 0xff,
199 .step = 0x1,
200 .default_value = RED_GAIN_DEFAULT,
201 .flags = V4L2_CTRL_FLAG_SLIDER
202 },
203 .set = ov9650_set_red_balance,
204 .get = ov9650_get_red_balance
205 }, {
206 {
207 .type = V4L2_CTRL_TYPE_INTEGER,
208 .name = "blue balance",
209 .minimum = 0x00,
210 .maximum = 0xff,
211 .step = 0x1,
212 .default_value = BLUE_GAIN_DEFAULT,
213 .flags = V4L2_CTRL_FLAG_SLIDER
214 },
215 .set = ov9650_set_blue_balance,
216 .get = ov9650_get_blue_balance
217 }, {
218 {
219 .id = V4L2_CID_HFLIP,
220 .type = V4L2_CTRL_TYPE_BOOLEAN,
221 .name = "horizontal flip",
222 .minimum = 0,
223 .maximum = 1,
224 .step = 1,
225 .default_value = 0
226 },
227 .set = ov9650_set_hflip,
228 .get = ov9650_get_hflip
229 }, {
230 {
231 .id = V4L2_CID_VFLIP,
232 .type = V4L2_CTRL_TYPE_BOOLEAN,
233 .name = "vertical flip",
234 .minimum = 0,
235 .maximum = 1,
236 .step = 1,
237 .default_value = 0
238 },
239 .set = ov9650_set_vflip,
240 .get = ov9650_get_vflip
241 }, {
242 {
243 .id = V4L2_CID_AUTO_WHITE_BALANCE,
244 .type = V4L2_CTRL_TYPE_BOOLEAN,
245 .name = "auto white balance",
246 .minimum = 0,
247 .maximum = 1,
248 .step = 1,
249 .default_value = 0
250 },
251 .set = ov9650_set_auto_white_balance,
252 .get = ov9650_get_auto_white_balance
253 }, {
254 {
255 .id = V4L2_CID_AUTOGAIN,
256 .type = V4L2_CTRL_TYPE_BOOLEAN,
257 .name = "auto gain control",
258 .minimum = 0,
259 .maximum = 1,
260 .step = 1,
261 .default_value = 0
262 },
263 .set = ov9650_set_auto_gain,
264 .get = ov9650_get_auto_gain
265 }
266 },
267
268 .nmodes = 1,
269 .modes = {
270 {
271 M5602_DEFAULT_FRAME_WIDTH,
272 M5602_DEFAULT_FRAME_HEIGHT,
273 V4L2_PIX_FMT_SBGGR8,
274 V4L2_FIELD_NONE,
275 .sizeimage =
276 M5602_DEFAULT_FRAME_WIDTH * M5602_DEFAULT_FRAME_HEIGHT,
277 .bytesperline = M5602_DEFAULT_FRAME_WIDTH,
278 .colorspace = V4L2_COLORSPACE_SRGB,
279 .priv = 1
280 }
281 }
282};
283
284static const unsigned char preinit_ov9650[][3] =
285{
286 /* [INITCAM] */
287 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02},
288 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0},
289 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
290 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
291 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
292 {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00},
293
294 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08},
295 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
296 {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
297 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
298 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
299 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00},
300 {BRIDGE, M5602_XB_GPIO_DAT, 0x00},
301 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a},
302 /* Reset chip */
303 {SENSOR, OV9650_COM7, OV9650_REGISTER_RESET},
304 /* Enable double clock */
305 {SENSOR, OV9650_CLKRC, 0x80},
306 /* Do something out of spec with the power */
307 {SENSOR, OV9650_OFON, 0x40}
308};
309
310static const unsigned char init_ov9650[][3] =
311{
312 /* [INITCAM] */
313 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02},
314 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0},
315 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
316 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
317 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
318 {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00},
319
320 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08},
321 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
322 {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
323 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
324 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
325 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00},
326 {BRIDGE, M5602_XB_GPIO_DAT, 0x00},
327 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a},
328 /* Reset chip */
329 {SENSOR, OV9650_COM7, OV9650_REGISTER_RESET},
330 /* Enable double clock */
331 {SENSOR, OV9650_CLKRC, 0x80},
332 /* Do something out of spec with the power */
333 {SENSOR, OV9650_OFON, 0x40},
334
335 /* Set QQVGA */
336 {SENSOR, OV9650_COM1, 0x20},
337 /* Set fast AGC/AEC algorithm with unlimited step size */
338 {SENSOR, OV9650_COM8, OV9650_FAST_AGC_AEC |
339 OV9650_AEC_UNLIM_STEP_SIZE |
340 OV9650_AWB_EN | OV9650_AGC_EN},
341
342 {SENSOR, OV9650_CHLF, 0x10},
343 {SENSOR, OV9650_ARBLM, 0xbf},
344 {SENSOR, OV9650_ACOM38, 0x81},
345 /* Turn off color matrix coefficient double option */
346 {SENSOR, OV9650_COM16, 0x00},
347 /* Enable color matrix for RGB/YUV, Delay Y channel,
348 set output Y/UV delay to 1 */
349 {SENSOR, OV9650_COM13, 0x19},
350 /* Enable digital BLC, Set output mode to U Y V Y */
351 {SENSOR, OV9650_TSLB, 0x0c},
352 /* Limit the AGC/AEC stable upper region */
353 {SENSOR, OV9650_COM24, 0x00},
354 /* Enable HREF and some out of spec things */
355 {SENSOR, OV9650_COM12, 0x73},
356 /* Set all DBLC offset signs to positive and
357 do some out of spec stuff */
358 {SENSOR, OV9650_DBLC1, 0xdf},
359 {SENSOR, OV9650_COM21, 0x06},
360 {SENSOR, OV9650_RSVD35, 0x91},
361 /* Necessary, no camera stream without it */
362 {SENSOR, OV9650_RSVD16, 0x06},
363 {SENSOR, OV9650_RSVD94, 0x99},
364 {SENSOR, OV9650_RSVD95, 0x99},
365 {SENSOR, OV9650_RSVD96, 0x04},
366 /* Enable full range output */
367 {SENSOR, OV9650_COM15, 0x0},
368 /* Enable HREF at optical black, enable ADBLC bias,
369 enable ADBLC, reset timings at format change */
370 {SENSOR, OV9650_COM6, 0x4b},
371 /* Subtract 32 from the B channel bias */
372 {SENSOR, OV9650_BBIAS, 0xa0},
373 /* Subtract 32 from the Gb channel bias */
374 {SENSOR, OV9650_GbBIAS, 0xa0},
375 /* Do not bypass the analog BLC and to some out of spec stuff */
376 {SENSOR, OV9650_Gr_COM, 0x00},
377 /* Subtract 32 from the R channel bias */
378 {SENSOR, OV9650_RBIAS, 0xa0},
379 /* Subtract 32 from the R channel bias */
380 {SENSOR, OV9650_RBIAS, 0x0},
381 {SENSOR, OV9650_COM26, 0x80},
382 {SENSOR, OV9650_ACOMA9, 0x98},
383 /* Set the AGC/AEC stable region upper limit */
384 {SENSOR, OV9650_AEW, 0x68},
385 /* Set the AGC/AEC stable region lower limit */
386 {SENSOR, OV9650_AEB, 0x5c},
387 /* Set the high and low limit nibbles to 3 */
388 {SENSOR, OV9650_VPT, 0xc3},
389 /* Set the Automatic Gain Ceiling (AGC) to 128x,
390 drop VSYNC at frame drop,
391 limit exposure timing,
392 drop frame when the AEC step is larger than the exposure gap */
393 {SENSOR, OV9650_COM9, 0x6e},
394 /* Set VSYNC negative, Set RESET to SLHS (slave mode horizontal sync)
395 and set PWDN to SLVS (slave mode vertical sync) */
396 {SENSOR, OV9650_COM10, 0x42},
397 /* Set horizontal column start high to default value */
398 {SENSOR, OV9650_HSTART, 0x1a},
399 /* Set horizontal column end */
400 {SENSOR, OV9650_HSTOP, 0xbf},
401 /* Complementing register to the two writes above */
402 {SENSOR, OV9650_HREF, 0xb2},
403 /* Set vertical row start high bits */
404 {SENSOR, OV9650_VSTRT, 0x02},
405 /* Set vertical row end low bits */
406 {SENSOR, OV9650_VSTOP, 0x7e},
407 /* Set complementing vertical frame control */
408 {SENSOR, OV9650_VREF, 0x10},
409 /* Set raw RGB output format with VGA resolution */
410 {SENSOR, OV9650_COM7, OV9650_VGA_SELECT |
411 OV9650_RGB_SELECT |
412 OV9650_RAW_RGB_SELECT},
413 {SENSOR, OV9650_ADC, 0x04},
414 {SENSOR, OV9650_HV, 0x40},
415 /* Enable denoise, and white-pixel erase */
416 {SENSOR, OV9650_COM22, 0x23},
417
418 /* Set the high bits of the exposure value */
419 {SENSOR, OV9650_AECH, ((EXPOSURE_DEFAULT & 0xff00) >> 8)},
420
421 /* Set the low bits of the exposure value */
422 {SENSOR, OV9650_COM1, (EXPOSURE_DEFAULT & 0xff)},
423 {SENSOR, OV9650_GAIN, GAIN_DEFAULT},
424 {SENSOR, OV9650_BLUE, BLUE_GAIN_DEFAULT},
425 {SENSOR, OV9650_RED, RED_GAIN_DEFAULT},
426
427 {SENSOR, OV9650_COM3, OV9650_VARIOPIXEL},
428 {SENSOR, OV9650_COM5, OV9650_SYSTEM_CLK_SEL},
429
430 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x82},
431 {BRIDGE, M5602_XB_LINE_OF_FRAME_L, 0x00},
432 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82},
433 {BRIDGE, M5602_XB_PIX_OF_LINE_L, 0x00},
434 {BRIDGE, M5602_XB_SIG_INI, 0x01},
435 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
436 {BRIDGE, M5602_XB_VSYNC_PARA, 0x09},
437 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
438 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01},
439 {BRIDGE, M5602_XB_VSYNC_PARA, 0xe0},
440 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
441 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
442 {BRIDGE, M5602_XB_HSYNC_PARA, 0x5e},
443 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02},
444 {BRIDGE, M5602_XB_HSYNC_PARA, 0xde}
445};
446
447static const unsigned char power_down_ov9650[][3] =
448{
449 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
450 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
451 {SENSOR, OV9650_COM7, 0x80},
452 {SENSOR, OV9650_OFON, 0xf4},
453 {SENSOR, OV9650_MVFP, 0x80},
454 {SENSOR, OV9650_DBLV, 0x3f},
455 {SENSOR, OV9650_RSVD36, 0x49},
456 {SENSOR, OV9650_COM7, 0x05},
457
458 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
459 {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
460 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
461 {BRIDGE, M5602_XB_GPIO_EN_L, 0x06},
462 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
463 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
464 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0}
465};
466
467/* Vertically and horizontally flips the image if matched, needed for machines
468 where the sensor is mounted upside down */
469static
470 const
471 struct dmi_system_id ov9650_flip_dmi_table[] = {
472 {
473 .ident = "ASUS A6VC",
474 .matches = {
475 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
476 DMI_MATCH(DMI_PRODUCT_NAME, "A6VC")
477 }
478 },
479 {
480 .ident = "ASUS A6VM",
481 .matches = {
482 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
483 DMI_MATCH(DMI_PRODUCT_NAME, "A6VM")
484 }
485 },
486 {
487 .ident = "ASUS A6JC",
488 .matches = {
489 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
490 DMI_MATCH(DMI_PRODUCT_NAME, "A6JC")
491 }
492 },
493 {
494 .ident = "ASUS A6Kt",
495 .matches = {
496 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
497 DMI_MATCH(DMI_PRODUCT_NAME, "A6Kt")
498 }
499 },
500 { }
501};
502
503#endif
diff --git a/drivers/media/video/gspca/m5602/m5602_po1030.c b/drivers/media/video/gspca/m5602/m5602_po1030.c
new file mode 100644
index 000000000000..08c015bde115
--- /dev/null
+++ b/drivers/media/video/gspca/m5602/m5602_po1030.c
@@ -0,0 +1,336 @@
1/*
2 * Driver for the po1030 sensor
3 *
4 * Copyright (c) 2008 Erik Andren
5 * Copyright (c) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
6 * Copyright (c) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
7 *
8 * Portions of code to USB interface and ALi driver software,
9 * Copyright (c) 2006 Willem Duinker
10 * v4l2 interface modeled after the V4L2 driver
11 * for SN9C10x PC Camera Controllers
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation, version 2.
16 *
17 */
18
19#include "m5602_po1030.h"
20
21int po1030_probe(struct sd *sd)
22{
23 u8 prod_id = 0, ver_id = 0, i;
24
25 if (force_sensor) {
26 if (force_sensor == PO1030_SENSOR) {
27 info("Forcing a %s sensor", po1030.name);
28 goto sensor_found;
29 }
30 /* If we want to force another sensor, don't try to probe this
31 * one */
32 return -ENODEV;
33 }
34
35 info("Probing for a po1030 sensor");
36
37 /* Run the pre-init to actually probe the unit */
38 for (i = 0; i < ARRAY_SIZE(preinit_po1030); i++) {
39 u8 data = preinit_po1030[i][2];
40 if (preinit_po1030[i][0] == SENSOR)
41 po1030_write_sensor(sd,
42 preinit_po1030[i][1], &data, 1);
43 else
44 m5602_write_bridge(sd, preinit_po1030[i][1], data);
45 }
46
47 if (po1030_read_sensor(sd, 0x3, &prod_id, 1))
48 return -ENODEV;
49
50 if (po1030_read_sensor(sd, 0x4, &ver_id, 1))
51 return -ENODEV;
52
53 if ((prod_id == 0x02) && (ver_id == 0xef)) {
54 info("Detected a po1030 sensor");
55 goto sensor_found;
56 }
57 return -ENODEV;
58
59sensor_found:
60 sd->gspca_dev.cam.cam_mode = po1030.modes;
61 sd->gspca_dev.cam.nmodes = po1030.nmodes;
62 sd->desc->ctrls = po1030.ctrls;
63 sd->desc->nctrls = po1030.nctrls;
64 return 0;
65}
66
67int po1030_read_sensor(struct sd *sd, const u8 address,
68 u8 *i2c_data, const u8 len)
69{
70 int err, i;
71
72 do {
73 err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data);
74 } while ((*i2c_data & I2C_BUSY) && !err);
75
76 m5602_write_bridge(sd, M5602_XB_I2C_DEV_ADDR,
77 sd->sensor->i2c_slave_id);
78 m5602_write_bridge(sd, M5602_XB_I2C_REG_ADDR, address);
79 m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x10 + len);
80 m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x08);
81
82 for (i = 0; i < len; i++) {
83 err = m5602_read_bridge(sd, M5602_XB_I2C_DATA, &(i2c_data[i]));
84
85 PDEBUG(DBG_TRACE, "Reading sensor register "
86 "0x%x containing 0x%x ", address, *i2c_data);
87 }
88 return (err < 0) ? err : 0;
89}
90
91int po1030_write_sensor(struct sd *sd, const u8 address,
92 u8 *i2c_data, const u8 len)
93{
94 int err, i;
95 u8 *p;
96 struct usb_device *udev = sd->gspca_dev.dev;
97 __u8 *buf = sd->gspca_dev.usb_buf;
98
99 /* The po1030 only supports one byte writes */
100 if (len > 1 || !len)
101 return -EINVAL;
102
103 memcpy(buf, sensor_urb_skeleton, sizeof(sensor_urb_skeleton));
104
105 buf[11] = sd->sensor->i2c_slave_id;
106 buf[15] = address;
107
108 p = buf + 16;
109
110 /* Copy a four byte write sequence for each byte to be written to */
111 for (i = 0; i < len; i++) {
112 memcpy(p, sensor_urb_skeleton + 16, 4);
113 p[3] = i2c_data[i];
114 p += 4;
115 PDEBUG(DBG_TRACE, "Writing sensor register 0x%x with 0x%x",
116 address, i2c_data[i]);
117 }
118
119 /* Copy the footer */
120 memcpy(p, sensor_urb_skeleton + 20, 4);
121
122 /* Set the total length */
123 p[3] = 0x10 + len;
124
125 err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
126 0x04, 0x40, 0x19,
127 0x0000, buf,
128 20 + len * 4, M5602_URB_MSG_TIMEOUT);
129
130 return (err < 0) ? err : 0;
131}
132
133int po1030_init(struct sd *sd)
134{
135 int i, err = 0;
136
137 /* Init the sensor */
138 for (i = 0; i < ARRAY_SIZE(init_po1030); i++) {
139 u8 data[2] = {0x00, 0x00};
140
141 switch (init_po1030[i][0]) {
142 case BRIDGE:
143 err = m5602_write_bridge(sd,
144 init_po1030[i][1],
145 init_po1030[i][2]);
146 break;
147
148 case SENSOR:
149 data[0] = init_po1030[i][2];
150 err = po1030_write_sensor(sd,
151 init_po1030[i][1], data, 1);
152 break;
153
154 case SENSOR_LONG:
155 data[0] = init_po1030[i][2];
156 data[1] = init_po1030[i][3];
157 err = po1030_write_sensor(sd,
158 init_po1030[i][1], data, 2);
159 break;
160 default:
161 info("Invalid stream command, exiting init");
162 return -EINVAL;
163 }
164 }
165
166 if (dump_sensor)
167 po1030_dump_registers(sd);
168
169 return (err < 0) ? err : 0;
170}
171
172int po1030_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
173{
174 struct sd *sd = (struct sd *) gspca_dev;
175 u8 i2c_data;
176 int err;
177
178 err = po1030_read_sensor(sd, PO1030_REG_INTEGLINES_H,
179 &i2c_data, 1);
180 if (err < 0)
181 goto out;
182 *val = (i2c_data << 8);
183
184 err = po1030_read_sensor(sd, PO1030_REG_INTEGLINES_M,
185 &i2c_data, 1);
186 *val |= i2c_data;
187
188 PDEBUG(DBG_V4L2_CID, "Exposure read as %d", *val);
189out:
190 return (err < 0) ? err : 0;
191}
192
193int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
194{
195 struct sd *sd = (struct sd *) gspca_dev;
196 u8 i2c_data;
197 int err;
198
199 PDEBUG(DBG_V4L2, "Set exposure to %d", val & 0xffff);
200
201 i2c_data = ((val & 0xff00) >> 8);
202 PDEBUG(DBG_V4L2, "Set exposure to high byte to 0x%x",
203 i2c_data);
204
205 err = po1030_write_sensor(sd, PO1030_REG_INTEGLINES_H,
206 &i2c_data, 1);
207 if (err < 0)
208 goto out;
209
210 i2c_data = (val & 0xff);
211 PDEBUG(DBG_V4L2, "Set exposure to low byte to 0x%x",
212 i2c_data);
213 err = po1030_write_sensor(sd, PO1030_REG_INTEGLINES_M,
214 &i2c_data, 1);
215
216out:
217 return (err < 0) ? err : 0;
218}
219
220int po1030_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
221{
222 struct sd *sd = (struct sd *) gspca_dev;
223 u8 i2c_data;
224 int err;
225
226 err = po1030_read_sensor(sd, PO1030_REG_GLOBALGAIN,
227 &i2c_data, 1);
228 *val = i2c_data;
229 PDEBUG(DBG_V4L2_CID, "Read global gain %d", *val);
230
231 return (err < 0) ? err : 0;
232}
233
234int po1030_set_gain(struct gspca_dev *gspca_dev, __s32 val)
235{
236 struct sd *sd = (struct sd *) gspca_dev;
237 u8 i2c_data;
238 int err;
239
240 i2c_data = val & 0xff;
241 PDEBUG(DBG_V4L2, "Set global gain to %d", i2c_data);
242 err = po1030_write_sensor(sd, PO1030_REG_GLOBALGAIN,
243 &i2c_data, 1);
244 return (err < 0) ? err : 0;
245}
246
247int po1030_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val)
248{
249 struct sd *sd = (struct sd *) gspca_dev;
250 u8 i2c_data;
251 int err;
252
253 err = po1030_read_sensor(sd, PO1030_REG_RED_GAIN,
254 &i2c_data, 1);
255 *val = i2c_data;
256 PDEBUG(DBG_V4L2_CID, "Read red gain %d", *val);
257 return (err < 0) ? err : 0;
258}
259
260int po1030_set_red_balance(struct gspca_dev *gspca_dev, __s32 val)
261{
262 struct sd *sd = (struct sd *) gspca_dev;
263 u8 i2c_data;
264 int err;
265
266 i2c_data = val & 0xff;
267 PDEBUG(DBG_V4L2, "Set red gain to %d", i2c_data);
268 err = po1030_write_sensor(sd, PO1030_REG_RED_GAIN,
269 &i2c_data, 1);
270 return (err < 0) ? err : 0;
271}
272
273int po1030_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val)
274{
275 struct sd *sd = (struct sd *) gspca_dev;
276 u8 i2c_data;
277 int err;
278
279 err = po1030_read_sensor(sd, PO1030_REG_BLUE_GAIN,
280 &i2c_data, 1);
281 *val = i2c_data;
282 PDEBUG(DBG_V4L2_CID, "Read blue gain %d", *val);
283
284 return (err < 0) ? err : 0;
285}
286
287int po1030_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val)
288{
289 struct sd *sd = (struct sd *) gspca_dev;
290 u8 i2c_data;
291 int err;
292 i2c_data = val & 0xff;
293 PDEBUG(DBG_V4L2, "Set blue gain to %d", i2c_data);
294 err = po1030_write_sensor(sd, PO1030_REG_BLUE_GAIN,
295 &i2c_data, 1);
296
297 return (err < 0) ? err : 0;
298}
299
300int po1030_power_down(struct sd *sd)
301{
302 return 0;
303}
304
305void po1030_dump_registers(struct sd *sd)
306{
307 int address;
308 u8 value = 0;
309
310 info("Dumping the po1030 sensor core registers");
311 for (address = 0; address < 0x7f; address++) {
312 po1030_read_sensor(sd, address, &value, 1);
313 info("register 0x%x contains 0x%x",
314 address, value);
315 }
316
317 info("po1030 register state dump complete");
318
319 info("Probing for which registers that are read/write");
320 for (address = 0; address < 0xff; address++) {
321 u8 old_value, ctrl_value;
322 u8 test_value[2] = {0xff, 0xff};
323
324 po1030_read_sensor(sd, address, &old_value, 1);
325 po1030_write_sensor(sd, address, test_value, 1);
326 po1030_read_sensor(sd, address, &ctrl_value, 1);
327
328 if (ctrl_value == test_value[0])
329 info("register 0x%x is writeable", address);
330 else
331 info("register 0x%x is read only", address);
332
333 /* Restore original value */
334 po1030_write_sensor(sd, address, &old_value, 1);
335 }
336}
diff --git a/drivers/media/video/gspca/m5602/m5602_po1030.h b/drivers/media/video/gspca/m5602/m5602_po1030.h
new file mode 100644
index 000000000000..68f34c97bf44
--- /dev/null
+++ b/drivers/media/video/gspca/m5602/m5602_po1030.h
@@ -0,0 +1,478 @@
1/*
2 * Driver for the po1030 sensor.
3 * This is probably a pixel plus sensor but we haven't identified it yet
4 *
5 * Copyright (c) 2008 Erik Andren
6 * Copyright (c) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
7 * Copyright (c) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
8 *
9 * Portions of code to USB interface and ALi driver software,
10 * Copyright (c) 2006 Willem Duinker
11 * v4l2 interface modeled after the V4L2 driver
12 * for SN9C10x PC Camera Controllers
13 *
14 * Register defines taken from Pascal Stangs Proxycon Armlib
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License as
18 * published by the Free Software Foundation, version 2.
19 *
20 */
21
22#ifndef M5602_PO1030_H_
23#define M5602_PO1030_H_
24
25#include "m5602_sensor.h"
26
27/*****************************************************************************/
28
29#define PO1030_REG_DEVID_H 0x00
30#define PO1030_REG_DEVID_L 0x01
31#define PO1030_REG_FRAMEWIDTH_H 0x04
32#define PO1030_REG_FRAMEWIDTH_L 0x05
33#define PO1030_REG_FRAMEHEIGHT_H 0x06
34#define PO1030_REG_FRAMEHEIGHT_L 0x07
35#define PO1030_REG_WINDOWX_H 0x08
36#define PO1030_REG_WINDOWX_L 0x09
37#define PO1030_REG_WINDOWY_H 0x0a
38#define PO1030_REG_WINDOWY_L 0x0b
39#define PO1030_REG_WINDOWWIDTH_H 0x0c
40#define PO1030_REG_WINDOWWIDTH_L 0x0d
41#define PO1030_REG_WINDOWHEIGHT_H 0x0e
42#define PO1030_REG_WINDOWHEIGHT_L 0x0f
43
44#define PO1030_REG_GLOBALIBIAS 0x12
45#define PO1030_REG_PIXELIBIAS 0x13
46
47#define PO1030_REG_GLOBALGAIN 0x15
48#define PO1030_REG_RED_GAIN 0x16
49#define PO1030_REG_GREEN_1_GAIN 0x17
50#define PO1030_REG_BLUE_GAIN 0x18
51#define PO1030_REG_GREEN_2_GAIN 0x19
52
53#define PO1030_REG_INTEGLINES_H 0x1a
54#define PO1030_REG_INTEGLINES_M 0x1b
55#define PO1030_REG_INTEGLINES_L 0x1c
56
57#define PO1030_REG_CONTROL1 0x1d
58#define PO1030_REG_CONTROL2 0x1e
59#define PO1030_REG_CONTROL3 0x1f
60#define PO1030_REG_CONTROL4 0x20
61
62#define PO1030_REG_PERIOD50_H 0x23
63#define PO1030_REG_PERIOD50_L 0x24
64#define PO1030_REG_PERIOD60_H 0x25
65#define PO1030_REG_PERIOD60_L 0x26
66#define PO1030_REG_REGCLK167 0x27
67#define PO1030_REG_DELTA50 0x28
68#define PO1030_REG_DELTA60 0x29
69
70#define PO1030_REG_ADCOFFSET 0x2c
71
72/* Gamma Correction Coeffs */
73#define PO1030_REG_GC0 0x2d
74#define PO1030_REG_GC1 0x2e
75#define PO1030_REG_GC2 0x2f
76#define PO1030_REG_GC3 0x30
77#define PO1030_REG_GC4 0x31
78#define PO1030_REG_GC5 0x32
79#define PO1030_REG_GC6 0x33
80#define PO1030_REG_GC7 0x34
81
82/* Color Transform Matrix */
83#define PO1030_REG_CT0 0x35
84#define PO1030_REG_CT1 0x36
85#define PO1030_REG_CT2 0x37
86#define PO1030_REG_CT3 0x38
87#define PO1030_REG_CT4 0x39
88#define PO1030_REG_CT5 0x3a
89#define PO1030_REG_CT6 0x3b
90#define PO1030_REG_CT7 0x3c
91#define PO1030_REG_CT8 0x3d
92
93#define PO1030_REG_AUTOCTRL1 0x3e
94#define PO1030_REG_AUTOCTRL2 0x3f
95
96#define PO1030_REG_YTARGET 0x40
97#define PO1030_REG_GLOBALGAINMIN 0x41
98#define PO1030_REG_GLOBALGAINMAX 0x42
99
100/* Output format control */
101#define PO1030_REG_OUTFORMCTRL1 0x5a
102#define PO1030_REG_OUTFORMCTRL2 0x5b
103#define PO1030_REG_OUTFORMCTRL3 0x5c
104#define PO1030_REG_OUTFORMCTRL4 0x5d
105#define PO1030_REG_OUTFORMCTRL5 0x5e
106
107/* Imaging coefficients */
108#define PO1030_REG_YBRIGHT 0x73
109#define PO1030_REG_YCONTRAST 0x74
110#define PO1030_REG_YSATURATION 0x75
111
112/*****************************************************************************/
113
114#define PO1030_GLOBAL_GAIN_DEFAULT 0x12
115#define PO1030_EXPOSURE_DEFAULT 0xf0ff
116#define PO1030_BLUE_GAIN_DEFAULT 0x40
117#define PO1030_RED_GAIN_DEFAULT 0x40
118
119/*****************************************************************************/
120
121/* Kernel module parameters */
122extern int force_sensor;
123extern int dump_sensor;
124extern unsigned int m5602_debug;
125
126int po1030_probe(struct sd *sd);
127int po1030_init(struct sd *sd);
128int po1030_power_down(struct sd *sd);
129
130void po1030_dump_registers(struct sd *sd);
131
132int po1030_read_sensor(struct sd *sd, const u8 address,
133 u8 *i2c_data, const u8 len);
134int po1030_write_sensor(struct sd *sd, const u8 address,
135 u8 *i2c_data, const u8 len);
136
137int po1030_get_exposure(struct gspca_dev *gspca_dev, __s32 *val);
138int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
139int po1030_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
140int po1030_set_gain(struct gspca_dev *gspca_dev, __s32 val);
141int po1030_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val);
142int po1030_set_red_balance(struct gspca_dev *gspca_dev, __s32 val);
143int po1030_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val);
144int po1030_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val);
145
146static struct m5602_sensor po1030 = {
147 .name = "PO1030",
148
149 .i2c_slave_id = 0xdc,
150
151 .probe = po1030_probe,
152 .init = po1030_init,
153 .power_down = po1030_power_down,
154
155 .nctrls = 4,
156 .ctrls = {
157 {
158 {
159 .id = V4L2_CID_GAIN,
160 .type = V4L2_CTRL_TYPE_INTEGER,
161 .name = "gain",
162 .minimum = 0x00,
163 .maximum = 0xff,
164 .step = 0x1,
165 .default_value = PO1030_GLOBAL_GAIN_DEFAULT,
166 .flags = V4L2_CTRL_FLAG_SLIDER
167 },
168 .set = po1030_set_gain,
169 .get = po1030_get_gain
170 }, {
171 {
172 .id = V4L2_CID_EXPOSURE,
173 .type = V4L2_CTRL_TYPE_INTEGER,
174 .name = "exposure",
175 .minimum = 0x00,
176 .maximum = 0xffff,
177 .step = 0x1,
178 .default_value = PO1030_EXPOSURE_DEFAULT,
179 .flags = V4L2_CTRL_FLAG_SLIDER
180 },
181 .set = po1030_set_exposure,
182 .get = po1030_get_exposure
183 }, {
184 {
185 .id = V4L2_CID_RED_BALANCE,
186 .type = V4L2_CTRL_TYPE_INTEGER,
187 .name = "red balance",
188 .minimum = 0x00,
189 .maximum = 0xff,
190 .step = 0x1,
191 .default_value = PO1030_RED_GAIN_DEFAULT,
192 .flags = V4L2_CTRL_FLAG_SLIDER
193 },
194 .set = po1030_set_red_balance,
195 .get = po1030_get_red_balance
196 }, {
197 {
198 .id = V4L2_CID_BLUE_BALANCE,
199 .type = V4L2_CTRL_TYPE_INTEGER,
200 .name = "blue balance",
201 .minimum = 0x00,
202 .maximum = 0xff,
203 .step = 0x1,
204 .default_value = PO1030_BLUE_GAIN_DEFAULT,
205 .flags = V4L2_CTRL_FLAG_SLIDER
206 },
207 .set = po1030_set_blue_balance,
208 .get = po1030_get_blue_balance
209 }
210 },
211 .nmodes = 1,
212 .modes = {
213 {
214 M5602_DEFAULT_FRAME_WIDTH,
215 M5602_DEFAULT_FRAME_HEIGHT,
216 V4L2_PIX_FMT_SBGGR8,
217 V4L2_FIELD_NONE,
218 .sizeimage =
219 M5602_DEFAULT_FRAME_WIDTH * M5602_DEFAULT_FRAME_HEIGHT,
220 .bytesperline = M5602_DEFAULT_FRAME_WIDTH,
221 .colorspace = V4L2_COLORSPACE_SRGB,
222 .priv = 1
223 }
224 }
225};
226
227static const unsigned char preinit_po1030[][3] =
228{
229 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02},
230 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0},
231 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
232 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
233 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
234 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d},
235 {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00},
236 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
237 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
238
239 {SENSOR, PO1030_REG_AUTOCTRL2, 0x24},
240
241 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
242 {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
243 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
244 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
245 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
246 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
247 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
248 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06},
249 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
250 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
251 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
252 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81},
253 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82},
254 {BRIDGE, M5602_XB_SIG_INI, 0x01},
255 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
256 {BRIDGE, M5602_XB_VSYNC_PARA, 0x02},
257 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
258 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
259 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01},
260 {BRIDGE, M5602_XB_VSYNC_PARA, 0xec},
261 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
262 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
263 {BRIDGE, M5602_XB_SIG_INI, 0x00},
264 {BRIDGE, M5602_XB_SIG_INI, 0x02},
265 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
266 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
267 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02},
268 {BRIDGE, M5602_XB_HSYNC_PARA, 0x87},
269 {BRIDGE, M5602_XB_SIG_INI, 0x00},
270
271 {SENSOR, PO1030_REG_AUTOCTRL2, 0x24},
272
273 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
274 {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
275 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
276 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
277 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
278 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
279 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
280 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
281 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
282 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
283 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
284 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
285 {BRIDGE, M5602_XB_GPIO_DAT, 0x00}
286};
287
288static const unsigned char init_po1030[][4] =
289{
290 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02},
291 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0},
292 /*sequence 1*/
293 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
294 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
295 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
296 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d},
297
298 {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00},
299 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
300 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
301 /*end of sequence 1*/
302
303 /*sequence 2 (same as stop sequence)*/
304 {SENSOR, PO1030_REG_AUTOCTRL2, 0x24},
305 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
306 {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
307 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
308 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
309 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
310
311 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
312 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
313 /*end of sequence 2*/
314
315 /*sequence 5*/
316 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06},
317 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
318 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
319 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
320 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81},
321 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82},
322 {BRIDGE, M5602_XB_SIG_INI, 0x01},
323 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
324 {BRIDGE, M5602_XB_VSYNC_PARA, 0x02},
325 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
326 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
327 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01},
328 {BRIDGE, M5602_XB_VSYNC_PARA, 0xec},
329 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
330 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
331 {BRIDGE, M5602_XB_SIG_INI, 0x00},
332 {BRIDGE, M5602_XB_SIG_INI, 0x02},
333 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
334 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
335 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02},
336 {BRIDGE, M5602_XB_HSYNC_PARA, 0x87},
337 {BRIDGE, M5602_XB_SIG_INI, 0x00},
338 /*end of sequence 5*/
339
340 /*sequence 2 stop */
341 {SENSOR, PO1030_REG_AUTOCTRL2, 0x24},
342
343 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
344 {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
345 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
346 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
347 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
348 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
349 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
350 /*end of sequence 2 stop */
351
352/* ---------------------------------
353 * end of init - begin of start
354 * --------------------------------- */
355
356 /*sequence 3*/
357 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
358 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
359 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
360 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
361 /*end of sequence 3*/
362 /*sequence 4*/
363 {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
364 {BRIDGE, M5602_XB_GPIO_DAT, 0x00},
365 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
366 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00},
367
368 {SENSOR, PO1030_REG_AUTOCTRL2, 0x04},
369
370 /* Set the width to 751 */
371 {SENSOR, PO1030_REG_FRAMEWIDTH_H, 0x02},
372 {SENSOR, PO1030_REG_FRAMEWIDTH_L, 0xef},
373
374 /* Set the height to 540 */
375 {SENSOR, PO1030_REG_FRAMEHEIGHT_H, 0x02},
376 {SENSOR, PO1030_REG_FRAMEHEIGHT_L, 0x1c},
377
378 /* Set the x window to 1 */
379 {SENSOR, PO1030_REG_WINDOWX_H, 0x00},
380 {SENSOR, PO1030_REG_WINDOWX_L, 0x01},
381
382 /* Set the y window to 1 */
383 {SENSOR, PO1030_REG_WINDOWY_H, 0x00},
384 {SENSOR, PO1030_REG_WINDOWX_L, 0x01},
385
386 {SENSOR, PO1030_REG_WINDOWWIDTH_H, 0x02},
387 {SENSOR, PO1030_REG_WINDOWWIDTH_L, 0x87},
388 {SENSOR, PO1030_REG_WINDOWHEIGHT_H, 0x01},
389 {SENSOR, PO1030_REG_WINDOWHEIGHT_L, 0xe3},
390
391 {SENSOR, PO1030_REG_OUTFORMCTRL2, 0x04},
392 {SENSOR, PO1030_REG_OUTFORMCTRL2, 0x04},
393 {SENSOR, PO1030_REG_AUTOCTRL1, 0x08},
394 {SENSOR, PO1030_REG_CONTROL2, 0x03},
395 {SENSOR, 0x21, 0x90},
396 {SENSOR, PO1030_REG_YTARGET, 0x60},
397 {SENSOR, 0x59, 0x13},
398 {SENSOR, PO1030_REG_OUTFORMCTRL1, 0x40},
399 {SENSOR, 0x5f, 0x00},
400 {SENSOR, 0x60, 0x80},
401 {SENSOR, 0x78, 0x14},
402 {SENSOR, 0x6f, 0x01},
403 {SENSOR, PO1030_REG_CONTROL1, 0x18},
404 {SENSOR, PO1030_REG_GLOBALGAINMAX, 0x14},
405 {SENSOR, 0x63, 0x38},
406 {SENSOR, 0x64, 0x38},
407 {SENSOR, PO1030_REG_CONTROL1, 0x58},
408 {SENSOR, PO1030_REG_RED_GAIN, 0x30},
409 {SENSOR, PO1030_REG_GREEN_1_GAIN, 0x30},
410 {SENSOR, PO1030_REG_BLUE_GAIN, 0x30},
411 {SENSOR, PO1030_REG_GREEN_2_GAIN, 0x30},
412 {SENSOR, PO1030_REG_GC0, 0x10},
413 {SENSOR, PO1030_REG_GC1, 0x20},
414 {SENSOR, PO1030_REG_GC2, 0x40},
415 {SENSOR, PO1030_REG_GC3, 0x60},
416 {SENSOR, PO1030_REG_GC4, 0x80},
417 {SENSOR, PO1030_REG_GC5, 0xa0},
418 {SENSOR, PO1030_REG_GC6, 0xc0},
419 {SENSOR, PO1030_REG_GC7, 0xff},
420 /*end of sequence 4*/
421 /*sequence 5*/
422 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06},
423 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
424 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
425 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
426 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81},
427 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82},
428 {BRIDGE, M5602_XB_SIG_INI, 0x01},
429 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
430 {BRIDGE, M5602_XB_VSYNC_PARA, 0x02},
431 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
432 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
433 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01},
434 {BRIDGE, M5602_XB_VSYNC_PARA, 0xec},
435 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
436 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
437 {BRIDGE, M5602_XB_SIG_INI, 0x00},
438 {BRIDGE, M5602_XB_SIG_INI, 0x00},
439 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
440 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
441 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02},
442 {BRIDGE, M5602_XB_HSYNC_PARA, 0x7e},
443 {BRIDGE, M5602_XB_SIG_INI, 0x00},
444 /*end of sequence 5*/
445
446 /*sequence 6*/
447 /* Changing 40 in f0 the image becomes green in bayer mode and red in
448 * rgb mode */
449 {SENSOR, PO1030_REG_RED_GAIN, PO1030_RED_GAIN_DEFAULT},
450 /* in changing 40 in f0 the image becomes green in bayer mode and red in
451 * rgb mode */
452 {SENSOR, PO1030_REG_BLUE_GAIN, PO1030_BLUE_GAIN_DEFAULT},
453
454 /* with a very low lighted environment increase the exposure but
455 * decrease the FPS (Frame Per Second) */
456 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
457 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
458
459 /* Controls high exposure more than SENSOR_LOW_EXPOSURE, use only in
460 * low lighted environment (f0 is more than ff ?)*/
461 {SENSOR, PO1030_REG_INTEGLINES_H, ((PO1030_EXPOSURE_DEFAULT >> 2)
462 & 0xff)},
463
464 /* Controls middle exposure, use only in high lighted environment */
465 {SENSOR, PO1030_REG_INTEGLINES_M, PO1030_EXPOSURE_DEFAULT & 0xff},
466
467 /* Controls clarity (not sure) */
468 {SENSOR, PO1030_REG_INTEGLINES_L, 0x00},
469 /* Controls gain (the image is more lighted) */
470 {SENSOR, PO1030_REG_GLOBALGAIN, PO1030_GLOBAL_GAIN_DEFAULT},
471
472 /* Sets the width */
473 {SENSOR, PO1030_REG_FRAMEWIDTH_H, 0x02},
474 {SENSOR, PO1030_REG_FRAMEWIDTH_L, 0xef}
475 /*end of sequence 6*/
476};
477
478#endif
diff --git a/drivers/media/video/gspca/m5602/m5602_s5k4aa.c b/drivers/media/video/gspca/m5602/m5602_s5k4aa.c
new file mode 100644
index 000000000000..68202565325d
--- /dev/null
+++ b/drivers/media/video/gspca/m5602/m5602_s5k4aa.c
@@ -0,0 +1,463 @@
1/*
2 * Driver for the s5k4aa sensor
3 *
4 * Copyright (C) 2008 Erik Andren
5 * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
6 * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
7 *
8 * Portions of code to USB interface and ALi driver software,
9 * Copyright (c) 2006 Willem Duinker
10 * v4l2 interface modeled after the V4L2 driver
11 * for SN9C10x PC Camera Controllers
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation, version 2.
16 *
17 */
18
19#include "m5602_s5k4aa.h"
20
21int s5k4aa_probe(struct sd *sd)
22{
23 u8 prod_id[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
24 const u8 expected_prod_id[6] = {0x00, 0x10, 0x00, 0x4b, 0x33, 0x75};
25 int i, err = 0;
26
27 if (force_sensor) {
28 if (force_sensor == S5K4AA_SENSOR) {
29 info("Forcing a %s sensor", s5k4aa.name);
30 goto sensor_found;
31 }
32 /* If we want to force another sensor, don't try to probe this
33 * one */
34 return -ENODEV;
35 }
36
37 info("Probing for a s5k4aa sensor");
38
39 /* Preinit the sensor */
40 for (i = 0; i < ARRAY_SIZE(preinit_s5k4aa) && !err; i++) {
41 u8 data[2] = {0x00, 0x00};
42
43 switch (preinit_s5k4aa[i][0]) {
44 case BRIDGE:
45 err = m5602_write_bridge(sd,
46 preinit_s5k4aa[i][1],
47 preinit_s5k4aa[i][2]);
48 break;
49
50 case SENSOR:
51 data[0] = preinit_s5k4aa[i][2];
52 err = s5k4aa_write_sensor(sd,
53 preinit_s5k4aa[i][1],
54 data, 1);
55 break;
56
57 case SENSOR_LONG:
58 data[0] = preinit_s5k4aa[i][2];
59 data[1] = preinit_s5k4aa[i][3];
60 err = s5k4aa_write_sensor(sd,
61 preinit_s5k4aa[i][1],
62 data, 2);
63 break;
64 default:
65 info("Invalid stream command, exiting init");
66 return -EINVAL;
67 }
68 }
69
70 /* Test some registers, but we don't know their exact meaning yet */
71 if (s5k4aa_read_sensor(sd, 0x00, prod_id, sizeof(prod_id)))
72 return -ENODEV;
73
74 if (memcmp(prod_id, expected_prod_id, sizeof(prod_id)))
75 return -ENODEV;
76 else
77 info("Detected a s5k4aa sensor");
78sensor_found:
79 sd->gspca_dev.cam.cam_mode = s5k4aa.modes;
80 sd->gspca_dev.cam.nmodes = s5k4aa.nmodes;
81 sd->desc->ctrls = s5k4aa.ctrls;
82 sd->desc->nctrls = s5k4aa.nctrls;
83
84 return 0;
85}
86
87int s5k4aa_read_sensor(struct sd *sd, const u8 address,
88 u8 *i2c_data, const u8 len)
89{
90 int err, i;
91
92 do {
93 err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data);
94 } while ((*i2c_data & I2C_BUSY) && !err);
95 if (err < 0)
96 goto out;
97
98 err = m5602_write_bridge(sd, M5602_XB_I2C_DEV_ADDR,
99 sd->sensor->i2c_slave_id);
100 if (err < 0)
101 goto out;
102
103 err = m5602_write_bridge(sd, M5602_XB_I2C_REG_ADDR, address);
104 if (err < 0)
105 goto out;
106
107 err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x18 + len);
108 if (err < 0)
109 goto out;
110
111 do {
112 err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data);
113 } while ((*i2c_data & I2C_BUSY) && !err);
114 if (err < 0)
115 goto out;
116
117 for (i = 0; (i < len) & !err; i++) {
118 err = m5602_read_bridge(sd, M5602_XB_I2C_DATA, &(i2c_data[i]));
119
120 PDEBUG(DBG_TRACE, "Reading sensor register "
121 "0x%x containing 0x%x ", address, *i2c_data);
122 }
123out:
124 return (err < 0) ? err : 0;
125}
126
127int s5k4aa_write_sensor(struct sd *sd, const u8 address,
128 u8 *i2c_data, const u8 len)
129{
130 int err, i;
131 u8 *p;
132 struct usb_device *udev = sd->gspca_dev.dev;
133 __u8 *buf = sd->gspca_dev.usb_buf;
134
135 /* No sensor with a data width larger than 16 bits has yet been seen */
136 if (len > 2 || !len)
137 return -EINVAL;
138
139 memcpy(buf, sensor_urb_skeleton,
140 sizeof(sensor_urb_skeleton));
141
142 buf[11] = sd->sensor->i2c_slave_id;
143 buf[15] = address;
144
145 /* Special case larger sensor writes */
146 p = buf + 16;
147
148 /* Copy a four byte write sequence for each byte to be written to */
149 for (i = 0; i < len; i++) {
150 memcpy(p, sensor_urb_skeleton + 16, 4);
151 p[3] = i2c_data[i];
152 p += 4;
153 PDEBUG(DBG_TRACE, "Writing sensor register 0x%x with 0x%x",
154 address, i2c_data[i]);
155 }
156
157 /* Copy the tailer */
158 memcpy(p, sensor_urb_skeleton + 20, 4);
159
160 /* Set the total length */
161 p[3] = 0x10 + len;
162
163 err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
164 0x04, 0x40, 0x19,
165 0x0000, buf,
166 20 + len * 4, M5602_URB_MSG_TIMEOUT);
167
168 return (err < 0) ? err : 0;
169}
170
171int s5k4aa_init(struct sd *sd)
172{
173 int i, err = 0;
174
175 for (i = 0; i < ARRAY_SIZE(init_s5k4aa) && !err; i++) {
176 u8 data[2] = {0x00, 0x00};
177
178 switch (init_s5k4aa[i][0]) {
179 case BRIDGE:
180 err = m5602_write_bridge(sd,
181 init_s5k4aa[i][1],
182 init_s5k4aa[i][2]);
183 break;
184
185 case SENSOR:
186 data[0] = init_s5k4aa[i][2];
187 err = s5k4aa_write_sensor(sd,
188 init_s5k4aa[i][1], data, 1);
189 break;
190
191 case SENSOR_LONG:
192 data[0] = init_s5k4aa[i][2];
193 data[1] = init_s5k4aa[i][3];
194 err = s5k4aa_write_sensor(sd,
195 init_s5k4aa[i][1], data, 2);
196 break;
197 default:
198 info("Invalid stream command, exiting init");
199 return -EINVAL;
200 }
201 }
202
203 if (dump_sensor)
204 s5k4aa_dump_registers(sd);
205
206 if (!err && dmi_check_system(s5k4aa_vflip_dmi_table)) {
207 u8 data = 0x02;
208 info("vertical flip quirk active");
209 s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
210 s5k4aa_read_sensor(sd, S5K4AA_READ_MODE, &data, 1);
211 data |= S5K4AA_RM_V_FLIP;
212 data &= ~S5K4AA_RM_H_FLIP;
213 s5k4aa_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
214
215 /* Decrement COLSTART to preserve color order (BGGR) */
216 s5k4aa_read_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
217 data--;
218 s5k4aa_write_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
219
220 /* Increment ROWSTART to preserve color order (BGGR) */
221 s5k4aa_read_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
222 data++;
223 s5k4aa_write_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
224 }
225
226 return (err < 0) ? err : 0;
227}
228
229int s5k4aa_power_down(struct sd *sd)
230{
231 return 0;
232}
233
234int s5k4aa_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
235{
236 struct sd *sd = (struct sd *) gspca_dev;
237 u8 data = S5K4AA_PAGE_MAP_2;
238 int err;
239
240 err = s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
241 if (err < 0)
242 goto out;
243
244 err = s5k4aa_read_sensor(sd, S5K4AA_EXPOSURE_HI, &data, 1);
245 if (err < 0)
246 goto out;
247
248 *val = data << 8;
249 err = s5k4aa_read_sensor(sd, S5K4AA_EXPOSURE_LO, &data, 1);
250 *val |= data;
251 PDEBUG(DBG_V4L2_CID, "Read exposure %d", *val);
252out:
253 return (err < 0) ? err : 0;
254}
255
256int s5k4aa_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
257{
258 struct sd *sd = (struct sd *) gspca_dev;
259 u8 data = S5K4AA_PAGE_MAP_2;
260 int err;
261
262 PDEBUG(DBG_V4L2_CID, "Set exposure to %d", val);
263 err = s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
264 if (err < 0)
265 goto out;
266 data = (val >> 8) & 0xff;
267 err = s5k4aa_write_sensor(sd, S5K4AA_EXPOSURE_HI, &data, 1);
268 if (err < 0)
269 goto out;
270 data = val & 0xff;
271 err = s5k4aa_write_sensor(sd, S5K4AA_EXPOSURE_LO, &data, 1);
272out:
273 return (err < 0) ? err : 0;
274}
275
276int s5k4aa_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
277{
278 struct sd *sd = (struct sd *) gspca_dev;
279 u8 data = S5K4AA_PAGE_MAP_2;
280 int err;
281
282 err = s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
283 if (err < 0)
284 goto out;
285
286 err = s5k4aa_read_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
287 *val = (data & S5K4AA_RM_V_FLIP) >> 7;
288 PDEBUG(DBG_V4L2_CID, "Read vertical flip %d", *val);
289
290out:
291 return (err < 0) ? err : 0;
292}
293
294int s5k4aa_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
295{
296 struct sd *sd = (struct sd *) gspca_dev;
297 u8 data = S5K4AA_PAGE_MAP_2;
298 int err;
299
300 PDEBUG(DBG_V4L2_CID, "Set vertical flip to %d", val);
301 err = s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
302 if (err < 0)
303 goto out;
304 err = s5k4aa_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
305 if (err < 0)
306 goto out;
307 data = ((data & ~S5K4AA_RM_V_FLIP)
308 | ((val & 0x01) << 7));
309 err = s5k4aa_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
310 if (err < 0)
311 goto out;
312
313 if (val) {
314 err = s5k4aa_read_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
315 if (err < 0)
316 goto out;
317
318 data++;
319 err = s5k4aa_write_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
320 } else {
321 err = s5k4aa_read_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
322 if (err < 0)
323 goto out;
324
325 data--;
326 err = s5k4aa_write_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
327 }
328out:
329 return (err < 0) ? err : 0;
330}
331
332int s5k4aa_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
333{
334 struct sd *sd = (struct sd *) gspca_dev;
335 u8 data = S5K4AA_PAGE_MAP_2;
336 int err;
337
338 err = s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
339 if (err < 0)
340 goto out;
341
342 err = s5k4aa_read_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
343 *val = (data & S5K4AA_RM_H_FLIP) >> 6;
344 PDEBUG(DBG_V4L2_CID, "Read horizontal flip %d", *val);
345out:
346 return (err < 0) ? err : 0;
347}
348
349int s5k4aa_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
350{
351 struct sd *sd = (struct sd *) gspca_dev;
352 u8 data = S5K4AA_PAGE_MAP_2;
353 int err;
354
355 PDEBUG(DBG_V4L2_CID, "Set horizontal flip to %d",
356 val);
357 err = s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
358 if (err < 0)
359 goto out;
360 err = s5k4aa_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
361 if (err < 0)
362 goto out;
363
364 data = ((data & ~S5K4AA_RM_H_FLIP) | ((val & 0x01) << 6));
365 err = s5k4aa_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
366 if (err < 0)
367 goto out;
368
369 if (val) {
370 err = s5k4aa_read_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
371 if (err < 0)
372 goto out;
373 data++;
374 err = s5k4aa_write_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
375 if (err < 0)
376 goto out;
377 } else {
378 err = s5k4aa_read_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
379 if (err < 0)
380 goto out;
381 data--;
382 err = s5k4aa_write_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
383 }
384out:
385 return (err < 0) ? err : 0;
386}
387
388int s5k4aa_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
389{
390 struct sd *sd = (struct sd *) gspca_dev;
391 u8 data = S5K4AA_PAGE_MAP_2;
392 int err;
393
394 err = s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
395 if (err < 0)
396 goto out;
397
398 err = s5k4aa_read_sensor(sd, S5K4AA_GAIN_2, &data, 1);
399 *val = data;
400 PDEBUG(DBG_V4L2_CID, "Read gain %d", *val);
401
402out:
403 return (err < 0) ? err : 0;
404}
405
406int s5k4aa_set_gain(struct gspca_dev *gspca_dev, __s32 val)
407{
408 struct sd *sd = (struct sd *) gspca_dev;
409 u8 data = S5K4AA_PAGE_MAP_2;
410 int err;
411
412 PDEBUG(DBG_V4L2_CID, "Set gain to %d", val);
413 err = s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
414 if (err < 0)
415 goto out;
416
417 data = val & 0xff;
418 err = s5k4aa_write_sensor(sd, S5K4AA_GAIN_2, &data, 1);
419
420out:
421 return (err < 0) ? err : 0;
422}
423
424void s5k4aa_dump_registers(struct sd *sd)
425{
426 int address;
427 u8 page, old_page;
428 s5k4aa_read_sensor(sd, S5K4AA_PAGE_MAP, &old_page, 1);
429 for (page = 0; page < 16; page++) {
430 s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &page, 1);
431 info("Dumping the s5k4aa register state for page 0x%x", page);
432 for (address = 0; address <= 0xff; address++) {
433 u8 value = 0;
434 s5k4aa_read_sensor(sd, address, &value, 1);
435 info("register 0x%x contains 0x%x",
436 address, value);
437 }
438 }
439 info("s5k4aa register state dump complete");
440
441 for (page = 0; page < 16; page++) {
442 s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &page, 1);
443 info("Probing for which registers that are "
444 "read/write for page 0x%x", page);
445 for (address = 0; address <= 0xff; address++) {
446 u8 old_value, ctrl_value, test_value = 0xff;
447
448 s5k4aa_read_sensor(sd, address, &old_value, 1);
449 s5k4aa_write_sensor(sd, address, &test_value, 1);
450 s5k4aa_read_sensor(sd, address, &ctrl_value, 1);
451
452 if (ctrl_value == test_value)
453 info("register 0x%x is writeable", address);
454 else
455 info("register 0x%x is read only", address);
456
457 /* Restore original value */
458 s5k4aa_write_sensor(sd, address, &old_value, 1);
459 }
460 }
461 info("Read/write register probing complete");
462 s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &old_page, 1);
463}
diff --git a/drivers/media/video/gspca/m5602/m5602_s5k4aa.h b/drivers/media/video/gspca/m5602/m5602_s5k4aa.h
new file mode 100644
index 000000000000..bb7f7e3e90af
--- /dev/null
+++ b/drivers/media/video/gspca/m5602/m5602_s5k4aa.h
@@ -0,0 +1,370 @@
1/*
2 * Driver for the s5k4aa sensor
3 *
4 * Copyright (C) 2008 Erik Andren
5 * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
6 * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
7 *
8 * Portions of code to USB interface and ALi driver software,
9 * Copyright (c) 2006 Willem Duinker
10 * v4l2 interface modeled after the V4L2 driver
11 * for SN9C10x PC Camera Controllers
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation, version 2.
16 *
17 */
18
19#ifndef M5602_S5K4AA_H_
20#define M5602_S5K4AA_H_
21
22#include <linux/dmi.h>
23
24#include "m5602_sensor.h"
25
26/*****************************************************************************/
27
28#define S5K4AA_PAGE_MAP 0xec
29
30#define S5K4AA_PAGE_MAP_0 0x00
31#define S5K4AA_PAGE_MAP_1 0x01
32#define S5K4AA_PAGE_MAP_2 0x02
33
34/* Sensor register definitions for page 0x02 */
35#define S5K4AA_READ_MODE 0x03
36#define S5K4AA_ROWSTART_HI 0x04
37#define S5K4AA_ROWSTART_LO 0x05
38#define S5K4AA_COLSTART_HI 0x06
39#define S5K4AA_COLSTART_LO 0x07
40#define S5K4AA_WINDOW_HEIGHT_HI 0x08
41#define S5K4AA_WINDOW_HEIGHT_LO 0x09
42#define S5K4AA_WINDOW_WIDTH_HI 0x0a
43#define S5K4AA_WINDOW_WIDTH_LO 0x0b
44#define S5K4AA_GLOBAL_GAIN__ 0x0f /* Only a guess ATM !!! */
45#define S5K4AA_H_BLANK_HI__ 0x1d /* Only a guess ATM !!! sync lost
46 if too low, reduces frame rate
47 if too high */
48#define S5K4AA_H_BLANK_LO__ 0x1e /* Only a guess ATM !!! */
49#define S5K4AA_EXPOSURE_HI 0x17
50#define S5K4AA_EXPOSURE_LO 0x18
51#define S5K4AA_GAIN_1 0x1f /* (digital?) gain : 5 bits */
52#define S5K4AA_GAIN_2 0x20 /* (analogue?) gain : 7 bits */
53
54#define S5K4AA_RM_ROW_SKIP_4X 0x08
55#define S5K4AA_RM_ROW_SKIP_2X 0x04
56#define S5K4AA_RM_COL_SKIP_4X 0x02
57#define S5K4AA_RM_COL_SKIP_2X 0x01
58#define S5K4AA_RM_H_FLIP 0x40
59#define S5K4AA_RM_V_FLIP 0x80
60
61/*****************************************************************************/
62
63/* Kernel module parameters */
64extern int force_sensor;
65extern int dump_sensor;
66extern unsigned int m5602_debug;
67
68int s5k4aa_probe(struct sd *sd);
69int s5k4aa_init(struct sd *sd);
70int s5k4aa_power_down(struct sd *sd);
71
72void s5k4aa_dump_registers(struct sd *sd);
73
74int s5k4aa_read_sensor(struct sd *sd, const u8 address,
75 u8 *i2c_data, const u8 len);
76int s5k4aa_write_sensor(struct sd *sd, const u8 address,
77 u8 *i2c_data, const u8 len);
78
79int s5k4aa_get_exposure(struct gspca_dev *gspca_dev, __s32 *val);
80int s5k4aa_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
81int s5k4aa_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
82int s5k4aa_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
83int s5k4aa_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
84int s5k4aa_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
85int s5k4aa_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
86int s5k4aa_set_gain(struct gspca_dev *gspca_dev, __s32 val);
87
88static struct m5602_sensor s5k4aa = {
89 .name = "S5K4AA",
90 .probe = s5k4aa_probe,
91 .init = s5k4aa_init,
92 .power_down = s5k4aa_power_down,
93 .read_sensor = s5k4aa_read_sensor,
94 .write_sensor = s5k4aa_write_sensor,
95 .i2c_slave_id = 0x5a,
96 .nctrls = 4,
97 .ctrls = {
98 {
99 {
100 .id = V4L2_CID_VFLIP,
101 .type = V4L2_CTRL_TYPE_BOOLEAN,
102 .name = "vertical flip",
103 .minimum = 0,
104 .maximum = 1,
105 .step = 1,
106 .default_value = 0
107 },
108 .set = s5k4aa_set_vflip,
109 .get = s5k4aa_get_vflip
110
111 }, {
112 {
113 .id = V4L2_CID_HFLIP,
114 .type = V4L2_CTRL_TYPE_BOOLEAN,
115 .name = "horizontal flip",
116 .minimum = 0,
117 .maximum = 1,
118 .step = 1,
119 .default_value = 0
120 },
121 .set = s5k4aa_set_hflip,
122 .get = s5k4aa_get_hflip
123
124 }, {
125 {
126 .id = V4L2_CID_GAIN,
127 .type = V4L2_CTRL_TYPE_INTEGER,
128 .name = "Gain",
129 .minimum = 0,
130 .maximum = 127,
131 .step = 1,
132 .default_value = 0xa0,
133 .flags = V4L2_CTRL_FLAG_SLIDER
134 },
135 .set = s5k4aa_set_gain,
136 .get = s5k4aa_get_gain
137 }, {
138 {
139 .id = V4L2_CID_EXPOSURE,
140 .type = V4L2_CTRL_TYPE_INTEGER,
141 .name = "Exposure",
142 .minimum = 13,
143 .maximum = 0xfff,
144 .step = 1,
145 .default_value = 0x100,
146 .flags = V4L2_CTRL_FLAG_SLIDER
147 },
148 .set = s5k4aa_set_exposure,
149 .get = s5k4aa_get_exposure
150 }
151 },
152
153 .nmodes = 1,
154 .modes = {
155 {
156 M5602_DEFAULT_FRAME_WIDTH,
157 M5602_DEFAULT_FRAME_HEIGHT,
158 V4L2_PIX_FMT_SBGGR8,
159 V4L2_FIELD_NONE,
160 .sizeimage =
161 M5602_DEFAULT_FRAME_WIDTH * M5602_DEFAULT_FRAME_HEIGHT,
162 .bytesperline = M5602_DEFAULT_FRAME_WIDTH,
163 .colorspace = V4L2_COLORSPACE_SRGB,
164 .priv = 1
165 }
166 }
167};
168
169static const unsigned char preinit_s5k4aa[][4] =
170{
171 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
172 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
173 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
174 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
175 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
176 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
177 {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
178
179 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
180 {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
181 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
182 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
183 {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
184 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
185 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
186 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
187 {BRIDGE, M5602_XB_GPIO_DAT, 0x00, 0x00},
188 {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
189 {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
190 {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
191 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
192 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
193 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
194 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
195
196 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
197 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
198 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
199 {BRIDGE, M5602_XB_GPIO_DAT, 0x14, 0x00},
200 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
201 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
202 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
203 {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
204 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
205 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
206 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
207 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
208 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
209
210 {SENSOR, S5K4AA_PAGE_MAP, 0x00, 0x00}
211};
212
213static const unsigned char init_s5k4aa[][4] =
214{
215 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
216 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
217 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
218 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
219 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
220 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
221 {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
222
223 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
224 {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
225 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
226 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
227 {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
228 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
229 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
230 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
231 {BRIDGE, M5602_XB_GPIO_DAT, 0x00, 0x00},
232 {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
233 {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
234 {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
235 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
236 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
237 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
238 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
239
240 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
241 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
242 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
243 {BRIDGE, M5602_XB_GPIO_DAT, 0x14, 0x00},
244 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
245 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
246 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
247 {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
248 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
249 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
250 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
251 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
252 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
253
254 {SENSOR, S5K4AA_PAGE_MAP, 0x07, 0x00},
255 {SENSOR, 0x36, 0x01, 0x00},
256 {SENSOR, S5K4AA_PAGE_MAP, 0x00, 0x00},
257 {SENSOR, 0x7b, 0xff, 0x00},
258 {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
259 {SENSOR, 0x0c, 0x05, 0x00},
260 {SENSOR, 0x02, 0x0e, 0x00},
261 {SENSOR, S5K4AA_GAIN_1, 0x0f, 0x00},
262 {SENSOR, S5K4AA_GAIN_2, 0x00, 0x00},
263 {SENSOR, S5K4AA_GLOBAL_GAIN__, 0x01, 0x00},
264 {SENSOR, 0x11, 0x00, 0x00},
265 {SENSOR, 0x12, 0x00, 0x00},
266 {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
267 {SENSOR, S5K4AA_READ_MODE, 0xa0, 0x00},
268 {SENSOR, 0x37, 0x00, 0x00},
269 {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
270 {SENSOR, S5K4AA_ROWSTART_LO, 0x2a, 0x00},
271 {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
272 {SENSOR, S5K4AA_COLSTART_LO, 0x0b, 0x00},
273 {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x03, 0x00},
274 {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0xc4, 0x00},
275 {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
276 {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x08, 0x00},
277 {SENSOR, S5K4AA_H_BLANK_HI__, 0x00, 0x00},
278 {SENSOR, S5K4AA_H_BLANK_LO__, 0x48, 0x00},
279 {SENSOR, S5K4AA_EXPOSURE_HI, 0x00, 0x00},
280 {SENSOR, S5K4AA_EXPOSURE_LO, 0x43, 0x00},
281 {SENSOR, 0x11, 0x04, 0x00},
282 {SENSOR, 0x12, 0xc3, 0x00},
283 {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
284
285 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
286 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
287 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
288 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
289 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
290 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
291 {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
292 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
293 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
294 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
295 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
296 /* VSYNC_PARA, VSYNC_PARA : img height 480 = 0x01e0 */
297 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
298 {BRIDGE, M5602_XB_VSYNC_PARA, 0xe0, 0x00},
299 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
300 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
301 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
302 {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
303 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
304 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
305 /* HSYNC_PARA, HSYNC_PARA : img width 640 = 0x0280 */
306 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
307 {BRIDGE, M5602_XB_HSYNC_PARA, 0x80, 0x00},
308 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
309 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
310 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00}, /* 48 MHz */
311
312 {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
313 {SENSOR, S5K4AA_READ_MODE, S5K4AA_RM_H_FLIP | S5K4AA_RM_ROW_SKIP_2X
314 | S5K4AA_RM_COL_SKIP_2X, 0x00},
315 /* 0x37 : Fix image stability when light is too bright and improves
316 * image quality in 640x480, but worsens it in 1280x1024 */
317 {SENSOR, 0x37, 0x01, 0x00},
318 /* ROWSTART_HI, ROWSTART_LO : 10 + (1024-960)/2 = 42 = 0x002a */
319 {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
320 {SENSOR, S5K4AA_ROWSTART_LO, 0x2a, 0x00},
321 {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
322 {SENSOR, S5K4AA_COLSTART_LO, 0x0c, 0x00},
323 /* window_height_hi, window_height_lo : 960 = 0x03c0 */
324 {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x03, 0x00},
325 {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0xc0, 0x00},
326 /* window_width_hi, window_width_lo : 1280 = 0x0500 */
327 {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
328 {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x00, 0x00},
329 {SENSOR, S5K4AA_H_BLANK_HI__, 0x00, 0x00},
330 {SENSOR, S5K4AA_H_BLANK_LO__, 0xa8, 0x00}, /* helps to sync... */
331 {SENSOR, S5K4AA_EXPOSURE_HI, 0x01, 0x00},
332 {SENSOR, S5K4AA_EXPOSURE_LO, 0x00, 0x00},
333 {SENSOR, 0x11, 0x04, 0x00},
334 {SENSOR, 0x12, 0xc3, 0x00},
335 {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
336 {SENSOR, 0x02, 0x0e, 0x00},
337 {SENSOR_LONG, S5K4AA_GLOBAL_GAIN__, 0x0f, 0x00},
338 {SENSOR, S5K4AA_GAIN_1, 0x0b, 0x00},
339 {SENSOR, S5K4AA_GAIN_2, 0xa0, 0x00}
340};
341
342static
343 const
344 struct dmi_system_id s5k4aa_vflip_dmi_table[] = {
345 {
346 .ident = "Fujitsu-Siemens Amilo Xa 2528",
347 .matches = {
348 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
349 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Xa 2528")
350 }
351 },
352 {
353 .ident = "Fujitsu-Siemens Amilo Xi 2550",
354 .matches = {
355 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
356 DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Xi 2550")
357 }
358 },
359 {
360 .ident = "MSI GX700",
361 .matches = {
362 DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star International"),
363 DMI_MATCH(DMI_PRODUCT_NAME, "GX700"),
364 DMI_MATCH(DMI_BIOS_DATE, "07/26/2007")
365 }
366 },
367 { }
368};
369
370#endif
diff --git a/drivers/media/video/gspca/m5602/m5602_s5k83a.c b/drivers/media/video/gspca/m5602/m5602_s5k83a.c
new file mode 100644
index 000000000000..b4b33c2d0499
--- /dev/null
+++ b/drivers/media/video/gspca/m5602/m5602_s5k83a.c
@@ -0,0 +1,423 @@
1/*
2 * Driver for the s5k83a sensor
3 *
4 * Copyright (C) 2008 Erik Andren
5 * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
6 * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
7 *
8 * Portions of code to USB interface and ALi driver software,
9 * Copyright (c) 2006 Willem Duinker
10 * v4l2 interface modeled after the V4L2 driver
11 * for SN9C10x PC Camera Controllers
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation, version 2.
16 *
17 */
18
19#include "m5602_s5k83a.h"
20
21int s5k83a_probe(struct sd *sd)
22{
23 u8 prod_id = 0, ver_id = 0;
24 int i, err = 0;
25
26 if (force_sensor) {
27 if (force_sensor == S5K83A_SENSOR) {
28 info("Forcing a %s sensor", s5k83a.name);
29 goto sensor_found;
30 }
31 /* If we want to force another sensor, don't try to probe this
32 * one */
33 return -ENODEV;
34 }
35
36 info("Probing for a s5k83a sensor");
37
38 /* Preinit the sensor */
39 for (i = 0; i < ARRAY_SIZE(preinit_s5k83a) && !err; i++) {
40 u8 data[2] = {preinit_s5k83a[i][2], preinit_s5k83a[i][3]};
41 if (preinit_s5k83a[i][0] == SENSOR)
42 err = s5k83a_write_sensor(sd, preinit_s5k83a[i][1],
43 data, 2);
44 else
45 err = m5602_write_bridge(sd, preinit_s5k83a[i][1],
46 data[0]);
47 }
48
49 /* We don't know what register (if any) that contain the product id
50 * Just pick the first addresses that seem to produce the same results
51 * on multiple machines */
52 if (s5k83a_read_sensor(sd, 0x00, &prod_id, 1))
53 return -ENODEV;
54
55 if (s5k83a_read_sensor(sd, 0x01, &ver_id, 1))
56 return -ENODEV;
57
58 if ((prod_id == 0xff) || (ver_id == 0xff))
59 return -ENODEV;
60 else
61 info("Detected a s5k83a sensor");
62
63sensor_found:
64 sd->gspca_dev.cam.cam_mode = s5k83a.modes;
65 sd->gspca_dev.cam.nmodes = s5k83a.nmodes;
66 sd->desc->ctrls = s5k83a.ctrls;
67 sd->desc->nctrls = s5k83a.nctrls;
68 return 0;
69}
70
71int s5k83a_read_sensor(struct sd *sd, const u8 address,
72 u8 *i2c_data, const u8 len)
73{
74 int err, i;
75
76 do {
77 err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data);
78 } while ((*i2c_data & I2C_BUSY) && !err);
79 if (err < 0)
80 goto out;
81
82 err = m5602_write_bridge(sd, M5602_XB_I2C_DEV_ADDR,
83 sd->sensor->i2c_slave_id);
84 if (err < 0)
85 goto out;
86
87 err = m5602_write_bridge(sd, M5602_XB_I2C_REG_ADDR, address);
88 if (err < 0)
89 goto out;
90
91 err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x18 + len);
92 if (err < 0)
93 goto out;
94
95 do {
96 err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data);
97 } while ((*i2c_data & I2C_BUSY) && !err);
98
99 if (err < 0)
100 goto out;
101 for (i = 0; i < len && !len; i++) {
102 err = m5602_read_bridge(sd, M5602_XB_I2C_DATA, &(i2c_data[i]));
103
104 PDEBUG(DBG_TRACE, "Reading sensor register "
105 "0x%x containing 0x%x ", address, *i2c_data);
106 }
107
108out:
109 return (err < 0) ? err : 0;
110}
111
112int s5k83a_write_sensor(struct sd *sd, const u8 address,
113 u8 *i2c_data, const u8 len)
114{
115 int err, i;
116 u8 *p;
117 struct usb_device *udev = sd->gspca_dev.dev;
118 __u8 *buf = sd->gspca_dev.usb_buf;
119
120 /* No sensor with a data width larger than 16 bits has yet been seen */
121 if (len > 2 || !len)
122 return -EINVAL;
123
124 memcpy(buf, sensor_urb_skeleton,
125 sizeof(sensor_urb_skeleton));
126
127 buf[11] = sd->sensor->i2c_slave_id;
128 buf[15] = address;
129
130 /* Special case larger sensor writes */
131 p = buf + 16;
132
133 /* Copy a four byte write sequence for each byte to be written to */
134 for (i = 0; i < len; i++) {
135 memcpy(p, sensor_urb_skeleton + 16, 4);
136 p[3] = i2c_data[i];
137 p += 4;
138 PDEBUG(DBG_TRACE, "Writing sensor register 0x%x with 0x%x",
139 address, i2c_data[i]);
140 }
141
142 /* Copy the tailer */
143 memcpy(p, sensor_urb_skeleton + 20, 4);
144
145 /* Set the total length */
146 p[3] = 0x10 + len;
147
148 err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
149 0x04, 0x40, 0x19,
150 0x0000, buf,
151 20 + len * 4, M5602_URB_MSG_TIMEOUT);
152
153 return (err < 0) ? err : 0;
154}
155
156int s5k83a_init(struct sd *sd)
157{
158 int i, err = 0;
159
160 for (i = 0; i < ARRAY_SIZE(init_s5k83a) && !err; i++) {
161 u8 data[2] = {0x00, 0x00};
162
163 switch (init_s5k83a[i][0]) {
164 case BRIDGE:
165 err = m5602_write_bridge(sd,
166 init_s5k83a[i][1],
167 init_s5k83a[i][2]);
168 break;
169
170 case SENSOR:
171 data[0] = init_s5k83a[i][2];
172 err = s5k83a_write_sensor(sd,
173 init_s5k83a[i][1], data, 1);
174 break;
175
176 case SENSOR_LONG:
177 data[0] = init_s5k83a[i][2];
178 data[1] = init_s5k83a[i][3];
179 err = s5k83a_write_sensor(sd,
180 init_s5k83a[i][1], data, 2);
181 break;
182 default:
183 info("Invalid stream command, exiting init");
184 return -EINVAL;
185 }
186 }
187
188 if (dump_sensor)
189 s5k83a_dump_registers(sd);
190
191 return (err < 0) ? err : 0;
192}
193
194int s5k83a_power_down(struct sd *sd)
195{
196 return 0;
197}
198
199void s5k83a_dump_registers(struct sd *sd)
200{
201 int address;
202 u8 page, old_page;
203 s5k83a_read_sensor(sd, S5K83A_PAGE_MAP, &old_page, 1);
204
205 for (page = 0; page < 16; page++) {
206 s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, &page, 1);
207 info("Dumping the s5k83a register state for page 0x%x", page);
208 for (address = 0; address <= 0xff; address++) {
209 u8 val = 0;
210 s5k83a_read_sensor(sd, address, &val, 1);
211 info("register 0x%x contains 0x%x",
212 address, val);
213 }
214 }
215 info("s5k83a register state dump complete");
216
217 for (page = 0; page < 16; page++) {
218 s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, &page, 1);
219 info("Probing for which registers that are read/write "
220 "for page 0x%x", page);
221 for (address = 0; address <= 0xff; address++) {
222 u8 old_val, ctrl_val, test_val = 0xff;
223
224 s5k83a_read_sensor(sd, address, &old_val, 1);
225 s5k83a_write_sensor(sd, address, &test_val, 1);
226 s5k83a_read_sensor(sd, address, &ctrl_val, 1);
227
228 if (ctrl_val == test_val)
229 info("register 0x%x is writeable", address);
230 else
231 info("register 0x%x is read only", address);
232
233 /* Restore original val */
234 s5k83a_write_sensor(sd, address, &old_val, 1);
235 }
236 }
237 info("Read/write register probing complete");
238 s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, &old_page, 1);
239}
240
241int s5k83a_get_brightness(struct gspca_dev *gspca_dev, __s32 *val)
242{
243 int err;
244 u8 data[2];
245 struct sd *sd = (struct sd *) gspca_dev;
246
247 err = s5k83a_read_sensor(sd, S5K83A_BRIGHTNESS, data, 2);
248 data[1] = data[1] << 1;
249 *val = data[1];
250
251 return (err < 0) ? err : 0;
252}
253
254int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val)
255{
256 int err;
257 u8 data[2];
258 struct sd *sd = (struct sd *) gspca_dev;
259
260 data[0] = 0x00;
261 data[1] = 0x20;
262 err = s5k83a_write_sensor(sd, 0x14, data, 2);
263 if (err < 0)
264 return err;
265
266 data[0] = 0x01;
267 data[1] = 0x00;
268 err = s5k83a_write_sensor(sd, 0x0d, data, 2);
269 if (err < 0)
270 return err;
271
272 /* FIXME: This is not sane, we need to figure out the composition
273 of these registers */
274 data[0] = val >> 3; /* brightness, high 5 bits */
275 data[1] = val >> 1; /* brightness, high 7 bits */
276 err = s5k83a_write_sensor(sd, S5K83A_BRIGHTNESS, data, 2);
277
278 return (err < 0) ? err : 0;
279}
280
281int s5k83a_get_whiteness(struct gspca_dev *gspca_dev, __s32 *val)
282{
283 int err;
284 u8 data;
285 struct sd *sd = (struct sd *) gspca_dev;
286
287 err = s5k83a_read_sensor(sd, S5K83A_WHITENESS, &data, 1);
288
289 *val = data;
290 return (err < 0) ? err : 0;
291}
292
293int s5k83a_set_whiteness(struct gspca_dev *gspca_dev, __s32 val)
294{
295 int err;
296 u8 data[1];
297 struct sd *sd = (struct sd *) gspca_dev;
298
299 data[0] = val;
300 err = s5k83a_write_sensor(sd, S5K83A_WHITENESS, data, 1);
301
302 return (err < 0) ? err : 0;
303}
304
305int s5k83a_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
306{
307 int err;
308 u8 data[2];
309 struct sd *sd = (struct sd *) gspca_dev;
310
311 err = s5k83a_read_sensor(sd, S5K83A_GAIN, data, 2);
312
313 data[1] = data[1] & 0x3f;
314 if (data[1] > S5K83A_MAXIMUM_GAIN)
315 data[1] = S5K83A_MAXIMUM_GAIN;
316
317 *val = data[1];
318
319 return (err < 0) ? err : 0;
320}
321
322int s5k83a_set_gain(struct gspca_dev *gspca_dev, __s32 val)
323{
324 int err;
325 u8 data[2];
326 struct sd *sd = (struct sd *) gspca_dev;
327
328 data[0] = 0;
329 data[1] = val;
330 err = s5k83a_write_sensor(sd, S5K83A_GAIN, data, 2);
331
332 return (err < 0) ? err : 0;
333}
334
335int s5k83a_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
336{
337 int err;
338 u8 data[1];
339 struct sd *sd = (struct sd *) gspca_dev;
340
341 data[0] = 0x05;
342 err = s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, data, 1);
343 if (err < 0)
344 return err;
345
346 err = s5k83a_read_sensor(sd, S5K83A_FLIP, data, 1);
347 *val = (data[0] | 0x40) ? 1 : 0;
348
349 return (err < 0) ? err : 0;
350}
351
352int s5k83a_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
353{
354 int err;
355 u8 data[1];
356 struct sd *sd = (struct sd *) gspca_dev;
357
358 data[0] = 0x05;
359 err = s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, data, 1);
360 if (err < 0)
361 return err;
362
363 err = s5k83a_read_sensor(sd, S5K83A_FLIP, data, 1);
364 if (err < 0)
365 return err;
366
367 /* set or zero six bit, seven is hflip */
368 data[0] = (val) ? (data[0] & 0x80) | 0x40 | S5K83A_FLIP_MASK
369 : (data[0] & 0x80) | S5K83A_FLIP_MASK;
370 err = s5k83a_write_sensor(sd, S5K83A_FLIP, data, 1);
371 if (err < 0)
372 return err;
373
374 data[0] = (val) ? 0x0b : 0x0a;
375 err = s5k83a_write_sensor(sd, S5K83A_VFLIP_TUNE, data, 1);
376
377 return (err < 0) ? err : 0;
378}
379
380int s5k83a_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
381{
382 int err;
383 u8 data[1];
384 struct sd *sd = (struct sd *) gspca_dev;
385
386 data[0] = 0x05;
387 err = s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, data, 1);
388 if (err < 0)
389 return err;
390
391 err = s5k83a_read_sensor(sd, S5K83A_FLIP, data, 1);
392 *val = (data[0] | 0x80) ? 1 : 0;
393
394 return (err < 0) ? err : 0;
395}
396
397int s5k83a_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
398{
399 int err;
400 u8 data[1];
401 struct sd *sd = (struct sd *) gspca_dev;
402
403 data[0] = 0x05;
404 err = s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, data, 1);
405 if (err < 0)
406 return err;
407
408 err = s5k83a_read_sensor(sd, S5K83A_FLIP, data, 1);
409 if (err < 0)
410 return err;
411
412 /* set or zero seven bit, six is vflip */
413 data[0] = (val) ? (data[0] & 0x40) | 0x80 | S5K83A_FLIP_MASK
414 : (data[0] & 0x40) | S5K83A_FLIP_MASK;
415 err = s5k83a_write_sensor(sd, S5K83A_FLIP, data, 1);
416 if (err < 0)
417 return err;
418
419 data[0] = (val) ? 0x0a : 0x0b;
420 err = s5k83a_write_sensor(sd, S5K83A_HFLIP_TUNE, data, 1);
421
422 return (err < 0) ? err : 0;
423}
diff --git a/drivers/media/video/gspca/m5602/m5602_s5k83a.h b/drivers/media/video/gspca/m5602/m5602_s5k83a.h
new file mode 100644
index 000000000000..833708eb5a42
--- /dev/null
+++ b/drivers/media/video/gspca/m5602/m5602_s5k83a.h
@@ -0,0 +1,484 @@
1/*
2 * Driver for the s5k83a sensor
3 *
4 * Copyright (C) 2008 Erik Andren
5 * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
6 * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
7 *
8 * Portions of code to USB interface and ALi driver software,
9 * Copyright (c) 2006 Willem Duinker
10 * v4l2 interface modeled after the V4L2 driver
11 * for SN9C10x PC Camera Controllers
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation, version 2.
16 *
17 */
18
19#ifndef M5602_S5K83A_H_
20#define M5602_S5K83A_H_
21
22#include "m5602_sensor.h"
23
24#define S5K83A_FLIP 0x01
25#define S5K83A_HFLIP_TUNE 0x03
26#define S5K83A_VFLIP_TUNE 0x05
27#define S5K83A_WHITENESS 0x0a
28#define S5K83A_GAIN 0x18
29#define S5K83A_BRIGHTNESS 0x1b
30#define S5K83A_PAGE_MAP 0xec
31
32#define S5K83A_DEFAULT_BRIGHTNESS 0x71
33#define S5K83A_DEFAULT_WHITENESS 0x7e
34#define S5K83A_DEFAULT_GAIN 0x00
35#define S5K83A_MAXIMUM_GAIN 0x3c
36#define S5K83A_FLIP_MASK 0x10
37
38
39/*****************************************************************************/
40
41/* Kernel module parameters */
42extern int force_sensor;
43extern int dump_sensor;
44extern unsigned int m5602_debug;
45
46
47int s5k83a_probe(struct sd *sd);
48int s5k83a_init(struct sd *sd);
49int s5k83a_power_down(struct sd *sd);
50
51void s5k83a_dump_registers(struct sd *sd);
52
53int s5k83a_read_sensor(struct sd *sd, const u8 address,
54 u8 *i2c_data, const u8 len);
55int s5k83a_write_sensor(struct sd *sd, const u8 address,
56 u8 *i2c_data, const u8 len);
57
58int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val);
59int s5k83a_get_brightness(struct gspca_dev *gspca_dev, __s32 *val);
60int s5k83a_set_whiteness(struct gspca_dev *gspca_dev, __s32 val);
61int s5k83a_get_whiteness(struct gspca_dev *gspca_dev, __s32 *val);
62int s5k83a_set_gain(struct gspca_dev *gspca_dev, __s32 val);
63int s5k83a_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
64int s5k83a_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
65int s5k83a_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
66int s5k83a_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
67int s5k83a_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
68
69
70static struct m5602_sensor s5k83a = {
71 .name = "S5K83A",
72 .probe = s5k83a_probe,
73 .init = s5k83a_init,
74 .power_down = s5k83a_power_down,
75 .read_sensor = s5k83a_read_sensor,
76 .write_sensor = s5k83a_write_sensor,
77 .i2c_slave_id = 0x5a,
78 .nctrls = 5,
79 .ctrls = {
80 {
81 {
82 .id = V4L2_CID_BRIGHTNESS,
83 .type = V4L2_CTRL_TYPE_INTEGER,
84 .name = "brightness",
85 .minimum = 0x00,
86 .maximum = 0xff,
87 .step = 0x01,
88 .default_value = S5K83A_DEFAULT_BRIGHTNESS,
89 .flags = V4L2_CTRL_FLAG_SLIDER
90 },
91 .set = s5k83a_set_brightness,
92 .get = s5k83a_get_brightness
93
94 }, {
95 {
96 .id = V4L2_CID_WHITENESS,
97 .type = V4L2_CTRL_TYPE_INTEGER,
98 .name = "whiteness",
99 .minimum = 0x00,
100 .maximum = 0xff,
101 .step = 0x01,
102 .default_value = S5K83A_DEFAULT_WHITENESS,
103 .flags = V4L2_CTRL_FLAG_SLIDER
104 },
105 .set = s5k83a_set_whiteness,
106 .get = s5k83a_get_whiteness,
107 }, {
108 {
109 .id = V4L2_CID_GAIN,
110 .type = V4L2_CTRL_TYPE_INTEGER,
111 .name = "gain",
112 .minimum = 0x00,
113 .maximum = S5K83A_MAXIMUM_GAIN,
114 .step = 0x01,
115 .default_value = S5K83A_DEFAULT_GAIN,
116 .flags = V4L2_CTRL_FLAG_SLIDER
117 },
118 .set = s5k83a_set_gain,
119 .get = s5k83a_get_gain
120 }, {
121 {
122 .id = V4L2_CID_HFLIP,
123 .type = V4L2_CTRL_TYPE_BOOLEAN,
124 .name = "horizontal flip",
125 .minimum = 0,
126 .maximum = 1,
127 .step = 1,
128 .default_value = 0
129 },
130 .set = s5k83a_set_hflip,
131 .get = s5k83a_get_hflip
132 }, {
133 {
134 .id = V4L2_CID_VFLIP,
135 .type = V4L2_CTRL_TYPE_BOOLEAN,
136 .name = "vertical flip",
137 .minimum = 0,
138 .maximum = 1,
139 .step = 1,
140 .default_value = 0
141 },
142 .set = s5k83a_set_vflip,
143 .get = s5k83a_get_vflip
144 }
145 },
146 .nmodes = 1,
147 .modes = {
148 {
149 M5602_DEFAULT_FRAME_WIDTH,
150 M5602_DEFAULT_FRAME_HEIGHT,
151 V4L2_PIX_FMT_SBGGR8,
152 V4L2_FIELD_NONE,
153 .sizeimage =
154 M5602_DEFAULT_FRAME_WIDTH * M5602_DEFAULT_FRAME_HEIGHT,
155 .bytesperline = M5602_DEFAULT_FRAME_WIDTH,
156 .colorspace = V4L2_COLORSPACE_SRGB,
157 .priv = 1
158 }
159 }
160};
161
162static const unsigned char preinit_s5k83a[][4] =
163{
164 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
165 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
166 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
167 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
168 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
169 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
170 {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
171
172 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
173 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
174 {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
175 {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
176 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
177 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
178 {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
179 {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
180 {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
181 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
182 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
183 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
184 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
185 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
186 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
187 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
188 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
189 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
190 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
191 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
192 {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
193 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
194 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
195 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
196 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
197 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
198
199 {SENSOR, S5K83A_PAGE_MAP, 0x00, 0x00}
200};
201
202/* This could probably be considerably shortened.
203 I don't have the hardware to experiment with it, patches welcome
204*/
205static const unsigned char init_s5k83a[][4] =
206{
207 {SENSOR, S5K83A_PAGE_MAP, 0x04, 0x00},
208 {SENSOR, 0xaf, 0x01, 0x00},
209 {SENSOR, S5K83A_PAGE_MAP, 0x00, 0x00},
210 {SENSOR, 0x7b, 0xff, 0x00},
211 {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
212 {SENSOR, 0x01, 0x50, 0x00},
213 {SENSOR, 0x12, 0x20, 0x00},
214 {SENSOR, 0x17, 0x40, 0x00},
215 {SENSOR, S5K83A_BRIGHTNESS, 0x0f, 0x00},
216 {SENSOR, 0x1c, 0x00, 0x00},
217 {SENSOR, 0x02, 0x70, 0x00},
218 {SENSOR, 0x03, 0x0b, 0x00},
219 {SENSOR, 0x04, 0xf0, 0x00},
220 {SENSOR, 0x05, 0x0b, 0x00},
221 {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
222
223 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
224 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
225 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
226 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
227 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
228 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
229 {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
230 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
231 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
232 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
233 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
234 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
235 {BRIDGE, M5602_XB_VSYNC_PARA, 0xe4, 0x00},
236 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
237 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
238 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
239 {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
240 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
241 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
242 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
243 {BRIDGE, M5602_XB_HSYNC_PARA, 0x87, 0x00},
244 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
245 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
246 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
247
248 {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
249 {SENSOR, 0x06, 0x71, 0x00},
250 {SENSOR, 0x07, 0xe8, 0x00},
251 {SENSOR, 0x08, 0x02, 0x00},
252 {SENSOR, 0x09, 0x88, 0x00},
253 {SENSOR, 0x14, 0x00, 0x00},
254 {SENSOR, 0x15, 0x20, 0x00},
255 {SENSOR, 0x19, 0x00, 0x00},
256 {SENSOR, 0x1a, 0x98, 0x00},
257 {SENSOR, 0x0f, 0x02, 0x00},
258 {SENSOR, 0x10, 0xe5, 0x00},
259 {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
260 {SENSOR_LONG, 0x14, 0x00, 0x20},
261 {SENSOR_LONG, 0x0d, 0x00, 0x7d},
262 {SENSOR_LONG, 0x1b, 0x0d, 0x05},
263
264 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
265 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
266 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
267 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
268 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
269 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
270 {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
271 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
272 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
273 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
274 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
275 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
276 {BRIDGE, M5602_XB_VSYNC_PARA, 0xe4, 0x00},
277 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
278 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
279 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
280 {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
281 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
282 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
283 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
284 {BRIDGE, M5602_XB_HSYNC_PARA, 0x87, 0x00},
285
286 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
287 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
288 {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
289 {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
290 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
291 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
292 {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
293 {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
294 {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
295 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
296 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
297 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
298 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
299 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
300 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
301 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
302 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
303 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
304 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
305 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
306 {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
307 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
308 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
309 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
310 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
311 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
312
313 {SENSOR, S5K83A_PAGE_MAP, 0x04, 0x00},
314 {SENSOR, 0xaf, 0x01, 0x00},
315 {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
316 /* ff ( init value )is very dark) || 71 and f0 better */
317 {SENSOR, 0x7b, 0xff, 0x00},
318 {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
319 {SENSOR, 0x01, 0x50, 0x00},
320 {SENSOR, 0x12, 0x20, 0x00},
321 {SENSOR, 0x17, 0x40, 0x00},
322 {SENSOR, S5K83A_BRIGHTNESS, 0x0f, 0x00},
323 {SENSOR, 0x1c, 0x00, 0x00},
324 {SENSOR, 0x02, 0x70, 0x00},
325 /* some values like 0x10 give a blue-purple image */
326 {SENSOR, 0x03, 0x0b, 0x00},
327 {SENSOR, 0x04, 0xf0, 0x00},
328 {SENSOR, 0x05, 0x0b, 0x00},
329 {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
330
331 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
332 /* under 80 don't work, highter depend on value */
333 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
334
335 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
336 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
337 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
338 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
339 {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
340 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
341 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
342 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
343 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
344 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
345 {BRIDGE, M5602_XB_VSYNC_PARA, 0xe4, 0x00},
346 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
347 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
348 {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
349 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
350 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
351 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
352 {BRIDGE, M5602_XB_HSYNC_PARA, 0x7f, 0x00},
353
354 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
355 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
356 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
357
358 {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
359 {SENSOR, 0x06, 0x71, 0x00},
360 {SENSOR, 0x07, 0xe8, 0x00},
361 {SENSOR, 0x08, 0x02, 0x00},
362 {SENSOR, 0x09, 0x88, 0x00},
363 {SENSOR, 0x14, 0x00, 0x00},
364 {SENSOR, 0x15, 0x20, 0x00},
365 {SENSOR, 0x19, 0x00, 0x00},
366 {SENSOR, 0x1a, 0x98, 0x00},
367 {SENSOR, 0x0f, 0x02, 0x00},
368 {SENSOR, 0x10, 0xe5, 0x00},
369 {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
370 {SENSOR_LONG, 0x14, 0x00, 0x20},
371 {SENSOR_LONG, 0x0d, 0x00, 0x7d},
372 {SENSOR_LONG, 0x1b, 0x0d, 0x05},
373
374 /* The following sequence is useless after a clean boot
375 but is necessary after resume from suspend */
376 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
377 {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
378 {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
379 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
380 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
381 {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
382 {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
383 {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
384 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
385 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
386 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
387 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
388 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
389 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
390 {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
391 {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
392 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
393 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
394 {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
395 {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
396 {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
397 {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
398 {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
399 {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
400 {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
401
402 {SENSOR, S5K83A_PAGE_MAP, 0x04, 0x00},
403 {SENSOR, 0xaf, 0x01, 0x00},
404 {SENSOR, S5K83A_PAGE_MAP, 0x00, 0x00},
405 {SENSOR, 0x7b, 0xff, 0x00},
406 {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
407 {SENSOR, 0x01, 0x50, 0x00},
408 {SENSOR, 0x12, 0x20, 0x00},
409 {SENSOR, 0x17, 0x40, 0x00},
410 {SENSOR, S5K83A_BRIGHTNESS, 0x0f, 0x00},
411 {SENSOR, 0x1c, 0x00, 0x00},
412 {SENSOR, 0x02, 0x70, 0x00},
413 {SENSOR, 0x03, 0x0b, 0x00},
414 {SENSOR, 0x04, 0xf0, 0x00},
415 {SENSOR, 0x05, 0x0b, 0x00},
416 {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
417
418 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
419 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
420 {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
421 {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
422 {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
423 {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
424 {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
425 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
426 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
427 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
428 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
429 {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
430 {BRIDGE, M5602_XB_VSYNC_PARA, 0xe4, 0x00},
431 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
432 {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
433 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
434 {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
435 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
436 {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
437 {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
438 {BRIDGE, M5602_XB_HSYNC_PARA, 0x7f, 0x00},
439 {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
440 {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
441 {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
442
443 {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
444 {SENSOR, 0x06, 0x71, 0x00},
445 {SENSOR, 0x07, 0xe8, 0x00},
446 {SENSOR, 0x08, 0x02, 0x00},
447 {SENSOR, 0x09, 0x88, 0x00},
448 {SENSOR, 0x14, 0x00, 0x00},
449 {SENSOR, 0x15, 0x20, 0x00},
450 {SENSOR, 0x19, 0x00, 0x00},
451 {SENSOR, 0x1a, 0x98, 0x00},
452 {SENSOR, 0x0f, 0x02, 0x00},
453
454 {SENSOR, 0x10, 0xe5, 0x00},
455 {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
456 {SENSOR_LONG, 0x14, 0x00, 0x20},
457 {SENSOR_LONG, 0x0d, 0x00, 0x7d},
458 {SENSOR_LONG, 0x1b, 0x0d, 0x05},
459
460 /* normal colors
461 (this is value after boot, but after tries can be different) */
462 {SENSOR, 0x00, 0x06, 0x00},
463
464 /* set default brightness */
465 {SENSOR_LONG, 0x14, 0x00, 0x20},
466 {SENSOR_LONG, 0x0d, 0x01, 0x00},
467 {SENSOR_LONG, 0x1b, S5K83A_DEFAULT_BRIGHTNESS >> 3,
468 S5K83A_DEFAULT_BRIGHTNESS >> 1},
469
470 /* set default whiteness */
471 {SENSOR, S5K83A_WHITENESS, S5K83A_DEFAULT_WHITENESS, 0x00},
472
473 /* set default gain */
474 {SENSOR_LONG, 0x18, 0x00, S5K83A_DEFAULT_GAIN},
475
476 /* set default flip */
477 {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
478 {SENSOR, S5K83A_FLIP, 0x00 | S5K83A_FLIP_MASK, 0x00},
479 {SENSOR, S5K83A_HFLIP_TUNE, 0x0b, 0x00},
480 {SENSOR, S5K83A_VFLIP_TUNE, 0x0a, 0x00}
481
482};
483
484#endif
diff --git a/drivers/media/video/gspca/m5602/m5602_sensor.h b/drivers/media/video/gspca/m5602/m5602_sensor.h
new file mode 100644
index 000000000000..930fcaab4416
--- /dev/null
+++ b/drivers/media/video/gspca/m5602/m5602_sensor.h
@@ -0,0 +1,76 @@
1/*
2 * USB Driver for ALi m5602 based webcams
3 *
4 * Copyright (C) 2008 Erik Andren
5 * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
6 * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
7 *
8 * Portions of code to USB interface and ALi driver software,
9 * Copyright (c) 2006 Willem Duinker
10 * v4l2 interface modeled after the V4L2 driver
11 * for SN9C10x PC Camera Controllers
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation, version 2.
16 *
17 */
18
19#ifndef M5602_SENSOR_H_
20#define M5602_SENSOR_H_
21
22#include "m5602_bridge.h"
23
24#define M5602_DEFAULT_FRAME_WIDTH 640
25#define M5602_DEFAULT_FRAME_HEIGHT 480
26
27#define M5602_MAX_CTRLS (V4L2_CID_LASTP1 - V4L2_CID_BASE + 10)
28
29/* Enumerates all supported sensors */
30enum sensors {
31 OV9650_SENSOR = 1,
32 S5K83A_SENSOR = 2,
33 S5K4AA_SENSOR = 3,
34 MT9M111_SENSOR = 4,
35 PO1030_SENSOR = 5
36};
37
38/* Enumerates all possible instruction types */
39enum instruction {
40 BRIDGE,
41 SENSOR,
42 SENSOR_LONG
43};
44
45struct m5602_sensor {
46 /* Defines the name of a sensor */
47 char name[32];
48
49 /* What i2c address the sensor is connected to */
50 u8 i2c_slave_id;
51
52 /* Probes if the sensor is connected */
53 int (*probe)(struct sd *sd);
54
55 /* Performs a initialization sequence */
56 int (*init)(struct sd *sd);
57
58 /* Performs a power down sequence */
59 int (*power_down)(struct sd *sd);
60
61 /* Reads a sensor register */
62 int (*read_sensor)(struct sd *sd, const u8 address,
63 u8 *i2c_data, const u8 len);
64
65 /* Writes to a sensor register */
66 int (*write_sensor)(struct sd *sd, const u8 address,
67 u8 *i2c_data, const u8 len);
68
69 int nctrls;
70 struct ctrl ctrls[M5602_MAX_CTRLS];
71
72 char nmodes;
73 struct v4l2_pix_format modes[];
74};
75
76#endif
diff --git a/drivers/media/video/gspca/mars.c b/drivers/media/video/gspca/mars.c
index 4d5db47ba8cb..277ca34a8817 100644
--- a/drivers/media/video/gspca/mars.c
+++ b/drivers/media/video/gspca/mars.c
@@ -134,7 +134,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
134 return 0; 134 return 0;
135} 135}
136 136
137static void sd_start(struct gspca_dev *gspca_dev) 137static int sd_start(struct gspca_dev *gspca_dev)
138{ 138{
139 int err_code; 139 int err_code;
140 __u8 *data; 140 __u8 *data;
@@ -143,9 +143,10 @@ static void sd_start(struct gspca_dev *gspca_dev)
143 int intpipe; 143 int intpipe;
144 144
145 PDEBUG(D_STREAM, "camera start, iface %d, alt 8", gspca_dev->iface); 145 PDEBUG(D_STREAM, "camera start, iface %d, alt 8", gspca_dev->iface);
146 if (usb_set_interface(gspca_dev->dev, gspca_dev->iface, 8) < 0) { 146 err_code = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 8);
147 if (err_code < 0) {
147 PDEBUG(D_ERR|D_STREAM, "Set packet size: set interface error"); 148 PDEBUG(D_ERR|D_STREAM, "Set packet size: set interface error");
148 return; 149 return err_code;
149 } 150 }
150 151
151 data = gspca_dev->usb_buf; 152 data = gspca_dev->usb_buf;
@@ -154,7 +155,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
154 155
155 err_code = reg_w(gspca_dev, data[0], 2); 156 err_code = reg_w(gspca_dev, data[0], 2);
156 if (err_code < 0) 157 if (err_code < 0)
157 return; 158 return err_code;
158 159
159 /* 160 /*
160 Initialize the MR97113 chip register 161 Initialize the MR97113 chip register
@@ -180,14 +181,14 @@ static void sd_start(struct gspca_dev *gspca_dev)
180 181
181 err_code = reg_w(gspca_dev, data[0], 11); 182 err_code = reg_w(gspca_dev, data[0], 11);
182 if (err_code < 0) 183 if (err_code < 0)
183 return; 184 return err_code;
184 185
185 data[0] = 0x23; /* address */ 186 data[0] = 0x23; /* address */
186 data[1] = 0x09; /* reg 35, append frame header */ 187 data[1] = 0x09; /* reg 35, append frame header */
187 188
188 err_code = reg_w(gspca_dev, data[0], 2); 189 err_code = reg_w(gspca_dev, data[0], 2);
189 if (err_code < 0) 190 if (err_code < 0)
190 return; 191 return err_code;
191 192
192 data[0] = 0x3c; /* address */ 193 data[0] = 0x3c; /* address */
193/* if (gspca_dev->width == 1280) */ 194/* if (gspca_dev->width == 1280) */
@@ -198,7 +199,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
198 * (unit: 4KB) 200KB */ 199 * (unit: 4KB) 200KB */
199 err_code = reg_w(gspca_dev, data[0], 2); 200 err_code = reg_w(gspca_dev, data[0], 2);
200 if (err_code < 0) 201 if (err_code < 0)
201 return; 202 return err_code;
202 203
203 if (0) { /* fixed dark-gain */ 204 if (0) { /* fixed dark-gain */
204 data[1] = 0; /* reg 94, Y Gain (1.75) */ 205 data[1] = 0; /* reg 94, Y Gain (1.75) */
@@ -240,13 +241,13 @@ static void sd_start(struct gspca_dev *gspca_dev)
240 241
241 err_code = reg_w(gspca_dev, data[0], 6); 242 err_code = reg_w(gspca_dev, data[0], 6);
242 if (err_code < 0) 243 if (err_code < 0)
243 return; 244 return err_code;
244 245
245 data[0] = 0x67; 246 data[0] = 0x67;
246 data[1] = 0x13; /* reg 103, first pixel B, disable sharpness */ 247 data[1] = 0x13; /* reg 103, first pixel B, disable sharpness */
247 err_code = reg_w(gspca_dev, data[0], 2); 248 err_code = reg_w(gspca_dev, data[0], 2);
248 if (err_code < 0) 249 if (err_code < 0)
249 return; 250 return err_code;
250 251
251 /* 252 /*
252 * initialize the value of MI sensor... 253 * initialize the value of MI sensor...
@@ -326,6 +327,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
326 data[0] = 0x00; 327 data[0] = 0x00;
327 data[1] = 0x4d; /* ISOC transfering enable... */ 328 data[1] = 0x4d; /* ISOC transfering enable... */
328 reg_w(gspca_dev, data[0], 2); 329 reg_w(gspca_dev, data[0], 2);
330 return err_code;
329} 331}
330 332
331static void sd_stopN(struct gspca_dev *gspca_dev) 333static void sd_stopN(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/ov519.c b/drivers/media/video/gspca/ov519.c
index 4df4eec9f7e7..ca671194679e 100644
--- a/drivers/media/video/gspca/ov519.c
+++ b/drivers/media/video/gspca/ov519.c
@@ -1854,7 +1854,7 @@ static int set_ov_sensor_window(struct sd *sd)
1854} 1854}
1855 1855
1856/* -- start the camera -- */ 1856/* -- start the camera -- */
1857static void sd_start(struct gspca_dev *gspca_dev) 1857static int sd_start(struct gspca_dev *gspca_dev)
1858{ 1858{
1859 struct sd *sd = (struct sd *) gspca_dev; 1859 struct sd *sd = (struct sd *) gspca_dev;
1860 int ret; 1860 int ret;
@@ -1871,9 +1871,10 @@ static void sd_start(struct gspca_dev *gspca_dev)
1871 goto out; 1871 goto out;
1872 PDEBUG(D_STREAM, "camera started alt: 0x%02x", gspca_dev->alt); 1872 PDEBUG(D_STREAM, "camera started alt: 0x%02x", gspca_dev->alt);
1873 ov51x_led_control(sd, 1); 1873 ov51x_led_control(sd, 1);
1874 return; 1874 return 0;
1875out: 1875out:
1876 PDEBUG(D_ERR, "camera start error:%d", ret); 1876 PDEBUG(D_ERR, "camera start error:%d", ret);
1877 return ret;
1877} 1878}
1878 1879
1879static void sd_stopN(struct gspca_dev *gspca_dev) 1880static void sd_stopN(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/pac207.c b/drivers/media/video/gspca/pac207.c
index 83b5f740c947..0b0c573d06da 100644
--- a/drivers/media/video/gspca/pac207.c
+++ b/drivers/media/video/gspca/pac207.c
@@ -281,7 +281,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
281} 281}
282 282
283/* -- start the camera -- */ 283/* -- start the camera -- */
284static void sd_start(struct gspca_dev *gspca_dev) 284static int sd_start(struct gspca_dev *gspca_dev)
285{ 285{
286 struct sd *sd = (struct sd *) gspca_dev; 286 struct sd *sd = (struct sd *) gspca_dev;
287 __u8 mode; 287 __u8 mode;
@@ -323,6 +323,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
323 sd->sof_read = 0; 323 sd->sof_read = 0;
324 sd->autogain_ignore_frames = 0; 324 sd->autogain_ignore_frames = 0;
325 atomic_set(&sd->avg_lum, -1); 325 atomic_set(&sd->avg_lum, -1);
326 return 0;
326} 327}
327 328
328static void sd_stopN(struct gspca_dev *gspca_dev) 329static void sd_stopN(struct gspca_dev *gspca_dev)
@@ -534,6 +535,7 @@ static const __devinitdata struct usb_device_id device_table[] = {
534 {USB_DEVICE(0x093a, 0x2470)}, 535 {USB_DEVICE(0x093a, 0x2470)},
535 {USB_DEVICE(0x093a, 0x2471)}, 536 {USB_DEVICE(0x093a, 0x2471)},
536 {USB_DEVICE(0x093a, 0x2472)}, 537 {USB_DEVICE(0x093a, 0x2472)},
538 {USB_DEVICE(0x093a, 0x2476)},
537 {USB_DEVICE(0x2001, 0xf115)}, 539 {USB_DEVICE(0x2001, 0xf115)},
538 {} 540 {}
539}; 541};
diff --git a/drivers/media/video/gspca/pac7311.c b/drivers/media/video/gspca/pac7311.c
index ba865b7f1ed8..e5ff9a6199ef 100644
--- a/drivers/media/video/gspca/pac7311.c
+++ b/drivers/media/video/gspca/pac7311.c
@@ -675,7 +675,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
675 return 0; 675 return 0;
676} 676}
677 677
678static void sd_start(struct gspca_dev *gspca_dev) 678static int sd_start(struct gspca_dev *gspca_dev)
679{ 679{
680 struct sd *sd = (struct sd *) gspca_dev; 680 struct sd *sd = (struct sd *) gspca_dev;
681 681
@@ -724,6 +724,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
724 reg_w(gspca_dev, 0x78, 0x01); 724 reg_w(gspca_dev, 0x78, 0x01);
725 else 725 else
726 reg_w(gspca_dev, 0x78, 0x05); 726 reg_w(gspca_dev, 0x78, 0x05);
727 return 0;
727} 728}
728 729
729static void sd_stopN(struct gspca_dev *gspca_dev) 730static void sd_stopN(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/sonixb.c b/drivers/media/video/gspca/sonixb.c
index 12b81ae526b7..6c69bc7778fc 100644
--- a/drivers/media/video/gspca/sonixb.c
+++ b/drivers/media/video/gspca/sonixb.c
@@ -490,7 +490,7 @@ static const __u8 tas5130_sensor_init[][8] = {
490 {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10}, 490 {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10},
491}; 491};
492 492
493struct sensor_data sensor_data[] = { 493static struct sensor_data sensor_data[] = {
494SENS(initHv7131, NULL, hv7131_sensor_init, NULL, NULL, 0, NO_EXPO|NO_FREQ, 0), 494SENS(initHv7131, NULL, hv7131_sensor_init, NULL, NULL, 0, NO_EXPO|NO_FREQ, 0),
495SENS(initOv6650, NULL, ov6650_sensor_init, NULL, NULL, F_GAIN|F_SIF, 0, 0x60), 495SENS(initOv6650, NULL, ov6650_sensor_init, NULL, NULL, F_GAIN|F_SIF, 0, 0x60),
496SENS(initOv7630, initOv7630_3, ov7630_sensor_init, NULL, ov7630_sensor_init_3, 496SENS(initOv7630, initOv7630_3, ov7630_sensor_init, NULL, ov7630_sensor_init_3,
@@ -892,7 +892,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
892} 892}
893 893
894/* -- start the camera -- */ 894/* -- start the camera -- */
895static void sd_start(struct gspca_dev *gspca_dev) 895static int sd_start(struct gspca_dev *gspca_dev)
896{ 896{
897 struct sd *sd = (struct sd *) gspca_dev; 897 struct sd *sd = (struct sd *) gspca_dev;
898 struct cam *cam = &gspca_dev->cam; 898 struct cam *cam = &gspca_dev->cam;
@@ -976,6 +976,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
976 sd->frames_to_drop = 0; 976 sd->frames_to_drop = 0;
977 sd->autogain_ignore_frames = 0; 977 sd->autogain_ignore_frames = 0;
978 atomic_set(&sd->avg_lum, -1); 978 atomic_set(&sd->avg_lum, -1);
979 return 0;
979} 980}
980 981
981static void sd_stopN(struct gspca_dev *gspca_dev) 982static void sd_stopN(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/sonixj.c b/drivers/media/video/gspca/sonixj.c
index 572b0f363b64..53cb82d9e7c6 100644
--- a/drivers/media/video/gspca/sonixj.c
+++ b/drivers/media/video/gspca/sonixj.c
@@ -39,6 +39,7 @@ struct sd {
39 unsigned char contrast; 39 unsigned char contrast;
40 unsigned char colors; 40 unsigned char colors;
41 unsigned char autogain; 41 unsigned char autogain;
42 __u8 vflip; /* ov7630 only */
42 43
43 signed char ag_cnt; 44 signed char ag_cnt;
44#define AG_CNT_START 13 45#define AG_CNT_START 13
@@ -70,6 +71,8 @@ static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
70static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); 71static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
71static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); 72static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
72static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); 73static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
74static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
75static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
73 76
74static struct ctrl sd_ctrls[] = { 77static struct ctrl sd_ctrls[] = {
75 { 78 {
@@ -131,6 +134,22 @@ static struct ctrl sd_ctrls[] = {
131 .set = sd_setautogain, 134 .set = sd_setautogain,
132 .get = sd_getautogain, 135 .get = sd_getautogain,
133 }, 136 },
137/* ov7630 only */
138#define VFLIP_IDX 4
139 {
140 {
141 .id = V4L2_CID_VFLIP,
142 .type = V4L2_CTRL_TYPE_BOOLEAN,
143 .name = "Vflip",
144 .minimum = 0,
145 .maximum = 1,
146 .step = 1,
147#define VFLIP_DEF 1
148 .default_value = VFLIP_DEF,
149 },
150 .set = sd_setvflip,
151 .get = sd_getvflip,
152 },
134}; 153};
135 154
136static struct v4l2_pix_format vga_mode[] = { 155static struct v4l2_pix_format vga_mode[] = {
@@ -248,10 +267,12 @@ static const __u8 gamma_def[] = {
248 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff 267 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
249}; 268};
250 269
270/* color matrix and offsets */
251static const __u8 reg84[] = { 271static const __u8 reg84[] = {
252 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, 0xe5, 0x0f, 272 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, /* YR YG YB gains */
253 0xe4, 0x0f, 0x38, 0x00, 0x3e, 0x00, 0xc3, 0x0f, 273 0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00, /* UR UG UB */
254 0xf7, 0x0f, 0x00, 0x00, 0x00 274 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */
275 0x00, 0x00, 0x00 /* YUV offsets */
255}; 276};
256static const __u8 hv7131r_sensor_init[][8] = { 277static const __u8 hv7131r_sensor_init[][8] = {
257 {0xC1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10}, 278 {0xC1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
@@ -434,7 +455,8 @@ static const __u8 ov7630_sensor_init[][8] = {
434 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10}, 455 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
435 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10}, 456 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
436/*fixme: + 0x12, 0x04*/ 457/*fixme: + 0x12, 0x04*/
437 {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10}, 458/* {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10}, * COMN
459 * set by setvflip */
438 {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10}, 460 {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
439 {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}, 461 {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
440 {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10}, 462 {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
@@ -949,6 +971,8 @@ static int sd_config(struct gspca_dev *gspca_dev,
949 gspca_dev->ctrl_dis = (1 << AUTOGAIN_IDX); 971 gspca_dev->ctrl_dis = (1 << AUTOGAIN_IDX);
950 break; 972 break;
951 } 973 }
974 if (sd->sensor != SENSOR_OV7630)
975 gspca_dev->ctrl_dis |= (1 << VFLIP_IDX);
952 976
953 return 0; 977 return 0;
954} 978}
@@ -1080,20 +1104,17 @@ static unsigned int setexposure(struct gspca_dev *gspca_dev,
1080static void setbrightcont(struct gspca_dev *gspca_dev) 1104static void setbrightcont(struct gspca_dev *gspca_dev)
1081{ 1105{
1082 struct sd *sd = (struct sd *) gspca_dev; 1106 struct sd *sd = (struct sd *) gspca_dev;
1083 unsigned val; 1107 int val;
1084 __u8 reg84_full[0x15]; 1108 __u8 reg84_full[0x15];
1085 1109
1086 memset(reg84_full, 0, sizeof reg84_full); 1110 memcpy(reg84_full, reg84, sizeof reg84_full);
1087 val = sd->contrast * 0x20 / CONTRAST_MAX + 0x10; /* 10..30 */ 1111 val = sd->contrast * 0x30 / CONTRAST_MAX + 0x10; /* 10..40 */
1088 reg84_full[2] = val; 1112 reg84_full[0] = (val + 1) / 2; /* red */
1089 reg84_full[0] = (val + 1) / 2; 1113 reg84_full[2] = val; /* green */
1090 reg84_full[4] = (val + 1) / 5; 1114 reg84_full[4] = (val + 1) / 5; /* blue */
1091 if (val > BRIGHTNESS_DEF) 1115 val = (sd->brightness - BRIGHTNESS_DEF) * 0x10
1092 val = (sd->brightness - BRIGHTNESS_DEF) * 0x20
1093 / BRIGHTNESS_MAX; 1116 / BRIGHTNESS_MAX;
1094 else 1117 reg84_full[0x12] = val & 0x1f; /* 5:0 signed value */
1095 val = 0;
1096 reg84_full[0x12] = val; /* 00..1f */
1097 reg_w(gspca_dev, 0x84, reg84_full, sizeof reg84_full); 1118 reg_w(gspca_dev, 0x84, reg84_full, sizeof reg84_full);
1098} 1119}
1099 1120
@@ -1172,8 +1193,16 @@ static void setautogain(struct gspca_dev *gspca_dev)
1172 sd->ag_cnt = -1; 1193 sd->ag_cnt = -1;
1173} 1194}
1174 1195
1196static void setvflip(struct sd *sd)
1197{
1198 if (sd->sensor != SENSOR_OV7630)
1199 return;
1200 i2c_w1(&sd->gspca_dev, 0x75, /* COMN */
1201 sd->vflip ? 0x82 : 0x02);
1202}
1203
1175/* -- start the camera -- */ 1204/* -- start the camera -- */
1176static void sd_start(struct gspca_dev *gspca_dev) 1205static int sd_start(struct gspca_dev *gspca_dev)
1177{ 1206{
1178 struct sd *sd = (struct sd *) gspca_dev; 1207 struct sd *sd = (struct sd *) gspca_dev;
1179 int i; 1208 int i;
@@ -1263,6 +1292,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
1263 break; 1292 break;
1264 case SENSOR_OV7630: 1293 case SENSOR_OV7630:
1265 ov7630_InitSensor(gspca_dev); 1294 ov7630_InitSensor(gspca_dev);
1295 setvflip(sd);
1266 reg17 = 0xe2; 1296 reg17 = 0xe2;
1267 reg1 = 0x44; 1297 reg1 = 0x44;
1268 break; 1298 break;
@@ -1320,12 +1350,16 @@ static void sd_start(struct gspca_dev *gspca_dev)
1320 setbrightness(gspca_dev); 1350 setbrightness(gspca_dev);
1321 setcontrast(gspca_dev); 1351 setcontrast(gspca_dev);
1322 break; 1352 break;
1353 case SENSOR_OV7630:
1354 setvflip(sd);
1355 /* fall thru */
1323 default: /* OV76xx */ 1356 default: /* OV76xx */
1324 setbrightcont(gspca_dev); 1357 setbrightcont(gspca_dev);
1325 break; 1358 break;
1326 } 1359 }
1327 setautogain(gspca_dev); 1360 setautogain(gspca_dev);
1328 reg_w1(gspca_dev, 0x01, reg1); 1361 reg_w1(gspca_dev, 0x01, reg1);
1362 return 0;
1329} 1363}
1330 1364
1331static void sd_stopN(struct gspca_dev *gspca_dev) 1365static void sd_stopN(struct gspca_dev *gspca_dev)
@@ -1546,6 +1580,24 @@ static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
1546 return 0; 1580 return 0;
1547} 1581}
1548 1582
1583static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
1584{
1585 struct sd *sd = (struct sd *) gspca_dev;
1586
1587 sd->vflip = val;
1588 if (gspca_dev->streaming)
1589 setvflip(sd);
1590 return 0;
1591}
1592
1593static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
1594{
1595 struct sd *sd = (struct sd *) gspca_dev;
1596
1597 *val = sd->vflip;
1598 return 0;
1599}
1600
1549/* sub-driver description */ 1601/* sub-driver description */
1550static const struct sd_desc sd_desc = { 1602static const struct sd_desc sd_desc = {
1551 .name = MODULE_NAME, 1603 .name = MODULE_NAME,
@@ -1567,6 +1619,7 @@ static const struct sd_desc sd_desc = {
1567static const __devinitdata struct usb_device_id device_table[] = { 1619static const __devinitdata struct usb_device_id device_table[] = {
1568#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE 1620#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
1569 {USB_DEVICE(0x0458, 0x7025), BSI(SN9C120, MI0360, 0x5d)}, 1621 {USB_DEVICE(0x0458, 0x7025), BSI(SN9C120, MI0360, 0x5d)},
1622 {USB_DEVICE(0x0458, 0x702e), BSI(SN9C120, OV7660, 0x21)},
1570 {USB_DEVICE(0x045e, 0x00f5), BSI(SN9C105, OV7660, 0x21)}, 1623 {USB_DEVICE(0x045e, 0x00f5), BSI(SN9C105, OV7660, 0x21)},
1571 {USB_DEVICE(0x045e, 0x00f7), BSI(SN9C105, OV7660, 0x21)}, 1624 {USB_DEVICE(0x045e, 0x00f7), BSI(SN9C105, OV7660, 0x21)},
1572 {USB_DEVICE(0x0471, 0x0327), BSI(SN9C105, MI0360, 0x5d)}, 1625 {USB_DEVICE(0x0471, 0x0327), BSI(SN9C105, MI0360, 0x5d)},
@@ -1588,7 +1641,9 @@ static const __devinitdata struct usb_device_id device_table[] = {
1588/* {USB_DEVICE(0x0c45, 0x60fa), BSI(SN9C105, OV7648, 0x??)}, */ 1641/* {USB_DEVICE(0x0c45, 0x60fa), BSI(SN9C105, OV7648, 0x??)}, */
1589 {USB_DEVICE(0x0c45, 0x60fb), BSI(SN9C105, OV7660, 0x21)}, 1642 {USB_DEVICE(0x0c45, 0x60fb), BSI(SN9C105, OV7660, 0x21)},
1590 {USB_DEVICE(0x0c45, 0x60fc), BSI(SN9C105, HV7131R, 0x11)}, 1643 {USB_DEVICE(0x0c45, 0x60fc), BSI(SN9C105, HV7131R, 0x11)},
1591/* {USB_DEVICE(0x0c45, 0x60fe), BSI(SN9C105, OV7630, 0x??)}, */ 1644#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
1645 {USB_DEVICE(0x0c45, 0x60fe), BSI(SN9C105, OV7630, 0x21)},
1646#endif
1592/* {USB_DEVICE(0x0c45, 0x6108), BSI(SN9C120, OM6801, 0x??)}, */ 1647/* {USB_DEVICE(0x0c45, 0x6108), BSI(SN9C120, OM6801, 0x??)}, */
1593/* {USB_DEVICE(0x0c45, 0x6122), BSI(SN9C110, ICM105C, 0x??)}, */ 1648/* {USB_DEVICE(0x0c45, 0x6122), BSI(SN9C110, ICM105C, 0x??)}, */
1594/* {USB_DEVICE(0x0c45, 0x6123), BSI(SN9C110, SanyoCCD, 0x??)}, */ 1649/* {USB_DEVICE(0x0c45, 0x6123), BSI(SN9C110, SanyoCCD, 0x??)}, */
diff --git a/drivers/media/video/gspca/spca500.c b/drivers/media/video/gspca/spca500.c
index 6e733901fcca..bca106c153fa 100644
--- a/drivers/media/video/gspca/spca500.c
+++ b/drivers/media/video/gspca/spca500.c
@@ -660,7 +660,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
660 return 0; 660 return 0;
661} 661}
662 662
663static void sd_start(struct gspca_dev *gspca_dev) 663static int sd_start(struct gspca_dev *gspca_dev)
664{ 664{
665 struct sd *sd = (struct sd *) gspca_dev; 665 struct sd *sd = (struct sd *) gspca_dev;
666 int err; 666 int err;
@@ -867,6 +867,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
867 write_vector(gspca_dev, Clicksmart510_defaults); 867 write_vector(gspca_dev, Clicksmart510_defaults);
868 break; 868 break;
869 } 869 }
870 return 0;
870} 871}
871 872
872static void sd_stopN(struct gspca_dev *gspca_dev) 873static void sd_stopN(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/spca501.c b/drivers/media/video/gspca/spca501.c
index e9eb59bae4fb..b742f260c7ca 100644
--- a/drivers/media/video/gspca/spca501.c
+++ b/drivers/media/video/gspca/spca501.c
@@ -1980,7 +1980,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
1980 return 0; 1980 return 0;
1981} 1981}
1982 1982
1983static void sd_start(struct gspca_dev *gspca_dev) 1983static int sd_start(struct gspca_dev *gspca_dev)
1984{ 1984{
1985 struct usb_device *dev = gspca_dev->dev; 1985 struct usb_device *dev = gspca_dev->dev;
1986 int mode; 1986 int mode;
@@ -2012,6 +2012,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
2012 setbrightness(gspca_dev); 2012 setbrightness(gspca_dev);
2013 setcontrast(gspca_dev); 2013 setcontrast(gspca_dev);
2014 setcolors(gspca_dev); 2014 setcolors(gspca_dev);
2015 return 0;
2015} 2016}
2016 2017
2017static void sd_stopN(struct gspca_dev *gspca_dev) 2018static void sd_stopN(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/spca505.c b/drivers/media/video/gspca/spca505.c
index f601daf19ebe..b345749213cf 100644
--- a/drivers/media/video/gspca/spca505.c
+++ b/drivers/media/video/gspca/spca505.c
@@ -688,7 +688,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
688 return 0; 688 return 0;
689} 689}
690 690
691static void sd_start(struct gspca_dev *gspca_dev) 691static int sd_start(struct gspca_dev *gspca_dev)
692{ 692{
693 struct usb_device *dev = gspca_dev->dev; 693 struct usb_device *dev = gspca_dev->dev;
694 int ret; 694 int ret;
@@ -733,6 +733,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
733/* reg_write(dev, 0x5, 0x0, 0x0); */ 733/* reg_write(dev, 0x5, 0x0, 0x0); */
734/* reg_write(dev, 0x5, 0x0, 0x1); */ 734/* reg_write(dev, 0x5, 0x0, 0x1); */
735/* reg_write(dev, 0x5, 0x11, 0x2); */ 735/* reg_write(dev, 0x5, 0x11, 0x2); */
736 return ret;
736} 737}
737 738
738static void sd_stopN(struct gspca_dev *gspca_dev) 739static void sd_stopN(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/spca506.c b/drivers/media/video/gspca/spca506.c
index 195dce96ef06..645ee9d44d02 100644
--- a/drivers/media/video/gspca/spca506.c
+++ b/drivers/media/video/gspca/spca506.c
@@ -422,7 +422,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
422 return 0; 422 return 0;
423} 423}
424 424
425static void sd_start(struct gspca_dev *gspca_dev) 425static int sd_start(struct gspca_dev *gspca_dev)
426{ 426{
427 struct usb_device *dev = gspca_dev->dev; 427 struct usb_device *dev = gspca_dev->dev;
428 __u16 norme; 428 __u16 norme;
@@ -549,6 +549,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
549 PDEBUG(D_STREAM, "webcam started"); 549 PDEBUG(D_STREAM, "webcam started");
550 spca506_GetNormeInput(gspca_dev, &norme, &channel); 550 spca506_GetNormeInput(gspca_dev, &norme, &channel);
551 spca506_SetNormeInput(gspca_dev, norme, channel); 551 spca506_SetNormeInput(gspca_dev, norme, channel);
552 return 0;
552} 553}
553 554
554static void sd_stopN(struct gspca_dev *gspca_dev) 555static void sd_stopN(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/spca508.c b/drivers/media/video/gspca/spca508.c
index 281ce02103a3..63ec902c895d 100644
--- a/drivers/media/video/gspca/spca508.c
+++ b/drivers/media/video/gspca/spca508.c
@@ -1528,7 +1528,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
1528 return 0; 1528 return 0;
1529} 1529}
1530 1530
1531static void sd_start(struct gspca_dev *gspca_dev) 1531static int sd_start(struct gspca_dev *gspca_dev)
1532{ 1532{
1533 int mode; 1533 int mode;
1534 1534
@@ -1546,6 +1546,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
1546 break; 1546 break;
1547 } 1547 }
1548 reg_write(gspca_dev->dev, 0x8112, 0x10 | 0x20); 1548 reg_write(gspca_dev->dev, 0x8112, 0x10 | 0x20);
1549 return 0;
1549} 1550}
1550 1551
1551static void sd_stopN(struct gspca_dev *gspca_dev) 1552static void sd_stopN(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/spca561.c b/drivers/media/video/gspca/spca561.c
index 95fcfcb9e31b..020a03c466c1 100644
--- a/drivers/media/video/gspca/spca561.c
+++ b/drivers/media/video/gspca/spca561.c
@@ -152,7 +152,7 @@ static void reg_w_val(struct usb_device *dev, __u16 index, __u8 value)
152 152
153 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), 153 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
154 0, /* request */ 154 0, /* request */
155 USB_TYPE_VENDOR | USB_RECIP_DEVICE, 155 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
156 value, index, NULL, 0, 500); 156 value, index, NULL, 0, 500);
157 PDEBUG(D_USBO, "reg write: 0x%02x:0x%02x", index, value); 157 PDEBUG(D_USBO, "reg write: 0x%02x:0x%02x", index, value);
158 if (ret < 0) 158 if (ret < 0)
@@ -699,7 +699,7 @@ static void setautogain(struct gspca_dev *gspca_dev)
699 sd->ag_cnt = -1; 699 sd->ag_cnt = -1;
700} 700}
701 701
702static void sd_start_12a(struct gspca_dev *gspca_dev) 702static int sd_start_12a(struct gspca_dev *gspca_dev)
703{ 703{
704 struct usb_device *dev = gspca_dev->dev; 704 struct usb_device *dev = gspca_dev->dev;
705 int Clck = 0x8a; /* lower 0x8X values lead to fps > 30 */ 705 int Clck = 0x8a; /* lower 0x8X values lead to fps > 30 */
@@ -725,8 +725,9 @@ static void sd_start_12a(struct gspca_dev *gspca_dev)
725 setwhite(gspca_dev); 725 setwhite(gspca_dev);
726 setautogain(gspca_dev); 726 setautogain(gspca_dev);
727 setexposure(gspca_dev); 727 setexposure(gspca_dev);
728 return 0;
728} 729}
729static void sd_start_72a(struct gspca_dev *gspca_dev) 730static int sd_start_72a(struct gspca_dev *gspca_dev)
730{ 731{
731 struct usb_device *dev = gspca_dev->dev; 732 struct usb_device *dev = gspca_dev->dev;
732 int Clck; 733 int Clck;
@@ -750,6 +751,7 @@ static void sd_start_72a(struct gspca_dev *gspca_dev)
750 reg_w_val(dev, 0x8700, Clck); /* 0x27 clock */ 751 reg_w_val(dev, 0x8700, Clck); /* 0x27 clock */
751 reg_w_val(dev, 0x8112, 0x10 | 0x20); 752 reg_w_val(dev, 0x8112, 0x10 | 0x20);
752 setautogain(gspca_dev); 753 setautogain(gspca_dev);
754 return 0;
753} 755}
754 756
755static void sd_stopN(struct gspca_dev *gspca_dev) 757static void sd_stopN(struct gspca_dev *gspca_dev)
@@ -1064,7 +1066,7 @@ static struct ctrl sd_ctrls_12a[] = {
1064 { 1066 {
1065 .id = V4L2_CID_DO_WHITE_BALANCE, 1067 .id = V4L2_CID_DO_WHITE_BALANCE,
1066 .type = V4L2_CTRL_TYPE_INTEGER, 1068 .type = V4L2_CTRL_TYPE_INTEGER,
1067 .name = "While Balance", 1069 .name = "White Balance",
1068 .minimum = WHITE_MIN, 1070 .minimum = WHITE_MIN,
1069 .maximum = WHITE_MAX, 1071 .maximum = WHITE_MAX,
1070 .step = 1, 1072 .step = 1,
diff --git a/drivers/media/video/gspca/stk014.c b/drivers/media/video/gspca/stk014.c
index 2f2de429e273..d9d64911f22a 100644
--- a/drivers/media/video/gspca/stk014.c
+++ b/drivers/media/video/gspca/stk014.c
@@ -324,7 +324,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
324} 324}
325 325
326/* -- start the camera -- */ 326/* -- start the camera -- */
327static void sd_start(struct gspca_dev *gspca_dev) 327static int sd_start(struct gspca_dev *gspca_dev)
328{ 328{
329 int ret, value; 329 int ret, value;
330 330
@@ -374,9 +374,10 @@ static void sd_start(struct gspca_dev *gspca_dev)
374 set_par(gspca_dev, 0x01000000); 374 set_par(gspca_dev, 0x01000000);
375 set_par(gspca_dev, 0x01000000); 375 set_par(gspca_dev, 0x01000000);
376 PDEBUG(D_STREAM, "camera started alt: 0x%02x", gspca_dev->alt); 376 PDEBUG(D_STREAM, "camera started alt: 0x%02x", gspca_dev->alt);
377 return; 377 return 0;
378out: 378out:
379 PDEBUG(D_ERR|D_STREAM, "camera start err %d", ret); 379 PDEBUG(D_ERR|D_STREAM, "camera start err %d", ret);
380 return ret;
380} 381}
381 382
382static void sd_stopN(struct gspca_dev *gspca_dev) 383static void sd_stopN(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/sunplus.c b/drivers/media/video/gspca/sunplus.c
index 1cfcc6c49558..bd9288665a80 100644
--- a/drivers/media/video/gspca/sunplus.c
+++ b/drivers/media/video/gspca/sunplus.c
@@ -961,7 +961,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
961 return 0; 961 return 0;
962} 962}
963 963
964static void sd_start(struct gspca_dev *gspca_dev) 964static int sd_start(struct gspca_dev *gspca_dev)
965{ 965{
966 struct sd *sd = (struct sd *) gspca_dev; 966 struct sd *sd = (struct sd *) gspca_dev;
967 struct usb_device *dev = gspca_dev->dev; 967 struct usb_device *dev = gspca_dev->dev;
@@ -1042,6 +1042,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
1042 break; 1042 break;
1043 } 1043 }
1044 sp5xx_initContBrigHueRegisters(gspca_dev); 1044 sp5xx_initContBrigHueRegisters(gspca_dev);
1045 return 0;
1045} 1046}
1046 1047
1047static void sd_stopN(struct gspca_dev *gspca_dev) 1048static void sd_stopN(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/t613.c b/drivers/media/video/gspca/t613.c
index f034c748fc7e..b561f7c4f066 100644
--- a/drivers/media/video/gspca/t613.c
+++ b/drivers/media/video/gspca/t613.c
@@ -28,8 +28,6 @@
28 28
29#include "gspca.h" 29#include "gspca.h"
30 30
31#define MAX_GAMMA 0x10 /* 0 to 15 */
32
33#define V4L2_CID_EFFECTS (V4L2_CID_PRIVATE_BASE + 0) 31#define V4L2_CID_EFFECTS (V4L2_CID_PRIVATE_BASE + 0)
34 32
35MODULE_AUTHOR("Leandro Costantino <le_costantino@pixartargentina.com.ar>"); 33MODULE_AUTHOR("Leandro Costantino <le_costantino@pixartargentina.com.ar>");
@@ -49,6 +47,10 @@ struct sd {
49 unsigned char whitebalance; 47 unsigned char whitebalance;
50 unsigned char mirror; 48 unsigned char mirror;
51 unsigned char effect; 49 unsigned char effect;
50
51 __u8 sensor;
52#define SENSOR_TAS5130A 0
53#define SENSOR_OTHER 1
52}; 54};
53 55
54/* V4L2 controls supported by the driver */ 56/* V4L2 controls supported by the driver */
@@ -83,9 +85,9 @@ static struct ctrl sd_ctrls[] = {
83 .type = V4L2_CTRL_TYPE_INTEGER, 85 .type = V4L2_CTRL_TYPE_INTEGER,
84 .name = "Brightness", 86 .name = "Brightness",
85 .minimum = 0, 87 .minimum = 0,
86 .maximum = 0x0f, 88 .maximum = 14,
87 .step = 1, 89 .step = 1,
88 .default_value = 0x09, 90 .default_value = 8,
89 }, 91 },
90 .set = sd_setbrightness, 92 .set = sd_setbrightness,
91 .get = sd_getbrightness, 93 .get = sd_getbrightness,
@@ -118,16 +120,17 @@ static struct ctrl sd_ctrls[] = {
118 .set = sd_setcolors, 120 .set = sd_setcolors,
119 .get = sd_getcolors, 121 .get = sd_getcolors,
120 }, 122 },
121#define SD_GAMMA 3 123#define GAMMA_MAX 16
124#define GAMMA_DEF 10
122 { 125 {
123 { 126 {
124 .id = V4L2_CID_GAMMA, /* (gamma on win) */ 127 .id = V4L2_CID_GAMMA, /* (gamma on win) */
125 .type = V4L2_CTRL_TYPE_INTEGER, 128 .type = V4L2_CTRL_TYPE_INTEGER,
126 .name = "Gamma (Untested)", 129 .name = "Gamma",
127 .minimum = 0, 130 .minimum = 0,
128 .maximum = MAX_GAMMA, 131 .maximum = GAMMA_MAX - 1,
129 .step = 1, 132 .step = 1,
130 .default_value = 0x09, 133 .default_value = GAMMA_DEF,
131 }, 134 },
132 .set = sd_setgamma, 135 .set = sd_setgamma,
133 .get = sd_getgamma, 136 .get = sd_getgamma,
@@ -197,7 +200,7 @@ static struct ctrl sd_ctrls[] = {
197 .type = V4L2_CTRL_TYPE_INTEGER, 200 .type = V4L2_CTRL_TYPE_INTEGER,
198 .name = "Sharpness", 201 .name = "Sharpness",
199 .minimum = 0, 202 .minimum = 0,
200 .maximum = MAX_GAMMA, /* 0 to 16 */ 203 .maximum = 15,
201 .step = 1, 204 .step = 1,
202 .default_value = 0x06, 205 .default_value = 0x06,
203 }, 206 },
@@ -258,7 +261,6 @@ static struct v4l2_pix_format vga_mode_t16[] = {
258 .priv = 0}, 261 .priv = 0},
259}; 262};
260 263
261#define T16_OFFSET_DATA 631
262#define MAX_EFFECTS 7 264#define MAX_EFFECTS 7
263/* easily done by soft, this table could be removed, 265/* easily done by soft, this table could be removed,
264 * i keep it here just in case */ 266 * i keep it here just in case */
@@ -272,87 +274,87 @@ static const __u8 effects_table[MAX_EFFECTS][6] = {
272 {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x40}, /* Negative */ 274 {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x40}, /* Negative */
273}; 275};
274 276
275static const __u8 gamma_table[MAX_GAMMA][34] = { 277static const __u8 gamma_table[GAMMA_MAX][34] = {
276 {0x90, 0x00, 0x91, 0x3e, 0x92, 0x69, 0x93, 0x85, 278 {0x90, 0x00, 0x91, 0x3e, 0x92, 0x69, 0x93, 0x85, /* 0 */
277 0x94, 0x95, 0x95, 0xa1, 0x96, 0xae, 0x97, 0xb9, 279 0x94, 0x95, 0x95, 0xa1, 0x96, 0xae, 0x97, 0xb9,
278 0x98, 0xc2, 0x99, 0xcb, 0x9a, 0xd4, 0x9b, 0xdb, 280 0x98, 0xc2, 0x99, 0xcb, 0x9a, 0xd4, 0x9b, 0xdb,
279 0x9c, 0xe3, 0x9d, 0xea, 0x9e, 0xf1, 0x9f, 0xf8, 281 0x9c, 0xe3, 0x9d, 0xea, 0x9e, 0xf1, 0x9f, 0xf8,
280 0xa0, 0xff}, 282 0xa0, 0xff},
281 {0x90, 0x00, 0x91, 0x33, 0x92, 0x5A, 0x93, 0x75, 283 {0x90, 0x00, 0x91, 0x33, 0x92, 0x5a, 0x93, 0x75, /* 1 */
282 0x94, 0x85, 0x95, 0x93, 0x96, 0xA1, 0x97, 0xAD, 284 0x94, 0x85, 0x95, 0x93, 0x96, 0xa1, 0x97, 0xad,
283 0x98, 0xB7, 0x99, 0xC2, 0x9A, 0xCB, 0x9B, 0xD4, 285 0x98, 0xb7, 0x99, 0xc2, 0x9a, 0xcb, 0x9b, 0xd4,
284 0x9C, 0xDE, 0x9D, 0xE7, 0x9E, 0xF0, 0x9F, 0xF7, 286 0x9c, 0xde, 0x9D, 0xe7, 0x9e, 0xf0, 0x9f, 0xf7,
285 0xa0, 0xff}, 287 0xa0, 0xff},
286 {0x90, 0x00, 0x91, 0x2F, 0x92, 0x51, 0x93, 0x6B, 288 {0x90, 0x00, 0x91, 0x2f, 0x92, 0x51, 0x93, 0x6b, /* 2 */
287 0x94, 0x7C, 0x95, 0x8A, 0x96, 0x99, 0x97, 0xA6, 289 0x94, 0x7c, 0x95, 0x8a, 0x96, 0x99, 0x97, 0xa6,
288 0x98, 0xB1, 0x99, 0xBC, 0x9A, 0xC6, 0x9B, 0xD0, 290 0x98, 0xb1, 0x99, 0xbc, 0x9a, 0xc6, 0x9b, 0xd0,
289 0x9C, 0xDB, 0x9D, 0xE4, 0x9E, 0xED, 0x9F, 0xF6, 291 0x9c, 0xdb, 0x9d, 0xe4, 0x9e, 0xed, 0x9f, 0xf6,
290 0xa0, 0xff}, 292 0xa0, 0xff},
291 {0x90, 0x00, 0x91, 0x29, 0x92, 0x48, 0x93, 0x60, 293 {0x90, 0x00, 0x91, 0x29, 0x92, 0x48, 0x93, 0x60, /* 3 */
292 0x94, 0x72, 0x95, 0x81, 0x96, 0x90, 0x97, 0x9E, 294 0x94, 0x72, 0x95, 0x81, 0x96, 0x90, 0x97, 0x9e,
293 0x98, 0xAA, 0x99, 0xB5, 0x9A, 0xBF, 0x9B, 0xCB, 295 0x98, 0xaa, 0x99, 0xb5, 0x9a, 0xbf, 0x9b, 0xcb,
294 0x9C, 0xD6, 0x9D, 0xE1, 0x9E, 0xEB, 0x9F, 0xF5, 296 0x9c, 0xd6, 0x9d, 0xe1, 0x9e, 0xeb, 0x9f, 0xf5,
295 0xa0, 0xff}, 297 0xa0, 0xff},
296 {0x90, 0x00, 0x91, 0x23, 0x92, 0x3F, 0x93, 0x55, 298 {0x90, 0x00, 0x91, 0x23, 0x92, 0x3f, 0x93, 0x55, /* 4 */
297 0x94, 0x68, 0x95, 0x77, 0x96, 0x86, 0x97, 0x95, 299 0x94, 0x68, 0x95, 0x77, 0x96, 0x86, 0x97, 0x95,
298 0x98, 0xA2, 0x99, 0xAD, 0x9A, 0xB9, 0x9B, 0xC6, 300 0x98, 0xa2, 0x99, 0xad, 0x9a, 0xb9, 0x9b, 0xc6,
299 0x9C, 0xD2, 0x9D, 0xDE, 0x9E, 0xE9, 0x9F, 0xF4, 301 0x9c, 0xd2, 0x9d, 0xde, 0x9e, 0xe9, 0x9f, 0xf4,
300 0xa0, 0xff}, 302 0xa0, 0xff},
301 {0x90, 0x00, 0x91, 0x1B, 0x92, 0x33, 0x93, 0x48, 303 {0x90, 0x00, 0x91, 0x1b, 0x92, 0x33, 0x93, 0x48, /* 5 */
302 0x94, 0x59, 0x95, 0x69, 0x96, 0x79, 0x97, 0x87, 304 0x94, 0x59, 0x95, 0x69, 0x96, 0x79, 0x97, 0x87,
303 0x98, 0x96, 0x99, 0xA3, 0x9A, 0xB1, 0x9B, 0xBE, 305 0x98, 0x96, 0x99, 0xa3, 0x9a, 0xb1, 0x9b, 0xbe,
304 0x9C, 0xCC, 0x9D, 0xDA, 0x9E, 0xE7, 0x9F, 0xF3, 306 0x9c, 0xcc, 0x9d, 0xda, 0x9e, 0xe7, 0x9f, 0xf3,
305 0xa0, 0xff}, 307 0xa0, 0xff},
306 {0x90, 0x00, 0x91, 0x02, 0x92, 0x10, 0x93, 0x20, 308 {0x90, 0x00, 0x91, 0x02, 0x92, 0x10, 0x93, 0x20, /* 6 */
307 0x94, 0x32, 0x95, 0x40, 0x96, 0x57, 0x97, 0x67, 309 0x94, 0x32, 0x95, 0x40, 0x96, 0x57, 0x97, 0x67,
308 0x98, 0x77, 0x99, 0x88, 0x9a, 0x99, 0x9b, 0xaa, 310 0x98, 0x77, 0x99, 0x88, 0x9a, 0x99, 0x9b, 0xaa,
309 0x9c, 0xbb, 0x9d, 0xcc, 0x9e, 0xdd, 0x9f, 0xee, 311 0x9c, 0xbb, 0x9d, 0xcc, 0x9e, 0xdd, 0x9f, 0xee,
310 0xa0, 0xff}, 312 0xa0, 0xff},
311 {0x90, 0x00, 0x91, 0x02, 0x92, 0x14, 0x93, 0x26, 313 {0x90, 0x00, 0x91, 0x02, 0x92, 0x14, 0x93, 0x26, /* 7 */
312 0x94, 0x38, 0x95, 0x4A, 0x96, 0x60, 0x97, 0x70, 314 0x94, 0x38, 0x95, 0x4a, 0x96, 0x60, 0x97, 0x70,
313 0x98, 0x80, 0x99, 0x90, 0x9A, 0xA0, 0x9B, 0xB0, 315 0x98, 0x80, 0x99, 0x90, 0x9a, 0xa0, 0x9b, 0xb0,
314 0x9C, 0xC0, 0x9D, 0xD0, 0x9E, 0xE0, 0x9F, 0xF0, 316 0x9c, 0xc0, 0x9D, 0xd0, 0x9e, 0xe0, 0x9f, 0xf0,
315 0xa0, 0xff}, 317 0xa0, 0xff},
316 {0x90, 0x00, 0x91, 0x10, 0x92, 0x22, 0x93, 0x35, 318 {0x90, 0x00, 0x91, 0x10, 0x92, 0x22, 0x93, 0x35, /* 8 */
317 0x94, 0x47, 0x95, 0x5A, 0x96, 0x69, 0x97, 0x79, 319 0x94, 0x47, 0x95, 0x5a, 0x96, 0x69, 0x97, 0x79,
318 0x98, 0x88, 0x99, 0x97, 0x9A, 0xA7, 0x9B, 0xB6, 320 0x98, 0x88, 0x99, 0x97, 0x9a, 0xa7, 0x9b, 0xb6,
319 0x9C, 0xC4, 0x9D, 0xD3, 0x9E, 0xE0, 0x9F, 0xF0, 321 0x9c, 0xc4, 0x9d, 0xd3, 0x9e, 0xe0, 0x9f, 0xf0,
320 0xa0, 0xff}, 322 0xa0, 0xff},
321 {0x90, 0x00, 0x91, 0x10, 0x92, 0x26, 0x93, 0x40, 323 {0x90, 0x00, 0x91, 0x10, 0x92, 0x26, 0x93, 0x40, /* 9 */
322 0x94, 0x54, 0x95, 0x65, 0x96, 0x75, 0x97, 0x84, 324 0x94, 0x54, 0x95, 0x65, 0x96, 0x75, 0x97, 0x84,
323 0x98, 0x93, 0x99, 0xa1, 0x9a, 0xb0, 0x9b, 0xbd, 325 0x98, 0x93, 0x99, 0xa1, 0x9a, 0xb0, 0x9b, 0xbd,
324 0x9c, 0xca, 0x9d, 0xd6, 0x9e, 0xe0, 0x9f, 0xf0, 326 0x9c, 0xca, 0x9d, 0xd6, 0x9e, 0xe0, 0x9f, 0xf0,
325 0xa0, 0xff}, 327 0xa0, 0xff},
326 {0x90, 0x00, 0x91, 0x18, 0x92, 0x2B, 0x93, 0x44, 328 {0x90, 0x00, 0x91, 0x18, 0x92, 0x2b, 0x93, 0x44, /* 10 */
327 0x94, 0x60, 0x95, 0x70, 0x96, 0x80, 0x97, 0x8E, 329 0x94, 0x60, 0x95, 0x70, 0x96, 0x80, 0x97, 0x8e,
328 0x98, 0x9C, 0x99, 0xAA, 0x9A, 0xB7, 0x9B, 0xC4, 330 0x98, 0x9c, 0x99, 0xaa, 0x9a, 0xb7, 0x9b, 0xc4,
329 0x9C, 0xD0, 0x9D, 0xD8, 0x9E, 0xE2, 0x9F, 0xF0, 331 0x9c, 0xd0, 0x9d, 0xd8, 0x9e, 0xe2, 0x9f, 0xf0,
330 0xa0, 0xff}, 332 0xa0, 0xff},
331 {0x90, 0x00, 0x91, 0x1A, 0x92, 0x34, 0x93, 0x52, 333 {0x90, 0x00, 0x91, 0x1a, 0x92, 0x34, 0x93, 0x52, /* 11 */
332 0x94, 0x66, 0x95, 0x7E, 0x96, 0x8D, 0x97, 0x9B, 334 0x94, 0x66, 0x95, 0x7e, 0x96, 0x8D, 0x97, 0x9B,
333 0x98, 0xA8, 0x99, 0xB4, 0x9A, 0xC0, 0x9B, 0xCB, 335 0x98, 0xa8, 0x99, 0xb4, 0x9a, 0xc0, 0x9b, 0xcb,
334 0x9C, 0xD6, 0x9D, 0xE1, 0x9E, 0xEB, 0x9F, 0xF5, 336 0x9c, 0xd6, 0x9d, 0xe1, 0x9e, 0xeb, 0x9f, 0xf5,
335 0xa0, 0xff}, 337 0xa0, 0xff},
336 {0x90, 0x00, 0x91, 0x3F, 0x92, 0x5A, 0x93, 0x6E, 338 {0x90, 0x00, 0x91, 0x3f, 0x92, 0x5a, 0x93, 0x6e, /* 12 */
337 0x94, 0x7F, 0x95, 0x8E, 0x96, 0x9C, 0x97, 0xA8, 339 0x94, 0x7f, 0x95, 0x8e, 0x96, 0x9c, 0x97, 0xa8,
338 0x98, 0xB4, 0x99, 0xBF, 0x9A, 0xC9, 0x9B, 0xD3, 340 0x98, 0xb4, 0x99, 0xbf, 0x9a, 0xc9, 0x9b, 0xd3,
339 0x9C, 0xDC, 0x9D, 0xE5, 0x9E, 0xEE, 0x9F, 0xF6, 341 0x9c, 0xdc, 0x9d, 0xe5, 0x9e, 0xee, 0x9f, 0xf6,
340 0xA0, 0xFF},
341 {0x90, 0x00, 0x91, 0x54, 0x92, 0x6F, 0x93, 0x83,
342 0x94, 0x93, 0x95, 0xA0, 0x96, 0xAD, 0x97, 0xB7,
343 0x98, 0xC2, 0x99, 0xCB, 0x9A, 0xD4, 0x9B, 0xDC,
344 0x9C, 0xE4, 0x9D, 0xEB, 0x9E, 0xF2, 0x9F, 0xF9,
345 0xa0, 0xff}, 342 0xa0, 0xff},
346 {0x90, 0x00, 0x91, 0x6E, 0x92, 0x88, 0x93, 0x9A, 343 {0x90, 0x00, 0x91, 0x54, 0x92, 0x6f, 0x93, 0x83, /* 13 */
347 0x94, 0xA8, 0x95, 0xB3, 0x96, 0xBD, 0x97, 0xC6, 344 0x94, 0x93, 0x95, 0xa0, 0x96, 0xad, 0x97, 0xb7,
348 0x98, 0xCF, 0x99, 0xD6, 0x9A, 0xDD, 0x9B, 0xE3, 345 0x98, 0xc2, 0x99, 0xcb, 0x9a, 0xd4, 0x9b, 0xdc,
349 0x9C, 0xE9, 0x9D, 0xEF, 0x9E, 0xF4, 0x9F, 0xFA, 346 0x9c, 0xe4, 0x9d, 0xeb, 0x9e, 0xf2, 0x9f, 0xf9,
350 0xa0, 0xff}, 347 0xa0, 0xff},
351 {0x90, 0x00, 0x91, 0x93, 0x92, 0xA8, 0x93, 0xB7, 348 {0x90, 0x00, 0x91, 0x6e, 0x92, 0x88, 0x93, 0x9a, /* 14 */
352 0x94, 0xC1, 0x95, 0xCA, 0x96, 0xD2, 0x97, 0xD8, 349 0x94, 0xa8, 0x95, 0xb3, 0x96, 0xbd, 0x97, 0xc6,
353 0x98, 0xDE, 0x99, 0xE3, 0x9A, 0xE8, 0x9B, 0xED, 350 0x98, 0xcf, 0x99, 0xd6, 0x9a, 0xdd, 0x9b, 0xe3,
354 0x9C, 0xF1, 0x9D, 0xF5, 0x9E, 0xF8, 0x9F, 0xFC, 351 0x9c, 0xe9, 0x9d, 0xef, 0x9e, 0xf4, 0x9f, 0xfa,
355 0xA0, 0xFF} 352 0xa0, 0xff},
353 {0x90, 0x00, 0x91, 0x93, 0x92, 0xa8, 0x93, 0xb7, /* 15 */
354 0x94, 0xc1, 0x95, 0xca, 0x96, 0xd2, 0x97, 0xd8,
355 0x98, 0xde, 0x99, 0xe3, 0x9a, 0xe8, 0x9b, 0xed,
356 0x9c, 0xf1, 0x9d, 0xf5, 0x9e, 0xf8, 0x9f, 0xfc,
357 0xa0, 0xff}
356}; 358};
357 359
358static const __u8 tas5130a_sensor_init[][8] = { 360static const __u8 tas5130a_sensor_init[][8] = {
@@ -364,7 +366,7 @@ static const __u8 tas5130a_sensor_init[][8] = {
364}; 366};
365 367
366/* read 1 byte */ 368/* read 1 byte */
367static int reg_r_1(struct gspca_dev *gspca_dev, 369static int reg_r(struct gspca_dev *gspca_dev,
368 __u16 index) 370 __u16 index)
369{ 371{
370 usb_control_msg(gspca_dev->dev, 372 usb_control_msg(gspca_dev->dev,
@@ -378,26 +380,26 @@ static int reg_r_1(struct gspca_dev *gspca_dev,
378} 380}
379 381
380static void reg_w(struct gspca_dev *gspca_dev, 382static void reg_w(struct gspca_dev *gspca_dev,
381 __u16 value, 383 __u16 index)
382 __u16 index, 384{
383 const __u8 *buffer, __u16 len) 385 usb_control_msg(gspca_dev->dev,
386 usb_sndctrlpipe(gspca_dev->dev, 0),
387 0,
388 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
389 0, index,
390 NULL, 0, 500);
391}
392
393static void i2c_w(struct gspca_dev *gspca_dev,
394 const __u8 *buffer, __u16 len)
384{ 395{
385 if (buffer == NULL) {
386 usb_control_msg(gspca_dev->dev,
387 usb_sndctrlpipe(gspca_dev->dev, 0),
388 0,
389 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
390 value, index,
391 NULL, 0, 500);
392 return;
393 }
394 if (len <= USB_BUF_SZ) { 396 if (len <= USB_BUF_SZ) {
395 memcpy(gspca_dev->usb_buf, buffer, len); 397 memcpy(gspca_dev->usb_buf, buffer, len);
396 usb_control_msg(gspca_dev->dev, 398 usb_control_msg(gspca_dev->dev,
397 usb_sndctrlpipe(gspca_dev->dev, 0), 399 usb_sndctrlpipe(gspca_dev->dev, 0),
398 0, 400 0,
399 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 401 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
400 value, index, 402 0x01, 0,
401 gspca_dev->usb_buf, len, 500); 403 gspca_dev->usb_buf, len, 500);
402 } else { 404 } else {
403 __u8 *tmpbuf; 405 __u8 *tmpbuf;
@@ -408,12 +410,56 @@ static void reg_w(struct gspca_dev *gspca_dev,
408 usb_sndctrlpipe(gspca_dev->dev, 0), 410 usb_sndctrlpipe(gspca_dev->dev, 0),
409 0, 411 0,
410 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, 412 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
411 value, index, 413 0x01, 0,
412 tmpbuf, len, 500); 414 tmpbuf, len, 500);
413 kfree(tmpbuf); 415 kfree(tmpbuf);
414 } 416 }
415} 417}
416 418
419static void other_sensor_init(struct gspca_dev *gspca_dev)
420{
421 int i;
422 const __u8 *p;
423 __u8 byte;
424 __u8 val[6] = {0x62, 0, 0x64, 0, 0x60, 0x05};
425 static const __u8 sensor_init[] = {
426 0xdf, 0x6d,
427 0xdd, 0x18,
428 0x5a, 0xe0,
429 0x5c, 0x07,
430 0x5d, 0xb0,
431 0x5e, 0x1e,
432 0x60, 0x71,
433 0xef, 0x00,
434 0xe9, 0x00,
435 0xea, 0x00,
436 0x90, 0x24,
437 0x91, 0xb2,
438 0x82, 0x32,
439 0xfd, 0x00,
440 0xfd, 0x01,
441 0xfd, 0x41,
442 0x00 /* table end */
443 };
444
445 p = sensor_init;
446 while (*p != 0) {
447 val[1] = *p++;
448 val[3] = *p++;
449 if (*p == 0)
450 reg_w(gspca_dev, 0x3c80);
451 i2c_w(gspca_dev, val, sizeof val);
452 i = 4;
453 while (--i >= 0) {
454 msleep(15);
455 byte = reg_r(gspca_dev, 0x60);
456 if (!(byte & 0x01))
457 break;
458 }
459 }
460 reg_w(gspca_dev, 0x3c80);
461}
462
417/* this function is called at probe time */ 463/* this function is called at probe time */
418static int sd_config(struct gspca_dev *gspca_dev, 464static int sd_config(struct gspca_dev *gspca_dev,
419 const struct usb_device_id *id) 465 const struct usb_device_id *id)
@@ -430,7 +476,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
430 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; 476 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
431 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value; 477 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
432 sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value; 478 sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
433 sd->gamma = sd_ctrls[SD_GAMMA].qctrl.default_value; 479 sd->gamma = GAMMA_DEF;
434 sd->mirror = sd_ctrls[SD_MIRROR].qctrl.default_value; 480 sd->mirror = sd_ctrls[SD_MIRROR].qctrl.default_value;
435 sd->freq = sd_ctrls[SD_LIGHTFREQ].qctrl.default_value; 481 sd->freq = sd_ctrls[SD_LIGHTFREQ].qctrl.default_value;
436 sd->whitebalance = sd_ctrls[SD_WHITE_BALANCE].qctrl.default_value; 482 sd->whitebalance = sd_ctrls[SD_WHITE_BALANCE].qctrl.default_value;
@@ -439,27 +485,37 @@ static int sd_config(struct gspca_dev *gspca_dev,
439 return 0; 485 return 0;
440} 486}
441 487
442static int init_default_parameters(struct gspca_dev *gspca_dev) 488static void setgamma(struct gspca_dev *gspca_dev)
489{
490 struct sd *sd = (struct sd *) gspca_dev;
491
492 PDEBUG(D_CONF, "Gamma: %d", sd->gamma);
493 i2c_w(gspca_dev, gamma_table[sd->gamma], sizeof gamma_table[0]);
494}
495
496/* this function is called at probe and resume time */
497static int sd_init(struct gspca_dev *gspca_dev)
443{ 498{
444 /* some of this registers are not really neded, because 499 /* some of this registers are not really neded, because
445 * they are overriden by setbrigthness, setcontrast, etc, 500 * they are overriden by setbrigthness, setcontrast, etc,
446 * but wont hurt anyway, and can help someone with similar webcam 501 * but wont hurt anyway, and can help someone with similar webcam
447 * to see the initial parameters.*/ 502 * to see the initial parameters.*/
448 int i = 0; 503 struct sd *sd = (struct sd *) gspca_dev;
449 __u8 test_byte; 504 int i;
505 __u8 byte, test_byte;
450 506
451 static const __u8 read_indexs[] = 507 static const __u8 read_indexs[] =
452 { 0x06, 0x07, 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5, 508 { 0x06, 0x07, 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5,
453 0xa6, 0xa8, 0xbb, 0xbc, 0xc6, 0x00, 0x00 }; 509 0xa6, 0xa8, 0xbb, 0xbc, 0xc6, 0x00, 0x00 };
454 static const __u8 n1[6] = 510 static const __u8 n1[] =
455 {0x08, 0x03, 0x09, 0x03, 0x12, 0x04}; 511 {0x08, 0x03, 0x09, 0x03, 0x12, 0x04};
456 static const __u8 n2[2] = 512 static const __u8 n2[] =
457 {0x08, 0x00}; 513 {0x08, 0x00};
458 static const __u8 nset[6] = 514 static const __u8 nset[] =
459 { 0x61, 0x68, 0x62, 0xff, 0x60, 0x07 }; 515 { 0x61, 0x68, 0x62, 0xff, 0x60, 0x07 };
460 static const __u8 n3[6] = 516 static const __u8 n3[] =
461 {0x61, 0x68, 0x65, 0x0a, 0x60, 0x04}; 517 {0x61, 0x68, 0x65, 0x0a, 0x60, 0x04};
462 static const __u8 n4[0x46] = 518 static const __u8 n4[] =
463 {0x09, 0x01, 0x12, 0x04, 0x66, 0x8a, 0x80, 0x3c, 519 {0x09, 0x01, 0x12, 0x04, 0x66, 0x8a, 0x80, 0x3c,
464 0x81, 0x22, 0x84, 0x50, 0x8a, 0x78, 0x8b, 0x68, 520 0x81, 0x22, 0x84, 0x50, 0x8a, 0x78, 0x8b, 0x68,
465 0x8c, 0x88, 0x8e, 0x33, 0x8f, 0x24, 0xaa, 0xb1, 521 0x8c, 0x88, 0x8e, 0x33, 0x8f, 0x24, 0xaa, 0xb1,
@@ -469,33 +525,26 @@ static int init_default_parameters(struct gspca_dev *gspca_dev)
469 0x65, 0x0a, 0xbb, 0x86, 0xaf, 0x58, 0xb0, 0x68, 525 0x65, 0x0a, 0xbb, 0x86, 0xaf, 0x58, 0xb0, 0x68,
470 0x87, 0x40, 0x89, 0x2b, 0x8d, 0xff, 0x83, 0x40, 526 0x87, 0x40, 0x89, 0x2b, 0x8d, 0xff, 0x83, 0x40,
471 0xac, 0x84, 0xad, 0x86, 0xaf, 0x46}; 527 0xac, 0x84, 0xad, 0x86, 0xaf, 0x46};
472 static const __u8 nset4[18] = { 528 static const __u8 nset4[] = {
473 0xe0, 0x60, 0xe1, 0xa8, 0xe2, 0xe0, 0xe3, 0x60, 0xe4, 0xa8, 529 0xe0, 0x60, 0xe1, 0xa8, 0xe2, 0xe0, 0xe3, 0x60, 0xe4, 0xa8,
474 0xe5, 0xe0, 0xe6, 0x60, 0xe7, 0xa8, 530 0xe5, 0xe0, 0xe6, 0x60, 0xe7, 0xa8,
475 0xe8, 0xe0 531 0xe8, 0xe0
476 }; 532 };
477 /* ojo puede ser 0xe6 en vez de 0xe9 */ 533 /* ojo puede ser 0xe6 en vez de 0xe9 */
478 static const __u8 nset2[20] = { 534 static const __u8 nset2[] = {
479 0xd0, 0xbb, 0xd1, 0x28, 0xd2, 0x10, 0xd3, 0x10, 0xd4, 0xbb, 535 0xd0, 0xbb, 0xd1, 0x28, 0xd2, 0x10, 0xd3, 0x10, 0xd4, 0xbb,
480 0xd5, 0x28, 0xd6, 0x1e, 0xd7, 0x27, 536 0xd5, 0x28, 0xd6, 0x1e, 0xd7, 0x27,
481 0xd8, 0xc8, 0xd9, 0xfc 537 0xd8, 0xc8, 0xd9, 0xfc
482 }; 538 };
483 static const __u8 missing[8] = 539 static const __u8 missing[] =
484 { 0x87, 0x20, 0x88, 0x20, 0x89, 0x20, 0x80, 0x38 }; 540 { 0x87, 0x20, 0x88, 0x20, 0x89, 0x20, 0x80, 0x38 };
485 static const __u8 nset3[18] = { 541 static const __u8 nset3[] = {
486 0xc7, 0x60, 0xc8, 0xa8, 0xc9, 0xe0, 0xca, 0x60, 0xcb, 0xa8, 542 0xc7, 0x60, 0xc8, 0xa8, 0xc9, 0xe0, 0xca, 0x60, 0xcb, 0xa8,
487 0xcc, 0xe0, 0xcd, 0x60, 0xce, 0xa8, 543 0xcc, 0xe0, 0xcd, 0x60, 0xce, 0xa8,
488 0xcf, 0xe0 544 0xcf, 0xe0
489 }; 545 };
490 static const __u8 nset5[4] = 546 static const __u8 nset5[] =
491 { 0x8f, 0x24, 0xc3, 0x00 }; /* bright */ 547 { 0x8f, 0x24, 0xc3, 0x00 }; /* bright */
492 static const __u8 nset6[34] = {
493 0x90, 0x00, 0x91, 0x1c, 0x92, 0x30, 0x93, 0x43, 0x94, 0x54,
494 0x95, 0x65, 0x96, 0x75, 0x97, 0x84,
495 0x98, 0x93, 0x99, 0xa1, 0x9a, 0xb0, 0x9b, 0xbd, 0x9c, 0xca,
496 0x9d, 0xd8, 0x9e, 0xe5, 0x9f, 0xf2,
497 0xa0, 0xff
498 }; /* Gamma */
499 static const __u8 nset7[4] = 548 static const __u8 nset7[4] =
500 { 0x66, 0xca, 0xa8, 0xf8 }; /* 50/60 Hz */ 549 { 0x66, 0xca, 0xa8, 0xf8 }; /* 50/60 Hz */
501 static const __u8 nset9[4] = 550 static const __u8 nset9[4] =
@@ -505,95 +554,111 @@ static int init_default_parameters(struct gspca_dev *gspca_dev)
505 static const __u8 nset10[6] = 554 static const __u8 nset10[6] =
506 { 0x0c, 0x03, 0xab, 0x10, 0x81, 0x20 }; 555 { 0x0c, 0x03, 0xab, 0x10, 0x81, 0x20 };
507 556
508 reg_w(gspca_dev, 0x01, 0x0000, n1, 0x06); 557 byte = reg_r(gspca_dev, 0x06);
509 reg_w(gspca_dev, 0x01, 0x0000, nset, 0x06); 558 test_byte = reg_r(gspca_dev, 0x07);
510 reg_r_1(gspca_dev, 0x0063); 559 if (byte == 0x08 && test_byte == 0x07) {
511 reg_w(gspca_dev, 0x01, 0x0000, n2, 0x02); 560 PDEBUG(D_CONF, "other sensor");
561 sd->sensor = SENSOR_OTHER;
562 } else {
563 PDEBUG(D_CONF, "sensor %02x %02x", byte, test_byte);
564 sd->sensor = SENSOR_TAS5130A;
565 }
566
567 i2c_w(gspca_dev, n1, sizeof n1);
568 test_byte = 0;
569 i = 5;
570 while (--i >= 0) {
571 i2c_w(gspca_dev, nset, sizeof nset);
572 msleep(5);
573 test_byte = reg_r(gspca_dev, 0x0063);
574 msleep(100);
575 if (test_byte == 0x17)
576 break; /* OK */
577 }
578 if (i < 0) {
579 err("Bad sensor reset %02x", test_byte);
580/* return -EIO; */
581/*fixme: test - continue */
582 }
583 i2c_w(gspca_dev, n2, sizeof n2);
512 584
585 i = 0;
513 while (read_indexs[i] != 0x00) { 586 while (read_indexs[i] != 0x00) {
514 test_byte = reg_r_1(gspca_dev, read_indexs[i]); 587 test_byte = reg_r(gspca_dev, read_indexs[i]);
515 PDEBUG(D_CONF, "Reg 0x%02x => 0x%02x", read_indexs[i], 588 PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", read_indexs[i],
516 test_byte); 589 test_byte);
517 i++; 590 i++;
518 } 591 }
519 592
520 reg_w(gspca_dev, 0x01, 0x0000, n3, 0x06); 593 i2c_w(gspca_dev, n3, sizeof n3);
521 reg_w(gspca_dev, 0x01, 0x0000, n4, 0x46); 594 i2c_w(gspca_dev, n4, sizeof n4);
522 reg_r_1(gspca_dev, 0x0080); 595 reg_r(gspca_dev, 0x0080);
523 reg_w(gspca_dev, 0x00, 0x2c80, NULL, 0); 596 reg_w(gspca_dev, 0x2c80);
524 reg_w(gspca_dev, 0x01, 0x0000, nset2, 0x14); 597 i2c_w(gspca_dev, nset2, sizeof nset2);
525 reg_w(gspca_dev, 0x01, 0x0000, nset3, 0x12); 598 i2c_w(gspca_dev, nset3, sizeof nset3);
526 reg_w(gspca_dev, 0x01, 0x0000, nset4, 0x12); 599 i2c_w(gspca_dev, nset4, sizeof nset4);
527 reg_w(gspca_dev, 0x00, 0x3880, NULL, 0); 600 reg_w(gspca_dev, 0x3880);
528 reg_w(gspca_dev, 0x00, 0x3880, NULL, 0); 601 reg_w(gspca_dev, 0x3880);
529 reg_w(gspca_dev, 0x00, 0x338e, NULL, 0); 602 reg_w(gspca_dev, 0x338e);
530 reg_w(gspca_dev, 0x01, 0x0000, nset5, 0x04); 603 i2c_w(gspca_dev, nset5, sizeof nset5);
531 reg_w(gspca_dev, 0x00, 0x00a9, NULL, 0); 604 reg_w(gspca_dev, 0x00a9);
532 reg_w(gspca_dev, 0x01, 0x0000, nset6, 0x22); 605 setgamma(gspca_dev);
533 reg_w(gspca_dev, 0x00, 0x86bb, NULL, 0); 606 reg_w(gspca_dev, 0x86bb);
534 reg_w(gspca_dev, 0x00, 0x4aa6, NULL, 0); 607 reg_w(gspca_dev, 0x4aa6);
535 608
536 reg_w(gspca_dev, 0x01, 0x0000, missing, 0x08); 609 i2c_w(gspca_dev, missing, sizeof missing);
537 610
538 reg_w(gspca_dev, 0x00, 0x2087, NULL, 0); 611 reg_w(gspca_dev, 0x2087);
539 reg_w(gspca_dev, 0x00, 0x2088, NULL, 0); 612 reg_w(gspca_dev, 0x2088);
540 reg_w(gspca_dev, 0x00, 0x2089, NULL, 0); 613 reg_w(gspca_dev, 0x2089);
541 614
542 reg_w(gspca_dev, 0x01, 0x0000, nset7, 0x04); 615 i2c_w(gspca_dev, nset7, sizeof nset7);
543 reg_w(gspca_dev, 0x01, 0x0000, nset10, 0x06); 616 i2c_w(gspca_dev, nset10, sizeof nset10);
544 reg_w(gspca_dev, 0x01, 0x0000, nset8, 0x06); 617 i2c_w(gspca_dev, nset8, sizeof nset8);
545 reg_w(gspca_dev, 0x01, 0x0000, nset9, 0x04); 618 i2c_w(gspca_dev, nset9, sizeof nset9);
546 619
547 reg_w(gspca_dev, 0x00, 0x2880, NULL, 0); 620 reg_w(gspca_dev, 0x2880);
548 reg_w(gspca_dev, 0x01, 0x0000, nset2, 0x14); 621 i2c_w(gspca_dev, nset2, sizeof nset2);
549 reg_w(gspca_dev, 0x01, 0x0000, nset3, 0x12); 622 i2c_w(gspca_dev, nset3, sizeof nset3);
550 reg_w(gspca_dev, 0x01, 0x0000, nset4, 0x12); 623 i2c_w(gspca_dev, nset4, sizeof nset4);
551 624
552 return 0; 625 return 0;
553} 626}
554 627
555/* this function is called at probe and resume time */
556static int sd_init(struct gspca_dev *gspca_dev)
557{
558 init_default_parameters(gspca_dev);
559 return 0;
560}
561
562static void setbrightness(struct gspca_dev *gspca_dev) 628static void setbrightness(struct gspca_dev *gspca_dev)
563{ 629{
564 struct sd *sd = (struct sd *) gspca_dev; 630 struct sd *sd = (struct sd *) gspca_dev;
565 unsigned int brightness; 631 unsigned int brightness;
566 __u8 set6[4] = { 0x8f, 0x26, 0xc3, 0x80 }; 632 __u8 set6[4] = { 0x8f, 0x26, 0xc3, 0x00 };
567 brightness = sd->brightness;
568 633
634 brightness = sd->brightness;
569 if (brightness < 7) { 635 if (brightness < 7) {
570 set6[3] = 0x70 - (brightness * 0xa); 636 set6[3] = 0x70 - brightness * 0x10;
571 } else { 637 } else {
572 set6[1] = 0x24; 638 set6[1] = 0x24;
573 set6[3] = 0x00 + ((brightness - 7) * 0xa); 639 set6[3] = 0x00 + ((brightness - 7) * 0x10);
574 } 640 }
575 641
576 reg_w(gspca_dev, 0x01, 0x0000, set6, 4); 642 i2c_w(gspca_dev, set6, sizeof set6);
577} 643}
578 644
579static void setflip(struct gspca_dev *gspca_dev) 645static void setflip(struct gspca_dev *gspca_dev)
580{ 646{
581 struct sd *sd = (struct sd *) gspca_dev; 647 struct sd *sd = (struct sd *) gspca_dev;
582
583 __u8 flipcmd[8] = 648 __u8 flipcmd[8] =
584 { 0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09 }; 649 {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09};
585 650
586 if (sd->mirror == 1) 651 if (sd->mirror)
587 flipcmd[3] = 0x01; 652 flipcmd[3] = 0x01;
588 653
589 reg_w(gspca_dev, 0x01, 0x0000, flipcmd, 8); 654 i2c_w(gspca_dev, flipcmd, sizeof flipcmd);
590} 655}
591 656
592static void seteffect(struct gspca_dev *gspca_dev) 657static void seteffect(struct gspca_dev *gspca_dev)
593{ 658{
594 struct sd *sd = (struct sd *) gspca_dev; 659 struct sd *sd = (struct sd *) gspca_dev;
595 660
596 reg_w(gspca_dev, 0x01, 0x0000, effects_table[sd->effect], 0x06); 661 i2c_w(gspca_dev, effects_table[sd->effect], sizeof effects_table[0]);
597 if (sd->effect == 1 || sd->effect == 5) { 662 if (sd->effect == 1 || sd->effect == 5) {
598 PDEBUG(D_CONF, 663 PDEBUG(D_CONF,
599 "This effect have been disabled for webcam \"safety\""); 664 "This effect have been disabled for webcam \"safety\"");
@@ -601,9 +666,9 @@ static void seteffect(struct gspca_dev *gspca_dev)
601 } 666 }
602 667
603 if (sd->effect == 1 || sd->effect == 4) 668 if (sd->effect == 1 || sd->effect == 4)
604 reg_w(gspca_dev, 0x00, 0x4aa6, NULL, 0); 669 reg_w(gspca_dev, 0x4aa6);
605 else 670 else
606 reg_w(gspca_dev, 0x00, 0xfaa6, NULL, 0); 671 reg_w(gspca_dev, 0xfaa6);
607} 672}
608 673
609static void setwhitebalance(struct gspca_dev *gspca_dev) 674static void setwhitebalance(struct gspca_dev *gspca_dev)
@@ -616,7 +681,7 @@ static void setwhitebalance(struct gspca_dev *gspca_dev)
616 if (sd->whitebalance == 1) 681 if (sd->whitebalance == 1)
617 white_balance[7] = 0x3c; 682 white_balance[7] = 0x3c;
618 683
619 reg_w(gspca_dev, 0x01, 0x0000, white_balance, 8); 684 i2c_w(gspca_dev, white_balance, sizeof white_balance);
620} 685}
621 686
622static void setlightfreq(struct gspca_dev *gspca_dev) 687static void setlightfreq(struct gspca_dev *gspca_dev)
@@ -627,21 +692,21 @@ static void setlightfreq(struct gspca_dev *gspca_dev)
627 if (sd->freq == 2) /* 60hz */ 692 if (sd->freq == 2) /* 60hz */
628 freq[1] = 0x00; 693 freq[1] = 0x00;
629 694
630 reg_w(gspca_dev, 0x1, 0x0000, freq, 0x4); 695 i2c_w(gspca_dev, freq, sizeof freq);
631} 696}
632 697
633static void setcontrast(struct gspca_dev *gspca_dev) 698static void setcontrast(struct gspca_dev *gspca_dev)
634{ 699{
635 struct sd *sd = (struct sd *) gspca_dev; 700 struct sd *sd = (struct sd *) gspca_dev;
636 unsigned int contrast = sd->contrast; 701 unsigned int contrast = sd->contrast;
637 __u16 reg_to_write = 0x00; 702 __u16 reg_to_write;
638 703
639 if (contrast < 7) 704 if (contrast < 7)
640 reg_to_write = 0x8ea9 - (0x200 * contrast); 705 reg_to_write = 0x8ea9 - (0x200 * contrast);
641 else 706 else
642 reg_to_write = (0x00a9 + ((contrast - 7) * 0x200)); 707 reg_to_write = (0x00a9 + ((contrast - 7) * 0x200));
643 708
644 reg_w(gspca_dev, 0x00, reg_to_write, NULL, 0); 709 reg_w(gspca_dev, reg_to_write);
645} 710}
646 711
647static void setcolors(struct gspca_dev *gspca_dev) 712static void setcolors(struct gspca_dev *gspca_dev)
@@ -650,11 +715,7 @@ static void setcolors(struct gspca_dev *gspca_dev)
650 __u16 reg_to_write; 715 __u16 reg_to_write;
651 716
652 reg_to_write = 0xc0bb + sd->colors * 0x100; 717 reg_to_write = 0xc0bb + sd->colors * 0x100;
653 reg_w(gspca_dev, 0x00, reg_to_write, NULL, 0); 718 reg_w(gspca_dev, reg_to_write);
654}
655
656static void setgamma(struct gspca_dev *gspca_dev)
657{
658} 719}
659 720
660static void setsharpness(struct gspca_dev *gspca_dev) 721static void setsharpness(struct gspca_dev *gspca_dev)
@@ -664,7 +725,99 @@ static void setsharpness(struct gspca_dev *gspca_dev)
664 725
665 reg_to_write = 0x0aa6 + 0x1000 * sd->sharpness; 726 reg_to_write = 0x0aa6 + 0x1000 * sd->sharpness;
666 727
667 reg_w(gspca_dev, 0x00, reg_to_write, NULL, 0); 728 reg_w(gspca_dev, reg_to_write);
729}
730
731static int sd_start(struct gspca_dev *gspca_dev)
732{
733 struct sd *sd = (struct sd *) gspca_dev;
734 int i, mode;
735 static const __u8 t1[] = { 0x66, 0x00, 0xa8, 0xe8 };
736 __u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 };
737 static const __u8 t3[] =
738 { 0xb3, 0x07, 0xb4, 0x00, 0xb5, 0x88, 0xb6, 0x02, 0xb7, 0x06,
739 0xb8, 0x00, 0xb9, 0xe7, 0xba, 0x01 };
740 static const __u8 t4[] = { 0x0b, 0x04, 0x0a, 0x40 };
741
742 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode]. priv;
743 switch (mode) {
744 case 1: /* 352x288 */
745 t2[1] = 0x40;
746 break;
747 case 2: /* 320x240 */
748 t2[1] = 0x10;
749 break;
750 case 3: /* 176x144 */
751 t2[1] = 0x50;
752 break;
753 case 4: /* 160x120 */
754 t2[1] = 0x20;
755 break;
756 default: /* 640x480 (0x00) */
757 break;
758 }
759
760 if (sd->sensor == SENSOR_TAS5130A) {
761 i = 0;
762 while (tas5130a_sensor_init[i][0] != 0) {
763 i2c_w(gspca_dev, tas5130a_sensor_init[i],
764 sizeof tas5130a_sensor_init[0]);
765 i++;
766 }
767 reg_w(gspca_dev, 0x3c80);
768 /* just in case and to keep sync with logs (for mine) */
769 i2c_w(gspca_dev, tas5130a_sensor_init[3],
770 sizeof tas5130a_sensor_init[0]);
771 reg_w(gspca_dev, 0x3c80);
772 } else {
773 other_sensor_init(gspca_dev);
774 }
775 /* just in case and to keep sync with logs (for mine) */
776 i2c_w(gspca_dev, t1, sizeof t1);
777 i2c_w(gspca_dev, t2, sizeof t2);
778 reg_r(gspca_dev, 0x0012);
779 i2c_w(gspca_dev, t3, sizeof t3);
780 reg_w(gspca_dev, 0x0013);
781 i2c_w(gspca_dev, t4, sizeof t4);
782 /* restart on each start, just in case, sometimes regs goes wrong
783 * when using controls from app */
784 setbrightness(gspca_dev);
785 setcontrast(gspca_dev);
786 setcolors(gspca_dev);
787 return 0;
788}
789
790static void sd_pkt_scan(struct gspca_dev *gspca_dev,
791 struct gspca_frame *frame, /* target */
792 __u8 *data, /* isoc packet */
793 int len) /* iso packet length */
794{
795 static __u8 ffd9[] = { 0xff, 0xd9 };
796
797 if (data[0] == 0x5a) {
798 /* Control Packet, after this came the header again,
799 * but extra bytes came in the packet before this,
800 * sometimes an EOF arrives, sometimes not... */
801 return;
802 }
803 data += 2;
804 len -= 2;
805 if (data[0] == 0xff && data[1] == 0xd8) {
806 /* extra bytes....., could be processed too but would be
807 * a waste of time, right now leave the application and
808 * libjpeg do it for ourserlves.. */
809 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
810 ffd9, 2);
811 gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, len);
812 return;
813 }
814
815 if (data[len - 2] == 0xff && data[len - 1] == 0xd9) {
816 /* Just in case, i have seen packets with the marker,
817 * other's do not include it... */
818 len -= 2;
819 }
820 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
668} 821}
669 822
670static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) 823static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
@@ -788,6 +941,7 @@ static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
788static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val) 941static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
789{ 942{
790 struct sd *sd = (struct sd *) gspca_dev; 943 struct sd *sd = (struct sd *) gspca_dev;
944
791 *val = sd->gamma; 945 *val = sd->gamma;
792 return 0; 946 return 0;
793} 947}
@@ -835,9 +989,9 @@ static int sd_setlowlight(struct gspca_dev *gspca_dev, __s32 val)
835 989
836 sd->autogain = val; 990 sd->autogain = val;
837 if (val != 0) 991 if (val != 0)
838 reg_w(gspca_dev, 0x00, 0xf48e, NULL, 0); 992 reg_w(gspca_dev, 0xf48e);
839 else 993 else
840 reg_w(gspca_dev, 0x00, 0xb48e, NULL, 0); 994 reg_w(gspca_dev, 0xb48e);
841 return 0; 995 return 0;
842} 996}
843 997
@@ -849,99 +1003,6 @@ static int sd_getlowlight(struct gspca_dev *gspca_dev, __s32 *val)
849 return 0; 1003 return 0;
850} 1004}
851 1005
852static void sd_start(struct gspca_dev *gspca_dev)
853{
854 int mode;
855
856 static const __u8 t1[] = { 0x66, 0x00, 0xa8, 0xe8 };
857 __u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 };
858 static const __u8 t3[] =
859 { 0xb3, 0x07, 0xb4, 0x00, 0xb5, 0x88, 0xb6, 0x02, 0xb7, 0x06,
860 0xb8, 0x00, 0xb9, 0xe7, 0xba, 0x01 };
861 static const __u8 t4[] = { 0x0b, 0x04, 0x0a, 0x40 };
862
863 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode]. priv;
864 switch (mode) {
865 case 1: /* 352x288 */
866 t2[1] = 0x40;
867 break;
868 case 2: /* 320x240 */
869 t2[1] = 0x10;
870 break;
871 case 3: /* 176x144 */
872 t2[1] = 0x50;
873 break;
874 case 4: /* 160x120 */
875 t2[1] = 0x20;
876 break;
877 default: /* 640x480 (0x00) */
878 break;
879 }
880
881 reg_w(gspca_dev, 0x01, 0x0000, tas5130a_sensor_init[0], 0x8);
882 reg_w(gspca_dev, 0x01, 0x0000, tas5130a_sensor_init[1], 0x8);
883 reg_w(gspca_dev, 0x01, 0x0000, tas5130a_sensor_init[2], 0x8);
884 reg_w(gspca_dev, 0x01, 0x0000, tas5130a_sensor_init[3], 0x8);
885 reg_w(gspca_dev, 0x00, 0x3c80, NULL, 0);
886 /* just in case and to keep sync with logs (for mine) */
887 reg_w(gspca_dev, 0x01, 0x0000, tas5130a_sensor_init[3], 0x8);
888 reg_w(gspca_dev, 0x00, 0x3c80, NULL, 0);
889 /* just in case and to keep sync with logs (for mine) */
890 reg_w(gspca_dev, 0x01, 0x0000, t1, 4);
891 reg_w(gspca_dev, 0x01, 0x0000, t2, 6);
892 reg_r_1(gspca_dev, 0x0012);
893 reg_w(gspca_dev, 0x01, 0x0000, t3, 0x10);
894 reg_w(gspca_dev, 0x00, 0x0013, NULL, 0);
895 reg_w(gspca_dev, 0x01, 0x0000, t4, 0x4);
896 /* restart on each start, just in case, sometimes regs goes wrong
897 * when using controls from app */
898 setbrightness(gspca_dev);
899 setcontrast(gspca_dev);
900 setcolors(gspca_dev);
901}
902
903static void sd_pkt_scan(struct gspca_dev *gspca_dev,
904 struct gspca_frame *frame, /* target */
905 __u8 *data, /* isoc packet */
906 int len) /* iso packet length */
907{
908 int sof = 0;
909 static __u8 ffd9[] = { 0xff, 0xd9 };
910
911 if (data[0] == 0x5a) {
912 /* Control Packet, after this came the header again,
913 * but extra bytes came in the packet before this,
914 * sometimes an EOF arrives, sometimes not... */
915 return;
916 }
917
918 if (data[len - 1] == 0xff && data[len] == 0xd9) {
919 /* Just in case, i have seen packets with the marker,
920 * other's do not include it... */
921 data += 2;
922 len -= 4;
923 } else if (data[2] == 0xff && data[3] == 0xd8) {
924 sof = 1;
925 data += 2;
926 len -= 2;
927 } else {
928 data += 2;
929 len -= 2;
930 }
931
932 if (sof) {
933 /* extra bytes....., could be processed too but would be
934 * a waste of time, right now leave the application and
935 * libjpeg do it for ourserlves.. */
936 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
937 ffd9, 2);
938 gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, len);
939 return;
940 }
941
942 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
943}
944
945static int sd_querymenu(struct gspca_dev *gspca_dev, 1006static int sd_querymenu(struct gspca_dev *gspca_dev,
946 struct v4l2_querymenu *menu) 1007 struct v4l2_querymenu *menu)
947{ 1008{
diff --git a/drivers/media/video/gspca/tv8532.c b/drivers/media/video/gspca/tv8532.c
index 084af05302a0..968a5911704f 100644
--- a/drivers/media/video/gspca/tv8532.c
+++ b/drivers/media/video/gspca/tv8532.c
@@ -390,7 +390,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
390} 390}
391 391
392/* -- start the camera -- */ 392/* -- start the camera -- */
393static void sd_start(struct gspca_dev *gspca_dev) 393static int sd_start(struct gspca_dev *gspca_dev)
394{ 394{
395 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x32); 395 reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x32);
396 reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x00); 396 reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x00);
@@ -443,6 +443,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
443 /************************************************/ 443 /************************************************/
444 tv_8532_PollReg(gspca_dev); 444 tv_8532_PollReg(gspca_dev);
445 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00); /* 0x31 */ 445 reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00); /* 0x31 */
446 return 0;
446} 447}
447 448
448static void sd_stopN(struct gspca_dev *gspca_dev) 449static void sd_stopN(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/vc032x.c b/drivers/media/video/gspca/vc032x.c
index bd4c226c9a07..be46d9232540 100644
--- a/drivers/media/video/gspca/vc032x.c
+++ b/drivers/media/video/gspca/vc032x.c
@@ -80,7 +80,6 @@ static struct ctrl sd_ctrls[] = {
80 .step = 1, 80 .step = 1,
81#define FREQ_DEF 1 81#define FREQ_DEF 1
82 .default_value = FREQ_DEF, 82 .default_value = FREQ_DEF,
83 .default_value = 1,
84 }, 83 },
85 .set = sd_setfreq, 84 .set = sd_setfreq,
86 .get = sd_getfreq, 85 .get = sd_getfreq,
@@ -1502,7 +1501,7 @@ static void setlightfreq(struct gspca_dev *gspca_dev)
1502 usb_exchange(gspca_dev, ov7660_freq_tb[sd->lightfreq]); 1501 usb_exchange(gspca_dev, ov7660_freq_tb[sd->lightfreq]);
1503} 1502}
1504 1503
1505static void sd_start(struct gspca_dev *gspca_dev) 1504static int sd_start(struct gspca_dev *gspca_dev)
1506{ 1505{
1507 struct sd *sd = (struct sd *) gspca_dev; 1506 struct sd *sd = (struct sd *) gspca_dev;
1508 const __u8 *GammaT = NULL; 1507 const __u8 *GammaT = NULL;
@@ -1586,7 +1585,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
1586 break; 1585 break;
1587 default: 1586 default:
1588 PDEBUG(D_PROBE, "Damned !! no sensor found Bye"); 1587 PDEBUG(D_PROBE, "Damned !! no sensor found Bye");
1589 return; 1588 return -EMEDIUMTYPE;
1590 } 1589 }
1591 if (GammaT && MatrixT) { 1590 if (GammaT && MatrixT) {
1592 put_tab_to_reg(gspca_dev, GammaT, 17, 0xb84a); 1591 put_tab_to_reg(gspca_dev, GammaT, 17, 0xb84a);
@@ -1622,6 +1621,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
1622 setautogain(gspca_dev); 1621 setautogain(gspca_dev);
1623 setlightfreq(gspca_dev); 1622 setlightfreq(gspca_dev);
1624 } 1623 }
1624 return 0;
1625} 1625}
1626 1626
1627static void sd_stopN(struct gspca_dev *gspca_dev) 1627static void sd_stopN(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/zc3xx.c b/drivers/media/video/gspca/zc3xx.c
index d61ef727e0c2..d0a4451dc46f 100644
--- a/drivers/media/video/gspca/zc3xx.c
+++ b/drivers/media/video/gspca/zc3xx.c
@@ -7178,7 +7178,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
7178 return 0; 7178 return 0;
7179} 7179}
7180 7180
7181static void sd_start(struct gspca_dev *gspca_dev) 7181static int sd_start(struct gspca_dev *gspca_dev)
7182{ 7182{
7183 struct sd *sd = (struct sd *) gspca_dev; 7183 struct sd *sd = (struct sd *) gspca_dev;
7184 struct usb_device *dev = gspca_dev->dev; 7184 struct usb_device *dev = gspca_dev->dev;
@@ -7331,6 +7331,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
7331 reg_w(dev, 0x02, 0x0008); 7331 reg_w(dev, 0x02, 0x0008);
7332 break; 7332 break;
7333 } 7333 }
7334 return 0;
7334} 7335}
7335 7336
7336static void sd_stop0(struct gspca_dev *gspca_dev) 7337static void sd_stop0(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index a30254bed311..efe849981ab7 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -12,6 +12,10 @@
12 * Markus Rechberger <mrechberger@gmail.com> 12 * Markus Rechberger <mrechberger@gmail.com>
13 * modified for DViCO Fusion HDTV 5 RT GOLD by 13 * modified for DViCO Fusion HDTV 5 RT GOLD by
14 * Chaogui Zhang <czhang1974@gmail.com> 14 * Chaogui Zhang <czhang1974@gmail.com>
15 * modified for MSI TV@nywhere Plus by
16 * Henry Wong <henry@stuffedcow.net>
17 * Mark Schultz <n9xmj@yahoo.com>
18 * Brian Rogers <brian_rogers@comcast.net>
15 * 19 *
16 * This program is free software; you can redistribute it and/or modify 20 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by 21 * it under the terms of the GNU General Public License as published by
@@ -65,7 +69,7 @@ static int get_key_haup_common(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
65 int size, int offset) 69 int size, int offset)
66{ 70{
67 unsigned char buf[6]; 71 unsigned char buf[6];
68 int start, range, toggle, dev, code; 72 int start, range, toggle, dev, code, ircode;
69 73
70 /* poll IR chip */ 74 /* poll IR chip */
71 if (size != i2c_master_recv(&ir->c,buf,size)) 75 if (size != i2c_master_recv(&ir->c,buf,size))
@@ -85,6 +89,24 @@ static int get_key_haup_common(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
85 if (!start) 89 if (!start)
86 /* no key pressed */ 90 /* no key pressed */
87 return 0; 91 return 0;
92 /*
93 * Hauppauge remotes (black/silver) always use
94 * specific device ids. If we do not filter the
95 * device ids then messages destined for devices
96 * such as TVs (id=0) will get through causing
97 * mis-fired events.
98 *
99 * We also filter out invalid key presses which
100 * produce annoying debug log entries.
101 */
102 ircode= (start << 12) | (toggle << 11) | (dev << 6) | code;
103 if ((ircode & 0x1fff)==0x1fff)
104 /* invalid key press */
105 return 0;
106
107 if (dev!=0x1e && dev!=0x1f)
108 /* not a hauppauge remote */
109 return 0;
88 110
89 if (!range) 111 if (!range)
90 code += 64; 112 code += 64;
@@ -94,7 +116,7 @@ static int get_key_haup_common(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
94 116
95 /* return key */ 117 /* return key */
96 *ir_key = code; 118 *ir_key = code;
97 *ir_raw = (start << 12) | (toggle << 11) | (dev << 6) | code; 119 *ir_raw = ircode;
98 return 1; 120 return 1;
99} 121}
100 122
@@ -224,9 +246,15 @@ static void ir_timer(unsigned long data)
224static void ir_work(struct work_struct *work) 246static void ir_work(struct work_struct *work)
225{ 247{
226 struct IR_i2c *ir = container_of(work, struct IR_i2c, work); 248 struct IR_i2c *ir = container_of(work, struct IR_i2c, work);
249 int polling_interval = 100;
250
251 /* MSI TV@nywhere Plus requires more frequent polling
252 otherwise it will miss some keypresses */
253 if (ir->c.adapter->id == I2C_HW_SAA7134 && ir->c.addr == 0x30)
254 polling_interval = 50;
227 255
228 ir_key_poll(ir); 256 ir_key_poll(ir);
229 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(100)); 257 mod_timer(&ir->timer, jiffies + msecs_to_jiffies(polling_interval));
230} 258}
231 259
232/* ----------------------------------------------------------------------- */ 260/* ----------------------------------------------------------------------- */
@@ -465,9 +493,37 @@ static int ir_probe(struct i2c_adapter *adap)
465 (1 == rc) ? "yes" : "no"); 493 (1 == rc) ? "yes" : "no");
466 if (1 == rc) { 494 if (1 == rc) {
467 ir_attach(adap, probe[i], 0, 0); 495 ir_attach(adap, probe[i], 0, 0);
468 break; 496 return 0;
469 } 497 }
470 } 498 }
499
500 /* Special case for MSI TV@nywhere Plus remote */
501 if (adap->id == I2C_HW_SAA7134) {
502 u8 temp;
503
504 /* MSI TV@nywhere Plus controller doesn't seem to
505 respond to probes unless we read something from
506 an existing device. Weird... */
507
508 msg.addr = 0x50;
509 rc = i2c_transfer(adap, &msg, 1);
510 dprintk(1, "probe 0x%02x @ %s: %s\n",
511 msg.addr, adap->name,
512 (1 == rc) ? "yes" : "no");
513
514 /* Now do the probe. The controller does not respond
515 to 0-byte reads, so we use a 1-byte read instead. */
516 msg.addr = 0x30;
517 msg.len = 1;
518 msg.buf = &temp;
519 rc = i2c_transfer(adap, &msg, 1);
520 dprintk(1, "probe 0x%02x @ %s: %s\n",
521 msg.addr, adap->name,
522 (1 == rc) ? "yes" : "no");
523 if (1 == rc)
524 ir_attach(adap, msg.addr, 0, 0);
525 }
526
471 return 0; 527 return 0;
472} 528}
473 529
diff --git a/drivers/media/video/ivtv/ivtv-cards.h b/drivers/media/video/ivtv/ivtv-cards.h
index 381af1bceef8..0b8fe85fb697 100644
--- a/drivers/media/video/ivtv/ivtv-cards.h
+++ b/drivers/media/video/ivtv/ivtv-cards.h
@@ -154,7 +154,7 @@
154#define IVTV_CAP_ENCODER (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TUNER | \ 154#define IVTV_CAP_ENCODER (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TUNER | \
155 V4L2_CAP_AUDIO | V4L2_CAP_READWRITE | V4L2_CAP_VBI_CAPTURE | \ 155 V4L2_CAP_AUDIO | V4L2_CAP_READWRITE | V4L2_CAP_VBI_CAPTURE | \
156 V4L2_CAP_SLICED_VBI_CAPTURE) 156 V4L2_CAP_SLICED_VBI_CAPTURE)
157#define IVTV_CAP_DECODER (V4L2_CAP_VBI_OUTPUT | V4L2_CAP_VIDEO_OUTPUT | \ 157#define IVTV_CAP_DECODER (V4L2_CAP_VIDEO_OUTPUT | \
158 V4L2_CAP_SLICED_VBI_OUTPUT | V4L2_CAP_VIDEO_OUTPUT_OVERLAY) 158 V4L2_CAP_SLICED_VBI_OUTPUT | V4L2_CAP_VIDEO_OUTPUT_OVERLAY)
159 159
160struct ivtv_card_video_input { 160struct ivtv_card_video_input {
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index 4afc7ea07e86..aeaa13f6cb36 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -61,14 +61,14 @@
61#include "tuner-xc2028.h" 61#include "tuner-xc2028.h"
62 62
63/* var to keep track of the number of array elements in use */ 63/* var to keep track of the number of array elements in use */
64int ivtv_cards_active = 0; 64int ivtv_cards_active;
65 65
66/* If you have already X v4l cards, then set this to X. This way 66/* If you have already X v4l cards, then set this to X. This way
67 the device numbers stay matched. Example: you have a WinTV card 67 the device numbers stay matched. Example: you have a WinTV card
68 without radio and a PVR-350 with. Normally this would give a 68 without radio and a PVR-350 with. Normally this would give a
69 video1 device together with a radio0 device for the PVR. By 69 video1 device together with a radio0 device for the PVR. By
70 setting this to 1 you ensure that radio0 is now also radio1. */ 70 setting this to 1 you ensure that radio0 is now also radio1. */
71int ivtv_first_minor = 0; 71int ivtv_first_minor;
72 72
73/* Master variable for all ivtv info */ 73/* Master variable for all ivtv info */
74struct ivtv *ivtv_cards[IVTV_MAX_CARDS]; 74struct ivtv *ivtv_cards[IVTV_MAX_CARDS];
@@ -251,7 +251,7 @@ MODULE_PARM_DESC(newi2c,
251 "\t\t\t-1 is autodetect, 0 is off, 1 is on\n" 251 "\t\t\t-1 is autodetect, 0 is off, 1 is on\n"
252 "\t\t\tDefault is autodetect"); 252 "\t\t\tDefault is autodetect");
253 253
254MODULE_PARM_DESC(ivtv_first_minor, "Set minor assigned to first card"); 254MODULE_PARM_DESC(ivtv_first_minor, "Set kernel number assigned to first card");
255 255
256MODULE_AUTHOR("Kevin Thayer, Chris Kennedy, Hans Verkuil"); 256MODULE_AUTHOR("Kevin Thayer, Chris Kennedy, Hans Verkuil");
257MODULE_DESCRIPTION("CX23415/CX23416 driver"); 257MODULE_DESCRIPTION("CX23415/CX23416 driver");
@@ -655,9 +655,9 @@ done:
655 655
656 if (itv->card == NULL) { 656 if (itv->card == NULL) {
657 itv->card = ivtv_get_card(IVTV_CARD_PVR_150); 657 itv->card = ivtv_get_card(IVTV_CARD_PVR_150);
658 IVTV_ERR("Unknown card: vendor/device: %04x/%04x\n", 658 IVTV_ERR("Unknown card: vendor/device: [%04x:%04x]\n",
659 itv->dev->vendor, itv->dev->device); 659 itv->dev->vendor, itv->dev->device);
660 IVTV_ERR(" subsystem vendor/device: %04x/%04x\n", 660 IVTV_ERR(" subsystem vendor/device: [%04x:%04x]\n",
661 itv->dev->subsystem_vendor, itv->dev->subsystem_device); 661 itv->dev->subsystem_vendor, itv->dev->subsystem_device);
662 IVTV_ERR(" %s based\n", chipname); 662 IVTV_ERR(" %s based\n", chipname);
663 IVTV_ERR("Defaulting to %s card\n", itv->card->name); 663 IVTV_ERR("Defaulting to %s card\n", itv->card->name);
@@ -720,7 +720,7 @@ static int __devinit ivtv_init_struct1(struct ivtv *itv)
720 itv->speed = 1000; 720 itv->speed = 1000;
721 721
722 /* VBI */ 722 /* VBI */
723 itv->vbi.in.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE; 723 itv->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
724 itv->vbi.sliced_in = &itv->vbi.in.fmt.sliced; 724 itv->vbi.sliced_in = &itv->vbi.in.fmt.sliced;
725 725
726 /* Init the sg table for osd/yuv output */ 726 /* Init the sg table for osd/yuv output */
diff --git a/drivers/media/video/ivtv/ivtv-driver.h b/drivers/media/video/ivtv/ivtv-driver.h
index 2ceb5227637c..bc29436e8a3c 100644
--- a/drivers/media/video/ivtv/ivtv-driver.h
+++ b/drivers/media/video/ivtv/ivtv-driver.h
@@ -49,7 +49,6 @@
49#include <linux/i2c-algo-bit.h> 49#include <linux/i2c-algo-bit.h>
50#include <linux/list.h> 50#include <linux/list.h>
51#include <linux/unistd.h> 51#include <linux/unistd.h>
52#include <linux/byteorder/swab.h>
53#include <linux/pagemap.h> 52#include <linux/pagemap.h>
54#include <linux/scatterlist.h> 53#include <linux/scatterlist.h>
55#include <linux/workqueue.h> 54#include <linux/workqueue.h>
@@ -507,6 +506,8 @@ struct yuv_playback_info
507 struct v4l2_rect main_rect; 506 struct v4l2_rect main_rect;
508 u32 v4l2_src_w; 507 u32 v4l2_src_w;
509 u32 v4l2_src_h; 508 u32 v4l2_src_h;
509
510 u8 running; /* Have any frames been displayed */
510}; 511};
511 512
512#define IVTV_VBI_FRAMES 32 513#define IVTV_VBI_FRAMES 32
@@ -751,6 +752,12 @@ void ivtv_read_eeprom(struct ivtv *itv, struct tveeprom *tv);
751/* First-open initialization: load firmware, init cx25840, etc. */ 752/* First-open initialization: load firmware, init cx25840, etc. */
752int ivtv_init_on_first_open(struct ivtv *itv); 753int ivtv_init_on_first_open(struct ivtv *itv);
753 754
755/* Test if the current VBI mode is raw (1) or sliced (0) */
756static inline int ivtv_raw_vbi(const struct ivtv *itv)
757{
758 return itv->vbi.in.type == V4L2_BUF_TYPE_VBI_CAPTURE;
759}
760
754/* This is a PCI post thing, where if the pci register is not read, then 761/* This is a PCI post thing, where if the pci register is not read, then
755 the write doesn't always take effect right away. By reading back the 762 the write doesn't always take effect right away. By reading back the
756 register any pending PCI writes will be performed (in order), and so 763 register any pending PCI writes will be performed (in order), and so
diff --git a/drivers/media/video/ivtv/ivtv-fileops.c b/drivers/media/video/ivtv/ivtv-fileops.c
index 7ec5c99f9ad1..b7457fc60ba5 100644
--- a/drivers/media/video/ivtv/ivtv-fileops.c
+++ b/drivers/media/video/ivtv/ivtv-fileops.c
@@ -39,7 +39,7 @@
39 associated VBI streams are also automatically claimed. 39 associated VBI streams are also automatically claimed.
40 Possible error returns: -EBUSY if someone else has claimed 40 Possible error returns: -EBUSY if someone else has claimed
41 the stream or 0 on success. */ 41 the stream or 0 on success. */
42int ivtv_claim_stream(struct ivtv_open_id *id, int type) 42static int ivtv_claim_stream(struct ivtv_open_id *id, int type)
43{ 43{
44 struct ivtv *itv = id->itv; 44 struct ivtv *itv = id->itv;
45 struct ivtv_stream *s = &itv->streams[type]; 45 struct ivtv_stream *s = &itv->streams[type];
@@ -78,7 +78,7 @@ int ivtv_claim_stream(struct ivtv_open_id *id, int type)
78 if (type == IVTV_DEC_STREAM_TYPE_MPG) { 78 if (type == IVTV_DEC_STREAM_TYPE_MPG) {
79 vbi_type = IVTV_DEC_STREAM_TYPE_VBI; 79 vbi_type = IVTV_DEC_STREAM_TYPE_VBI;
80 } else if (type == IVTV_ENC_STREAM_TYPE_MPG && 80 } else if (type == IVTV_ENC_STREAM_TYPE_MPG &&
81 itv->vbi.insert_mpeg && itv->vbi.sliced_in->service_set) { 81 itv->vbi.insert_mpeg && !ivtv_raw_vbi(itv)) {
82 vbi_type = IVTV_ENC_STREAM_TYPE_VBI; 82 vbi_type = IVTV_ENC_STREAM_TYPE_VBI;
83 } else { 83 } else {
84 return 0; 84 return 0;
@@ -305,7 +305,7 @@ static size_t ivtv_copy_buf_to_user(struct ivtv_stream *s, struct ivtv_buffer *b
305 305
306 if (len > ucount) len = ucount; 306 if (len > ucount) len = ucount;
307 if (itv->vbi.insert_mpeg && s->type == IVTV_ENC_STREAM_TYPE_MPG && 307 if (itv->vbi.insert_mpeg && s->type == IVTV_ENC_STREAM_TYPE_MPG &&
308 itv->vbi.sliced_in->service_set && buf != &itv->vbi.sliced_mpeg_buf) { 308 !ivtv_raw_vbi(itv) && buf != &itv->vbi.sliced_mpeg_buf) {
309 const char *start = buf->buf + buf->readpos; 309 const char *start = buf->buf + buf->readpos;
310 const char *p = start + 1; 310 const char *p = start + 1;
311 const u8 *q; 311 const u8 *q;
@@ -372,7 +372,7 @@ static ssize_t ivtv_read(struct ivtv_stream *s, char __user *ubuf, size_t tot_co
372 /* Each VBI buffer is one frame, the v4l2 API says that for VBI the frames should 372 /* Each VBI buffer is one frame, the v4l2 API says that for VBI the frames should
373 arrive one-by-one, so make sure we never output more than one VBI frame at a time */ 373 arrive one-by-one, so make sure we never output more than one VBI frame at a time */
374 if (s->type == IVTV_DEC_STREAM_TYPE_VBI || 374 if (s->type == IVTV_DEC_STREAM_TYPE_VBI ||
375 (s->type == IVTV_ENC_STREAM_TYPE_VBI && itv->vbi.sliced_in->service_set)) 375 (s->type == IVTV_ENC_STREAM_TYPE_VBI && !ivtv_raw_vbi(itv)))
376 single_frame = 1; 376 single_frame = 1;
377 377
378 for (;;) { 378 for (;;) {
diff --git a/drivers/media/video/ivtv/ivtv-fileops.h b/drivers/media/video/ivtv/ivtv-fileops.h
index 2c8d5186c9c3..df81e790147f 100644
--- a/drivers/media/video/ivtv/ivtv-fileops.h
+++ b/drivers/media/video/ivtv/ivtv-fileops.h
@@ -38,11 +38,6 @@ void ivtv_unmute(struct ivtv *itv);
38 38
39/* Utilities */ 39/* Utilities */
40 40
41/* Try to claim a stream for the filehandle. Return 0 on success,
42 -EBUSY if stream already claimed. Once a stream is claimed, it
43 remains claimed until the associated filehandle is closed. */
44int ivtv_claim_stream(struct ivtv_open_id *id, int type);
45
46/* Release a previously claimed stream. */ 41/* Release a previously claimed stream. */
47void ivtv_release_stream(struct ivtv_stream *s); 42void ivtv_release_stream(struct ivtv_stream *s);
48 43
diff --git a/drivers/media/video/ivtv/ivtv-gpio.c b/drivers/media/video/ivtv/ivtv-gpio.c
index bc22905ea20f..74a44844ccaf 100644
--- a/drivers/media/video/ivtv/ivtv-gpio.c
+++ b/drivers/media/video/ivtv/ivtv-gpio.c
@@ -124,7 +124,7 @@ void ivtv_reset_ir_gpio(struct ivtv *itv)
124} 124}
125 125
126/* Xceive tuner reset function */ 126/* Xceive tuner reset function */
127int ivtv_reset_tuner_gpio(void *dev, int cmd, int value) 127int ivtv_reset_tuner_gpio(void *dev, int component, int cmd, int value)
128{ 128{
129 struct i2c_algo_bit_data *algo = dev; 129 struct i2c_algo_bit_data *algo = dev;
130 struct ivtv *itv = algo->data; 130 struct ivtv *itv = algo->data;
diff --git a/drivers/media/video/ivtv/ivtv-gpio.h b/drivers/media/video/ivtv/ivtv-gpio.h
index 964a265d91a9..48b6291613a2 100644
--- a/drivers/media/video/ivtv/ivtv-gpio.h
+++ b/drivers/media/video/ivtv/ivtv-gpio.h
@@ -24,7 +24,7 @@
24/* GPIO stuff */ 24/* GPIO stuff */
25void ivtv_gpio_init(struct ivtv *itv); 25void ivtv_gpio_init(struct ivtv *itv);
26void ivtv_reset_ir_gpio(struct ivtv *itv); 26void ivtv_reset_ir_gpio(struct ivtv *itv);
27int ivtv_reset_tuner_gpio(void *dev, int cmd, int value); 27int ivtv_reset_tuner_gpio(void *dev, int component, int cmd, int value);
28int ivtv_gpio(struct ivtv *itv, unsigned int command, void *arg); 28int ivtv_gpio(struct ivtv *itv, unsigned int command, void *arg);
29 29
30#endif 30#endif
diff --git a/drivers/media/video/ivtv/ivtv-i2c.c b/drivers/media/video/ivtv/ivtv-i2c.c
index af154238fb9a..24700c211d52 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.c
+++ b/drivers/media/video/ivtv/ivtv-i2c.c
@@ -64,8 +64,6 @@
64#include "ivtv-gpio.h" 64#include "ivtv-gpio.h"
65#include "ivtv-i2c.h" 65#include "ivtv-i2c.h"
66 66
67#include <media/ir-kbd-i2c.h>
68
69/* i2c implementation for cx23415/6 chip, ivtv project. 67/* i2c implementation for cx23415/6 chip, ivtv project.
70 * Author: Kevin Thayer (nufan_wfk at yahoo.com) 68 * Author: Kevin Thayer (nufan_wfk at yahoo.com)
71 */ 69 */
diff --git a/drivers/media/video/ivtv/ivtv-ioctl.c b/drivers/media/video/ivtv/ivtv-ioctl.c
index 61030309d0ad..8696527ab134 100644
--- a/drivers/media/video/ivtv/ivtv-ioctl.c
+++ b/drivers/media/video/ivtv/ivtv-ioctl.c
@@ -101,18 +101,15 @@ void ivtv_expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
101 } 101 }
102} 102}
103 103
104static int check_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal) 104static void check_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
105{ 105{
106 int f, l; 106 int f, l;
107 u16 set = 0;
108 107
109 for (f = 0; f < 2; f++) { 108 for (f = 0; f < 2; f++) {
110 for (l = 0; l < 24; l++) { 109 for (l = 0; l < 24; l++) {
111 fmt->service_lines[f][l] = select_service_from_set(f, l, fmt->service_lines[f][l], is_pal); 110 fmt->service_lines[f][l] = select_service_from_set(f, l, fmt->service_lines[f][l], is_pal);
112 set |= fmt->service_lines[f][l];
113 } 111 }
114 } 112 }
115 return set != 0;
116} 113}
117 114
118u16 ivtv_get_service_set(struct v4l2_sliced_vbi_format *fmt) 115u16 ivtv_get_service_set(struct v4l2_sliced_vbi_format *fmt)
@@ -474,7 +471,7 @@ static int ivtv_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format
474 int h = fmt->fmt.pix.height; 471 int h = fmt->fmt.pix.height;
475 472
476 w = min(w, 720); 473 w = min(w, 720);
477 w = max(w, 1); 474 w = max(w, 2);
478 h = min(h, itv->is_50hz ? 576 : 480); 475 h = min(h, itv->is_50hz ? 576 : 480);
479 h = max(h, 2); 476 h = max(h, 2);
480 ivtv_g_fmt_vid_cap(file, fh, fmt); 477 ivtv_g_fmt_vid_cap(file, fh, fmt);
@@ -512,27 +509,20 @@ static int ivtv_try_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_
512static int ivtv_try_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *fmt) 509static int ivtv_try_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *fmt)
513{ 510{
514 struct ivtv_open_id *id = fh; 511 struct ivtv_open_id *id = fh;
515 s32 w, h; 512 struct ivtv *itv = id->itv;
516 int field; 513 s32 w = fmt->fmt.pix.width;
517 int ret; 514 s32 h = fmt->fmt.pix.height;
515 int field = fmt->fmt.pix.field;
516 int ret = ivtv_g_fmt_vid_out(file, fh, fmt);
518 517
519 w = fmt->fmt.pix.width; 518 w = min(w, 720);
520 h = fmt->fmt.pix.height; 519 w = max(w, 2);
521 field = fmt->fmt.pix.field; 520 h = min(h, itv->is_out_50hz ? 576 : 480);
522 ret = ivtv_g_fmt_vid_out(file, fh, fmt); 521 h = max(h, 2);
522 if (id->type == IVTV_DEC_STREAM_TYPE_YUV)
523 fmt->fmt.pix.field = field;
523 fmt->fmt.pix.width = w; 524 fmt->fmt.pix.width = w;
524 fmt->fmt.pix.height = h; 525 fmt->fmt.pix.height = h;
525 if (!ret && id->type == IVTV_DEC_STREAM_TYPE_YUV) {
526 fmt->fmt.pix.field = field;
527 if (fmt->fmt.pix.width < 2)
528 fmt->fmt.pix.width = 2;
529 if (fmt->fmt.pix.width > 720)
530 fmt->fmt.pix.width = 720;
531 if (fmt->fmt.pix.height < 2)
532 fmt->fmt.pix.height = 2;
533 if (fmt->fmt.pix.height > 576)
534 fmt->fmt.pix.height = 576;
535 }
536 return ret; 526 return ret;
537} 527}
538 528
@@ -560,9 +550,9 @@ static int ivtv_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f
560 struct ivtv_open_id *id = fh; 550 struct ivtv_open_id *id = fh;
561 struct ivtv *itv = id->itv; 551 struct ivtv *itv = id->itv;
562 struct cx2341x_mpeg_params *p = &itv->params; 552 struct cx2341x_mpeg_params *p = &itv->params;
553 int ret = ivtv_try_fmt_vid_cap(file, fh, fmt);
563 int w = fmt->fmt.pix.width; 554 int w = fmt->fmt.pix.width;
564 int h = fmt->fmt.pix.height; 555 int h = fmt->fmt.pix.height;
565 int ret = ivtv_try_fmt_vid_cap(file, fh, fmt);
566 556
567 if (ret) 557 if (ret)
568 return ret; 558 return ret;
@@ -585,8 +575,11 @@ static int ivtv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f
585{ 575{
586 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv; 576 struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
587 577
578 if (!ivtv_raw_vbi(itv) && atomic_read(&itv->capturing) > 0)
579 return -EBUSY;
588 itv->vbi.sliced_in->service_set = 0; 580 itv->vbi.sliced_in->service_set = 0;
589 itv->video_dec_func(itv, VIDIOC_S_FMT, &itv->vbi.in); 581 itv->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
582 itv->video_dec_func(itv, VIDIOC_S_FMT, fmt);
590 return ivtv_g_fmt_vbi_cap(file, fh, fmt); 583 return ivtv_g_fmt_vbi_cap(file, fh, fmt);
591} 584}
592 585
@@ -600,10 +593,10 @@ static int ivtv_s_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_fo
600 if (ret || id->type == IVTV_DEC_STREAM_TYPE_VBI) 593 if (ret || id->type == IVTV_DEC_STREAM_TYPE_VBI)
601 return ret; 594 return ret;
602 595
603 if (check_service_set(vbifmt, itv->is_50hz) == 0) 596 check_service_set(vbifmt, itv->is_50hz);
604 return -EINVAL; 597 if (ivtv_raw_vbi(itv) && atomic_read(&itv->capturing) > 0)
605 if (atomic_read(&itv->capturing) > 0)
606 return -EBUSY; 598 return -EBUSY;
599 itv->vbi.in.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
607 itv->video_dec_func(itv, VIDIOC_S_FMT, fmt); 600 itv->video_dec_func(itv, VIDIOC_S_FMT, fmt);
608 memcpy(itv->vbi.sliced_in, vbifmt, sizeof(*itv->vbi.sliced_in)); 601 memcpy(itv->vbi.sliced_in, vbifmt, sizeof(*itv->vbi.sliced_in));
609 return 0; 602 return 0;
@@ -651,8 +644,6 @@ static int ivtv_s_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *f
651 itv->dma_data_req_size = 644 itv->dma_data_req_size =
652 1080 * ((yi->v4l2_src_h + 31) & ~31); 645 1080 * ((yi->v4l2_src_h + 31) & ~31);
653 646
654 /* Force update of yuv registers */
655 yi->yuv_forced_update = 1;
656 return 0; 647 return 0;
657} 648}
658 649
@@ -761,7 +752,7 @@ static int ivtv_querycap(struct file *file, void *fh, struct v4l2_capability *vc
761 752
762 strlcpy(vcap->driver, IVTV_DRIVER_NAME, sizeof(vcap->driver)); 753 strlcpy(vcap->driver, IVTV_DRIVER_NAME, sizeof(vcap->driver));
763 strlcpy(vcap->card, itv->card_name, sizeof(vcap->card)); 754 strlcpy(vcap->card, itv->card_name, sizeof(vcap->card));
764 strlcpy(vcap->bus_info, pci_name(itv->dev), sizeof(vcap->bus_info)); 755 snprintf(vcap->bus_info, sizeof(vcap->bus_info), "PCI:%s", pci_name(itv->dev));
765 vcap->version = IVTV_DRIVER_VERSION; /* version */ 756 vcap->version = IVTV_DRIVER_VERSION; /* version */
766 vcap->capabilities = itv->v4l2_cap; /* capabilities */ 757 vcap->capabilities = itv->v4l2_cap; /* capabilities */
767 return 0; 758 return 0;
@@ -1370,6 +1361,9 @@ static int ivtv_g_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *fb)
1370 if (itv->osd_global_alpha_state) 1361 if (itv->osd_global_alpha_state)
1371 fb->flags |= V4L2_FBUF_FLAG_GLOBAL_ALPHA; 1362 fb->flags |= V4L2_FBUF_FLAG_GLOBAL_ALPHA;
1372 1363
1364 if (yi->track_osd)
1365 fb->flags |= V4L2_FBUF_FLAG_OVERLAY;
1366
1373 pixfmt &= 7; 1367 pixfmt &= 7;
1374 1368
1375 /* no local alpha for RGB565 or unknown formats */ 1369 /* no local alpha for RGB565 or unknown formats */
@@ -1389,8 +1383,6 @@ static int ivtv_g_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *fb)
1389 else 1383 else
1390 fb->flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA; 1384 fb->flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA;
1391 } 1385 }
1392 if (yi->track_osd)
1393 fb->flags |= V4L2_FBUF_FLAG_OVERLAY;
1394 1386
1395 return 0; 1387 return 0;
1396} 1388}
diff --git a/drivers/media/video/ivtv/ivtv-irq.c b/drivers/media/video/ivtv/ivtv-irq.c
index 34f3ab827858..f5d00ec5da73 100644
--- a/drivers/media/video/ivtv/ivtv-irq.c
+++ b/drivers/media/video/ivtv/ivtv-irq.c
@@ -753,7 +753,7 @@ static void ivtv_irq_vsync(struct ivtv *itv)
753 */ 753 */
754 unsigned int frame = read_reg(0x28c0) & 1; 754 unsigned int frame = read_reg(0x28c0) & 1;
755 struct yuv_playback_info *yi = &itv->yuv_info; 755 struct yuv_playback_info *yi = &itv->yuv_info;
756 int last_dma_frame = atomic_read(&itv->yuv_info.next_dma_frame); 756 int last_dma_frame = atomic_read(&yi->next_dma_frame);
757 struct yuv_frame_info *f = &yi->new_frame_info[last_dma_frame]; 757 struct yuv_frame_info *f = &yi->new_frame_info[last_dma_frame];
758 758
759 if (0) IVTV_DEBUG_IRQ("DEC VSYNC\n"); 759 if (0) IVTV_DEBUG_IRQ("DEC VSYNC\n");
@@ -772,6 +772,7 @@ static void ivtv_irq_vsync(struct ivtv *itv)
772 next_dma_frame = (next_dma_frame + 1) % IVTV_YUV_BUFFERS; 772 next_dma_frame = (next_dma_frame + 1) % IVTV_YUV_BUFFERS;
773 atomic_set(&yi->next_dma_frame, next_dma_frame); 773 atomic_set(&yi->next_dma_frame, next_dma_frame);
774 yi->fields_lapsed = -1; 774 yi->fields_lapsed = -1;
775 yi->running = 1;
775 } 776 }
776 } 777 }
777 } 778 }
@@ -804,9 +805,11 @@ static void ivtv_irq_vsync(struct ivtv *itv)
804 } 805 }
805 806
806 /* Check if we need to update the yuv registers */ 807 /* Check if we need to update the yuv registers */
807 if ((yi->yuv_forced_update || f->update) && last_dma_frame != -1) { 808 if (yi->running && (yi->yuv_forced_update || f->update)) {
808 if (!f->update) { 809 if (!f->update) {
809 last_dma_frame = (u8)(last_dma_frame - 1) % IVTV_YUV_BUFFERS; 810 last_dma_frame =
811 (u8)(atomic_read(&yi->next_dma_frame) -
812 1) % IVTV_YUV_BUFFERS;
810 f = &yi->new_frame_info[last_dma_frame]; 813 f = &yi->new_frame_info[last_dma_frame];
811 } 814 }
812 815
diff --git a/drivers/media/video/ivtv/ivtv-streams.c b/drivers/media/video/ivtv/ivtv-streams.c
index 730e85d86fc8..5bbf31e39304 100644
--- a/drivers/media/video/ivtv/ivtv-streams.c
+++ b/drivers/media/video/ivtv/ivtv-streams.c
@@ -75,7 +75,7 @@ static const struct file_operations ivtv_v4l2_dec_fops = {
75static struct { 75static struct {
76 const char *name; 76 const char *name;
77 int vfl_type; 77 int vfl_type;
78 int minor_offset; 78 int num_offset;
79 int dma, pio; 79 int dma, pio;
80 enum v4l2_buf_type buf_type; 80 enum v4l2_buf_type buf_type;
81 const struct file_operations *fops; 81 const struct file_operations *fops;
@@ -171,8 +171,8 @@ static void ivtv_stream_init(struct ivtv *itv, int type)
171static int ivtv_prep_dev(struct ivtv *itv, int type) 171static int ivtv_prep_dev(struct ivtv *itv, int type)
172{ 172{
173 struct ivtv_stream *s = &itv->streams[type]; 173 struct ivtv_stream *s = &itv->streams[type];
174 int minor_offset = ivtv_stream_info[type].minor_offset; 174 int num_offset = ivtv_stream_info[type].num_offset;
175 int minor; 175 int num = itv->num + ivtv_first_minor + num_offset;
176 176
177 /* These four fields are always initialized. If v4l2dev == NULL, then 177 /* These four fields are always initialized. If v4l2dev == NULL, then
178 this stream is not in use. In that case no other fields but these 178 this stream is not in use. In that case no other fields but these
@@ -188,9 +188,6 @@ static int ivtv_prep_dev(struct ivtv *itv, int type)
188 if (type >= IVTV_DEC_STREAM_TYPE_MPG && !(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) 188 if (type >= IVTV_DEC_STREAM_TYPE_MPG && !(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
189 return 0; 189 return 0;
190 190
191 /* card number + user defined offset + device offset */
192 minor = itv->num + ivtv_first_minor + minor_offset;
193
194 /* User explicitly selected 0 buffers for these streams, so don't 191 /* User explicitly selected 0 buffers for these streams, so don't
195 create them. */ 192 create them. */
196 if (ivtv_stream_info[type].dma != PCI_DMA_NONE && 193 if (ivtv_stream_info[type].dma != PCI_DMA_NONE &&
@@ -211,7 +208,7 @@ static int ivtv_prep_dev(struct ivtv *itv, int type)
211 snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "ivtv%d %s", 208 snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "ivtv%d %s",
212 itv->num, s->name); 209 itv->num, s->name);
213 210
214 s->v4l2dev->minor = minor; 211 s->v4l2dev->num = num;
215 s->v4l2dev->parent = &itv->dev->dev; 212 s->v4l2dev->parent = &itv->dev->dev;
216 s->v4l2dev->fops = ivtv_stream_info[type].fops; 213 s->v4l2dev->fops = ivtv_stream_info[type].fops;
217 s->v4l2dev->release = video_device_release; 214 s->v4l2dev->release = video_device_release;
@@ -250,39 +247,46 @@ static int ivtv_reg_dev(struct ivtv *itv, int type)
250{ 247{
251 struct ivtv_stream *s = &itv->streams[type]; 248 struct ivtv_stream *s = &itv->streams[type];
252 int vfl_type = ivtv_stream_info[type].vfl_type; 249 int vfl_type = ivtv_stream_info[type].vfl_type;
253 int minor; 250 int num;
254 251
255 if (s->v4l2dev == NULL) 252 if (s->v4l2dev == NULL)
256 return 0; 253 return 0;
257 254
258 minor = s->v4l2dev->minor; 255 num = s->v4l2dev->num;
256 /* card number + user defined offset + device offset */
257 if (type != IVTV_ENC_STREAM_TYPE_MPG) {
258 struct ivtv_stream *s_mpg = &itv->streams[IVTV_ENC_STREAM_TYPE_MPG];
259
260 if (s_mpg->v4l2dev)
261 num = s_mpg->v4l2dev->num + ivtv_stream_info[type].num_offset;
262 }
263
259 /* Register device. First try the desired minor, then any free one. */ 264 /* Register device. First try the desired minor, then any free one. */
260 if (video_register_device(s->v4l2dev, vfl_type, minor) && 265 if (video_register_device(s->v4l2dev, vfl_type, num)) {
261 video_register_device(s->v4l2dev, vfl_type, -1)) { 266 IVTV_ERR("Couldn't register v4l2 device for %s kernel number %d\n",
262 IVTV_ERR("Couldn't register v4l2 device for %s minor %d\n", 267 s->name, num);
263 s->name, minor);
264 video_device_release(s->v4l2dev); 268 video_device_release(s->v4l2dev);
265 s->v4l2dev = NULL; 269 s->v4l2dev = NULL;
266 return -ENOMEM; 270 return -ENOMEM;
267 } 271 }
272 num = s->v4l2dev->num;
268 273
269 switch (vfl_type) { 274 switch (vfl_type) {
270 case VFL_TYPE_GRABBER: 275 case VFL_TYPE_GRABBER:
271 IVTV_INFO("Registered device video%d for %s (%d kB)\n", 276 IVTV_INFO("Registered device video%d for %s (%d kB)\n",
272 s->v4l2dev->minor, s->name, itv->options.kilobytes[type]); 277 num, s->name, itv->options.kilobytes[type]);
273 break; 278 break;
274 case VFL_TYPE_RADIO: 279 case VFL_TYPE_RADIO:
275 IVTV_INFO("Registered device radio%d for %s\n", 280 IVTV_INFO("Registered device radio%d for %s\n",
276 s->v4l2dev->minor - MINOR_VFL_TYPE_RADIO_MIN, s->name); 281 num, s->name);
277 break; 282 break;
278 case VFL_TYPE_VBI: 283 case VFL_TYPE_VBI:
279 if (itv->options.kilobytes[type]) 284 if (itv->options.kilobytes[type])
280 IVTV_INFO("Registered device vbi%d for %s (%d kB)\n", 285 IVTV_INFO("Registered device vbi%d for %s (%d kB)\n",
281 s->v4l2dev->minor - MINOR_VFL_TYPE_VBI_MIN, 286 num, s->name, itv->options.kilobytes[type]);
282 s->name, itv->options.kilobytes[type]);
283 else 287 else
284 IVTV_INFO("Registered device vbi%d for %s\n", 288 IVTV_INFO("Registered device vbi%d for %s\n",
285 s->v4l2dev->minor - MINOR_VFL_TYPE_VBI_MIN, s->name); 289 num, s->name);
286 break; 290 break;
287 } 291 }
288 return 0; 292 return 0;
@@ -330,7 +334,7 @@ void ivtv_streams_cleanup(struct ivtv *itv, int unregister)
330 334
331static void ivtv_vbi_setup(struct ivtv *itv) 335static void ivtv_vbi_setup(struct ivtv *itv)
332{ 336{
333 int raw = itv->vbi.sliced_in->service_set == 0; 337 int raw = ivtv_raw_vbi(itv);
334 u32 data[CX2341X_MBOX_MAX_DATA]; 338 u32 data[CX2341X_MBOX_MAX_DATA];
335 int lines; 339 int lines;
336 int i; 340 int i;
diff --git a/drivers/media/video/ivtv/ivtv-vbi.c b/drivers/media/video/ivtv/ivtv-vbi.c
index 1ce9deb1104f..4a37a7d2e69d 100644
--- a/drivers/media/video/ivtv/ivtv-vbi.c
+++ b/drivers/media/video/ivtv/ivtv-vbi.c
@@ -334,7 +334,7 @@ void ivtv_process_vbi_data(struct ivtv *itv, struct ivtv_buffer *buf,
334 int y; 334 int y;
335 335
336 /* Raw VBI data */ 336 /* Raw VBI data */
337 if (streamtype == IVTV_ENC_STREAM_TYPE_VBI && itv->vbi.sliced_in->service_set == 0) { 337 if (streamtype == IVTV_ENC_STREAM_TYPE_VBI && ivtv_raw_vbi(itv)) {
338 u8 type; 338 u8 type;
339 339
340 ivtv_buf_swap(buf); 340 ivtv_buf_swap(buf);
diff --git a/drivers/media/video/ivtv/ivtv-yuv.c b/drivers/media/video/ivtv/ivtv-yuv.c
index 3092ff1d00a0..ee91107376c7 100644
--- a/drivers/media/video/ivtv/ivtv-yuv.c
+++ b/drivers/media/video/ivtv/ivtv-yuv.c
@@ -1147,6 +1147,7 @@ void ivtv_yuv_close(struct ivtv *itv)
1147 IVTV_DEBUG_YUV("ivtv_yuv_close\n"); 1147 IVTV_DEBUG_YUV("ivtv_yuv_close\n");
1148 ivtv_waitq(&itv->vsync_waitq); 1148 ivtv_waitq(&itv->vsync_waitq);
1149 1149
1150 yi->running = 0;
1150 atomic_set(&yi->next_dma_frame, -1); 1151 atomic_set(&yi->next_dma_frame, -1);
1151 atomic_set(&yi->next_fill_frame, 0); 1152 atomic_set(&yi->next_fill_frame, 0);
1152 1153
diff --git a/drivers/media/video/ivtv/ivtvfb.c b/drivers/media/video/ivtv/ivtvfb.c
index bdfda48e56bf..8a4a150b12fb 100644
--- a/drivers/media/video/ivtv/ivtvfb.c
+++ b/drivers/media/video/ivtv/ivtvfb.c
@@ -275,7 +275,6 @@ static int ivtvfb_prep_dec_dma_to_device(struct ivtv *itv,
275 int size_in_bytes) 275 int size_in_bytes)
276{ 276{
277 DEFINE_WAIT(wait); 277 DEFINE_WAIT(wait);
278 int ret = 0;
279 int got_sig = 0; 278 int got_sig = 0;
280 279
281 mutex_lock(&itv->udma.lock); 280 mutex_lock(&itv->udma.lock);
@@ -316,7 +315,7 @@ static int ivtvfb_prep_dec_dma_to_device(struct ivtv *itv,
316 return -EINTR; 315 return -EINTR;
317 } 316 }
318 317
319 return ret; 318 return 0;
320} 319}
321 320
322static int ivtvfb_prep_frame(struct ivtv *itv, int cmd, void __user *source, 321static int ivtvfb_prep_frame(struct ivtv *itv, int cmd, void __user *source,
@@ -368,11 +367,12 @@ static int ivtvfb_prep_frame(struct ivtv *itv, int cmd, void __user *source,
368} 367}
369 368
370static ssize_t ivtvfb_write(struct fb_info *info, const char __user *buf, 369static ssize_t ivtvfb_write(struct fb_info *info, const char __user *buf,
371 size_t count, loff_t *ppos) 370 size_t count, loff_t *ppos)
372{ 371{
373 unsigned long p = *ppos; 372 unsigned long p = *ppos;
374 void *dst; 373 void *dst;
375 int err = 0; 374 int err = 0;
375 int dma_err;
376 unsigned long total_size; 376 unsigned long total_size;
377 struct ivtv *itv = (struct ivtv *) info->par; 377 struct ivtv *itv = (struct ivtv *) info->par;
378 unsigned long dma_offset = 378 unsigned long dma_offset =
@@ -399,7 +399,6 @@ static ssize_t ivtvfb_write(struct fb_info *info, const char __user *buf,
399 if (count + p > total_size) { 399 if (count + p > total_size) {
400 if (!err) 400 if (!err)
401 err = -ENOSPC; 401 err = -ENOSPC;
402
403 count = total_size - p; 402 count = total_size - p;
404 } 403 }
405 404
@@ -408,39 +407,34 @@ static ssize_t ivtvfb_write(struct fb_info *info, const char __user *buf,
408 if (info->fbops->fb_sync) 407 if (info->fbops->fb_sync)
409 info->fbops->fb_sync(info); 408 info->fbops->fb_sync(info);
410 409
411 if (!access_ok(VERIFY_READ, buf, count)) { 410 /* If transfer size > threshold and both src/dst
412 IVTVFB_WARN("Invalid userspace pointer 0x%08lx\n", 411 addresses are aligned, use DMA */
413 (unsigned long)buf); 412 if (count >= 4096 &&
414 err = -EFAULT; 413 ((unsigned long)buf & 3) == ((unsigned long)dst & 3)) {
415 } 414 /* Odd address = can't DMA. Align */
416 415 if ((unsigned long)dst & 3) {
417 if (!err) { 416 lead = 4 - ((unsigned long)dst & 3);
418 /* If transfer size > threshold and both src/dst 417 if (copy_from_user(dst, buf, lead))
419 addresses are aligned, use DMA */ 418 return -EFAULT;
420 if (count >= 4096 && 419 buf += lead;
421 ((unsigned long)buf & 3) == ((unsigned long)dst & 3)) { 420 dst += lead;
422 /* Odd address = can't DMA. Align */
423 if ((unsigned long)dst & 3) {
424 lead = 4 - ((unsigned long)dst & 3);
425 memcpy(dst, buf, lead);
426 buf += lead;
427 dst += lead;
428 }
429 /* DMA resolution is 32 bits */
430 if ((count - lead) & 3)
431 tail = (count - lead) & 3;
432 /* DMA the data */
433 dma_size = count - lead - tail;
434 err = ivtvfb_prep_dec_dma_to_device(itv,
435 p + lead + dma_offset, (void *)buf, dma_size);
436 dst += dma_size;
437 buf += dma_size;
438 /* Copy any leftover data */
439 if (tail)
440 memcpy(dst, buf, tail);
441 } else {
442 memcpy(dst, buf, count);
443 } 421 }
422 /* DMA resolution is 32 bits */
423 if ((count - lead) & 3)
424 tail = (count - lead) & 3;
425 /* DMA the data */
426 dma_size = count - lead - tail;
427 dma_err = ivtvfb_prep_dec_dma_to_device(itv,
428 p + lead + dma_offset, (void __user *)buf, dma_size);
429 if (dma_err)
430 return dma_err;
431 dst += dma_size;
432 buf += dma_size;
433 /* Copy any leftover data */
434 if (tail && copy_from_user(dst, buf, tail))
435 return -EFAULT;
436 } else if (copy_from_user(dst, buf, count)) {
437 return -EFAULT;
444 } 438 }
445 439
446 if (!err) 440 if (!err)
@@ -463,9 +457,12 @@ static int ivtvfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long ar
463 vblank.flags = FB_VBLANK_HAVE_COUNT |FB_VBLANK_HAVE_VCOUNT | 457 vblank.flags = FB_VBLANK_HAVE_COUNT |FB_VBLANK_HAVE_VCOUNT |
464 FB_VBLANK_HAVE_VSYNC; 458 FB_VBLANK_HAVE_VSYNC;
465 trace = read_reg(0x028c0) >> 16; 459 trace = read_reg(0x028c0) >> 16;
466 if (itv->is_50hz && trace > 312) trace -= 312; 460 if (itv->is_50hz && trace > 312)
467 else if (itv->is_60hz && trace > 262) trace -= 262; 461 trace -= 312;
468 if (trace == 1) vblank.flags |= FB_VBLANK_VSYNCING; 462 else if (itv->is_60hz && trace > 262)
463 trace -= 262;
464 if (trace == 1)
465 vblank.flags |= FB_VBLANK_VSYNCING;
469 vblank.count = itv->last_vsync_field; 466 vblank.count = itv->last_vsync_field;
470 vblank.vcount = trace; 467 vblank.vcount = trace;
471 vblank.hcount = 0; 468 vblank.hcount = 0;
@@ -476,7 +473,8 @@ static int ivtvfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long ar
476 473
477 case FBIO_WAITFORVSYNC: 474 case FBIO_WAITFORVSYNC:
478 prepare_to_wait(&itv->vsync_waitq, &wait, TASK_INTERRUPTIBLE); 475 prepare_to_wait(&itv->vsync_waitq, &wait, TASK_INTERRUPTIBLE);
479 if (!schedule_timeout(msecs_to_jiffies(50))) rc = -ETIMEDOUT; 476 if (!schedule_timeout(msecs_to_jiffies(50)))
477 rc = -ETIMEDOUT;
480 finish_wait(&itv->vsync_waitq, &wait); 478 finish_wait(&itv->vsync_waitq, &wait);
481 return rc; 479 return rc;
482 480
diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
index a9ef7802eb5f..6418f4a78f2a 100644
--- a/drivers/media/video/meye.c
+++ b/drivers/media/video/meye.c
@@ -843,17 +843,16 @@ again:
843 843
844static int meye_open(struct inode *inode, struct file *file) 844static int meye_open(struct inode *inode, struct file *file)
845{ 845{
846 int i, err; 846 int i;
847 847
848 err = video_exclusive_open(inode, file); 848 if (test_and_set_bit(0, &meye.in_use))
849 if (err < 0) 849 return -EBUSY;
850 return err;
851 850
852 mchip_hic_stop(); 851 mchip_hic_stop();
853 852
854 if (mchip_dma_alloc()) { 853 if (mchip_dma_alloc()) {
855 printk(KERN_ERR "meye: mchip framebuffer allocation failed\n"); 854 printk(KERN_ERR "meye: mchip framebuffer allocation failed\n");
856 video_exclusive_release(inode, file); 855 clear_bit(0, &meye.in_use);
857 return -ENOBUFS; 856 return -ENOBUFS;
858 } 857 }
859 858
@@ -868,7 +867,7 @@ static int meye_release(struct inode *inode, struct file *file)
868{ 867{
869 mchip_hic_stop(); 868 mchip_hic_stop();
870 mchip_dma_free(); 869 mchip_dma_free();
871 video_exclusive_release(inode, file); 870 clear_bit(0, &meye.in_use);
872 return 0; 871 return 0;
873} 872}
874 873
@@ -1774,6 +1773,7 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
1774 goto outnotdev; 1773 goto outnotdev;
1775 } 1774 }
1776 1775
1776 ret = -ENOMEM;
1777 meye.mchip_dev = pcidev; 1777 meye.mchip_dev = pcidev;
1778 meye.video_dev = video_device_alloc(); 1778 meye.video_dev = video_device_alloc();
1779 if (!meye.video_dev) { 1779 if (!meye.video_dev) {
@@ -1781,7 +1781,6 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
1781 goto outnotdev; 1781 goto outnotdev;
1782 } 1782 }
1783 1783
1784 ret = -ENOMEM;
1785 meye.grab_temp = vmalloc(MCHIP_NB_PAGES_MJPEG * PAGE_SIZE); 1784 meye.grab_temp = vmalloc(MCHIP_NB_PAGES_MJPEG * PAGE_SIZE);
1786 if (!meye.grab_temp) { 1785 if (!meye.grab_temp) {
1787 printk(KERN_ERR "meye: grab buffer allocation failed\n"); 1786 printk(KERN_ERR "meye: grab buffer allocation failed\n");
diff --git a/drivers/media/video/meye.h b/drivers/media/video/meye.h
index d535748df445..5f70a106ba2b 100644
--- a/drivers/media/video/meye.h
+++ b/drivers/media/video/meye.h
@@ -311,6 +311,7 @@ struct meye {
311 struct video_device *video_dev; /* video device parameters */ 311 struct video_device *video_dev; /* video device parameters */
312 struct video_picture picture; /* video picture parameters */ 312 struct video_picture picture; /* video picture parameters */
313 struct meye_params params; /* additional parameters */ 313 struct meye_params params; /* additional parameters */
314 unsigned long in_use; /* set to 1 if the device is in use */
314#ifdef CONFIG_PM 315#ifdef CONFIG_PM
315 u8 pm_mchip_mode; /* old mchip mode */ 316 u8 pm_mchip_mode; /* old mchip mode */
316#endif 317#endif
diff --git a/drivers/media/video/mt9m001.c b/drivers/media/video/mt9m001.c
index 554d2295484e..0c524376b67e 100644
--- a/drivers/media/video/mt9m001.c
+++ b/drivers/media/video/mt9m001.c
@@ -117,24 +117,51 @@ static int reg_clear(struct soc_camera_device *icd, const u8 reg,
117 117
118static int mt9m001_init(struct soc_camera_device *icd) 118static int mt9m001_init(struct soc_camera_device *icd)
119{ 119{
120 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
121 struct soc_camera_link *icl = mt9m001->client->dev.platform_data;
120 int ret; 122 int ret;
121 123
122 /* Disable chip, synchronous option update */
123 dev_dbg(icd->vdev->parent, "%s\n", __func__); 124 dev_dbg(icd->vdev->parent, "%s\n", __func__);
124 125
125 ret = reg_write(icd, MT9M001_RESET, 1); 126 if (icl->power) {
126 if (ret >= 0) 127 ret = icl->power(&mt9m001->client->dev, 1);
127 ret = reg_write(icd, MT9M001_RESET, 0); 128 if (ret < 0) {
128 if (ret >= 0) 129 dev_err(icd->vdev->parent,
130 "Platform failed to power-on the camera.\n");
131 return ret;
132 }
133 }
134
135 /* The camera could have been already on, we reset it additionally */
136 if (icl->reset)
137 ret = icl->reset(&mt9m001->client->dev);
138 else
139 ret = -ENODEV;
140
141 if (ret < 0) {
142 /* Either no platform reset, or platform reset failed */
143 ret = reg_write(icd, MT9M001_RESET, 1);
144 if (!ret)
145 ret = reg_write(icd, MT9M001_RESET, 0);
146 }
147 /* Disable chip, synchronous option update */
148 if (!ret)
129 ret = reg_write(icd, MT9M001_OUTPUT_CONTROL, 0); 149 ret = reg_write(icd, MT9M001_OUTPUT_CONTROL, 0);
130 150
131 return ret >= 0 ? 0 : -EIO; 151 return ret;
132} 152}
133 153
134static int mt9m001_release(struct soc_camera_device *icd) 154static int mt9m001_release(struct soc_camera_device *icd)
135{ 155{
156 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
157 struct soc_camera_link *icl = mt9m001->client->dev.platform_data;
158
136 /* Disable the chip */ 159 /* Disable the chip */
137 reg_write(icd, MT9M001_OUTPUT_CONTROL, 0); 160 reg_write(icd, MT9M001_OUTPUT_CONTROL, 0);
161
162 if (icl->power)
163 icl->power(&mt9m001->client->dev, 0);
164
138 return 0; 165 return 0;
139} 166}
140 167
@@ -267,24 +294,24 @@ static int mt9m001_set_fmt_cap(struct soc_camera_device *icd,
267 294
268 /* Blanking and start values - default... */ 295 /* Blanking and start values - default... */
269 ret = reg_write(icd, MT9M001_HORIZONTAL_BLANKING, hblank); 296 ret = reg_write(icd, MT9M001_HORIZONTAL_BLANKING, hblank);
270 if (ret >= 0) 297 if (!ret)
271 ret = reg_write(icd, MT9M001_VERTICAL_BLANKING, vblank); 298 ret = reg_write(icd, MT9M001_VERTICAL_BLANKING, vblank);
272 299
273 /* The caller provides a supported format, as verified per 300 /* The caller provides a supported format, as verified per
274 * call to icd->try_fmt_cap() */ 301 * call to icd->try_fmt_cap() */
275 if (ret >= 0) 302 if (!ret)
276 ret = reg_write(icd, MT9M001_COLUMN_START, rect->left); 303 ret = reg_write(icd, MT9M001_COLUMN_START, rect->left);
277 if (ret >= 0) 304 if (!ret)
278 ret = reg_write(icd, MT9M001_ROW_START, rect->top); 305 ret = reg_write(icd, MT9M001_ROW_START, rect->top);
279 if (ret >= 0) 306 if (!ret)
280 ret = reg_write(icd, MT9M001_WINDOW_WIDTH, rect->width - 1); 307 ret = reg_write(icd, MT9M001_WINDOW_WIDTH, rect->width - 1);
281 if (ret >= 0) 308 if (!ret)
282 ret = reg_write(icd, MT9M001_WINDOW_HEIGHT, 309 ret = reg_write(icd, MT9M001_WINDOW_HEIGHT,
283 rect->height + icd->y_skip_top - 1); 310 rect->height + icd->y_skip_top - 1);
284 if (ret >= 0 && mt9m001->autoexposure) { 311 if (!ret && mt9m001->autoexposure) {
285 ret = reg_write(icd, MT9M001_SHUTTER_WIDTH, 312 ret = reg_write(icd, MT9M001_SHUTTER_WIDTH,
286 rect->height + icd->y_skip_top + vblank); 313 rect->height + icd->y_skip_top + vblank);
287 if (ret >= 0) { 314 if (!ret) {
288 const struct v4l2_queryctrl *qctrl = 315 const struct v4l2_queryctrl *qctrl =
289 soc_camera_find_qctrl(icd->ops, 316 soc_camera_find_qctrl(icd->ops,
290 V4L2_CID_EXPOSURE); 317 V4L2_CID_EXPOSURE);
@@ -295,7 +322,7 @@ static int mt9m001_set_fmt_cap(struct soc_camera_device *icd,
295 } 322 }
296 } 323 }
297 324
298 return ret < 0 ? ret : 0; 325 return ret;
299} 326}
300 327
301static int mt9m001_try_fmt_cap(struct soc_camera_device *icd, 328static int mt9m001_try_fmt_cap(struct soc_camera_device *icd,
diff --git a/drivers/media/video/mt9m111.c b/drivers/media/video/mt9m111.c
new file mode 100644
index 000000000000..da0b2d553fd0
--- /dev/null
+++ b/drivers/media/video/mt9m111.c
@@ -0,0 +1,973 @@
1/*
2 * Driver for MT9M111 CMOS Image Sensor from Micron
3 *
4 * Copyright (C) 2008, Robert Jarzmik <robert.jarzmik@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#include <linux/videodev2.h>
11#include <linux/slab.h>
12#include <linux/i2c.h>
13#include <linux/log2.h>
14#include <linux/gpio.h>
15#include <linux/delay.h>
16
17#include <media/v4l2-common.h>
18#include <media/v4l2-chip-ident.h>
19#include <media/soc_camera.h>
20
21/*
22 * mt9m111 i2c address is 0x5d or 0x48 (depending on SAddr pin)
23 * The platform has to define i2c_board_info and call i2c_register_board_info()
24 */
25
26/* mt9m111: Sensor register addresses */
27#define MT9M111_CHIP_VERSION 0x000
28#define MT9M111_ROW_START 0x001
29#define MT9M111_COLUMN_START 0x002
30#define MT9M111_WINDOW_HEIGHT 0x003
31#define MT9M111_WINDOW_WIDTH 0x004
32#define MT9M111_HORIZONTAL_BLANKING_B 0x005
33#define MT9M111_VERTICAL_BLANKING_B 0x006
34#define MT9M111_HORIZONTAL_BLANKING_A 0x007
35#define MT9M111_VERTICAL_BLANKING_A 0x008
36#define MT9M111_SHUTTER_WIDTH 0x009
37#define MT9M111_ROW_SPEED 0x00a
38#define MT9M111_EXTRA_DELAY 0x00b
39#define MT9M111_SHUTTER_DELAY 0x00c
40#define MT9M111_RESET 0x00d
41#define MT9M111_READ_MODE_B 0x020
42#define MT9M111_READ_MODE_A 0x021
43#define MT9M111_FLASH_CONTROL 0x023
44#define MT9M111_GREEN1_GAIN 0x02b
45#define MT9M111_BLUE_GAIN 0x02c
46#define MT9M111_RED_GAIN 0x02d
47#define MT9M111_GREEN2_GAIN 0x02e
48#define MT9M111_GLOBAL_GAIN 0x02f
49#define MT9M111_CONTEXT_CONTROL 0x0c8
50#define MT9M111_PAGE_MAP 0x0f0
51#define MT9M111_BYTE_WISE_ADDR 0x0f1
52
53#define MT9M111_RESET_SYNC_CHANGES (1 << 15)
54#define MT9M111_RESET_RESTART_BAD_FRAME (1 << 9)
55#define MT9M111_RESET_SHOW_BAD_FRAMES (1 << 8)
56#define MT9M111_RESET_RESET_SOC (1 << 5)
57#define MT9M111_RESET_OUTPUT_DISABLE (1 << 4)
58#define MT9M111_RESET_CHIP_ENABLE (1 << 3)
59#define MT9M111_RESET_ANALOG_STANDBY (1 << 2)
60#define MT9M111_RESET_RESTART_FRAME (1 << 1)
61#define MT9M111_RESET_RESET_MODE (1 << 0)
62
63#define MT9M111_RMB_MIRROR_COLS (1 << 1)
64#define MT9M111_RMB_MIRROR_ROWS (1 << 0)
65#define MT9M111_CTXT_CTRL_RESTART (1 << 15)
66#define MT9M111_CTXT_CTRL_DEFECTCOR_B (1 << 12)
67#define MT9M111_CTXT_CTRL_RESIZE_B (1 << 10)
68#define MT9M111_CTXT_CTRL_CTRL2_B (1 << 9)
69#define MT9M111_CTXT_CTRL_GAMMA_B (1 << 8)
70#define MT9M111_CTXT_CTRL_XENON_EN (1 << 7)
71#define MT9M111_CTXT_CTRL_READ_MODE_B (1 << 3)
72#define MT9M111_CTXT_CTRL_LED_FLASH_EN (1 << 2)
73#define MT9M111_CTXT_CTRL_VBLANK_SEL_B (1 << 1)
74#define MT9M111_CTXT_CTRL_HBLANK_SEL_B (1 << 0)
75/*
76 * mt9m111: Colorpipe register addresses (0x100..0x1ff)
77 */
78#define MT9M111_OPER_MODE_CTRL 0x106
79#define MT9M111_OUTPUT_FORMAT_CTRL 0x108
80#define MT9M111_REDUCER_XZOOM_B 0x1a0
81#define MT9M111_REDUCER_XSIZE_B 0x1a1
82#define MT9M111_REDUCER_YZOOM_B 0x1a3
83#define MT9M111_REDUCER_YSIZE_B 0x1a4
84#define MT9M111_REDUCER_XZOOM_A 0x1a6
85#define MT9M111_REDUCER_XSIZE_A 0x1a7
86#define MT9M111_REDUCER_YZOOM_A 0x1a9
87#define MT9M111_REDUCER_YSIZE_A 0x1aa
88
89#define MT9M111_OUTPUT_FORMAT_CTRL2_A 0x13a
90#define MT9M111_OUTPUT_FORMAT_CTRL2_B 0x19b
91
92#define MT9M111_OPMODE_AUTOEXPO_EN (1 << 14)
93
94
95#define MT9M111_OUTFMT_PROCESSED_BAYER (1 << 14)
96#define MT9M111_OUTFMT_BYPASS_IFP (1 << 10)
97#define MT9M111_OUTFMT_INV_PIX_CLOCK (1 << 9)
98#define MT9M111_OUTFMT_RGB (1 << 8)
99#define MT9M111_OUTFMT_RGB565 (0x0 << 6)
100#define MT9M111_OUTFMT_RGB555 (0x1 << 6)
101#define MT9M111_OUTFMT_RGB444x (0x2 << 6)
102#define MT9M111_OUTFMT_RGBx444 (0x3 << 6)
103#define MT9M111_OUTFMT_TST_RAMP_OFF (0x0 << 4)
104#define MT9M111_OUTFMT_TST_RAMP_COL (0x1 << 4)
105#define MT9M111_OUTFMT_TST_RAMP_ROW (0x2 << 4)
106#define MT9M111_OUTFMT_TST_RAMP_FRAME (0x3 << 4)
107#define MT9M111_OUTFMT_SHIFT_3_UP (1 << 3)
108#define MT9M111_OUTFMT_AVG_CHROMA (1 << 2)
109#define MT9M111_OUTFMT_SWAP_YCbCr_C_Y (1 << 1)
110#define MT9M111_OUTFMT_SWAP_RGB_EVEN (1 << 1)
111#define MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr (1 << 0)
112/*
113 * mt9m111: Camera control register addresses (0x200..0x2ff not implemented)
114 */
115
116#define reg_read(reg) mt9m111_reg_read(icd, MT9M111_##reg)
117#define reg_write(reg, val) mt9m111_reg_write(icd, MT9M111_##reg, (val))
118#define reg_set(reg, val) mt9m111_reg_set(icd, MT9M111_##reg, (val))
119#define reg_clear(reg, val) mt9m111_reg_clear(icd, MT9M111_##reg, (val))
120
121#define MT9M111_MIN_DARK_ROWS 8
122#define MT9M111_MIN_DARK_COLS 24
123#define MT9M111_MAX_HEIGHT 1024
124#define MT9M111_MAX_WIDTH 1280
125
126#define COL_FMT(_name, _depth, _fourcc, _colorspace) \
127 { .name = _name, .depth = _depth, .fourcc = _fourcc, \
128 .colorspace = _colorspace }
129#define RGB_FMT(_name, _depth, _fourcc) \
130 COL_FMT(_name, _depth, _fourcc, V4L2_COLORSPACE_SRGB)
131
132static const struct soc_camera_data_format mt9m111_colour_formats[] = {
133 COL_FMT("YCrYCb 8 bit", 8, V4L2_PIX_FMT_YUYV, V4L2_COLORSPACE_JPEG),
134 RGB_FMT("RGB 565", 16, V4L2_PIX_FMT_RGB565),
135 RGB_FMT("RGB 555", 16, V4L2_PIX_FMT_RGB555),
136 RGB_FMT("Bayer (sRGB) 10 bit", 10, V4L2_PIX_FMT_SBGGR16),
137 RGB_FMT("Bayer (sRGB) 8 bit", 8, V4L2_PIX_FMT_SBGGR8),
138};
139
140enum mt9m111_context {
141 HIGHPOWER = 0,
142 LOWPOWER,
143};
144
145struct mt9m111 {
146 struct i2c_client *client;
147 struct soc_camera_device icd;
148 int model; /* V4L2_IDENT_MT9M111* codes from v4l2-chip-ident.h */
149 enum mt9m111_context context;
150 unsigned int left, top, width, height;
151 u32 pixfmt;
152 unsigned char autoexposure;
153 unsigned char datawidth;
154 unsigned int powered:1;
155 unsigned int hflip:1;
156 unsigned int vflip:1;
157 unsigned int swap_rgb_even_odd:1;
158 unsigned int swap_rgb_red_blue:1;
159 unsigned int swap_yuv_y_chromas:1;
160 unsigned int swap_yuv_cb_cr:1;
161};
162
163static int reg_page_map_set(struct i2c_client *client, const u16 reg)
164{
165 int ret;
166 u16 page;
167 static int lastpage = -1; /* PageMap cache value */
168
169 page = (reg >> 8);
170 if (page == lastpage)
171 return 0;
172 if (page > 2)
173 return -EINVAL;
174
175 ret = i2c_smbus_write_word_data(client, MT9M111_PAGE_MAP, swab16(page));
176 if (!ret)
177 lastpage = page;
178 return ret;
179}
180
181static int mt9m111_reg_read(struct soc_camera_device *icd, const u16 reg)
182{
183 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
184 struct i2c_client *client = mt9m111->client;
185 int ret;
186
187 ret = reg_page_map_set(client, reg);
188 if (!ret)
189 ret = swab16(i2c_smbus_read_word_data(client, (reg & 0xff)));
190
191 dev_dbg(&icd->dev, "read reg.%03x -> %04x\n", reg, ret);
192 return ret;
193}
194
195static int mt9m111_reg_write(struct soc_camera_device *icd, const u16 reg,
196 const u16 data)
197{
198 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
199 struct i2c_client *client = mt9m111->client;
200 int ret;
201
202 ret = reg_page_map_set(client, reg);
203 if (!ret)
204 ret = i2c_smbus_write_word_data(mt9m111->client, (reg & 0xff),
205 swab16(data));
206 dev_dbg(&icd->dev, "write reg.%03x = %04x -> %d\n", reg, data, ret);
207 return ret;
208}
209
210static int mt9m111_reg_set(struct soc_camera_device *icd, const u16 reg,
211 const u16 data)
212{
213 int ret;
214
215 ret = mt9m111_reg_read(icd, reg);
216 if (ret >= 0)
217 ret = mt9m111_reg_write(icd, reg, ret | data);
218 return ret;
219}
220
221static int mt9m111_reg_clear(struct soc_camera_device *icd, const u16 reg,
222 const u16 data)
223{
224 int ret;
225
226 ret = mt9m111_reg_read(icd, reg);
227 return mt9m111_reg_write(icd, reg, ret & ~data);
228}
229
230static int mt9m111_set_context(struct soc_camera_device *icd,
231 enum mt9m111_context ctxt)
232{
233 int valB = MT9M111_CTXT_CTRL_RESTART | MT9M111_CTXT_CTRL_DEFECTCOR_B
234 | MT9M111_CTXT_CTRL_RESIZE_B | MT9M111_CTXT_CTRL_CTRL2_B
235 | MT9M111_CTXT_CTRL_GAMMA_B | MT9M111_CTXT_CTRL_READ_MODE_B
236 | MT9M111_CTXT_CTRL_VBLANK_SEL_B
237 | MT9M111_CTXT_CTRL_HBLANK_SEL_B;
238 int valA = MT9M111_CTXT_CTRL_RESTART;
239
240 if (ctxt == HIGHPOWER)
241 return reg_write(CONTEXT_CONTROL, valB);
242 else
243 return reg_write(CONTEXT_CONTROL, valA);
244}
245
246static int mt9m111_setup_rect(struct soc_camera_device *icd)
247{
248 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
249 int ret, is_raw_format;
250 int width = mt9m111->width;
251 int height = mt9m111->height;
252
253 if ((mt9m111->pixfmt == V4L2_PIX_FMT_SBGGR8)
254 || (mt9m111->pixfmt == V4L2_PIX_FMT_SBGGR16))
255 is_raw_format = 1;
256 else
257 is_raw_format = 0;
258
259 ret = reg_write(COLUMN_START, mt9m111->left);
260 if (!ret)
261 ret = reg_write(ROW_START, mt9m111->top);
262
263 if (is_raw_format) {
264 if (!ret)
265 ret = reg_write(WINDOW_WIDTH, width);
266 if (!ret)
267 ret = reg_write(WINDOW_HEIGHT, height);
268 } else {
269 if (!ret)
270 ret = reg_write(REDUCER_XZOOM_B, MT9M111_MAX_WIDTH);
271 if (!ret)
272 ret = reg_write(REDUCER_YZOOM_B, MT9M111_MAX_HEIGHT);
273 if (!ret)
274 ret = reg_write(REDUCER_XSIZE_B, width);
275 if (!ret)
276 ret = reg_write(REDUCER_YSIZE_B, height);
277 if (!ret)
278 ret = reg_write(REDUCER_XZOOM_A, MT9M111_MAX_WIDTH);
279 if (!ret)
280 ret = reg_write(REDUCER_YZOOM_A, MT9M111_MAX_HEIGHT);
281 if (!ret)
282 ret = reg_write(REDUCER_XSIZE_A, width);
283 if (!ret)
284 ret = reg_write(REDUCER_YSIZE_A, height);
285 }
286
287 return ret;
288}
289
290static int mt9m111_setup_pixfmt(struct soc_camera_device *icd, u16 outfmt)
291{
292 int ret;
293
294 ret = reg_write(OUTPUT_FORMAT_CTRL2_A, outfmt);
295 if (!ret)
296 ret = reg_write(OUTPUT_FORMAT_CTRL2_B, outfmt);
297 return ret;
298}
299
300static int mt9m111_setfmt_bayer8(struct soc_camera_device *icd)
301{
302 return mt9m111_setup_pixfmt(icd, MT9M111_OUTFMT_PROCESSED_BAYER);
303}
304
305static int mt9m111_setfmt_bayer10(struct soc_camera_device *icd)
306{
307 return mt9m111_setup_pixfmt(icd, MT9M111_OUTFMT_BYPASS_IFP);
308}
309
310static int mt9m111_setfmt_rgb565(struct soc_camera_device *icd)
311{
312 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
313 int val = 0;
314
315 if (mt9m111->swap_rgb_red_blue)
316 val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
317 if (mt9m111->swap_rgb_even_odd)
318 val |= MT9M111_OUTFMT_SWAP_RGB_EVEN;
319 val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565;
320
321 return mt9m111_setup_pixfmt(icd, val);
322}
323
324static int mt9m111_setfmt_rgb555(struct soc_camera_device *icd)
325{
326 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
327 int val = 0;
328
329 if (mt9m111->swap_rgb_red_blue)
330 val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
331 if (mt9m111->swap_rgb_even_odd)
332 val |= MT9M111_OUTFMT_SWAP_RGB_EVEN;
333 val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB555;
334
335 return mt9m111_setup_pixfmt(icd, val);
336}
337
338static int mt9m111_setfmt_yuv(struct soc_camera_device *icd)
339{
340 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
341 int val = 0;
342
343 if (mt9m111->swap_yuv_cb_cr)
344 val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
345 if (mt9m111->swap_yuv_y_chromas)
346 val |= MT9M111_OUTFMT_SWAP_YCbCr_C_Y;
347
348 return mt9m111_setup_pixfmt(icd, val);
349}
350
351static int mt9m111_enable(struct soc_camera_device *icd)
352{
353 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
354 struct soc_camera_link *icl = mt9m111->client->dev.platform_data;
355 int ret;
356
357 if (icl->power) {
358 ret = icl->power(&mt9m111->client->dev, 1);
359 if (ret < 0) {
360 dev_err(icd->vdev->parent,
361 "Platform failed to power-on the camera.\n");
362 return ret;
363 }
364 }
365
366 ret = reg_set(RESET, MT9M111_RESET_CHIP_ENABLE);
367 if (!ret)
368 mt9m111->powered = 1;
369 return ret;
370}
371
372static int mt9m111_disable(struct soc_camera_device *icd)
373{
374 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
375 struct soc_camera_link *icl = mt9m111->client->dev.platform_data;
376 int ret;
377
378 ret = reg_clear(RESET, MT9M111_RESET_CHIP_ENABLE);
379 if (!ret)
380 mt9m111->powered = 0;
381
382 if (icl->power)
383 icl->power(&mt9m111->client->dev, 0);
384
385 return ret;
386}
387
388static int mt9m111_reset(struct soc_camera_device *icd)
389{
390 int ret;
391
392 ret = reg_set(RESET, MT9M111_RESET_RESET_MODE);
393 if (!ret)
394 ret = reg_set(RESET, MT9M111_RESET_RESET_SOC);
395 if (!ret)
396 ret = reg_clear(RESET, MT9M111_RESET_RESET_MODE
397 | MT9M111_RESET_RESET_SOC);
398 return ret;
399}
400
401static int mt9m111_start_capture(struct soc_camera_device *icd)
402{
403 return 0;
404}
405
406static int mt9m111_stop_capture(struct soc_camera_device *icd)
407{
408 return 0;
409}
410
411static unsigned long mt9m111_query_bus_param(struct soc_camera_device *icd)
412{
413 return SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |
414 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
415 SOCAM_DATAWIDTH_8;
416}
417
418static int mt9m111_set_bus_param(struct soc_camera_device *icd, unsigned long f)
419{
420 return 0;
421}
422
423static int mt9m111_set_pixfmt(struct soc_camera_device *icd, u32 pixfmt)
424{
425 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
426 int ret;
427
428 switch (pixfmt) {
429 case V4L2_PIX_FMT_SBGGR8:
430 ret = mt9m111_setfmt_bayer8(icd);
431 break;
432 case V4L2_PIX_FMT_SBGGR16:
433 ret = mt9m111_setfmt_bayer10(icd);
434 break;
435 case V4L2_PIX_FMT_RGB555:
436 ret = mt9m111_setfmt_rgb555(icd);
437 break;
438 case V4L2_PIX_FMT_RGB565:
439 ret = mt9m111_setfmt_rgb565(icd);
440 break;
441 case V4L2_PIX_FMT_YUYV:
442 ret = mt9m111_setfmt_yuv(icd);
443 break;
444 default:
445 dev_err(&icd->dev, "Pixel format not handled : %x\n", pixfmt);
446 ret = -EINVAL;
447 }
448
449 if (!ret)
450 mt9m111->pixfmt = pixfmt;
451
452 return ret;
453}
454
455static int mt9m111_set_fmt_cap(struct soc_camera_device *icd,
456 __u32 pixfmt, struct v4l2_rect *rect)
457{
458 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
459 int ret;
460
461 mt9m111->left = rect->left;
462 mt9m111->top = rect->top;
463 mt9m111->width = rect->width;
464 mt9m111->height = rect->height;
465
466 dev_dbg(&icd->dev, "%s fmt=%x left=%d, top=%d, width=%d, height=%d\n",
467 __func__, pixfmt, mt9m111->left, mt9m111->top, mt9m111->width,
468 mt9m111->height);
469
470 ret = mt9m111_setup_rect(icd);
471 if (!ret)
472 ret = mt9m111_set_pixfmt(icd, pixfmt);
473 return ret;
474}
475
476static int mt9m111_try_fmt_cap(struct soc_camera_device *icd,
477 struct v4l2_format *f)
478{
479 if (f->fmt.pix.height > MT9M111_MAX_HEIGHT)
480 f->fmt.pix.height = MT9M111_MAX_HEIGHT;
481 if (f->fmt.pix.width > MT9M111_MAX_WIDTH)
482 f->fmt.pix.width = MT9M111_MAX_WIDTH;
483
484 return 0;
485}
486
487static int mt9m111_get_chip_id(struct soc_camera_device *icd,
488 struct v4l2_chip_ident *id)
489{
490 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
491
492 if (id->match_type != V4L2_CHIP_MATCH_I2C_ADDR)
493 return -EINVAL;
494
495 if (id->match_chip != mt9m111->client->addr)
496 return -ENODEV;
497
498 id->ident = mt9m111->model;
499 id->revision = 0;
500
501 return 0;
502}
503
504#ifdef CONFIG_VIDEO_ADV_DEBUG
505static int mt9m111_get_register(struct soc_camera_device *icd,
506 struct v4l2_register *reg)
507{
508 int val;
509
510 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
511
512 if (reg->match_type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff)
513 return -EINVAL;
514 if (reg->match_chip != mt9m111->client->addr)
515 return -ENODEV;
516
517 val = mt9m111_reg_read(icd, reg->reg);
518 reg->val = (u64)val;
519
520 if (reg->val > 0xffff)
521 return -EIO;
522
523 return 0;
524}
525
526static int mt9m111_set_register(struct soc_camera_device *icd,
527 struct v4l2_register *reg)
528{
529 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
530
531 if (reg->match_type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff)
532 return -EINVAL;
533
534 if (reg->match_chip != mt9m111->client->addr)
535 return -ENODEV;
536
537 if (mt9m111_reg_write(icd, reg->reg, reg->val) < 0)
538 return -EIO;
539
540 return 0;
541}
542#endif
543
544static const struct v4l2_queryctrl mt9m111_controls[] = {
545 {
546 .id = V4L2_CID_VFLIP,
547 .type = V4L2_CTRL_TYPE_BOOLEAN,
548 .name = "Flip Verticaly",
549 .minimum = 0,
550 .maximum = 1,
551 .step = 1,
552 .default_value = 0,
553 }, {
554 .id = V4L2_CID_HFLIP,
555 .type = V4L2_CTRL_TYPE_BOOLEAN,
556 .name = "Flip Horizontaly",
557 .minimum = 0,
558 .maximum = 1,
559 .step = 1,
560 .default_value = 0,
561 }, { /* gain = 1/32*val (=>gain=1 if val==32) */
562 .id = V4L2_CID_GAIN,
563 .type = V4L2_CTRL_TYPE_INTEGER,
564 .name = "Gain",
565 .minimum = 0,
566 .maximum = 63 * 2 * 2,
567 .step = 1,
568 .default_value = 32,
569 .flags = V4L2_CTRL_FLAG_SLIDER,
570 }, {
571 .id = V4L2_CID_EXPOSURE_AUTO,
572 .type = V4L2_CTRL_TYPE_BOOLEAN,
573 .name = "Auto Exposure",
574 .minimum = 0,
575 .maximum = 1,
576 .step = 1,
577 .default_value = 1,
578 }
579};
580
581static int mt9m111_video_probe(struct soc_camera_device *);
582static void mt9m111_video_remove(struct soc_camera_device *);
583static int mt9m111_get_control(struct soc_camera_device *,
584 struct v4l2_control *);
585static int mt9m111_set_control(struct soc_camera_device *,
586 struct v4l2_control *);
587static int mt9m111_resume(struct soc_camera_device *icd);
588static int mt9m111_init(struct soc_camera_device *icd);
589static int mt9m111_release(struct soc_camera_device *icd);
590
591static struct soc_camera_ops mt9m111_ops = {
592 .owner = THIS_MODULE,
593 .probe = mt9m111_video_probe,
594 .remove = mt9m111_video_remove,
595 .init = mt9m111_init,
596 .resume = mt9m111_resume,
597 .release = mt9m111_release,
598 .start_capture = mt9m111_start_capture,
599 .stop_capture = mt9m111_stop_capture,
600 .set_fmt_cap = mt9m111_set_fmt_cap,
601 .try_fmt_cap = mt9m111_try_fmt_cap,
602 .query_bus_param = mt9m111_query_bus_param,
603 .set_bus_param = mt9m111_set_bus_param,
604 .controls = mt9m111_controls,
605 .num_controls = ARRAY_SIZE(mt9m111_controls),
606 .get_control = mt9m111_get_control,
607 .set_control = mt9m111_set_control,
608 .get_chip_id = mt9m111_get_chip_id,
609#ifdef CONFIG_VIDEO_ADV_DEBUG
610 .get_register = mt9m111_get_register,
611 .set_register = mt9m111_set_register,
612#endif
613};
614
615static int mt9m111_set_flip(struct soc_camera_device *icd, int flip, int mask)
616{
617 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
618 int ret;
619
620 if (mt9m111->context == HIGHPOWER) {
621 if (flip)
622 ret = reg_set(READ_MODE_B, mask);
623 else
624 ret = reg_clear(READ_MODE_B, mask);
625 } else {
626 if (flip)
627 ret = reg_set(READ_MODE_A, mask);
628 else
629 ret = reg_clear(READ_MODE_A, mask);
630 }
631
632 return ret;
633}
634
635static int mt9m111_get_global_gain(struct soc_camera_device *icd)
636{
637 unsigned int data, gain;
638
639 data = reg_read(GLOBAL_GAIN);
640 if (data >= 0)
641 gain = ((data & (1 << 10)) * 2)
642 | ((data & (1 << 9)) * 2)
643 | (data & 0x2f);
644 else
645 gain = data;
646
647 return gain;
648}
649static int mt9m111_set_global_gain(struct soc_camera_device *icd, int gain)
650{
651 u16 val;
652
653 if (gain > 63 * 2 * 2)
654 return -EINVAL;
655
656 icd->gain = gain;
657 if ((gain >= 64 * 2) && (gain < 63 * 2 * 2))
658 val = (1 << 10) | (1 << 9) | (gain / 4);
659 else if ((gain >= 64) && (gain < 64 * 2))
660 val = (1 << 9) | (gain / 2);
661 else
662 val = gain;
663
664 return reg_write(GLOBAL_GAIN, val);
665}
666
667static int mt9m111_set_autoexposure(struct soc_camera_device *icd, int on)
668{
669 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
670 int ret;
671
672 if (on)
673 ret = reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN);
674 else
675 ret = reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN);
676
677 if (!ret)
678 mt9m111->autoexposure = on;
679
680 return ret;
681}
682static int mt9m111_get_control(struct soc_camera_device *icd,
683 struct v4l2_control *ctrl)
684{
685 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
686 int data;
687
688 switch (ctrl->id) {
689 case V4L2_CID_VFLIP:
690 if (mt9m111->context == HIGHPOWER)
691 data = reg_read(READ_MODE_B);
692 else
693 data = reg_read(READ_MODE_A);
694
695 if (data < 0)
696 return -EIO;
697 ctrl->value = !!(data & MT9M111_RMB_MIRROR_ROWS);
698 break;
699 case V4L2_CID_HFLIP:
700 if (mt9m111->context == HIGHPOWER)
701 data = reg_read(READ_MODE_B);
702 else
703 data = reg_read(READ_MODE_A);
704
705 if (data < 0)
706 return -EIO;
707 ctrl->value = !!(data & MT9M111_RMB_MIRROR_COLS);
708 break;
709 case V4L2_CID_GAIN:
710 data = mt9m111_get_global_gain(icd);
711 if (data < 0)
712 return data;
713 ctrl->value = data;
714 break;
715 case V4L2_CID_EXPOSURE_AUTO:
716 ctrl->value = mt9m111->autoexposure;
717 break;
718 }
719 return 0;
720}
721
722static int mt9m111_set_control(struct soc_camera_device *icd,
723 struct v4l2_control *ctrl)
724{
725 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
726 const struct v4l2_queryctrl *qctrl;
727 int ret;
728
729 qctrl = soc_camera_find_qctrl(&mt9m111_ops, ctrl->id);
730
731 if (!qctrl)
732 return -EINVAL;
733
734 switch (ctrl->id) {
735 case V4L2_CID_VFLIP:
736 mt9m111->vflip = ctrl->value;
737 ret = mt9m111_set_flip(icd, ctrl->value,
738 MT9M111_RMB_MIRROR_ROWS);
739 break;
740 case V4L2_CID_HFLIP:
741 mt9m111->hflip = ctrl->value;
742 ret = mt9m111_set_flip(icd, ctrl->value,
743 MT9M111_RMB_MIRROR_COLS);
744 break;
745 case V4L2_CID_GAIN:
746 ret = mt9m111_set_global_gain(icd, ctrl->value);
747 break;
748 case V4L2_CID_EXPOSURE_AUTO:
749 ret = mt9m111_set_autoexposure(icd, ctrl->value);
750 break;
751 default:
752 ret = -EINVAL;
753 }
754
755 return ret;
756}
757
758static int mt9m111_restore_state(struct soc_camera_device *icd)
759{
760 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
761
762 mt9m111_set_context(icd, mt9m111->context);
763 mt9m111_set_pixfmt(icd, mt9m111->pixfmt);
764 mt9m111_setup_rect(icd);
765 mt9m111_set_flip(icd, mt9m111->hflip, MT9M111_RMB_MIRROR_COLS);
766 mt9m111_set_flip(icd, mt9m111->vflip, MT9M111_RMB_MIRROR_ROWS);
767 mt9m111_set_global_gain(icd, icd->gain);
768 mt9m111_set_autoexposure(icd, mt9m111->autoexposure);
769 return 0;
770}
771
772static int mt9m111_resume(struct soc_camera_device *icd)
773{
774 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
775 int ret = 0;
776
777 if (mt9m111->powered) {
778 ret = mt9m111_enable(icd);
779 if (!ret)
780 ret = mt9m111_reset(icd);
781 if (!ret)
782 ret = mt9m111_restore_state(icd);
783 }
784 return ret;
785}
786
787static int mt9m111_init(struct soc_camera_device *icd)
788{
789 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
790 int ret;
791
792 mt9m111->context = HIGHPOWER;
793 ret = mt9m111_enable(icd);
794 if (!ret)
795 ret = mt9m111_reset(icd);
796 if (!ret)
797 ret = mt9m111_set_context(icd, mt9m111->context);
798 if (!ret)
799 ret = mt9m111_set_autoexposure(icd, mt9m111->autoexposure);
800 if (ret)
801 dev_err(&icd->dev, "mt9m111 init failed: %d\n", ret);
802 return ret;
803}
804
805static int mt9m111_release(struct soc_camera_device *icd)
806{
807 int ret;
808
809 ret = mt9m111_disable(icd);
810 if (ret < 0)
811 dev_err(&icd->dev, "mt9m111 release failed: %d\n", ret);
812
813 return ret;
814}
815
816/*
817 * Interface active, can use i2c. If it fails, it can indeed mean, that
818 * this wasn't our capture interface, so, we wait for the right one
819 */
820static int mt9m111_video_probe(struct soc_camera_device *icd)
821{
822 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
823 s32 data;
824 int ret;
825
826 /*
827 * We must have a parent by now. And it cannot be a wrong one.
828 * So this entire test is completely redundant.
829 */
830 if (!icd->dev.parent ||
831 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
832 return -ENODEV;
833
834 ret = mt9m111_enable(icd);
835 if (ret)
836 goto ei2c;
837 ret = mt9m111_reset(icd);
838 if (ret)
839 goto ei2c;
840
841 data = reg_read(CHIP_VERSION);
842
843 switch (data) {
844 case 0x143a:
845 mt9m111->model = V4L2_IDENT_MT9M111;
846 icd->formats = mt9m111_colour_formats;
847 icd->num_formats = ARRAY_SIZE(mt9m111_colour_formats);
848 break;
849 default:
850 ret = -ENODEV;
851 dev_err(&icd->dev,
852 "No MT9M111 chip detected, register read %x\n", data);
853 goto ei2c;
854 }
855
856 dev_info(&icd->dev, "Detected a MT9M111 chip ID 0x143a\n");
857
858 ret = soc_camera_video_start(icd);
859 if (ret)
860 goto eisis;
861
862 mt9m111->autoexposure = 1;
863
864 mt9m111->swap_rgb_even_odd = 1;
865 mt9m111->swap_rgb_red_blue = 1;
866
867 return 0;
868eisis:
869ei2c:
870 return ret;
871}
872
873static void mt9m111_video_remove(struct soc_camera_device *icd)
874{
875 struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
876
877 dev_dbg(&icd->dev, "Video %x removed: %p, %p\n", mt9m111->client->addr,
878 mt9m111->icd.dev.parent, mt9m111->icd.vdev);
879 soc_camera_video_stop(&mt9m111->icd);
880}
881
882static int mt9m111_probe(struct i2c_client *client,
883 const struct i2c_device_id *did)
884{
885 struct mt9m111 *mt9m111;
886 struct soc_camera_device *icd;
887 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
888 struct soc_camera_link *icl = client->dev.platform_data;
889 int ret;
890
891 if (!icl) {
892 dev_err(&client->dev, "MT9M111 driver needs platform data\n");
893 return -EINVAL;
894 }
895
896 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) {
897 dev_warn(&adapter->dev,
898 "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");
899 return -EIO;
900 }
901
902 mt9m111 = kzalloc(sizeof(struct mt9m111), GFP_KERNEL);
903 if (!mt9m111)
904 return -ENOMEM;
905
906 mt9m111->client = client;
907 i2c_set_clientdata(client, mt9m111);
908
909 /* Second stage probe - when a capture adapter is there */
910 icd = &mt9m111->icd;
911 icd->ops = &mt9m111_ops;
912 icd->control = &client->dev;
913 icd->x_min = MT9M111_MIN_DARK_COLS;
914 icd->y_min = MT9M111_MIN_DARK_ROWS;
915 icd->x_current = icd->x_min;
916 icd->y_current = icd->y_min;
917 icd->width_min = MT9M111_MIN_DARK_ROWS;
918 icd->width_max = MT9M111_MAX_WIDTH;
919 icd->height_min = MT9M111_MIN_DARK_COLS;
920 icd->height_max = MT9M111_MAX_HEIGHT;
921 icd->y_skip_top = 0;
922 icd->iface = icl->bus_id;
923
924 ret = soc_camera_device_register(icd);
925 if (ret)
926 goto eisdr;
927 return 0;
928
929eisdr:
930 kfree(mt9m111);
931 return ret;
932}
933
934static int mt9m111_remove(struct i2c_client *client)
935{
936 struct mt9m111 *mt9m111 = i2c_get_clientdata(client);
937 soc_camera_device_unregister(&mt9m111->icd);
938 kfree(mt9m111);
939
940 return 0;
941}
942
943static const struct i2c_device_id mt9m111_id[] = {
944 { "mt9m111", 0 },
945 { }
946};
947MODULE_DEVICE_TABLE(i2c, mt9m111_id);
948
949static struct i2c_driver mt9m111_i2c_driver = {
950 .driver = {
951 .name = "mt9m111",
952 },
953 .probe = mt9m111_probe,
954 .remove = mt9m111_remove,
955 .id_table = mt9m111_id,
956};
957
958static int __init mt9m111_mod_init(void)
959{
960 return i2c_add_driver(&mt9m111_i2c_driver);
961}
962
963static void __exit mt9m111_mod_exit(void)
964{
965 i2c_del_driver(&mt9m111_i2c_driver);
966}
967
968module_init(mt9m111_mod_init);
969module_exit(mt9m111_mod_exit);
970
971MODULE_DESCRIPTION("Micron MT9M111 Camera driver");
972MODULE_AUTHOR("Robert Jarzmik");
973MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/mt9v022.c b/drivers/media/video/mt9v022.c
index 56808cd2f8a9..2584201059d8 100644
--- a/drivers/media/video/mt9v022.c
+++ b/drivers/media/video/mt9v022.c
@@ -134,34 +134,56 @@ static int reg_clear(struct soc_camera_device *icd, const u8 reg,
134static int mt9v022_init(struct soc_camera_device *icd) 134static int mt9v022_init(struct soc_camera_device *icd)
135{ 135{
136 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd); 136 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
137 struct soc_camera_link *icl = mt9v022->client->dev.platform_data;
137 int ret; 138 int ret;
138 139
140 if (icl->power) {
141 ret = icl->power(&mt9v022->client->dev, 1);
142 if (ret < 0) {
143 dev_err(icd->vdev->parent,
144 "Platform failed to power-on the camera.\n");
145 return ret;
146 }
147 }
148
149 /*
150 * The camera could have been already on, we hard-reset it additionally,
151 * if available. Soft reset is done in video_probe().
152 */
153 if (icl->reset)
154 icl->reset(&mt9v022->client->dev);
155
139 /* Almost the default mode: master, parallel, simultaneous, and an 156 /* Almost the default mode: master, parallel, simultaneous, and an
140 * undocumented bit 0x200, which is present in table 7, but not in 8, 157 * undocumented bit 0x200, which is present in table 7, but not in 8,
141 * plus snapshot mode to disable scan for now */ 158 * plus snapshot mode to disable scan for now */
142 mt9v022->chip_control |= 0x10; 159 mt9v022->chip_control |= 0x10;
143 ret = reg_write(icd, MT9V022_CHIP_CONTROL, mt9v022->chip_control); 160 ret = reg_write(icd, MT9V022_CHIP_CONTROL, mt9v022->chip_control);
144 if (ret >= 0) 161 if (!ret)
145 reg_write(icd, MT9V022_READ_MODE, 0x300); 162 ret = reg_write(icd, MT9V022_READ_MODE, 0x300);
146 163
147 /* All defaults */ 164 /* All defaults */
148 if (ret >= 0) 165 if (!ret)
149 /* AEC, AGC on */ 166 /* AEC, AGC on */
150 ret = reg_set(icd, MT9V022_AEC_AGC_ENABLE, 0x3); 167 ret = reg_set(icd, MT9V022_AEC_AGC_ENABLE, 0x3);
151 if (ret >= 0) 168 if (!ret)
152 ret = reg_write(icd, MT9V022_MAX_TOTAL_SHUTTER_WIDTH, 480); 169 ret = reg_write(icd, MT9V022_MAX_TOTAL_SHUTTER_WIDTH, 480);
153 if (ret >= 0) 170 if (!ret)
154 /* default - auto */ 171 /* default - auto */
155 ret = reg_clear(icd, MT9V022_BLACK_LEVEL_CALIB_CTRL, 1); 172 ret = reg_clear(icd, MT9V022_BLACK_LEVEL_CALIB_CTRL, 1);
156 if (ret >= 0) 173 if (!ret)
157 ret = reg_write(icd, MT9V022_DIGITAL_TEST_PATTERN, 0); 174 ret = reg_write(icd, MT9V022_DIGITAL_TEST_PATTERN, 0);
158 175
159 return ret >= 0 ? 0 : -EIO; 176 return ret;
160} 177}
161 178
162static int mt9v022_release(struct soc_camera_device *icd) 179static int mt9v022_release(struct soc_camera_device *icd)
163{ 180{
164 /* Nothing? */ 181 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
182 struct soc_camera_link *icl = mt9v022->client->dev.platform_data;
183
184 if (icl->power)
185 icl->power(&mt9v022->client->dev, 0);
186
165 return 0; 187 return 0;
166} 188}
167 189
@@ -352,21 +374,21 @@ static int mt9v022_set_fmt_cap(struct soc_camera_device *icd,
352 rect->height + icd->y_skip_top + 43); 374 rect->height + icd->y_skip_top + 43);
353 } 375 }
354 /* Setup frame format: defaults apart from width and height */ 376 /* Setup frame format: defaults apart from width and height */
355 if (ret >= 0) 377 if (!ret)
356 ret = reg_write(icd, MT9V022_COLUMN_START, rect->left); 378 ret = reg_write(icd, MT9V022_COLUMN_START, rect->left);
357 if (ret >= 0) 379 if (!ret)
358 ret = reg_write(icd, MT9V022_ROW_START, rect->top); 380 ret = reg_write(icd, MT9V022_ROW_START, rect->top);
359 if (ret >= 0) 381 if (!ret)
360 /* Default 94, Phytec driver says: 382 /* Default 94, Phytec driver says:
361 * "width + horizontal blank >= 660" */ 383 * "width + horizontal blank >= 660" */
362 ret = reg_write(icd, MT9V022_HORIZONTAL_BLANKING, 384 ret = reg_write(icd, MT9V022_HORIZONTAL_BLANKING,
363 rect->width > 660 - 43 ? 43 : 385 rect->width > 660 - 43 ? 43 :
364 660 - rect->width); 386 660 - rect->width);
365 if (ret >= 0) 387 if (!ret)
366 ret = reg_write(icd, MT9V022_VERTICAL_BLANKING, 45); 388 ret = reg_write(icd, MT9V022_VERTICAL_BLANKING, 45);
367 if (ret >= 0) 389 if (!ret)
368 ret = reg_write(icd, MT9V022_WINDOW_WIDTH, rect->width); 390 ret = reg_write(icd, MT9V022_WINDOW_WIDTH, rect->width);
369 if (ret >= 0) 391 if (!ret)
370 ret = reg_write(icd, MT9V022_WINDOW_HEIGHT, 392 ret = reg_write(icd, MT9V022_WINDOW_HEIGHT,
371 rect->height + icd->y_skip_top); 393 rect->height + icd->y_skip_top);
372 394
@@ -717,7 +739,7 @@ static int mt9v022_video_probe(struct soc_camera_device *icd)
717 icd->num_formats = 1; 739 icd->num_formats = 1;
718 } 740 }
719 741
720 if (ret >= 0) 742 if (!ret)
721 ret = soc_camera_video_start(icd); 743 ret = soc_camera_video_start(icd);
722 if (ret < 0) 744 if (ret < 0)
723 goto eisis; 745 goto eisis;
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index 8ef578caba3b..7f130284b5c7 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -27,6 +27,7 @@
27#include <media/tuner.h> 27#include <media/tuner.h>
28#include <linux/video_decoder.h> 28#include <linux/video_decoder.h>
29#include <media/v4l2-common.h> 29#include <media/v4l2-common.h>
30#include <media/saa7115.h>
30 31
31#include "mxb.h" 32#include "mxb.h"
32#include "tea6415c.h" 33#include "tea6415c.h"
@@ -122,6 +123,8 @@ static struct saa7146_extension_ioctls ioctls[] = {
122 { VIDIOC_S_FREQUENCY, SAA7146_EXCLUSIVE }, 123 { VIDIOC_S_FREQUENCY, SAA7146_EXCLUSIVE },
123 { VIDIOC_G_AUDIO, SAA7146_EXCLUSIVE }, 124 { VIDIOC_G_AUDIO, SAA7146_EXCLUSIVE },
124 { VIDIOC_S_AUDIO, SAA7146_EXCLUSIVE }, 125 { VIDIOC_S_AUDIO, SAA7146_EXCLUSIVE },
126 { VIDIOC_DBG_G_REGISTER, SAA7146_EXCLUSIVE },
127 { VIDIOC_DBG_S_REGISTER, SAA7146_EXCLUSIVE },
125 { MXB_S_AUDIO_CD, SAA7146_EXCLUSIVE }, /* custom control */ 128 { MXB_S_AUDIO_CD, SAA7146_EXCLUSIVE }, /* custom control */
126 { MXB_S_AUDIO_LINE, SAA7146_EXCLUSIVE }, /* custom control */ 129 { MXB_S_AUDIO_LINE, SAA7146_EXCLUSIVE }, /* custom control */
127 { 0, 0 } 130 { 0, 0 }
@@ -134,12 +137,12 @@ struct mxb
134 137
135 struct i2c_adapter i2c_adapter; 138 struct i2c_adapter i2c_adapter;
136 139
137 struct i2c_client* saa7111a; 140 struct i2c_client *saa7111a;
138 struct i2c_client* tda9840; 141 struct i2c_client *tda9840;
139 struct i2c_client* tea6415c; 142 struct i2c_client *tea6415c;
140 struct i2c_client* tuner; 143 struct i2c_client *tuner;
141 struct i2c_client* tea6420_1; 144 struct i2c_client *tea6420_1;
142 struct i2c_client* tea6420_2; 145 struct i2c_client *tea6420_2;
143 146
144 int cur_mode; /* current audio mode (mono, stereo, ...) */ 147 int cur_mode; /* current audio mode (mono, stereo, ...) */
145 int cur_input; /* current input */ 148 int cur_input; /* current input */
@@ -151,23 +154,23 @@ static struct saa7146_extension extension;
151 154
152static int mxb_check_clients(struct device *dev, void *data) 155static int mxb_check_clients(struct device *dev, void *data)
153{ 156{
154 struct mxb* mxb = data; 157 struct mxb *mxb = data;
155 struct i2c_client *client = i2c_verify_client(dev); 158 struct i2c_client *client = i2c_verify_client(dev);
156 159
157 if( !client ) 160 if (!client)
158 return 0; 161 return 0;
159 162
160 if( I2C_ADDR_TEA6420_1 == client->addr ) 163 if (I2C_ADDR_TEA6420_1 == client->addr)
161 mxb->tea6420_1 = client; 164 mxb->tea6420_1 = client;
162 if( I2C_ADDR_TEA6420_2 == client->addr ) 165 if (I2C_ADDR_TEA6420_2 == client->addr)
163 mxb->tea6420_2 = client; 166 mxb->tea6420_2 = client;
164 if( I2C_TEA6415C_2 == client->addr ) 167 if (I2C_TEA6415C_2 == client->addr)
165 mxb->tea6415c = client; 168 mxb->tea6415c = client;
166 if( I2C_ADDR_TDA9840 == client->addr ) 169 if (I2C_ADDR_TDA9840 == client->addr)
167 mxb->tda9840 = client; 170 mxb->tda9840 = client;
168 if( I2C_SAA7111 == client->addr ) 171 if (I2C_SAA7111 == client->addr)
169 mxb->saa7111a = client; 172 mxb->saa7111a = client;
170 if( 0x60 == client->addr ) 173 if (0x60 == client->addr)
171 mxb->tuner = client; 174 mxb->tuner = client;
172 175
173 return 0; 176 return 0;
@@ -178,23 +181,28 @@ static int mxb_probe(struct saa7146_dev* dev)
178 struct mxb* mxb = NULL; 181 struct mxb* mxb = NULL;
179 int result; 182 int result;
180 183
181 if ((result = request_module("saa7111")) < 0) { 184 result = request_module("saa7115");
185 if (result < 0) {
182 printk("mxb: saa7111 i2c module not available.\n"); 186 printk("mxb: saa7111 i2c module not available.\n");
183 return -ENODEV; 187 return -ENODEV;
184 } 188 }
185 if ((result = request_module("tea6420")) < 0) { 189 result = request_module("tea6420");
190 if (result < 0) {
186 printk("mxb: tea6420 i2c module not available.\n"); 191 printk("mxb: tea6420 i2c module not available.\n");
187 return -ENODEV; 192 return -ENODEV;
188 } 193 }
189 if ((result = request_module("tea6415c")) < 0) { 194 result = request_module("tea6415c");
195 if (result < 0) {
190 printk("mxb: tea6415c i2c module not available.\n"); 196 printk("mxb: tea6415c i2c module not available.\n");
191 return -ENODEV; 197 return -ENODEV;
192 } 198 }
193 if ((result = request_module("tda9840")) < 0) { 199 result = request_module("tda9840");
200 if (result < 0) {
194 printk("mxb: tda9840 i2c module not available.\n"); 201 printk("mxb: tda9840 i2c module not available.\n");
195 return -ENODEV; 202 return -ENODEV;
196 } 203 }
197 if ((result = request_module("tuner")) < 0) { 204 result = request_module("tuner");
205 if (result < 0) {
198 printk("mxb: tuner i2c module not available.\n"); 206 printk("mxb: tuner i2c module not available.\n");
199 return -ENODEV; 207 return -ENODEV;
200 } 208 }
@@ -207,9 +215,10 @@ static int mxb_probe(struct saa7146_dev* dev)
207 215
208 mxb->i2c_adapter = (struct i2c_adapter) { 216 mxb->i2c_adapter = (struct i2c_adapter) {
209 .class = I2C_CLASS_TV_ANALOG, 217 .class = I2C_CLASS_TV_ANALOG,
210 .name = "mxb",
211 }; 218 };
212 219
220 snprintf(mxb->i2c_adapter.name, sizeof(mxb->i2c_adapter.name), "mxb%d", mxb_num);
221
213 saa7146_i2c_adapter_prepare(dev, &mxb->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480); 222 saa7146_i2c_adapter_prepare(dev, &mxb->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
214 if(i2c_add_adapter(&mxb->i2c_adapter) < 0) { 223 if(i2c_add_adapter(&mxb->i2c_adapter) < 0) {
215 DEB_S(("cannot register i2c-device. skipping.\n")); 224 DEB_S(("cannot register i2c-device. skipping.\n"));
@@ -290,38 +299,7 @@ static struct {
290 { 9, { 0x1d, 0xed, 0xd0, 0x68, 0x29, 0xb4, 0xe1, 0x00, 0xb8 } }, 299 { 9, { 0x1d, 0xed, 0xd0, 0x68, 0x29, 0xb4, 0xe1, 0x00, 0xb8 } },
291 { 9, { 0x3d, 0xed, 0xd0, 0x68, 0x29, 0xb4, 0xe1, 0x00, 0xb8 } }, 300 { 9, { 0x3d, 0xed, 0xd0, 0x68, 0x29, 0xb4, 0xe1, 0x00, 0xb8 } },
292 { 3, { 0x80, 0xb3, 0x0a } }, 301 { 3, { 0x80, 0xb3, 0x0a } },
293 {-1, { 0} } 302 {-1, { 0 } }
294};
295
296static const unsigned char mxb_saa7111_init[] = {
297 0x00, 0x00, /* 00 - ID byte */
298 0x01, 0x00, /* 01 - reserved */
299
300 /*front end */
301 0x02, 0xd8, /* 02 - FUSE=x, GUDL=x, MODE=x */
302 0x03, 0x23, /* 03 - HLNRS=0, VBSL=1, WPOFF=0, HOLDG=0, GAFIX=0, GAI1=256, GAI2=256 */
303 0x04, 0x00, /* 04 - GAI1=256 */
304 0x05, 0x00, /* 05 - GAI2=256 */
305
306 /* decoder */
307 0x06, 0xf0, /* 06 - HSB at xx(50Hz) / xx(60Hz) pixels after end of last line */
308 0x07, 0x30, /* 07 - HSS at xx(50Hz) / xx(60Hz) pixels after end of last line */
309 0x08, 0xa8, /* 08 - AUFD=x, FSEL=x, EXFIL=x, VTRC=x, HPLL=x, VNOI=x */
310 0x09, 0x02, /* 09 - BYPS=x, PREF=x, BPSS=x, VBLB=x, UPTCV=x, APER=x */
311 0x0a, 0x80, /* 0a - BRIG=128 */
312 0x0b, 0x47, /* 0b - CONT=1.109 */
313 0x0c, 0x40, /* 0c - SATN=1.0 */
314 0x0d, 0x00, /* 0d - HUE=0 */
315 0x0e, 0x01, /* 0e - CDTO=0, CSTD=0, DCCF=0, FCTC=0, CHBW=1 */
316 0x0f, 0x00, /* 0f - reserved */
317 0x10, 0xd0, /* 10 - OFTS=x, HDEL=x, VRLN=x, YDEL=x */
318 0x11, 0x8c, /* 11 - GPSW=x, CM99=x, FECO=x, COMPO=x, OEYC=1, OEHV=1, VIPB=0, COLO=0 */
319 0x12, 0x80, /* 12 - xx output control 2 */
320 0x13, 0x30, /* 13 - xx output control 3 */
321 0x14, 0x00, /* 14 - reserved */
322 0x15, 0x15, /* 15 - VBI */
323 0x16, 0x04, /* 16 - VBI */
324 0x17, 0x00, /* 17 - VBI */
325}; 303};
326 304
327/* bring hardware to a sane state. this has to be done, just in case someone 305/* bring hardware to a sane state. this has to be done, just in case someone
@@ -331,37 +309,28 @@ static const unsigned char mxb_saa7111_init[] = {
331static int mxb_init_done(struct saa7146_dev* dev) 309static int mxb_init_done(struct saa7146_dev* dev)
332{ 310{
333 struct mxb* mxb = (struct mxb*)dev->ext_priv; 311 struct mxb* mxb = (struct mxb*)dev->ext_priv;
334 struct video_decoder_init init;
335 struct i2c_msg msg; 312 struct i2c_msg msg;
336 struct tuner_setup tun_setup; 313 struct tuner_setup tun_setup;
337 v4l2_std_id std = V4L2_STD_PAL_BG; 314 v4l2_std_id std = V4L2_STD_PAL_BG;
315 struct v4l2_routing route;
338 316
339 int i = 0, err = 0; 317 int i = 0, err = 0;
340 struct tea6415c_multiplex vm; 318 struct tea6415c_multiplex vm;
341 319
342 /* select video mode in saa7111a */ 320 /* select video mode in saa7111a */
343 i = VIDEO_MODE_PAL; 321 mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_S_STD, &std);
344 /* fixme: currently pointless: gets overwritten by configuration below */
345 mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_NORM, &i);
346
347 /* write configuration to saa7111a */
348 init.data = mxb_saa7111_init;
349 init.len = sizeof(mxb_saa7111_init);
350 mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_INIT, &init);
351 322
352 /* select tuner-output on saa7111a */ 323 /* select tuner-output on saa7111a */
353 i = 0; 324 i = 0;
354 mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_INPUT, &i); 325 route.input = SAA7115_COMPOSITE0;
355 326 route.output = SAA7111_FMT_CCIR | SAA7111_VBI_BYPASS;
356 /* enable vbi bypass */ 327 mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_VIDEO_ROUTING, &route);
357 i = 1;
358 mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_VBI_BYPASS, &i);
359 328
360 /* select a tuner type */ 329 /* select a tuner type */
361 tun_setup.mode_mask = T_ANALOG_TV; 330 tun_setup.mode_mask = T_ANALOG_TV;
362 tun_setup.addr = ADDR_UNSET; 331 tun_setup.addr = ADDR_UNSET;
363 tun_setup.type = TUNER_PHILIPS_PAL; 332 tun_setup.type = TUNER_PHILIPS_PAL;
364 mxb->tuner->driver->command(mxb->tuner,TUNER_SET_TYPE_ADDR, &tun_setup); 333 mxb->tuner->driver->command(mxb->tuner, TUNER_SET_TYPE_ADDR, &tun_setup);
365 /* tune in some frequency on tuner */ 334 /* tune in some frequency on tuner */
366 mxb->cur_freq.tuner = 0; 335 mxb->cur_freq.tuner = 0;
367 mxb->cur_freq.type = V4L2_TUNER_ANALOG_TV; 336 mxb->cur_freq.type = V4L2_TUNER_ANALOG_TV;
@@ -373,27 +342,26 @@ static int mxb_init_done(struct saa7146_dev* dev)
373 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std); 342 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std);
374 343
375 /* mute audio on tea6420s */ 344 /* mute audio on tea6420s */
376 mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[6][0]); 345 mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH, &TEA6420_line[6][0]);
377 mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[6][1]); 346 mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH, &TEA6420_line[6][1]);
378 mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_cd[6][0]); 347 mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH, &TEA6420_cd[6][0]);
379 mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_cd[6][1]); 348 mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH, &TEA6420_cd[6][1]);
380 349
381 /* switch to tuner-channel on tea6415c*/ 350 /* switch to tuner-channel on tea6415c*/
382 vm.out = 17; 351 vm.out = 17;
383 vm.in = 3; 352 vm.in = 3;
384 mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm); 353 mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm);
385 354
386 /* select tuner-output on multicable on tea6415c*/ 355 /* select tuner-output on multicable on tea6415c*/
387 vm.in = 3; 356 vm.in = 3;
388 vm.out = 13; 357 vm.out = 13;
389 mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm); 358 mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm);
390 359
391 /* the rest for mxb */ 360 /* the rest for mxb */
392 mxb->cur_input = 0; 361 mxb->cur_input = 0;
393 mxb->cur_mute = 1; 362 mxb->cur_mute = 1;
394 363
395 mxb->cur_mode = V4L2_TUNER_MODE_STEREO; 364 mxb->cur_mode = V4L2_TUNER_MODE_STEREO;
396 mxb->tda9840->driver->command(mxb->tda9840, TDA9840_SWITCH, &mxb->cur_mode);
397 365
398 /* check if the saa7740 (aka 'sound arena module') is present 366 /* check if the saa7740 (aka 'sound arena module') is present
399 on the mxb. if so, we must initialize it. due to lack of 367 on the mxb. if so, we must initialize it. due to lack of
@@ -404,21 +372,22 @@ static int mxb_init_done(struct saa7146_dev* dev)
404 msg.len = mxb_saa7740_init[0].length; 372 msg.len = mxb_saa7740_init[0].length;
405 msg.buf = &mxb_saa7740_init[0].data[0]; 373 msg.buf = &mxb_saa7740_init[0].data[0];
406 374
407 if( 1 == (err = i2c_transfer(&mxb->i2c_adapter, &msg, 1))) { 375 err = i2c_transfer(&mxb->i2c_adapter, &msg, 1);
376 if (err == 1) {
408 /* the sound arena module is a pos, that's probably the reason 377 /* the sound arena module is a pos, that's probably the reason
409 philips refuses to hand out a datasheet for the saa7740... 378 philips refuses to hand out a datasheet for the saa7740...
410 it seems to screw up the i2c bus, so we disable fast irq 379 it seems to screw up the i2c bus, so we disable fast irq
411 based i2c transactions here and rely on the slow and safe 380 based i2c transactions here and rely on the slow and safe
412 polling method ... */ 381 polling method ... */
413 extension.flags &= ~SAA7146_USE_I2C_IRQ; 382 extension.flags &= ~SAA7146_USE_I2C_IRQ;
414 for(i = 1;;i++) { 383 for (i = 1; ; i++) {
415 if( -1 == mxb_saa7740_init[i].length ) { 384 if (-1 == mxb_saa7740_init[i].length)
416 break; 385 break;
417 }
418 386
419 msg.len = mxb_saa7740_init[i].length; 387 msg.len = mxb_saa7740_init[i].length;
420 msg.buf = &mxb_saa7740_init[i].data[0]; 388 msg.buf = &mxb_saa7740_init[i].data[0];
421 if( 1 != (err = i2c_transfer(&mxb->i2c_adapter, &msg, 1))) { 389 err = i2c_transfer(&mxb->i2c_adapter, &msg, 1);
390 if (err != 1) {
422 DEB_D(("failed to initialize 'sound arena module'.\n")); 391 DEB_D(("failed to initialize 'sound arena module'.\n"));
423 goto err; 392 goto err;
424 } 393 }
@@ -432,7 +401,8 @@ err:
432 /* ext->saa has been filled by the core driver */ 401 /* ext->saa has been filled by the core driver */
433 402
434 /* some stuff is done via variables */ 403 /* some stuff is done via variables */
435 saa7146_set_hps_source_and_sync(dev, input_port_selection[mxb->cur_input].hps_source, input_port_selection[mxb->cur_input].hps_sync); 404 saa7146_set_hps_source_and_sync(dev, input_port_selection[mxb->cur_input].hps_source,
405 input_port_selection[mxb->cur_input].hps_sync);
436 406
437 /* some stuff is done via direct write to the registers */ 407 /* some stuff is done via direct write to the registers */
438 408
@@ -457,24 +427,24 @@ void mxb_irq_bh(struct saa7146_dev* dev, u32* irq_mask)
457static struct saa7146_ext_vv vv_data; 427static struct saa7146_ext_vv vv_data;
458 428
459/* this function only gets called when the probing was successful */ 429/* this function only gets called when the probing was successful */
460static int mxb_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_data *info) 430static int mxb_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
461{ 431{
462 struct mxb* mxb = (struct mxb*)dev->ext_priv; 432 struct mxb *mxb = (struct mxb *)dev->ext_priv;
463 433
464 DEB_EE(("dev:%p\n",dev)); 434 DEB_EE(("dev:%p\n", dev));
465 435
466 /* checking for i2c-devices can be omitted here, because we 436 /* checking for i2c-devices can be omitted here, because we
467 already did this in "mxb_vl42_probe" */ 437 already did this in "mxb_vl42_probe" */
468 438
469 saa7146_vv_init(dev,&vv_data); 439 saa7146_vv_init(dev, &vv_data);
470 if( 0 != saa7146_register_device(&mxb->video_dev, dev, "mxb", VFL_TYPE_GRABBER)) { 440 if (saa7146_register_device(&mxb->video_dev, dev, "mxb", VFL_TYPE_GRABBER)) {
471 ERR(("cannot register capture v4l2 device. skipping.\n")); 441 ERR(("cannot register capture v4l2 device. skipping.\n"));
472 return -1; 442 return -1;
473 } 443 }
474 444
475 /* initialization stuff (vbi) (only for revision > 0 and for extensions which want it)*/ 445 /* initialization stuff (vbi) (only for revision > 0 and for extensions which want it)*/
476 if( 0 != MXB_BOARD_CAN_DO_VBI(dev)) { 446 if (MXB_BOARD_CAN_DO_VBI(dev)) {
477 if( 0 != saa7146_register_device(&mxb->vbi_dev, dev, "mxb", VFL_TYPE_VBI)) { 447 if (saa7146_register_device(&mxb->vbi_dev, dev, "mxb", VFL_TYPE_VBI)) {
478 ERR(("cannot register vbi v4l2 device. skipping.\n")); 448 ERR(("cannot register vbi v4l2 device. skipping.\n"));
479 } 449 }
480 } 450 }
@@ -486,18 +456,18 @@ static int mxb_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_data
486 i2c_use_client(mxb->saa7111a); 456 i2c_use_client(mxb->saa7111a);
487 i2c_use_client(mxb->tuner); 457 i2c_use_client(mxb->tuner);
488 458
489 printk("mxb: found 'Multimedia eXtension Board'-%d.\n",mxb_num); 459 printk("mxb: found Multimedia eXtension Board #%d.\n", mxb_num);
490 460
491 mxb_num++; 461 mxb_num++;
492 mxb_init_done(dev); 462 mxb_init_done(dev);
493 return 0; 463 return 0;
494} 464}
495 465
496static int mxb_detach(struct saa7146_dev* dev) 466static int mxb_detach(struct saa7146_dev *dev)
497{ 467{
498 struct mxb* mxb = (struct mxb*)dev->ext_priv; 468 struct mxb *mxb = (struct mxb *)dev->ext_priv;
499 469
500 DEB_EE(("dev:%p\n",dev)); 470 DEB_EE(("dev:%p\n", dev));
501 471
502 i2c_release_client(mxb->tea6420_1); 472 i2c_release_client(mxb->tea6420_1);
503 i2c_release_client(mxb->tea6420_2); 473 i2c_release_client(mxb->tea6420_2);
@@ -507,9 +477,8 @@ static int mxb_detach(struct saa7146_dev* dev)
507 i2c_release_client(mxb->tuner); 477 i2c_release_client(mxb->tuner);
508 478
509 saa7146_unregister_device(&mxb->video_dev,dev); 479 saa7146_unregister_device(&mxb->video_dev,dev);
510 if( 0 != MXB_BOARD_CAN_DO_VBI(dev)) { 480 if (MXB_BOARD_CAN_DO_VBI(dev))
511 saa7146_unregister_device(&mxb->vbi_dev,dev); 481 saa7146_unregister_device(&mxb->vbi_dev, dev);
512 }
513 saa7146_vv_release(dev); 482 saa7146_vv_release(dev);
514 483
515 mxb_num--; 484 mxb_num--;
@@ -523,7 +492,7 @@ static int mxb_detach(struct saa7146_dev* dev)
523static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg) 492static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
524{ 493{
525 struct saa7146_dev *dev = fh->dev; 494 struct saa7146_dev *dev = fh->dev;
526 struct mxb* mxb = (struct mxb*)dev->ext_priv; 495 struct mxb *mxb = (struct mxb *)dev->ext_priv;
527 struct saa7146_vv *vv = dev->vv_data; 496 struct saa7146_vv *vv = dev->vv_data;
528 497
529 switch(cmd) { 498 switch(cmd) {
@@ -532,11 +501,9 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
532 struct v4l2_input *i = arg; 501 struct v4l2_input *i = arg;
533 502
534 DEB_EE(("VIDIOC_ENUMINPUT %d.\n",i->index)); 503 DEB_EE(("VIDIOC_ENUMINPUT %d.\n",i->index));
535 if( i->index < 0 || i->index >= MXB_INPUTS) { 504 if (i->index < 0 || i->index >= MXB_INPUTS)
536 return -EINVAL; 505 return -EINVAL;
537 }
538 memcpy(i, &mxb_inputs[i->index], sizeof(struct v4l2_input)); 506 memcpy(i, &mxb_inputs[i->index], sizeof(struct v4l2_input));
539
540 return 0; 507 return 0;
541 } 508 }
542 /* the saa7146 provides some controls (brightness, contrast, saturation) 509 /* the saa7146 provides some controls (brightness, contrast, saturation)
@@ -550,7 +517,7 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
550 for (i = MAXCONTROLS - 1; i >= 0; i--) { 517 for (i = MAXCONTROLS - 1; i >= 0; i--) {
551 if (mxb_controls[i].id == qc->id) { 518 if (mxb_controls[i].id == qc->id) {
552 *qc = mxb_controls[i]; 519 *qc = mxb_controls[i];
553 DEB_D(("VIDIOC_QUERYCTRL %d.\n",qc->id)); 520 DEB_D(("VIDIOC_QUERYCTRL %d.\n", qc->id));
554 return 0; 521 return 0;
555 } 522 }
556 } 523 }
@@ -562,56 +529,51 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
562 int i; 529 int i;
563 530
564 for (i = MAXCONTROLS - 1; i >= 0; i--) { 531 for (i = MAXCONTROLS - 1; i >= 0; i--) {
565 if (mxb_controls[i].id == vc->id) { 532 if (mxb_controls[i].id == vc->id)
566 break; 533 break;
567 }
568 } 534 }
569 535
570 if( i < 0 ) { 536 if (i < 0)
571 return -EAGAIN; 537 return -EAGAIN;
572 }
573 538
574 switch (vc->id ) { 539 if (vc->id == V4L2_CID_AUDIO_MUTE) {
575 case V4L2_CID_AUDIO_MUTE: { 540 vc->value = mxb->cur_mute;
576 vc->value = mxb->cur_mute; 541 DEB_D(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n", vc->value));
577 DEB_D(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n",vc->value)); 542 return 0;
578 return 0;
579 }
580 } 543 }
581 544
582 DEB_EE(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n",vc->value)); 545 DEB_EE(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n", vc->value));
583 return 0; 546 return 0;
584 } 547 }
585 548
586 case VIDIOC_S_CTRL: 549 case VIDIOC_S_CTRL:
587 { 550 {
588 struct v4l2_control *vc = arg; 551 struct v4l2_control *vc = arg;
589 int i = 0; 552 int i = 0;
590 553
591 for (i = MAXCONTROLS - 1; i >= 0; i--) { 554 for (i = MAXCONTROLS - 1; i >= 0; i--) {
592 if (mxb_controls[i].id == vc->id) { 555 if (mxb_controls[i].id == vc->id)
593 break; 556 break;
594 }
595 } 557 }
596 558
597 if( i < 0 ) { 559 if (i < 0)
598 return -EAGAIN; 560 return -EAGAIN;
599 }
600 561
601 switch (vc->id ) { 562 if (vc->id == V4L2_CID_AUDIO_MUTE) {
602 case V4L2_CID_AUDIO_MUTE: { 563 mxb->cur_mute = vc->value;
603 mxb->cur_mute = vc->value; 564 if (!vc->value) {
604 if( 0 == vc->value ) { 565 /* switch the audio-source */
605 /* switch the audio-source */ 566 mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH,
606 mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[video_audio_connect[mxb->cur_input]][0]); 567 &TEA6420_line[video_audio_connect[mxb->cur_input]][0]);
607 mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[video_audio_connect[mxb->cur_input]][1]); 568 mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH,
608 } else { 569 &TEA6420_line[video_audio_connect[mxb->cur_input]][1]);
609 mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[6][0]); 570 } else {
610 mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[6][1]); 571 mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH,
611 } 572 &TEA6420_line[6][0]);
612 DEB_EE(("VIDIOC_S_CTRL, V4L2_CID_AUDIO_MUTE: %d.\n",vc->value)); 573 mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH,
613 break; 574 &TEA6420_line[6][1]);
614 } 575 }
576 DEB_EE(("VIDIOC_S_CTRL, V4L2_CID_AUDIO_MUTE: %d.\n", vc->value));
615 } 577 }
616 return 0; 578 return 0;
617 } 579 }
@@ -620,106 +582,84 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
620 int *input = (int *)arg; 582 int *input = (int *)arg;
621 *input = mxb->cur_input; 583 *input = mxb->cur_input;
622 584
623 DEB_EE(("VIDIOC_G_INPUT %d.\n",*input)); 585 DEB_EE(("VIDIOC_G_INPUT %d.\n", *input));
624 return 0; 586 return 0;
625 } 587 }
626 case VIDIOC_S_INPUT: 588 case VIDIOC_S_INPUT:
627 { 589 {
628 int input = *(int *)arg; 590 int input = *(int *)arg;
629 struct tea6415c_multiplex vm; 591 struct tea6415c_multiplex vm;
592 struct v4l2_routing route;
630 int i = 0; 593 int i = 0;
631 594
632 DEB_EE(("VIDIOC_S_INPUT %d.\n",input)); 595 DEB_EE(("VIDIOC_S_INPUT %d.\n", input));
633 596
634 if (input < 0 || input >= MXB_INPUTS) { 597 if (input < 0 || input >= MXB_INPUTS)
635 return -EINVAL; 598 return -EINVAL;
636 }
637
638 /* fixme: locke das setzen des inputs mit hilfe des mutexes
639 mutex_lock(&dev->lock);
640 video_mux(dev,*i);
641 mutex_unlock(&dev->lock);
642 */
643
644 /* fixme: check if streaming capture
645 if ( 0 != dev->streaming ) {
646 DEB_D(("VIDIOC_S_INPUT illegal while streaming.\n"));
647 return -EPERM;
648 }
649 */
650 599
651 mxb->cur_input = input; 600 mxb->cur_input = input;
652 601
653 saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source, input_port_selection[input].hps_sync); 602 saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source,
603 input_port_selection[input].hps_sync);
654 604
655 /* prepare switching of tea6415c and saa7111a; 605 /* prepare switching of tea6415c and saa7111a;
656 have a look at the 'background'-file for further informations */ 606 have a look at the 'background'-file for further informations */
657 switch( input ) { 607 switch (input) {
658 608 case TUNER:
659 case TUNER: 609 i = SAA7115_COMPOSITE0;
660 { 610 vm.in = 3;
661 i = 0; 611 vm.out = 17;
662 vm.in = 3; 612
663 vm.out = 17; 613 if (mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm)) {
664 614 printk(KERN_ERR "VIDIOC_S_INPUT: could not address tea6415c #1\n");
665 if ( 0 != mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm)) { 615 return -EFAULT;
666 printk("VIDIOC_S_INPUT: could not address tea6415c #1\n");
667 return -EFAULT;
668 }
669 /* connect tuner-output always to multicable */
670 vm.in = 3;
671 vm.out = 13;
672 break;
673 }
674 case AUX3_YC:
675 {
676 /* nothing to be done here. aux3_yc is
677 directly connected to the saa711a */
678 i = 5;
679 break;
680 }
681 case AUX3:
682 {
683 /* nothing to be done here. aux3 is
684 directly connected to the saa711a */
685 i = 1;
686 break;
687 }
688 case AUX1:
689 {
690 i = 0;
691 vm.in = 1;
692 vm.out = 17;
693 break;
694 } 616 }
617 /* connect tuner-output always to multicable */
618 vm.in = 3;
619 vm.out = 13;
620 break;
621 case AUX3_YC:
622 /* nothing to be done here. aux3_yc is
623 directly connected to the saa711a */
624 i = SAA7115_SVIDEO1;
625 break;
626 case AUX3:
627 /* nothing to be done here. aux3 is
628 directly connected to the saa711a */
629 i = SAA7115_COMPOSITE1;
630 break;
631 case AUX1:
632 i = SAA7115_COMPOSITE0;
633 vm.in = 1;
634 vm.out = 17;
635 break;
695 } 636 }
696 637
697 /* switch video in tea6415c only if necessary */ 638 /* switch video in tea6415c only if necessary */
698 switch( input ) { 639 switch (input) {
699 case TUNER: 640 case TUNER:
700 case AUX1: 641 case AUX1:
701 { 642 if (mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm)) {
702 if ( 0 != mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm)) { 643 printk(KERN_ERR "VIDIOC_S_INPUT: could not address tea6415c #3\n");
703 printk("VIDIOC_S_INPUT: could not address tea6415c #3\n"); 644 return -EFAULT;
704 return -EFAULT;
705 }
706 break;
707 }
708 default:
709 {
710 break;
711 } 645 }
646 break;
647 default:
648 break;
712 } 649 }
713 650
714 /* switch video in saa7111a */ 651 /* switch video in saa7111a */
715 if ( 0 != mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_INPUT, &i)) { 652 route.input = i;
653 route.output = 0;
654 if (mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_VIDEO_ROUTING, &route))
716 printk("VIDIOC_S_INPUT: could not address saa7111a #1.\n"); 655 printk("VIDIOC_S_INPUT: could not address saa7111a #1.\n");
717 }
718 656
719 /* switch the audio-source only if necessary */ 657 /* switch the audio-source only if necessary */
720 if( 0 == mxb->cur_mute ) { 658 if( 0 == mxb->cur_mute ) {
721 mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[video_audio_connect[input]][0]); 659 mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH,
722 mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[video_audio_connect[input]][1]); 660 &TEA6420_line[video_audio_connect[input]][0]);
661 mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH,
662 &TEA6420_line[video_audio_connect[input]][1]);
723 } 663 }
724 664
725 return 0; 665 return 0;
@@ -727,114 +667,44 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
727 case VIDIOC_G_TUNER: 667 case VIDIOC_G_TUNER:
728 { 668 {
729 struct v4l2_tuner *t = arg; 669 struct v4l2_tuner *t = arg;
730 int byte = 0;
731 670
732 if( 0 != t->index ) { 671 if (t->index) {
733 DEB_D(("VIDIOC_G_TUNER: channel %d does not have a tuner attached.\n", t->index)); 672 DEB_D(("VIDIOC_G_TUNER: channel %d does not have a tuner attached.\n", t->index));
734 return -EINVAL; 673 return -EINVAL;
735 } 674 }
736 675
737 DEB_EE(("VIDIOC_G_TUNER: %d\n", t->index)); 676 DEB_EE(("VIDIOC_G_TUNER: %d\n", t->index));
738 677
739 memset(t,0,sizeof(*t)); 678 memset(t, 0, sizeof(*t));
740 strcpy(t->name, "Television"); 679 i2c_clients_command(&mxb->i2c_adapter, cmd, arg);
741 680
681 strlcpy(t->name, "TV Tuner", sizeof(t->name));
742 t->type = V4L2_TUNER_ANALOG_TV; 682 t->type = V4L2_TUNER_ANALOG_TV;
743 t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP; 683 t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO | \
744 t->rangelow = 772; /* 48.25 MHZ / 62.5 kHz = 772, see fi1216mk2-specs, page 2 */ 684 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
745 t->rangehigh = 13684; /* 855.25 MHz / 62.5 kHz = 13684 */
746 /* FIXME: add the real signal strength here */
747 t->signal = 0xffff;
748 t->afc = 0;
749
750 mxb->tda9840->driver->command(mxb->tda9840,TDA9840_DETECT, &byte);
751 t->audmode = mxb->cur_mode; 685 t->audmode = mxb->cur_mode;
752
753 if( byte < 0 ) {
754 t->rxsubchans = V4L2_TUNER_SUB_MONO;
755 } else {
756 switch(byte) {
757 case TDA9840_MONO_DETECT: {
758 t->rxsubchans = V4L2_TUNER_SUB_MONO;
759 DEB_D(("VIDIOC_G_TUNER: V4L2_TUNER_MODE_MONO.\n"));
760 break;
761 }
762 case TDA9840_DUAL_DETECT: {
763 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
764 DEB_D(("VIDIOC_G_TUNER: V4L2_TUNER_MODE_LANG1.\n"));
765 break;
766 }
767 case TDA9840_STEREO_DETECT: {
768 t->rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;
769 DEB_D(("VIDIOC_G_TUNER: V4L2_TUNER_MODE_STEREO.\n"));
770 break;
771 }
772 default: { /* TDA9840_INCORRECT_DETECT */
773 t->rxsubchans = V4L2_TUNER_MODE_MONO;
774 DEB_D(("VIDIOC_G_TUNER: TDA9840_INCORRECT_DETECT => V4L2_TUNER_MODE_MONO\n"));
775 break;
776 }
777 }
778 }
779
780 return 0; 686 return 0;
781 } 687 }
782 case VIDIOC_S_TUNER: 688 case VIDIOC_S_TUNER:
783 { 689 {
784 struct v4l2_tuner *t = arg; 690 struct v4l2_tuner *t = arg;
785 int result = 0;
786 int byte = 0;
787 691
788 if( 0 != t->index ) { 692 if (t->index) {
789 DEB_D(("VIDIOC_S_TUNER: channel %d does not have a tuner attached.\n",t->index)); 693 DEB_D(("VIDIOC_S_TUNER: channel %d does not have a tuner attached.\n",t->index));
790 return -EINVAL; 694 return -EINVAL;
791 } 695 }
792 696
793 switch(t->audmode) { 697 mxb->cur_mode = t->audmode;
794 case V4L2_TUNER_MODE_STEREO: { 698 i2c_clients_command(&mxb->i2c_adapter, cmd, arg);
795 mxb->cur_mode = V4L2_TUNER_MODE_STEREO;
796 byte = TDA9840_SET_STEREO;
797 DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_STEREO\n"));
798 break;
799 }
800 case V4L2_TUNER_MODE_LANG1_LANG2: {
801 mxb->cur_mode = V4L2_TUNER_MODE_LANG1_LANG2;
802 byte = TDA9840_SET_BOTH;
803 DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1_LANG2\n"));
804 break;
805 }
806 case V4L2_TUNER_MODE_LANG1: {
807 mxb->cur_mode = V4L2_TUNER_MODE_LANG1;
808 byte = TDA9840_SET_LANG1;
809 DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1\n"));
810 break;
811 }
812 case V4L2_TUNER_MODE_LANG2: {
813 mxb->cur_mode = V4L2_TUNER_MODE_LANG2;
814 byte = TDA9840_SET_LANG2;
815 DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG2\n"));
816 break;
817 }
818 default: { /* case V4L2_TUNER_MODE_MONO: {*/
819 mxb->cur_mode = V4L2_TUNER_MODE_MONO;
820 byte = TDA9840_SET_MONO;
821 DEB_D(("VIDIOC_S_TUNER: TDA9840_SET_MONO\n"));
822 break;
823 }
824 }
825
826 if( 0 != (result = mxb->tda9840->driver->command(mxb->tda9840, TDA9840_SWITCH, &byte))) {
827 printk("VIDIOC_S_TUNER error. result:%d, byte:%d\n",result,byte);
828 }
829
830 return 0; 699 return 0;
831 } 700 }
832 case VIDIOC_G_FREQUENCY: 701 case VIDIOC_G_FREQUENCY:
833 { 702 {
834 struct v4l2_frequency *f = arg; 703 struct v4l2_frequency *f = arg;
835 704
836 if(0 != mxb->cur_input) { 705 if (mxb->cur_input) {
837 DEB_D(("VIDIOC_G_FREQ: channel %d does not have a tuner!\n",mxb->cur_input)); 706 DEB_D(("VIDIOC_G_FREQ: channel %d does not have a tuner!\n",
707 mxb->cur_input));
838 return -EINVAL; 708 return -EINVAL;
839 } 709 }
840 710
@@ -847,14 +717,14 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
847 { 717 {
848 struct v4l2_frequency *f = arg; 718 struct v4l2_frequency *f = arg;
849 719
850 if (0 != f->tuner) 720 if (f->tuner)
851 return -EINVAL; 721 return -EINVAL;
852 722
853 if (V4L2_TUNER_ANALOG_TV != f->type) 723 if (V4L2_TUNER_ANALOG_TV != f->type)
854 return -EINVAL; 724 return -EINVAL;
855 725
856 if(0 != mxb->cur_input) { 726 if (mxb->cur_input) {
857 DEB_D(("VIDIOC_S_FREQ: channel %d does not have a tuner!\n",mxb->cur_input)); 727 DEB_D(("VIDIOC_S_FREQ: channel %d does not have a tuner!\n", mxb->cur_input));
858 return -EINVAL; 728 return -EINVAL;
859 } 729 }
860 730
@@ -875,7 +745,7 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
875 { 745 {
876 int i = *(int*)arg; 746 int i = *(int*)arg;
877 747
878 if( i < 0 || i >= MXB_AUDIOS ) { 748 if (i < 0 || i >= MXB_AUDIOS) {
879 DEB_D(("illegal argument to MXB_S_AUDIO_CD: i:%d.\n",i)); 749 DEB_D(("illegal argument to MXB_S_AUDIO_CD: i:%d.\n",i));
880 return -EINVAL; 750 return -EINVAL;
881 } 751 }
@@ -891,7 +761,7 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
891 { 761 {
892 int i = *(int*)arg; 762 int i = *(int*)arg;
893 763
894 if( i < 0 || i >= MXB_AUDIOS ) { 764 if (i < 0 || i >= MXB_AUDIOS) {
895 DEB_D(("illegal argument to MXB_S_AUDIO_LINE: i:%d.\n",i)); 765 DEB_D(("illegal argument to MXB_S_AUDIO_LINE: i:%d.\n",i));
896 return -EINVAL; 766 return -EINVAL;
897 } 767 }
@@ -906,12 +776,12 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
906 { 776 {
907 struct v4l2_audio *a = arg; 777 struct v4l2_audio *a = arg;
908 778
909 if( a->index < 0 || a->index > MXB_INPUTS ) { 779 if (a->index < 0 || a->index > MXB_INPUTS) {
910 DEB_D(("VIDIOC_G_AUDIO %d out of range.\n",a->index)); 780 DEB_D(("VIDIOC_G_AUDIO %d out of range.\n", a->index));
911 return -EINVAL; 781 return -EINVAL;
912 } 782 }
913 783
914 DEB_EE(("VIDIOC_G_AUDIO %d.\n",a->index)); 784 DEB_EE(("VIDIOC_G_AUDIO %d.\n", a->index));
915 memcpy(a, &mxb_audios[video_audio_connect[mxb->cur_input]], sizeof(struct v4l2_audio)); 785 memcpy(a, &mxb_audios[video_audio_connect[mxb->cur_input]], sizeof(struct v4l2_audio));
916 786
917 return 0; 787 return 0;
@@ -919,9 +789,16 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
919 case VIDIOC_S_AUDIO: 789 case VIDIOC_S_AUDIO:
920 { 790 {
921 struct v4l2_audio *a = arg; 791 struct v4l2_audio *a = arg;
922 DEB_D(("VIDIOC_S_AUDIO %d.\n",a->index)); 792
793 DEB_D(("VIDIOC_S_AUDIO %d.\n", a->index));
923 return 0; 794 return 0;
924 } 795 }
796#ifdef CONFIG_VIDEO_ADV_DEBUG
797 case VIDIOC_DBG_S_REGISTER:
798 case VIDIOC_DBG_G_REGISTER:
799 i2c_clients_command(&mxb->i2c_adapter, cmd, arg);
800 return 0;
801#endif
925 default: 802 default:
926/* 803/*
927 DEB2(printk("does not handle this ioctl.\n")); 804 DEB2(printk("does not handle this ioctl.\n"));
@@ -944,7 +821,7 @@ static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standa
944 /* set the 7146 gpio register -- I don't know what this does exactly */ 821 /* set the 7146 gpio register -- I don't know what this does exactly */
945 saa7146_write(dev, GPIO_CTRL, 0x00404050); 822 saa7146_write(dev, GPIO_CTRL, 0x00404050);
946 /* unset the 7111 gpio register -- I don't know what this does exactly */ 823 /* unset the 7111 gpio register -- I don't know what this does exactly */
947 mxb->saa7111a->driver->command(mxb->saa7111a, DECODER_SET_GPIO, &zero); 824 mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_GPIO, &zero);
948 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std); 825 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std);
949 } else { 826 } else {
950 v4l2_std_id std = V4L2_STD_PAL_BG; 827 v4l2_std_id std = V4L2_STD_PAL_BG;
@@ -953,7 +830,7 @@ static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standa
953 /* set the 7146 gpio register -- I don't know what this does exactly */ 830 /* set the 7146 gpio register -- I don't know what this does exactly */
954 saa7146_write(dev, GPIO_CTRL, 0x00404050); 831 saa7146_write(dev, GPIO_CTRL, 0x00404050);
955 /* set the 7111 gpio register -- I don't know what this does exactly */ 832 /* set the 7111 gpio register -- I don't know what this does exactly */
956 mxb->saa7111a->driver->command(mxb->saa7111a, DECODER_SET_GPIO, &one); 833 mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_GPIO, &one);
957 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std); 834 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std);
958 } 835 }
959 return 0; 836 return 0;
@@ -1029,7 +906,7 @@ static struct saa7146_extension extension = {
1029 906
1030static int __init mxb_init_module(void) 907static int __init mxb_init_module(void)
1031{ 908{
1032 if( 0 != saa7146_register_extension(&extension)) { 909 if (saa7146_register_extension(&extension)) {
1033 DEB_S(("failed to register extension.\n")); 910 DEB_S(("failed to register extension.\n"));
1034 return -ENODEV; 911 return -ENODEV;
1035 } 912 }
diff --git a/drivers/media/video/ov511.c b/drivers/media/video/ov511.c
index c6852402c5e9..935d73de57bd 100644
--- a/drivers/media/video/ov511.c
+++ b/drivers/media/video/ov511.c
@@ -974,14 +974,14 @@ dump_i2c_range(struct usb_ov511 *ov, int reg1, int regn)
974 974
975 for (i = reg1; i <= regn; i++) { 975 for (i = reg1; i <= regn; i++) {
976 rc = i2c_r(ov, i); 976 rc = i2c_r(ov, i);
977 info("Sensor[0x%02X] = 0x%02X", i, rc); 977 dev_info(&ov->dev->dev, "Sensor[0x%02X] = 0x%02X\n", i, rc);
978 } 978 }
979} 979}
980 980
981static void 981static void
982dump_i2c_regs(struct usb_ov511 *ov) 982dump_i2c_regs(struct usb_ov511 *ov)
983{ 983{
984 info("I2C REGS"); 984 dev_info(&ov->dev->dev, "I2C REGS\n");
985 dump_i2c_range(ov, 0x00, 0x7C); 985 dump_i2c_range(ov, 0x00, 0x7C);
986} 986}
987 987
@@ -992,28 +992,28 @@ dump_reg_range(struct usb_ov511 *ov, int reg1, int regn)
992 992
993 for (i = reg1; i <= regn; i++) { 993 for (i = reg1; i <= regn; i++) {
994 rc = reg_r(ov, i); 994 rc = reg_r(ov, i);
995 info("OV511[0x%02X] = 0x%02X", i, rc); 995 dev_info(&ov->dev->dev, "OV511[0x%02X] = 0x%02X\n", i, rc);
996 } 996 }
997} 997}
998 998
999static void 999static void
1000ov511_dump_regs(struct usb_ov511 *ov) 1000ov511_dump_regs(struct usb_ov511 *ov)
1001{ 1001{
1002 info("CAMERA INTERFACE REGS"); 1002 dev_info(&ov->dev->dev, "CAMERA INTERFACE REGS\n");
1003 dump_reg_range(ov, 0x10, 0x1f); 1003 dump_reg_range(ov, 0x10, 0x1f);
1004 info("DRAM INTERFACE REGS"); 1004 dev_info(&ov->dev->dev, "DRAM INTERFACE REGS\n");
1005 dump_reg_range(ov, 0x20, 0x23); 1005 dump_reg_range(ov, 0x20, 0x23);
1006 info("ISO FIFO REGS"); 1006 dev_info(&ov->dev->dev, "ISO FIFO REGS\n");
1007 dump_reg_range(ov, 0x30, 0x31); 1007 dump_reg_range(ov, 0x30, 0x31);
1008 info("PIO REGS"); 1008 dev_info(&ov->dev->dev, "PIO REGS\n");
1009 dump_reg_range(ov, 0x38, 0x39); 1009 dump_reg_range(ov, 0x38, 0x39);
1010 dump_reg_range(ov, 0x3e, 0x3e); 1010 dump_reg_range(ov, 0x3e, 0x3e);
1011 info("I2C REGS"); 1011 dev_info(&ov->dev->dev, "I2C REGS\n");
1012 dump_reg_range(ov, 0x40, 0x49); 1012 dump_reg_range(ov, 0x40, 0x49);
1013 info("SYSTEM CONTROL REGS"); 1013 dev_info(&ov->dev->dev, "SYSTEM CONTROL REGS\n");
1014 dump_reg_range(ov, 0x50, 0x55); 1014 dump_reg_range(ov, 0x50, 0x55);
1015 dump_reg_range(ov, 0x5e, 0x5f); 1015 dump_reg_range(ov, 0x5e, 0x5f);
1016 info("OmniCE REGS"); 1016 dev_info(&ov->dev->dev, "OmniCE REGS\n");
1017 dump_reg_range(ov, 0x70, 0x79); 1017 dump_reg_range(ov, 0x70, 0x79);
1018 /* NOTE: Quantization tables are not readable. You will get the value 1018 /* NOTE: Quantization tables are not readable. You will get the value
1019 * in reg. 0x79 for every table register */ 1019 * in reg. 0x79 for every table register */
@@ -1025,25 +1025,25 @@ ov511_dump_regs(struct usb_ov511 *ov)
1025static void 1025static void
1026ov518_dump_regs(struct usb_ov511 *ov) 1026ov518_dump_regs(struct usb_ov511 *ov)
1027{ 1027{
1028 info("VIDEO MODE REGS"); 1028 dev_info(&ov->dev->dev, "VIDEO MODE REGS\n");
1029 dump_reg_range(ov, 0x20, 0x2f); 1029 dump_reg_range(ov, 0x20, 0x2f);
1030 info("DATA PUMP AND SNAPSHOT REGS"); 1030 dev_info(&ov->dev->dev, "DATA PUMP AND SNAPSHOT REGS\n");
1031 dump_reg_range(ov, 0x30, 0x3f); 1031 dump_reg_range(ov, 0x30, 0x3f);
1032 info("I2C REGS"); 1032 dev_info(&ov->dev->dev, "I2C REGS\n");
1033 dump_reg_range(ov, 0x40, 0x4f); 1033 dump_reg_range(ov, 0x40, 0x4f);
1034 info("SYSTEM CONTROL AND VENDOR REGS"); 1034 dev_info(&ov->dev->dev, "SYSTEM CONTROL AND VENDOR REGS\n");
1035 dump_reg_range(ov, 0x50, 0x5f); 1035 dump_reg_range(ov, 0x50, 0x5f);
1036 info("60 - 6F"); 1036 dev_info(&ov->dev->dev, "60 - 6F\n");
1037 dump_reg_range(ov, 0x60, 0x6f); 1037 dump_reg_range(ov, 0x60, 0x6f);
1038 info("70 - 7F"); 1038 dev_info(&ov->dev->dev, "70 - 7F\n");
1039 dump_reg_range(ov, 0x70, 0x7f); 1039 dump_reg_range(ov, 0x70, 0x7f);
1040 info("Y QUANTIZATION TABLE"); 1040 dev_info(&ov->dev->dev, "Y QUANTIZATION TABLE\n");
1041 dump_reg_range(ov, 0x80, 0x8f); 1041 dump_reg_range(ov, 0x80, 0x8f);
1042 info("UV QUANTIZATION TABLE"); 1042 dev_info(&ov->dev->dev, "UV QUANTIZATION TABLE\n");
1043 dump_reg_range(ov, 0x90, 0x9f); 1043 dump_reg_range(ov, 0x90, 0x9f);
1044 info("A0 - BF"); 1044 dev_info(&ov->dev->dev, "A0 - BF\n");
1045 dump_reg_range(ov, 0xa0, 0xbf); 1045 dump_reg_range(ov, 0xa0, 0xbf);
1046 info("CBR"); 1046 dev_info(&ov->dev->dev, "CBR\n");
1047 dump_reg_range(ov, 0xc0, 0xcf); 1047 dump_reg_range(ov, 0xc0, 0xcf);
1048} 1048}
1049#endif 1049#endif
@@ -3205,9 +3205,10 @@ ov511_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
3205 */ 3205 */
3206 3206
3207 if (printph) { 3207 if (printph) {
3208 info("ph(%3d): %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x", 3208 dev_info(&ov->dev->dev,
3209 pnum, in[0], in[1], in[2], in[3], in[4], in[5], in[6], 3209 "ph(%3d): %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x\n",
3210 in[7], in[8], in[9], in[10], in[11]); 3210 pnum, in[0], in[1], in[2], in[3], in[4], in[5], in[6],
3211 in[7], in[8], in[9], in[10], in[11]);
3211 } 3212 }
3212 3213
3213 /* Check for SOF/EOF packet */ 3214 /* Check for SOF/EOF packet */
@@ -3366,8 +3367,10 @@ ov518_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
3366 * the definitive SOF/EOF format */ 3367 * the definitive SOF/EOF format */
3367 if ((!(in[0] | in[1] | in[2] | in[3] | in[5])) && in[6]) { 3368 if ((!(in[0] | in[1] | in[2] | in[3] | in[5])) && in[6]) {
3368 if (printph) { 3369 if (printph) {
3369 info("ph: %2x %2x %2x %2x %2x %2x %2x %2x", in[0], 3370 dev_info(&ov->dev->dev,
3370 in[1], in[2], in[3], in[4], in[5], in[6], in[7]); 3371 "ph: %2x %2x %2x %2x %2x %2x %2x %2x\n",
3372 in[0], in[1], in[2], in[3], in[4], in[5],
3373 in[6], in[7]);
3371 } 3374 }
3372 3375
3373 if (frame->scanstate == STATE_LINES) { 3376 if (frame->scanstate == STATE_LINES) {
@@ -3646,14 +3649,16 @@ ov51x_init_isoc(struct usb_ov511 *ov)
3646 if (packetsize == -1) { 3649 if (packetsize == -1) {
3647 ov518_set_packet_size(ov, 640); 3650 ov518_set_packet_size(ov, 640);
3648 } else { 3651 } else {
3649 info("Forcing packet size to %d", packetsize); 3652 dev_info(&ov->dev->dev, "Forcing packet size to %d\n",
3653 packetsize);
3650 ov518_set_packet_size(ov, packetsize); 3654 ov518_set_packet_size(ov, packetsize);
3651 } 3655 }
3652 } else { 3656 } else {
3653 if (packetsize == -1) { 3657 if (packetsize == -1) {
3654 ov511_set_packet_size(ov, size); 3658 ov511_set_packet_size(ov, size);
3655 } else { 3659 } else {
3656 info("Forcing packet size to %d", packetsize); 3660 dev_info(&ov->dev->dev, "Forcing packet size to %d\n",
3661 packetsize);
3657 ov511_set_packet_size(ov, packetsize); 3662 ov511_set_packet_size(ov, packetsize);
3658 } 3663 }
3659 } 3664 }
@@ -4121,7 +4126,7 @@ ov51x_v4l1_ioctl_internal(struct inode *inode, struct file *file,
4121 return -EIO; 4126 return -EIO;
4122 4127
4123 if (force_palette && p->palette != force_palette) { 4128 if (force_palette && p->palette != force_palette) {
4124 info("Palette rejected (%s)", 4129 dev_info(&ov->dev->dev, "Palette rejected (%s)\n",
4125 symbolic(v4l1_plist, p->palette)); 4130 symbolic(v4l1_plist, p->palette));
4126 return -EINVAL; 4131 return -EINVAL;
4127 } 4132 }
@@ -4849,26 +4854,27 @@ ov7xx0_configure(struct usb_ov511 *ov)
4849 err("Error detecting sensor type"); 4854 err("Error detecting sensor type");
4850 return -1; 4855 return -1;
4851 } else if ((rc & 3) == 3) { 4856 } else if ((rc & 3) == 3) {
4852 info("Sensor is an OV7610"); 4857 dev_info(&ov->dev->dev, "Sensor is an OV7610\n");
4853 ov->sensor = SEN_OV7610; 4858 ov->sensor = SEN_OV7610;
4854 } else if ((rc & 3) == 1) { 4859 } else if ((rc & 3) == 1) {
4855 /* I don't know what's different about the 76BE yet. */ 4860 /* I don't know what's different about the 76BE yet. */
4856 if (i2c_r(ov, 0x15) & 1) 4861 if (i2c_r(ov, 0x15) & 1)
4857 info("Sensor is an OV7620AE"); 4862 dev_info(&ov->dev->dev, "Sensor is an OV7620AE\n");
4858 else 4863 else
4859 info("Sensor is an OV76BE"); 4864 dev_info(&ov->dev->dev, "Sensor is an OV76BE\n");
4860 4865
4861 /* OV511+ will return all zero isoc data unless we 4866 /* OV511+ will return all zero isoc data unless we
4862 * configure the sensor as a 7620. Someone needs to 4867 * configure the sensor as a 7620. Someone needs to
4863 * find the exact reg. setting that causes this. */ 4868 * find the exact reg. setting that causes this. */
4864 if (ov->bridge == BRG_OV511PLUS) { 4869 if (ov->bridge == BRG_OV511PLUS) {
4865 info("Enabling 511+/7620AE workaround"); 4870 dev_info(&ov->dev->dev,
4871 "Enabling 511+/7620AE workaround\n");
4866 ov->sensor = SEN_OV7620; 4872 ov->sensor = SEN_OV7620;
4867 } else { 4873 } else {
4868 ov->sensor = SEN_OV76BE; 4874 ov->sensor = SEN_OV76BE;
4869 } 4875 }
4870 } else if ((rc & 3) == 0) { 4876 } else if ((rc & 3) == 0) {
4871 info("Sensor is an OV7620"); 4877 dev_info(&ov->dev->dev, "Sensor is an OV7620\n");
4872 ov->sensor = SEN_OV7620; 4878 ov->sensor = SEN_OV7620;
4873 } else { 4879 } else {
4874 err("Unknown image sensor version: %d", rc & 3); 4880 err("Unknown image sensor version: %d", rc & 3);
@@ -5024,16 +5030,16 @@ ov6xx0_configure(struct usb_ov511 *ov)
5024 5030
5025 if ((rc & 3) == 0) { 5031 if ((rc & 3) == 0) {
5026 ov->sensor = SEN_OV6630; 5032 ov->sensor = SEN_OV6630;
5027 info("Sensor is an OV6630"); 5033 dev_info(&ov->dev->dev, "Sensor is an OV6630\n");
5028 } else if ((rc & 3) == 1) { 5034 } else if ((rc & 3) == 1) {
5029 ov->sensor = SEN_OV6620; 5035 ov->sensor = SEN_OV6620;
5030 info("Sensor is an OV6620"); 5036 dev_info(&ov->dev->dev, "Sensor is an OV6620\n");
5031 } else if ((rc & 3) == 2) { 5037 } else if ((rc & 3) == 2) {
5032 ov->sensor = SEN_OV6630; 5038 ov->sensor = SEN_OV6630;
5033 info("Sensor is an OV6630AE"); 5039 dev_info(&ov->dev->dev, "Sensor is an OV6630AE\n");
5034 } else if ((rc & 3) == 3) { 5040 } else if ((rc & 3) == 3) {
5035 ov->sensor = SEN_OV6630; 5041 ov->sensor = SEN_OV6630;
5036 info("Sensor is an OV6630AF"); 5042 dev_info(&ov->dev->dev, "Sensor is an OV6630AF\n");
5037 } 5043 }
5038 5044
5039 /* Set sensor-specific vars */ 5045 /* Set sensor-specific vars */
@@ -5088,10 +5094,10 @@ ks0127_configure(struct usb_ov511 *ov)
5088 err("Error detecting sensor type"); 5094 err("Error detecting sensor type");
5089 return -1; 5095 return -1;
5090 } else if ((rc & 0x0f) == 0) { 5096 } else if ((rc & 0x0f) == 0) {
5091 info("Sensor is a KS0127"); 5097 dev_info(&ov->dev->dev, "Sensor is a KS0127\n");
5092 ov->sensor = SEN_KS0127; 5098 ov->sensor = SEN_KS0127;
5093 } else if ((rc & 0x0f) == 9) { 5099 } else if ((rc & 0x0f) == 9) {
5094 info("Sensor is a KS0127B Rev. A"); 5100 dev_info(&ov->dev->dev, "Sensor is a KS0127B Rev. A\n");
5095 ov->sensor = SEN_KS0127B; 5101 ov->sensor = SEN_KS0127B;
5096 } 5102 }
5097 } else { 5103 } else {
@@ -5200,7 +5206,8 @@ saa7111a_configure(struct usb_ov511 *ov)
5200 err("Error detecting sensor version"); 5206 err("Error detecting sensor version");
5201 return -1; 5207 return -1;
5202 } else { 5208 } else {
5203 info("Sensor is an SAA7111A (version 0x%x)", rc); 5209 dev_info(&ov->dev->dev,
5210 "Sensor is an SAA7111A (version 0x%x)\n", rc);
5204 ov->sensor = SEN_SAA7111A; 5211 ov->sensor = SEN_SAA7111A;
5205 } 5212 }
5206 5213
@@ -5262,7 +5269,7 @@ ov511_configure(struct usb_ov511 *ov)
5262 5269
5263 PDEBUG (1, "CustomID = %d", ov->customid); 5270 PDEBUG (1, "CustomID = %d", ov->customid);
5264 ov->desc = symbolic(camlist, ov->customid); 5271 ov->desc = symbolic(camlist, ov->customid);
5265 info("model: %s", ov->desc); 5272 dev_info(&ov->dev->dev, "model: %s\n", ov->desc);
5266 5273
5267 if (0 == strcmp(ov->desc, NOT_DEFINED_STR)) { 5274 if (0 == strcmp(ov->desc, NOT_DEFINED_STR)) {
5268 err("Camera type (%d) not recognized", ov->customid); 5275 err("Camera type (%d) not recognized", ov->customid);
@@ -5426,7 +5433,8 @@ ov518_configure(struct usb_ov511 *ov)
5426 PDEBUG(4, ""); 5433 PDEBUG(4, "");
5427 5434
5428 /* First 5 bits of custom ID reg are a revision ID on OV518 */ 5435 /* First 5 bits of custom ID reg are a revision ID on OV518 */
5429 info("Device revision %d", 0x1F & reg_r(ov, R511_SYS_CUST_ID)); 5436 dev_info(&ov->dev->dev, "Device revision %d\n",
5437 0x1F & reg_r(ov, R511_SYS_CUST_ID));
5430 5438
5431 /* Give it the default description */ 5439 /* Give it the default description */
5432 ov->desc = symbolic(camlist, 0); 5440 ov->desc = symbolic(camlist, 0);
@@ -5773,7 +5781,8 @@ ov51x_probe(struct usb_interface *intf, const struct usb_device_id *id)
5773 goto error; 5781 goto error;
5774 } 5782 }
5775 5783
5776 info("USB %s video device found", symbolic(brglist, ov->bridge)); 5784 dev_info(&intf->dev, "USB %s video device found\n",
5785 symbolic(brglist, ov->bridge));
5777 5786
5778 init_waitqueue_head(&ov->wq); 5787 init_waitqueue_head(&ov->wq);
5779 5788
@@ -5854,8 +5863,8 @@ ov51x_probe(struct usb_interface *intf, const struct usb_device_id *id)
5854 goto error; 5863 goto error;
5855 } 5864 }
5856 5865
5857 info("Device at %s registered to minor %d", ov->usb_path, 5866 dev_info(&intf->dev, "Device at %s registered to minor %d\n",
5858 ov->vdev->minor); 5867 ov->usb_path, ov->vdev->minor);
5859 5868
5860 usb_set_intfdata(intf, ov); 5869 usb_set_intfdata(intf, ov);
5861 if (ov_create_sysfs(ov->vdev)) { 5870 if (ov_create_sysfs(ov->vdev)) {
@@ -5958,7 +5967,8 @@ usb_ov511_init(void)
5958 if (retval) 5967 if (retval)
5959 goto out; 5968 goto out;
5960 5969
5961 info(DRIVER_VERSION " : " DRIVER_DESC); 5970 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
5971 DRIVER_DESC "\n");
5962 5972
5963out: 5973out:
5964 return retval; 5974 return retval;
@@ -5968,8 +5978,7 @@ static void __exit
5968usb_ov511_exit(void) 5978usb_ov511_exit(void)
5969{ 5979{
5970 usb_deregister(&ov511_driver); 5980 usb_deregister(&ov511_driver);
5971 info("driver deregistered"); 5981 printk(KERN_INFO KBUILD_MODNAME ": driver deregistered\n");
5972
5973} 5982}
5974 5983
5975module_init(usb_ov511_init); 5984module_init(usb_ov511_init);
diff --git a/drivers/media/video/ov511.h b/drivers/media/video/ov511.h
index baded1262ca9..70d99e52329d 100644
--- a/drivers/media/video/ov511.h
+++ b/drivers/media/video/ov511.h
@@ -12,7 +12,8 @@
12 12
13#ifdef OV511_DEBUG 13#ifdef OV511_DEBUG
14 #define PDEBUG(level, fmt, args...) \ 14 #define PDEBUG(level, fmt, args...) \
15 if (debug >= (level)) info("[%s:%d] " fmt, \ 15 if (debug >= (level)) \
16 printk(KERN_INFO KBUILD_MODNAME "[%s:%d] \n" fmt, \
16 __func__, __LINE__ , ## args) 17 __func__, __LINE__ , ## args)
17#else 18#else
18 #define PDEBUG(level, fmt, args...) do {} while(0) 19 #define PDEBUG(level, fmt, args...) do {} while(0)
diff --git a/drivers/media/video/ovcamchip/ovcamchip_core.c b/drivers/media/video/ovcamchip/ovcamchip_core.c
index 065c2454113e..2c4acbf5a4fe 100644
--- a/drivers/media/video/ovcamchip/ovcamchip_core.c
+++ b/drivers/media/video/ovcamchip/ovcamchip_core.c
@@ -49,12 +49,6 @@ MODULE_LICENSE("GPL");
49#define GENERIC_REG_ID_LOW 0x1D /* manufacturer ID LSB */ 49#define GENERIC_REG_ID_LOW 0x1D /* manufacturer ID LSB */
50#define GENERIC_REG_COM_I 0x29 /* misc ID bits */ 50#define GENERIC_REG_COM_I 0x29 /* misc ID bits */
51 51
52extern struct ovcamchip_ops ov6x20_ops;
53extern struct ovcamchip_ops ov6x30_ops;
54extern struct ovcamchip_ops ov7x10_ops;
55extern struct ovcamchip_ops ov7x20_ops;
56extern struct ovcamchip_ops ov76be_ops;
57
58static char *chip_names[NUM_CC_TYPES] = { 52static char *chip_names[NUM_CC_TYPES] = {
59 [CC_UNKNOWN] = "Unknown chip", 53 [CC_UNKNOWN] = "Unknown chip",
60 [CC_OV76BE] = "OV76BE", 54 [CC_OV76BE] = "OV76BE",
diff --git a/drivers/media/video/ovcamchip/ovcamchip_priv.h b/drivers/media/video/ovcamchip/ovcamchip_priv.h
index 9afa4fe47726..a05650faedda 100644
--- a/drivers/media/video/ovcamchip/ovcamchip_priv.h
+++ b/drivers/media/video/ovcamchip/ovcamchip_priv.h
@@ -53,6 +53,12 @@ struct ovcamchip {
53 int initialized; /* OVCAMCHIP_CMD_INITIALIZE was successful */ 53 int initialized; /* OVCAMCHIP_CMD_INITIALIZE was successful */
54}; 54};
55 55
56extern struct ovcamchip_ops ov6x20_ops;
57extern struct ovcamchip_ops ov6x30_ops;
58extern struct ovcamchip_ops ov7x10_ops;
59extern struct ovcamchip_ops ov7x20_ops;
60extern struct ovcamchip_ops ov76be_ops;
61
56/* --------------------------------- */ 62/* --------------------------------- */
57/* I2C I/O */ 63/* I2C I/O */
58/* --------------------------------- */ 64/* --------------------------------- */
diff --git a/drivers/media/video/pms.c b/drivers/media/video/pms.c
index 7c84f795db54..994807818aa2 100644
--- a/drivers/media/video/pms.c
+++ b/drivers/media/video/pms.c
@@ -47,6 +47,7 @@ struct pms_device
47 struct video_picture picture; 47 struct video_picture picture;
48 int height; 48 int height;
49 int width; 49 int width;
50 unsigned long in_use;
50 struct mutex lock; 51 struct mutex lock;
51}; 52};
52 53
@@ -881,10 +882,27 @@ static ssize_t pms_read(struct file *file, char __user *buf,
881 return len; 882 return len;
882} 883}
883 884
885static int pms_exclusive_open(struct inode *inode, struct file *file)
886{
887 struct video_device *v = video_devdata(file);
888 struct pms_device *pd = (struct pms_device *)v;
889
890 return test_and_set_bit(0, &pd->in_use) ? -EBUSY : 0;
891}
892
893static int pms_exclusive_release(struct inode *inode, struct file *file)
894{
895 struct video_device *v = video_devdata(file);
896 struct pms_device *pd = (struct pms_device *)v;
897
898 clear_bit(0, &pd->in_use);
899 return 0;
900}
901
884static const struct file_operations pms_fops = { 902static const struct file_operations pms_fops = {
885 .owner = THIS_MODULE, 903 .owner = THIS_MODULE,
886 .open = video_exclusive_open, 904 .open = pms_exclusive_open,
887 .release = video_exclusive_release, 905 .release = pms_exclusive_release,
888 .ioctl = pms_ioctl, 906 .ioctl = pms_ioctl,
889#ifdef CONFIG_COMPAT 907#ifdef CONFIG_COMPAT
890 .compat_ioctl = v4l_compat_ioctl32, 908 .compat_ioctl = v4l_compat_ioctl32,
@@ -897,6 +915,7 @@ static struct video_device pms_template=
897{ 915{
898 .name = "Mediavision PMS", 916 .name = "Mediavision PMS",
899 .fops = &pms_fops, 917 .fops = &pms_fops,
918 .release = video_device_release_empty,
900}; 919};
901 920
902static struct pms_device pms_device; 921static struct pms_device pms_device;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
index 0764fbfffb73..203f54cd18a1 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
@@ -134,13 +134,17 @@ int pvr2_ctrl_get_min(struct pvr2_ctrl *cptr)
134 134
135 135
136/* Retrieve control's default value (any type) */ 136/* Retrieve control's default value (any type) */
137int pvr2_ctrl_get_def(struct pvr2_ctrl *cptr) 137int pvr2_ctrl_get_def(struct pvr2_ctrl *cptr, int *valptr)
138{ 138{
139 int ret = 0; 139 int ret = 0;
140 if (!cptr) return 0; 140 if (!cptr) return 0;
141 LOCK_TAKE(cptr->hdw->big_lock); do { 141 LOCK_TAKE(cptr->hdw->big_lock); do {
142 if (cptr->info->type == pvr2_ctl_int) { 142 if (cptr->info->type == pvr2_ctl_int) {
143 ret = cptr->info->default_value; 143 if (cptr->info->get_def_value) {
144 ret = cptr->info->get_def_value(cptr, valptr);
145 } else {
146 *valptr = cptr->info->default_value;
147 }
144 } 148 }
145 } while(0); LOCK_GIVE(cptr->hdw->big_lock); 149 } while(0); LOCK_GIVE(cptr->hdw->big_lock);
146 return ret; 150 return ret;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ctrl.h b/drivers/media/video/pvrusb2/pvrusb2-ctrl.h
index 0371ae6e6e4e..794ff90121c7 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-ctrl.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-ctrl.h
@@ -49,7 +49,7 @@ int pvr2_ctrl_get_max(struct pvr2_ctrl *);
49int pvr2_ctrl_get_min(struct pvr2_ctrl *); 49int pvr2_ctrl_get_min(struct pvr2_ctrl *);
50 50
51/* Retrieve control's default value (any type) */ 51/* Retrieve control's default value (any type) */
52int pvr2_ctrl_get_def(struct pvr2_ctrl *); 52int pvr2_ctrl_get_def(struct pvr2_ctrl *, int *valptr);
53 53
54/* Retrieve control's enumeration count (enum only) */ 54/* Retrieve control's enumeration count (enum only) */
55int pvr2_ctrl_get_cnt(struct pvr2_ctrl *); 55int pvr2_ctrl_get_cnt(struct pvr2_ctrl *);
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
index 657f861593b3..de7ee7264be6 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
@@ -82,6 +82,7 @@ struct pvr2_ctl_info {
82 82
83 /* Control's implementation */ 83 /* Control's implementation */
84 pvr2_ctlf_get_value get_value; /* Get its value */ 84 pvr2_ctlf_get_value get_value; /* Get its value */
85 pvr2_ctlf_get_value get_def_value; /* Get its default value */
85 pvr2_ctlf_get_value get_min_value; /* Get minimum allowed value */ 86 pvr2_ctlf_get_value get_min_value; /* Get minimum allowed value */
86 pvr2_ctlf_get_value get_max_value; /* Get maximum allowed value */ 87 pvr2_ctlf_get_value get_max_value; /* Get maximum allowed value */
87 pvr2_ctlf_set_value set_value; /* Set its value */ 88 pvr2_ctlf_set_value set_value; /* Set its value */
@@ -307,6 +308,10 @@ struct pvr2_hdw {
307 struct v4l2_tuner tuner_signal_info; 308 struct v4l2_tuner tuner_signal_info;
308 int tuner_signal_stale; 309 int tuner_signal_stale;
309 310
311 /* Cropping capability info */
312 struct v4l2_cropcap cropcap_info;
313 int cropcap_stale;
314
310 /* Video standard handling */ 315 /* Video standard handling */
311 v4l2_std_id std_mask_eeprom; // Hardware supported selections 316 v4l2_std_id std_mask_eeprom; // Hardware supported selections
312 v4l2_std_id std_mask_avail; // Which standards we may select from 317 v4l2_std_id std_mask_avail; // Which standards we may select from
@@ -367,6 +372,10 @@ struct pvr2_hdw {
367 VCREATE_DATA(bass); 372 VCREATE_DATA(bass);
368 VCREATE_DATA(treble); 373 VCREATE_DATA(treble);
369 VCREATE_DATA(mute); 374 VCREATE_DATA(mute);
375 VCREATE_DATA(cropl);
376 VCREATE_DATA(cropt);
377 VCREATE_DATA(cropw);
378 VCREATE_DATA(croph);
370 VCREATE_DATA(input); 379 VCREATE_DATA(input);
371 VCREATE_DATA(audiomode); 380 VCREATE_DATA(audiomode);
372 VCREATE_DATA(res_hor); 381 VCREATE_DATA(res_hor);
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index f051c6aa7f1f..94265bd3d926 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -298,6 +298,7 @@ static int pvr2_send_request_ex(struct pvr2_hdw *hdw,
298 unsigned int timeout,int probe_fl, 298 unsigned int timeout,int probe_fl,
299 void *write_data,unsigned int write_len, 299 void *write_data,unsigned int write_len,
300 void *read_data,unsigned int read_len); 300 void *read_data,unsigned int read_len);
301static int pvr2_hdw_check_cropcap(struct pvr2_hdw *hdw);
301 302
302 303
303static void trace_stbit(const char *name,int val) 304static void trace_stbit(const char *name,int val)
@@ -402,6 +403,194 @@ static int ctrl_freq_set(struct pvr2_ctrl *cptr,int m,int v)
402 return 0; 403 return 0;
403} 404}
404 405
406static int ctrl_cropl_min_get(struct pvr2_ctrl *cptr, int *left)
407{
408 struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
409 int stat = pvr2_hdw_check_cropcap(cptr->hdw);
410 if (stat != 0) {
411 return stat;
412 }
413 *left = cap->bounds.left;
414 return 0;
415}
416
417static int ctrl_cropl_max_get(struct pvr2_ctrl *cptr, int *left)
418{
419 struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
420 int stat = pvr2_hdw_check_cropcap(cptr->hdw);
421 if (stat != 0) {
422 return stat;
423 }
424 *left = cap->bounds.left;
425 if (cap->bounds.width > cptr->hdw->cropw_val) {
426 *left += cap->bounds.width - cptr->hdw->cropw_val;
427 }
428 return 0;
429}
430
431static int ctrl_cropt_min_get(struct pvr2_ctrl *cptr, int *top)
432{
433 struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
434 int stat = pvr2_hdw_check_cropcap(cptr->hdw);
435 if (stat != 0) {
436 return stat;
437 }
438 *top = cap->bounds.top;
439 return 0;
440}
441
442static int ctrl_cropt_max_get(struct pvr2_ctrl *cptr, int *top)
443{
444 struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
445 int stat = pvr2_hdw_check_cropcap(cptr->hdw);
446 if (stat != 0) {
447 return stat;
448 }
449 *top = cap->bounds.top;
450 if (cap->bounds.height > cptr->hdw->croph_val) {
451 *top += cap->bounds.height - cptr->hdw->croph_val;
452 }
453 return 0;
454}
455
456static int ctrl_cropw_max_get(struct pvr2_ctrl *cptr, int *val)
457{
458 struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
459 int stat = pvr2_hdw_check_cropcap(cptr->hdw);
460 if (stat != 0) {
461 return stat;
462 }
463 *val = 0;
464 if (cap->bounds.width > cptr->hdw->cropl_val) {
465 *val = cap->bounds.width - cptr->hdw->cropl_val;
466 }
467 return 0;
468}
469
470static int ctrl_croph_max_get(struct pvr2_ctrl *cptr, int *val)
471{
472 struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
473 int stat = pvr2_hdw_check_cropcap(cptr->hdw);
474 if (stat != 0) {
475 return stat;
476 }
477 *val = 0;
478 if (cap->bounds.height > cptr->hdw->cropt_val) {
479 *val = cap->bounds.height - cptr->hdw->cropt_val;
480 }
481 return 0;
482}
483
484static int ctrl_get_cropcapbl(struct pvr2_ctrl *cptr, int *val)
485{
486 struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
487 int stat = pvr2_hdw_check_cropcap(cptr->hdw);
488 if (stat != 0) {
489 return stat;
490 }
491 *val = cap->bounds.left;
492 return 0;
493}
494
495static int ctrl_get_cropcapbt(struct pvr2_ctrl *cptr, int *val)
496{
497 struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
498 int stat = pvr2_hdw_check_cropcap(cptr->hdw);
499 if (stat != 0) {
500 return stat;
501 }
502 *val = cap->bounds.top;
503 return 0;
504}
505
506static int ctrl_get_cropcapbw(struct pvr2_ctrl *cptr, int *val)
507{
508 struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
509 int stat = pvr2_hdw_check_cropcap(cptr->hdw);
510 if (stat != 0) {
511 return stat;
512 }
513 *val = cap->bounds.width;
514 return 0;
515}
516
517static int ctrl_get_cropcapbh(struct pvr2_ctrl *cptr, int *val)
518{
519 struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
520 int stat = pvr2_hdw_check_cropcap(cptr->hdw);
521 if (stat != 0) {
522 return stat;
523 }
524 *val = cap->bounds.height;
525 return 0;
526}
527
528static int ctrl_get_cropcapdl(struct pvr2_ctrl *cptr, int *val)
529{
530 struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
531 int stat = pvr2_hdw_check_cropcap(cptr->hdw);
532 if (stat != 0) {
533 return stat;
534 }
535 *val = cap->defrect.left;
536 return 0;
537}
538
539static int ctrl_get_cropcapdt(struct pvr2_ctrl *cptr, int *val)
540{
541 struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
542 int stat = pvr2_hdw_check_cropcap(cptr->hdw);
543 if (stat != 0) {
544 return stat;
545 }
546 *val = cap->defrect.top;
547 return 0;
548}
549
550static int ctrl_get_cropcapdw(struct pvr2_ctrl *cptr, int *val)
551{
552 struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
553 int stat = pvr2_hdw_check_cropcap(cptr->hdw);
554 if (stat != 0) {
555 return stat;
556 }
557 *val = cap->defrect.width;
558 return 0;
559}
560
561static int ctrl_get_cropcapdh(struct pvr2_ctrl *cptr, int *val)
562{
563 struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
564 int stat = pvr2_hdw_check_cropcap(cptr->hdw);
565 if (stat != 0) {
566 return stat;
567 }
568 *val = cap->defrect.height;
569 return 0;
570}
571
572static int ctrl_get_cropcappan(struct pvr2_ctrl *cptr, int *val)
573{
574 struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
575 int stat = pvr2_hdw_check_cropcap(cptr->hdw);
576 if (stat != 0) {
577 return stat;
578 }
579 *val = cap->pixelaspect.numerator;
580 return 0;
581}
582
583static int ctrl_get_cropcappad(struct pvr2_ctrl *cptr, int *val)
584{
585 struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
586 int stat = pvr2_hdw_check_cropcap(cptr->hdw);
587 if (stat != 0) {
588 return stat;
589 }
590 *val = cap->pixelaspect.denominator;
591 return 0;
592}
593
405static int ctrl_vres_max_get(struct pvr2_ctrl *cptr,int *vp) 594static int ctrl_vres_max_get(struct pvr2_ctrl *cptr,int *vp)
406{ 595{
407 /* Actual maximum depends on the video standard in effect. */ 596 /* Actual maximum depends on the video standard in effect. */
@@ -779,6 +968,10 @@ VCREATE_FUNCS(balance)
779VCREATE_FUNCS(bass) 968VCREATE_FUNCS(bass)
780VCREATE_FUNCS(treble) 969VCREATE_FUNCS(treble)
781VCREATE_FUNCS(mute) 970VCREATE_FUNCS(mute)
971VCREATE_FUNCS(cropl)
972VCREATE_FUNCS(cropt)
973VCREATE_FUNCS(cropw)
974VCREATE_FUNCS(croph)
782VCREATE_FUNCS(audiomode) 975VCREATE_FUNCS(audiomode)
783VCREATE_FUNCS(res_hor) 976VCREATE_FUNCS(res_hor)
784VCREATE_FUNCS(res_ver) 977VCREATE_FUNCS(res_ver)
@@ -849,6 +1042,72 @@ static const struct pvr2_ctl_info control_defs[] = {
849 .default_value = 0, 1042 .default_value = 0,
850 DEFREF(mute), 1043 DEFREF(mute),
851 DEFBOOL, 1044 DEFBOOL,
1045 }, {
1046 .desc = "Capture crop left margin",
1047 .name = "crop_left",
1048 .internal_id = PVR2_CID_CROPL,
1049 .default_value = 0,
1050 DEFREF(cropl),
1051 DEFINT(-129, 340),
1052 .get_min_value = ctrl_cropl_min_get,
1053 .get_max_value = ctrl_cropl_max_get,
1054 .get_def_value = ctrl_get_cropcapdl,
1055 }, {
1056 .desc = "Capture crop top margin",
1057 .name = "crop_top",
1058 .internal_id = PVR2_CID_CROPT,
1059 .default_value = 0,
1060 DEFREF(cropt),
1061 DEFINT(-35, 544),
1062 .get_min_value = ctrl_cropt_min_get,
1063 .get_max_value = ctrl_cropt_max_get,
1064 .get_def_value = ctrl_get_cropcapdt,
1065 }, {
1066 .desc = "Capture crop width",
1067 .name = "crop_width",
1068 .internal_id = PVR2_CID_CROPW,
1069 .default_value = 720,
1070 DEFREF(cropw),
1071 .get_max_value = ctrl_cropw_max_get,
1072 .get_def_value = ctrl_get_cropcapdw,
1073 }, {
1074 .desc = "Capture crop height",
1075 .name = "crop_height",
1076 .internal_id = PVR2_CID_CROPH,
1077 .default_value = 480,
1078 DEFREF(croph),
1079 .get_max_value = ctrl_croph_max_get,
1080 .get_def_value = ctrl_get_cropcapdh,
1081 }, {
1082 .desc = "Capture capability pixel aspect numerator",
1083 .name = "cropcap_pixel_numerator",
1084 .internal_id = PVR2_CID_CROPCAPPAN,
1085 .get_value = ctrl_get_cropcappan,
1086 }, {
1087 .desc = "Capture capability pixel aspect denominator",
1088 .name = "cropcap_pixel_denominator",
1089 .internal_id = PVR2_CID_CROPCAPPAD,
1090 .get_value = ctrl_get_cropcappad,
1091 }, {
1092 .desc = "Capture capability bounds top",
1093 .name = "cropcap_bounds_top",
1094 .internal_id = PVR2_CID_CROPCAPBT,
1095 .get_value = ctrl_get_cropcapbt,
1096 }, {
1097 .desc = "Capture capability bounds left",
1098 .name = "cropcap_bounds_left",
1099 .internal_id = PVR2_CID_CROPCAPBL,
1100 .get_value = ctrl_get_cropcapbl,
1101 }, {
1102 .desc = "Capture capability bounds width",
1103 .name = "cropcap_bounds_width",
1104 .internal_id = PVR2_CID_CROPCAPBW,
1105 .get_value = ctrl_get_cropcapbw,
1106 }, {
1107 .desc = "Capture capability bounds height",
1108 .name = "cropcap_bounds_height",
1109 .internal_id = PVR2_CID_CROPCAPBH,
1110 .get_value = ctrl_get_cropcapbh,
852 },{ 1111 },{
853 .desc = "Video Source", 1112 .desc = "Video Source",
854 .name = "input", 1113 .name = "input",
@@ -1313,9 +1572,19 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
1313 if (bcnt > FIRMWARE_CHUNK_SIZE) bcnt = FIRMWARE_CHUNK_SIZE; 1572 if (bcnt > FIRMWARE_CHUNK_SIZE) bcnt = FIRMWARE_CHUNK_SIZE;
1314 memcpy(fw_ptr, fw_entry->data + fw_done, bcnt); 1573 memcpy(fw_ptr, fw_entry->data + fw_done, bcnt);
1315 /* Usbsnoop log shows that we must swap bytes... */ 1574 /* Usbsnoop log shows that we must swap bytes... */
1575 /* Some background info: The data being swapped here is a
1576 firmware image destined for the mpeg encoder chip that
1577 lives at the other end of a USB endpoint. The encoder
1578 chip always talks in 32 bit chunks and its storage is
1579 organized into 32 bit words. However from the file
1580 system to the encoder chip everything is purely a byte
1581 stream. The firmware file's contents are always 32 bit
1582 swapped from what the encoder expects. Thus the need
1583 always exists to swap the bytes regardless of the endian
1584 type of the host processor and therefore swab32() makes
1585 the most sense. */
1316 for (icnt = 0; icnt < bcnt/4 ; icnt++) 1586 for (icnt = 0; icnt < bcnt/4 ; icnt++)
1317 ((u32 *)fw_ptr)[icnt] = 1587 ((u32 *)fw_ptr)[icnt] = swab32(((u32 *)fw_ptr)[icnt]);
1318 ___swab32(((u32 *)fw_ptr)[icnt]);
1319 1588
1320 ret |= usb_bulk_msg(hdw->usb_dev, pipe, fw_ptr,bcnt, 1589 ret |= usb_bulk_msg(hdw->usb_dev, pipe, fw_ptr,bcnt,
1321 &actual_length, HZ); 1590 &actual_length, HZ);
@@ -1905,7 +2174,7 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
1905 const struct usb_device_id *devid) 2174 const struct usb_device_id *devid)
1906{ 2175{
1907 unsigned int idx,cnt1,cnt2,m; 2176 unsigned int idx,cnt1,cnt2,m;
1908 struct pvr2_hdw *hdw; 2177 struct pvr2_hdw *hdw = NULL;
1909 int valid_std_mask; 2178 int valid_std_mask;
1910 struct pvr2_ctrl *cptr; 2179 struct pvr2_ctrl *cptr;
1911 const struct pvr2_device_desc *hdw_desc; 2180 const struct pvr2_device_desc *hdw_desc;
@@ -1915,6 +2184,16 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
1915 2184
1916 hdw_desc = (const struct pvr2_device_desc *)(devid->driver_info); 2185 hdw_desc = (const struct pvr2_device_desc *)(devid->driver_info);
1917 2186
2187 if (hdw_desc == NULL) {
2188 pvr2_trace(PVR2_TRACE_INIT, "pvr2_hdw_create:"
2189 " No device description pointer,"
2190 " unable to continue.");
2191 pvr2_trace(PVR2_TRACE_INIT, "If you have a new device type,"
2192 " please contact Mike Isely <isely@pobox.com>"
2193 " to get it included in the driver\n");
2194 goto fail;
2195 }
2196
1918 hdw = kzalloc(sizeof(*hdw),GFP_KERNEL); 2197 hdw = kzalloc(sizeof(*hdw),GFP_KERNEL);
1919 pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_create: hdw=%p, type \"%s\"", 2198 pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_create: hdw=%p, type \"%s\"",
1920 hdw,hdw_desc->description); 2199 hdw,hdw_desc->description);
@@ -2072,6 +2351,7 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2072 valid_std_mask; 2351 valid_std_mask;
2073 } 2352 }
2074 2353
2354 hdw->cropcap_stale = !0;
2075 hdw->eeprom_addr = -1; 2355 hdw->eeprom_addr = -1;
2076 hdw->unit_number = -1; 2356 hdw->unit_number = -1;
2077 hdw->v4l_minor_number_video = -1; 2357 hdw->v4l_minor_number_video = -1;
@@ -2508,6 +2788,28 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw)
2508 /* Can't commit anything until pathway is ok. */ 2788 /* Can't commit anything until pathway is ok. */
2509 return 0; 2789 return 0;
2510 } 2790 }
2791 /* The broadcast decoder can only scale down, so if
2792 * res_*_dirty && crop window < output format ==> enlarge crop.
2793 *
2794 * The mpeg encoder receives fields of res_hor_val dots and
2795 * res_ver_val halflines. Limits: hor<=720, ver<=576.
2796 */
2797 if (hdw->res_hor_dirty && hdw->cropw_val < hdw->res_hor_val) {
2798 hdw->cropw_val = hdw->res_hor_val;
2799 hdw->cropw_dirty = !0;
2800 } else if (hdw->cropw_dirty) {
2801 hdw->res_hor_dirty = !0; /* must rescale */
2802 hdw->res_hor_val = min(720, hdw->cropw_val);
2803 }
2804 if (hdw->res_ver_dirty && hdw->croph_val < hdw->res_ver_val) {
2805 hdw->croph_val = hdw->res_ver_val;
2806 hdw->croph_dirty = !0;
2807 } else if (hdw->croph_dirty) {
2808 int nvres = hdw->std_mask_cur & V4L2_STD_525_60 ? 480 : 576;
2809 hdw->res_ver_dirty = !0;
2810 hdw->res_ver_val = min(nvres, hdw->croph_val);
2811 }
2812
2511 /* If any of the below has changed, then we can't do the update 2813 /* If any of the below has changed, then we can't do the update
2512 while the pipeline is running. Pipeline must be paused first 2814 while the pipeline is running. Pipeline must be paused first
2513 and decoder -> encoder connection be made quiescent before we 2815 and decoder -> encoder connection be made quiescent before we
@@ -2518,6 +2820,8 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw)
2518 hdw->srate_dirty || 2820 hdw->srate_dirty ||
2519 hdw->res_ver_dirty || 2821 hdw->res_ver_dirty ||
2520 hdw->res_hor_dirty || 2822 hdw->res_hor_dirty ||
2823 hdw->cropw_dirty ||
2824 hdw->croph_dirty ||
2521 hdw->input_dirty || 2825 hdw->input_dirty ||
2522 (hdw->active_stream_type != hdw->desired_stream_type)); 2826 (hdw->active_stream_type != hdw->desired_stream_type));
2523 if (disruptive_change && !hdw->state_pipeline_idle) { 2827 if (disruptive_change && !hdw->state_pipeline_idle) {
@@ -2587,6 +2891,9 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw)
2587 } 2891 }
2588 2892
2589 hdw->state_pipeline_config = !0; 2893 hdw->state_pipeline_config = !0;
2894 /* Hardware state may have changed in a way to cause the cropping
2895 capabilities to have changed. So mark it stale, which will
2896 cause a later re-fetch. */
2590 trace_stbit("state_pipeline_config",hdw->state_pipeline_config); 2897 trace_stbit("state_pipeline_config",hdw->state_pipeline_config);
2591 return !0; 2898 return !0;
2592} 2899}
@@ -2677,6 +2984,33 @@ void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *hdw)
2677} 2984}
2678 2985
2679 2986
2987static int pvr2_hdw_check_cropcap(struct pvr2_hdw *hdw)
2988{
2989 if (!hdw->cropcap_stale) {
2990 return 0;
2991 }
2992 pvr2_i2c_core_status_poll(hdw);
2993 if (hdw->cropcap_stale) {
2994 return -EIO;
2995 }
2996 return 0;
2997}
2998
2999
3000/* Return information about cropping capabilities */
3001int pvr2_hdw_get_cropcap(struct pvr2_hdw *hdw, struct v4l2_cropcap *pp)
3002{
3003 int stat = 0;
3004 LOCK_TAKE(hdw->big_lock);
3005 stat = pvr2_hdw_check_cropcap(hdw);
3006 if (!stat) {
3007 memcpy(pp, &hdw->cropcap_info, sizeof(hdw->cropcap_info));
3008 }
3009 LOCK_GIVE(hdw->big_lock);
3010 return stat;
3011}
3012
3013
2680/* Return information about the tuner */ 3014/* Return information about the tuner */
2681int pvr2_hdw_get_tuner_status(struct pvr2_hdw *hdw,struct v4l2_tuner *vtp) 3015int pvr2_hdw_get_tuner_status(struct pvr2_hdw *hdw,struct v4l2_tuner *vtp)
2682{ 3016{
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.h b/drivers/media/video/pvrusb2/pvrusb2-hdw.h
index c04956d304a7..49482d1f2b28 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.h
@@ -36,6 +36,16 @@
36#define PVR2_CID_FREQUENCY 6 36#define PVR2_CID_FREQUENCY 6
37#define PVR2_CID_HRES 7 37#define PVR2_CID_HRES 7
38#define PVR2_CID_VRES 8 38#define PVR2_CID_VRES 8
39#define PVR2_CID_CROPL 9
40#define PVR2_CID_CROPT 10
41#define PVR2_CID_CROPW 11
42#define PVR2_CID_CROPH 12
43#define PVR2_CID_CROPCAPPAN 13
44#define PVR2_CID_CROPCAPPAD 14
45#define PVR2_CID_CROPCAPBL 15
46#define PVR2_CID_CROPCAPBT 16
47#define PVR2_CID_CROPCAPBW 17
48#define PVR2_CID_CROPCAPBH 18
39 49
40/* Legal values for the INPUT state variable */ 50/* Legal values for the INPUT state variable */
41#define PVR2_CVAL_INPUT_TV 0 51#define PVR2_CVAL_INPUT_TV 0
@@ -170,6 +180,9 @@ void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *);
170/* Return information about the tuner */ 180/* Return information about the tuner */
171int pvr2_hdw_get_tuner_status(struct pvr2_hdw *,struct v4l2_tuner *); 181int pvr2_hdw_get_tuner_status(struct pvr2_hdw *,struct v4l2_tuner *);
172 182
183/* Return information about cropping capabilities */
184int pvr2_hdw_get_cropcap(struct pvr2_hdw *, struct v4l2_cropcap *);
185
173/* Query device and see if it thinks it is on a high-speed USB link */ 186/* Query device and see if it thinks it is on a high-speed USB link */
174int pvr2_hdw_is_hsm(struct pvr2_hdw *); 187int pvr2_hdw_is_hsm(struct pvr2_hdw *);
175 188
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c
index ccdb429fc7af..94a47718e88e 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c
@@ -37,8 +37,9 @@
37#define OP_VOLUME 3 37#define OP_VOLUME 3
38#define OP_FREQ 4 38#define OP_FREQ 4
39#define OP_AUDIORATE 5 39#define OP_AUDIORATE 5
40#define OP_SIZE 6 40#define OP_CROP 6
41#define OP_LOG 7 41#define OP_SIZE 7
42#define OP_LOG 8
42 43
43static const struct pvr2_i2c_op * const ops[] = { 44static const struct pvr2_i2c_op * const ops[] = {
44 [OP_STANDARD] = &pvr2_i2c_op_v4l2_standard, 45 [OP_STANDARD] = &pvr2_i2c_op_v4l2_standard,
@@ -46,6 +47,7 @@ static const struct pvr2_i2c_op * const ops[] = {
46 [OP_BCSH] = &pvr2_i2c_op_v4l2_bcsh, 47 [OP_BCSH] = &pvr2_i2c_op_v4l2_bcsh,
47 [OP_VOLUME] = &pvr2_i2c_op_v4l2_volume, 48 [OP_VOLUME] = &pvr2_i2c_op_v4l2_volume,
48 [OP_FREQ] = &pvr2_i2c_op_v4l2_frequency, 49 [OP_FREQ] = &pvr2_i2c_op_v4l2_frequency,
50 [OP_CROP] = &pvr2_i2c_op_v4l2_crop,
49 [OP_SIZE] = &pvr2_i2c_op_v4l2_size, 51 [OP_SIZE] = &pvr2_i2c_op_v4l2_size,
50 [OP_LOG] = &pvr2_i2c_op_v4l2_log, 52 [OP_LOG] = &pvr2_i2c_op_v4l2_log,
51}; 53};
@@ -59,6 +61,7 @@ void pvr2_i2c_probe(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
59 (1 << OP_BCSH) | 61 (1 << OP_BCSH) |
60 (1 << OP_VOLUME) | 62 (1 << OP_VOLUME) |
61 (1 << OP_FREQ) | 63 (1 << OP_FREQ) |
64 (1 << OP_CROP) |
62 (1 << OP_SIZE) | 65 (1 << OP_SIZE) |
63 (1 << OP_LOG)); 66 (1 << OP_LOG));
64 cp->status_poll = pvr2_v4l2_cmd_status_poll; 67 cp->status_poll = pvr2_v4l2_cmd_status_poll;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c
index 55f04a0b2047..16bb11902a52 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c
@@ -37,6 +37,7 @@ static void set_standard(struct pvr2_hdw *hdw)
37 pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs); 37 pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs);
38 } 38 }
39 hdw->tuner_signal_stale = !0; 39 hdw->tuner_signal_stale = !0;
40 hdw->cropcap_stale = !0;
40} 41}
41 42
42 43
@@ -233,6 +234,37 @@ const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = {
233}; 234};
234 235
235 236
237static void set_crop(struct pvr2_hdw *hdw)
238{
239 struct v4l2_crop crop;
240
241 memset(&crop, 0, sizeof crop);
242 crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
243 crop.c.left = hdw->cropl_val;
244 crop.c.top = hdw->cropt_val;
245 crop.c.height = hdw->croph_val;
246 crop.c.width = hdw->cropw_val;
247
248 pvr2_trace(PVR2_TRACE_CHIPS,
249 "i2c v4l2 set_crop crop=%d:%d:%d:%d",
250 crop.c.width, crop.c.height, crop.c.left, crop.c.top);
251
252 pvr2_i2c_core_cmd(hdw, VIDIOC_S_CROP, &crop);
253}
254
255static int check_crop(struct pvr2_hdw *hdw)
256{
257 return (hdw->cropl_dirty || hdw->cropt_dirty ||
258 hdw->cropw_dirty || hdw->croph_dirty);
259}
260
261const struct pvr2_i2c_op pvr2_i2c_op_v4l2_crop = {
262 .check = check_crop,
263 .update = set_crop,
264 .name = "v4l2_crop",
265};
266
267
236static void do_log(struct pvr2_hdw *hdw) 268static void do_log(struct pvr2_hdw *hdw)
237{ 269{
238 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()"); 270 pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()");
@@ -263,7 +295,19 @@ void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl)
263 295
264void pvr2_v4l2_cmd_status_poll(struct pvr2_i2c_client *cp) 296void pvr2_v4l2_cmd_status_poll(struct pvr2_i2c_client *cp)
265{ 297{
266 pvr2_i2c_client_cmd(cp,VIDIOC_G_TUNER,&cp->hdw->tuner_signal_info); 298 int stat;
299 struct pvr2_hdw *hdw = cp->hdw;
300 if (hdw->cropcap_stale) {
301 hdw->cropcap_info.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
302 stat = pvr2_i2c_client_cmd(cp, VIDIOC_CROPCAP,
303 &hdw->cropcap_info);
304 if (stat == 0) {
305 /* Check was successful, so the data is no
306 longer considered stale. */
307 hdw->cropcap_stale = 0;
308 }
309 }
310 pvr2_i2c_client_cmd(cp, VIDIOC_G_TUNER, &hdw->tuner_signal_info);
267} 311}
268 312
269 313
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h b/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h
index 7fa38683b3b1..eb744a20610d 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h
@@ -29,6 +29,7 @@ extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_radio;
29extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh; 29extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh;
30extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume; 30extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume;
31extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency; 31extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency;
32extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_crop;
32extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size; 33extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size;
33extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_audiomode; 34extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_audiomode;
34extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log; 35extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
index e600576a6c4b..d6a35401fefb 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
@@ -827,7 +827,7 @@ static unsigned int pvr2_i2c_client_describe(struct pvr2_i2c_client *cp,
827 if ((detail & PVR2_I2C_DETAIL_CTLMASK) && cp->ctl_mask) { 827 if ((detail & PVR2_I2C_DETAIL_CTLMASK) && cp->ctl_mask) {
828 unsigned int idx; 828 unsigned int idx;
829 unsigned long msk,sm; 829 unsigned long msk,sm;
830 int spcfl; 830
831 bcnt = scnprintf(buf,maxlen," ["); 831 bcnt = scnprintf(buf,maxlen," [");
832 ccnt += bcnt; buf += bcnt; maxlen -= bcnt; 832 ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
833 sm = 0; 833 sm = 0;
@@ -891,6 +891,7 @@ static int pvr2_i2c_attach_inform(struct i2c_client *client)
891 INIT_LIST_HEAD(&cp->list); 891 INIT_LIST_HEAD(&cp->list);
892 cp->client = client; 892 cp->client = client;
893 mutex_lock(&hdw->i2c_list_lock); do { 893 mutex_lock(&hdw->i2c_list_lock); do {
894 hdw->cropcap_stale = !0;
894 list_add_tail(&cp->list,&hdw->i2c_clients); 895 list_add_tail(&cp->list,&hdw->i2c_clients);
895 hdw->i2c_pend_types |= PVR2_I2C_PEND_DETECT; 896 hdw->i2c_pend_types |= PVR2_I2C_PEND_DETECT;
896 } while (0); mutex_unlock(&hdw->i2c_list_lock); 897 } while (0); mutex_unlock(&hdw->i2c_list_lock);
@@ -905,6 +906,7 @@ static int pvr2_i2c_detach_inform(struct i2c_client *client)
905 unsigned long amask = 0; 906 unsigned long amask = 0;
906 int foundfl = 0; 907 int foundfl = 0;
907 mutex_lock(&hdw->i2c_list_lock); do { 908 mutex_lock(&hdw->i2c_list_lock); do {
909 hdw->cropcap_stale = !0;
908 list_for_each_entry_safe(cp, ncp, &hdw->i2c_clients, list) { 910 list_for_each_entry_safe(cp, ncp, &hdw->i2c_clients, list) {
909 if (cp->client == client) { 911 if (cp->client == client) {
910 trace_i2c("pvr2_i2c_detach" 912 trace_i2c("pvr2_i2c_detach"
@@ -946,22 +948,32 @@ static struct i2c_adapter pvr2_i2c_adap_template = {
946 .client_unregister = pvr2_i2c_detach_inform, 948 .client_unregister = pvr2_i2c_detach_inform,
947}; 949};
948 950
949static void do_i2c_scan(struct pvr2_hdw *hdw) 951
952/* Return true if device exists at given address */
953static int do_i2c_probe(struct pvr2_hdw *hdw, int addr)
950{ 954{
951 struct i2c_msg msg[1]; 955 struct i2c_msg msg[1];
952 int i,rc; 956 int rc;
953 msg[0].addr = 0; 957 msg[0].addr = 0;
954 msg[0].flags = I2C_M_RD; 958 msg[0].flags = I2C_M_RD;
955 msg[0].len = 0; 959 msg[0].len = 0;
956 msg[0].buf = NULL; 960 msg[0].buf = NULL;
957 printk("%s: i2c scan beginning\n",hdw->name); 961 msg[0].addr = addr;
962 rc = i2c_transfer(&hdw->i2c_adap, msg, ARRAY_SIZE(msg));
963 return rc == 1;
964}
965
966static void do_i2c_scan(struct pvr2_hdw *hdw)
967{
968 int i;
969 printk(KERN_INFO "%s: i2c scan beginning\n", hdw->name);
958 for (i = 0; i < 128; i++) { 970 for (i = 0; i < 128; i++) {
959 msg[0].addr = i; 971 if (do_i2c_probe(hdw, i)) {
960 rc = i2c_transfer(&hdw->i2c_adap,msg, ARRAY_SIZE(msg)); 972 printk(KERN_INFO "%s: i2c scan: found device @ 0x%x\n",
961 if (rc != 1) continue; 973 hdw->name, i);
962 printk("%s: i2c scan: found device @ 0x%x\n",hdw->name,i); 974 }
963 } 975 }
964 printk("%s: i2c scan done.\n",hdw->name); 976 printk(KERN_INFO "%s: i2c scan done.\n", hdw->name);
965} 977}
966 978
967void pvr2_i2c_core_init(struct pvr2_hdw *hdw) 979void pvr2_i2c_core_init(struct pvr2_hdw *hdw)
@@ -980,8 +992,6 @@ void pvr2_i2c_core_init(struct pvr2_hdw *hdw)
980 hdw->i2c_func[0x18] = i2c_black_hole; 992 hdw->i2c_func[0x18] = i2c_black_hole;
981 } else if (ir_mode[hdw->unit_number] == 1) { 993 } else if (ir_mode[hdw->unit_number] == 1) {
982 if (hdw->hdw_desc->ir_scheme == PVR2_IR_SCHEME_24XXX) { 994 if (hdw->hdw_desc->ir_scheme == PVR2_IR_SCHEME_24XXX) {
983 /* This comment is present PURELY to get
984 checkpatch.pl to STFU. Lovely, eh? */
985 hdw->i2c_func[0x18] = i2c_24xxx_ir; 995 hdw->i2c_func[0x18] = i2c_24xxx_ir;
986 } 996 }
987 } 997 }
@@ -1006,6 +1016,16 @@ void pvr2_i2c_core_init(struct pvr2_hdw *hdw)
1006 mutex_init(&hdw->i2c_list_lock); 1016 mutex_init(&hdw->i2c_list_lock);
1007 hdw->i2c_linked = !0; 1017 hdw->i2c_linked = !0;
1008 i2c_add_adapter(&hdw->i2c_adap); 1018 i2c_add_adapter(&hdw->i2c_adap);
1019 if (hdw->i2c_func[0x18] == i2c_24xxx_ir) {
1020 /* Probe for a different type of IR receiver on this
1021 device. If present, disable the emulated IR receiver. */
1022 if (do_i2c_probe(hdw, 0x71)) {
1023 pvr2_trace(PVR2_TRACE_INFO,
1024 "Device has newer IR hardware;"
1025 " disabling unneeded virtual IR device");
1026 hdw->i2c_func[0x18] = NULL;
1027 }
1028 }
1009 if (i2c_scan) do_i2c_scan(hdw); 1029 if (i2c_scan) do_i2c_scan(hdw);
1010} 1030}
1011 1031
diff --git a/drivers/media/video/pvrusb2/pvrusb2-main.c b/drivers/media/video/pvrusb2/pvrusb2-main.c
index ad0d98c2ebb4..9b3c874d96d6 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-main.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-main.c
@@ -137,9 +137,11 @@ static int __init pvr_init(void)
137 ret = usb_register(&pvr_driver); 137 ret = usb_register(&pvr_driver);
138 138
139 if (ret == 0) 139 if (ret == 0)
140 info(DRIVER_DESC " : " DRIVER_VERSION); 140 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
141 if (pvrusb2_debug) info("Debug mask is %d (0x%x)", 141 DRIVER_DESC "\n");
142 pvrusb2_debug,pvrusb2_debug); 142 if (pvrusb2_debug)
143 printk(KERN_INFO KBUILD_MODNAME ": Debug mask is %d (0x%x)\n",
144 pvrusb2_debug,pvrusb2_debug);
143 145
144 pvr2_trace(PVR2_TRACE_INIT,"pvr_init complete"); 146 pvr2_trace(PVR2_TRACE_INIT,"pvr_init complete");
145 147
diff --git a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
index 46a8c39ba030..733680f21317 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
@@ -65,6 +65,7 @@ struct pvr2_sysfs_ctl_item {
65 struct device_attribute attr_type; 65 struct device_attribute attr_type;
66 struct device_attribute attr_min; 66 struct device_attribute attr_min;
67 struct device_attribute attr_max; 67 struct device_attribute attr_max;
68 struct device_attribute attr_def;
68 struct device_attribute attr_enum; 69 struct device_attribute attr_enum;
69 struct device_attribute attr_bits; 70 struct device_attribute attr_bits;
70 struct device_attribute attr_val; 71 struct device_attribute attr_val;
@@ -145,6 +146,23 @@ static ssize_t show_max(struct device *class_dev,
145 return scnprintf(buf, PAGE_SIZE, "%ld\n", val); 146 return scnprintf(buf, PAGE_SIZE, "%ld\n", val);
146} 147}
147 148
149static ssize_t show_def(struct device *class_dev,
150 struct device_attribute *attr,
151 char *buf)
152{
153 struct pvr2_sysfs_ctl_item *cip;
154 int val;
155 int ret;
156 cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_def);
157 ret = pvr2_ctrl_get_def(cip->cptr, &val);
158 pvr2_sysfs_trace("pvr2_sysfs(%p) show_def(cid=%d) is %d, stat=%d",
159 cip->chptr, cip->ctl_id, val, ret);
160 if (ret < 0) {
161 return ret;
162 }
163 return scnprintf(buf, PAGE_SIZE, "%d\n", val);
164}
165
148static ssize_t show_val_norm(struct device *class_dev, 166static ssize_t show_val_norm(struct device *class_dev,
149 struct device_attribute *attr, 167 struct device_attribute *attr,
150 char *buf) 168 char *buf)
@@ -320,6 +338,10 @@ static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
320 cip->attr_max.attr.mode = S_IRUGO; 338 cip->attr_max.attr.mode = S_IRUGO;
321 cip->attr_max.show = show_max; 339 cip->attr_max.show = show_max;
322 340
341 cip->attr_def.attr.name = "def_val";
342 cip->attr_def.attr.mode = S_IRUGO;
343 cip->attr_def.show = show_def;
344
323 cip->attr_val.attr.name = "cur_val"; 345 cip->attr_val.attr.name = "cur_val";
324 cip->attr_val.attr.mode = S_IRUGO; 346 cip->attr_val.attr.mode = S_IRUGO;
325 347
@@ -343,6 +365,7 @@ static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
343 cip->attr_gen[acnt++] = &cip->attr_name.attr; 365 cip->attr_gen[acnt++] = &cip->attr_name.attr;
344 cip->attr_gen[acnt++] = &cip->attr_type.attr; 366 cip->attr_gen[acnt++] = &cip->attr_type.attr;
345 cip->attr_gen[acnt++] = &cip->attr_val.attr; 367 cip->attr_gen[acnt++] = &cip->attr_val.attr;
368 cip->attr_gen[acnt++] = &cip->attr_def.attr;
346 cip->attr_val.show = show_val_norm; 369 cip->attr_val.show = show_val_norm;
347 cip->attr_val.store = store_val_norm; 370 cip->attr_val.store = store_val_norm;
348 if (pvr2_ctrl_has_custom_symbols(cptr)) { 371 if (pvr2_ctrl_has_custom_symbols(cptr)) {
diff --git a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
index 00306faeac01..f048d80b77e5 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
@@ -533,7 +533,7 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
533 533
534 lmin = pvr2_ctrl_get_min(hcp); 534 lmin = pvr2_ctrl_get_min(hcp);
535 lmax = pvr2_ctrl_get_max(hcp); 535 lmax = pvr2_ctrl_get_max(hcp);
536 ldef = pvr2_ctrl_get_def(hcp); 536 pvr2_ctrl_get_def(hcp, &ldef);
537 if (w == -1) { 537 if (w == -1) {
538 w = ldef; 538 w = ldef;
539 } else if (w < lmin) { 539 } else if (w < lmin) {
@@ -543,7 +543,7 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
543 } 543 }
544 lmin = pvr2_ctrl_get_min(vcp); 544 lmin = pvr2_ctrl_get_min(vcp);
545 lmax = pvr2_ctrl_get_max(vcp); 545 lmax = pvr2_ctrl_get_max(vcp);
546 ldef = pvr2_ctrl_get_def(vcp); 546 pvr2_ctrl_get_def(vcp, &ldef);
547 if (h == -1) { 547 if (h == -1) {
548 h = ldef; 548 h = ldef;
549 } else if (h < lmin) { 549 } else if (h < lmin) {
@@ -604,6 +604,7 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
604 case VIDIOC_QUERYCTRL: 604 case VIDIOC_QUERYCTRL:
605 { 605 {
606 struct pvr2_ctrl *cptr; 606 struct pvr2_ctrl *cptr;
607 int val;
607 struct v4l2_queryctrl *vc = (struct v4l2_queryctrl *)arg; 608 struct v4l2_queryctrl *vc = (struct v4l2_queryctrl *)arg;
608 ret = 0; 609 ret = 0;
609 if (vc->id & V4L2_CTRL_FLAG_NEXT_CTRL) { 610 if (vc->id & V4L2_CTRL_FLAG_NEXT_CTRL) {
@@ -627,7 +628,8 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
627 pvr2_ctrl_get_desc(cptr)); 628 pvr2_ctrl_get_desc(cptr));
628 strlcpy(vc->name,pvr2_ctrl_get_desc(cptr),sizeof(vc->name)); 629 strlcpy(vc->name,pvr2_ctrl_get_desc(cptr),sizeof(vc->name));
629 vc->flags = pvr2_ctrl_get_v4lflags(cptr); 630 vc->flags = pvr2_ctrl_get_v4lflags(cptr);
630 vc->default_value = pvr2_ctrl_get_def(cptr); 631 pvr2_ctrl_get_def(cptr, &val);
632 vc->default_value = val;
631 switch (pvr2_ctrl_get_type(cptr)) { 633 switch (pvr2_ctrl_get_type(cptr)) {
632 case pvr2_ctl_enum: 634 case pvr2_ctl_enum:
633 vc->type = V4L2_CTRL_TYPE_MENU; 635 vc->type = V4L2_CTRL_TYPE_MENU;
@@ -753,6 +755,92 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
753 break; 755 break;
754 } 756 }
755 757
758 case VIDIOC_CROPCAP:
759 {
760 struct v4l2_cropcap *cap = (struct v4l2_cropcap *)arg;
761 if (cap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
762 ret = -EINVAL;
763 break;
764 }
765 ret = pvr2_hdw_get_cropcap(hdw, cap);
766 cap->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; /* paranoia */
767 break;
768 }
769 case VIDIOC_G_CROP:
770 {
771 struct v4l2_crop *crop = (struct v4l2_crop *)arg;
772 int val = 0;
773 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
774 ret = -EINVAL;
775 break;
776 }
777 ret = pvr2_ctrl_get_value(
778 pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPL), &val);
779 if (ret != 0) {
780 ret = -EINVAL;
781 break;
782 }
783 crop->c.left = val;
784 ret = pvr2_ctrl_get_value(
785 pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPT), &val);
786 if (ret != 0) {
787 ret = -EINVAL;
788 break;
789 }
790 crop->c.top = val;
791 ret = pvr2_ctrl_get_value(
792 pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPW), &val);
793 if (ret != 0) {
794 ret = -EINVAL;
795 break;
796 }
797 crop->c.width = val;
798 ret = pvr2_ctrl_get_value(
799 pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPH), &val);
800 if (ret != 0) {
801 ret = -EINVAL;
802 break;
803 }
804 crop->c.height = val;
805 }
806 case VIDIOC_S_CROP:
807 {
808 struct v4l2_crop *crop = (struct v4l2_crop *)arg;
809 struct v4l2_cropcap cap;
810 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
811 ret = -EINVAL;
812 break;
813 }
814 cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
815 ret = pvr2_ctrl_set_value(
816 pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPL),
817 crop->c.left);
818 if (ret != 0) {
819 ret = -EINVAL;
820 break;
821 }
822 ret = pvr2_ctrl_set_value(
823 pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPT),
824 crop->c.top);
825 if (ret != 0) {
826 ret = -EINVAL;
827 break;
828 }
829 ret = pvr2_ctrl_set_value(
830 pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPW),
831 crop->c.width);
832 if (ret != 0) {
833 ret = -EINVAL;
834 break;
835 }
836 ret = pvr2_ctrl_set_value(
837 pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPH),
838 crop->c.height);
839 if (ret != 0) {
840 ret = -EINVAL;
841 break;
842 }
843 }
756 case VIDIOC_LOG_STATUS: 844 case VIDIOC_LOG_STATUS:
757 { 845 {
758 pvr2_hdw_trigger_module_log(hdw); 846 pvr2_hdw_trigger_module_log(hdw);
diff --git a/drivers/media/video/pwc/pwc-ctrl.c b/drivers/media/video/pwc/pwc-ctrl.c
index dbc560742553..c66530210192 100644
--- a/drivers/media/video/pwc/pwc-ctrl.c
+++ b/drivers/media/video/pwc/pwc-ctrl.c
@@ -41,7 +41,6 @@
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#include <linux/version.h>
45 44
46#include "pwc.h" 45#include "pwc.h"
47#include "pwc-uncompress.h" 46#include "pwc-uncompress.h"
diff --git a/drivers/media/video/pwc/pwc-if.c b/drivers/media/video/pwc/pwc-if.c
index 9aee7cb6f79a..ab28389b4cda 100644
--- a/drivers/media/video/pwc/pwc-if.c
+++ b/drivers/media/video/pwc/pwc-if.c
@@ -1112,7 +1112,7 @@ static int pwc_video_open(struct inode *inode, struct file *file)
1112 1112
1113 PWC_DEBUG_OPEN(">> video_open called(vdev = 0x%p).\n", vdev); 1113 PWC_DEBUG_OPEN(">> video_open called(vdev = 0x%p).\n", vdev);
1114 1114
1115 pdev = (struct pwc_device *)vdev->priv; 1115 pdev = video_get_drvdata(vdev);
1116 BUG_ON(!pdev); 1116 BUG_ON(!pdev);
1117 if (pdev->vopen) { 1117 if (pdev->vopen) {
1118 PWC_DEBUG_OPEN("I'm busy, someone is using the device.\n"); 1118 PWC_DEBUG_OPEN("I'm busy, someone is using the device.\n");
@@ -1233,7 +1233,7 @@ static int pwc_video_close(struct inode *inode, struct file *file)
1233 PWC_DEBUG_OPEN(">> video_close called(vdev = 0x%p).\n", vdev); 1233 PWC_DEBUG_OPEN(">> video_close called(vdev = 0x%p).\n", vdev);
1234 1234
1235 lock_kernel(); 1235 lock_kernel();
1236 pdev = (struct pwc_device *)vdev->priv; 1236 pdev = video_get_drvdata(vdev);
1237 if (pdev->vopen == 0) 1237 if (pdev->vopen == 0)
1238 PWC_DEBUG_MODULE("video_close() called on closed device?\n"); 1238 PWC_DEBUG_MODULE("video_close() called on closed device?\n");
1239 1239
@@ -1304,7 +1304,7 @@ static ssize_t pwc_video_read(struct file *file, char __user *buf,
1304 vdev, buf, count); 1304 vdev, buf, count);
1305 if (vdev == NULL) 1305 if (vdev == NULL)
1306 return -EFAULT; 1306 return -EFAULT;
1307 pdev = vdev->priv; 1307 pdev = video_get_drvdata(vdev);
1308 if (pdev == NULL) 1308 if (pdev == NULL)
1309 return -EFAULT; 1309 return -EFAULT;
1310 1310
@@ -1386,7 +1386,7 @@ static unsigned int pwc_video_poll(struct file *file, poll_table *wait)
1386 1386
1387 if (vdev == NULL) 1387 if (vdev == NULL)
1388 return -EFAULT; 1388 return -EFAULT;
1389 pdev = vdev->priv; 1389 pdev = video_get_drvdata(vdev);
1390 if (pdev == NULL) 1390 if (pdev == NULL)
1391 return -EFAULT; 1391 return -EFAULT;
1392 1392
@@ -1408,7 +1408,7 @@ static int pwc_video_ioctl(struct inode *inode, struct file *file,
1408 1408
1409 if (!vdev) 1409 if (!vdev)
1410 goto out; 1410 goto out;
1411 pdev = vdev->priv; 1411 pdev = video_get_drvdata(vdev);
1412 1412
1413 mutex_lock(&pdev->modlock); 1413 mutex_lock(&pdev->modlock);
1414 if (!pdev->unplugged) 1414 if (!pdev->unplugged)
@@ -1428,7 +1428,7 @@ static int pwc_video_mmap(struct file *file, struct vm_area_struct *vma)
1428 int index; 1428 int index;
1429 1429
1430 PWC_DEBUG_MEMORY(">> %s\n", __func__); 1430 PWC_DEBUG_MEMORY(">> %s\n", __func__);
1431 pdev = vdev->priv; 1431 pdev = video_get_drvdata(vdev);
1432 size = vma->vm_end - vma->vm_start; 1432 size = vma->vm_end - vma->vm_start;
1433 start = vma->vm_start; 1433 start = vma->vm_start;
1434 1434
diff --git a/drivers/media/video/pwc/pwc-v4l.c b/drivers/media/video/pwc/pwc-v4l.c
index 1742889874df..76a1376c9751 100644
--- a/drivers/media/video/pwc/pwc-v4l.c
+++ b/drivers/media/video/pwc/pwc-v4l.c
@@ -346,7 +346,7 @@ int pwc_video_do_ioctl(struct inode *inode, struct file *file,
346 346
347 if (vdev == NULL) 347 if (vdev == NULL)
348 return -EFAULT; 348 return -EFAULT;
349 pdev = vdev->priv; 349 pdev = video_get_drvdata(vdev);
350 if (pdev == NULL) 350 if (pdev == NULL)
351 return -EFAULT; 351 return -EFAULT;
352 352
diff --git a/drivers/media/video/pxa_camera.c b/drivers/media/video/pxa_camera.c
index cf96b2cc4f1c..eb6be5802928 100644
--- a/drivers/media/video/pxa_camera.c
+++ b/drivers/media/video/pxa_camera.c
@@ -629,17 +629,6 @@ static void pxa_camera_activate(struct pxa_camera_dev *pcdev)
629 pdata->init(pcdev->dev); 629 pdata->init(pcdev->dev);
630 } 630 }
631 631
632 if (pdata && pdata->power) {
633 dev_dbg(pcdev->dev, "%s: Power on camera\n", __func__);
634 pdata->power(pcdev->dev, 1);
635 }
636
637 if (pdata && pdata->reset) {
638 dev_dbg(pcdev->dev, "%s: Releasing camera reset\n",
639 __func__);
640 pdata->reset(pcdev->dev, 1);
641 }
642
643 CICR0 = 0x3FF; /* disable all interrupts */ 632 CICR0 = 0x3FF; /* disable all interrupts */
644 633
645 if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN) 634 if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN)
@@ -660,20 +649,7 @@ static void pxa_camera_activate(struct pxa_camera_dev *pcdev)
660 649
661static void pxa_camera_deactivate(struct pxa_camera_dev *pcdev) 650static void pxa_camera_deactivate(struct pxa_camera_dev *pcdev)
662{ 651{
663 struct pxacamera_platform_data *board = pcdev->pdata;
664
665 clk_disable(pcdev->clk); 652 clk_disable(pcdev->clk);
666
667 if (board && board->reset) {
668 dev_dbg(pcdev->dev, "%s: Asserting camera reset\n",
669 __func__);
670 board->reset(pcdev->dev, 0);
671 }
672
673 if (board && board->power) {
674 dev_dbg(pcdev->dev, "%s: Power off camera\n", __func__);
675 board->power(pcdev->dev, 0);
676 }
677} 653}
678 654
679static irqreturn_t pxa_camera_irq(int irq, void *data) 655static irqreturn_t pxa_camera_irq(int irq, void *data)
@@ -1144,31 +1120,31 @@ static int pxa_camera_probe(struct platform_device *pdev)
1144 pcdev->dev = &pdev->dev; 1120 pcdev->dev = &pdev->dev;
1145 1121
1146 /* request dma */ 1122 /* request dma */
1147 pcdev->dma_chans[0] = pxa_request_dma("CI_Y", DMA_PRIO_HIGH, 1123 err = pxa_request_dma("CI_Y", DMA_PRIO_HIGH,
1148 pxa_camera_dma_irq_y, pcdev); 1124 pxa_camera_dma_irq_y, pcdev);
1149 if (pcdev->dma_chans[0] < 0) { 1125 if (err < 0) {
1150 dev_err(pcdev->dev, "Can't request DMA for Y\n"); 1126 dev_err(pcdev->dev, "Can't request DMA for Y\n");
1151 err = -ENOMEM;
1152 goto exit_iounmap; 1127 goto exit_iounmap;
1153 } 1128 }
1129 pcdev->dma_chans[0] = err;
1154 dev_dbg(pcdev->dev, "got DMA channel %d\n", pcdev->dma_chans[0]); 1130 dev_dbg(pcdev->dev, "got DMA channel %d\n", pcdev->dma_chans[0]);
1155 1131
1156 pcdev->dma_chans[1] = pxa_request_dma("CI_U", DMA_PRIO_HIGH, 1132 err = pxa_request_dma("CI_U", DMA_PRIO_HIGH,
1157 pxa_camera_dma_irq_u, pcdev); 1133 pxa_camera_dma_irq_u, pcdev);
1158 if (pcdev->dma_chans[1] < 0) { 1134 if (err < 0) {
1159 dev_err(pcdev->dev, "Can't request DMA for U\n"); 1135 dev_err(pcdev->dev, "Can't request DMA for U\n");
1160 err = -ENOMEM;
1161 goto exit_free_dma_y; 1136 goto exit_free_dma_y;
1162 } 1137 }
1138 pcdev->dma_chans[1] = err;
1163 dev_dbg(pcdev->dev, "got DMA channel (U) %d\n", pcdev->dma_chans[1]); 1139 dev_dbg(pcdev->dev, "got DMA channel (U) %d\n", pcdev->dma_chans[1]);
1164 1140
1165 pcdev->dma_chans[2] = pxa_request_dma("CI_V", DMA_PRIO_HIGH, 1141 err = pxa_request_dma("CI_V", DMA_PRIO_HIGH,
1166 pxa_camera_dma_irq_v, pcdev); 1142 pxa_camera_dma_irq_v, pcdev);
1167 if (pcdev->dma_chans[0] < 0) { 1143 if (err < 0) {
1168 dev_err(pcdev->dev, "Can't request DMA for V\n"); 1144 dev_err(pcdev->dev, "Can't request DMA for V\n");
1169 err = -ENOMEM;
1170 goto exit_free_dma_u; 1145 goto exit_free_dma_u;
1171 } 1146 }
1147 pcdev->dma_chans[2] = err;
1172 dev_dbg(pcdev->dev, "got DMA channel (V) %d\n", pcdev->dma_chans[2]); 1148 dev_dbg(pcdev->dev, "got DMA channel (V) %d\n", pcdev->dma_chans[2]);
1173 1149
1174 DRCMR(68) = pcdev->dma_chans[0] | DRCMR_MAPVLD; 1150 DRCMR(68) = pcdev->dma_chans[0] | DRCMR_MAPVLD;
diff --git a/drivers/media/video/s2255drv.c b/drivers/media/video/s2255drv.c
index 92b83feae366..5272926db73e 100644
--- a/drivers/media/video/s2255drv.c
+++ b/drivers/media/video/s2255drv.c
@@ -58,6 +58,8 @@
58 58
59 59
60 60
61/* default JPEG quality */
62#define S2255_DEF_JPEG_QUAL 50
61/* vendor request in */ 63/* vendor request in */
62#define S2255_VR_IN 0 64#define S2255_VR_IN 0
63/* vendor request out */ 65/* vendor request out */
@@ -67,20 +69,21 @@
67/* USB endpoint number for configuring the device */ 69/* USB endpoint number for configuring the device */
68#define S2255_CONFIG_EP 2 70#define S2255_CONFIG_EP 2
69/* maximum time for DSP to start responding after last FW word loaded(ms) */ 71/* maximum time for DSP to start responding after last FW word loaded(ms) */
70#define S2255_DSP_BOOTTIME 400 72#define S2255_DSP_BOOTTIME 800
71/* maximum time to wait for firmware to load (ms) */ 73/* maximum time to wait for firmware to load (ms) */
72#define S2255_LOAD_TIMEOUT (5000 + S2255_DSP_BOOTTIME) 74#define S2255_LOAD_TIMEOUT (5000 + S2255_DSP_BOOTTIME)
73#define S2255_DEF_BUFS 16 75#define S2255_DEF_BUFS 16
76#define S2255_SETMODE_TIMEOUT 500
74#define MAX_CHANNELS 4 77#define MAX_CHANNELS 4
75#define FRAME_MARKER 0x2255DA4AL 78#define S2255_MARKER_FRAME 0x2255DA4AL
76#define MAX_PIPE_USBBLOCK (40 * 1024) 79#define S2255_MARKER_RESPONSE 0x2255ACACL
77#define DEFAULT_PIPE_USBBLOCK (16 * 1024) 80#define S2255_USB_XFER_SIZE (16 * 1024)
78#define MAX_CHANNELS 4 81#define MAX_CHANNELS 4
79#define MAX_PIPE_BUFFERS 1 82#define MAX_PIPE_BUFFERS 1
80#define SYS_FRAMES 4 83#define SYS_FRAMES 4
81/* maximum size is PAL full size plus room for the marker header(s) */ 84/* maximum size is PAL full size plus room for the marker header(s) */
82#define SYS_FRAMES_MAXSIZE (720 * 288 * 2 * 2 + 4096) 85#define SYS_FRAMES_MAXSIZE (720*288*2*2 + 4096)
83#define DEF_USB_BLOCK (4096) 86#define DEF_USB_BLOCK S2255_USB_XFER_SIZE
84#define LINE_SZ_4CIFS_NTSC 640 87#define LINE_SZ_4CIFS_NTSC 640
85#define LINE_SZ_2CIFS_NTSC 640 88#define LINE_SZ_2CIFS_NTSC 640
86#define LINE_SZ_1CIFS_NTSC 320 89#define LINE_SZ_1CIFS_NTSC 320
@@ -108,6 +111,9 @@
108#define COLOR_YUVPL 1 /* YUV planar */ 111#define COLOR_YUVPL 1 /* YUV planar */
109#define COLOR_YUVPK 2 /* YUV packed */ 112#define COLOR_YUVPK 2 /* YUV packed */
110#define COLOR_Y8 4 /* monochrome */ 113#define COLOR_Y8 4 /* monochrome */
114#define COLOR_JPG 5 /* JPEG */
115#define MASK_COLOR 0xff
116#define MASK_JPG_QUALITY 0xff00
111 117
112/* frame decimation. Not implemented by V4L yet(experimental in V4L) */ 118/* frame decimation. Not implemented by V4L yet(experimental in V4L) */
113#define FDEC_1 1 /* capture every frame. default */ 119#define FDEC_1 1 /* capture every frame. default */
@@ -148,16 +154,14 @@ struct s2255_mode {
148 u32 restart; /* if DSP requires restart */ 154 u32 restart; /* if DSP requires restart */
149}; 155};
150 156
151/* frame structure */
152#define FRAME_STATE_UNUSED 0
153#define FRAME_STATE_FILLING 1
154#define FRAME_STATE_FULL 2
155 157
158#define S2255_READ_IDLE 0
159#define S2255_READ_FRAME 1
156 160
161/* frame structure */
157struct s2255_framei { 162struct s2255_framei {
158 unsigned long size; 163 unsigned long size;
159 164 unsigned long ulState; /* ulState:S2255_READ_IDLE, S2255_READ_FRAME*/
160 unsigned long ulState; /* ulState ==0 unused, 1 being filled, 2 full */
161 void *lpvbits; /* image data */ 165 void *lpvbits; /* image data */
162 unsigned long cur_size; /* current data copied to it */ 166 unsigned long cur_size; /* current data copied to it */
163}; 167};
@@ -188,6 +192,10 @@ struct s2255_dmaqueue {
188#define S2255_FW_FAILED 3 192#define S2255_FW_FAILED 3
189#define S2255_FW_DISCONNECTING 4 193#define S2255_FW_DISCONNECTING 4
190 194
195#define S2255_FW_MARKER 0x22552f2f
196/* 2255 read states */
197#define S2255_READ_IDLE 0
198#define S2255_READ_FRAME 1
191struct s2255_fw { 199struct s2255_fw {
192 int fw_loaded; 200 int fw_loaded;
193 int fw_size; 201 int fw_size;
@@ -195,7 +203,6 @@ struct s2255_fw {
195 atomic_t fw_state; 203 atomic_t fw_state;
196 void *pfw_data; 204 void *pfw_data;
197 wait_queue_head_t wait_fw; 205 wait_queue_head_t wait_fw;
198 struct timer_list dsp_wait;
199 const struct firmware *fw; 206 const struct firmware *fw;
200}; 207};
201 208
@@ -237,15 +244,27 @@ struct s2255_dev {
237 struct s2255_pipeinfo pipes[MAX_PIPE_BUFFERS]; 244 struct s2255_pipeinfo pipes[MAX_PIPE_BUFFERS];
238 struct s2255_bufferi buffer[MAX_CHANNELS]; 245 struct s2255_bufferi buffer[MAX_CHANNELS];
239 struct s2255_mode mode[MAX_CHANNELS]; 246 struct s2255_mode mode[MAX_CHANNELS];
247 /* jpeg compression */
248 struct v4l2_jpegcompression jc[MAX_CHANNELS];
240 const struct s2255_fmt *cur_fmt[MAX_CHANNELS]; 249 const struct s2255_fmt *cur_fmt[MAX_CHANNELS];
241 int cur_frame[MAX_CHANNELS]; 250 int cur_frame[MAX_CHANNELS];
242 int last_frame[MAX_CHANNELS]; 251 int last_frame[MAX_CHANNELS];
243 u32 cc; /* current channel */ 252 u32 cc; /* current channel */
244 int b_acquire[MAX_CHANNELS]; 253 int b_acquire[MAX_CHANNELS];
254 /* allocated image size */
245 unsigned long req_image_size[MAX_CHANNELS]; 255 unsigned long req_image_size[MAX_CHANNELS];
256 /* received packet size */
257 unsigned long pkt_size[MAX_CHANNELS];
246 int bad_payload[MAX_CHANNELS]; 258 int bad_payload[MAX_CHANNELS];
247 unsigned long frame_count[MAX_CHANNELS]; 259 unsigned long frame_count[MAX_CHANNELS];
248 int frame_ready; 260 int frame_ready;
261 /* if JPEG image */
262 int jpg_size[MAX_CHANNELS];
263 /* if channel configured to default state */
264 int chn_configured[MAX_CHANNELS];
265 wait_queue_head_t wait_setmode[MAX_CHANNELS];
266 int setmode_ready[MAX_CHANNELS];
267 int chn_ready;
249 struct kref kref; 268 struct kref kref;
250 spinlock_t slock; 269 spinlock_t slock;
251}; 270};
@@ -306,12 +325,16 @@ static void s2255_stop_readpipe(struct s2255_dev *dev);
306static int s2255_start_acquire(struct s2255_dev *dev, unsigned long chn); 325static int s2255_start_acquire(struct s2255_dev *dev, unsigned long chn);
307static int s2255_stop_acquire(struct s2255_dev *dev, unsigned long chn); 326static int s2255_stop_acquire(struct s2255_dev *dev, unsigned long chn);
308static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf, 327static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf,
309 int chn); 328 int chn, int jpgsize);
310static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn, 329static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn,
311 struct s2255_mode *mode); 330 struct s2255_mode *mode);
312static int s2255_board_shutdown(struct s2255_dev *dev); 331static int s2255_board_shutdown(struct s2255_dev *dev);
313static void s2255_exit_v4l(struct s2255_dev *dev); 332static void s2255_exit_v4l(struct s2255_dev *dev);
314static void s2255_fwload_start(struct s2255_dev *dev); 333static void s2255_fwload_start(struct s2255_dev *dev, int reset);
334static void s2255_destroy(struct kref *kref);
335static long s2255_vendor_req(struct s2255_dev *dev, unsigned char req,
336 u16 index, u16 value, void *buf,
337 s32 buf_len, int bOut);
315 338
316#define dprintk(level, fmt, arg...) \ 339#define dprintk(level, fmt, arg...) \
317 do { \ 340 do { \
@@ -407,6 +430,10 @@ static const struct s2255_fmt formats[] = {
407 .fourcc = V4L2_PIX_FMT_UYVY, 430 .fourcc = V4L2_PIX_FMT_UYVY,
408 .depth = 16 431 .depth = 16
409 }, { 432 }, {
433 .name = "JPG",
434 .fourcc = V4L2_PIX_FMT_JPEG,
435 .depth = 24
436 }, {
410 .name = "8bpp GREY", 437 .name = "8bpp GREY",
411 .fourcc = V4L2_PIX_FMT_GREY, 438 .fourcc = V4L2_PIX_FMT_GREY,
412 .depth = 8 439 .depth = 8
@@ -464,6 +491,13 @@ static void planar422p_to_yuv_packed(const unsigned char *in,
464 return; 491 return;
465} 492}
466 493
494static void s2255_reset_dsppower(struct s2255_dev *dev)
495{
496 s2255_vendor_req(dev, 0x40, 0x0b0b, 0x0b0b, NULL, 0, 1);
497 msleep(10);
498 s2255_vendor_req(dev, 0x50, 0x0000, 0x0000, NULL, 0, 1);
499 return;
500}
467 501
468/* kickstarts the firmware loading. from probe 502/* kickstarts the firmware loading. from probe
469 */ 503 */
@@ -480,18 +514,6 @@ static void s2255_timer(unsigned long user_data)
480 } 514 }
481} 515}
482 516
483/* called when DSP is up and running. DSP is guaranteed to
484 be running after S2255_DSP_BOOTTIME */
485static void s2255_dsp_running(unsigned long user_data)
486{
487 struct s2255_fw *data = (struct s2255_fw *)user_data;
488 dprintk(1, "dsp running\n");
489 atomic_set(&data->fw_state, S2255_FW_SUCCESS);
490 wake_up(&data->wait_fw);
491 printk(KERN_INFO "s2255: firmware loaded successfully\n");
492 return;
493}
494
495 517
496/* this loads the firmware asynchronously. 518/* this loads the firmware asynchronously.
497 Originally this was done synchroously in probe. 519 Originally this was done synchroously in probe.
@@ -549,19 +571,14 @@ static void s2255_fwchunk_complete(struct urb *urb)
549 } 571 }
550 data->fw_loaded += len; 572 data->fw_loaded += len;
551 } else { 573 } else {
552 init_timer(&data->dsp_wait);
553 data->dsp_wait.function = s2255_dsp_running;
554 data->dsp_wait.data = (unsigned long)data;
555 atomic_set(&data->fw_state, S2255_FW_LOADED_DSPWAIT); 574 atomic_set(&data->fw_state, S2255_FW_LOADED_DSPWAIT);
556 mod_timer(&data->dsp_wait, msecs_to_jiffies(S2255_DSP_BOOTTIME)
557 + jiffies);
558 } 575 }
559 dprintk(100, "2255 complete done\n"); 576 dprintk(100, "2255 complete done\n");
560 return; 577 return;
561 578
562} 579}
563 580
564static int s2255_got_frame(struct s2255_dev *dev, int chn) 581static int s2255_got_frame(struct s2255_dev *dev, int chn, int jpgsize)
565{ 582{
566 struct s2255_dmaqueue *dma_q = &dev->vidq[chn]; 583 struct s2255_dmaqueue *dma_q = &dev->vidq[chn];
567 struct s2255_buffer *buf; 584 struct s2255_buffer *buf;
@@ -586,8 +603,7 @@ static int s2255_got_frame(struct s2255_dev *dev, int chn)
586 list_del(&buf->vb.queue); 603 list_del(&buf->vb.queue);
587 do_gettimeofday(&buf->vb.ts); 604 do_gettimeofday(&buf->vb.ts);
588 dprintk(100, "[%p/%d] wakeup\n", buf, buf->vb.i); 605 dprintk(100, "[%p/%d] wakeup\n", buf, buf->vb.i);
589 606 s2255_fillbuff(dev, buf, dma_q->channel, jpgsize);
590 s2255_fillbuff(dev, buf, dma_q->channel);
591 wake_up(&buf->vb.done); 607 wake_up(&buf->vb.done);
592 dprintk(2, "wakeup [buf/i] [%p/%d]\n", buf, buf->vb.i); 608 dprintk(2, "wakeup [buf/i] [%p/%d]\n", buf, buf->vb.i);
593unlock: 609unlock:
@@ -621,7 +637,7 @@ static const struct s2255_fmt *format_by_fourcc(int fourcc)
621 * 637 *
622 */ 638 */
623static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf, 639static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf,
624 int chn) 640 int chn, int jpgsize)
625{ 641{
626 int pos = 0; 642 int pos = 0;
627 struct timeval ts; 643 struct timeval ts;
@@ -649,6 +665,10 @@ static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf,
649 case V4L2_PIX_FMT_GREY: 665 case V4L2_PIX_FMT_GREY:
650 memcpy(vbuf, tmpbuf, buf->vb.width * buf->vb.height); 666 memcpy(vbuf, tmpbuf, buf->vb.width * buf->vb.height);
651 break; 667 break;
668 case V4L2_PIX_FMT_JPEG:
669 buf->vb.size = jpgsize;
670 memcpy(vbuf, tmpbuf, buf->vb.size);
671 break;
652 case V4L2_PIX_FMT_YUV422P: 672 case V4L2_PIX_FMT_YUV422P:
653 memcpy(vbuf, tmpbuf, 673 memcpy(vbuf, tmpbuf,
654 buf->vb.width * buf->vb.height * 2); 674 buf->vb.width * buf->vb.height * 2);
@@ -657,9 +677,6 @@ static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf,
657 printk(KERN_DEBUG "s2255: unknown format?\n"); 677 printk(KERN_DEBUG "s2255: unknown format?\n");
658 } 678 }
659 dev->last_frame[chn] = -1; 679 dev->last_frame[chn] = -1;
660 /* done with the frame, free it */
661 frm->ulState = 0;
662 dprintk(4, "freeing buffer\n");
663 } else { 680 } else {
664 printk(KERN_ERR "s2255: =======no frame\n"); 681 printk(KERN_ERR "s2255: =======no frame\n");
665 return; 682 return;
@@ -1021,6 +1038,10 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1021 case V4L2_PIX_FMT_GREY: 1038 case V4L2_PIX_FMT_GREY:
1022 fh->mode.color = COLOR_Y8; 1039 fh->mode.color = COLOR_Y8;
1023 break; 1040 break;
1041 case V4L2_PIX_FMT_JPEG:
1042 fh->mode.color = COLOR_JPG |
1043 (fh->dev->jc[fh->channel].quality << 8);
1044 break;
1024 case V4L2_PIX_FMT_YUV422P: 1045 case V4L2_PIX_FMT_YUV422P:
1025 fh->mode.color = COLOR_YUVPL; 1046 fh->mode.color = COLOR_YUVPL;
1026 break; 1047 break;
@@ -1139,7 +1160,7 @@ static u32 get_transfer_size(struct s2255_mode *mode)
1139 } 1160 }
1140 } 1161 }
1141 outImageSize = linesPerFrame * pixelsPerLine; 1162 outImageSize = linesPerFrame * pixelsPerLine;
1142 if (mode->color != COLOR_Y8) { 1163 if ((mode->color & MASK_COLOR) != COLOR_Y8) {
1143 /* 2 bytes/pixel if not monochrome */ 1164 /* 2 bytes/pixel if not monochrome */
1144 outImageSize *= 2; 1165 outImageSize *= 2;
1145 } 1166 }
@@ -1185,12 +1206,17 @@ static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn,
1185 u32 *buffer; 1206 u32 *buffer;
1186 unsigned long chn_rev; 1207 unsigned long chn_rev;
1187 1208
1209 mutex_lock(&dev->lock);
1188 chn_rev = G_chnmap[chn]; 1210 chn_rev = G_chnmap[chn];
1189 dprintk(3, "mode scale [%ld] %p %d\n", chn, mode, mode->scale); 1211 dprintk(3, "mode scale [%ld] %p %d\n", chn, mode, mode->scale);
1190 dprintk(3, "mode scale [%ld] %p %d\n", chn, &dev->mode[chn], 1212 dprintk(3, "mode scale [%ld] %p %d\n", chn, &dev->mode[chn],
1191 dev->mode[chn].scale); 1213 dev->mode[chn].scale);
1192 dprintk(2, "mode contrast %x\n", mode->contrast); 1214 dprintk(2, "mode contrast %x\n", mode->contrast);
1193 1215
1216 /* if JPEG, set the quality */
1217 if ((mode->color & MASK_COLOR) == COLOR_JPG)
1218 mode->color = (dev->jc[chn].quality << 8) | COLOR_JPG;
1219
1194 /* save the mode */ 1220 /* save the mode */
1195 dev->mode[chn] = *mode; 1221 dev->mode[chn] = *mode;
1196 dev->req_image_size[chn] = get_transfer_size(mode); 1222 dev->req_image_size[chn] = get_transfer_size(mode);
@@ -1199,6 +1225,7 @@ static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn,
1199 buffer = kzalloc(512, GFP_KERNEL); 1225 buffer = kzalloc(512, GFP_KERNEL);
1200 if (buffer == NULL) { 1226 if (buffer == NULL) {
1201 dev_err(&dev->udev->dev, "out of mem\n"); 1227 dev_err(&dev->udev->dev, "out of mem\n");
1228 mutex_unlock(&dev->lock);
1202 return -ENOMEM; 1229 return -ENOMEM;
1203 } 1230 }
1204 1231
@@ -1214,12 +1241,20 @@ static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn,
1214 dprintk(1, "set mode done chn %lu, %d\n", chn, res); 1241 dprintk(1, "set mode done chn %lu, %d\n", chn, res);
1215 1242
1216 /* wait at least 3 frames before continuing */ 1243 /* wait at least 3 frames before continuing */
1217 if (mode->restart) 1244 if (mode->restart) {
1218 msleep(125); 1245 dev->setmode_ready[chn] = 0;
1246 wait_event_timeout(dev->wait_setmode[chn],
1247 (dev->setmode_ready[chn] != 0),
1248 msecs_to_jiffies(S2255_SETMODE_TIMEOUT));
1249 if (dev->setmode_ready[chn] != 1) {
1250 printk(KERN_DEBUG "s2255: no set mode response\n");
1251 res = -EFAULT;
1252 }
1253 }
1219 1254
1220 /* clear the restart flag */ 1255 /* clear the restart flag */
1221 dev->mode[chn].restart = 0; 1256 dev->mode[chn].restart = 0;
1222 1257 mutex_unlock(&dev->lock);
1223 return res; 1258 return res;
1224} 1259}
1225 1260
@@ -1270,7 +1305,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
1270 dev->cur_frame[chn] = 0; 1305 dev->cur_frame[chn] = 0;
1271 dev->frame_count[chn] = 0; 1306 dev->frame_count[chn] = 0;
1272 for (j = 0; j < SYS_FRAMES; j++) { 1307 for (j = 0; j < SYS_FRAMES; j++) {
1273 dev->buffer[chn].frame[j].ulState = 0; 1308 dev->buffer[chn].frame[j].ulState = S2255_READ_IDLE;
1274 dev->buffer[chn].frame[j].cur_size = 0; 1309 dev->buffer[chn].frame[j].cur_size = 0;
1275 } 1310 }
1276 res = videobuf_streamon(&fh->vb_vidq); 1311 res = videobuf_streamon(&fh->vb_vidq);
@@ -1446,6 +1481,27 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
1446 return -EINVAL; 1481 return -EINVAL;
1447} 1482}
1448 1483
1484static int vidioc_g_jpegcomp(struct file *file, void *priv,
1485 struct v4l2_jpegcompression *jc)
1486{
1487 struct s2255_fh *fh = priv;
1488 struct s2255_dev *dev = fh->dev;
1489 *jc = dev->jc[fh->channel];
1490 dprintk(2, "getting jpegcompression, quality %d\n", jc->quality);
1491 return 0;
1492}
1493
1494static int vidioc_s_jpegcomp(struct file *file, void *priv,
1495 struct v4l2_jpegcompression *jc)
1496{
1497 struct s2255_fh *fh = priv;
1498 struct s2255_dev *dev = fh->dev;
1499 if (jc->quality < 0 || jc->quality > 100)
1500 return -EINVAL;
1501 dev->jc[fh->channel].quality = jc->quality;
1502 dprintk(2, "setting jpeg quality %d\n", jc->quality);
1503 return 0;
1504}
1449static int s2255_open(struct inode *inode, struct file *file) 1505static int s2255_open(struct inode *inode, struct file *file)
1450{ 1506{
1451 int minor = iminor(inode); 1507 int minor = iminor(inode);
@@ -1455,8 +1511,10 @@ static int s2255_open(struct inode *inode, struct file *file)
1455 enum v4l2_buf_type type = 0; 1511 enum v4l2_buf_type type = 0;
1456 int i = 0; 1512 int i = 0;
1457 int cur_channel = -1; 1513 int cur_channel = -1;
1514 int state;
1458 dprintk(1, "s2255: open called (minor=%d)\n", minor); 1515 dprintk(1, "s2255: open called (minor=%d)\n", minor);
1459 1516
1517 lock_kernel();
1460 list_for_each(list, &s2255_devlist) { 1518 list_for_each(list, &s2255_devlist) {
1461 h = list_entry(list, struct s2255_dev, s2255_devlist); 1519 h = list_entry(list, struct s2255_dev, s2255_devlist);
1462 for (i = 0; i < MAX_CHANNELS; i++) { 1520 for (i = 0; i < MAX_CHANNELS; i++) {
@@ -1469,45 +1527,78 @@ static int s2255_open(struct inode *inode, struct file *file)
1469 } 1527 }
1470 1528
1471 if ((NULL == dev) || (cur_channel == -1)) { 1529 if ((NULL == dev) || (cur_channel == -1)) {
1472 dprintk(1, "s2255: openv4l no dev\n"); 1530 unlock_kernel();
1531 printk(KERN_INFO "s2255: openv4l no dev\n");
1473 return -ENODEV; 1532 return -ENODEV;
1474 } 1533 }
1475 1534
1535 if (atomic_read(&dev->fw_data->fw_state) == S2255_FW_DISCONNECTING) {
1536 unlock_kernel();
1537 printk(KERN_INFO "disconnecting\n");
1538 return -ENODEV;
1539 }
1540 kref_get(&dev->kref);
1476 mutex_lock(&dev->open_lock); 1541 mutex_lock(&dev->open_lock);
1477 1542
1478 dev->users[cur_channel]++; 1543 dev->users[cur_channel]++;
1479 dprintk(4, "s2255: open_handles %d\n", dev->users[cur_channel]); 1544 dprintk(4, "s2255: open_handles %d\n", dev->users[cur_channel]);
1480 1545
1481 if (atomic_read(&dev->fw_data->fw_state) == S2255_FW_FAILED) { 1546 switch (atomic_read(&dev->fw_data->fw_state)) {
1547 case S2255_FW_FAILED:
1482 err("2255 firmware load failed. retrying.\n"); 1548 err("2255 firmware load failed. retrying.\n");
1483 s2255_fwload_start(dev); 1549 s2255_fwload_start(dev, 1);
1484 wait_event_timeout(dev->fw_data->wait_fw, 1550 wait_event_timeout(dev->fw_data->wait_fw,
1485 (atomic_read(&dev->fw_data->fw_state) 1551 ((atomic_read(&dev->fw_data->fw_state)
1486 != S2255_FW_NOTLOADED), 1552 == S2255_FW_SUCCESS) ||
1553 (atomic_read(&dev->fw_data->fw_state)
1554 == S2255_FW_DISCONNECTING)),
1487 msecs_to_jiffies(S2255_LOAD_TIMEOUT)); 1555 msecs_to_jiffies(S2255_LOAD_TIMEOUT));
1488 if (atomic_read(&dev->fw_data->fw_state) 1556 break;
1489 != S2255_FW_SUCCESS) { 1557 case S2255_FW_NOTLOADED:
1490 printk(KERN_INFO "2255 FW load failed.\n"); 1558 case S2255_FW_LOADED_DSPWAIT:
1491 dev->users[cur_channel]--;
1492 mutex_unlock(&dev->open_lock);
1493 return -EFAULT;
1494 }
1495 } else if (atomic_read(&dev->fw_data->fw_state) == S2255_FW_NOTLOADED) {
1496 /* give S2255_LOAD_TIMEOUT time for firmware to load in case 1559 /* give S2255_LOAD_TIMEOUT time for firmware to load in case
1497 driver loaded and then device immediately opened */ 1560 driver loaded and then device immediately opened */
1498 printk(KERN_INFO "%s waiting for firmware load\n", __func__); 1561 printk(KERN_INFO "%s waiting for firmware load\n", __func__);
1499 wait_event_timeout(dev->fw_data->wait_fw, 1562 wait_event_timeout(dev->fw_data->wait_fw,
1500 (atomic_read(&dev->fw_data->fw_state) 1563 ((atomic_read(&dev->fw_data->fw_state)
1501 != S2255_FW_NOTLOADED), 1564 == S2255_FW_SUCCESS) ||
1502 msecs_to_jiffies(S2255_LOAD_TIMEOUT)); 1565 (atomic_read(&dev->fw_data->fw_state)
1503 if (atomic_read(&dev->fw_data->fw_state) 1566 == S2255_FW_DISCONNECTING)),
1504 != S2255_FW_SUCCESS) { 1567 msecs_to_jiffies(S2255_LOAD_TIMEOUT));
1505 printk(KERN_INFO "2255 firmware not loaded" 1568 break;
1506 "try again\n"); 1569 case S2255_FW_SUCCESS:
1507 dev->users[cur_channel]--; 1570 default:
1508 mutex_unlock(&dev->open_lock); 1571 break;
1509 return -EBUSY; 1572 }
1573 state = atomic_read(&dev->fw_data->fw_state);
1574 if (state != S2255_FW_SUCCESS) {
1575 int rc;
1576 switch (state) {
1577 case S2255_FW_FAILED:
1578 printk(KERN_INFO "2255 FW load failed. %d\n", state);
1579 rc = -ENODEV;
1580 break;
1581 case S2255_FW_DISCONNECTING:
1582 printk(KERN_INFO "%s: disconnecting\n", __func__);
1583 rc = -ENODEV;
1584 break;
1585 case S2255_FW_LOADED_DSPWAIT:
1586 case S2255_FW_NOTLOADED:
1587 printk(KERN_INFO "%s: firmware not loaded yet"
1588 "please try again later\n",
1589 __func__);
1590 rc = -EAGAIN;
1591 break;
1592 default:
1593 printk(KERN_INFO "%s: unknown state\n", __func__);
1594 rc = -EFAULT;
1595 break;
1510 } 1596 }
1597 dev->users[cur_channel]--;
1598 mutex_unlock(&dev->open_lock);
1599 kref_put(&dev->kref, s2255_destroy);
1600 unlock_kernel();
1601 return rc;
1511 } 1602 }
1512 1603
1513 /* allocate + initialize per filehandle data */ 1604 /* allocate + initialize per filehandle data */
@@ -1515,6 +1606,8 @@ static int s2255_open(struct inode *inode, struct file *file)
1515 if (NULL == fh) { 1606 if (NULL == fh) {
1516 dev->users[cur_channel]--; 1607 dev->users[cur_channel]--;
1517 mutex_unlock(&dev->open_lock); 1608 mutex_unlock(&dev->open_lock);
1609 kref_put(&dev->kref, s2255_destroy);
1610 unlock_kernel();
1518 return -ENOMEM; 1611 return -ENOMEM;
1519 } 1612 }
1520 1613
@@ -1528,6 +1621,13 @@ static int s2255_open(struct inode *inode, struct file *file)
1528 fh->height = NUM_LINES_4CIFS_NTSC * 2; 1621 fh->height = NUM_LINES_4CIFS_NTSC * 2;
1529 fh->channel = cur_channel; 1622 fh->channel = cur_channel;
1530 1623
1624 /* configure channel to default state */
1625 if (!dev->chn_configured[cur_channel]) {
1626 s2255_set_mode(dev, cur_channel, &fh->mode);
1627 dev->chn_configured[cur_channel] = 1;
1628 }
1629
1630
1531 /* Put all controls at a sane state */ 1631 /* Put all controls at a sane state */
1532 for (i = 0; i < ARRAY_SIZE(s2255_qctrl); i++) 1632 for (i = 0; i < ARRAY_SIZE(s2255_qctrl); i++)
1533 qctl_regs[i] = s2255_qctrl[i].default_value; 1633 qctl_regs[i] = s2255_qctrl[i].default_value;
@@ -1546,8 +1646,8 @@ static int s2255_open(struct inode *inode, struct file *file)
1546 V4L2_FIELD_INTERLACED, 1646 V4L2_FIELD_INTERLACED,
1547 sizeof(struct s2255_buffer), fh); 1647 sizeof(struct s2255_buffer), fh);
1548 1648
1549 kref_get(&dev->kref);
1550 mutex_unlock(&dev->open_lock); 1649 mutex_unlock(&dev->open_lock);
1650 unlock_kernel();
1551 return 0; 1651 return 0;
1552} 1652}
1553 1653
@@ -1569,30 +1669,24 @@ static unsigned int s2255_poll(struct file *file,
1569static void s2255_destroy(struct kref *kref) 1669static void s2255_destroy(struct kref *kref)
1570{ 1670{
1571 struct s2255_dev *dev = to_s2255_dev(kref); 1671 struct s2255_dev *dev = to_s2255_dev(kref);
1672 struct list_head *list;
1673 int i;
1572 if (!dev) { 1674 if (!dev) {
1573 printk(KERN_ERR "s2255drv: kref problem\n"); 1675 printk(KERN_ERR "s2255drv: kref problem\n");
1574 return; 1676 return;
1575 } 1677 }
1576
1577 /*
1578 * Wake up any firmware load waiting (only done in .open,
1579 * which holds the open_lock mutex)
1580 */
1581 atomic_set(&dev->fw_data->fw_state, S2255_FW_DISCONNECTING); 1678 atomic_set(&dev->fw_data->fw_state, S2255_FW_DISCONNECTING);
1582 wake_up(&dev->fw_data->wait_fw); 1679 wake_up(&dev->fw_data->wait_fw);
1583 1680 for (i = 0; i < MAX_CHANNELS; i++) {
1584 /* prevent s2255_disconnect from racing s2255_open */ 1681 dev->setmode_ready[i] = 1;
1682 wake_up(&dev->wait_setmode[i]);
1683 }
1585 mutex_lock(&dev->open_lock); 1684 mutex_lock(&dev->open_lock);
1685 /* reset the DSP so firmware can be reload next time */
1686 s2255_reset_dsppower(dev);
1586 s2255_exit_v4l(dev); 1687 s2255_exit_v4l(dev);
1587 /*
1588 * device unregistered so no longer possible to open. open_mutex
1589 * can be unlocked and timers deleted afterwards.
1590 */
1591 mutex_unlock(&dev->open_lock);
1592
1593 /* board shutdown stops the read pipe if it is running */ 1688 /* board shutdown stops the read pipe if it is running */
1594 s2255_board_shutdown(dev); 1689 s2255_board_shutdown(dev);
1595
1596 /* make sure firmware still not trying to load */ 1690 /* make sure firmware still not trying to load */
1597 del_timer(&dev->timer); /* only started in .probe and .open */ 1691 del_timer(&dev->timer); /* only started in .probe and .open */
1598 1692
@@ -1602,23 +1696,19 @@ static void s2255_destroy(struct kref *kref)
1602 usb_free_urb(dev->fw_data->fw_urb); 1696 usb_free_urb(dev->fw_data->fw_urb);
1603 dev->fw_data->fw_urb = NULL; 1697 dev->fw_data->fw_urb = NULL;
1604 } 1698 }
1605
1606 /*
1607 * delete the dsp_wait timer, which sets the firmware
1608 * state on completion. This is done before fw_data
1609 * is freed below.
1610 */
1611
1612 del_timer(&dev->fw_data->dsp_wait); /* only started in .open */
1613
1614 if (dev->fw_data->fw) 1699 if (dev->fw_data->fw)
1615 release_firmware(dev->fw_data->fw); 1700 release_firmware(dev->fw_data->fw);
1616 kfree(dev->fw_data->pfw_data); 1701 kfree(dev->fw_data->pfw_data);
1617 kfree(dev->fw_data); 1702 kfree(dev->fw_data);
1618
1619 usb_put_dev(dev->udev); 1703 usb_put_dev(dev->udev);
1620 dprintk(1, "%s", __func__); 1704 dprintk(1, "%s", __func__);
1621 kfree(dev); 1705 kfree(dev);
1706
1707 while (!list_empty(&s2255_devlist)) {
1708 list = s2255_devlist.next;
1709 list_del(list);
1710 }
1711 mutex_unlock(&dev->open_lock);
1622} 1712}
1623 1713
1624static int s2255_close(struct inode *inode, struct file *file) 1714static int s2255_close(struct inode *inode, struct file *file)
@@ -1702,6 +1792,8 @@ static const struct v4l2_ioctl_ops s2255_ioctl_ops = {
1702#ifdef CONFIG_VIDEO_V4L1_COMPAT 1792#ifdef CONFIG_VIDEO_V4L1_COMPAT
1703 .vidiocgmbuf = vidioc_cgmbuf, 1793 .vidiocgmbuf = vidioc_cgmbuf,
1704#endif 1794#endif
1795 .vidioc_s_jpegcomp = vidioc_s_jpegcomp,
1796 .vidioc_g_jpegcomp = vidioc_g_jpegcomp,
1705}; 1797};
1706 1798
1707static struct video_device template = { 1799static struct video_device template = {
@@ -1740,7 +1832,7 @@ static int s2255_probe_v4l(struct s2255_dev *dev)
1740 ret = video_register_device(dev->vdev[i], 1832 ret = video_register_device(dev->vdev[i],
1741 VFL_TYPE_GRABBER, 1833 VFL_TYPE_GRABBER,
1742 cur_nr + i); 1834 cur_nr + i);
1743 dev->vdev[i]->priv = dev; 1835 video_set_drvdata(dev->vdev[i], dev);
1744 1836
1745 if (ret != 0) { 1837 if (ret != 0) {
1746 dev_err(&dev->udev->dev, 1838 dev_err(&dev->udev->dev,
@@ -1754,18 +1846,16 @@ static int s2255_probe_v4l(struct s2255_dev *dev)
1754 1846
1755static void s2255_exit_v4l(struct s2255_dev *dev) 1847static void s2255_exit_v4l(struct s2255_dev *dev)
1756{ 1848{
1757 struct list_head *list; 1849
1758 int i; 1850 int i;
1759 /* unregister the video devices */
1760 while (!list_empty(&s2255_devlist)) {
1761 list = s2255_devlist.next;
1762 list_del(list);
1763 }
1764 for (i = 0; i < MAX_CHANNELS; i++) { 1851 for (i = 0; i < MAX_CHANNELS; i++) {
1765 if (-1 != dev->vdev[i]->minor) 1852 if (-1 != dev->vdev[i]->minor) {
1766 video_unregister_device(dev->vdev[i]); 1853 video_unregister_device(dev->vdev[i]);
1767 else 1854 printk(KERN_INFO "s2255 unregistered\n");
1855 } else {
1768 video_device_release(dev->vdev[i]); 1856 video_device_release(dev->vdev[i]);
1857 printk(KERN_INFO "s2255 released\n");
1858 }
1769 } 1859 }
1770} 1860}
1771 1861
@@ -1775,134 +1865,123 @@ static void s2255_exit_v4l(struct s2255_dev *dev)
1775 * function again). 1865 * function again).
1776 * 1866 *
1777 * Received frame structure: 1867 * Received frame structure:
1778 * bytes 0-3: marker : 0x2255DA4AL (FRAME_MARKER) 1868 * bytes 0-3: marker : 0x2255DA4AL (S2255_MARKER_FRAME)
1779 * bytes 4-7: channel: 0-3 1869 * bytes 4-7: channel: 0-3
1780 * bytes 8-11: payload size: size of the frame 1870 * bytes 8-11: payload size: size of the frame
1781 * bytes 12-payloadsize+12: frame data 1871 * bytes 12-payloadsize+12: frame data
1782 */ 1872 */
1783static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info) 1873static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
1784{ 1874{
1785 static int dbgsync; /* = 0; */
1786 char *pdest; 1875 char *pdest;
1787 u32 offset = 0; 1876 u32 offset = 0;
1788 int bsync = 0; 1877 int bframe = 0;
1789 int btrunc = 0;
1790 char *psrc; 1878 char *psrc;
1791 unsigned long copy_size; 1879 unsigned long copy_size;
1792 unsigned long size; 1880 unsigned long size;
1793 s32 idx = -1; 1881 s32 idx = -1;
1794 struct s2255_framei *frm; 1882 struct s2255_framei *frm;
1795 unsigned char *pdata; 1883 unsigned char *pdata;
1796 unsigned long cur_size; 1884
1797 int bsearch = 0;
1798 struct s2255_bufferi *buf;
1799 dprintk(100, "buffer to user\n"); 1885 dprintk(100, "buffer to user\n");
1800 1886
1801 idx = dev->cur_frame[dev->cc]; 1887 idx = dev->cur_frame[dev->cc];
1802 buf = &dev->buffer[dev->cc]; 1888 frm = &dev->buffer[dev->cc].frame[idx];
1803 frm = &buf->frame[idx];
1804
1805 if (frm->ulState == 0) {
1806 frm->ulState = 1;
1807 frm->cur_size = 0;
1808 bsearch = 1;
1809 } else if (frm->ulState == 2) {
1810 /* system frame was not freed */
1811 dprintk(2, "sys frame not free. overrun ringbuf\n");
1812 bsearch = 1;
1813 frm->ulState = 1;
1814 frm->cur_size = 0;
1815 }
1816
1817 if (bsearch) {
1818 if (*(s32 *) pipe_info->transfer_buffer != FRAME_MARKER) {
1819 u32 jj;
1820 if (dbgsync == 0) {
1821 dprintk(3, "not synched, discarding all packets"
1822 "until marker\n");
1823 1889
1824 dbgsync++; 1890 if (frm->ulState == S2255_READ_IDLE) {
1825 } 1891 int jj;
1826 pdata = (unsigned char *)pipe_info->transfer_buffer; 1892 unsigned int cc;
1827 for (jj = 0; jj < (pipe_info->cur_transfer_size - 12); 1893 s32 *pdword;
1828 jj++) { 1894 int payload;
1829 if (*(s32 *) pdata == FRAME_MARKER) { 1895 /* search for marker codes */
1830 int cc; 1896 pdata = (unsigned char *)pipe_info->transfer_buffer;
1831 dprintk(3, 1897 for (jj = 0; jj < (pipe_info->cur_transfer_size - 12); jj++) {
1832 "found frame marker at offset:" 1898 switch (*(s32 *) pdata) {
1833 " %d [%x %x]\n", jj, pdata[0], 1899 case S2255_MARKER_FRAME:
1834 pdata[1]); 1900 pdword = (s32 *)pdata;
1835 offset = jj; 1901 dprintk(4, "found frame marker at offset:"
1836 bsync = 1; 1902 " %d [%x %x]\n", jj, pdata[0],
1837 cc = *(u32 *) (pdata + sizeof(u32)); 1903 pdata[1]);
1838 if (cc >= MAX_CHANNELS) { 1904 offset = jj + PREFIX_SIZE;
1839 printk(KERN_ERR 1905 bframe = 1;
1840 "bad channel\n"); 1906 cc = pdword[1];
1841 return -EINVAL; 1907 if (cc >= MAX_CHANNELS) {
1842 } 1908 printk(KERN_ERR
1843 /* reverse it */ 1909 "bad channel\n");
1844 dev->cc = G_chnmap[cc]; 1910 return -EINVAL;
1911 }
1912 /* reverse it */
1913 dev->cc = G_chnmap[cc];
1914 payload = pdword[3];
1915 if (payload > dev->req_image_size[dev->cc]) {
1916 dev->bad_payload[dev->cc]++;
1917 /* discard the bad frame */
1918 return -EINVAL;
1919 }
1920 dev->pkt_size[dev->cc] = payload;
1921 dev->jpg_size[dev->cc] = pdword[4];
1922 break;
1923 case S2255_MARKER_RESPONSE:
1924 pdword = (s32 *)pdata;
1925 pdata += DEF_USB_BLOCK;
1926 jj += DEF_USB_BLOCK;
1927 if (pdword[1] >= MAX_CHANNELS)
1928 break;
1929 cc = G_chnmap[pdword[1]];
1930 if (!(cc >= 0 && cc < MAX_CHANNELS))
1931 break;
1932 switch (pdword[2]) {
1933 case 0x01:
1934 /* check if channel valid */
1935 /* set mode ready */
1936 dev->setmode_ready[cc] = 1;
1937 wake_up(&dev->wait_setmode[cc]);
1938 dprintk(5, "setmode ready %d\n", cc);
1845 break; 1939 break;
1940 case 0x10:
1941
1942 dev->chn_ready |= (1 << cc);
1943 if ((dev->chn_ready & 0x0f) != 0x0f)
1944 break;
1945 /* all channels ready */
1946 printk(KERN_INFO "s2255: fw loaded\n");
1947 atomic_set(&dev->fw_data->fw_state,
1948 S2255_FW_SUCCESS);
1949 wake_up(&dev->fw_data->wait_fw);
1950 break;
1951 default:
1952 printk(KERN_INFO "s2255 unknwn resp\n");
1846 } 1953 }
1954 default:
1847 pdata++; 1955 pdata++;
1956 break;
1848 } 1957 }
1849 if (bsync == 0) 1958 if (bframe)
1850 return -EINVAL; 1959 break;
1851 } else { 1960 } /* for */
1852 u32 *pword; 1961 if (!bframe)
1853 u32 payload; 1962 return -EINVAL;
1854 int cc;
1855 dbgsync = 0;
1856 bsync = 1;
1857 pword = (u32 *) pipe_info->transfer_buffer;
1858 cc = pword[1];
1859
1860 if (cc >= MAX_CHANNELS) {
1861 printk("invalid channel found. "
1862 "throwing out data!\n");
1863 return -EINVAL;
1864 }
1865 dev->cc = G_chnmap[cc];
1866 payload = pword[2];
1867 if (payload != dev->req_image_size[dev->cc]) {
1868 dprintk(1, "[%d][%d]unexpected payload: %d"
1869 "required: %lu \n", cc, dev->cc,
1870 payload, dev->req_image_size[dev->cc]);
1871 dev->bad_payload[dev->cc]++;
1872 /* discard the bad frame */
1873 return -EINVAL;
1874 }
1875
1876 }
1877 }
1878 /* search done. now find out if should be acquiring
1879 on this channel */
1880 if (!dev->b_acquire[dev->cc]) {
1881 frm->ulState = 0;
1882 return -EINVAL;
1883 } 1963 }
1884 1964
1965
1885 idx = dev->cur_frame[dev->cc]; 1966 idx = dev->cur_frame[dev->cc];
1886 frm = &dev->buffer[dev->cc].frame[idx]; 1967 frm = &dev->buffer[dev->cc].frame[idx];
1887 1968
1888 if (frm->ulState == 0) { 1969 /* search done. now find out if should be acquiring on this channel */
1889 frm->ulState = 1; 1970 if (!dev->b_acquire[dev->cc]) {
1890 frm->cur_size = 0; 1971 /* we found a frame, but this channel is turned off */
1891 } else if (frm->ulState == 2) { 1972 frm->ulState = S2255_READ_IDLE;
1892 /* system frame ring buffer overrun */ 1973 return -EINVAL;
1893 dprintk(2, "sys frame overrun. overwriting frame %d %d\n",
1894 dev->cc, idx);
1895 frm->ulState = 1;
1896 frm->cur_size = 0;
1897 } 1974 }
1898 1975
1899 if (bsync) { 1976 if (frm->ulState == S2255_READ_IDLE) {
1900 /* skip the marker 512 bytes (and offset if out of sync) */ 1977 frm->ulState = S2255_READ_FRAME;
1901 psrc = (u8 *)pipe_info->transfer_buffer + offset + PREFIX_SIZE; 1978 frm->cur_size = 0;
1902 } else {
1903 psrc = (u8 *)pipe_info->transfer_buffer;
1904 } 1979 }
1905 1980
1981 /* skip the marker 512 bytes (and offset if out of sync) */
1982 psrc = (u8 *)pipe_info->transfer_buffer + offset;
1983
1984
1906 if (frm->lpvbits == NULL) { 1985 if (frm->lpvbits == NULL) {
1907 dprintk(1, "s2255 frame buffer == NULL.%p %p %d %d", 1986 dprintk(1, "s2255 frame buffer == NULL.%p %p %d %d",
1908 frm, dev, dev->cc, idx); 1987 frm, dev, dev->cc, idx);
@@ -1911,33 +1990,20 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
1911 1990
1912 pdest = frm->lpvbits + frm->cur_size; 1991 pdest = frm->lpvbits + frm->cur_size;
1913 1992
1914 if (bsync) { 1993 copy_size = (pipe_info->cur_transfer_size - offset);
1915 copy_size =
1916 (pipe_info->cur_transfer_size - offset) - PREFIX_SIZE;
1917 if (copy_size > pipe_info->cur_transfer_size) {
1918 printk("invalid copy size, overflow!\n");
1919 return -ENOMEM;
1920 }
1921 } else {
1922 copy_size = pipe_info->cur_transfer_size;
1923 }
1924 1994
1925 cur_size = frm->cur_size; 1995 size = dev->pkt_size[dev->cc] - PREFIX_SIZE;
1926 size = dev->req_image_size[dev->cc];
1927 1996
1928 if ((copy_size + cur_size) > size) { 1997 /* sanity check on pdest */
1929 copy_size = size - cur_size; 1998 if ((copy_size + frm->cur_size) < dev->req_image_size[dev->cc])
1930 btrunc = 1; 1999 memcpy(pdest, psrc, copy_size);
1931 }
1932 2000
1933 memcpy(pdest, psrc, copy_size);
1934 cur_size += copy_size;
1935 frm->cur_size += copy_size; 2001 frm->cur_size += copy_size;
1936 dprintk(50, "cur_size size %lu size %lu \n", cur_size, size); 2002 dprintk(4, "cur_size size %lu size %lu \n", frm->cur_size, size);
2003
2004 if (frm->cur_size >= size) {
1937 2005
1938 if (cur_size >= (size - PREFIX_SIZE)) {
1939 u32 cc = dev->cc; 2006 u32 cc = dev->cc;
1940 frm->ulState = 2;
1941 dprintk(2, "****************[%d]Buffer[%d]full*************\n", 2007 dprintk(2, "****************[%d]Buffer[%d]full*************\n",
1942 cc, idx); 2008 cc, idx);
1943 dev->last_frame[cc] = dev->cur_frame[cc]; 2009 dev->last_frame[cc] = dev->cur_frame[cc];
@@ -1946,16 +2012,13 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
1946 if ((dev->cur_frame[cc] == SYS_FRAMES) || 2012 if ((dev->cur_frame[cc] == SYS_FRAMES) ||
1947 (dev->cur_frame[cc] == dev->buffer[cc].dwFrames)) 2013 (dev->cur_frame[cc] == dev->buffer[cc].dwFrames))
1948 dev->cur_frame[cc] = 0; 2014 dev->cur_frame[cc] = 0;
1949 2015 /* frame ready */
1950 /* signal the semaphore for this channel */
1951 if (dev->b_acquire[cc]) 2016 if (dev->b_acquire[cc])
1952 s2255_got_frame(dev, cc); 2017 s2255_got_frame(dev, cc, dev->jpg_size[cc]);
1953 dev->frame_count[cc]++; 2018 dev->frame_count[cc]++;
1954 } 2019 frm->ulState = S2255_READ_IDLE;
1955 /* frame was truncated */ 2020 frm->cur_size = 0;
1956 if (btrunc) { 2021
1957 /* return more data to process */
1958 return EAGAIN;
1959 } 2022 }
1960 /* done successfully */ 2023 /* done successfully */
1961 return 0; 2024 return 0;
@@ -1974,8 +2037,8 @@ static void s2255_read_video_callback(struct s2255_dev *dev,
1974 } 2037 }
1975 /* otherwise copy to the system buffers */ 2038 /* otherwise copy to the system buffers */
1976 res = save_frame(dev, pipe_info); 2039 res = save_frame(dev, pipe_info);
1977 if (res == EAGAIN) 2040 if (res != 0)
1978 save_frame(dev, pipe_info); 2041 dprintk(4, "s2255: read callback failed\n");
1979 2042
1980 dprintk(50, "callback read video done\n"); 2043 dprintk(50, "callback read video done\n");
1981 return; 2044 return;
@@ -2095,11 +2158,9 @@ static int s2255_board_init(struct s2255_dev *dev)
2095 2158
2096 memset(pipe, 0, sizeof(*pipe)); 2159 memset(pipe, 0, sizeof(*pipe));
2097 pipe->dev = dev; 2160 pipe->dev = dev;
2098 pipe->cur_transfer_size = DEFAULT_PIPE_USBBLOCK; 2161 pipe->cur_transfer_size = S2255_USB_XFER_SIZE;
2099 pipe->max_transfer_size = MAX_PIPE_USBBLOCK; 2162 pipe->max_transfer_size = S2255_USB_XFER_SIZE;
2100 2163
2101 if (pipe->cur_transfer_size > pipe->max_transfer_size)
2102 pipe->cur_transfer_size = pipe->max_transfer_size;
2103 pipe->transfer_buffer = kzalloc(pipe->max_transfer_size, 2164 pipe->transfer_buffer = kzalloc(pipe->max_transfer_size,
2104 GFP_KERNEL); 2165 GFP_KERNEL);
2105 if (pipe->transfer_buffer == NULL) { 2166 if (pipe->transfer_buffer == NULL) {
@@ -2119,6 +2180,7 @@ static int s2255_board_init(struct s2255_dev *dev)
2119 for (j = 0; j < MAX_CHANNELS; j++) { 2180 for (j = 0; j < MAX_CHANNELS; j++) {
2120 dev->b_acquire[j] = 0; 2181 dev->b_acquire[j] = 0;
2121 dev->mode[j] = mode_def; 2182 dev->mode[j] = mode_def;
2183 dev->jc[j].quality = S2255_DEF_JPEG_QUAL;
2122 dev->cur_fmt[j] = &formats[0]; 2184 dev->cur_fmt[j] = &formats[0];
2123 dev->mode[j].restart = 1; 2185 dev->mode[j].restart = 1;
2124 dev->req_image_size[j] = get_transfer_size(&mode_def); 2186 dev->req_image_size[j] = get_transfer_size(&mode_def);
@@ -2323,7 +2385,7 @@ static int s2255_stop_acquire(struct s2255_dev *dev, unsigned long chn)
2323 kfree(buffer); 2385 kfree(buffer);
2324 dev->b_acquire[chn] = 0; 2386 dev->b_acquire[chn] = 0;
2325 2387
2326 return 0; 2388 return res;
2327} 2389}
2328 2390
2329static void s2255_stop_readpipe(struct s2255_dev *dev) 2391static void s2255_stop_readpipe(struct s2255_dev *dev)
@@ -2359,8 +2421,10 @@ static void s2255_stop_readpipe(struct s2255_dev *dev)
2359 return; 2421 return;
2360} 2422}
2361 2423
2362static void s2255_fwload_start(struct s2255_dev *dev) 2424static void s2255_fwload_start(struct s2255_dev *dev, int reset)
2363{ 2425{
2426 if (reset)
2427 s2255_reset_dsppower(dev);
2364 dev->fw_data->fw_size = dev->fw_data->fw->size; 2428 dev->fw_data->fw_size = dev->fw_data->fw->size;
2365 atomic_set(&dev->fw_data->fw_state, S2255_FW_NOTLOADED); 2429 atomic_set(&dev->fw_data->fw_state, S2255_FW_NOTLOADED);
2366 memcpy(dev->fw_data->pfw_data, 2430 memcpy(dev->fw_data->pfw_data,
@@ -2383,6 +2447,8 @@ static int s2255_probe(struct usb_interface *interface,
2383 struct usb_endpoint_descriptor *endpoint; 2447 struct usb_endpoint_descriptor *endpoint;
2384 int i; 2448 int i;
2385 int retval = -ENOMEM; 2449 int retval = -ENOMEM;
2450 __le32 *pdata;
2451 int fw_size;
2386 2452
2387 dprintk(2, "s2255: probe\n"); 2453 dprintk(2, "s2255: probe\n");
2388 2454
@@ -2437,6 +2503,8 @@ static int s2255_probe(struct usb_interface *interface,
2437 dev->timer.data = (unsigned long)dev->fw_data; 2503 dev->timer.data = (unsigned long)dev->fw_data;
2438 2504
2439 init_waitqueue_head(&dev->fw_data->wait_fw); 2505 init_waitqueue_head(&dev->fw_data->wait_fw);
2506 for (i = 0; i < MAX_CHANNELS; i++)
2507 init_waitqueue_head(&dev->wait_setmode[i]);
2440 2508
2441 2509
2442 dev->fw_data->fw_urb = usb_alloc_urb(0, GFP_KERNEL); 2510 dev->fw_data->fw_urb = usb_alloc_urb(0, GFP_KERNEL);
@@ -2456,16 +2524,30 @@ static int s2255_probe(struct usb_interface *interface,
2456 printk(KERN_ERR "sensoray 2255 failed to get firmware\n"); 2524 printk(KERN_ERR "sensoray 2255 failed to get firmware\n");
2457 goto error; 2525 goto error;
2458 } 2526 }
2527 /* check the firmware is valid */
2528 fw_size = dev->fw_data->fw->size;
2529 pdata = (__le32 *) &dev->fw_data->fw->data[fw_size - 8];
2459 2530
2531 if (*pdata != S2255_FW_MARKER) {
2532 printk(KERN_INFO "Firmware invalid.\n");
2533 retval = -ENODEV;
2534 goto error;
2535 } else {
2536 /* make sure firmware is the latest */
2537 __le32 *pRel;
2538 pRel = (__le32 *) &dev->fw_data->fw->data[fw_size - 4];
2539 printk(KERN_INFO "s2255 dsp fw version %x\n", *pRel);
2540 }
2460 /* loads v4l specific */ 2541 /* loads v4l specific */
2461 s2255_probe_v4l(dev); 2542 s2255_probe_v4l(dev);
2543 usb_reset_device(dev->udev);
2462 /* load 2255 board specific */ 2544 /* load 2255 board specific */
2463 s2255_board_init(dev); 2545 s2255_board_init(dev);
2464 2546
2465 dprintk(4, "before probe done %p\n", dev); 2547 dprintk(4, "before probe done %p\n", dev);
2466 spin_lock_init(&dev->slock); 2548 spin_lock_init(&dev->slock);
2467 2549
2468 s2255_fwload_start(dev); 2550 s2255_fwload_start(dev, 0);
2469 dev_info(&interface->dev, "Sensoray 2255 detected\n"); 2551 dev_info(&interface->dev, "Sensoray 2255 detected\n");
2470 return 0; 2552 return 0;
2471error: 2553error:
@@ -2476,14 +2558,30 @@ error:
2476static void s2255_disconnect(struct usb_interface *interface) 2558static void s2255_disconnect(struct usb_interface *interface)
2477{ 2559{
2478 struct s2255_dev *dev = NULL; 2560 struct s2255_dev *dev = NULL;
2561 int i;
2479 dprintk(1, "s2255: disconnect interface %p\n", interface); 2562 dprintk(1, "s2255: disconnect interface %p\n", interface);
2480 dev = usb_get_intfdata(interface); 2563 dev = usb_get_intfdata(interface);
2564
2565 /*
2566 * wake up any of the timers to allow open_lock to be
2567 * acquired sooner
2568 */
2569 atomic_set(&dev->fw_data->fw_state, S2255_FW_DISCONNECTING);
2570 wake_up(&dev->fw_data->wait_fw);
2571 for (i = 0; i < MAX_CHANNELS; i++) {
2572 dev->setmode_ready[i] = 1;
2573 wake_up(&dev->wait_setmode[i]);
2574 }
2575
2576 mutex_lock(&dev->open_lock);
2577 usb_set_intfdata(interface, NULL);
2578 mutex_unlock(&dev->open_lock);
2579
2481 if (dev) { 2580 if (dev) {
2482 kref_put(&dev->kref, s2255_destroy); 2581 kref_put(&dev->kref, s2255_destroy);
2483 dprintk(1, "s2255drv: disconnect\n"); 2582 dprintk(1, "s2255drv: disconnect\n");
2484 dev_info(&interface->dev, "s2255usb now disconnected\n"); 2583 dev_info(&interface->dev, "s2255usb now disconnected\n");
2485 } 2584 }
2486 usb_set_intfdata(interface, NULL);
2487} 2585}
2488 2586
2489static struct usb_driver s2255_driver = { 2587static struct usb_driver s2255_driver = {
diff --git a/drivers/media/video/saa5246a.c b/drivers/media/video/saa5246a.c
index 6ee63e69b36c..4a21b8a6a709 100644
--- a/drivers/media/video/saa5246a.c
+++ b/drivers/media/video/saa5246a.c
@@ -43,135 +43,363 @@
43#include <linux/mm.h> 43#include <linux/mm.h>
44#include <linux/init.h> 44#include <linux/init.h>
45#include <linux/i2c.h> 45#include <linux/i2c.h>
46#include <linux/smp_lock.h>
47#include <linux/mutex.h>
46#include <linux/videotext.h> 48#include <linux/videotext.h>
47#include <linux/videodev.h> 49#include <linux/videodev.h>
48#include <media/v4l2-common.h> 50#include <media/v4l2-common.h>
49#include <media/v4l2-ioctl.h> 51#include <media/v4l2-ioctl.h>
50#include <linux/mutex.h> 52#include <media/v4l2-i2c-drv-legacy.h>
51
52#include "saa5246a.h"
53 53
54MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>"); 54MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>");
55MODULE_DESCRIPTION("Philips SAA5246A, SAA5281 Teletext decoder driver"); 55MODULE_DESCRIPTION("Philips SAA5246A, SAA5281 Teletext decoder driver");
56MODULE_LICENSE("GPL"); 56MODULE_LICENSE("GPL");
57 57
58struct saa5246a_device 58#define MAJOR_VERSION 1 /* driver major version number */
59{ 59#define MINOR_VERSION 8 /* driver minor version number */
60 u8 pgbuf[NUM_DAUS][VTX_VIRTUALSIZE]; 60
61 int is_searching[NUM_DAUS]; 61/* Number of DAUs = number of pages that can be searched at the same time. */
62 struct i2c_client *client; 62#define NUM_DAUS 4
63 struct mutex lock; 63
64}; 64#define NUM_ROWS_PER_PAGE 40
65
66/* first column is 0 (not 1) */
67#define POS_TIME_START 32
68#define POS_TIME_END 39
69
70#define POS_HEADER_START 7
71#define POS_HEADER_END 31
72
73/* Returns 'true' if the part of the videotext page described with req contains
74 (at least parts of) the time field */
75#define REQ_CONTAINS_TIME(p_req) \
76 ((p_req)->start <= POS_TIME_END && \
77 (p_req)->end >= POS_TIME_START)
78
79/* Returns 'true' if the part of the videotext page described with req contains
80 (at least parts of) the page header */
81#define REQ_CONTAINS_HEADER(p_req) \
82 ((p_req)->start <= POS_HEADER_END && \
83 (p_req)->end >= POS_HEADER_START)
84
85/*****************************************************************************/
86/* Mode register numbers of the SAA5246A */
87/*****************************************************************************/
88#define SAA5246A_REGISTER_R0 0
89#define SAA5246A_REGISTER_R1 1
90#define SAA5246A_REGISTER_R2 2
91#define SAA5246A_REGISTER_R3 3
92#define SAA5246A_REGISTER_R4 4
93#define SAA5246A_REGISTER_R5 5
94#define SAA5246A_REGISTER_R6 6
95#define SAA5246A_REGISTER_R7 7
96#define SAA5246A_REGISTER_R8 8
97#define SAA5246A_REGISTER_R9 9
98#define SAA5246A_REGISTER_R10 10
99#define SAA5246A_REGISTER_R11 11
100#define SAA5246A_REGISTER_R11B 11
101
102/* SAA5246A mode registers often autoincrement to the next register.
103 Therefore we use variable argument lists. The following macro indicates
104 the end of a command list. */
105#define COMMAND_END (-1)
106
107/*****************************************************************************/
108/* Contents of the mode registers of the SAA5246A */
109/*****************************************************************************/
110/* Register R0 (Advanced Control) */
111#define R0_SELECT_R11 0x00
112#define R0_SELECT_R11B 0x01
113
114#define R0_PLL_TIME_CONSTANT_LONG 0x00
115#define R0_PLL_TIME_CONSTANT_SHORT 0x02
116
117#define R0_ENABLE_nODD_EVEN_OUTPUT 0x00
118#define R0_DISABLE_nODD_EVEN_OUTPUT 0x04
119
120#define R0_ENABLE_HDR_POLL 0x00
121#define R0_DISABLE_HDR_POLL 0x10
122
123#define R0_DO_NOT_FORCE_nODD_EVEN_LOW_IF_PICTURE_DISPLAYED 0x00
124#define R0_FORCE_nODD_EVEN_LOW_IF_PICTURE_DISPLAYED 0x20
125
126#define R0_NO_FREE_RUN_PLL 0x00
127#define R0_FREE_RUN_PLL 0x40
128
129#define R0_NO_AUTOMATIC_FASTEXT_PROMPT 0x00
130#define R0_AUTOMATIC_FASTEXT_PROMPT 0x80
131
132/* Register R1 (Mode) */
133#define R1_INTERLACED_312_AND_HALF_312_AND_HALF_LINES 0x00
134#define R1_NON_INTERLACED_312_313_LINES 0x01
135#define R1_NON_INTERLACED_312_312_LINES 0x02
136#define R1_FFB_LEADING_EDGE_IN_FIRST_BROAD_PULSE 0x03
137#define R1_FFB_LEADING_EDGE_IN_SECOND_BROAD_PULSE 0x07
138
139#define R1_DEW 0x00
140#define R1_FULL_FIELD 0x08
141
142#define R1_EXTENDED_PACKET_DISABLE 0x00
143#define R1_EXTENDED_PACKET_ENABLE 0x10
144
145#define R1_DAUS_ALL_ON 0x00
146#define R1_DAUS_ALL_OFF 0x20
147
148#define R1_7_BITS_PLUS_PARITY 0x00
149#define R1_8_BITS_NO_PARITY 0x40
150
151#define R1_VCS_TO_SCS 0x00
152#define R1_NO_VCS_TO_SCS 0x80
153
154/* Register R2 (Page request address) */
155#define R2_IN_R3_SELECT_PAGE_HUNDREDS 0x00
156#define R2_IN_R3_SELECT_PAGE_TENS 0x01
157#define R2_IN_R3_SELECT_PAGE_UNITS 0x02
158#define R2_IN_R3_SELECT_HOURS_TENS 0x03
159#define R2_IN_R3_SELECT_HOURS_UNITS 0x04
160#define R2_IN_R3_SELECT_MINUTES_TENS 0x05
161#define R2_IN_R3_SELECT_MINUTES_UNITS 0x06
162
163#define R2_DAU_0 0x00
164#define R2_DAU_1 0x10
165#define R2_DAU_2 0x20
166#define R2_DAU_3 0x30
167
168#define R2_BANK_0 0x00
169#define R2_BANK 1 0x40
170
171#define R2_HAMMING_CHECK_ON 0x80
172#define R2_HAMMING_CHECK_OFF 0x00
173
174/* Register R3 (Page request data) */
175#define R3_PAGE_HUNDREDS_0 0x00
176#define R3_PAGE_HUNDREDS_1 0x01
177#define R3_PAGE_HUNDREDS_2 0x02
178#define R3_PAGE_HUNDREDS_3 0x03
179#define R3_PAGE_HUNDREDS_4 0x04
180#define R3_PAGE_HUNDREDS_5 0x05
181#define R3_PAGE_HUNDREDS_6 0x06
182#define R3_PAGE_HUNDREDS_7 0x07
65 183
66static struct video_device saa_template; /* Declared near bottom */ 184#define R3_HOLD_PAGE 0x00
185#define R3_UPDATE_PAGE 0x08
67 186
68/* Addresses to scan */ 187#define R3_PAGE_HUNDREDS_DO_NOT_CARE 0x00
69static unsigned short normal_i2c[] = { I2C_ADDRESS, I2C_CLIENT_END }; 188#define R3_PAGE_HUNDREDS_DO_CARE 0x10
70 189
71I2C_CLIENT_INSMOD; 190#define R3_PAGE_TENS_DO_NOT_CARE 0x00
191#define R3_PAGE_TENS_DO_CARE 0x10
72 192
73static struct i2c_client client_template; 193#define R3_PAGE_UNITS_DO_NOT_CARE 0x00
194#define R3_PAGE_UNITS_DO_CARE 0x10
74 195
75static int saa5246a_attach(struct i2c_adapter *adap, int addr, int kind) 196#define R3_HOURS_TENS_DO_NOT_CARE 0x00
76{ 197#define R3_HOURS_TENS_DO_CARE 0x10
77 int pgbuf;
78 int err;
79 struct i2c_client *client;
80 struct video_device *vd;
81 struct saa5246a_device *t;
82 198
83 printk(KERN_INFO "saa5246a: teletext chip found.\n"); 199#define R3_HOURS_UNITS_DO_NOT_CARE 0x00
84 client=kmalloc(sizeof(*client), GFP_KERNEL); 200#define R3_HOURS_UNITS_DO_CARE 0x10
85 if(client==NULL)
86 return -ENOMEM;
87 client_template.adapter = adap;
88 client_template.addr = addr;
89 memcpy(client, &client_template, sizeof(*client));
90 t = kzalloc(sizeof(*t), GFP_KERNEL);
91 if(t==NULL)
92 {
93 kfree(client);
94 return -ENOMEM;
95 }
96 strlcpy(client->name, IF_NAME, I2C_NAME_SIZE);
97 mutex_init(&t->lock);
98 201
99 /* 202#define R3_MINUTES_TENS_DO_NOT_CARE 0x00
100 * Now create a video4linux device 203#define R3_MINUTES_TENS_DO_CARE 0x10
101 */
102 204
103 vd = video_device_alloc(); 205#define R3_MINUTES_UNITS_DO_NOT_CARE 0x00
104 if(vd==NULL) 206#define R3_MINUTES_UNITS_DO_CARE 0x10
105 {
106 kfree(t);
107 kfree(client);
108 return -ENOMEM;
109 }
110 i2c_set_clientdata(client, vd);
111 memcpy(vd, &saa_template, sizeof(*vd));
112 207
113 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) 208/* Register R4 (Display chapter) */
114 { 209#define R4_DISPLAY_PAGE_0 0x00
115 memset(t->pgbuf[pgbuf], ' ', sizeof(t->pgbuf[0])); 210#define R4_DISPLAY_PAGE_1 0x01
116 t->is_searching[pgbuf] = false; 211#define R4_DISPLAY_PAGE_2 0x02
117 } 212#define R4_DISPLAY_PAGE_3 0x03
118 vd->priv=t; 213#define R4_DISPLAY_PAGE_4 0x04
214#define R4_DISPLAY_PAGE_5 0x05
215#define R4_DISPLAY_PAGE_6 0x06
216#define R4_DISPLAY_PAGE_7 0x07
119 217
218/* Register R5 (Normal display control) */
219#define R5_PICTURE_INSIDE_BOXING_OFF 0x00
220#define R5_PICTURE_INSIDE_BOXING_ON 0x01
120 221
121 /* 222#define R5_PICTURE_OUTSIDE_BOXING_OFF 0x00
122 * Register it 223#define R5_PICTURE_OUTSIDE_BOXING_ON 0x02
123 */
124 224
125 if((err=video_register_device(vd, VFL_TYPE_VTX,-1))<0) 225#define R5_TEXT_INSIDE_BOXING_OFF 0x00
126 { 226#define R5_TEXT_INSIDE_BOXING_ON 0x04
127 kfree(t);
128 kfree(client);
129 video_device_release(vd);
130 return err;
131 }
132 t->client = client;
133 i2c_attach_client(client);
134 return 0;
135}
136 227
137/* 228#define R5_TEXT_OUTSIDE_BOXING_OFF 0x00
138 * We do most of the hard work when we become a device on the i2c. 229#define R5_TEXT_OUTSIDE_BOXING_ON 0x08
139 */
140static int saa5246a_probe(struct i2c_adapter *adap)
141{
142 if (adap->class & I2C_CLASS_TV_ANALOG)
143 return i2c_probe(adap, &addr_data, saa5246a_attach);
144 return 0;
145}
146 230
147static int saa5246a_detach(struct i2c_client *client) 231#define R5_CONTRAST_REDUCTION_INSIDE_BOXING_OFF 0x00
148{ 232#define R5_CONTRAST_REDUCTION_INSIDE_BOXING_ON 0x10
149 struct video_device *vd = i2c_get_clientdata(client);
150 i2c_detach_client(client);
151 video_unregister_device(vd);
152 kfree(vd->priv);
153 kfree(client);
154 return 0;
155}
156 233
157/* 234#define R5_CONTRAST_REDUCTION_OUTSIDE_BOXING_OFF 0x00
158 * I2C interfaces 235#define R5_CONTRAST_REDUCTION_OUTSIDE_BOXING_ON 0x20
159 */ 236
237#define R5_BACKGROUND_COLOR_INSIDE_BOXING_OFF 0x00
238#define R5_BACKGROUND_COLOR_INSIDE_BOXING_ON 0x40
239
240#define R5_BACKGROUND_COLOR_OUTSIDE_BOXING_OFF 0x00
241#define R5_BACKGROUND_COLOR_OUTSIDE_BOXING_ON 0x80
242
243/* Register R6 (Newsflash display) */
244#define R6_NEWSFLASH_PICTURE_INSIDE_BOXING_OFF 0x00
245#define R6_NEWSFLASH_PICTURE_INSIDE_BOXING_ON 0x01
246
247#define R6_NEWSFLASH_PICTURE_OUTSIDE_BOXING_OFF 0x00
248#define R6_NEWSFLASH_PICTURE_OUTSIDE_BOXING_ON 0x02
249
250#define R6_NEWSFLASH_TEXT_INSIDE_BOXING_OFF 0x00
251#define R6_NEWSFLASH_TEXT_INSIDE_BOXING_ON 0x04
252
253#define R6_NEWSFLASH_TEXT_OUTSIDE_BOXING_OFF 0x00
254#define R6_NEWSFLASH_TEXT_OUTSIDE_BOXING_ON 0x08
255
256#define R6_NEWSFLASH_CONTRAST_REDUCTION_INSIDE_BOXING_OFF 0x00
257#define R6_NEWSFLASH_CONTRAST_REDUCTION_INSIDE_BOXING_ON 0x10
258
259#define R6_NEWSFLASH_CONTRAST_REDUCTION_OUTSIDE_BOXING_OFF 0x00
260#define R6_NEWSFLASH_CONTRAST_REDUCTION_OUTSIDE_BOXING_ON 0x20
261
262#define R6_NEWSFLASH_BACKGROUND_COLOR_INSIDE_BOXING_OFF 0x00
263#define R6_NEWSFLASH_BACKGROUND_COLOR_INSIDE_BOXING_ON 0x40
264
265#define R6_NEWSFLASH_BACKGROUND_COLOR_OUTSIDE_BOXING_OFF 0x00
266#define R6_NEWSFLASH_BACKGROUND_COLOR_OUTSIDE_BOXING_ON 0x80
267
268/* Register R7 (Display mode) */
269#define R7_BOX_OFF_ROW_0 0x00
270#define R7_BOX_ON_ROW_0 0x01
271
272#define R7_BOX_OFF_ROW_1_TO_23 0x00
273#define R7_BOX_ON_ROW_1_TO_23 0x02
274
275#define R7_BOX_OFF_ROW_24 0x00
276#define R7_BOX_ON_ROW_24 0x04
277
278#define R7_SINGLE_HEIGHT 0x00
279#define R7_DOUBLE_HEIGHT 0x08
280
281#define R7_TOP_HALF 0x00
282#define R7_BOTTOM_HALF 0x10
283
284#define R7_REVEAL_OFF 0x00
285#define R7_REVEAL_ON 0x20
286
287#define R7_CURSER_OFF 0x00
288#define R7_CURSER_ON 0x40
289
290#define R7_STATUS_BOTTOM 0x00
291#define R7_STATUS_TOP 0x80
292
293/* Register R8 (Active chapter) */
294#define R8_ACTIVE_CHAPTER_0 0x00
295#define R8_ACTIVE_CHAPTER_1 0x01
296#define R8_ACTIVE_CHAPTER_2 0x02
297#define R8_ACTIVE_CHAPTER_3 0x03
298#define R8_ACTIVE_CHAPTER_4 0x04
299#define R8_ACTIVE_CHAPTER_5 0x05
300#define R8_ACTIVE_CHAPTER_6 0x06
301#define R8_ACTIVE_CHAPTER_7 0x07
302
303#define R8_CLEAR_MEMORY 0x08
304#define R8_DO_NOT_CLEAR_MEMORY 0x00
305
306/* Register R9 (Curser row) */
307#define R9_CURSER_ROW_0 0x00
308#define R9_CURSER_ROW_1 0x01
309#define R9_CURSER_ROW_2 0x02
310#define R9_CURSER_ROW_25 0x19
311
312/* Register R10 (Curser column) */
313#define R10_CURSER_COLUMN_0 0x00
314#define R10_CURSER_COLUMN_6 0x06
315#define R10_CURSER_COLUMN_8 0x08
316
317/*****************************************************************************/
318/* Row 25 control data in column 0 to 9 */
319/*****************************************************************************/
320#define ROW25_COLUMN0_PAGE_UNITS 0x0F
321
322#define ROW25_COLUMN1_PAGE_TENS 0x0F
323
324#define ROW25_COLUMN2_MINUTES_UNITS 0x0F
160 325
161static struct i2c_driver i2c_driver_videotext = 326#define ROW25_COLUMN3_MINUTES_TENS 0x07
327#define ROW25_COLUMN3_DELETE_PAGE 0x08
328
329#define ROW25_COLUMN4_HOUR_UNITS 0x0F
330
331#define ROW25_COLUMN5_HOUR_TENS 0x03
332#define ROW25_COLUMN5_INSERT_HEADLINE 0x04
333#define ROW25_COLUMN5_INSERT_SUBTITLE 0x08
334
335#define ROW25_COLUMN6_SUPPRESS_HEADER 0x01
336#define ROW25_COLUMN6_UPDATE_PAGE 0x02
337#define ROW25_COLUMN6_INTERRUPTED_SEQUENCE 0x04
338#define ROW25_COLUMN6_SUPPRESS_DISPLAY 0x08
339
340#define ROW25_COLUMN7_SERIAL_MODE 0x01
341#define ROW25_COLUMN7_CHARACTER_SET 0x0E
342
343#define ROW25_COLUMN8_PAGE_HUNDREDS 0x07
344#define ROW25_COLUMN8_PAGE_NOT_FOUND 0x10
345
346#define ROW25_COLUMN9_PAGE_BEING_LOOKED_FOR 0x20
347
348#define ROW25_COLUMN0_TO_7_HAMMING_ERROR 0x10
349
350/*****************************************************************************/
351/* Helper macros for extracting page, hour and minute digits */
352/*****************************************************************************/
353/* BYTE_POS 0 is at row 0, column 0,
354 BYTE_POS 1 is at row 0, column 1,
355 BYTE_POS 40 is at row 1, column 0, (with NUM_ROWS_PER_PAGE = 40)
356 BYTE_POS 41 is at row 1, column 1, (with NUM_ROWS_PER_PAGE = 40),
357 ... */
358#define ROW(BYTE_POS) (BYTE_POS / NUM_ROWS_PER_PAGE)
359#define COLUMN(BYTE_POS) (BYTE_POS % NUM_ROWS_PER_PAGE)
360
361/*****************************************************************************/
362/* Helper macros for extracting page, hour and minute digits */
363/*****************************************************************************/
364/* Macros for extracting hundreds, tens and units of a page number which
365 must be in the range 0 ... 0x799.
366 Note that page is coded in hexadecimal, i.e. 0x123 means page 123.
367 page 0x.. means page 8.. */
368#define HUNDREDS_OF_PAGE(page) (((page) / 0x100) & 0x7)
369#define TENS_OF_PAGE(page) (((page) / 0x10) & 0xF)
370#define UNITS_OF_PAGE(page) ((page) & 0xF)
371
372/* Macros for extracting tens and units of a hour information which
373 must be in the range 0 ... 0x24.
374 Note that hour is coded in hexadecimal, i.e. 0x12 means 12 hours */
375#define TENS_OF_HOUR(hour) ((hour) / 0x10)
376#define UNITS_OF_HOUR(hour) ((hour) & 0xF)
377
378/* Macros for extracting tens and units of a minute information which
379 must be in the range 0 ... 0x59.
380 Note that minute is coded in hexadecimal, i.e. 0x12 means 12 minutes */
381#define TENS_OF_MINUTE(minute) ((minute) / 0x10)
382#define UNITS_OF_MINUTE(minute) ((minute) & 0xF)
383
384#define HOUR_MAX 0x23
385#define MINUTE_MAX 0x59
386#define PAGE_MAX 0x8FF
387
388
389struct saa5246a_device
162{ 390{
163 .driver = { 391 u8 pgbuf[NUM_DAUS][VTX_VIRTUALSIZE];
164 .name = IF_NAME, /* name */ 392 int is_searching[NUM_DAUS];
165 }, 393 struct i2c_client *client;
166 .id = I2C_DRIVERID_SAA5249, /* in i2c.h */ 394 unsigned long in_use;
167 .attach_adapter = saa5246a_probe, 395 struct mutex lock;
168 .detach_client = saa5246a_detach,
169}; 396};
170 397
171static struct i2c_client client_template = { 398static struct video_device saa_template; /* Declared near bottom */
172 .driver = &i2c_driver_videotext, 399
173 .name = "(unset)", 400/*
174}; 401 * I2C interfaces
402 */
175 403
176static int i2c_sendbuf(struct saa5246a_device *t, int reg, int count, u8 *data) 404static int i2c_sendbuf(struct saa5246a_device *t, int reg, int count, u8 *data)
177{ 405{
@@ -579,8 +807,8 @@ static inline int saa5246a_stop_dau(struct saa5246a_device *t,
579static int do_saa5246a_ioctl(struct inode *inode, struct file *file, 807static int do_saa5246a_ioctl(struct inode *inode, struct file *file,
580 unsigned int cmd, void *arg) 808 unsigned int cmd, void *arg)
581{ 809{
582 struct video_device *vd = video_devdata(file); 810 struct saa5246a_device *t = video_drvdata(file);
583 struct saa5246a_device *t=vd->priv; 811
584 switch(cmd) 812 switch(cmd)
585 { 813 {
586 case VTXIOCGETINFO: 814 case VTXIOCGETINFO:
@@ -720,8 +948,7 @@ static inline unsigned int vtx_fix_command(unsigned int cmd)
720static int saa5246a_ioctl(struct inode *inode, struct file *file, 948static int saa5246a_ioctl(struct inode *inode, struct file *file,
721 unsigned int cmd, unsigned long arg) 949 unsigned int cmd, unsigned long arg)
722{ 950{
723 struct video_device *vd = video_devdata(file); 951 struct saa5246a_device *t = video_drvdata(file);
724 struct saa5246a_device *t = vd->priv;
725 int err; 952 int err;
726 953
727 cmd = vtx_fix_command(cmd); 954 cmd = vtx_fix_command(cmd);
@@ -733,21 +960,15 @@ static int saa5246a_ioctl(struct inode *inode, struct file *file,
733 960
734static int saa5246a_open(struct inode *inode, struct file *file) 961static int saa5246a_open(struct inode *inode, struct file *file)
735{ 962{
736 struct video_device *vd = video_devdata(file); 963 struct saa5246a_device *t = video_drvdata(file);
737 struct saa5246a_device *t = vd->priv;
738 int err;
739 964
740 err = video_exclusive_open(inode,file); 965 if (t->client == NULL)
741 if (err < 0) 966 return -ENODEV;
742 return err;
743 967
744 if (t->client==NULL) { 968 if (test_and_set_bit(0, &t->in_use))
745 err = -ENODEV; 969 return -EBUSY;
746 goto fail;
747 }
748 970
749 if (i2c_senddata(t, SAA5246A_REGISTER_R0, 971 if (i2c_senddata(t, SAA5246A_REGISTER_R0,
750
751 R0_SELECT_R11 | 972 R0_SELECT_R11 |
752 R0_PLL_TIME_CONSTANT_LONG | 973 R0_PLL_TIME_CONSTANT_LONG |
753 R0_ENABLE_nODD_EVEN_OUTPUT | 974 R0_ENABLE_nODD_EVEN_OUTPUT |
@@ -773,21 +994,15 @@ static int saa5246a_open(struct inode *inode, struct file *file)
773 994
774 COMMAND_END)) 995 COMMAND_END))
775 { 996 {
776 err = -EIO; 997 clear_bit(0, &t->in_use);
777 goto fail; 998 return -EIO;
778 } 999 }
779
780 return 0; 1000 return 0;
781
782fail:
783 video_exclusive_release(inode,file);
784 return err;
785} 1001}
786 1002
787static int saa5246a_release(struct inode *inode, struct file *file) 1003static int saa5246a_release(struct inode *inode, struct file *file)
788{ 1004{
789 struct video_device *vd = video_devdata(file); 1005 struct saa5246a_device *t = video_drvdata(file);
790 struct saa5246a_device *t = vd->priv;
791 1006
792 /* Stop all acquisition circuits. */ 1007 /* Stop all acquisition circuits. */
793 i2c_senddata(t, SAA5246A_REGISTER_R1, 1008 i2c_senddata(t, SAA5246A_REGISTER_R1,
@@ -800,26 +1015,10 @@ static int saa5246a_release(struct inode *inode, struct file *file)
800 R1_VCS_TO_SCS, 1015 R1_VCS_TO_SCS,
801 1016
802 COMMAND_END); 1017 COMMAND_END);
803 video_exclusive_release(inode,file); 1018 clear_bit(0, &t->in_use);
804 return 0; 1019 return 0;
805} 1020}
806 1021
807static int __init init_saa_5246a (void)
808{
809 printk(KERN_INFO
810 "SAA5246A (or compatible) Teletext decoder driver version %d.%d\n",
811 MAJOR_VERSION, MINOR_VERSION);
812 return i2c_add_driver(&i2c_driver_videotext);
813}
814
815static void __exit cleanup_saa_5246a (void)
816{
817 i2c_del_driver(&i2c_driver_videotext);
818}
819
820module_init(init_saa_5246a);
821module_exit(cleanup_saa_5246a);
822
823static const struct file_operations saa_fops = { 1022static const struct file_operations saa_fops = {
824 .owner = THIS_MODULE, 1023 .owner = THIS_MODULE,
825 .open = saa5246a_open, 1024 .open = saa5246a_open,
@@ -830,8 +1029,79 @@ static const struct file_operations saa_fops = {
830 1029
831static struct video_device saa_template = 1030static struct video_device saa_template =
832{ 1031{
833 .name = IF_NAME, 1032 .name = "saa5246a",
834 .fops = &saa_fops, 1033 .fops = &saa_fops,
835 .release = video_device_release, 1034 .release = video_device_release,
836 .minor = -1, 1035 .minor = -1,
837}; 1036};
1037
1038/* Addresses to scan */
1039static unsigned short normal_i2c[] = { 0x22 >> 1, I2C_CLIENT_END };
1040
1041I2C_CLIENT_INSMOD;
1042
1043static int saa5246a_probe(struct i2c_client *client,
1044 const struct i2c_device_id *id)
1045{
1046 int pgbuf;
1047 int err;
1048 struct video_device *vd;
1049 struct saa5246a_device *t;
1050
1051 v4l_info(client, "chip found @ 0x%x (%s)\n",
1052 client->addr << 1, client->adapter->name);
1053 v4l_info(client, "VideoText version %d.%d\n",
1054 MAJOR_VERSION, MINOR_VERSION);
1055 t = kzalloc(sizeof(*t), GFP_KERNEL);
1056 if (t == NULL)
1057 return -ENOMEM;
1058 mutex_init(&t->lock);
1059
1060 /* Now create a video4linux device */
1061 vd = video_device_alloc();
1062 if (vd == NULL) {
1063 kfree(t);
1064 return -ENOMEM;
1065 }
1066 i2c_set_clientdata(client, vd);
1067 memcpy(vd, &saa_template, sizeof(*vd));
1068
1069 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) {
1070 memset(t->pgbuf[pgbuf], ' ', sizeof(t->pgbuf[0]));
1071 t->is_searching[pgbuf] = false;
1072 }
1073 video_set_drvdata(vd, t);
1074
1075 /* Register it */
1076 err = video_register_device(vd, VFL_TYPE_VTX, -1);
1077 if (err < 0) {
1078 kfree(t);
1079 video_device_release(vd);
1080 return err;
1081 }
1082 t->client = client;
1083 return 0;
1084}
1085
1086static int saa5246a_remove(struct i2c_client *client)
1087{
1088 struct video_device *vd = i2c_get_clientdata(client);
1089
1090 video_unregister_device(vd);
1091 kfree(video_get_drvdata(vd));
1092 return 0;
1093}
1094
1095static const struct i2c_device_id saa5246a_id[] = {
1096 { "saa5246a", 0 },
1097 { }
1098};
1099MODULE_DEVICE_TABLE(i2c, saa5246a_id);
1100
1101static struct v4l2_i2c_driver_data v4l2_i2c_data = {
1102 .name = "saa5246a",
1103 .driverid = I2C_DRIVERID_SAA5249,
1104 .probe = saa5246a_probe,
1105 .remove = saa5246a_remove,
1106 .id_table = saa5246a_id,
1107};
diff --git a/drivers/media/video/saa5246a.h b/drivers/media/video/saa5246a.h
deleted file mode 100644
index 64394c036c60..000000000000
--- a/drivers/media/video/saa5246a.h
+++ /dev/null
@@ -1,359 +0,0 @@
1/*
2 Driver for the SAA5246A or SAA5281 Teletext (=Videotext) decoder chips from
3 Philips.
4
5 Copyright (C) 2004 Michael Geng (linux@MichaelGeng.de)
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20
21 */
22#ifndef __SAA5246A_H__
23#define __SAA5246A_H__
24
25#define MAJOR_VERSION 1 /* driver major version number */
26#define MINOR_VERSION 8 /* driver minor version number */
27
28#define IF_NAME "SAA5246A"
29
30#define I2C_ADDRESS 17
31
32/* Number of DAUs = number of pages that can be searched at the same time. */
33#define NUM_DAUS 4
34
35#define NUM_ROWS_PER_PAGE 40
36
37/* first column is 0 (not 1) */
38#define POS_TIME_START 32
39#define POS_TIME_END 39
40
41#define POS_HEADER_START 7
42#define POS_HEADER_END 31
43
44/* Returns 'true' if the part of the videotext page described with req contains
45 (at least parts of) the time field */
46#define REQ_CONTAINS_TIME(p_req) \
47 ((p_req)->start <= POS_TIME_END && \
48 (p_req)->end >= POS_TIME_START)
49
50/* Returns 'true' if the part of the videotext page described with req contains
51 (at least parts of) the page header */
52#define REQ_CONTAINS_HEADER(p_req) \
53 ((p_req)->start <= POS_HEADER_END && \
54 (p_req)->end >= POS_HEADER_START)
55
56/*****************************************************************************/
57/* Mode register numbers of the SAA5246A */
58/*****************************************************************************/
59#define SAA5246A_REGISTER_R0 0
60#define SAA5246A_REGISTER_R1 1
61#define SAA5246A_REGISTER_R2 2
62#define SAA5246A_REGISTER_R3 3
63#define SAA5246A_REGISTER_R4 4
64#define SAA5246A_REGISTER_R5 5
65#define SAA5246A_REGISTER_R6 6
66#define SAA5246A_REGISTER_R7 7
67#define SAA5246A_REGISTER_R8 8
68#define SAA5246A_REGISTER_R9 9
69#define SAA5246A_REGISTER_R10 10
70#define SAA5246A_REGISTER_R11 11
71#define SAA5246A_REGISTER_R11B 11
72
73/* SAA5246A mode registers often autoincrement to the next register.
74 Therefore we use variable argument lists. The following macro indicates
75 the end of a command list. */
76#define COMMAND_END (- 1)
77
78/*****************************************************************************/
79/* Contents of the mode registers of the SAA5246A */
80/*****************************************************************************/
81/* Register R0 (Advanced Control) */
82#define R0_SELECT_R11 0x00
83#define R0_SELECT_R11B 0x01
84
85#define R0_PLL_TIME_CONSTANT_LONG 0x00
86#define R0_PLL_TIME_CONSTANT_SHORT 0x02
87
88#define R0_ENABLE_nODD_EVEN_OUTPUT 0x00
89#define R0_DISABLE_nODD_EVEN_OUTPUT 0x04
90
91#define R0_ENABLE_HDR_POLL 0x00
92#define R0_DISABLE_HDR_POLL 0x10
93
94#define R0_DO_NOT_FORCE_nODD_EVEN_LOW_IF_PICTURE_DISPLAYED 0x00
95#define R0_FORCE_nODD_EVEN_LOW_IF_PICTURE_DISPLAYED 0x20
96
97#define R0_NO_FREE_RUN_PLL 0x00
98#define R0_FREE_RUN_PLL 0x40
99
100#define R0_NO_AUTOMATIC_FASTEXT_PROMPT 0x00
101#define R0_AUTOMATIC_FASTEXT_PROMPT 0x80
102
103/* Register R1 (Mode) */
104#define R1_INTERLACED_312_AND_HALF_312_AND_HALF_LINES 0x00
105#define R1_NON_INTERLACED_312_313_LINES 0x01
106#define R1_NON_INTERLACED_312_312_LINES 0x02
107#define R1_FFB_LEADING_EDGE_IN_FIRST_BROAD_PULSE 0x03
108#define R1_FFB_LEADING_EDGE_IN_SECOND_BROAD_PULSE 0x07
109
110#define R1_DEW 0x00
111#define R1_FULL_FIELD 0x08
112
113#define R1_EXTENDED_PACKET_DISABLE 0x00
114#define R1_EXTENDED_PACKET_ENABLE 0x10
115
116#define R1_DAUS_ALL_ON 0x00
117#define R1_DAUS_ALL_OFF 0x20
118
119#define R1_7_BITS_PLUS_PARITY 0x00
120#define R1_8_BITS_NO_PARITY 0x40
121
122#define R1_VCS_TO_SCS 0x00
123#define R1_NO_VCS_TO_SCS 0x80
124
125/* Register R2 (Page request address) */
126#define R2_IN_R3_SELECT_PAGE_HUNDREDS 0x00
127#define R2_IN_R3_SELECT_PAGE_TENS 0x01
128#define R2_IN_R3_SELECT_PAGE_UNITS 0x02
129#define R2_IN_R3_SELECT_HOURS_TENS 0x03
130#define R2_IN_R3_SELECT_HOURS_UNITS 0x04
131#define R2_IN_R3_SELECT_MINUTES_TENS 0x05
132#define R2_IN_R3_SELECT_MINUTES_UNITS 0x06
133
134#define R2_DAU_0 0x00
135#define R2_DAU_1 0x10
136#define R2_DAU_2 0x20
137#define R2_DAU_3 0x30
138
139#define R2_BANK_0 0x00
140#define R2_BANK 1 0x40
141
142#define R2_HAMMING_CHECK_ON 0x80
143#define R2_HAMMING_CHECK_OFF 0x00
144
145/* Register R3 (Page request data) */
146#define R3_PAGE_HUNDREDS_0 0x00
147#define R3_PAGE_HUNDREDS_1 0x01
148#define R3_PAGE_HUNDREDS_2 0x02
149#define R3_PAGE_HUNDREDS_3 0x03
150#define R3_PAGE_HUNDREDS_4 0x04
151#define R3_PAGE_HUNDREDS_5 0x05
152#define R3_PAGE_HUNDREDS_6 0x06
153#define R3_PAGE_HUNDREDS_7 0x07
154
155#define R3_HOLD_PAGE 0x00
156#define R3_UPDATE_PAGE 0x08
157
158#define R3_PAGE_HUNDREDS_DO_NOT_CARE 0x00
159#define R3_PAGE_HUNDREDS_DO_CARE 0x10
160
161#define R3_PAGE_TENS_DO_NOT_CARE 0x00
162#define R3_PAGE_TENS_DO_CARE 0x10
163
164#define R3_PAGE_UNITS_DO_NOT_CARE 0x00
165#define R3_PAGE_UNITS_DO_CARE 0x10
166
167#define R3_HOURS_TENS_DO_NOT_CARE 0x00
168#define R3_HOURS_TENS_DO_CARE 0x10
169
170#define R3_HOURS_UNITS_DO_NOT_CARE 0x00
171#define R3_HOURS_UNITS_DO_CARE 0x10
172
173#define R3_MINUTES_TENS_DO_NOT_CARE 0x00
174#define R3_MINUTES_TENS_DO_CARE 0x10
175
176#define R3_MINUTES_UNITS_DO_NOT_CARE 0x00
177#define R3_MINUTES_UNITS_DO_CARE 0x10
178
179/* Register R4 (Display chapter) */
180#define R4_DISPLAY_PAGE_0 0x00
181#define R4_DISPLAY_PAGE_1 0x01
182#define R4_DISPLAY_PAGE_2 0x02
183#define R4_DISPLAY_PAGE_3 0x03
184#define R4_DISPLAY_PAGE_4 0x04
185#define R4_DISPLAY_PAGE_5 0x05
186#define R4_DISPLAY_PAGE_6 0x06
187#define R4_DISPLAY_PAGE_7 0x07
188
189/* Register R5 (Normal display control) */
190#define R5_PICTURE_INSIDE_BOXING_OFF 0x00
191#define R5_PICTURE_INSIDE_BOXING_ON 0x01
192
193#define R5_PICTURE_OUTSIDE_BOXING_OFF 0x00
194#define R5_PICTURE_OUTSIDE_BOXING_ON 0x02
195
196#define R5_TEXT_INSIDE_BOXING_OFF 0x00
197#define R5_TEXT_INSIDE_BOXING_ON 0x04
198
199#define R5_TEXT_OUTSIDE_BOXING_OFF 0x00
200#define R5_TEXT_OUTSIDE_BOXING_ON 0x08
201
202#define R5_CONTRAST_REDUCTION_INSIDE_BOXING_OFF 0x00
203#define R5_CONTRAST_REDUCTION_INSIDE_BOXING_ON 0x10
204
205#define R5_CONTRAST_REDUCTION_OUTSIDE_BOXING_OFF 0x00
206#define R5_CONTRAST_REDUCTION_OUTSIDE_BOXING_ON 0x20
207
208#define R5_BACKGROUND_COLOR_INSIDE_BOXING_OFF 0x00
209#define R5_BACKGROUND_COLOR_INSIDE_BOXING_ON 0x40
210
211#define R5_BACKGROUND_COLOR_OUTSIDE_BOXING_OFF 0x00
212#define R5_BACKGROUND_COLOR_OUTSIDE_BOXING_ON 0x80
213
214/* Register R6 (Newsflash display) */
215#define R6_NEWSFLASH_PICTURE_INSIDE_BOXING_OFF 0x00
216#define R6_NEWSFLASH_PICTURE_INSIDE_BOXING_ON 0x01
217
218#define R6_NEWSFLASH_PICTURE_OUTSIDE_BOXING_OFF 0x00
219#define R6_NEWSFLASH_PICTURE_OUTSIDE_BOXING_ON 0x02
220
221#define R6_NEWSFLASH_TEXT_INSIDE_BOXING_OFF 0x00
222#define R6_NEWSFLASH_TEXT_INSIDE_BOXING_ON 0x04
223
224#define R6_NEWSFLASH_TEXT_OUTSIDE_BOXING_OFF 0x00
225#define R6_NEWSFLASH_TEXT_OUTSIDE_BOXING_ON 0x08
226
227#define R6_NEWSFLASH_CONTRAST_REDUCTION_INSIDE_BOXING_OFF 0x00
228#define R6_NEWSFLASH_CONTRAST_REDUCTION_INSIDE_BOXING_ON 0x10
229
230#define R6_NEWSFLASH_CONTRAST_REDUCTION_OUTSIDE_BOXING_OFF 0x00
231#define R6_NEWSFLASH_CONTRAST_REDUCTION_OUTSIDE_BOXING_ON 0x20
232
233#define R6_NEWSFLASH_BACKGROUND_COLOR_INSIDE_BOXING_OFF 0x00
234#define R6_NEWSFLASH_BACKGROUND_COLOR_INSIDE_BOXING_ON 0x40
235
236#define R6_NEWSFLASH_BACKGROUND_COLOR_OUTSIDE_BOXING_OFF 0x00
237#define R6_NEWSFLASH_BACKGROUND_COLOR_OUTSIDE_BOXING_ON 0x80
238
239/* Register R7 (Display mode) */
240#define R7_BOX_OFF_ROW_0 0x00
241#define R7_BOX_ON_ROW_0 0x01
242
243#define R7_BOX_OFF_ROW_1_TO_23 0x00
244#define R7_BOX_ON_ROW_1_TO_23 0x02
245
246#define R7_BOX_OFF_ROW_24 0x00
247#define R7_BOX_ON_ROW_24 0x04
248
249#define R7_SINGLE_HEIGHT 0x00
250#define R7_DOUBLE_HEIGHT 0x08
251
252#define R7_TOP_HALF 0x00
253#define R7_BOTTOM_HALF 0x10
254
255#define R7_REVEAL_OFF 0x00
256#define R7_REVEAL_ON 0x20
257
258#define R7_CURSER_OFF 0x00
259#define R7_CURSER_ON 0x40
260
261#define R7_STATUS_BOTTOM 0x00
262#define R7_STATUS_TOP 0x80
263
264/* Register R8 (Active chapter) */
265#define R8_ACTIVE_CHAPTER_0 0x00
266#define R8_ACTIVE_CHAPTER_1 0x01
267#define R8_ACTIVE_CHAPTER_2 0x02
268#define R8_ACTIVE_CHAPTER_3 0x03
269#define R8_ACTIVE_CHAPTER_4 0x04
270#define R8_ACTIVE_CHAPTER_5 0x05
271#define R8_ACTIVE_CHAPTER_6 0x06
272#define R8_ACTIVE_CHAPTER_7 0x07
273
274#define R8_CLEAR_MEMORY 0x08
275#define R8_DO_NOT_CLEAR_MEMORY 0x00
276
277/* Register R9 (Curser row) */
278#define R9_CURSER_ROW_0 0x00
279#define R9_CURSER_ROW_1 0x01
280#define R9_CURSER_ROW_2 0x02
281#define R9_CURSER_ROW_25 0x19
282
283/* Register R10 (Curser column) */
284#define R10_CURSER_COLUMN_0 0x00
285#define R10_CURSER_COLUMN_6 0x06
286#define R10_CURSER_COLUMN_8 0x08
287
288/*****************************************************************************/
289/* Row 25 control data in column 0 to 9 */
290/*****************************************************************************/
291#define ROW25_COLUMN0_PAGE_UNITS 0x0F
292
293#define ROW25_COLUMN1_PAGE_TENS 0x0F
294
295#define ROW25_COLUMN2_MINUTES_UNITS 0x0F
296
297#define ROW25_COLUMN3_MINUTES_TENS 0x07
298#define ROW25_COLUMN3_DELETE_PAGE 0x08
299
300#define ROW25_COLUMN4_HOUR_UNITS 0x0F
301
302#define ROW25_COLUMN5_HOUR_TENS 0x03
303#define ROW25_COLUMN5_INSERT_HEADLINE 0x04
304#define ROW25_COLUMN5_INSERT_SUBTITLE 0x08
305
306#define ROW25_COLUMN6_SUPPRESS_HEADER 0x01
307#define ROW25_COLUMN6_UPDATE_PAGE 0x02
308#define ROW25_COLUMN6_INTERRUPTED_SEQUENCE 0x04
309#define ROW25_COLUMN6_SUPPRESS_DISPLAY 0x08
310
311#define ROW25_COLUMN7_SERIAL_MODE 0x01
312#define ROW25_COLUMN7_CHARACTER_SET 0x0E
313
314#define ROW25_COLUMN8_PAGE_HUNDREDS 0x07
315#define ROW25_COLUMN8_PAGE_NOT_FOUND 0x10
316
317#define ROW25_COLUMN9_PAGE_BEING_LOOKED_FOR 0x20
318
319#define ROW25_COLUMN0_TO_7_HAMMING_ERROR 0x10
320
321/*****************************************************************************/
322/* Helper macros for extracting page, hour and minute digits */
323/*****************************************************************************/
324/* BYTE_POS 0 is at row 0, column 0,
325 BYTE_POS 1 is at row 0, column 1,
326 BYTE_POS 40 is at row 1, column 0, (with NUM_ROWS_PER_PAGE = 40)
327 BYTE_POS 41 is at row 1, column 1, (with NUM_ROWS_PER_PAGE = 40),
328 ... */
329#define ROW(BYTE_POS) (BYTE_POS / NUM_ROWS_PER_PAGE)
330#define COLUMN(BYTE_POS) (BYTE_POS % NUM_ROWS_PER_PAGE)
331
332/*****************************************************************************/
333/* Helper macros for extracting page, hour and minute digits */
334/*****************************************************************************/
335/* Macros for extracting hundreds, tens and units of a page number which
336 must be in the range 0 ... 0x799.
337 Note that page is coded in hexadecimal, i.e. 0x123 means page 123.
338 page 0x.. means page 8.. */
339#define HUNDREDS_OF_PAGE(page) (((page) / 0x100) & 0x7)
340#define TENS_OF_PAGE(page) (((page) / 0x10) & 0xF)
341#define UNITS_OF_PAGE(page) ((page) & 0xF)
342
343/* Macros for extracting tens and units of a hour information which
344 must be in the range 0 ... 0x24.
345 Note that hour is coded in hexadecimal, i.e. 0x12 means 12 hours */
346#define TENS_OF_HOUR(hour) ((hour) / 0x10)
347#define UNITS_OF_HOUR(hour) ((hour) & 0xF)
348
349/* Macros for extracting tens and units of a minute information which
350 must be in the range 0 ... 0x59.
351 Note that minute is coded in hexadecimal, i.e. 0x12 means 12 minutes */
352#define TENS_OF_MINUTE(minute) ((minute) / 0x10)
353#define UNITS_OF_MINUTE(minute) ((minute) & 0xF)
354
355#define HOUR_MAX 0x23
356#define MINUTE_MAX 0x59
357#define PAGE_MAX 0x8FF
358
359#endif /* __SAA5246A_H__ */
diff --git a/drivers/media/video/saa5249.c b/drivers/media/video/saa5249.c
index 0d639738d4e6..3bb959c25d9d 100644
--- a/drivers/media/video/saa5249.c
+++ b/drivers/media/video/saa5249.c
@@ -15,8 +15,6 @@
15 * 15 *
16 * Copyright (c) 1998 Richard Guenther <richard.guenther@student.uni-tuebingen.de> 16 * Copyright (c) 1998 Richard Guenther <richard.guenther@student.uni-tuebingen.de>
17 * 17 *
18 * $Id: saa5249.c,v 1.1 1998/03/30 22:23:23 alan Exp $
19 *
20 * Derived From 18 * Derived From
21 * 19 *
22 * vtx.c: 20 * vtx.c:
@@ -45,33 +43,28 @@
45 43
46#include <linux/module.h> 44#include <linux/module.h>
47#include <linux/kernel.h> 45#include <linux/kernel.h>
48#include <linux/sched.h>
49#include <linux/mm.h> 46#include <linux/mm.h>
50#include <linux/errno.h>
51#include <linux/delay.h>
52#include <linux/ioport.h>
53#include <linux/slab.h>
54#include <linux/init.h> 47#include <linux/init.h>
55#include <stdarg.h>
56#include <linux/i2c.h> 48#include <linux/i2c.h>
49#include <linux/smp_lock.h>
50#include <linux/mutex.h>
51#include <linux/delay.h>
57#include <linux/videotext.h> 52#include <linux/videotext.h>
58#include <linux/videodev.h> 53#include <linux/videodev.h>
59#include <media/v4l2-common.h> 54#include <media/v4l2-common.h>
60#include <media/v4l2-ioctl.h> 55#include <media/v4l2-ioctl.h>
61#include <linux/mutex.h> 56#include <media/v4l2-i2c-drv-legacy.h>
62
63 57
64#include <asm/io.h> 58MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>");
65#include <asm/uaccess.h> 59MODULE_DESCRIPTION("Philips SAA5249 Teletext decoder driver");
60MODULE_LICENSE("GPL");
66 61
67#define VTX_VER_MAJ 1 62#define VTX_VER_MAJ 1
68#define VTX_VER_MIN 8 63#define VTX_VER_MIN 8
69 64
70 65
71
72#define NUM_DAUS 4 66#define NUM_DAUS 4
73#define NUM_BUFS 8 67#define NUM_BUFS 8
74#define IF_NAME "SAA5249"
75 68
76static const int disp_modes[8][3] = 69static const int disp_modes[8][3] =
77{ 70{
@@ -109,6 +102,7 @@ struct saa5249_device
109 int disp_mode; 102 int disp_mode;
110 int virtual_mode; 103 int virtual_mode;
111 struct i2c_client *client; 104 struct i2c_client *client;
105 unsigned long in_use;
112 struct mutex lock; 106 struct mutex lock;
113}; 107};
114 108
@@ -123,125 +117,8 @@ struct saa5249_device
123 117
124#define VTX_DEV_MINOR 0 118#define VTX_DEV_MINOR 0
125 119
126/* General defines and debugging support */
127
128#define RESCHED do { cond_resched(); } while(0)
129
130static struct video_device saa_template; /* Declared near bottom */ 120static struct video_device saa_template; /* Declared near bottom */
131 121
132/* Addresses to scan */
133static unsigned short normal_i2c[] = {34>>1,I2C_CLIENT_END};
134
135I2C_CLIENT_INSMOD;
136
137static struct i2c_client client_template;
138
139static int saa5249_attach(struct i2c_adapter *adap, int addr, int kind)
140{
141 int pgbuf;
142 int err;
143 struct i2c_client *client;
144 struct video_device *vd;
145 struct saa5249_device *t;
146
147 printk(KERN_INFO "saa5249: teletext chip found.\n");
148 client=kmalloc(sizeof(*client), GFP_KERNEL);
149 if(client==NULL)
150 return -ENOMEM;
151 client_template.adapter = adap;
152 client_template.addr = addr;
153 memcpy(client, &client_template, sizeof(*client));
154 t = kzalloc(sizeof(*t), GFP_KERNEL);
155 if(t==NULL)
156 {
157 kfree(client);
158 return -ENOMEM;
159 }
160 strlcpy(client->name, IF_NAME, I2C_NAME_SIZE);
161 mutex_init(&t->lock);
162
163 /*
164 * Now create a video4linux device
165 */
166
167 vd = kmalloc(sizeof(struct video_device), GFP_KERNEL);
168 if(vd==NULL)
169 {
170 kfree(t);
171 kfree(client);
172 return -ENOMEM;
173 }
174 i2c_set_clientdata(client, vd);
175 memcpy(vd, &saa_template, sizeof(*vd));
176
177 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++)
178 {
179 memset(t->vdau[pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
180 memset(t->vdau[pgbuf].sregs, 0, sizeof(t->vdau[0].sregs));
181 memset(t->vdau[pgbuf].laststat, 0, sizeof(t->vdau[0].laststat));
182 t->vdau[pgbuf].expire = 0;
183 t->vdau[pgbuf].clrfound = true;
184 t->vdau[pgbuf].stopped = true;
185 t->is_searching[pgbuf] = false;
186 }
187 vd->priv=t;
188
189
190 /*
191 * Register it
192 */
193
194 if((err=video_register_device(vd, VFL_TYPE_VTX,-1))<0)
195 {
196 kfree(t);
197 kfree(vd);
198 kfree(client);
199 return err;
200 }
201 t->client = client;
202 i2c_attach_client(client);
203 return 0;
204}
205
206/*
207 * We do most of the hard work when we become a device on the i2c.
208 */
209
210static int saa5249_probe(struct i2c_adapter *adap)
211{
212 if (adap->class & I2C_CLASS_TV_ANALOG)
213 return i2c_probe(adap, &addr_data, saa5249_attach);
214 return 0;
215}
216
217static int saa5249_detach(struct i2c_client *client)
218{
219 struct video_device *vd = i2c_get_clientdata(client);
220 i2c_detach_client(client);
221 video_unregister_device(vd);
222 kfree(vd->priv);
223 kfree(vd);
224 kfree(client);
225 return 0;
226}
227
228/* new I2C driver support */
229
230static struct i2c_driver i2c_driver_videotext =
231{
232 .driver = {
233 .name = IF_NAME, /* name */
234 },
235 .id = I2C_DRIVERID_SAA5249, /* in i2c.h */
236 .attach_adapter = saa5249_probe,
237 .detach_client = saa5249_detach,
238};
239
240static struct i2c_client client_template = {
241 .driver = &i2c_driver_videotext,
242 .name = "(unset)",
243};
244
245/* 122/*
246 * Wait the given number of jiffies (10ms). This calls the scheduler, so the actual 123 * Wait the given number of jiffies (10ms). This calls the scheduler, so the actual
247 * delay may be longer. 124 * delay may be longer.
@@ -275,7 +152,7 @@ static int i2c_sendbuf(struct saa5249_device *t, int reg, int count, u8 *data)
275 buf[0] = reg; 152 buf[0] = reg;
276 memcpy(buf+1, data, count); 153 memcpy(buf+1, data, count);
277 154
278 if(i2c_master_send(t->client, buf, count+1)==count+1) 155 if (i2c_master_send(t->client, buf, count + 1) == count + 1)
279 return 0; 156 return 0;
280 return -1; 157 return -1;
281} 158}
@@ -317,246 +194,236 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
317 unsigned int cmd, void *arg) 194 unsigned int cmd, void *arg)
318{ 195{
319 static int virtual_mode = false; 196 static int virtual_mode = false;
320 struct video_device *vd = video_devdata(file); 197 struct saa5249_device *t = video_drvdata(file);
321 struct saa5249_device *t=vd->priv;
322 198
323 switch(cmd) 199 switch (cmd) {
200 case VTXIOCGETINFO:
324 { 201 {
325 case VTXIOCGETINFO: 202 vtx_info_t *info = arg;
326 { 203 info->version_major = VTX_VER_MAJ;
327 vtx_info_t *info = arg; 204 info->version_minor = VTX_VER_MIN;
328 info->version_major = VTX_VER_MAJ; 205 info->numpages = NUM_DAUS;
329 info->version_minor = VTX_VER_MIN; 206 /*info->cct_type = CCT_TYPE;*/
330 info->numpages = NUM_DAUS; 207 return 0;
331 /*info->cct_type = CCT_TYPE;*/ 208 }
332 return 0;
333 }
334 209
335 case VTXIOCCLRPAGE: 210 case VTXIOCCLRPAGE:
336 { 211 {
337 vtx_pagereq_t *req = arg; 212 vtx_pagereq_t *req = arg;
338 213
339 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS) 214 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
340 return -EINVAL; 215 return -EINVAL;
341 memset(t->vdau[req->pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf)); 216 memset(t->vdau[req->pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
342 t->vdau[req->pgbuf].clrfound = true; 217 t->vdau[req->pgbuf].clrfound = true;
343 return 0; 218 return 0;
344 } 219 }
345 220
346 case VTXIOCCLRFOUND: 221 case VTXIOCCLRFOUND:
347 { 222 {
348 vtx_pagereq_t *req = arg; 223 vtx_pagereq_t *req = arg;
349 224
350 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS) 225 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
351 return -EINVAL; 226 return -EINVAL;
352 t->vdau[req->pgbuf].clrfound = true; 227 t->vdau[req->pgbuf].clrfound = true;
353 return 0; 228 return 0;
354 } 229 }
355 230
356 case VTXIOCPAGEREQ: 231 case VTXIOCPAGEREQ:
357 { 232 {
358 vtx_pagereq_t *req = arg; 233 vtx_pagereq_t *req = arg;
359 if (!(req->pagemask & PGMASK_PAGE)) 234 if (!(req->pagemask & PGMASK_PAGE))
360 req->page = 0; 235 req->page = 0;
361 if (!(req->pagemask & PGMASK_HOUR)) 236 if (!(req->pagemask & PGMASK_HOUR))
362 req->hour = 0; 237 req->hour = 0;
363 if (!(req->pagemask & PGMASK_MINUTE)) 238 if (!(req->pagemask & PGMASK_MINUTE))
364 req->minute = 0; 239 req->minute = 0;
365 if (req->page < 0 || req->page > 0x8ff) /* 7FF ?? */ 240 if (req->page < 0 || req->page > 0x8ff) /* 7FF ?? */
366 return -EINVAL; 241 return -EINVAL;
367 req->page &= 0x7ff; 242 req->page &= 0x7ff;
368 if (req->hour < 0 || req->hour > 0x3f || req->minute < 0 || req->minute > 0x7f || 243 if (req->hour < 0 || req->hour > 0x3f || req->minute < 0 || req->minute > 0x7f ||
369 req->pagemask < 0 || req->pagemask >= PGMASK_MAX || req->pgbuf < 0 || req->pgbuf >= NUM_DAUS) 244 req->pagemask < 0 || req->pagemask >= PGMASK_MAX || req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
370 return -EINVAL; 245 return -EINVAL;
371 t->vdau[req->pgbuf].sregs[0] = (req->pagemask & PG_HUND ? 0x10 : 0) | (req->page / 0x100); 246 t->vdau[req->pgbuf].sregs[0] = (req->pagemask & PG_HUND ? 0x10 : 0) | (req->page / 0x100);
372 t->vdau[req->pgbuf].sregs[1] = (req->pagemask & PG_TEN ? 0x10 : 0) | ((req->page / 0x10) & 0xf); 247 t->vdau[req->pgbuf].sregs[1] = (req->pagemask & PG_TEN ? 0x10 : 0) | ((req->page / 0x10) & 0xf);
373 t->vdau[req->pgbuf].sregs[2] = (req->pagemask & PG_UNIT ? 0x10 : 0) | (req->page & 0xf); 248 t->vdau[req->pgbuf].sregs[2] = (req->pagemask & PG_UNIT ? 0x10 : 0) | (req->page & 0xf);
374 t->vdau[req->pgbuf].sregs[3] = (req->pagemask & HR_TEN ? 0x10 : 0) | (req->hour / 0x10); 249 t->vdau[req->pgbuf].sregs[3] = (req->pagemask & HR_TEN ? 0x10 : 0) | (req->hour / 0x10);
375 t->vdau[req->pgbuf].sregs[4] = (req->pagemask & HR_UNIT ? 0x10 : 0) | (req->hour & 0xf); 250 t->vdau[req->pgbuf].sregs[4] = (req->pagemask & HR_UNIT ? 0x10 : 0) | (req->hour & 0xf);
376 t->vdau[req->pgbuf].sregs[5] = (req->pagemask & MIN_TEN ? 0x10 : 0) | (req->minute / 0x10); 251 t->vdau[req->pgbuf].sregs[5] = (req->pagemask & MIN_TEN ? 0x10 : 0) | (req->minute / 0x10);
377 t->vdau[req->pgbuf].sregs[6] = (req->pagemask & MIN_UNIT ? 0x10 : 0) | (req->minute & 0xf); 252 t->vdau[req->pgbuf].sregs[6] = (req->pagemask & MIN_UNIT ? 0x10 : 0) | (req->minute & 0xf);
378 t->vdau[req->pgbuf].stopped = false; 253 t->vdau[req->pgbuf].stopped = false;
379 t->vdau[req->pgbuf].clrfound = true; 254 t->vdau[req->pgbuf].clrfound = true;
380 t->is_searching[req->pgbuf] = true; 255 t->is_searching[req->pgbuf] = true;
381 return 0; 256 return 0;
382 } 257 }
383 258
384 case VTXIOCGETSTAT: 259 case VTXIOCGETSTAT:
385 { 260 {
386 vtx_pagereq_t *req = arg; 261 vtx_pagereq_t *req = arg;
387 u8 infobits[10]; 262 u8 infobits[10];
388 vtx_pageinfo_t info; 263 vtx_pageinfo_t info;
389 int a; 264 int a;
390 265
391 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS) 266 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
392 return -EINVAL; 267 return -EINVAL;
393 if (!t->vdau[req->pgbuf].stopped) 268 if (!t->vdau[req->pgbuf].stopped) {
394 { 269 if (i2c_senddata(t, 2, 0, -1) ||
395 if (i2c_senddata(t, 2, 0, -1) || 270 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) || 271 i2c_senddata(t, 8, 0, 25, 0, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', -1) ||
397 i2c_senddata(t, 8, 0, 25, 0, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', -1) || 272 i2c_senddata(t, 2, 0, t->vdau[req->pgbuf].sregs[0] | 8, -1) ||
398 i2c_senddata(t, 2, 0, t->vdau[req->pgbuf].sregs[0] | 8, -1) || 273 i2c_senddata(t, 8, 0, 25, 0, -1))
399 i2c_senddata(t, 8, 0, 25, 0, -1)) 274 return -EIO;
400 return -EIO; 275 jdelay(PAGE_WAIT);
401 jdelay(PAGE_WAIT); 276 if (i2c_getdata(t, 10, infobits))
402 if (i2c_getdata(t, 10, infobits)) 277 return -EIO;
403 return -EIO;
404 278
405 if (!(infobits[8] & 0x10) && !(infobits[7] & 0xf0) && /* check FOUND-bit */ 279 if (!(infobits[8] & 0x10) && !(infobits[7] & 0xf0) && /* check FOUND-bit */
406 (memcmp(infobits, t->vdau[req->pgbuf].laststat, sizeof(infobits)) || 280 (memcmp(infobits, t->vdau[req->pgbuf].laststat, sizeof(infobits)) ||
407 time_after_eq(jiffies, t->vdau[req->pgbuf].expire))) 281 time_after_eq(jiffies, t->vdau[req->pgbuf].expire)))
408 { /* check if new page arrived */ 282 { /* check if new page arrived */
409 if (i2c_senddata(t, 8, 0, 0, 0, -1) || 283 if (i2c_senddata(t, 8, 0, 0, 0, -1) ||
410 i2c_getdata(t, VTX_PAGESIZE, t->vdau[req->pgbuf].pgbuf)) 284 i2c_getdata(t, VTX_PAGESIZE, t->vdau[req->pgbuf].pgbuf))
285 return -EIO;
286 t->vdau[req->pgbuf].expire = jiffies + PGBUF_EXPIRE;
287 memset(t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE, ' ', VTX_VIRTUALSIZE - VTX_PAGESIZE);
288 if (t->virtual_mode) {
289 /* Packet X/24 */
290 if (i2c_senddata(t, 8, 0, 0x20, 0, -1) ||
291 i2c_getdata(t, 40, t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE + 20 * 40))
292 return -EIO;
293 /* Packet X/27/0 */
294 if (i2c_senddata(t, 8, 0, 0x21, 0, -1) ||
295 i2c_getdata(t, 40, t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE + 16 * 40))
296 return -EIO;
297 /* Packet 8/30/0...8/30/15
298 * FIXME: AFAIK, the 5249 does hamming-decoding for some bytes in packet 8/30,
299 * so we should undo this here.
300 */
301 if (i2c_senddata(t, 8, 0, 0x22, 0, -1) ||
302 i2c_getdata(t, 40, t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE + 23 * 40))
411 return -EIO; 303 return -EIO;
412 t->vdau[req->pgbuf].expire = jiffies + PGBUF_EXPIRE;
413 memset(t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE, ' ', VTX_VIRTUALSIZE - VTX_PAGESIZE);
414 if (t->virtual_mode)
415 {
416 /* Packet X/24 */
417 if (i2c_senddata(t, 8, 0, 0x20, 0, -1) ||
418 i2c_getdata(t, 40, t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE + 20 * 40))
419 return -EIO;
420 /* Packet X/27/0 */
421 if (i2c_senddata(t, 8, 0, 0x21, 0, -1) ||
422 i2c_getdata(t, 40, t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE + 16 * 40))
423 return -EIO;
424 /* Packet 8/30/0...8/30/15
425 * FIXME: AFAIK, the 5249 does hamming-decoding for some bytes in packet 8/30,
426 * so we should undo this here.
427 */
428 if (i2c_senddata(t, 8, 0, 0x22, 0, -1) ||
429 i2c_getdata(t, 40, t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE + 23 * 40))
430 return -EIO;
431 }
432 t->vdau[req->pgbuf].clrfound = false;
433 memcpy(t->vdau[req->pgbuf].laststat, infobits, sizeof(infobits));
434 }
435 else
436 {
437 memcpy(infobits, t->vdau[req->pgbuf].laststat, sizeof(infobits));
438 } 304 }
439 } 305 t->vdau[req->pgbuf].clrfound = false;
440 else 306 memcpy(t->vdau[req->pgbuf].laststat, infobits, sizeof(infobits));
441 { 307 } else {
442 memcpy(infobits, t->vdau[req->pgbuf].laststat, sizeof(infobits)); 308 memcpy(infobits, t->vdau[req->pgbuf].laststat, sizeof(infobits));
443 } 309 }
310 } else {
311 memcpy(infobits, t->vdau[req->pgbuf].laststat, sizeof(infobits));
312 }
444 313
445 info.pagenum = ((infobits[8] << 8) & 0x700) | ((infobits[1] << 4) & 0xf0) | (infobits[0] & 0x0f); 314 info.pagenum = ((infobits[8] << 8) & 0x700) | ((infobits[1] << 4) & 0xf0) | (infobits[0] & 0x0f);
446 if (info.pagenum < 0x100) 315 if (info.pagenum < 0x100)
447 info.pagenum += 0x800; 316 info.pagenum += 0x800;
448 info.hour = ((infobits[5] << 4) & 0x30) | (infobits[4] & 0x0f); 317 info.hour = ((infobits[5] << 4) & 0x30) | (infobits[4] & 0x0f);
449 info.minute = ((infobits[3] << 4) & 0x70) | (infobits[2] & 0x0f); 318 info.minute = ((infobits[3] << 4) & 0x70) | (infobits[2] & 0x0f);
450 info.charset = ((infobits[7] >> 1) & 7); 319 info.charset = ((infobits[7] >> 1) & 7);
451 info.delete = !!(infobits[3] & 8); 320 info.delete = !!(infobits[3] & 8);
452 info.headline = !!(infobits[5] & 4); 321 info.headline = !!(infobits[5] & 4);
453 info.subtitle = !!(infobits[5] & 8); 322 info.subtitle = !!(infobits[5] & 8);
454 info.supp_header = !!(infobits[6] & 1); 323 info.supp_header = !!(infobits[6] & 1);
455 info.update = !!(infobits[6] & 2); 324 info.update = !!(infobits[6] & 2);
456 info.inter_seq = !!(infobits[6] & 4); 325 info.inter_seq = !!(infobits[6] & 4);
457 info.dis_disp = !!(infobits[6] & 8); 326 info.dis_disp = !!(infobits[6] & 8);
458 info.serial = !!(infobits[7] & 1); 327 info.serial = !!(infobits[7] & 1);
459 info.notfound = !!(infobits[8] & 0x10); 328 info.notfound = !!(infobits[8] & 0x10);
460 info.pblf = !!(infobits[9] & 0x20); 329 info.pblf = !!(infobits[9] & 0x20);
461 info.hamming = 0; 330 info.hamming = 0;
462 for (a = 0; a <= 7; a++) 331 for (a = 0; a <= 7; a++) {
463 { 332 if (infobits[a] & 0xf0) {
464 if (infobits[a] & 0xf0) 333 info.hamming = 1;
465 { 334 break;
466 info.hamming = 1;
467 break;
468 }
469 }
470 if (t->vdau[req->pgbuf].clrfound)
471 info.notfound = 1;
472 if(copy_to_user(req->buffer, &info, sizeof(vtx_pageinfo_t)))
473 return -EFAULT;
474 if (!info.hamming && !info.notfound)
475 {
476 t->is_searching[req->pgbuf] = false;
477 } 335 }
478 return 0;
479 } 336 }
337 if (t->vdau[req->pgbuf].clrfound)
338 info.notfound = 1;
339 if (copy_to_user(req->buffer, &info, sizeof(vtx_pageinfo_t)))
340 return -EFAULT;
341 if (!info.hamming && !info.notfound)
342 t->is_searching[req->pgbuf] = false;
343 return 0;
344 }
480 345
481 case VTXIOCGETPAGE: 346 case VTXIOCGETPAGE:
482 { 347 {
483 vtx_pagereq_t *req = arg; 348 vtx_pagereq_t *req = arg;
484 int start, end; 349 int start, end;
485 350
486 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS || req->start < 0 || 351 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS || req->start < 0 ||
487 req->start > req->end || req->end >= (virtual_mode ? VTX_VIRTUALSIZE : VTX_PAGESIZE)) 352 req->start > req->end || req->end >= (virtual_mode ? VTX_VIRTUALSIZE : VTX_PAGESIZE))
488 return -EINVAL; 353 return -EINVAL;
489 if(copy_to_user(req->buffer, &t->vdau[req->pgbuf].pgbuf[req->start], req->end - req->start + 1)) 354 if (copy_to_user(req->buffer, &t->vdau[req->pgbuf].pgbuf[req->start], req->end - req->start + 1))
355 return -EFAULT;
356
357 /*
358 * Always read the time directly from SAA5249
359 */
360
361 if (req->start <= 39 && req->end >= 32) {
362 int len;
363 char buf[16];
364 start = max(req->start, 32);
365 end = min(req->end, 39);
366 len = end - start + 1;
367 if (i2c_senddata(t, 8, 0, 0, start, -1) ||
368 i2c_getdata(t, len, buf))
369 return -EIO;
370 if (copy_to_user(req->buffer + start - req->start, buf, len))
371 return -EFAULT;
372 }
373 /* Insert the current header if DAU is still searching for a page */
374 if (req->start <= 31 && req->end >= 7 && t->is_searching[req->pgbuf]) {
375 char buf[32];
376 int len;
377
378 start = max(req->start, 7);
379 end = min(req->end, 31);
380 len = end - start + 1;
381 if (i2c_senddata(t, 8, 0, 0, start, -1) ||
382 i2c_getdata(t, len, buf))
383 return -EIO;
384 if (copy_to_user(req->buffer + start - req->start, buf, len))
490 return -EFAULT; 385 return -EFAULT;
491
492 /*
493 * Always read the time directly from SAA5249
494 */
495
496 if (req->start <= 39 && req->end >= 32)
497 {
498 int len;
499 char buf[16];
500 start = max(req->start, 32);
501 end = min(req->end, 39);
502 len=end-start+1;
503 if (i2c_senddata(t, 8, 0, 0, start, -1) ||
504 i2c_getdata(t, len, buf))
505 return -EIO;
506 if(copy_to_user(req->buffer+start-req->start, buf, len))
507 return -EFAULT;
508 }
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])
511 {
512 char buf[32];
513 int len;
514 start = max(req->start, 7);
515 end = min(req->end, 31);
516 len=end-start+1;
517 if (i2c_senddata(t, 8, 0, 0, start, -1) ||
518 i2c_getdata(t, len, buf))
519 return -EIO;
520 if(copy_to_user(req->buffer+start-req->start, buf, len))
521 return -EFAULT;
522 }
523 return 0;
524 } 386 }
387 return 0;
388 }
525 389
526 case VTXIOCSTOPDAU: 390 case VTXIOCSTOPDAU:
527 { 391 {
528 vtx_pagereq_t *req = arg; 392 vtx_pagereq_t *req = arg;
529 393
530 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS) 394 if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
531 return -EINVAL; 395 return -EINVAL;
532 t->vdau[req->pgbuf].stopped = true; 396 t->vdau[req->pgbuf].stopped = true;
533 t->is_searching[req->pgbuf] = false; 397 t->is_searching[req->pgbuf] = false;
534 return 0; 398 return 0;
535 } 399 }
536 400
537 case VTXIOCPUTPAGE: 401 case VTXIOCPUTPAGE:
538 case VTXIOCSETDISP: 402 case VTXIOCSETDISP:
539 case VTXIOCPUTSTAT: 403 case VTXIOCPUTSTAT:
540 return 0; 404 return 0;
541 405
542 case VTXIOCCLRCACHE: 406 case VTXIOCCLRCACHE:
543 { 407 {
544 if (i2c_senddata(t, 0, NUM_DAUS, 0, 8, -1) || i2c_senddata(t, 11, 408 if (i2c_senddata(t, 0, NUM_DAUS, 0, 8, -1) || i2c_senddata(t, 11,
545 ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', 409 ' ', ' ', ' ', ' ', ' ', ' ',
546 ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', -1)) 410 ' ', ' ', ' ', ' ', ' ', ' ',
547 return -EIO; 411 ' ', ' ', ' ', ' ', ' ', ' ',
548 if (i2c_senddata(t, 3, 0x20, -1)) 412 ' ', ' ', ' ', ' ', ' ', ' ',
549 return -EIO; 413 -1))
550 jdelay(10 * CLEAR_DELAY); /* I have no idea how long we have to wait here */ 414 return -EIO;
551 return 0; 415 if (i2c_senddata(t, 3, 0x20, -1))
552 } 416 return -EIO;
417 jdelay(10 * CLEAR_DELAY); /* I have no idea how long we have to wait here */
418 return 0;
419 }
553 420
554 case VTXIOCSETVIRT: 421 case VTXIOCSETVIRT:
555 { 422 {
556 /* The SAA5249 has virtual-row reception turned on always */ 423 /* The SAA5249 has virtual-row reception turned on always */
557 t->virtual_mode = (int)(long)arg; 424 t->virtual_mode = (int)(long)arg;
558 return 0; 425 return 0;
559 } 426 }
560 } 427 }
561 return -EINVAL; 428 return -EINVAL;
562} 429}
@@ -616,8 +483,7 @@ static inline unsigned int vtx_fix_command(unsigned int cmd)
616static int saa5249_ioctl(struct inode *inode, struct file *file, 483static int saa5249_ioctl(struct inode *inode, struct file *file,
617 unsigned int cmd, unsigned long arg) 484 unsigned int cmd, unsigned long arg)
618{ 485{
619 struct video_device *vd = video_devdata(file); 486 struct saa5249_device *t = video_drvdata(file);
620 struct saa5249_device *t=vd->priv;
621 int err; 487 int err;
622 488
623 cmd = vtx_fix_command(cmd); 489 cmd = vtx_fix_command(cmd);
@@ -629,32 +495,27 @@ static int saa5249_ioctl(struct inode *inode, struct file *file,
629 495
630static int saa5249_open(struct inode *inode, struct file *file) 496static int saa5249_open(struct inode *inode, struct file *file)
631{ 497{
632 struct video_device *vd = video_devdata(file); 498 struct saa5249_device *t = video_drvdata(file);
633 struct saa5249_device *t=vd->priv; 499 int pgbuf;
634 int err,pgbuf;
635 500
636 err = video_exclusive_open(inode,file); 501 if (t->client == NULL)
637 if (err < 0) 502 return -ENODEV;
638 return err;
639 503
640 if (t->client==NULL) { 504 if (test_and_set_bit(0, &t->in_use))
641 err = -ENODEV; 505 return -EBUSY;
642 goto fail;
643 }
644 506
645 if (i2c_senddata(t, 0, 0, -1) || /* Select R11 */ 507 if (i2c_senddata(t, 0, 0, -1) || /* Select R11 */
646 /* Turn off parity checks (we do this ourselves) */ 508 /* Turn off parity checks (we do this ourselves) */
647 i2c_senddata(t, 1, disp_modes[t->disp_mode][0], 0, -1) || 509 i2c_senddata(t, 1, disp_modes[t->disp_mode][0], 0, -1) ||
648 /* Display TV-picture, no virtual rows */ 510 /* 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 */ 511 i2c_senddata(t, 4, NUM_DAUS, disp_modes[t->disp_mode][1], disp_modes[t->disp_mode][2], 7, -1))
650 512 /* Set display to page 4 */
651 { 513 {
652 err = -EIO; 514 clear_bit(0, &t->in_use);
653 goto fail; 515 return -EIO;
654 } 516 }
655 517
656 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) 518 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) {
657 {
658 memset(t->vdau[pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf)); 519 memset(t->vdau[pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
659 memset(t->vdau[pgbuf].sregs, 0, sizeof(t->vdau[0].sregs)); 520 memset(t->vdau[pgbuf].sregs, 0, sizeof(t->vdau[0].sregs));
660 memset(t->vdau[pgbuf].laststat, 0, sizeof(t->vdau[0].laststat)); 521 memset(t->vdau[pgbuf].laststat, 0, sizeof(t->vdau[0].laststat));
@@ -665,39 +526,20 @@ static int saa5249_open(struct inode *inode, struct file *file)
665 } 526 }
666 t->virtual_mode = false; 527 t->virtual_mode = false;
667 return 0; 528 return 0;
668
669 fail:
670 video_exclusive_release(inode,file);
671 return err;
672} 529}
673 530
674 531
675 532
676static int saa5249_release(struct inode *inode, struct file *file) 533static int saa5249_release(struct inode *inode, struct file *file)
677{ 534{
678 struct video_device *vd = video_devdata(file); 535 struct saa5249_device *t = video_drvdata(file);
679 struct saa5249_device *t=vd->priv; 536
680 i2c_senddata(t, 1, 0x20, -1); /* Turn off CCT */ 537 i2c_senddata(t, 1, 0x20, -1); /* Turn off CCT */
681 i2c_senddata(t, 5, 3, 3, -1); /* Turn off TV-display */ 538 i2c_senddata(t, 5, 3, 3, -1); /* Turn off TV-display */
682 video_exclusive_release(inode,file); 539 clear_bit(0, &t->in_use);
683 return 0; 540 return 0;
684} 541}
685 542
686static int __init init_saa_5249 (void)
687{
688 printk(KERN_INFO "SAA5249 driver (" IF_NAME " interface) for VideoText version %d.%d\n",
689 VTX_VER_MAJ, VTX_VER_MIN);
690 return i2c_add_driver(&i2c_driver_videotext);
691}
692
693static void __exit cleanup_saa_5249 (void)
694{
695 i2c_del_driver(&i2c_driver_videotext);
696}
697
698module_init(init_saa_5249);
699module_exit(cleanup_saa_5249);
700
701static const struct file_operations saa_fops = { 543static const struct file_operations saa_fops = {
702 .owner = THIS_MODULE, 544 .owner = THIS_MODULE,
703 .open = saa5249_open, 545 .open = saa5249_open,
@@ -711,8 +553,84 @@ static const struct file_operations saa_fops = {
711 553
712static struct video_device saa_template = 554static struct video_device saa_template =
713{ 555{
714 .name = IF_NAME, 556 .name = "saa5249",
715 .fops = &saa_fops, 557 .fops = &saa_fops,
558 .release = video_device_release,
716}; 559};
717 560
718MODULE_LICENSE("GPL"); 561/* Addresses to scan */
562static unsigned short normal_i2c[] = { 0x22 >> 1, I2C_CLIENT_END };
563
564I2C_CLIENT_INSMOD;
565
566static int saa5249_probe(struct i2c_client *client,
567 const struct i2c_device_id *id)
568{
569 int pgbuf;
570 int err;
571 struct video_device *vd;
572 struct saa5249_device *t;
573
574 v4l_info(client, "chip found @ 0x%x (%s)\n",
575 client->addr << 1, client->adapter->name);
576 v4l_info(client, "VideoText version %d.%d\n",
577 VTX_VER_MAJ, VTX_VER_MIN);
578 t = kzalloc(sizeof(*t), GFP_KERNEL);
579 if (t == NULL)
580 return -ENOMEM;
581 mutex_init(&t->lock);
582
583 /* Now create a video4linux device */
584 vd = kmalloc(sizeof(struct video_device), GFP_KERNEL);
585 if (vd == NULL) {
586 kfree(client);
587 return -ENOMEM;
588 }
589 i2c_set_clientdata(client, vd);
590 memcpy(vd, &saa_template, sizeof(*vd));
591
592 for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) {
593 memset(t->vdau[pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
594 memset(t->vdau[pgbuf].sregs, 0, sizeof(t->vdau[0].sregs));
595 memset(t->vdau[pgbuf].laststat, 0, sizeof(t->vdau[0].laststat));
596 t->vdau[pgbuf].expire = 0;
597 t->vdau[pgbuf].clrfound = true;
598 t->vdau[pgbuf].stopped = true;
599 t->is_searching[pgbuf] = false;
600 }
601 video_set_drvdata(vd, t);
602
603 /* Register it */
604 err = video_register_device(vd, VFL_TYPE_VTX, -1);
605 if (err < 0) {
606 kfree(t);
607 kfree(vd);
608 return err;
609 }
610 t->client = client;
611 return 0;
612}
613
614static int saa5249_remove(struct i2c_client *client)
615{
616 struct video_device *vd = i2c_get_clientdata(client);
617
618 video_unregister_device(vd);
619 kfree(video_get_drvdata(vd));
620 kfree(vd);
621 return 0;
622}
623
624static const struct i2c_device_id saa5249_id[] = {
625 { "saa5249", 0 },
626 { }
627};
628MODULE_DEVICE_TABLE(i2c, saa5249_id);
629
630static struct v4l2_i2c_driver_data v4l2_i2c_data = {
631 .name = "saa5249",
632 .driverid = I2C_DRIVERID_SAA5249,
633 .probe = saa5249_probe,
634 .remove = saa5249_remove,
635 .id_table = saa5249_id,
636};
diff --git a/drivers/media/video/saa7115.c b/drivers/media/video/saa7115.c
index ad733caec720..c8e9cb3db30a 100644
--- a/drivers/media/video/saa7115.c
+++ b/drivers/media/video/saa7115.c
@@ -1057,7 +1057,7 @@ static void saa711x_set_lcr(struct i2c_client *client, struct v4l2_sliced_vbi_fo
1057 for (i = 0; i <= 23; i++) 1057 for (i = 0; i <= 23; i++)
1058 lcr[i] = 0xff; 1058 lcr[i] = 0xff;
1059 1059
1060 if (fmt->service_set == 0) { 1060 if (fmt == NULL) {
1061 /* raw VBI */ 1061 /* raw VBI */
1062 if (is_50hz) 1062 if (is_50hz)
1063 for (i = 6; i <= 23; i++) 1063 for (i = 6; i <= 23; i++)
@@ -1113,7 +1113,7 @@ static void saa711x_set_lcr(struct i2c_client *client, struct v4l2_sliced_vbi_fo
1113 } 1113 }
1114 1114
1115 /* enable/disable raw VBI capturing */ 1115 /* enable/disable raw VBI capturing */
1116 saa711x_writeregs(client, fmt->service_set == 0 ? 1116 saa711x_writeregs(client, fmt == NULL ?
1117 saa7115_cfg_vbi_on : 1117 saa7115_cfg_vbi_on :
1118 saa7115_cfg_vbi_off); 1118 saa7115_cfg_vbi_off);
1119} 1119}
@@ -1153,6 +1153,10 @@ static int saa711x_set_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt
1153 saa711x_set_lcr(client, &fmt->fmt.sliced); 1153 saa711x_set_lcr(client, &fmt->fmt.sliced);
1154 return 0; 1154 return 0;
1155 } 1155 }
1156 if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1157 saa711x_set_lcr(client, NULL);
1158 return 0;
1159 }
1156 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1160 if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1157 return -EINVAL; 1161 return -EINVAL;
1158 1162
@@ -1309,10 +1313,13 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
1309 case VIDIOC_INT_S_VIDEO_ROUTING: 1313 case VIDIOC_INT_S_VIDEO_ROUTING:
1310 { 1314 {
1311 struct v4l2_routing *route = arg; 1315 struct v4l2_routing *route = arg;
1316 u32 input = route->input;
1317 u8 mask = (state->ident == V4L2_IDENT_SAA7111) ? 0xf8 : 0xf0;
1312 1318
1313 v4l_dbg(1, debug, client, "decoder set input %d output %d\n", route->input, route->output); 1319 v4l_dbg(1, debug, client, "decoder set input %d output %d\n", route->input, route->output);
1314 /* saa7113 does not have these inputs */ 1320 /* saa7111/3 does not have these inputs */
1315 if (state->ident == V4L2_IDENT_SAA7113 && 1321 if ((state->ident == V4L2_IDENT_SAA7113 ||
1322 state->ident == V4L2_IDENT_SAA7111) &&
1316 (route->input == SAA7115_COMPOSITE4 || 1323 (route->input == SAA7115_COMPOSITE4 ||
1317 route->input == SAA7115_COMPOSITE5)) { 1324 route->input == SAA7115_COMPOSITE5)) {
1318 return -EINVAL; 1325 return -EINVAL;
@@ -1327,10 +1334,23 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
1327 (route->input >= SAA7115_SVIDEO0) ? "S-Video" : "Composite", (route->output == SAA7115_IPORT_ON) ? "iport on" : "iport off"); 1334 (route->input >= SAA7115_SVIDEO0) ? "S-Video" : "Composite", (route->output == SAA7115_IPORT_ON) ? "iport on" : "iport off");
1328 state->input = route->input; 1335 state->input = route->input;
1329 1336
1337 /* saa7111 has slightly different input numbering */
1338 if (state->ident == V4L2_IDENT_SAA7111) {
1339 if (input >= SAA7115_COMPOSITE4)
1340 input -= 2;
1341 /* saa7111 specific */
1342 saa711x_write(client, R_10_CHROMA_CNTL_2,
1343 (saa711x_read(client, R_10_CHROMA_CNTL_2) & 0x3f) |
1344 ((route->output & 0xc0) ^ 0x40));
1345 saa711x_write(client, R_13_RT_X_PORT_OUT_CNTL,
1346 (saa711x_read(client, R_13_RT_X_PORT_OUT_CNTL) & 0xf0) |
1347 ((route->output & 2) ? 0x0a : 0));
1348 }
1349
1330 /* select mode */ 1350 /* select mode */
1331 saa711x_write(client, R_02_INPUT_CNTL_1, 1351 saa711x_write(client, R_02_INPUT_CNTL_1,
1332 (saa711x_read(client, R_02_INPUT_CNTL_1) & 0xf0) | 1352 (saa711x_read(client, R_02_INPUT_CNTL_1) & mask) |
1333 state->input); 1353 input);
1334 1354
1335 /* bypass chrominance trap for S-Video modes */ 1355 /* bypass chrominance trap for S-Video modes */
1336 saa711x_write(client, R_09_LUMA_CNTL, 1356 saa711x_write(client, R_09_LUMA_CNTL,
@@ -1384,6 +1404,13 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
1384 saa711x_writeregs(client, saa7115_cfg_reset_scaler); 1404 saa711x_writeregs(client, saa7115_cfg_reset_scaler);
1385 break; 1405 break;
1386 1406
1407 case VIDIOC_INT_S_GPIO:
1408 if (state->ident != V4L2_IDENT_SAA7111)
1409 return -EINVAL;
1410 saa711x_write(client, 0x11, (saa711x_read(client, 0x11) & 0x7f) |
1411 (*(u32 *)arg ? 0x80 : 0));
1412 break;
1413
1387 case VIDIOC_INT_G_VBI_DATA: 1414 case VIDIOC_INT_G_VBI_DATA:
1388 { 1415 {
1389 struct v4l2_sliced_vbi_data *data = arg; 1416 struct v4l2_sliced_vbi_data *data = arg;
@@ -1539,7 +1566,8 @@ static int saa7115_probe(struct i2c_client *client,
1539 state->crystal_freq = SAA7115_FREQ_32_11_MHZ; 1566 state->crystal_freq = SAA7115_FREQ_32_11_MHZ;
1540 saa711x_writeregs(client, saa7115_init_auto_input); 1567 saa711x_writeregs(client, saa7115_init_auto_input);
1541 } 1568 }
1542 saa711x_writeregs(client, saa7115_init_misc); 1569 if (state->ident != V4L2_IDENT_SAA7111)
1570 saa711x_writeregs(client, saa7115_init_misc);
1543 saa711x_set_v4lstd(client, V4L2_STD_NTSC); 1571 saa711x_set_v4lstd(client, V4L2_STD_NTSC);
1544 1572
1545 v4l_dbg(1, debug, client, "status: (1E) 0x%02x, (1F) 0x%02x\n", 1573 v4l_dbg(1, debug, client, "status: (1E) 0x%02x, (1F) 0x%02x\n",
diff --git a/drivers/media/video/saa7134/saa6752hs.c b/drivers/media/video/saa7134/saa6752hs.c
index 707be175509d..1fb6eccdade3 100644
--- a/drivers/media/video/saa7134/saa6752hs.c
+++ b/drivers/media/video/saa7134/saa6752hs.c
@@ -1,3 +1,27 @@
1 /*
2 saa6752hs - i2c-driver for the saa6752hs by Philips
3
4 Copyright (C) 2004 Andrew de Quincey
5
6 AC-3 support:
7
8 Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
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 vs published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mvss Ave, Cambridge, MA 02139, USA.
23 */
24
1#include <linux/module.h> 25#include <linux/module.h>
2#include <linux/kernel.h> 26#include <linux/kernel.h>
3#include <linux/string.h> 27#include <linux/string.h>
@@ -10,6 +34,8 @@
10#include <linux/types.h> 34#include <linux/types.h>
11#include <linux/videodev2.h> 35#include <linux/videodev2.h>
12#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
37#include <media/v4l2-chip-ident.h>
38#include <media/v4l2-i2c-drv-legacy.h>
13#include <linux/init.h> 39#include <linux/init.h>
14#include <linux/crc32.h> 40#include <linux/crc32.h>
15 41
@@ -27,9 +53,6 @@ MODULE_DESCRIPTION("device driver for saa6752hs MPEG2 encoder");
27MODULE_AUTHOR("Andrew de Quincey"); 53MODULE_AUTHOR("Andrew de Quincey");
28MODULE_LICENSE("GPL"); 54MODULE_LICENSE("GPL");
29 55
30static struct i2c_driver driver;
31static struct i2c_client client_template;
32
33enum saa6752hs_videoformat { 56enum saa6752hs_videoformat {
34 SAA6752HS_VF_D1 = 0, /* standard D1 video format: 720x576 */ 57 SAA6752HS_VF_D1 = 0, /* standard D1 video format: 720x576 */
35 SAA6752HS_VF_2_3_D1 = 1,/* 2/3D1 video format: 480x576 */ 58 SAA6752HS_VF_2_3_D1 = 1,/* 2/3D1 video format: 480x576 */
@@ -46,7 +69,9 @@ struct saa6752hs_mpeg_params {
46 __u16 ts_pid_pcr; 69 __u16 ts_pid_pcr;
47 70
48 /* audio */ 71 /* audio */
49 enum v4l2_mpeg_audio_l2_bitrate au_l2_bitrate; 72 enum v4l2_mpeg_audio_encoding au_encoding;
73 enum v4l2_mpeg_audio_l2_bitrate au_l2_bitrate;
74 enum v4l2_mpeg_audio_ac3_bitrate au_ac3_bitrate;
50 75
51 /* video */ 76 /* video */
52 enum v4l2_mpeg_video_aspect vi_aspect; 77 enum v4l2_mpeg_video_aspect vi_aspect;
@@ -70,7 +95,9 @@ static const struct v4l2_format v4l2_format_table[] =
70}; 95};
71 96
72struct saa6752hs_state { 97struct saa6752hs_state {
73 struct i2c_client client; 98 int chip;
99 u32 revision;
100 int has_ac3;
74 struct saa6752hs_mpeg_params params; 101 struct saa6752hs_mpeg_params params;
75 enum saa6752hs_videoformat video_format; 102 enum saa6752hs_videoformat video_format;
76 v4l2_std_id standard; 103 v4l2_std_id standard;
@@ -145,6 +172,39 @@ static u8 PMT[] = {
145 0x00, 0x00, 0x00, 0x00 /* CRC32 */ 172 0x00, 0x00, 0x00, 0x00 /* CRC32 */
146}; 173};
147 174
175static u8 PMT_AC3[] = {
176 0xc2, /* i2c register */
177 0x01, /* table number for encoder(1) */
178 0x47, /* sync */
179
180 0x40, /* transport_error_indicator(0), payload_unit_start(1), transport_priority(0) */
181 0x10, /* PMT PID (0x0010) */
182 0x10, /* transport_scrambling_control(00), adaptation_field_control(01), continuity_counter(0) */
183
184 0x00, /* PSI pointer to start of table */
185
186 0x02, /* TID (2) */
187 0xb0, 0x1a, /* section_syntax_indicator(1), section_length(26) */
188
189 0x00, 0x01, /* program_number(1) */
190
191 0xc1, /* version_number(0), current_next_indicator(1) */
192
193 0x00, 0x00, /* section_number(0), last_section_number(0) */
194
195 0xe1, 0x04, /* PCR_PID (0x0104) */
196
197 0xf0, 0x00, /* program_info_length(0) */
198
199 0x02, 0xe1, 0x00, 0xf0, 0x00, /* video stream type(2), pid */
200 0x06, 0xe1, 0x03, 0xf0, 0x03, /* audio stream type(6), pid */
201 0x6a, /* AC3 */
202 0x01, /* Descriptor_length(1) */
203 0x00, /* component_type_flag(0), bsid_flag(0), mainid_flag(0), asvc_flag(0), reserved flags(0) */
204
205 0xED, 0xDE, 0x2D, 0xF3 /* CRC32 BE */
206};
207
148static struct saa6752hs_mpeg_params param_defaults = 208static struct saa6752hs_mpeg_params param_defaults =
149{ 209{
150 .ts_pid_pmt = 16, 210 .ts_pid_pmt = 16,
@@ -157,12 +217,14 @@ static struct saa6752hs_mpeg_params param_defaults =
157 .vi_bitrate_peak = 6000, 217 .vi_bitrate_peak = 6000,
158 .vi_bitrate_mode = V4L2_MPEG_VIDEO_BITRATE_MODE_VBR, 218 .vi_bitrate_mode = V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
159 219
220 .au_encoding = V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
160 .au_l2_bitrate = V4L2_MPEG_AUDIO_L2_BITRATE_256K, 221 .au_l2_bitrate = V4L2_MPEG_AUDIO_L2_BITRATE_256K,
222 .au_ac3_bitrate = V4L2_MPEG_AUDIO_AC3_BITRATE_256K,
161}; 223};
162 224
163/* ---------------------------------------------------------------------- */ 225/* ---------------------------------------------------------------------- */
164 226
165static int saa6752hs_chip_command(struct i2c_client* client, 227static int saa6752hs_chip_command(struct i2c_client *client,
166 enum saa6752hs_command command) 228 enum saa6752hs_command command)
167{ 229{
168 unsigned char buf[3]; 230 unsigned char buf[3];
@@ -229,45 +291,61 @@ static int saa6752hs_chip_command(struct i2c_client* client,
229} 291}
230 292
231 293
232static int saa6752hs_set_bitrate(struct i2c_client* client, 294static inline void set_reg8(struct i2c_client *client, uint8_t reg, uint8_t val)
233 struct saa6752hs_mpeg_params* params) 295{
296 u8 buf[2];
297
298 buf[0] = reg;
299 buf[1] = val;
300 i2c_master_send(client, buf, 2);
301}
302
303static inline void set_reg16(struct i2c_client *client, uint8_t reg, uint16_t val)
234{ 304{
235 u8 buf[3]; 305 u8 buf[3];
306
307 buf[0] = reg;
308 buf[1] = val >> 8;
309 buf[2] = val & 0xff;
310 i2c_master_send(client, buf, 3);
311}
312
313static int saa6752hs_set_bitrate(struct i2c_client *client,
314 struct saa6752hs_state *h)
315{
316 struct saa6752hs_mpeg_params *params = &h->params;
236 int tot_bitrate; 317 int tot_bitrate;
318 int is_384k;
237 319
238 /* set the bitrate mode */ 320 /* set the bitrate mode */
239 buf[0] = 0x71; 321 set_reg8(client, 0x71,
240 buf[1] = (params->vi_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) ? 0 : 1; 322 params->vi_bitrate_mode != V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
241 i2c_master_send(client, buf, 2);
242 323
243 /* set the video bitrate */ 324 /* set the video bitrate */
244 if (params->vi_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) { 325 if (params->vi_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) {
245 /* set the target bitrate */ 326 /* set the target bitrate */
246 buf[0] = 0x80; 327 set_reg16(client, 0x80, params->vi_bitrate);
247 buf[1] = params->vi_bitrate >> 8;
248 buf[2] = params->vi_bitrate & 0xff;
249 i2c_master_send(client, buf, 3);
250 328
251 /* set the max bitrate */ 329 /* set the max bitrate */
252 buf[0] = 0x81; 330 set_reg16(client, 0x81, params->vi_bitrate_peak);
253 buf[1] = params->vi_bitrate_peak >> 8;
254 buf[2] = params->vi_bitrate_peak & 0xff;
255 i2c_master_send(client, buf, 3);
256 tot_bitrate = params->vi_bitrate_peak; 331 tot_bitrate = params->vi_bitrate_peak;
257 } else { 332 } else {
258 /* set the target bitrate (no max bitrate for CBR) */ 333 /* set the target bitrate (no max bitrate for CBR) */
259 buf[0] = 0x81; 334 set_reg16(client, 0x81, params->vi_bitrate);
260 buf[1] = params->vi_bitrate >> 8;
261 buf[2] = params->vi_bitrate & 0xff;
262 i2c_master_send(client, buf, 3);
263 tot_bitrate = params->vi_bitrate; 335 tot_bitrate = params->vi_bitrate;
264 } 336 }
265 337
338 /* set the audio encoding */
339 set_reg8(client, 0x93,
340 params->au_encoding == V4L2_MPEG_AUDIO_ENCODING_AC3);
341
266 /* set the audio bitrate */ 342 /* set the audio bitrate */
267 buf[0] = 0x94; 343 if (params->au_encoding == V4L2_MPEG_AUDIO_ENCODING_AC3)
268 buf[1] = (V4L2_MPEG_AUDIO_L2_BITRATE_256K == params->au_l2_bitrate) ? 0 : 1; 344 is_384k = V4L2_MPEG_AUDIO_AC3_BITRATE_384K == params->au_ac3_bitrate;
269 i2c_master_send(client, buf, 2); 345 else
270 tot_bitrate += (V4L2_MPEG_AUDIO_L2_BITRATE_256K == params->au_l2_bitrate) ? 256 : 384; 346 is_384k = V4L2_MPEG_AUDIO_L2_BITRATE_384K == params->au_l2_bitrate;
347 set_reg8(client, 0x94, is_384k);
348 tot_bitrate += is_384k ? 384 : 256;
271 349
272 /* Note: the total max bitrate is determined by adding the video and audio 350 /* Note: the total max bitrate is determined by adding the video and audio
273 bitrates together and also adding an extra 768kbit/s to stay on the 351 bitrates together and also adding an extra 768kbit/s to stay on the
@@ -278,16 +356,12 @@ static int saa6752hs_set_bitrate(struct i2c_client* client,
278 tot_bitrate = MPEG_TOTAL_TARGET_BITRATE_MAX; 356 tot_bitrate = MPEG_TOTAL_TARGET_BITRATE_MAX;
279 357
280 /* set the total bitrate */ 358 /* set the total bitrate */
281 buf[0] = 0xb1; 359 set_reg16(client, 0xb1, tot_bitrate);
282 buf[1] = tot_bitrate >> 8;
283 buf[2] = tot_bitrate & 0xff;
284 i2c_master_send(client, buf, 3);
285
286 return 0; 360 return 0;
287} 361}
288 362
289static void saa6752hs_set_subsampling(struct i2c_client* client, 363static void saa6752hs_set_subsampling(struct i2c_client *client,
290 struct v4l2_format* f) 364 struct v4l2_format *f)
291{ 365{
292 struct saa6752hs_state *h = i2c_get_clientdata(client); 366 struct saa6752hs_state *h = i2c_get_clientdata(client);
293 int dist_352, dist_480, dist_720; 367 int dist_352, dist_480, dist_720;
@@ -332,7 +406,7 @@ static void saa6752hs_set_subsampling(struct i2c_client* client,
332} 406}
333 407
334 408
335static int handle_ctrl(struct saa6752hs_mpeg_params *params, 409static int handle_ctrl(int has_ac3, struct saa6752hs_mpeg_params *params,
336 struct v4l2_ext_control *ctrl, unsigned int cmd) 410 struct v4l2_ext_control *ctrl, unsigned int cmd)
337{ 411{
338 int old = 0, new; 412 int old = 0, new;
@@ -379,8 +453,9 @@ static int handle_ctrl(struct saa6752hs_mpeg_params *params,
379 params->ts_pid_pcr = new; 453 params->ts_pid_pcr = new;
380 break; 454 break;
381 case V4L2_CID_MPEG_AUDIO_ENCODING: 455 case V4L2_CID_MPEG_AUDIO_ENCODING:
382 old = V4L2_MPEG_AUDIO_ENCODING_LAYER_2; 456 old = params->au_encoding;
383 if (set && new != old) 457 if (set && new != V4L2_MPEG_AUDIO_ENCODING_LAYER_2 &&
458 (!has_ac3 || new != V4L2_MPEG_AUDIO_ENCODING_AC3))
384 return -ERANGE; 459 return -ERANGE;
385 new = old; 460 new = old;
386 break; 461 break;
@@ -395,6 +470,19 @@ static int handle_ctrl(struct saa6752hs_mpeg_params *params,
395 new = V4L2_MPEG_AUDIO_L2_BITRATE_384K; 470 new = V4L2_MPEG_AUDIO_L2_BITRATE_384K;
396 params->au_l2_bitrate = new; 471 params->au_l2_bitrate = new;
397 break; 472 break;
473 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
474 if (!has_ac3)
475 return -EINVAL;
476 old = params->au_ac3_bitrate;
477 if (set && new != V4L2_MPEG_AUDIO_AC3_BITRATE_256K &&
478 new != V4L2_MPEG_AUDIO_AC3_BITRATE_384K)
479 return -ERANGE;
480 if (new <= V4L2_MPEG_AUDIO_AC3_BITRATE_256K)
481 new = V4L2_MPEG_AUDIO_AC3_BITRATE_256K;
482 else
483 new = V4L2_MPEG_AUDIO_AC3_BITRATE_384K;
484 params->au_ac3_bitrate = new;
485 break;
398 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: 486 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
399 old = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000; 487 old = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000;
400 if (set && new != old) 488 if (set && new != old)
@@ -448,17 +536,19 @@ static int handle_ctrl(struct saa6752hs_mpeg_params *params,
448 return 0; 536 return 0;
449} 537}
450 538
451static int saa6752hs_qctrl(struct saa6752hs_mpeg_params *params, 539static int saa6752hs_qctrl(struct saa6752hs_state *h,
452 struct v4l2_queryctrl *qctrl) 540 struct v4l2_queryctrl *qctrl)
453{ 541{
542 struct saa6752hs_mpeg_params *params = &h->params;
454 int err; 543 int err;
455 544
456 switch (qctrl->id) { 545 switch (qctrl->id) {
457 case V4L2_CID_MPEG_AUDIO_ENCODING: 546 case V4L2_CID_MPEG_AUDIO_ENCODING:
458 return v4l2_ctrl_query_fill(qctrl, 547 return v4l2_ctrl_query_fill(qctrl,
459 V4L2_MPEG_AUDIO_ENCODING_LAYER_2, 548 V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
460 V4L2_MPEG_AUDIO_ENCODING_LAYER_2, 1, 549 h->has_ac3 ? V4L2_MPEG_AUDIO_ENCODING_AC3 :
461 V4L2_MPEG_AUDIO_ENCODING_LAYER_2); 550 V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
551 1, V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
462 552
463 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: 553 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
464 return v4l2_ctrl_query_fill(qctrl, 554 return v4l2_ctrl_query_fill(qctrl,
@@ -466,6 +556,14 @@ static int saa6752hs_qctrl(struct saa6752hs_mpeg_params *params,
466 V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1, 556 V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1,
467 V4L2_MPEG_AUDIO_L2_BITRATE_256K); 557 V4L2_MPEG_AUDIO_L2_BITRATE_256K);
468 558
559 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
560 if (!h->has_ac3)
561 return -EINVAL;
562 return v4l2_ctrl_query_fill(qctrl,
563 V4L2_MPEG_AUDIO_AC3_BITRATE_256K,
564 V4L2_MPEG_AUDIO_AC3_BITRATE_384K, 1,
565 V4L2_MPEG_AUDIO_AC3_BITRATE_256K);
566
469 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: 567 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
470 return v4l2_ctrl_query_fill(qctrl, 568 return v4l2_ctrl_query_fill(qctrl,
471 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000, 569 V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000,
@@ -512,44 +610,57 @@ static int saa6752hs_qctrl(struct saa6752hs_mpeg_params *params,
512 return -EINVAL; 610 return -EINVAL;
513} 611}
514 612
515static int saa6752hs_qmenu(struct saa6752hs_mpeg_params *params, 613static int saa6752hs_qmenu(struct saa6752hs_state *h,
516 struct v4l2_querymenu *qmenu) 614 struct v4l2_querymenu *qmenu)
517{ 615{
518 static const char *mpeg_audio_l2_bitrate[] = { 616 static const u32 mpeg_audio_encoding[] = {
519 "", 617 V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
520 "", 618 V4L2_CTRL_MENU_IDS_END
521 "", 619 };
522 "", 620 static const u32 mpeg_audio_ac3_encoding[] = {
523 "", 621 V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
524 "", 622 V4L2_MPEG_AUDIO_ENCODING_AC3,
525 "", 623 V4L2_CTRL_MENU_IDS_END
526 "", 624 };
527 "", 625 static u32 mpeg_audio_l2_bitrate[] = {
528 "", 626 V4L2_MPEG_AUDIO_L2_BITRATE_256K,
529 "", 627 V4L2_MPEG_AUDIO_L2_BITRATE_384K,
530 "256 kbps", 628 V4L2_CTRL_MENU_IDS_END
531 "", 629 };
532 "384 kbps", 630 static u32 mpeg_audio_ac3_bitrate[] = {
533 NULL 631 V4L2_MPEG_AUDIO_AC3_BITRATE_256K,
632 V4L2_MPEG_AUDIO_AC3_BITRATE_384K,
633 V4L2_CTRL_MENU_IDS_END
534 }; 634 };
535 struct v4l2_queryctrl qctrl; 635 struct v4l2_queryctrl qctrl;
536 int err; 636 int err;
537 637
538 qctrl.id = qmenu->id; 638 qctrl.id = qmenu->id;
539 err = saa6752hs_qctrl(params, &qctrl); 639 err = saa6752hs_qctrl(h, &qctrl);
540 if (err) 640 if (err)
541 return err; 641 return err;
542 if (qmenu->id == V4L2_CID_MPEG_AUDIO_L2_BITRATE) 642 switch (qmenu->id) {
543 return v4l2_ctrl_query_menu(qmenu, &qctrl, 643 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
644 return v4l2_ctrl_query_menu_valid_items(qmenu,
544 mpeg_audio_l2_bitrate); 645 mpeg_audio_l2_bitrate);
545 return v4l2_ctrl_query_menu(qmenu, &qctrl, 646 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
546 v4l2_ctrl_get_menu(qmenu->id)); 647 if (!h->has_ac3)
648 return -EINVAL;
649 return v4l2_ctrl_query_menu_valid_items(qmenu,
650 mpeg_audio_ac3_bitrate);
651 case V4L2_CID_MPEG_AUDIO_ENCODING:
652 return v4l2_ctrl_query_menu_valid_items(qmenu,
653 h->has_ac3 ? mpeg_audio_ac3_encoding :
654 mpeg_audio_encoding);
655 }
656 return v4l2_ctrl_query_menu(qmenu, &qctrl, NULL);
547} 657}
548 658
549static int saa6752hs_init(struct i2c_client* client) 659static int saa6752hs_init(struct i2c_client *client, u32 leading_null_bytes)
550{ 660{
551 unsigned char buf[9], buf2[4]; 661 unsigned char buf[9], buf2[4];
552 struct saa6752hs_state *h; 662 struct saa6752hs_state *h;
663 unsigned size;
553 u32 crc; 664 u32 crc;
554 unsigned char localPAT[256]; 665 unsigned char localPAT[256];
555 unsigned char localPMT[256]; 666 unsigned char localPMT[256];
@@ -557,45 +668,31 @@ static int saa6752hs_init(struct i2c_client* client)
557 h = i2c_get_clientdata(client); 668 h = i2c_get_clientdata(client);
558 669
559 /* Set video format - must be done first as it resets other settings */ 670 /* Set video format - must be done first as it resets other settings */
560 buf[0] = 0x41; 671 set_reg8(client, 0x41, h->video_format);
561 buf[1] = h->video_format;
562 i2c_master_send(client, buf, 2);
563 672
564 /* Set number of lines in input signal */ 673 /* Set number of lines in input signal */
565 buf[0] = 0x40; 674 set_reg8(client, 0x40, (h->standard & V4L2_STD_525_60) ? 1 : 0);
566 buf[1] = 0x00;
567 if (h->standard & V4L2_STD_525_60)
568 buf[1] = 0x01;
569 i2c_master_send(client, buf, 2);
570 675
571 /* set bitrate */ 676 /* set bitrate */
572 saa6752hs_set_bitrate(client, &h->params); 677 saa6752hs_set_bitrate(client, h);
573 678
574 /* Set GOP structure {3, 13} */ 679 /* Set GOP structure {3, 13} */
575 buf[0] = 0x72; 680 set_reg16(client, 0x72, 0x030d);
576 buf[1] = 0x03;
577 buf[2] = 0x0D;
578 i2c_master_send(client,buf,3);
579 681
580 /* Set minimum Q-scale {4} */ 682 /* Set minimum Q-scale {4} */
581 buf[0] = 0x82; 683 set_reg8(client, 0x82, 0x04);
582 buf[1] = 0x04;
583 i2c_master_send(client,buf,2);
584 684
585 /* Set maximum Q-scale {12} */ 685 /* Set maximum Q-scale {12} */
586 buf[0] = 0x83; 686 set_reg8(client, 0x83, 0x0c);
587 buf[1] = 0x0C;
588 i2c_master_send(client,buf,2);
589 687
590 /* Set Output Protocol */ 688 /* Set Output Protocol */
591 buf[0] = 0xD0; 689 set_reg8(client, 0xd0, 0x81);
592 buf[1] = 0x81;
593 i2c_master_send(client,buf,2);
594 690
595 /* Set video output stream format {TS} */ 691 /* Set video output stream format {TS} */
596 buf[0] = 0xB0; 692 set_reg8(client, 0xb0, 0x05);
597 buf[1] = 0x05; 693
598 i2c_master_send(client,buf,2); 694 /* Set leading null byte for TS */
695 set_reg16(client, 0xf6, leading_null_bytes);
599 696
600 /* compute PAT */ 697 /* compute PAT */
601 memcpy(localPAT, PAT, sizeof(PAT)); 698 memcpy(localPAT, PAT, sizeof(PAT));
@@ -608,7 +705,13 @@ static int saa6752hs_init(struct i2c_client* client)
608 localPAT[sizeof(PAT) - 1] = crc & 0xFF; 705 localPAT[sizeof(PAT) - 1] = crc & 0xFF;
609 706
610 /* compute PMT */ 707 /* compute PMT */
611 memcpy(localPMT, PMT, sizeof(PMT)); 708 if (h->params.au_encoding == V4L2_MPEG_AUDIO_ENCODING_AC3) {
709 size = sizeof(PMT_AC3);
710 memcpy(localPMT, PMT_AC3, size);
711 } else {
712 size = sizeof(PMT);
713 memcpy(localPMT, PMT, size);
714 }
612 localPMT[3] = 0x40 | ((h->params.ts_pid_pmt >> 8) & 0x0f); 715 localPMT[3] = 0x40 | ((h->params.ts_pid_pmt >> 8) & 0x0f);
613 localPMT[4] = h->params.ts_pid_pmt & 0xff; 716 localPMT[4] = h->params.ts_pid_pmt & 0xff;
614 localPMT[15] = 0xE0 | ((h->params.ts_pid_pcr >> 8) & 0x0F); 717 localPMT[15] = 0xE0 | ((h->params.ts_pid_pcr >> 8) & 0x0F);
@@ -617,40 +720,28 @@ static int saa6752hs_init(struct i2c_client* client)
617 localPMT[21] = h->params.ts_pid_video & 0xFF; 720 localPMT[21] = h->params.ts_pid_video & 0xFF;
618 localPMT[25] = 0xE0 | ((h->params.ts_pid_audio >> 8) & 0x0F); 721 localPMT[25] = 0xE0 | ((h->params.ts_pid_audio >> 8) & 0x0F);
619 localPMT[26] = h->params.ts_pid_audio & 0xFF; 722 localPMT[26] = h->params.ts_pid_audio & 0xFF;
620 crc = crc32_be(~0, &localPMT[7], sizeof(PMT) - 7 - 4); 723 crc = crc32_be(~0, &localPMT[7], size - 7 - 4);
621 localPMT[sizeof(PMT) - 4] = (crc >> 24) & 0xFF; 724 localPMT[size - 4] = (crc >> 24) & 0xFF;
622 localPMT[sizeof(PMT) - 3] = (crc >> 16) & 0xFF; 725 localPMT[size - 3] = (crc >> 16) & 0xFF;
623 localPMT[sizeof(PMT) - 2] = (crc >> 8) & 0xFF; 726 localPMT[size - 2] = (crc >> 8) & 0xFF;
624 localPMT[sizeof(PMT) - 1] = crc & 0xFF; 727 localPMT[size - 1] = crc & 0xFF;
625 728
626 /* Set Audio PID */ 729 /* Set Audio PID */
627 buf[0] = 0xC1; 730 set_reg16(client, 0xc1, h->params.ts_pid_audio);
628 buf[1] = (h->params.ts_pid_audio >> 8) & 0xFF;
629 buf[2] = h->params.ts_pid_audio & 0xFF;
630 i2c_master_send(client,buf,3);
631 731
632 /* Set Video PID */ 732 /* Set Video PID */
633 buf[0] = 0xC0; 733 set_reg16(client, 0xc0, h->params.ts_pid_video);
634 buf[1] = (h->params.ts_pid_video >> 8) & 0xFF;
635 buf[2] = h->params.ts_pid_video & 0xFF;
636 i2c_master_send(client,buf,3);
637 734
638 /* Set PCR PID */ 735 /* Set PCR PID */
639 buf[0] = 0xC4; 736 set_reg16(client, 0xc4, h->params.ts_pid_pcr);
640 buf[1] = (h->params.ts_pid_pcr >> 8) & 0xFF;
641 buf[2] = h->params.ts_pid_pcr & 0xFF;
642 i2c_master_send(client,buf,3);
643 737
644 /* Send SI tables */ 738 /* Send SI tables */
645 i2c_master_send(client,localPAT,sizeof(PAT)); 739 i2c_master_send(client, localPAT, sizeof(PAT));
646 i2c_master_send(client,localPMT,sizeof(PMT)); 740 i2c_master_send(client, localPMT, size);
647 741
648 /* mute then unmute audio. This removes buzzing artefacts */ 742 /* mute then unmute audio. This removes buzzing artefacts */
649 buf[0] = 0xa4; 743 set_reg8(client, 0xa4, 1);
650 buf[1] = 1; 744 set_reg8(client, 0xa4, 0);
651 i2c_master_send(client, buf, 2);
652 buf[1] = 0;
653 i2c_master_send(client, buf, 2);
654 745
655 /* start it going */ 746 /* start it going */
656 saa6752hs_chip_command(client, SAA6752HS_COMMAND_START); 747 saa6752hs_chip_command(client, SAA6752HS_COMMAND_START);
@@ -688,45 +779,6 @@ static int saa6752hs_init(struct i2c_client* client)
688 return 0; 779 return 0;
689} 780}
690 781
691static int saa6752hs_attach(struct i2c_adapter *adap, int addr, int kind)
692{
693 struct saa6752hs_state *h;
694
695
696 if (NULL == (h = kzalloc(sizeof(*h), GFP_KERNEL)))
697 return -ENOMEM;
698 h->client = client_template;
699 h->params = param_defaults;
700 h->client.adapter = adap;
701 h->client.addr = addr;
702
703 /* Assume 625 input lines */
704 h->standard = 0;
705
706 i2c_set_clientdata(&h->client, h);
707 i2c_attach_client(&h->client);
708
709 v4l_info(&h->client,"saa6752hs: chip found @ 0x%x\n", addr<<1);
710 return 0;
711}
712
713static int saa6752hs_probe(struct i2c_adapter *adap)
714{
715 if (adap->class & I2C_CLASS_TV_ANALOG)
716 return i2c_probe(adap, &addr_data, saa6752hs_attach);
717 return 0;
718}
719
720static int saa6752hs_detach(struct i2c_client *client)
721{
722 struct saa6752hs_state *h;
723
724 h = i2c_get_clientdata(client);
725 i2c_detach_client(client);
726 kfree(h);
727 return 0;
728}
729
730static int 782static int
731saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg) 783saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
732{ 784{
@@ -737,14 +789,13 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
737 int i; 789 int i;
738 790
739 switch (cmd) { 791 switch (cmd) {
792 case VIDIOC_INT_INIT:
793 /* apply settings and start encoder */
794 saa6752hs_init(client, *(u32 *)arg);
795 break;
740 case VIDIOC_S_EXT_CTRLS: 796 case VIDIOC_S_EXT_CTRLS:
741 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG) 797 if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
742 return -EINVAL; 798 return -EINVAL;
743 if (ctrls->count == 0) {
744 /* apply settings and start encoder */
745 saa6752hs_init(client);
746 break;
747 }
748 /* fall through */ 799 /* fall through */
749 case VIDIOC_TRY_EXT_CTRLS: 800 case VIDIOC_TRY_EXT_CTRLS:
750 case VIDIOC_G_EXT_CTRLS: 801 case VIDIOC_G_EXT_CTRLS:
@@ -752,7 +803,8 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
752 return -EINVAL; 803 return -EINVAL;
753 params = h->params; 804 params = h->params;
754 for (i = 0; i < ctrls->count; i++) { 805 for (i = 0; i < ctrls->count; i++) {
755 if ((err = handle_ctrl(&params, ctrls->controls + i, cmd))) { 806 err = handle_ctrl(h->has_ac3, &params, ctrls->controls + i, cmd);
807 if (err) {
756 ctrls->error_idx = i; 808 ctrls->error_idx = i;
757 return err; 809 return err;
758 } 810 }
@@ -760,9 +812,9 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
760 h->params = params; 812 h->params = params;
761 break; 813 break;
762 case VIDIOC_QUERYCTRL: 814 case VIDIOC_QUERYCTRL:
763 return saa6752hs_qctrl(&h->params, arg); 815 return saa6752hs_qctrl(h, arg);
764 case VIDIOC_QUERYMENU: 816 case VIDIOC_QUERYMENU:
765 return saa6752hs_qmenu(&h->params, arg); 817 return saa6752hs_qmenu(h, arg);
766 case VIDIOC_G_FMT: 818 case VIDIOC_G_FMT:
767 { 819 {
768 struct v4l2_format *f = arg; 820 struct v4l2_format *f = arg;
@@ -785,6 +837,11 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
785 case VIDIOC_S_STD: 837 case VIDIOC_S_STD:
786 h->standard = *((v4l2_std_id *) arg); 838 h->standard = *((v4l2_std_id *) arg);
787 break; 839 break;
840
841 case VIDIOC_G_CHIP_IDENT:
842 return v4l2_chip_ident_i2c_client(client,
843 arg, h->chip, h->revision);
844
788 default: 845 default:
789 /* nothing */ 846 /* nothing */
790 break; 847 break;
@@ -793,36 +850,55 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
793 return err; 850 return err;
794} 851}
795 852
796/* ----------------------------------------------------------------------- */ 853static int saa6752hs_probe(struct i2c_client *client,
854 const struct i2c_device_id *id)
855{
856 struct saa6752hs_state *h = kzalloc(sizeof(*h), GFP_KERNEL);
857 u8 addr = 0x13;
858 u8 data[12];
797 859
798static struct i2c_driver driver = { 860 v4l_info(client, "chip found @ 0x%x (%s)\n",
799 .driver = { 861 client->addr << 1, client->adapter->name);
800 .name = "saa6752hs", 862 if (h == NULL)
801 }, 863 return -ENOMEM;
802 .id = I2C_DRIVERID_SAA6752HS,
803 .attach_adapter = saa6752hs_probe,
804 .detach_client = saa6752hs_detach,
805 .command = saa6752hs_command,
806};
807 864
808static struct i2c_client client_template = 865 i2c_master_send(client, &addr, 1);
809{ 866 i2c_master_recv(client, data, sizeof(data));
810 .name = "saa6752hs", 867 h->chip = V4L2_IDENT_SAA6752HS;
811 .driver = &driver, 868 h->revision = (data[8] << 8) | data[9];
812}; 869 h->has_ac3 = 0;
870 if (h->revision == 0x0206) {
871 h->chip = V4L2_IDENT_SAA6752HS_AC3;
872 h->has_ac3 = 1;
873 v4l_info(client, "support AC-3\n");
874 }
875 h->params = param_defaults;
876 h->standard = 0; /* Assume 625 input lines */
813 877
814static int __init saa6752hs_init_module(void) 878 i2c_set_clientdata(client, h);
815{ 879 return 0;
816 return i2c_add_driver(&driver);
817} 880}
818 881
819static void __exit saa6752hs_cleanup_module(void) 882static int saa6752hs_remove(struct i2c_client *client)
820{ 883{
821 i2c_del_driver(&driver); 884 kfree(i2c_get_clientdata(client));
885 return 0;
822} 886}
823 887
824module_init(saa6752hs_init_module); 888static const struct i2c_device_id saa6752hs_id[] = {
825module_exit(saa6752hs_cleanup_module); 889 { "saa6752hs", 0 },
890 { }
891};
892MODULE_DEVICE_TABLE(i2c, saa6752hs_id);
893
894static struct v4l2_i2c_driver_data v4l2_i2c_data = {
895 .name = "saa6752hs",
896 .driverid = I2C_DRIVERID_SAA6752HS,
897 .command = saa6752hs_command,
898 .probe = saa6752hs_probe,
899 .remove = saa6752hs_remove,
900 .id_table = saa6752hs_id,
901};
826 902
827/* 903/*
828 * Overrides for Emacs so that we follow Linus's tabbing style. 904 * Overrides for Emacs so that we follow Linus's tabbing style.
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 98364d171def..ddc5402c5fb0 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -3260,6 +3260,7 @@ struct saa7134_board saa7134_boards[] = {
3260 }, 3260 },
3261 [SAA7134_BOARD_HAUPPAUGE_HVR1110] = { 3261 [SAA7134_BOARD_HAUPPAUGE_HVR1110] = {
3262 /* Thomas Genty <tomlohave@gmail.com> */ 3262 /* Thomas Genty <tomlohave@gmail.com> */
3263 /* David Bentham <db260179@hotmail.com> */
3263 .name = "Hauppauge WinTV-HVR1110 DVB-T/Hybrid", 3264 .name = "Hauppauge WinTV-HVR1110 DVB-T/Hybrid",
3264 .audio_clock = 0x00187de7, 3265 .audio_clock = 0x00187de7,
3265 .tuner_type = TUNER_PHILIPS_TDA8290, 3266 .tuner_type = TUNER_PHILIPS_TDA8290,
@@ -3268,23 +3269,26 @@ struct saa7134_board saa7134_boards[] = {
3268 .radio_addr = ADDR_UNSET, 3269 .radio_addr = ADDR_UNSET,
3269 .tuner_config = 1, 3270 .tuner_config = 1,
3270 .mpeg = SAA7134_MPEG_DVB, 3271 .mpeg = SAA7134_MPEG_DVB,
3272 .gpiomask = 0x0200100,
3271 .inputs = {{ 3273 .inputs = {{
3272 .name = name_tv, 3274 .name = name_tv,
3273 .vmux = 1, 3275 .vmux = 1,
3274 .amux = TV, 3276 .amux = TV,
3275 .tv = 1, 3277 .tv = 1,
3276 },{ 3278 .gpio = 0x0000100,
3277 .name = name_comp1, 3279 }, {
3278 .vmux = 3, 3280 .name = name_comp1,
3279 .amux = LINE2, /* FIXME: audio doesn't work on svideo/composite */ 3281 .vmux = 3,
3280 },{ 3282 .amux = LINE1,
3281 .name = name_svideo, 3283 }, {
3282 .vmux = 8, 3284 .name = name_svideo,
3283 .amux = LINE2, /* FIXME: audio doesn't work on svideo/composite */ 3285 .vmux = 8,
3284 }}, 3286 .amux = LINE1,
3287 } },
3285 .radio = { 3288 .radio = {
3286 .name = name_radio, 3289 .name = name_radio,
3287 .amux = TV, 3290 .amux = TV,
3291 .gpio = 0x0200100,
3288 }, 3292 },
3289 }, 3293 },
3290 [SAA7134_BOARD_CINERGY_HT_PCMCIA] = { 3294 [SAA7134_BOARD_CINERGY_HT_PCMCIA] = {
@@ -3388,6 +3392,42 @@ struct saa7134_board saa7134_boards[] = {
3388 .amux = 0, 3392 .amux = 0,
3389 }, 3393 },
3390 }, 3394 },
3395 [SAA7134_BOARD_ENCORE_ENLTV_FM53] = {
3396 .name = "Encore ENLTV-FM v5.3",
3397 .audio_clock = 0x00200000,
3398 .tuner_type = TUNER_TNF_5335MF,
3399 .radio_type = UNSET,
3400 .tuner_addr = ADDR_UNSET,
3401 .radio_addr = ADDR_UNSET,
3402 .gpiomask = 0x7000,
3403 .inputs = { {
3404 .name = name_tv,
3405 .vmux = 1,
3406 .amux = 1,
3407 .tv = 1,
3408 .gpio = 0x50000,
3409 }, {
3410 .name = name_comp1,
3411 .vmux = 3,
3412 .amux = 2,
3413 .gpio = 0x2000,
3414 }, {
3415 .name = name_svideo,
3416 .vmux = 8,
3417 .amux = 2,
3418 .gpio = 0x2000,
3419 } },
3420 .radio = {
3421 .name = name_radio,
3422 .vmux = 1,
3423 .amux = 1,
3424 },
3425 .mute = {
3426 .name = name_mute,
3427 .gpio = 0xf000,
3428 .amux = 0,
3429 },
3430 },
3391 [SAA7134_BOARD_CINERGY_HT_PCI] = { 3431 [SAA7134_BOARD_CINERGY_HT_PCI] = {
3392 .name = "Terratec Cinergy HT PCI", 3432 .name = "Terratec Cinergy HT PCI",
3393 .audio_clock = 0x00187de7, 3433 .audio_clock = 0x00187de7,
@@ -3631,6 +3671,40 @@ struct saa7134_board saa7134_boards[] = {
3631 .tv = 1, 3671 .tv = 1,
3632 }}, 3672 }},
3633 }, 3673 },
3674 [SAA7134_BOARD_AVERMEDIA_M135A] = {
3675 .name = "Avermedia PCI pure analog (M135A)",
3676 .audio_clock = 0x00187de7,
3677 .tuner_type = TUNER_PHILIPS_TDA8290,
3678 .radio_type = UNSET,
3679 .tuner_addr = ADDR_UNSET,
3680 .radio_addr = ADDR_UNSET,
3681 .tuner_config = 2,
3682 .gpiomask = 0x020200000,
3683 .inputs = {{
3684 .name = name_tv,
3685 .vmux = 1,
3686 .amux = TV,
3687 .tv = 1,
3688 }, {
3689 .name = name_comp1,
3690 .vmux = 3,
3691 .amux = LINE1,
3692 }, {
3693 .name = name_svideo,
3694 .vmux = 8,
3695 .amux = LINE1,
3696 } },
3697 .radio = {
3698 .name = name_radio,
3699 .amux = TV,
3700 .gpio = 0x00200000,
3701 },
3702 .mute = {
3703 .name = name_mute,
3704 .amux = TV,
3705 .gpio = 0x01,
3706 },
3707 },
3634 [SAA7134_BOARD_BEHOLD_401] = { 3708 [SAA7134_BOARD_BEHOLD_401] = {
3635 /* Beholder Intl. Ltd. 2008 */ 3709 /* Beholder Intl. Ltd. 2008 */
3636 /*Dmitry Belimov <d.belimov@gmail.com> */ 3710 /*Dmitry Belimov <d.belimov@gmail.com> */
@@ -4409,6 +4483,129 @@ struct saa7134_board saa7134_boards[] = {
4409 /* no DVB support for now */ 4483 /* no DVB support for now */
4410 /* .mpeg = SAA7134_MPEG_DVB, */ 4484 /* .mpeg = SAA7134_MPEG_DVB, */
4411 }, 4485 },
4486 [SAA7134_BOARD_ASUSTeK_TIGER_3IN1] = {
4487 .name = "Asus Tiger 3in1",
4488 .audio_clock = 0x00187de7,
4489 .tuner_type = TUNER_PHILIPS_TDA8290,
4490 .radio_type = UNSET,
4491 .tuner_addr = ADDR_UNSET,
4492 .radio_addr = ADDR_UNSET,
4493 .tuner_config = 2,
4494 .gpiomask = 1 << 21,
4495 .mpeg = SAA7134_MPEG_DVB,
4496 .inputs = {{
4497 .name = name_tv,
4498 .vmux = 1,
4499 .amux = TV,
4500 .tv = 1,
4501 }, {
4502 .name = name_comp,
4503 .vmux = 0,
4504 .amux = LINE2,
4505 }, {
4506 .name = name_svideo,
4507 .vmux = 8,
4508 .amux = LINE2,
4509 } },
4510 .radio = {
4511 .name = name_radio,
4512 .amux = TV,
4513 .gpio = 0x0200000,
4514 },
4515 },
4516 [SAA7134_BOARD_REAL_ANGEL_220] = {
4517 .name = "Zogis Real Angel 220",
4518 .audio_clock = 0x00187de7,
4519 .tuner_type = TUNER_TNF_5335MF,
4520 .radio_type = UNSET,
4521 .tuner_addr = ADDR_UNSET,
4522 .radio_addr = ADDR_UNSET,
4523 .gpiomask = 0x801a8087,
4524 .inputs = { {
4525 .name = name_tv,
4526 .vmux = 3,
4527 .amux = LINE2,
4528 .tv = 1,
4529 .gpio = 0x624000,
4530 }, {
4531 .name = name_comp1,
4532 .vmux = 1,
4533 .amux = LINE1,
4534 .gpio = 0x624000,
4535 }, {
4536 .name = name_svideo,
4537 .vmux = 1,
4538 .amux = LINE1,
4539 .gpio = 0x624000,
4540 } },
4541 .radio = {
4542 .name = name_radio,
4543 .amux = LINE2,
4544 .gpio = 0x624001,
4545 },
4546 .mute = {
4547 .name = name_mute,
4548 .amux = TV,
4549 },
4550 },
4551 [SAA7134_BOARD_ADS_INSTANT_HDTV_PCI] = {
4552 .name = "ADS Tech Instant HDTV",
4553 .audio_clock = 0x00187de7,
4554 .tuner_type = TUNER_PHILIPS_TUV1236D,
4555 .radio_type = UNSET,
4556 .tuner_addr = ADDR_UNSET,
4557 .radio_addr = ADDR_UNSET,
4558 .tda9887_conf = TDA9887_PRESENT,
4559 .mpeg = SAA7134_MPEG_DVB,
4560 .inputs = { {
4561 .name = name_tv,
4562 .vmux = 1,
4563 .amux = TV,
4564 .tv = 1,
4565 }, {
4566 .name = name_comp,
4567 .vmux = 4,
4568 .amux = LINE1,
4569 }, {
4570 .name = name_svideo,
4571 .vmux = 8,
4572 .amux = LINE1,
4573 } },
4574 },
4575 [SAA7134_BOARD_ASUSTeK_TIGER] = {
4576 .name = "Asus Tiger Rev:1.00",
4577 .audio_clock = 0x00187de7,
4578 .tuner_type = TUNER_PHILIPS_TDA8290,
4579 .radio_type = UNSET,
4580 .tuner_addr = ADDR_UNSET,
4581 .radio_addr = ADDR_UNSET,
4582 .tuner_config = 0,
4583 .mpeg = SAA7134_MPEG_DVB,
4584 .gpiomask = 0x0200000,
4585 .inputs = { {
4586 .name = name_tv,
4587 .vmux = 1,
4588 .amux = TV,
4589 .tv = 1,
4590 }, {
4591 .name = name_comp1,
4592 .vmux = 3,
4593 .amux = LINE2,
4594 }, {
4595 .name = name_comp2,
4596 .vmux = 0,
4597 .amux = LINE2,
4598 }, {
4599 .name = name_svideo,
4600 .vmux = 8,
4601 .amux = LINE2,
4602 } },
4603 .radio = {
4604 .name = name_radio,
4605 .amux = TV,
4606 .gpio = 0x0200000,
4607 },
4608 },
4412}; 4609};
4413 4610
4414const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards); 4611const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
@@ -4777,6 +4974,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
4777 4974
4778 },{ 4975 },{
4779 .vendor = PCI_VENDOR_ID_PHILIPS, 4976 .vendor = PCI_VENDOR_ID_PHILIPS,
4977 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4978 .subvendor = 0x1461, /* Avermedia Technologies Inc */
4979 .subdevice = 0xf11d,
4980 .driver_data = SAA7134_BOARD_AVERMEDIA_M135A,
4981 }, {
4982 .vendor = PCI_VENDOR_ID_PHILIPS,
4780 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 4983 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
4781 .subvendor = PCI_VENDOR_ID_PHILIPS, 4984 .subvendor = PCI_VENDOR_ID_PHILIPS,
4782 .subdevice = 0x2004, 4985 .subdevice = 0x2004,
@@ -5157,6 +5360,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
5157 .driver_data = SAA7134_BOARD_ENCORE_ENLTV_FM, 5360 .driver_data = SAA7134_BOARD_ENCORE_ENLTV_FM,
5158 },{ 5361 },{
5159 .vendor = PCI_VENDOR_ID_PHILIPS, 5362 .vendor = PCI_VENDOR_ID_PHILIPS,
5363 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
5364 .subvendor = 0x1a7f,
5365 .subdevice = 0x2008,
5366 .driver_data = SAA7134_BOARD_ENCORE_ENLTV_FM53,
5367 }, {
5368 .vendor = PCI_VENDOR_ID_PHILIPS,
5160 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 5369 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5161 .subvendor = 0x153b, 5370 .subvendor = 0x153b,
5162 .subdevice = 0x1175, 5371 .subdevice = 0x1175,
@@ -5183,8 +5392,8 @@ struct pci_device_id saa7134_pci_tbl[] = {
5183 .vendor = PCI_VENDOR_ID_PHILIPS, 5392 .vendor = PCI_VENDOR_ID_PHILIPS,
5184 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 5393 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5185 .subvendor = 0x1043, 5394 .subvendor = 0x1043,
5186 .subdevice = 0x4857, 5395 .subdevice = 0x4857, /* REV:1.00 */
5187 .driver_data = SAA7134_BOARD_ASUSTeK_P7131_DUAL, 5396 .driver_data = SAA7134_BOARD_ASUSTeK_TIGER,
5188 },{ 5397 },{
5189 .vendor = PCI_VENDOR_ID_PHILIPS, 5398 .vendor = PCI_VENDOR_ID_PHILIPS,
5190 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 5399 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -5415,6 +5624,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
5415 .driver_data = SAA7134_BOARD_VIDEOMATE_T750, 5624 .driver_data = SAA7134_BOARD_VIDEOMATE_T750,
5416 }, { 5625 }, {
5417 .vendor = PCI_VENDOR_ID_PHILIPS, 5626 .vendor = PCI_VENDOR_ID_PHILIPS,
5627 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, /* SAA7135HL */
5628 .subvendor = 0x1421,
5629 .subdevice = 0x0380,
5630 .driver_data = SAA7134_BOARD_ADS_INSTANT_HDTV_PCI,
5631 }, {
5632 .vendor = PCI_VENDOR_ID_PHILIPS,
5418 .device = PCI_DEVICE_ID_PHILIPS_SAA7133, 5633 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5419 .subvendor = 0x5169, 5634 .subvendor = 0x5169,
5420 .subdevice = 0x1502, 5635 .subdevice = 0x1502,
@@ -5432,6 +5647,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
5432 .subdevice = 0xf636, 5647 .subdevice = 0xf636,
5433 .driver_data = SAA7134_BOARD_AVERMEDIA_M103, 5648 .driver_data = SAA7134_BOARD_AVERMEDIA_M103,
5434 }, { 5649 }, {
5650 .vendor = PCI_VENDOR_ID_PHILIPS,
5651 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5652 .subvendor = 0x1043,
5653 .subdevice = 0x4878, /* REV:1.02G */
5654 .driver_data = SAA7134_BOARD_ASUSTeK_TIGER_3IN1,
5655 }, {
5435 /* --- boards without eeprom + subsystem ID --- */ 5656 /* --- boards without eeprom + subsystem ID --- */
5436 .vendor = PCI_VENDOR_ID_PHILIPS, 5657 .vendor = PCI_VENDOR_ID_PHILIPS,
5437 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 5658 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -5540,7 +5761,7 @@ static int saa7134_tda8290_callback(struct saa7134_dev *dev,
5540 return 0; 5761 return 0;
5541} 5762}
5542 5763
5543int saa7134_tuner_callback(void *priv, int command, int arg) 5764int saa7134_tuner_callback(void *priv, int component, int command, int arg)
5544{ 5765{
5545 struct saa7134_dev *dev = priv; 5766 struct saa7134_dev *dev = priv;
5546 if (dev != NULL) { 5767 if (dev != NULL) {
@@ -5620,6 +5841,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
5620 case SAA7134_BOARD_AVERMEDIA_STUDIO_507: 5841 case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
5621 case SAA7134_BOARD_AVERMEDIA_GO_007_FM: 5842 case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
5622 case SAA7134_BOARD_AVERMEDIA_777: 5843 case SAA7134_BOARD_AVERMEDIA_777:
5844 case SAA7134_BOARD_AVERMEDIA_M135A:
5623/* case SAA7134_BOARD_SABRENT_SBTTVFM: */ /* not finished yet */ 5845/* case SAA7134_BOARD_SABRENT_SBTTVFM: */ /* not finished yet */
5624 case SAA7134_BOARD_VIDEOMATE_TV_PVR: 5846 case SAA7134_BOARD_VIDEOMATE_TV_PVR:
5625 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS: 5847 case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
@@ -5644,6 +5866,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
5644 case SAA7134_BOARD_AVERMEDIA_A16AR: 5866 case SAA7134_BOARD_AVERMEDIA_A16AR:
5645 case SAA7134_BOARD_ENCORE_ENLTV: 5867 case SAA7134_BOARD_ENCORE_ENLTV:
5646 case SAA7134_BOARD_ENCORE_ENLTV_FM: 5868 case SAA7134_BOARD_ENCORE_ENLTV_FM:
5869 case SAA7134_BOARD_ENCORE_ENLTV_FM53:
5647 case SAA7134_BOARD_10MOONSTVMASTER3: 5870 case SAA7134_BOARD_10MOONSTVMASTER3:
5648 case SAA7134_BOARD_BEHOLD_401: 5871 case SAA7134_BOARD_BEHOLD_401:
5649 case SAA7134_BOARD_BEHOLD_403: 5872 case SAA7134_BOARD_BEHOLD_403:
@@ -5656,6 +5879,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
5656 case SAA7134_BOARD_BEHOLD_505FM: 5879 case SAA7134_BOARD_BEHOLD_505FM:
5657 case SAA7134_BOARD_BEHOLD_507_9FM: 5880 case SAA7134_BOARD_BEHOLD_507_9FM:
5658 case SAA7134_BOARD_GENIUS_TVGO_A11MCE: 5881 case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
5882 case SAA7134_BOARD_REAL_ANGEL_220:
5659 dev->has_remote = SAA7134_REMOTE_GPIO; 5883 dev->has_remote = SAA7134_REMOTE_GPIO;
5660 break; 5884 break;
5661 case SAA7134_BOARD_FLYDVBS_LR300: 5885 case SAA7134_BOARD_FLYDVBS_LR300:
@@ -5745,6 +5969,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
5745 case SAA7134_BOARD_PINNACLE_PCTV_110i: 5969 case SAA7134_BOARD_PINNACLE_PCTV_110i:
5746 case SAA7134_BOARD_PINNACLE_PCTV_310i: 5970 case SAA7134_BOARD_PINNACLE_PCTV_310i:
5747 case SAA7134_BOARD_UPMOST_PURPLE_TV: 5971 case SAA7134_BOARD_UPMOST_PURPLE_TV:
5972 case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
5748 case SAA7134_BOARD_HAUPPAUGE_HVR1110: 5973 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
5749 case SAA7134_BOARD_BEHOLD_607_9FM: 5974 case SAA7134_BOARD_BEHOLD_607_9FM:
5750 case SAA7134_BOARD_BEHOLD_M6: 5975 case SAA7134_BOARD_BEHOLD_M6:
@@ -5987,6 +6212,7 @@ int saa7134_board_init2(struct saa7134_dev *dev)
5987 case SAA7134_BOARD_PINNACLE_PCTV_310i: 6212 case SAA7134_BOARD_PINNACLE_PCTV_310i:
5988 case SAA7134_BOARD_KWORLD_DVBT_210: 6213 case SAA7134_BOARD_KWORLD_DVBT_210:
5989 case SAA7134_BOARD_TEVION_DVBT_220RF: 6214 case SAA7134_BOARD_TEVION_DVBT_220RF:
6215 case SAA7134_BOARD_ASUSTeK_TIGER:
5990 case SAA7134_BOARD_ASUSTeK_P7131_DUAL: 6216 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
5991 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA: 6217 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
5992 case SAA7134_BOARD_MEDION_MD8800_QUADRO: 6218 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
@@ -6002,6 +6228,14 @@ int saa7134_board_init2(struct saa7134_dev *dev)
6002 i2c_transfer(&dev->i2c_adap, &msg, 1); 6228 i2c_transfer(&dev->i2c_adap, &msg, 1);
6003 break; 6229 break;
6004 } 6230 }
6231 case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:
6232 {
6233 u8 data[] = { 0x3c, 0x33, 0x60};
6234 struct i2c_msg msg = {.addr = 0x0b, .flags = 0, .buf = data,
6235 .len = sizeof(data)};
6236 i2c_transfer(&dev->i2c_adap, &msg, 1);
6237 break;
6238 }
6005 case SAA7134_BOARD_FLYDVB_TRIO: 6239 case SAA7134_BOARD_FLYDVB_TRIO:
6006 { 6240 {
6007 u8 data[] = { 0x3c, 0x33, 0x62}; 6241 u8 data[] = { 0x3c, 0x33, 0x62};
@@ -6027,6 +6261,7 @@ int saa7134_board_init2(struct saa7134_dev *dev)
6027 i2c_transfer(&dev->i2c_adap, &msg, 1); 6261 i2c_transfer(&dev->i2c_adap, &msg, 1);
6028 break; 6262 break;
6029 } 6263 }
6264 case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
6030 case SAA7134_BOARD_KWORLD_ATSC110: 6265 case SAA7134_BOARD_KWORLD_ATSC110:
6031 { 6266 {
6032 /* enable tuner */ 6267 /* enable tuner */
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index 75d618415f4f..b686bfabbde0 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -215,7 +215,7 @@ unsigned long saa7134_buffer_base(struct saa7134_buf *buf)
215int saa7134_pgtable_alloc(struct pci_dev *pci, struct saa7134_pgtable *pt) 215int saa7134_pgtable_alloc(struct pci_dev *pci, struct saa7134_pgtable *pt)
216{ 216{
217 __le32 *cpu; 217 __le32 *cpu;
218 dma_addr_t dma_addr; 218 dma_addr_t dma_addr = 0;
219 219
220 cpu = pci_alloc_consistent(pci, SAA7134_PGTABLE_SIZE, &dma_addr); 220 cpu = pci_alloc_consistent(pci, SAA7134_PGTABLE_SIZE, &dma_addr);
221 if (NULL == cpu) 221 if (NULL == cpu)
@@ -359,32 +359,6 @@ void saa7134_buffer_timeout(unsigned long data)
359 spin_unlock_irqrestore(&dev->slock,flags); 359 spin_unlock_irqrestore(&dev->slock,flags);
360} 360}
361 361
362/* resends a current buffer in queue after resume */
363
364static int saa7134_buffer_requeue(struct saa7134_dev *dev,
365 struct saa7134_dmaqueue *q)
366{
367 struct saa7134_buf *buf, *next;
368
369 assert_spin_locked(&dev->slock);
370
371 buf = q->curr;
372 next = buf;
373 dprintk("buffer_requeue\n");
374
375 if (!buf)
376 return 0;
377
378 dprintk("buffer_requeue : resending active buffers \n");
379
380 if (!list_empty(&q->queue))
381 next = list_entry(q->queue.next, struct saa7134_buf,
382 vb.queue);
383 buf->activate(dev, buf, next);
384
385 return 0;
386}
387
388/* ------------------------------------------------------------------ */ 362/* ------------------------------------------------------------------ */
389 363
390int saa7134_set_dmabits(struct saa7134_dev *dev) 364int saa7134_set_dmabits(struct saa7134_dev *dev)
@@ -442,9 +416,7 @@ int saa7134_set_dmabits(struct saa7134_dev *dev)
442 /* TS capture -- dma 5 */ 416 /* TS capture -- dma 5 */
443 if (dev->ts_q.curr) { 417 if (dev->ts_q.curr) {
444 ctrl |= SAA7134_MAIN_CTRL_TE5; 418 ctrl |= SAA7134_MAIN_CTRL_TE5;
445 irq |= SAA7134_IRQ1_INTE_RA2_3 | 419 irq |= SAA7134_IRQ1_INTE_RA2_1 |
446 SAA7134_IRQ1_INTE_RA2_2 |
447 SAA7134_IRQ1_INTE_RA2_1 |
448 SAA7134_IRQ1_INTE_RA2_0; 420 SAA7134_IRQ1_INTE_RA2_0;
449 } 421 }
450 422
@@ -727,6 +699,10 @@ static int saa7134_hw_enable2(struct saa7134_dev *dev)
727 irq2_mask |= SAA7134_IRQ2_INTE_GPIO18A; 699 irq2_mask |= SAA7134_IRQ2_INTE_GPIO18A;
728 } 700 }
729 701
702 if (dev->has_remote == SAA7134_REMOTE_I2C) {
703 request_module("ir-kbd-i2c");
704 }
705
730 saa_writel(SAA7134_IRQ1, 0); 706 saa_writel(SAA7134_IRQ1, 0);
731 saa_writel(SAA7134_IRQ2, irq2_mask); 707 saa_writel(SAA7134_IRQ2, irq2_mask);
732 708
@@ -1139,6 +1115,32 @@ static void __devexit saa7134_finidev(struct pci_dev *pci_dev)
1139} 1115}
1140 1116
1141#ifdef CONFIG_PM 1117#ifdef CONFIG_PM
1118
1119/* resends a current buffer in queue after resume */
1120static int saa7134_buffer_requeue(struct saa7134_dev *dev,
1121 struct saa7134_dmaqueue *q)
1122{
1123 struct saa7134_buf *buf, *next;
1124
1125 assert_spin_locked(&dev->slock);
1126
1127 buf = q->curr;
1128 next = buf;
1129 dprintk("buffer_requeue\n");
1130
1131 if (!buf)
1132 return 0;
1133
1134 dprintk("buffer_requeue : resending active buffers \n");
1135
1136 if (!list_empty(&q->queue))
1137 next = list_entry(q->queue.next, struct saa7134_buf,
1138 vb.queue);
1139 buf->activate(dev, buf, next);
1140
1141 return 0;
1142}
1143
1142static int saa7134_suspend(struct pci_dev *pci_dev , pm_message_t state) 1144static int saa7134_suspend(struct pci_dev *pci_dev , pm_message_t state)
1143{ 1145{
1144 1146
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index be48b9b66a67..87c10983266f 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -553,7 +553,6 @@ static int configure_tda827x_fe(struct saa7134_dev *dev,
553/* ------------------------------------------------------------------ */ 553/* ------------------------------------------------------------------ */
554 554
555static struct tda827x_config tda827x_cfg_0 = { 555static struct tda827x_config tda827x_cfg_0 = {
556 .tuner_callback = saa7134_tuner_callback,
557 .init = philips_tda827x_tuner_init, 556 .init = philips_tda827x_tuner_init,
558 .sleep = philips_tda827x_tuner_sleep, 557 .sleep = philips_tda827x_tuner_sleep,
559 .config = 0, 558 .config = 0,
@@ -561,7 +560,6 @@ static struct tda827x_config tda827x_cfg_0 = {
561}; 560};
562 561
563static struct tda827x_config tda827x_cfg_1 = { 562static struct tda827x_config tda827x_cfg_1 = {
564 .tuner_callback = saa7134_tuner_callback,
565 .init = philips_tda827x_tuner_init, 563 .init = philips_tda827x_tuner_init,
566 .sleep = philips_tda827x_tuner_sleep, 564 .sleep = philips_tda827x_tuner_sleep,
567 .config = 1, 565 .config = 1,
@@ -569,7 +567,6 @@ static struct tda827x_config tda827x_cfg_1 = {
569}; 567};
570 568
571static struct tda827x_config tda827x_cfg_2 = { 569static struct tda827x_config tda827x_cfg_2 = {
572 .tuner_callback = saa7134_tuner_callback,
573 .init = philips_tda827x_tuner_init, 570 .init = philips_tda827x_tuner_init,
574 .sleep = philips_tda827x_tuner_sleep, 571 .sleep = philips_tda827x_tuner_sleep,
575 .config = 2, 572 .config = 2,
@@ -577,7 +574,6 @@ static struct tda827x_config tda827x_cfg_2 = {
577}; 574};
578 575
579static struct tda827x_config tda827x_cfg_2_sw42 = { 576static struct tda827x_config tda827x_cfg_2_sw42 = {
580 .tuner_callback = saa7134_tuner_callback,
581 .init = philips_tda827x_tuner_init, 577 .init = philips_tda827x_tuner_init,
582 .sleep = philips_tda827x_tuner_sleep, 578 .sleep = philips_tda827x_tuner_sleep,
583 .config = 2, 579 .config = 2,
@@ -799,6 +795,20 @@ static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
799 .request_firmware = philips_tda1004x_request_firmware 795 .request_firmware = philips_tda1004x_request_firmware
800}; 796};
801 797
798static struct tda1004x_config asus_tiger_3in1_config = {
799 .demod_address = 0x0b,
800 .invert = 1,
801 .invert_oclk = 0,
802 .xtal_freq = TDA10046_XTAL_16M,
803 .agc_config = TDA10046_AGC_TDA827X,
804 .gpio_config = TDA10046_GP11_I,
805 .if_freq = TDA10046_FREQ_045,
806 .i2c_gate = 0x4b,
807 .tuner_address = 0x61,
808 .antenna_switch = 1,
809 .request_firmware = philips_tda1004x_request_firmware
810};
811
802/* ------------------------------------------------------------------ 812/* ------------------------------------------------------------------
803 * special case: this card uses saa713x GPIO22 for the mode switch 813 * special case: this card uses saa713x GPIO22 for the mode switch
804 */ 814 */
@@ -822,7 +832,6 @@ static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
822} 832}
823 833
824static struct tda827x_config ads_duo_cfg = { 834static struct tda827x_config ads_duo_cfg = {
825 .tuner_callback = saa7134_tuner_callback,
826 .init = ads_duo_tuner_init, 835 .init = ads_duo_tuner_init,
827 .sleep = ads_duo_tuner_sleep, 836 .sleep = ads_duo_tuner_sleep,
828 .config = 0 837 .config = 0
@@ -1147,6 +1156,7 @@ static int dvb_init(struct saa7134_dev *dev)
1147 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61, 1156 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
1148 NULL, DVB_PLL_TDHU2); 1157 NULL, DVB_PLL_TDHU2);
1149 break; 1158 break;
1159 case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
1150 case SAA7134_BOARD_KWORLD_ATSC110: 1160 case SAA7134_BOARD_KWORLD_ATSC110:
1151 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110, 1161 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1152 &dev->i2c_adap); 1162 &dev->i2c_adap);
@@ -1300,6 +1310,36 @@ static int dvb_init(struct saa7134_dev *dev)
1300 &dev->i2c_adap); 1310 &dev->i2c_adap);
1301 attach_xc3028 = 1; 1311 attach_xc3028 = 1;
1302 break; 1312 break;
1313 case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:
1314 if (!use_frontend) { /* terrestrial */
1315 if (configure_tda827x_fe(dev, &asus_tiger_3in1_config,
1316 &tda827x_cfg_2) < 0)
1317 goto dettach_frontend;
1318 } else { /* satellite */
1319 dev->dvb.frontend = dvb_attach(tda10086_attach,
1320 &flydvbs, &dev->i2c_adap);
1321 if (dev->dvb.frontend) {
1322 if (dvb_attach(tda826x_attach,
1323 dev->dvb.frontend, 0x60,
1324 &dev->i2c_adap, 0) == NULL) {
1325 wprintk("%s: Asus Tiger 3in1, no "
1326 "tda826x found!\n", __func__);
1327 goto dettach_frontend;
1328 }
1329 if (dvb_attach(lnbp21_attach, dev->dvb.frontend,
1330 &dev->i2c_adap, 0, 0) == NULL) {
1331 wprintk("%s: Asus Tiger 3in1, no lnbp21"
1332 " found!\n", __func__);
1333 goto dettach_frontend;
1334 }
1335 }
1336 }
1337 break;
1338 case SAA7134_BOARD_ASUSTeK_TIGER:
1339 if (configure_tda827x_fe(dev, &philips_tiger_config,
1340 &tda827x_cfg_0) < 0)
1341 goto dettach_frontend;
1342 break;
1303 default: 1343 default:
1304 wprintk("Huh? unknown DVB card?\n"); 1344 wprintk("Huh? unknown DVB card?\n");
1305 break; 1345 break;
@@ -1327,6 +1367,8 @@ static int dvb_init(struct saa7134_dev *dev)
1327 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name); 1367 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
1328 return -1; 1368 return -1;
1329 } 1369 }
1370 /* define general-purpose callback pointer */
1371 dev->dvb.frontend->callback = saa7134_tuner_callback;
1330 1372
1331 /* register everything else */ 1373 /* register everything else */
1332 ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev, 1374 ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev,
diff --git a/drivers/media/video/saa7134/saa7134-empress.c b/drivers/media/video/saa7134/saa7134-empress.c
index c0c5d7509c25..9a8766a78a0c 100644
--- a/drivers/media/video/saa7134/saa7134-empress.c
+++ b/drivers/media/video/saa7134/saa7134-empress.c
@@ -29,6 +29,7 @@
29 29
30#include <media/saa6752hs.h> 30#include <media/saa6752hs.h>
31#include <media/v4l2-common.h> 31#include <media/v4l2-common.h>
32#include <media/v4l2-chip-ident.h>
32 33
33/* ------------------------------------------------------------------ */ 34/* ------------------------------------------------------------------ */
34 35
@@ -63,10 +64,19 @@ static void ts_reset_encoder(struct saa7134_dev* dev)
63 64
64static int ts_init_encoder(struct saa7134_dev* dev) 65static int ts_init_encoder(struct saa7134_dev* dev)
65{ 66{
66 struct v4l2_ext_controls ctrls = { V4L2_CTRL_CLASS_MPEG, 0 }; 67 u32 leading_null_bytes = 0;
67 68
69 /* If more cards start to need this, then this
70 should probably be added to the card definitions. */
71 switch (dev->board) {
72 case SAA7134_BOARD_BEHOLD_M6:
73 case SAA7134_BOARD_BEHOLD_M63:
74 case SAA7134_BOARD_BEHOLD_M6_EXTRA:
75 leading_null_bytes = 1;
76 break;
77 }
68 ts_reset_encoder(dev); 78 ts_reset_encoder(dev);
69 saa7134_i2c_call_clients(dev, VIDIOC_S_EXT_CTRLS, &ctrls); 79 saa7134_i2c_call_clients(dev, VIDIOC_INT_INIT, &leading_null_bytes);
70 dev->empress_started = 1; 80 dev->empress_started = 1;
71 return 0; 81 return 0;
72} 82}
@@ -79,9 +89,11 @@ static int ts_open(struct inode *inode, struct file *file)
79 struct saa7134_dev *dev; 89 struct saa7134_dev *dev;
80 int err; 90 int err;
81 91
92 lock_kernel();
82 list_for_each_entry(dev, &saa7134_devlist, devlist) 93 list_for_each_entry(dev, &saa7134_devlist, devlist)
83 if (dev->empress_dev && dev->empress_dev->minor == minor) 94 if (dev->empress_dev && dev->empress_dev->minor == minor)
84 goto found; 95 goto found;
96 unlock_kernel();
85 return -ENODEV; 97 return -ENODEV;
86 found: 98 found:
87 99
@@ -103,6 +115,7 @@ static int ts_open(struct inode *inode, struct file *file)
103done_up: 115done_up:
104 mutex_unlock(&dev->empress_tsq.vb_lock); 116 mutex_unlock(&dev->empress_tsq.vb_lock);
105done: 117done:
118 unlock_kernel();
106 return err; 119 return err;
107} 120}
108 121
@@ -290,15 +303,6 @@ static int empress_streamoff(struct file *file, void *priv,
290 return videobuf_streamoff(&dev->empress_tsq); 303 return videobuf_streamoff(&dev->empress_tsq);
291} 304}
292 305
293static int saa7134_i2c_call_saa6752(struct saa7134_dev *dev,
294 unsigned int cmd, void *arg)
295{
296 if (dev->mpeg_i2c_client == NULL)
297 return -EINVAL;
298 return dev->mpeg_i2c_client->driver->command(dev->mpeg_i2c_client,
299 cmd, arg);
300}
301
302static int empress_s_ext_ctrls(struct file *file, void *priv, 306static int empress_s_ext_ctrls(struct file *file, void *priv,
303 struct v4l2_ext_controls *ctrls) 307 struct v4l2_ext_controls *ctrls)
304{ 308{
@@ -400,6 +404,39 @@ static int empress_querymenu(struct file *file, void *priv,
400 return saa7134_i2c_call_saa6752(dev, VIDIOC_QUERYMENU, c); 404 return saa7134_i2c_call_saa6752(dev, VIDIOC_QUERYMENU, c);
401} 405}
402 406
407static int empress_g_chip_ident(struct file *file, void *fh,
408 struct v4l2_chip_ident *chip)
409{
410 struct saa7134_dev *dev = file->private_data;
411
412 chip->ident = V4L2_IDENT_NONE;
413 chip->revision = 0;
414 if (dev->mpeg_i2c_client == NULL)
415 return -EINVAL;
416 if (chip->match_type == V4L2_CHIP_MATCH_I2C_DRIVER &&
417 chip->match_chip == I2C_DRIVERID_SAA6752HS)
418 return saa7134_i2c_call_saa6752(dev, VIDIOC_G_CHIP_IDENT, chip);
419 if (chip->match_type == V4L2_CHIP_MATCH_I2C_ADDR &&
420 chip->match_chip == dev->mpeg_i2c_client->addr)
421 return saa7134_i2c_call_saa6752(dev, VIDIOC_G_CHIP_IDENT, chip);
422 return -EINVAL;
423}
424
425static int empress_s_std(struct file *file, void *priv, v4l2_std_id *id)
426{
427 struct saa7134_dev *dev = file->private_data;
428
429 return saa7134_s_std_internal(dev, NULL, id);
430}
431
432static int empress_g_std(struct file *file, void *priv, v4l2_std_id *id)
433{
434 struct saa7134_dev *dev = file->private_data;
435
436 *id = dev->tvnorm->id;
437 return 0;
438}
439
403static const struct file_operations ts_fops = 440static const struct file_operations ts_fops =
404{ 441{
405 .owner = THIS_MODULE, 442 .owner = THIS_MODULE,
@@ -428,11 +465,13 @@ static const struct v4l2_ioctl_ops ts_ioctl_ops = {
428 .vidioc_enum_input = empress_enum_input, 465 .vidioc_enum_input = empress_enum_input,
429 .vidioc_g_input = empress_g_input, 466 .vidioc_g_input = empress_g_input,
430 .vidioc_s_input = empress_s_input, 467 .vidioc_s_input = empress_s_input,
431
432 .vidioc_queryctrl = empress_queryctrl, 468 .vidioc_queryctrl = empress_queryctrl,
433 .vidioc_querymenu = empress_querymenu, 469 .vidioc_querymenu = empress_querymenu,
434 .vidioc_g_ctrl = empress_g_ctrl, 470 .vidioc_g_ctrl = empress_g_ctrl,
435 .vidioc_s_ctrl = empress_s_ctrl, 471 .vidioc_s_ctrl = empress_s_ctrl,
472 .vidioc_g_chip_ident = empress_g_chip_ident,
473 .vidioc_s_std = empress_s_std,
474 .vidioc_g_std = empress_g_std,
436}; 475};
437 476
438/* ----------------------------------------------------------- */ 477/* ----------------------------------------------------------- */
diff --git a/drivers/media/video/saa7134/saa7134-i2c.c b/drivers/media/video/saa7134/saa7134-i2c.c
index 5f713e637683..20c1b33caf7b 100644
--- a/drivers/media/video/saa7134/saa7134-i2c.c
+++ b/drivers/media/video/saa7134/saa7134-i2c.c
@@ -337,6 +337,7 @@ static int attach_inform(struct i2c_client *client)
337 case 0x47: 337 case 0x47:
338 case 0x71: 338 case 0x71:
339 case 0x2d: 339 case 0x2d:
340 case 0x30:
340 { 341 {
341 struct IR_i2c *ir = i2c_get_clientdata(client); 342 struct IR_i2c *ir = i2c_get_clientdata(client);
342 d1printk("%s i2c IR detected (%s).\n", 343 d1printk("%s i2c IR detected (%s).\n",
@@ -427,6 +428,16 @@ void saa7134_i2c_call_clients(struct saa7134_dev *dev,
427 i2c_clients_command(&dev->i2c_adap, cmd, arg); 428 i2c_clients_command(&dev->i2c_adap, cmd, arg);
428} 429}
429 430
431int saa7134_i2c_call_saa6752(struct saa7134_dev *dev,
432 unsigned int cmd, void *arg)
433{
434 if (dev->mpeg_i2c_client == NULL)
435 return -EINVAL;
436 return dev->mpeg_i2c_client->driver->command(dev->mpeg_i2c_client,
437 cmd, arg);
438}
439EXPORT_SYMBOL_GPL(saa7134_i2c_call_saa6752);
440
430int saa7134_i2c_register(struct saa7134_dev *dev) 441int saa7134_i2c_register(struct saa7134_dev *dev)
431{ 442{
432 dev->i2c_adap = saa7134_adap_template; 443 dev->i2c_adap = saa7134_adap_template;
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index ad08d13dffdd..c53fd5f9f6b5 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -62,8 +62,11 @@ MODULE_PARM_DESC(disable_other_ir, "disable full codes of "
62#define i2cdprintk(fmt, arg...) if (ir_debug) \ 62#define i2cdprintk(fmt, arg...) if (ir_debug) \
63 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg) 63 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
64 64
65/** rc5 functions */ 65/* Helper functions for RC5 and NEC decoding at GPIO16 or GPIO18 */
66static int saa7134_rc5_irq(struct saa7134_dev *dev); 66static int saa7134_rc5_irq(struct saa7134_dev *dev);
67static int saa7134_nec_irq(struct saa7134_dev *dev);
68static void nec_task(unsigned long data);
69static void saa7134_nec_timer(unsigned long data);
67 70
68/* -------------------- GPIO generic keycode builder -------------------- */ 71/* -------------------- GPIO generic keycode builder -------------------- */
69 72
@@ -115,6 +118,53 @@ static int build_key(struct saa7134_dev *dev)
115 118
116/* --------------------- Chip specific I2C key builders ----------------- */ 119/* --------------------- Chip specific I2C key builders ----------------- */
117 120
121static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, u32 *ir_key,
122 u32 *ir_raw)
123{
124 unsigned char b;
125 int gpio;
126
127 /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
128 struct saa7134_dev *dev = ir->c.adapter->algo_data;
129 if (dev == NULL) {
130 dprintk("get_key_msi_tvanywhere_plus: "
131 "gir->c.adapter->algo_data is NULL!\n");
132 return -EIO;
133 }
134
135 /* rising SAA7134_GPIO_GPRESCAN reads the status */
136
137 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
138 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
139
140 gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
141
142 /* GPIO&0x40 is pulsed low when a button is pressed. Don't do
143 I2C receive if gpio&0x40 is not low. */
144
145 if (gpio & 0x40)
146 return 0; /* No button press */
147
148 /* GPIO says there is a button press. Get it. */
149
150 if (1 != i2c_master_recv(&ir->c, &b, 1)) {
151 i2cdprintk("read error\n");
152 return -EIO;
153 }
154
155 /* No button press */
156
157 if (b == 0xff)
158 return 0;
159
160 /* Button pressed */
161
162 dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b);
163 *ir_key = b;
164 *ir_raw = b;
165 return 1;
166}
167
118static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw) 168static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
119{ 169{
120 unsigned char b; 170 unsigned char b;
@@ -280,7 +330,9 @@ void saa7134_input_irq(struct saa7134_dev *dev)
280{ 330{
281 struct card_ir *ir = dev->remote; 331 struct card_ir *ir = dev->remote;
282 332
283 if (!ir->polling && !ir->rc5_gpio) { 333 if (ir->nec_gpio) {
334 saa7134_nec_irq(dev);
335 } else if (!ir->polling && !ir->rc5_gpio) {
284 build_key(dev); 336 build_key(dev);
285 } else if (ir->rc5_gpio) { 337 } else if (ir->rc5_gpio) {
286 saa7134_rc5_irq(dev); 338 saa7134_rc5_irq(dev);
@@ -316,6 +368,10 @@ void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir)
316 ir->addr = 0x17; 368 ir->addr = 0x17;
317 ir->rc5_key_timeout = ir_rc5_key_timeout; 369 ir->rc5_key_timeout = ir_rc5_key_timeout;
318 ir->rc5_remote_gap = ir_rc5_remote_gap; 370 ir->rc5_remote_gap = ir_rc5_remote_gap;
371 } else if (ir->nec_gpio) {
372 setup_timer(&ir->timer_keyup, saa7134_nec_timer,
373 (unsigned long)dev);
374 tasklet_init(&ir->tlet, nec_task, (unsigned long)dev);
319 } 375 }
320} 376}
321 377
@@ -335,6 +391,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
335 u32 mask_keyup = 0; 391 u32 mask_keyup = 0;
336 int polling = 0; 392 int polling = 0;
337 int rc5_gpio = 0; 393 int rc5_gpio = 0;
394 int nec_gpio = 0;
338 int ir_type = IR_TYPE_OTHER; 395 int ir_type = IR_TYPE_OTHER;
339 int err; 396 int err;
340 397
@@ -391,6 +448,12 @@ int saa7134_input_init1(struct saa7134_dev *dev)
391 saa_setb(SAA7134_GPIO_GPMODE0, 0x4); 448 saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
392 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4); 449 saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
393 break; 450 break;
451 case SAA7134_BOARD_AVERMEDIA_M135A:
452 ir_codes = ir_codes_avermedia_m135a;
453 mask_keydown = 0x0040000;
454 mask_keycode = 0x00013f;
455 nec_gpio = 1;
456 break;
394 case SAA7134_BOARD_AVERMEDIA_777: 457 case SAA7134_BOARD_AVERMEDIA_777:
395 case SAA7134_BOARD_AVERMEDIA_A16AR: 458 case SAA7134_BOARD_AVERMEDIA_A16AR:
396 ir_codes = ir_codes_avermedia; 459 ir_codes = ir_codes_avermedia;
@@ -499,6 +562,12 @@ int saa7134_input_init1(struct saa7134_dev *dev)
499 mask_keyup = 0x040000; 562 mask_keyup = 0x040000;
500 polling = 50; // ms 563 polling = 50; // ms
501 break; 564 break;
565 case SAA7134_BOARD_ENCORE_ENLTV_FM53:
566 ir_codes = ir_codes_encore_enltv_fm53;
567 mask_keydown = 0x0040000;
568 mask_keycode = 0x00007f;
569 nec_gpio = 1;
570 break;
502 case SAA7134_BOARD_10MOONSTVMASTER3: 571 case SAA7134_BOARD_10MOONSTVMASTER3:
503 ir_codes = ir_codes_encore_enltv; 572 ir_codes = ir_codes_encore_enltv;
504 mask_keycode = 0x5f80000; 573 mask_keycode = 0x5f80000;
@@ -511,6 +580,12 @@ int saa7134_input_init1(struct saa7134_dev *dev)
511 mask_keydown = 0xf00000; 580 mask_keydown = 0xf00000;
512 polling = 50; /* ms */ 581 polling = 50; /* ms */
513 break; 582 break;
583 case SAA7134_BOARD_REAL_ANGEL_220:
584 ir_codes = ir_codes_real_audio_220_32_keys;
585 mask_keycode = 0x3f00;
586 mask_keyup = 0x4000;
587 polling = 50; /* ms */
588 break;
514 } 589 }
515 if (NULL == ir_codes) { 590 if (NULL == ir_codes) {
516 printk("%s: Oops: IR config error [card=%d]\n", 591 printk("%s: Oops: IR config error [card=%d]\n",
@@ -533,6 +608,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
533 ir->mask_keyup = mask_keyup; 608 ir->mask_keyup = mask_keyup;
534 ir->polling = polling; 609 ir->polling = polling;
535 ir->rc5_gpio = rc5_gpio; 610 ir->rc5_gpio = rc5_gpio;
611 ir->nec_gpio = nec_gpio;
536 612
537 /* init input device */ 613 /* init input device */
538 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)", 614 snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
@@ -612,6 +688,11 @@ void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
612 ir->get_key = get_key_purpletv; 688 ir->get_key = get_key_purpletv;
613 ir->ir_codes = ir_codes_purpletv; 689 ir->ir_codes = ir_codes_purpletv;
614 break; 690 break;
691 case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
692 snprintf(ir->c.name, sizeof(ir->c.name), "MSI TV@nywhere Plus");
693 ir->get_key = get_key_msi_tvanywhere_plus;
694 ir->ir_codes = ir_codes_msi_tvanywhere_plus;
695 break;
615 case SAA7134_BOARD_HAUPPAUGE_HVR1110: 696 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
616 snprintf(ir->c.name, sizeof(ir->c.name), "HVR 1110"); 697 snprintf(ir->c.name, sizeof(ir->c.name), "HVR 1110");
617 ir->get_key = get_key_hvr1110; 698 ir->get_key = get_key_hvr1110;
@@ -675,8 +756,125 @@ static int saa7134_rc5_irq(struct saa7134_dev *dev)
675 return 1; 756 return 1;
676} 757}
677 758
678/* ---------------------------------------------------------------------- 759
679 * Local variables: 760/* On NEC protocol, One has 2.25 ms, and zero has 1.125 ms
680 * c-basic-offset: 8 761 The first pulse (start) has 9 + 4.5 ms
681 * End:
682 */ 762 */
763
764static void saa7134_nec_timer(unsigned long data)
765{
766 struct saa7134_dev *dev = (struct saa7134_dev *) data;
767 struct card_ir *ir = dev->remote;
768
769 dprintk("Cancel key repeat\n");
770
771 ir_input_nokey(ir->dev, &ir->ir);
772}
773
774static void nec_task(unsigned long data)
775{
776 struct saa7134_dev *dev = (struct saa7134_dev *) data;
777 struct card_ir *ir;
778 struct timeval tv;
779 int count, pulse, oldpulse, gap;
780 u32 ircode = 0, not_code = 0;
781 int ngap = 0;
782
783 if (!data) {
784 printk(KERN_ERR "saa713x/ir: Can't recover dev struct\n");
785 /* GPIO will be kept disabled */
786 return;
787 }
788
789 ir = dev->remote;
790
791 /* rising SAA7134_GPIO_GPRESCAN reads the status */
792 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
793 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
794
795 oldpulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
796 pulse = oldpulse;
797
798 do_gettimeofday(&tv);
799 ir->base_time = tv;
800
801 /* Decode NEC pulsecode. This code can take up to 76.5 ms to run.
802 Unfortunately, using IRQ to decode pulse didn't work, since it uses
803 a pulse train of 38KHz. This means one pulse on each 52 us
804 */
805 do {
806 /* Wait until the end of pulse/space or 5 ms */
807 for (count = 0; count < 500; count++) {
808 udelay(10);
809 /* rising SAA7134_GPIO_GPRESCAN reads the status */
810 saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
811 saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
812 pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2)
813 & ir->mask_keydown;
814 if (pulse != oldpulse)
815 break;
816 }
817
818 do_gettimeofday(&tv);
819 gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
820 tv.tv_usec - ir->base_time.tv_usec;
821
822 if (!pulse) {
823 /* Bit 0 has 560 us, while bit 1 has 1120 us.
824 Do something only if bit == 1
825 */
826 if (ngap && (gap > 560 + 280)) {
827 unsigned int shift = ngap - 1;
828
829 /* Address first, then command */
830 if (shift < 8) {
831 shift += 8;
832 ircode |= 1 << shift;
833 } else if (shift < 16) {
834 not_code |= 1 << shift;
835 } else if (shift < 24) {
836 shift -= 16;
837 ircode |= 1 << shift;
838 } else {
839 shift -= 24;
840 not_code |= 1 << shift;
841 }
842 }
843 ngap++;
844 }
845
846
847 ir->base_time = tv;
848
849 /* TIMEOUT - Long pulse */
850 if (gap >= 5000)
851 break;
852 oldpulse = pulse;
853 } while (ngap < 32);
854
855 if (ngap == 32) {
856 /* FIXME: should check if not_code == ~ircode */
857 ir->code = ir_extract_bits(ircode, ir->mask_keycode);
858
859 dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n",
860 ir->code, ircode, not_code);
861
862 ir_input_keydown(ir->dev, &ir->ir, ir->code, ir->code);
863 } else
864 dprintk("Repeat last key\n");
865
866 /* Keep repeating the last key */
867 mod_timer(&ir->timer_keyup, jiffies + msecs_to_jiffies(150));
868
869 saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
870}
871
872static int saa7134_nec_irq(struct saa7134_dev *dev)
873{
874 struct card_ir *ir = dev->remote;
875
876 saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
877 tasklet_schedule(&ir->tlet);
878
879 return 1;
880}
diff --git a/drivers/media/video/saa7134/saa7134-ts.c b/drivers/media/video/saa7134/saa7134-ts.c
index eae72fd60cec..ef55a59f0cda 100644
--- a/drivers/media/video/saa7134/saa7134-ts.c
+++ b/drivers/media/video/saa7134/saa7134-ts.c
@@ -66,11 +66,29 @@ static int buffer_activate(struct saa7134_dev *dev,
66 saa7134_set_dmabits(dev); 66 saa7134_set_dmabits(dev);
67 67
68 mod_timer(&dev->ts_q.timeout, jiffies+BUFFER_TIMEOUT); 68 mod_timer(&dev->ts_q.timeout, jiffies+BUFFER_TIMEOUT);
69
70 if (dev->ts_state == SAA7134_TS_BUFF_DONE) {
71 /* Clear TS cache */
72 dev->buff_cnt = 0;
73 saa_writeb(SAA7134_TS_SERIAL1, 0x00);
74 saa_writeb(SAA7134_TS_SERIAL1, 0x03);
75 saa_writeb(SAA7134_TS_SERIAL1, 0x00);
76 saa_writeb(SAA7134_TS_SERIAL1, 0x01);
77
78 /* TS clock non-inverted */
79 saa_writeb(SAA7134_TS_SERIAL1, 0x00);
80
81 /* Start TS stream */
82 saa_writeb(SAA7134_TS_SERIAL0, 0x40);
83 saa_writeb(SAA7134_TS_PARALLEL, 0xEC);
84 dev->ts_state = SAA7134_TS_STARTED;
85 }
86
69 return 0; 87 return 0;
70} 88}
71 89
72static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, 90static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
73 enum v4l2_field field) 91 enum v4l2_field field)
74{ 92{
75 struct saa7134_dev *dev = q->priv_data; 93 struct saa7134_dev *dev = q->priv_data;
76 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb); 94 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
@@ -110,16 +128,22 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
110 goto oops; 128 goto oops;
111 } 129 }
112 130
113 /* dma: setup channel 5 (= TS) */ 131 dev->buff_cnt++;
114 control = SAA7134_RS_CONTROL_BURST_16 | 132
115 SAA7134_RS_CONTROL_ME | 133 if (dev->buff_cnt == dev->ts.nr_bufs) {
116 (buf->pt->dma >> 12); 134 dev->ts_state = SAA7134_TS_BUFF_DONE;
117 135 /* dma: setup channel 5 (= TS) */
118 saa_writeb(SAA7134_TS_DMA0, ((lines-1)&0xff)); 136 control = SAA7134_RS_CONTROL_BURST_16 |
119 saa_writeb(SAA7134_TS_DMA1, (((lines-1)>>8)&0xff)); 137 SAA7134_RS_CONTROL_ME |
120 saa_writeb(SAA7134_TS_DMA2, ((((lines-1)>>16)&0x3f) | 0x00)); /* TSNOPIT=0, TSCOLAP=0 */ 138 (buf->pt->dma >> 12);
121 saa_writel(SAA7134_RS_PITCH(5),TS_PACKET_SIZE); 139
122 saa_writel(SAA7134_RS_CONTROL(5),control); 140 saa_writeb(SAA7134_TS_DMA0, (lines - 1) & 0xff);
141 saa_writeb(SAA7134_TS_DMA1, ((lines - 1) >> 8) & 0xff);
142 /* TSNOPIT=0, TSCOLAP=0 */
143 saa_writeb(SAA7134_TS_DMA2, (((lines - 1) >> 16) & 0x3f) | 0x00);
144 saa_writel(SAA7134_RS_PITCH(5), TS_PACKET_SIZE);
145 saa_writel(SAA7134_RS_CONTROL(5), control);
146 }
123 147
124 buf->vb.state = VIDEOBUF_PREPARED; 148 buf->vb.state = VIDEOBUF_PREPARED;
125 buf->activate = buffer_activate; 149 buf->activate = buffer_activate;
@@ -140,6 +164,8 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
140 if (0 == *count) 164 if (0 == *count)
141 *count = dev->ts.nr_bufs; 165 *count = dev->ts.nr_bufs;
142 *count = saa7134_buffer_count(*size,*count); 166 *count = saa7134_buffer_count(*size,*count);
167 dev->buff_cnt = 0;
168 dev->ts_state = SAA7134_TS_STOPPED;
143 return 0; 169 return 0;
144} 170}
145 171
@@ -154,7 +180,13 @@ static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
154static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb) 180static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
155{ 181{
156 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb); 182 struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
183 struct saa7134_dev *dev = q->priv_data;
157 184
185 if (dev->ts_state == SAA7134_TS_STARTED) {
186 /* Stop TS transport */
187 saa_writeb(SAA7134_TS_PARALLEL, 0x6c);
188 dev->ts_state = SAA7134_TS_STOPPED;
189 }
158 saa7134_dma_free(q,buf); 190 saa7134_dma_free(q,buf);
159} 191}
160 192
@@ -182,7 +214,7 @@ int saa7134_ts_init_hw(struct saa7134_dev *dev)
182 /* deactivate TS softreset */ 214 /* deactivate TS softreset */
183 saa_writeb(SAA7134_TS_SERIAL1, 0x00); 215 saa_writeb(SAA7134_TS_SERIAL1, 0x00);
184 /* TSSOP high active, TSVAL high active, TSLOCK ignored */ 216 /* TSSOP high active, TSVAL high active, TSLOCK ignored */
185 saa_writeb(SAA7134_TS_PARALLEL, 0xec); 217 saa_writeb(SAA7134_TS_PARALLEL, 0x6c);
186 saa_writeb(SAA7134_TS_PARALLEL_SERIAL, (TS_PACKET_SIZE-1)); 218 saa_writeb(SAA7134_TS_PARALLEL_SERIAL, (TS_PACKET_SIZE-1));
187 saa_writeb(SAA7134_TS_DMA0, ((dev->ts.nr_packets-1)&0xff)); 219 saa_writeb(SAA7134_TS_DMA0, ((dev->ts.nr_packets-1)&0xff));
188 saa_writeb(SAA7134_TS_DMA1, (((dev->ts.nr_packets-1)>>8)&0xff)); 220 saa_writeb(SAA7134_TS_DMA1, (((dev->ts.nr_packets-1)>>8)&0xff));
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index 68c268981861..02bb6747a39c 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -628,6 +628,9 @@ void saa7134_set_tvnorm_hw(struct saa7134_dev *dev)
628 628
629 if (card_in(dev, dev->ctl_input).tv) 629 if (card_in(dev, dev->ctl_input).tv)
630 saa7134_i2c_call_clients(dev, VIDIOC_S_STD, &dev->tvnorm->id); 630 saa7134_i2c_call_clients(dev, VIDIOC_S_STD, &dev->tvnorm->id);
631 /* Set the correct norm for the saa6752hs. This function
632 does nothing if there is no saa6752hs. */
633 saa7134_i2c_call_saa6752(dev, VIDIOC_S_STD, &dev->tvnorm->id);
631} 634}
632 635
633static void set_h_prescale(struct saa7134_dev *dev, int task, int prescale) 636static void set_h_prescale(struct saa7134_dev *dev, int task, int prescale)
@@ -1330,6 +1333,8 @@ static int video_open(struct inode *inode, struct file *file)
1330 struct saa7134_fh *fh; 1333 struct saa7134_fh *fh;
1331 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1334 enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1332 int radio = 0; 1335 int radio = 0;
1336
1337 lock_kernel();
1333 list_for_each_entry(dev, &saa7134_devlist, devlist) { 1338 list_for_each_entry(dev, &saa7134_devlist, devlist) {
1334 if (dev->video_dev && (dev->video_dev->minor == minor)) 1339 if (dev->video_dev && (dev->video_dev->minor == minor))
1335 goto found; 1340 goto found;
@@ -1342,6 +1347,7 @@ static int video_open(struct inode *inode, struct file *file)
1342 goto found; 1347 goto found;
1343 } 1348 }
1344 } 1349 }
1350 unlock_kernel();
1345 return -ENODEV; 1351 return -ENODEV;
1346 found: 1352 found:
1347 1353
@@ -1350,8 +1356,10 @@ static int video_open(struct inode *inode, struct file *file)
1350 1356
1351 /* allocate + initialize per filehandle data */ 1357 /* allocate + initialize per filehandle data */
1352 fh = kzalloc(sizeof(*fh),GFP_KERNEL); 1358 fh = kzalloc(sizeof(*fh),GFP_KERNEL);
1353 if (NULL == fh) 1359 if (NULL == fh) {
1360 unlock_kernel();
1354 return -ENOMEM; 1361 return -ENOMEM;
1362 }
1355 file->private_data = fh; 1363 file->private_data = fh;
1356 fh->dev = dev; 1364 fh->dev = dev;
1357 fh->radio = radio; 1365 fh->radio = radio;
@@ -1384,6 +1392,7 @@ static int video_open(struct inode *inode, struct file *file)
1384 /* switch to video/vbi mode */ 1392 /* switch to video/vbi mode */
1385 video_mux(dev,dev->ctl_input); 1393 video_mux(dev,dev->ctl_input);
1386 } 1394 }
1395 unlock_kernel();
1387 return 0; 1396 return 0;
1388} 1397}
1389 1398
@@ -1790,18 +1799,25 @@ static int saa7134_querycap(struct file *file, void *priv,
1790 return 0; 1799 return 0;
1791} 1800}
1792 1801
1793static int saa7134_s_std(struct file *file, void *priv, v4l2_std_id *id) 1802int saa7134_s_std_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, v4l2_std_id *id)
1794{ 1803{
1795 struct saa7134_fh *fh = priv;
1796 struct saa7134_dev *dev = fh->dev;
1797 unsigned long flags; 1804 unsigned long flags;
1798 unsigned int i; 1805 unsigned int i;
1799 v4l2_std_id fixup; 1806 v4l2_std_id fixup;
1800 int err; 1807 int err;
1801 1808
1802 err = v4l2_prio_check(&dev->prio, &fh->prio); 1809 /* When called from the empress code fh == NULL.
1803 if (0 != err) 1810 That needs to be fixed somehow, but for now this is
1804 return err; 1811 good enough. */
1812 if (fh) {
1813 err = v4l2_prio_check(&dev->prio, &fh->prio);
1814 if (0 != err)
1815 return err;
1816 } else if (res_locked(dev, RESOURCE_OVERLAY)) {
1817 /* Don't change the std from the mpeg device
1818 if overlay is active. */
1819 return -EBUSY;
1820 }
1805 1821
1806 for (i = 0; i < TVNORMS; i++) 1822 for (i = 0; i < TVNORMS; i++)
1807 if (*id == tvnorms[i].id) 1823 if (*id == tvnorms[i].id)
@@ -1834,7 +1850,7 @@ static int saa7134_s_std(struct file *file, void *priv, v4l2_std_id *id)
1834 *id = tvnorms[i].id; 1850 *id = tvnorms[i].id;
1835 1851
1836 mutex_lock(&dev->lock); 1852 mutex_lock(&dev->lock);
1837 if (res_check(fh, RESOURCE_OVERLAY)) { 1853 if (fh && res_check(fh, RESOURCE_OVERLAY)) {
1838 spin_lock_irqsave(&dev->slock, flags); 1854 spin_lock_irqsave(&dev->slock, flags);
1839 stop_preview(dev, fh); 1855 stop_preview(dev, fh);
1840 spin_unlock_irqrestore(&dev->slock, flags); 1856 spin_unlock_irqrestore(&dev->slock, flags);
@@ -1851,6 +1867,23 @@ static int saa7134_s_std(struct file *file, void *priv, v4l2_std_id *id)
1851 mutex_unlock(&dev->lock); 1867 mutex_unlock(&dev->lock);
1852 return 0; 1868 return 0;
1853} 1869}
1870EXPORT_SYMBOL_GPL(saa7134_s_std_internal);
1871
1872static int saa7134_s_std(struct file *file, void *priv, v4l2_std_id *id)
1873{
1874 struct saa7134_fh *fh = priv;
1875
1876 return saa7134_s_std_internal(fh->dev, fh, id);
1877}
1878
1879static int saa7134_g_std(struct file *file, void *priv, v4l2_std_id *id)
1880{
1881 struct saa7134_fh *fh = priv;
1882 struct saa7134_dev *dev = fh->dev;
1883
1884 *id = dev->tvnorm->id;
1885 return 0;
1886}
1854 1887
1855static int saa7134_cropcap(struct file *file, void *priv, 1888static int saa7134_cropcap(struct file *file, void *priv,
1856 struct v4l2_cropcap *cap) 1889 struct v4l2_cropcap *cap)
@@ -2077,18 +2110,6 @@ static int saa7134_enum_fmt_vid_overlay(struct file *file, void *priv,
2077 return 0; 2110 return 0;
2078} 2111}
2079 2112
2080static int saa7134_enum_fmt_vbi_cap(struct file *file, void *priv,
2081 struct v4l2_fmtdesc *f)
2082{
2083 if (0 != f->index)
2084 return -EINVAL;
2085
2086 f->pixelformat = V4L2_PIX_FMT_GREY;
2087 strcpy(f->description, "vbi data");
2088
2089 return 0;
2090}
2091
2092static int saa7134_g_fbuf(struct file *file, void *f, 2113static int saa7134_g_fbuf(struct file *file, void *f,
2093 struct v4l2_framebuffer *fb) 2114 struct v4l2_framebuffer *fb)
2094{ 2115{
@@ -2379,7 +2400,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
2379 .vidioc_g_fmt_vid_overlay = saa7134_g_fmt_vid_overlay, 2400 .vidioc_g_fmt_vid_overlay = saa7134_g_fmt_vid_overlay,
2380 .vidioc_try_fmt_vid_overlay = saa7134_try_fmt_vid_overlay, 2401 .vidioc_try_fmt_vid_overlay = saa7134_try_fmt_vid_overlay,
2381 .vidioc_s_fmt_vid_overlay = saa7134_s_fmt_vid_overlay, 2402 .vidioc_s_fmt_vid_overlay = saa7134_s_fmt_vid_overlay,
2382 .vidioc_enum_fmt_vbi_cap = saa7134_enum_fmt_vbi_cap,
2383 .vidioc_g_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap, 2403 .vidioc_g_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap,
2384 .vidioc_try_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap, 2404 .vidioc_try_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap,
2385 .vidioc_s_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap, 2405 .vidioc_s_fmt_vbi_cap = saa7134_try_get_set_fmt_vbi_cap,
@@ -2391,6 +2411,7 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
2391 .vidioc_qbuf = saa7134_qbuf, 2411 .vidioc_qbuf = saa7134_qbuf,
2392 .vidioc_dqbuf = saa7134_dqbuf, 2412 .vidioc_dqbuf = saa7134_dqbuf,
2393 .vidioc_s_std = saa7134_s_std, 2413 .vidioc_s_std = saa7134_s_std,
2414 .vidioc_g_std = saa7134_g_std,
2394 .vidioc_enum_input = saa7134_enum_input, 2415 .vidioc_enum_input = saa7134_enum_input,
2395 .vidioc_g_input = saa7134_g_input, 2416 .vidioc_g_input = saa7134_g_input,
2396 .vidioc_s_input = saa7134_s_input, 2417 .vidioc_s_input = saa7134_s_input,
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index a0884f639f65..491ab1f8fdd3 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -269,6 +269,12 @@ struct saa7134_format {
269#define SAA7134_BOARD_BEHOLD_M6_EXTRA 144 269#define SAA7134_BOARD_BEHOLD_M6_EXTRA 144
270#define SAA7134_BOARD_AVERMEDIA_M103 145 270#define SAA7134_BOARD_AVERMEDIA_M103 145
271#define SAA7134_BOARD_ASUSTeK_P7131_ANALOG 146 271#define SAA7134_BOARD_ASUSTeK_P7131_ANALOG 146
272#define SAA7134_BOARD_ASUSTeK_TIGER_3IN1 147
273#define SAA7134_BOARD_ENCORE_ENLTV_FM53 148
274#define SAA7134_BOARD_AVERMEDIA_M135A 149
275#define SAA7134_BOARD_REAL_ANGEL_220 150
276#define SAA7134_BOARD_ADS_INSTANT_HDTV_PCI 151
277#define SAA7134_BOARD_ASUSTeK_TIGER 152
272 278
273#define SAA7134_MAXBOARDS 8 279#define SAA7134_MAXBOARDS 8
274#define SAA7134_INPUT_MAX 8 280#define SAA7134_INPUT_MAX 8
@@ -462,6 +468,12 @@ struct saa7134_mpeg_ops {
462 void (*signal_change)(struct saa7134_dev *dev); 468 void (*signal_change)(struct saa7134_dev *dev);
463}; 469};
464 470
471enum saa7134_ts_status {
472 SAA7134_TS_STOPPED,
473 SAA7134_TS_BUFF_DONE,
474 SAA7134_TS_STARTED,
475};
476
465/* global device status */ 477/* global device status */
466struct saa7134_dev { 478struct saa7134_dev {
467 struct list_head devlist; 479 struct list_head devlist;
@@ -555,6 +567,8 @@ struct saa7134_dev {
555 /* SAA7134_MPEG_* */ 567 /* SAA7134_MPEG_* */
556 struct saa7134_ts ts; 568 struct saa7134_ts ts;
557 struct saa7134_dmaqueue ts_q; 569 struct saa7134_dmaqueue ts_q;
570 enum saa7134_ts_status ts_state;
571 unsigned int buff_cnt;
558 struct saa7134_mpeg_ops *mops; 572 struct saa7134_mpeg_ops *mops;
559 struct i2c_client *mpeg_i2c_client; 573 struct i2c_client *mpeg_i2c_client;
560 574
@@ -644,7 +658,7 @@ extern struct pci_device_id __devinitdata saa7134_pci_tbl[];
644 658
645extern int saa7134_board_init1(struct saa7134_dev *dev); 659extern int saa7134_board_init1(struct saa7134_dev *dev);
646extern int saa7134_board_init2(struct saa7134_dev *dev); 660extern int saa7134_board_init2(struct saa7134_dev *dev);
647int saa7134_tuner_callback(void *priv, int command, int arg); 661int saa7134_tuner_callback(void *priv, int component, int command, int arg);
648 662
649 663
650/* ----------------------------------------------------------- */ 664/* ----------------------------------------------------------- */
@@ -654,6 +668,8 @@ int saa7134_i2c_register(struct saa7134_dev *dev);
654int saa7134_i2c_unregister(struct saa7134_dev *dev); 668int saa7134_i2c_unregister(struct saa7134_dev *dev);
655void saa7134_i2c_call_clients(struct saa7134_dev *dev, 669void saa7134_i2c_call_clients(struct saa7134_dev *dev,
656 unsigned int cmd, void *arg); 670 unsigned int cmd, void *arg);
671int saa7134_i2c_call_saa6752(struct saa7134_dev *dev,
672 unsigned int cmd, void *arg);
657 673
658 674
659/* ----------------------------------------------------------- */ 675/* ----------------------------------------------------------- */
@@ -666,6 +682,7 @@ extern struct video_device saa7134_radio_template;
666int saa7134_s_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c); 682int saa7134_s_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c);
667int saa7134_g_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c); 683int saa7134_g_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c);
668int saa7134_queryctrl(struct file *file, void *priv, struct v4l2_queryctrl *c); 684int saa7134_queryctrl(struct file *file, void *priv, struct v4l2_queryctrl *c);
685int saa7134_s_std_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, v4l2_std_id *id);
669 686
670int saa7134_videoport_init(struct saa7134_dev *dev); 687int saa7134_videoport_init(struct saa7134_dev *dev);
671void saa7134_set_tvnorm_hw(struct saa7134_dev *dev); 688void saa7134_set_tvnorm_hw(struct saa7134_dev *dev);
diff --git a/drivers/media/video/se401.c b/drivers/media/video/se401.c
index acceed5d04ae..ae3949180c4e 100644
--- a/drivers/media/video/se401.c
+++ b/drivers/media/video/se401.c
@@ -288,7 +288,7 @@ static void se401_button_irq(struct urb *urb)
288 int status; 288 int status;
289 289
290 if (!se401->dev) { 290 if (!se401->dev) {
291 info("ohoh: device vapourished"); 291 dev_info(&urb->dev->dev, "device vapourished\n");
292 return; 292 return;
293 } 293 }
294 294
@@ -328,7 +328,7 @@ static void se401_video_irq(struct urb *urb)
328 return; 328 return;
329 329
330 if (!se401->dev) { 330 if (!se401->dev) {
331 info ("ohoh: device vapourished"); 331 dev_info(&urb->dev->dev, "device vapourished\n");
332 return; 332 return;
333 } 333 }
334 334
@@ -375,7 +375,7 @@ static void se401_video_irq(struct urb *urb)
375 urb->status=0; 375 urb->status=0;
376 urb->dev=se401->dev; 376 urb->dev=se401->dev;
377 if(usb_submit_urb(urb, GFP_KERNEL)) 377 if(usb_submit_urb(urb, GFP_KERNEL))
378 info("urb burned down"); 378 dev_info(&urb->dev->dev, "urb burned down\n");
379 return; 379 return;
380} 380}
381 381
@@ -860,7 +860,8 @@ static int se401_newframe(struct usb_se401 *se401, int framenr)
860 ); 860 );
861 if (se401->nullpackets > SE401_MAX_NULLPACKETS) { 861 if (se401->nullpackets > SE401_MAX_NULLPACKETS) {
862 se401->nullpackets=0; 862 se401->nullpackets=0;
863 info("to many null length packets, restarting capture"); 863 dev_info(&se401->dev->dev,
864 "too many null length packets, restarting capture\n");
864 se401_stop_stream(se401); 865 se401_stop_stream(se401);
865 se401_start_stream(se401); 866 se401_start_stream(se401);
866 } else { 867 } else {
@@ -880,7 +881,8 @@ static int se401_newframe(struct usb_se401 *se401, int framenr)
880 se401->scratch_use=0; 881 se401->scratch_use=0;
881 if (errors > SE401_MAX_ERRORS) { 882 if (errors > SE401_MAX_ERRORS) {
882 errors=0; 883 errors=0;
883 info("to much errors, restarting capture"); 884 dev_info(&se401->dev->dev,
885 "too many errors, restarting capture\n");
884 se401_stop_stream(se401); 886 se401_stop_stream(se401);
885 se401_start_stream(se401); 887 se401_start_stream(se401);
886 } 888 }
@@ -913,7 +915,7 @@ static void usb_se401_remove_disconnected (struct usb_se401 *se401)
913 usb_kill_urb(se401->inturb); 915 usb_kill_urb(se401->inturb);
914 usb_free_urb(se401->inturb); 916 usb_free_urb(se401->inturb);
915 } 917 }
916 info("%s disconnected", se401->camera_name); 918 dev_info(&se401->dev->dev, "%s disconnected", se401->camera_name);
917 919
918 /* Free the memory */ 920 /* Free the memory */
919 kfree(se401->width); 921 kfree(se401->width);
@@ -936,14 +938,18 @@ static int se401_open(struct inode *inode, struct file *file)
936 struct usb_se401 *se401 = (struct usb_se401 *)dev; 938 struct usb_se401 *se401 = (struct usb_se401 *)dev;
937 int err = 0; 939 int err = 0;
938 940
939 if (se401->user) 941 lock_kernel();
942 if (se401->user) {
943 unlock_kernel();
940 return -EBUSY; 944 return -EBUSY;
945 }
941 se401->fbuf = rvmalloc(se401->maxframesize * SE401_NUMFRAMES); 946 se401->fbuf = rvmalloc(se401->maxframesize * SE401_NUMFRAMES);
942 if (se401->fbuf) 947 if (se401->fbuf)
943 file->private_data = dev; 948 file->private_data = dev;
944 else 949 else
945 err = -ENOMEM; 950 err = -ENOMEM;
946 se401->user = !err; 951 se401->user = !err;
952 unlock_kernel();
947 953
948 return err; 954 return err;
949} 955}
@@ -956,8 +962,8 @@ static int se401_close(struct inode *inode, struct file *file)
956 962
957 rvfree(se401->fbuf, se401->maxframesize * SE401_NUMFRAMES); 963 rvfree(se401->fbuf, se401->maxframesize * SE401_NUMFRAMES);
958 if (se401->removed) { 964 if (se401->removed) {
965 dev_info(&se401->dev->dev, "device unregistered\n");
959 usb_se401_remove_disconnected(se401); 966 usb_se401_remove_disconnected(se401);
960 info("device unregistered");
961 } else { 967 } else {
962 for (i=0; i<SE401_NUMFRAMES; i++) 968 for (i=0; i<SE401_NUMFRAMES; i++)
963 se401->frame[i].grabstate=FRAME_UNUSED; 969 se401->frame[i].grabstate=FRAME_UNUSED;
@@ -1232,6 +1238,7 @@ static const struct file_operations se401_fops = {
1232static struct video_device se401_template = { 1238static struct video_device se401_template = {
1233 .name = "se401 USB camera", 1239 .name = "se401 USB camera",
1234 .fops = &se401_fops, 1240 .fops = &se401_fops,
1241 .release = video_device_release_empty,
1235}; 1242};
1236 1243
1237 1244
@@ -1271,7 +1278,7 @@ static int se401_init(struct usb_se401 *se401, int button)
1271 for (i=0; i<se401->sizes; i++) { 1278 for (i=0; i<se401->sizes; i++) {
1272 sprintf(temp, "%s %dx%d", temp, se401->width[i], se401->height[i]); 1279 sprintf(temp, "%s %dx%d", temp, se401->width[i], se401->height[i]);
1273 } 1280 }
1274 info("%s", temp); 1281 dev_info(&se401->dev->dev, "%s\n", temp);
1275 se401->maxframesize=se401->width[se401->sizes-1]*se401->height[se401->sizes-1]*3; 1282 se401->maxframesize=se401->width[se401->sizes-1]*se401->height[se401->sizes-1]*3;
1276 1283
1277 rc=se401_sndctrl(0, se401, SE401_REQ_GET_WIDTH, 0, cp, sizeof(cp)); 1284 rc=se401_sndctrl(0, se401, SE401_REQ_GET_WIDTH, 0, cp, sizeof(cp));
@@ -1305,7 +1312,8 @@ static int se401_init(struct usb_se401 *se401, int button)
1305 if (button) { 1312 if (button) {
1306 se401->inturb=usb_alloc_urb(0, GFP_KERNEL); 1313 se401->inturb=usb_alloc_urb(0, GFP_KERNEL);
1307 if (!se401->inturb) { 1314 if (!se401->inturb) {
1308 info("Allocation of inturb failed"); 1315 dev_info(&se401->dev->dev,
1316 "Allocation of inturb failed\n");
1309 return 1; 1317 return 1;
1310 } 1318 }
1311 usb_fill_int_urb(se401->inturb, se401->dev, 1319 usb_fill_int_urb(se401->inturb, se401->dev,
@@ -1316,7 +1324,7 @@ static int se401_init(struct usb_se401 *se401, int button)
1316 8 1324 8
1317 ); 1325 );
1318 if (usb_submit_urb(se401->inturb, GFP_KERNEL)) { 1326 if (usb_submit_urb(se401->inturb, GFP_KERNEL)) {
1319 info("int urb burned down"); 1327 dev_info(&se401->dev->dev, "int urb burned down\n");
1320 return 1; 1328 return 1;
1321 } 1329 }
1322 } else 1330 } else
@@ -1373,7 +1381,7 @@ static int se401_probe(struct usb_interface *intf,
1373 return -ENODEV; 1381 return -ENODEV;
1374 1382
1375 /* We found one */ 1383 /* We found one */
1376 info("SE401 camera found: %s", camera_name); 1384 dev_info(&intf->dev, "SE401 camera found: %s\n", camera_name);
1377 1385
1378 if ((se401 = kzalloc(sizeof(*se401), GFP_KERNEL)) == NULL) { 1386 if ((se401 = kzalloc(sizeof(*se401), GFP_KERNEL)) == NULL) {
1379 err("couldn't kmalloc se401 struct"); 1387 err("couldn't kmalloc se401 struct");
@@ -1384,7 +1392,8 @@ static int se401_probe(struct usb_interface *intf,
1384 se401->iface = interface->bInterfaceNumber; 1392 se401->iface = interface->bInterfaceNumber;
1385 se401->camera_name = camera_name; 1393 se401->camera_name = camera_name;
1386 1394
1387 info("firmware version: %02x", le16_to_cpu(dev->descriptor.bcdDevice) & 255); 1395 dev_info(&intf->dev, "firmware version: %02x\n",
1396 le16_to_cpu(dev->descriptor.bcdDevice) & 255);
1388 1397
1389 if (se401_init(se401, button)) { 1398 if (se401_init(se401, button)) {
1390 kfree(se401); 1399 kfree(se401);
@@ -1402,7 +1411,8 @@ static int se401_probe(struct usb_interface *intf,
1402 err("video_register_device failed"); 1411 err("video_register_device failed");
1403 return -EIO; 1412 return -EIO;
1404 } 1413 }
1405 info("registered new video device: video%d", se401->vdev.minor); 1414 dev_info(&intf->dev, "registered new video device: video%d\n",
1415 se401->vdev.minor);
1406 1416
1407 usb_set_intfdata (intf, se401); 1417 usb_set_intfdata (intf, se401);
1408 return 0; 1418 return 0;
@@ -1446,10 +1456,10 @@ static struct usb_driver se401_driver = {
1446 1456
1447static int __init usb_se401_init(void) 1457static int __init usb_se401_init(void)
1448{ 1458{
1449 info("SE401 usb camera driver version %s registering", version); 1459 printk(KERN_INFO "SE401 usb camera driver version %s registering\n", version);
1450 if (flickerless) 1460 if (flickerless)
1451 if (flickerless!=50 && flickerless!=60) { 1461 if (flickerless!=50 && flickerless!=60) {
1452 info("Invallid flickerless value, use 0, 50 or 60."); 1462 printk(KERN_ERR "Invallid flickerless value, use 0, 50 or 60.\n");
1453 return -1; 1463 return -1;
1454 } 1464 }
1455 return usb_register(&se401_driver); 1465 return usb_register(&se401_driver);
@@ -1458,7 +1468,7 @@ static int __init usb_se401_init(void)
1458static void __exit usb_se401_exit(void) 1468static void __exit usb_se401_exit(void)
1459{ 1469{
1460 usb_deregister(&se401_driver); 1470 usb_deregister(&se401_driver);
1461 info("SE401 driver deregistered"); 1471 printk(KERN_INFO "SE401 driver deregistered\frame");
1462} 1472}
1463 1473
1464module_init(usb_se401_init); 1474module_init(usb_se401_init);
diff --git a/drivers/media/video/sh_mobile_ceu_camera.c b/drivers/media/video/sh_mobile_ceu_camera.c
index 318754e73132..76838091dc66 100644
--- a/drivers/media/video/sh_mobile_ceu_camera.c
+++ b/drivers/media/video/sh_mobile_ceu_camera.c
@@ -304,9 +304,6 @@ static int sh_mobile_ceu_add_device(struct soc_camera_device *icd)
304 "SuperH Mobile CEU driver attached to camera %d\n", 304 "SuperH Mobile CEU driver attached to camera %d\n",
305 icd->devnum); 305 icd->devnum);
306 306
307 if (pcdev->pdata->enable_camera)
308 pcdev->pdata->enable_camera();
309
310 ret = icd->ops->init(icd); 307 ret = icd->ops->init(icd);
311 if (ret) 308 if (ret)
312 goto err; 309 goto err;
@@ -333,8 +330,6 @@ static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd)
333 ceu_write(pcdev, CEIER, 0); 330 ceu_write(pcdev, CEIER, 0);
334 ceu_write(pcdev, CAPSR, 1 << 16); /* reset */ 331 ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
335 icd->ops->release(icd); 332 icd->ops->release(icd);
336 if (pcdev->pdata->disable_camera)
337 pcdev->pdata->disable_camera();
338 333
339 dev_info(&icd->dev, 334 dev_info(&icd->dev,
340 "SuperH Mobile CEU driver detached from camera %d\n", 335 "SuperH Mobile CEU driver detached from camera %d\n",
diff --git a/drivers/media/video/sn9c102/sn9c102_core.c b/drivers/media/video/sn9c102/sn9c102_core.c
index 2da6938718f2..20e30bd9364b 100644
--- a/drivers/media/video/sn9c102/sn9c102_core.c
+++ b/drivers/media/video/sn9c102/sn9c102_core.c
@@ -116,6 +116,26 @@ MODULE_PARM_DESC(debug,
116 "\n"); 116 "\n");
117#endif 117#endif
118 118
119/*
120 Add the probe entries to this table. Be sure to add the entry in the right
121 place, since, on failure, the next probing routine is called according to
122 the order of the list below, from top to bottom.
123*/
124static int (*sn9c102_sensor_table[])(struct sn9c102_device *) = {
125 &sn9c102_probe_hv7131d, /* strong detection based on SENSOR ids */
126 &sn9c102_probe_hv7131r, /* strong detection based on SENSOR ids */
127 &sn9c102_probe_mi0343, /* strong detection based on SENSOR ids */
128 &sn9c102_probe_mi0360, /* strong detection based on SENSOR ids */
129 &sn9c102_probe_mt9v111, /* strong detection based on SENSOR ids */
130 &sn9c102_probe_pas106b, /* strong detection based on SENSOR ids */
131 &sn9c102_probe_pas202bcb, /* strong detection based on SENSOR ids */
132 &sn9c102_probe_ov7630, /* strong detection based on SENSOR ids */
133 &sn9c102_probe_ov7660, /* strong detection based on SENSOR ids */
134 &sn9c102_probe_tas5110c1b, /* detection based on USB pid/vid */
135 &sn9c102_probe_tas5110d, /* detection based on USB pid/vid */
136 &sn9c102_probe_tas5130d1b, /* detection based on USB pid/vid */
137};
138
119/*****************************************************************************/ 139/*****************************************************************************/
120 140
121static u32 141static u32
@@ -1746,7 +1766,7 @@ static int sn9c102_open(struct inode* inode, struct file* filp)
1746 if (!down_read_trylock(&sn9c102_dev_lock)) 1766 if (!down_read_trylock(&sn9c102_dev_lock))
1747 return -ERESTARTSYS; 1767 return -ERESTARTSYS;
1748 1768
1749 cam = video_get_drvdata(video_devdata(filp)); 1769 cam = video_drvdata(filp);
1750 1770
1751 if (wait_for_completion_interruptible(&cam->probe)) { 1771 if (wait_for_completion_interruptible(&cam->probe)) {
1752 up_read(&sn9c102_dev_lock); 1772 up_read(&sn9c102_dev_lock);
@@ -1843,7 +1863,7 @@ static int sn9c102_release(struct inode* inode, struct file* filp)
1843 1863
1844 down_write(&sn9c102_dev_lock); 1864 down_write(&sn9c102_dev_lock);
1845 1865
1846 cam = video_get_drvdata(video_devdata(filp)); 1866 cam = video_drvdata(filp);
1847 1867
1848 sn9c102_stop_transfer(cam); 1868 sn9c102_stop_transfer(cam);
1849 sn9c102_release_buffers(cam); 1869 sn9c102_release_buffers(cam);
@@ -1863,7 +1883,7 @@ static int sn9c102_release(struct inode* inode, struct file* filp)
1863static ssize_t 1883static ssize_t
1864sn9c102_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos) 1884sn9c102_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
1865{ 1885{
1866 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp)); 1886 struct sn9c102_device *cam = video_drvdata(filp);
1867 struct sn9c102_frame_t* f, * i; 1887 struct sn9c102_frame_t* f, * i;
1868 unsigned long lock_flags; 1888 unsigned long lock_flags;
1869 long timeout; 1889 long timeout;
@@ -1987,7 +2007,7 @@ exit:
1987 2007
1988static unsigned int sn9c102_poll(struct file *filp, poll_table *wait) 2008static unsigned int sn9c102_poll(struct file *filp, poll_table *wait)
1989{ 2009{
1990 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp)); 2010 struct sn9c102_device *cam = video_drvdata(filp);
1991 struct sn9c102_frame_t* f; 2011 struct sn9c102_frame_t* f;
1992 unsigned long lock_flags; 2012 unsigned long lock_flags;
1993 unsigned int mask = 0; 2013 unsigned int mask = 0;
@@ -2063,7 +2083,7 @@ static struct vm_operations_struct sn9c102_vm_ops = {
2063 2083
2064static int sn9c102_mmap(struct file* filp, struct vm_area_struct *vma) 2084static int sn9c102_mmap(struct file* filp, struct vm_area_struct *vma)
2065{ 2085{
2066 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp)); 2086 struct sn9c102_device *cam = video_drvdata(filp);
2067 unsigned long size = vma->vm_end - vma->vm_start, 2087 unsigned long size = vma->vm_end - vma->vm_start,
2068 start = vma->vm_start; 2088 start = vma->vm_start;
2069 void *pos; 2089 void *pos;
@@ -3075,7 +3095,7 @@ sn9c102_vidioc_s_audio(struct sn9c102_device* cam, void __user * arg)
3075static int sn9c102_ioctl_v4l2(struct inode* inode, struct file* filp, 3095static int sn9c102_ioctl_v4l2(struct inode* inode, struct file* filp,
3076 unsigned int cmd, void __user * arg) 3096 unsigned int cmd, void __user * arg)
3077{ 3097{
3078 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp)); 3098 struct sn9c102_device *cam = video_drvdata(filp);
3079 3099
3080 switch (cmd) { 3100 switch (cmd) {
3081 3101
@@ -3179,7 +3199,7 @@ static int sn9c102_ioctl_v4l2(struct inode* inode, struct file* filp,
3179static int sn9c102_ioctl(struct inode* inode, struct file* filp, 3199static int sn9c102_ioctl(struct inode* inode, struct file* filp,
3180 unsigned int cmd, unsigned long arg) 3200 unsigned int cmd, unsigned long arg)
3181{ 3201{
3182 struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp)); 3202 struct sn9c102_device *cam = video_drvdata(filp);
3183 int err = 0; 3203 int err = 0;
3184 3204
3185 if (mutex_lock_interruptible(&cam->fileop_mutex)) 3205 if (mutex_lock_interruptible(&cam->fileop_mutex))
diff --git a/drivers/media/video/sn9c102/sn9c102_devtable.h b/drivers/media/video/sn9c102/sn9c102_devtable.h
index 90a401dc3884..e23734f6d6e2 100644
--- a/drivers/media/video/sn9c102/sn9c102_devtable.h
+++ b/drivers/media/video/sn9c102/sn9c102_devtable.h
@@ -140,24 +140,4 @@ extern int sn9c102_probe_tas5110c1b(struct sn9c102_device* cam);
140extern int sn9c102_probe_tas5110d(struct sn9c102_device* cam); 140extern int sn9c102_probe_tas5110d(struct sn9c102_device* cam);
141extern int sn9c102_probe_tas5130d1b(struct sn9c102_device* cam); 141extern int sn9c102_probe_tas5130d1b(struct sn9c102_device* cam);
142 142
143/*
144 Add the above entries to this table. Be sure to add the entry in the right
145 place, since, on failure, the next probing routine is called according to
146 the order of the list below, from top to bottom.
147*/
148static int (*sn9c102_sensor_table[])(struct sn9c102_device*) = {
149 &sn9c102_probe_hv7131d, /* strong detection based on SENSOR ids */
150 &sn9c102_probe_hv7131r, /* strong detection based on SENSOR ids */
151 &sn9c102_probe_mi0343, /* strong detection based on SENSOR ids */
152 &sn9c102_probe_mi0360, /* strong detection based on SENSOR ids */
153 &sn9c102_probe_mt9v111, /* strong detection based on SENSOR ids */
154 &sn9c102_probe_pas106b, /* strong detection based on SENSOR ids */
155 &sn9c102_probe_pas202bcb, /* strong detection based on SENSOR ids */
156 &sn9c102_probe_ov7630, /* strong detection based on SENSOR ids */
157 &sn9c102_probe_ov7660, /* strong detection based on SENSOR ids */
158 &sn9c102_probe_tas5110c1b, /* detection based on USB pid/vid */
159 &sn9c102_probe_tas5110d, /* detection based on USB pid/vid */
160 &sn9c102_probe_tas5130d1b, /* detection based on USB pid/vid */
161};
162
163#endif /* _SN9C102_DEVTABLE_H_ */ 143#endif /* _SN9C102_DEVTABLE_H_ */
diff --git a/drivers/media/video/sn9c102/sn9c102_hv7131d.c b/drivers/media/video/sn9c102/sn9c102_hv7131d.c
index eaf9ad0dc8a6..db2434948939 100644
--- a/drivers/media/video/sn9c102/sn9c102_hv7131d.c
+++ b/drivers/media/video/sn9c102/sn9c102_hv7131d.c
@@ -20,6 +20,7 @@
20 ***************************************************************************/ 20 ***************************************************************************/
21 21
22#include "sn9c102_sensor.h" 22#include "sn9c102_sensor.h"
23#include "sn9c102_devtable.h"
23 24
24 25
25static int hv7131d_init(struct sn9c102_device* cam) 26static int hv7131d_init(struct sn9c102_device* cam)
diff --git a/drivers/media/video/sn9c102/sn9c102_hv7131r.c b/drivers/media/video/sn9c102/sn9c102_hv7131r.c
index 0fc401223cfc..4295887ff609 100644
--- a/drivers/media/video/sn9c102/sn9c102_hv7131r.c
+++ b/drivers/media/video/sn9c102/sn9c102_hv7131r.c
@@ -20,6 +20,7 @@
20 ***************************************************************************/ 20 ***************************************************************************/
21 21
22#include "sn9c102_sensor.h" 22#include "sn9c102_sensor.h"
23#include "sn9c102_devtable.h"
23 24
24 25
25static int hv7131r_init(struct sn9c102_device* cam) 26static int hv7131r_init(struct sn9c102_device* cam)
diff --git a/drivers/media/video/sn9c102/sn9c102_mi0343.c b/drivers/media/video/sn9c102/sn9c102_mi0343.c
index 00b134ca0a3d..1f5b09bec89c 100644
--- a/drivers/media/video/sn9c102/sn9c102_mi0343.c
+++ b/drivers/media/video/sn9c102/sn9c102_mi0343.c
@@ -20,6 +20,7 @@
20 ***************************************************************************/ 20 ***************************************************************************/
21 21
22#include "sn9c102_sensor.h" 22#include "sn9c102_sensor.h"
23#include "sn9c102_devtable.h"
23 24
24 25
25static int mi0343_init(struct sn9c102_device* cam) 26static int mi0343_init(struct sn9c102_device* cam)
diff --git a/drivers/media/video/sn9c102/sn9c102_mi0360.c b/drivers/media/video/sn9c102/sn9c102_mi0360.c
index f8d81d82e8d5..d973fc1973d9 100644
--- a/drivers/media/video/sn9c102/sn9c102_mi0360.c
+++ b/drivers/media/video/sn9c102/sn9c102_mi0360.c
@@ -20,6 +20,7 @@
20 ***************************************************************************/ 20 ***************************************************************************/
21 21
22#include "sn9c102_sensor.h" 22#include "sn9c102_sensor.h"
23#include "sn9c102_devtable.h"
23 24
24 25
25static int mi0360_init(struct sn9c102_device* cam) 26static int mi0360_init(struct sn9c102_device* cam)
diff --git a/drivers/media/video/sn9c102/sn9c102_mt9v111.c b/drivers/media/video/sn9c102/sn9c102_mt9v111.c
index 3b98ac3bbc38..95986eb492e4 100644
--- a/drivers/media/video/sn9c102/sn9c102_mt9v111.c
+++ b/drivers/media/video/sn9c102/sn9c102_mt9v111.c
@@ -20,6 +20,7 @@
20 ***************************************************************************/ 20 ***************************************************************************/
21 21
22#include "sn9c102_sensor.h" 22#include "sn9c102_sensor.h"
23#include "sn9c102_devtable.h"
23 24
24 25
25static int mt9v111_init(struct sn9c102_device *cam) 26static int mt9v111_init(struct sn9c102_device *cam)
diff --git a/drivers/media/video/sn9c102/sn9c102_ov7630.c b/drivers/media/video/sn9c102/sn9c102_ov7630.c
index e4856fd77982..803712c29f02 100644
--- a/drivers/media/video/sn9c102/sn9c102_ov7630.c
+++ b/drivers/media/video/sn9c102/sn9c102_ov7630.c
@@ -20,6 +20,7 @@
20 ***************************************************************************/ 20 ***************************************************************************/
21 21
22#include "sn9c102_sensor.h" 22#include "sn9c102_sensor.h"
23#include "sn9c102_devtable.h"
23 24
24 25
25static int ov7630_init(struct sn9c102_device* cam) 26static int ov7630_init(struct sn9c102_device* cam)
diff --git a/drivers/media/video/sn9c102/sn9c102_ov7660.c b/drivers/media/video/sn9c102/sn9c102_ov7660.c
index 8aae416ba8ec..7977795d342b 100644
--- a/drivers/media/video/sn9c102/sn9c102_ov7660.c
+++ b/drivers/media/video/sn9c102/sn9c102_ov7660.c
@@ -20,6 +20,7 @@
20 ***************************************************************************/ 20 ***************************************************************************/
21 21
22#include "sn9c102_sensor.h" 22#include "sn9c102_sensor.h"
23#include "sn9c102_devtable.h"
23 24
24 25
25static int ov7660_init(struct sn9c102_device* cam) 26static int ov7660_init(struct sn9c102_device* cam)
diff --git a/drivers/media/video/sn9c102/sn9c102_pas106b.c b/drivers/media/video/sn9c102/sn9c102_pas106b.c
index 360f2a848bc0..81cd969c1b7b 100644
--- a/drivers/media/video/sn9c102/sn9c102_pas106b.c
+++ b/drivers/media/video/sn9c102/sn9c102_pas106b.c
@@ -21,6 +21,7 @@
21 21
22#include <linux/delay.h> 22#include <linux/delay.h>
23#include "sn9c102_sensor.h" 23#include "sn9c102_sensor.h"
24#include "sn9c102_devtable.h"
24 25
25 26
26static int pas106b_init(struct sn9c102_device* cam) 27static int pas106b_init(struct sn9c102_device* cam)
diff --git a/drivers/media/video/sn9c102/sn9c102_pas202bcb.c b/drivers/media/video/sn9c102/sn9c102_pas202bcb.c
index ca4a1506ed3d..2782f94cf6f8 100644
--- a/drivers/media/video/sn9c102/sn9c102_pas202bcb.c
+++ b/drivers/media/video/sn9c102/sn9c102_pas202bcb.c
@@ -26,6 +26,7 @@
26 26
27#include <linux/delay.h> 27#include <linux/delay.h>
28#include "sn9c102_sensor.h" 28#include "sn9c102_sensor.h"
29#include "sn9c102_devtable.h"
29 30
30 31
31static int pas202bcb_init(struct sn9c102_device* cam) 32static int pas202bcb_init(struct sn9c102_device* cam)
diff --git a/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c b/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c
index e7d2de2bace1..04cdfdde8564 100644
--- a/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c
+++ b/drivers/media/video/sn9c102/sn9c102_tas5110c1b.c
@@ -20,6 +20,7 @@
20 ***************************************************************************/ 20 ***************************************************************************/
21 21
22#include "sn9c102_sensor.h" 22#include "sn9c102_sensor.h"
23#include "sn9c102_devtable.h"
23 24
24 25
25static int tas5110c1b_init(struct sn9c102_device* cam) 26static int tas5110c1b_init(struct sn9c102_device* cam)
diff --git a/drivers/media/video/sn9c102/sn9c102_tas5110d.c b/drivers/media/video/sn9c102/sn9c102_tas5110d.c
index d32fdbccdc5e..9372e6f9fcff 100644
--- a/drivers/media/video/sn9c102/sn9c102_tas5110d.c
+++ b/drivers/media/video/sn9c102/sn9c102_tas5110d.c
@@ -20,6 +20,7 @@
20 ***************************************************************************/ 20 ***************************************************************************/
21 21
22#include "sn9c102_sensor.h" 22#include "sn9c102_sensor.h"
23#include "sn9c102_devtable.h"
23 24
24 25
25static int tas5110d_init(struct sn9c102_device* cam) 26static int tas5110d_init(struct sn9c102_device* cam)
diff --git a/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c b/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c
index 56fb1d575a8a..a30bbc4389f5 100644
--- a/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c
+++ b/drivers/media/video/sn9c102/sn9c102_tas5130d1b.c
@@ -20,6 +20,7 @@
20 ***************************************************************************/ 20 ***************************************************************************/
21 21
22#include "sn9c102_sensor.h" 22#include "sn9c102_sensor.h"
23#include "sn9c102_devtable.h"
23 24
24 25
25static int tas5130d1b_init(struct sn9c102_device* cam) 26static int tas5130d1b_init(struct sn9c102_device* cam)
diff --git a/drivers/media/video/stk-webcam.c b/drivers/media/video/stk-webcam.c
index ad36af30e099..db69bc5556d6 100644
--- a/drivers/media/video/stk-webcam.c
+++ b/drivers/media/video/stk-webcam.c
@@ -65,22 +65,6 @@ static struct usb_device_id stkwebcam_table[] = {
65}; 65};
66MODULE_DEVICE_TABLE(usb, stkwebcam_table); 66MODULE_DEVICE_TABLE(usb, stkwebcam_table);
67 67
68static void stk_camera_cleanup(struct kref *kref)
69{
70 struct stk_camera *dev = to_stk_camera(kref);
71
72 STK_INFO("Syntek USB2.0 Camera release resources"
73 " video device /dev/video%d\n", dev->vdev.minor);
74 video_unregister_device(&dev->vdev);
75 dev->vdev.priv = NULL;
76
77 if (dev->sio_bufs != NULL || dev->isobufs != NULL)
78 STK_ERROR("We are leaking memory\n");
79 usb_put_intf(dev->interface);
80 kfree(dev);
81}
82
83
84/* 68/*
85 * Basic stuff 69 * Basic stuff
86 */ 70 */
@@ -689,34 +673,24 @@ static int v4l_stk_open(struct inode *inode, struct file *fp)
689 vdev = video_devdata(fp); 673 vdev = video_devdata(fp);
690 dev = vdev_to_camera(vdev); 674 dev = vdev_to_camera(vdev);
691 675
692 if (dev == NULL || !is_present(dev)) 676 lock_kernel();
677 if (dev == NULL || !is_present(dev)) {
678 unlock_kernel();
693 return -ENXIO; 679 return -ENXIO;
694 fp->private_data = vdev; 680 }
695 kref_get(&dev->kref); 681 fp->private_data = dev;
696 usb_autopm_get_interface(dev->interface); 682 usb_autopm_get_interface(dev->interface);
683 unlock_kernel();
697 684
698 return 0; 685 return 0;
699} 686}
700 687
701static int v4l_stk_release(struct inode *inode, struct file *fp) 688static int v4l_stk_release(struct inode *inode, struct file *fp)
702{ 689{
703 struct stk_camera *dev; 690 struct stk_camera *dev = fp->private_data;
704 struct video_device *vdev;
705
706 vdev = video_devdata(fp);
707 if (vdev == NULL) {
708 STK_ERROR("v4l_release called w/o video devdata\n");
709 return -EFAULT;
710 }
711 dev = vdev_to_camera(vdev);
712 if (dev == NULL) {
713 STK_ERROR("v4l_release called on removed device\n");
714 return -ENODEV;
715 }
716 691
717 if (dev->owner != fp) { 692 if (dev->owner != fp) {
718 usb_autopm_put_interface(dev->interface); 693 usb_autopm_put_interface(dev->interface);
719 kref_put(&dev->kref, stk_camera_cleanup);
720 return 0; 694 return 0;
721 } 695 }
722 696
@@ -727,7 +701,6 @@ static int v4l_stk_release(struct inode *inode, struct file *fp)
727 dev->owner = NULL; 701 dev->owner = NULL;
728 702
729 usb_autopm_put_interface(dev->interface); 703 usb_autopm_put_interface(dev->interface);
730 kref_put(&dev->kref, stk_camera_cleanup);
731 704
732 return 0; 705 return 0;
733} 706}
@@ -738,14 +711,8 @@ static ssize_t v4l_stk_read(struct file *fp, char __user *buf,
738 int i; 711 int i;
739 int ret; 712 int ret;
740 unsigned long flags; 713 unsigned long flags;
741 struct stk_camera *dev;
742 struct video_device *vdev;
743 struct stk_sio_buffer *sbuf; 714 struct stk_sio_buffer *sbuf;
744 715 struct stk_camera *dev = fp->private_data;
745 vdev = video_devdata(fp);
746 if (vdev == NULL)
747 return -EFAULT;
748 dev = vdev_to_camera(vdev);
749 716
750 if (dev == NULL) 717 if (dev == NULL)
751 return -EIO; 718 return -EIO;
@@ -804,15 +771,8 @@ static ssize_t v4l_stk_read(struct file *fp, char __user *buf,
804 771
805static unsigned int v4l_stk_poll(struct file *fp, poll_table *wait) 772static unsigned int v4l_stk_poll(struct file *fp, poll_table *wait)
806{ 773{
807 struct stk_camera *dev; 774 struct stk_camera *dev = fp->private_data;
808 struct video_device *vdev;
809
810 vdev = video_devdata(fp);
811
812 if (vdev == NULL)
813 return -EFAULT;
814 775
815 dev = vdev_to_camera(vdev);
816 if (dev == NULL) 776 if (dev == NULL)
817 return -ENODEV; 777 return -ENODEV;
818 778
@@ -850,16 +810,12 @@ static int v4l_stk_mmap(struct file *fp, struct vm_area_struct *vma)
850 unsigned int i; 810 unsigned int i;
851 int ret; 811 int ret;
852 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; 812 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
853 struct stk_camera *dev; 813 struct stk_camera *dev = fp->private_data;
854 struct video_device *vdev;
855 struct stk_sio_buffer *sbuf = NULL; 814 struct stk_sio_buffer *sbuf = NULL;
856 815
857 if (!(vma->vm_flags & VM_WRITE) || !(vma->vm_flags & VM_SHARED)) 816 if (!(vma->vm_flags & VM_WRITE) || !(vma->vm_flags & VM_SHARED))
858 return -EINVAL; 817 return -EINVAL;
859 818
860 vdev = video_devdata(fp);
861 dev = vdev_to_camera(vdev);
862
863 for (i = 0; i < dev->n_sbufs; i++) { 819 for (i = 0; i < dev->n_sbufs; i++) {
864 if (dev->sio_bufs[i].v4lbuf.m.offset == offset) { 820 if (dev->sio_bufs[i].v4lbuf.m.offset == offset) {
865 sbuf = dev->sio_bufs + i; 821 sbuf = dev->sio_bufs + i;
@@ -1355,6 +1311,12 @@ static const struct v4l2_ioctl_ops v4l_stk_ioctl_ops = {
1355 1311
1356static void stk_v4l_dev_release(struct video_device *vd) 1312static void stk_v4l_dev_release(struct video_device *vd)
1357{ 1313{
1314 struct stk_camera *dev = vdev_to_camera(vd);
1315
1316 if (dev->sio_bufs != NULL || dev->isobufs != NULL)
1317 STK_ERROR("We are leaking memory\n");
1318 usb_put_intf(dev->interface);
1319 kfree(dev);
1358} 1320}
1359 1321
1360static struct video_device stk_v4l_data = { 1322static struct video_device stk_v4l_data = {
@@ -1375,7 +1337,6 @@ static int stk_register_video_device(struct stk_camera *dev)
1375 dev->vdev = stk_v4l_data; 1337 dev->vdev = stk_v4l_data;
1376 dev->vdev.debug = debug; 1338 dev->vdev.debug = debug;
1377 dev->vdev.parent = &dev->interface->dev; 1339 dev->vdev.parent = &dev->interface->dev;
1378 dev->vdev.priv = dev;
1379 err = video_register_device(&dev->vdev, VFL_TYPE_GRABBER, -1); 1340 err = video_register_device(&dev->vdev, VFL_TYPE_GRABBER, -1);
1380 if (err) 1341 if (err)
1381 STK_ERROR("v4l registration failed\n"); 1342 STK_ERROR("v4l registration failed\n");
@@ -1392,7 +1353,7 @@ static int stk_camera_probe(struct usb_interface *interface,
1392 const struct usb_device_id *id) 1353 const struct usb_device_id *id)
1393{ 1354{
1394 int i; 1355 int i;
1395 int err; 1356 int err = 0;
1396 1357
1397 struct stk_camera *dev = NULL; 1358 struct stk_camera *dev = NULL;
1398 struct usb_device *udev = interface_to_usbdev(interface); 1359 struct usb_device *udev = interface_to_usbdev(interface);
@@ -1405,7 +1366,6 @@ static int stk_camera_probe(struct usb_interface *interface,
1405 return -ENOMEM; 1366 return -ENOMEM;
1406 } 1367 }
1407 1368
1408 kref_init(&dev->kref);
1409 spin_lock_init(&dev->spinlock); 1369 spin_lock_init(&dev->spinlock);
1410 init_waitqueue_head(&dev->wait_frame); 1370 init_waitqueue_head(&dev->wait_frame);
1411 1371
@@ -1438,8 +1398,8 @@ static int stk_camera_probe(struct usb_interface *interface,
1438 } 1398 }
1439 if (!dev->isoc_ep) { 1399 if (!dev->isoc_ep) {
1440 STK_ERROR("Could not find isoc-in endpoint"); 1400 STK_ERROR("Could not find isoc-in endpoint");
1441 kref_put(&dev->kref, stk_camera_cleanup); 1401 err = -ENODEV;
1442 return -ENODEV; 1402 goto error;
1443 } 1403 }
1444 dev->vsettings.brightness = 0x7fff; 1404 dev->vsettings.brightness = 0x7fff;
1445 dev->vsettings.palette = V4L2_PIX_FMT_RGB565; 1405 dev->vsettings.palette = V4L2_PIX_FMT_RGB565;
@@ -1453,14 +1413,17 @@ static int stk_camera_probe(struct usb_interface *interface,
1453 1413
1454 err = stk_register_video_device(dev); 1414 err = stk_register_video_device(dev);
1455 if (err) { 1415 if (err) {
1456 kref_put(&dev->kref, stk_camera_cleanup); 1416 goto error;
1457 return err;
1458 } 1417 }
1459 1418
1460 stk_create_sysfs_files(&dev->vdev); 1419 stk_create_sysfs_files(&dev->vdev);
1461 usb_autopm_enable(dev->interface); 1420 usb_autopm_enable(dev->interface);
1462 1421
1463 return 0; 1422 return 0;
1423
1424error:
1425 kfree(dev);
1426 return err;
1464} 1427}
1465 1428
1466static void stk_camera_disconnect(struct usb_interface *interface) 1429static void stk_camera_disconnect(struct usb_interface *interface)
@@ -1473,7 +1436,10 @@ static void stk_camera_disconnect(struct usb_interface *interface)
1473 wake_up_interruptible(&dev->wait_frame); 1436 wake_up_interruptible(&dev->wait_frame);
1474 stk_remove_sysfs_files(&dev->vdev); 1437 stk_remove_sysfs_files(&dev->vdev);
1475 1438
1476 kref_put(&dev->kref, stk_camera_cleanup); 1439 STK_INFO("Syntek USB2.0 Camera release resources"
1440 "video device /dev/video%d\n", dev->vdev.minor);
1441
1442 video_unregister_device(&dev->vdev);
1477} 1443}
1478 1444
1479#ifdef CONFIG_PM 1445#ifdef CONFIG_PM
diff --git a/drivers/media/video/stk-webcam.h b/drivers/media/video/stk-webcam.h
index df4dfefc5327..084a85bdd16e 100644
--- a/drivers/media/video/stk-webcam.h
+++ b/drivers/media/video/stk-webcam.h
@@ -99,7 +99,6 @@ struct stk_camera {
99 99
100 u8 isoc_ep; 100 u8 isoc_ep;
101 101
102 struct kref kref;
103 /* Not sure if this is right */ 102 /* Not sure if this is right */
104 atomic_t urbs_used; 103 atomic_t urbs_used;
105 104
@@ -121,7 +120,6 @@ struct stk_camera {
121 unsigned sequence; 120 unsigned sequence;
122}; 121};
123 122
124#define to_stk_camera(d) container_of(d, struct stk_camera, kref)
125#define vdev_to_camera(d) container_of(d, struct stk_camera, vdev) 123#define vdev_to_camera(d) container_of(d, struct stk_camera, vdev)
126 124
127void stk_camera_delete(struct kref *); 125void stk_camera_delete(struct kref *);
diff --git a/drivers/media/video/stradis.c b/drivers/media/video/stradis.c
index 276bded06ab3..bbad54f85c83 100644
--- a/drivers/media/video/stradis.c
+++ b/drivers/media/video/stradis.c
@@ -1882,12 +1882,16 @@ static int saa_open(struct inode *inode, struct file *file)
1882 struct video_device *vdev = video_devdata(file); 1882 struct video_device *vdev = video_devdata(file);
1883 struct saa7146 *saa = container_of(vdev, struct saa7146, video_dev); 1883 struct saa7146 *saa = container_of(vdev, struct saa7146, video_dev);
1884 1884
1885 lock_kernel();
1885 file->private_data = saa; 1886 file->private_data = saa;
1886 1887
1887 saa->user++; 1888 saa->user++;
1888 if (saa->user > 1) 1889 if (saa->user > 1) {
1890 unlock_kernel();
1889 return 0; /* device open already, don't reset */ 1891 return 0; /* device open already, don't reset */
1892 }
1890 saa->writemode = VID_WRITE_MPEG_VID; /* default to video */ 1893 saa->writemode = VID_WRITE_MPEG_VID; /* default to video */
1894 unlock_kernel();
1891 return 0; 1895 return 0;
1892} 1896}
1893 1897
@@ -1921,6 +1925,7 @@ static struct video_device saa_template = {
1921 .name = "SAA7146A", 1925 .name = "SAA7146A",
1922 .fops = &saa_fops, 1926 .fops = &saa_fops,
1923 .minor = -1, 1927 .minor = -1,
1928 .release = video_device_release_empty,
1924}; 1929};
1925 1930
1926static int __devinit configure_saa7146(struct pci_dev *pdev, int num) 1931static int __devinit configure_saa7146(struct pci_dev *pdev, int num)
diff --git a/drivers/media/video/stv680.c b/drivers/media/video/stv680.c
index dce947439459..9c549d935994 100644
--- a/drivers/media/video/stv680.c
+++ b/drivers/media/video/stv680.c
@@ -84,7 +84,8 @@ static unsigned int debug;
84#define PDEBUG(level, fmt, args...) \ 84#define PDEBUG(level, fmt, args...) \
85 do { \ 85 do { \
86 if (debug >= level) \ 86 if (debug >= level) \
87 info("[%s:%d] " fmt, __func__, __LINE__ , ## args); \ 87 printk(KERN_INFO KBUILD_MODNAME " [%s:%d] \n" fmt, \
88 __func__, __LINE__ , ## args); \
88 } while (0) 89 } while (0)
89 90
90 91
@@ -1086,6 +1087,7 @@ static int stv_open (struct inode *inode, struct file *file)
1086 int err = 0; 1087 int err = 0;
1087 1088
1088 /* we are called with the BKL held */ 1089 /* we are called with the BKL held */
1090 lock_kernel();
1089 stv680->user = 1; 1091 stv680->user = 1;
1090 err = stv_init (stv680); /* main initialization routine for camera */ 1092 err = stv_init (stv680); /* main initialization routine for camera */
1091 1093
@@ -1099,6 +1101,7 @@ static int stv_open (struct inode *inode, struct file *file)
1099 } 1101 }
1100 if (err) 1102 if (err)
1101 stv680->user = 0; 1103 stv680->user = 0;
1104 unlock_kernel();
1102 1105
1103 return err; 1106 return err;
1104} 1107}
@@ -1550,7 +1553,8 @@ static int __init usb_stv680_init (void)
1550 } 1553 }
1551 PDEBUG (0, "STV(i): usb camera driver version %s registering", DRIVER_VERSION); 1554 PDEBUG (0, "STV(i): usb camera driver version %s registering", DRIVER_VERSION);
1552 1555
1553 info(DRIVER_DESC " " DRIVER_VERSION); 1556 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
1557 DRIVER_DESC "\n");
1554 return 0; 1558 return 0;
1555} 1559}
1556 1560
diff --git a/drivers/media/video/tda9840.c b/drivers/media/video/tda9840.c
index 2437c1a269c5..1c391f0328fd 100644
--- a/drivers/media/video/tda9840.c
+++ b/drivers/media/video/tda9840.c
@@ -2,6 +2,7 @@
2 tda9840 - i2c-driver for the tda9840 by SGS Thomson 2 tda9840 - i2c-driver for the tda9840 by SGS Thomson
3 3
4 Copyright (C) 1998-2003 Michael Hunold <michael@mihu.de> 4 Copyright (C) 1998-2003 Michael Hunold <michael@mihu.de>
5 Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
5 6
6 The tda9840 is a stereo/dual sound processor with digital 7 The tda9840 is a stereo/dual sound processor with digital
7 identification. It can be found at address 0x84 on the i2c-bus. 8 identification. It can be found at address 0x84 on the i2c-bus.
@@ -28,59 +29,118 @@
28#include <linux/module.h> 29#include <linux/module.h>
29#include <linux/ioctl.h> 30#include <linux/ioctl.h>
30#include <linux/i2c.h> 31#include <linux/i2c.h>
31 32#include <media/v4l2-common.h>
33#include <media/v4l2-i2c-drv-legacy.h>
32#include "tda9840.h" 34#include "tda9840.h"
33 35
34static int debug; /* insmod parameter */ 36MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
37MODULE_DESCRIPTION("tda9840 driver");
38MODULE_LICENSE("GPL");
39
40static int debug;
35module_param(debug, int, 0644); 41module_param(debug, int, 0644);
36MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
37 42
38#define dprintk(args...) \ 43MODULE_PARM_DESC(debug, "Debug level (0-1)");
39 do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __func__, __LINE__); printk(args); } } while (0)
40 44
41#define SWITCH 0x00 45#define SWITCH 0x00
42#define LEVEL_ADJUST 0x02 46#define LEVEL_ADJUST 0x02
43#define STEREO_ADJUST 0x03 47#define STEREO_ADJUST 0x03
44#define TEST 0x04 48#define TEST 0x04
45 49
50#define TDA9840_SET_MUTE 0x00
51#define TDA9840_SET_MONO 0x10
52#define TDA9840_SET_STEREO 0x2a
53#define TDA9840_SET_LANG1 0x12
54#define TDA9840_SET_LANG2 0x1e
55#define TDA9840_SET_BOTH 0x1a
56#define TDA9840_SET_BOTH_R 0x16
57#define TDA9840_SET_EXTERNAL 0x7a
58
46/* addresses to scan, found only at 0x42 (7-Bit) */ 59/* addresses to scan, found only at 0x42 (7-Bit) */
47static unsigned short normal_i2c[] = { I2C_ADDR_TDA9840, I2C_CLIENT_END }; 60static unsigned short normal_i2c[] = { I2C_ADDR_TDA9840, I2C_CLIENT_END };
48 61
49/* magic definition of all other variables and things */ 62/* magic definition of all other variables and things */
50I2C_CLIENT_INSMOD; 63I2C_CLIENT_INSMOD;
51 64
52static struct i2c_driver driver; 65static void tda9840_write(struct i2c_client *client, u8 reg, u8 val)
53static struct i2c_client client_template; 66{
67 if (i2c_smbus_write_byte_data(client, reg, val))
68 v4l_dbg(1, debug, client, "error writing %02x to %02x\n",
69 val, reg);
70}
54 71
55static int command(struct i2c_client *client, unsigned int cmd, void *arg) 72static int tda9840_command(struct i2c_client *client, unsigned cmd, void *arg)
56{ 73{
57 int result;
58 int byte = *(int *)arg; 74 int byte = *(int *)arg;
59 75
60 switch (cmd) { 76 switch (cmd) {
61 case TDA9840_SWITCH: 77 case VIDIOC_S_TUNER: {
62 78 struct v4l2_tuner *t = arg;
63 dprintk("TDA9840_SWITCH: 0x%02x\n", byte); 79 int byte;
64 80
65 if (byte != TDA9840_SET_MONO 81 if (t->index)
66 && byte != TDA9840_SET_MUTE
67 && byte != TDA9840_SET_STEREO
68 && byte != TDA9840_SET_LANG1
69 && byte != TDA9840_SET_LANG2
70 && byte != TDA9840_SET_BOTH
71 && byte != TDA9840_SET_BOTH_R
72 && byte != TDA9840_SET_EXTERNAL) {
73 return -EINVAL; 82 return -EINVAL;
83
84 switch (t->audmode) {
85 case V4L2_TUNER_MODE_STEREO:
86 byte = TDA9840_SET_STEREO;
87 break;
88 case V4L2_TUNER_MODE_LANG1_LANG2:
89 byte = TDA9840_SET_BOTH;
90 break;
91 case V4L2_TUNER_MODE_LANG1:
92 byte = TDA9840_SET_LANG1;
93 break;
94 case V4L2_TUNER_MODE_LANG2:
95 byte = TDA9840_SET_LANG2;
96 break;
97 default:
98 byte = TDA9840_SET_MONO;
99 break;
100 }
101 v4l_dbg(1, debug, client, "TDA9840_SWITCH: 0x%02x\n", byte);
102 tda9840_write(client, SWITCH, byte);
103 break;
104 }
105
106 case VIDIOC_G_TUNER: {
107 struct v4l2_tuner *t = arg;
108 u8 byte;
109
110 t->rxsubchans = V4L2_TUNER_SUB_MONO;
111 if (1 != i2c_master_recv(client, &byte, 1)) {
112 v4l_dbg(1, debug, client,
113 "i2c_master_recv() failed\n");
114 return -EIO;
74 } 115 }
75 116
76 result = i2c_smbus_write_byte_data(client, SWITCH, byte); 117 if (byte & 0x80) {
77 if (result) 118 v4l_dbg(1, debug, client,
78 dprintk("i2c_smbus_write_byte() failed, ret:%d\n", result); 119 "TDA9840_DETECT: register contents invalid\n");
120 return -EINVAL;
121 }
122
123 v4l_dbg(1, debug, client, "TDA9840_DETECT: byte: 0x%02x\n", byte);
124
125 switch (byte & 0x60) {
126 case 0x00:
127 t->rxsubchans = V4L2_TUNER_SUB_MONO;
128 break;
129 case 0x20:
130 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
131 break;
132 case 0x40:
133 t->rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;
134 break;
135 default: /* Incorrect detect */
136 t->rxsubchans = V4L2_TUNER_MODE_MONO;
137 break;
138 }
79 break; 139 break;
140 }
80 141
81 case TDA9840_LEVEL_ADJUST: 142 case TDA9840_LEVEL_ADJUST:
82 143 v4l_dbg(1, debug, client, "TDA9840_LEVEL_ADJUST: %d\n", byte);
83 dprintk("TDA9840_LEVEL_ADJUST: %d\n", byte);
84 144
85 /* check for correct range */ 145 /* check for correct range */
86 if (byte > 25 || byte < -20) 146 if (byte > 25 || byte < -20)
@@ -92,15 +152,11 @@ static int command(struct i2c_client *client, unsigned int cmd, void *arg)
92 byte += 0x8; 152 byte += 0x8;
93 else 153 else
94 byte = -byte; 154 byte = -byte;
95 155 tda9840_write(client, LEVEL_ADJUST, byte);
96 result = i2c_smbus_write_byte_data(client, LEVEL_ADJUST, byte);
97 if (result)
98 dprintk("i2c_smbus_write_byte() failed, ret:%d\n", result);
99 break; 156 break;
100 157
101 case TDA9840_STEREO_ADJUST: 158 case TDA9840_STEREO_ADJUST:
102 159 v4l_dbg(1, debug, client, "TDA9840_STEREO_ADJUST: %d\n", byte);
103 dprintk("TDA9840_STEREO_ADJUST: %d\n", byte);
104 160
105 /* check for correct range */ 161 /* check for correct range */
106 if (byte > 25 || byte < -24) 162 if (byte > 25 || byte < -24)
@@ -113,143 +169,59 @@ static int command(struct i2c_client *client, unsigned int cmd, void *arg)
113 else 169 else
114 byte = -byte; 170 byte = -byte;
115 171
116 result = i2c_smbus_write_byte_data(client, STEREO_ADJUST, byte); 172 tda9840_write(client, STEREO_ADJUST, byte);
117 if (result)
118 dprintk("i2c_smbus_write_byte() failed, ret:%d\n", result);
119 break;
120
121 case TDA9840_DETECT: {
122 int *ret = (int *)arg;
123
124 byte = i2c_smbus_read_byte_data(client, STEREO_ADJUST);
125 if (byte == -1) {
126 dprintk("i2c_smbus_read_byte_data() failed\n");
127 return -EIO;
128 }
129
130 if (0 != (byte & 0x80)) {
131 dprintk("TDA9840_DETECT: register contents invalid\n");
132 return -EINVAL;
133 }
134
135 dprintk("TDA9840_DETECT: byte: 0x%02x\n", byte);
136 *ret = ((byte & 0x60) >> 5);
137 result = 0;
138 break;
139 }
140 case TDA9840_TEST:
141 dprintk("TDA9840_TEST: 0x%02x\n", byte);
142
143 /* mask out irrelevant bits */
144 byte &= 0x3;
145
146 result = i2c_smbus_write_byte_data(client, TEST, byte);
147 if (result)
148 dprintk("i2c_smbus_write_byte() failed, ret:%d\n", result);
149 break; 173 break;
150 default: 174 default:
151 return -ENOIOCTLCMD; 175 return -ENOIOCTLCMD;
152 } 176 }
153 177
154 if (result)
155 return -EIO;
156
157 return 0; 178 return 0;
158} 179}
159 180
160static int detect(struct i2c_adapter *adapter, int address, int kind) 181static int tda9840_probe(struct i2c_client *client,
182 const struct i2c_device_id *id)
161{ 183{
162 struct i2c_client *client; 184 int result;
163 int result = 0; 185 int byte;
164
165 int byte = 0x0;
166 186
167 /* let's see whether this adapter can support what we need */ 187 /* let's see whether this adapter can support what we need */
168 if (0 == i2c_check_functionality(adapter, 188 if (!i2c_check_functionality(client->adapter,
169 I2C_FUNC_SMBUS_READ_BYTE_DATA | 189 I2C_FUNC_SMBUS_READ_BYTE_DATA |
170 I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) { 190 I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
171 return 0; 191 return 0;
172 }
173
174 /* allocate memory for client structure */
175 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
176 if (!client) {
177 printk("not enough kernel memory\n");
178 return -ENOMEM;
179 }
180
181 /* fill client structure */
182 memcpy(client, &client_template, sizeof(struct i2c_client));
183 client->addr = address;
184 client->adapter = adapter;
185 192
186 /* tell the i2c layer a new client has arrived */ 193 v4l_info(client, "chip found @ 0x%x (%s)\n",
187 if (0 != (result = i2c_attach_client(client))) { 194 client->addr << 1, client->adapter->name);
188 kfree(client);
189 return result;
190 }
191 195
192 /* set initial values for level & stereo - adjustment, mode */ 196 /* set initial values for level & stereo - adjustment, mode */
193 byte = 0; 197 byte = 0;
194 result = command(client, TDA9840_LEVEL_ADJUST, &byte); 198 result = tda9840_command(client, TDA9840_LEVEL_ADJUST, &byte);
195 result += command(client, TDA9840_STEREO_ADJUST, &byte); 199 result += tda9840_command(client, TDA9840_STEREO_ADJUST, &byte);
196 byte = TDA9840_SET_MONO; 200 tda9840_write(client, SWITCH, TDA9840_SET_STEREO);
197 result = command(client, TDA9840_SWITCH, &byte);
198 if (result) { 201 if (result) {
199 dprintk("could not initialize tda9840\n"); 202 v4l_dbg(1, debug, client, "could not initialize tda9840\n");
200 return -ENODEV; 203 return -ENODEV;
201 } 204 }
202
203 printk("tda9840: detected @ 0x%02x on adapter %s\n", address, &client->adapter->name[0]);
204 return 0; 205 return 0;
205} 206}
206 207
207static int attach(struct i2c_adapter *adapter) 208static int tda9840_legacy_probe(struct i2c_adapter *adapter)
208{
209 /* let's see whether this is a know adapter we can attach to */
210 if (adapter->id != I2C_HW_SAA7146) {
211 dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter->name, adapter->id);
212 return -ENODEV;
213 }
214
215 return i2c_probe(adapter, &addr_data, &detect);
216}
217
218static int detach(struct i2c_client *client)
219{ 209{
220 int ret = i2c_detach_client(client); 210 /* Let's see whether this is a known adapter we can attach to.
221 kfree(client); 211 Prevents conflicts with tvaudio.c. */
222 return ret; 212 return adapter->id == I2C_HW_SAA7146;
223} 213}
224 214static const struct i2c_device_id tda9840_id[] = {
225static struct i2c_driver driver = { 215 { "tda9840", 0 },
226 .driver = { 216 { }
227 .name = "tda9840",
228 },
229 .id = I2C_DRIVERID_TDA9840,
230 .attach_adapter = attach,
231 .detach_client = detach,
232 .command = command,
233}; 217};
218MODULE_DEVICE_TABLE(i2c, tda9840_id);
234 219
235static struct i2c_client client_template = { 220static struct v4l2_i2c_driver_data v4l2_i2c_data = {
236 .name = "tda9840", 221 .name = "tda9840",
237 .driver = &driver, 222 .driverid = I2C_DRIVERID_TDA9840,
223 .command = tda9840_command,
224 .probe = tda9840_probe,
225 .legacy_probe = tda9840_legacy_probe,
226 .id_table = tda9840_id,
238}; 227};
239
240static int __init this_module_init(void)
241{
242 return i2c_add_driver(&driver);
243}
244
245static void __exit this_module_exit(void)
246{
247 i2c_del_driver(&driver);
248}
249
250module_init(this_module_init);
251module_exit(this_module_exit);
252
253MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
254MODULE_DESCRIPTION("tda9840 driver");
255MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/tda9840.h b/drivers/media/video/tda9840.h
index 7da8432cdca7..dc12ae7caf6f 100644
--- a/drivers/media/video/tda9840.h
+++ b/drivers/media/video/tda9840.h
@@ -3,24 +3,6 @@
3 3
4#define I2C_ADDR_TDA9840 0x42 4#define I2C_ADDR_TDA9840 0x42
5 5
6#define TDA9840_DETECT _IOR('v',1,int)
7/* return values for TDA9840_DETCT */
8#define TDA9840_MONO_DETECT 0x0
9#define TDA9840_DUAL_DETECT 0x1
10#define TDA9840_STEREO_DETECT 0x2
11#define TDA9840_INCORRECT_DETECT 0x3
12
13#define TDA9840_SWITCH _IOW('v',2,int)
14/* modes than can be set with TDA9840_SWITCH */
15#define TDA9840_SET_MUTE 0x00
16#define TDA9840_SET_MONO 0x10
17#define TDA9840_SET_STEREO 0x2a
18#define TDA9840_SET_LANG1 0x12
19#define TDA9840_SET_LANG2 0x1e
20#define TDA9840_SET_BOTH 0x1a
21#define TDA9840_SET_BOTH_R 0x16
22#define TDA9840_SET_EXTERNAL 0x7a
23
24/* values may range between +2.5 and -2.0; 6/* values may range between +2.5 and -2.0;
25 the value has to be multiplied with 10 */ 7 the value has to be multiplied with 10 */
26#define TDA9840_LEVEL_ADJUST _IOW('v',3,int) 8#define TDA9840_LEVEL_ADJUST _IOW('v',3,int)
@@ -29,7 +11,4 @@
29 the value has to be multiplied with 10 */ 11 the value has to be multiplied with 10 */
30#define TDA9840_STEREO_ADJUST _IOW('v',4,int) 12#define TDA9840_STEREO_ADJUST _IOW('v',4,int)
31 13
32/* currently not implemented */
33#define TDA9840_TEST _IOW('v',5,int)
34
35#endif 14#endif
diff --git a/drivers/media/video/tea6415c.c b/drivers/media/video/tea6415c.c
index 421c1445e96c..cde092adbb5a 100644
--- a/drivers/media/video/tea6415c.c
+++ b/drivers/media/video/tea6415c.c
@@ -2,6 +2,7 @@
2 tea6415c - i2c-driver for the tea6415c by SGS Thomson 2 tea6415c - i2c-driver for the tea6415c by SGS Thomson
3 3
4 Copyright (C) 1998-2003 Michael Hunold <michael@mihu.de> 4 Copyright (C) 1998-2003 Michael Hunold <michael@mihu.de>
5 Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
5 6
6 The tea6415c is a bus controlled video-matrix-switch 7 The tea6415c is a bus controlled video-matrix-switch
7 with 8 inputs and 6 outputs. 8 with 8 inputs and 6 outputs.
@@ -30,18 +31,18 @@
30#include <linux/module.h> 31#include <linux/module.h>
31#include <linux/ioctl.h> 32#include <linux/ioctl.h>
32#include <linux/i2c.h> 33#include <linux/i2c.h>
33 34#include <media/v4l2-common.h>
35#include <media/v4l2-i2c-drv-legacy.h>
34#include "tea6415c.h" 36#include "tea6415c.h"
35 37
36static int debug; /* insmod parameter */ 38MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
37module_param(debug, int, 0644); 39MODULE_DESCRIPTION("tea6415c driver");
38MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off)."); 40MODULE_LICENSE("GPL");
39 41
40#define dprintk(args...) \ 42static int debug;
41 do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __func__, __LINE__); printk(args); } } while (0) 43module_param(debug, int, 0644);
42 44
43#define TEA6415C_NUM_INPUTS 8 45MODULE_PARM_DESC(debug, "Debug level (0-1)");
44#define TEA6415C_NUM_OUTPUTS 6
45 46
46/* addresses to scan, found only at 0x03 and/or 0x43 (7-bit) */ 47/* addresses to scan, found only at 0x03 and/or 0x43 (7-bit) */
47static unsigned short normal_i2c[] = { I2C_TEA6415C_1, I2C_TEA6415C_2, I2C_CLIENT_END }; 48static unsigned short normal_i2c[] = { I2C_TEA6415C_1, I2C_TEA6415C_2, I2C_CLIENT_END };
@@ -49,60 +50,6 @@ static unsigned short normal_i2c[] = { I2C_TEA6415C_1, I2C_TEA6415C_2, I2C_CLIEN
49/* magic definition of all other variables and things */ 50/* magic definition of all other variables and things */
50I2C_CLIENT_INSMOD; 51I2C_CLIENT_INSMOD;
51 52
52static struct i2c_driver driver;
53static struct i2c_client client_template;
54
55/* this function is called by i2c_probe */
56static int detect(struct i2c_adapter *adapter, int address, int kind)
57{
58 struct i2c_client *client = NULL;
59 int err = 0;
60
61 /* let's see whether this adapter can support what we need */
62 if (0 == i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE)) {
63 return 0;
64 }
65
66 /* allocate memory for client structure */
67 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
68 if (!client) {
69 return -ENOMEM;
70 }
71
72 /* fill client structure */
73 memcpy(client, &client_template, sizeof(struct i2c_client));
74 client->addr = address;
75 client->adapter = adapter;
76
77 /* tell the i2c layer a new client has arrived */
78 if (0 != (err = i2c_attach_client(client))) {
79 kfree(client);
80 return err;
81 }
82
83 printk("tea6415c: detected @ 0x%02x on adapter %s\n", address, &client->adapter->name[0]);
84
85 return 0;
86}
87
88static int attach(struct i2c_adapter *adapter)
89{
90 /* let's see whether this is a know adapter we can attach to */
91 if (adapter->id != I2C_HW_SAA7146) {
92 dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter->name, adapter->id);
93 return -ENODEV;
94 }
95
96 return i2c_probe(adapter, &addr_data, &detect);
97}
98
99static int detach(struct i2c_client *client)
100{
101 int ret = i2c_detach_client(client);
102 kfree(client);
103 return ret;
104}
105
106/* makes a connection between the input-pin 'i' and the output-pin 'o' 53/* makes a connection between the input-pin 'i' and the output-pin 'o'
107 for the tea6415c-client 'client' */ 54 for the tea6415c-client 'client' */
108static int switch_matrix(struct i2c_client *client, int i, int o) 55static int switch_matrix(struct i2c_client *client, int i, int o)
@@ -110,7 +57,7 @@ static int switch_matrix(struct i2c_client *client, int i, int o)
110 u8 byte = 0; 57 u8 byte = 0;
111 int ret; 58 int ret;
112 59
113 dprintk("adr:0x%02x, i:%d, o:%d\n", client->addr, i, o); 60 v4l_dbg(1, debug, client, "i=%d, o=%d\n", i, o);
114 61
115 /* check if the pins are valid */ 62 /* check if the pins are valid */
116 if (0 == ((1 == i || 3 == i || 5 == i || 6 == i || 8 == i || 10 == i || 20 == i || 11 == i) 63 if (0 == ((1 == i || 3 == i || 5 == i || 6 == i || 8 == i || 10 == i || 20 == i || 11 == i)
@@ -168,14 +115,14 @@ static int switch_matrix(struct i2c_client *client, int i, int o)
168 115
169 ret = i2c_smbus_write_byte(client, byte); 116 ret = i2c_smbus_write_byte(client, byte);
170 if (ret) { 117 if (ret) {
171 dprintk("i2c_smbus_write_byte() failed, ret:%d\n", ret); 118 v4l_dbg(1, debug, client,
119 "i2c_smbus_write_byte() failed, ret:%d\n", ret);
172 return -EIO; 120 return -EIO;
173 } 121 }
174
175 return ret; 122 return ret;
176} 123}
177 124
178static int command(struct i2c_client *client, unsigned int cmd, void *arg) 125static int tea6415c_command(struct i2c_client *client, unsigned cmd, void *arg)
179{ 126{
180 struct tea6415c_multiplex *v = (struct tea6415c_multiplex *)arg; 127 struct tea6415c_multiplex *v = (struct tea6415c_multiplex *)arg;
181 int result = 0; 128 int result = 0;
@@ -187,38 +134,40 @@ static int command(struct i2c_client *client, unsigned int cmd, void *arg)
187 default: 134 default:
188 return -ENOIOCTLCMD; 135 return -ENOIOCTLCMD;
189 } 136 }
190
191 return result; 137 return result;
192} 138}
193 139
194static struct i2c_driver driver = { 140/* this function is called by i2c_probe */
195 .driver = { 141static int tea6415c_probe(struct i2c_client *client,
196 .name = "tea6415c", 142 const struct i2c_device_id *id)
197 },
198 .id = I2C_DRIVERID_TEA6415C,
199 .attach_adapter = attach,
200 .detach_client = detach,
201 .command = command,
202};
203
204static struct i2c_client client_template = {
205 .name = "tea6415c",
206 .driver = &driver,
207};
208
209static int __init this_module_init(void)
210{ 143{
211 return i2c_add_driver(&driver); 144 /* let's see whether this adapter can support what we need */
145 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WRITE_BYTE))
146 return 0;
147
148 v4l_info(client, "chip found @ 0x%x (%s)\n",
149 client->addr << 1, client->adapter->name);
150 return 0;
212} 151}
213 152
214static void __exit this_module_exit(void) 153static int tea6415c_legacy_probe(struct i2c_adapter *adapter)
215{ 154{
216 i2c_del_driver(&driver); 155 /* Let's see whether this is a known adapter we can attach to.
156 Prevents conflicts with tvaudio.c. */
157 return adapter->id == I2C_HW_SAA7146;
217} 158}
218 159
219module_init(this_module_init); 160static const struct i2c_device_id tea6415c_id[] = {
220module_exit(this_module_exit); 161 { "tea6415c", 0 },
162 { }
163};
164MODULE_DEVICE_TABLE(i2c, tea6415c_id);
221 165
222MODULE_AUTHOR("Michael Hunold <michael@mihu.de>"); 166static struct v4l2_i2c_driver_data v4l2_i2c_data = {
223MODULE_DESCRIPTION("tea6415c driver"); 167 .name = "tea6415c",
224MODULE_LICENSE("GPL"); 168 .driverid = I2C_DRIVERID_TEA6415C,
169 .command = tea6415c_command,
170 .probe = tea6415c_probe,
171 .legacy_probe = tea6415c_legacy_probe,
172 .id_table = tea6415c_id,
173};
diff --git a/drivers/media/video/tea6420.c b/drivers/media/video/tea6420.c
index b5c8957d130e..e50820969e64 100644
--- a/drivers/media/video/tea6420.c
+++ b/drivers/media/video/tea6420.c
@@ -2,6 +2,7 @@
2 tea6420 - i2c-driver for the tea6420 by SGS Thomson 2 tea6420 - i2c-driver for the tea6420 by SGS Thomson
3 3
4 Copyright (C) 1998-2003 Michael Hunold <michael@mihu.de> 4 Copyright (C) 1998-2003 Michael Hunold <michael@mihu.de>
5 Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
5 6
6 The tea6420 is a bus controlled audio-matrix with 5 stereo inputs, 7 The tea6420 is a bus controlled audio-matrix with 5 stereo inputs,
7 4 stereo outputs and gain control for each output. 8 4 stereo outputs and gain control for each output.
@@ -30,15 +31,18 @@
30#include <linux/module.h> 31#include <linux/module.h>
31#include <linux/ioctl.h> 32#include <linux/ioctl.h>
32#include <linux/i2c.h> 33#include <linux/i2c.h>
33 34#include <media/v4l2-common.h>
35#include <media/v4l2-i2c-drv-legacy.h>
34#include "tea6420.h" 36#include "tea6420.h"
35 37
36static int debug; /* insmod parameter */ 38MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
39MODULE_DESCRIPTION("tea6420 driver");
40MODULE_LICENSE("GPL");
41
42static int debug;
37module_param(debug, int, 0644); 43module_param(debug, int, 0644);
38MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
39 44
40#define dprintk(args...) \ 45MODULE_PARM_DESC(debug, "Debug level (0-1)");
41 do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __func__, __LINE__); printk(args); } } while (0)
42 46
43/* addresses to scan, found only at 0x4c and/or 0x4d (7-Bit) */ 47/* addresses to scan, found only at 0x4c and/or 0x4d (7-Bit) */
44static unsigned short normal_i2c[] = { I2C_ADDR_TEA6420_1, I2C_ADDR_TEA6420_2, I2C_CLIENT_END }; 48static unsigned short normal_i2c[] = { I2C_ADDR_TEA6420_1, I2C_ADDR_TEA6420_2, I2C_CLIENT_END };
@@ -46,23 +50,20 @@ static unsigned short normal_i2c[] = { I2C_ADDR_TEA6420_1, I2C_ADDR_TEA6420_2, I
46/* magic definition of all other variables and things */ 50/* magic definition of all other variables and things */
47I2C_CLIENT_INSMOD; 51I2C_CLIENT_INSMOD;
48 52
49static struct i2c_driver driver;
50static struct i2c_client client_template;
51
52/* make a connection between the input 'i' and the output 'o' 53/* make a connection between the input 'i' and the output 'o'
53 with gain 'g' for the tea6420-client 'client' (note: i = 6 means 'mute') */ 54 with gain 'g' for the tea6420-client 'client' (note: i = 6 means 'mute') */
54static int tea6420_switch(struct i2c_client *client, int i, int o, int g) 55static int tea6420_switch(struct i2c_client *client, int i, int o, int g)
55{ 56{
56 u8 byte = 0; 57 u8 byte;
57 int ret; 58 int ret;
58 59
59 dprintk("adr:0x%02x, i:%d, o:%d, g:%d\n", client->addr, i, o, g); 60 v4l_dbg(1, debug, client, "i=%d, o=%d, g=%d\n", i, o, g);
60 61
61 /* check if the parameters are valid */ 62 /* check if the parameters are valid */
62 if (i < 1 || i > 6 || o < 1 || o > 4 || g < 0 || g > 6 || g % 2 != 0) 63 if (i < 1 || i > 6 || o < 1 || o > 4 || g < 0 || g > 6 || g % 2 != 0)
63 return -1; 64 return -1;
64 65
65 byte = ((o - 1) << 5); 66 byte = ((o - 1) << 5);
66 byte |= (i - 1); 67 byte |= (i - 1);
67 68
68 /* to understand this, have a look at the tea6420-specs (p.5) */ 69 /* to understand this, have a look at the tea6420-specs (p.5) */
@@ -82,40 +83,41 @@ static int tea6420_switch(struct i2c_client *client, int i, int o, int g)
82 83
83 ret = i2c_smbus_write_byte(client, byte); 84 ret = i2c_smbus_write_byte(client, byte);
84 if (ret) { 85 if (ret) {
85 dprintk("i2c_smbus_write_byte() failed, ret:%d\n", ret); 86 v4l_dbg(1, debug, client,
87 "i2c_smbus_write_byte() failed, ret:%d\n", ret);
86 return -EIO; 88 return -EIO;
87 } 89 }
88
89 return 0; 90 return 0;
90} 91}
91 92
92/* this function is called by i2c_probe */ 93static int tea6420_command(struct i2c_client *client, unsigned cmd, void *arg)
93static int tea6420_detect(struct i2c_adapter *adapter, int address, int kind)
94{ 94{
95 struct i2c_client *client; 95 struct tea6420_multiplex *a = (struct tea6420_multiplex *)arg;
96 int err = 0, i = 0; 96 int result = 0;
97 97
98 /* let's see whether this adapter can support what we need */ 98 switch (cmd) {
99 if (0 == i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE)) { 99 case TEA6420_SWITCH:
100 return 0; 100 result = tea6420_switch(client, a->in, a->out, a->gain);
101 break;
102 default:
103 return -ENOIOCTLCMD;
101 } 104 }
102 105
103 /* allocate memory for client structure */ 106 return result;
104 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); 107}
105 if (!client) {
106 return -ENOMEM;
107 }
108 108
109 /* fill client structure */ 109/* this function is called by i2c_probe */
110 memcpy(client, &client_template, sizeof(struct i2c_client)); 110static int tea6420_probe(struct i2c_client *client,
111 client->addr = address; 111 const struct i2c_device_id *id)
112 client->adapter = adapter; 112{
113 int err, i;
113 114
114 /* tell the i2c layer a new client has arrived */ 115 /* let's see whether this adapter can support what we need */
115 if (0 != (err = i2c_attach_client(client))) { 116 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WRITE_BYTE))
116 kfree(client); 117 return -EIO;
117 return err; 118
118 } 119 v4l_info(client, "chip found @ 0x%x (%s)\n",
120 client->addr << 1, client->adapter->name);
119 121
120 /* set initial values: set "mute"-input to all outputs at gain 0 */ 122 /* set initial values: set "mute"-input to all outputs at gain 0 */
121 err = 0; 123 err = 0;
@@ -123,78 +125,31 @@ static int tea6420_detect(struct i2c_adapter *adapter, int address, int kind)
123 err += tea6420_switch(client, 6, i, 0); 125 err += tea6420_switch(client, 6, i, 0);
124 } 126 }
125 if (err) { 127 if (err) {
126 dprintk("could not initialize tea6420\n"); 128 v4l_dbg(1, debug, client, "could not initialize tea6420\n");
127 kfree(client); 129 kfree(client);
128 return -ENODEV; 130 return -ENODEV;
129 } 131 }
130
131 printk("tea6420: detected @ 0x%02x on adapter %s\n", address, &client->adapter->name[0]);
132
133 return 0; 132 return 0;
134} 133}
135 134
136static int attach(struct i2c_adapter *adapter) 135static int tea6420_legacy_probe(struct i2c_adapter *adapter)
137{ 136{
138 /* let's see whether this is a know adapter we can attach to */ 137 /* Let's see whether this is a known adapter we can attach to.
139 if (adapter->id != I2C_HW_SAA7146) { 138 Prevents conflicts with tvaudio.c. */
140 dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter->name, adapter->id); 139 return adapter->id == I2C_HW_SAA7146;
141 return -ENODEV;
142 }
143
144 return i2c_probe(adapter, &addr_data, &tea6420_detect);
145}
146
147static int detach(struct i2c_client *client)
148{
149 int ret = i2c_detach_client(client);
150 kfree(client);
151 return ret;
152}
153
154static int command(struct i2c_client *client, unsigned int cmd, void *arg)
155{
156 struct tea6420_multiplex *a = (struct tea6420_multiplex *)arg;
157 int result = 0;
158
159 switch (cmd) {
160 case TEA6420_SWITCH:
161 result = tea6420_switch(client, a->in, a->out, a->gain);
162 break;
163 default:
164 return -ENOIOCTLCMD;
165 }
166
167 return result;
168} 140}
169 141
170static struct i2c_driver driver = { 142static const struct i2c_device_id tea6420_id[] = {
171 .driver = { 143 { "tea6420", 0 },
172 .name = "tea6420", 144 { }
173 },
174 .id = I2C_DRIVERID_TEA6420,
175 .attach_adapter = attach,
176 .detach_client = detach,
177 .command = command,
178}; 145};
146MODULE_DEVICE_TABLE(i2c, tea6420_id);
179 147
180static struct i2c_client client_template = { 148static struct v4l2_i2c_driver_data v4l2_i2c_data = {
181 .name = "tea6420", 149 .name = "tea6420",
182 .driver = &driver, 150 .driverid = I2C_DRIVERID_TEA6420,
151 .command = tea6420_command,
152 .probe = tea6420_probe,
153 .legacy_probe = tea6420_legacy_probe,
154 .id_table = tea6420_id,
183}; 155};
184
185static int __init this_module_init(void)
186{
187 return i2c_add_driver(&driver);
188}
189
190static void __exit this_module_exit(void)
191{
192 i2c_del_driver(&driver);
193}
194
195module_init(this_module_init);
196module_exit(this_module_exit);
197
198MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
199MODULE_DESCRIPTION("tea6420 driver");
200MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/tuner-3036.c b/drivers/media/video/tuner-3036.c
deleted file mode 100644
index bdf506e6ae27..000000000000
--- a/drivers/media/video/tuner-3036.c
+++ /dev/null
@@ -1,214 +0,0 @@
1/*
2 * Driver for Philips SAB3036 "CITAC" tuner control chip.
3 *
4 * Author: Phil Blundell <philb@gnu.org>
5 *
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
8 * the support into that file. So instead we have a separate driver.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 */
15
16#include <linux/module.h>
17#include <linux/kernel.h>
18#include <linux/sched.h>
19#include <linux/string.h>
20#include <linux/timer.h>
21#include <linux/delay.h>
22#include <linux/errno.h>
23#include <linux/slab.h>
24#include <linux/init.h>
25
26#include <linux/i2c.h>
27#include <linux/videodev.h>
28#include <media/v4l2-common.h>
29
30#include <media/tuner.h>
31
32static int debug; /* insmod parameter */
33static int this_adap;
34
35static struct i2c_client client_template;
36
37/* Addresses to scan */
38static unsigned short normal_i2c[] = { 0x60, 0x61, I2C_CLIENT_END };
39static unsigned short ignore = I2C_CLIENT_END;
40
41static struct i2c_client_address_data addr_data = {
42 .normal_i2c = normal_i2c,
43 .probe = &ignore,
44 .ignore = &ignore,
45};
46
47/* ---------------------------------------------------------------------- */
48
49static unsigned char
50tuner_getstatus (struct i2c_client *c)
51{
52 unsigned char byte;
53 if (i2c_master_recv(c, &byte, 1) != 1)
54 printk(KERN_ERR "tuner-3036: I/O error.\n");
55 return byte;
56}
57
58#define TUNER_FL 0x80
59
60static int
61tuner_islocked (struct i2c_client *c)
62{
63 return (tuner_getstatus(c) & TUNER_FL);
64}
65
66/* ---------------------------------------------------------------------- */
67
68static void
69set_tv_freq(struct i2c_client *c, int freq)
70{
71 u16 div = ((freq * 20) / 16);
72 unsigned long give_up = jiffies + HZ;
73 unsigned char buffer[2];
74
75 if (debug)
76 printk(KERN_DEBUG "tuner: setting frequency %dMHz, divisor %x\n", freq / 16, div);
77
78 /* Select high tuning current */
79 buffer[0] = 0x29;
80 buffer[1] = 0x3e;
81
82 if (i2c_master_send(c, buffer, 2) != 2)
83 printk("tuner: i2c i/o error 1\n");
84
85 buffer[0] = 0x80 | ((div>>8) & 0x7f);
86 buffer[1] = div & 0xff;
87
88 if (i2c_master_send(c, buffer, 2) != 2)
89 printk("tuner: i2c i/o error 2\n");
90
91 while (!tuner_islocked(c) && time_before(jiffies, give_up))
92 schedule();
93
94 if (!tuner_islocked(c))
95 printk(KERN_WARNING "tuner: failed to achieve PLL lock\n");
96
97 /* Select low tuning current and engage AFC */
98 buffer[0] = 0x29;
99 buffer[1] = 0xb2;
100
101 if (i2c_master_send(c, buffer, 2) != 2)
102 printk("tuner: i2c i/o error 3\n");
103
104 if (debug)
105 printk(KERN_DEBUG "tuner: status %02x\n", tuner_getstatus(c));
106}
107
108/* ---------------------------------------------------------------------- */
109
110static int
111tuner_attach(struct i2c_adapter *adap, int addr, int kind)
112{
113 static unsigned char buffer[] = { 0x29, 0x32, 0x2a, 0, 0x2b, 0 };
114
115 struct i2c_client *client;
116
117 if (this_adap > 0)
118 return -1;
119 this_adap++;
120
121 client_template.adapter = adap;
122 client_template.addr = addr;
123
124 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
125 if (client == NULL)
126 return -ENOMEM;
127 memcpy(client, &client_template, sizeof(struct i2c_client));
128
129 printk("tuner: SAB3036 found, status %02x\n", tuner_getstatus(client));
130
131 i2c_attach_client(client);
132
133 if (i2c_master_send(client, buffer, 2) != 2)
134 printk("tuner: i2c i/o error 1\n");
135 if (i2c_master_send(client, buffer+2, 2) != 2)
136 printk("tuner: i2c i/o error 2\n");
137 if (i2c_master_send(client, buffer+4, 2) != 2)
138 printk("tuner: i2c i/o error 3\n");
139 return 0;
140}
141
142static int
143tuner_detach(struct i2c_client *c)
144{
145 return 0;
146}
147
148static int
149tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
150{
151 int *iarg = (int*)arg;
152
153 switch (cmd)
154 {
155 case VIDIOCSFREQ:
156 set_tv_freq(client, *iarg);
157 break;
158
159 default:
160 return -EINVAL;
161 }
162 return 0;
163}
164
165static int
166tuner_probe(struct i2c_adapter *adap)
167{
168 this_adap = 0;
169 if (adap->id == I2C_HW_B_LP)
170 return i2c_probe(adap, &addr_data, tuner_attach);
171 return 0;
172}
173
174/* ----------------------------------------------------------------------- */
175
176static struct i2c_driver
177i2c_driver_tuner =
178{
179 .driver = {
180 .name = "sab3036",
181 },
182 .id = I2C_DRIVERID_SAB3036,
183 .attach_adapter = tuner_probe,
184 .detach_client = tuner_detach,
185 .command = tuner_command
186};
187
188static struct i2c_client client_template =
189{
190 .driver = &i2c_driver_tuner,
191 .name = "SAB3036",
192};
193
194static int __init
195tuner3036_init(void)
196{
197 return i2c_add_driver(&i2c_driver_tuner);
198}
199
200static void __exit
201tuner3036_exit(void)
202{
203 i2c_del_driver(&i2c_driver_tuner);
204}
205
206MODULE_DESCRIPTION("SAB3036 tuner driver");
207MODULE_AUTHOR("Philip Blundell <philb@gnu.org>");
208MODULE_LICENSE("GPL");
209
210module_param(debug, int, 0);
211MODULE_PARM_DESC(debug,"Enable debugging output");
212
213module_init(tuner3036_init);
214module_exit(tuner3036_exit);
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index d806a3556eed..4a7735c6c1a6 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -92,7 +92,6 @@ struct tuner {
92 92
93 unsigned int type; /* chip type id */ 93 unsigned int type; /* chip type id */
94 unsigned int config; 94 unsigned int config;
95 int (*tuner_callback) (void *dev, int command, int arg);
96 const char *name; 95 const char *name;
97}; 96};
98 97
@@ -346,7 +345,7 @@ static struct xc5000_config xc5000_cfg;
346 345
347static void set_type(struct i2c_client *c, unsigned int type, 346static void set_type(struct i2c_client *c, unsigned int type,
348 unsigned int new_mode_mask, unsigned int new_config, 347 unsigned int new_mode_mask, unsigned int new_config,
349 int (*tuner_callback) (void *dev, int command,int arg)) 348 int (*tuner_callback) (void *dev, int component, int cmd, int arg))
350{ 349{
351 struct tuner *t = i2c_get_clientdata(c); 350 struct tuner *t = i2c_get_clientdata(c);
352 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops; 351 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
@@ -362,7 +361,7 @@ static void set_type(struct i2c_client *c, unsigned int type,
362 t->config = new_config; 361 t->config = new_config;
363 if (tuner_callback != NULL) { 362 if (tuner_callback != NULL) {
364 tuner_dbg("defining GPIO callback\n"); 363 tuner_dbg("defining GPIO callback\n");
365 t->tuner_callback = tuner_callback; 364 t->fe.callback = tuner_callback;
366 } 365 }
367 366
368 if (t->mode == T_UNINITIALIZED) { 367 if (t->mode == T_UNINITIALIZED) {
@@ -385,7 +384,6 @@ static void set_type(struct i2c_client *c, unsigned int type,
385 { 384 {
386 struct tda829x_config cfg = { 385 struct tda829x_config cfg = {
387 .lna_cfg = t->config, 386 .lna_cfg = t->config,
388 .tuner_callback = t->tuner_callback,
389 }; 387 };
390 if (!dvb_attach(tda829x_attach, &t->fe, t->i2c->adapter, 388 if (!dvb_attach(tda829x_attach, &t->fe, t->i2c->adapter,
391 t->i2c->addr, &cfg)) 389 t->i2c->addr, &cfg))
@@ -433,7 +431,6 @@ static void set_type(struct i2c_client *c, unsigned int type,
433 struct xc2028_config cfg = { 431 struct xc2028_config cfg = {
434 .i2c_adap = t->i2c->adapter, 432 .i2c_adap = t->i2c->adapter,
435 .i2c_addr = t->i2c->addr, 433 .i2c_addr = t->i2c->addr,
436 .callback = t->tuner_callback,
437 }; 434 };
438 if (!dvb_attach(xc2028_attach, &t->fe, &cfg)) 435 if (!dvb_attach(xc2028_attach, &t->fe, &cfg))
439 goto attach_failed; 436 goto attach_failed;
@@ -450,10 +447,8 @@ static void set_type(struct i2c_client *c, unsigned int type,
450 447
451 xc5000_cfg.i2c_address = t->i2c->addr; 448 xc5000_cfg.i2c_address = t->i2c->addr;
452 xc5000_cfg.if_khz = 5380; 449 xc5000_cfg.if_khz = 5380;
453 xc5000_cfg.tuner_callback = t->tuner_callback;
454 if (!dvb_attach(xc5000_attach, 450 if (!dvb_attach(xc5000_attach,
455 &t->fe, t->i2c->adapter, &xc5000_cfg, 451 &t->fe, t->i2c->adapter, &xc5000_cfg))
456 c->adapter->algo_data))
457 goto attach_failed; 452 goto attach_failed;
458 453
459 xc_tuner_ops = &t->fe.ops.tuner_ops; 454 xc_tuner_ops = &t->fe.ops.tuner_ops;
@@ -1225,7 +1220,7 @@ register_client:
1225 } else { 1220 } else {
1226 t->mode = V4L2_TUNER_DIGITAL_TV; 1221 t->mode = V4L2_TUNER_DIGITAL_TV;
1227 } 1222 }
1228 set_type(client, t->type, t->mode_mask, t->config, t->tuner_callback); 1223 set_type(client, t->type, t->mode_mask, t->config, t->fe.callback);
1229 list_add_tail(&t->list, &tuner_list); 1224 list_add_tail(&t->list, &tuner_list);
1230 return 0; 1225 return 0;
1231} 1226}
diff --git a/drivers/media/video/usbvideo/ibmcam.c b/drivers/media/video/usbvideo/ibmcam.c
index cc27efe121dd..28421d386f1e 100644
--- a/drivers/media/video/usbvideo/ibmcam.c
+++ b/drivers/media/video/usbvideo/ibmcam.c
@@ -258,7 +258,9 @@ static enum ParseState ibmcam_find_header(struct uvd *uvd) /* FIXME: Add frame h
258 (RING_QUEUE_PEEK(&uvd->dp, 2) == 0x00)) 258 (RING_QUEUE_PEEK(&uvd->dp, 2) == 0x00))
259 { 259 {
260#if 0 /* This code helps to detect new frame markers */ 260#if 0 /* This code helps to detect new frame markers */
261 info("Header sig: 00 FF 00 %02X", RING_QUEUE_PEEK(&uvd->dp, 3)); 261 dev_info(&uvd->dev->dev,
262 "Header sig: 00 FF 00 %02X\n",
263 RING_QUEUE_PEEK(&uvd->dp, 3));
262#endif 264#endif
263 frame->header = RING_QUEUE_PEEK(&uvd->dp, 3); 265 frame->header = RING_QUEUE_PEEK(&uvd->dp, 3);
264 if ((frame->header == HDRSIG_MODEL1_128x96) || 266 if ((frame->header == HDRSIG_MODEL1_128x96) ||
@@ -266,7 +268,8 @@ static enum ParseState ibmcam_find_header(struct uvd *uvd) /* FIXME: Add frame h
266 (frame->header == HDRSIG_MODEL1_352x288)) 268 (frame->header == HDRSIG_MODEL1_352x288))
267 { 269 {
268#if 0 270#if 0
269 info("Header found."); 271 dev_info(&uvd->dev->dev,
272 "Header found.\n");
270#endif 273#endif
271 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, marker_len); 274 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, marker_len);
272 icam->has_hdr = 1; 275 icam->has_hdr = 1;
@@ -295,7 +298,7 @@ case IBMCAM_MODEL_4:
295 (RING_QUEUE_PEEK(&uvd->dp, 1) == 0xFF)) 298 (RING_QUEUE_PEEK(&uvd->dp, 1) == 0xFF))
296 { 299 {
297#if 0 300#if 0
298 info("Header found."); 301 dev_info(&uvd->dev->dev, "Header found.\n");
299#endif 302#endif
300 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, marker_len); 303 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, marker_len);
301 icam->has_hdr = 1; 304 icam->has_hdr = 1;
@@ -338,7 +341,7 @@ case IBMCAM_MODEL_4:
338 byte4 = RING_QUEUE_PEEK(&uvd->dp, 3); 341 byte4 = RING_QUEUE_PEEK(&uvd->dp, 3);
339 frame->header = (byte3 << 8) | byte4; 342 frame->header = (byte3 << 8) | byte4;
340#if 0 343#if 0
341 info("Header found."); 344 dev_info(&uvd->dev->dev, "Header found.\n");
342#endif 345#endif
343 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, marker_len); 346 RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, marker_len);
344 icam->has_hdr = 1; 347 icam->has_hdr = 1;
@@ -354,7 +357,8 @@ case IBMCAM_MODEL_4:
354 } 357 }
355 if (!icam->has_hdr) { 358 if (!icam->has_hdr) {
356 if (uvd->debug > 2) 359 if (uvd->debug > 2)
357 info("Skipping frame, no header"); 360 dev_info(&uvd->dev->dev,
361 "Skipping frame, no header\n");
358 return scan_EndParse; 362 return scan_EndParse;
359 } 363 }
360 364
@@ -881,7 +885,9 @@ static enum ParseState ibmcam_model3_parse_lines(
881 */ 885 */
882 if ((frame->curline + 1) >= data_h) { 886 if ((frame->curline + 1) >= data_h) {
883 if (uvd->debug >= 3) 887 if (uvd->debug >= 3)
884 info("Reached line %d. (frame is done)", frame->curline); 888 dev_info(&uvd->dev->dev,
889 "Reached line %d. (frame is done)\n",
890 frame->curline);
885 return scan_NextFrame; 891 return scan_NextFrame;
886 } 892 }
887 893
@@ -954,8 +960,9 @@ static enum ParseState ibmcam_model3_parse_lines(
954 960
955 if (frame->curline >= VIDEOSIZE_Y(frame->request)) { 961 if (frame->curline >= VIDEOSIZE_Y(frame->request)) {
956 if (uvd->debug >= 3) { 962 if (uvd->debug >= 3) {
957 info("All requested lines (%ld.) done.", 963 dev_info(&uvd->dev->dev,
958 VIDEOSIZE_Y(frame->request)); 964 "All requested lines (%ld.) done.\n",
965 VIDEOSIZE_Y(frame->request));
959 } 966 }
960 return scan_NextFrame; 967 return scan_NextFrame;
961 } else 968 } else
@@ -1000,7 +1007,9 @@ static enum ParseState ibmcam_model4_128x96_parse_lines(
1000 */ 1007 */
1001 if ((frame->curline + 1) >= data_h) { 1008 if ((frame->curline + 1) >= data_h) {
1002 if (uvd->debug >= 3) 1009 if (uvd->debug >= 3)
1003 info("Reached line %d. (frame is done)", frame->curline); 1010 dev_info(&uvd->dev->dev,
1011 "Reached line %d. (frame is done)\n",
1012 frame->curline);
1004 return scan_NextFrame; 1013 return scan_NextFrame;
1005 } 1014 }
1006 1015
@@ -1049,8 +1058,9 @@ static enum ParseState ibmcam_model4_128x96_parse_lines(
1049 1058
1050 if (frame->curline >= VIDEOSIZE_Y(frame->request)) { 1059 if (frame->curline >= VIDEOSIZE_Y(frame->request)) {
1051 if (uvd->debug >= 3) { 1060 if (uvd->debug >= 3) {
1052 info("All requested lines (%ld.) done.", 1061 dev_info(&uvd->dev->dev,
1053 VIDEOSIZE_Y(frame->request)); 1062 "All requested lines (%ld.) done.\n",
1063 VIDEOSIZE_Y(frame->request));
1054 } 1064 }
1055 return scan_NextFrame; 1065 return scan_NextFrame;
1056 } else 1066 } else
@@ -1171,10 +1181,11 @@ static int ibmcam_veio(
1171 sizeof(cp), 1181 sizeof(cp),
1172 1000); 1182 1000);
1173#if 0 1183#if 0
1174 info("USB => %02x%02x%02x%02x%02x%02x%02x%02x " 1184 dev_info(&uvd->dev->dev,
1175 "(req=$%02x val=$%04x ind=$%04x)", 1185 "USB => %02x%02x%02x%02x%02x%02x%02x%02x "
1176 cp[0],cp[1],cp[2],cp[3],cp[4],cp[5],cp[6],cp[7], 1186 "(req=$%02x val=$%04x ind=$%04x)\n",
1177 req, value, index); 1187 cp[0],cp[1],cp[2],cp[3],cp[4],cp[5],cp[6],cp[7],
1188 req, value, index);
1178#endif 1189#endif
1179 } else { 1190 } else {
1180 i = usb_control_msg( 1191 i = usb_control_msg(
@@ -1449,10 +1460,9 @@ static void ibmcam_adjust_contrast(struct uvd *uvd)
1449 */ 1460 */
1450static void ibmcam_change_lighting_conditions(struct uvd *uvd) 1461static void ibmcam_change_lighting_conditions(struct uvd *uvd)
1451{ 1462{
1452 static const char proc[] = "ibmcam_change_lighting_conditions";
1453
1454 if (debug > 0) 1463 if (debug > 0)
1455 info("%s: Set lighting to %hu.", proc, lighting); 1464 dev_info(&uvd->dev->dev,
1465 "%s: Set lighting to %hu.\n", __func__, lighting);
1456 1466
1457 switch (IBMCAM_T(uvd)->camera_model) { 1467 switch (IBMCAM_T(uvd)->camera_model) {
1458 case IBMCAM_MODEL_1: 1468 case IBMCAM_MODEL_1:
@@ -1495,8 +1505,6 @@ static void ibmcam_change_lighting_conditions(struct uvd *uvd)
1495 */ 1505 */
1496static void ibmcam_set_sharpness(struct uvd *uvd) 1506static void ibmcam_set_sharpness(struct uvd *uvd)
1497{ 1507{
1498 static const char proc[] = "ibmcam_set_sharpness";
1499
1500 switch (IBMCAM_T(uvd)->camera_model) { 1508 switch (IBMCAM_T(uvd)->camera_model) {
1501 case IBMCAM_MODEL_1: 1509 case IBMCAM_MODEL_1:
1502 { 1510 {
@@ -1505,7 +1513,8 @@ static void ibmcam_set_sharpness(struct uvd *uvd)
1505 1513
1506 RESTRICT_TO_RANGE(sharpness, SHARPNESS_MIN, SHARPNESS_MAX); 1514 RESTRICT_TO_RANGE(sharpness, SHARPNESS_MIN, SHARPNESS_MAX);
1507 if (debug > 0) 1515 if (debug > 0)
1508 info("%s: Set sharpness to %hu.", proc, sharpness); 1516 dev_info(&uvd->dev->dev, "%s: Set sharpness to %hu.\n",
1517 __func__, sharpness);
1509 1518
1510 sv = sa[sharpness - SHARPNESS_MIN]; 1519 sv = sa[sharpness - SHARPNESS_MIN];
1511 for (i=0; i < 2; i++) { 1520 for (i=0; i < 2; i++) {
@@ -1564,11 +1573,11 @@ static void ibmcam_set_sharpness(struct uvd *uvd)
1564 */ 1573 */
1565static void ibmcam_set_brightness(struct uvd *uvd) 1574static void ibmcam_set_brightness(struct uvd *uvd)
1566{ 1575{
1567 static const char proc[] = "ibmcam_set_brightness";
1568 static const unsigned short n = 1; 1576 static const unsigned short n = 1;
1569 1577
1570 if (debug > 0) 1578 if (debug > 0)
1571 info("%s: Set brightness to %hu.", proc, uvd->vpic.brightness); 1579 dev_info(&uvd->dev->dev, "%s: Set brightness to %hu.\n",
1580 __func__, uvd->vpic.brightness);
1572 1581
1573 switch (IBMCAM_T(uvd)->camera_model) { 1582 switch (IBMCAM_T(uvd)->camera_model) {
1574 case IBMCAM_MODEL_1: 1583 case IBMCAM_MODEL_1:
@@ -2115,7 +2124,8 @@ static void ibmcam_model2_setup_after_video_if(struct uvd *uvd)
2115 break; 2124 break;
2116 } 2125 }
2117 if (uvd->debug > 0) 2126 if (uvd->debug > 0)
2118 info("Framerate (hardware): %hd.", hw_fps); 2127 dev_info(&uvd->dev->dev, "Framerate (hardware): %hd.\n",
2128 hw_fps);
2119 RESTRICT_TO_RANGE(hw_fps, 0, 31); 2129 RESTRICT_TO_RANGE(hw_fps, 0, 31);
2120 ibmcam_model2_Packet1(uvd, mod2_set_framerate, hw_fps); 2130 ibmcam_model2_Packet1(uvd, mod2_set_framerate, hw_fps);
2121 } 2131 }
@@ -3487,7 +3497,7 @@ static void ibmcam_model3_setup_after_video_if(struct uvd *uvd)
3487 /* 01.01.08 - Added for RCA video in support -LO */ 3497 /* 01.01.08 - Added for RCA video in support -LO */
3488 if(init_model3_input) { 3498 if(init_model3_input) {
3489 if (debug > 0) 3499 if (debug > 0)
3490 info("Setting input to RCA."); 3500 dev_info(&uvd->dev->dev, "Setting input to RCA.\n");
3491 for (i=0; i < ARRAY_SIZE(initData); i++) { 3501 for (i=0; i < ARRAY_SIZE(initData); i++) {
3492 ibmcam_veio(uvd, initData[i].req, initData[i].value, initData[i].index); 3502 ibmcam_veio(uvd, initData[i].req, initData[i].value, initData[i].index);
3493 } 3503 }
@@ -3685,7 +3695,7 @@ static int ibmcam_probe(struct usb_interface *intf, const struct usb_device_id *
3685 unsigned char video_ep = 0; 3695 unsigned char video_ep = 0;
3686 3696
3687 if (debug >= 1) 3697 if (debug >= 1)
3688 info("ibmcam_probe(%p,%u.)", intf, ifnum); 3698 dev_info(&uvd->dev->dev, "ibmcam_probe(%p,%u.)\n", intf, ifnum);
3689 3699
3690 /* We don't handle multi-config cameras */ 3700 /* We don't handle multi-config cameras */
3691 if (dev->descriptor.bNumConfigurations != 1) 3701 if (dev->descriptor.bNumConfigurations != 1)
@@ -3736,14 +3746,16 @@ static int ibmcam_probe(struct usb_interface *intf, const struct usb_device_id *
3736 brand = "IBM PC Camera"; /* a.k.a. Xirlink C-It */ 3746 brand = "IBM PC Camera"; /* a.k.a. Xirlink C-It */
3737 break; 3747 break;
3738 } 3748 }
3739 info("%s USB camera found (model %d, rev. 0x%04x)", 3749 dev_info(&uvd->dev->dev,
3740 brand, model, le16_to_cpu(dev->descriptor.bcdDevice)); 3750 "%s USB camera found (model %d, rev. 0x%04x)\n",
3751 brand, model, le16_to_cpu(dev->descriptor.bcdDevice));
3741 } while (0); 3752 } while (0);
3742 3753
3743 /* Validate found interface: must have one ISO endpoint */ 3754 /* Validate found interface: must have one ISO endpoint */
3744 nas = intf->num_altsetting; 3755 nas = intf->num_altsetting;
3745 if (debug > 0) 3756 if (debug > 0)
3746 info("Number of alternate settings=%d.", nas); 3757 dev_info(&uvd->dev->dev, "Number of alternate settings=%d.\n",
3758 nas);
3747 if (nas < 2) { 3759 if (nas < 2) {
3748 err("Too few alternate settings for this camera!"); 3760 err("Too few alternate settings for this camera!");
3749 return -ENODEV; 3761 return -ENODEV;
@@ -3787,7 +3799,9 @@ static int ibmcam_probe(struct usb_interface *intf, const struct usb_device_id *
3787 actInterface = i; 3799 actInterface = i;
3788 maxPS = le16_to_cpu(endpoint->wMaxPacketSize); 3800 maxPS = le16_to_cpu(endpoint->wMaxPacketSize);
3789 if (debug > 0) 3801 if (debug > 0)
3790 info("Active setting=%d. maxPS=%d.", i, maxPS); 3802 dev_info(&uvd->dev->dev,
3803 "Active setting=%d. "
3804 "maxPS=%d.\n", i, maxPS);
3791 } else 3805 } else
3792 err("More than one active alt. setting! Ignoring #%d.", i); 3806 err("More than one active alt. setting! Ignoring #%d.", i);
3793 } 3807 }
@@ -3826,7 +3840,7 @@ static int ibmcam_probe(struct usb_interface *intf, const struct usb_device_id *
3826 RESTRICT_TO_RANGE(framerate, 0, 5); 3840 RESTRICT_TO_RANGE(framerate, 0, 5);
3827 break; 3841 break;
3828 default: 3842 default:
3829 info("IBM camera: using 320x240"); 3843 dev_info(&uvd->dev->dev, "IBM camera: using 320x240\n");
3830 size = SIZE_320x240; 3844 size = SIZE_320x240;
3831 /* No break here */ 3845 /* No break here */
3832 case SIZE_320x240: 3846 case SIZE_320x240:
@@ -3855,7 +3869,7 @@ static int ibmcam_probe(struct usb_interface *intf, const struct usb_device_id *
3855 canvasY = 120; 3869 canvasY = 120;
3856 break; 3870 break;
3857 default: 3871 default:
3858 info("IBM NetCamera: using 176x144"); 3872 dev_info(&uvd->dev->dev, "IBM NetCamera: using 176x144\n");
3859 size = SIZE_176x144; 3873 size = SIZE_176x144;
3860 /* No break here */ 3874 /* No break here */
3861 case SIZE_176x144: 3875 case SIZE_176x144:
diff --git a/drivers/media/video/usbvideo/konicawc.c b/drivers/media/video/usbvideo/konicawc.c
index 1c180284ec6c..e986c28b7bb0 100644
--- a/drivers/media/video/usbvideo/konicawc.c
+++ b/drivers/media/video/usbvideo/konicawc.c
@@ -337,7 +337,8 @@ static int konicawc_compress_iso(struct uvd *uvd, struct urb *dataurb, struct ur
337 } 337 }
338 338
339 if((sts > 0x01) && (sts < 0x80)) { 339 if((sts > 0x01) && (sts < 0x80)) {
340 info("unknown status %2.2x", sts); 340 dev_info(&uvd->dev->dev, "unknown status %2.2x\n",
341 sts);
341 bad++; 342 bad++;
342 continue; 343 continue;
343 } 344 }
@@ -568,8 +569,12 @@ static void konicawc_process_isoc(struct uvd *uvd, struct usbvideo_frame *frame)
568 fdrops = (0x80 + curframe - cam->lastframe) & 0x7F; 569 fdrops = (0x80 + curframe - cam->lastframe) & 0x7F;
569 fdrops--; 570 fdrops--;
570 if(fdrops) { 571 if(fdrops) {
571 info("Dropped %d frames (%d -> %d)", fdrops, 572 dev_info(&uvd->dev->dev,
572 cam->lastframe, curframe); 573 "Dropped %d frames "
574 "(%d -> %d)\n",
575 fdrops,
576 cam->lastframe,
577 curframe);
573 } 578 }
574 } 579 }
575 cam->lastframe = curframe; 580 cam->lastframe = curframe;
@@ -784,7 +789,8 @@ static int konicawc_probe(struct usb_interface *intf, const struct usb_device_id
784 if (dev->descriptor.bNumConfigurations != 1) 789 if (dev->descriptor.bNumConfigurations != 1)
785 return -ENODEV; 790 return -ENODEV;
786 791
787 info("Konica Webcam (rev. 0x%04x)", le16_to_cpu(dev->descriptor.bcdDevice)); 792 dev_info(&intf->dev, "Konica Webcam (rev. 0x%04x)\n",
793 le16_to_cpu(dev->descriptor.bcdDevice));
788 RESTRICT_TO_RANGE(speed, 0, MAX_SPEED); 794 RESTRICT_TO_RANGE(speed, 0, MAX_SPEED);
789 795
790 /* Validate found interface: must have one ISO endpoint */ 796 /* Validate found interface: must have one ISO endpoint */
@@ -925,7 +931,8 @@ static struct usb_device_id id_table[] = {
925static int __init konicawc_init(void) 931static int __init konicawc_init(void)
926{ 932{
927 struct usbvideo_cb cbTbl; 933 struct usbvideo_cb cbTbl;
928 info(DRIVER_DESC " " DRIVER_VERSION); 934 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
935 DRIVER_DESC "\n");
929 memset(&cbTbl, 0, sizeof(cbTbl)); 936 memset(&cbTbl, 0, sizeof(cbTbl));
930 cbTbl.probe = konicawc_probe; 937 cbTbl.probe = konicawc_probe;
931 cbTbl.setupOnOpen = konicawc_setup_on_open; 938 cbTbl.setupOnOpen = konicawc_setup_on_open;
diff --git a/drivers/media/video/usbvideo/quickcam_messenger.c b/drivers/media/video/usbvideo/quickcam_messenger.c
index 3d26a30abe1e..05c61b523115 100644
--- a/drivers/media/video/usbvideo/quickcam_messenger.c
+++ b/drivers/media/video/usbvideo/quickcam_messenger.c
@@ -1080,7 +1080,8 @@ static struct usbvideo_cb qcm_driver = {
1080 1080
1081static int __init qcm_init(void) 1081static int __init qcm_init(void)
1082{ 1082{
1083 info(DRIVER_DESC " " DRIVER_VERSION); 1083 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
1084 DRIVER_DESC "\n");
1084 1085
1085 return usbvideo_register( 1086 return usbvideo_register(
1086 &cams, 1087 &cams,
diff --git a/drivers/media/video/usbvideo/ultracam.c b/drivers/media/video/usbvideo/ultracam.c
index 9544e644bf0d..9714baab7833 100644
--- a/drivers/media/video/usbvideo/ultracam.c
+++ b/drivers/media/video/usbvideo/ultracam.c
@@ -156,10 +156,11 @@ static int ultracam_veio(
156 sizeof(cp), 156 sizeof(cp),
157 1000); 157 1000);
158#if 1 158#if 1
159 info("USB => %02x%02x%02x%02x%02x%02x%02x%02x " 159 dev_info(&uvd->dev->dev,
160 "(req=$%02x val=$%04x ind=$%04x)", 160 "USB => %02x%02x%02x%02x%02x%02x%02x%02x "
161 cp[0],cp[1],cp[2],cp[3],cp[4],cp[5],cp[6],cp[7], 161 "(req=$%02x val=$%04x ind=$%04x)\n",
162 req, value, index); 162 cp[0],cp[1],cp[2],cp[3],cp[4],cp[5],cp[6],cp[7],
163 req, value, index);
163#endif 164#endif
164 } else { 165 } else {
165 i = usb_control_msg( 166 i = usb_control_msg(
@@ -517,19 +518,20 @@ static int ultracam_probe(struct usb_interface *intf, const struct usb_device_id
517 unsigned char video_ep = 0; 518 unsigned char video_ep = 0;
518 519
519 if (debug >= 1) 520 if (debug >= 1)
520 info("ultracam_probe(%p)", intf); 521 dev_info(&intf->dev, "ultracam_probe\n");
521 522
522 /* We don't handle multi-config cameras */ 523 /* We don't handle multi-config cameras */
523 if (dev->descriptor.bNumConfigurations != 1) 524 if (dev->descriptor.bNumConfigurations != 1)
524 return -ENODEV; 525 return -ENODEV;
525 526
526 info("IBM Ultra camera found (rev. 0x%04x)", 527 dev_info(&intf->dev, "IBM Ultra camera found (rev. 0x%04x)\n",
527 le16_to_cpu(dev->descriptor.bcdDevice)); 528 le16_to_cpu(dev->descriptor.bcdDevice));
528 529
529 /* Validate found interface: must have one ISO endpoint */ 530 /* Validate found interface: must have one ISO endpoint */
530 nas = intf->num_altsetting; 531 nas = intf->num_altsetting;
531 if (debug > 0) 532 if (debug > 0)
532 info("Number of alternate settings=%d.", nas); 533 dev_info(&intf->dev, "Number of alternate settings=%d.\n",
534 nas);
533 if (nas < 8) { 535 if (nas < 8) {
534 err("Too few alternate settings for this camera!"); 536 err("Too few alternate settings for this camera!");
535 return -ENODEV; 537 return -ENODEV;
@@ -576,7 +578,9 @@ static int ultracam_probe(struct usb_interface *intf, const struct usb_device_id
576 actInterface = i; 578 actInterface = i;
577 maxPS = le16_to_cpu(endpoint->wMaxPacketSize); 579 maxPS = le16_to_cpu(endpoint->wMaxPacketSize);
578 if (debug > 0) 580 if (debug > 0)
579 info("Active setting=%d. maxPS=%d.", i, maxPS); 581 dev_info(&intf->dev,
582 "Active setting=%d. "
583 "maxPS=%d.\n", i, maxPS);
580 } else { 584 } else {
581 /* Got another active alt. setting */ 585 /* Got another active alt. setting */
582 if (maxPS < le16_to_cpu(endpoint->wMaxPacketSize)) { 586 if (maxPS < le16_to_cpu(endpoint->wMaxPacketSize)) {
@@ -584,8 +588,11 @@ static int ultracam_probe(struct usb_interface *intf, const struct usb_device_id
584 actInterface = i; 588 actInterface = i;
585 maxPS = le16_to_cpu(endpoint->wMaxPacketSize); 589 maxPS = le16_to_cpu(endpoint->wMaxPacketSize);
586 if (debug > 0) { 590 if (debug > 0) {
587 info("Even better ctive setting=%d. maxPS=%d.", 591 dev_info(&intf->dev,
588 i, maxPS); 592 "Even better ctive "
593 "setting=%d. "
594 "maxPS=%d.\n",
595 i, maxPS);
589 } 596 }
590 } 597 }
591 } 598 }
diff --git a/drivers/media/video/usbvideo/usbvideo.c b/drivers/media/video/usbvideo/usbvideo.c
index bf1bc2f69b02..07cd87d16f69 100644
--- a/drivers/media/video/usbvideo/usbvideo.c
+++ b/drivers/media/video/usbvideo/usbvideo.c
@@ -468,8 +468,9 @@ static void usbvideo_ReportStatistics(const struct uvd *uvd)
468 percent = (100 * goodPackets) / allPackets; 468 percent = (100 * goodPackets) / allPackets;
469 else 469 else
470 percent = goodPackets / (allPackets / 100); 470 percent = goodPackets / (allPackets / 100);
471 info("Packet Statistics: Total=%lu. Empty=%lu. Usage=%lu%%", 471 dev_info(&uvd->dev->dev,
472 allPackets, badPackets, percent); 472 "Packet Statistics: Total=%lu. Empty=%lu. Usage=%lu%%\n",
473 allPackets, badPackets, percent);
473 if (uvd->iso_packet_len > 0) { 474 if (uvd->iso_packet_len > 0) {
474 unsigned long allBytes, xferBytes; 475 unsigned long allBytes, xferBytes;
475 char multiplier = ' '; 476 char multiplier = ' ';
@@ -497,8 +498,9 @@ static void usbvideo_ReportStatistics(const struct uvd *uvd)
497 } 498 }
498 } 499 }
499 } 500 }
500 info("Transfer Statistics: Transferred=%lu%cB Usage=%lu%%", 501 dev_info(&uvd->dev->dev,
501 xferBytes, multiplier, percent); 502 "Transfer Statistics: Transferred=%lu%cB Usage=%lu%%\n",
503 xferBytes, multiplier, percent);
502 } 504 }
503 } 505 }
504} 506}
@@ -545,7 +547,7 @@ void usbvideo_TestPattern(struct uvd *uvd, int fullframe, int pmode)
545 { /* For debugging purposes only */ 547 { /* For debugging purposes only */
546 char tmp[20]; 548 char tmp[20];
547 usbvideo_VideosizeToString(tmp, sizeof(tmp), frame->request); 549 usbvideo_VideosizeToString(tmp, sizeof(tmp), frame->request);
548 info("testpattern: frame=%s", tmp); 550 dev_info(&uvd->dev->dev, "testpattern: frame=%s\n", tmp);
549 } 551 }
550#endif 552#endif
551 /* Form every scan line */ 553 /* Form every scan line */
@@ -854,7 +856,7 @@ static void usbvideo_Disconnect(struct usb_interface *intf)
854 856
855 usbvideo_ClientIncModCount(uvd); 857 usbvideo_ClientIncModCount(uvd);
856 if (uvd->debug > 0) 858 if (uvd->debug > 0)
857 info("%s(%p.)", __func__, intf); 859 dev_info(&intf->dev, "%s(%p.)\n", __func__, intf);
858 860
859 mutex_lock(&uvd->lock); 861 mutex_lock(&uvd->lock);
860 uvd->remove_pending = 1; /* Now all ISO data will be ignored */ 862 uvd->remove_pending = 1; /* Now all ISO data will be ignored */
@@ -870,14 +872,15 @@ static void usbvideo_Disconnect(struct usb_interface *intf)
870 872
871 video_unregister_device(&uvd->vdev); 873 video_unregister_device(&uvd->vdev);
872 if (uvd->debug > 0) 874 if (uvd->debug > 0)
873 info("%s: Video unregistered.", __func__); 875 dev_info(&intf->dev, "%s: Video unregistered.\n", __func__);
874 876
875 if (uvd->user) 877 if (uvd->user)
876 info("%s: In use, disconnect pending.", __func__); 878 dev_info(&intf->dev, "%s: In use, disconnect pending.\n",
879 __func__);
877 else 880 else
878 usbvideo_CameraRelease(uvd); 881 usbvideo_CameraRelease(uvd);
879 mutex_unlock(&uvd->lock); 882 mutex_unlock(&uvd->lock);
880 info("USB camera disconnected."); 883 dev_info(&intf->dev, "USB camera disconnected.\n");
881 884
882 usbvideo_ClientDecModCount(uvd); 885 usbvideo_ClientDecModCount(uvd);
883} 886}
@@ -1015,14 +1018,17 @@ int usbvideo_RegisterVideoDevice(struct uvd *uvd)
1015 return -EINVAL; 1018 return -EINVAL;
1016 } 1019 }
1017 if (uvd->video_endp == 0) { 1020 if (uvd->video_endp == 0) {
1018 info("%s: No video endpoint specified; data pump disabled.", __func__); 1021 dev_info(&uvd->dev->dev,
1022 "%s: No video endpoint specified; data pump disabled.\n",
1023 __func__);
1019 } 1024 }
1020 if (uvd->paletteBits == 0) { 1025 if (uvd->paletteBits == 0) {
1021 err("%s: No palettes specified!", __func__); 1026 err("%s: No palettes specified!", __func__);
1022 return -EINVAL; 1027 return -EINVAL;
1023 } 1028 }
1024 if (uvd->defaultPalette == 0) { 1029 if (uvd->defaultPalette == 0) {
1025 info("%s: No default palette!", __func__); 1030 dev_info(&uvd->dev->dev, "%s: No default palette!\n",
1031 __func__);
1026 } 1032 }
1027 1033
1028 uvd->max_frame_size = VIDEOSIZE_X(uvd->canvas) * 1034 uvd->max_frame_size = VIDEOSIZE_X(uvd->canvas) *
@@ -1031,25 +1037,29 @@ int usbvideo_RegisterVideoDevice(struct uvd *uvd)
1031 usbvideo_VideosizeToString(tmp2, sizeof(tmp2), uvd->canvas); 1037 usbvideo_VideosizeToString(tmp2, sizeof(tmp2), uvd->canvas);
1032 1038
1033 if (uvd->debug > 0) { 1039 if (uvd->debug > 0) {
1034 info("%s: iface=%d. endpoint=$%02x paletteBits=$%08lx", 1040 dev_info(&uvd->dev->dev,
1035 __func__, uvd->iface, uvd->video_endp, uvd->paletteBits); 1041 "%s: iface=%d. endpoint=$%02x paletteBits=$%08lx\n",
1042 __func__, uvd->iface, uvd->video_endp,
1043 uvd->paletteBits);
1036 } 1044 }
1037 if (uvd->dev == NULL) { 1045 if (uvd->dev == NULL) {
1038 err("%s: uvd->dev == NULL", __func__); 1046 err("%s: uvd->dev == NULL", __func__);
1039 return -EINVAL; 1047 return -EINVAL;
1040 } 1048 }
1041 uvd->vdev.parent = &uvd->dev->dev; 1049 uvd->vdev.parent = &uvd->dev->dev;
1042 if (video_register_device(&uvd->vdev, VFL_TYPE_GRABBER, video_nr) == -1) { 1050 uvd->vdev.release = video_device_release_empty;
1051 if (video_register_device(&uvd->vdev, VFL_TYPE_GRABBER, video_nr) < 0) {
1043 err("%s: video_register_device failed", __func__); 1052 err("%s: video_register_device failed", __func__);
1044 return -EPIPE; 1053 return -EPIPE;
1045 } 1054 }
1046 if (uvd->debug > 1) { 1055 if (uvd->debug > 1) {
1047 info("%s: video_register_device() successful", __func__); 1056 dev_info(&uvd->dev->dev,
1057 "%s: video_register_device() successful\n", __func__);
1048 } 1058 }
1049 1059
1050 info("%s on /dev/video%d: canvas=%s videosize=%s", 1060 dev_info(&uvd->dev->dev, "%s on /dev/video%d: canvas=%s videosize=%s\n",
1051 (uvd->handle != NULL) ? uvd->handle->drvName : "???", 1061 (uvd->handle != NULL) ? uvd->handle->drvName : "???",
1052 uvd->vdev.minor, tmp2, tmp1); 1062 uvd->vdev.minor, tmp2, tmp1);
1053 1063
1054 usb_get_dev(uvd->dev); 1064 usb_get_dev(uvd->dev);
1055 return 0; 1065 return 0;
@@ -1111,7 +1121,7 @@ static int usbvideo_v4l_open(struct inode *inode, struct file *file)
1111 int i, errCode = 0; 1121 int i, errCode = 0;
1112 1122
1113 if (uvd->debug > 1) 1123 if (uvd->debug > 1)
1114 info("%s($%p)", __func__, dev); 1124 dev_info(&uvd->dev->dev, "%s($%p)\n", __func__, dev);
1115 1125
1116 if (0 < usbvideo_ClientIncModCount(uvd)) 1126 if (0 < usbvideo_ClientIncModCount(uvd))
1117 return -ENODEV; 1127 return -ENODEV;
@@ -1178,19 +1188,25 @@ static int usbvideo_v4l_open(struct inode *inode, struct file *file)
1178 if (errCode == 0) { 1188 if (errCode == 0) {
1179 if (VALID_CALLBACK(uvd, setupOnOpen)) { 1189 if (VALID_CALLBACK(uvd, setupOnOpen)) {
1180 if (uvd->debug > 1) 1190 if (uvd->debug > 1)
1181 info("%s: setupOnOpen callback", __func__); 1191 dev_info(&uvd->dev->dev,
1192 "%s: setupOnOpen callback\n",
1193 __func__);
1182 errCode = GET_CALLBACK(uvd, setupOnOpen)(uvd); 1194 errCode = GET_CALLBACK(uvd, setupOnOpen)(uvd);
1183 if (errCode < 0) { 1195 if (errCode < 0) {
1184 err("%s: setupOnOpen callback failed (%d.).", 1196 err("%s: setupOnOpen callback failed (%d.).",
1185 __func__, errCode); 1197 __func__, errCode);
1186 } else if (uvd->debug > 1) { 1198 } else if (uvd->debug > 1) {
1187 info("%s: setupOnOpen callback successful", __func__); 1199 dev_info(&uvd->dev->dev,
1200 "%s: setupOnOpen callback successful\n",
1201 __func__);
1188 } 1202 }
1189 } 1203 }
1190 if (errCode == 0) { 1204 if (errCode == 0) {
1191 uvd->settingsAdjusted = 0; 1205 uvd->settingsAdjusted = 0;
1192 if (uvd->debug > 1) 1206 if (uvd->debug > 1)
1193 info("%s: Open succeeded.", __func__); 1207 dev_info(&uvd->dev->dev,
1208 "%s: Open succeeded.\n",
1209 __func__);
1194 uvd->user++; 1210 uvd->user++;
1195 file->private_data = uvd; 1211 file->private_data = uvd;
1196 } 1212 }
@@ -1200,7 +1216,8 @@ static int usbvideo_v4l_open(struct inode *inode, struct file *file)
1200 if (errCode != 0) 1216 if (errCode != 0)
1201 usbvideo_ClientDecModCount(uvd); 1217 usbvideo_ClientDecModCount(uvd);
1202 if (uvd->debug > 0) 1218 if (uvd->debug > 0)
1203 info("%s: Returning %d.", __func__, errCode); 1219 dev_info(&uvd->dev->dev, "%s: Returning %d.\n", __func__,
1220 errCode);
1204 return errCode; 1221 return errCode;
1205} 1222}
1206 1223
@@ -1223,7 +1240,7 @@ static int usbvideo_v4l_close(struct inode *inode, struct file *file)
1223 int i; 1240 int i;
1224 1241
1225 if (uvd->debug > 1) 1242 if (uvd->debug > 1)
1226 info("%s($%p)", __func__, dev); 1243 dev_info(&uvd->dev->dev, "%s($%p)\n", __func__, dev);
1227 1244
1228 mutex_lock(&uvd->lock); 1245 mutex_lock(&uvd->lock);
1229 GET_CALLBACK(uvd, stopDataPump)(uvd); 1246 GET_CALLBACK(uvd, stopDataPump)(uvd);
@@ -1243,14 +1260,15 @@ static int usbvideo_v4l_close(struct inode *inode, struct file *file)
1243 uvd->user--; 1260 uvd->user--;
1244 if (uvd->remove_pending) { 1261 if (uvd->remove_pending) {
1245 if (uvd->debug > 0) 1262 if (uvd->debug > 0)
1246 info("usbvideo_v4l_close: Final disconnect."); 1263 dev_info(&uvd->dev->dev, "%s: Final disconnect.\n",
1264 __func__);
1247 usbvideo_CameraRelease(uvd); 1265 usbvideo_CameraRelease(uvd);
1248 } 1266 }
1249 mutex_unlock(&uvd->lock); 1267 mutex_unlock(&uvd->lock);
1250 usbvideo_ClientDecModCount(uvd); 1268 usbvideo_ClientDecModCount(uvd);
1251 1269
1252 if (uvd->debug > 1) 1270 if (uvd->debug > 1)
1253 info("%s: Completed.", __func__); 1271 dev_info(&uvd->dev->dev, "%s: Completed.\n", __func__);
1254 file->private_data = NULL; 1272 file->private_data = NULL;
1255 return 0; 1273 return 0;
1256} 1274}
@@ -1364,8 +1382,9 @@ static int usbvideo_v4l_do_ioctl(struct inode *inode, struct file *file,
1364 struct video_mmap *vm = arg; 1382 struct video_mmap *vm = arg;
1365 1383
1366 if (uvd->debug >= 1) { 1384 if (uvd->debug >= 1) {
1367 info("VIDIOCMCAPTURE: frame=%d. size=%dx%d, format=%d.", 1385 dev_info(&uvd->dev->dev,
1368 vm->frame, vm->width, vm->height, vm->format); 1386 "VIDIOCMCAPTURE: frame=%d. size=%dx%d, format=%d.\n",
1387 vm->frame, vm->width, vm->height, vm->format);
1369 } 1388 }
1370 /* 1389 /*
1371 * Check if the requested size is supported. If the requestor 1390 * Check if the requested size is supported. If the requestor
@@ -1383,18 +1402,24 @@ static int usbvideo_v4l_do_ioctl(struct inode *inode, struct file *file,
1383 if ((vm->width > VIDEOSIZE_X(uvd->canvas)) || 1402 if ((vm->width > VIDEOSIZE_X(uvd->canvas)) ||
1384 (vm->height > VIDEOSIZE_Y(uvd->canvas))) { 1403 (vm->height > VIDEOSIZE_Y(uvd->canvas))) {
1385 if (uvd->debug > 0) { 1404 if (uvd->debug > 0) {
1386 info("VIDIOCMCAPTURE: Size=%dx%d too large; " 1405 dev_info(&uvd->dev->dev,
1387 "allowed only up to %ldx%ld", vm->width, vm->height, 1406 "VIDIOCMCAPTURE: Size=%dx%d "
1388 VIDEOSIZE_X(uvd->canvas), VIDEOSIZE_Y(uvd->canvas)); 1407 "too large; allowed only up "
1408 "to %ldx%ld\n", vm->width,
1409 vm->height,
1410 VIDEOSIZE_X(uvd->canvas),
1411 VIDEOSIZE_Y(uvd->canvas));
1389 } 1412 }
1390 return -EINVAL; 1413 return -EINVAL;
1391 } 1414 }
1392 /* Check if the palette is supported */ 1415 /* Check if the palette is supported */
1393 if (((1L << vm->format) & uvd->paletteBits) == 0) { 1416 if (((1L << vm->format) & uvd->paletteBits) == 0) {
1394 if (uvd->debug > 0) { 1417 if (uvd->debug > 0) {
1395 info("VIDIOCMCAPTURE: format=%d. not supported" 1418 dev_info(&uvd->dev->dev,
1396 " (paletteBits=$%08lx)", 1419 "VIDIOCMCAPTURE: format=%d. "
1397 vm->format, uvd->paletteBits); 1420 "not supported "
1421 "(paletteBits=$%08lx)\n",
1422 vm->format, uvd->paletteBits);
1398 } 1423 }
1399 return -EINVAL; 1424 return -EINVAL;
1400 } 1425 }
@@ -1422,7 +1447,9 @@ static int usbvideo_v4l_do_ioctl(struct inode *inode, struct file *file,
1422 return -EINVAL; 1447 return -EINVAL;
1423 1448
1424 if (uvd->debug >= 1) 1449 if (uvd->debug >= 1)
1425 info("VIDIOCSYNC: syncing to frame %d.", *frameNum); 1450 dev_info(&uvd->dev->dev,
1451 "VIDIOCSYNC: syncing to frame %d.\n",
1452 *frameNum);
1426 if (uvd->flags & FLAGS_NO_DECODING) 1453 if (uvd->flags & FLAGS_NO_DECODING)
1427 ret = usbvideo_GetFrame(uvd, *frameNum); 1454 ret = usbvideo_GetFrame(uvd, *frameNum);
1428 else if (VALID_CALLBACK(uvd, getFrame)) { 1455 else if (VALID_CALLBACK(uvd, getFrame)) {
@@ -1504,7 +1531,9 @@ static ssize_t usbvideo_v4l_read(struct file *file, char __user *buf,
1504 return -EFAULT; 1531 return -EFAULT;
1505 1532
1506 if (uvd->debug >= 1) 1533 if (uvd->debug >= 1)
1507 info("%s: %Zd. bytes, noblock=%d.", __func__, count, noblock); 1534 dev_info(&uvd->dev->dev,
1535 "%s: %Zd. bytes, noblock=%d.\n",
1536 __func__, count, noblock);
1508 1537
1509 mutex_lock(&uvd->lock); 1538 mutex_lock(&uvd->lock);
1510 1539
@@ -1685,18 +1714,21 @@ static void usbvideo_IsocIrq(struct urb *urb)
1685 return; 1714 return;
1686#if 0 1715#if 0
1687 if (urb->actual_length > 0) { 1716 if (urb->actual_length > 0) {
1688 info("urb=$%p status=%d. errcount=%d. length=%d.", 1717 dev_info(&uvd->dev->dev,
1689 urb, urb->status, urb->error_count, urb->actual_length); 1718 "urb=$%p status=%d. errcount=%d. length=%d.\n",
1719 urb, urb->status, urb->error_count,
1720 urb->actual_length);
1690 } else { 1721 } else {
1691 static int c = 0; 1722 static int c = 0;
1692 if (c++ % 100 == 0) 1723 if (c++ % 100 == 0)
1693 info("No Isoc data"); 1724 dev_info(&uvd->dev->dev, "No Isoc data\n");
1694 } 1725 }
1695#endif 1726#endif
1696 1727
1697 if (!uvd->streaming) { 1728 if (!uvd->streaming) {
1698 if (uvd->debug >= 1) 1729 if (uvd->debug >= 1)
1699 info("Not streaming, but interrupt!"); 1730 dev_info(&uvd->dev->dev,
1731 "Not streaming, but interrupt!\n");
1700 return; 1732 return;
1701 } 1733 }
1702 1734
@@ -1741,7 +1773,7 @@ static int usbvideo_StartDataPump(struct uvd *uvd)
1741 int i, errFlag; 1773 int i, errFlag;
1742 1774
1743 if (uvd->debug > 1) 1775 if (uvd->debug > 1)
1744 info("%s($%p)", __func__, uvd); 1776 dev_info(&uvd->dev->dev, "%s($%p)\n", __func__, uvd);
1745 1777
1746 if (!CAMERA_IS_OPERATIONAL(uvd)) { 1778 if (!CAMERA_IS_OPERATIONAL(uvd)) {
1747 err("%s: Camera is not operational", __func__); 1779 err("%s: Camera is not operational", __func__);
@@ -1789,7 +1821,9 @@ static int usbvideo_StartDataPump(struct uvd *uvd)
1789 1821
1790 uvd->streaming = 1; 1822 uvd->streaming = 1;
1791 if (uvd->debug > 1) 1823 if (uvd->debug > 1)
1792 info("%s: streaming=1 video_endp=$%02x", __func__, uvd->video_endp); 1824 dev_info(&uvd->dev->dev,
1825 "%s: streaming=1 video_endp=$%02x\n", __func__,
1826 uvd->video_endp);
1793 return 0; 1827 return 0;
1794} 1828}
1795 1829
@@ -1811,14 +1845,14 @@ static void usbvideo_StopDataPump(struct uvd *uvd)
1811 return; 1845 return;
1812 1846
1813 if (uvd->debug > 1) 1847 if (uvd->debug > 1)
1814 info("%s($%p)", __func__, uvd); 1848 dev_info(&uvd->dev->dev, "%s($%p)\n", __func__, uvd);
1815 1849
1816 /* Unschedule all of the iso td's */ 1850 /* Unschedule all of the iso td's */
1817 for (i=0; i < USBVIDEO_NUMSBUF; i++) { 1851 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
1818 usb_kill_urb(uvd->sbuf[i].urb); 1852 usb_kill_urb(uvd->sbuf[i].urb);
1819 } 1853 }
1820 if (uvd->debug > 1) 1854 if (uvd->debug > 1)
1821 info("%s: streaming=0", __func__); 1855 dev_info(&uvd->dev->dev, "%s: streaming=0\n", __func__);
1822 uvd->streaming = 0; 1856 uvd->streaming = 0;
1823 1857
1824 if (!uvd->remove_pending) { 1858 if (!uvd->remove_pending) {
@@ -1850,7 +1884,8 @@ static int usbvideo_NewFrame(struct uvd *uvd, int framenum)
1850 int n; 1884 int n;
1851 1885
1852 if (uvd->debug > 1) 1886 if (uvd->debug > 1)
1853 info("usbvideo_NewFrame($%p,%d.)", uvd, framenum); 1887 dev_info(&uvd->dev->dev, "usbvideo_NewFrame($%p,%d.)\n", uvd,
1888 framenum);
1854 1889
1855 /* If we're not grabbing a frame right now and the other frame is */ 1890 /* If we're not grabbing a frame right now and the other frame is */
1856 /* ready to be grabbed into, then use it instead */ 1891 /* ready to be grabbed into, then use it instead */
@@ -1955,12 +1990,14 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
1955 struct usbvideo_frame *frame = &uvd->frame[frameNum]; 1990 struct usbvideo_frame *frame = &uvd->frame[frameNum];
1956 1991
1957 if (uvd->debug >= 2) 1992 if (uvd->debug >= 2)
1958 info("%s($%p,%d.)", __func__, uvd, frameNum); 1993 dev_info(&uvd->dev->dev, "%s($%p,%d.)\n", __func__, uvd,
1994 frameNum);
1959 1995
1960 switch (frame->frameState) { 1996 switch (frame->frameState) {
1961 case FrameState_Unused: 1997 case FrameState_Unused:
1962 if (uvd->debug >= 2) 1998 if (uvd->debug >= 2)
1963 info("%s: FrameState_Unused", __func__); 1999 dev_info(&uvd->dev->dev, "%s: FrameState_Unused\n",
2000 __func__);
1964 return -EINVAL; 2001 return -EINVAL;
1965 case FrameState_Ready: 2002 case FrameState_Ready:
1966 case FrameState_Grabbing: 2003 case FrameState_Grabbing:
@@ -1970,7 +2007,9 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
1970 redo: 2007 redo:
1971 if (!CAMERA_IS_OPERATIONAL(uvd)) { 2008 if (!CAMERA_IS_OPERATIONAL(uvd)) {
1972 if (uvd->debug >= 2) 2009 if (uvd->debug >= 2)
1973 info("%s: Camera is not operational (1)", __func__); 2010 dev_info(&uvd->dev->dev,
2011 "%s: Camera is not operational (1)\n",
2012 __func__);
1974 return -EIO; 2013 return -EIO;
1975 } 2014 }
1976 ntries = 0; 2015 ntries = 0;
@@ -1979,24 +2018,33 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
1979 signalPending = signal_pending(current); 2018 signalPending = signal_pending(current);
1980 if (!CAMERA_IS_OPERATIONAL(uvd)) { 2019 if (!CAMERA_IS_OPERATIONAL(uvd)) {
1981 if (uvd->debug >= 2) 2020 if (uvd->debug >= 2)
1982 info("%s: Camera is not operational (2)", __func__); 2021 dev_info(&uvd->dev->dev,
2022 "%s: Camera is not "
2023 "operational (2)\n", __func__);
1983 return -EIO; 2024 return -EIO;
1984 } 2025 }
1985 assert(uvd->fbuf != NULL); 2026 assert(uvd->fbuf != NULL);
1986 if (signalPending) { 2027 if (signalPending) {
1987 if (uvd->debug >= 2) 2028 if (uvd->debug >= 2)
1988 info("%s: Signal=$%08x", __func__, signalPending); 2029 dev_info(&uvd->dev->dev,
2030 "%s: Signal=$%08x\n", __func__,
2031 signalPending);
1989 if (uvd->flags & FLAGS_RETRY_VIDIOCSYNC) { 2032 if (uvd->flags & FLAGS_RETRY_VIDIOCSYNC) {
1990 usbvideo_TestPattern(uvd, 1, 0); 2033 usbvideo_TestPattern(uvd, 1, 0);
1991 uvd->curframe = -1; 2034 uvd->curframe = -1;
1992 uvd->stats.frame_num++; 2035 uvd->stats.frame_num++;
1993 if (uvd->debug >= 2) 2036 if (uvd->debug >= 2)
1994 info("%s: Forced test pattern screen", __func__); 2037 dev_info(&uvd->dev->dev,
2038 "%s: Forced test "
2039 "pattern screen\n",
2040 __func__);
1995 return 0; 2041 return 0;
1996 } else { 2042 } else {
1997 /* Standard answer: Interrupted! */ 2043 /* Standard answer: Interrupted! */
1998 if (uvd->debug >= 2) 2044 if (uvd->debug >= 2)
1999 info("%s: Interrupted!", __func__); 2045 dev_info(&uvd->dev->dev,
2046 "%s: Interrupted!\n",
2047 __func__);
2000 return -EINTR; 2048 return -EINTR;
2001 } 2049 }
2002 } else { 2050 } else {
@@ -2010,8 +2058,10 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
2010 } 2058 }
2011 } while (frame->frameState == FrameState_Grabbing); 2059 } while (frame->frameState == FrameState_Grabbing);
2012 if (uvd->debug >= 2) { 2060 if (uvd->debug >= 2) {
2013 info("%s: Grabbing done; state=%d. (%lu. bytes)", 2061 dev_info(&uvd->dev->dev,
2014 __func__, frame->frameState, frame->seqRead_Length); 2062 "%s: Grabbing done; state=%d. (%lu. bytes)\n",
2063 __func__, frame->frameState,
2064 frame->seqRead_Length);
2015 } 2065 }
2016 if (frame->frameState == FrameState_Error) { 2066 if (frame->frameState == FrameState_Error) {
2017 int ret = usbvideo_NewFrame(uvd, frameNum); 2067 int ret = usbvideo_NewFrame(uvd, frameNum);
@@ -2048,7 +2098,9 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
2048 } 2098 }
2049 frame->frameState = FrameState_Done_Hold; 2099 frame->frameState = FrameState_Done_Hold;
2050 if (uvd->debug >= 2) 2100 if (uvd->debug >= 2)
2051 info("%s: Entered FrameState_Done_Hold state.", __func__); 2101 dev_info(&uvd->dev->dev,
2102 "%s: Entered FrameState_Done_Hold state.\n",
2103 __func__);
2052 return 0; 2104 return 0;
2053 2105
2054 case FrameState_Done_Hold: 2106 case FrameState_Done_Hold:
@@ -2059,7 +2111,9 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
2059 * it will be released back into the wild to roam freely. 2111 * it will be released back into the wild to roam freely.
2060 */ 2112 */
2061 if (uvd->debug >= 2) 2113 if (uvd->debug >= 2)
2062 info("%s: FrameState_Done_Hold state.", __func__); 2114 dev_info(&uvd->dev->dev,
2115 "%s: FrameState_Done_Hold state.\n",
2116 __func__);
2063 return 0; 2117 return 0;
2064 } 2118 }
2065 2119
diff --git a/drivers/media/video/usbvideo/vicam.c b/drivers/media/video/usbvideo/vicam.c
index 2eb45829791c..7a127d6bfdee 100644
--- a/drivers/media/video/usbvideo/vicam.c
+++ b/drivers/media/video/usbvideo/vicam.c
@@ -472,9 +472,8 @@ vicam_ioctl(struct inode *inode, struct file *file, unsigned int ioctlnr, unsign
472static int 472static int
473vicam_open(struct inode *inode, struct file *file) 473vicam_open(struct inode *inode, struct file *file)
474{ 474{
475 struct video_device *dev = video_devdata(file); 475 struct vicam_camera *cam = video_drvdata(file);
476 struct vicam_camera *cam = 476
477 (struct vicam_camera *) dev->priv;
478 DBG("open\n"); 477 DBG("open\n");
479 478
480 if (!cam) { 479 if (!cam) {
@@ -488,20 +487,24 @@ vicam_open(struct inode *inode, struct file *file)
488 * rely on this fact forever. 487 * rely on this fact forever.
489 */ 488 */
490 489
490 lock_kernel();
491 if (cam->open_count > 0) { 491 if (cam->open_count > 0) {
492 printk(KERN_INFO 492 printk(KERN_INFO
493 "vicam_open called on already opened camera"); 493 "vicam_open called on already opened camera");
494 unlock_kernel();
494 return -EBUSY; 495 return -EBUSY;
495 } 496 }
496 497
497 cam->raw_image = kmalloc(VICAM_MAX_READ_SIZE, GFP_KERNEL); 498 cam->raw_image = kmalloc(VICAM_MAX_READ_SIZE, GFP_KERNEL);
498 if (!cam->raw_image) { 499 if (!cam->raw_image) {
500 unlock_kernel();
499 return -ENOMEM; 501 return -ENOMEM;
500 } 502 }
501 503
502 cam->framebuf = rvmalloc(VICAM_MAX_FRAME_SIZE * VICAM_FRAMES); 504 cam->framebuf = rvmalloc(VICAM_MAX_FRAME_SIZE * VICAM_FRAMES);
503 if (!cam->framebuf) { 505 if (!cam->framebuf) {
504 kfree(cam->raw_image); 506 kfree(cam->raw_image);
507 unlock_kernel();
505 return -ENOMEM; 508 return -ENOMEM;
506 } 509 }
507 510
@@ -509,6 +512,7 @@ vicam_open(struct inode *inode, struct file *file)
509 if (!cam->cntrlbuf) { 512 if (!cam->cntrlbuf) {
510 kfree(cam->raw_image); 513 kfree(cam->raw_image);
511 rvfree(cam->framebuf, VICAM_MAX_FRAME_SIZE * VICAM_FRAMES); 514 rvfree(cam->framebuf, VICAM_MAX_FRAME_SIZE * VICAM_FRAMES);
515 unlock_kernel();
512 return -ENOMEM; 516 return -ENOMEM;
513 } 517 }
514 518
@@ -526,6 +530,7 @@ vicam_open(struct inode *inode, struct file *file)
526 cam->open_count++; 530 cam->open_count++;
527 531
528 file->private_data = cam; 532 file->private_data = cam;
533 unlock_kernel();
529 534
530 return 0; 535 return 0;
531} 536}
@@ -795,6 +800,7 @@ static struct video_device vicam_template = {
795 .name = "ViCam-based USB Camera", 800 .name = "ViCam-based USB Camera",
796 .fops = &vicam_fops, 801 .fops = &vicam_fops,
797 .minor = -1, 802 .minor = -1,
803 .release = video_device_release_empty,
798}; 804};
799 805
800/* table of devices that work with this driver */ 806/* table of devices that work with this driver */
@@ -859,9 +865,8 @@ vicam_probe( struct usb_interface *intf, const struct usb_device_id *id)
859 865
860 mutex_init(&cam->cam_lock); 866 mutex_init(&cam->cam_lock);
861 867
862 memcpy(&cam->vdev, &vicam_template, 868 memcpy(&cam->vdev, &vicam_template, sizeof(vicam_template));
863 sizeof (vicam_template)); 869 video_set_drvdata(&cam->vdev, cam);
864 cam->vdev.priv = cam; // sort of a reverse mapping for those functions that get vdev only
865 870
866 cam->udev = dev; 871 cam->udev = dev;
867 cam->bulkEndpoint = bulkEndpoint; 872 cam->bulkEndpoint = bulkEndpoint;
diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
index c317ed7a8482..9e4f50639975 100644
--- a/drivers/media/video/usbvision/usbvision-core.c
+++ b/drivers/media/video/usbvision/usbvision-core.c
@@ -45,10 +45,6 @@
45 45
46#include <linux/workqueue.h> 46#include <linux/workqueue.h>
47 47
48#ifdef CONFIG_KMOD
49#include <linux/kmod.h>
50#endif
51
52#include "usbvision.h" 48#include "usbvision.h"
53 49
54static unsigned int core_debug; 50static unsigned int core_debug;
@@ -84,7 +80,8 @@ MODULE_PARM_DESC(adjust_Y_Offset, "adjust Y offset display [core]");
84#ifdef USBVISION_DEBUG 80#ifdef USBVISION_DEBUG
85 #define PDEBUG(level, fmt, args...) { \ 81 #define PDEBUG(level, fmt, args...) { \
86 if (core_debug & (level)) \ 82 if (core_debug & (level)) \
87 info("[%s:%d] " fmt, __func__, __LINE__ , ## args); \ 83 printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \
84 __func__, __LINE__ , ## args); \
88 } 85 }
89#else 86#else
90 #define PDEBUG(level, fmt, args...) do {} while(0) 87 #define PDEBUG(level, fmt, args...) do {} while(0)
diff --git a/drivers/media/video/usbvision/usbvision-i2c.c b/drivers/media/video/usbvision/usbvision-i2c.c
index a6d00858b07e..92427fdc1459 100644
--- a/drivers/media/video/usbvision/usbvision-i2c.c
+++ b/drivers/media/video/usbvision/usbvision-i2c.c
@@ -47,7 +47,8 @@ MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
47 47
48#define PDEBUG(level, fmt, args...) { \ 48#define PDEBUG(level, fmt, args...) { \
49 if (i2c_debug & (level)) \ 49 if (i2c_debug & (level)) \
50 info("[%s:%d] " fmt, __func__, __LINE__ , ## args); \ 50 printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \
51 __func__, __LINE__ , ## args); \
51 } 52 }
52 53
53static int usbvision_i2c_write(struct usb_usbvision *usbvision, unsigned char addr, char *buf, 54static int usbvision_i2c_write(struct usb_usbvision *usbvision, unsigned char addr, char *buf,
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index b977116a0dd9..77aeb39b2750 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -69,10 +69,6 @@
69 69
70#include <linux/workqueue.h> 70#include <linux/workqueue.h>
71 71
72#ifdef CONFIG_KMOD
73#include <linux/kmod.h>
74#endif
75
76#include "usbvision.h" 72#include "usbvision.h"
77#include "usbvision-cards.h" 73#include "usbvision-cards.h"
78 74
@@ -98,7 +94,8 @@ USBVISION_DRIVER_VERSION_PATCHLEVEL)
98#ifdef USBVISION_DEBUG 94#ifdef USBVISION_DEBUG
99 #define PDEBUG(level, fmt, args...) { \ 95 #define PDEBUG(level, fmt, args...) { \
100 if (video_debug & (level)) \ 96 if (video_debug & (level)) \
101 info("[%s:%d] " fmt, __func__, __LINE__ , ## args); \ 97 printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \
98 __func__, __LINE__ , ## args); \
102 } 99 }
103#else 100#else
104 #define PDEBUG(level, fmt, args...) do {} while(0) 101 #define PDEBUG(level, fmt, args...) do {} while(0)
@@ -360,13 +357,12 @@ static void usbvision_remove_sysfs(struct video_device *vdev)
360 */ 357 */
361static int usbvision_v4l2_open(struct inode *inode, struct file *file) 358static int usbvision_v4l2_open(struct inode *inode, struct file *file)
362{ 359{
363 struct video_device *dev = video_devdata(file); 360 struct usb_usbvision *usbvision = video_drvdata(file);
364 struct usb_usbvision *usbvision =
365 (struct usb_usbvision *) video_get_drvdata(dev);
366 int errCode = 0; 361 int errCode = 0;
367 362
368 PDEBUG(DBG_IO, "open"); 363 PDEBUG(DBG_IO, "open");
369 364
365 lock_kernel();
370 usbvision_reset_powerOffTimer(usbvision); 366 usbvision_reset_powerOffTimer(usbvision);
371 367
372 if (usbvision->user) 368 if (usbvision->user)
@@ -424,6 +420,7 @@ static int usbvision_v4l2_open(struct inode *inode, struct file *file)
424 usbvision_empty_framequeues(usbvision); 420 usbvision_empty_framequeues(usbvision);
425 421
426 PDEBUG(DBG_IO, "success"); 422 PDEBUG(DBG_IO, "success");
423 unlock_kernel();
427 return errCode; 424 return errCode;
428} 425}
429 426
@@ -437,9 +434,7 @@ static int usbvision_v4l2_open(struct inode *inode, struct file *file)
437 */ 434 */
438static int usbvision_v4l2_close(struct inode *inode, struct file *file) 435static int usbvision_v4l2_close(struct inode *inode, struct file *file)
439{ 436{
440 struct video_device *dev = video_devdata(file); 437 struct usb_usbvision *usbvision = video_drvdata(file);
441 struct usb_usbvision *usbvision =
442 (struct usb_usbvision *) video_get_drvdata(dev);
443 438
444 PDEBUG(DBG_IO, "close"); 439 PDEBUG(DBG_IO, "close");
445 mutex_lock(&usbvision->lock); 440 mutex_lock(&usbvision->lock);
@@ -484,9 +479,7 @@ static int usbvision_v4l2_close(struct inode *inode, struct file *file)
484static int vidioc_g_register (struct file *file, void *priv, 479static int vidioc_g_register (struct file *file, void *priv,
485 struct v4l2_register *reg) 480 struct v4l2_register *reg)
486{ 481{
487 struct video_device *dev = video_devdata(file); 482 struct usb_usbvision *usbvision = video_drvdata(file);
488 struct usb_usbvision *usbvision =
489 (struct usb_usbvision *) video_get_drvdata(dev);
490 int errCode; 483 int errCode;
491 484
492 if (!v4l2_chip_match_host(reg->match_type, reg->match_chip)) 485 if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
@@ -505,9 +498,7 @@ static int vidioc_g_register (struct file *file, void *priv,
505static int vidioc_s_register (struct file *file, void *priv, 498static int vidioc_s_register (struct file *file, void *priv,
506 struct v4l2_register *reg) 499 struct v4l2_register *reg)
507{ 500{
508 struct video_device *dev = video_devdata(file); 501 struct usb_usbvision *usbvision = video_drvdata(file);
509 struct usb_usbvision *usbvision =
510 (struct usb_usbvision *) video_get_drvdata(dev);
511 int errCode; 502 int errCode;
512 503
513 if (!v4l2_chip_match_host(reg->match_type, reg->match_chip)) 504 if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
@@ -526,9 +517,7 @@ static int vidioc_s_register (struct file *file, void *priv,
526static int vidioc_querycap (struct file *file, void *priv, 517static int vidioc_querycap (struct file *file, void *priv,
527 struct v4l2_capability *vc) 518 struct v4l2_capability *vc)
528{ 519{
529 struct video_device *dev = video_devdata(file); 520 struct usb_usbvision *usbvision = video_drvdata(file);
530 struct usb_usbvision *usbvision =
531 (struct usb_usbvision *) video_get_drvdata(dev);
532 521
533 strlcpy(vc->driver, "USBVision", sizeof(vc->driver)); 522 strlcpy(vc->driver, "USBVision", sizeof(vc->driver));
534 strlcpy(vc->card, 523 strlcpy(vc->card,
@@ -548,9 +537,7 @@ static int vidioc_querycap (struct file *file, void *priv,
548static int vidioc_enum_input (struct file *file, void *priv, 537static int vidioc_enum_input (struct file *file, void *priv,
549 struct v4l2_input *vi) 538 struct v4l2_input *vi)
550{ 539{
551 struct video_device *dev = video_devdata(file); 540 struct usb_usbvision *usbvision = video_drvdata(file);
552 struct usb_usbvision *usbvision =
553 (struct usb_usbvision *) video_get_drvdata(dev);
554 int chan; 541 int chan;
555 542
556 if ((vi->index >= usbvision->video_inputs) || (vi->index < 0) ) 543 if ((vi->index >= usbvision->video_inputs) || (vi->index < 0) )
@@ -603,9 +590,7 @@ static int vidioc_enum_input (struct file *file, void *priv,
603 590
604static int vidioc_g_input (struct file *file, void *priv, unsigned int *input) 591static int vidioc_g_input (struct file *file, void *priv, unsigned int *input)
605{ 592{
606 struct video_device *dev = video_devdata(file); 593 struct usb_usbvision *usbvision = video_drvdata(file);
607 struct usb_usbvision *usbvision =
608 (struct usb_usbvision *) video_get_drvdata(dev);
609 594
610 *input = usbvision->ctl_input; 595 *input = usbvision->ctl_input;
611 return 0; 596 return 0;
@@ -613,9 +598,7 @@ static int vidioc_g_input (struct file *file, void *priv, unsigned int *input)
613 598
614static int vidioc_s_input (struct file *file, void *priv, unsigned int input) 599static int vidioc_s_input (struct file *file, void *priv, unsigned int input)
615{ 600{
616 struct video_device *dev = video_devdata(file); 601 struct usb_usbvision *usbvision = video_drvdata(file);
617 struct usb_usbvision *usbvision =
618 (struct usb_usbvision *) video_get_drvdata(dev);
619 602
620 if ((input >= usbvision->video_inputs) || (input < 0) ) 603 if ((input >= usbvision->video_inputs) || (input < 0) )
621 return -EINVAL; 604 return -EINVAL;
@@ -632,9 +615,8 @@ static int vidioc_s_input (struct file *file, void *priv, unsigned int input)
632 615
633static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *id) 616static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *id)
634{ 617{
635 struct video_device *dev = video_devdata(file); 618 struct usb_usbvision *usbvision = video_drvdata(file);
636 struct usb_usbvision *usbvision = 619
637 (struct usb_usbvision *) video_get_drvdata(dev);
638 usbvision->tvnormId=*id; 620 usbvision->tvnormId=*id;
639 621
640 mutex_lock(&usbvision->lock); 622 mutex_lock(&usbvision->lock);
@@ -650,9 +632,7 @@ static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *id)
650static int vidioc_g_tuner (struct file *file, void *priv, 632static int vidioc_g_tuner (struct file *file, void *priv,
651 struct v4l2_tuner *vt) 633 struct v4l2_tuner *vt)
652{ 634{
653 struct video_device *dev = video_devdata(file); 635 struct usb_usbvision *usbvision = video_drvdata(file);
654 struct usb_usbvision *usbvision =
655 (struct usb_usbvision *) video_get_drvdata(dev);
656 636
657 if (!usbvision->have_tuner || vt->index) // Only tuner 0 637 if (!usbvision->have_tuner || vt->index) // Only tuner 0
658 return -EINVAL; 638 return -EINVAL;
@@ -671,9 +651,7 @@ static int vidioc_g_tuner (struct file *file, void *priv,
671static int vidioc_s_tuner (struct file *file, void *priv, 651static int vidioc_s_tuner (struct file *file, void *priv,
672 struct v4l2_tuner *vt) 652 struct v4l2_tuner *vt)
673{ 653{
674 struct video_device *dev = video_devdata(file); 654 struct usb_usbvision *usbvision = video_drvdata(file);
675 struct usb_usbvision *usbvision =
676 (struct usb_usbvision *) video_get_drvdata(dev);
677 655
678 // Only no or one tuner for now 656 // Only no or one tuner for now
679 if (!usbvision->have_tuner || vt->index) 657 if (!usbvision->have_tuner || vt->index)
@@ -687,9 +665,7 @@ static int vidioc_s_tuner (struct file *file, void *priv,
687static int vidioc_g_frequency (struct file *file, void *priv, 665static int vidioc_g_frequency (struct file *file, void *priv,
688 struct v4l2_frequency *freq) 666 struct v4l2_frequency *freq)
689{ 667{
690 struct video_device *dev = video_devdata(file); 668 struct usb_usbvision *usbvision = video_drvdata(file);
691 struct usb_usbvision *usbvision =
692 (struct usb_usbvision *) video_get_drvdata(dev);
693 669
694 freq->tuner = 0; // Only one tuner 670 freq->tuner = 0; // Only one tuner
695 if(usbvision->radio) { 671 if(usbvision->radio) {
@@ -705,9 +681,7 @@ static int vidioc_g_frequency (struct file *file, void *priv,
705static int vidioc_s_frequency (struct file *file, void *priv, 681static int vidioc_s_frequency (struct file *file, void *priv,
706 struct v4l2_frequency *freq) 682 struct v4l2_frequency *freq)
707{ 683{
708 struct video_device *dev = video_devdata(file); 684 struct usb_usbvision *usbvision = video_drvdata(file);
709 struct usb_usbvision *usbvision =
710 (struct usb_usbvision *) video_get_drvdata(dev);
711 685
712 // Only no or one tuner for now 686 // Only no or one tuner for now
713 if (!usbvision->have_tuner || freq->tuner) 687 if (!usbvision->have_tuner || freq->tuner)
@@ -721,9 +695,7 @@ static int vidioc_s_frequency (struct file *file, void *priv,
721 695
722static int vidioc_g_audio (struct file *file, void *priv, struct v4l2_audio *a) 696static int vidioc_g_audio (struct file *file, void *priv, struct v4l2_audio *a)
723{ 697{
724 struct video_device *dev = video_devdata(file); 698 struct usb_usbvision *usbvision = video_drvdata(file);
725 struct usb_usbvision *usbvision =
726 (struct usb_usbvision *) video_get_drvdata(dev);
727 699
728 memset(a,0,sizeof(*a)); 700 memset(a,0,sizeof(*a));
729 if(usbvision->radio) { 701 if(usbvision->radio) {
@@ -748,9 +720,7 @@ static int vidioc_s_audio (struct file *file, void *fh,
748static int vidioc_queryctrl (struct file *file, void *priv, 720static int vidioc_queryctrl (struct file *file, void *priv,
749 struct v4l2_queryctrl *ctrl) 721 struct v4l2_queryctrl *ctrl)
750{ 722{
751 struct video_device *dev = video_devdata(file); 723 struct usb_usbvision *usbvision = video_drvdata(file);
752 struct usb_usbvision *usbvision =
753 (struct usb_usbvision *) video_get_drvdata(dev);
754 int id=ctrl->id; 724 int id=ctrl->id;
755 725
756 memset(ctrl,0,sizeof(*ctrl)); 726 memset(ctrl,0,sizeof(*ctrl));
@@ -767,9 +737,7 @@ static int vidioc_queryctrl (struct file *file, void *priv,
767static int vidioc_g_ctrl (struct file *file, void *priv, 737static int vidioc_g_ctrl (struct file *file, void *priv,
768 struct v4l2_control *ctrl) 738 struct v4l2_control *ctrl)
769{ 739{
770 struct video_device *dev = video_devdata(file); 740 struct usb_usbvision *usbvision = video_drvdata(file);
771 struct usb_usbvision *usbvision =
772 (struct usb_usbvision *) video_get_drvdata(dev);
773 call_i2c_clients(usbvision, VIDIOC_G_CTRL, ctrl); 741 call_i2c_clients(usbvision, VIDIOC_G_CTRL, ctrl);
774 742
775 return 0; 743 return 0;
@@ -778,9 +746,7 @@ static int vidioc_g_ctrl (struct file *file, void *priv,
778static int vidioc_s_ctrl (struct file *file, void *priv, 746static int vidioc_s_ctrl (struct file *file, void *priv,
779 struct v4l2_control *ctrl) 747 struct v4l2_control *ctrl)
780{ 748{
781 struct video_device *dev = video_devdata(file); 749 struct usb_usbvision *usbvision = video_drvdata(file);
782 struct usb_usbvision *usbvision =
783 (struct usb_usbvision *) video_get_drvdata(dev);
784 call_i2c_clients(usbvision, VIDIOC_S_CTRL, ctrl); 750 call_i2c_clients(usbvision, VIDIOC_S_CTRL, ctrl);
785 751
786 return 0; 752 return 0;
@@ -789,9 +755,7 @@ static int vidioc_s_ctrl (struct file *file, void *priv,
789static int vidioc_reqbufs (struct file *file, 755static int vidioc_reqbufs (struct file *file,
790 void *priv, struct v4l2_requestbuffers *vr) 756 void *priv, struct v4l2_requestbuffers *vr)
791{ 757{
792 struct video_device *dev = video_devdata(file); 758 struct usb_usbvision *usbvision = video_drvdata(file);
793 struct usb_usbvision *usbvision =
794 (struct usb_usbvision *) video_get_drvdata(dev);
795 int ret; 759 int ret;
796 760
797 RESTRICT_TO_RANGE(vr->count,1,USBVISION_NUMFRAMES); 761 RESTRICT_TO_RANGE(vr->count,1,USBVISION_NUMFRAMES);
@@ -819,9 +783,7 @@ static int vidioc_reqbufs (struct file *file,
819static int vidioc_querybuf (struct file *file, 783static int vidioc_querybuf (struct file *file,
820 void *priv, struct v4l2_buffer *vb) 784 void *priv, struct v4l2_buffer *vb)
821{ 785{
822 struct video_device *dev = video_devdata(file); 786 struct usb_usbvision *usbvision = video_drvdata(file);
823 struct usb_usbvision *usbvision =
824 (struct usb_usbvision *) video_get_drvdata(dev);
825 struct usbvision_frame *frame; 787 struct usbvision_frame *frame;
826 788
827 /* FIXME : must control 789 /* FIXME : must control
@@ -857,9 +819,7 @@ static int vidioc_querybuf (struct file *file,
857 819
858static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *vb) 820static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
859{ 821{
860 struct video_device *dev = video_devdata(file); 822 struct usb_usbvision *usbvision = video_drvdata(file);
861 struct usb_usbvision *usbvision =
862 (struct usb_usbvision *) video_get_drvdata(dev);
863 struct usbvision_frame *frame; 823 struct usbvision_frame *frame;
864 unsigned long lock_flags; 824 unsigned long lock_flags;
865 825
@@ -896,9 +856,7 @@ static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
896 856
897static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *vb) 857static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
898{ 858{
899 struct video_device *dev = video_devdata(file); 859 struct usb_usbvision *usbvision = video_drvdata(file);
900 struct usb_usbvision *usbvision =
901 (struct usb_usbvision *) video_get_drvdata(dev);
902 int ret; 860 int ret;
903 struct usbvision_frame *f; 861 struct usbvision_frame *f;
904 unsigned long lock_flags; 862 unsigned long lock_flags;
@@ -939,9 +897,7 @@ static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
939 897
940static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i) 898static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
941{ 899{
942 struct video_device *dev = video_devdata(file); 900 struct usb_usbvision *usbvision = video_drvdata(file);
943 struct usb_usbvision *usbvision =
944 (struct usb_usbvision *) video_get_drvdata(dev);
945 int b=V4L2_BUF_TYPE_VIDEO_CAPTURE; 901 int b=V4L2_BUF_TYPE_VIDEO_CAPTURE;
946 902
947 usbvision->streaming = Stream_On; 903 usbvision->streaming = Stream_On;
@@ -953,9 +909,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
953static int vidioc_streamoff(struct file *file, 909static int vidioc_streamoff(struct file *file,
954 void *priv, enum v4l2_buf_type type) 910 void *priv, enum v4l2_buf_type type)
955{ 911{
956 struct video_device *dev = video_devdata(file); 912 struct usb_usbvision *usbvision = video_drvdata(file);
957 struct usb_usbvision *usbvision =
958 (struct usb_usbvision *) video_get_drvdata(dev);
959 int b=V4L2_BUF_TYPE_VIDEO_CAPTURE; 913 int b=V4L2_BUF_TYPE_VIDEO_CAPTURE;
960 914
961 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 915 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
@@ -988,9 +942,7 @@ static int vidioc_enum_fmt_vid_cap (struct file *file, void *priv,
988static int vidioc_g_fmt_vid_cap (struct file *file, void *priv, 942static int vidioc_g_fmt_vid_cap (struct file *file, void *priv,
989 struct v4l2_format *vf) 943 struct v4l2_format *vf)
990{ 944{
991 struct video_device *dev = video_devdata(file); 945 struct usb_usbvision *usbvision = video_drvdata(file);
992 struct usb_usbvision *usbvision =
993 (struct usb_usbvision *) video_get_drvdata(dev);
994 vf->fmt.pix.width = usbvision->curwidth; 946 vf->fmt.pix.width = usbvision->curwidth;
995 vf->fmt.pix.height = usbvision->curheight; 947 vf->fmt.pix.height = usbvision->curheight;
996 vf->fmt.pix.pixelformat = usbvision->palette.format; 948 vf->fmt.pix.pixelformat = usbvision->palette.format;
@@ -1006,9 +958,7 @@ static int vidioc_g_fmt_vid_cap (struct file *file, void *priv,
1006static int vidioc_try_fmt_vid_cap (struct file *file, void *priv, 958static int vidioc_try_fmt_vid_cap (struct file *file, void *priv,
1007 struct v4l2_format *vf) 959 struct v4l2_format *vf)
1008{ 960{
1009 struct video_device *dev = video_devdata(file); 961 struct usb_usbvision *usbvision = video_drvdata(file);
1010 struct usb_usbvision *usbvision =
1011 (struct usb_usbvision *) video_get_drvdata(dev);
1012 int formatIdx; 962 int formatIdx;
1013 963
1014 /* Find requested format in available ones */ 964 /* Find requested format in available ones */
@@ -1036,9 +986,7 @@ static int vidioc_try_fmt_vid_cap (struct file *file, void *priv,
1036static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, 986static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1037 struct v4l2_format *vf) 987 struct v4l2_format *vf)
1038{ 988{
1039 struct video_device *dev = video_devdata(file); 989 struct usb_usbvision *usbvision = video_drvdata(file);
1040 struct usb_usbvision *usbvision =
1041 (struct usb_usbvision *) video_get_drvdata(dev);
1042 int ret; 990 int ret;
1043 991
1044 if( 0 != (ret=vidioc_try_fmt_vid_cap (file, priv, vf)) ) { 992 if( 0 != (ret=vidioc_try_fmt_vid_cap (file, priv, vf)) ) {
@@ -1066,9 +1014,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1066static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf, 1014static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1067 size_t count, loff_t *ppos) 1015 size_t count, loff_t *ppos)
1068{ 1016{
1069 struct video_device *dev = video_devdata(file); 1017 struct usb_usbvision *usbvision = video_drvdata(file);
1070 struct usb_usbvision *usbvision =
1071 (struct usb_usbvision *) video_get_drvdata(dev);
1072 int noblock = file->f_flags & O_NONBLOCK; 1018 int noblock = file->f_flags & O_NONBLOCK;
1073 unsigned long lock_flags; 1019 unsigned long lock_flags;
1074 1020
@@ -1177,10 +1123,7 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1177 start = vma->vm_start; 1123 start = vma->vm_start;
1178 void *pos; 1124 void *pos;
1179 u32 i; 1125 u32 i;
1180 1126 struct usb_usbvision *usbvision = video_drvdata(file);
1181 struct video_device *dev = video_devdata(file);
1182 struct usb_usbvision *usbvision =
1183 (struct usb_usbvision *) video_get_drvdata(dev);
1184 1127
1185 PDEBUG(DBG_MMAP, "mmap"); 1128 PDEBUG(DBG_MMAP, "mmap");
1186 1129
@@ -1237,9 +1180,7 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1237 */ 1180 */
1238static int usbvision_radio_open(struct inode *inode, struct file *file) 1181static int usbvision_radio_open(struct inode *inode, struct file *file)
1239{ 1182{
1240 struct video_device *dev = video_devdata(file); 1183 struct usb_usbvision *usbvision = video_drvdata(file);
1241 struct usb_usbvision *usbvision =
1242 (struct usb_usbvision *) video_get_drvdata(dev);
1243 int errCode = 0; 1184 int errCode = 0;
1244 1185
1245 PDEBUG(DBG_IO, "%s:", __func__); 1186 PDEBUG(DBG_IO, "%s:", __func__);
@@ -1289,9 +1230,7 @@ out:
1289 1230
1290static int usbvision_radio_close(struct inode *inode, struct file *file) 1231static int usbvision_radio_close(struct inode *inode, struct file *file)
1291{ 1232{
1292 struct video_device *dev = video_devdata(file); 1233 struct usb_usbvision *usbvision = video_drvdata(file);
1293 struct usb_usbvision *usbvision =
1294 (struct usb_usbvision *) video_get_drvdata(dev);
1295 int errCode = 0; 1234 int errCode = 0;
1296 1235
1297 PDEBUG(DBG_IO, ""); 1236 PDEBUG(DBG_IO, "");
diff --git a/drivers/media/video/uvc/uvc_ctrl.c b/drivers/media/video/uvc/uvc_ctrl.c
index feab12aa2c7b..f16aafe9cf14 100644
--- a/drivers/media/video/uvc/uvc_ctrl.c
+++ b/drivers/media/video/uvc/uvc_ctrl.c
@@ -83,6 +83,22 @@ static struct uvc_control_info uvc_ctrls[] = {
83 }, 83 },
84 { 84 {
85 .entity = UVC_GUID_UVC_PROCESSING, 85 .entity = UVC_GUID_UVC_PROCESSING,
86 .selector = PU_WHITE_BALANCE_TEMPERATURE_CONTROL,
87 .index = 6,
88 .size = 2,
89 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
90 | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
91 },
92 {
93 .entity = UVC_GUID_UVC_PROCESSING,
94 .selector = PU_WHITE_BALANCE_COMPONENT_CONTROL,
95 .index = 7,
96 .size = 4,
97 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
98 | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
99 },
100 {
101 .entity = UVC_GUID_UVC_PROCESSING,
86 .selector = PU_BACKLIGHT_COMPENSATION_CONTROL, 102 .selector = PU_BACKLIGHT_COMPENSATION_CONTROL,
87 .index = 8, 103 .index = 8,
88 .size = 2, 104 .size = 2,
@@ -114,6 +130,60 @@ static struct uvc_control_info uvc_ctrls[] = {
114 | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE, 130 | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
115 }, 131 },
116 { 132 {
133 .entity = UVC_GUID_UVC_PROCESSING,
134 .selector = PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL,
135 .index = 12,
136 .size = 1,
137 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
138 | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
139 },
140 {
141 .entity = UVC_GUID_UVC_PROCESSING,
142 .selector = PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL,
143 .index = 13,
144 .size = 1,
145 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
146 | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
147 },
148 {
149 .entity = UVC_GUID_UVC_PROCESSING,
150 .selector = PU_DIGITAL_MULTIPLIER_CONTROL,
151 .index = 14,
152 .size = 2,
153 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
154 | UVC_CONTROL_RESTORE,
155 },
156 {
157 .entity = UVC_GUID_UVC_PROCESSING,
158 .selector = PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL,
159 .index = 15,
160 .size = 2,
161 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
162 | UVC_CONTROL_RESTORE,
163 },
164 {
165 .entity = UVC_GUID_UVC_PROCESSING,
166 .selector = PU_ANALOG_VIDEO_STANDARD_CONTROL,
167 .index = 16,
168 .size = 1,
169 .flags = UVC_CONTROL_GET_CUR,
170 },
171 {
172 .entity = UVC_GUID_UVC_PROCESSING,
173 .selector = PU_ANALOG_LOCK_STATUS_CONTROL,
174 .index = 17,
175 .size = 1,
176 .flags = UVC_CONTROL_GET_CUR,
177 },
178 {
179 .entity = UVC_GUID_UVC_CAMERA,
180 .selector = CT_SCANNING_MODE_CONTROL,
181 .index = 0,
182 .size = 1,
183 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
184 | UVC_CONTROL_RESTORE,
185 },
186 {
117 .entity = UVC_GUID_UVC_CAMERA, 187 .entity = UVC_GUID_UVC_CAMERA,
118 .selector = CT_AE_MODE_CONTROL, 188 .selector = CT_AE_MODE_CONTROL,
119 .index = 1, 189 .index = 1,
@@ -140,6 +210,14 @@ static struct uvc_control_info uvc_ctrls[] = {
140 }, 210 },
141 { 211 {
142 .entity = UVC_GUID_UVC_CAMERA, 212 .entity = UVC_GUID_UVC_CAMERA,
213 .selector = CT_EXPOSURE_TIME_RELATIVE_CONTROL,
214 .index = 4,
215 .size = 1,
216 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
217 | UVC_CONTROL_RESTORE,
218 },
219 {
220 .entity = UVC_GUID_UVC_CAMERA,
143 .selector = CT_FOCUS_ABSOLUTE_CONTROL, 221 .selector = CT_FOCUS_ABSOLUTE_CONTROL,
144 .index = 5, 222 .index = 5,
145 .size = 2, 223 .size = 2,
@@ -148,42 +226,90 @@ static struct uvc_control_info uvc_ctrls[] = {
148 }, 226 },
149 { 227 {
150 .entity = UVC_GUID_UVC_CAMERA, 228 .entity = UVC_GUID_UVC_CAMERA,
151 .selector = CT_FOCUS_AUTO_CONTROL, 229 .selector = CT_FOCUS_RELATIVE_CONTROL,
152 .index = 17, 230 .index = 6,
153 .size = 1, 231 .size = 2,
154 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR 232 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
155 | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE, 233 | UVC_CONTROL_AUTO_UPDATE,
156 }, 234 },
157 { 235 {
158 .entity = UVC_GUID_UVC_PROCESSING, 236 .entity = UVC_GUID_UVC_CAMERA,
159 .selector = PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL, 237 .selector = CT_IRIS_ABSOLUTE_CONTROL,
160 .index = 12, 238 .index = 7,
239 .size = 2,
240 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
241 | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
242 },
243 {
244 .entity = UVC_GUID_UVC_CAMERA,
245 .selector = CT_IRIS_RELATIVE_CONTROL,
246 .index = 8,
161 .size = 1, 247 .size = 1,
162 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR 248 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
163 | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE, 249 | UVC_CONTROL_AUTO_UPDATE,
164 }, 250 },
165 { 251 {
166 .entity = UVC_GUID_UVC_PROCESSING, 252 .entity = UVC_GUID_UVC_CAMERA,
167 .selector = PU_WHITE_BALANCE_TEMPERATURE_CONTROL, 253 .selector = CT_ZOOM_ABSOLUTE_CONTROL,
168 .index = 6, 254 .index = 9,
169 .size = 2, 255 .size = 2,
170 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 256 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
171 | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE, 257 | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
172 }, 258 },
173 { 259 {
174 .entity = UVC_GUID_UVC_PROCESSING, 260 .entity = UVC_GUID_UVC_CAMERA,
175 .selector = PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL, 261 .selector = CT_ZOOM_RELATIVE_CONTROL,
262 .index = 10,
263 .size = 3,
264 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
265 | UVC_CONTROL_AUTO_UPDATE,
266 },
267 {
268 .entity = UVC_GUID_UVC_CAMERA,
269 .selector = CT_PANTILT_ABSOLUTE_CONTROL,
270 .index = 11,
271 .size = 8,
272 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
273 | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
274 },
275 {
276 .entity = UVC_GUID_UVC_CAMERA,
277 .selector = CT_PANTILT_RELATIVE_CONTROL,
278 .index = 12,
279 .size = 4,
280 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
281 | UVC_CONTROL_AUTO_UPDATE,
282 },
283 {
284 .entity = UVC_GUID_UVC_CAMERA,
285 .selector = CT_ROLL_ABSOLUTE_CONTROL,
176 .index = 13, 286 .index = 13,
287 .size = 2,
288 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
289 | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
290 },
291 {
292 .entity = UVC_GUID_UVC_CAMERA,
293 .selector = CT_ROLL_RELATIVE_CONTROL,
294 .index = 14,
295 .size = 2,
296 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
297 | UVC_CONTROL_AUTO_UPDATE,
298 },
299 {
300 .entity = UVC_GUID_UVC_CAMERA,
301 .selector = CT_FOCUS_AUTO_CONTROL,
302 .index = 17,
177 .size = 1, 303 .size = 1,
178 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR 304 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
179 | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE, 305 | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
180 }, 306 },
181 { 307 {
182 .entity = UVC_GUID_UVC_PROCESSING, 308 .entity = UVC_GUID_UVC_CAMERA,
183 .selector = PU_WHITE_BALANCE_COMPONENT_CONTROL, 309 .selector = CT_PRIVACY_CONTROL,
184 .index = 7, 310 .index = 18,
185 .size = 4, 311 .size = 1,
186 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE 312 .flags = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
187 | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE, 313 | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
188 }, 314 },
189}; 315};
@@ -711,7 +837,17 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev,
711 837
712 for (i = 0; i < entity->ncontrols; ++i) { 838 for (i = 0; i < entity->ncontrols; ++i) {
713 ctrl = &entity->controls[i]; 839 ctrl = &entity->controls[i];
714 if (ctrl->info == NULL || !ctrl->dirty) 840 if (ctrl->info == NULL)
841 continue;
842
843 /* Reset the loaded flag for auto-update controls that were
844 * marked as loaded in uvc_ctrl_get/uvc_ctrl_set to prevent
845 * uvc_ctrl_get from using the cached value.
846 */
847 if (ctrl->info->flags & UVC_CONTROL_AUTO_UPDATE)
848 ctrl->loaded = 0;
849
850 if (!ctrl->dirty)
715 continue; 851 continue;
716 852
717 if (!rollback) 853 if (!rollback)
@@ -727,9 +863,6 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev,
727 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP), 863 uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP),
728 ctrl->info->size); 864 ctrl->info->size);
729 865
730 if ((ctrl->info->flags & UVC_CONTROL_GET_CUR) == 0)
731 ctrl->loaded = 0;
732
733 ctrl->dirty = 0; 866 ctrl->dirty = 0;
734 867
735 if (ret < 0) 868 if (ret < 0)
@@ -787,8 +920,7 @@ int uvc_ctrl_get(struct uvc_video_device *video,
787 if (ret < 0) 920 if (ret < 0)
788 return ret; 921 return ret;
789 922
790 if ((ctrl->info->flags & UVC_CONTROL_AUTO_UPDATE) == 0) 923 ctrl->loaded = 1;
791 ctrl->loaded = 1;
792 } 924 }
793 925
794 xctrl->value = uvc_get_le_value( 926 xctrl->value = uvc_get_le_value(
@@ -839,8 +971,7 @@ int uvc_ctrl_set(struct uvc_video_device *video,
839 return ret; 971 return ret;
840 } 972 }
841 973
842 if ((ctrl->info->flags & UVC_CONTROL_AUTO_UPDATE) == 0) 974 ctrl->loaded = 1;
843 ctrl->loaded = 1;
844 } 975 }
845 976
846 if (!ctrl->dirty) { 977 if (!ctrl->dirty) {
diff --git a/drivers/media/video/uvc/uvc_driver.c b/drivers/media/video/uvc/uvc_driver.c
index 7e102034d38d..d7ad060640bc 100644
--- a/drivers/media/video/uvc/uvc_driver.c
+++ b/drivers/media/video/uvc/uvc_driver.c
@@ -1663,7 +1663,7 @@ static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
1663 return uvc_video_suspend(&dev->video); 1663 return uvc_video_suspend(&dev->video);
1664} 1664}
1665 1665
1666static int uvc_resume(struct usb_interface *intf) 1666static int __uvc_resume(struct usb_interface *intf, int reset)
1667{ 1667{
1668 struct uvc_device *dev = usb_get_intfdata(intf); 1668 struct uvc_device *dev = usb_get_intfdata(intf);
1669 int ret; 1669 int ret;
@@ -1672,7 +1672,7 @@ static int uvc_resume(struct usb_interface *intf)
1672 intf->cur_altsetting->desc.bInterfaceNumber); 1672 intf->cur_altsetting->desc.bInterfaceNumber);
1673 1673
1674 if (intf->cur_altsetting->desc.bInterfaceSubClass == SC_VIDEOCONTROL) { 1674 if (intf->cur_altsetting->desc.bInterfaceSubClass == SC_VIDEOCONTROL) {
1675 if ((ret = uvc_ctrl_resume_device(dev)) < 0) 1675 if (reset && (ret = uvc_ctrl_resume_device(dev)) < 0)
1676 return ret; 1676 return ret;
1677 1677
1678 return uvc_status_resume(dev); 1678 return uvc_status_resume(dev);
@@ -1687,6 +1687,16 @@ static int uvc_resume(struct usb_interface *intf)
1687 return uvc_video_resume(&dev->video); 1687 return uvc_video_resume(&dev->video);
1688} 1688}
1689 1689
1690static int uvc_resume(struct usb_interface *intf)
1691{
1692 return __uvc_resume(intf, 0);
1693}
1694
1695static int uvc_reset_resume(struct usb_interface *intf)
1696{
1697 return __uvc_resume(intf, 1);
1698}
1699
1690/* ------------------------------------------------------------------------ 1700/* ------------------------------------------------------------------------
1691 * Driver initialization and cleanup 1701 * Driver initialization and cleanup
1692 */ 1702 */
@@ -1902,6 +1912,24 @@ static struct usb_device_id uvc_ids[] = {
1902 .bInterfaceSubClass = 1, 1912 .bInterfaceSubClass = 1,
1903 .bInterfaceProtocol = 0, 1913 .bInterfaceProtocol = 0,
1904 .driver_info = UVC_QUIRK_PROBE_MINMAX }, 1914 .driver_info = UVC_QUIRK_PROBE_MINMAX },
1915 /* Compaq Presario B1200 - Bison Electronics */
1916 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1917 | USB_DEVICE_ID_MATCH_INT_INFO,
1918 .idVendor = 0x5986,
1919 .idProduct = 0x0104,
1920 .bInterfaceClass = USB_CLASS_VIDEO,
1921 .bInterfaceSubClass = 1,
1922 .bInterfaceProtocol = 0,
1923 .driver_info = UVC_QUIRK_PROBE_MINMAX },
1924 /* Acer Travelmate 7720 - Bison Electronics */
1925 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1926 | USB_DEVICE_ID_MATCH_INT_INFO,
1927 .idVendor = 0x5986,
1928 .idProduct = 0x0105,
1929 .bInterfaceClass = USB_CLASS_VIDEO,
1930 .bInterfaceSubClass = 1,
1931 .bInterfaceProtocol = 0,
1932 .driver_info = UVC_QUIRK_PROBE_MINMAX },
1905 /* Medion Akoya Mini E1210 - Bison Electronics */ 1933 /* Medion Akoya Mini E1210 - Bison Electronics */
1906 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 1934 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1907 | USB_DEVICE_ID_MATCH_INT_INFO, 1935 | USB_DEVICE_ID_MATCH_INT_INFO,
@@ -1920,6 +1948,24 @@ static struct usb_device_id uvc_ids[] = {
1920 .bInterfaceSubClass = 1, 1948 .bInterfaceSubClass = 1,
1921 .bInterfaceProtocol = 0, 1949 .bInterfaceProtocol = 0,
1922 .driver_info = UVC_QUIRK_PROBE_MINMAX }, 1950 .driver_info = UVC_QUIRK_PROBE_MINMAX },
1951 /* Fujitsu Amilo SI2636 - Bison Electronics */
1952 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1953 | USB_DEVICE_ID_MATCH_INT_INFO,
1954 .idVendor = 0x5986,
1955 .idProduct = 0x0202,
1956 .bInterfaceClass = USB_CLASS_VIDEO,
1957 .bInterfaceSubClass = 1,
1958 .bInterfaceProtocol = 0,
1959 .driver_info = UVC_QUIRK_PROBE_MINMAX },
1960 /* Advent 4211 - Bison Electronics */
1961 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1962 | USB_DEVICE_ID_MATCH_INT_INFO,
1963 .idVendor = 0x5986,
1964 .idProduct = 0x0203,
1965 .bInterfaceClass = USB_CLASS_VIDEO,
1966 .bInterfaceSubClass = 1,
1967 .bInterfaceProtocol = 0,
1968 .driver_info = UVC_QUIRK_PROBE_MINMAX },
1923 /* Bison Electronics */ 1969 /* Bison Electronics */
1924 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE 1970 { .match_flags = USB_DEVICE_ID_MATCH_DEVICE
1925 | USB_DEVICE_ID_MATCH_INT_INFO, 1971 | USB_DEVICE_ID_MATCH_INT_INFO,
@@ -1952,6 +1998,7 @@ struct uvc_driver uvc_driver = {
1952 .disconnect = uvc_disconnect, 1998 .disconnect = uvc_disconnect,
1953 .suspend = uvc_suspend, 1999 .suspend = uvc_suspend,
1954 .resume = uvc_resume, 2000 .resume = uvc_resume,
2001 .reset_resume = uvc_reset_resume,
1955 .id_table = uvc_ids, 2002 .id_table = uvc_ids,
1956 .supports_autosuspend = 1, 2003 .supports_autosuspend = 1,
1957 }, 2004 },
diff --git a/drivers/media/video/uvc/uvc_status.c b/drivers/media/video/uvc/uvc_status.c
index 75e678ac54eb..5d60b264d59a 100644
--- a/drivers/media/video/uvc/uvc_status.c
+++ b/drivers/media/video/uvc/uvc_status.c
@@ -177,9 +177,15 @@ int uvc_status_init(struct uvc_device *dev)
177 177
178 uvc_input_init(dev); 178 uvc_input_init(dev);
179 179
180 dev->status = kzalloc(UVC_MAX_STATUS_SIZE, GFP_KERNEL);
181 if (dev->status == NULL)
182 return -ENOMEM;
183
180 dev->int_urb = usb_alloc_urb(0, GFP_KERNEL); 184 dev->int_urb = usb_alloc_urb(0, GFP_KERNEL);
181 if (dev->int_urb == NULL) 185 if (dev->int_urb == NULL) {
186 kfree(dev->status);
182 return -ENOMEM; 187 return -ENOMEM;
188 }
183 189
184 pipe = usb_rcvintpipe(dev->udev, ep->desc.bEndpointAddress); 190 pipe = usb_rcvintpipe(dev->udev, ep->desc.bEndpointAddress);
185 191
@@ -192,7 +198,7 @@ int uvc_status_init(struct uvc_device *dev)
192 interval = fls(interval) - 1; 198 interval = fls(interval) - 1;
193 199
194 usb_fill_int_urb(dev->int_urb, dev->udev, pipe, 200 usb_fill_int_urb(dev->int_urb, dev->udev, pipe,
195 dev->status, sizeof dev->status, uvc_status_complete, 201 dev->status, UVC_MAX_STATUS_SIZE, uvc_status_complete,
196 dev, interval); 202 dev, interval);
197 203
198 return usb_submit_urb(dev->int_urb, GFP_KERNEL); 204 return usb_submit_urb(dev->int_urb, GFP_KERNEL);
@@ -202,6 +208,7 @@ void uvc_status_cleanup(struct uvc_device *dev)
202{ 208{
203 usb_kill_urb(dev->int_urb); 209 usb_kill_urb(dev->int_urb);
204 usb_free_urb(dev->int_urb); 210 usb_free_urb(dev->int_urb);
211 kfree(dev->status);
205 uvc_input_cleanup(dev); 212 uvc_input_cleanup(dev);
206} 213}
207 214
diff --git a/drivers/media/video/uvc/uvc_v4l2.c b/drivers/media/video/uvc/uvc_v4l2.c
index d7bd71be40a9..78e4c4e09d89 100644
--- a/drivers/media/video/uvc/uvc_v4l2.c
+++ b/drivers/media/video/uvc/uvc_v4l2.c
@@ -400,15 +400,13 @@ static int uvc_has_privileges(struct uvc_fh *handle)
400 400
401static int uvc_v4l2_open(struct inode *inode, struct file *file) 401static int uvc_v4l2_open(struct inode *inode, struct file *file)
402{ 402{
403 struct video_device *vdev;
404 struct uvc_video_device *video; 403 struct uvc_video_device *video;
405 struct uvc_fh *handle; 404 struct uvc_fh *handle;
406 int ret = 0; 405 int ret = 0;
407 406
408 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n"); 407 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n");
409 mutex_lock(&uvc_driver.open_mutex); 408 mutex_lock(&uvc_driver.open_mutex);
410 vdev = video_devdata(file); 409 video = video_drvdata(file);
411 video = video_get_drvdata(vdev);
412 410
413 if (video->dev->state & UVC_DEV_DISCONNECTED) { 411 if (video->dev->state & UVC_DEV_DISCONNECTED) {
414 ret = -ENODEV; 412 ret = -ENODEV;
@@ -440,8 +438,7 @@ done:
440 438
441static int uvc_v4l2_release(struct inode *inode, struct file *file) 439static int uvc_v4l2_release(struct inode *inode, struct file *file)
442{ 440{
443 struct video_device *vdev = video_devdata(file); 441 struct uvc_video_device *video = video_drvdata(file);
444 struct uvc_video_device *video = video_get_drvdata(vdev);
445 struct uvc_fh *handle = (struct uvc_fh *)file->private_data; 442 struct uvc_fh *handle = (struct uvc_fh *)file->private_data;
446 443
447 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_release\n"); 444 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_release\n");
@@ -845,10 +842,6 @@ static int uvc_v4l2_do_ioctl(struct inode *inode, struct file *file,
845 if (ret < 0) 842 if (ret < 0)
846 return ret; 843 return ret;
847 844
848 if (!(video->streaming->cur_format->flags &
849 UVC_FMT_FLAG_COMPRESSED))
850 video->queue.flags |= UVC_QUEUE_DROP_INCOMPLETE;
851
852 rb->count = ret; 845 rb->count = ret;
853 ret = 0; 846 ret = 0;
854 break; 847 break;
@@ -1031,8 +1024,7 @@ static struct vm_operations_struct uvc_vm_ops = {
1031 1024
1032static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma) 1025static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
1033{ 1026{
1034 struct video_device *vdev = video_devdata(file); 1027 struct uvc_video_device *video = video_drvdata(file);
1035 struct uvc_video_device *video = video_get_drvdata(vdev);
1036 struct uvc_buffer *uninitialized_var(buffer); 1028 struct uvc_buffer *uninitialized_var(buffer);
1037 struct page *page; 1029 struct page *page;
1038 unsigned long addr, start, size; 1030 unsigned long addr, start, size;
@@ -1085,8 +1077,7 @@ done:
1085 1077
1086static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait) 1078static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait)
1087{ 1079{
1088 struct video_device *vdev = video_devdata(file); 1080 struct uvc_video_device *video = video_drvdata(file);
1089 struct uvc_video_device *video = video_get_drvdata(vdev);
1090 1081
1091 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_poll\n"); 1082 uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_poll\n");
1092 1083
diff --git a/drivers/media/video/uvc/uvc_video.c b/drivers/media/video/uvc/uvc_video.c
index 6854ac78a161..b7bb23820d80 100644
--- a/drivers/media/video/uvc/uvc_video.c
+++ b/drivers/media/video/uvc/uvc_video.c
@@ -455,7 +455,8 @@ static void uvc_video_decode_isoc(struct urb *urb,
455 urb->iso_frame_desc[i].actual_length - ret); 455 urb->iso_frame_desc[i].actual_length - ret);
456 456
457 /* Process the header again. */ 457 /* Process the header again. */
458 uvc_video_decode_end(video, buf, mem, ret); 458 uvc_video_decode_end(video, buf, mem,
459 urb->iso_frame_desc[i].actual_length);
459 460
460 if (buf->state == UVC_BUF_STATE_DONE || 461 if (buf->state == UVC_BUF_STATE_DONE ||
461 buf->state == UVC_BUF_STATE_ERROR) 462 buf->state == UVC_BUF_STATE_ERROR)
@@ -512,7 +513,7 @@ static void uvc_video_decode_bulk(struct urb *urb,
512 video->bulk.payload_size >= video->bulk.max_payload_size) { 513 video->bulk.payload_size >= video->bulk.max_payload_size) {
513 if (!video->bulk.skip_payload && buf != NULL) { 514 if (!video->bulk.skip_payload && buf != NULL) {
514 uvc_video_decode_end(video, buf, video->bulk.header, 515 uvc_video_decode_end(video, buf, video->bulk.header,
515 video->bulk.header_size); 516 video->bulk.payload_size);
516 if (buf->state == UVC_BUF_STATE_DONE || 517 if (buf->state == UVC_BUF_STATE_DONE ||
517 buf->state == UVC_BUF_STATE_ERROR) 518 buf->state == UVC_BUF_STATE_ERROR)
518 buf = uvc_queue_next_buffer(&video->queue, buf); 519 buf = uvc_queue_next_buffer(&video->queue, buf);
@@ -655,7 +656,7 @@ static int uvc_init_video_isoc(struct uvc_video_device *video,
655 if (size > UVC_MAX_FRAME_SIZE) 656 if (size > UVC_MAX_FRAME_SIZE)
656 return -EINVAL; 657 return -EINVAL;
657 658
658 npackets = (size + psize - 1) / psize; 659 npackets = DIV_ROUND_UP(size, psize);
659 if (npackets > UVC_MAX_ISO_PACKETS) 660 if (npackets > UVC_MAX_ISO_PACKETS)
660 npackets = UVC_MAX_ISO_PACKETS; 661 npackets = UVC_MAX_ISO_PACKETS;
661 662
@@ -970,6 +971,11 @@ int uvc_video_enable(struct uvc_video_device *video, int enable)
970 return 0; 971 return 0;
971 } 972 }
972 973
974 if (video->streaming->cur_format->flags & UVC_FMT_FLAG_COMPRESSED)
975 video->queue.flags &= ~UVC_QUEUE_DROP_INCOMPLETE;
976 else
977 video->queue.flags |= UVC_QUEUE_DROP_INCOMPLETE;
978
973 if ((ret = uvc_queue_enable(&video->queue, 1)) < 0) 979 if ((ret = uvc_queue_enable(&video->queue, 1)) < 0)
974 return ret; 980 return ret;
975 981
diff --git a/drivers/media/video/uvc/uvcvideo.h b/drivers/media/video/uvc/uvcvideo.h
index bafe3406e305..9a6bc1aafb16 100644
--- a/drivers/media/video/uvc/uvcvideo.h
+++ b/drivers/media/video/uvc/uvcvideo.h
@@ -303,6 +303,8 @@ struct uvc_xu_control {
303#define UVC_MAX_FRAME_SIZE (16*1024*1024) 303#define UVC_MAX_FRAME_SIZE (16*1024*1024)
304/* Maximum number of video buffers. */ 304/* Maximum number of video buffers. */
305#define UVC_MAX_VIDEO_BUFFERS 32 305#define UVC_MAX_VIDEO_BUFFERS 32
306/* Maximum status buffer size in bytes of interrupt URB. */
307#define UVC_MAX_STATUS_SIZE 16
306 308
307#define UVC_CTRL_CONTROL_TIMEOUT 300 309#define UVC_CTRL_CONTROL_TIMEOUT 300
308#define UVC_CTRL_STREAMING_TIMEOUT 1000 310#define UVC_CTRL_STREAMING_TIMEOUT 1000
@@ -634,7 +636,7 @@ struct uvc_device {
634 /* Status Interrupt Endpoint */ 636 /* Status Interrupt Endpoint */
635 struct usb_host_endpoint *int_ep; 637 struct usb_host_endpoint *int_ep;
636 struct urb *int_urb; 638 struct urb *int_urb;
637 __u8 status[16]; 639 __u8 *status;
638 struct input_dev *input; 640 struct input_dev *input;
639 641
640 /* Video Streaming interfaces */ 642 /* Video Streaming interfaces */
diff --git a/drivers/media/video/v4l1-compat.c b/drivers/media/video/v4l1-compat.c
index 79937d1031fc..928cb4037372 100644
--- a/drivers/media/video/v4l1-compat.c
+++ b/drivers/media/video/v4l1-compat.c
@@ -36,10 +36,6 @@
36#include <asm/system.h> 36#include <asm/system.h>
37#include <asm/pgtable.h> 37#include <asm/pgtable.h>
38 38
39#ifdef CONFIG_KMOD
40#include <linux/kmod.h>
41#endif
42
43static unsigned int debug; 39static unsigned int debug;
44module_param(debug, int, 0644); 40module_param(debug, int, 0644);
45MODULE_PARM_DESC(debug, "enable debug messages"); 41MODULE_PARM_DESC(debug, "enable debug messages");
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index 88ca13104417..846763d7349e 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -60,10 +60,6 @@
60#include <media/v4l2-common.h> 60#include <media/v4l2-common.h>
61#include <media/v4l2-chip-ident.h> 61#include <media/v4l2-chip-ident.h>
62 62
63#ifdef CONFIG_KMOD
64#include <linux/kmod.h>
65#endif
66
67#include <linux/videodev2.h> 63#include <linux/videodev2.h>
68 64
69MODULE_AUTHOR("Bill Dirks, Justin Schoeman, Gerd Knorr"); 65MODULE_AUTHOR("Bill Dirks, Justin Schoeman, Gerd Knorr");
@@ -187,9 +183,11 @@ const char **v4l2_ctrl_get_menu(u32 id)
187 NULL 183 NULL
188 }; 184 };
189 static const char *mpeg_audio_encoding[] = { 185 static const char *mpeg_audio_encoding[] = {
190 "Layer I", 186 "MPEG-1/2 Layer I",
191 "Layer II", 187 "MPEG-1/2 Layer II",
192 "Layer III", 188 "MPEG-1/2 Layer III",
189 "MPEG-2/4 AAC",
190 "AC-3",
193 NULL 191 NULL
194 }; 192 };
195 static const char *mpeg_audio_l1_bitrate[] = { 193 static const char *mpeg_audio_l1_bitrate[] = {
@@ -243,6 +241,28 @@ const char **v4l2_ctrl_get_menu(u32 id)
243 "320 kbps", 241 "320 kbps",
244 NULL 242 NULL
245 }; 243 };
244 static const char *mpeg_audio_ac3_bitrate[] = {
245 "32 kbps",
246 "40 kbps",
247 "48 kbps",
248 "56 kbps",
249 "64 kbps",
250 "80 kbps",
251 "96 kbps",
252 "112 kbps",
253 "128 kbps",
254 "160 kbps",
255 "192 kbps",
256 "224 kbps",
257 "256 kbps",
258 "320 kbps",
259 "384 kbps",
260 "448 kbps",
261 "512 kbps",
262 "576 kbps",
263 "640 kbps",
264 NULL
265 };
246 static const char *mpeg_audio_mode[] = { 266 static const char *mpeg_audio_mode[] = {
247 "Stereo", 267 "Stereo",
248 "Joint Stereo", 268 "Joint Stereo",
@@ -271,6 +291,7 @@ const char **v4l2_ctrl_get_menu(u32 id)
271 static const char *mpeg_video_encoding[] = { 291 static const char *mpeg_video_encoding[] = {
272 "MPEG-1", 292 "MPEG-1",
273 "MPEG-2", 293 "MPEG-2",
294 "MPEG-4 AVC",
274 NULL 295 NULL
275 }; 296 };
276 static const char *mpeg_video_aspect[] = { 297 static const char *mpeg_video_aspect[] = {
@@ -311,6 +332,8 @@ const char **v4l2_ctrl_get_menu(u32 id)
311 return mpeg_audio_l2_bitrate; 332 return mpeg_audio_l2_bitrate;
312 case V4L2_CID_MPEG_AUDIO_L3_BITRATE: 333 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
313 return mpeg_audio_l3_bitrate; 334 return mpeg_audio_l3_bitrate;
335 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
336 return mpeg_audio_ac3_bitrate;
314 case V4L2_CID_MPEG_AUDIO_MODE: 337 case V4L2_CID_MPEG_AUDIO_MODE:
315 return mpeg_audio_mode; 338 return mpeg_audio_mode;
316 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: 339 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
@@ -335,62 +358,73 @@ const char **v4l2_ctrl_get_menu(u32 id)
335} 358}
336EXPORT_SYMBOL(v4l2_ctrl_get_menu); 359EXPORT_SYMBOL(v4l2_ctrl_get_menu);
337 360
338/* Fill in a struct v4l2_queryctrl */ 361/* Return the control name. */
339int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def) 362const char *v4l2_ctrl_get_name(u32 id)
340{ 363{
341 const char *name; 364 switch (id) {
342
343 qctrl->flags = 0;
344 switch (qctrl->id) {
345 /* USER controls */ 365 /* USER controls */
346 case V4L2_CID_USER_CLASS: name = "User Controls"; break; 366 case V4L2_CID_USER_CLASS: return "User Controls";
347 case V4L2_CID_AUDIO_VOLUME: name = "Volume"; break; 367 case V4L2_CID_AUDIO_VOLUME: return "Volume";
348 case V4L2_CID_AUDIO_MUTE: name = "Mute"; break; 368 case V4L2_CID_AUDIO_MUTE: return "Mute";
349 case V4L2_CID_AUDIO_BALANCE: name = "Balance"; break; 369 case V4L2_CID_AUDIO_BALANCE: return "Balance";
350 case V4L2_CID_AUDIO_BASS: name = "Bass"; break; 370 case V4L2_CID_AUDIO_BASS: return "Bass";
351 case V4L2_CID_AUDIO_TREBLE: name = "Treble"; break; 371 case V4L2_CID_AUDIO_TREBLE: return "Treble";
352 case V4L2_CID_AUDIO_LOUDNESS: name = "Loudness"; break; 372 case V4L2_CID_AUDIO_LOUDNESS: return "Loudness";
353 case V4L2_CID_BRIGHTNESS: name = "Brightness"; break; 373 case V4L2_CID_BRIGHTNESS: return "Brightness";
354 case V4L2_CID_CONTRAST: name = "Contrast"; break; 374 case V4L2_CID_CONTRAST: return "Contrast";
355 case V4L2_CID_SATURATION: name = "Saturation"; break; 375 case V4L2_CID_SATURATION: return "Saturation";
356 case V4L2_CID_HUE: name = "Hue"; break; 376 case V4L2_CID_HUE: return "Hue";
357 377
358 /* MPEG controls */ 378 /* MPEG controls */
359 case V4L2_CID_MPEG_CLASS: name = "MPEG Encoder Controls"; break; 379 case V4L2_CID_MPEG_CLASS: return "MPEG Encoder Controls";
360 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: name = "Audio Sampling Frequency"; break; 380 case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: return "Audio Sampling Frequency";
361 case V4L2_CID_MPEG_AUDIO_ENCODING: name = "Audio Encoding Layer"; break; 381 case V4L2_CID_MPEG_AUDIO_ENCODING: return "Audio Encoding";
362 case V4L2_CID_MPEG_AUDIO_L1_BITRATE: name = "Audio Layer I Bitrate"; break; 382 case V4L2_CID_MPEG_AUDIO_L1_BITRATE: return "Audio Layer I Bitrate";
363 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: name = "Audio Layer II Bitrate"; break; 383 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: return "Audio Layer II Bitrate";
364 case V4L2_CID_MPEG_AUDIO_L3_BITRATE: name = "Audio Layer III Bitrate"; break; 384 case V4L2_CID_MPEG_AUDIO_L3_BITRATE: return "Audio Layer III Bitrate";
365 case V4L2_CID_MPEG_AUDIO_MODE: name = "Audio Stereo Mode"; break; 385 case V4L2_CID_MPEG_AUDIO_AAC_BITRATE: return "Audio AAC Bitrate";
366 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: name = "Audio Stereo Mode Extension"; break; 386 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE: return "Audio AC-3 Bitrate";
367 case V4L2_CID_MPEG_AUDIO_EMPHASIS: name = "Audio Emphasis"; break; 387 case V4L2_CID_MPEG_AUDIO_MODE: return "Audio Stereo Mode";
368 case V4L2_CID_MPEG_AUDIO_CRC: name = "Audio CRC"; break; 388 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: return "Audio Stereo Mode Extension";
369 case V4L2_CID_MPEG_AUDIO_MUTE: name = "Audio Mute"; break; 389 case V4L2_CID_MPEG_AUDIO_EMPHASIS: return "Audio Emphasis";
370 case V4L2_CID_MPEG_VIDEO_ENCODING: name = "Video Encoding"; break; 390 case V4L2_CID_MPEG_AUDIO_CRC: return "Audio CRC";
371 case V4L2_CID_MPEG_VIDEO_ASPECT: name = "Video Aspect"; break; 391 case V4L2_CID_MPEG_AUDIO_MUTE: return "Audio Mute";
372 case V4L2_CID_MPEG_VIDEO_B_FRAMES: name = "Video B Frames"; break; 392 case V4L2_CID_MPEG_VIDEO_ENCODING: return "Video Encoding";
373 case V4L2_CID_MPEG_VIDEO_GOP_SIZE: name = "Video GOP Size"; break; 393 case V4L2_CID_MPEG_VIDEO_ASPECT: return "Video Aspect";
374 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: name = "Video GOP Closure"; break; 394 case V4L2_CID_MPEG_VIDEO_B_FRAMES: return "Video B Frames";
375 case V4L2_CID_MPEG_VIDEO_PULLDOWN: name = "Video Pulldown"; break; 395 case V4L2_CID_MPEG_VIDEO_GOP_SIZE: return "Video GOP Size";
376 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: name = "Video Bitrate Mode"; break; 396 case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE: return "Video GOP Closure";
377 case V4L2_CID_MPEG_VIDEO_BITRATE: name = "Video Bitrate"; break; 397 case V4L2_CID_MPEG_VIDEO_PULLDOWN: return "Video Pulldown";
378 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: name = "Video Peak Bitrate"; break; 398 case V4L2_CID_MPEG_VIDEO_BITRATE_MODE: return "Video Bitrate Mode";
379 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: name = "Video Temporal Decimation"; break; 399 case V4L2_CID_MPEG_VIDEO_BITRATE: return "Video Bitrate";
380 case V4L2_CID_MPEG_VIDEO_MUTE: name = "Video Mute"; break; 400 case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK: return "Video Peak Bitrate";
381 case V4L2_CID_MPEG_VIDEO_MUTE_YUV: name = "Video Mute YUV"; break; 401 case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation";
382 case V4L2_CID_MPEG_STREAM_TYPE: name = "Stream Type"; break; 402 case V4L2_CID_MPEG_VIDEO_MUTE: return "Video Mute";
383 case V4L2_CID_MPEG_STREAM_PID_PMT: name = "Stream PMT Program ID"; break; 403 case V4L2_CID_MPEG_VIDEO_MUTE_YUV: return "Video Mute YUV";
384 case V4L2_CID_MPEG_STREAM_PID_AUDIO: name = "Stream Audio Program ID"; break; 404 case V4L2_CID_MPEG_STREAM_TYPE: return "Stream Type";
385 case V4L2_CID_MPEG_STREAM_PID_VIDEO: name = "Stream Video Program ID"; break; 405 case V4L2_CID_MPEG_STREAM_PID_PMT: return "Stream PMT Program ID";
386 case V4L2_CID_MPEG_STREAM_PID_PCR: name = "Stream PCR Program ID"; break; 406 case V4L2_CID_MPEG_STREAM_PID_AUDIO: return "Stream Audio Program ID";
387 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: name = "Stream PES Audio ID"; break; 407 case V4L2_CID_MPEG_STREAM_PID_VIDEO: return "Stream Video Program ID";
388 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: name = "Stream PES Video ID"; break; 408 case V4L2_CID_MPEG_STREAM_PID_PCR: return "Stream PCR Program ID";
389 case V4L2_CID_MPEG_STREAM_VBI_FMT: name = "Stream VBI Format"; break; 409 case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: return "Stream PES Audio ID";
410 case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: return "Stream PES Video ID";
411 case V4L2_CID_MPEG_STREAM_VBI_FMT: return "Stream VBI Format";
390 412
391 default: 413 default:
392 return -EINVAL; 414 return NULL;
393 } 415 }
416}
417EXPORT_SYMBOL(v4l2_ctrl_get_name);
418
419/* Fill in a struct v4l2_queryctrl */
420int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def)
421{
422 const char *name = v4l2_ctrl_get_name(qctrl->id);
423
424 qctrl->flags = 0;
425 if (name == NULL)
426 return -EINVAL;
427
394 switch (qctrl->id) { 428 switch (qctrl->id) {
395 case V4L2_CID_AUDIO_MUTE: 429 case V4L2_CID_AUDIO_MUTE:
396 case V4L2_CID_AUDIO_LOUDNESS: 430 case V4L2_CID_AUDIO_LOUDNESS:
@@ -407,6 +441,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 ste
407 case V4L2_CID_MPEG_AUDIO_L1_BITRATE: 441 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
408 case V4L2_CID_MPEG_AUDIO_L2_BITRATE: 442 case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
409 case V4L2_CID_MPEG_AUDIO_L3_BITRATE: 443 case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
444 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
410 case V4L2_CID_MPEG_AUDIO_MODE: 445 case V4L2_CID_MPEG_AUDIO_MODE:
411 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: 446 case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
412 case V4L2_CID_MPEG_AUDIO_EMPHASIS: 447 case V4L2_CID_MPEG_AUDIO_EMPHASIS:
@@ -493,7 +528,7 @@ int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl)
493 case V4L2_CID_MPEG_AUDIO_ENCODING: 528 case V4L2_CID_MPEG_AUDIO_ENCODING:
494 return v4l2_ctrl_query_fill(qctrl, 529 return v4l2_ctrl_query_fill(qctrl,
495 V4L2_MPEG_AUDIO_ENCODING_LAYER_1, 530 V4L2_MPEG_AUDIO_ENCODING_LAYER_1,
496 V4L2_MPEG_AUDIO_ENCODING_LAYER_3, 1, 531 V4L2_MPEG_AUDIO_ENCODING_AC3, 1,
497 V4L2_MPEG_AUDIO_ENCODING_LAYER_2); 532 V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
498 case V4L2_CID_MPEG_AUDIO_L1_BITRATE: 533 case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
499 return v4l2_ctrl_query_fill(qctrl, 534 return v4l2_ctrl_query_fill(qctrl,
@@ -510,6 +545,13 @@ int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl)
510 V4L2_MPEG_AUDIO_L3_BITRATE_32K, 545 V4L2_MPEG_AUDIO_L3_BITRATE_32K,
511 V4L2_MPEG_AUDIO_L3_BITRATE_320K, 1, 546 V4L2_MPEG_AUDIO_L3_BITRATE_320K, 1,
512 V4L2_MPEG_AUDIO_L3_BITRATE_192K); 547 V4L2_MPEG_AUDIO_L3_BITRATE_192K);
548 case V4L2_CID_MPEG_AUDIO_AAC_BITRATE:
549 return v4l2_ctrl_query_fill(qctrl, 0, 6400, 1, 3200000);
550 case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
551 return v4l2_ctrl_query_fill(qctrl,
552 V4L2_MPEG_AUDIO_AC3_BITRATE_32K,
553 V4L2_MPEG_AUDIO_AC3_BITRATE_640K, 1,
554 V4L2_MPEG_AUDIO_AC3_BITRATE_384K);
513 case V4L2_CID_MPEG_AUDIO_MODE: 555 case V4L2_CID_MPEG_AUDIO_MODE:
514 return v4l2_ctrl_query_fill(qctrl, 556 return v4l2_ctrl_query_fill(qctrl,
515 V4L2_MPEG_AUDIO_MODE_STEREO, 557 V4L2_MPEG_AUDIO_MODE_STEREO,
@@ -535,7 +577,7 @@ int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl)
535 case V4L2_CID_MPEG_VIDEO_ENCODING: 577 case V4L2_CID_MPEG_VIDEO_ENCODING:
536 return v4l2_ctrl_query_fill(qctrl, 578 return v4l2_ctrl_query_fill(qctrl,
537 V4L2_MPEG_VIDEO_ENCODING_MPEG_1, 579 V4L2_MPEG_VIDEO_ENCODING_MPEG_1,
538 V4L2_MPEG_VIDEO_ENCODING_MPEG_2, 1, 580 V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC, 1,
539 V4L2_MPEG_VIDEO_ENCODING_MPEG_2); 581 V4L2_MPEG_VIDEO_ENCODING_MPEG_2);
540 case V4L2_CID_MPEG_VIDEO_ASPECT: 582 case V4L2_CID_MPEG_VIDEO_ASPECT:
541 return v4l2_ctrl_query_fill(qctrl, 583 return v4l2_ctrl_query_fill(qctrl,
@@ -594,12 +636,17 @@ int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl)
594EXPORT_SYMBOL(v4l2_ctrl_query_fill_std); 636EXPORT_SYMBOL(v4l2_ctrl_query_fill_std);
595 637
596/* Fill in a struct v4l2_querymenu based on the struct v4l2_queryctrl and 638/* Fill in a struct v4l2_querymenu based on the struct v4l2_queryctrl and
597 the menu. The qctrl pointer may be NULL, in which case it is ignored. */ 639 the menu. The qctrl pointer may be NULL, in which case it is ignored.
640 If menu_items is NULL, then the menu items are retrieved using
641 v4l2_ctrl_get_menu. */
598int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qctrl, 642int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qctrl,
599 const char **menu_items) 643 const char **menu_items)
600{ 644{
601 int i; 645 int i;
602 646
647 qmenu->reserved = 0;
648 if (menu_items == NULL)
649 menu_items = v4l2_ctrl_get_menu(qmenu->id);
603 if (menu_items == NULL || 650 if (menu_items == NULL ||
604 (qctrl && (qmenu->index < qctrl->minimum || qmenu->index > qctrl->maximum))) 651 (qctrl && (qmenu->index < qctrl->minimum || qmenu->index > qctrl->maximum)))
605 return -EINVAL; 652 return -EINVAL;
@@ -607,11 +654,31 @@ int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qc
607 if (menu_items[i] == NULL || menu_items[i][0] == '\0') 654 if (menu_items[i] == NULL || menu_items[i][0] == '\0')
608 return -EINVAL; 655 return -EINVAL;
609 snprintf(qmenu->name, sizeof(qmenu->name), menu_items[qmenu->index]); 656 snprintf(qmenu->name, sizeof(qmenu->name), menu_items[qmenu->index]);
610 qmenu->reserved = 0;
611 return 0; 657 return 0;
612} 658}
613EXPORT_SYMBOL(v4l2_ctrl_query_menu); 659EXPORT_SYMBOL(v4l2_ctrl_query_menu);
614 660
661/* Fill in a struct v4l2_querymenu based on the specified array of valid
662 menu items (terminated by V4L2_CTRL_MENU_IDS_END).
663 Use this if there are 'holes' in the list of valid menu items. */
664int v4l2_ctrl_query_menu_valid_items(struct v4l2_querymenu *qmenu, const u32 *ids)
665{
666 const char **menu_items = v4l2_ctrl_get_menu(qmenu->id);
667
668 qmenu->reserved = 0;
669 if (menu_items == NULL || ids == NULL)
670 return -EINVAL;
671 while (*ids != V4L2_CTRL_MENU_IDS_END) {
672 if (*ids++ == qmenu->index) {
673 snprintf(qmenu->name, sizeof(qmenu->name),
674 menu_items[qmenu->index]);
675 return 0;
676 }
677 }
678 return -EINVAL;
679}
680EXPORT_SYMBOL(v4l2_ctrl_query_menu_valid_items);
681
615/* ctrl_classes points to an array of u32 pointers, the last element is 682/* ctrl_classes points to an array of u32 pointers, the last element is
616 a NULL pointer. Each u32 array is a 0-terminated array of control IDs. 683 a NULL pointer. Each u32 array is a 0-terminated array of control IDs.
617 Each array must be sorted low to high and belong to the same control 684 Each array must be sorted low to high and belong to the same control
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
index 155fdec9ac7d..ccd6566a515e 100644
--- a/drivers/media/video/v4l2-dev.c
+++ b/drivers/media/video/v4l2-dev.c
@@ -42,6 +42,7 @@ static ssize_t show_index(struct device *cd,
42 struct device_attribute *attr, char *buf) 42 struct device_attribute *attr, char *buf)
43{ 43{
44 struct video_device *vfd = container_of(cd, struct video_device, dev); 44 struct video_device *vfd = container_of(cd, struct video_device, dev);
45
45 return sprintf(buf, "%i\n", vfd->index); 46 return sprintf(buf, "%i\n", vfd->index);
46} 47}
47 48
@@ -49,6 +50,7 @@ static ssize_t show_name(struct device *cd,
49 struct device_attribute *attr, char *buf) 50 struct device_attribute *attr, char *buf)
50{ 51{
51 struct video_device *vfd = container_of(cd, struct video_device, dev); 52 struct video_device *vfd = container_of(cd, struct video_device, dev);
53
52 return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name); 54 return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name);
53} 55}
54 56
@@ -58,12 +60,16 @@ static struct device_attribute video_device_attrs[] = {
58 __ATTR_NULL 60 __ATTR_NULL
59}; 61};
60 62
63/*
64 * Active devices
65 */
66static struct video_device *video_device[VIDEO_NUM_DEVICES];
67static DEFINE_MUTEX(videodev_lock);
68static DECLARE_BITMAP(video_nums[VFL_TYPE_MAX], VIDEO_NUM_DEVICES);
69
61struct video_device *video_device_alloc(void) 70struct video_device *video_device_alloc(void)
62{ 71{
63 struct video_device *vfd; 72 return kzalloc(sizeof(struct video_device), GFP_KERNEL);
64
65 vfd = kzalloc(sizeof(*vfd), GFP_KERNEL);
66 return vfd;
67} 73}
68EXPORT_SYMBOL(video_device_alloc); 74EXPORT_SYMBOL(video_device_alloc);
69 75
@@ -73,16 +79,52 @@ void video_device_release(struct video_device *vfd)
73} 79}
74EXPORT_SYMBOL(video_device_release); 80EXPORT_SYMBOL(video_device_release);
75 81
82void video_device_release_empty(struct video_device *vfd)
83{
84 /* Do nothing */
85 /* Only valid when the video_device struct is a static. */
86}
87EXPORT_SYMBOL(video_device_release_empty);
88
89/* Called when the last user of the character device is gone. */
90static void v4l2_chardev_release(struct kobject *kobj)
91{
92 struct video_device *vfd = container_of(kobj, struct video_device, cdev.kobj);
93
94 mutex_lock(&videodev_lock);
95 if (video_device[vfd->minor] != vfd) {
96 mutex_unlock(&videodev_lock);
97 BUG();
98 return;
99 }
100
101 /* Free up this device for reuse */
102 video_device[vfd->minor] = NULL;
103 clear_bit(vfd->num, video_nums[vfd->vfl_type]);
104 mutex_unlock(&videodev_lock);
105
106 /* Release the character device */
107 vfd->cdev_release(kobj);
108 /* Release video_device and perform other
109 cleanups as needed. */
110 if (vfd->release)
111 vfd->release(vfd);
112}
113
114/* The new kobj_type for the character device */
115static struct kobj_type v4l2_ktype_cdev_default = {
116 .release = v4l2_chardev_release,
117};
118
76static void video_release(struct device *cd) 119static void video_release(struct device *cd)
77{ 120{
78 struct video_device *vfd = container_of(cd, struct video_device, dev); 121 struct video_device *vfd = container_of(cd, struct video_device, dev);
79 122
80#if 1 123 /* It's now safe to delete the char device.
81 /* needed until all drivers are fixed */ 124 This will either trigger the v4l2_chardev_release immediately (if
82 if (!vfd->release) 125 the refcount goes to 0) or later when the last user of the
83 return; 126 character device closes it. */
84#endif 127 cdev_del(&vfd->cdev);
85 vfd->release(vfd);
86} 128}
87 129
88static struct class video_class = { 130static struct class video_class = {
@@ -91,87 +133,12 @@ static struct class video_class = {
91 .dev_release = video_release, 133 .dev_release = video_release,
92}; 134};
93 135
94/*
95 * Active devices
96 */
97
98static struct video_device *video_device[VIDEO_NUM_DEVICES];
99static DEFINE_MUTEX(videodev_lock);
100
101struct video_device *video_devdata(struct file *file) 136struct video_device *video_devdata(struct file *file)
102{ 137{
103 return video_device[iminor(file->f_path.dentry->d_inode)]; 138 return video_device[iminor(file->f_path.dentry->d_inode)];
104} 139}
105EXPORT_SYMBOL(video_devdata); 140EXPORT_SYMBOL(video_devdata);
106 141
107/*
108 * Open a video device - FIXME: Obsoleted
109 */
110static int video_open(struct inode *inode, struct file *file)
111{
112 unsigned int minor = iminor(inode);
113 int err = 0;
114 struct video_device *vfl;
115 const struct file_operations *old_fops;
116
117 if (minor >= VIDEO_NUM_DEVICES)
118 return -ENODEV;
119 lock_kernel();
120 mutex_lock(&videodev_lock);
121 vfl = video_device[minor];
122 if (vfl == NULL) {
123 mutex_unlock(&videodev_lock);
124 request_module("char-major-%d-%d", VIDEO_MAJOR, minor);
125 mutex_lock(&videodev_lock);
126 vfl = video_device[minor];
127 if (vfl == NULL) {
128 mutex_unlock(&videodev_lock);
129 unlock_kernel();
130 return -ENODEV;
131 }
132 }
133 old_fops = file->f_op;
134 file->f_op = fops_get(vfl->fops);
135 if (file->f_op->open)
136 err = file->f_op->open(inode, file);
137 if (err) {
138 fops_put(file->f_op);
139 file->f_op = fops_get(old_fops);
140 }
141 fops_put(old_fops);
142 mutex_unlock(&videodev_lock);
143 unlock_kernel();
144 return err;
145}
146
147/*
148 * open/release helper functions -- handle exclusive opens
149 * Should be removed soon
150 */
151int video_exclusive_open(struct inode *inode, struct file *file)
152{
153 struct video_device *vfl = video_devdata(file);
154 int retval = 0;
155
156 mutex_lock(&vfl->lock);
157 if (vfl->users)
158 retval = -EBUSY;
159 else
160 vfl->users++;
161 mutex_unlock(&vfl->lock);
162 return retval;
163}
164EXPORT_SYMBOL(video_exclusive_open);
165
166int video_exclusive_release(struct inode *inode, struct file *file)
167{
168 struct video_device *vfl = video_devdata(file);
169
170 vfl->users--;
171 return 0;
172}
173EXPORT_SYMBOL(video_exclusive_release);
174
175/** 142/**
176 * get_index - assign stream number based on parent device 143 * get_index - assign stream number based on parent device
177 * @vdev: video_device to assign index number to, vdev->dev should be assigned 144 * @vdev: video_device to assign index number to, vdev->dev should be assigned
@@ -252,33 +219,29 @@ int video_register_device_index(struct video_device *vfd, int type, int nr,
252 int index) 219 int index)
253{ 220{
254 int i = 0; 221 int i = 0;
255 int base;
256 int end;
257 int ret; 222 int ret;
258 char *name_base; 223 int minor_offset = 0;
224 int minor_cnt = VIDEO_NUM_DEVICES;
225 const char *name_base;
226 void *priv = video_get_drvdata(vfd);
227
228 /* the release callback MUST be present */
229 BUG_ON(!vfd->release);
259 230
260 if (vfd == NULL) 231 if (vfd == NULL)
261 return -EINVAL; 232 return -EINVAL;
262 233
263 switch (type) { 234 switch (type) {
264 case VFL_TYPE_GRABBER: 235 case VFL_TYPE_GRABBER:
265 base = MINOR_VFL_TYPE_GRABBER_MIN;
266 end = MINOR_VFL_TYPE_GRABBER_MAX+1;
267 name_base = "video"; 236 name_base = "video";
268 break; 237 break;
269 case VFL_TYPE_VTX: 238 case VFL_TYPE_VTX:
270 base = MINOR_VFL_TYPE_VTX_MIN;
271 end = MINOR_VFL_TYPE_VTX_MAX+1;
272 name_base = "vtx"; 239 name_base = "vtx";
273 break; 240 break;
274 case VFL_TYPE_VBI: 241 case VFL_TYPE_VBI:
275 base = MINOR_VFL_TYPE_VBI_MIN;
276 end = MINOR_VFL_TYPE_VBI_MAX+1;
277 name_base = "vbi"; 242 name_base = "vbi";
278 break; 243 break;
279 case VFL_TYPE_RADIO: 244 case VFL_TYPE_RADIO:
280 base = MINOR_VFL_TYPE_RADIO_MIN;
281 end = MINOR_VFL_TYPE_RADIO_MAX+1;
282 name_base = "radio"; 245 name_base = "radio";
283 break; 246 break;
284 default: 247 default:
@@ -287,28 +250,70 @@ int video_register_device_index(struct video_device *vfd, int type, int nr,
287 return -EINVAL; 250 return -EINVAL;
288 } 251 }
289 252
253 vfd->vfl_type = type;
254
255#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
256 /* Keep the ranges for the first four types for historical
257 * reasons.
258 * Newer devices (not yet in place) should use the range
259 * of 128-191 and just pick the first free minor there
260 * (new style). */
261 switch (type) {
262 case VFL_TYPE_GRABBER:
263 minor_offset = 0;
264 minor_cnt = 64;
265 break;
266 case VFL_TYPE_RADIO:
267 minor_offset = 64;
268 minor_cnt = 64;
269 break;
270 case VFL_TYPE_VTX:
271 minor_offset = 192;
272 minor_cnt = 32;
273 break;
274 case VFL_TYPE_VBI:
275 minor_offset = 224;
276 minor_cnt = 32;
277 break;
278 default:
279 minor_offset = 128;
280 minor_cnt = 64;
281 break;
282 }
283#endif
284
285 /* Initialize the character device */
286 cdev_init(&vfd->cdev, vfd->fops);
287 vfd->cdev.owner = vfd->fops->owner;
290 /* pick a minor number */ 288 /* pick a minor number */
291 mutex_lock(&videodev_lock); 289 mutex_lock(&videodev_lock);
292 if (nr >= 0 && nr < end-base) { 290 nr = find_next_zero_bit(video_nums[type], minor_cnt, nr == -1 ? 0 : nr);
293 /* use the one the driver asked for */ 291 if (nr == minor_cnt)
294 i = base + nr; 292 nr = find_first_zero_bit(video_nums[type], minor_cnt);
295 if (NULL != video_device[i]) { 293 if (nr == minor_cnt) {
296 mutex_unlock(&videodev_lock); 294 printk(KERN_ERR "could not get a free kernel number\n");
297 return -ENFILE; 295 mutex_unlock(&videodev_lock);
298 } 296 return -ENFILE;
299 } else {
300 /* use first free */
301 for (i = base; i < end; i++)
302 if (NULL == video_device[i])
303 break;
304 if (i == end) {
305 mutex_unlock(&videodev_lock);
306 return -ENFILE;
307 }
308 } 297 }
309 video_device[i] = vfd; 298#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
310 vfd->vfl_type = type; 299 /* 1-on-1 mapping of kernel number to minor number */
311 vfd->minor = i; 300 i = nr;
301#else
302 /* The kernel number and minor numbers are independent */
303 for (i = 0; i < VIDEO_NUM_DEVICES; i++)
304 if (video_device[i] == NULL)
305 break;
306 if (i == VIDEO_NUM_DEVICES) {
307 mutex_unlock(&videodev_lock);
308 printk(KERN_ERR "could not get a free minor\n");
309 return -ENFILE;
310 }
311#endif
312 vfd->minor = i + minor_offset;
313 vfd->num = nr;
314 set_bit(nr, video_nums[type]);
315 BUG_ON(video_device[vfd->minor]);
316 video_device[vfd->minor] = vfd;
312 317
313 ret = get_index(vfd, index); 318 ret = get_index(vfd, index);
314 vfd->index = ret; 319 vfd->index = ret;
@@ -320,35 +325,41 @@ int video_register_device_index(struct video_device *vfd, int type, int nr,
320 goto fail_minor; 325 goto fail_minor;
321 } 326 }
322 327
323 mutex_init(&vfd->lock); 328 ret = cdev_add(&vfd->cdev, MKDEV(VIDEO_MAJOR, vfd->minor), 1);
324 329 if (ret < 0) {
330 printk(KERN_ERR "%s: cdev_add failed\n", __func__);
331 goto fail_minor;
332 }
325 /* sysfs class */ 333 /* sysfs class */
326 memset(&vfd->dev, 0x00, sizeof(vfd->dev)); 334 memset(&vfd->dev, 0, sizeof(vfd->dev));
335 /* The memset above cleared the device's drvdata, so
336 put back the copy we made earlier. */
337 video_set_drvdata(vfd, priv);
327 vfd->dev.class = &video_class; 338 vfd->dev.class = &video_class;
328 vfd->dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor); 339 vfd->dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
329 if (vfd->parent) 340 if (vfd->parent)
330 vfd->dev.parent = vfd->parent; 341 vfd->dev.parent = vfd->parent;
331 sprintf(vfd->dev.bus_id, "%s%d", name_base, i - base); 342 sprintf(vfd->dev.bus_id, "%s%d", name_base, nr);
332 ret = device_register(&vfd->dev); 343 ret = device_register(&vfd->dev);
333 if (ret < 0) { 344 if (ret < 0) {
334 printk(KERN_ERR "%s: device_register failed\n", __func__); 345 printk(KERN_ERR "%s: device_register failed\n", __func__);
335 goto fail_minor; 346 goto del_cdev;
336 } 347 }
337 348 /* Remember the cdev's release function */
338#if 1 349 vfd->cdev_release = vfd->cdev.kobj.ktype->release;
339 /* needed until all drivers are fixed */ 350 /* Install our own */
340 if (!vfd->release) 351 vfd->cdev.kobj.ktype = &v4l2_ktype_cdev_default;
341 printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
342 "Please fix your driver for proper sysfs support, see "
343 "http://lwn.net/Articles/36850/\n", vfd->name);
344#endif
345 return 0; 352 return 0;
346 353
354del_cdev:
355 cdev_del(&vfd->cdev);
356
347fail_minor: 357fail_minor:
348 mutex_lock(&videodev_lock); 358 mutex_lock(&videodev_lock);
349 video_device[vfd->minor] = NULL; 359 video_device[vfd->minor] = NULL;
350 vfd->minor = -1; 360 clear_bit(vfd->num, video_nums[type]);
351 mutex_unlock(&videodev_lock); 361 mutex_unlock(&videodev_lock);
362 vfd->minor = -1;
352 return ret; 363 return ret;
353} 364}
354EXPORT_SYMBOL(video_register_device_index); 365EXPORT_SYMBOL(video_register_device_index);
@@ -363,42 +374,29 @@ EXPORT_SYMBOL(video_register_device_index);
363 374
364void video_unregister_device(struct video_device *vfd) 375void video_unregister_device(struct video_device *vfd)
365{ 376{
366 mutex_lock(&videodev_lock);
367 if (video_device[vfd->minor] != vfd)
368 panic("videodev: bad unregister");
369
370 video_device[vfd->minor] = NULL;
371 device_unregister(&vfd->dev); 377 device_unregister(&vfd->dev);
372 mutex_unlock(&videodev_lock);
373} 378}
374EXPORT_SYMBOL(video_unregister_device); 379EXPORT_SYMBOL(video_unregister_device);
375 380
376/* 381/*
377 * Video fs operations
378 */
379static const struct file_operations video_fops = {
380 .owner = THIS_MODULE,
381 .llseek = no_llseek,
382 .open = video_open,
383};
384
385/*
386 * Initialise video for linux 382 * Initialise video for linux
387 */ 383 */
388
389static int __init videodev_init(void) 384static int __init videodev_init(void)
390{ 385{
386 dev_t dev = MKDEV(VIDEO_MAJOR, 0);
391 int ret; 387 int ret;
392 388
393 printk(KERN_INFO "Linux video capture interface: v2.00\n"); 389 printk(KERN_INFO "Linux video capture interface: v2.00\n");
394 if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) { 390 ret = register_chrdev_region(dev, VIDEO_NUM_DEVICES, VIDEO_NAME);
395 printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR); 391 if (ret < 0) {
396 return -EIO; 392 printk(KERN_WARNING "videodev: unable to get major %d\n",
393 VIDEO_MAJOR);
394 return ret;
397 } 395 }
398 396
399 ret = class_register(&video_class); 397 ret = class_register(&video_class);
400 if (ret < 0) { 398 if (ret < 0) {
401 unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME); 399 unregister_chrdev_region(dev, VIDEO_NUM_DEVICES);
402 printk(KERN_WARNING "video_dev: class_register failed\n"); 400 printk(KERN_WARNING "video_dev: class_register failed\n");
403 return -EIO; 401 return -EIO;
404 } 402 }
@@ -408,8 +406,10 @@ static int __init videodev_init(void)
408 406
409static void __exit videodev_exit(void) 407static void __exit videodev_exit(void)
410{ 408{
409 dev_t dev = MKDEV(VIDEO_MAJOR, 0);
410
411 class_unregister(&video_class); 411 class_unregister(&video_class);
412 unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME); 412 unregister_chrdev_region(dev, VIDEO_NUM_DEVICES);
413} 413}
414 414
415module_init(videodev_init) 415module_init(videodev_init)
diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 140ef92c19c1..155c9d77a463 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -746,18 +746,6 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
746 ret = ops->vidioc_enum_fmt_vid_overlay(file, 746 ret = ops->vidioc_enum_fmt_vid_overlay(file,
747 fh, f); 747 fh, f);
748 break; 748 break;
749#if 1
750 /* V4L2_BUF_TYPE_VBI_CAPTURE should not support VIDIOC_ENUM_FMT
751 * according to the spec. The bttv and saa7134 drivers support
752 * it though, so just warn that this is deprecated and will be
753 * removed in the near future. */
754 case V4L2_BUF_TYPE_VBI_CAPTURE:
755 if (ops->vidioc_enum_fmt_vbi_cap) {
756 printk(KERN_WARNING "vidioc_enum_fmt_vbi_cap will be removed in 2.6.28!\n");
757 ret = ops->vidioc_enum_fmt_vbi_cap(file, fh, f);
758 }
759 break;
760#endif
761 case V4L2_BUF_TYPE_VIDEO_OUTPUT: 749 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
762 if (ops->vidioc_enum_fmt_vid_out) 750 if (ops->vidioc_enum_fmt_vid_out)
763 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f); 751 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index 1edda456fc64..1efc5f3462c6 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -30,16 +30,12 @@
30#include <linux/mm.h> 30#include <linux/mm.h>
31#include <linux/time.h> 31#include <linux/time.h>
32#include <linux/version.h> 32#include <linux/version.h>
33
34#ifdef CONFIG_KMOD
35#include <linux/kmod.h> 33#include <linux/kmod.h>
36#endif
37 34
38#include <linux/i2c.h> 35#include <linux/i2c.h>
39#include <linux/i2c-algo-sgi.h> 36#include <linux/i2c-algo-sgi.h>
40 37
41#include <linux/videodev2.h> 38#include <linux/videodev2.h>
42#include <media/v4l2-ioctl.h>
43#include <media/v4l2-common.h> 39#include <media/v4l2-common.h>
44#include <media/v4l2-ioctl.h> 40#include <media/v4l2-ioctl.h>
45#include <linux/video_decoder.h> 41#include <linux/video_decoder.h>
@@ -810,7 +806,7 @@ static void vino_free_buffer_with_count(struct vino_framebuffer *fb,
810 dprintk("vino_free_buffer_with_count(): count = %d\n", count); 806 dprintk("vino_free_buffer_with_count(): count = %d\n", count);
811 807
812 for (i = 0; i < count; i++) { 808 for (i = 0; i < count; i++) {
813 ClearPageReserved(virt_to_page(fb->desc_table.virtual[i])); 809 ClearPageReserved(virt_to_page((void *)fb->desc_table.virtual[i]));
814 dma_unmap_single(NULL, 810 dma_unmap_single(NULL,
815 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i], 811 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i],
816 PAGE_SIZE, DMA_FROM_DEVICE); 812 PAGE_SIZE, DMA_FROM_DEVICE);
@@ -888,7 +884,7 @@ static int vino_allocate_buffer(struct vino_framebuffer *fb,
888 dma_data_addr + VINO_PAGE_SIZE * j; 884 dma_data_addr + VINO_PAGE_SIZE * j;
889 } 885 }
890 886
891 SetPageReserved(virt_to_page(fb->desc_table.virtual[i])); 887 SetPageReserved(virt_to_page((void *)fb->desc_table.virtual[i]));
892 } 888 }
893 889
894 /* page_count needs to be set anyway, because the descriptor table has 890 /* page_count needs to be set anyway, because the descriptor table has
@@ -975,7 +971,7 @@ static int vino_prepare_user_buffer(struct vino_framebuffer *fb,
975 dma_data_addr + VINO_PAGE_SIZE * j; 971 dma_data_addr + VINO_PAGE_SIZE * j;
976 } 972 }
977 973
978 SetPageReserved(virt_to_page(fb->desc_table.virtual[i])); 974 SetPageReserved(virt_to_page((void *)fb->desc_table.virtual[i]));
979 } 975 }
980 976
981 /* page_count needs to be set anyway, because the descriptor table has 977 /* page_count needs to be set anyway, because the descriptor table has
@@ -4025,8 +4021,7 @@ out:
4025 4021
4026static int vino_open(struct inode *inode, struct file *file) 4022static int vino_open(struct inode *inode, struct file *file)
4027{ 4023{
4028 struct video_device *dev = video_devdata(file); 4024 struct vino_channel_settings *vcs = video_drvdata(file);
4029 struct vino_channel_settings *vcs = video_get_drvdata(dev);
4030 int ret = 0; 4025 int ret = 0;
4031 dprintk("open(): channel = %c\n", 4026 dprintk("open(): channel = %c\n",
4032 (vcs->channel == VINO_CHANNEL_A) ? 'A' : 'B'); 4027 (vcs->channel == VINO_CHANNEL_A) ? 'A' : 'B');
@@ -4057,8 +4052,7 @@ static int vino_open(struct inode *inode, struct file *file)
4057 4052
4058static int vino_close(struct inode *inode, struct file *file) 4053static int vino_close(struct inode *inode, struct file *file)
4059{ 4054{
4060 struct video_device *dev = video_devdata(file); 4055 struct vino_channel_settings *vcs = video_drvdata(file);
4061 struct vino_channel_settings *vcs = video_get_drvdata(dev);
4062 dprintk("close():\n"); 4056 dprintk("close():\n");
4063 4057
4064 mutex_lock(&vcs->mutex); 4058 mutex_lock(&vcs->mutex);
@@ -4101,8 +4095,7 @@ static struct vm_operations_struct vino_vm_ops = {
4101 4095
4102static int vino_mmap(struct file *file, struct vm_area_struct *vma) 4096static int vino_mmap(struct file *file, struct vm_area_struct *vma)
4103{ 4097{
4104 struct video_device *dev = video_devdata(file); 4098 struct vino_channel_settings *vcs = video_drvdata(file);
4105 struct vino_channel_settings *vcs = video_get_drvdata(dev);
4106 4099
4107 unsigned long start = vma->vm_start; 4100 unsigned long start = vma->vm_start;
4108 unsigned long size = vma->vm_end - vma->vm_start; 4101 unsigned long size = vma->vm_end - vma->vm_start;
@@ -4207,8 +4200,7 @@ out:
4207 4200
4208static unsigned int vino_poll(struct file *file, poll_table *pt) 4201static unsigned int vino_poll(struct file *file, poll_table *pt)
4209{ 4202{
4210 struct video_device *dev = video_devdata(file); 4203 struct vino_channel_settings *vcs = video_drvdata(file);
4211 struct vino_channel_settings *vcs = video_get_drvdata(dev);
4212 unsigned int outgoing; 4204 unsigned int outgoing;
4213 unsigned int ret = 0; 4205 unsigned int ret = 0;
4214 4206
@@ -4248,8 +4240,7 @@ error:
4248static int vino_do_ioctl(struct inode *inode, struct file *file, 4240static int vino_do_ioctl(struct inode *inode, struct file *file,
4249 unsigned int cmd, void *arg) 4241 unsigned int cmd, void *arg)
4250{ 4242{
4251 struct video_device *dev = video_devdata(file); 4243 struct vino_channel_settings *vcs = video_drvdata(file);
4252 struct vino_channel_settings *vcs = video_get_drvdata(dev);
4253 4244
4254#ifdef VINO_DEBUG 4245#ifdef VINO_DEBUG
4255 switch (_IOC_TYPE(cmd)) { 4246 switch (_IOC_TYPE(cmd)) {
@@ -4356,8 +4347,7 @@ static int vino_do_ioctl(struct inode *inode, struct file *file,
4356static int vino_ioctl(struct inode *inode, struct file *file, 4347static int vino_ioctl(struct inode *inode, struct file *file,
4357 unsigned int cmd, unsigned long arg) 4348 unsigned int cmd, unsigned long arg)
4358{ 4349{
4359 struct video_device *dev = video_devdata(file); 4350 struct vino_channel_settings *vcs = video_drvdata(file);
4360 struct vino_channel_settings *vcs = video_get_drvdata(dev);
4361 int ret; 4351 int ret;
4362 4352
4363 if (mutex_lock_interruptible(&vcs->mutex)) 4353 if (mutex_lock_interruptible(&vcs->mutex))
@@ -4641,7 +4631,7 @@ static int __init vino_module_init(void)
4641 } 4631 }
4642 vino_init_stage++; 4632 vino_init_stage++;
4643 4633
4644#if defined(CONFIG_KMOD) && defined(MODULE) 4634#ifdef MODULE
4645 request_module("saa7191"); 4635 request_module("saa7191");
4646 request_module("indycam"); 4636 request_module("indycam");
4647#endif 4637#endif
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 8ba8daafd7ea..65c8af18e767 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -898,9 +898,11 @@ static int vivi_open(struct inode *inode, struct file *file)
898 898
899 printk(KERN_DEBUG "vivi: open called (minor=%d)\n", minor); 899 printk(KERN_DEBUG "vivi: open called (minor=%d)\n", minor);
900 900
901 lock_kernel();
901 list_for_each_entry(dev, &vivi_devlist, vivi_devlist) 902 list_for_each_entry(dev, &vivi_devlist, vivi_devlist)
902 if (dev->vfd->minor == minor) 903 if (dev->vfd->minor == minor)
903 goto found; 904 goto found;
905 unlock_kernel();
904 return -ENODEV; 906 return -ENODEV;
905 907
906found: 908found:
@@ -925,8 +927,10 @@ found:
925 } 927 }
926unlock: 928unlock:
927 mutex_unlock(&dev->mutex); 929 mutex_unlock(&dev->mutex);
928 if (retval) 930 if (retval) {
931 unlock_kernel();
929 return retval; 932 return retval;
933 }
930 934
931 file->private_data = fh; 935 file->private_data = fh;
932 fh->dev = dev; 936 fh->dev = dev;
@@ -955,6 +959,7 @@ unlock:
955 sizeof(struct vivi_buffer), fh); 959 sizeof(struct vivi_buffer), fh);
956 960
957 vivi_start_thread(fh); 961 vivi_start_thread(fh);
962 unlock_kernel();
958 963
959 return 0; 964 return 0;
960} 965}
diff --git a/drivers/media/video/vpx3220.c b/drivers/media/video/vpx3220.c
index 35293029da02..45be9ec8edc4 100644
--- a/drivers/media/video/vpx3220.c
+++ b/drivers/media/video/vpx3220.c
@@ -24,8 +24,6 @@
24#include <linux/types.h> 24#include <linux/types.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26 26
27#include <linux/byteorder/swab.h>
28
29#include <asm/io.h> 27#include <asm/io.h>
30#include <asm/uaccess.h> 28#include <asm/uaccess.h>
31 29
diff --git a/drivers/media/video/w9966.c b/drivers/media/video/w9966.c
index 2ff00bc5ad64..b2dbe48a92bb 100644
--- a/drivers/media/video/w9966.c
+++ b/drivers/media/video/w9966.c
@@ -113,6 +113,7 @@ struct w9966_dev {
113 signed char contrast; 113 signed char contrast;
114 signed char color; 114 signed char color;
115 signed char hue; 115 signed char hue;
116 unsigned long in_use;
116}; 117};
117 118
118/* 119/*
@@ -184,10 +185,25 @@ static int w9966_v4l_ioctl(struct inode *inode, struct file *file,
184static ssize_t w9966_v4l_read(struct file *file, char __user *buf, 185static ssize_t w9966_v4l_read(struct file *file, char __user *buf,
185 size_t count, loff_t *ppos); 186 size_t count, loff_t *ppos);
186 187
188static int w9966_exclusive_open(struct inode *inode, struct file *file)
189{
190 struct w9966_dev *cam = video_drvdata(file);
191
192 return test_and_set_bit(0, &cam->in_use) ? -EBUSY : 0;
193}
194
195static int w9966_exclusive_release(struct inode *inode, struct file *file)
196{
197 struct w9966_dev *cam = video_drvdata(file);
198
199 clear_bit(0, &cam->in_use);
200 return 0;
201}
202
187static const struct file_operations w9966_fops = { 203static const struct file_operations w9966_fops = {
188 .owner = THIS_MODULE, 204 .owner = THIS_MODULE,
189 .open = video_exclusive_open, 205 .open = w9966_exclusive_open,
190 .release = video_exclusive_release, 206 .release = w9966_exclusive_release,
191 .ioctl = w9966_v4l_ioctl, 207 .ioctl = w9966_v4l_ioctl,
192#ifdef CONFIG_COMPAT 208#ifdef CONFIG_COMPAT
193 .compat_ioctl = v4l_compat_ioctl32, 209 .compat_ioctl = v4l_compat_ioctl32,
@@ -198,6 +214,7 @@ static const struct file_operations w9966_fops = {
198static struct video_device w9966_template = { 214static struct video_device w9966_template = {
199 .name = W9966_DRIVERNAME, 215 .name = W9966_DRIVERNAME,
200 .fops = &w9966_fops, 216 .fops = &w9966_fops,
217 .release = video_device_release_empty,
201}; 218};
202 219
203/* 220/*
@@ -332,7 +349,7 @@ static int w9966_init(struct w9966_dev* cam, struct parport* port)
332 349
333// Fill in the video_device struct and register us to v4l 350// Fill in the video_device struct and register us to v4l
334 memcpy(&cam->vdev, &w9966_template, sizeof(struct video_device)); 351 memcpy(&cam->vdev, &w9966_template, sizeof(struct video_device));
335 cam->vdev.priv = cam; 352 video_set_drvdata(&cam->vdev, cam);
336 353
337 if (video_register_device(&cam->vdev, VFL_TYPE_GRABBER, video_nr) < 0) 354 if (video_register_device(&cam->vdev, VFL_TYPE_GRABBER, video_nr) < 0)
338 return -1; 355 return -1;
@@ -713,8 +730,7 @@ static int w9966_wReg_i2c(struct w9966_dev* cam, int reg, int data)
713static int w9966_v4l_do_ioctl(struct inode *inode, struct file *file, 730static int w9966_v4l_do_ioctl(struct inode *inode, struct file *file,
714 unsigned int cmd, void *arg) 731 unsigned int cmd, void *arg)
715{ 732{
716 struct video_device *vdev = video_devdata(file); 733 struct w9966_dev *cam = video_drvdata(file);
717 struct w9966_dev *cam = vdev->priv;
718 734
719 switch(cmd) 735 switch(cmd)
720 { 736 {
@@ -872,8 +888,7 @@ static int w9966_v4l_ioctl(struct inode *inode, struct file *file,
872static ssize_t w9966_v4l_read(struct file *file, char __user *buf, 888static ssize_t w9966_v4l_read(struct file *file, char __user *buf,
873 size_t count, loff_t *ppos) 889 size_t count, loff_t *ppos)
874{ 890{
875 struct video_device *vdev = video_devdata(file); 891 struct w9966_dev *cam = video_drvdata(file);
876 struct w9966_dev *cam = vdev->priv;
877 unsigned char addr = 0xa0; // ECP, read, CCD-transfer, 00000 892 unsigned char addr = 0xa0; // ECP, read, CCD-transfer, 00000
878 unsigned char __user *dest = (unsigned char __user *)buf; 893 unsigned char __user *dest = (unsigned char __user *)buf;
879 unsigned long dleft = count; 894 unsigned long dleft = count;
diff --git a/drivers/media/video/w9968cf.c b/drivers/media/video/w9968cf.c
index 11edf79f57be..dcd45dbd82dc 100644
--- a/drivers/media/video/w9968cf.c
+++ b/drivers/media/video/w9968cf.c
@@ -111,7 +111,7 @@ static int specific_debug = W9968CF_SPECIFIC_DEBUG;
111 111
112static unsigned int param_nv[24]; /* number of values per parameter */ 112static unsigned int param_nv[24]; /* number of values per parameter */
113 113
114#ifdef CONFIG_KMOD 114#ifdef CONFIG_MODULES
115module_param(ovmod_load, bool, 0644); 115module_param(ovmod_load, bool, 0644);
116#endif 116#endif
117module_param(simcams, ushort, 0644); 117module_param(simcams, ushort, 0644);
@@ -144,7 +144,7 @@ module_param(debug, ushort, 0644);
144module_param(specific_debug, bool, 0644); 144module_param(specific_debug, bool, 0644);
145#endif 145#endif
146 146
147#ifdef CONFIG_KMOD 147#ifdef CONFIG_MODULES
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."
diff --git a/drivers/media/video/zc0301/zc0301_core.c b/drivers/media/video/zc0301/zc0301_core.c
index 0c3287734c93..6a0902bcba6b 100644
--- a/drivers/media/video/zc0301/zc0301_core.c
+++ b/drivers/media/video/zc0301/zc0301_core.c
@@ -657,7 +657,7 @@ static int zc0301_open(struct inode* inode, struct file* filp)
657 if (!down_read_trylock(&zc0301_dev_lock)) 657 if (!down_read_trylock(&zc0301_dev_lock))
658 return -EAGAIN; 658 return -EAGAIN;
659 659
660 cam = video_get_drvdata(video_devdata(filp)); 660 cam = video_drvdata(filp);
661 661
662 if (wait_for_completion_interruptible(&cam->probe)) { 662 if (wait_for_completion_interruptible(&cam->probe)) {
663 up_read(&zc0301_dev_lock); 663 up_read(&zc0301_dev_lock);
@@ -739,7 +739,7 @@ static int zc0301_release(struct inode* inode, struct file* filp)
739 739
740 down_write(&zc0301_dev_lock); 740 down_write(&zc0301_dev_lock);
741 741
742 cam = video_get_drvdata(video_devdata(filp)); 742 cam = video_drvdata(filp);
743 743
744 zc0301_stop_transfer(cam); 744 zc0301_stop_transfer(cam);
745 zc0301_release_buffers(cam); 745 zc0301_release_buffers(cam);
@@ -759,7 +759,7 @@ static int zc0301_release(struct inode* inode, struct file* filp)
759static ssize_t 759static ssize_t
760zc0301_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos) 760zc0301_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
761{ 761{
762 struct zc0301_device* cam = video_get_drvdata(video_devdata(filp)); 762 struct zc0301_device *cam = video_drvdata(filp);
763 struct zc0301_frame_t* f, * i; 763 struct zc0301_frame_t* f, * i;
764 unsigned long lock_flags; 764 unsigned long lock_flags;
765 long timeout; 765 long timeout;
@@ -866,7 +866,7 @@ exit:
866 866
867static unsigned int zc0301_poll(struct file *filp, poll_table *wait) 867static unsigned int zc0301_poll(struct file *filp, poll_table *wait)
868{ 868{
869 struct zc0301_device* cam = video_get_drvdata(video_devdata(filp)); 869 struct zc0301_device *cam = video_drvdata(filp);
870 struct zc0301_frame_t* f; 870 struct zc0301_frame_t* f;
871 unsigned long lock_flags; 871 unsigned long lock_flags;
872 unsigned int mask = 0; 872 unsigned int mask = 0;
@@ -941,7 +941,7 @@ static struct vm_operations_struct zc0301_vm_ops = {
941 941
942static int zc0301_mmap(struct file* filp, struct vm_area_struct *vma) 942static int zc0301_mmap(struct file* filp, struct vm_area_struct *vma)
943{ 943{
944 struct zc0301_device* cam = video_get_drvdata(video_devdata(filp)); 944 struct zc0301_device *cam = video_drvdata(filp);
945 unsigned long size = vma->vm_end - vma->vm_start, 945 unsigned long size = vma->vm_end - vma->vm_start,
946 start = vma->vm_start; 946 start = vma->vm_start;
947 void *pos; 947 void *pos;
@@ -1796,7 +1796,7 @@ zc0301_vidioc_s_parm(struct zc0301_device* cam, void __user * arg)
1796static int zc0301_ioctl_v4l2(struct inode* inode, struct file* filp, 1796static int zc0301_ioctl_v4l2(struct inode* inode, struct file* filp,
1797 unsigned int cmd, void __user * arg) 1797 unsigned int cmd, void __user * arg)
1798{ 1798{
1799 struct zc0301_device* cam = video_get_drvdata(video_devdata(filp)); 1799 struct zc0301_device *cam = video_drvdata(filp);
1800 1800
1801 switch (cmd) { 1801 switch (cmd) {
1802 1802
@@ -1891,7 +1891,7 @@ static int zc0301_ioctl_v4l2(struct inode* inode, struct file* filp,
1891static int zc0301_ioctl(struct inode* inode, struct file* filp, 1891static int zc0301_ioctl(struct inode* inode, struct file* filp,
1892 unsigned int cmd, unsigned long arg) 1892 unsigned int cmd, unsigned long arg)
1893{ 1893{
1894 struct zc0301_device* cam = video_get_drvdata(video_devdata(filp)); 1894 struct zc0301_device *cam = video_drvdata(filp);
1895 int err = 0; 1895 int err = 0;
1896 1896
1897 if (mutex_lock_interruptible(&cam->fileop_mutex)) 1897 if (mutex_lock_interruptible(&cam->fileop_mutex))
diff --git a/drivers/media/video/zoran/Kconfig b/drivers/media/video/zoran/Kconfig
new file mode 100644
index 000000000000..4ea5fa71de89
--- /dev/null
+++ b/drivers/media/video/zoran/Kconfig
@@ -0,0 +1,73 @@
1config VIDEO_ZORAN
2 tristate "Zoran ZR36057/36067 Video For Linux"
3 depends on PCI && I2C_ALGOBIT && VIDEO_V4L1 && VIRT_TO_BUS
4 help
5 Say Y for support for MJPEG capture cards based on the Zoran
6 36057/36067 PCI controller chipset. This includes the Iomega
7 Buz, Pinnacle DC10+ and the Linux Media Labs LML33. There is
8 a driver homepage at <http://mjpeg.sf.net/driver-zoran/>. For
9 more information, check <file:Documentation/video4linux/Zoran>.
10
11 To compile this driver as a module, choose M here: the
12 module will be called zr36067.
13
14config VIDEO_ZORAN_DC30
15 tristate "Pinnacle/Miro DC30(+) support"
16 depends on VIDEO_ZORAN
17 select VIDEO_ADV7175 if VIDEO_HELPER_CHIPS_AUTO
18 select VIDEO_VPX3220 if VIDEO_HELPER_CHIPS_AUTO
19 help
20 Support for the Pinnacle/Miro DC30(+) MJPEG capture/playback
21 card. This also supports really old DC10 cards based on the
22 zr36050 MJPEG codec and zr36016 VFE.
23
24config VIDEO_ZORAN_ZR36060
25 tristate "Zoran ZR36060"
26 depends on VIDEO_ZORAN
27 help
28 Say Y to support Zoran boards based on 36060 chips.
29 This includes Iomega Buz, Pinnacle DC10, Linux media Labs 33
30 and 33 R10 and AverMedia 6 boards.
31
32config VIDEO_ZORAN_BUZ
33 tristate "Iomega Buz support"
34 depends on VIDEO_ZORAN_ZR36060
35 select VIDEO_SAA7111 if VIDEO_HELPER_CHIPS_AUTO
36 select VIDEO_SAA7185 if VIDEO_HELPER_CHIPS_AUTO
37 help
38 Support for the Iomega Buz MJPEG capture/playback card.
39
40config VIDEO_ZORAN_DC10
41 tristate "Pinnacle/Miro DC10(+) support"
42 depends on VIDEO_ZORAN_ZR36060
43 select VIDEO_SAA7110 if VIDEO_HELPER_CHIPS_AUTO
44 select VIDEO_ADV7175 if VIDEO_HELPER_CHIPS_AUTO
45 help
46 Support for the Pinnacle/Miro DC10(+) MJPEG capture/playback
47 card.
48
49config VIDEO_ZORAN_LML33
50 tristate "Linux Media Labs LML33 support"
51 depends on VIDEO_ZORAN_ZR36060
52 select VIDEO_BT819 if VIDEO_HELPER_CHIPS_AUTO
53 select VIDEO_BT856 if VIDEO_HELPER_CHIPS_AUTO
54 help
55 Support for the Linux Media Labs LML33 MJPEG capture/playback
56 card.
57
58config VIDEO_ZORAN_LML33R10
59 tristate "Linux Media Labs LML33R10 support"
60 depends on VIDEO_ZORAN_ZR36060
61 select VIDEO_SAA7114 if VIDEO_HELPER_CHIPS_AUTO
62 select VIDEO_ADV7170 if VIDEO_HELPER_CHIPS_AUTO
63 help
64 support for the Linux Media Labs LML33R10 MJPEG capture/playback
65 card.
66
67config VIDEO_ZORAN_AVS6EYES
68 tristate "AverMedia 6 Eyes support (EXPERIMENTAL)"
69 depends on VIDEO_ZORAN_ZR36060 && EXPERIMENTAL && VIDEO_V4L1
70 select VIDEO_BT856 if VIDEO_HELPER_CHIPS_AUTO
71 select VIDEO_KS0127 if VIDEO_HELPER_CHIPS_AUTO
72 help
73 Support for the AverMedia 6 Eyes video surveillance card.
diff --git a/drivers/media/video/zoran/Makefile b/drivers/media/video/zoran/Makefile
new file mode 100644
index 000000000000..44cc13352c88
--- /dev/null
+++ b/drivers/media/video/zoran/Makefile
@@ -0,0 +1,6 @@
1zr36067-objs := zoran_procfs.o zoran_device.o \
2 zoran_driver.o zoran_card.o
3
4obj-$(CONFIG_VIDEO_ZORAN) += zr36067.o videocodec.o
5obj-$(CONFIG_VIDEO_ZORAN_DC30) += zr36050.o zr36016.o
6obj-$(CONFIG_VIDEO_ZORAN_ZR36060) += zr36060.o
diff --git a/drivers/media/video/videocodec.c b/drivers/media/video/zoran/videocodec.c
index cf24956f3204..cf24956f3204 100644
--- a/drivers/media/video/videocodec.c
+++ b/drivers/media/video/zoran/videocodec.c
diff --git a/drivers/media/video/videocodec.h b/drivers/media/video/zoran/videocodec.h
index 97a3bbeda505..97a3bbeda505 100644
--- a/drivers/media/video/videocodec.h
+++ b/drivers/media/video/zoran/videocodec.h
diff --git a/drivers/media/video/zoran.h b/drivers/media/video/zoran/zoran.h
index 46b7ad477ceb..46b7ad477ceb 100644
--- a/drivers/media/video/zoran.h
+++ b/drivers/media/video/zoran/zoran.h
diff --git a/drivers/media/video/zoran_card.c b/drivers/media/video/zoran/zoran_card.c
index 3282be730298..3282be730298 100644
--- a/drivers/media/video/zoran_card.c
+++ b/drivers/media/video/zoran/zoran_card.c
diff --git a/drivers/media/video/zoran_card.h b/drivers/media/video/zoran/zoran_card.h
index e4dc9d29b404..e4dc9d29b404 100644
--- a/drivers/media/video/zoran_card.h
+++ b/drivers/media/video/zoran/zoran_card.h
diff --git a/drivers/media/video/zoran_device.c b/drivers/media/video/zoran/zoran_device.c
index 88d369708e4c..5d948ff7faf0 100644
--- a/drivers/media/video/zoran_device.c
+++ b/drivers/media/video/zoran/zoran_device.c
@@ -58,8 +58,6 @@
58 ZR36057_ISR_GIRQ1 | \ 58 ZR36057_ISR_GIRQ1 | \
59 ZR36057_ISR_JPEGRepIRQ ) 59 ZR36057_ISR_JPEGRepIRQ )
60 60
61extern const struct zoran_format zoran_formats[];
62
63static int lml33dpath; /* default = 0 61static int lml33dpath; /* default = 0
64 * 1 will use digital path in capture 62 * 1 will use digital path in capture
65 * mode instead of analog. It can be 63 * mode instead of analog. It can be
@@ -377,7 +375,7 @@ zr36057_set_vfe (struct zoran *zr,
377 375
378 /* horizontal */ 376 /* horizontal */
379 VidWinWid = video_width; 377 VidWinWid = video_width;
380 X = (VidWinWid * 64 + tvn->Wa - 1) / tvn->Wa; 378 X = DIV_ROUND_UP(VidWinWid * 64, tvn->Wa);
381 We = (VidWinWid * 64) / X; 379 We = (VidWinWid * 64) / X;
382 HorDcm = 64 - X; 380 HorDcm = 64 - X;
383 hcrop1 = 2 * ((tvn->Wa - We) / 4); 381 hcrop1 = 2 * ((tvn->Wa - We) / 4);
@@ -403,7 +401,7 @@ zr36057_set_vfe (struct zoran *zr,
403 /* Vertical */ 401 /* Vertical */
404 DispMode = !(video_height > BUZ_MAX_HEIGHT / 2); 402 DispMode = !(video_height > BUZ_MAX_HEIGHT / 2);
405 VidWinHt = DispMode ? video_height : video_height / 2; 403 VidWinHt = DispMode ? video_height : video_height / 2;
406 Y = (VidWinHt * 64 * 2 + tvn->Ha - 1) / tvn->Ha; 404 Y = DIV_ROUND_UP(VidWinHt * 64 * 2, tvn->Ha);
407 He = (VidWinHt * 64) / Y; 405 He = (VidWinHt * 64) / Y;
408 VerDcm = 64 - Y; 406 VerDcm = 64 - Y;
409 vcrop1 = (tvn->Ha / 2 - He) / 2; 407 vcrop1 = (tvn->Ha / 2 - He) / 2;
diff --git a/drivers/media/video/zoran_device.h b/drivers/media/video/zoran/zoran_device.h
index 37fa86a34083..74c6c8edb7d0 100644
--- a/drivers/media/video/zoran_device.h
+++ b/drivers/media/video/zoran/zoran_device.h
@@ -78,6 +78,14 @@ extern void zoran_set_pci_master(struct zoran *zr,
78extern void zoran_init_hardware(struct zoran *zr); 78extern void zoran_init_hardware(struct zoran *zr);
79extern void zr36057_restart(struct zoran *zr); 79extern void zr36057_restart(struct zoran *zr);
80 80
81extern const struct zoran_format zoran_formats[];
82
83extern int v4l_nbufs;
84extern int v4l_bufsize;
85extern int jpg_nbufs;
86extern int jpg_bufsize;
87extern int pass_through;
88
81/* i2c */ 89/* i2c */
82extern int decoder_command(struct zoran *zr, 90extern int decoder_command(struct zoran *zr,
83 int cmd, 91 int cmd,
diff --git a/drivers/media/video/zoran_driver.c b/drivers/media/video/zoran/zoran_driver.c
index 2dab9eea4def..25de7631443e 100644
--- a/drivers/media/video/zoran_driver.c
+++ b/drivers/media/video/zoran/zoran_driver.c
@@ -194,12 +194,6 @@ const struct zoran_format zoran_formats[] = {
194// RJ: Test only - want to test BUZ_USE_HIMEM even when CONFIG_BIGPHYS_AREA is defined 194// RJ: Test only - want to test BUZ_USE_HIMEM even when CONFIG_BIGPHYS_AREA is defined
195 195
196 196
197extern int v4l_nbufs;
198extern int v4l_bufsize;
199extern int jpg_nbufs;
200extern int jpg_bufsize;
201extern int pass_through;
202
203static int lock_norm; /* 0 = default 1 = Don't change TV standard (norm) */ 197static int lock_norm; /* 0 = default 1 = Don't change TV standard (norm) */
204module_param(lock_norm, int, 0644); 198module_param(lock_norm, int, 0644);
205MODULE_PARM_DESC(lock_norm, "Prevent norm changes (1 = ignore, >1 = fail)"); 199MODULE_PARM_DESC(lock_norm, "Prevent norm changes (1 = ignore, >1 = fail)");
@@ -1211,6 +1205,7 @@ zoran_open (struct inode *inode,
1211 struct zoran_fh *fh; 1205 struct zoran_fh *fh;
1212 int i, res, first_open = 0, have_module_locks = 0; 1206 int i, res, first_open = 0, have_module_locks = 0;
1213 1207
1208 lock_kernel();
1214 /* find the device */ 1209 /* find the device */
1215 for (i = 0; i < zoran_num; i++) { 1210 for (i = 0; i < zoran_num; i++) {
1216 if (zoran[i]->video_dev->minor == minor) { 1211 if (zoran[i]->video_dev->minor == minor) {
@@ -1321,6 +1316,7 @@ zoran_open (struct inode *inode,
1321 file->private_data = fh; 1316 file->private_data = fh;
1322 fh->zr = zr; 1317 fh->zr = zr;
1323 zoran_open_init_session(file); 1318 zoran_open_init_session(file);
1319 unlock_kernel();
1324 1320
1325 return 0; 1321 return 0;
1326 1322
@@ -1338,6 +1334,7 @@ open_unlock_and_return:
1338 if (zr) { 1334 if (zr) {
1339 /*mutex_unlock(&zr->resource_lock);*/ 1335 /*mutex_unlock(&zr->resource_lock);*/
1340 } 1336 }
1337 unlock_kernel();
1341 1338
1342 return res; 1339 return res;
1343} 1340}
@@ -2920,6 +2917,8 @@ zoran_do_ioctl (struct inode *inode,
2920 fmt->fmt.pix.bytesperline = 0; 2917 fmt->fmt.pix.bytesperline = 0;
2921 fmt->fmt.pix.sizeimage = 2918 fmt->fmt.pix.sizeimage =
2922 fh->jpg_buffers.buffer_size; 2919 fh->jpg_buffers.buffer_size;
2920 fmt->fmt.pix.colorspace =
2921 V4L2_COLORSPACE_SMPTE170M;
2923 2922
2924 /* we hereby abuse this variable to show that 2923 /* we hereby abuse this variable to show that
2925 * we're gonna do mjpeg capture */ 2924 * we're gonna do mjpeg capture */
@@ -2979,6 +2978,8 @@ zoran_do_ioctl (struct inode *inode,
2979 fmt->fmt.pix.sizeimage = 2978 fmt->fmt.pix.sizeimage =
2980 fh->v4l_settings.height * 2979 fh->v4l_settings.height *
2981 fh->v4l_settings.bytesperline; 2980 fh->v4l_settings.bytesperline;
2981 fmt->fmt.pix.colorspace =
2982 fh->v4l_settings.format->colorspace;
2982 if (BUZ_MAX_HEIGHT < 2983 if (BUZ_MAX_HEIGHT <
2983 (fh->v4l_settings.height * 2)) 2984 (fh->v4l_settings.height * 2))
2984 fmt->fmt.pix.field = 2985 fmt->fmt.pix.field =
diff --git a/drivers/media/video/zoran_procfs.c b/drivers/media/video/zoran/zoran_procfs.c
index 870bc5a70e3f..870bc5a70e3f 100644
--- a/drivers/media/video/zoran_procfs.c
+++ b/drivers/media/video/zoran/zoran_procfs.c
diff --git a/drivers/media/video/zoran_procfs.h b/drivers/media/video/zoran/zoran_procfs.h
index f2d5b1ba448f..f2d5b1ba448f 100644
--- a/drivers/media/video/zoran_procfs.h
+++ b/drivers/media/video/zoran/zoran_procfs.h
diff --git a/drivers/media/video/zr36016.c b/drivers/media/video/zoran/zr36016.c
index 00d132bcd1e4..00d132bcd1e4 100644
--- a/drivers/media/video/zr36016.c
+++ b/drivers/media/video/zoran/zr36016.c
diff --git a/drivers/media/video/zr36016.h b/drivers/media/video/zoran/zr36016.h
index 8c79229f69d1..8c79229f69d1 100644
--- a/drivers/media/video/zr36016.h
+++ b/drivers/media/video/zoran/zr36016.h
diff --git a/drivers/media/video/zr36050.c b/drivers/media/video/zoran/zr36050.c
index cf8b271a1c8f..cf8b271a1c8f 100644
--- a/drivers/media/video/zr36050.c
+++ b/drivers/media/video/zoran/zr36050.c
diff --git a/drivers/media/video/zr36050.h b/drivers/media/video/zoran/zr36050.h
index 9f52f0cdde50..9f52f0cdde50 100644
--- a/drivers/media/video/zr36050.h
+++ b/drivers/media/video/zoran/zr36050.h
diff --git a/drivers/media/video/zr36057.h b/drivers/media/video/zoran/zr36057.h
index 54c9362aa980..54c9362aa980 100644
--- a/drivers/media/video/zr36057.h
+++ b/drivers/media/video/zoran/zr36057.h
diff --git a/drivers/media/video/zr36060.c b/drivers/media/video/zoran/zr36060.c
index 8e74054d5ef1..8e74054d5ef1 100644
--- a/drivers/media/video/zr36060.c
+++ b/drivers/media/video/zoran/zr36060.c
diff --git a/drivers/media/video/zr36060.h b/drivers/media/video/zoran/zr36060.h
index 914ffa4ad8d3..914ffa4ad8d3 100644
--- a/drivers/media/video/zr36060.h
+++ b/drivers/media/video/zoran/zr36060.h
diff --git a/drivers/media/video/zr364xx.c b/drivers/media/video/zr364xx.c
index 18d1c4ba79fb..7cdac99deea6 100644
--- a/drivers/media/video/zr364xx.c
+++ b/drivers/media/video/zr364xx.c
@@ -52,7 +52,7 @@
52 52
53 53
54/* Debug macro */ 54/* Debug macro */
55#define DBG(x...) if (debug) info(x) 55#define DBG(x...) if (debug) printk(KERN_INFO KBUILD_MODNAME x)
56 56
57 57
58/* Init methods, need to find nicer names for these 58/* Init methods, need to find nicer names for these
@@ -116,6 +116,7 @@ struct zr364xx_camera {
116 int height; 116 int height;
117 int method; 117 int method;
118 struct mutex lock; 118 struct mutex lock;
119 int users;
119}; 120};
120 121
121 122
@@ -127,7 +128,7 @@ static int send_control_msg(struct usb_device *udev, u8 request, u16 value,
127 128
128 unsigned char *transfer_buffer = kmalloc(size, GFP_KERNEL); 129 unsigned char *transfer_buffer = kmalloc(size, GFP_KERNEL);
129 if (!transfer_buffer) { 130 if (!transfer_buffer) {
130 info("kmalloc(%d) failed", size); 131 dev_err(&udev->dev, "kmalloc(%d) failed\n", size);
131 return -ENOMEM; 132 return -ENOMEM;
132 } 133 }
133 134
@@ -143,7 +144,8 @@ static int send_control_msg(struct usb_device *udev, u8 request, u16 value,
143 kfree(transfer_buffer); 144 kfree(transfer_buffer);
144 145
145 if (status < 0) 146 if (status < 0)
146 info("Failed sending control message, error %d.", status); 147 dev_err(&udev->dev,
148 "Failed sending control message, error %d.\n", status);
147 149
148 return status; 150 return status;
149} 151}
@@ -303,11 +305,11 @@ static int read_frame(struct zr364xx_camera *cam, int framenum)
303 DBG("buffer : %d %d", cam->buffer[0], cam->buffer[1]); 305 DBG("buffer : %d %d", cam->buffer[0], cam->buffer[1]);
304 DBG("bulk : n=%d size=%d", n, actual_length); 306 DBG("bulk : n=%d size=%d", n, actual_length);
305 if (n < 0) { 307 if (n < 0) {
306 info("error reading bulk msg"); 308 dev_err(&cam->udev->dev, "error reading bulk msg\n");
307 return 0; 309 return 0;
308 } 310 }
309 if (actual_length < 0 || actual_length > BUFFER_SIZE) { 311 if (actual_length < 0 || actual_length > BUFFER_SIZE) {
310 info("wrong number of bytes"); 312 dev_err(&cam->udev->dev, "wrong number of bytes\n");
311 return 0; 313 return 0;
312 } 314 }
313 315
@@ -641,42 +643,47 @@ static int zr364xx_open(struct inode *inode, struct file *file)
641 643
642 DBG("zr364xx_open"); 644 DBG("zr364xx_open");
643 645
644 cam->skip = 2; 646 mutex_lock(&cam->lock);
645 647
646 err = video_exclusive_open(inode, file); 648 if (cam->users) {
647 if (err < 0) 649 err = -EBUSY;
648 return err; 650 goto out;
651 }
649 652
650 if (!cam->framebuf) { 653 if (!cam->framebuf) {
651 cam->framebuf = vmalloc_32(MAX_FRAME_SIZE * FRAMES); 654 cam->framebuf = vmalloc_32(MAX_FRAME_SIZE * FRAMES);
652 if (!cam->framebuf) { 655 if (!cam->framebuf) {
653 info("vmalloc_32 failed!"); 656 dev_err(&cam->udev->dev, "vmalloc_32 failed!\n");
654 return -ENOMEM; 657 err = -ENOMEM;
658 goto out;
655 } 659 }
656 } 660 }
657 661
658 mutex_lock(&cam->lock);
659 for (i = 0; init[cam->method][i].size != -1; i++) { 662 for (i = 0; init[cam->method][i].size != -1; i++) {
660 err = 663 err =
661 send_control_msg(udev, 1, init[cam->method][i].value, 664 send_control_msg(udev, 1, init[cam->method][i].value,
662 0, init[cam->method][i].bytes, 665 0, init[cam->method][i].bytes,
663 init[cam->method][i].size); 666 init[cam->method][i].size);
664 if (err < 0) { 667 if (err < 0) {
665 info("error during open sequence: %d", i); 668 dev_err(&cam->udev->dev,
666 mutex_unlock(&cam->lock); 669 "error during open sequence: %d\n", i);
667 return err; 670 goto out;
668 } 671 }
669 } 672 }
670 673
674 cam->skip = 2;
675 cam->users++;
671 file->private_data = vdev; 676 file->private_data = vdev;
672 677
673 /* Added some delay here, since opening/closing the camera quickly, 678 /* Added some delay here, since opening/closing the camera quickly,
674 * like Ekiga does during its startup, can crash the webcam 679 * like Ekiga does during its startup, can crash the webcam
675 */ 680 */
676 mdelay(100); 681 mdelay(100);
682 err = 0;
677 683
684out:
678 mutex_unlock(&cam->lock); 685 mutex_unlock(&cam->lock);
679 return 0; 686 return err;
680} 687}
681 688
682 689
@@ -697,28 +704,30 @@ static int zr364xx_release(struct inode *inode, struct file *file)
697 udev = cam->udev; 704 udev = cam->udev;
698 705
699 mutex_lock(&cam->lock); 706 mutex_lock(&cam->lock);
707
708 cam->users--;
709 file->private_data = NULL;
710
700 for (i = 0; i < 2; i++) { 711 for (i = 0; i < 2; i++) {
701 err = 712 err =
702 send_control_msg(udev, 1, init[cam->method][i].value, 713 send_control_msg(udev, 1, init[cam->method][i].value,
703 0, init[i][cam->method].bytes, 714 0, init[i][cam->method].bytes,
704 init[cam->method][i].size); 715 init[cam->method][i].size);
705 if (err < 0) { 716 if (err < 0) {
706 info("error during release sequence"); 717 dev_err(&udev->dev, "error during release sequence\n");
707 mutex_unlock(&cam->lock); 718 goto out;
708 return err;
709 } 719 }
710 } 720 }
711 721
712 file->private_data = NULL;
713 video_exclusive_release(inode, file);
714
715 /* Added some delay here, since opening/closing the camera quickly, 722 /* Added some delay here, since opening/closing the camera quickly,
716 * like Ekiga does during its startup, can crash the webcam 723 * like Ekiga does during its startup, can crash the webcam
717 */ 724 */
718 mdelay(100); 725 mdelay(100);
726 err = 0;
719 727
728out:
720 mutex_unlock(&cam->lock); 729 mutex_unlock(&cam->lock);
721 return 0; 730 return err;
722} 731}
723 732
724 733
@@ -801,13 +810,14 @@ static int zr364xx_probe(struct usb_interface *intf,
801 810
802 DBG("probing..."); 811 DBG("probing...");
803 812
804 info(DRIVER_DESC " compatible webcam plugged"); 813 dev_info(&intf->dev, DRIVER_DESC " compatible webcam plugged\n");
805 info("model %04x:%04x detected", udev->descriptor.idVendor, 814 dev_info(&intf->dev, "model %04x:%04x detected\n",
806 udev->descriptor.idProduct); 815 le16_to_cpu(udev->descriptor.idVendor),
816 le16_to_cpu(udev->descriptor.idProduct));
807 817
808 cam = kzalloc(sizeof(struct zr364xx_camera), GFP_KERNEL); 818 cam = kzalloc(sizeof(struct zr364xx_camera), GFP_KERNEL);
809 if (cam == NULL) { 819 if (cam == NULL) {
810 info("cam: out of memory !"); 820 dev_err(&udev->dev, "cam: out of memory !\n");
811 return -ENOMEM; 821 return -ENOMEM;
812 } 822 }
813 /* save the init method used by this camera */ 823 /* save the init method used by this camera */
@@ -815,7 +825,7 @@ static int zr364xx_probe(struct usb_interface *intf,
815 825
816 cam->vdev = video_device_alloc(); 826 cam->vdev = video_device_alloc();
817 if (cam->vdev == NULL) { 827 if (cam->vdev == NULL) {
818 info("cam->vdev: out of memory !"); 828 dev_err(&udev->dev, "cam->vdev: out of memory !\n");
819 kfree(cam); 829 kfree(cam);
820 return -ENOMEM; 830 return -ENOMEM;
821 } 831 }
@@ -827,7 +837,7 @@ static int zr364xx_probe(struct usb_interface *intf,
827 cam->udev = udev; 837 cam->udev = udev;
828 838
829 if ((cam->buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL)) == NULL) { 839 if ((cam->buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL)) == NULL) {
830 info("cam->buffer: out of memory !"); 840 dev_info(&udev->dev, "cam->buffer: out of memory !\n");
831 video_device_release(cam->vdev); 841 video_device_release(cam->vdev);
832 kfree(cam); 842 kfree(cam);
833 return -ENODEV; 843 return -ENODEV;
@@ -835,17 +845,17 @@ static int zr364xx_probe(struct usb_interface *intf,
835 845
836 switch (mode) { 846 switch (mode) {
837 case 1: 847 case 1:
838 info("160x120 mode selected"); 848 dev_info(&udev->dev, "160x120 mode selected\n");
839 cam->width = 160; 849 cam->width = 160;
840 cam->height = 120; 850 cam->height = 120;
841 break; 851 break;
842 case 2: 852 case 2:
843 info("640x480 mode selected"); 853 dev_info(&udev->dev, "640x480 mode selected\n");
844 cam->width = 640; 854 cam->width = 640;
845 cam->height = 480; 855 cam->height = 480;
846 break; 856 break;
847 default: 857 default:
848 info("320x240 mode selected"); 858 dev_info(&udev->dev, "320x240 mode selected\n");
849 cam->width = 320; 859 cam->width = 320;
850 cam->height = 240; 860 cam->height = 240;
851 break; 861 break;
@@ -865,7 +875,7 @@ static int zr364xx_probe(struct usb_interface *intf,
865 875
866 err = video_register_device(cam->vdev, VFL_TYPE_GRABBER, -1); 876 err = video_register_device(cam->vdev, VFL_TYPE_GRABBER, -1);
867 if (err) { 877 if (err) {
868 info("video_register_device failed"); 878 dev_err(&udev->dev, "video_register_device failed\n");
869 video_device_release(cam->vdev); 879 video_device_release(cam->vdev);
870 kfree(cam->buffer); 880 kfree(cam->buffer);
871 kfree(cam); 881 kfree(cam);
@@ -874,7 +884,8 @@ static int zr364xx_probe(struct usb_interface *intf,
874 884
875 usb_set_intfdata(intf, cam); 885 usb_set_intfdata(intf, cam);
876 886
877 info(DRIVER_DESC " controlling video device %d", cam->vdev->minor); 887 dev_info(&udev->dev, DRIVER_DESC " controlling video device %d\n",
888 cam->vdev->minor);
878 return 0; 889 return 0;
879} 890}
880 891
@@ -884,7 +895,7 @@ static void zr364xx_disconnect(struct usb_interface *intf)
884 struct zr364xx_camera *cam = usb_get_intfdata(intf); 895 struct zr364xx_camera *cam = usb_get_intfdata(intf);
885 usb_set_intfdata(intf, NULL); 896 usb_set_intfdata(intf, NULL);
886 dev_set_drvdata(&intf->dev, NULL); 897 dev_set_drvdata(&intf->dev, NULL);
887 info(DRIVER_DESC " webcam unplugged"); 898 dev_info(&intf->dev, DRIVER_DESC " webcam unplugged\n");
888 if (cam->vdev) 899 if (cam->vdev)
889 video_unregister_device(cam->vdev); 900 video_unregister_device(cam->vdev);
890 cam->vdev = NULL; 901 cam->vdev = NULL;
@@ -913,16 +924,16 @@ static int __init zr364xx_init(void)
913 int retval; 924 int retval;
914 retval = usb_register(&zr364xx_driver); 925 retval = usb_register(&zr364xx_driver);
915 if (retval) 926 if (retval)
916 info("usb_register failed!"); 927 printk(KERN_ERR KBUILD_MODNAME ": usb_register failed!\n");
917 else 928 else
918 info(DRIVER_DESC " module loaded"); 929 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n");
919 return retval; 930 return retval;
920} 931}
921 932
922 933
923static void __exit zr364xx_exit(void) 934static void __exit zr364xx_exit(void)
924{ 935{
925 info(DRIVER_DESC " module unloaded"); 936 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC " module unloaded\n");
926 usb_deregister(&zr364xx_driver); 937 usb_deregister(&zr364xx_driver);
927} 938}
928 939
diff --git a/drivers/message/i2o/Makefile b/drivers/message/i2o/Makefile
index 2c2e39aa1efa..b0982dacfd0a 100644
--- a/drivers/message/i2o/Makefile
+++ b/drivers/message/i2o/Makefile
@@ -5,7 +5,7 @@
5# In the future, some of these should be built conditionally. 5# In the future, some of these should be built conditionally.
6# 6#
7 7
8i2o_core-y += iop.o driver.o device.o debug.o pci.o exec-osm.o 8i2o_core-y += iop.o driver.o device.o debug.o pci.o exec-osm.o memory.o
9i2o_bus-y += bus-osm.o 9i2o_bus-y += bus-osm.o
10i2o_config-y += config-osm.o 10i2o_config-y += config-osm.o
11obj-$(CONFIG_I2O) += i2o_core.o 11obj-$(CONFIG_I2O) += i2o_core.o
diff --git a/drivers/message/i2o/device.c b/drivers/message/i2o/device.c
index 8774c670e668..54c2e9ae23e5 100644
--- a/drivers/message/i2o/device.c
+++ b/drivers/message/i2o/device.c
@@ -467,7 +467,7 @@ int i2o_parm_issue(struct i2o_device *i2o_dev, int cmd, void *oplist,
467 467
468 res.virt = NULL; 468 res.virt = NULL;
469 469
470 if (i2o_dma_alloc(dev, &res, reslen, GFP_KERNEL)) 470 if (i2o_dma_alloc(dev, &res, reslen))
471 return -ENOMEM; 471 return -ENOMEM;
472 472
473 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET); 473 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
diff --git a/drivers/message/i2o/exec-osm.c b/drivers/message/i2o/exec-osm.c
index 6cbcc21de518..56faef1a1d55 100644
--- a/drivers/message/i2o/exec-osm.c
+++ b/drivers/message/i2o/exec-osm.c
@@ -388,8 +388,8 @@ static int i2o_exec_lct_notify(struct i2o_controller *c, u32 change_ind)
388 388
389 dev = &c->pdev->dev; 389 dev = &c->pdev->dev;
390 390
391 if (i2o_dma_realloc 391 if (i2o_dma_realloc(dev, &c->dlct,
392 (dev, &c->dlct, le32_to_cpu(sb->expected_lct_size), GFP_KERNEL)) 392 le32_to_cpu(sb->expected_lct_size)))
393 return -ENOMEM; 393 return -ENOMEM;
394 394
395 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET); 395 msg = i2o_msg_get_wait(c, I2O_TIMEOUT_MESSAGE_GET);
diff --git a/drivers/message/i2o/i2o_config.c b/drivers/message/i2o/i2o_config.c
index 4238de98d4a6..a3fabdbe6ca6 100644
--- a/drivers/message/i2o/i2o_config.c
+++ b/drivers/message/i2o/i2o_config.c
@@ -260,7 +260,7 @@ static int i2o_cfg_swdl(unsigned long arg)
260 if (IS_ERR(msg)) 260 if (IS_ERR(msg))
261 return PTR_ERR(msg); 261 return PTR_ERR(msg);
262 262
263 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize, GFP_KERNEL)) { 263 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) {
264 i2o_msg_nop(c, msg); 264 i2o_msg_nop(c, msg);
265 return -ENOMEM; 265 return -ENOMEM;
266 } 266 }
@@ -339,7 +339,7 @@ static int i2o_cfg_swul(unsigned long arg)
339 if (IS_ERR(msg)) 339 if (IS_ERR(msg))
340 return PTR_ERR(msg); 340 return PTR_ERR(msg);
341 341
342 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize, GFP_KERNEL)) { 342 if (i2o_dma_alloc(&c->pdev->dev, &buffer, fragsize)) {
343 i2o_msg_nop(c, msg); 343 i2o_msg_nop(c, msg);
344 return -ENOMEM; 344 return -ENOMEM;
345 } 345 }
@@ -634,9 +634,7 @@ static int i2o_cfg_passthru32(struct file *file, unsigned cmnd,
634 sg_size = sg[i].flag_count & 0xffffff; 634 sg_size = sg[i].flag_count & 0xffffff;
635 p = &(sg_list[sg_index]); 635 p = &(sg_list[sg_index]);
636 /* Allocate memory for the transfer */ 636 /* Allocate memory for the transfer */
637 if (i2o_dma_alloc 637 if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) {
638 (&c->pdev->dev, p, sg_size,
639 PCI_DMA_BIDIRECTIONAL)) {
640 printk(KERN_DEBUG 638 printk(KERN_DEBUG
641 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n", 639 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
642 c->name, sg_size, i, sg_count); 640 c->name, sg_size, i, sg_count);
@@ -780,12 +778,11 @@ static int i2o_cfg_passthru(unsigned long arg)
780 u32 size = 0; 778 u32 size = 0;
781 u32 reply_size = 0; 779 u32 reply_size = 0;
782 u32 rcode = 0; 780 u32 rcode = 0;
783 void *sg_list[SG_TABLESIZE]; 781 struct i2o_dma sg_list[SG_TABLESIZE];
784 u32 sg_offset = 0; 782 u32 sg_offset = 0;
785 u32 sg_count = 0; 783 u32 sg_count = 0;
786 int sg_index = 0; 784 int sg_index = 0;
787 u32 i = 0; 785 u32 i = 0;
788 void *p = NULL;
789 i2o_status_block *sb; 786 i2o_status_block *sb;
790 struct i2o_message *msg; 787 struct i2o_message *msg;
791 unsigned int iop; 788 unsigned int iop;
@@ -842,6 +839,7 @@ static int i2o_cfg_passthru(unsigned long arg)
842 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE); 839 memset(sg_list, 0, sizeof(sg_list[0]) * SG_TABLESIZE);
843 if (sg_offset) { 840 if (sg_offset) {
844 struct sg_simple_element *sg; 841 struct sg_simple_element *sg;
842 struct i2o_dma *p;
845 843
846 if (sg_offset * 4 >= size) { 844 if (sg_offset * 4 >= size) {
847 rcode = -EFAULT; 845 rcode = -EFAULT;
@@ -871,22 +869,22 @@ static int i2o_cfg_passthru(unsigned long arg)
871 goto sg_list_cleanup; 869 goto sg_list_cleanup;
872 } 870 }
873 sg_size = sg[i].flag_count & 0xffffff; 871 sg_size = sg[i].flag_count & 0xffffff;
872 p = &(sg_list[sg_index]);
873 if (i2o_dma_alloc(&c->pdev->dev, p, sg_size)) {
874 /* Allocate memory for the transfer */ 874 /* Allocate memory for the transfer */
875 p = kmalloc(sg_size, GFP_KERNEL);
876 if (!p) {
877 printk(KERN_DEBUG 875 printk(KERN_DEBUG
878 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n", 876 "%s: Could not allocate SG buffer - size = %d buffer number %d of %d\n",
879 c->name, sg_size, i, sg_count); 877 c->name, sg_size, i, sg_count);
880 rcode = -ENOMEM; 878 rcode = -ENOMEM;
881 goto sg_list_cleanup; 879 goto sg_list_cleanup;
882 } 880 }
883 sg_list[sg_index++] = p; // sglist indexed with input frame, not our internal frame. 881 sg_index++;
884 /* Copy in the user's SG buffer if necessary */ 882 /* Copy in the user's SG buffer if necessary */
885 if (sg[i]. 883 if (sg[i].
886 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) { 884 flag_count & 0x04000000 /*I2O_SGL_FLAGS_DIR */ ) {
887 // TODO 64bit fix 885 // TODO 64bit fix
888 if (copy_from_user 886 if (copy_from_user
889 (p, (void __user *)sg[i].addr_bus, 887 (p->virt, (void __user *)sg[i].addr_bus,
890 sg_size)) { 888 sg_size)) {
891 printk(KERN_DEBUG 889 printk(KERN_DEBUG
892 "%s: Could not copy SG buf %d FROM user\n", 890 "%s: Could not copy SG buf %d FROM user\n",
@@ -895,8 +893,7 @@ static int i2o_cfg_passthru(unsigned long arg)
895 goto sg_list_cleanup; 893 goto sg_list_cleanup;
896 } 894 }
897 } 895 }
898 //TODO 64bit fix 896 sg[i].addr_bus = p->phys;
899 sg[i].addr_bus = virt_to_bus(p);
900 } 897 }
901 } 898 }
902 899
@@ -908,7 +905,7 @@ static int i2o_cfg_passthru(unsigned long arg)
908 } 905 }
909 906
910 if (sg_offset) { 907 if (sg_offset) {
911 u32 rmsg[128]; 908 u32 rmsg[I2O_OUTBOUND_MSG_FRAME_SIZE];
912 /* Copy back the Scatter Gather buffers back to user space */ 909 /* Copy back the Scatter Gather buffers back to user space */
913 u32 j; 910 u32 j;
914 // TODO 64bit fix 911 // TODO 64bit fix
@@ -942,11 +939,11 @@ static int i2o_cfg_passthru(unsigned long arg)
942 sg_size = sg[j].flag_count & 0xffffff; 939 sg_size = sg[j].flag_count & 0xffffff;
943 // TODO 64bit fix 940 // TODO 64bit fix
944 if (copy_to_user 941 if (copy_to_user
945 ((void __user *)sg[j].addr_bus, sg_list[j], 942 ((void __user *)sg[j].addr_bus, sg_list[j].virt,
946 sg_size)) { 943 sg_size)) {
947 printk(KERN_WARNING 944 printk(KERN_WARNING
948 "%s: Could not copy %p TO user %x\n", 945 "%s: Could not copy %p TO user %x\n",
949 c->name, sg_list[j], 946 c->name, sg_list[j].virt,
950 sg[j].addr_bus); 947 sg[j].addr_bus);
951 rcode = -EFAULT; 948 rcode = -EFAULT;
952 goto sg_list_cleanup; 949 goto sg_list_cleanup;
@@ -973,7 +970,7 @@ sg_list_cleanup:
973 } 970 }
974 971
975 for (i = 0; i < sg_index; i++) 972 for (i = 0; i < sg_index; i++)
976 kfree(sg_list[i]); 973 i2o_dma_free(&c->pdev->dev, &sg_list[i]);
977 974
978cleanup: 975cleanup:
979 kfree(reply); 976 kfree(reply);
diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
index da715e11c1b2..be2b5926d26c 100644
--- a/drivers/message/i2o/iop.c
+++ b/drivers/message/i2o/iop.c
@@ -1004,7 +1004,7 @@ static int i2o_hrt_get(struct i2o_controller *c)
1004 1004
1005 size = hrt->num_entries * hrt->entry_len << 2; 1005 size = hrt->num_entries * hrt->entry_len << 2;
1006 if (size > c->hrt.len) { 1006 if (size > c->hrt.len) {
1007 if (i2o_dma_realloc(dev, &c->hrt, size, GFP_KERNEL)) 1007 if (i2o_dma_realloc(dev, &c->hrt, size))
1008 return -ENOMEM; 1008 return -ENOMEM;
1009 else 1009 else
1010 hrt = c->hrt.virt; 1010 hrt = c->hrt.virt;
diff --git a/drivers/message/i2o/memory.c b/drivers/message/i2o/memory.c
new file mode 100644
index 000000000000..f5cc95c564e2
--- /dev/null
+++ b/drivers/message/i2o/memory.c
@@ -0,0 +1,313 @@
1/*
2 * Functions to handle I2O memory
3 *
4 * Pulled from the inlines in i2o headers and uninlined
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 */
12
13#include <linux/module.h>
14#include <linux/i2o.h>
15#include <linux/delay.h>
16#include <linux/string.h>
17#include <linux/slab.h>
18#include "core.h"
19
20/* Protects our 32/64bit mask switching */
21static DEFINE_MUTEX(mem_lock);
22
23/**
24 * i2o_sg_tablesize - Calculate the maximum number of elements in a SGL
25 * @c: I2O controller for which the calculation should be done
26 * @body_size: maximum body size used for message in 32-bit words.
27 *
28 * Return the maximum number of SG elements in a SG list.
29 */
30u16 i2o_sg_tablesize(struct i2o_controller *c, u16 body_size)
31{
32 i2o_status_block *sb = c->status_block.virt;
33 u16 sg_count =
34 (sb->inbound_frame_size - sizeof(struct i2o_message) / 4) -
35 body_size;
36
37 if (c->pae_support) {
38 /*
39 * for 64-bit a SG attribute element must be added and each
40 * SG element needs 12 bytes instead of 8.
41 */
42 sg_count -= 2;
43 sg_count /= 3;
44 } else
45 sg_count /= 2;
46
47 if (c->short_req && (sg_count > 8))
48 sg_count = 8;
49
50 return sg_count;
51}
52EXPORT_SYMBOL_GPL(i2o_sg_tablesize);
53
54
55/**
56 * i2o_dma_map_single - Map pointer to controller and fill in I2O message.
57 * @c: I2O controller
58 * @ptr: pointer to the data which should be mapped
59 * @size: size of data in bytes
60 * @direction: DMA_TO_DEVICE / DMA_FROM_DEVICE
61 * @sg_ptr: pointer to the SG list inside the I2O message
62 *
63 * This function does all necessary DMA handling and also writes the I2O
64 * SGL elements into the I2O message. For details on DMA handling see also
65 * dma_map_single(). The pointer sg_ptr will only be set to the end of the
66 * SG list if the allocation was successful.
67 *
68 * Returns DMA address which must be checked for failures using
69 * dma_mapping_error().
70 */
71dma_addr_t i2o_dma_map_single(struct i2o_controller *c, void *ptr,
72 size_t size,
73 enum dma_data_direction direction,
74 u32 ** sg_ptr)
75{
76 u32 sg_flags;
77 u32 *mptr = *sg_ptr;
78 dma_addr_t dma_addr;
79
80 switch (direction) {
81 case DMA_TO_DEVICE:
82 sg_flags = 0xd4000000;
83 break;
84 case DMA_FROM_DEVICE:
85 sg_flags = 0xd0000000;
86 break;
87 default:
88 return 0;
89 }
90
91 dma_addr = dma_map_single(&c->pdev->dev, ptr, size, direction);
92 if (!dma_mapping_error(&c->pdev->dev, dma_addr)) {
93#ifdef CONFIG_I2O_EXT_ADAPTEC_DMA64
94 if ((sizeof(dma_addr_t) > 4) && c->pae_support) {
95 *mptr++ = cpu_to_le32(0x7C020002);
96 *mptr++ = cpu_to_le32(PAGE_SIZE);
97 }
98#endif
99
100 *mptr++ = cpu_to_le32(sg_flags | size);
101 *mptr++ = cpu_to_le32(i2o_dma_low(dma_addr));
102#ifdef CONFIG_I2O_EXT_ADAPTEC_DMA64
103 if ((sizeof(dma_addr_t) > 4) && c->pae_support)
104 *mptr++ = cpu_to_le32(i2o_dma_high(dma_addr));
105#endif
106 *sg_ptr = mptr;
107 }
108 return dma_addr;
109}
110EXPORT_SYMBOL_GPL(i2o_dma_map_single);
111
112/**
113 * i2o_dma_map_sg - Map a SG List to controller and fill in I2O message.
114 * @c: I2O controller
115 * @sg: SG list to be mapped
116 * @sg_count: number of elements in the SG list
117 * @direction: DMA_TO_DEVICE / DMA_FROM_DEVICE
118 * @sg_ptr: pointer to the SG list inside the I2O message
119 *
120 * This function does all necessary DMA handling and also writes the I2O
121 * SGL elements into the I2O message. For details on DMA handling see also
122 * dma_map_sg(). The pointer sg_ptr will only be set to the end of the SG
123 * list if the allocation was successful.
124 *
125 * Returns 0 on failure or 1 on success.
126 */
127int i2o_dma_map_sg(struct i2o_controller *c, struct scatterlist *sg,
128 int sg_count, enum dma_data_direction direction, u32 ** sg_ptr)
129{
130 u32 sg_flags;
131 u32 *mptr = *sg_ptr;
132
133 switch (direction) {
134 case DMA_TO_DEVICE:
135 sg_flags = 0x14000000;
136 break;
137 case DMA_FROM_DEVICE:
138 sg_flags = 0x10000000;
139 break;
140 default:
141 return 0;
142 }
143
144 sg_count = dma_map_sg(&c->pdev->dev, sg, sg_count, direction);
145 if (!sg_count)
146 return 0;
147
148#ifdef CONFIG_I2O_EXT_ADAPTEC_DMA64
149 if ((sizeof(dma_addr_t) > 4) && c->pae_support) {
150 *mptr++ = cpu_to_le32(0x7C020002);
151 *mptr++ = cpu_to_le32(PAGE_SIZE);
152 }
153#endif
154
155 while (sg_count-- > 0) {
156 if (!sg_count)
157 sg_flags |= 0xC0000000;
158 *mptr++ = cpu_to_le32(sg_flags | sg_dma_len(sg));
159 *mptr++ = cpu_to_le32(i2o_dma_low(sg_dma_address(sg)));
160#ifdef CONFIG_I2O_EXT_ADAPTEC_DMA64
161 if ((sizeof(dma_addr_t) > 4) && c->pae_support)
162 *mptr++ = cpu_to_le32(i2o_dma_high(sg_dma_address(sg)));
163#endif
164 sg = sg_next(sg);
165 }
166 *sg_ptr = mptr;
167
168 return 1;
169}
170EXPORT_SYMBOL_GPL(i2o_dma_map_sg);
171
172/**
173 * i2o_dma_alloc - Allocate DMA memory
174 * @dev: struct device pointer to the PCI device of the I2O controller
175 * @addr: i2o_dma struct which should get the DMA buffer
176 * @len: length of the new DMA memory
177 *
178 * Allocate a coherent DMA memory and write the pointers into addr.
179 *
180 * Returns 0 on success or -ENOMEM on failure.
181 */
182int i2o_dma_alloc(struct device *dev, struct i2o_dma *addr, size_t len)
183{
184 struct pci_dev *pdev = to_pci_dev(dev);
185 int dma_64 = 0;
186
187 mutex_lock(&mem_lock);
188 if ((sizeof(dma_addr_t) > 4) && (pdev->dma_mask == DMA_64BIT_MASK)) {
189 dma_64 = 1;
190 if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
191 mutex_unlock(&mem_lock);
192 return -ENOMEM;
193 }
194 }
195
196 addr->virt = dma_alloc_coherent(dev, len, &addr->phys, GFP_KERNEL);
197
198 if ((sizeof(dma_addr_t) > 4) && dma_64)
199 if (pci_set_dma_mask(pdev, DMA_64BIT_MASK))
200 printk(KERN_WARNING "i2o: unable to set 64-bit DMA");
201 mutex_unlock(&mem_lock);
202
203 if (!addr->virt)
204 return -ENOMEM;
205
206 memset(addr->virt, 0, len);
207 addr->len = len;
208
209 return 0;
210}
211EXPORT_SYMBOL_GPL(i2o_dma_alloc);
212
213
214/**
215 * i2o_dma_free - Free DMA memory
216 * @dev: struct device pointer to the PCI device of the I2O controller
217 * @addr: i2o_dma struct which contains the DMA buffer
218 *
219 * Free a coherent DMA memory and set virtual address of addr to NULL.
220 */
221void i2o_dma_free(struct device *dev, struct i2o_dma *addr)
222{
223 if (addr->virt) {
224 if (addr->phys)
225 dma_free_coherent(dev, addr->len, addr->virt,
226 addr->phys);
227 else
228 kfree(addr->virt);
229 addr->virt = NULL;
230 }
231}
232EXPORT_SYMBOL_GPL(i2o_dma_free);
233
234
235/**
236 * i2o_dma_realloc - Realloc DMA memory
237 * @dev: struct device pointer to the PCI device of the I2O controller
238 * @addr: pointer to a i2o_dma struct DMA buffer
239 * @len: new length of memory
240 *
241 * If there was something allocated in the addr, free it first. If len > 0
242 * than try to allocate it and write the addresses back to the addr
243 * structure. If len == 0 set the virtual address to NULL.
244 *
245 * Returns the 0 on success or negative error code on failure.
246 */
247int i2o_dma_realloc(struct device *dev, struct i2o_dma *addr, size_t len)
248{
249 i2o_dma_free(dev, addr);
250
251 if (len)
252 return i2o_dma_alloc(dev, addr, len);
253
254 return 0;
255}
256EXPORT_SYMBOL_GPL(i2o_dma_realloc);
257
258/*
259 * i2o_pool_alloc - Allocate an slab cache and mempool
260 * @mempool: pointer to struct i2o_pool to write data into.
261 * @name: name which is used to identify cache
262 * @size: size of each object
263 * @min_nr: minimum number of objects
264 *
265 * First allocates a slab cache with name and size. Then allocates a
266 * mempool which uses the slab cache for allocation and freeing.
267 *
268 * Returns 0 on success or negative error code on failure.
269 */
270int i2o_pool_alloc(struct i2o_pool *pool, const char *name,
271 size_t size, int min_nr)
272{
273 pool->name = kmalloc(strlen(name) + 1, GFP_KERNEL);
274 if (!pool->name)
275 goto exit;
276 strcpy(pool->name, name);
277
278 pool->slab =
279 kmem_cache_create(pool->name, size, 0, SLAB_HWCACHE_ALIGN, NULL);
280 if (!pool->slab)
281 goto free_name;
282
283 pool->mempool = mempool_create_slab_pool(min_nr, pool->slab);
284 if (!pool->mempool)
285 goto free_slab;
286
287 return 0;
288
289free_slab:
290 kmem_cache_destroy(pool->slab);
291
292free_name:
293 kfree(pool->name);
294
295exit:
296 return -ENOMEM;
297}
298EXPORT_SYMBOL_GPL(i2o_pool_alloc);
299
300/*
301 * i2o_pool_free - Free slab cache and mempool again
302 * @mempool: pointer to struct i2o_pool which should be freed
303 *
304 * Note that you have to return all objects to the mempool again before
305 * calling i2o_pool_free().
306 */
307void i2o_pool_free(struct i2o_pool *pool)
308{
309 mempool_destroy(pool->mempool);
310 kmem_cache_destroy(pool->slab);
311 kfree(pool->name);
312};
313EXPORT_SYMBOL_GPL(i2o_pool_free);
diff --git a/drivers/message/i2o/pci.c b/drivers/message/i2o/pci.c
index 685a89547a51..610ef1204e68 100644
--- a/drivers/message/i2o/pci.c
+++ b/drivers/message/i2o/pci.c
@@ -186,31 +186,29 @@ static int __devinit i2o_pci_alloc(struct i2o_controller *c)
186 } 186 }
187 } 187 }
188 188
189 if (i2o_dma_alloc(dev, &c->status, 8, GFP_KERNEL)) { 189 if (i2o_dma_alloc(dev, &c->status, 8)) {
190 i2o_pci_free(c); 190 i2o_pci_free(c);
191 return -ENOMEM; 191 return -ENOMEM;
192 } 192 }
193 193
194 if (i2o_dma_alloc(dev, &c->hrt, sizeof(i2o_hrt), GFP_KERNEL)) { 194 if (i2o_dma_alloc(dev, &c->hrt, sizeof(i2o_hrt))) {
195 i2o_pci_free(c); 195 i2o_pci_free(c);
196 return -ENOMEM; 196 return -ENOMEM;
197 } 197 }
198 198
199 if (i2o_dma_alloc(dev, &c->dlct, 8192, GFP_KERNEL)) { 199 if (i2o_dma_alloc(dev, &c->dlct, 8192)) {
200 i2o_pci_free(c); 200 i2o_pci_free(c);
201 return -ENOMEM; 201 return -ENOMEM;
202 } 202 }
203 203
204 if (i2o_dma_alloc(dev, &c->status_block, sizeof(i2o_status_block), 204 if (i2o_dma_alloc(dev, &c->status_block, sizeof(i2o_status_block))) {
205 GFP_KERNEL)) {
206 i2o_pci_free(c); 205 i2o_pci_free(c);
207 return -ENOMEM; 206 return -ENOMEM;
208 } 207 }
209 208
210 if (i2o_dma_alloc 209 if (i2o_dma_alloc(dev, &c->out_queue,
211 (dev, &c->out_queue, 210 I2O_MAX_OUTBOUND_MSG_FRAMES * I2O_OUTBOUND_MSG_FRAME_SIZE *
212 I2O_MAX_OUTBOUND_MSG_FRAMES * I2O_OUTBOUND_MSG_FRAME_SIZE * 211 sizeof(u32))) {
213 sizeof(u32), GFP_KERNEL)) {
214 i2o_pci_free(c); 212 i2o_pci_free(c);
215 return -ENOMEM; 213 return -ENOMEM;
216 } 214 }
diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 0dae245c6259..5eff8ad834d6 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -87,6 +87,44 @@ config MFD_TC6393XB
87 help 87 help
88 Support for Toshiba Mobile IO Controller TC6393XB 88 Support for Toshiba Mobile IO Controller TC6393XB
89 89
90config MFD_WM8400
91 tristate "Support Wolfson Microelectronics WM8400"
92 help
93 Support for the Wolfson Microelecronics WM8400 PMIC and audio
94 CODEC. This driver adds provides common support for accessing
95 the device, additional drivers must be enabled in order to use
96 the functionality of the device.
97
98config MFD_WM8350
99 tristate
100
101config MFD_WM8350_CONFIG_MODE_0
102 bool
103 depends on MFD_WM8350
104
105config MFD_WM8350_CONFIG_MODE_1
106 bool
107 depends on MFD_WM8350
108
109config MFD_WM8350_CONFIG_MODE_2
110 bool
111 depends on MFD_WM8350
112
113config MFD_WM8350_CONFIG_MODE_3
114 bool
115 depends on MFD_WM8350
116
117config MFD_WM8350_I2C
118 tristate "Support Wolfson Microelectronics WM8350 with I2C"
119 select MFD_WM8350
120 depends on I2C
121 help
122 The WM8350 is an integrated audio and power management
123 subsystem with watchdog and RTC functionality for embedded
124 systems. This option enables core support for the WM8350 with
125 I2C as the control interface. Additional options must be
126 selected to enable support for the functionality of the chip.
127
90endmenu 128endmenu
91 129
92menu "Multimedia Capabilities Port drivers" 130menu "Multimedia Capabilities Port drivers"
diff --git a/drivers/mfd/Makefile b/drivers/mfd/Makefile
index 6abebe364419..759b1fe1c891 100644
--- a/drivers/mfd/Makefile
+++ b/drivers/mfd/Makefile
@@ -12,6 +12,11 @@ obj-$(CONFIG_MFD_T7L66XB) += t7l66xb.o
12obj-$(CONFIG_MFD_TC6387XB) += tc6387xb.o 12obj-$(CONFIG_MFD_TC6387XB) += tc6387xb.o
13obj-$(CONFIG_MFD_TC6393XB) += tc6393xb.o 13obj-$(CONFIG_MFD_TC6393XB) += tc6393xb.o
14 14
15obj-$(CONFIG_MFD_WM8400) += wm8400-core.o
16wm8350-objs := wm8350-core.o wm8350-regmap.o wm8350-gpio.o
17obj-$(CONFIG_MFD_WM8350) += wm8350.o
18obj-$(CONFIG_MFD_WM8350_I2C) += wm8350-i2c.o
19
15obj-$(CONFIG_MFD_CORE) += mfd-core.o 20obj-$(CONFIG_MFD_CORE) += mfd-core.o
16 21
17obj-$(CONFIG_MCP) += mcp-core.o 22obj-$(CONFIG_MCP) += mcp-core.o
diff --git a/drivers/mfd/wm8350-core.c b/drivers/mfd/wm8350-core.c
new file mode 100644
index 000000000000..25a7a5d08bce
--- /dev/null
+++ b/drivers/mfd/wm8350-core.c
@@ -0,0 +1,1273 @@
1/*
2 * wm8350-core.c -- Device access for Wolfson WM8350
3 *
4 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
5 *
6 * Author: Liam Girdwood, Mark Brown
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 */
14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/init.h>
18#include <linux/bug.h>
19#include <linux/device.h>
20#include <linux/delay.h>
21#include <linux/interrupt.h>
22#include <linux/workqueue.h>
23
24#include <linux/mfd/wm8350/core.h>
25#include <linux/mfd/wm8350/audio.h>
26#include <linux/mfd/wm8350/comparator.h>
27#include <linux/mfd/wm8350/gpio.h>
28#include <linux/mfd/wm8350/pmic.h>
29#include <linux/mfd/wm8350/rtc.h>
30#include <linux/mfd/wm8350/supply.h>
31#include <linux/mfd/wm8350/wdt.h>
32
33#define WM8350_UNLOCK_KEY 0x0013
34#define WM8350_LOCK_KEY 0x0000
35
36#define WM8350_CLOCK_CONTROL_1 0x28
37#define WM8350_AIF_TEST 0x74
38
39/* debug */
40#define WM8350_BUS_DEBUG 0
41#if WM8350_BUS_DEBUG
42#define dump(regs, src) do { \
43 int i_; \
44 u16 *src_ = src; \
45 printk(KERN_DEBUG); \
46 for (i_ = 0; i_ < regs; i_++) \
47 printk(" 0x%4.4x", *src_++); \
48 printk("\n"); \
49} while (0);
50#else
51#define dump(bytes, src)
52#endif
53
54#define WM8350_LOCK_DEBUG 0
55#if WM8350_LOCK_DEBUG
56#define ldbg(format, arg...) printk(format, ## arg)
57#else
58#define ldbg(format, arg...)
59#endif
60
61/*
62 * WM8350 Device IO
63 */
64static DEFINE_MUTEX(io_mutex);
65static DEFINE_MUTEX(reg_lock_mutex);
66static DEFINE_MUTEX(auxadc_mutex);
67
68/* Perform a physical read from the device.
69 */
70static int wm8350_phys_read(struct wm8350 *wm8350, u8 reg, int num_regs,
71 u16 *dest)
72{
73 int i, ret;
74 int bytes = num_regs * 2;
75
76 dev_dbg(wm8350->dev, "volatile read\n");
77 ret = wm8350->read_dev(wm8350, reg, bytes, (char *)dest);
78
79 for (i = reg; i < reg + num_regs; i++) {
80 /* Cache is CPU endian */
81 dest[i - reg] = be16_to_cpu(dest[i - reg]);
82
83 /* Satisfy non-volatile bits from cache */
84 dest[i - reg] &= wm8350_reg_io_map[i].vol;
85 dest[i - reg] |= wm8350->reg_cache[i];
86
87 /* Mask out non-readable bits */
88 dest[i - reg] &= wm8350_reg_io_map[i].readable;
89 }
90
91 dump(num_regs, dest);
92
93 return ret;
94}
95
96static int wm8350_read(struct wm8350 *wm8350, u8 reg, int num_regs, u16 *dest)
97{
98 int i;
99 int end = reg + num_regs;
100 int ret = 0;
101 int bytes = num_regs * 2;
102
103 if (wm8350->read_dev == NULL)
104 return -ENODEV;
105
106 if ((reg + num_regs - 1) > WM8350_MAX_REGISTER) {
107 dev_err(wm8350->dev, "invalid reg %x\n",
108 reg + num_regs - 1);
109 return -EINVAL;
110 }
111
112 dev_dbg(wm8350->dev,
113 "%s R%d(0x%2.2x) %d regs\n", __func__, reg, reg, num_regs);
114
115#if WM8350_BUS_DEBUG
116 /* we can _safely_ read any register, but warn if read not supported */
117 for (i = reg; i < end; i++) {
118 if (!wm8350_reg_io_map[i].readable)
119 dev_warn(wm8350->dev,
120 "reg R%d is not readable\n", i);
121 }
122#endif
123
124 /* if any volatile registers are required, then read back all */
125 for (i = reg; i < end; i++)
126 if (wm8350_reg_io_map[i].vol)
127 return wm8350_phys_read(wm8350, reg, num_regs, dest);
128
129 /* no volatiles, then cache is good */
130 dev_dbg(wm8350->dev, "cache read\n");
131 memcpy(dest, &wm8350->reg_cache[reg], bytes);
132 dump(num_regs, dest);
133 return ret;
134}
135
136static inline int is_reg_locked(struct wm8350 *wm8350, u8 reg)
137{
138 if (reg == WM8350_SECURITY ||
139 wm8350->reg_cache[WM8350_SECURITY] == WM8350_UNLOCK_KEY)
140 return 0;
141
142 if ((reg == WM8350_GPIO_CONFIGURATION_I_O) ||
143 (reg >= WM8350_GPIO_FUNCTION_SELECT_1 &&
144 reg <= WM8350_GPIO_FUNCTION_SELECT_4) ||
145 (reg >= WM8350_BATTERY_CHARGER_CONTROL_1 &&
146 reg <= WM8350_BATTERY_CHARGER_CONTROL_3))
147 return 1;
148 return 0;
149}
150
151static int wm8350_write(struct wm8350 *wm8350, u8 reg, int num_regs, u16 *src)
152{
153 int i;
154 int end = reg + num_regs;
155 int bytes = num_regs * 2;
156
157 if (wm8350->write_dev == NULL)
158 return -ENODEV;
159
160 if ((reg + num_regs - 1) > WM8350_MAX_REGISTER) {
161 dev_err(wm8350->dev, "invalid reg %x\n",
162 reg + num_regs - 1);
163 return -EINVAL;
164 }
165
166 /* it's generally not a good idea to write to RO or locked registers */
167 for (i = reg; i < end; i++) {
168 if (!wm8350_reg_io_map[i].writable) {
169 dev_err(wm8350->dev,
170 "attempted write to read only reg R%d\n", i);
171 return -EINVAL;
172 }
173
174 if (is_reg_locked(wm8350, i)) {
175 dev_err(wm8350->dev,
176 "attempted write to locked reg R%d\n", i);
177 return -EINVAL;
178 }
179
180 src[i - reg] &= wm8350_reg_io_map[i].writable;
181
182 wm8350->reg_cache[i] =
183 (wm8350->reg_cache[i] & ~wm8350_reg_io_map[i].writable)
184 | src[i - reg];
185
186 src[i - reg] = cpu_to_be16(src[i - reg]);
187 }
188
189 /* Actually write it out */
190 return wm8350->write_dev(wm8350, reg, bytes, (char *)src);
191}
192
193/*
194 * Safe read, modify, write methods
195 */
196int wm8350_clear_bits(struct wm8350 *wm8350, u16 reg, u16 mask)
197{
198 u16 data;
199 int err;
200
201 mutex_lock(&io_mutex);
202 err = wm8350_read(wm8350, reg, 1, &data);
203 if (err) {
204 dev_err(wm8350->dev, "read from reg R%d failed\n", reg);
205 goto out;
206 }
207
208 data &= ~mask;
209 err = wm8350_write(wm8350, reg, 1, &data);
210 if (err)
211 dev_err(wm8350->dev, "write to reg R%d failed\n", reg);
212out:
213 mutex_unlock(&io_mutex);
214 return err;
215}
216EXPORT_SYMBOL_GPL(wm8350_clear_bits);
217
218int wm8350_set_bits(struct wm8350 *wm8350, u16 reg, u16 mask)
219{
220 u16 data;
221 int err;
222
223 mutex_lock(&io_mutex);
224 err = wm8350_read(wm8350, reg, 1, &data);
225 if (err) {
226 dev_err(wm8350->dev, "read from reg R%d failed\n", reg);
227 goto out;
228 }
229
230 data |= mask;
231 err = wm8350_write(wm8350, reg, 1, &data);
232 if (err)
233 dev_err(wm8350->dev, "write to reg R%d failed\n", reg);
234out:
235 mutex_unlock(&io_mutex);
236 return err;
237}
238EXPORT_SYMBOL_GPL(wm8350_set_bits);
239
240u16 wm8350_reg_read(struct wm8350 *wm8350, int reg)
241{
242 u16 data;
243 int err;
244
245 mutex_lock(&io_mutex);
246 err = wm8350_read(wm8350, reg, 1, &data);
247 if (err)
248 dev_err(wm8350->dev, "read from reg R%d failed\n", reg);
249
250 mutex_unlock(&io_mutex);
251 return data;
252}
253EXPORT_SYMBOL_GPL(wm8350_reg_read);
254
255int wm8350_reg_write(struct wm8350 *wm8350, int reg, u16 val)
256{
257 int ret;
258 u16 data = val;
259
260 mutex_lock(&io_mutex);
261 ret = wm8350_write(wm8350, reg, 1, &data);
262 if (ret)
263 dev_err(wm8350->dev, "write to reg R%d failed\n", reg);
264 mutex_unlock(&io_mutex);
265 return ret;
266}
267EXPORT_SYMBOL_GPL(wm8350_reg_write);
268
269int wm8350_block_read(struct wm8350 *wm8350, int start_reg, int regs,
270 u16 *dest)
271{
272 int err = 0;
273
274 mutex_lock(&io_mutex);
275 err = wm8350_read(wm8350, start_reg, regs, dest);
276 if (err)
277 dev_err(wm8350->dev, "block read starting from R%d failed\n",
278 start_reg);
279 mutex_unlock(&io_mutex);
280 return err;
281}
282EXPORT_SYMBOL_GPL(wm8350_block_read);
283
284int wm8350_block_write(struct wm8350 *wm8350, int start_reg, int regs,
285 u16 *src)
286{
287 int ret = 0;
288
289 mutex_lock(&io_mutex);
290 ret = wm8350_write(wm8350, start_reg, regs, src);
291 if (ret)
292 dev_err(wm8350->dev, "block write starting at R%d failed\n",
293 start_reg);
294 mutex_unlock(&io_mutex);
295 return ret;
296}
297EXPORT_SYMBOL_GPL(wm8350_block_write);
298
299int wm8350_reg_lock(struct wm8350 *wm8350)
300{
301 u16 key = WM8350_LOCK_KEY;
302 int ret;
303
304 ldbg(__func__);
305 mutex_lock(&io_mutex);
306 ret = wm8350_write(wm8350, WM8350_SECURITY, 1, &key);
307 if (ret)
308 dev_err(wm8350->dev, "lock failed\n");
309 mutex_unlock(&io_mutex);
310 return ret;
311}
312EXPORT_SYMBOL_GPL(wm8350_reg_lock);
313
314int wm8350_reg_unlock(struct wm8350 *wm8350)
315{
316 u16 key = WM8350_UNLOCK_KEY;
317 int ret;
318
319 ldbg(__func__);
320 mutex_lock(&io_mutex);
321 ret = wm8350_write(wm8350, WM8350_SECURITY, 1, &key);
322 if (ret)
323 dev_err(wm8350->dev, "unlock failed\n");
324 mutex_unlock(&io_mutex);
325 return ret;
326}
327EXPORT_SYMBOL_GPL(wm8350_reg_unlock);
328
329static void wm8350_irq_call_handler(struct wm8350 *wm8350, int irq)
330{
331 mutex_lock(&wm8350->irq_mutex);
332
333 if (wm8350->irq[irq].handler)
334 wm8350->irq[irq].handler(wm8350, irq, wm8350->irq[irq].data);
335 else {
336 dev_err(wm8350->dev, "irq %d nobody cared. now masked.\n",
337 irq);
338 wm8350_mask_irq(wm8350, irq);
339 }
340
341 mutex_unlock(&wm8350->irq_mutex);
342}
343
344/*
345 * wm8350_irq_worker actually handles the interrupts. Since all
346 * interrupts are clear on read the IRQ line will be reasserted and
347 * the physical IRQ will be handled again if another interrupt is
348 * asserted while we run - in the normal course of events this is a
349 * rare occurrence so we save I2C/SPI reads.
350 */
351static void wm8350_irq_worker(struct work_struct *work)
352{
353 struct wm8350 *wm8350 = container_of(work, struct wm8350, irq_work);
354 u16 level_one, status1, status2, comp;
355
356 /* TODO: Use block reads to improve performance? */
357 level_one = wm8350_reg_read(wm8350, WM8350_SYSTEM_INTERRUPTS)
358 & ~wm8350_reg_read(wm8350, WM8350_SYSTEM_INTERRUPTS_MASK);
359 status1 = wm8350_reg_read(wm8350, WM8350_INT_STATUS_1)
360 & ~wm8350_reg_read(wm8350, WM8350_INT_STATUS_1_MASK);
361 status2 = wm8350_reg_read(wm8350, WM8350_INT_STATUS_2)
362 & ~wm8350_reg_read(wm8350, WM8350_INT_STATUS_2_MASK);
363 comp = wm8350_reg_read(wm8350, WM8350_COMPARATOR_INT_STATUS)
364 & ~wm8350_reg_read(wm8350, WM8350_COMPARATOR_INT_STATUS_MASK);
365
366 /* over current */
367 if (level_one & WM8350_OC_INT) {
368 u16 oc;
369
370 oc = wm8350_reg_read(wm8350, WM8350_OVER_CURRENT_INT_STATUS);
371 oc &= ~wm8350_reg_read(wm8350,
372 WM8350_OVER_CURRENT_INT_STATUS_MASK);
373
374 if (oc & WM8350_OC_LS_EINT) /* limit switch */
375 wm8350_irq_call_handler(wm8350, WM8350_IRQ_OC_LS);
376 }
377
378 /* under voltage */
379 if (level_one & WM8350_UV_INT) {
380 u16 uv;
381
382 uv = wm8350_reg_read(wm8350, WM8350_UNDER_VOLTAGE_INT_STATUS);
383 uv &= ~wm8350_reg_read(wm8350,
384 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK);
385
386 if (uv & WM8350_UV_DC1_EINT)
387 wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC1);
388 if (uv & WM8350_UV_DC2_EINT)
389 wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC2);
390 if (uv & WM8350_UV_DC3_EINT)
391 wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC3);
392 if (uv & WM8350_UV_DC4_EINT)
393 wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC4);
394 if (uv & WM8350_UV_DC5_EINT)
395 wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC5);
396 if (uv & WM8350_UV_DC6_EINT)
397 wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC6);
398 if (uv & WM8350_UV_LDO1_EINT)
399 wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_LDO1);
400 if (uv & WM8350_UV_LDO2_EINT)
401 wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_LDO2);
402 if (uv & WM8350_UV_LDO3_EINT)
403 wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_LDO3);
404 if (uv & WM8350_UV_LDO4_EINT)
405 wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_LDO4);
406 }
407
408 /* charger, RTC */
409 if (status1) {
410 if (status1 & WM8350_CHG_BAT_HOT_EINT)
411 wm8350_irq_call_handler(wm8350,
412 WM8350_IRQ_CHG_BAT_HOT);
413 if (status1 & WM8350_CHG_BAT_COLD_EINT)
414 wm8350_irq_call_handler(wm8350,
415 WM8350_IRQ_CHG_BAT_COLD);
416 if (status1 & WM8350_CHG_BAT_FAIL_EINT)
417 wm8350_irq_call_handler(wm8350,
418 WM8350_IRQ_CHG_BAT_FAIL);
419 if (status1 & WM8350_CHG_TO_EINT)
420 wm8350_irq_call_handler(wm8350, WM8350_IRQ_CHG_TO);
421 if (status1 & WM8350_CHG_END_EINT)
422 wm8350_irq_call_handler(wm8350, WM8350_IRQ_CHG_END);
423 if (status1 & WM8350_CHG_START_EINT)
424 wm8350_irq_call_handler(wm8350, WM8350_IRQ_CHG_START);
425 if (status1 & WM8350_CHG_FAST_RDY_EINT)
426 wm8350_irq_call_handler(wm8350,
427 WM8350_IRQ_CHG_FAST_RDY);
428 if (status1 & WM8350_CHG_VBATT_LT_3P9_EINT)
429 wm8350_irq_call_handler(wm8350,
430 WM8350_IRQ_CHG_VBATT_LT_3P9);
431 if (status1 & WM8350_CHG_VBATT_LT_3P1_EINT)
432 wm8350_irq_call_handler(wm8350,
433 WM8350_IRQ_CHG_VBATT_LT_3P1);
434 if (status1 & WM8350_CHG_VBATT_LT_2P85_EINT)
435 wm8350_irq_call_handler(wm8350,
436 WM8350_IRQ_CHG_VBATT_LT_2P85);
437 if (status1 & WM8350_RTC_ALM_EINT)
438 wm8350_irq_call_handler(wm8350, WM8350_IRQ_RTC_ALM);
439 if (status1 & WM8350_RTC_SEC_EINT)
440 wm8350_irq_call_handler(wm8350, WM8350_IRQ_RTC_SEC);
441 if (status1 & WM8350_RTC_PER_EINT)
442 wm8350_irq_call_handler(wm8350, WM8350_IRQ_RTC_PER);
443 }
444
445 /* current sink, system, aux adc */
446 if (status2) {
447 if (status2 & WM8350_CS1_EINT)
448 wm8350_irq_call_handler(wm8350, WM8350_IRQ_CS1);
449 if (status2 & WM8350_CS2_EINT)
450 wm8350_irq_call_handler(wm8350, WM8350_IRQ_CS2);
451
452 if (status2 & WM8350_SYS_HYST_COMP_FAIL_EINT)
453 wm8350_irq_call_handler(wm8350,
454 WM8350_IRQ_SYS_HYST_COMP_FAIL);
455 if (status2 & WM8350_SYS_CHIP_GT115_EINT)
456 wm8350_irq_call_handler(wm8350,
457 WM8350_IRQ_SYS_CHIP_GT115);
458 if (status2 & WM8350_SYS_CHIP_GT140_EINT)
459 wm8350_irq_call_handler(wm8350,
460 WM8350_IRQ_SYS_CHIP_GT140);
461 if (status2 & WM8350_SYS_WDOG_TO_EINT)
462 wm8350_irq_call_handler(wm8350,
463 WM8350_IRQ_SYS_WDOG_TO);
464
465 if (status2 & WM8350_AUXADC_DATARDY_EINT)
466 wm8350_irq_call_handler(wm8350,
467 WM8350_IRQ_AUXADC_DATARDY);
468 if (status2 & WM8350_AUXADC_DCOMP4_EINT)
469 wm8350_irq_call_handler(wm8350,
470 WM8350_IRQ_AUXADC_DCOMP4);
471 if (status2 & WM8350_AUXADC_DCOMP3_EINT)
472 wm8350_irq_call_handler(wm8350,
473 WM8350_IRQ_AUXADC_DCOMP3);
474 if (status2 & WM8350_AUXADC_DCOMP2_EINT)
475 wm8350_irq_call_handler(wm8350,
476 WM8350_IRQ_AUXADC_DCOMP2);
477 if (status2 & WM8350_AUXADC_DCOMP1_EINT)
478 wm8350_irq_call_handler(wm8350,
479 WM8350_IRQ_AUXADC_DCOMP1);
480
481 if (status2 & WM8350_USB_LIMIT_EINT)
482 wm8350_irq_call_handler(wm8350, WM8350_IRQ_USB_LIMIT);
483 }
484
485 /* wake, codec, ext */
486 if (comp) {
487 if (comp & WM8350_WKUP_OFF_STATE_EINT)
488 wm8350_irq_call_handler(wm8350,
489 WM8350_IRQ_WKUP_OFF_STATE);
490 if (comp & WM8350_WKUP_HIB_STATE_EINT)
491 wm8350_irq_call_handler(wm8350,
492 WM8350_IRQ_WKUP_HIB_STATE);
493 if (comp & WM8350_WKUP_CONV_FAULT_EINT)
494 wm8350_irq_call_handler(wm8350,
495 WM8350_IRQ_WKUP_CONV_FAULT);
496 if (comp & WM8350_WKUP_WDOG_RST_EINT)
497 wm8350_irq_call_handler(wm8350,
498 WM8350_IRQ_WKUP_WDOG_RST);
499 if (comp & WM8350_WKUP_GP_PWR_ON_EINT)
500 wm8350_irq_call_handler(wm8350,
501 WM8350_IRQ_WKUP_GP_PWR_ON);
502 if (comp & WM8350_WKUP_ONKEY_EINT)
503 wm8350_irq_call_handler(wm8350, WM8350_IRQ_WKUP_ONKEY);
504 if (comp & WM8350_WKUP_GP_WAKEUP_EINT)
505 wm8350_irq_call_handler(wm8350,
506 WM8350_IRQ_WKUP_GP_WAKEUP);
507
508 if (comp & WM8350_CODEC_JCK_DET_L_EINT)
509 wm8350_irq_call_handler(wm8350,
510 WM8350_IRQ_CODEC_JCK_DET_L);
511 if (comp & WM8350_CODEC_JCK_DET_R_EINT)
512 wm8350_irq_call_handler(wm8350,
513 WM8350_IRQ_CODEC_JCK_DET_R);
514 if (comp & WM8350_CODEC_MICSCD_EINT)
515 wm8350_irq_call_handler(wm8350,
516 WM8350_IRQ_CODEC_MICSCD);
517 if (comp & WM8350_CODEC_MICD_EINT)
518 wm8350_irq_call_handler(wm8350, WM8350_IRQ_CODEC_MICD);
519
520 if (comp & WM8350_EXT_USB_FB_EINT)
521 wm8350_irq_call_handler(wm8350, WM8350_IRQ_EXT_USB_FB);
522 if (comp & WM8350_EXT_WALL_FB_EINT)
523 wm8350_irq_call_handler(wm8350,
524 WM8350_IRQ_EXT_WALL_FB);
525 if (comp & WM8350_EXT_BAT_FB_EINT)
526 wm8350_irq_call_handler(wm8350, WM8350_IRQ_EXT_BAT_FB);
527 }
528
529 if (level_one & WM8350_GP_INT) {
530 int i;
531 u16 gpio;
532
533 gpio = wm8350_reg_read(wm8350, WM8350_GPIO_INT_STATUS);
534 gpio &= ~wm8350_reg_read(wm8350,
535 WM8350_GPIO_INT_STATUS_MASK);
536
537 for (i = 0; i < 12; i++) {
538 if (gpio & (1 << i))
539 wm8350_irq_call_handler(wm8350,
540 WM8350_IRQ_GPIO(i));
541 }
542 }
543
544 enable_irq(wm8350->chip_irq);
545}
546
547static irqreturn_t wm8350_irq(int irq, void *data)
548{
549 struct wm8350 *wm8350 = data;
550
551 disable_irq_nosync(irq);
552 schedule_work(&wm8350->irq_work);
553
554 return IRQ_HANDLED;
555}
556
557int wm8350_register_irq(struct wm8350 *wm8350, int irq,
558 void (*handler) (struct wm8350 *, int, void *),
559 void *data)
560{
561 if (irq < 0 || irq > WM8350_NUM_IRQ || !handler)
562 return -EINVAL;
563
564 if (wm8350->irq[irq].handler)
565 return -EBUSY;
566
567 mutex_lock(&wm8350->irq_mutex);
568 wm8350->irq[irq].handler = handler;
569 wm8350->irq[irq].data = data;
570 mutex_unlock(&wm8350->irq_mutex);
571
572 return 0;
573}
574EXPORT_SYMBOL_GPL(wm8350_register_irq);
575
576int wm8350_free_irq(struct wm8350 *wm8350, int irq)
577{
578 if (irq < 0 || irq > WM8350_NUM_IRQ)
579 return -EINVAL;
580
581 mutex_lock(&wm8350->irq_mutex);
582 wm8350->irq[irq].handler = NULL;
583 mutex_unlock(&wm8350->irq_mutex);
584 return 0;
585}
586EXPORT_SYMBOL_GPL(wm8350_free_irq);
587
588int wm8350_mask_irq(struct wm8350 *wm8350, int irq)
589{
590 switch (irq) {
591 case WM8350_IRQ_CHG_BAT_HOT:
592 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
593 WM8350_IM_CHG_BAT_HOT_EINT);
594 case WM8350_IRQ_CHG_BAT_COLD:
595 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
596 WM8350_IM_CHG_BAT_COLD_EINT);
597 case WM8350_IRQ_CHG_BAT_FAIL:
598 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
599 WM8350_IM_CHG_BAT_FAIL_EINT);
600 case WM8350_IRQ_CHG_TO:
601 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
602 WM8350_IM_CHG_TO_EINT);
603 case WM8350_IRQ_CHG_END:
604 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
605 WM8350_IM_CHG_END_EINT);
606 case WM8350_IRQ_CHG_START:
607 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
608 WM8350_IM_CHG_START_EINT);
609 case WM8350_IRQ_CHG_FAST_RDY:
610 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
611 WM8350_IM_CHG_FAST_RDY_EINT);
612 case WM8350_IRQ_RTC_PER:
613 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
614 WM8350_IM_RTC_PER_EINT);
615 case WM8350_IRQ_RTC_SEC:
616 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
617 WM8350_IM_RTC_SEC_EINT);
618 case WM8350_IRQ_RTC_ALM:
619 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
620 WM8350_IM_RTC_ALM_EINT);
621 case WM8350_IRQ_CHG_VBATT_LT_3P9:
622 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
623 WM8350_IM_CHG_VBATT_LT_3P9_EINT);
624 case WM8350_IRQ_CHG_VBATT_LT_3P1:
625 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
626 WM8350_IM_CHG_VBATT_LT_3P1_EINT);
627 case WM8350_IRQ_CHG_VBATT_LT_2P85:
628 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
629 WM8350_IM_CHG_VBATT_LT_2P85_EINT);
630 case WM8350_IRQ_CS1:
631 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
632 WM8350_IM_CS1_EINT);
633 case WM8350_IRQ_CS2:
634 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
635 WM8350_IM_CS2_EINT);
636 case WM8350_IRQ_USB_LIMIT:
637 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
638 WM8350_IM_USB_LIMIT_EINT);
639 case WM8350_IRQ_AUXADC_DATARDY:
640 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
641 WM8350_IM_AUXADC_DATARDY_EINT);
642 case WM8350_IRQ_AUXADC_DCOMP4:
643 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
644 WM8350_IM_AUXADC_DCOMP4_EINT);
645 case WM8350_IRQ_AUXADC_DCOMP3:
646 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
647 WM8350_IM_AUXADC_DCOMP3_EINT);
648 case WM8350_IRQ_AUXADC_DCOMP2:
649 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
650 WM8350_IM_AUXADC_DCOMP2_EINT);
651 case WM8350_IRQ_AUXADC_DCOMP1:
652 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
653 WM8350_IM_AUXADC_DCOMP1_EINT);
654 case WM8350_IRQ_SYS_HYST_COMP_FAIL:
655 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
656 WM8350_IM_SYS_HYST_COMP_FAIL_EINT);
657 case WM8350_IRQ_SYS_CHIP_GT115:
658 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
659 WM8350_IM_SYS_CHIP_GT115_EINT);
660 case WM8350_IRQ_SYS_CHIP_GT140:
661 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
662 WM8350_IM_SYS_CHIP_GT140_EINT);
663 case WM8350_IRQ_SYS_WDOG_TO:
664 return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
665 WM8350_IM_SYS_WDOG_TO_EINT);
666 case WM8350_IRQ_UV_LDO4:
667 return wm8350_set_bits(wm8350,
668 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
669 WM8350_IM_UV_LDO4_EINT);
670 case WM8350_IRQ_UV_LDO3:
671 return wm8350_set_bits(wm8350,
672 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
673 WM8350_IM_UV_LDO3_EINT);
674 case WM8350_IRQ_UV_LDO2:
675 return wm8350_set_bits(wm8350,
676 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
677 WM8350_IM_UV_LDO2_EINT);
678 case WM8350_IRQ_UV_LDO1:
679 return wm8350_set_bits(wm8350,
680 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
681 WM8350_IM_UV_LDO1_EINT);
682 case WM8350_IRQ_UV_DC6:
683 return wm8350_set_bits(wm8350,
684 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
685 WM8350_IM_UV_DC6_EINT);
686 case WM8350_IRQ_UV_DC5:
687 return wm8350_set_bits(wm8350,
688 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
689 WM8350_IM_UV_DC5_EINT);
690 case WM8350_IRQ_UV_DC4:
691 return wm8350_set_bits(wm8350,
692 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
693 WM8350_IM_UV_DC4_EINT);
694 case WM8350_IRQ_UV_DC3:
695 return wm8350_set_bits(wm8350,
696 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
697 WM8350_IM_UV_DC3_EINT);
698 case WM8350_IRQ_UV_DC2:
699 return wm8350_set_bits(wm8350,
700 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
701 WM8350_IM_UV_DC2_EINT);
702 case WM8350_IRQ_UV_DC1:
703 return wm8350_set_bits(wm8350,
704 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
705 WM8350_IM_UV_DC1_EINT);
706 case WM8350_IRQ_OC_LS:
707 return wm8350_set_bits(wm8350,
708 WM8350_OVER_CURRENT_INT_STATUS_MASK,
709 WM8350_IM_OC_LS_EINT);
710 case WM8350_IRQ_EXT_USB_FB:
711 return wm8350_set_bits(wm8350,
712 WM8350_COMPARATOR_INT_STATUS_MASK,
713 WM8350_IM_EXT_USB_FB_EINT);
714 case WM8350_IRQ_EXT_WALL_FB:
715 return wm8350_set_bits(wm8350,
716 WM8350_COMPARATOR_INT_STATUS_MASK,
717 WM8350_IM_EXT_WALL_FB_EINT);
718 case WM8350_IRQ_EXT_BAT_FB:
719 return wm8350_set_bits(wm8350,
720 WM8350_COMPARATOR_INT_STATUS_MASK,
721 WM8350_IM_EXT_BAT_FB_EINT);
722 case WM8350_IRQ_CODEC_JCK_DET_L:
723 return wm8350_set_bits(wm8350,
724 WM8350_COMPARATOR_INT_STATUS_MASK,
725 WM8350_IM_CODEC_JCK_DET_L_EINT);
726 case WM8350_IRQ_CODEC_JCK_DET_R:
727 return wm8350_set_bits(wm8350,
728 WM8350_COMPARATOR_INT_STATUS_MASK,
729 WM8350_IM_CODEC_JCK_DET_R_EINT);
730 case WM8350_IRQ_CODEC_MICSCD:
731 return wm8350_set_bits(wm8350,
732 WM8350_COMPARATOR_INT_STATUS_MASK,
733 WM8350_IM_CODEC_MICSCD_EINT);
734 case WM8350_IRQ_CODEC_MICD:
735 return wm8350_set_bits(wm8350,
736 WM8350_COMPARATOR_INT_STATUS_MASK,
737 WM8350_IM_CODEC_MICD_EINT);
738 case WM8350_IRQ_WKUP_OFF_STATE:
739 return wm8350_set_bits(wm8350,
740 WM8350_COMPARATOR_INT_STATUS_MASK,
741 WM8350_IM_WKUP_OFF_STATE_EINT);
742 case WM8350_IRQ_WKUP_HIB_STATE:
743 return wm8350_set_bits(wm8350,
744 WM8350_COMPARATOR_INT_STATUS_MASK,
745 WM8350_IM_WKUP_HIB_STATE_EINT);
746 case WM8350_IRQ_WKUP_CONV_FAULT:
747 return wm8350_set_bits(wm8350,
748 WM8350_COMPARATOR_INT_STATUS_MASK,
749 WM8350_IM_WKUP_CONV_FAULT_EINT);
750 case WM8350_IRQ_WKUP_WDOG_RST:
751 return wm8350_set_bits(wm8350,
752 WM8350_COMPARATOR_INT_STATUS_MASK,
753 WM8350_IM_WKUP_OFF_STATE_EINT);
754 case WM8350_IRQ_WKUP_GP_PWR_ON:
755 return wm8350_set_bits(wm8350,
756 WM8350_COMPARATOR_INT_STATUS_MASK,
757 WM8350_IM_WKUP_GP_PWR_ON_EINT);
758 case WM8350_IRQ_WKUP_ONKEY:
759 return wm8350_set_bits(wm8350,
760 WM8350_COMPARATOR_INT_STATUS_MASK,
761 WM8350_IM_WKUP_ONKEY_EINT);
762 case WM8350_IRQ_WKUP_GP_WAKEUP:
763 return wm8350_set_bits(wm8350,
764 WM8350_COMPARATOR_INT_STATUS_MASK,
765 WM8350_IM_WKUP_GP_WAKEUP_EINT);
766 case WM8350_IRQ_GPIO(0):
767 return wm8350_set_bits(wm8350,
768 WM8350_GPIO_INT_STATUS_MASK,
769 WM8350_IM_GP0_EINT);
770 case WM8350_IRQ_GPIO(1):
771 return wm8350_set_bits(wm8350,
772 WM8350_GPIO_INT_STATUS_MASK,
773 WM8350_IM_GP1_EINT);
774 case WM8350_IRQ_GPIO(2):
775 return wm8350_set_bits(wm8350,
776 WM8350_GPIO_INT_STATUS_MASK,
777 WM8350_IM_GP2_EINT);
778 case WM8350_IRQ_GPIO(3):
779 return wm8350_set_bits(wm8350,
780 WM8350_GPIO_INT_STATUS_MASK,
781 WM8350_IM_GP3_EINT);
782 case WM8350_IRQ_GPIO(4):
783 return wm8350_set_bits(wm8350,
784 WM8350_GPIO_INT_STATUS_MASK,
785 WM8350_IM_GP4_EINT);
786 case WM8350_IRQ_GPIO(5):
787 return wm8350_set_bits(wm8350,
788 WM8350_GPIO_INT_STATUS_MASK,
789 WM8350_IM_GP5_EINT);
790 case WM8350_IRQ_GPIO(6):
791 return wm8350_set_bits(wm8350,
792 WM8350_GPIO_INT_STATUS_MASK,
793 WM8350_IM_GP6_EINT);
794 case WM8350_IRQ_GPIO(7):
795 return wm8350_set_bits(wm8350,
796 WM8350_GPIO_INT_STATUS_MASK,
797 WM8350_IM_GP7_EINT);
798 case WM8350_IRQ_GPIO(8):
799 return wm8350_set_bits(wm8350,
800 WM8350_GPIO_INT_STATUS_MASK,
801 WM8350_IM_GP8_EINT);
802 case WM8350_IRQ_GPIO(9):
803 return wm8350_set_bits(wm8350,
804 WM8350_GPIO_INT_STATUS_MASK,
805 WM8350_IM_GP9_EINT);
806 case WM8350_IRQ_GPIO(10):
807 return wm8350_set_bits(wm8350,
808 WM8350_GPIO_INT_STATUS_MASK,
809 WM8350_IM_GP10_EINT);
810 case WM8350_IRQ_GPIO(11):
811 return wm8350_set_bits(wm8350,
812 WM8350_GPIO_INT_STATUS_MASK,
813 WM8350_IM_GP11_EINT);
814 case WM8350_IRQ_GPIO(12):
815 return wm8350_set_bits(wm8350,
816 WM8350_GPIO_INT_STATUS_MASK,
817 WM8350_IM_GP12_EINT);
818 default:
819 dev_warn(wm8350->dev, "Attempting to mask unknown IRQ %d\n",
820 irq);
821 return -EINVAL;
822 }
823 return 0;
824}
825EXPORT_SYMBOL_GPL(wm8350_mask_irq);
826
827int wm8350_unmask_irq(struct wm8350 *wm8350, int irq)
828{
829 switch (irq) {
830 case WM8350_IRQ_CHG_BAT_HOT:
831 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
832 WM8350_IM_CHG_BAT_HOT_EINT);
833 case WM8350_IRQ_CHG_BAT_COLD:
834 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
835 WM8350_IM_CHG_BAT_COLD_EINT);
836 case WM8350_IRQ_CHG_BAT_FAIL:
837 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
838 WM8350_IM_CHG_BAT_FAIL_EINT);
839 case WM8350_IRQ_CHG_TO:
840 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
841 WM8350_IM_CHG_TO_EINT);
842 case WM8350_IRQ_CHG_END:
843 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
844 WM8350_IM_CHG_END_EINT);
845 case WM8350_IRQ_CHG_START:
846 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
847 WM8350_IM_CHG_START_EINT);
848 case WM8350_IRQ_CHG_FAST_RDY:
849 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
850 WM8350_IM_CHG_FAST_RDY_EINT);
851 case WM8350_IRQ_RTC_PER:
852 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
853 WM8350_IM_RTC_PER_EINT);
854 case WM8350_IRQ_RTC_SEC:
855 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
856 WM8350_IM_RTC_SEC_EINT);
857 case WM8350_IRQ_RTC_ALM:
858 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
859 WM8350_IM_RTC_ALM_EINT);
860 case WM8350_IRQ_CHG_VBATT_LT_3P9:
861 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
862 WM8350_IM_CHG_VBATT_LT_3P9_EINT);
863 case WM8350_IRQ_CHG_VBATT_LT_3P1:
864 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
865 WM8350_IM_CHG_VBATT_LT_3P1_EINT);
866 case WM8350_IRQ_CHG_VBATT_LT_2P85:
867 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
868 WM8350_IM_CHG_VBATT_LT_2P85_EINT);
869 case WM8350_IRQ_CS1:
870 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
871 WM8350_IM_CS1_EINT);
872 case WM8350_IRQ_CS2:
873 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
874 WM8350_IM_CS2_EINT);
875 case WM8350_IRQ_USB_LIMIT:
876 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
877 WM8350_IM_USB_LIMIT_EINT);
878 case WM8350_IRQ_AUXADC_DATARDY:
879 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
880 WM8350_IM_AUXADC_DATARDY_EINT);
881 case WM8350_IRQ_AUXADC_DCOMP4:
882 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
883 WM8350_IM_AUXADC_DCOMP4_EINT);
884 case WM8350_IRQ_AUXADC_DCOMP3:
885 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
886 WM8350_IM_AUXADC_DCOMP3_EINT);
887 case WM8350_IRQ_AUXADC_DCOMP2:
888 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
889 WM8350_IM_AUXADC_DCOMP2_EINT);
890 case WM8350_IRQ_AUXADC_DCOMP1:
891 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
892 WM8350_IM_AUXADC_DCOMP1_EINT);
893 case WM8350_IRQ_SYS_HYST_COMP_FAIL:
894 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
895 WM8350_IM_SYS_HYST_COMP_FAIL_EINT);
896 case WM8350_IRQ_SYS_CHIP_GT115:
897 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
898 WM8350_IM_SYS_CHIP_GT115_EINT);
899 case WM8350_IRQ_SYS_CHIP_GT140:
900 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
901 WM8350_IM_SYS_CHIP_GT140_EINT);
902 case WM8350_IRQ_SYS_WDOG_TO:
903 return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
904 WM8350_IM_SYS_WDOG_TO_EINT);
905 case WM8350_IRQ_UV_LDO4:
906 return wm8350_clear_bits(wm8350,
907 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
908 WM8350_IM_UV_LDO4_EINT);
909 case WM8350_IRQ_UV_LDO3:
910 return wm8350_clear_bits(wm8350,
911 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
912 WM8350_IM_UV_LDO3_EINT);
913 case WM8350_IRQ_UV_LDO2:
914 return wm8350_clear_bits(wm8350,
915 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
916 WM8350_IM_UV_LDO2_EINT);
917 case WM8350_IRQ_UV_LDO1:
918 return wm8350_clear_bits(wm8350,
919 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
920 WM8350_IM_UV_LDO1_EINT);
921 case WM8350_IRQ_UV_DC6:
922 return wm8350_clear_bits(wm8350,
923 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
924 WM8350_IM_UV_DC6_EINT);
925 case WM8350_IRQ_UV_DC5:
926 return wm8350_clear_bits(wm8350,
927 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
928 WM8350_IM_UV_DC5_EINT);
929 case WM8350_IRQ_UV_DC4:
930 return wm8350_clear_bits(wm8350,
931 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
932 WM8350_IM_UV_DC4_EINT);
933 case WM8350_IRQ_UV_DC3:
934 return wm8350_clear_bits(wm8350,
935 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
936 WM8350_IM_UV_DC3_EINT);
937 case WM8350_IRQ_UV_DC2:
938 return wm8350_clear_bits(wm8350,
939 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
940 WM8350_IM_UV_DC2_EINT);
941 case WM8350_IRQ_UV_DC1:
942 return wm8350_clear_bits(wm8350,
943 WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
944 WM8350_IM_UV_DC1_EINT);
945 case WM8350_IRQ_OC_LS:
946 return wm8350_clear_bits(wm8350,
947 WM8350_OVER_CURRENT_INT_STATUS_MASK,
948 WM8350_IM_OC_LS_EINT);
949 case WM8350_IRQ_EXT_USB_FB:
950 return wm8350_clear_bits(wm8350,
951 WM8350_COMPARATOR_INT_STATUS_MASK,
952 WM8350_IM_EXT_USB_FB_EINT);
953 case WM8350_IRQ_EXT_WALL_FB:
954 return wm8350_clear_bits(wm8350,
955 WM8350_COMPARATOR_INT_STATUS_MASK,
956 WM8350_IM_EXT_WALL_FB_EINT);
957 case WM8350_IRQ_EXT_BAT_FB:
958 return wm8350_clear_bits(wm8350,
959 WM8350_COMPARATOR_INT_STATUS_MASK,
960 WM8350_IM_EXT_BAT_FB_EINT);
961 case WM8350_IRQ_CODEC_JCK_DET_L:
962 return wm8350_clear_bits(wm8350,
963 WM8350_COMPARATOR_INT_STATUS_MASK,
964 WM8350_IM_CODEC_JCK_DET_L_EINT);
965 case WM8350_IRQ_CODEC_JCK_DET_R:
966 return wm8350_clear_bits(wm8350,
967 WM8350_COMPARATOR_INT_STATUS_MASK,
968 WM8350_IM_CODEC_JCK_DET_R_EINT);
969 case WM8350_IRQ_CODEC_MICSCD:
970 return wm8350_clear_bits(wm8350,
971 WM8350_COMPARATOR_INT_STATUS_MASK,
972 WM8350_IM_CODEC_MICSCD_EINT);
973 case WM8350_IRQ_CODEC_MICD:
974 return wm8350_clear_bits(wm8350,
975 WM8350_COMPARATOR_INT_STATUS_MASK,
976 WM8350_IM_CODEC_MICD_EINT);
977 case WM8350_IRQ_WKUP_OFF_STATE:
978 return wm8350_clear_bits(wm8350,
979 WM8350_COMPARATOR_INT_STATUS_MASK,
980 WM8350_IM_WKUP_OFF_STATE_EINT);
981 case WM8350_IRQ_WKUP_HIB_STATE:
982 return wm8350_clear_bits(wm8350,
983 WM8350_COMPARATOR_INT_STATUS_MASK,
984 WM8350_IM_WKUP_HIB_STATE_EINT);
985 case WM8350_IRQ_WKUP_CONV_FAULT:
986 return wm8350_clear_bits(wm8350,
987 WM8350_COMPARATOR_INT_STATUS_MASK,
988 WM8350_IM_WKUP_CONV_FAULT_EINT);
989 case WM8350_IRQ_WKUP_WDOG_RST:
990 return wm8350_clear_bits(wm8350,
991 WM8350_COMPARATOR_INT_STATUS_MASK,
992 WM8350_IM_WKUP_OFF_STATE_EINT);
993 case WM8350_IRQ_WKUP_GP_PWR_ON:
994 return wm8350_clear_bits(wm8350,
995 WM8350_COMPARATOR_INT_STATUS_MASK,
996 WM8350_IM_WKUP_GP_PWR_ON_EINT);
997 case WM8350_IRQ_WKUP_ONKEY:
998 return wm8350_clear_bits(wm8350,
999 WM8350_COMPARATOR_INT_STATUS_MASK,
1000 WM8350_IM_WKUP_ONKEY_EINT);
1001 case WM8350_IRQ_WKUP_GP_WAKEUP:
1002 return wm8350_clear_bits(wm8350,
1003 WM8350_COMPARATOR_INT_STATUS_MASK,
1004 WM8350_IM_WKUP_GP_WAKEUP_EINT);
1005 case WM8350_IRQ_GPIO(0):
1006 return wm8350_clear_bits(wm8350,
1007 WM8350_GPIO_INT_STATUS_MASK,
1008 WM8350_IM_GP0_EINT);
1009 case WM8350_IRQ_GPIO(1):
1010 return wm8350_clear_bits(wm8350,
1011 WM8350_GPIO_INT_STATUS_MASK,
1012 WM8350_IM_GP1_EINT);
1013 case WM8350_IRQ_GPIO(2):
1014 return wm8350_clear_bits(wm8350,
1015 WM8350_GPIO_INT_STATUS_MASK,
1016 WM8350_IM_GP2_EINT);
1017 case WM8350_IRQ_GPIO(3):
1018 return wm8350_clear_bits(wm8350,
1019 WM8350_GPIO_INT_STATUS_MASK,
1020 WM8350_IM_GP3_EINT);
1021 case WM8350_IRQ_GPIO(4):
1022 return wm8350_clear_bits(wm8350,
1023 WM8350_GPIO_INT_STATUS_MASK,
1024 WM8350_IM_GP4_EINT);
1025 case WM8350_IRQ_GPIO(5):
1026 return wm8350_clear_bits(wm8350,
1027 WM8350_GPIO_INT_STATUS_MASK,
1028 WM8350_IM_GP5_EINT);
1029 case WM8350_IRQ_GPIO(6):
1030 return wm8350_clear_bits(wm8350,
1031 WM8350_GPIO_INT_STATUS_MASK,
1032 WM8350_IM_GP6_EINT);
1033 case WM8350_IRQ_GPIO(7):
1034 return wm8350_clear_bits(wm8350,
1035 WM8350_GPIO_INT_STATUS_MASK,
1036 WM8350_IM_GP7_EINT);
1037 case WM8350_IRQ_GPIO(8):
1038 return wm8350_clear_bits(wm8350,
1039 WM8350_GPIO_INT_STATUS_MASK,
1040 WM8350_IM_GP8_EINT);
1041 case WM8350_IRQ_GPIO(9):
1042 return wm8350_clear_bits(wm8350,
1043 WM8350_GPIO_INT_STATUS_MASK,
1044 WM8350_IM_GP9_EINT);
1045 case WM8350_IRQ_GPIO(10):
1046 return wm8350_clear_bits(wm8350,
1047 WM8350_GPIO_INT_STATUS_MASK,
1048 WM8350_IM_GP10_EINT);
1049 case WM8350_IRQ_GPIO(11):
1050 return wm8350_clear_bits(wm8350,
1051 WM8350_GPIO_INT_STATUS_MASK,
1052 WM8350_IM_GP11_EINT);
1053 case WM8350_IRQ_GPIO(12):
1054 return wm8350_clear_bits(wm8350,
1055 WM8350_GPIO_INT_STATUS_MASK,
1056 WM8350_IM_GP12_EINT);
1057 default:
1058 dev_warn(wm8350->dev, "Attempting to unmask unknown IRQ %d\n",
1059 irq);
1060 return -EINVAL;
1061 }
1062 return 0;
1063}
1064EXPORT_SYMBOL_GPL(wm8350_unmask_irq);
1065
1066/*
1067 * Cache is always host endian.
1068 */
1069static int wm8350_create_cache(struct wm8350 *wm8350, int mode)
1070{
1071 int i, ret = 0;
1072 u16 value;
1073 const u16 *reg_map;
1074
1075 switch (mode) {
1076#ifdef CONFIG_MFD_WM8350_CONFIG_MODE_0
1077 case 0:
1078 reg_map = wm8350_mode0_defaults;
1079 break;
1080#endif
1081#ifdef CONFIG_MFD_WM8350_CONFIG_MODE_1
1082 case 1:
1083 reg_map = wm8350_mode1_defaults;
1084 break;
1085#endif
1086#ifdef CONFIG_MFD_WM8350_CONFIG_MODE_2
1087 case 2:
1088 reg_map = wm8350_mode2_defaults;
1089 break;
1090#endif
1091#ifdef CONFIG_MFD_WM8350_CONFIG_MODE_3
1092 case 3:
1093 reg_map = wm8350_mode3_defaults;
1094 break;
1095#endif
1096 default:
1097 dev_err(wm8350->dev, "Configuration mode %d not supported\n",
1098 mode);
1099 return -EINVAL;
1100 }
1101
1102 wm8350->reg_cache =
1103 kzalloc(sizeof(u16) * (WM8350_MAX_REGISTER + 1), GFP_KERNEL);
1104 if (wm8350->reg_cache == NULL)
1105 return -ENOMEM;
1106
1107 /* Read the initial cache state back from the device - this is
1108 * a PMIC so the device many not be in a virgin state and we
1109 * can't rely on the silicon values.
1110 */
1111 for (i = 0; i < WM8350_MAX_REGISTER; i++) {
1112 /* audio register range */
1113 if (wm8350_reg_io_map[i].readable &&
1114 (i < WM8350_CLOCK_CONTROL_1 || i > WM8350_AIF_TEST)) {
1115 ret = wm8350->read_dev(wm8350, i, 2, (char *)&value);
1116 if (ret < 0) {
1117 dev_err(wm8350->dev,
1118 "failed to read initial cache value\n");
1119 goto out;
1120 }
1121 value = be16_to_cpu(value);
1122 value &= wm8350_reg_io_map[i].readable;
1123 wm8350->reg_cache[i] = value;
1124 } else
1125 wm8350->reg_cache[i] = reg_map[i];
1126 }
1127
1128out:
1129 return ret;
1130}
1131EXPORT_SYMBOL_GPL(wm8350_create_cache);
1132
1133/*
1134 * Register a client device. This is non-fatal since there is no need to
1135 * fail the entire device init due to a single platform device failing.
1136 */
1137static void wm8350_client_dev_register(struct wm8350 *wm8350,
1138 const char *name,
1139 struct platform_device **pdev)
1140{
1141 int ret;
1142
1143 *pdev = platform_device_alloc(name, -1);
1144 if (pdev == NULL) {
1145 dev_err(wm8350->dev, "Failed to allocate %s\n", name);
1146 return;
1147 }
1148
1149 (*pdev)->dev.parent = wm8350->dev;
1150 platform_set_drvdata(*pdev, wm8350);
1151 ret = platform_device_add(*pdev);
1152 if (ret != 0) {
1153 dev_err(wm8350->dev, "Failed to register %s: %d\n", name, ret);
1154 platform_device_put(*pdev);
1155 *pdev = NULL;
1156 }
1157}
1158
1159int wm8350_device_init(struct wm8350 *wm8350, int irq,
1160 struct wm8350_platform_data *pdata)
1161{
1162 int ret = -EINVAL;
1163 u16 id1, id2, mask, mode;
1164
1165 /* get WM8350 revision and config mode */
1166 wm8350->read_dev(wm8350, WM8350_RESET_ID, sizeof(id1), &id1);
1167 wm8350->read_dev(wm8350, WM8350_ID, sizeof(id2), &id2);
1168
1169 id1 = be16_to_cpu(id1);
1170 id2 = be16_to_cpu(id2);
1171
1172 if (id1 == 0x6143) {
1173 switch ((id2 & WM8350_CHIP_REV_MASK) >> 12) {
1174 case WM8350_REV_E:
1175 dev_info(wm8350->dev, "Found Rev E device\n");
1176 wm8350->rev = WM8350_REV_E;
1177 break;
1178 case WM8350_REV_F:
1179 dev_info(wm8350->dev, "Found Rev F device\n");
1180 wm8350->rev = WM8350_REV_F;
1181 break;
1182 case WM8350_REV_G:
1183 dev_info(wm8350->dev, "Found Rev G device\n");
1184 wm8350->rev = WM8350_REV_G;
1185 break;
1186 default:
1187 /* For safety we refuse to run on unknown hardware */
1188 dev_info(wm8350->dev, "Found unknown rev\n");
1189 ret = -ENODEV;
1190 goto err;
1191 }
1192 } else {
1193 dev_info(wm8350->dev, "Device with ID %x is not a WM8350\n",
1194 id1);
1195 ret = -ENODEV;
1196 goto err;
1197 }
1198
1199 mode = id2 & WM8350_CONF_STS_MASK >> 10;
1200 mask = id2 & WM8350_CUST_ID_MASK;
1201 dev_info(wm8350->dev, "Config mode %d, ROM mask %d\n", mode, mask);
1202
1203 ret = wm8350_create_cache(wm8350, mode);
1204 if (ret < 0) {
1205 printk(KERN_ERR "wm8350: failed to create register cache\n");
1206 return ret;
1207 }
1208
1209 if (pdata->init) {
1210 ret = pdata->init(wm8350);
1211 if (ret != 0) {
1212 dev_err(wm8350->dev, "Platform init() failed: %d\n",
1213 ret);
1214 goto err;
1215 }
1216 }
1217
1218 mutex_init(&wm8350->irq_mutex);
1219 INIT_WORK(&wm8350->irq_work, wm8350_irq_worker);
1220 if (irq != NO_IRQ) {
1221 ret = request_irq(irq, wm8350_irq, 0,
1222 "wm8350", wm8350);
1223 if (ret != 0) {
1224 dev_err(wm8350->dev, "Failed to request IRQ: %d\n",
1225 ret);
1226 goto err;
1227 }
1228 } else {
1229 dev_err(wm8350->dev, "No IRQ configured\n");
1230 goto err;
1231 }
1232 wm8350->chip_irq = irq;
1233
1234 wm8350_reg_write(wm8350, WM8350_SYSTEM_INTERRUPTS_MASK, 0x0);
1235
1236 wm8350_client_dev_register(wm8350, "wm8350-codec",
1237 &(wm8350->codec.pdev));
1238 wm8350_client_dev_register(wm8350, "wm8350-gpio",
1239 &(wm8350->gpio.pdev));
1240 wm8350_client_dev_register(wm8350, "wm8350-power",
1241 &(wm8350->power.pdev));
1242 wm8350_client_dev_register(wm8350, "wm8350-rtc", &(wm8350->rtc.pdev));
1243 wm8350_client_dev_register(wm8350, "wm8350-wdt", &(wm8350->wdt.pdev));
1244
1245 return 0;
1246
1247err:
1248 kfree(wm8350->reg_cache);
1249 return ret;
1250}
1251EXPORT_SYMBOL_GPL(wm8350_device_init);
1252
1253void wm8350_device_exit(struct wm8350 *wm8350)
1254{
1255 int i;
1256
1257 for (i = 0; i < ARRAY_SIZE(wm8350->pmic.pdev); i++)
1258 platform_device_unregister(wm8350->pmic.pdev[i]);
1259
1260 platform_device_unregister(wm8350->wdt.pdev);
1261 platform_device_unregister(wm8350->rtc.pdev);
1262 platform_device_unregister(wm8350->power.pdev);
1263 platform_device_unregister(wm8350->gpio.pdev);
1264 platform_device_unregister(wm8350->codec.pdev);
1265
1266 free_irq(wm8350->chip_irq, wm8350);
1267 flush_work(&wm8350->irq_work);
1268 kfree(wm8350->reg_cache);
1269}
1270EXPORT_SYMBOL_GPL(wm8350_device_exit);
1271
1272MODULE_DESCRIPTION("WM8350 AudioPlus PMIC core driver");
1273MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/wm8350-gpio.c b/drivers/mfd/wm8350-gpio.c
new file mode 100644
index 000000000000..ebf99bef392f
--- /dev/null
+++ b/drivers/mfd/wm8350-gpio.c
@@ -0,0 +1,222 @@
1/*
2 * wm8350-core.c -- Device access for Wolfson WM8350
3 *
4 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
5 *
6 * Author: Liam Girdwood
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 */
14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/errno.h>
18
19#include <linux/mfd/wm8350/core.h>
20#include <linux/mfd/wm8350/gpio.h>
21#include <linux/mfd/wm8350/pmic.h>
22
23static int gpio_set_dir(struct wm8350 *wm8350, int gpio, int dir)
24{
25 int ret;
26
27 wm8350_reg_unlock(wm8350);
28 if (dir == WM8350_GPIO_DIR_OUT)
29 ret = wm8350_clear_bits(wm8350,
30 WM8350_GPIO_CONFIGURATION_I_O,
31 1 << gpio);
32 else
33 ret = wm8350_set_bits(wm8350,
34 WM8350_GPIO_CONFIGURATION_I_O,
35 1 << gpio);
36 wm8350_reg_lock(wm8350);
37 return ret;
38}
39
40static int gpio_set_debounce(struct wm8350 *wm8350, int gpio, int db)
41{
42 if (db == WM8350_GPIO_DEBOUNCE_ON)
43 return wm8350_set_bits(wm8350, WM8350_GPIO_DEBOUNCE,
44 1 << gpio);
45 else
46 return wm8350_clear_bits(wm8350,
47 WM8350_GPIO_DEBOUNCE, 1 << gpio);
48}
49
50static int gpio_set_func(struct wm8350 *wm8350, int gpio, int func)
51{
52 u16 reg;
53
54 wm8350_reg_unlock(wm8350);
55 switch (gpio) {
56 case 0:
57 reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_1)
58 & ~WM8350_GP0_FN_MASK;
59 wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_1,
60 reg | ((func & 0xf) << 0));
61 break;
62 case 1:
63 reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_1)
64 & ~WM8350_GP1_FN_MASK;
65 wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_1,
66 reg | ((func & 0xf) << 4));
67 break;
68 case 2:
69 reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_1)
70 & ~WM8350_GP2_FN_MASK;
71 wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_1,
72 reg | ((func & 0xf) << 8));
73 break;
74 case 3:
75 reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_1)
76 & ~WM8350_GP3_FN_MASK;
77 wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_1,
78 reg | ((func & 0xf) << 12));
79 break;
80 case 4:
81 reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_2)
82 & ~WM8350_GP4_FN_MASK;
83 wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_2,
84 reg | ((func & 0xf) << 0));
85 break;
86 case 5:
87 reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_2)
88 & ~WM8350_GP5_FN_MASK;
89 wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_2,
90 reg | ((func & 0xf) << 4));
91 break;
92 case 6:
93 reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_2)
94 & ~WM8350_GP6_FN_MASK;
95 wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_2,
96 reg | ((func & 0xf) << 8));
97 break;
98 case 7:
99 reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_2)
100 & ~WM8350_GP7_FN_MASK;
101 wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_2,
102 reg | ((func & 0xf) << 12));
103 break;
104 case 8:
105 reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_3)
106 & ~WM8350_GP8_FN_MASK;
107 wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_3,
108 reg | ((func & 0xf) << 0));
109 break;
110 case 9:
111 reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_3)
112 & ~WM8350_GP9_FN_MASK;
113 wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_3,
114 reg | ((func & 0xf) << 4));
115 break;
116 case 10:
117 reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_3)
118 & ~WM8350_GP10_FN_MASK;
119 wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_3,
120 reg | ((func & 0xf) << 8));
121 break;
122 case 11:
123 reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_3)
124 & ~WM8350_GP11_FN_MASK;
125 wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_3,
126 reg | ((func & 0xf) << 12));
127 break;
128 case 12:
129 reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_4)
130 & ~WM8350_GP12_FN_MASK;
131 wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_4,
132 reg | ((func & 0xf) << 0));
133 break;
134 default:
135 wm8350_reg_lock(wm8350);
136 return -EINVAL;
137 }
138
139 wm8350_reg_lock(wm8350);
140 return 0;
141}
142
143static int gpio_set_pull_up(struct wm8350 *wm8350, int gpio, int up)
144{
145 if (up)
146 return wm8350_set_bits(wm8350,
147 WM8350_GPIO_PIN_PULL_UP_CONTROL,
148 1 << gpio);
149 else
150 return wm8350_clear_bits(wm8350,
151 WM8350_GPIO_PIN_PULL_UP_CONTROL,
152 1 << gpio);
153}
154
155static int gpio_set_pull_down(struct wm8350 *wm8350, int gpio, int down)
156{
157 if (down)
158 return wm8350_set_bits(wm8350,
159 WM8350_GPIO_PULL_DOWN_CONTROL,
160 1 << gpio);
161 else
162 return wm8350_clear_bits(wm8350,
163 WM8350_GPIO_PULL_DOWN_CONTROL,
164 1 << gpio);
165}
166
167static int gpio_set_polarity(struct wm8350 *wm8350, int gpio, int pol)
168{
169 if (pol == WM8350_GPIO_ACTIVE_HIGH)
170 return wm8350_set_bits(wm8350,
171 WM8350_GPIO_PIN_POLARITY_TYPE,
172 1 << gpio);
173 else
174 return wm8350_clear_bits(wm8350,
175 WM8350_GPIO_PIN_POLARITY_TYPE,
176 1 << gpio);
177}
178
179static int gpio_set_invert(struct wm8350 *wm8350, int gpio, int invert)
180{
181 if (invert == WM8350_GPIO_INVERT_ON)
182 return wm8350_set_bits(wm8350, WM8350_GPIO_INT_MODE, 1 << gpio);
183 else
184 return wm8350_clear_bits(wm8350,
185 WM8350_GPIO_INT_MODE, 1 << gpio);
186}
187
188int wm8350_gpio_config(struct wm8350 *wm8350, int gpio, int dir, int func,
189 int pol, int pull, int invert, int debounce)
190{
191 /* make sure we never pull up and down at the same time */
192 if (pull == WM8350_GPIO_PULL_NONE) {
193 if (gpio_set_pull_up(wm8350, gpio, 0))
194 goto err;
195 if (gpio_set_pull_down(wm8350, gpio, 0))
196 goto err;
197 } else if (pull == WM8350_GPIO_PULL_UP) {
198 if (gpio_set_pull_down(wm8350, gpio, 0))
199 goto err;
200 if (gpio_set_pull_up(wm8350, gpio, 1))
201 goto err;
202 } else if (pull == WM8350_GPIO_PULL_DOWN) {
203 if (gpio_set_pull_up(wm8350, gpio, 0))
204 goto err;
205 if (gpio_set_pull_down(wm8350, gpio, 1))
206 goto err;
207 }
208
209 if (gpio_set_invert(wm8350, gpio, invert))
210 goto err;
211 if (gpio_set_polarity(wm8350, gpio, pol))
212 goto err;
213 if (gpio_set_debounce(wm8350, gpio, debounce))
214 goto err;
215 if (gpio_set_dir(wm8350, gpio, dir))
216 goto err;
217 return gpio_set_func(wm8350, gpio, func);
218
219err:
220 return -EIO;
221}
222EXPORT_SYMBOL_GPL(wm8350_gpio_config);
diff --git a/drivers/mfd/wm8350-i2c.c b/drivers/mfd/wm8350-i2c.c
new file mode 100644
index 000000000000..8dfe21bb3bd1
--- /dev/null
+++ b/drivers/mfd/wm8350-i2c.c
@@ -0,0 +1,120 @@
1/*
2 * wm8350-i2c.c -- Generic I2C driver for Wolfson WM8350 PMIC
3 *
4 * This driver defines and configures the WM8350 for the Freescale i.MX32ADS.
5 *
6 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
7 *
8 * Author: Liam Girdwood
9 * linux@wolfsonmicro.com
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/moduleparam.h>
20#include <linux/init.h>
21#include <linux/i2c.h>
22#include <linux/platform_device.h>
23#include <linux/mfd/wm8350/core.h>
24
25static int wm8350_i2c_read_device(struct wm8350 *wm8350, char reg,
26 int bytes, void *dest)
27{
28 int ret;
29
30 ret = i2c_master_send(wm8350->i2c_client, &reg, 1);
31 if (ret < 0)
32 return ret;
33 return i2c_master_recv(wm8350->i2c_client, dest, bytes);
34}
35
36static int wm8350_i2c_write_device(struct wm8350 *wm8350, char reg,
37 int bytes, void *src)
38{
39 /* we add 1 byte for device register */
40 u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
41
42 if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
43 return -EINVAL;
44
45 msg[0] = reg;
46 memcpy(&msg[1], src, bytes);
47 return i2c_master_send(wm8350->i2c_client, msg, bytes + 1);
48}
49
50static int wm8350_i2c_probe(struct i2c_client *i2c,
51 const struct i2c_device_id *id)
52{
53 struct wm8350 *wm8350;
54 int ret = 0;
55
56 wm8350 = kzalloc(sizeof(struct wm8350), GFP_KERNEL);
57 if (wm8350 == NULL) {
58 kfree(i2c);
59 return -ENOMEM;
60 }
61
62 i2c_set_clientdata(i2c, wm8350);
63 wm8350->dev = &i2c->dev;
64 wm8350->i2c_client = i2c;
65 wm8350->read_dev = wm8350_i2c_read_device;
66 wm8350->write_dev = wm8350_i2c_write_device;
67
68 ret = wm8350_device_init(wm8350, i2c->irq, i2c->dev.platform_data);
69 if (ret < 0)
70 goto err;
71
72 return ret;
73
74err:
75 kfree(wm8350);
76 return ret;
77}
78
79static int wm8350_i2c_remove(struct i2c_client *i2c)
80{
81 struct wm8350 *wm8350 = i2c_get_clientdata(i2c);
82
83 wm8350_device_exit(wm8350);
84 kfree(wm8350);
85
86 return 0;
87}
88
89static const struct i2c_device_id wm8350_i2c_id[] = {
90 { "wm8350", 0 },
91 { }
92};
93MODULE_DEVICE_TABLE(i2c, wm8350_i2c_id);
94
95
96static struct i2c_driver wm8350_i2c_driver = {
97 .driver = {
98 .name = "wm8350",
99 .owner = THIS_MODULE,
100 },
101 .probe = wm8350_i2c_probe,
102 .remove = wm8350_i2c_remove,
103 .id_table = wm8350_i2c_id,
104};
105
106static int __init wm8350_i2c_init(void)
107{
108 return i2c_add_driver(&wm8350_i2c_driver);
109}
110/* init early so consumer devices can complete system boot */
111subsys_initcall(wm8350_i2c_init);
112
113static void __exit wm8350_i2c_exit(void)
114{
115 i2c_del_driver(&wm8350_i2c_driver);
116}
117module_exit(wm8350_i2c_exit);
118
119MODULE_DESCRIPTION("I2C support for the WM8350 AudioPlus PMIC");
120MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/wm8350-regmap.c b/drivers/mfd/wm8350-regmap.c
new file mode 100644
index 000000000000..974678db22cd
--- /dev/null
+++ b/drivers/mfd/wm8350-regmap.c
@@ -0,0 +1,1347 @@
1/*
2 * wm8350-regmap.c -- Wolfson Microelectronics WM8350 register map
3 *
4 * This file splits out the tables describing the defaults and access
5 * status of the WM8350 registers since they are rather large.
6 *
7 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
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
15#include <linux/mfd/wm8350/core.h>
16
17#ifdef CONFIG_MFD_WM8350_CONFIG_MODE_0
18
19#undef WM8350_HAVE_CONFIG_MODE
20#define WM8350_HAVE_CONFIG_MODE
21
22const u16 wm8350_mode0_defaults[] = {
23 0x17FF, /* R0 - Reset/ID */
24 0x1000, /* R1 - ID */
25 0x0000, /* R2 */
26 0x1002, /* R3 - System Control 1 */
27 0x0004, /* R4 - System Control 2 */
28 0x0000, /* R5 - System Hibernate */
29 0x8A00, /* R6 - Interface Control */
30 0x0000, /* R7 */
31 0x8000, /* R8 - Power mgmt (1) */
32 0x0000, /* R9 - Power mgmt (2) */
33 0x0000, /* R10 - Power mgmt (3) */
34 0x2000, /* R11 - Power mgmt (4) */
35 0x0E00, /* R12 - Power mgmt (5) */
36 0x0000, /* R13 - Power mgmt (6) */
37 0x0000, /* R14 - Power mgmt (7) */
38 0x0000, /* R15 */
39 0x0000, /* R16 - RTC Seconds/Minutes */
40 0x0100, /* R17 - RTC Hours/Day */
41 0x0101, /* R18 - RTC Date/Month */
42 0x1400, /* R19 - RTC Year */
43 0x0000, /* R20 - Alarm Seconds/Minutes */
44 0x0000, /* R21 - Alarm Hours/Day */
45 0x0000, /* R22 - Alarm Date/Month */
46 0x0320, /* R23 - RTC Time Control */
47 0x0000, /* R24 - System Interrupts */
48 0x0000, /* R25 - Interrupt Status 1 */
49 0x0000, /* R26 - Interrupt Status 2 */
50 0x0000, /* R27 - Power Up Interrupt Status */
51 0x0000, /* R28 - Under Voltage Interrupt status */
52 0x0000, /* R29 - Over Current Interrupt status */
53 0x0000, /* R30 - GPIO Interrupt Status */
54 0x0000, /* R31 - Comparator Interrupt Status */
55 0x3FFF, /* R32 - System Interrupts Mask */
56 0x0000, /* R33 - Interrupt Status 1 Mask */
57 0x0000, /* R34 - Interrupt Status 2 Mask */
58 0x0000, /* R35 - Power Up Interrupt Status Mask */
59 0x0000, /* R36 - Under Voltage Interrupt status Mask */
60 0x0000, /* R37 - Over Current Interrupt status Mask */
61 0x0000, /* R38 - GPIO Interrupt Status Mask */
62 0x0000, /* R39 - Comparator Interrupt Status Mask */
63 0x0040, /* R40 - Clock Control 1 */
64 0x0000, /* R41 - Clock Control 2 */
65 0x3B00, /* R42 - FLL Control 1 */
66 0x7086, /* R43 - FLL Control 2 */
67 0xC226, /* R44 - FLL Control 3 */
68 0x0000, /* R45 - FLL Control 4 */
69 0x0000, /* R46 */
70 0x0000, /* R47 */
71 0x0000, /* R48 - DAC Control */
72 0x0000, /* R49 */
73 0x00C0, /* R50 - DAC Digital Volume L */
74 0x00C0, /* R51 - DAC Digital Volume R */
75 0x0000, /* R52 */
76 0x0040, /* R53 - DAC LR Rate */
77 0x0000, /* R54 - DAC Clock Control */
78 0x0000, /* R55 */
79 0x0000, /* R56 */
80 0x0000, /* R57 */
81 0x4000, /* R58 - DAC Mute */
82 0x0000, /* R59 - DAC Mute Volume */
83 0x0000, /* R60 - DAC Side */
84 0x0000, /* R61 */
85 0x0000, /* R62 */
86 0x0000, /* R63 */
87 0x8000, /* R64 - ADC Control */
88 0x0000, /* R65 */
89 0x00C0, /* R66 - ADC Digital Volume L */
90 0x00C0, /* R67 - ADC Digital Volume R */
91 0x0000, /* R68 - ADC Divider */
92 0x0000, /* R69 */
93 0x0040, /* R70 - ADC LR Rate */
94 0x0000, /* R71 */
95 0x0303, /* R72 - Input Control */
96 0x0000, /* R73 - IN3 Input Control */
97 0x0000, /* R74 - Mic Bias Control */
98 0x0000, /* R75 */
99 0x0000, /* R76 - Output Control */
100 0x0000, /* R77 - Jack Detect */
101 0x0000, /* R78 - Anti Pop Control */
102 0x0000, /* R79 */
103 0x0040, /* R80 - Left Input Volume */
104 0x0040, /* R81 - Right Input Volume */
105 0x0000, /* R82 */
106 0x0000, /* R83 */
107 0x0000, /* R84 */
108 0x0000, /* R85 */
109 0x0000, /* R86 */
110 0x0000, /* R87 */
111 0x0800, /* R88 - Left Mixer Control */
112 0x1000, /* R89 - Right Mixer Control */
113 0x0000, /* R90 */
114 0x0000, /* R91 */
115 0x0000, /* R92 - OUT3 Mixer Control */
116 0x0000, /* R93 - OUT4 Mixer Control */
117 0x0000, /* R94 */
118 0x0000, /* R95 */
119 0x0000, /* R96 - Output Left Mixer Volume */
120 0x0000, /* R97 - Output Right Mixer Volume */
121 0x0000, /* R98 - Input Mixer Volume L */
122 0x0000, /* R99 - Input Mixer Volume R */
123 0x0000, /* R100 - Input Mixer Volume */
124 0x0000, /* R101 */
125 0x0000, /* R102 */
126 0x0000, /* R103 */
127 0x00E4, /* R104 - LOUT1 Volume */
128 0x00E4, /* R105 - ROUT1 Volume */
129 0x00E4, /* R106 - LOUT2 Volume */
130 0x02E4, /* R107 - ROUT2 Volume */
131 0x0000, /* R108 */
132 0x0000, /* R109 */
133 0x0000, /* R110 */
134 0x0000, /* R111 - BEEP Volume */
135 0x0A00, /* R112 - AI Formating */
136 0x0000, /* R113 - ADC DAC COMP */
137 0x0020, /* R114 - AI ADC Control */
138 0x0020, /* R115 - AI DAC Control */
139 0x0000, /* R116 - AIF Test */
140 0x0000, /* R117 */
141 0x0000, /* R118 */
142 0x0000, /* R119 */
143 0x0000, /* R120 */
144 0x0000, /* R121 */
145 0x0000, /* R122 */
146 0x0000, /* R123 */
147 0x0000, /* R124 */
148 0x0000, /* R125 */
149 0x0000, /* R126 */
150 0x0000, /* R127 */
151 0x1FFF, /* R128 - GPIO Debounce */
152 0x0000, /* R129 - GPIO Pin pull up Control */
153 0x03FC, /* R130 - GPIO Pull down Control */
154 0x0000, /* R131 - GPIO Interrupt Mode */
155 0x0000, /* R132 */
156 0x0000, /* R133 - GPIO Control */
157 0x0FFC, /* R134 - GPIO Configuration (i/o) */
158 0x0FFC, /* R135 - GPIO Pin Polarity / Type */
159 0x0000, /* R136 */
160 0x0000, /* R137 */
161 0x0000, /* R138 */
162 0x0000, /* R139 */
163 0x0013, /* R140 - GPIO Function Select 1 */
164 0x0000, /* R141 - GPIO Function Select 2 */
165 0x0000, /* R142 - GPIO Function Select 3 */
166 0x0003, /* R143 - GPIO Function Select 4 */
167 0x0000, /* R144 - Digitiser Control (1) */
168 0x0002, /* R145 - Digitiser Control (2) */
169 0x0000, /* R146 */
170 0x0000, /* R147 */
171 0x0000, /* R148 */
172 0x0000, /* R149 */
173 0x0000, /* R150 */
174 0x0000, /* R151 */
175 0x7000, /* R152 - AUX1 Readback */
176 0x7000, /* R153 - AUX2 Readback */
177 0x7000, /* R154 - AUX3 Readback */
178 0x7000, /* R155 - AUX4 Readback */
179 0x0000, /* R156 - USB Voltage Readback */
180 0x0000, /* R157 - LINE Voltage Readback */
181 0x0000, /* R158 - BATT Voltage Readback */
182 0x0000, /* R159 - Chip Temp Readback */
183 0x0000, /* R160 */
184 0x0000, /* R161 */
185 0x0000, /* R162 */
186 0x0000, /* R163 - Generic Comparator Control */
187 0x0000, /* R164 - Generic comparator 1 */
188 0x0000, /* R165 - Generic comparator 2 */
189 0x0000, /* R166 - Generic comparator 3 */
190 0x0000, /* R167 - Generic comparator 4 */
191 0xA00F, /* R168 - Battery Charger Control 1 */
192 0x0B06, /* R169 - Battery Charger Control 2 */
193 0x0000, /* R170 - Battery Charger Control 3 */
194 0x0000, /* R171 */
195 0x0000, /* R172 - Current Sink Driver A */
196 0x0000, /* R173 - CSA Flash control */
197 0x0000, /* R174 - Current Sink Driver B */
198 0x0000, /* R175 - CSB Flash control */
199 0x0000, /* R176 - DCDC/LDO requested */
200 0x002D, /* R177 - DCDC Active options */
201 0x0000, /* R178 - DCDC Sleep options */
202 0x0025, /* R179 - Power-check comparator */
203 0x000E, /* R180 - DCDC1 Control */
204 0x0000, /* R181 - DCDC1 Timeouts */
205 0x1006, /* R182 - DCDC1 Low Power */
206 0x0018, /* R183 - DCDC2 Control */
207 0x0000, /* R184 - DCDC2 Timeouts */
208 0x0000, /* R185 */
209 0x0000, /* R186 - DCDC3 Control */
210 0x0000, /* R187 - DCDC3 Timeouts */
211 0x0006, /* R188 - DCDC3 Low Power */
212 0x0000, /* R189 - DCDC4 Control */
213 0x0000, /* R190 - DCDC4 Timeouts */
214 0x0006, /* R191 - DCDC4 Low Power */
215 0x0008, /* R192 - DCDC5 Control */
216 0x0000, /* R193 - DCDC5 Timeouts */
217 0x0000, /* R194 */
218 0x0000, /* R195 - DCDC6 Control */
219 0x0000, /* R196 - DCDC6 Timeouts */
220 0x0006, /* R197 - DCDC6 Low Power */
221 0x0000, /* R198 */
222 0x0003, /* R199 - Limit Switch Control */
223 0x001C, /* R200 - LDO1 Control */
224 0x0000, /* R201 - LDO1 Timeouts */
225 0x001C, /* R202 - LDO1 Low Power */
226 0x001B, /* R203 - LDO2 Control */
227 0x0000, /* R204 - LDO2 Timeouts */
228 0x001C, /* R205 - LDO2 Low Power */
229 0x001B, /* R206 - LDO3 Control */
230 0x0000, /* R207 - LDO3 Timeouts */
231 0x001C, /* R208 - LDO3 Low Power */
232 0x001B, /* R209 - LDO4 Control */
233 0x0000, /* R210 - LDO4 Timeouts */
234 0x001C, /* R211 - LDO4 Low Power */
235 0x0000, /* R212 */
236 0x0000, /* R213 */
237 0x0000, /* R214 */
238 0x0000, /* R215 - VCC_FAULT Masks */
239 0x001F, /* R216 - Main Bandgap Control */
240 0x0000, /* R217 - OSC Control */
241 0x9000, /* R218 - RTC Tick Control */
242 0x0000, /* R219 */
243 0x4000, /* R220 - RAM BIST 1 */
244 0x0000, /* R221 */
245 0x0000, /* R222 */
246 0x0000, /* R223 */
247 0x0000, /* R224 */
248 0x0000, /* R225 - DCDC/LDO status */
249 0x0000, /* R226 */
250 0x0000, /* R227 */
251 0x0000, /* R228 */
252 0x0000, /* R229 */
253 0xE000, /* R230 - GPIO Pin Status */
254 0x0000, /* R231 */
255 0x0000, /* R232 */
256 0x0000, /* R233 */
257 0x0000, /* R234 */
258 0x0000, /* R235 */
259 0x0000, /* R236 */
260 0x0000, /* R237 */
261 0x0000, /* R238 */
262 0x0000, /* R239 */
263 0x0000, /* R240 */
264 0x0000, /* R241 */
265 0x0000, /* R242 */
266 0x0000, /* R243 */
267 0x0000, /* R244 */
268 0x0000, /* R245 */
269 0x0000, /* R246 */
270 0x0000, /* R247 */
271 0x0000, /* R248 */
272 0x0000, /* R249 */
273 0x0000, /* R250 */
274 0x0000, /* R251 */
275 0x0000, /* R252 */
276 0x0000, /* R253 */
277 0x0000, /* R254 */
278 0x0000, /* R255 */
279};
280#endif
281
282#ifdef CONFIG_MFD_WM8350_CONFIG_MODE_1
283
284#undef WM8350_HAVE_CONFIG_MODE
285#define WM8350_HAVE_CONFIG_MODE
286
287const u16 wm8350_mode1_defaults[] = {
288 0x17FF, /* R0 - Reset/ID */
289 0x1000, /* R1 - ID */
290 0x0000, /* R2 */
291 0x1002, /* R3 - System Control 1 */
292 0x0014, /* R4 - System Control 2 */
293 0x0000, /* R5 - System Hibernate */
294 0x8A00, /* R6 - Interface Control */
295 0x0000, /* R7 */
296 0x8000, /* R8 - Power mgmt (1) */
297 0x0000, /* R9 - Power mgmt (2) */
298 0x0000, /* R10 - Power mgmt (3) */
299 0x2000, /* R11 - Power mgmt (4) */
300 0x0E00, /* R12 - Power mgmt (5) */
301 0x0000, /* R13 - Power mgmt (6) */
302 0x0000, /* R14 - Power mgmt (7) */
303 0x0000, /* R15 */
304 0x0000, /* R16 - RTC Seconds/Minutes */
305 0x0100, /* R17 - RTC Hours/Day */
306 0x0101, /* R18 - RTC Date/Month */
307 0x1400, /* R19 - RTC Year */
308 0x0000, /* R20 - Alarm Seconds/Minutes */
309 0x0000, /* R21 - Alarm Hours/Day */
310 0x0000, /* R22 - Alarm Date/Month */
311 0x0320, /* R23 - RTC Time Control */
312 0x0000, /* R24 - System Interrupts */
313 0x0000, /* R25 - Interrupt Status 1 */
314 0x0000, /* R26 - Interrupt Status 2 */
315 0x0000, /* R27 - Power Up Interrupt Status */
316 0x0000, /* R28 - Under Voltage Interrupt status */
317 0x0000, /* R29 - Over Current Interrupt status */
318 0x0000, /* R30 - GPIO Interrupt Status */
319 0x0000, /* R31 - Comparator Interrupt Status */
320 0x3FFF, /* R32 - System Interrupts Mask */
321 0x0000, /* R33 - Interrupt Status 1 Mask */
322 0x0000, /* R34 - Interrupt Status 2 Mask */
323 0x0000, /* R35 - Power Up Interrupt Status Mask */
324 0x0000, /* R36 - Under Voltage Interrupt status Mask */
325 0x0000, /* R37 - Over Current Interrupt status Mask */
326 0x0000, /* R38 - GPIO Interrupt Status Mask */
327 0x0000, /* R39 - Comparator Interrupt Status Mask */
328 0x0040, /* R40 - Clock Control 1 */
329 0x0000, /* R41 - Clock Control 2 */
330 0x3B00, /* R42 - FLL Control 1 */
331 0x7086, /* R43 - FLL Control 2 */
332 0xC226, /* R44 - FLL Control 3 */
333 0x0000, /* R45 - FLL Control 4 */
334 0x0000, /* R46 */
335 0x0000, /* R47 */
336 0x0000, /* R48 - DAC Control */
337 0x0000, /* R49 */
338 0x00C0, /* R50 - DAC Digital Volume L */
339 0x00C0, /* R51 - DAC Digital Volume R */
340 0x0000, /* R52 */
341 0x0040, /* R53 - DAC LR Rate */
342 0x0000, /* R54 - DAC Clock Control */
343 0x0000, /* R55 */
344 0x0000, /* R56 */
345 0x0000, /* R57 */
346 0x4000, /* R58 - DAC Mute */
347 0x0000, /* R59 - DAC Mute Volume */
348 0x0000, /* R60 - DAC Side */
349 0x0000, /* R61 */
350 0x0000, /* R62 */
351 0x0000, /* R63 */
352 0x8000, /* R64 - ADC Control */
353 0x0000, /* R65 */
354 0x00C0, /* R66 - ADC Digital Volume L */
355 0x00C0, /* R67 - ADC Digital Volume R */
356 0x0000, /* R68 - ADC Divider */
357 0x0000, /* R69 */
358 0x0040, /* R70 - ADC LR Rate */
359 0x0000, /* R71 */
360 0x0303, /* R72 - Input Control */
361 0x0000, /* R73 - IN3 Input Control */
362 0x0000, /* R74 - Mic Bias Control */
363 0x0000, /* R75 */
364 0x0000, /* R76 - Output Control */
365 0x0000, /* R77 - Jack Detect */
366 0x0000, /* R78 - Anti Pop Control */
367 0x0000, /* R79 */
368 0x0040, /* R80 - Left Input Volume */
369 0x0040, /* R81 - Right Input Volume */
370 0x0000, /* R82 */
371 0x0000, /* R83 */
372 0x0000, /* R84 */
373 0x0000, /* R85 */
374 0x0000, /* R86 */
375 0x0000, /* R87 */
376 0x0800, /* R88 - Left Mixer Control */
377 0x1000, /* R89 - Right Mixer Control */
378 0x0000, /* R90 */
379 0x0000, /* R91 */
380 0x0000, /* R92 - OUT3 Mixer Control */
381 0x0000, /* R93 - OUT4 Mixer Control */
382 0x0000, /* R94 */
383 0x0000, /* R95 */
384 0x0000, /* R96 - Output Left Mixer Volume */
385 0x0000, /* R97 - Output Right Mixer Volume */
386 0x0000, /* R98 - Input Mixer Volume L */
387 0x0000, /* R99 - Input Mixer Volume R */
388 0x0000, /* R100 - Input Mixer Volume */
389 0x0000, /* R101 */
390 0x0000, /* R102 */
391 0x0000, /* R103 */
392 0x00E4, /* R104 - LOUT1 Volume */
393 0x00E4, /* R105 - ROUT1 Volume */
394 0x00E4, /* R106 - LOUT2 Volume */
395 0x02E4, /* R107 - ROUT2 Volume */
396 0x0000, /* R108 */
397 0x0000, /* R109 */
398 0x0000, /* R110 */
399 0x0000, /* R111 - BEEP Volume */
400 0x0A00, /* R112 - AI Formating */
401 0x0000, /* R113 - ADC DAC COMP */
402 0x0020, /* R114 - AI ADC Control */
403 0x0020, /* R115 - AI DAC Control */
404 0x0000, /* R116 - AIF Test */
405 0x0000, /* R117 */
406 0x0000, /* R118 */
407 0x0000, /* R119 */
408 0x0000, /* R120 */
409 0x0000, /* R121 */
410 0x0000, /* R122 */
411 0x0000, /* R123 */
412 0x0000, /* R124 */
413 0x0000, /* R125 */
414 0x0000, /* R126 */
415 0x0000, /* R127 */
416 0x1FFF, /* R128 - GPIO Debounce */
417 0x0000, /* R129 - GPIO Pin pull up Control */
418 0x03FC, /* R130 - GPIO Pull down Control */
419 0x0000, /* R131 - GPIO Interrupt Mode */
420 0x0000, /* R132 */
421 0x0000, /* R133 - GPIO Control */
422 0x00FB, /* R134 - GPIO Configuration (i/o) */
423 0x04FE, /* R135 - GPIO Pin Polarity / Type */
424 0x0000, /* R136 */
425 0x0000, /* R137 */
426 0x0000, /* R138 */
427 0x0000, /* R139 */
428 0x0312, /* R140 - GPIO Function Select 1 */
429 0x1003, /* R141 - GPIO Function Select 2 */
430 0x1331, /* R142 - GPIO Function Select 3 */
431 0x0003, /* R143 - GPIO Function Select 4 */
432 0x0000, /* R144 - Digitiser Control (1) */
433 0x0002, /* R145 - Digitiser Control (2) */
434 0x0000, /* R146 */
435 0x0000, /* R147 */
436 0x0000, /* R148 */
437 0x0000, /* R149 */
438 0x0000, /* R150 */
439 0x0000, /* R151 */
440 0x7000, /* R152 - AUX1 Readback */
441 0x7000, /* R153 - AUX2 Readback */
442 0x7000, /* R154 - AUX3 Readback */
443 0x7000, /* R155 - AUX4 Readback */
444 0x0000, /* R156 - USB Voltage Readback */
445 0x0000, /* R157 - LINE Voltage Readback */
446 0x0000, /* R158 - BATT Voltage Readback */
447 0x0000, /* R159 - Chip Temp Readback */
448 0x0000, /* R160 */
449 0x0000, /* R161 */
450 0x0000, /* R162 */
451 0x0000, /* R163 - Generic Comparator Control */
452 0x0000, /* R164 - Generic comparator 1 */
453 0x0000, /* R165 - Generic comparator 2 */
454 0x0000, /* R166 - Generic comparator 3 */
455 0x0000, /* R167 - Generic comparator 4 */
456 0xA00F, /* R168 - Battery Charger Control 1 */
457 0x0B06, /* R169 - Battery Charger Control 2 */
458 0x0000, /* R170 - Battery Charger Control 3 */
459 0x0000, /* R171 */
460 0x0000, /* R172 - Current Sink Driver A */
461 0x0000, /* R173 - CSA Flash control */
462 0x0000, /* R174 - Current Sink Driver B */
463 0x0000, /* R175 - CSB Flash control */
464 0x0000, /* R176 - DCDC/LDO requested */
465 0x002D, /* R177 - DCDC Active options */
466 0x0000, /* R178 - DCDC Sleep options */
467 0x0025, /* R179 - Power-check comparator */
468 0x0062, /* R180 - DCDC1 Control */
469 0x0400, /* R181 - DCDC1 Timeouts */
470 0x1006, /* R182 - DCDC1 Low Power */
471 0x0018, /* R183 - DCDC2 Control */
472 0x0000, /* R184 - DCDC2 Timeouts */
473 0x0000, /* R185 */
474 0x0026, /* R186 - DCDC3 Control */
475 0x0400, /* R187 - DCDC3 Timeouts */
476 0x0006, /* R188 - DCDC3 Low Power */
477 0x0062, /* R189 - DCDC4 Control */
478 0x0400, /* R190 - DCDC4 Timeouts */
479 0x0006, /* R191 - DCDC4 Low Power */
480 0x0008, /* R192 - DCDC5 Control */
481 0x0000, /* R193 - DCDC5 Timeouts */
482 0x0000, /* R194 */
483 0x0026, /* R195 - DCDC6 Control */
484 0x0800, /* R196 - DCDC6 Timeouts */
485 0x0006, /* R197 - DCDC6 Low Power */
486 0x0000, /* R198 */
487 0x0003, /* R199 - Limit Switch Control */
488 0x0006, /* R200 - LDO1 Control */
489 0x0400, /* R201 - LDO1 Timeouts */
490 0x001C, /* R202 - LDO1 Low Power */
491 0x0006, /* R203 - LDO2 Control */
492 0x0400, /* R204 - LDO2 Timeouts */
493 0x001C, /* R205 - LDO2 Low Power */
494 0x001B, /* R206 - LDO3 Control */
495 0x0000, /* R207 - LDO3 Timeouts */
496 0x001C, /* R208 - LDO3 Low Power */
497 0x001B, /* R209 - LDO4 Control */
498 0x0000, /* R210 - LDO4 Timeouts */
499 0x001C, /* R211 - LDO4 Low Power */
500 0x0000, /* R212 */
501 0x0000, /* R213 */
502 0x0000, /* R214 */
503 0x0000, /* R215 - VCC_FAULT Masks */
504 0x001F, /* R216 - Main Bandgap Control */
505 0x0000, /* R217 - OSC Control */
506 0x9000, /* R218 - RTC Tick Control */
507 0x0000, /* R219 */
508 0x4000, /* R220 - RAM BIST 1 */
509 0x0000, /* R221 */
510 0x0000, /* R222 */
511 0x0000, /* R223 */
512 0x0000, /* R224 */
513 0x0000, /* R225 - DCDC/LDO status */
514 0x0000, /* R226 */
515 0x0000, /* R227 */
516 0x0000, /* R228 */
517 0x0000, /* R229 */
518 0xE000, /* R230 - GPIO Pin Status */
519 0x0000, /* R231 */
520 0x0000, /* R232 */
521 0x0000, /* R233 */
522 0x0000, /* R234 */
523 0x0000, /* R235 */
524 0x0000, /* R236 */
525 0x0000, /* R237 */
526 0x0000, /* R238 */
527 0x0000, /* R239 */
528 0x0000, /* R240 */
529 0x0000, /* R241 */
530 0x0000, /* R242 */
531 0x0000, /* R243 */
532 0x0000, /* R244 */
533 0x0000, /* R245 */
534 0x0000, /* R246 */
535 0x0000, /* R247 */
536 0x0000, /* R248 */
537 0x0000, /* R249 */
538 0x0000, /* R250 */
539 0x0000, /* R251 */
540 0x0000, /* R252 */
541 0x0000, /* R253 */
542 0x0000, /* R254 */
543 0x0000, /* R255 */
544};
545#endif
546
547#ifdef CONFIG_MFD_WM8350_CONFIG_MODE_2
548
549#undef WM8350_HAVE_CONFIG_MODE
550#define WM8350_HAVE_CONFIG_MODE
551
552const u16 wm8350_mode2_defaults[] = {
553 0x17FF, /* R0 - Reset/ID */
554 0x1000, /* R1 - ID */
555 0x0000, /* R2 */
556 0x1002, /* R3 - System Control 1 */
557 0x0014, /* R4 - System Control 2 */
558 0x0000, /* R5 - System Hibernate */
559 0x8A00, /* R6 - Interface Control */
560 0x0000, /* R7 */
561 0x8000, /* R8 - Power mgmt (1) */
562 0x0000, /* R9 - Power mgmt (2) */
563 0x0000, /* R10 - Power mgmt (3) */
564 0x2000, /* R11 - Power mgmt (4) */
565 0x0E00, /* R12 - Power mgmt (5) */
566 0x0000, /* R13 - Power mgmt (6) */
567 0x0000, /* R14 - Power mgmt (7) */
568 0x0000, /* R15 */
569 0x0000, /* R16 - RTC Seconds/Minutes */
570 0x0100, /* R17 - RTC Hours/Day */
571 0x0101, /* R18 - RTC Date/Month */
572 0x1400, /* R19 - RTC Year */
573 0x0000, /* R20 - Alarm Seconds/Minutes */
574 0x0000, /* R21 - Alarm Hours/Day */
575 0x0000, /* R22 - Alarm Date/Month */
576 0x0320, /* R23 - RTC Time Control */
577 0x0000, /* R24 - System Interrupts */
578 0x0000, /* R25 - Interrupt Status 1 */
579 0x0000, /* R26 - Interrupt Status 2 */
580 0x0000, /* R27 - Power Up Interrupt Status */
581 0x0000, /* R28 - Under Voltage Interrupt status */
582 0x0000, /* R29 - Over Current Interrupt status */
583 0x0000, /* R30 - GPIO Interrupt Status */
584 0x0000, /* R31 - Comparator Interrupt Status */
585 0x3FFF, /* R32 - System Interrupts Mask */
586 0x0000, /* R33 - Interrupt Status 1 Mask */
587 0x0000, /* R34 - Interrupt Status 2 Mask */
588 0x0000, /* R35 - Power Up Interrupt Status Mask */
589 0x0000, /* R36 - Under Voltage Interrupt status Mask */
590 0x0000, /* R37 - Over Current Interrupt status Mask */
591 0x0000, /* R38 - GPIO Interrupt Status Mask */
592 0x0000, /* R39 - Comparator Interrupt Status Mask */
593 0x0040, /* R40 - Clock Control 1 */
594 0x0000, /* R41 - Clock Control 2 */
595 0x3B00, /* R42 - FLL Control 1 */
596 0x7086, /* R43 - FLL Control 2 */
597 0xC226, /* R44 - FLL Control 3 */
598 0x0000, /* R45 - FLL Control 4 */
599 0x0000, /* R46 */
600 0x0000, /* R47 */
601 0x0000, /* R48 - DAC Control */
602 0x0000, /* R49 */
603 0x00C0, /* R50 - DAC Digital Volume L */
604 0x00C0, /* R51 - DAC Digital Volume R */
605 0x0000, /* R52 */
606 0x0040, /* R53 - DAC LR Rate */
607 0x0000, /* R54 - DAC Clock Control */
608 0x0000, /* R55 */
609 0x0000, /* R56 */
610 0x0000, /* R57 */
611 0x4000, /* R58 - DAC Mute */
612 0x0000, /* R59 - DAC Mute Volume */
613 0x0000, /* R60 - DAC Side */
614 0x0000, /* R61 */
615 0x0000, /* R62 */
616 0x0000, /* R63 */
617 0x8000, /* R64 - ADC Control */
618 0x0000, /* R65 */
619 0x00C0, /* R66 - ADC Digital Volume L */
620 0x00C0, /* R67 - ADC Digital Volume R */
621 0x0000, /* R68 - ADC Divider */
622 0x0000, /* R69 */
623 0x0040, /* R70 - ADC LR Rate */
624 0x0000, /* R71 */
625 0x0303, /* R72 - Input Control */
626 0x0000, /* R73 - IN3 Input Control */
627 0x0000, /* R74 - Mic Bias Control */
628 0x0000, /* R75 */
629 0x0000, /* R76 - Output Control */
630 0x0000, /* R77 - Jack Detect */
631 0x0000, /* R78 - Anti Pop Control */
632 0x0000, /* R79 */
633 0x0040, /* R80 - Left Input Volume */
634 0x0040, /* R81 - Right Input Volume */
635 0x0000, /* R82 */
636 0x0000, /* R83 */
637 0x0000, /* R84 */
638 0x0000, /* R85 */
639 0x0000, /* R86 */
640 0x0000, /* R87 */
641 0x0800, /* R88 - Left Mixer Control */
642 0x1000, /* R89 - Right Mixer Control */
643 0x0000, /* R90 */
644 0x0000, /* R91 */
645 0x0000, /* R92 - OUT3 Mixer Control */
646 0x0000, /* R93 - OUT4 Mixer Control */
647 0x0000, /* R94 */
648 0x0000, /* R95 */
649 0x0000, /* R96 - Output Left Mixer Volume */
650 0x0000, /* R97 - Output Right Mixer Volume */
651 0x0000, /* R98 - Input Mixer Volume L */
652 0x0000, /* R99 - Input Mixer Volume R */
653 0x0000, /* R100 - Input Mixer Volume */
654 0x0000, /* R101 */
655 0x0000, /* R102 */
656 0x0000, /* R103 */
657 0x00E4, /* R104 - LOUT1 Volume */
658 0x00E4, /* R105 - ROUT1 Volume */
659 0x00E4, /* R106 - LOUT2 Volume */
660 0x02E4, /* R107 - ROUT2 Volume */
661 0x0000, /* R108 */
662 0x0000, /* R109 */
663 0x0000, /* R110 */
664 0x0000, /* R111 - BEEP Volume */
665 0x0A00, /* R112 - AI Formating */
666 0x0000, /* R113 - ADC DAC COMP */
667 0x0020, /* R114 - AI ADC Control */
668 0x0020, /* R115 - AI DAC Control */
669 0x0000, /* R116 - AIF Test */
670 0x0000, /* R117 */
671 0x0000, /* R118 */
672 0x0000, /* R119 */
673 0x0000, /* R120 */
674 0x0000, /* R121 */
675 0x0000, /* R122 */
676 0x0000, /* R123 */
677 0x0000, /* R124 */
678 0x0000, /* R125 */
679 0x0000, /* R126 */
680 0x0000, /* R127 */
681 0x1FFF, /* R128 - GPIO Debounce */
682 0x0000, /* R129 - GPIO Pin pull up Control */
683 0x03FC, /* R130 - GPIO Pull down Control */
684 0x0000, /* R131 - GPIO Interrupt Mode */
685 0x0000, /* R132 */
686 0x0000, /* R133 - GPIO Control */
687 0x08FB, /* R134 - GPIO Configuration (i/o) */
688 0x0CFE, /* R135 - GPIO Pin Polarity / Type */
689 0x0000, /* R136 */
690 0x0000, /* R137 */
691 0x0000, /* R138 */
692 0x0000, /* R139 */
693 0x0312, /* R140 - GPIO Function Select 1 */
694 0x0003, /* R141 - GPIO Function Select 2 */
695 0x2331, /* R142 - GPIO Function Select 3 */
696 0x0003, /* R143 - GPIO Function Select 4 */
697 0x0000, /* R144 - Digitiser Control (1) */
698 0x0002, /* R145 - Digitiser Control (2) */
699 0x0000, /* R146 */
700 0x0000, /* R147 */
701 0x0000, /* R148 */
702 0x0000, /* R149 */
703 0x0000, /* R150 */
704 0x0000, /* R151 */
705 0x7000, /* R152 - AUX1 Readback */
706 0x7000, /* R153 - AUX2 Readback */
707 0x7000, /* R154 - AUX3 Readback */
708 0x7000, /* R155 - AUX4 Readback */
709 0x0000, /* R156 - USB Voltage Readback */
710 0x0000, /* R157 - LINE Voltage Readback */
711 0x0000, /* R158 - BATT Voltage Readback */
712 0x0000, /* R159 - Chip Temp Readback */
713 0x0000, /* R160 */
714 0x0000, /* R161 */
715 0x0000, /* R162 */
716 0x0000, /* R163 - Generic Comparator Control */
717 0x0000, /* R164 - Generic comparator 1 */
718 0x0000, /* R165 - Generic comparator 2 */
719 0x0000, /* R166 - Generic comparator 3 */
720 0x0000, /* R167 - Generic comparator 4 */
721 0xA00F, /* R168 - Battery Charger Control 1 */
722 0x0B06, /* R169 - Battery Charger Control 2 */
723 0x0000, /* R170 - Battery Charger Control 3 */
724 0x0000, /* R171 */
725 0x0000, /* R172 - Current Sink Driver A */
726 0x0000, /* R173 - CSA Flash control */
727 0x0000, /* R174 - Current Sink Driver B */
728 0x0000, /* R175 - CSB Flash control */
729 0x0000, /* R176 - DCDC/LDO requested */
730 0x002D, /* R177 - DCDC Active options */
731 0x0000, /* R178 - DCDC Sleep options */
732 0x0025, /* R179 - Power-check comparator */
733 0x000E, /* R180 - DCDC1 Control */
734 0x0400, /* R181 - DCDC1 Timeouts */
735 0x1006, /* R182 - DCDC1 Low Power */
736 0x0018, /* R183 - DCDC2 Control */
737 0x0000, /* R184 - DCDC2 Timeouts */
738 0x0000, /* R185 */
739 0x002E, /* R186 - DCDC3 Control */
740 0x0800, /* R187 - DCDC3 Timeouts */
741 0x0006, /* R188 - DCDC3 Low Power */
742 0x000E, /* R189 - DCDC4 Control */
743 0x0800, /* R190 - DCDC4 Timeouts */
744 0x0006, /* R191 - DCDC4 Low Power */
745 0x0008, /* R192 - DCDC5 Control */
746 0x0000, /* R193 - DCDC5 Timeouts */
747 0x0000, /* R194 */
748 0x0026, /* R195 - DCDC6 Control */
749 0x0C00, /* R196 - DCDC6 Timeouts */
750 0x0006, /* R197 - DCDC6 Low Power */
751 0x0000, /* R198 */
752 0x0003, /* R199 - Limit Switch Control */
753 0x001A, /* R200 - LDO1 Control */
754 0x0800, /* R201 - LDO1 Timeouts */
755 0x001C, /* R202 - LDO1 Low Power */
756 0x0010, /* R203 - LDO2 Control */
757 0x0800, /* R204 - LDO2 Timeouts */
758 0x001C, /* R205 - LDO2 Low Power */
759 0x000A, /* R206 - LDO3 Control */
760 0x0C00, /* R207 - LDO3 Timeouts */
761 0x001C, /* R208 - LDO3 Low Power */
762 0x001A, /* R209 - LDO4 Control */
763 0x0800, /* R210 - LDO4 Timeouts */
764 0x001C, /* R211 - LDO4 Low Power */
765 0x0000, /* R212 */
766 0x0000, /* R213 */
767 0x0000, /* R214 */
768 0x0000, /* R215 - VCC_FAULT Masks */
769 0x001F, /* R216 - Main Bandgap Control */
770 0x0000, /* R217 - OSC Control */
771 0x9000, /* R218 - RTC Tick Control */
772 0x0000, /* R219 */
773 0x4000, /* R220 - RAM BIST 1 */
774 0x0000, /* R221 */
775 0x0000, /* R222 */
776 0x0000, /* R223 */
777 0x0000, /* R224 */
778 0x0000, /* R225 - DCDC/LDO status */
779 0x0000, /* R226 */
780 0x0000, /* R227 */
781 0x0000, /* R228 */
782 0x0000, /* R229 */
783 0xE000, /* R230 - GPIO Pin Status */
784 0x0000, /* R231 */
785 0x0000, /* R232 */
786 0x0000, /* R233 */
787 0x0000, /* R234 */
788 0x0000, /* R235 */
789 0x0000, /* R236 */
790 0x0000, /* R237 */
791 0x0000, /* R238 */
792 0x0000, /* R239 */
793 0x0000, /* R240 */
794 0x0000, /* R241 */
795 0x0000, /* R242 */
796 0x0000, /* R243 */
797 0x0000, /* R244 */
798 0x0000, /* R245 */
799 0x0000, /* R246 */
800 0x0000, /* R247 */
801 0x0000, /* R248 */
802 0x0000, /* R249 */
803 0x0000, /* R250 */
804 0x0000, /* R251 */
805 0x0000, /* R252 */
806 0x0000, /* R253 */
807 0x0000, /* R254 */
808 0x0000, /* R255 */
809};
810#endif
811
812#ifdef CONFIG_MFD_WM8350_CONFIG_MODE_3
813
814#undef WM8350_HAVE_CONFIG_MODE
815#define WM8350_HAVE_CONFIG_MODE
816
817const u16 wm8350_mode3_defaults[] = {
818 0x17FF, /* R0 - Reset/ID */
819 0x1000, /* R1 - ID */
820 0x0000, /* R2 */
821 0x1000, /* R3 - System Control 1 */
822 0x0004, /* R4 - System Control 2 */
823 0x0000, /* R5 - System Hibernate */
824 0x8A00, /* R6 - Interface Control */
825 0x0000, /* R7 */
826 0x8000, /* R8 - Power mgmt (1) */
827 0x0000, /* R9 - Power mgmt (2) */
828 0x0000, /* R10 - Power mgmt (3) */
829 0x2000, /* R11 - Power mgmt (4) */
830 0x0E00, /* R12 - Power mgmt (5) */
831 0x0000, /* R13 - Power mgmt (6) */
832 0x0000, /* R14 - Power mgmt (7) */
833 0x0000, /* R15 */
834 0x0000, /* R16 - RTC Seconds/Minutes */
835 0x0100, /* R17 - RTC Hours/Day */
836 0x0101, /* R18 - RTC Date/Month */
837 0x1400, /* R19 - RTC Year */
838 0x0000, /* R20 - Alarm Seconds/Minutes */
839 0x0000, /* R21 - Alarm Hours/Day */
840 0x0000, /* R22 - Alarm Date/Month */
841 0x0320, /* R23 - RTC Time Control */
842 0x0000, /* R24 - System Interrupts */
843 0x0000, /* R25 - Interrupt Status 1 */
844 0x0000, /* R26 - Interrupt Status 2 */
845 0x0000, /* R27 - Power Up Interrupt Status */
846 0x0000, /* R28 - Under Voltage Interrupt status */
847 0x0000, /* R29 - Over Current Interrupt status */
848 0x0000, /* R30 - GPIO Interrupt Status */
849 0x0000, /* R31 - Comparator Interrupt Status */
850 0x3FFF, /* R32 - System Interrupts Mask */
851 0x0000, /* R33 - Interrupt Status 1 Mask */
852 0x0000, /* R34 - Interrupt Status 2 Mask */
853 0x0000, /* R35 - Power Up Interrupt Status Mask */
854 0x0000, /* R36 - Under Voltage Interrupt status Mask */
855 0x0000, /* R37 - Over Current Interrupt status Mask */
856 0x0000, /* R38 - GPIO Interrupt Status Mask */
857 0x0000, /* R39 - Comparator Interrupt Status Mask */
858 0x0040, /* R40 - Clock Control 1 */
859 0x0000, /* R41 - Clock Control 2 */
860 0x3B00, /* R42 - FLL Control 1 */
861 0x7086, /* R43 - FLL Control 2 */
862 0xC226, /* R44 - FLL Control 3 */
863 0x0000, /* R45 - FLL Control 4 */
864 0x0000, /* R46 */
865 0x0000, /* R47 */
866 0x0000, /* R48 - DAC Control */
867 0x0000, /* R49 */
868 0x00C0, /* R50 - DAC Digital Volume L */
869 0x00C0, /* R51 - DAC Digital Volume R */
870 0x0000, /* R52 */
871 0x0040, /* R53 - DAC LR Rate */
872 0x0000, /* R54 - DAC Clock Control */
873 0x0000, /* R55 */
874 0x0000, /* R56 */
875 0x0000, /* R57 */
876 0x4000, /* R58 - DAC Mute */
877 0x0000, /* R59 - DAC Mute Volume */
878 0x0000, /* R60 - DAC Side */
879 0x0000, /* R61 */
880 0x0000, /* R62 */
881 0x0000, /* R63 */
882 0x8000, /* R64 - ADC Control */
883 0x0000, /* R65 */
884 0x00C0, /* R66 - ADC Digital Volume L */
885 0x00C0, /* R67 - ADC Digital Volume R */
886 0x0000, /* R68 - ADC Divider */
887 0x0000, /* R69 */
888 0x0040, /* R70 - ADC LR Rate */
889 0x0000, /* R71 */
890 0x0303, /* R72 - Input Control */
891 0x0000, /* R73 - IN3 Input Control */
892 0x0000, /* R74 - Mic Bias Control */
893 0x0000, /* R75 */
894 0x0000, /* R76 - Output Control */
895 0x0000, /* R77 - Jack Detect */
896 0x0000, /* R78 - Anti Pop Control */
897 0x0000, /* R79 */
898 0x0040, /* R80 - Left Input Volume */
899 0x0040, /* R81 - Right Input Volume */
900 0x0000, /* R82 */
901 0x0000, /* R83 */
902 0x0000, /* R84 */
903 0x0000, /* R85 */
904 0x0000, /* R86 */
905 0x0000, /* R87 */
906 0x0800, /* R88 - Left Mixer Control */
907 0x1000, /* R89 - Right Mixer Control */
908 0x0000, /* R90 */
909 0x0000, /* R91 */
910 0x0000, /* R92 - OUT3 Mixer Control */
911 0x0000, /* R93 - OUT4 Mixer Control */
912 0x0000, /* R94 */
913 0x0000, /* R95 */
914 0x0000, /* R96 - Output Left Mixer Volume */
915 0x0000, /* R97 - Output Right Mixer Volume */
916 0x0000, /* R98 - Input Mixer Volume L */
917 0x0000, /* R99 - Input Mixer Volume R */
918 0x0000, /* R100 - Input Mixer Volume */
919 0x0000, /* R101 */
920 0x0000, /* R102 */
921 0x0000, /* R103 */
922 0x00E4, /* R104 - LOUT1 Volume */
923 0x00E4, /* R105 - ROUT1 Volume */
924 0x00E4, /* R106 - LOUT2 Volume */
925 0x02E4, /* R107 - ROUT2 Volume */
926 0x0000, /* R108 */
927 0x0000, /* R109 */
928 0x0000, /* R110 */
929 0x0000, /* R111 - BEEP Volume */
930 0x0A00, /* R112 - AI Formating */
931 0x0000, /* R113 - ADC DAC COMP */
932 0x0020, /* R114 - AI ADC Control */
933 0x0020, /* R115 - AI DAC Control */
934 0x0000, /* R116 - AIF Test */
935 0x0000, /* R117 */
936 0x0000, /* R118 */
937 0x0000, /* R119 */
938 0x0000, /* R120 */
939 0x0000, /* R121 */
940 0x0000, /* R122 */
941 0x0000, /* R123 */
942 0x0000, /* R124 */
943 0x0000, /* R125 */
944 0x0000, /* R126 */
945 0x0000, /* R127 */
946 0x1FFF, /* R128 - GPIO Debounce */
947 0x0000, /* R129 - GPIO Pin pull up Control */
948 0x03FC, /* R130 - GPIO Pull down Control */
949 0x0000, /* R131 - GPIO Interrupt Mode */
950 0x0000, /* R132 */
951 0x0000, /* R133 - GPIO Control */
952 0x0A7B, /* R134 - GPIO Configuration (i/o) */
953 0x06FE, /* R135 - GPIO Pin Polarity / Type */
954 0x0000, /* R136 */
955 0x0000, /* R137 */
956 0x0000, /* R138 */
957 0x0000, /* R139 */
958 0x1312, /* R140 - GPIO Function Select 1 */
959 0x1030, /* R141 - GPIO Function Select 2 */
960 0x2231, /* R142 - GPIO Function Select 3 */
961 0x0003, /* R143 - GPIO Function Select 4 */
962 0x0000, /* R144 - Digitiser Control (1) */
963 0x0002, /* R145 - Digitiser Control (2) */
964 0x0000, /* R146 */
965 0x0000, /* R147 */
966 0x0000, /* R148 */
967 0x0000, /* R149 */
968 0x0000, /* R150 */
969 0x0000, /* R151 */
970 0x7000, /* R152 - AUX1 Readback */
971 0x7000, /* R153 - AUX2 Readback */
972 0x7000, /* R154 - AUX3 Readback */
973 0x7000, /* R155 - AUX4 Readback */
974 0x0000, /* R156 - USB Voltage Readback */
975 0x0000, /* R157 - LINE Voltage Readback */
976 0x0000, /* R158 - BATT Voltage Readback */
977 0x0000, /* R159 - Chip Temp Readback */
978 0x0000, /* R160 */
979 0x0000, /* R161 */
980 0x0000, /* R162 */
981 0x0000, /* R163 - Generic Comparator Control */
982 0x0000, /* R164 - Generic comparator 1 */
983 0x0000, /* R165 - Generic comparator 2 */
984 0x0000, /* R166 - Generic comparator 3 */
985 0x0000, /* R167 - Generic comparator 4 */
986 0xA00F, /* R168 - Battery Charger Control 1 */
987 0x0B06, /* R169 - Battery Charger Control 2 */
988 0x0000, /* R170 - Battery Charger Control 3 */
989 0x0000, /* R171 */
990 0x0000, /* R172 - Current Sink Driver A */
991 0x0000, /* R173 - CSA Flash control */
992 0x0000, /* R174 - Current Sink Driver B */
993 0x0000, /* R175 - CSB Flash control */
994 0x0000, /* R176 - DCDC/LDO requested */
995 0x002D, /* R177 - DCDC Active options */
996 0x0000, /* R178 - DCDC Sleep options */
997 0x0025, /* R179 - Power-check comparator */
998 0x000E, /* R180 - DCDC1 Control */
999 0x0400, /* R181 - DCDC1 Timeouts */
1000 0x1006, /* R182 - DCDC1 Low Power */
1001 0x0018, /* R183 - DCDC2 Control */
1002 0x0000, /* R184 - DCDC2 Timeouts */
1003 0x0000, /* R185 */
1004 0x000E, /* R186 - DCDC3 Control */
1005 0x0400, /* R187 - DCDC3 Timeouts */
1006 0x0006, /* R188 - DCDC3 Low Power */
1007 0x0026, /* R189 - DCDC4 Control */
1008 0x0400, /* R190 - DCDC4 Timeouts */
1009 0x0006, /* R191 - DCDC4 Low Power */
1010 0x0008, /* R192 - DCDC5 Control */
1011 0x0000, /* R193 - DCDC5 Timeouts */
1012 0x0000, /* R194 */
1013 0x0026, /* R195 - DCDC6 Control */
1014 0x0400, /* R196 - DCDC6 Timeouts */
1015 0x0006, /* R197 - DCDC6 Low Power */
1016 0x0000, /* R198 */
1017 0x0003, /* R199 - Limit Switch Control */
1018 0x001C, /* R200 - LDO1 Control */
1019 0x0000, /* R201 - LDO1 Timeouts */
1020 0x001C, /* R202 - LDO1 Low Power */
1021 0x001C, /* R203 - LDO2 Control */
1022 0x0400, /* R204 - LDO2 Timeouts */
1023 0x001C, /* R205 - LDO2 Low Power */
1024 0x001C, /* R206 - LDO3 Control */
1025 0x0400, /* R207 - LDO3 Timeouts */
1026 0x001C, /* R208 - LDO3 Low Power */
1027 0x001F, /* R209 - LDO4 Control */
1028 0x0400, /* R210 - LDO4 Timeouts */
1029 0x001C, /* R211 - LDO4 Low Power */
1030 0x0000, /* R212 */
1031 0x0000, /* R213 */
1032 0x0000, /* R214 */
1033 0x0000, /* R215 - VCC_FAULT Masks */
1034 0x001F, /* R216 - Main Bandgap Control */
1035 0x0000, /* R217 - OSC Control */
1036 0x9000, /* R218 - RTC Tick Control */
1037 0x0000, /* R219 */
1038 0x4000, /* R220 - RAM BIST 1 */
1039 0x0000, /* R221 */
1040 0x0000, /* R222 */
1041 0x0000, /* R223 */
1042 0x0000, /* R224 */
1043 0x0000, /* R225 - DCDC/LDO status */
1044 0x0000, /* R226 */
1045 0x0000, /* R227 */
1046 0x0000, /* R228 */
1047 0x0000, /* R229 */
1048 0xE000, /* R230 - GPIO Pin Status */
1049 0x0000, /* R231 */
1050 0x0000, /* R232 */
1051 0x0000, /* R233 */
1052 0x0000, /* R234 */
1053 0x0000, /* R235 */
1054 0x0000, /* R236 */
1055 0x0000, /* R237 */
1056 0x0000, /* R238 */
1057 0x0000, /* R239 */
1058 0x0000, /* R240 */
1059 0x0000, /* R241 */
1060 0x0000, /* R242 */
1061 0x0000, /* R243 */
1062 0x0000, /* R244 */
1063 0x0000, /* R245 */
1064 0x0000, /* R246 */
1065 0x0000, /* R247 */
1066 0x0000, /* R248 */
1067 0x0000, /* R249 */
1068 0x0000, /* R250 */
1069 0x0000, /* R251 */
1070 0x0000, /* R252 */
1071 0x0000, /* R253 */
1072 0x0000, /* R254 */
1073 0x0000, /* R255 */
1074};
1075#endif
1076
1077/* The register defaults for the config mode used must be compiled in but
1078 * due to the impact on kernel size it is possible to disable
1079 */
1080#ifndef WM8350_HAVE_CONFIG_MODE
1081#warning No WM8350 config modes supported - select at least one of the
1082#warning MFD_WM8350_CONFIG_MODE_n options from the board driver.
1083#endif
1084
1085/*
1086 * Access masks.
1087 */
1088
1089const struct wm8350_reg_access wm8350_reg_io_map[] = {
1090 /* read write volatile */
1091 { 0xFFFF, 0xFFFF, 0xFFFF }, /* R0 - Reset/ID */
1092 { 0x7CFF, 0x0C00, 0x7FFF }, /* R1 - ID */
1093 { 0x0000, 0x0000, 0x0000 }, /* R2 */
1094 { 0xBE3B, 0xBE3B, 0x8000 }, /* R3 - System Control 1 */
1095 { 0xFCF7, 0xFCF7, 0xF800 }, /* R4 - System Control 2 */
1096 { 0x80FF, 0x80FF, 0x8000 }, /* R5 - System Hibernate */
1097 { 0xFB0E, 0xFB0E, 0x0000 }, /* R6 - Interface Control */
1098 { 0x0000, 0x0000, 0x0000 }, /* R7 */
1099 { 0xE537, 0xE537, 0xFFFF }, /* R8 - Power mgmt (1) */
1100 { 0x0FF3, 0x0FF3, 0xFFFF }, /* R9 - Power mgmt (2) */
1101 { 0x008F, 0x008F, 0xFFFF }, /* R10 - Power mgmt (3) */
1102 { 0x6D3C, 0x6D3C, 0xFFFF }, /* R11 - Power mgmt (4) */
1103 { 0x1F8F, 0x1F8F, 0xFFFF }, /* R12 - Power mgmt (5) */
1104 { 0x8F3F, 0x8F3F, 0xFFFF }, /* R13 - Power mgmt (6) */
1105 { 0x0003, 0x0003, 0xFFFF }, /* R14 - Power mgmt (7) */
1106 { 0x0000, 0x0000, 0x0000 }, /* R15 */
1107 { 0x7F7F, 0x7F7F, 0xFFFF }, /* R16 - RTC Seconds/Minutes */
1108 { 0x073F, 0x073F, 0xFFFF }, /* R17 - RTC Hours/Day */
1109 { 0x1F3F, 0x1F3F, 0xFFFF }, /* R18 - RTC Date/Month */
1110 { 0x3FFF, 0x00FF, 0xFFFF }, /* R19 - RTC Year */
1111 { 0x7F7F, 0x7F7F, 0x0000 }, /* R20 - Alarm Seconds/Minutes */
1112 { 0x0F3F, 0x0F3F, 0x0000 }, /* R21 - Alarm Hours/Day */
1113 { 0x1F3F, 0x1F3F, 0x0000 }, /* R22 - Alarm Date/Month */
1114 { 0xEF7F, 0xEA7F, 0xFFFF }, /* R23 - RTC Time Control */
1115 { 0x3BFF, 0x0000, 0xFFFF }, /* R24 - System Interrupts */
1116 { 0xFEE7, 0x0000, 0xFFFF }, /* R25 - Interrupt Status 1 */
1117 { 0x35FF, 0x0000, 0xFFFF }, /* R26 - Interrupt Status 2 */
1118 { 0x0F3F, 0x0000, 0xFFFF }, /* R27 - Power Up Interrupt Status */
1119 { 0x0F3F, 0x0000, 0xFFFF }, /* R28 - Under Voltage Interrupt status */
1120 { 0x8000, 0x0000, 0xFFFF }, /* R29 - Over Current Interrupt status */
1121 { 0x1FFF, 0x0000, 0xFFFF }, /* R30 - GPIO Interrupt Status */
1122 { 0xEF7F, 0x0000, 0xFFFF }, /* R31 - Comparator Interrupt Status */
1123 { 0x3FFF, 0x3FFF, 0x0000 }, /* R32 - System Interrupts Mask */
1124 { 0xFEE7, 0xFEE7, 0x0000 }, /* R33 - Interrupt Status 1 Mask */
1125 { 0xF5FF, 0xF5FF, 0x0000 }, /* R34 - Interrupt Status 2 Mask */
1126 { 0x0F3F, 0x0F3F, 0x0000 }, /* R35 - Power Up Interrupt Status Mask */
1127 { 0x0F3F, 0x0F3F, 0x0000 }, /* R36 - Under Voltage Int status Mask */
1128 { 0x8000, 0x8000, 0x0000 }, /* R37 - Over Current Int status Mask */
1129 { 0x1FFF, 0x1FFF, 0x0000 }, /* R38 - GPIO Interrupt Status Mask */
1130 { 0xEF7F, 0xEF7F, 0x0000 }, /* R39 - Comparator IntStatus Mask */
1131 { 0xC9F7, 0xC9F7, 0xFFFF }, /* R40 - Clock Control 1 */
1132 { 0x8001, 0x8001, 0x0000 }, /* R41 - Clock Control 2 */
1133 { 0xFFF7, 0xFFF7, 0xFFFF }, /* R42 - FLL Control 1 */
1134 { 0xFBFF, 0xFBFF, 0x0000 }, /* R43 - FLL Control 2 */
1135 { 0xFFFF, 0xFFFF, 0x0000 }, /* R44 - FLL Control 3 */
1136 { 0x0033, 0x0033, 0x0000 }, /* R45 - FLL Control 4 */
1137 { 0x0000, 0x0000, 0x0000 }, /* R46 */
1138 { 0x0000, 0x0000, 0x0000 }, /* R47 */
1139 { 0x3033, 0x3033, 0x0000 }, /* R48 - DAC Control */
1140 { 0x0000, 0x0000, 0x0000 }, /* R49 */
1141 { 0x81FF, 0x81FF, 0xFFFF }, /* R50 - DAC Digital Volume L */
1142 { 0x81FF, 0x81FF, 0xFFFF }, /* R51 - DAC Digital Volume R */
1143 { 0x0000, 0x0000, 0x0000 }, /* R52 */
1144 { 0x0FFF, 0x0FFF, 0xFFFF }, /* R53 - DAC LR Rate */
1145 { 0x0017, 0x0017, 0x0000 }, /* R54 - DAC Clock Control */
1146 { 0x0000, 0x0000, 0x0000 }, /* R55 */
1147 { 0x0000, 0x0000, 0x0000 }, /* R56 */
1148 { 0x0000, 0x0000, 0x0000 }, /* R57 */
1149 { 0x4000, 0x4000, 0x0000 }, /* R58 - DAC Mute */
1150 { 0x7000, 0x7000, 0x0000 }, /* R59 - DAC Mute Volume */
1151 { 0x3C00, 0x3C00, 0x0000 }, /* R60 - DAC Side */
1152 { 0x0000, 0x0000, 0x0000 }, /* R61 */
1153 { 0x0000, 0x0000, 0x0000 }, /* R62 */
1154 { 0x0000, 0x0000, 0x0000 }, /* R63 */
1155 { 0x8303, 0x8303, 0xFFFF }, /* R64 - ADC Control */
1156 { 0x0000, 0x0000, 0x0000 }, /* R65 */
1157 { 0x81FF, 0x81FF, 0xFFFF }, /* R66 - ADC Digital Volume L */
1158 { 0x81FF, 0x81FF, 0xFFFF }, /* R67 - ADC Digital Volume R */
1159 { 0x0FFF, 0x0FFF, 0x0000 }, /* R68 - ADC Divider */
1160 { 0x0000, 0x0000, 0x0000 }, /* R69 */
1161 { 0x0FFF, 0x0FFF, 0xFFFF }, /* R70 - ADC LR Rate */
1162 { 0x0000, 0x0000, 0x0000 }, /* R71 */
1163 { 0x0707, 0x0707, 0xFFFF }, /* R72 - Input Control */
1164 { 0xC0C0, 0xC0C0, 0xFFFF }, /* R73 - IN3 Input Control */
1165 { 0xC09F, 0xC09F, 0xFFFF }, /* R74 - Mic Bias Control */
1166 { 0x0000, 0x0000, 0x0000 }, /* R75 */
1167 { 0x0F15, 0x0F15, 0xFFFF }, /* R76 - Output Control */
1168 { 0xC000, 0xC000, 0xFFFF }, /* R77 - Jack Detect */
1169 { 0x03FF, 0x03FF, 0x0000 }, /* R78 - Anti Pop Control */
1170 { 0x0000, 0x0000, 0x0000 }, /* R79 */
1171 { 0xE1FC, 0xE1FC, 0x8000 }, /* R80 - Left Input Volume */
1172 { 0xE1FC, 0xE1FC, 0x8000 }, /* R81 - Right Input Volume */
1173 { 0x0000, 0x0000, 0x0000 }, /* R82 */
1174 { 0x0000, 0x0000, 0x0000 }, /* R83 */
1175 { 0x0000, 0x0000, 0x0000 }, /* R84 */
1176 { 0x0000, 0x0000, 0x0000 }, /* R85 */
1177 { 0x0000, 0x0000, 0x0000 }, /* R86 */
1178 { 0x0000, 0x0000, 0x0000 }, /* R87 */
1179 { 0x9807, 0x9807, 0xFFFF }, /* R88 - Left Mixer Control */
1180 { 0x980B, 0x980B, 0xFFFF }, /* R89 - Right Mixer Control */
1181 { 0x0000, 0x0000, 0x0000 }, /* R90 */
1182 { 0x0000, 0x0000, 0x0000 }, /* R91 */
1183 { 0x8909, 0x8909, 0xFFFF }, /* R92 - OUT3 Mixer Control */
1184 { 0x9E07, 0x9E07, 0xFFFF }, /* R93 - OUT4 Mixer Control */
1185 { 0x0000, 0x0000, 0x0000 }, /* R94 */
1186 { 0x0000, 0x0000, 0x0000 }, /* R95 */
1187 { 0x0EEE, 0x0EEE, 0x0000 }, /* R96 - Output Left Mixer Volume */
1188 { 0xE0EE, 0xE0EE, 0x0000 }, /* R97 - Output Right Mixer Volume */
1189 { 0x0E0F, 0x0E0F, 0x0000 }, /* R98 - Input Mixer Volume L */
1190 { 0xE0E1, 0xE0E1, 0x0000 }, /* R99 - Input Mixer Volume R */
1191 { 0x800E, 0x800E, 0x0000 }, /* R100 - Input Mixer Volume */
1192 { 0x0000, 0x0000, 0x0000 }, /* R101 */
1193 { 0x0000, 0x0000, 0x0000 }, /* R102 */
1194 { 0x0000, 0x0000, 0x0000 }, /* R103 */
1195 { 0xE1FC, 0xE1FC, 0xFFFF }, /* R104 - LOUT1 Volume */
1196 { 0xE1FC, 0xE1FC, 0xFFFF }, /* R105 - ROUT1 Volume */
1197 { 0xE1FC, 0xE1FC, 0xFFFF }, /* R106 - LOUT2 Volume */
1198 { 0xE7FC, 0xE7FC, 0xFFFF }, /* R107 - ROUT2 Volume */
1199 { 0x0000, 0x0000, 0x0000 }, /* R108 */
1200 { 0x0000, 0x0000, 0x0000 }, /* R109 */
1201 { 0x0000, 0x0000, 0x0000 }, /* R110 */
1202 { 0x80E0, 0x80E0, 0xFFFF }, /* R111 - BEEP Volume */
1203 { 0xBF00, 0xBF00, 0x0000 }, /* R112 - AI Formating */
1204 { 0x00F1, 0x00F1, 0x0000 }, /* R113 - ADC DAC COMP */
1205 { 0x00F8, 0x00F8, 0x0000 }, /* R114 - AI ADC Control */
1206 { 0x40FB, 0x40FB, 0x0000 }, /* R115 - AI DAC Control */
1207 { 0x7C30, 0x7C30, 0x0000 }, /* R116 - AIF Test */
1208 { 0x0000, 0x0000, 0x0000 }, /* R117 */
1209 { 0x0000, 0x0000, 0x0000 }, /* R118 */
1210 { 0x0000, 0x0000, 0x0000 }, /* R119 */
1211 { 0x0000, 0x0000, 0x0000 }, /* R120 */
1212 { 0x0000, 0x0000, 0x0000 }, /* R121 */
1213 { 0x0000, 0x0000, 0x0000 }, /* R122 */
1214 { 0x0000, 0x0000, 0x0000 }, /* R123 */
1215 { 0x0000, 0x0000, 0x0000 }, /* R124 */
1216 { 0x0000, 0x0000, 0x0000 }, /* R125 */
1217 { 0x0000, 0x0000, 0x0000 }, /* R126 */
1218 { 0x0000, 0x0000, 0x0000 }, /* R127 */
1219 { 0x1FFF, 0x1FFF, 0x0000 }, /* R128 - GPIO Debounce */
1220 { 0x1FFF, 0x1FFF, 0x0000 }, /* R129 - GPIO Pin pull up Control */
1221 { 0x1FFF, 0x1FFF, 0x0000 }, /* R130 - GPIO Pull down Control */
1222 { 0x1FFF, 0x1FFF, 0x0000 }, /* R131 - GPIO Interrupt Mode */
1223 { 0x0000, 0x0000, 0x0000 }, /* R132 */
1224 { 0x00C0, 0x00C0, 0x0000 }, /* R133 - GPIO Control */
1225 { 0x1FFF, 0x1FFF, 0x0000 }, /* R134 - GPIO Configuration (i/o) */
1226 { 0x1FFF, 0x1FFF, 0x0000 }, /* R135 - GPIO Pin Polarity / Type */
1227 { 0x0000, 0x0000, 0x0000 }, /* R136 */
1228 { 0x0000, 0x0000, 0x0000 }, /* R137 */
1229 { 0x0000, 0x0000, 0x0000 }, /* R138 */
1230 { 0x0000, 0x0000, 0x0000 }, /* R139 */
1231 { 0xFFFF, 0xFFFF, 0x0000 }, /* R140 - GPIO Function Select 1 */
1232 { 0xFFFF, 0xFFFF, 0x0000 }, /* R141 - GPIO Function Select 2 */
1233 { 0xFFFF, 0xFFFF, 0x0000 }, /* R142 - GPIO Function Select 3 */
1234 { 0x000F, 0x000F, 0x0000 }, /* R143 - GPIO Function Select 4 */
1235 { 0xF0FF, 0xF0FF, 0xA000 }, /* R144 - Digitiser Control (1) */
1236 { 0x3707, 0x3707, 0x0000 }, /* R145 - Digitiser Control (2) */
1237 { 0x0000, 0x0000, 0x0000 }, /* R146 */
1238 { 0x0000, 0x0000, 0x0000 }, /* R147 */
1239 { 0x0000, 0x0000, 0x0000 }, /* R148 */
1240 { 0x0000, 0x0000, 0x0000 }, /* R149 */
1241 { 0x0000, 0x0000, 0x0000 }, /* R150 */
1242 { 0x0000, 0x0000, 0x0000 }, /* R151 */
1243 { 0x7FFF, 0x7000, 0xFFFF }, /* R152 - AUX1 Readback */
1244 { 0x7FFF, 0x7000, 0xFFFF }, /* R153 - AUX2 Readback */
1245 { 0x7FFF, 0x7000, 0xFFFF }, /* R154 - AUX3 Readback */
1246 { 0x7FFF, 0x7000, 0xFFFF }, /* R155 - AUX4 Readback */
1247 { 0x0FFF, 0x0000, 0xFFFF }, /* R156 - USB Voltage Readback */
1248 { 0x0FFF, 0x0000, 0xFFFF }, /* R157 - LINE Voltage Readback */
1249 { 0x0FFF, 0x0000, 0xFFFF }, /* R158 - BATT Voltage Readback */
1250 { 0x0FFF, 0x0000, 0xFFFF }, /* R159 - Chip Temp Readback */
1251 { 0x0000, 0x0000, 0x0000 }, /* R160 */
1252 { 0x0000, 0x0000, 0x0000 }, /* R161 */
1253 { 0x0000, 0x0000, 0x0000 }, /* R162 */
1254 { 0x000F, 0x000F, 0x0000 }, /* R163 - Generic Comparator Control */
1255 { 0xFFFF, 0xFFFF, 0x0000 }, /* R164 - Generic comparator 1 */
1256 { 0xFFFF, 0xFFFF, 0x0000 }, /* R165 - Generic comparator 2 */
1257 { 0xFFFF, 0xFFFF, 0x0000 }, /* R166 - Generic comparator 3 */
1258 { 0xFFFF, 0xFFFF, 0x0000 }, /* R167 - Generic comparator 4 */
1259 { 0xBFFF, 0xBFFF, 0x8000 }, /* R168 - Battery Charger Control 1 */
1260 { 0xFFFF, 0x4FFF, 0xB000 }, /* R169 - Battery Charger Control 2 */
1261 { 0x007F, 0x007F, 0x0000 }, /* R170 - Battery Charger Control 3 */
1262 { 0x0000, 0x0000, 0x0000 }, /* R171 */
1263 { 0x903F, 0x903F, 0xFFFF }, /* R172 - Current Sink Driver A */
1264 { 0xE333, 0xE333, 0xFFFF }, /* R173 - CSA Flash control */
1265 { 0x903F, 0x903F, 0xFFFF }, /* R174 - Current Sink Driver B */
1266 { 0xE333, 0xE333, 0xFFFF }, /* R175 - CSB Flash control */
1267 { 0x8F3F, 0x8F3F, 0xFFFF }, /* R176 - DCDC/LDO requested */
1268 { 0x332D, 0x332D, 0x0000 }, /* R177 - DCDC Active options */
1269 { 0x002D, 0x002D, 0x0000 }, /* R178 - DCDC Sleep options */
1270 { 0x5177, 0x5177, 0x8000 }, /* R179 - Power-check comparator */
1271 { 0x047F, 0x047F, 0x0000 }, /* R180 - DCDC1 Control */
1272 { 0xFFC0, 0xFFC0, 0x0000 }, /* R181 - DCDC1 Timeouts */
1273 { 0x737F, 0x737F, 0x0000 }, /* R182 - DCDC1 Low Power */
1274 { 0x535B, 0x535B, 0x0000 }, /* R183 - DCDC2 Control */
1275 { 0xFFC0, 0xFFC0, 0x0000 }, /* R184 - DCDC2 Timeouts */
1276 { 0x0000, 0x0000, 0x0000 }, /* R185 */
1277 { 0x047F, 0x047F, 0x0000 }, /* R186 - DCDC3 Control */
1278 { 0xFFC0, 0xFFC0, 0x0000 }, /* R187 - DCDC3 Timeouts */
1279 { 0x737F, 0x737F, 0x0000 }, /* R188 - DCDC3 Low Power */
1280 { 0x047F, 0x047F, 0x0000 }, /* R189 - DCDC4 Control */
1281 { 0xFFC0, 0xFFC0, 0x0000 }, /* R190 - DCDC4 Timeouts */
1282 { 0x737F, 0x737F, 0x0000 }, /* R191 - DCDC4 Low Power */
1283 { 0x535B, 0x535B, 0x0000 }, /* R192 - DCDC5 Control */
1284 { 0xFFC0, 0xFFC0, 0x0000 }, /* R193 - DCDC5 Timeouts */
1285 { 0x0000, 0x0000, 0x0000 }, /* R194 */
1286 { 0x047F, 0x047F, 0x0000 }, /* R195 - DCDC6 Control */
1287 { 0xFFC0, 0xFFC0, 0x0000 }, /* R196 - DCDC6 Timeouts */
1288 { 0x737F, 0x737F, 0x0000 }, /* R197 - DCDC6 Low Power */
1289 { 0x0000, 0x0000, 0x0000 }, /* R198 */
1290 { 0xFFD3, 0xFFD3, 0x0000 }, /* R199 - Limit Switch Control */
1291 { 0x441F, 0x441F, 0x0000 }, /* R200 - LDO1 Control */
1292 { 0xFFC0, 0xFFC0, 0x0000 }, /* R201 - LDO1 Timeouts */
1293 { 0x331F, 0x331F, 0x0000 }, /* R202 - LDO1 Low Power */
1294 { 0x441F, 0x441F, 0x0000 }, /* R203 - LDO2 Control */
1295 { 0xFFC0, 0xFFC0, 0x0000 }, /* R204 - LDO2 Timeouts */
1296 { 0x331F, 0x331F, 0x0000 }, /* R205 - LDO2 Low Power */
1297 { 0x441F, 0x441F, 0x0000 }, /* R206 - LDO3 Control */
1298 { 0xFFC0, 0xFFC0, 0x0000 }, /* R207 - LDO3 Timeouts */
1299 { 0x331F, 0x331F, 0x0000 }, /* R208 - LDO3 Low Power */
1300 { 0x441F, 0x441F, 0x0000 }, /* R209 - LDO4 Control */
1301 { 0xFFC0, 0xFFC0, 0x0000 }, /* R210 - LDO4 Timeouts */
1302 { 0x331F, 0x331F, 0x0000 }, /* R211 - LDO4 Low Power */
1303 { 0x0000, 0x0000, 0x0000 }, /* R212 */
1304 { 0x0000, 0x0000, 0x0000 }, /* R213 */
1305 { 0x0000, 0x0000, 0x0000 }, /* R214 */
1306 { 0x8F3F, 0x8F3F, 0x0000 }, /* R215 - VCC_FAULT Masks */
1307 { 0xFF3F, 0xE03F, 0x0000 }, /* R216 - Main Bandgap Control */
1308 { 0xEF2F, 0xE02F, 0x0000 }, /* R217 - OSC Control */
1309 { 0xF3FF, 0xB3FF, 0xc000 }, /* R218 - RTC Tick Control */
1310 { 0xFFFF, 0xFFFF, 0xFFFF }, /* R219 */
1311 { 0x09FF, 0x01FF, 0x0000 }, /* R220 - RAM BIST 1 */
1312 { 0x0000, 0x0000, 0x0000 }, /* R221 */
1313 { 0xFFFF, 0xFFFF, 0xFFFF }, /* R222 */
1314 { 0xFFFF, 0xFFFF, 0xFFFF }, /* R223 */
1315 { 0x0000, 0x0000, 0x0000 }, /* R224 */
1316 { 0x8F3F, 0x0000, 0xFFFF }, /* R225 - DCDC/LDO status */
1317 { 0x0000, 0x0000, 0x0000 }, /* R226 */
1318 { 0x0000, 0x0000, 0xFFFF }, /* R227 */
1319 { 0x0000, 0x0000, 0x0000 }, /* R228 */
1320 { 0x0000, 0x0000, 0x0000 }, /* R229 */
1321 { 0xFFFF, 0x1FFF, 0xFFFF }, /* R230 - GPIO Pin Status */
1322 { 0xFFFF, 0x1FFF, 0xFFFF }, /* R231 */
1323 { 0xFFFF, 0x1FFF, 0xFFFF }, /* R232 */
1324 { 0xFFFF, 0x1FFF, 0xFFFF }, /* R233 */
1325 { 0x0000, 0x0000, 0x0000 }, /* R234 */
1326 { 0x0000, 0x0000, 0x0000 }, /* R235 */
1327 { 0x0000, 0x0000, 0x0000 }, /* R236 */
1328 { 0x0000, 0x0000, 0x0000 }, /* R237 */
1329 { 0x0000, 0x0000, 0x0000 }, /* R238 */
1330 { 0x0000, 0x0000, 0x0000 }, /* R239 */
1331 { 0x0000, 0x0000, 0x0000 }, /* R240 */
1332 { 0x0000, 0x0000, 0x0000 }, /* R241 */
1333 { 0x0000, 0x0000, 0x0000 }, /* R242 */
1334 { 0x0000, 0x0000, 0x0000 }, /* R243 */
1335 { 0x0000, 0x0000, 0x0000 }, /* R244 */
1336 { 0x0000, 0x0000, 0x0000 }, /* R245 */
1337 { 0x0000, 0x0000, 0x0000 }, /* R246 */
1338 { 0x0000, 0x0000, 0x0000 }, /* R247 */
1339 { 0xFFFF, 0x0010, 0xFFFF }, /* R248 */
1340 { 0x0000, 0x0000, 0x0000 }, /* R249 */
1341 { 0xFFFF, 0x0010, 0xFFFF }, /* R250 */
1342 { 0xFFFF, 0x0010, 0xFFFF }, /* R251 */
1343 { 0x0000, 0x0000, 0x0000 }, /* R252 */
1344 { 0xFFFF, 0x0010, 0xFFFF }, /* R253 */
1345 { 0x0000, 0x0000, 0x0000 }, /* R254 */
1346 { 0x0000, 0x0000, 0x0000 }, /* R255 */
1347};
diff --git a/drivers/mfd/wm8400-core.c b/drivers/mfd/wm8400-core.c
new file mode 100644
index 000000000000..6a0cedb5bb8a
--- /dev/null
+++ b/drivers/mfd/wm8400-core.c
@@ -0,0 +1,455 @@
1/*
2 * Core driver for WM8400.
3 *
4 * Copyright 2008 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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 the
11 * License, or (at your option) any later version.
12 *
13 */
14
15#include <linux/bug.h>
16#include <linux/i2c.h>
17#include <linux/kernel.h>
18#include <linux/mfd/wm8400-private.h>
19#include <linux/mfd/wm8400-audio.h>
20
21static struct {
22 u16 readable; /* Mask of readable bits */
23 u16 writable; /* Mask of writable bits */
24 u16 vol; /* Mask of volatile bits */
25 int is_codec; /* Register controlled by codec reset */
26 u16 default_val; /* Value on reset */
27} reg_data[] = {
28 { 0xFFFF, 0xFFFF, 0x0000, 0, 0x6172 }, /* R0 */
29 { 0x7000, 0x0000, 0x8000, 0, 0x0000 }, /* R1 */
30 { 0xFF17, 0xFF17, 0x0000, 0, 0x0000 }, /* R2 */
31 { 0xEBF3, 0xEBF3, 0x0000, 1, 0x6000 }, /* R3 */
32 { 0x3CF3, 0x3CF3, 0x0000, 1, 0x0000 }, /* R4 */
33 { 0xF1F8, 0xF1F8, 0x0000, 1, 0x4050 }, /* R5 */
34 { 0xFC1F, 0xFC1F, 0x0000, 1, 0x4000 }, /* R6 */
35 { 0xDFDE, 0xDFDE, 0x0000, 1, 0x01C8 }, /* R7 */
36 { 0xFCFC, 0xFCFC, 0x0000, 1, 0x0000 }, /* R8 */
37 { 0xEFFF, 0xEFFF, 0x0000, 1, 0x0040 }, /* R9 */
38 { 0xEFFF, 0xEFFF, 0x0000, 1, 0x0040 }, /* R10 */
39 { 0x27F7, 0x27F7, 0x0000, 1, 0x0004 }, /* R11 */
40 { 0x01FF, 0x01FF, 0x0000, 1, 0x00C0 }, /* R12 */
41 { 0x01FF, 0x01FF, 0x0000, 1, 0x00C0 }, /* R13 */
42 { 0x1FEF, 0x1FEF, 0x0000, 1, 0x0000 }, /* R14 */
43 { 0x0163, 0x0163, 0x0000, 1, 0x0100 }, /* R15 */
44 { 0x01FF, 0x01FF, 0x0000, 1, 0x00C0 }, /* R16 */
45 { 0x01FF, 0x01FF, 0x0000, 1, 0x00C0 }, /* R17 */
46 { 0x1FFF, 0x0FFF, 0x0000, 1, 0x0000 }, /* R18 */
47 { 0xFFFF, 0xFFFF, 0x0000, 1, 0x1000 }, /* R19 */
48 { 0xFFFF, 0xFFFF, 0x0000, 1, 0x1010 }, /* R20 */
49 { 0xFFFF, 0xFFFF, 0x0000, 1, 0x1010 }, /* R21 */
50 { 0x0FDD, 0x0FDD, 0x0000, 1, 0x8000 }, /* R22 */
51 { 0x1FFF, 0x1FFF, 0x0000, 1, 0x0800 }, /* R23 */
52 { 0x0000, 0x01DF, 0x0000, 1, 0x008B }, /* R24 */
53 { 0x0000, 0x01DF, 0x0000, 1, 0x008B }, /* R25 */
54 { 0x0000, 0x01DF, 0x0000, 1, 0x008B }, /* R26 */
55 { 0x0000, 0x01DF, 0x0000, 1, 0x008B }, /* R27 */
56 { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R28 */
57 { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R29 */
58 { 0x0000, 0x0077, 0x0000, 1, 0x0066 }, /* R30 */
59 { 0x0000, 0x0033, 0x0000, 1, 0x0022 }, /* R31 */
60 { 0x0000, 0x01FF, 0x0000, 1, 0x0079 }, /* R32 */
61 { 0x0000, 0x01FF, 0x0000, 1, 0x0079 }, /* R33 */
62 { 0x0000, 0x0003, 0x0000, 1, 0x0003 }, /* R34 */
63 { 0x0000, 0x01FF, 0x0000, 1, 0x0003 }, /* R35 */
64 { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R36 */
65 { 0x0000, 0x003F, 0x0000, 1, 0x0100 }, /* R37 */
66 { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R38 */
67 { 0x0000, 0x000F, 0x0000, 0, 0x0000 }, /* R39 */
68 { 0x0000, 0x00FF, 0x0000, 1, 0x0000 }, /* R40 */
69 { 0x0000, 0x01B7, 0x0000, 1, 0x0000 }, /* R41 */
70 { 0x0000, 0x01B7, 0x0000, 1, 0x0000 }, /* R42 */
71 { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R43 */
72 { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R44 */
73 { 0x0000, 0x00FD, 0x0000, 1, 0x0000 }, /* R45 */
74 { 0x0000, 0x00FD, 0x0000, 1, 0x0000 }, /* R46 */
75 { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R47 */
76 { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R48 */
77 { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R49 */
78 { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R50 */
79 { 0x0000, 0x01B3, 0x0000, 1, 0x0180 }, /* R51 */
80 { 0x0000, 0x0077, 0x0000, 1, 0x0000 }, /* R52 */
81 { 0x0000, 0x0077, 0x0000, 1, 0x0000 }, /* R53 */
82 { 0x0000, 0x00FF, 0x0000, 1, 0x0000 }, /* R54 */
83 { 0x0000, 0x0001, 0x0000, 1, 0x0000 }, /* R55 */
84 { 0x0000, 0x003F, 0x0000, 1, 0x0000 }, /* R56 */
85 { 0x0000, 0x004F, 0x0000, 1, 0x0000 }, /* R57 */
86 { 0x0000, 0x00FD, 0x0000, 1, 0x0000 }, /* R58 */
87 { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R59 */
88 { 0x1FFF, 0x1FFF, 0x0000, 1, 0x0000 }, /* R60 */
89 { 0xFFFF, 0xFFFF, 0x0000, 1, 0x0000 }, /* R61 */
90 { 0x03FF, 0x03FF, 0x0000, 1, 0x0000 }, /* R62 */
91 { 0x007F, 0x007F, 0x0000, 1, 0x0000 }, /* R63 */
92 { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R64 */
93 { 0xDFFF, 0xDFFF, 0x0000, 0, 0x0000 }, /* R65 */
94 { 0xDFFF, 0xDFFF, 0x0000, 0, 0x0000 }, /* R66 */
95 { 0xDFFF, 0xDFFF, 0x0000, 0, 0x0000 }, /* R67 */
96 { 0xDFFF, 0xDFFF, 0x0000, 0, 0x0000 }, /* R68 */
97 { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R69 */
98 { 0xFFFF, 0xFFFF, 0x0000, 0, 0x4400 }, /* R70 */
99 { 0x23FF, 0x23FF, 0x0000, 0, 0x0000 }, /* R71 */
100 { 0xFFFF, 0xFFFF, 0x0000, 0, 0x4400 }, /* R72 */
101 { 0x23FF, 0x23FF, 0x0000, 0, 0x0000 }, /* R73 */
102 { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R74 */
103 { 0x000E, 0x000E, 0x0000, 0, 0x0008 }, /* R75 */
104 { 0xE00F, 0xE00F, 0x0000, 0, 0x0000 }, /* R76 */
105 { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R77 */
106 { 0x03C0, 0x03C0, 0x0000, 0, 0x02C0 }, /* R78 */
107 { 0xFFFF, 0x0000, 0xffff, 0, 0x0000 }, /* R79 */
108 { 0xFFFF, 0xFFFF, 0x0000, 0, 0x0000 }, /* R80 */
109 { 0xFFFF, 0x0000, 0xffff, 0, 0x0000 }, /* R81 */
110 { 0x2BFF, 0x0000, 0xffff, 0, 0x0000 }, /* R82 */
111 { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R83 */
112 { 0x80FF, 0x80FF, 0x0000, 0, 0x00ff }, /* R84 */
113};
114
115static int wm8400_read(struct wm8400 *wm8400, u8 reg, int num_regs, u16 *dest)
116{
117 int i, ret = 0;
118
119 BUG_ON(reg + num_regs - 1 > ARRAY_SIZE(wm8400->reg_cache));
120
121 /* If there are any volatile reads then read back the entire block */
122 for (i = reg; i < reg + num_regs; i++)
123 if (reg_data[i].vol) {
124 ret = wm8400->read_dev(wm8400->io_data, reg,
125 num_regs, dest);
126 if (ret != 0)
127 return ret;
128 for (i = 0; i < num_regs; i++)
129 dest[i] = be16_to_cpu(dest[i]);
130
131 return 0;
132 }
133
134 /* Otherwise use the cache */
135 memcpy(dest, &wm8400->reg_cache[reg], num_regs * sizeof(u16));
136
137 return 0;
138}
139
140static int wm8400_write(struct wm8400 *wm8400, u8 reg, int num_regs,
141 u16 *src)
142{
143 int ret, i;
144
145 BUG_ON(reg + num_regs - 1 > ARRAY_SIZE(wm8400->reg_cache));
146
147 for (i = 0; i < num_regs; i++) {
148 BUG_ON(!reg_data[reg + i].writable);
149 wm8400->reg_cache[reg + i] = src[i];
150 src[i] = cpu_to_be16(src[i]);
151 }
152
153 /* Do the actual I/O */
154 ret = wm8400->write_dev(wm8400->io_data, reg, num_regs, src);
155 if (ret != 0)
156 return -EIO;
157
158 return 0;
159}
160
161/**
162 * wm8400_reg_read - Single register read
163 *
164 * @wm8400: Pointer to wm8400 control structure
165 * @reg: Register to read
166 *
167 * @return Read value
168 */
169u16 wm8400_reg_read(struct wm8400 *wm8400, u8 reg)
170{
171 u16 val;
172
173 mutex_lock(&wm8400->io_lock);
174
175 wm8400_read(wm8400, reg, 1, &val);
176
177 mutex_unlock(&wm8400->io_lock);
178
179 return val;
180}
181EXPORT_SYMBOL_GPL(wm8400_reg_read);
182
183int wm8400_block_read(struct wm8400 *wm8400, u8 reg, int count, u16 *data)
184{
185 int ret;
186
187 mutex_lock(&wm8400->io_lock);
188
189 ret = wm8400_read(wm8400, reg, count, data);
190
191 mutex_unlock(&wm8400->io_lock);
192
193 return ret;
194}
195EXPORT_SYMBOL_GPL(wm8400_block_read);
196
197/**
198 * wm8400_set_bits - Bitmask write
199 *
200 * @wm8400: Pointer to wm8400 control structure
201 * @reg: Register to access
202 * @mask: Mask of bits to change
203 * @val: Value to set for masked bits
204 */
205int wm8400_set_bits(struct wm8400 *wm8400, u8 reg, u16 mask, u16 val)
206{
207 u16 tmp;
208 int ret;
209
210 mutex_lock(&wm8400->io_lock);
211
212 ret = wm8400_read(wm8400, reg, 1, &tmp);
213 tmp = (tmp & ~mask) | val;
214 if (ret == 0)
215 ret = wm8400_write(wm8400, reg, 1, &tmp);
216
217 mutex_unlock(&wm8400->io_lock);
218
219 return ret;
220}
221EXPORT_SYMBOL_GPL(wm8400_set_bits);
222
223/**
224 * wm8400_reset_codec_reg_cache - Reset cached codec registers to
225 * their default values.
226 */
227void wm8400_reset_codec_reg_cache(struct wm8400 *wm8400)
228{
229 int i;
230
231 mutex_lock(&wm8400->io_lock);
232
233 /* Reset all codec registers to their initial value */
234 for (i = 0; i < ARRAY_SIZE(wm8400->reg_cache); i++)
235 if (reg_data[i].is_codec)
236 wm8400->reg_cache[i] = reg_data[i].default_val;
237
238 mutex_unlock(&wm8400->io_lock);
239}
240EXPORT_SYMBOL_GPL(wm8400_reset_codec_reg_cache);
241
242/*
243 * wm8400_init - Generic initialisation
244 *
245 * The WM8400 can be configured as either an I2C or SPI device. Probe
246 * functions for each bus set up the accessors then call into this to
247 * set up the device itself.
248 */
249static int wm8400_init(struct wm8400 *wm8400,
250 struct wm8400_platform_data *pdata)
251{
252 u16 reg;
253 int ret, i;
254
255 mutex_init(&wm8400->io_lock);
256
257 wm8400->dev->driver_data = wm8400;
258
259 /* Check that this is actually a WM8400 */
260 ret = wm8400->read_dev(wm8400->io_data, WM8400_RESET_ID, 1, &reg);
261 if (ret != 0) {
262 dev_err(wm8400->dev, "Chip ID register read failed\n");
263 return -EIO;
264 }
265 if (be16_to_cpu(reg) != reg_data[WM8400_RESET_ID].default_val) {
266 dev_err(wm8400->dev, "Device is not a WM8400, ID is %x\n",
267 be16_to_cpu(reg));
268 return -ENODEV;
269 }
270
271 /* We don't know what state the hardware is in and since this
272 * is a PMIC we can't reset it safely so initialise the register
273 * cache from the hardware.
274 */
275 ret = wm8400->read_dev(wm8400->io_data, 0,
276 ARRAY_SIZE(wm8400->reg_cache),
277 wm8400->reg_cache);
278 if (ret != 0) {
279 dev_err(wm8400->dev, "Register cache read failed\n");
280 return -EIO;
281 }
282 for (i = 0; i < ARRAY_SIZE(wm8400->reg_cache); i++)
283 wm8400->reg_cache[i] = be16_to_cpu(wm8400->reg_cache[i]);
284
285 /* If the codec is in reset use hard coded values */
286 if (!(wm8400->reg_cache[WM8400_POWER_MANAGEMENT_1] & WM8400_CODEC_ENA))
287 for (i = 0; i < ARRAY_SIZE(wm8400->reg_cache); i++)
288 if (reg_data[i].is_codec)
289 wm8400->reg_cache[i] = reg_data[i].default_val;
290
291 ret = wm8400_read(wm8400, WM8400_ID, 1, &reg);
292 if (ret != 0) {
293 dev_err(wm8400->dev, "ID register read failed: %d\n", ret);
294 return ret;
295 }
296 reg = (reg & WM8400_CHIP_REV_MASK) >> WM8400_CHIP_REV_SHIFT;
297 dev_info(wm8400->dev, "WM8400 revision %x\n", reg);
298
299 if (pdata && pdata->platform_init) {
300 ret = pdata->platform_init(wm8400->dev);
301 if (ret != 0)
302 dev_err(wm8400->dev, "Platform init failed: %d\n",
303 ret);
304 } else
305 dev_warn(wm8400->dev, "No platform initialisation supplied\n");
306
307 return ret;
308}
309
310static void wm8400_release(struct wm8400 *wm8400)
311{
312 int i;
313
314 for (i = 0; i < ARRAY_SIZE(wm8400->regulators); i++)
315 if (wm8400->regulators[i].name)
316 platform_device_unregister(&wm8400->regulators[i]);
317}
318
319#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
320static int wm8400_i2c_read(void *io_data, char reg, int count, u16 *dest)
321{
322 struct i2c_client *i2c = io_data;
323 struct i2c_msg xfer[2];
324 int ret;
325
326 /* Write register */
327 xfer[0].addr = i2c->addr;
328 xfer[0].flags = 0;
329 xfer[0].len = 1;
330 xfer[0].buf = &reg;
331
332 /* Read data */
333 xfer[1].addr = i2c->addr;
334 xfer[1].flags = I2C_M_RD;
335 xfer[1].len = count * sizeof(u16);
336 xfer[1].buf = (u8 *)dest;
337
338 ret = i2c_transfer(i2c->adapter, xfer, 2);
339 if (ret == 2)
340 ret = 0;
341 else if (ret >= 0)
342 ret = -EIO;
343
344 return ret;
345}
346
347static int wm8400_i2c_write(void *io_data, char reg, int count, const u16 *src)
348{
349 struct i2c_client *i2c = io_data;
350 u8 *msg;
351 int ret;
352
353 /* We add 1 byte for device register - ideally I2C would gather. */
354 msg = kmalloc((count * sizeof(u16)) + 1, GFP_KERNEL);
355 if (msg == NULL)
356 return -ENOMEM;
357
358 msg[0] = reg;
359 memcpy(&msg[1], src, count * sizeof(u16));
360
361 ret = i2c_master_send(i2c, msg, (count * sizeof(u16)) + 1);
362
363 if (ret == (count * 2) + 1)
364 ret = 0;
365 else if (ret >= 0)
366 ret = -EIO;
367
368 kfree(msg);
369
370 return ret;
371}
372
373static int wm8400_i2c_probe(struct i2c_client *i2c,
374 const struct i2c_device_id *id)
375{
376 struct wm8400 *wm8400;
377 int ret;
378
379 wm8400 = kzalloc(sizeof(struct wm8400), GFP_KERNEL);
380 if (wm8400 == NULL) {
381 ret = -ENOMEM;
382 goto err;
383 }
384
385 wm8400->io_data = i2c;
386 wm8400->read_dev = wm8400_i2c_read;
387 wm8400->write_dev = wm8400_i2c_write;
388 wm8400->dev = &i2c->dev;
389 i2c_set_clientdata(i2c, wm8400);
390
391 ret = wm8400_init(wm8400, i2c->dev.platform_data);
392 if (ret != 0)
393 goto struct_err;
394
395 return 0;
396
397struct_err:
398 i2c_set_clientdata(i2c, NULL);
399 kfree(wm8400);
400err:
401 return ret;
402}
403
404static int wm8400_i2c_remove(struct i2c_client *i2c)
405{
406 struct wm8400 *wm8400 = i2c_get_clientdata(i2c);
407
408 wm8400_release(wm8400);
409 i2c_set_clientdata(i2c, NULL);
410 kfree(wm8400);
411
412 return 0;
413}
414
415static const struct i2c_device_id wm8400_i2c_id[] = {
416 { "wm8400", 0 },
417 { }
418};
419MODULE_DEVICE_TABLE(i2c, wm8400_i2c_id);
420
421static struct i2c_driver wm8400_i2c_driver = {
422 .driver = {
423 .name = "WM8400",
424 .owner = THIS_MODULE,
425 },
426 .probe = wm8400_i2c_probe,
427 .remove = wm8400_i2c_remove,
428 .id_table = wm8400_i2c_id,
429};
430#endif
431
432static int __init wm8400_module_init(void)
433{
434 int ret = -ENODEV;
435
436#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
437 ret = i2c_add_driver(&wm8400_i2c_driver);
438 if (ret != 0)
439 pr_err("Failed to register I2C driver: %d\n", ret);
440#endif
441
442 return ret;
443}
444module_init(wm8400_module_init);
445
446static void __exit wm8400_module_exit(void)
447{
448#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
449 i2c_del_driver(&wm8400_i2c_driver);
450#endif
451}
452module_exit(wm8400_module_exit);
453
454MODULE_LICENSE("GPL");
455MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index a726f3b01a6b..efd3aa08b88b 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -15,7 +15,7 @@ if MISC_DEVICES
15 15
16config ATMEL_PWM 16config ATMEL_PWM
17 tristate "Atmel AT32/AT91 PWM support" 17 tristate "Atmel AT32/AT91 PWM support"
18 depends on AVR32 || ARCH_AT91 18 depends on AVR32 || ARCH_AT91SAM9263 || ARCH_AT91SAM9RL || ARCH_AT91CAP9
19 help 19 help
20 This option enables device driver support for the PWM channels 20 This option enables device driver support for the PWM channels
21 on certain Atmel prcoessors. Pulse Width Modulation is used for 21 on certain Atmel prcoessors. Pulse Width Modulation is used for
@@ -409,6 +409,7 @@ config EEEPC_LAPTOP
409 depends on BACKLIGHT_CLASS_DEVICE 409 depends on BACKLIGHT_CLASS_DEVICE
410 depends on HWMON 410 depends on HWMON
411 depends on EXPERIMENTAL 411 depends on EXPERIMENTAL
412 depends on RFKILL
412 ---help--- 413 ---help---
413 This driver supports the Fn-Fx keys on Eee PC laptops. 414 This driver supports the Fn-Fx keys on Eee PC laptops.
414 It also adds the ability to switch camera/wlan on/off. 415 It also adds the ability to switch camera/wlan on/off.
diff --git a/drivers/misc/hp-wmi.c b/drivers/misc/hp-wmi.c
index 6d407c2a4f91..5dabfb69ee53 100644
--- a/drivers/misc/hp-wmi.c
+++ b/drivers/misc/hp-wmi.c
@@ -309,7 +309,7 @@ static int hp_wmi_setkeycode(struct input_dev *dev, int scancode, int keycode)
309 return -EINVAL; 309 return -EINVAL;
310} 310}
311 311
312void hp_wmi_notify(u32 value, void *context) 312static void hp_wmi_notify(u32 value, void *context)
313{ 313{
314 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; 314 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
315 static struct key_entry *key; 315 static struct key_entry *key;
diff --git a/drivers/misc/phantom.c b/drivers/misc/phantom.c
index daf585689ce3..abdebe347383 100644
--- a/drivers/misc/phantom.c
+++ b/drivers/misc/phantom.c
@@ -399,9 +399,9 @@ static int __devinit phantom_probe(struct pci_dev *pdev,
399 goto err_irq; 399 goto err_irq;
400 } 400 }
401 401
402 if (IS_ERR(device_create_drvdata(phantom_class, &pdev->dev, 402 if (IS_ERR(device_create(phantom_class, &pdev->dev,
403 MKDEV(phantom_major, minor), 403 MKDEV(phantom_major, minor), NULL,
404 NULL, "phantom%u", minor))) 404 "phantom%u", minor)))
405 dev_err(&pdev->dev, "can't create device\n"); 405 dev_err(&pdev->dev, "can't create device\n");
406 406
407 pci_set_drvdata(pdev, pht); 407 pci_set_drvdata(pdev, pht);
diff --git a/drivers/misc/sgi-gru/gru.h b/drivers/misc/sgi-gru/gru.h
index 40df7cb3f0a5..f93f03a9e6e9 100644
--- a/drivers/misc/sgi-gru/gru.h
+++ b/drivers/misc/sgi-gru/gru.h
@@ -30,9 +30,9 @@
30/* 30/*
31 * Size used to map GRU GSeg 31 * Size used to map GRU GSeg
32 */ 32 */
33#if defined CONFIG_IA64 33#if defined(CONFIG_IA64)
34#define GRU_GSEG_PAGESIZE (256 * 1024UL) 34#define GRU_GSEG_PAGESIZE (256 * 1024UL)
35#elif defined CONFIG_X86_64 35#elif defined(CONFIG_X86_64)
36#define GRU_GSEG_PAGESIZE (256 * 1024UL) /* ZZZ 2MB ??? */ 36#define GRU_GSEG_PAGESIZE (256 * 1024UL) /* ZZZ 2MB ??? */
37#else 37#else
38#error "Unsupported architecture" 38#error "Unsupported architecture"
diff --git a/drivers/misc/sgi-gru/gru_instructions.h b/drivers/misc/sgi-gru/gru_instructions.h
index 0dc36225c7c6..48762e7b98be 100644
--- a/drivers/misc/sgi-gru/gru_instructions.h
+++ b/drivers/misc/sgi-gru/gru_instructions.h
@@ -26,7 +26,7 @@
26 * Architecture dependent functions 26 * Architecture dependent functions
27 */ 27 */
28 28
29#if defined CONFIG_IA64 29#if defined(CONFIG_IA64)
30#include <linux/compiler.h> 30#include <linux/compiler.h>
31#include <asm/intrinsics.h> 31#include <asm/intrinsics.h>
32#define __flush_cache(p) ia64_fc(p) 32#define __flush_cache(p) ia64_fc(p)
@@ -36,7 +36,7 @@
36 barrier(); \ 36 barrier(); \
37 *((volatile int *)(p)) = v; /* force st.rel */ \ 37 *((volatile int *)(p)) = v; /* force st.rel */ \
38 } while (0) 38 } while (0)
39#elif defined CONFIG_X86_64 39#elif defined(CONFIG_X86_64)
40#define __flush_cache(p) clflush(p) 40#define __flush_cache(p) clflush(p)
41#define gru_ordered_store_int(p,v) \ 41#define gru_ordered_store_int(p,v) \
42 do { \ 42 do { \
@@ -299,6 +299,7 @@ static inline void gru_flush_cache(void *p)
299static inline void gru_start_instruction(struct gru_instruction *ins, int op32) 299static inline void gru_start_instruction(struct gru_instruction *ins, int op32)
300{ 300{
301 gru_ordered_store_int(ins, op32); 301 gru_ordered_store_int(ins, op32);
302 gru_flush_cache(ins);
302} 303}
303 304
304 305
@@ -604,8 +605,9 @@ static inline int gru_get_cb_substatus(void *cb)
604static inline int gru_check_status(void *cb) 605static inline int gru_check_status(void *cb)
605{ 606{
606 struct gru_control_block_status *cbs = (void *)cb; 607 struct gru_control_block_status *cbs = (void *)cb;
607 int ret = cbs->istatus; 608 int ret;
608 609
610 ret = cbs->istatus;
609 if (ret == CBS_CALL_OS) 611 if (ret == CBS_CALL_OS)
610 ret = gru_check_status_proc(cb); 612 ret = gru_check_status_proc(cb);
611 return ret; 613 return ret;
@@ -617,7 +619,7 @@ static inline int gru_check_status(void *cb)
617static inline int gru_wait(void *cb) 619static inline int gru_wait(void *cb)
618{ 620{
619 struct gru_control_block_status *cbs = (void *)cb; 621 struct gru_control_block_status *cbs = (void *)cb;
620 int ret = cbs->istatus;; 622 int ret = cbs->istatus;
621 623
622 if (ret != CBS_IDLE) 624 if (ret != CBS_IDLE)
623 ret = gru_wait_proc(cb); 625 ret = gru_wait_proc(cb);
diff --git a/drivers/misc/sgi-gru/grufault.c b/drivers/misc/sgi-gru/grufault.c
index 3d33015bbf31..8c389d606c30 100644
--- a/drivers/misc/sgi-gru/grufault.c
+++ b/drivers/misc/sgi-gru/grufault.c
@@ -214,12 +214,14 @@ static int non_atomic_pte_lookup(struct vm_area_struct *vma,
214} 214}
215 215
216/* 216/*
217 *
218 * atomic_pte_lookup 217 * atomic_pte_lookup
219 * 218 *
220 * Convert a user virtual address to a physical address 219 * Convert a user virtual address to a physical address
221 * Only supports Intel large pages (2MB only) on x86_64. 220 * Only supports Intel large pages (2MB only) on x86_64.
222 * ZZZ - hugepage support is incomplete 221 * ZZZ - hugepage support is incomplete
222 *
223 * NOTE: mmap_sem is already held on entry to this function. This
224 * guarantees existence of the page tables.
223 */ 225 */
224static int atomic_pte_lookup(struct vm_area_struct *vma, unsigned long vaddr, 226static int atomic_pte_lookup(struct vm_area_struct *vma, unsigned long vaddr,
225 int write, unsigned long *paddr, int *pageshift) 227 int write, unsigned long *paddr, int *pageshift)
@@ -229,9 +231,6 @@ static int atomic_pte_lookup(struct vm_area_struct *vma, unsigned long vaddr,
229 pud_t *pudp; 231 pud_t *pudp;
230 pte_t pte; 232 pte_t pte;
231 233
232 WARN_ON(irqs_disabled()); /* ZZZ debug */
233
234 local_irq_disable();
235 pgdp = pgd_offset(vma->vm_mm, vaddr); 234 pgdp = pgd_offset(vma->vm_mm, vaddr);
236 if (unlikely(pgd_none(*pgdp))) 235 if (unlikely(pgd_none(*pgdp)))
237 goto err; 236 goto err;
@@ -250,8 +249,6 @@ static int atomic_pte_lookup(struct vm_area_struct *vma, unsigned long vaddr,
250#endif 249#endif
251 pte = *pte_offset_kernel(pmdp, vaddr); 250 pte = *pte_offset_kernel(pmdp, vaddr);
252 251
253 local_irq_enable();
254
255 if (unlikely(!pte_present(pte) || 252 if (unlikely(!pte_present(pte) ||
256 (write && (!pte_write(pte) || !pte_dirty(pte))))) 253 (write && (!pte_write(pte) || !pte_dirty(pte)))))
257 return 1; 254 return 1;
@@ -324,6 +321,7 @@ static int gru_try_dropin(struct gru_thread_state *gts,
324 * Atomic lookup is faster & usually works even if called in non-atomic 321 * Atomic lookup is faster & usually works even if called in non-atomic
325 * context. 322 * context.
326 */ 323 */
324 rmb(); /* Must/check ms_range_active before loading PTEs */
327 ret = atomic_pte_lookup(vma, vaddr, write, &paddr, &pageshift); 325 ret = atomic_pte_lookup(vma, vaddr, write, &paddr, &pageshift);
328 if (ret) { 326 if (ret) {
329 if (!cb) 327 if (!cb)
@@ -543,6 +541,7 @@ int gru_get_exception_detail(unsigned long arg)
543 ucbnum = get_cb_number((void *)excdet.cb); 541 ucbnum = get_cb_number((void *)excdet.cb);
544 cbrnum = thread_cbr_number(gts, ucbnum); 542 cbrnum = thread_cbr_number(gts, ucbnum);
545 cbe = get_cbe_by_index(gts->ts_gru, cbrnum); 543 cbe = get_cbe_by_index(gts->ts_gru, cbrnum);
544 prefetchw(cbe); /* Harmless on hardware, required for emulator */
546 excdet.opc = cbe->opccpy; 545 excdet.opc = cbe->opccpy;
547 excdet.exopc = cbe->exopccpy; 546 excdet.exopc = cbe->exopccpy;
548 excdet.ecause = cbe->ecause; 547 excdet.ecause = cbe->ecause;
diff --git a/drivers/misc/sgi-gru/grufile.c b/drivers/misc/sgi-gru/grufile.c
index d61cee796efd..5c027b6b4e5a 100644
--- a/drivers/misc/sgi-gru/grufile.c
+++ b/drivers/misc/sgi-gru/grufile.c
@@ -113,7 +113,7 @@ static int gru_file_mmap(struct file *file, struct vm_area_struct *vma)
113 return -EPERM; 113 return -EPERM;
114 114
115 if (vma->vm_start & (GRU_GSEG_PAGESIZE - 1) || 115 if (vma->vm_start & (GRU_GSEG_PAGESIZE - 1) ||
116 vma->vm_end & (GRU_GSEG_PAGESIZE - 1)) 116 vma->vm_end & (GRU_GSEG_PAGESIZE - 1))
117 return -EINVAL; 117 return -EINVAL;
118 118
119 vma->vm_flags |= 119 vma->vm_flags |=
@@ -398,6 +398,12 @@ static int __init gru_init(void)
398 irq = get_base_irq(); 398 irq = get_base_irq();
399 for (chip = 0; chip < GRU_CHIPLETS_PER_BLADE; chip++) { 399 for (chip = 0; chip < GRU_CHIPLETS_PER_BLADE; chip++) {
400 ret = request_irq(irq + chip, gru_intr, 0, id, NULL); 400 ret = request_irq(irq + chip, gru_intr, 0, id, NULL);
401 /* TODO: fix irq handling on x86. For now ignore failures because
402 * interrupts are not required & not yet fully supported */
403 if (ret) {
404 printk("!!!WARNING: GRU ignoring request failure!!!\n");
405 ret = 0;
406 }
401 if (ret) { 407 if (ret) {
402 printk(KERN_ERR "%s: request_irq failed\n", 408 printk(KERN_ERR "%s: request_irq failed\n",
403 GRU_DRIVER_ID_STR); 409 GRU_DRIVER_ID_STR);
diff --git a/drivers/misc/sgi-gru/gruhandles.h b/drivers/misc/sgi-gru/gruhandles.h
index d16031d62673..b63018d60fe1 100644
--- a/drivers/misc/sgi-gru/gruhandles.h
+++ b/drivers/misc/sgi-gru/gruhandles.h
@@ -91,12 +91,7 @@
91#define GSEGPOFF(h) ((h) & (GRU_SIZE - 1)) 91#define GSEGPOFF(h) ((h) & (GRU_SIZE - 1))
92 92
93/* Convert an arbitrary handle address to the beginning of the GRU segment */ 93/* Convert an arbitrary handle address to the beginning of the GRU segment */
94#ifndef __PLUGIN__
95#define GRUBASE(h) ((void *)((unsigned long)(h) & ~(GRU_SIZE - 1))) 94#define GRUBASE(h) ((void *)((unsigned long)(h) & ~(GRU_SIZE - 1)))
96#else
97extern void *gmu_grubase(void *h);
98#define GRUBASE(h) gmu_grubase(h)
99#endif
100 95
101/* General addressing macros. */ 96/* General addressing macros. */
102static inline void *get_gseg_base_address(void *base, int ctxnum) 97static inline void *get_gseg_base_address(void *base, int ctxnum)
diff --git a/drivers/misc/sgi-gru/grukservices.c b/drivers/misc/sgi-gru/grukservices.c
index dfd49af0fe18..880c55dfb662 100644
--- a/drivers/misc/sgi-gru/grukservices.c
+++ b/drivers/misc/sgi-gru/grukservices.c
@@ -122,6 +122,7 @@ int gru_get_cb_exception_detail(void *cb,
122 struct gru_control_block_extended *cbe; 122 struct gru_control_block_extended *cbe;
123 123
124 cbe = get_cbe(GRUBASE(cb), get_cb_number(cb)); 124 cbe = get_cbe(GRUBASE(cb), get_cb_number(cb));
125 prefetchw(cbe); /* Harmless on hardware, required for emulator */
125 excdet->opc = cbe->opccpy; 126 excdet->opc = cbe->opccpy;
126 excdet->exopc = cbe->exopccpy; 127 excdet->exopc = cbe->exopccpy;
127 excdet->ecause = cbe->ecause; 128 excdet->ecause = cbe->ecause;
@@ -466,7 +467,7 @@ int gru_send_message_gpa(unsigned long mq, void *mesg, unsigned int bytes)
466 STAT(mesq_send); 467 STAT(mesq_send);
467 BUG_ON(bytes < sizeof(int) || bytes > 2 * GRU_CACHE_LINE_BYTES); 468 BUG_ON(bytes < sizeof(int) || bytes > 2 * GRU_CACHE_LINE_BYTES);
468 469
469 clines = (bytes + GRU_CACHE_LINE_BYTES - 1) / GRU_CACHE_LINE_BYTES; 470 clines = DIV_ROUND_UP(bytes, GRU_CACHE_LINE_BYTES);
470 if (gru_get_cpu_resources(bytes, &cb, &dsr)) 471 if (gru_get_cpu_resources(bytes, &cb, &dsr))
471 return MQE_BUG_NO_RESOURCES; 472 return MQE_BUG_NO_RESOURCES;
472 memcpy(dsr, mesg, bytes); 473 memcpy(dsr, mesg, bytes);
diff --git a/drivers/misc/sgi-gru/grumain.c b/drivers/misc/sgi-gru/grumain.c
index 0eeb8dddd2f5..e11e1ac50900 100644
--- a/drivers/misc/sgi-gru/grumain.c
+++ b/drivers/misc/sgi-gru/grumain.c
@@ -432,29 +432,35 @@ static inline long gru_copy_handle(void *d, void *s)
432 return GRU_HANDLE_BYTES; 432 return GRU_HANDLE_BYTES;
433} 433}
434 434
435/* rewrite in assembly & use lots of prefetch */ 435static void gru_prefetch_context(void *gseg, void *cb, void *cbe, unsigned long cbrmap,
436static void gru_load_context_data(void *save, void *grubase, int ctxnum, 436 unsigned long length)
437 unsigned long cbrmap, unsigned long dsrmap)
438{ 437{
439 void *gseg, *cb, *cbe;
440 unsigned long length;
441 int i, scr; 438 int i, scr;
442 439
443 gseg = grubase + ctxnum * GRU_GSEG_STRIDE;
444 length = hweight64(dsrmap) * GRU_DSR_AU_BYTES;
445 prefetch_data(gseg + GRU_DS_BASE, length / GRU_CACHE_LINE_BYTES, 440 prefetch_data(gseg + GRU_DS_BASE, length / GRU_CACHE_LINE_BYTES,
446 GRU_CACHE_LINE_BYTES); 441 GRU_CACHE_LINE_BYTES);
447 442
448 cb = gseg + GRU_CB_BASE;
449 cbe = grubase + GRU_CBE_BASE;
450 for_each_cbr_in_allocation_map(i, &cbrmap, scr) { 443 for_each_cbr_in_allocation_map(i, &cbrmap, scr) {
451 prefetch_data(cb, 1, GRU_CACHE_LINE_BYTES); 444 prefetch_data(cb, 1, GRU_CACHE_LINE_BYTES);
452 prefetch_data(cbe + i * GRU_HANDLE_STRIDE, 1, 445 prefetch_data(cbe + i * GRU_HANDLE_STRIDE, 1,
453 GRU_CACHE_LINE_BYTES); 446 GRU_CACHE_LINE_BYTES);
454 cb += GRU_HANDLE_STRIDE; 447 cb += GRU_HANDLE_STRIDE;
455 } 448 }
449}
450
451static void gru_load_context_data(void *save, void *grubase, int ctxnum,
452 unsigned long cbrmap, unsigned long dsrmap)
453{
454 void *gseg, *cb, *cbe;
455 unsigned long length;
456 int i, scr;
456 457
458 gseg = grubase + ctxnum * GRU_GSEG_STRIDE;
457 cb = gseg + GRU_CB_BASE; 459 cb = gseg + GRU_CB_BASE;
460 cbe = grubase + GRU_CBE_BASE;
461 length = hweight64(dsrmap) * GRU_DSR_AU_BYTES;
462 gru_prefetch_context(gseg, cb, cbe, cbrmap, length);
463
458 for_each_cbr_in_allocation_map(i, &cbrmap, scr) { 464 for_each_cbr_in_allocation_map(i, &cbrmap, scr) {
459 save += gru_copy_handle(cb, save); 465 save += gru_copy_handle(cb, save);
460 save += gru_copy_handle(cbe + i * GRU_HANDLE_STRIDE, save); 466 save += gru_copy_handle(cbe + i * GRU_HANDLE_STRIDE, save);
@@ -472,15 +478,16 @@ static void gru_unload_context_data(void *save, void *grubase, int ctxnum,
472 int i, scr; 478 int i, scr;
473 479
474 gseg = grubase + ctxnum * GRU_GSEG_STRIDE; 480 gseg = grubase + ctxnum * GRU_GSEG_STRIDE;
475
476 cb = gseg + GRU_CB_BASE; 481 cb = gseg + GRU_CB_BASE;
477 cbe = grubase + GRU_CBE_BASE; 482 cbe = grubase + GRU_CBE_BASE;
483 length = hweight64(dsrmap) * GRU_DSR_AU_BYTES;
484 gru_prefetch_context(gseg, cb, cbe, cbrmap, length);
485
478 for_each_cbr_in_allocation_map(i, &cbrmap, scr) { 486 for_each_cbr_in_allocation_map(i, &cbrmap, scr) {
479 save += gru_copy_handle(save, cb); 487 save += gru_copy_handle(save, cb);
480 save += gru_copy_handle(save, cbe + i * GRU_HANDLE_STRIDE); 488 save += gru_copy_handle(save, cbe + i * GRU_HANDLE_STRIDE);
481 cb += GRU_HANDLE_STRIDE; 489 cb += GRU_HANDLE_STRIDE;
482 } 490 }
483 length = hweight64(dsrmap) * GRU_DSR_AU_BYTES;
484 memcpy(save, gseg + GRU_DS_BASE, length); 491 memcpy(save, gseg + GRU_DS_BASE, length);
485} 492}
486 493
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index c16028872bbb..1b9fc3c6b875 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -172,7 +172,7 @@ struct mmc_omap_host {
172 struct omap_mmc_platform_data *pdata; 172 struct omap_mmc_platform_data *pdata;
173}; 173};
174 174
175void mmc_omap_fclk_offdelay(struct mmc_omap_slot *slot) 175static void mmc_omap_fclk_offdelay(struct mmc_omap_slot *slot)
176{ 176{
177 unsigned long tick_ns; 177 unsigned long tick_ns;
178 178
@@ -182,7 +182,7 @@ void mmc_omap_fclk_offdelay(struct mmc_omap_slot *slot)
182 } 182 }
183} 183}
184 184
185void mmc_omap_fclk_enable(struct mmc_omap_host *host, unsigned int enable) 185static void mmc_omap_fclk_enable(struct mmc_omap_host *host, unsigned int enable)
186{ 186{
187 unsigned long flags; 187 unsigned long flags;
188 188
@@ -1455,7 +1455,9 @@ static int __init mmc_omap_probe(struct platform_device *pdev)
1455 1455
1456 host->irq = irq; 1456 host->irq = irq;
1457 host->phys_base = host->mem_res->start; 1457 host->phys_base = host->mem_res->start;
1458 host->virt_base = (void __iomem *) IO_ADDRESS(host->phys_base); 1458 host->virt_base = ioremap(res->start, res->end - res->start + 1);
1459 if (!host->virt_base)
1460 goto err_ioremap;
1459 1461
1460 if (cpu_is_omap24xx()) { 1462 if (cpu_is_omap24xx()) {
1461 host->iclk = clk_get(&pdev->dev, "mmc_ick"); 1463 host->iclk = clk_get(&pdev->dev, "mmc_ick");
@@ -1510,6 +1512,8 @@ err_free_iclk:
1510 clk_put(host->iclk); 1512 clk_put(host->iclk);
1511 } 1513 }
1512err_free_mmc_host: 1514err_free_mmc_host:
1515 iounmap(host->virt_base);
1516err_ioremap:
1513 kfree(host); 1517 kfree(host);
1514err_free_mem_region: 1518err_free_mem_region:
1515 release_mem_region(res->start, res->end - res->start + 1); 1519 release_mem_region(res->start, res->end - res->start + 1);
@@ -1536,6 +1540,7 @@ static int mmc_omap_remove(struct platform_device *pdev)
1536 if (host->fclk && !IS_ERR(host->fclk)) 1540 if (host->fclk && !IS_ERR(host->fclk))
1537 clk_put(host->fclk); 1541 clk_put(host->fclk);
1538 1542
1543 iounmap(host->virt_base);
1539 release_mem_region(pdev->resource[0].start, 1544 release_mem_region(pdev->resource[0].start,
1540 pdev->resource[0].end - pdev->resource[0].start + 1); 1545 pdev->resource[0].end - pdev->resource[0].start + 1);
1541 1546
diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
index 0a84f10d719c..9bd7026b0021 100644
--- a/drivers/mmc/host/sdhci-pci.c
+++ b/drivers/mmc/host/sdhci-pci.c
@@ -327,7 +327,7 @@ static const struct pci_device_id pci_ids[] __devinitdata = {
327 327
328 { 328 {
329 .vendor = PCI_VENDOR_ID_MARVELL, 329 .vendor = PCI_VENDOR_ID_MARVELL,
330 .device = PCI_DEVICE_ID_MARVELL_CAFE_SD, 330 .device = PCI_DEVICE_ID_MARVELL_88ALP01_SD,
331 .subvendor = PCI_ANY_ID, 331 .subvendor = PCI_ANY_ID,
332 .subdevice = PCI_ANY_ID, 332 .subdevice = PCI_ANY_ID,
333 .driver_data = (kernel_ulong_t)&sdhci_cafe, 333 .driver_data = (kernel_ulong_t)&sdhci_cafe,
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c
index 90924fb00481..d600c2deff73 100644
--- a/drivers/mtd/maps/pcmciamtd.c
+++ b/drivers/mtd/maps/pcmciamtd.c
@@ -118,7 +118,8 @@ static caddr_t remap_window(struct map_info *map, unsigned long to)
118 DEBUG(2, "Remapping window from 0x%8.8x to 0x%8.8x", 118 DEBUG(2, "Remapping window from 0x%8.8x to 0x%8.8x",
119 dev->offset, mrq.CardOffset); 119 dev->offset, mrq.CardOffset);
120 mrq.Page = 0; 120 mrq.Page = 0;
121 if( (ret = pcmcia_map_mem_page(win, &mrq)) != CS_SUCCESS) { 121 ret = pcmcia_map_mem_page(win, &mrq);
122 if (ret != 0) {
122 cs_error(dev->p_dev, MapMemPage, ret); 123 cs_error(dev->p_dev, MapMemPage, ret);
123 return NULL; 124 return NULL;
124 } 125 }
@@ -326,9 +327,8 @@ static void pcmciamtd_set_vpp(struct map_info *map, int on)
326 327
327 DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp); 328 DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp);
328 ret = pcmcia_modify_configuration(link, &mod); 329 ret = pcmcia_modify_configuration(link, &mod);
329 if(ret != CS_SUCCESS) { 330 if (ret != 0)
330 cs_error(link, ModifyConfiguration, ret); 331 cs_error(link, ModifyConfiguration, ret);
331 }
332} 332}
333 333
334 334
@@ -368,14 +368,14 @@ static void card_settings(struct pcmciamtd_dev *dev, struct pcmcia_device *link,
368 tuple.DesiredTuple = RETURN_FIRST_TUPLE; 368 tuple.DesiredTuple = RETURN_FIRST_TUPLE;
369 369
370 rc = pcmcia_get_first_tuple(link, &tuple); 370 rc = pcmcia_get_first_tuple(link, &tuple);
371 while(rc == CS_SUCCESS) { 371 while (rc == 0) {
372 rc = pcmcia_get_tuple_data(link, &tuple); 372 rc = pcmcia_get_tuple_data(link, &tuple);
373 if(rc != CS_SUCCESS) { 373 if (rc != 0) {
374 cs_error(link, GetTupleData, rc); 374 cs_error(link, GetTupleData, rc);
375 break; 375 break;
376 } 376 }
377 rc = pcmcia_parse_tuple(link, &tuple, &parse); 377 rc = pcmcia_parse_tuple(&tuple, &parse);
378 if(rc != CS_SUCCESS) { 378 if (rc != 0) {
379 cs_error(link, ParseTuple, rc); 379 cs_error(link, ParseTuple, rc);
380 break; 380 break;
381 } 381 }
@@ -493,18 +493,11 @@ static int pcmciamtd_config(struct pcmcia_device *link)
493 int last_ret = 0, last_fn = 0; 493 int last_ret = 0, last_fn = 0;
494 int ret; 494 int ret;
495 int i; 495 int i;
496 config_info_t t;
497 static char *probes[] = { "jedec_probe", "cfi_probe" }; 496 static char *probes[] = { "jedec_probe", "cfi_probe" };
498 int new_name = 0; 497 int new_name = 0;
499 498
500 DEBUG(3, "link=0x%p", link); 499 DEBUG(3, "link=0x%p", link);
501 500
502 DEBUG(2, "Validating CIS");
503 ret = pcmcia_validate_cis(link, NULL);
504 if(ret != CS_SUCCESS) {
505 cs_error(link, GetTupleData, ret);
506 }
507
508 card_settings(dev, link, &new_name); 501 card_settings(dev, link, &new_name);
509 502
510 dev->pcmcia_map.phys = NO_XIP; 503 dev->pcmcia_map.phys = NO_XIP;
@@ -571,10 +564,7 @@ static int pcmciamtd_config(struct pcmcia_device *link)
571 dev->pcmcia_map.map_priv_1 = (unsigned long)dev; 564 dev->pcmcia_map.map_priv_1 = (unsigned long)dev;
572 dev->pcmcia_map.map_priv_2 = (unsigned long)link->win; 565 dev->pcmcia_map.map_priv_2 = (unsigned long)link->win;
573 566
574 DEBUG(2, "Getting configuration"); 567 dev->vpp = (vpp) ? vpp : link->socket.socket.Vpp;
575 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &t));
576 DEBUG(2, "Vcc = %d Vpp1 = %d Vpp2 = %d", t.Vcc, t.Vpp1, t.Vpp2);
577 dev->vpp = (vpp) ? vpp : t.Vpp1;
578 link->conf.Attributes = 0; 568 link->conf.Attributes = 0;
579 if(setvpp == 2) { 569 if(setvpp == 2) {
580 link->conf.Vpp = dev->vpp; 570 link->conf.Vpp = dev->vpp;
@@ -583,16 +573,10 @@ static int pcmciamtd_config(struct pcmcia_device *link)
583 } 573 }
584 574
585 link->conf.IntType = INT_MEMORY; 575 link->conf.IntType = INT_MEMORY;
586 link->conf.ConfigBase = t.ConfigBase;
587 link->conf.Status = t.Status;
588 link->conf.Pin = t.Pin;
589 link->conf.Copy = t.Copy;
590 link->conf.ExtStatus = t.ExtStatus;
591 link->conf.ConfigIndex = 0; 576 link->conf.ConfigIndex = 0;
592 link->conf.Present = t.Present;
593 DEBUG(2, "Setting Configuration"); 577 DEBUG(2, "Setting Configuration");
594 ret = pcmcia_request_configuration(link, &link->conf); 578 ret = pcmcia_request_configuration(link, &link->conf);
595 if(ret != CS_SUCCESS) { 579 if (ret != 0) {
596 cs_error(link, RequestConfiguration, ret); 580 cs_error(link, RequestConfiguration, ret);
597 if (dev->win_base) { 581 if (dev->win_base) {
598 iounmap(dev->win_base); 582 iounmap(dev->win_base);
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index e00d424e6575..1c74762dec89 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -26,13 +26,11 @@ static void mtd_notify_add(struct mtd_info* mtd)
26 if (!mtd) 26 if (!mtd)
27 return; 27 return;
28 28
29 device_create_drvdata(mtd_class, NULL, 29 device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
30 MKDEV(MTD_CHAR_MAJOR, mtd->index*2), 30 NULL, "mtd%d", mtd->index);
31 NULL, "mtd%d", mtd->index);
32 31
33 device_create_drvdata(mtd_class, NULL, 32 device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1),
34 MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1), 33 NULL, "mtd%dro", mtd->index);
35 NULL, "mtd%dro", mtd->index);
36} 34}
37 35
38static void mtd_notify_remove(struct mtd_info* mtd) 36static void mtd_notify_remove(struct mtd_info* mtd)
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index edb90b58a9b1..9a06dc93ee0d 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -564,10 +564,8 @@ int parse_mtd_partitions(struct mtd_info *master, const char **types,
564 564
565 for ( ; ret <= 0 && *types; types++) { 565 for ( ; ret <= 0 && *types; types++) {
566 parser = get_partition_parser(*types); 566 parser = get_partition_parser(*types);
567#ifdef CONFIG_KMOD
568 if (!parser && !request_module("%s", *types)) 567 if (!parser && !request_module("%s", *types))
569 parser = get_partition_parser(*types); 568 parser = get_partition_parser(*types);
570#endif
571 if (!parser) { 569 if (!parser) {
572 printk(KERN_NOTICE "%s partition parsing not available\n", 570 printk(KERN_NOTICE "%s partition parsing not available\n",
573 *types); 571 *types);
diff --git a/drivers/mtd/nand/ams-delta.c b/drivers/mtd/nand/ams-delta.c
index 26d42987971f..782994ead0e8 100644
--- a/drivers/mtd/nand/ams-delta.c
+++ b/drivers/mtd/nand/ams-delta.c
@@ -145,7 +145,7 @@ static void ams_delta_hwcontrol(struct mtd_info *mtd, int cmd,
145 145
146static int ams_delta_nand_ready(struct mtd_info *mtd) 146static int ams_delta_nand_ready(struct mtd_info *mtd)
147{ 147{
148 return omap_get_gpio_datain(AMS_DELTA_GPIO_PIN_NAND_RB); 148 return gpio_get_value(AMS_DELTA_GPIO_PIN_NAND_RB);
149} 149}
150 150
151/* 151/*
@@ -185,7 +185,7 @@ static int __init ams_delta_init(void)
185 this->read_buf = ams_delta_read_buf; 185 this->read_buf = ams_delta_read_buf;
186 this->verify_buf = ams_delta_verify_buf; 186 this->verify_buf = ams_delta_verify_buf;
187 this->cmd_ctrl = ams_delta_hwcontrol; 187 this->cmd_ctrl = ams_delta_hwcontrol;
188 if (!omap_request_gpio(AMS_DELTA_GPIO_PIN_NAND_RB)) { 188 if (gpio_request(AMS_DELTA_GPIO_PIN_NAND_RB, "nand_rdy") == 0) {
189 this->dev_ready = ams_delta_nand_ready; 189 this->dev_ready = ams_delta_nand_ready;
190 } else { 190 } else {
191 this->dev_ready = NULL; 191 this->dev_ready = NULL;
diff --git a/drivers/mtd/nand/cafe_nand.c b/drivers/mtd/nand/cafe_nand.c
index 95345d051579..b8064bf3aee4 100644
--- a/drivers/mtd/nand/cafe_nand.c
+++ b/drivers/mtd/nand/cafe_nand.c
@@ -1,6 +1,9 @@
1/* 1/*
2 * Driver for One Laptop Per Child ‘CAFÉ’ controller, aka Marvell 88ALP01 2 * Driver for One Laptop Per Child ‘CAFÉ’ controller, aka Marvell 88ALP01
3 * 3 *
4 * The data sheet for this device can be found at:
5 * http://www.marvell.com/products/pcconn/88ALP01.jsp
6 *
4 * Copyright © 2006 Red Hat, Inc. 7 * Copyright © 2006 Red Hat, Inc.
5 * Copyright © 2006 David Woodhouse <dwmw2@infradead.org> 8 * Copyright © 2006 David Woodhouse <dwmw2@infradead.org>
6 */ 9 */
@@ -842,7 +845,8 @@ static void __devexit cafe_nand_remove(struct pci_dev *pdev)
842} 845}
843 846
844static struct pci_device_id cafe_nand_tbl[] = { 847static struct pci_device_id cafe_nand_tbl[] = {
845 { 0x11ab, 0x4100, PCI_ANY_ID, PCI_ANY_ID }, 848 { PCI_VENDOR_ID_MARVELL, PCI_DEVICE_ID_MARVELL_88ALP01_NAND,
849 PCI_ANY_ID, PCI_ANY_ID },
846 { } 850 { }
847}; 851};
848 852
diff --git a/drivers/net/3c501.c b/drivers/net/3c501.c
index 5ba4bab6d43e..7d15e7c6bcad 100644
--- a/drivers/net/3c501.c
+++ b/drivers/net/3c501.c
@@ -17,7 +17,7 @@
17 Annapolis MD 21403 17 Annapolis MD 21403
18 18
19 Fixed (again!) the missing interrupt locking on TX/RX shifting. 19 Fixed (again!) the missing interrupt locking on TX/RX shifting.
20 Alan Cox <Alan.Cox@linux.org> 20 Alan Cox <alan@lxorguk.ukuu.org.uk>
21 21
22 Removed calls to init_etherdev since they are no longer needed, and 22 Removed calls to init_etherdev since they are no longer needed, and
23 cleaned up modularization just a bit. The driver still allows only 23 cleaned up modularization just a bit. The driver still allows only
@@ -29,16 +29,16 @@
29 the board. Now getting 150K/second FTP with a 3c501 card. Still playing 29 the board. Now getting 150K/second FTP with a 3c501 card. Still playing
30 with a TX-TX optimisation to see if we can touch 180-200K/second as seems 30 with a TX-TX optimisation to see if we can touch 180-200K/second as seems
31 theoretically maximum. 31 theoretically maximum.
32 19950402 Alan Cox <Alan.Cox@linux.org> 32 19950402 Alan Cox <alan@lxorguk.ukuu.org.uk>
33 33
34 Cleaned up for 2.3.x because we broke SMP now. 34 Cleaned up for 2.3.x because we broke SMP now.
35 20000208 Alan Cox <alan@redhat.com> 35 20000208 Alan Cox <alan@lxorguk.ukuu.org.uk>
36 36
37 Check up pass for 2.5. Nothing significant changed 37 Check up pass for 2.5. Nothing significant changed
38 20021009 Alan Cox <alan@redhat.com> 38 20021009 Alan Cox <alan@lxorguk.ukuu.org.uk>
39 39
40 Fixed zero fill corner case 40 Fixed zero fill corner case
41 20030104 Alan Cox <alan@redhat.com> 41 20030104 Alan Cox <alan@lxorguk.ukuu.org.uk>
42 42
43 43
44 For the avoidance of doubt the "preferred form" of this code is one which 44 For the avoidance of doubt the "preferred form" of this code is one which
@@ -104,7 +104,7 @@
104 104
105 105
106static const char version[] = 106static const char version[] =
107 DRV_NAME ".c: " DRV_VERSION " Alan Cox (alan@redhat.com).\n"; 107 DRV_NAME ".c: " DRV_VERSION " Alan Cox (alan@lxorguk.ukuu.org.uk).\n";
108 108
109/* 109/*
110 * Braindamage remaining: 110 * Braindamage remaining:
diff --git a/drivers/net/3c509.c b/drivers/net/3c509.c
index b9d097c9f6bb..3a7bc524af33 100644
--- a/drivers/net/3c509.c
+++ b/drivers/net/3c509.c
@@ -40,7 +40,7 @@
40 v1.14 10/15/97 Avoided waiting..discard message for fast machines -djb 40 v1.14 10/15/97 Avoided waiting..discard message for fast machines -djb
41 v1.15 1/31/98 Faster recovery for Tx errors. -djb 41 v1.15 1/31/98 Faster recovery for Tx errors. -djb
42 v1.16 2/3/98 Different ID port handling to avoid sound cards. -djb 42 v1.16 2/3/98 Different ID port handling to avoid sound cards. -djb
43 v1.18 12Mar2001 Andrew Morton <andrewm@uow.edu.au> 43 v1.18 12Mar2001 Andrew Morton
44 - Avoid bogus detect of 3c590's (Andrzej Krzysztofowicz) 44 - Avoid bogus detect of 3c590's (Andrzej Krzysztofowicz)
45 - Reviewed against 1.18 from scyld.com 45 - Reviewed against 1.18 from scyld.com
46 v1.18a 17Nov2001 Jeff Garzik <jgarzik@pobox.com> 46 v1.18a 17Nov2001 Jeff Garzik <jgarzik@pobox.com>
diff --git a/drivers/net/3c515.c b/drivers/net/3c515.c
index e4e3241628d6..a0f8b6e2d0af 100644
--- a/drivers/net/3c515.c
+++ b/drivers/net/3c515.c
@@ -18,7 +18,7 @@
18 18
19 2001/11/17 - Added ethtool support (jgarzik) 19 2001/11/17 - Added ethtool support (jgarzik)
20 20
21 2002/10/28 - Locking updates for 2.5 (alan@redhat.com) 21 2002/10/28 - Locking updates for 2.5 (alan@lxorguk.ukuu.org.uk)
22 22
23*/ 23*/
24 24
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index e9d529442b06..ad301ace6085 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -2400,7 +2400,7 @@ config EHEA
2400 will be called ehea. 2400 will be called ehea.
2401 2401
2402config ENIC 2402config ENIC
2403 tristate "E, the Cisco 10G Ethernet NIC" 2403 tristate "Cisco 10G Ethernet NIC support"
2404 depends on PCI && INET 2404 depends on PCI && INET
2405 select INET_LRO 2405 select INET_LRO
2406 help 2406 help
@@ -2410,7 +2410,6 @@ config IXGBE
2410 tristate "Intel(R) 10GbE PCI Express adapters support" 2410 tristate "Intel(R) 10GbE PCI Express adapters support"
2411 depends on PCI && INET 2411 depends on PCI && INET
2412 select INET_LRO 2412 select INET_LRO
2413 select INTEL_IOATDMA
2414 ---help--- 2413 ---help---
2415 This driver supports Intel(R) 10GbE PCI Express family of 2414 This driver supports Intel(R) 10GbE PCI Express family of
2416 adapters. For more information on how to identify your adapter, go 2415 adapters. For more information on how to identify your adapter, go
@@ -2426,6 +2425,11 @@ config IXGBE
2426 To compile this driver as a module, choose M here. The module 2425 To compile this driver as a module, choose M here. The module
2427 will be called ixgbe. 2426 will be called ixgbe.
2428 2427
2428config IXGBE_DCA
2429 bool
2430 default y
2431 depends on IXGBE && DCA && !(IXGBE=y && DCA=m)
2432
2429config IXGB 2433config IXGB
2430 tristate "Intel(R) PRO/10GbE support" 2434 tristate "Intel(R) PRO/10GbE support"
2431 depends on PCI 2435 depends on PCI
@@ -2462,7 +2466,6 @@ config MYRI10GE
2462 select FW_LOADER 2466 select FW_LOADER
2463 select CRC32 2467 select CRC32
2464 select INET_LRO 2468 select INET_LRO
2465 select INTEL_IOATDMA
2466 ---help--- 2469 ---help---
2467 This driver supports Myricom Myri-10G Dual Protocol interface in 2470 This driver supports Myricom Myri-10G Dual Protocol interface in
2468 Ethernet mode. If the eeprom on your board is not recent enough, 2471 Ethernet mode. If the eeprom on your board is not recent enough,
@@ -2474,6 +2477,11 @@ config MYRI10GE
2474 To compile this driver as a module, choose M here. The module 2477 To compile this driver as a module, choose M here. The module
2475 will be called myri10ge. 2478 will be called myri10ge.
2476 2479
2480config MYRI10GE_DCA
2481 bool
2482 default y
2483 depends on MYRI10GE && DCA && !(MYRI10GE=y && DCA=m)
2484
2477config NETXEN_NIC 2485config NETXEN_NIC
2478 tristate "NetXen Multi port (1/10) Gigabit Ethernet NIC" 2486 tristate "NetXen Multi port (1/10) Gigabit Ethernet NIC"
2479 depends on PCI 2487 depends on PCI
diff --git a/drivers/net/appletalk/cops.c b/drivers/net/appletalk/cops.c
index a0b4c8516073..735fc9476403 100644
--- a/drivers/net/appletalk/cops.c
+++ b/drivers/net/appletalk/cops.c
@@ -4,7 +4,7 @@
4 * - Jay Schulist <jschlst@samba.org> 4 * - Jay Schulist <jschlst@samba.org>
5 * 5 *
6 * With more than a little help from; 6 * With more than a little help from;
7 * - Alan Cox <Alan.Cox@linux.org> 7 * - Alan Cox <alan@lxorguk.ukuu.org.uk>
8 * 8 *
9 * Derived from: 9 * Derived from:
10 * - skeleton.c: A network driver outline for linux. 10 * - skeleton.c: A network driver outline for linux.
diff --git a/drivers/net/au1000_eth.c b/drivers/net/au1000_eth.c
index 7b92201a7b50..019b13c08ae6 100644
--- a/drivers/net/au1000_eth.c
+++ b/drivers/net/au1000_eth.c
@@ -94,8 +94,8 @@ static irqreturn_t au1000_interrupt(int, void *);
94static void au1000_tx_timeout(struct net_device *); 94static void au1000_tx_timeout(struct net_device *);
95static void set_rx_mode(struct net_device *); 95static void set_rx_mode(struct net_device *);
96static int au1000_ioctl(struct net_device *, struct ifreq *, int); 96static int au1000_ioctl(struct net_device *, struct ifreq *, int);
97static int mdio_read(struct net_device *, int, int); 97static int au1000_mdio_read(struct net_device *, int, int);
98static void mdio_write(struct net_device *, int, int, u16); 98static void au1000_mdio_write(struct net_device *, int, int, u16);
99static void au1000_adjust_link(struct net_device *); 99static void au1000_adjust_link(struct net_device *);
100static void enable_mac(struct net_device *, int); 100static void enable_mac(struct net_device *, int);
101 101
@@ -191,7 +191,7 @@ struct au1000_private *au_macs[NUM_ETH_INTERFACES];
191/* 191/*
192 * MII operations 192 * MII operations
193 */ 193 */
194static int mdio_read(struct net_device *dev, int phy_addr, int reg) 194static int au1000_mdio_read(struct net_device *dev, int phy_addr, int reg)
195{ 195{
196 struct au1000_private *aup = (struct au1000_private *) dev->priv; 196 struct au1000_private *aup = (struct au1000_private *) dev->priv;
197 volatile u32 *const mii_control_reg = &aup->mac->mii_control; 197 volatile u32 *const mii_control_reg = &aup->mac->mii_control;
@@ -225,7 +225,8 @@ static int mdio_read(struct net_device *dev, int phy_addr, int reg)
225 return (int)*mii_data_reg; 225 return (int)*mii_data_reg;
226} 226}
227 227
228static void mdio_write(struct net_device *dev, int phy_addr, int reg, u16 value) 228static void au1000_mdio_write(struct net_device *dev, int phy_addr,
229 int reg, u16 value)
229{ 230{
230 struct au1000_private *aup = (struct au1000_private *) dev->priv; 231 struct au1000_private *aup = (struct au1000_private *) dev->priv;
231 volatile u32 *const mii_control_reg = &aup->mac->mii_control; 232 volatile u32 *const mii_control_reg = &aup->mac->mii_control;
@@ -249,7 +250,7 @@ static void mdio_write(struct net_device *dev, int phy_addr, int reg, u16 value)
249 *mii_control_reg = mii_control; 250 *mii_control_reg = mii_control;
250} 251}
251 252
252static int mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum) 253static int au1000_mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum)
253{ 254{
254 /* WARNING: bus->phy_map[phy_addr].attached_dev == dev does 255 /* WARNING: bus->phy_map[phy_addr].attached_dev == dev does
255 * _NOT_ hold (e.g. when PHY is accessed through other MAC's MII bus) */ 256 * _NOT_ hold (e.g. when PHY is accessed through other MAC's MII bus) */
@@ -257,21 +258,21 @@ static int mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum)
257 258
258 enable_mac(dev, 0); /* make sure the MAC associated with this 259 enable_mac(dev, 0); /* make sure the MAC associated with this
259 * mii_bus is enabled */ 260 * mii_bus is enabled */
260 return mdio_read(dev, phy_addr, regnum); 261 return au1000_mdio_read(dev, phy_addr, regnum);
261} 262}
262 263
263static int mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum, 264static int au1000_mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum,
264 u16 value) 265 u16 value)
265{ 266{
266 struct net_device *const dev = bus->priv; 267 struct net_device *const dev = bus->priv;
267 268
268 enable_mac(dev, 0); /* make sure the MAC associated with this 269 enable_mac(dev, 0); /* make sure the MAC associated with this
269 * mii_bus is enabled */ 270 * mii_bus is enabled */
270 mdio_write(dev, phy_addr, regnum, value); 271 au1000_mdio_write(dev, phy_addr, regnum, value);
271 return 0; 272 return 0;
272} 273}
273 274
274static int mdiobus_reset(struct mii_bus *bus) 275static int au1000_mdiobus_reset(struct mii_bus *bus)
275{ 276{
276 struct net_device *const dev = bus->priv; 277 struct net_device *const dev = bus->priv;
277 278
@@ -703,9 +704,9 @@ static struct net_device * au1000_probe(int port_num)
703 goto err_out; 704 goto err_out;
704 705
705 aup->mii_bus->priv = dev; 706 aup->mii_bus->priv = dev;
706 aup->mii_bus->read = mdiobus_read; 707 aup->mii_bus->read = au1000_mdiobus_read;
707 aup->mii_bus->write = mdiobus_write; 708 aup->mii_bus->write = au1000_mdiobus_write;
708 aup->mii_bus->reset = mdiobus_reset; 709 aup->mii_bus->reset = au1000_mdiobus_reset;
709 aup->mii_bus->name = "au1000_eth_mii"; 710 aup->mii_bus->name = "au1000_eth_mii";
710 snprintf(aup->mii_bus->id, MII_BUS_ID_SIZE, "%x", aup->mac_id); 711 snprintf(aup->mii_bus->id, MII_BUS_ID_SIZE, "%x", aup->mac_id);
711 aup->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); 712 aup->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
diff --git a/drivers/net/bfin_mac.c b/drivers/net/bfin_mac.c
index a0d41c5d97d8..b458d607a9c6 100644
--- a/drivers/net/bfin_mac.c
+++ b/drivers/net/bfin_mac.c
@@ -253,7 +253,7 @@ init_error:
253 * MII operations 253 * MII operations
254 */ 254 */
255/* Wait until the previous MDC/MDIO transaction has completed */ 255/* Wait until the previous MDC/MDIO transaction has completed */
256static void mdio_poll(void) 256static void bfin_mdio_poll(void)
257{ 257{
258 int timeout_cnt = MAX_TIMEOUT_CNT; 258 int timeout_cnt = MAX_TIMEOUT_CNT;
259 259
@@ -269,25 +269,25 @@ static void mdio_poll(void)
269} 269}
270 270
271/* Read an off-chip register in a PHY through the MDC/MDIO port */ 271/* Read an off-chip register in a PHY through the MDC/MDIO port */
272static int mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum) 272static int bfin_mdiobus_read(struct mii_bus *bus, int phy_addr, int regnum)
273{ 273{
274 mdio_poll(); 274 bfin_mdio_poll();
275 275
276 /* read mode */ 276 /* read mode */
277 bfin_write_EMAC_STAADD(SET_PHYAD((u16) phy_addr) | 277 bfin_write_EMAC_STAADD(SET_PHYAD((u16) phy_addr) |
278 SET_REGAD((u16) regnum) | 278 SET_REGAD((u16) regnum) |
279 STABUSY); 279 STABUSY);
280 280
281 mdio_poll(); 281 bfin_mdio_poll();
282 282
283 return (int) bfin_read_EMAC_STADAT(); 283 return (int) bfin_read_EMAC_STADAT();
284} 284}
285 285
286/* Write an off-chip register in a PHY through the MDC/MDIO port */ 286/* Write an off-chip register in a PHY through the MDC/MDIO port */
287static int mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum, 287static int bfin_mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum,
288 u16 value) 288 u16 value)
289{ 289{
290 mdio_poll(); 290 bfin_mdio_poll();
291 291
292 bfin_write_EMAC_STADAT((u32) value); 292 bfin_write_EMAC_STADAT((u32) value);
293 293
@@ -297,12 +297,12 @@ static int mdiobus_write(struct mii_bus *bus, int phy_addr, int regnum,
297 STAOP | 297 STAOP |
298 STABUSY); 298 STABUSY);
299 299
300 mdio_poll(); 300 bfin_mdio_poll();
301 301
302 return 0; 302 return 0;
303} 303}
304 304
305static int mdiobus_reset(struct mii_bus *bus) 305static int bfin_mdiobus_reset(struct mii_bus *bus)
306{ 306{
307 return 0; 307 return 0;
308} 308}
@@ -818,7 +818,7 @@ static void bfin_mac_enable(void)
818 bfin_write_DMA1_CONFIG(rx_list_head->desc_a.config); 818 bfin_write_DMA1_CONFIG(rx_list_head->desc_a.config);
819 819
820 /* Wait MII done */ 820 /* Wait MII done */
821 mdio_poll(); 821 bfin_mdio_poll();
822 822
823 /* We enable only RX here */ 823 /* We enable only RX here */
824 /* ASTP : Enable Automatic Pad Stripping 824 /* ASTP : Enable Automatic Pad Stripping
@@ -1063,9 +1063,9 @@ static int __devinit bfin_mac_probe(struct platform_device *pdev)
1063 goto out_err_mdiobus_alloc; 1063 goto out_err_mdiobus_alloc;
1064 1064
1065 lp->mii_bus->priv = ndev; 1065 lp->mii_bus->priv = ndev;
1066 lp->mii_bus->read = mdiobus_read; 1066 lp->mii_bus->read = bfin_mdiobus_read;
1067 lp->mii_bus->write = mdiobus_write; 1067 lp->mii_bus->write = bfin_mdiobus_write;
1068 lp->mii_bus->reset = mdiobus_reset; 1068 lp->mii_bus->reset = bfin_mdiobus_reset;
1069 lp->mii_bus->name = "bfin_mac_mdio"; 1069 lp->mii_bus->name = "bfin_mac_mdio";
1070 snprintf(lp->mii_bus->id, MII_BUS_ID_SIZE, "0"); 1070 snprintf(lp->mii_bus->id, MII_BUS_ID_SIZE, "0");
1071 lp->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); 1071 lp->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
diff --git a/drivers/net/cs89x0.c b/drivers/net/cs89x0.c
index a28de8182802..7107620f615d 100644
--- a/drivers/net/cs89x0.c
+++ b/drivers/net/cs89x0.c
@@ -36,8 +36,7 @@
36 36
37 Alan Cox : Removed 1.2 support, added 2.1 extra counters. 37 Alan Cox : Removed 1.2 support, added 2.1 extra counters.
38 38
39 Andrew Morton : andrewm@uow.edu.au 39 Andrew Morton : Kernel 2.3.48
40 : Kernel 2.3.48
41 : Handle kmalloc() failures 40 : Handle kmalloc() failures
42 : Other resource allocation fixes 41 : Other resource allocation fixes
43 : Add SMP locks 42 : Add SMP locks
@@ -49,7 +48,7 @@
49 : Fixed an out-of-mem bug in dma_rx() 48 : Fixed an out-of-mem bug in dma_rx()
50 : Updated Documentation/networking/cs89x0.txt 49 : Updated Documentation/networking/cs89x0.txt
51 50
52 Andrew Morton : andrewm@uow.edu.au / Kernel 2.3.99-pre1 51 Andrew Morton : Kernel 2.3.99-pre1
53 : Use skb_reserve to longword align IP header (two places) 52 : Use skb_reserve to longword align IP header (two places)
54 : Remove a delay loop from dma_rx() 53 : Remove a delay loop from dma_rx()
55 : Replace '100' with HZ 54 : Replace '100' with HZ
@@ -57,11 +56,11 @@
57 : Added 'cs89x0_dma=N' kernel boot option 56 : Added 'cs89x0_dma=N' kernel boot option
58 : Correctly initialise lp->lock in non-module compile 57 : Correctly initialise lp->lock in non-module compile
59 58
60 Andrew Morton : andrewm@uow.edu.au / Kernel 2.3.99-pre4-1 59 Andrew Morton : Kernel 2.3.99-pre4-1
61 : MOD_INC/DEC race fix (see 60 : MOD_INC/DEC race fix (see
62 : http://www.uwsg.indiana.edu/hypermail/linux/kernel/0003.3/1532.html) 61 : http://www.uwsg.indiana.edu/hypermail/linux/kernel/0003.3/1532.html)
63 62
64 Andrew Morton : andrewm@uow.edu.au / Kernel 2.4.0-test7-pre2 63 Andrew Morton : Kernel 2.4.0-test7-pre2
65 : Enhanced EEPROM support to cover more devices, 64 : Enhanced EEPROM support to cover more devices,
66 : abstracted IRQ mapping to support CONFIG_ARCH_CLPS7500 arch 65 : abstracted IRQ mapping to support CONFIG_ARCH_CLPS7500 arch
67 : (Jason Gunthorpe <jgg@ualberta.ca>) 66 : (Jason Gunthorpe <jgg@ualberta.ca>)
@@ -156,7 +155,7 @@
156#include "cs89x0.h" 155#include "cs89x0.h"
157 156
158static char version[] __initdata = 157static char version[] __initdata =
159"cs89x0.c: v2.4.3-pre1 Russell Nelson <nelson@crynwr.com>, Andrew Morton <andrewm@uow.edu.au>\n"; 158"cs89x0.c: v2.4.3-pre1 Russell Nelson <nelson@crynwr.com>, Andrew Morton\n";
160 159
161#define DRV_NAME "cs89x0" 160#define DRV_NAME "cs89x0"
162 161
@@ -1877,7 +1876,7 @@ MODULE_PARM_DESC(dmasize , "(ignored)");
1877MODULE_PARM_DESC(use_dma , "(ignored)"); 1876MODULE_PARM_DESC(use_dma , "(ignored)");
1878#endif 1877#endif
1879 1878
1880MODULE_AUTHOR("Mike Cruse, Russwll Nelson <nelson@crynwr.com>, Andrew Morton <andrewm@uow.edu.au>"); 1879MODULE_AUTHOR("Mike Cruse, Russwll Nelson <nelson@crynwr.com>, Andrew Morton");
1881MODULE_LICENSE("GPL"); 1880MODULE_LICENSE("GPL");
1882 1881
1883 1882
diff --git a/drivers/net/cxgb3/adapter.h b/drivers/net/cxgb3/adapter.h
index 455ef529cd62..bc8e2413abd2 100644
--- a/drivers/net/cxgb3/adapter.h
+++ b/drivers/net/cxgb3/adapter.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/ael1002.c b/drivers/net/cxgb3/ael1002.c
index 744fac0b1617..5c3c05da4d96 100644
--- a/drivers/net/cxgb3/ael1002.c
+++ b/drivers/net/cxgb3/ael1002.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/common.h b/drivers/net/cxgb3/common.h
index 593fb643a615..e312d315a42d 100644
--- a/drivers/net/cxgb3/common.h
+++ b/drivers/net/cxgb3/common.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/cxgb3_ctl_defs.h b/drivers/net/cxgb3/cxgb3_ctl_defs.h
index 6ad92405d9a0..1d8d46eb3c96 100644
--- a/drivers/net/cxgb3/cxgb3_ctl_defs.h
+++ b/drivers/net/cxgb3/cxgb3_ctl_defs.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/cxgb3_defs.h b/drivers/net/cxgb3/cxgb3_defs.h
index 45e92164c260..47e53769af5b 100644
--- a/drivers/net/cxgb3/cxgb3_defs.h
+++ b/drivers/net/cxgb3/cxgb3_defs.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/cxgb3_ioctl.h b/drivers/net/cxgb3/cxgb3_ioctl.h
index 3e8d5faec3a4..b19e4376ba76 100644
--- a/drivers/net/cxgb3/cxgb3_ioctl.h
+++ b/drivers/net/cxgb3/cxgb3_ioctl.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/cxgb3_main.c b/drivers/net/cxgb3/cxgb3_main.c
index f31985df0bb9..1ace41a13ac3 100644
--- a/drivers/net/cxgb3/cxgb3_main.c
+++ b/drivers/net/cxgb3/cxgb3_main.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/cxgb3_offload.c b/drivers/net/cxgb3/cxgb3_offload.c
index 0f6fd63b2847..265aa8a15afa 100644
--- a/drivers/net/cxgb3/cxgb3_offload.c
+++ b/drivers/net/cxgb3/cxgb3_offload.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/cxgb3_offload.h b/drivers/net/cxgb3/cxgb3_offload.h
index 7a379138b5a6..d514e5019dfc 100644
--- a/drivers/net/cxgb3/cxgb3_offload.h
+++ b/drivers/net/cxgb3/cxgb3_offload.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2006-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/firmware_exports.h b/drivers/net/cxgb3/firmware_exports.h
index b75ddd8777fe..0d9b0e6dccff 100644
--- a/drivers/net/cxgb3/firmware_exports.h
+++ b/drivers/net/cxgb3/firmware_exports.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2004-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2004-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/l2t.c b/drivers/net/cxgb3/l2t.c
index b2c5314582aa..4407ac9bb555 100644
--- a/drivers/net/cxgb3/l2t.c
+++ b/drivers/net/cxgb3/l2t.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/l2t.h b/drivers/net/cxgb3/l2t.h
index 42ce65f76a87..fd3eb07e3f40 100644
--- a/drivers/net/cxgb3/l2t.h
+++ b/drivers/net/cxgb3/l2t.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/mc5.c b/drivers/net/cxgb3/mc5.c
index 4c4d6e877ea6..3b5517b8fbde 100644
--- a/drivers/net/cxgb3/mc5.c
+++ b/drivers/net/cxgb3/mc5.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/sge.c b/drivers/net/cxgb3/sge.c
index 87919419b707..c6480be0bc1f 100644
--- a/drivers/net/cxgb3/sge.c
+++ b/drivers/net/cxgb3/sge.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/t3_cpl.h b/drivers/net/cxgb3/t3_cpl.h
index 917970ed24a1..852c399a8b0a 100644
--- a/drivers/net/cxgb3/t3_cpl.h
+++ b/drivers/net/cxgb3/t3_cpl.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2004-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2004-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/t3_hw.c b/drivers/net/cxgb3/t3_hw.c
index 4da5b09b9bc2..968f64be3743 100644
--- a/drivers/net/cxgb3/t3_hw.c
+++ b/drivers/net/cxgb3/t3_hw.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/t3cdev.h b/drivers/net/cxgb3/t3cdev.h
index 0a21cfbd2b21..be55e9ae74d1 100644
--- a/drivers/net/cxgb3/t3cdev.h
+++ b/drivers/net/cxgb3/t3cdev.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (C) 2006-2007 Chelsio Communications. All rights reserved. 2 * Copyright (C) 2006-2008 Chelsio Communications. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/version.h b/drivers/net/cxgb3/version.h
index 29db711303b9..bb8698a86754 100644
--- a/drivers/net/cxgb3/version.h
+++ b/drivers/net/cxgb3/version.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
@@ -35,7 +35,7 @@
35#define DRV_DESC "Chelsio T3 Network Driver" 35#define DRV_DESC "Chelsio T3 Network Driver"
36#define DRV_NAME "cxgb3" 36#define DRV_NAME "cxgb3"
37/* Driver version */ 37/* Driver version */
38#define DRV_VERSION "1.0-ko" 38#define DRV_VERSION "1.1.0-ko"
39 39
40/* Firmware version */ 40/* Firmware version */
41#define FW_VERSION_MAJOR 7 41#define FW_VERSION_MAJOR 7
diff --git a/drivers/net/cxgb3/vsc8211.c b/drivers/net/cxgb3/vsc8211.c
index 306c2dc4ab34..33f956bd6b59 100644
--- a/drivers/net/cxgb3/vsc8211.c
+++ b/drivers/net/cxgb3/vsc8211.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/cxgb3/xgmac.c b/drivers/net/cxgb3/xgmac.c
index ffdc0a1892bd..9d7786937aad 100644
--- a/drivers/net/cxgb3/xgmac.c
+++ b/drivers/net/cxgb3/xgmac.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved. 2 * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved.
3 * 3 *
4 * This software is available to you under a choice of one of two 4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU 5 * licenses. You may choose to be licensed under the terms of the GNU
diff --git a/drivers/net/eexpress.c b/drivers/net/eexpress.c
index 795c594a4b7c..b751c1b96cfa 100644
--- a/drivers/net/eexpress.c
+++ b/drivers/net/eexpress.c
@@ -8,7 +8,7 @@
8 * 8 *
9 * Many modifications, and currently maintained, by 9 * Many modifications, and currently maintained, by
10 * Philip Blundell <philb@gnu.org> 10 * Philip Blundell <philb@gnu.org>
11 * Added the Compaq LTE Alan Cox <alan@redhat.com> 11 * Added the Compaq LTE Alan Cox <alan@lxorguk.ukuu.org.uk>
12 * Added MCA support Adam Fritzler 12 * Added MCA support Adam Fritzler
13 * 13 *
14 * Note - this driver is experimental still - it has problems on faster 14 * Note - this driver is experimental still - it has problems on faster
diff --git a/drivers/net/enic/enic_main.c b/drivers/net/enic/enic_main.c
index f3a47a87dbbe..180e968dc54d 100644
--- a/drivers/net/enic/enic_main.c
+++ b/drivers/net/enic/enic_main.c
@@ -34,6 +34,7 @@
34#include <linux/ip.h> 34#include <linux/ip.h>
35#include <linux/ipv6.h> 35#include <linux/ipv6.h>
36#include <linux/tcp.h> 36#include <linux/tcp.h>
37#include <net/ip6_checksum.h>
37 38
38#include "cq_enet_desc.h" 39#include "cq_enet_desc.h"
39#include "vnic_dev.h" 40#include "vnic_dev.h"
diff --git a/drivers/net/ibm_newemac/Kconfig b/drivers/net/ibm_newemac/Kconfig
index bcec7320895c..78a1628c9892 100644
--- a/drivers/net/ibm_newemac/Kconfig
+++ b/drivers/net/ibm_newemac/Kconfig
@@ -62,3 +62,15 @@ config IBM_NEW_EMAC_TAH
62config IBM_NEW_EMAC_EMAC4 62config IBM_NEW_EMAC_EMAC4
63 bool 63 bool
64 default n 64 default n
65
66config IBM_NEW_EMAC_NO_FLOW_CTRL
67 bool
68 default n
69
70config IBM_NEW_EMAC_MAL_CLR_ICINTSTAT
71 bool
72 default n
73
74config IBM_NEW_EMAC_MAL_COMMON_ERR
75 bool
76 default n
diff --git a/drivers/net/ibm_newemac/core.c b/drivers/net/ibm_newemac/core.c
index 58dfd32ccca8..efcf21c9f5c7 100644
--- a/drivers/net/ibm_newemac/core.c
+++ b/drivers/net/ibm_newemac/core.c
@@ -202,13 +202,15 @@ static inline int emac_phy_supports_gige(int phy_mode)
202{ 202{
203 return phy_mode == PHY_MODE_GMII || 203 return phy_mode == PHY_MODE_GMII ||
204 phy_mode == PHY_MODE_RGMII || 204 phy_mode == PHY_MODE_RGMII ||
205 phy_mode == PHY_MODE_SGMII ||
205 phy_mode == PHY_MODE_TBI || 206 phy_mode == PHY_MODE_TBI ||
206 phy_mode == PHY_MODE_RTBI; 207 phy_mode == PHY_MODE_RTBI;
207} 208}
208 209
209static inline int emac_phy_gpcs(int phy_mode) 210static inline int emac_phy_gpcs(int phy_mode)
210{ 211{
211 return phy_mode == PHY_MODE_TBI || 212 return phy_mode == PHY_MODE_SGMII ||
213 phy_mode == PHY_MODE_TBI ||
212 phy_mode == PHY_MODE_RTBI; 214 phy_mode == PHY_MODE_RTBI;
213} 215}
214 216
@@ -562,8 +564,9 @@ static int emac_configure(struct emac_instance *dev)
562 switch (dev->phy.speed) { 564 switch (dev->phy.speed) {
563 case SPEED_1000: 565 case SPEED_1000:
564 if (emac_phy_gpcs(dev->phy.mode)) { 566 if (emac_phy_gpcs(dev->phy.mode)) {
565 mr1 |= EMAC_MR1_MF_1000GPCS | 567 mr1 |= EMAC_MR1_MF_1000GPCS | EMAC_MR1_MF_IPPA(
566 EMAC_MR1_MF_IPPA(dev->phy.address); 568 (dev->phy.gpcs_address != 0xffffffff) ?
569 dev->phy.gpcs_address : dev->phy.address);
567 570
568 /* Put some arbitrary OUI, Manuf & Rev IDs so we can 571 /* Put some arbitrary OUI, Manuf & Rev IDs so we can
569 * identify this GPCS PHY later. 572 * identify this GPCS PHY later.
@@ -675,8 +678,12 @@ static int emac_configure(struct emac_instance *dev)
675 out_be32(&p->iser, r); 678 out_be32(&p->iser, r);
676 679
677 /* We need to take GPCS PHY out of isolate mode after EMAC reset */ 680 /* We need to take GPCS PHY out of isolate mode after EMAC reset */
678 if (emac_phy_gpcs(dev->phy.mode)) 681 if (emac_phy_gpcs(dev->phy.mode)) {
679 emac_mii_reset_phy(&dev->phy); 682 if (dev->phy.gpcs_address != 0xffffffff)
683 emac_mii_reset_gpcs(&dev->phy);
684 else
685 emac_mii_reset_phy(&dev->phy);
686 }
680 687
681 return 0; 688 return 0;
682} 689}
@@ -881,7 +888,9 @@ static int emac_mdio_read(struct net_device *ndev, int id, int reg)
881 struct emac_instance *dev = netdev_priv(ndev); 888 struct emac_instance *dev = netdev_priv(ndev);
882 int res; 889 int res;
883 890
884 res = __emac_mdio_read(dev->mdio_instance ? dev->mdio_instance : dev, 891 res = __emac_mdio_read((dev->mdio_instance &&
892 dev->phy.gpcs_address != id) ?
893 dev->mdio_instance : dev,
885 (u8) id, (u8) reg); 894 (u8) id, (u8) reg);
886 return res; 895 return res;
887} 896}
@@ -890,7 +899,9 @@ static void emac_mdio_write(struct net_device *ndev, int id, int reg, int val)
890{ 899{
891 struct emac_instance *dev = netdev_priv(ndev); 900 struct emac_instance *dev = netdev_priv(ndev);
892 901
893 __emac_mdio_write(dev->mdio_instance ? dev->mdio_instance : dev, 902 __emac_mdio_write((dev->mdio_instance &&
903 dev->phy.gpcs_address != id) ?
904 dev->mdio_instance : dev,
894 (u8) id, (u8) reg, (u16) val); 905 (u8) id, (u8) reg, (u16) val);
895} 906}
896 907
@@ -2382,7 +2393,11 @@ static int __devinit emac_init_phy(struct emac_instance *dev)
2382 * XXX I probably should move these settings to the dev tree 2393 * XXX I probably should move these settings to the dev tree
2383 */ 2394 */
2384 dev->phy.address = -1; 2395 dev->phy.address = -1;
2385 dev->phy.features = SUPPORTED_100baseT_Full | SUPPORTED_MII; 2396 dev->phy.features = SUPPORTED_MII;
2397 if (emac_phy_supports_gige(dev->phy_mode))
2398 dev->phy.features |= SUPPORTED_1000baseT_Full;
2399 else
2400 dev->phy.features |= SUPPORTED_100baseT_Full;
2386 dev->phy.pause = 1; 2401 dev->phy.pause = 1;
2387 2402
2388 return 0; 2403 return 0;
@@ -2421,7 +2436,9 @@ static int __devinit emac_init_phy(struct emac_instance *dev)
2421 * Note that the busy_phy_map is currently global 2436 * Note that the busy_phy_map is currently global
2422 * while it should probably be per-ASIC... 2437 * while it should probably be per-ASIC...
2423 */ 2438 */
2424 dev->phy.address = dev->cell_index; 2439 dev->phy.gpcs_address = dev->gpcs_address;
2440 if (dev->phy.gpcs_address == 0xffffffff)
2441 dev->phy.address = dev->cell_index;
2425 } 2442 }
2426 2443
2427 emac_configure(dev); 2444 emac_configure(dev);
@@ -2531,6 +2548,8 @@ static int __devinit emac_init_config(struct emac_instance *dev)
2531 dev->phy_address = 0xffffffff; 2548 dev->phy_address = 0xffffffff;
2532 if (emac_read_uint_prop(np, "phy-map", &dev->phy_map, 0)) 2549 if (emac_read_uint_prop(np, "phy-map", &dev->phy_map, 0))
2533 dev->phy_map = 0xffffffff; 2550 dev->phy_map = 0xffffffff;
2551 if (emac_read_uint_prop(np, "gpcs-address", &dev->gpcs_address, 0))
2552 dev->gpcs_address = 0xffffffff;
2534 if (emac_read_uint_prop(np->parent, "clock-frequency", &dev->opb_bus_freq, 1)) 2553 if (emac_read_uint_prop(np->parent, "clock-frequency", &dev->opb_bus_freq, 1))
2535 return -ENXIO; 2554 return -ENXIO;
2536 if (emac_read_uint_prop(np, "tah-device", &dev->tah_ph, 0)) 2555 if (emac_read_uint_prop(np, "tah-device", &dev->tah_ph, 0))
@@ -2585,6 +2604,8 @@ static int __devinit emac_init_config(struct emac_instance *dev)
2585 if (of_device_is_compatible(np, "ibm,emac-440ep") || 2604 if (of_device_is_compatible(np, "ibm,emac-440ep") ||
2586 of_device_is_compatible(np, "ibm,emac-440gr")) 2605 of_device_is_compatible(np, "ibm,emac-440gr"))
2587 dev->features |= EMAC_FTR_440EP_PHY_CLK_FIX; 2606 dev->features |= EMAC_FTR_440EP_PHY_CLK_FIX;
2607 if (of_device_is_compatible(np, "ibm,emac-405ez"))
2608 dev->features |= EMAC_FTR_NO_FLOW_CONTROL_40x;
2588 } 2609 }
2589 2610
2590 /* Fixup some feature bits based on the device tree */ 2611 /* Fixup some feature bits based on the device tree */
@@ -2842,6 +2863,9 @@ static int __devinit emac_probe(struct of_device *ofdev,
2842 ndev->dev_addr[0], ndev->dev_addr[1], ndev->dev_addr[2], 2863 ndev->dev_addr[0], ndev->dev_addr[1], ndev->dev_addr[2],
2843 ndev->dev_addr[3], ndev->dev_addr[4], ndev->dev_addr[5]); 2864 ndev->dev_addr[3], ndev->dev_addr[4], ndev->dev_addr[5]);
2844 2865
2866 if (dev->phy_mode == PHY_MODE_SGMII)
2867 printk(KERN_NOTICE "%s: in SGMII mode\n", ndev->name);
2868
2845 if (dev->phy.address >= 0) 2869 if (dev->phy.address >= 0)
2846 printk("%s: found %s PHY (0x%02x)\n", ndev->name, 2870 printk("%s: found %s PHY (0x%02x)\n", ndev->name,
2847 dev->phy.def->name, dev->phy.address); 2871 dev->phy.def->name, dev->phy.address);
diff --git a/drivers/net/ibm_newemac/core.h b/drivers/net/ibm_newemac/core.h
index 5ca70e55b6c5..18d56c6c4238 100644
--- a/drivers/net/ibm_newemac/core.h
+++ b/drivers/net/ibm_newemac/core.h
@@ -190,6 +190,9 @@ struct emac_instance {
190 struct delayed_work link_work; 190 struct delayed_work link_work;
191 int link_polling; 191 int link_polling;
192 192
193 /* GPCS PHY infos */
194 u32 gpcs_address;
195
193 /* Shared MDIO if any */ 196 /* Shared MDIO if any */
194 u32 mdio_ph; 197 u32 mdio_ph;
195 struct of_device *mdio_dev; 198 struct of_device *mdio_dev;
@@ -345,6 +348,9 @@ enum {
345#ifdef CONFIG_IBM_NEW_EMAC_RGMII 348#ifdef CONFIG_IBM_NEW_EMAC_RGMII
346 EMAC_FTR_HAS_RGMII | 349 EMAC_FTR_HAS_RGMII |
347#endif 350#endif
351#ifdef CONFIG_IBM_NEW_EMAC_NO_FLOW_CTRL
352 EMAC_FTR_NO_FLOW_CONTROL_40x |
353#endif
348 EMAC_FTR_460EX_PHY_CLK_FIX | 354 EMAC_FTR_460EX_PHY_CLK_FIX |
349 EMAC_FTR_440EP_PHY_CLK_FIX, 355 EMAC_FTR_440EP_PHY_CLK_FIX,
350}; 356};
diff --git a/drivers/net/ibm_newemac/mal.c b/drivers/net/ibm_newemac/mal.c
index 10c267b2b961..1839d3f154a3 100644
--- a/drivers/net/ibm_newemac/mal.c
+++ b/drivers/net/ibm_newemac/mal.c
@@ -28,6 +28,7 @@
28#include <linux/delay.h> 28#include <linux/delay.h>
29 29
30#include "core.h" 30#include "core.h"
31#include <asm/dcr-regs.h>
31 32
32static int mal_count; 33static int mal_count;
33 34
@@ -279,6 +280,10 @@ static irqreturn_t mal_txeob(int irq, void *dev_instance)
279 mal_schedule_poll(mal); 280 mal_schedule_poll(mal);
280 set_mal_dcrn(mal, MAL_TXEOBISR, r); 281 set_mal_dcrn(mal, MAL_TXEOBISR, r);
281 282
283 if (mal_has_feature(mal, MAL_FTR_CLEAR_ICINTSTAT))
284 mtdcri(SDR0, DCRN_SDR_ICINTSTAT,
285 (mfdcri(SDR0, DCRN_SDR_ICINTSTAT) | ICINTSTAT_ICTX));
286
282 return IRQ_HANDLED; 287 return IRQ_HANDLED;
283} 288}
284 289
@@ -293,6 +298,10 @@ static irqreturn_t mal_rxeob(int irq, void *dev_instance)
293 mal_schedule_poll(mal); 298 mal_schedule_poll(mal);
294 set_mal_dcrn(mal, MAL_RXEOBISR, r); 299 set_mal_dcrn(mal, MAL_RXEOBISR, r);
295 300
301 if (mal_has_feature(mal, MAL_FTR_CLEAR_ICINTSTAT))
302 mtdcri(SDR0, DCRN_SDR_ICINTSTAT,
303 (mfdcri(SDR0, DCRN_SDR_ICINTSTAT) | ICINTSTAT_ICRX));
304
296 return IRQ_HANDLED; 305 return IRQ_HANDLED;
297} 306}
298 307
@@ -336,6 +345,25 @@ static irqreturn_t mal_rxde(int irq, void *dev_instance)
336 return IRQ_HANDLED; 345 return IRQ_HANDLED;
337} 346}
338 347
348static irqreturn_t mal_int(int irq, void *dev_instance)
349{
350 struct mal_instance *mal = dev_instance;
351 u32 esr = get_mal_dcrn(mal, MAL_ESR);
352
353 if (esr & MAL_ESR_EVB) {
354 /* descriptor error */
355 if (esr & MAL_ESR_DE) {
356 if (esr & MAL_ESR_CIDT)
357 return mal_rxde(irq, dev_instance);
358 else
359 return mal_txde(irq, dev_instance);
360 } else { /* SERR */
361 return mal_serr(irq, dev_instance);
362 }
363 }
364 return IRQ_HANDLED;
365}
366
339void mal_poll_disable(struct mal_instance *mal, struct mal_commac *commac) 367void mal_poll_disable(struct mal_instance *mal, struct mal_commac *commac)
340{ 368{
341 /* Spinlock-type semantics: only one caller disable poll at a time */ 369 /* Spinlock-type semantics: only one caller disable poll at a time */
@@ -493,6 +521,8 @@ static int __devinit mal_probe(struct of_device *ofdev,
493 unsigned int dcr_base; 521 unsigned int dcr_base;
494 const u32 *prop; 522 const u32 *prop;
495 u32 cfg; 523 u32 cfg;
524 unsigned long irqflags;
525 irq_handler_t hdlr_serr, hdlr_txde, hdlr_rxde;
496 526
497 mal = kzalloc(sizeof(struct mal_instance), GFP_KERNEL); 527 mal = kzalloc(sizeof(struct mal_instance), GFP_KERNEL);
498 if (!mal) { 528 if (!mal) {
@@ -542,11 +572,21 @@ static int __devinit mal_probe(struct of_device *ofdev,
542 goto fail; 572 goto fail;
543 } 573 }
544 574
575 if (of_device_is_compatible(ofdev->node, "ibm,mcmal-405ez"))
576 mal->features |= (MAL_FTR_CLEAR_ICINTSTAT |
577 MAL_FTR_COMMON_ERR_INT);
578
545 mal->txeob_irq = irq_of_parse_and_map(ofdev->node, 0); 579 mal->txeob_irq = irq_of_parse_and_map(ofdev->node, 0);
546 mal->rxeob_irq = irq_of_parse_and_map(ofdev->node, 1); 580 mal->rxeob_irq = irq_of_parse_and_map(ofdev->node, 1);
547 mal->serr_irq = irq_of_parse_and_map(ofdev->node, 2); 581 mal->serr_irq = irq_of_parse_and_map(ofdev->node, 2);
548 mal->txde_irq = irq_of_parse_and_map(ofdev->node, 3); 582
549 mal->rxde_irq = irq_of_parse_and_map(ofdev->node, 4); 583 if (mal_has_feature(mal, MAL_FTR_COMMON_ERR_INT)) {
584 mal->txde_irq = mal->rxde_irq = mal->serr_irq;
585 } else {
586 mal->txde_irq = irq_of_parse_and_map(ofdev->node, 3);
587 mal->rxde_irq = irq_of_parse_and_map(ofdev->node, 4);
588 }
589
550 if (mal->txeob_irq == NO_IRQ || mal->rxeob_irq == NO_IRQ || 590 if (mal->txeob_irq == NO_IRQ || mal->rxeob_irq == NO_IRQ ||
551 mal->serr_irq == NO_IRQ || mal->txde_irq == NO_IRQ || 591 mal->serr_irq == NO_IRQ || mal->txde_irq == NO_IRQ ||
552 mal->rxde_irq == NO_IRQ) { 592 mal->rxde_irq == NO_IRQ) {
@@ -608,16 +648,26 @@ static int __devinit mal_probe(struct of_device *ofdev,
608 sizeof(struct mal_descriptor) * 648 sizeof(struct mal_descriptor) *
609 mal_rx_bd_offset(mal, i)); 649 mal_rx_bd_offset(mal, i));
610 650
611 err = request_irq(mal->serr_irq, mal_serr, 0, "MAL SERR", mal); 651 if (mal_has_feature(mal, MAL_FTR_COMMON_ERR_INT)) {
652 irqflags = IRQF_SHARED;
653 hdlr_serr = hdlr_txde = hdlr_rxde = mal_int;
654 } else {
655 irqflags = 0;
656 hdlr_serr = mal_serr;
657 hdlr_txde = mal_txde;
658 hdlr_rxde = mal_rxde;
659 }
660
661 err = request_irq(mal->serr_irq, hdlr_serr, irqflags, "MAL SERR", mal);
612 if (err) 662 if (err)
613 goto fail2; 663 goto fail2;
614 err = request_irq(mal->txde_irq, mal_txde, 0, "MAL TX DE", mal); 664 err = request_irq(mal->txde_irq, hdlr_txde, irqflags, "MAL TX DE", mal);
615 if (err) 665 if (err)
616 goto fail3; 666 goto fail3;
617 err = request_irq(mal->txeob_irq, mal_txeob, 0, "MAL TX EOB", mal); 667 err = request_irq(mal->txeob_irq, mal_txeob, 0, "MAL TX EOB", mal);
618 if (err) 668 if (err)
619 goto fail4; 669 goto fail4;
620 err = request_irq(mal->rxde_irq, mal_rxde, 0, "MAL RX DE", mal); 670 err = request_irq(mal->rxde_irq, hdlr_rxde, irqflags, "MAL RX DE", mal);
621 if (err) 671 if (err)
622 goto fail5; 672 goto fail5;
623 err = request_irq(mal->rxeob_irq, mal_rxeob, 0, "MAL RX EOB", mal); 673 err = request_irq(mal->rxeob_irq, mal_rxeob, 0, "MAL RX EOB", mal);
diff --git a/drivers/net/ibm_newemac/mal.h b/drivers/net/ibm_newemac/mal.h
index 717dc38b6858..2f0a87360844 100644
--- a/drivers/net/ibm_newemac/mal.h
+++ b/drivers/net/ibm_newemac/mal.h
@@ -213,6 +213,8 @@ struct mal_instance {
213 struct of_device *ofdev; 213 struct of_device *ofdev;
214 int index; 214 int index;
215 spinlock_t lock; 215 spinlock_t lock;
216
217 unsigned int features;
216}; 218};
217 219
218static inline u32 get_mal_dcrn(struct mal_instance *mal, int reg) 220static inline u32 get_mal_dcrn(struct mal_instance *mal, int reg)
@@ -225,6 +227,38 @@ static inline void set_mal_dcrn(struct mal_instance *mal, int reg, u32 val)
225 dcr_write(mal->dcr_host, reg, val); 227 dcr_write(mal->dcr_host, reg, val);
226} 228}
227 229
230/* Features of various MAL implementations */
231
232/* Set if you have interrupt coalescing and you have to clear the SDR
233 * register for TXEOB and RXEOB interrupts to work
234 */
235#define MAL_FTR_CLEAR_ICINTSTAT 0x00000001
236
237/* Set if your MAL has SERR, TXDE, and RXDE OR'd into a single UIC
238 * interrupt
239 */
240#define MAL_FTR_COMMON_ERR_INT 0x00000002
241
242enum {
243 MAL_FTRS_ALWAYS = 0,
244
245 MAL_FTRS_POSSIBLE =
246#ifdef CONFIG_IBM_NEW_EMAC_MAL_CLR_ICINTSTAT
247 MAL_FTR_CLEAR_ICINTSTAT |
248#endif
249#ifdef CONFIG_IBM_NEW_EMAC_MAL_COMMON_ERR
250 MAL_FTR_COMMON_ERR_INT |
251#endif
252 0,
253};
254
255static inline int mal_has_feature(struct mal_instance *dev,
256 unsigned long feature)
257{
258 return (MAL_FTRS_ALWAYS & feature) ||
259 (MAL_FTRS_POSSIBLE & dev->features & feature);
260}
261
228/* Register MAL devices */ 262/* Register MAL devices */
229int mal_init(void); 263int mal_init(void);
230void mal_exit(void); 264void mal_exit(void);
diff --git a/drivers/net/ibm_newemac/phy.c b/drivers/net/ibm_newemac/phy.c
index 9164abb72d9b..c40cd8df2212 100644
--- a/drivers/net/ibm_newemac/phy.c
+++ b/drivers/net/ibm_newemac/phy.c
@@ -38,6 +38,16 @@ static inline void phy_write(struct mii_phy *phy, int reg, int val)
38 phy->mdio_write(phy->dev, phy->address, reg, val); 38 phy->mdio_write(phy->dev, phy->address, reg, val);
39} 39}
40 40
41static inline int gpcs_phy_read(struct mii_phy *phy, int reg)
42{
43 return phy->mdio_read(phy->dev, phy->gpcs_address, reg);
44}
45
46static inline void gpcs_phy_write(struct mii_phy *phy, int reg, int val)
47{
48 phy->mdio_write(phy->dev, phy->gpcs_address, reg, val);
49}
50
41int emac_mii_reset_phy(struct mii_phy *phy) 51int emac_mii_reset_phy(struct mii_phy *phy)
42{ 52{
43 int val; 53 int val;
@@ -62,6 +72,37 @@ int emac_mii_reset_phy(struct mii_phy *phy)
62 return limit <= 0; 72 return limit <= 0;
63} 73}
64 74
75int emac_mii_reset_gpcs(struct mii_phy *phy)
76{
77 int val;
78 int limit = 10000;
79
80 val = gpcs_phy_read(phy, MII_BMCR);
81 val &= ~(BMCR_ISOLATE | BMCR_ANENABLE);
82 val |= BMCR_RESET;
83 gpcs_phy_write(phy, MII_BMCR, val);
84
85 udelay(300);
86
87 while (limit--) {
88 val = gpcs_phy_read(phy, MII_BMCR);
89 if (val >= 0 && (val & BMCR_RESET) == 0)
90 break;
91 udelay(10);
92 }
93 if ((val & BMCR_ISOLATE) && limit > 0)
94 gpcs_phy_write(phy, MII_BMCR, val & ~BMCR_ISOLATE);
95
96 if (limit > 0 && phy->mode == PHY_MODE_SGMII) {
97 /* Configure GPCS interface to recommended setting for SGMII */
98 gpcs_phy_write(phy, 0x04, 0x8120); /* AsymPause, FDX */
99 gpcs_phy_write(phy, 0x07, 0x2801); /* msg_pg, toggle */
100 gpcs_phy_write(phy, 0x00, 0x0140); /* 1Gbps, FDX */
101 }
102
103 return limit <= 0;
104}
105
65static int genmii_setup_aneg(struct mii_phy *phy, u32 advertise) 106static int genmii_setup_aneg(struct mii_phy *phy, u32 advertise)
66{ 107{
67 int ctl, adv; 108 int ctl, adv;
@@ -332,6 +373,33 @@ static int m88e1111_init(struct mii_phy *phy)
332 return 0; 373 return 0;
333} 374}
334 375
376static int m88e1112_init(struct mii_phy *phy)
377{
378 /*
379 * Marvell 88E1112 PHY needs to have the SGMII MAC
380 * interace (page 2) properly configured to
381 * communicate with the 460EX/GT GPCS interface.
382 */
383
384 u16 reg_short;
385
386 pr_debug("%s: Marvell 88E1112 Ethernet\n", __func__);
387
388 /* Set access to Page 2 */
389 phy_write(phy, 0x16, 0x0002);
390
391 phy_write(phy, 0x00, 0x0040); /* 1Gbps */
392 reg_short = (u16)(phy_read(phy, 0x1a));
393 reg_short |= 0x8000; /* bypass Auto-Negotiation */
394 phy_write(phy, 0x1a, reg_short);
395 emac_mii_reset_phy(phy); /* reset MAC interface */
396
397 /* Reset access to Page 0 */
398 phy_write(phy, 0x16, 0x0000);
399
400 return 0;
401}
402
335static int et1011c_init(struct mii_phy *phy) 403static int et1011c_init(struct mii_phy *phy)
336{ 404{
337 u16 reg_short; 405 u16 reg_short;
@@ -384,11 +452,27 @@ static struct mii_phy_def m88e1111_phy_def = {
384 .ops = &m88e1111_phy_ops, 452 .ops = &m88e1111_phy_ops,
385}; 453};
386 454
455static struct mii_phy_ops m88e1112_phy_ops = {
456 .init = m88e1112_init,
457 .setup_aneg = genmii_setup_aneg,
458 .setup_forced = genmii_setup_forced,
459 .poll_link = genmii_poll_link,
460 .read_link = genmii_read_link
461};
462
463static struct mii_phy_def m88e1112_phy_def = {
464 .phy_id = 0x01410C90,
465 .phy_id_mask = 0x0ffffff0,
466 .name = "Marvell 88E1112 Ethernet",
467 .ops = &m88e1112_phy_ops,
468};
469
387static struct mii_phy_def *mii_phy_table[] = { 470static struct mii_phy_def *mii_phy_table[] = {
388 &et1011c_phy_def, 471 &et1011c_phy_def,
389 &cis8201_phy_def, 472 &cis8201_phy_def,
390 &bcm5248_phy_def, 473 &bcm5248_phy_def,
391 &m88e1111_phy_def, 474 &m88e1111_phy_def,
475 &m88e1112_phy_def,
392 &genmii_phy_def, 476 &genmii_phy_def,
393 NULL 477 NULL
394}; 478};
diff --git a/drivers/net/ibm_newemac/phy.h b/drivers/net/ibm_newemac/phy.h
index 1b65c81f6557..5d2bf4cbe50b 100644
--- a/drivers/net/ibm_newemac/phy.h
+++ b/drivers/net/ibm_newemac/phy.h
@@ -57,6 +57,7 @@ struct mii_phy {
57 or determined automaticaly */ 57 or determined automaticaly */
58 int address; /* PHY address */ 58 int address; /* PHY address */
59 int mode; /* PHY mode */ 59 int mode; /* PHY mode */
60 int gpcs_address; /* GPCS PHY address */
60 61
61 /* 1: autoneg enabled, 0: disabled */ 62 /* 1: autoneg enabled, 0: disabled */
62 int autoneg; 63 int autoneg;
@@ -81,5 +82,6 @@ struct mii_phy {
81 */ 82 */
82int emac_mii_phy_probe(struct mii_phy *phy, int address); 83int emac_mii_phy_probe(struct mii_phy *phy, int address);
83int emac_mii_reset_phy(struct mii_phy *phy); 84int emac_mii_reset_phy(struct mii_phy *phy);
85int emac_mii_reset_gpcs(struct mii_phy *phy);
84 86
85#endif /* __IBM_NEWEMAC_PHY_H */ 87#endif /* __IBM_NEWEMAC_PHY_H */
diff --git a/drivers/net/ibmlana.c b/drivers/net/ibmlana.c
index 95e3464068db..f02764725a22 100644
--- a/drivers/net/ibmlana.c
+++ b/drivers/net/ibmlana.c
@@ -71,7 +71,7 @@ History:
71 June 1st, 2000 71 June 1st, 2000
72 corrected version codes, added support for the latest 2.3 changes 72 corrected version codes, added support for the latest 2.3 changes
73 Oct 28th, 2002 73 Oct 28th, 2002
74 cleaned up for the 2.5 tree <alan@redhat.com> 74 cleaned up for the 2.5 tree <alan@lxorguk.ukuu.org.uk>
75 75
76 *************************************************************************/ 76 *************************************************************************/
77 77
diff --git a/drivers/net/irda/sir_dongle.c b/drivers/net/irda/sir_dongle.c
index 36030241f7a9..2a9930e6e2af 100644
--- a/drivers/net/irda/sir_dongle.c
+++ b/drivers/net/irda/sir_dongle.c
@@ -67,9 +67,7 @@ int sirdev_get_dongle(struct sir_dev *dev, IRDA_DONGLE type)
67 const struct dongle_driver *drv = NULL; 67 const struct dongle_driver *drv = NULL;
68 int err = -EINVAL; 68 int err = -EINVAL;
69 69
70#ifdef CONFIG_KMOD
71 request_module("irda-dongle-%d", type); 70 request_module("irda-dongle-%d", type);
72#endif
73 71
74 if (dev->dongle_drv != NULL) 72 if (dev->dongle_drv != NULL)
75 return -EBUSY; 73 return -EBUSY;
diff --git a/drivers/net/ixgbe/ixgbe.h b/drivers/net/ixgbe/ixgbe.h
index 2198b77c53ed..e116d340dcc6 100644
--- a/drivers/net/ixgbe/ixgbe.h
+++ b/drivers/net/ixgbe/ixgbe.h
@@ -36,7 +36,7 @@
36#include "ixgbe_type.h" 36#include "ixgbe_type.h"
37#include "ixgbe_common.h" 37#include "ixgbe_common.h"
38 38
39#if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE) 39#ifdef CONFIG_IXGBE_DCA
40#include <linux/dca.h> 40#include <linux/dca.h>
41#endif 41#endif
42 42
@@ -136,7 +136,7 @@ struct ixgbe_ring {
136 * offset associated with this ring, which is different 136 * offset associated with this ring, which is different
137 * for DCE and RSS modes */ 137 * for DCE and RSS modes */
138 138
139#if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE) 139#ifdef CONFIG_IXGBE_DCA
140 /* cpu for tx queue */ 140 /* cpu for tx queue */
141 int cpu; 141 int cpu;
142#endif 142#endif
diff --git a/drivers/net/ixgbe/ixgbe_main.c b/drivers/net/ixgbe/ixgbe_main.c
index ca17af4349d0..7548fb7360d9 100644
--- a/drivers/net/ixgbe/ixgbe_main.c
+++ b/drivers/net/ixgbe/ixgbe_main.c
@@ -80,7 +80,7 @@ static struct pci_device_id ixgbe_pci_tbl[] = {
80}; 80};
81MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); 81MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
82 82
83#if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE) 83#ifdef CONFIG_IXGBE_DCA
84static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, 84static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
85 void *p); 85 void *p);
86static struct notifier_block dca_notifier = { 86static struct notifier_block dca_notifier = {
@@ -296,7 +296,7 @@ done_cleaning:
296 return (total_packets ? true : false); 296 return (total_packets ? true : false);
297} 297}
298 298
299#if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE) 299#ifdef CONFIG_IXGBE_DCA
300static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, 300static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
301 struct ixgbe_ring *rx_ring) 301 struct ixgbe_ring *rx_ring)
302{ 302{
@@ -383,7 +383,7 @@ static int __ixgbe_notify_dca(struct device *dev, void *data)
383 return 0; 383 return 0;
384} 384}
385 385
386#endif /* CONFIG_DCA or CONFIG_DCA_MODULE */ 386#endif /* CONFIG_IXGBE_DCA */
387/** 387/**
388 * ixgbe_receive_skb - Send a completed packet up the stack 388 * ixgbe_receive_skb - Send a completed packet up the stack
389 * @adapter: board private structure 389 * @adapter: board private structure
@@ -947,7 +947,7 @@ static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
947 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); 947 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
948 for (i = 0; i < q_vector->txr_count; i++) { 948 for (i = 0; i < q_vector->txr_count; i++) {
949 tx_ring = &(adapter->tx_ring[r_idx]); 949 tx_ring = &(adapter->tx_ring[r_idx]);
950#if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE) 950#ifdef CONFIG_IXGBE_DCA
951 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) 951 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
952 ixgbe_update_tx_dca(adapter, tx_ring); 952 ixgbe_update_tx_dca(adapter, tx_ring);
953#endif 953#endif
@@ -1022,7 +1022,7 @@ static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
1022 1022
1023 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); 1023 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1024 rx_ring = &(adapter->rx_ring[r_idx]); 1024 rx_ring = &(adapter->rx_ring[r_idx]);
1025#if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE) 1025#ifdef CONFIG_IXGBE_DCA
1026 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) 1026 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1027 ixgbe_update_rx_dca(adapter, rx_ring); 1027 ixgbe_update_rx_dca(adapter, rx_ring);
1028#endif 1028#endif
@@ -1066,7 +1066,7 @@ static int ixgbe_clean_rxonly_many(struct napi_struct *napi, int budget)
1066 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); 1066 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1067 for (i = 0; i < q_vector->rxr_count; i++) { 1067 for (i = 0; i < q_vector->rxr_count; i++) {
1068 rx_ring = &(adapter->rx_ring[r_idx]); 1068 rx_ring = &(adapter->rx_ring[r_idx]);
1069#if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE) 1069#ifdef CONFIG_IXGBE_DCA
1070 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) 1070 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1071 ixgbe_update_rx_dca(adapter, rx_ring); 1071 ixgbe_update_rx_dca(adapter, rx_ring);
1072#endif 1072#endif
@@ -2155,7 +2155,7 @@ void ixgbe_down(struct ixgbe_adapter *adapter)
2155 2155
2156 netif_carrier_off(netdev); 2156 netif_carrier_off(netdev);
2157 2157
2158#if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE) 2158#ifdef CONFIG_IXGBE_DCA
2159 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { 2159 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2160 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; 2160 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
2161 dca_remove_requester(&adapter->pdev->dev); 2161 dca_remove_requester(&adapter->pdev->dev);
@@ -2167,7 +2167,7 @@ void ixgbe_down(struct ixgbe_adapter *adapter)
2167 ixgbe_clean_all_tx_rings(adapter); 2167 ixgbe_clean_all_tx_rings(adapter);
2168 ixgbe_clean_all_rx_rings(adapter); 2168 ixgbe_clean_all_rx_rings(adapter);
2169 2169
2170#if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE) 2170#ifdef CONFIG_IXGBE_DCA
2171 /* since we reset the hardware DCA settings were cleared */ 2171 /* since we reset the hardware DCA settings were cleared */
2172 if (dca_add_requester(&adapter->pdev->dev) == 0) { 2172 if (dca_add_requester(&adapter->pdev->dev) == 0) {
2173 adapter->flags |= IXGBE_FLAG_DCA_ENABLED; 2173 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
@@ -2193,7 +2193,7 @@ static int ixgbe_poll(struct napi_struct *napi, int budget)
2193 struct ixgbe_adapter *adapter = q_vector->adapter; 2193 struct ixgbe_adapter *adapter = q_vector->adapter;
2194 int tx_cleaned, work_done = 0; 2194 int tx_cleaned, work_done = 0;
2195 2195
2196#if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE) 2196#ifdef CONFIG_IXGBE_DCA
2197 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { 2197 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
2198 ixgbe_update_tx_dca(adapter, adapter->tx_ring); 2198 ixgbe_update_tx_dca(adapter, adapter->tx_ring);
2199 ixgbe_update_rx_dca(adapter, adapter->rx_ring); 2199 ixgbe_update_rx_dca(adapter, adapter->rx_ring);
@@ -3922,7 +3922,7 @@ static int __devinit ixgbe_probe(struct pci_dev *pdev,
3922 if (err) 3922 if (err)
3923 goto err_register; 3923 goto err_register;
3924 3924
3925#if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE) 3925#ifdef CONFIG_IXGBE_DCA
3926 if (dca_add_requester(&pdev->dev) == 0) { 3926 if (dca_add_requester(&pdev->dev) == 0) {
3927 adapter->flags |= IXGBE_FLAG_DCA_ENABLED; 3927 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
3928 /* always use CB2 mode, difference is masked 3928 /* always use CB2 mode, difference is masked
@@ -3972,7 +3972,7 @@ static void __devexit ixgbe_remove(struct pci_dev *pdev)
3972 3972
3973 flush_scheduled_work(); 3973 flush_scheduled_work();
3974 3974
3975#if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE) 3975#ifdef CONFIG_IXGBE_DCA
3976 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { 3976 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
3977 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; 3977 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
3978 dca_remove_requester(&pdev->dev); 3978 dca_remove_requester(&pdev->dev);
@@ -4105,10 +4105,10 @@ static int __init ixgbe_init_module(void)
4105 4105
4106 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright); 4106 printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright);
4107 4107
4108#if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE) 4108#ifdef CONFIG_IXGBE_DCA
4109 dca_register_notify(&dca_notifier); 4109 dca_register_notify(&dca_notifier);
4110
4111#endif 4110#endif
4111
4112 ret = pci_register_driver(&ixgbe_driver); 4112 ret = pci_register_driver(&ixgbe_driver);
4113 return ret; 4113 return ret;
4114} 4114}
@@ -4123,13 +4123,13 @@ module_init(ixgbe_init_module);
4123 **/ 4123 **/
4124static void __exit ixgbe_exit_module(void) 4124static void __exit ixgbe_exit_module(void)
4125{ 4125{
4126#if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE) 4126#ifdef CONFIG_IXGBE_DCA
4127 dca_unregister_notify(&dca_notifier); 4127 dca_unregister_notify(&dca_notifier);
4128#endif 4128#endif
4129 pci_unregister_driver(&ixgbe_driver); 4129 pci_unregister_driver(&ixgbe_driver);
4130} 4130}
4131 4131
4132#if defined(CONFIG_DCA) || defined(CONFIG_DCA_MODULE) 4132#ifdef CONFIG_IXGBE_DCA
4133static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, 4133static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
4134 void *p) 4134 void *p)
4135{ 4135{
@@ -4140,7 +4140,7 @@ static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
4140 4140
4141 return ret_val ? NOTIFY_BAD : NOTIFY_DONE; 4141 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
4142} 4142}
4143#endif /* CONFIG_DCA or CONFIG_DCA_MODULE */ 4143#endif /* CONFIG_IXGBE_DCA */
4144 4144
4145module_exit(ixgbe_exit_module); 4145module_exit(ixgbe_exit_module);
4146 4146
diff --git a/drivers/net/jme.c b/drivers/net/jme.c
index 5f9a1313fa3e..81c6cdc3851f 100644
--- a/drivers/net/jme.c
+++ b/drivers/net/jme.c
@@ -21,7 +21,6 @@
21 * 21 *
22 */ 22 */
23 23
24#include <linux/version.h>
25#include <linux/module.h> 24#include <linux/module.h>
26#include <linux/kernel.h> 25#include <linux/kernel.h>
27#include <linux/pci.h> 26#include <linux/pci.h>
@@ -38,6 +37,7 @@
38#include <linux/tcp.h> 37#include <linux/tcp.h>
39#include <linux/udp.h> 38#include <linux/udp.h>
40#include <linux/if_vlan.h> 39#include <linux/if_vlan.h>
40#include <net/ip6_checksum.h>
41#include "jme.h" 41#include "jme.h"
42 42
43static int force_pseudohp = -1; 43static int force_pseudohp = -1;
diff --git a/drivers/net/macmace.c b/drivers/net/macmace.c
index 51ad3765e075..85587a6667b9 100644
--- a/drivers/net/macmace.c
+++ b/drivers/net/macmace.c
@@ -9,7 +9,7 @@
9 * 2 of the License, or (at your option) any later version. 9 * 2 of the License, or (at your option) any later version.
10 * 10 *
11 * Copyright (C) 1996 Paul Mackerras. 11 * Copyright (C) 1996 Paul Mackerras.
12 * Copyright (C) 1998 Alan Cox <alan@redhat.com> 12 * Copyright (C) 1998 Alan Cox <alan@lxorguk.ukuu.org.uk>
13 * 13 *
14 * Modified heavily by Joshua M. Thompson based on Dave Huang's NetBSD driver 14 * Modified heavily by Joshua M. Thompson based on Dave Huang's NetBSD driver
15 * 15 *
diff --git a/drivers/net/myri10ge/myri10ge.c b/drivers/net/myri10ge/myri10ge.c
index 6dce901c7f45..a9aebad52652 100644
--- a/drivers/net/myri10ge/myri10ge.c
+++ b/drivers/net/myri10ge/myri10ge.c
@@ -188,7 +188,7 @@ struct myri10ge_slice_state {
188 dma_addr_t fw_stats_bus; 188 dma_addr_t fw_stats_bus;
189 int watchdog_tx_done; 189 int watchdog_tx_done;
190 int watchdog_tx_req; 190 int watchdog_tx_req;
191#if (defined CONFIG_DCA) || (defined CONFIG_DCA_MODULE) 191#ifdef CONFIG_MYRI10GE_DCA
192 int cached_dca_tag; 192 int cached_dca_tag;
193 int cpu; 193 int cpu;
194 __be32 __iomem *dca_tag; 194 __be32 __iomem *dca_tag;
@@ -220,7 +220,7 @@ struct myri10ge_priv {
220 int msi_enabled; 220 int msi_enabled;
221 int msix_enabled; 221 int msix_enabled;
222 struct msix_entry *msix_vectors; 222 struct msix_entry *msix_vectors;
223#if (defined CONFIG_DCA) || (defined CONFIG_DCA_MODULE) 223#ifdef CONFIG_MYRI10GE_DCA
224 int dca_enabled; 224 int dca_enabled;
225#endif 225#endif
226 u32 link_state; 226 u32 link_state;
@@ -902,7 +902,7 @@ static int myri10ge_reset(struct myri10ge_priv *mgp)
902 struct myri10ge_slice_state *ss; 902 struct myri10ge_slice_state *ss;
903 int i, status; 903 int i, status;
904 size_t bytes; 904 size_t bytes;
905#if (defined CONFIG_DCA) || (defined CONFIG_DCA_MODULE) 905#ifdef CONFIG_MYRI10GE_DCA
906 unsigned long dca_tag_off; 906 unsigned long dca_tag_off;
907#endif 907#endif
908 908
@@ -1012,7 +1012,7 @@ static int myri10ge_reset(struct myri10ge_priv *mgp)
1012 } 1012 }
1013 put_be32(htonl(mgp->intr_coal_delay), mgp->intr_coal_delay_ptr); 1013 put_be32(htonl(mgp->intr_coal_delay), mgp->intr_coal_delay_ptr);
1014 1014
1015#if (defined CONFIG_DCA) || (defined CONFIG_DCA_MODULE) 1015#ifdef CONFIG_MYRI10GE_DCA
1016 status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_DCA_OFFSET, &cmd, 0); 1016 status = myri10ge_send_cmd(mgp, MXGEFW_CMD_GET_DCA_OFFSET, &cmd, 0);
1017 dca_tag_off = cmd.data0; 1017 dca_tag_off = cmd.data0;
1018 for (i = 0; i < mgp->num_slices; i++) { 1018 for (i = 0; i < mgp->num_slices; i++) {
@@ -1051,7 +1051,7 @@ static int myri10ge_reset(struct myri10ge_priv *mgp)
1051 return status; 1051 return status;
1052} 1052}
1053 1053
1054#if (defined CONFIG_DCA) || (defined CONFIG_DCA_MODULE) 1054#ifdef CONFIG_MYRI10GE_DCA
1055static void 1055static void
1056myri10ge_write_dca(struct myri10ge_slice_state *ss, int cpu, int tag) 1056myri10ge_write_dca(struct myri10ge_slice_state *ss, int cpu, int tag)
1057{ 1057{
@@ -1505,7 +1505,7 @@ static int myri10ge_poll(struct napi_struct *napi, int budget)
1505 struct net_device *netdev = ss->mgp->dev; 1505 struct net_device *netdev = ss->mgp->dev;
1506 int work_done; 1506 int work_done;
1507 1507
1508#if (defined CONFIG_DCA) || (defined CONFIG_DCA_MODULE) 1508#ifdef CONFIG_MYRI10GE_DCA
1509 if (ss->mgp->dca_enabled) 1509 if (ss->mgp->dca_enabled)
1510 myri10ge_update_dca(ss); 1510 myri10ge_update_dca(ss);
1511#endif 1511#endif
@@ -1736,7 +1736,7 @@ static const char myri10ge_gstrings_main_stats[][ETH_GSTRING_LEN] = {
1736 "tx_boundary", "WC", "irq", "MSI", "MSIX", 1736 "tx_boundary", "WC", "irq", "MSI", "MSIX",
1737 "read_dma_bw_MBs", "write_dma_bw_MBs", "read_write_dma_bw_MBs", 1737 "read_dma_bw_MBs", "write_dma_bw_MBs", "read_write_dma_bw_MBs",
1738 "serial_number", "watchdog_resets", 1738 "serial_number", "watchdog_resets",
1739#if (defined CONFIG_DCA) || (defined CONFIG_DCA_MODULE) 1739#ifdef CONFIG_MYRI10GE_DCA
1740 "dca_capable_firmware", "dca_device_present", 1740 "dca_capable_firmware", "dca_device_present",
1741#endif 1741#endif
1742 "link_changes", "link_up", "dropped_link_overflow", 1742 "link_changes", "link_up", "dropped_link_overflow",
@@ -1815,7 +1815,7 @@ myri10ge_get_ethtool_stats(struct net_device *netdev,
1815 data[i++] = (unsigned int)mgp->read_write_dma; 1815 data[i++] = (unsigned int)mgp->read_write_dma;
1816 data[i++] = (unsigned int)mgp->serial_number; 1816 data[i++] = (unsigned int)mgp->serial_number;
1817 data[i++] = (unsigned int)mgp->watchdog_resets; 1817 data[i++] = (unsigned int)mgp->watchdog_resets;
1818#if (defined CONFIG_DCA) || (defined CONFIG_DCA_MODULE) 1818#ifdef CONFIG_MYRI10GE_DCA
1819 data[i++] = (unsigned int)(mgp->ss[0].dca_tag != NULL); 1819 data[i++] = (unsigned int)(mgp->ss[0].dca_tag != NULL);
1820 data[i++] = (unsigned int)(mgp->dca_enabled); 1820 data[i++] = (unsigned int)(mgp->dca_enabled);
1821#endif 1821#endif
@@ -3844,7 +3844,7 @@ static int myri10ge_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3844 dev_err(&pdev->dev, "failed reset\n"); 3844 dev_err(&pdev->dev, "failed reset\n");
3845 goto abort_with_slices; 3845 goto abort_with_slices;
3846 } 3846 }
3847#if (defined CONFIG_DCA) || (defined CONFIG_DCA_MODULE) 3847#ifdef CONFIG_MYRI10GE_DCA
3848 myri10ge_setup_dca(mgp); 3848 myri10ge_setup_dca(mgp);
3849#endif 3849#endif
3850 pci_set_drvdata(pdev, mgp); 3850 pci_set_drvdata(pdev, mgp);
@@ -3948,7 +3948,7 @@ static void myri10ge_remove(struct pci_dev *pdev)
3948 netdev = mgp->dev; 3948 netdev = mgp->dev;
3949 unregister_netdev(netdev); 3949 unregister_netdev(netdev);
3950 3950
3951#if (defined CONFIG_DCA) || (defined CONFIG_DCA_MODULE) 3951#ifdef CONFIG_MYRI10GE_DCA
3952 myri10ge_teardown_dca(mgp); 3952 myri10ge_teardown_dca(mgp);
3953#endif 3953#endif
3954 myri10ge_dummy_rdma(mgp, 0); 3954 myri10ge_dummy_rdma(mgp, 0);
@@ -3993,7 +3993,7 @@ static struct pci_driver myri10ge_driver = {
3993#endif 3993#endif
3994}; 3994};
3995 3995
3996#if (defined CONFIG_DCA) || (defined CONFIG_DCA_MODULE) 3996#ifdef CONFIG_MYRI10GE_DCA
3997static int 3997static int
3998myri10ge_notify_dca(struct notifier_block *nb, unsigned long event, void *p) 3998myri10ge_notify_dca(struct notifier_block *nb, unsigned long event, void *p)
3999{ 3999{
@@ -4024,7 +4024,7 @@ static __init int myri10ge_init_module(void)
4024 myri10ge_driver.name, myri10ge_rss_hash); 4024 myri10ge_driver.name, myri10ge_rss_hash);
4025 myri10ge_rss_hash = MXGEFW_RSS_HASH_TYPE_SRC_PORT; 4025 myri10ge_rss_hash = MXGEFW_RSS_HASH_TYPE_SRC_PORT;
4026 } 4026 }
4027#if (defined CONFIG_DCA) || (defined CONFIG_DCA_MODULE) 4027#ifdef CONFIG_MYRI10GE_DCA
4028 dca_register_notify(&myri10ge_dca_notifier); 4028 dca_register_notify(&myri10ge_dca_notifier);
4029#endif 4029#endif
4030 if (myri10ge_max_slices > MYRI10GE_MAX_SLICES) 4030 if (myri10ge_max_slices > MYRI10GE_MAX_SLICES)
@@ -4037,7 +4037,7 @@ module_init(myri10ge_init_module);
4037 4037
4038static __exit void myri10ge_cleanup_module(void) 4038static __exit void myri10ge_cleanup_module(void)
4039{ 4039{
4040#if (defined CONFIG_DCA) || (defined CONFIG_DCA_MODULE) 4040#ifdef CONFIG_MYRI10GE_DCA
4041 dca_unregister_notify(&myri10ge_dca_notifier); 4041 dca_unregister_notify(&myri10ge_dca_notifier);
4042#endif 4042#endif
4043 pci_unregister_driver(&myri10ge_driver); 4043 pci_unregister_driver(&myri10ge_driver);
diff --git a/drivers/net/pcmcia/3c574_cs.c b/drivers/net/pcmcia/3c574_cs.c
index 7112fd5e0e1b..08c4dd896077 100644
--- a/drivers/net/pcmcia/3c574_cs.c
+++ b/drivers/net/pcmcia/3c574_cs.c
@@ -355,9 +355,10 @@ static int tc574_config(struct pcmcia_device *link)
355 for (i = j = 0; j < 0x400; j += 0x20) { 355 for (i = j = 0; j < 0x400; j += 0x20) {
356 link->io.BasePort1 = j ^ 0x300; 356 link->io.BasePort1 = j ^ 0x300;
357 i = pcmcia_request_io(link, &link->io); 357 i = pcmcia_request_io(link, &link->io);
358 if (i == CS_SUCCESS) break; 358 if (i == 0)
359 break;
359 } 360 }
360 if (i != CS_SUCCESS) { 361 if (i != 0) {
361 cs_error(link, RequestIO, i); 362 cs_error(link, RequestIO, i);
362 goto failed; 363 goto failed;
363 } 364 }
@@ -377,7 +378,7 @@ static int tc574_config(struct pcmcia_device *link)
377 tuple.TupleDataMax = 64; 378 tuple.TupleDataMax = 64;
378 tuple.TupleOffset = 0; 379 tuple.TupleOffset = 0;
379 tuple.DesiredTuple = 0x88; 380 tuple.DesiredTuple = 0x88;
380 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) { 381 if (pcmcia_get_first_tuple(link, &tuple) == 0) {
381 pcmcia_get_tuple_data(link, &tuple); 382 pcmcia_get_tuple_data(link, &tuple);
382 for (i = 0; i < 3; i++) 383 for (i = 0; i < 3; i++)
383 phys_addr[i] = htons(le16_to_cpu(buf[i])); 384 phys_addr[i] = htons(le16_to_cpu(buf[i]));
diff --git a/drivers/net/pcmcia/3c589_cs.c b/drivers/net/pcmcia/3c589_cs.c
index 549a64558420..c235cdba69c6 100644
--- a/drivers/net/pcmcia/3c589_cs.c
+++ b/drivers/net/pcmcia/3c589_cs.c
@@ -15,7 +15,7 @@
15 incorporated herein by reference. 15 incorporated herein by reference.
16 Donald Becker may be reached at becker@scyld.com 16 Donald Becker may be reached at becker@scyld.com
17 17
18 Updated for 2.5.x by Alan Cox <alan@redhat.com> 18 Updated for 2.5.x by Alan Cox <alan@lxorguk.ukuu.org.uk>
19 19
20======================================================================*/ 20======================================================================*/
21 21
@@ -278,9 +278,10 @@ static int tc589_config(struct pcmcia_device *link)
278 if (multi && (j & 0x80)) continue; 278 if (multi && (j & 0x80)) continue;
279 link->io.BasePort1 = j ^ 0x300; 279 link->io.BasePort1 = j ^ 0x300;
280 i = pcmcia_request_io(link, &link->io); 280 i = pcmcia_request_io(link, &link->io);
281 if (i == CS_SUCCESS) break; 281 if (i == 0)
282 break;
282 } 283 }
283 if (i != CS_SUCCESS) { 284 if (i != 0) {
284 cs_error(link, RequestIO, i); 285 cs_error(link, RequestIO, i);
285 goto failed; 286 goto failed;
286 } 287 }
@@ -295,7 +296,7 @@ static int tc589_config(struct pcmcia_device *link)
295 /* The 3c589 has an extra EEPROM for configuration info, including 296 /* The 3c589 has an extra EEPROM for configuration info, including
296 the hardware address. The 3c562 puts the address in the CIS. */ 297 the hardware address. The 3c562 puts the address in the CIS. */
297 tuple.DesiredTuple = 0x88; 298 tuple.DesiredTuple = 0x88;
298 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) { 299 if (pcmcia_get_first_tuple(link, &tuple) == 0) {
299 pcmcia_get_tuple_data(link, &tuple); 300 pcmcia_get_tuple_data(link, &tuple);
300 for (i = 0; i < 3; i++) 301 for (i = 0; i < 3; i++)
301 phys_addr[i] = htons(le16_to_cpu(buf[i])); 302 phys_addr[i] = htons(le16_to_cpu(buf[i]));
diff --git a/drivers/net/pcmcia/Kconfig b/drivers/net/pcmcia/Kconfig
index e8f55d8ed7a9..9b8f793b1cc8 100644
--- a/drivers/net/pcmcia/Kconfig
+++ b/drivers/net/pcmcia/Kconfig
@@ -111,7 +111,7 @@ config ARCNET_COM20020_CS
111 111
112config PCMCIA_IBMTR 112config PCMCIA_IBMTR
113 tristate "IBM PCMCIA tokenring adapter support" 113 tristate "IBM PCMCIA tokenring adapter support"
114 depends on IBMTR!=y && TR && !64BIT 114 depends on IBMTR!=y && TR
115 help 115 help
116 Say Y here if you intend to attach this type of Token Ring PCMCIA 116 Say Y here if you intend to attach this type of Token Ring PCMCIA
117 card to your computer. You then also need to say Y to "Token Ring 117 card to your computer. You then also need to say Y to "Token Ring
diff --git a/drivers/net/pcmcia/axnet_cs.c b/drivers/net/pcmcia/axnet_cs.c
index 52bf11b73c6e..b37a498939ae 100644
--- a/drivers/net/pcmcia/axnet_cs.c
+++ b/drivers/net/pcmcia/axnet_cs.c
@@ -262,7 +262,7 @@ static int try_io_port(struct pcmcia_device *link)
262 if (link->io.NumPorts2 > 0) { 262 if (link->io.NumPorts2 > 0) {
263 /* for master/slave multifunction cards */ 263 /* for master/slave multifunction cards */
264 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 264 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
265 link->irq.Attributes = 265 link->irq.Attributes =
266 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED; 266 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
267 } 267 }
268 } else { 268 } else {
@@ -276,7 +276,8 @@ static int try_io_port(struct pcmcia_device *link)
276 link->io.BasePort1 = j ^ 0x300; 276 link->io.BasePort1 = j ^ 0x300;
277 link->io.BasePort2 = (j ^ 0x300) + 0x10; 277 link->io.BasePort2 = (j ^ 0x300) + 0x10;
278 ret = pcmcia_request_io(link, &link->io); 278 ret = pcmcia_request_io(link, &link->io);
279 if (ret == CS_SUCCESS) return ret; 279 if (ret == 0)
280 return ret;
280 } 281 }
281 return ret; 282 return ret;
282 } else { 283 } else {
@@ -284,59 +285,50 @@ static int try_io_port(struct pcmcia_device *link)
284 } 285 }
285} 286}
286 287
288static int axnet_configcheck(struct pcmcia_device *p_dev,
289 cistpl_cftable_entry_t *cfg,
290 cistpl_cftable_entry_t *dflt,
291 unsigned int vcc,
292 void *priv_data)
293{
294 int i;
295 cistpl_io_t *io = &cfg->io;
296
297 if (cfg->index == 0 || cfg->io.nwin == 0)
298 return -ENODEV;
299
300 p_dev->conf.ConfigIndex = 0x05;
301 /* For multifunction cards, by convention, we configure the
302 network function with window 0, and serial with window 1 */
303 if (io->nwin > 1) {
304 i = (io->win[1].len > io->win[0].len);
305 p_dev->io.BasePort2 = io->win[1-i].base;
306 p_dev->io.NumPorts2 = io->win[1-i].len;
307 } else {
308 i = p_dev->io.NumPorts2 = 0;
309 }
310 p_dev->io.BasePort1 = io->win[i].base;
311 p_dev->io.NumPorts1 = io->win[i].len;
312 p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
313 if (p_dev->io.NumPorts1 + p_dev->io.NumPorts2 >= 32)
314 return try_io_port(p_dev);
315
316 return -ENODEV;
317}
318
287static int axnet_config(struct pcmcia_device *link) 319static int axnet_config(struct pcmcia_device *link)
288{ 320{
289 struct net_device *dev = link->priv; 321 struct net_device *dev = link->priv;
290 axnet_dev_t *info = PRIV(dev); 322 axnet_dev_t *info = PRIV(dev);
291 tuple_t tuple;
292 cisparse_t parse;
293 int i, j, last_ret, last_fn; 323 int i, j, last_ret, last_fn;
294 u_short buf[64];
295 DECLARE_MAC_BUF(mac); 324 DECLARE_MAC_BUF(mac);
296 325
297 DEBUG(0, "axnet_config(0x%p)\n", link); 326 DEBUG(0, "axnet_config(0x%p)\n", link);
298 327
299 tuple.Attributes = 0;
300 tuple.TupleData = (cisdata_t *)buf;
301 tuple.TupleDataMax = sizeof(buf);
302 tuple.TupleOffset = 0;
303
304 /* don't trust the CIS on this; Linksys got it wrong */ 328 /* don't trust the CIS on this; Linksys got it wrong */
305 link->conf.Present = 0x63; 329 link->conf.Present = 0x63;
306 330 last_ret = pcmcia_loop_config(link, axnet_configcheck, NULL);
307 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 331 if (last_ret != 0) {
308 tuple.Attributes = 0;
309 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
310 while (last_ret == CS_SUCCESS) {
311 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
312 cistpl_io_t *io = &(parse.cftable_entry.io);
313
314 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
315 pcmcia_parse_tuple(link, &tuple, &parse) != 0 ||
316 cfg->index == 0 || cfg->io.nwin == 0)
317 goto next_entry;
318
319 link->conf.ConfigIndex = 0x05;
320 /* For multifunction cards, by convention, we configure the
321 network function with window 0, and serial with window 1 */
322 if (io->nwin > 1) {
323 i = (io->win[1].len > io->win[0].len);
324 link->io.BasePort2 = io->win[1-i].base;
325 link->io.NumPorts2 = io->win[1-i].len;
326 } else {
327 i = link->io.NumPorts2 = 0;
328 }
329 link->io.BasePort1 = io->win[i].base;
330 link->io.NumPorts1 = io->win[i].len;
331 link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
332 if (link->io.NumPorts1 + link->io.NumPorts2 >= 32) {
333 last_ret = try_io_port(link);
334 if (last_ret == CS_SUCCESS) break;
335 }
336 next_entry:
337 last_ret = pcmcia_get_next_tuple(link, &tuple);
338 }
339 if (last_ret != CS_SUCCESS) {
340 cs_error(link, RequestIO, last_ret); 332 cs_error(link, RequestIO, last_ret);
341 goto failed; 333 goto failed;
342 } 334 }
diff --git a/drivers/net/pcmcia/com20020_cs.c b/drivers/net/pcmcia/com20020_cs.c
index ea9414c4d900..831090c75622 100644
--- a/drivers/net/pcmcia/com20020_cs.c
+++ b/drivers/net/pcmcia/com20020_cs.c
@@ -260,21 +260,21 @@ static int com20020_config(struct pcmcia_device *link)
260 DEBUG(0, "com20020_config(0x%p)\n", link); 260 DEBUG(0, "com20020_config(0x%p)\n", link);
261 261
262 DEBUG(1,"arcnet: baseport1 is %Xh\n", link->io.BasePort1); 262 DEBUG(1,"arcnet: baseport1 is %Xh\n", link->io.BasePort1);
263 i = !CS_SUCCESS; 263 i = -ENODEV;
264 if (!link->io.BasePort1) 264 if (!link->io.BasePort1)
265 { 265 {
266 for (ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x10) 266 for (ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x10)
267 { 267 {
268 link->io.BasePort1 = ioaddr; 268 link->io.BasePort1 = ioaddr;
269 i = pcmcia_request_io(link, &link->io); 269 i = pcmcia_request_io(link, &link->io);
270 if (i == CS_SUCCESS) 270 if (i == 0)
271 break; 271 break;
272 } 272 }
273 } 273 }
274 else 274 else
275 i = pcmcia_request_io(link, &link->io); 275 i = pcmcia_request_io(link, &link->io);
276 276
277 if (i != CS_SUCCESS) 277 if (i != 0)
278 { 278 {
279 DEBUG(1,"arcnet: requestIO failed totally!\n"); 279 DEBUG(1,"arcnet: requestIO failed totally!\n");
280 goto failed; 280 goto failed;
@@ -287,7 +287,7 @@ static int com20020_config(struct pcmcia_device *link)
287 link->irq.AssignedIRQ, 287 link->irq.AssignedIRQ,
288 link->irq.IRQInfo1, link->irq.IRQInfo2); 288 link->irq.IRQInfo1, link->irq.IRQInfo2);
289 i = pcmcia_request_irq(link, &link->irq); 289 i = pcmcia_request_irq(link, &link->irq);
290 if (i != CS_SUCCESS) 290 if (i != 0)
291 { 291 {
292 DEBUG(1,"arcnet: requestIRQ failed totally!\n"); 292 DEBUG(1,"arcnet: requestIRQ failed totally!\n");
293 goto failed; 293 goto failed;
diff --git a/drivers/net/pcmcia/fmvj18x_cs.c b/drivers/net/pcmcia/fmvj18x_cs.c
index a550c9bd126f..69d916daa7bb 100644
--- a/drivers/net/pcmcia/fmvj18x_cs.c
+++ b/drivers/net/pcmcia/fmvj18x_cs.c
@@ -309,7 +309,8 @@ static int mfc_try_io_port(struct pcmcia_device *link)
309 printk(KERN_NOTICE "fmvj18x_cs: out of resource for serial\n"); 309 printk(KERN_NOTICE "fmvj18x_cs: out of resource for serial\n");
310 } 310 }
311 ret = pcmcia_request_io(link, &link->io); 311 ret = pcmcia_request_io(link, &link->io);
312 if (ret == CS_SUCCESS) return ret; 312 if (ret == 0)
313 return ret;
313 } 314 }
314 return ret; 315 return ret;
315} 316}
@@ -325,7 +326,7 @@ static int ungermann_try_io_port(struct pcmcia_device *link)
325 for (ioaddr = 0x300; ioaddr < 0x3e0; ioaddr += 0x20) { 326 for (ioaddr = 0x300; ioaddr < 0x3e0; ioaddr += 0x20) {
326 link->io.BasePort1 = ioaddr; 327 link->io.BasePort1 = ioaddr;
327 ret = pcmcia_request_io(link, &link->io); 328 ret = pcmcia_request_io(link, &link->io);
328 if (ret == CS_SUCCESS) { 329 if (ret == 0) {
329 /* calculate ConfigIndex value */ 330 /* calculate ConfigIndex value */
330 link->conf.ConfigIndex = 331 link->conf.ConfigIndex =
331 ((link->io.BasePort1 & 0x0f0) >> 3) | 0x22; 332 ((link->io.BasePort1 & 0x0f0) >> 3) | 0x22;
@@ -356,12 +357,12 @@ static int fmvj18x_config(struct pcmcia_device *link)
356 tuple.TupleOffset = 0; 357 tuple.TupleOffset = 0;
357 tuple.DesiredTuple = CISTPL_FUNCE; 358 tuple.DesiredTuple = CISTPL_FUNCE;
358 tuple.TupleOffset = 0; 359 tuple.TupleOffset = 0;
359 if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) { 360 if (pcmcia_get_first_tuple(link, &tuple) == 0) {
360 /* Yes, I have CISTPL_FUNCE. Let's check CISTPL_MANFID */ 361 /* Yes, I have CISTPL_FUNCE. Let's check CISTPL_MANFID */
361 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 362 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
362 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); 363 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
363 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple)); 364 CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
364 CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse)); 365 CS_CHECK(ParseTuple, pcmcia_parse_tuple(&tuple, &parse));
365 link->conf.ConfigIndex = parse.cftable_entry.index; 366 link->conf.ConfigIndex = parse.cftable_entry.index;
366 switch (link->manf_id) { 367 switch (link->manf_id) {
367 case MANFID_TDK: 368 case MANFID_TDK:
@@ -430,10 +431,10 @@ static int fmvj18x_config(struct pcmcia_device *link)
430 link->irq.Attributes = 431 link->irq.Attributes =
431 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT; 432 IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
432 ret = mfc_try_io_port(link); 433 ret = mfc_try_io_port(link);
433 if (ret != CS_SUCCESS) goto cs_failed; 434 if (ret != 0) goto cs_failed;
434 } else if (cardtype == UNGERMANN) { 435 } else if (cardtype == UNGERMANN) {
435 ret = ungermann_try_io_port(link); 436 ret = ungermann_try_io_port(link);
436 if (ret != CS_SUCCESS) goto cs_failed; 437 if (ret != 0) goto cs_failed;
437 } else { 438 } else {
438 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io)); 439 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
439 } 440 }
@@ -565,7 +566,7 @@ static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id)
565 req.Base = 0; req.Size = 0; 566 req.Base = 0; req.Size = 0;
566 req.AccessSpeed = 0; 567 req.AccessSpeed = 0;
567 i = pcmcia_request_window(&link, &req, &link->win); 568 i = pcmcia_request_window(&link, &req, &link->win);
568 if (i != CS_SUCCESS) { 569 if (i != 0) {
569 cs_error(link, RequestWindow, i); 570 cs_error(link, RequestWindow, i);
570 return -1; 571 return -1;
571 } 572 }
@@ -599,7 +600,7 @@ static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id)
599 600
600 iounmap(base); 601 iounmap(base);
601 j = pcmcia_release_window(link->win); 602 j = pcmcia_release_window(link->win);
602 if (j != CS_SUCCESS) 603 if (j != 0)
603 cs_error(link, ReleaseWindow, j); 604 cs_error(link, ReleaseWindow, j);
604 return (i != 0x200) ? 0 : -1; 605 return (i != 0x200) ? 0 : -1;
605 606
@@ -620,7 +621,7 @@ static int fmvj18x_setup_mfc(struct pcmcia_device *link)
620 req.Base = 0; req.Size = 0; 621 req.Base = 0; req.Size = 0;
621 req.AccessSpeed = 0; 622 req.AccessSpeed = 0;
622 i = pcmcia_request_window(&link, &req, &link->win); 623 i = pcmcia_request_window(&link, &req, &link->win);
623 if (i != CS_SUCCESS) { 624 if (i != 0) {
624 cs_error(link, RequestWindow, i); 625 cs_error(link, RequestWindow, i);
625 return -1; 626 return -1;
626 } 627 }
@@ -642,7 +643,7 @@ static int fmvj18x_setup_mfc(struct pcmcia_device *link)
642 643
643 iounmap(base); 644 iounmap(base);
644 j = pcmcia_release_window(link->win); 645 j = pcmcia_release_window(link->win);
645 if (j != CS_SUCCESS) 646 if (j != 0)
646 cs_error(link, ReleaseWindow, j); 647 cs_error(link, ReleaseWindow, j);
647 return 0; 648 return 0;
648 649
diff --git a/drivers/net/pcmcia/ibmtr_cs.c b/drivers/net/pcmcia/ibmtr_cs.c
index 4eafa4f42cff..cf3cca4642f2 100644
--- a/drivers/net/pcmcia/ibmtr_cs.c
+++ b/drivers/net/pcmcia/ibmtr_cs.c
@@ -238,7 +238,7 @@ static int __devinit ibmtr_config(struct pcmcia_device *link)
238 /* Try PRIMARY card at 0xA20-0xA23 */ 238 /* Try PRIMARY card at 0xA20-0xA23 */
239 link->io.BasePort1 = 0xA20; 239 link->io.BasePort1 = 0xA20;
240 i = pcmcia_request_io(link, &link->io); 240 i = pcmcia_request_io(link, &link->io);
241 if (i != CS_SUCCESS) { 241 if (i != 0) {
242 /* Couldn't get 0xA20-0xA23. Try ALTERNATE at 0xA24-0xA27. */ 242 /* Couldn't get 0xA20-0xA23. Try ALTERNATE at 0xA24-0xA27. */
243 link->io.BasePort1 = 0xA24; 243 link->io.BasePort1 = 0xA24;
244 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io)); 244 CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
diff --git a/drivers/net/pcmcia/nmclan_cs.c b/drivers/net/pcmcia/nmclan_cs.c
index cfcbea9b7e2e..448cd40aeba5 100644
--- a/drivers/net/pcmcia/nmclan_cs.c
+++ b/drivers/net/pcmcia/nmclan_cs.c
@@ -69,7 +69,7 @@ Driver Notes and Issues
69History 69History
70------------------------------------------------------------------------------- 70-------------------------------------------------------------------------------
71Log: nmclan_cs.c,v 71Log: nmclan_cs.c,v
72 * 2.5.75-ac1 2003/07/11 Alan Cox <alan@redhat.com> 72 * 2.5.75-ac1 2003/07/11 Alan Cox <alan@lxorguk.ukuu.org.uk>
73 * Fixed hang on card eject as we probe it 73 * Fixed hang on card eject as we probe it
74 * Cleaned up to use new style locking. 74 * Cleaned up to use new style locking.
75 * 75 *
@@ -925,7 +925,7 @@ static void mace_tx_timeout(struct net_device *dev)
925 printk(KERN_NOTICE "%s: transmit timed out -- ", dev->name); 925 printk(KERN_NOTICE "%s: transmit timed out -- ", dev->name);
926#if RESET_ON_TIMEOUT 926#if RESET_ON_TIMEOUT
927 printk("resetting card\n"); 927 printk("resetting card\n");
928 pcmcia_reset_card(link, NULL); 928 pcmcia_reset_card(link->socket);
929#else /* #if RESET_ON_TIMEOUT */ 929#else /* #if RESET_ON_TIMEOUT */
930 printk("NOT resetting card\n"); 930 printk("NOT resetting card\n");
931#endif /* #if RESET_ON_TIMEOUT */ 931#endif /* #if RESET_ON_TIMEOUT */
diff --git a/drivers/net/pcmcia/pcnet_cs.c b/drivers/net/pcmcia/pcnet_cs.c
index ebc1ae6bcbe5..e40d6301aa7a 100644
--- a/drivers/net/pcmcia/pcnet_cs.c
+++ b/drivers/net/pcmcia/pcnet_cs.c
@@ -310,7 +310,7 @@ static hw_info_t *get_hwinfo(struct pcmcia_device *link)
310 req.Base = 0; req.Size = 0; 310 req.Base = 0; req.Size = 0;
311 req.AccessSpeed = 0; 311 req.AccessSpeed = 0;
312 i = pcmcia_request_window(&link, &req, &link->win); 312 i = pcmcia_request_window(&link, &req, &link->win);
313 if (i != CS_SUCCESS) { 313 if (i != 0) {
314 cs_error(link, RequestWindow, i); 314 cs_error(link, RequestWindow, i);
315 return NULL; 315 return NULL;
316 } 316 }
@@ -333,7 +333,7 @@ static hw_info_t *get_hwinfo(struct pcmcia_device *link)
333 333
334 iounmap(virt); 334 iounmap(virt);
335 j = pcmcia_release_window(link->win); 335 j = pcmcia_release_window(link->win);
336 if (j != CS_SUCCESS) 336 if (j != 0)
337 cs_error(link, ReleaseWindow, j); 337 cs_error(link, ReleaseWindow, j);
338 return (i < NR_INFO) ? hw_info+i : NULL; 338 return (i < NR_INFO) ? hw_info+i : NULL;
339} /* get_hwinfo */ 339} /* get_hwinfo */
@@ -504,7 +504,8 @@ static int try_io_port(struct pcmcia_device *link)
504 link->io.BasePort1 = j ^ 0x300; 504 link->io.BasePort1 = j ^ 0x300;
505 link->io.BasePort2 = (j ^ 0x300) + 0x10; 505 link->io.BasePort2 = (j ^ 0x300) + 0x10;
506 ret = pcmcia_request_io(link, &link->io); 506 ret = pcmcia_request_io(link, &link->io);
507 if (ret == CS_SUCCESS) return ret; 507 if (ret == 0)
508 return ret;
508 } 509 }
509 return ret; 510 return ret;
510 } else { 511 } else {
@@ -512,58 +513,53 @@ static int try_io_port(struct pcmcia_device *link)
512 } 513 }
513} 514}
514 515
516static int pcnet_confcheck(struct pcmcia_device *p_dev,
517 cistpl_cftable_entry_t *cfg,
518 cistpl_cftable_entry_t *dflt,
519 unsigned int vcc,
520 void *priv_data)
521{
522 int *has_shmem = priv_data;
523 int i;
524 cistpl_io_t *io = &cfg->io;
525
526 if (cfg->index == 0 || cfg->io.nwin == 0)
527 return -EINVAL;
528
529 /* For multifunction cards, by convention, we configure the
530 network function with window 0, and serial with window 1 */
531 if (io->nwin > 1) {
532 i = (io->win[1].len > io->win[0].len);
533 p_dev->io.BasePort2 = io->win[1-i].base;
534 p_dev->io.NumPorts2 = io->win[1-i].len;
535 } else {
536 i = p_dev->io.NumPorts2 = 0;
537 }
538
539 *has_shmem = ((cfg->mem.nwin == 1) &&
540 (cfg->mem.win[0].len >= 0x4000));
541 p_dev->io.BasePort1 = io->win[i].base;
542 p_dev->io.NumPorts1 = io->win[i].len;
543 p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
544 if (p_dev->io.NumPorts1 + p_dev->io.NumPorts2 >= 32)
545 return try_io_port(p_dev);
546
547 return 0;
548}
549
515static int pcnet_config(struct pcmcia_device *link) 550static int pcnet_config(struct pcmcia_device *link)
516{ 551{
517 struct net_device *dev = link->priv; 552 struct net_device *dev = link->priv;
518 pcnet_dev_t *info = PRIV(dev); 553 pcnet_dev_t *info = PRIV(dev);
519 tuple_t tuple; 554 int last_ret, last_fn, start_pg, stop_pg, cm_offset;
520 cisparse_t parse;
521 int i, last_ret, last_fn, start_pg, stop_pg, cm_offset;
522 int has_shmem = 0; 555 int has_shmem = 0;
523 u_short buf[64];
524 hw_info_t *local_hw_info; 556 hw_info_t *local_hw_info;
525 DECLARE_MAC_BUF(mac); 557 DECLARE_MAC_BUF(mac);
526 558
527 DEBUG(0, "pcnet_config(0x%p)\n", link); 559 DEBUG(0, "pcnet_config(0x%p)\n", link);
528 560
529 tuple.TupleData = (cisdata_t *)buf; 561 last_ret = pcmcia_loop_config(link, pcnet_confcheck, &has_shmem);
530 tuple.TupleDataMax = sizeof(buf); 562 if (last_ret) {
531 tuple.TupleOffset = 0;
532 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
533 tuple.Attributes = 0;
534 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
535 while (last_ret == CS_SUCCESS) {
536 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
537 cistpl_io_t *io = &(parse.cftable_entry.io);
538
539 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
540 pcmcia_parse_tuple(link, &tuple, &parse) != 0 ||
541 cfg->index == 0 || cfg->io.nwin == 0)
542 goto next_entry;
543
544 link->conf.ConfigIndex = cfg->index;
545 /* For multifunction cards, by convention, we configure the
546 network function with window 0, and serial with window 1 */
547 if (io->nwin > 1) {
548 i = (io->win[1].len > io->win[0].len);
549 link->io.BasePort2 = io->win[1-i].base;
550 link->io.NumPorts2 = io->win[1-i].len;
551 } else {
552 i = link->io.NumPorts2 = 0;
553 }
554 has_shmem = ((cfg->mem.nwin == 1) &&
555 (cfg->mem.win[0].len >= 0x4000));
556 link->io.BasePort1 = io->win[i].base;
557 link->io.NumPorts1 = io->win[i].len;
558 link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
559 if (link->io.NumPorts1 + link->io.NumPorts2 >= 32) {
560 last_ret = try_io_port(link);
561 if (last_ret == CS_SUCCESS) break;
562 }
563 next_entry:
564 last_ret = pcmcia_get_next_tuple(link, &tuple);
565 }
566 if (last_ret != CS_SUCCESS) {
567 cs_error(link, RequestIO, last_ret); 563 cs_error(link, RequestIO, last_ret);
568 goto failed; 564 goto failed;
569 } 565 }
diff --git a/drivers/net/pcmcia/smc91c92_cs.c b/drivers/net/pcmcia/smc91c92_cs.c
index 250eb1954c34..c74d6656d266 100644
--- a/drivers/net/pcmcia/smc91c92_cs.c
+++ b/drivers/net/pcmcia/smc91c92_cs.c
@@ -409,10 +409,13 @@ static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
409{ 409{
410 int i; 410 int i;
411 411
412 if ((i = pcmcia_get_first_tuple(handle, tuple)) != CS_SUCCESS || 412 i = pcmcia_get_first_tuple(handle, tuple);
413 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS) 413 if (i != 0)
414 return i; 414 return i;
415 return pcmcia_parse_tuple(handle, tuple, parse); 415 i = pcmcia_get_tuple_data(handle, tuple);
416 if (i != 0)
417 return i;
418 return pcmcia_parse_tuple(tuple, parse);
416} 419}
417 420
418static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, 421static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
@@ -420,10 +423,10 @@ static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
420{ 423{
421 int i; 424 int i;
422 425
423 if ((i = pcmcia_get_next_tuple(handle, tuple)) != CS_SUCCESS || 426 if ((i = pcmcia_get_next_tuple(handle, tuple)) != 0 ||
424 (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS) 427 (i = pcmcia_get_tuple_data(handle, tuple)) != 0)
425 return i; 428 return i;
426 return pcmcia_parse_tuple(handle, tuple, parse); 429 return pcmcia_parse_tuple(tuple, parse);
427} 430}
428 431
429/*====================================================================== 432/*======================================================================
@@ -459,27 +462,36 @@ static int mhz_3288_power(struct pcmcia_device *link)
459 return 0; 462 return 0;
460} 463}
461 464
465static int mhz_mfc_config_check(struct pcmcia_device *p_dev,
466 cistpl_cftable_entry_t *cf,
467 cistpl_cftable_entry_t *dflt,
468 unsigned int vcc,
469 void *priv_data)
470{
471 int k;
472 p_dev->io.BasePort2 = cf->io.win[0].base;
473 for (k = 0; k < 0x400; k += 0x10) {
474 if (k & 0x80)
475 continue;
476 p_dev->io.BasePort1 = k ^ 0x300;
477 if (!pcmcia_request_io(p_dev, &p_dev->io))
478 return 0;
479 }
480 return -ENODEV;
481}
482
462static int mhz_mfc_config(struct pcmcia_device *link) 483static int mhz_mfc_config(struct pcmcia_device *link)
463{ 484{
464 struct net_device *dev = link->priv; 485 struct net_device *dev = link->priv;
465 struct smc_private *smc = netdev_priv(dev); 486 struct smc_private *smc = netdev_priv(dev);
466 struct smc_cfg_mem *cfg_mem; 487 struct smc_cfg_mem *cfg_mem;
467 tuple_t *tuple;
468 cisparse_t *parse;
469 cistpl_cftable_entry_t *cf;
470 u_char *buf;
471 win_req_t req; 488 win_req_t req;
472 memreq_t mem; 489 memreq_t mem;
473 int i, k; 490 int i;
474 491
475 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL); 492 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
476 if (!cfg_mem) 493 if (!cfg_mem)
477 return CS_OUT_OF_RESOURCE; 494 return -ENOMEM;
478
479 tuple = &cfg_mem->tuple;
480 parse = &cfg_mem->parse;
481 cf = &parse->cftable_entry;
482 buf = cfg_mem->buf;
483 495
484 link->conf.Attributes |= CONF_ENABLE_SPKR; 496 link->conf.Attributes |= CONF_ENABLE_SPKR;
485 link->conf.Status = CCSR_AUDIO_ENA; 497 link->conf.Status = CCSR_AUDIO_ENA;
@@ -489,27 +501,9 @@ static int mhz_mfc_config(struct pcmcia_device *link)
489 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; 501 link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
490 link->io.NumPorts2 = 8; 502 link->io.NumPorts2 = 8;
491 503
492 tuple->Attributes = tuple->TupleOffset = 0;
493 tuple->TupleData = (cisdata_t *)buf;
494 tuple->TupleDataMax = 255;
495 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
496
497 i = first_tuple(link, tuple, parse);
498 /* The Megahertz combo cards have modem-like CIS entries, so 504 /* The Megahertz combo cards have modem-like CIS entries, so
499 we have to explicitly try a bunch of port combinations. */ 505 we have to explicitly try a bunch of port combinations. */
500 while (i == CS_SUCCESS) { 506 if (pcmcia_loop_config(link, mhz_mfc_config_check, NULL))
501 link->conf.ConfigIndex = cf->index;
502 link->io.BasePort2 = cf->io.win[0].base;
503 for (k = 0; k < 0x400; k += 0x10) {
504 if (k & 0x80) continue;
505 link->io.BasePort1 = k ^ 0x300;
506 i = pcmcia_request_io(link, &link->io);
507 if (i == CS_SUCCESS) break;
508 }
509 if (i == CS_SUCCESS) break;
510 i = next_tuple(link, tuple, parse);
511 }
512 if (i != CS_SUCCESS)
513 goto free_cfg_mem; 507 goto free_cfg_mem;
514 dev->base_addr = link->io.BasePort1; 508 dev->base_addr = link->io.BasePort1;
515 509
@@ -518,7 +512,7 @@ static int mhz_mfc_config(struct pcmcia_device *link)
518 req.Base = req.Size = 0; 512 req.Base = req.Size = 0;
519 req.AccessSpeed = 0; 513 req.AccessSpeed = 0;
520 i = pcmcia_request_window(&link, &req, &link->win); 514 i = pcmcia_request_window(&link, &req, &link->win);
521 if (i != CS_SUCCESS) 515 if (i != 0)
522 goto free_cfg_mem; 516 goto free_cfg_mem;
523 smc->base = ioremap(req.Base, req.Size); 517 smc->base = ioremap(req.Base, req.Size);
524 mem.CardOffset = mem.Page = 0; 518 mem.CardOffset = mem.Page = 0;
@@ -526,14 +520,14 @@ static int mhz_mfc_config(struct pcmcia_device *link)
526 mem.CardOffset = link->conf.ConfigBase; 520 mem.CardOffset = link->conf.ConfigBase;
527 i = pcmcia_map_mem_page(link->win, &mem); 521 i = pcmcia_map_mem_page(link->win, &mem);
528 522
529 if ((i == CS_SUCCESS) 523 if ((i == 0)
530 && (smc->manfid == MANFID_MEGAHERTZ) 524 && (smc->manfid == MANFID_MEGAHERTZ)
531 && (smc->cardid == PRODID_MEGAHERTZ_EM3288)) 525 && (smc->cardid == PRODID_MEGAHERTZ_EM3288))
532 mhz_3288_power(link); 526 mhz_3288_power(link);
533 527
534free_cfg_mem: 528free_cfg_mem:
535 kfree(cfg_mem); 529 kfree(cfg_mem);
536 return i; 530 return -ENODEV;
537} 531}
538 532
539static int mhz_setup(struct pcmcia_device *link) 533static int mhz_setup(struct pcmcia_device *link)
@@ -560,12 +554,12 @@ static int mhz_setup(struct pcmcia_device *link)
560 /* Read the station address from the CIS. It is stored as the last 554 /* Read the station address from the CIS. It is stored as the last
561 (fourth) string in the Version 1 Version/ID tuple. */ 555 (fourth) string in the Version 1 Version/ID tuple. */
562 tuple->DesiredTuple = CISTPL_VERS_1; 556 tuple->DesiredTuple = CISTPL_VERS_1;
563 if (first_tuple(link, tuple, parse) != CS_SUCCESS) { 557 if (first_tuple(link, tuple, parse) != 0) {
564 rc = -1; 558 rc = -1;
565 goto free_cfg_mem; 559 goto free_cfg_mem;
566 } 560 }
567 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */ 561 /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
568 if (next_tuple(link, tuple, parse) != CS_SUCCESS) 562 if (next_tuple(link, tuple, parse) != 0)
569 first_tuple(link, tuple, parse); 563 first_tuple(link, tuple, parse);
570 if (parse->version_1.ns > 3) { 564 if (parse->version_1.ns > 3) {
571 station_addr = parse->version_1.str + parse->version_1.ofs[3]; 565 station_addr = parse->version_1.str + parse->version_1.ofs[3];
@@ -577,11 +571,11 @@ static int mhz_setup(struct pcmcia_device *link)
577 571
578 /* Another possibility: for the EM3288, in a special tuple */ 572 /* Another possibility: for the EM3288, in a special tuple */
579 tuple->DesiredTuple = 0x81; 573 tuple->DesiredTuple = 0x81;
580 if (pcmcia_get_first_tuple(link, tuple) != CS_SUCCESS) { 574 if (pcmcia_get_first_tuple(link, tuple) != 0) {
581 rc = -1; 575 rc = -1;
582 goto free_cfg_mem; 576 goto free_cfg_mem;
583 } 577 }
584 if (pcmcia_get_tuple_data(link, tuple) != CS_SUCCESS) { 578 if (pcmcia_get_tuple_data(link, tuple) != 0) {
585 rc = -1; 579 rc = -1;
586 goto free_cfg_mem; 580 goto free_cfg_mem;
587 } 581 }
@@ -660,46 +654,27 @@ static int mot_setup(struct pcmcia_device *link)
660 654
661/*====================================================================*/ 655/*====================================================================*/
662 656
657static int smc_configcheck(struct pcmcia_device *p_dev,
658 cistpl_cftable_entry_t *cf,
659 cistpl_cftable_entry_t *dflt,
660 unsigned int vcc,
661 void *priv_data)
662{
663 p_dev->io.BasePort1 = cf->io.win[0].base;
664 p_dev->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
665 return pcmcia_request_io(p_dev, &p_dev->io);
666}
667
663static int smc_config(struct pcmcia_device *link) 668static int smc_config(struct pcmcia_device *link)
664{ 669{
665 struct net_device *dev = link->priv; 670 struct net_device *dev = link->priv;
666 struct smc_cfg_mem *cfg_mem;
667 tuple_t *tuple;
668 cisparse_t *parse;
669 cistpl_cftable_entry_t *cf;
670 u_char *buf;
671 int i; 671 int i;
672 672
673 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
674 if (!cfg_mem)
675 return CS_OUT_OF_RESOURCE;
676
677 tuple = &cfg_mem->tuple;
678 parse = &cfg_mem->parse;
679 cf = &parse->cftable_entry;
680 buf = cfg_mem->buf;
681
682 tuple->Attributes = tuple->TupleOffset = 0;
683 tuple->TupleData = (cisdata_t *)buf;
684 tuple->TupleDataMax = 255;
685 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
686
687 link->io.NumPorts1 = 16; 673 link->io.NumPorts1 = 16;
688 i = first_tuple(link, tuple, parse); 674 i = pcmcia_loop_config(link, smc_configcheck, NULL);
689 while (i != CS_NO_MORE_ITEMS) { 675 if (!i)
690 if (i == CS_SUCCESS) { 676 dev->base_addr = link->io.BasePort1;
691 link->conf.ConfigIndex = cf->index;
692 link->io.BasePort1 = cf->io.win[0].base;
693 link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
694 i = pcmcia_request_io(link, &link->io);
695 if (i == CS_SUCCESS) break;
696 }
697 i = next_tuple(link, tuple, parse);
698 }
699 if (i == CS_SUCCESS)
700 dev->base_addr = link->io.BasePort1;
701 677
702 kfree(cfg_mem);
703 return i; 678 return i;
704} 679}
705 680
@@ -715,7 +690,7 @@ static int smc_setup(struct pcmcia_device *link)
715 690
716 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL); 691 cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
717 if (!cfg_mem) 692 if (!cfg_mem)
718 return CS_OUT_OF_RESOURCE; 693 return -ENOMEM;
719 694
720 tuple = &cfg_mem->tuple; 695 tuple = &cfg_mem->tuple;
721 parse = &cfg_mem->parse; 696 parse = &cfg_mem->parse;
@@ -728,12 +703,12 @@ static int smc_setup(struct pcmcia_device *link)
728 /* Check for a LAN function extension tuple */ 703 /* Check for a LAN function extension tuple */
729 tuple->DesiredTuple = CISTPL_FUNCE; 704 tuple->DesiredTuple = CISTPL_FUNCE;
730 i = first_tuple(link, tuple, parse); 705 i = first_tuple(link, tuple, parse);
731 while (i == CS_SUCCESS) { 706 while (i == 0) {
732 if (parse->funce.type == CISTPL_FUNCE_LAN_NODE_ID) 707 if (parse->funce.type == CISTPL_FUNCE_LAN_NODE_ID)
733 break; 708 break;
734 i = next_tuple(link, tuple, parse); 709 i = next_tuple(link, tuple, parse);
735 } 710 }
736 if (i == CS_SUCCESS) { 711 if (i == 0) {
737 node_id = (cistpl_lan_node_id_t *)parse->funce.data; 712 node_id = (cistpl_lan_node_id_t *)parse->funce.data;
738 if (node_id->nb == 6) { 713 if (node_id->nb == 6) {
739 for (i = 0; i < 6; i++) 714 for (i = 0; i < 6; i++)
@@ -780,9 +755,10 @@ static int osi_config(struct pcmcia_device *link)
780 for (i = j = 0; j < 4; j++) { 755 for (i = j = 0; j < 4; j++) {
781 link->io.BasePort2 = com[j]; 756 link->io.BasePort2 = com[j];
782 i = pcmcia_request_io(link, &link->io); 757 i = pcmcia_request_io(link, &link->io);
783 if (i == CS_SUCCESS) break; 758 if (i == 0)
759 break;
784 } 760 }
785 if (i != CS_SUCCESS) { 761 if (i != 0) {
786 /* Fallback: turn off hard decode */ 762 /* Fallback: turn off hard decode */
787 link->conf.ConfigIndex = 0x03; 763 link->conf.ConfigIndex = 0x03;
788 link->io.NumPorts2 = 0; 764 link->io.NumPorts2 = 0;
@@ -815,13 +791,13 @@ static int osi_setup(struct pcmcia_device *link, u_short manfid, u_short cardid)
815 /* Read the station address from tuple 0x90, subtuple 0x04 */ 791 /* Read the station address from tuple 0x90, subtuple 0x04 */
816 tuple->DesiredTuple = 0x90; 792 tuple->DesiredTuple = 0x90;
817 i = pcmcia_get_first_tuple(link, tuple); 793 i = pcmcia_get_first_tuple(link, tuple);
818 while (i == CS_SUCCESS) { 794 while (i == 0) {
819 i = pcmcia_get_tuple_data(link, tuple); 795 i = pcmcia_get_tuple_data(link, tuple);
820 if ((i != CS_SUCCESS) || (buf[0] == 0x04)) 796 if ((i != 0) || (buf[0] == 0x04))
821 break; 797 break;
822 i = pcmcia_get_next_tuple(link, tuple); 798 i = pcmcia_get_next_tuple(link, tuple);
823 } 799 }
824 if (i != CS_SUCCESS) { 800 if (i != 0) {
825 rc = -1; 801 rc = -1;
826 goto free_cfg_mem; 802 goto free_cfg_mem;
827 } 803 }
@@ -959,8 +935,11 @@ static int check_sig(struct pcmcia_device *link)
959 935
960======================================================================*/ 936======================================================================*/
961 937
962#define CS_EXIT_TEST(ret, svc, label) \ 938#define CS_EXIT_TEST(ret, svc, label) \
963if (ret != CS_SUCCESS) { cs_error(link, svc, ret); goto label; } 939if (ret != 0) { \
940 cs_error(link, svc, ret); \
941 goto label; \
942}
964 943
965static int smc91c92_config(struct pcmcia_device *link) 944static int smc91c92_config(struct pcmcia_device *link)
966{ 945{
diff --git a/drivers/net/pcmcia/xirc2ps_cs.c b/drivers/net/pcmcia/xirc2ps_cs.c
index c33a3d523566..e1fd585e7131 100644
--- a/drivers/net/pcmcia/xirc2ps_cs.c
+++ b/drivers/net/pcmcia/xirc2ps_cs.c
@@ -377,7 +377,7 @@ first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
377 377
378 if ((err = pcmcia_get_first_tuple(handle, tuple)) == 0 && 378 if ((err = pcmcia_get_first_tuple(handle, tuple)) == 0 &&
379 (err = pcmcia_get_tuple_data(handle, tuple)) == 0) 379 (err = pcmcia_get_tuple_data(handle, tuple)) == 0)
380 err = pcmcia_parse_tuple(handle, tuple, parse); 380 err = pcmcia_parse_tuple(tuple, parse);
381 return err; 381 return err;
382} 382}
383 383
@@ -388,7 +388,7 @@ next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
388 388
389 if ((err = pcmcia_get_next_tuple(handle, tuple)) == 0 && 389 if ((err = pcmcia_get_next_tuple(handle, tuple)) == 0 &&
390 (err = pcmcia_get_tuple_data(handle, tuple)) == 0) 390 (err = pcmcia_get_tuple_data(handle, tuple)) == 0)
391 err = pcmcia_parse_tuple(handle, tuple, parse); 391 err = pcmcia_parse_tuple(tuple, parse);
392 return err; 392 return err;
393} 393}
394 394
@@ -715,6 +715,47 @@ has_ce2_string(struct pcmcia_device * p_dev)
715 return 0; 715 return 0;
716} 716}
717 717
718static int
719xirc2ps_config_modem(struct pcmcia_device *p_dev,
720 cistpl_cftable_entry_t *cf,
721 cistpl_cftable_entry_t *dflt,
722 unsigned int vcc,
723 void *priv_data)
724{
725 unsigned int ioaddr;
726
727 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8) {
728 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
729 p_dev->io.BasePort2 = cf->io.win[0].base;
730 p_dev->io.BasePort1 = ioaddr;
731 if (!pcmcia_request_io(p_dev, &p_dev->io))
732 return 0;
733 }
734 }
735 return -ENODEV;
736}
737
738static int
739xirc2ps_config_check(struct pcmcia_device *p_dev,
740 cistpl_cftable_entry_t *cf,
741 cistpl_cftable_entry_t *dflt,
742 unsigned int vcc,
743 void *priv_data)
744{
745 int *pass = priv_data;
746
747 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8) {
748 p_dev->io.BasePort2 = cf->io.win[0].base;
749 p_dev->io.BasePort1 = p_dev->io.BasePort2
750 + (*pass ? (cf->index & 0x20 ? -24:8)
751 : (cf->index & 0x20 ? 8:-24));
752 if (!pcmcia_request_io(p_dev, &p_dev->io))
753 return 0;
754 }
755 return -ENODEV;
756
757}
758
718/**************** 759/****************
719 * xirc2ps_config() is scheduled to run after a CARD_INSERTION event 760 * xirc2ps_config() is scheduled to run after a CARD_INSERTION event
720 * is received, to configure the PCMCIA socket, and to make the 761 * is received, to configure the PCMCIA socket, and to make the
@@ -725,13 +766,12 @@ xirc2ps_config(struct pcmcia_device * link)
725{ 766{
726 struct net_device *dev = link->priv; 767 struct net_device *dev = link->priv;
727 local_info_t *local = netdev_priv(dev); 768 local_info_t *local = netdev_priv(dev);
769 unsigned int ioaddr;
728 tuple_t tuple; 770 tuple_t tuple;
729 cisparse_t parse; 771 cisparse_t parse;
730 unsigned int ioaddr;
731 int err, i; 772 int err, i;
732 u_char buf[64]; 773 u_char buf[64];
733 cistpl_lan_node_id_t *node_id = (cistpl_lan_node_id_t*)parse.funce.data; 774 cistpl_lan_node_id_t *node_id = (cistpl_lan_node_id_t*)parse.funce.data;
734 cistpl_cftable_entry_t *cf = &parse.cftable_entry;
735 DECLARE_MAC_BUF(mac); 775 DECLARE_MAC_BUF(mac);
736 776
737 local->dingo_ccr = NULL; 777 local->dingo_ccr = NULL;
@@ -846,19 +886,8 @@ xirc2ps_config(struct pcmcia_device * link)
846 /* Take the Modem IO port from the CIS and scan for a free 886 /* Take the Modem IO port from the CIS and scan for a free
847 * Ethernet port */ 887 * Ethernet port */
848 link->io.NumPorts1 = 16; /* no Mako stuff anymore */ 888 link->io.NumPorts1 = 16; /* no Mako stuff anymore */
849 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 889 if (!pcmcia_loop_config(link, xirc2ps_config_modem, NULL))
850 for (err = first_tuple(link, &tuple, &parse); !err; 890 goto port_found;
851 err = next_tuple(link, &tuple, &parse)) {
852 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8) {
853 for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
854 link->conf.ConfigIndex = cf->index ;
855 link->io.BasePort2 = cf->io.win[0].base;
856 link->io.BasePort1 = ioaddr;
857 if (!(err=pcmcia_request_io(link, &link->io)))
858 goto port_found;
859 }
860 }
861 }
862 } else { 891 } else {
863 link->io.NumPorts1 = 18; 892 link->io.NumPorts1 = 18;
864 /* We do 2 passes here: The first one uses the regular mapping and 893 /* We do 2 passes here: The first one uses the regular mapping and
@@ -866,21 +895,9 @@ xirc2ps_config(struct pcmcia_device * link)
866 * mirrored every 32 bytes. Actually we use a mirrored port for 895 * mirrored every 32 bytes. Actually we use a mirrored port for
867 * the Mako if (on the first pass) the COR bit 5 is set. 896 * the Mako if (on the first pass) the COR bit 5 is set.
868 */ 897 */
869 for (pass=0; pass < 2; pass++) { 898 for (pass=0; pass < 2; pass++)
870 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 899 if (!pcmcia_loop_config(link, xirc2ps_config_check, &pass))
871 for (err = first_tuple(link, &tuple, &parse); !err;
872 err = next_tuple(link, &tuple, &parse)){
873 if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8){
874 link->conf.ConfigIndex = cf->index ;
875 link->io.BasePort2 = cf->io.win[0].base;
876 link->io.BasePort1 = link->io.BasePort2
877 + (pass ? (cf->index & 0x20 ? -24:8)
878 : (cf->index & 0x20 ? 8:-24));
879 if (!(err=pcmcia_request_io(link, &link->io)))
880 goto port_found; 900 goto port_found;
881 }
882 }
883 }
884 /* if special option: 901 /* if special option:
885 * try to configure as Ethernet only. 902 * try to configure as Ethernet only.
886 * .... */ 903 * .... */
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 6671e2da0d57..d0ed1ef284a8 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -55,6 +55,7 @@ EXPORT_SYMBOL(mdiobus_alloc);
55 55
56/** 56/**
57 * mdiobus_release - mii_bus device release callback 57 * mdiobus_release - mii_bus device release callback
58 * @d: the target struct device that contains the mii_bus
58 * 59 *
59 * Description: called when the last reference to an mii_bus is 60 * Description: called when the last reference to an mii_bus is
60 * dropped, to free the underlying memory. 61 * dropped, to free the underlying memory.
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 171627480058..e11b03b2b25a 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -309,11 +309,6 @@ void phy_disconnect(struct phy_device *phydev)
309} 309}
310EXPORT_SYMBOL(phy_disconnect); 310EXPORT_SYMBOL(phy_disconnect);
311 311
312static int phy_compare_id(struct device *dev, void *data)
313{
314 return strcmp((char *)data, dev->bus_id) ? 0 : 1;
315}
316
317/** 312/**
318 * phy_attach - attach a network device to a particular PHY device 313 * phy_attach - attach a network device to a particular PHY device
319 * @dev: network device to attach 314 * @dev: network device to attach
@@ -337,8 +332,7 @@ struct phy_device *phy_attach(struct net_device *dev,
337 332
338 /* Search the list of PHY devices on the mdio bus for the 333 /* Search the list of PHY devices on the mdio bus for the
339 * PHY with the requested name */ 334 * PHY with the requested name */
340 d = bus_find_device(bus, NULL, (void *)bus_id, phy_compare_id); 335 d = bus_find_device_by_name(bus, NULL, bus_id);
341
342 if (d) { 336 if (d) {
343 phydev = to_phy_device(d); 337 phydev = to_phy_device(d);
344 } else { 338 } else {
@@ -557,6 +551,7 @@ int genphy_restart_aneg(struct phy_device *phydev)
557 551
558 return ctl; 552 return ctl;
559} 553}
554EXPORT_SYMBOL(genphy_restart_aneg);
560 555
561 556
562/** 557/**
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index 0ca0fcbb7c01..7e857e938adb 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -866,8 +866,8 @@ static int __init ppp_init(void)
866 err = PTR_ERR(ppp_class); 866 err = PTR_ERR(ppp_class);
867 goto out_chrdev; 867 goto out_chrdev;
868 } 868 }
869 device_create_drvdata(ppp_class, NULL, MKDEV(PPP_MAJOR, 0), 869 device_create(ppp_class, NULL, MKDEV(PPP_MAJOR, 0), NULL,
870 NULL, "ppp"); 870 "ppp");
871 } 871 }
872 872
873out: 873out:
@@ -2127,13 +2127,9 @@ ppp_set_compress(struct ppp *ppp, unsigned long arg)
2127 || ccp_option[1] < 2 || ccp_option[1] > data.length) 2127 || ccp_option[1] < 2 || ccp_option[1] > data.length)
2128 goto out; 2128 goto out;
2129 2129
2130 cp = find_compressor(ccp_option[0]); 2130 cp = try_then_request_module(
2131#ifdef CONFIG_KMOD 2131 find_compressor(ccp_option[0]),
2132 if (!cp) { 2132 "ppp-compress-%d", ccp_option[0]);
2133 request_module("ppp-compress-%d", ccp_option[0]);
2134 cp = find_compressor(ccp_option[0]);
2135 }
2136#endif /* CONFIG_KMOD */
2137 if (!cp) 2133 if (!cp)
2138 goto out; 2134 goto out;
2139 2135
diff --git a/drivers/net/pppox.c b/drivers/net/pppox.c
index c6898c1fc54d..03aecc97fb45 100644
--- a/drivers/net/pppox.c
+++ b/drivers/net/pppox.c
@@ -115,13 +115,8 @@ static int pppox_create(struct net *net, struct socket *sock, int protocol)
115 goto out; 115 goto out;
116 116
117 rc = -EPROTONOSUPPORT; 117 rc = -EPROTONOSUPPORT;
118#ifdef CONFIG_KMOD 118 if (!pppox_protos[protocol])
119 if (!pppox_protos[protocol]) { 119 request_module("pppox-proto-%d", protocol);
120 char buffer[32];
121 sprintf(buffer, "pppox-proto-%d", protocol);
122 request_module(buffer);
123 }
124#endif
125 if (!pppox_protos[protocol] || 120 if (!pppox_protos[protocol] ||
126 !try_module_get(pppox_protos[protocol]->owner)) 121 !try_module_get(pppox_protos[protocol]->owner))
127 goto out; 122 goto out;
diff --git a/drivers/net/qlge/qlge.h b/drivers/net/qlge/qlge.h
index c37ea436c918..38116f9d4163 100644
--- a/drivers/net/qlge/qlge.h
+++ b/drivers/net/qlge/qlge.h
@@ -58,7 +58,7 @@
58 */ 58 */
59#if (PAGE_SHIFT == 12) || (PAGE_SHIFT == 13) /* 4k & 8k pages */ 59#if (PAGE_SHIFT == 12) || (PAGE_SHIFT == 13) /* 4k & 8k pages */
60#define TX_DESC_PER_OAL ((MAX_SKB_FRAGS - TX_DESC_PER_IOCB) + 2) 60#define TX_DESC_PER_OAL ((MAX_SKB_FRAGS - TX_DESC_PER_IOCB) + 2)
61#elif (PAGE_SHIFT == 16) /* 64k pages */ 61#else /* all other page sizes */
62#define TX_DESC_PER_OAL 0 62#define TX_DESC_PER_OAL 0
63#endif 63#endif
64 64
diff --git a/drivers/net/qlge/qlge_ethtool.c b/drivers/net/qlge/qlge_ethtool.c
index 6457f8c4fdaa..b62fbd4bf00f 100644
--- a/drivers/net/qlge/qlge_ethtool.c
+++ b/drivers/net/qlge/qlge_ethtool.c
@@ -29,7 +29,6 @@
29#include <linux/skbuff.h> 29#include <linux/skbuff.h>
30#include <linux/rtnetlink.h> 30#include <linux/rtnetlink.h>
31#include <linux/if_vlan.h> 31#include <linux/if_vlan.h>
32#include <linux/init.h>
33#include <linux/delay.h> 32#include <linux/delay.h>
34#include <linux/mm.h> 33#include <linux/mm.h>
35#include <linux/vmalloc.h> 34#include <linux/vmalloc.h>
diff --git a/drivers/net/qlge/qlge_main.c b/drivers/net/qlge/qlge_main.c
index 3af822b6226e..4b2caa6b7ac5 100644
--- a/drivers/net/qlge/qlge_main.c
+++ b/drivers/net/qlge/qlge_main.c
@@ -36,10 +36,10 @@
36#include <linux/skbuff.h> 36#include <linux/skbuff.h>
37#include <linux/rtnetlink.h> 37#include <linux/rtnetlink.h>
38#include <linux/if_vlan.h> 38#include <linux/if_vlan.h>
39#include <linux/init.h>
40#include <linux/delay.h> 39#include <linux/delay.h>
41#include <linux/mm.h> 40#include <linux/mm.h>
42#include <linux/vmalloc.h> 41#include <linux/vmalloc.h>
42#include <net/ip6_checksum.h>
43 43
44#include "qlge.h" 44#include "qlge.h"
45 45
diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index bdae2c59a750..c821da21d8eb 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -2154,6 +2154,8 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2154 2154
2155 spin_lock_init(&tp->lock); 2155 spin_lock_init(&tp->lock);
2156 2156
2157 tp->mmio_addr = ioaddr;
2158
2157 rtl_init_mac_address(tp, ioaddr); 2159 rtl_init_mac_address(tp, ioaddr);
2158 2160
2159 /* Get MAC address */ 2161 /* Get MAC address */
@@ -2186,7 +2188,6 @@ rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
2186#endif 2188#endif
2187 2189
2188 tp->intr_mask = 0xffff; 2190 tp->intr_mask = 0xffff;
2189 tp->mmio_addr = ioaddr;
2190 tp->align = cfg->align; 2191 tp->align = cfg->align;
2191 tp->hw_start = cfg->hw_start; 2192 tp->hw_start = cfg->hw_start;
2192 tp->intr_event = cfg->intr_event; 2193 tp->intr_event = cfg->intr_event;
diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index 3805b9318be7..3813d15e2df7 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -3034,7 +3034,8 @@ static int sky2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
3034 struct sky2_port *sky2 = netdev_priv(dev); 3034 struct sky2_port *sky2 = netdev_priv(dev);
3035 struct sky2_hw *hw = sky2->hw; 3035 struct sky2_hw *hw = sky2->hw;
3036 3036
3037 if (wol->wolopts & ~sky2_wol_supported(sky2->hw)) 3037 if ((wol->wolopts & ~sky2_wol_supported(sky2->hw))
3038 || !device_can_wakeup(&hw->pdev->dev))
3038 return -EOPNOTSUPP; 3039 return -EOPNOTSUPP;
3039 3040
3040 sky2->wol = wol->wolopts; 3041 sky2->wol = wol->wolopts;
@@ -3045,6 +3046,8 @@ static int sky2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
3045 sky2_write32(hw, B0_CTST, sky2->wol 3046 sky2_write32(hw, B0_CTST, sky2->wol
3046 ? Y2_HW_WOL_ON : Y2_HW_WOL_OFF); 3047 ? Y2_HW_WOL_ON : Y2_HW_WOL_OFF);
3047 3048
3049 device_set_wakeup_enable(&hw->pdev->dev, sky2->wol);
3050
3048 if (!netif_running(dev)) 3051 if (!netif_running(dev))
3049 sky2_wol_init(sky2); 3052 sky2_wol_init(sky2);
3050 return 0; 3053 return 0;
@@ -4179,18 +4182,6 @@ static int __devinit sky2_test_msi(struct sky2_hw *hw)
4179 return err; 4182 return err;
4180} 4183}
4181 4184
4182static int __devinit pci_wake_enabled(struct pci_dev *dev)
4183{
4184 int pm = pci_find_capability(dev, PCI_CAP_ID_PM);
4185 u16 value;
4186
4187 if (!pm)
4188 return 0;
4189 if (pci_read_config_word(dev, pm + PCI_PM_CTRL, &value))
4190 return 0;
4191 return value & PCI_PM_CTRL_PME_ENABLE;
4192}
4193
4194/* 4185/*
4195 * Read and parse the first part of Vital Product Data 4186 * Read and parse the first part of Vital Product Data
4196 */ 4187 */
@@ -4314,7 +4305,7 @@ static int __devinit sky2_probe(struct pci_dev *pdev,
4314 } 4305 }
4315 } 4306 }
4316 4307
4317 wol_default = pci_wake_enabled(pdev) ? WAKE_MAGIC : 0; 4308 wol_default = device_may_wakeup(&pdev->dev) ? WAKE_MAGIC : 0;
4318 4309
4319 err = -ENOMEM; 4310 err = -ENOMEM;
4320 hw = kzalloc(sizeof(*hw), GFP_KERNEL); 4311 hw = kzalloc(sizeof(*hw), GFP_KERNEL);
diff --git a/drivers/net/smc911x.c b/drivers/net/smc911x.c
index 3d19d00e8eec..8aa7460ef0e3 100644
--- a/drivers/net/smc911x.c
+++ b/drivers/net/smc911x.c
@@ -685,8 +685,10 @@ static void smc911x_phy_detect(struct net_device *dev)
685 * PHY#1 to PHY#31, and then PHY#0 last. 685 * PHY#1 to PHY#31, and then PHY#0 last.
686 */ 686 */
687 switch(lp->version) { 687 switch(lp->version) {
688 case 0x115: 688 case CHIP_9115:
689 case 0x117: 689 case CHIP_9117:
690 case CHIP_9215:
691 case CHIP_9217:
690 cfg = SMC_GET_HW_CFG(lp); 692 cfg = SMC_GET_HW_CFG(lp);
691 if (cfg & HW_CFG_EXT_PHY_DET_) { 693 if (cfg & HW_CFG_EXT_PHY_DET_) {
692 cfg &= ~HW_CFG_PHY_CLK_SEL_; 694 cfg &= ~HW_CFG_PHY_CLK_SEL_;
diff --git a/drivers/net/smc911x.h b/drivers/net/smc911x.h
index 2abfc2845198..bf6240f23f5d 100644
--- a/drivers/net/smc911x.h
+++ b/drivers/net/smc911x.h
@@ -666,10 +666,13 @@ smc_pxa_dma_outsl(struct smc911x_local *lp, u_long physaddr,
666#define LAN911X_INTERNAL_PHY_ID (0x0007C000) 666#define LAN911X_INTERNAL_PHY_ID (0x0007C000)
667 667
668/* Chip ID values */ 668/* Chip ID values */
669#define CHIP_9115 0x115 669#define CHIP_9115 0x0115
670#define CHIP_9116 0x116 670#define CHIP_9116 0x0116
671#define CHIP_9117 0x117 671#define CHIP_9117 0x0117
672#define CHIP_9118 0x118 672#define CHIP_9118 0x0118
673#define CHIP_9215 0x115A
674#define CHIP_9217 0x117A
675#define CHIP_9218 0x118A
673 676
674struct chip_id { 677struct chip_id {
675 u16 id; 678 u16 id;
@@ -681,6 +684,9 @@ static const struct chip_id chip_ids[] = {
681 { CHIP_9116, "LAN9116" }, 684 { CHIP_9116, "LAN9116" },
682 { CHIP_9117, "LAN9117" }, 685 { CHIP_9117, "LAN9117" },
683 { CHIP_9118, "LAN9118" }, 686 { CHIP_9118, "LAN9118" },
687 { CHIP_9215, "LAN9215" },
688 { CHIP_9217, "LAN9217" },
689 { CHIP_9218, "LAN9218" },
684 { 0, NULL }, 690 { 0, NULL },
685}; 691};
686 692
diff --git a/drivers/net/tc35815.c b/drivers/net/tc35815.c
index 4980b12b6219..df20cafff7dd 100644
--- a/drivers/net/tc35815.c
+++ b/drivers/net/tc35815.c
@@ -796,7 +796,7 @@ err_out_unregister_bus:
796 mdiobus_unregister(lp->mii_bus); 796 mdiobus_unregister(lp->mii_bus);
797err_out_free_mdio_irq: 797err_out_free_mdio_irq:
798 kfree(lp->mii_bus->irq); 798 kfree(lp->mii_bus->irq);
799err_out_free_mii_bus; 799err_out_free_mii_bus:
800 mdiobus_free(lp->mii_bus); 800 mdiobus_free(lp->mii_bus);
801err_out: 801err_out:
802 return err; 802 return err;
diff --git a/drivers/net/tlan.c b/drivers/net/tlan.c
index ec871f646766..c41d68761364 100644
--- a/drivers/net/tlan.c
+++ b/drivers/net/tlan.c
@@ -29,7 +29,8 @@
29 * 29 *
30 * Tigran Aivazian <tigran@sco.com>: TLan_PciProbe() now uses 30 * Tigran Aivazian <tigran@sco.com>: TLan_PciProbe() now uses
31 * new PCI BIOS interface. 31 * new PCI BIOS interface.
32 * Alan Cox <alan@redhat.com>: Fixed the out of memory 32 * Alan Cox <alan@lxorguk.ukuu.org.uk>:
33 * Fixed the out of memory
33 * handling. 34 * handling.
34 * 35 *
35 * Torben Mathiasen <torben.mathiasen@compaq.com> New Maintainer! 36 * Torben Mathiasen <torben.mathiasen@compaq.com> New Maintainer!
diff --git a/drivers/net/tokenring/smctr.c b/drivers/net/tokenring/smctr.c
index fa73e6eed6be..ed50d288e494 100644
--- a/drivers/net/tokenring/smctr.c
+++ b/drivers/net/tokenring/smctr.c
@@ -25,7 +25,7 @@
25 * To do: 25 * To do:
26 * 1. Multicast support. 26 * 1. Multicast support.
27 * 27 *
28 * Initial 2.5 cleanup Alan Cox <alan@redhat.com> 2002/10/28 28 * Initial 2.5 cleanup Alan Cox <alan@lxorguk.ukuu.org.uk> 2002/10/28
29 */ 29 */
30 30
31#include <linux/module.h> 31#include <linux/module.h>
diff --git a/drivers/net/tulip/de2104x.c b/drivers/net/tulip/de2104x.c
index f54c45049d50..124d5d690dde 100644
--- a/drivers/net/tulip/de2104x.c
+++ b/drivers/net/tulip/de2104x.c
@@ -1688,6 +1688,7 @@ static void __devinit de21040_get_mac_address (struct de_private *de)
1688 unsigned i; 1688 unsigned i;
1689 1689
1690 dw32 (ROMCmd, 0); /* Reset the pointer with a dummy write. */ 1690 dw32 (ROMCmd, 0); /* Reset the pointer with a dummy write. */
1691 udelay(5);
1691 1692
1692 for (i = 0; i < 6; i++) { 1693 for (i = 0; i < 6; i++) {
1693 int value, boguscnt = 100000; 1694 int value, boguscnt = 100000;
diff --git a/drivers/net/tulip/dmfe.c b/drivers/net/tulip/dmfe.c
index 656200472fa1..8e46a513a252 100644
--- a/drivers/net/tulip/dmfe.c
+++ b/drivers/net/tulip/dmfe.c
@@ -23,7 +23,7 @@
23 Marcelo Tosatti <marcelo@conectiva.com.br> : 23 Marcelo Tosatti <marcelo@conectiva.com.br> :
24 Made it compile in 2.3 (device to net_device) 24 Made it compile in 2.3 (device to net_device)
25 25
26 Alan Cox <alan@redhat.com> : 26 Alan Cox <alan@lxorguk.ukuu.org.uk> :
27 Cleaned up for kernel merge. 27 Cleaned up for kernel merge.
28 Removed the back compatibility support 28 Removed the back compatibility support
29 Reformatted, fixing spelling etc as I went 29 Reformatted, fixing spelling etc as I went
@@ -49,7 +49,7 @@
49 support. Updated PCI resource allocation. Do not 49 support. Updated PCI resource allocation. Do not
50 forget to unmap PCI mapped skbs. 50 forget to unmap PCI mapped skbs.
51 51
52 Alan Cox <alan@redhat.com> 52 Alan Cox <alan@lxorguk.ukuu.org.uk>
53 Added new PCI identifiers provided by Clear Zhang at ALi 53 Added new PCI identifiers provided by Clear Zhang at ALi
54 for their 1563 ethernet device. 54 for their 1563 ethernet device.
55 55
diff --git a/drivers/net/via-velocity.c b/drivers/net/via-velocity.c
index ad20f96edfa1..2dced383bcfb 100644
--- a/drivers/net/via-velocity.c
+++ b/drivers/net/via-velocity.c
@@ -12,7 +12,7 @@
12 * Scatter gather 12 * Scatter gather
13 * More testing 13 * More testing
14 * 14 *
15 * The changes are (c) Copyright 2004, Red Hat Inc. <alan@redhat.com> 15 * The changes are (c) Copyright 2004, Red Hat Inc. <alan@lxorguk.ukuu.org.uk>
16 * Additional fixes and clean up: Francois Romieu 16 * Additional fixes and clean up: Francois Romieu
17 * 17 *
18 * This source has not been verified for use in safety critical systems. 18 * This source has not been verified for use in safety critical systems.
diff --git a/drivers/net/wan/Kconfig b/drivers/net/wan/Kconfig
index 2ae2ec40015d..21efd99b9294 100644
--- a/drivers/net/wan/Kconfig
+++ b/drivers/net/wan/Kconfig
@@ -205,7 +205,7 @@ config WANXL_BUILD_FIRMWARE
205 205
206config PC300 206config PC300
207 tristate "Cyclades-PC300 support (RS-232/V.35, X.21, T1/E1 boards)" 207 tristate "Cyclades-PC300 support (RS-232/V.35, X.21, T1/E1 boards)"
208 depends on HDLC && PCI 208 depends on HDLC && PCI && BROKEN
209 ---help--- 209 ---help---
210 Driver for the Cyclades-PC300 synchronous communication boards. 210 Driver for the Cyclades-PC300 synchronous communication boards.
211 211
diff --git a/drivers/net/wan/cosa.c b/drivers/net/wan/cosa.c
index f14051556c87..7f97f8d08c39 100644
--- a/drivers/net/wan/cosa.c
+++ b/drivers/net/wan/cosa.c
@@ -388,8 +388,8 @@ static int __init cosa_init(void)
388 goto out_chrdev; 388 goto out_chrdev;
389 } 389 }
390 for (i = 0; i < nr_cards; i++) 390 for (i = 0; i < nr_cards; i++)
391 device_create_drvdata(cosa_class, NULL, MKDEV(cosa_major, i), 391 device_create(cosa_class, NULL, MKDEV(cosa_major, i), NULL,
392 NULL, "cosa%d", i); 392 "cosa%d", i);
393 err = 0; 393 err = 0;
394 goto out; 394 goto out;
395 395
diff --git a/drivers/net/wan/lmc/lmc_main.c b/drivers/net/wan/lmc/lmc_main.c
index f80640f5a744..d7bb63e616b5 100644
--- a/drivers/net/wan/lmc/lmc_main.c
+++ b/drivers/net/wan/lmc/lmc_main.c
@@ -122,7 +122,6 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
122 * Most functions mess with the structure 122 * Most functions mess with the structure
123 * Disable interrupts while we do the polling 123 * Disable interrupts while we do the polling
124 */ 124 */
125 spin_lock_irqsave(&sc->lmc_lock, flags);
126 125
127 switch (cmd) { 126 switch (cmd) {
128 /* 127 /*
@@ -152,6 +151,7 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
152 break; 151 break;
153 } 152 }
154 153
154 spin_lock_irqsave(&sc->lmc_lock, flags);
155 sc->lmc_media->set_status (sc, &ctl); 155 sc->lmc_media->set_status (sc, &ctl);
156 156
157 if(ctl.crc_length != sc->ictl.crc_length) { 157 if(ctl.crc_length != sc->ictl.crc_length) {
@@ -161,6 +161,7 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
161 else 161 else
162 sc->TxDescriptControlInit &= ~LMC_TDES_ADD_CRC_DISABLE; 162 sc->TxDescriptControlInit &= ~LMC_TDES_ADD_CRC_DISABLE;
163 } 163 }
164 spin_unlock_irqrestore(&sc->lmc_lock, flags);
164 165
165 ret = 0; 166 ret = 0;
166 break; 167 break;
@@ -187,15 +188,18 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
187 break; /* no change */ 188 break; /* no change */
188 } 189 }
189 190
191 spin_lock_irqsave(&sc->lmc_lock, flags);
190 lmc_proto_close(sc); 192 lmc_proto_close(sc);
191 193
192 sc->if_type = new_type; 194 sc->if_type = new_type;
193 lmc_proto_attach(sc); 195 lmc_proto_attach(sc);
194 ret = lmc_proto_open(sc); 196 ret = lmc_proto_open(sc);
197 spin_unlock_irqrestore(&sc->lmc_lock, flags);
195 break; 198 break;
196 } 199 }
197 200
198 case LMCIOCGETXINFO: /*fold01*/ 201 case LMCIOCGETXINFO: /*fold01*/
202 spin_lock_irqsave(&sc->lmc_lock, flags);
199 sc->lmc_xinfo.Magic0 = 0xBEEFCAFE; 203 sc->lmc_xinfo.Magic0 = 0xBEEFCAFE;
200 204
201 sc->lmc_xinfo.PciCardType = sc->lmc_cardtype; 205 sc->lmc_xinfo.PciCardType = sc->lmc_cardtype;
@@ -208,6 +212,7 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
208 sc->lmc_xinfo.MaxFrameSize = LMC_PKT_BUF_SZ; 212 sc->lmc_xinfo.MaxFrameSize = LMC_PKT_BUF_SZ;
209 sc->lmc_xinfo.link_status = sc->lmc_media->get_link_status (sc); 213 sc->lmc_xinfo.link_status = sc->lmc_media->get_link_status (sc);
210 sc->lmc_xinfo.mii_reg16 = lmc_mii_readreg (sc, 0, 16); 214 sc->lmc_xinfo.mii_reg16 = lmc_mii_readreg (sc, 0, 16);
215 spin_unlock_irqrestore(&sc->lmc_lock, flags);
211 216
212 sc->lmc_xinfo.Magic1 = 0xDEADBEEF; 217 sc->lmc_xinfo.Magic1 = 0xDEADBEEF;
213 218
@@ -220,6 +225,7 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
220 break; 225 break;
221 226
222 case LMCIOCGETLMCSTATS: 227 case LMCIOCGETLMCSTATS:
228 spin_lock_irqsave(&sc->lmc_lock, flags);
223 if (sc->lmc_cardtype == LMC_CARDTYPE_T1) { 229 if (sc->lmc_cardtype == LMC_CARDTYPE_T1) {
224 lmc_mii_writereg(sc, 0, 17, T1FRAMER_FERR_LSB); 230 lmc_mii_writereg(sc, 0, 17, T1FRAMER_FERR_LSB);
225 sc->extra_stats.framingBitErrorCount += 231 sc->extra_stats.framingBitErrorCount +=
@@ -243,6 +249,7 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
243 sc->extra_stats.severelyErroredFrameCount += 249 sc->extra_stats.severelyErroredFrameCount +=
244 regVal & T1FRAMER_SEF_MASK; 250 regVal & T1FRAMER_SEF_MASK;
245 } 251 }
252 spin_unlock_irqrestore(&sc->lmc_lock, flags);
246 if (copy_to_user(ifr->ifr_data, &sc->lmc_device->stats, 253 if (copy_to_user(ifr->ifr_data, &sc->lmc_device->stats,
247 sizeof(sc->lmc_device->stats)) || 254 sizeof(sc->lmc_device->stats)) ||
248 copy_to_user(ifr->ifr_data + sizeof(sc->lmc_device->stats), 255 copy_to_user(ifr->ifr_data + sizeof(sc->lmc_device->stats),
@@ -258,12 +265,14 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
258 break; 265 break;
259 } 266 }
260 267
268 spin_lock_irqsave(&sc->lmc_lock, flags);
261 memset(&sc->lmc_device->stats, 0, sizeof(sc->lmc_device->stats)); 269 memset(&sc->lmc_device->stats, 0, sizeof(sc->lmc_device->stats));
262 memset(&sc->extra_stats, 0, sizeof(sc->extra_stats)); 270 memset(&sc->extra_stats, 0, sizeof(sc->extra_stats));
263 sc->extra_stats.check = STATCHECK; 271 sc->extra_stats.check = STATCHECK;
264 sc->extra_stats.version_size = (DRIVER_VERSION << 16) + 272 sc->extra_stats.version_size = (DRIVER_VERSION << 16) +
265 sizeof(sc->lmc_device->stats) + sizeof(sc->extra_stats); 273 sizeof(sc->lmc_device->stats) + sizeof(sc->extra_stats);
266 sc->extra_stats.lmc_cardtype = sc->lmc_cardtype; 274 sc->extra_stats.lmc_cardtype = sc->lmc_cardtype;
275 spin_unlock_irqrestore(&sc->lmc_lock, flags);
267 ret = 0; 276 ret = 0;
268 break; 277 break;
269 278
@@ -282,8 +291,10 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
282 ret = -EFAULT; 291 ret = -EFAULT;
283 break; 292 break;
284 } 293 }
294 spin_lock_irqsave(&sc->lmc_lock, flags);
285 sc->lmc_media->set_circuit_type(sc, ctl.circuit_type); 295 sc->lmc_media->set_circuit_type(sc, ctl.circuit_type);
286 sc->ictl.circuit_type = ctl.circuit_type; 296 sc->ictl.circuit_type = ctl.circuit_type;
297 spin_unlock_irqrestore(&sc->lmc_lock, flags);
287 ret = 0; 298 ret = 0;
288 299
289 break; 300 break;
@@ -294,12 +305,14 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
294 break; 305 break;
295 } 306 }
296 307
308 spin_lock_irqsave(&sc->lmc_lock, flags);
297 /* Reset driver and bring back to current state */ 309 /* Reset driver and bring back to current state */
298 printk (" REG16 before reset +%04x\n", lmc_mii_readreg (sc, 0, 16)); 310 printk (" REG16 before reset +%04x\n", lmc_mii_readreg (sc, 0, 16));
299 lmc_running_reset (dev); 311 lmc_running_reset (dev);
300 printk (" REG16 after reset +%04x\n", lmc_mii_readreg (sc, 0, 16)); 312 printk (" REG16 after reset +%04x\n", lmc_mii_readreg (sc, 0, 16));
301 313
302 LMC_EVENT_LOG(LMC_EVENT_FORCEDRESET, LMC_CSR_READ (sc, csr_status), lmc_mii_readreg (sc, 0, 16)); 314 LMC_EVENT_LOG(LMC_EVENT_FORCEDRESET, LMC_CSR_READ (sc, csr_status), lmc_mii_readreg (sc, 0, 16));
315 spin_unlock_irqrestore(&sc->lmc_lock, flags);
303 316
304 ret = 0; 317 ret = 0;
305 break; 318 break;
@@ -338,14 +351,15 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
338 */ 351 */
339 netif_stop_queue(dev); 352 netif_stop_queue(dev);
340 353
341 if (copy_from_user(&xc, ifr->ifr_data, sizeof(struct lmc_xilinx_control))) { 354 if (copy_from_user(&xc, ifr->ifr_data, sizeof(struct lmc_xilinx_control))) {
342 ret = -EFAULT; 355 ret = -EFAULT;
343 break; 356 break;
344 } 357 }
345 switch(xc.command){ 358 switch(xc.command){
346 case lmc_xilinx_reset: /*fold02*/ 359 case lmc_xilinx_reset: /*fold02*/
347 { 360 {
348 u16 mii; 361 u16 mii;
362 spin_lock_irqsave(&sc->lmc_lock, flags);
349 mii = lmc_mii_readreg (sc, 0, 16); 363 mii = lmc_mii_readreg (sc, 0, 16);
350 364
351 /* 365 /*
@@ -404,6 +418,7 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
404 lmc_led_off(sc, LMC_DS3_LED2); 418 lmc_led_off(sc, LMC_DS3_LED2);
405 } 419 }
406 } 420 }
421 spin_unlock_irqrestore(&sc->lmc_lock, flags);
407 422
408 423
409 424
@@ -416,6 +431,7 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
416 { 431 {
417 u16 mii; 432 u16 mii;
418 int timeout = 500000; 433 int timeout = 500000;
434 spin_lock_irqsave(&sc->lmc_lock, flags);
419 mii = lmc_mii_readreg (sc, 0, 16); 435 mii = lmc_mii_readreg (sc, 0, 16);
420 436
421 /* 437 /*
@@ -451,13 +467,14 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
451 */ 467 */
452 while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 && 468 while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 &&
453 (timeout-- > 0)) 469 (timeout-- > 0))
454 ; 470 cpu_relax();
455 471
456 472
457 /* 473 /*
458 * stop driving Xilinx-related signals 474 * stop driving Xilinx-related signals
459 */ 475 */
460 lmc_gpio_mkinput(sc, 0xff); 476 lmc_gpio_mkinput(sc, 0xff);
477 spin_unlock_irqrestore(&sc->lmc_lock, flags);
461 478
462 ret = 0x0; 479 ret = 0x0;
463 480
@@ -493,6 +510,7 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
493 510
494 printk("%s: Starting load of data Len: %d at 0x%p == 0x%p\n", dev->name, xc.len, xc.data, data); 511 printk("%s: Starting load of data Len: %d at 0x%p == 0x%p\n", dev->name, xc.len, xc.data, data);
495 512
513 spin_lock_irqsave(&sc->lmc_lock, flags);
496 lmc_gpio_mkinput(sc, 0xff); 514 lmc_gpio_mkinput(sc, 0xff);
497 515
498 /* 516 /*
@@ -545,7 +563,7 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
545 */ 563 */
546 while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 && 564 while( (LMC_CSR_READ(sc, csr_gp) & LMC_GEP_INIT) == 0 &&
547 (timeout-- > 0)) 565 (timeout-- > 0))
548 ; 566 cpu_relax();
549 567
550 printk(KERN_DEBUG "%s: Waited %d for the Xilinx to clear it's memory\n", dev->name, 500000-timeout); 568 printk(KERN_DEBUG "%s: Waited %d for the Xilinx to clear it's memory\n", dev->name, 500000-timeout);
551 569
@@ -588,6 +606,7 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
588 606
589 sc->lmc_miireg16 &= ~LMC_MII16_FIFO_RESET; 607 sc->lmc_miireg16 &= ~LMC_MII16_FIFO_RESET;
590 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16); 608 lmc_mii_writereg(sc, 0, 16, sc->lmc_miireg16);
609 spin_unlock_irqrestore(&sc->lmc_lock, flags);
591 610
592 kfree(data); 611 kfree(data);
593 612
@@ -611,8 +630,6 @@ int lmc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) /*fold00*/
611 break; 630 break;
612 } 631 }
613 632
614 spin_unlock_irqrestore(&sc->lmc_lock, flags); /*fold01*/
615
616 lmc_trace(dev, "lmc_ioctl out"); 633 lmc_trace(dev, "lmc_ioctl out");
617 634
618 return ret; 635 return ret;
diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
index 243bd8d918fe..ccd9cd35ecbe 100644
--- a/drivers/net/wan/z85230.c
+++ b/drivers/net/wan/z85230.c
@@ -18,7 +18,8 @@
18 * DMA now uses get_free_page as kmalloc buffers may span a 64K 18 * DMA now uses get_free_page as kmalloc buffers may span a 64K
19 * boundary. 19 * boundary.
20 * 20 *
21 * Modified for SMP safety and SMP locking by Alan Cox <alan@redhat.com> 21 * Modified for SMP safety and SMP locking by Alan Cox
22 * <alan@lxorguk.ukuu.org.uk>
22 * 23 *
23 * Performance 24 * Performance
24 * 25 *
diff --git a/drivers/net/wan/z85230.h b/drivers/net/wan/z85230.h
index 4f372396c512..85b3e785d484 100644
--- a/drivers/net/wan/z85230.h
+++ b/drivers/net/wan/z85230.h
@@ -2,7 +2,7 @@
2 * Description of Z8530 Z85C30 and Z85230 communications chips 2 * Description of Z8530 Z85C30 and Z85230 communications chips
3 * 3 *
4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) 4 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
5 * Copyright (C) 1998 Alan Cox <alan@redhat.com> 5 * Copyright (C) 1998 Alan Cox <alan@lxorguk.ukuu.org.uk>
6 */ 6 */
7 7
8#ifndef _Z8530_H 8#ifndef _Z8530_H
diff --git a/drivers/net/wireless/airo_cs.c b/drivers/net/wireless/airo_cs.c
index fd72e427cb28..27696c20f4c2 100644
--- a/drivers/net/wireless/airo_cs.c
+++ b/drivers/net/wireless/airo_cs.c
@@ -206,126 +206,123 @@ static void airo_detach(struct pcmcia_device *link)
206#define CS_CHECK(fn, ret) \ 206#define CS_CHECK(fn, ret) \
207do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 207do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
208 208
209static int airo_cs_config_check(struct pcmcia_device *p_dev,
210 cistpl_cftable_entry_t *cfg,
211 cistpl_cftable_entry_t *dflt,
212 unsigned int vcc,
213 void *priv_data)
214{
215 win_req_t *req = priv_data;
216
217 if (cfg->index == 0)
218 return -ENODEV;
219
220 /* Does this card need audio output? */
221 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
222 p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
223 p_dev->conf.Status = CCSR_AUDIO_ENA;
224 }
225
226 /* Use power settings for Vcc and Vpp if present */
227 /* Note that the CIS values need to be rescaled */
228 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
229 p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
230 else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
231 p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
232
233 /* Do we need to allocate an interrupt? */
234 if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
235 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
236
237 /* IO window settings */
238 p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
239 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
240 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
241 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
242 if (!(io->flags & CISTPL_IO_8BIT))
243 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
244 if (!(io->flags & CISTPL_IO_16BIT))
245 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
246 p_dev->io.BasePort1 = io->win[0].base;
247 p_dev->io.NumPorts1 = io->win[0].len;
248 if (io->nwin > 1) {
249 p_dev->io.Attributes2 = p_dev->io.Attributes1;
250 p_dev->io.BasePort2 = io->win[1].base;
251 p_dev->io.NumPorts2 = io->win[1].len;
252 }
253 }
254
255 /* This reserves IO space but doesn't actually enable it */
256 if (pcmcia_request_io(p_dev, &p_dev->io) != 0)
257 return -ENODEV;
258
259 /*
260 Now set up a common memory window, if needed. There is room
261 in the struct pcmcia_device structure for one memory window handle,
262 but if the base addresses need to be saved, or if multiple
263 windows are needed, the info should go in the private data
264 structure for this device.
265
266 Note that the memory window base is a physical address, and
267 needs to be mapped to virtual space with ioremap() before it
268 is used.
269 */
270 if ((cfg->mem.nwin > 0) || (dflt->mem.nwin > 0)) {
271 cistpl_mem_t *mem = (cfg->mem.nwin) ? &cfg->mem : &dflt->mem;
272 memreq_t map;
273 req->Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
274 req->Base = mem->win[0].host_addr;
275 req->Size = mem->win[0].len;
276 req->AccessSpeed = 0;
277 if (pcmcia_request_window(&p_dev, req, &p_dev->win) != 0)
278 return -ENODEV;
279 map.Page = 0;
280 map.CardOffset = mem->win[0].card_addr;
281 if (pcmcia_map_mem_page(p_dev->win, &map) != 0)
282 return -ENODEV;
283 }
284 /* If we got this far, we're cool! */
285 return 0;
286}
287
288
209static int airo_config(struct pcmcia_device *link) 289static int airo_config(struct pcmcia_device *link)
210{ 290{
211 tuple_t tuple;
212 cisparse_t parse;
213 local_info_t *dev; 291 local_info_t *dev;
292 win_req_t *req;
214 int last_fn, last_ret; 293 int last_fn, last_ret;
215 u_char buf[64];
216 win_req_t req;
217 memreq_t map;
218 294
219 dev = link->priv; 295 dev = link->priv;
220 296
221 DEBUG(0, "airo_config(0x%p)\n", link); 297 DEBUG(0, "airo_config(0x%p)\n", link);
222 298
299 req = kzalloc(sizeof(win_req_t), GFP_KERNEL);
300 if (!req)
301 return -ENOMEM;
302
303 /*
304 * In this loop, we scan the CIS for configuration table
305 * entries, each of which describes a valid card
306 * configuration, including voltage, IO window, memory window,
307 * and interrupt settings.
308 *
309 * We make no assumptions about the card to be configured: we
310 * use just the information available in the CIS. In an ideal
311 * world, this would work for any PCMCIA card, but it requires
312 * a complete and accurate CIS. In practice, a driver usually
313 * "knows" most of these things without consulting the CIS,
314 * and most client drivers will only use the CIS to fill in
315 * implementation-defined details.
316 */
317 last_ret = pcmcia_loop_config(link, airo_cs_config_check, req);
318 if (last_ret)
319 goto failed;
320
223 /* 321 /*
224 In this loop, we scan the CIS for configuration table entries, 322 Allocate an interrupt line. Note that this does not assign a
225 each of which describes a valid card configuration, including 323 handler to the interrupt, unless the 'Handler' member of the
226 voltage, IO window, memory window, and interrupt settings. 324 irq structure is initialized.
227
228 We make no assumptions about the card to be configured: we use
229 just the information available in the CIS. In an ideal world,
230 this would work for any PCMCIA card, but it requires a complete
231 and accurate CIS. In practice, a driver usually "knows" most of
232 these things without consulting the CIS, and most client drivers
233 will only use the CIS to fill in implementation-defined details.
234 */ 325 */
235 tuple.Attributes = 0;
236 tuple.TupleData = buf;
237 tuple.TupleDataMax = sizeof(buf);
238 tuple.TupleOffset = 0;
239 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
240 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
241 while (1) {
242 cistpl_cftable_entry_t dflt = { 0 };
243 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
244 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
245 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
246 goto next_entry;
247
248 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
249 if (cfg->index == 0) goto next_entry;
250 link->conf.ConfigIndex = cfg->index;
251
252 /* Does this card need audio output? */
253 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
254 link->conf.Attributes |= CONF_ENABLE_SPKR;
255 link->conf.Status = CCSR_AUDIO_ENA;
256 }
257
258 /* Use power settings for Vcc and Vpp if present */
259 /* Note that the CIS values need to be rescaled */
260 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
261 link->conf.Vpp =
262 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
263 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
264 link->conf.Vpp =
265 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
266
267 /* Do we need to allocate an interrupt? */
268 if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
269 link->conf.Attributes |= CONF_ENABLE_IRQ;
270
271 /* IO window settings */
272 link->io.NumPorts1 = link->io.NumPorts2 = 0;
273 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
274 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
275 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
276 if (!(io->flags & CISTPL_IO_8BIT))
277 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
278 if (!(io->flags & CISTPL_IO_16BIT))
279 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
280 link->io.BasePort1 = io->win[0].base;
281 link->io.NumPorts1 = io->win[0].len;
282 if (io->nwin > 1) {
283 link->io.Attributes2 = link->io.Attributes1;
284 link->io.BasePort2 = io->win[1].base;
285 link->io.NumPorts2 = io->win[1].len;
286 }
287 }
288
289 /* This reserves IO space but doesn't actually enable it */
290 if (pcmcia_request_io(link, &link->io) != 0)
291 goto next_entry;
292
293 /*
294 Now set up a common memory window, if needed. There is room
295 in the struct pcmcia_device structure for one memory window handle,
296 but if the base addresses need to be saved, or if multiple
297 windows are needed, the info should go in the private data
298 structure for this device.
299
300 Note that the memory window base is a physical address, and
301 needs to be mapped to virtual space with ioremap() before it
302 is used.
303 */
304 if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) {
305 cistpl_mem_t *mem =
306 (cfg->mem.nwin) ? &cfg->mem : &dflt.mem;
307 req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
308 req.Base = mem->win[0].host_addr;
309 req.Size = mem->win[0].len;
310 req.AccessSpeed = 0;
311 if (pcmcia_request_window(&link, &req, &link->win) != 0)
312 goto next_entry;
313 map.Page = 0; map.CardOffset = mem->win[0].card_addr;
314 if (pcmcia_map_mem_page(link->win, &map) != 0)
315 goto next_entry;
316 }
317 /* If we got this far, we're cool! */
318 break;
319
320 next_entry:
321 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
322 }
323
324 /*
325 Allocate an interrupt line. Note that this does not assign a
326 handler to the interrupt, unless the 'Handler' member of the
327 irq structure is initialized.
328 */
329 if (link->conf.Attributes & CONF_ENABLE_IRQ) 326 if (link->conf.Attributes & CONF_ENABLE_IRQ)
330 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 327 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
331 328
@@ -362,14 +359,17 @@ static int airo_config(struct pcmcia_device *link)
362 printk(" & 0x%04x-0x%04x", link->io.BasePort2, 359 printk(" & 0x%04x-0x%04x", link->io.BasePort2,
363 link->io.BasePort2+link->io.NumPorts2-1); 360 link->io.BasePort2+link->io.NumPorts2-1);
364 if (link->win) 361 if (link->win)
365 printk(", mem 0x%06lx-0x%06lx", req.Base, 362 printk(", mem 0x%06lx-0x%06lx", req->Base,
366 req.Base+req.Size-1); 363 req->Base+req->Size-1);
367 printk("\n"); 364 printk("\n");
365 kfree(req);
368 return 0; 366 return 0;
369 367
370 cs_failed: 368 cs_failed:
371 cs_error(link, last_fn, last_ret); 369 cs_error(link, last_fn, last_ret);
370 failed:
372 airo_release(link); 371 airo_release(link);
372 kfree(req);
373 return -ENODEV; 373 return -ENODEV;
374} /* airo_config */ 374} /* airo_config */
375 375
diff --git a/drivers/net/wireless/ath9k/main.c b/drivers/net/wireless/ath9k/main.c
index 74726990d59e..f05f584ab7bc 100644
--- a/drivers/net/wireless/ath9k/main.c
+++ b/drivers/net/wireless/ath9k/main.c
@@ -1640,6 +1640,11 @@ static int ath9k_ampdu_action(struct ieee80211_hw *hw,
1640 return ret; 1640 return ret;
1641} 1641}
1642 1642
1643static int ath9k_no_fragmentation(struct ieee80211_hw *hw, u32 value)
1644{
1645 return -EOPNOTSUPP;
1646}
1647
1643static struct ieee80211_ops ath9k_ops = { 1648static struct ieee80211_ops ath9k_ops = {
1644 .tx = ath9k_tx, 1649 .tx = ath9k_tx,
1645 .start = ath9k_start, 1650 .start = ath9k_start,
@@ -1664,7 +1669,8 @@ static struct ieee80211_ops ath9k_ops = {
1664 .get_tsf = ath9k_get_tsf, 1669 .get_tsf = ath9k_get_tsf,
1665 .reset_tsf = ath9k_reset_tsf, 1670 .reset_tsf = ath9k_reset_tsf,
1666 .tx_last_beacon = NULL, 1671 .tx_last_beacon = NULL,
1667 .ampdu_action = ath9k_ampdu_action 1672 .ampdu_action = ath9k_ampdu_action,
1673 .set_frag_threshold = ath9k_no_fragmentation,
1668}; 1674};
1669 1675
1670static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) 1676static int ath_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
diff --git a/drivers/net/wireless/atmel_cs.c b/drivers/net/wireless/atmel_cs.c
index d2388e8d179a..77406245dc7b 100644
--- a/drivers/net/wireless/atmel_cs.c
+++ b/drivers/net/wireless/atmel_cs.c
@@ -224,13 +224,58 @@ static int card_present(void *arg)
224 return 0; 224 return 0;
225} 225}
226 226
227static int atmel_config_check(struct pcmcia_device *p_dev,
228 cistpl_cftable_entry_t *cfg,
229 cistpl_cftable_entry_t *dflt,
230 unsigned int vcc,
231 void *priv_data)
232{
233 if (cfg->index == 0)
234 return -ENODEV;
235
236 /* Does this card need audio output? */
237 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
238 p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
239 p_dev->conf.Status = CCSR_AUDIO_ENA;
240 }
241
242 /* Use power settings for Vcc and Vpp if present */
243 /* Note that the CIS values need to be rescaled */
244 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
245 p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
246 else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
247 p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
248
249 /* Do we need to allocate an interrupt? */
250 if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
251 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
252
253 /* IO window settings */
254 p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
255 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
256 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
257 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
258 if (!(io->flags & CISTPL_IO_8BIT))
259 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
260 if (!(io->flags & CISTPL_IO_16BIT))
261 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
262 p_dev->io.BasePort1 = io->win[0].base;
263 p_dev->io.NumPorts1 = io->win[0].len;
264 if (io->nwin > 1) {
265 p_dev->io.Attributes2 = p_dev->io.Attributes1;
266 p_dev->io.BasePort2 = io->win[1].base;
267 p_dev->io.NumPorts2 = io->win[1].len;
268 }
269 }
270
271 /* This reserves IO space but doesn't actually enable it */
272 return pcmcia_request_io(p_dev, &p_dev->io);
273}
274
227static int atmel_config(struct pcmcia_device *link) 275static int atmel_config(struct pcmcia_device *link)
228{ 276{
229 tuple_t tuple;
230 cisparse_t parse;
231 local_info_t *dev; 277 local_info_t *dev;
232 int last_fn, last_ret; 278 int last_fn, last_ret;
233 u_char buf[64];
234 struct pcmcia_device_id *did; 279 struct pcmcia_device_id *did;
235 280
236 dev = link->priv; 281 dev = link->priv;
@@ -238,11 +283,6 @@ static int atmel_config(struct pcmcia_device *link)
238 283
239 DEBUG(0, "atmel_config(0x%p)\n", link); 284 DEBUG(0, "atmel_config(0x%p)\n", link);
240 285
241 tuple.Attributes = 0;
242 tuple.TupleData = buf;
243 tuple.TupleDataMax = sizeof(buf);
244 tuple.TupleOffset = 0;
245
246 /* 286 /*
247 In this loop, we scan the CIS for configuration table entries, 287 In this loop, we scan the CIS for configuration table entries,
248 each of which describes a valid card configuration, including 288 each of which describes a valid card configuration, including
@@ -255,66 +295,8 @@ static int atmel_config(struct pcmcia_device *link)
255 these things without consulting the CIS, and most client drivers 295 these things without consulting the CIS, and most client drivers
256 will only use the CIS to fill in implementation-defined details. 296 will only use the CIS to fill in implementation-defined details.
257 */ 297 */
258 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 298 if (pcmcia_loop_config(link, atmel_config_check, NULL))
259 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); 299 goto failed;
260 while (1) {
261 cistpl_cftable_entry_t dflt = { 0 };
262 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
263 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
264 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
265 goto next_entry;
266
267 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
268 if (cfg->index == 0) goto next_entry;
269 link->conf.ConfigIndex = cfg->index;
270
271 /* Does this card need audio output? */
272 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
273 link->conf.Attributes |= CONF_ENABLE_SPKR;
274 link->conf.Status = CCSR_AUDIO_ENA;
275 }
276
277 /* Use power settings for Vcc and Vpp if present */
278 /* Note that the CIS values need to be rescaled */
279 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
280 link->conf.Vpp =
281 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
282 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
283 link->conf.Vpp =
284 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
285
286 /* Do we need to allocate an interrupt? */
287 if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
288 link->conf.Attributes |= CONF_ENABLE_IRQ;
289
290 /* IO window settings */
291 link->io.NumPorts1 = link->io.NumPorts2 = 0;
292 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
293 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
294 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
295 if (!(io->flags & CISTPL_IO_8BIT))
296 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
297 if (!(io->flags & CISTPL_IO_16BIT))
298 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
299 link->io.BasePort1 = io->win[0].base;
300 link->io.NumPorts1 = io->win[0].len;
301 if (io->nwin > 1) {
302 link->io.Attributes2 = link->io.Attributes1;
303 link->io.BasePort2 = io->win[1].base;
304 link->io.NumPorts2 = io->win[1].len;
305 }
306 }
307
308 /* This reserves IO space but doesn't actually enable it */
309 if (pcmcia_request_io(link, &link->io) != 0)
310 goto next_entry;
311
312 /* If we got this far, we're cool! */
313 break;
314
315 next_entry:
316 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
317 }
318 300
319 /* 301 /*
320 Allocate an interrupt line. Note that this does not assign a 302 Allocate an interrupt line. Note that this does not assign a
@@ -360,6 +342,7 @@ static int atmel_config(struct pcmcia_device *link)
360 342
361 cs_failed: 343 cs_failed:
362 cs_error(link, last_fn, last_ret); 344 cs_error(link, last_fn, last_ret);
345 failed:
363 atmel_release(link); 346 atmel_release(link);
364 return -ENODEV; 347 return -ENODEV;
365} 348}
diff --git a/drivers/net/wireless/b43/pcmcia.c b/drivers/net/wireless/b43/pcmcia.c
index b8aa16307f79..3cfc30307a27 100644
--- a/drivers/net/wireless/b43/pcmcia.c
+++ b/drivers/net/wireless/b43/pcmcia.c
@@ -82,13 +82,13 @@ static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
82 tuple.TupleOffset = 0; 82 tuple.TupleOffset = 0;
83 83
84 res = pcmcia_get_first_tuple(dev, &tuple); 84 res = pcmcia_get_first_tuple(dev, &tuple);
85 if (res != CS_SUCCESS) 85 if (res != 0)
86 goto err_kfree_ssb; 86 goto err_kfree_ssb;
87 res = pcmcia_get_tuple_data(dev, &tuple); 87 res = pcmcia_get_tuple_data(dev, &tuple);
88 if (res != CS_SUCCESS) 88 if (res != 0)
89 goto err_kfree_ssb; 89 goto err_kfree_ssb;
90 res = pcmcia_parse_tuple(dev, &tuple, &parse); 90 res = pcmcia_parse_tuple(&tuple, &parse);
91 if (res != CS_SUCCESS) 91 if (res != 0)
92 goto err_kfree_ssb; 92 goto err_kfree_ssb;
93 93
94 dev->conf.ConfigBase = parse.config.base; 94 dev->conf.ConfigBase = parse.config.base;
@@ -107,13 +107,13 @@ static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
107 win.Size = SSB_CORE_SIZE; 107 win.Size = SSB_CORE_SIZE;
108 win.AccessSpeed = 250; 108 win.AccessSpeed = 250;
109 res = pcmcia_request_window(&dev, &win, &dev->win); 109 res = pcmcia_request_window(&dev, &win, &dev->win);
110 if (res != CS_SUCCESS) 110 if (res != 0)
111 goto err_kfree_ssb; 111 goto err_kfree_ssb;
112 112
113 mem.CardOffset = 0; 113 mem.CardOffset = 0;
114 mem.Page = 0; 114 mem.Page = 0;
115 res = pcmcia_map_mem_page(dev->win, &mem); 115 res = pcmcia_map_mem_page(dev->win, &mem);
116 if (res != CS_SUCCESS) 116 if (res != 0)
117 goto err_disable; 117 goto err_disable;
118 118
119 dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING; 119 dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
@@ -121,11 +121,11 @@ static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
121 dev->irq.Handler = NULL; /* The handler is registered later. */ 121 dev->irq.Handler = NULL; /* The handler is registered later. */
122 dev->irq.Instance = NULL; 122 dev->irq.Instance = NULL;
123 res = pcmcia_request_irq(dev, &dev->irq); 123 res = pcmcia_request_irq(dev, &dev->irq);
124 if (res != CS_SUCCESS) 124 if (res != 0)
125 goto err_disable; 125 goto err_disable;
126 126
127 res = pcmcia_request_configuration(dev, &dev->conf); 127 res = pcmcia_request_configuration(dev, &dev->conf);
128 if (res != CS_SUCCESS) 128 if (res != 0)
129 goto err_disable; 129 goto err_disable;
130 130
131 err = ssb_bus_pcmciabus_register(ssb, dev, win.Base); 131 err = ssb_bus_pcmciabus_register(ssb, dev, win.Base);
diff --git a/drivers/net/wireless/hostap/hostap_cs.c b/drivers/net/wireless/hostap/hostap_cs.c
index 3b4e55cf33cd..633740277352 100644
--- a/drivers/net/wireless/hostap/hostap_cs.c
+++ b/drivers/net/wireless/hostap/hostap_cs.c
@@ -234,7 +234,7 @@ static void sandisk_set_iobase(local_info_t *local)
234 reg.Value = hw_priv->link->io.BasePort1 & 0x00ff; 234 reg.Value = hw_priv->link->io.BasePort1 & 0x00ff;
235 res = pcmcia_access_configuration_register(hw_priv->link, 235 res = pcmcia_access_configuration_register(hw_priv->link,
236 &reg); 236 &reg);
237 if (res != CS_SUCCESS) { 237 if (res != 0) {
238 printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 0 -" 238 printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 0 -"
239 " res=%d\n", res); 239 " res=%d\n", res);
240 } 240 }
@@ -246,7 +246,7 @@ static void sandisk_set_iobase(local_info_t *local)
246 reg.Value = (hw_priv->link->io.BasePort1 & 0xff00) >> 8; 246 reg.Value = (hw_priv->link->io.BasePort1 & 0xff00) >> 8;
247 res = pcmcia_access_configuration_register(hw_priv->link, 247 res = pcmcia_access_configuration_register(hw_priv->link,
248 &reg); 248 &reg);
249 if (res != CS_SUCCESS) { 249 if (res != 0) {
250 printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 1 -" 250 printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 1 -"
251 " res=%d\n", res); 251 " res=%d\n", res);
252 } 252 }
@@ -305,7 +305,7 @@ static int sandisk_enable_wireless(struct net_device *dev)
305 tuple.DesiredTuple = CISTPL_LONGLINK_MFC; 305 tuple.DesiredTuple = CISTPL_LONGLINK_MFC;
306 if (pcmcia_get_first_tuple(hw_priv->link, &tuple) || 306 if (pcmcia_get_first_tuple(hw_priv->link, &tuple) ||
307 pcmcia_get_tuple_data(hw_priv->link, &tuple) || 307 pcmcia_get_tuple_data(hw_priv->link, &tuple) ||
308 pcmcia_parse_tuple(hw_priv->link, &tuple, parse) || 308 pcmcia_parse_tuple(&tuple, parse) ||
309 parse->longlink_mfc.nfn < 2) { 309 parse->longlink_mfc.nfn < 2) {
310 /* No multi-function links found */ 310 /* No multi-function links found */
311 ret = -ENODEV; 311 ret = -ENODEV;
@@ -322,7 +322,7 @@ static int sandisk_enable_wireless(struct net_device *dev)
322 reg.Value = COR_SOFT_RESET; 322 reg.Value = COR_SOFT_RESET;
323 res = pcmcia_access_configuration_register(hw_priv->link, 323 res = pcmcia_access_configuration_register(hw_priv->link,
324 &reg); 324 &reg);
325 if (res != CS_SUCCESS) { 325 if (res != 0) {
326 printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n", 326 printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
327 dev->name, res); 327 dev->name, res);
328 goto done; 328 goto done;
@@ -339,7 +339,7 @@ static int sandisk_enable_wireless(struct net_device *dev)
339 reg.Value = COR_LEVEL_REQ | 0x8 | COR_ADDR_DECODE | COR_FUNC_ENA; 339 reg.Value = COR_LEVEL_REQ | 0x8 | COR_ADDR_DECODE | COR_FUNC_ENA;
340 res = pcmcia_access_configuration_register(hw_priv->link, 340 res = pcmcia_access_configuration_register(hw_priv->link,
341 &reg); 341 &reg);
342 if (res != CS_SUCCESS) { 342 if (res != 0) {
343 printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n", 343 printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
344 dev->name, res); 344 dev->name, res);
345 goto done; 345 goto done;
@@ -374,7 +374,7 @@ static void prism2_pccard_cor_sreset(local_info_t *local)
374 reg.Value = 0; 374 reg.Value = 0;
375 res = pcmcia_access_configuration_register(hw_priv->link, 375 res = pcmcia_access_configuration_register(hw_priv->link,
376 &reg); 376 &reg);
377 if (res != CS_SUCCESS) { 377 if (res != 0) {
378 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 1 (%d)\n", 378 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 1 (%d)\n",
379 res); 379 res);
380 return; 380 return;
@@ -386,7 +386,7 @@ static void prism2_pccard_cor_sreset(local_info_t *local)
386 reg.Value |= COR_SOFT_RESET; 386 reg.Value |= COR_SOFT_RESET;
387 res = pcmcia_access_configuration_register(hw_priv->link, 387 res = pcmcia_access_configuration_register(hw_priv->link,
388 &reg); 388 &reg);
389 if (res != CS_SUCCESS) { 389 if (res != 0) {
390 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 2 (%d)\n", 390 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 2 (%d)\n",
391 res); 391 res);
392 return; 392 return;
@@ -399,7 +399,7 @@ static void prism2_pccard_cor_sreset(local_info_t *local)
399 reg.Value |= COR_IREQ_ENA; 399 reg.Value |= COR_IREQ_ENA;
400 res = pcmcia_access_configuration_register(hw_priv->link, 400 res = pcmcia_access_configuration_register(hw_priv->link,
401 &reg); 401 &reg);
402 if (res != CS_SUCCESS) { 402 if (res != 0) {
403 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 3 (%d)\n", 403 printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 3 (%d)\n",
404 res); 404 res);
405 return; 405 return;
@@ -433,7 +433,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
433 reg.Value = 0; 433 reg.Value = 0;
434 res = pcmcia_access_configuration_register(hw_priv->link, 434 res = pcmcia_access_configuration_register(hw_priv->link,
435 &reg); 435 &reg);
436 if (res != CS_SUCCESS) { 436 if (res != 0) {
437 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 1 " 437 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 1 "
438 "(%d)\n", res); 438 "(%d)\n", res);
439 return; 439 return;
@@ -446,7 +446,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
446 reg.Value |= COR_SOFT_RESET; 446 reg.Value |= COR_SOFT_RESET;
447 res = pcmcia_access_configuration_register(hw_priv->link, 447 res = pcmcia_access_configuration_register(hw_priv->link,
448 &reg); 448 &reg);
449 if (res != CS_SUCCESS) { 449 if (res != 0) {
450 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 2 " 450 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 2 "
451 "(%d)\n", res); 451 "(%d)\n", res);
452 return; 452 return;
@@ -460,7 +460,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
460 reg.Offset = CISREG_CCSR; 460 reg.Offset = CISREG_CCSR;
461 res = pcmcia_access_configuration_register(hw_priv->link, 461 res = pcmcia_access_configuration_register(hw_priv->link,
462 &reg); 462 &reg);
463 if (res != CS_SUCCESS) { 463 if (res != 0) {
464 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 3 " 464 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 3 "
465 "(%d)\n", res); 465 "(%d)\n", res);
466 return; 466 return;
@@ -472,7 +472,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
472 reg.Value = old_cor & ~COR_SOFT_RESET; 472 reg.Value = old_cor & ~COR_SOFT_RESET;
473 res = pcmcia_access_configuration_register(hw_priv->link, 473 res = pcmcia_access_configuration_register(hw_priv->link,
474 &reg); 474 &reg);
475 if (res != CS_SUCCESS) { 475 if (res != 0) {
476 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 4 " 476 printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 4 "
477 "(%d)\n", res); 477 "(%d)\n", res);
478 return; 478 return;
@@ -532,145 +532,118 @@ static void prism2_detach(struct pcmcia_device *link)
532#define CS_CHECK(fn, ret) \ 532#define CS_CHECK(fn, ret) \
533do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 533do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
534 534
535#define CFG_CHECK2(fn, retf) \
536do { int _ret = (retf); \
537if (_ret != 0) { \
538 PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", _ret); \
539 cs_error(link, fn, _ret); \
540 goto next_entry; \
541} \
542} while (0)
543
544 535
545/* run after a CARD_INSERTION event is received to configure the PCMCIA 536/* run after a CARD_INSERTION event is received to configure the PCMCIA
546 * socket and make the device available to the system */ 537 * socket and make the device available to the system */
538
539static int prism2_config_check(struct pcmcia_device *p_dev,
540 cistpl_cftable_entry_t *cfg,
541 cistpl_cftable_entry_t *dflt,
542 unsigned int vcc,
543 void *priv_data)
544{
545 if (cfg->index == 0)
546 return -ENODEV;
547
548 PDEBUG(DEBUG_EXTRA, "Checking CFTABLE_ENTRY 0x%02X "
549 "(default 0x%02X)\n", cfg->index, dflt->index);
550
551 /* Does this card need audio output? */
552 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
553 p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
554 p_dev->conf.Status = CCSR_AUDIO_ENA;
555 }
556
557 /* Use power settings for Vcc and Vpp if present */
558 /* Note that the CIS values need to be rescaled */
559 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
560 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] /
561 10000 && !ignore_cis_vcc) {
562 PDEBUG(DEBUG_EXTRA, " Vcc mismatch - skipping"
563 " this entry\n");
564 return -ENODEV;
565 }
566 } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
567 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] /
568 10000 && !ignore_cis_vcc) {
569 PDEBUG(DEBUG_EXTRA, " Vcc (default) mismatch "
570 "- skipping this entry\n");
571 return -ENODEV;
572 }
573 }
574
575 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
576 p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
577 else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
578 p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
579
580 /* Do we need to allocate an interrupt? */
581 if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
582 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
583 else if (!(p_dev->conf.Attributes & CONF_ENABLE_IRQ)) {
584 /* At least Compaq WL200 does not have IRQInfo1 set,
585 * but it does not work without interrupts.. */
586 printk(KERN_WARNING "Config has no IRQ info, but trying to "
587 "enable IRQ anyway..\n");
588 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
589 }
590
591 /* IO window settings */
592 PDEBUG(DEBUG_EXTRA, "IO window settings: cfg->io.nwin=%d "
593 "dflt->io.nwin=%d\n",
594 cfg->io.nwin, dflt->io.nwin);
595 p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
596 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
597 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
598 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
599 PDEBUG(DEBUG_EXTRA, "io->flags = 0x%04X, "
600 "io.base=0x%04x, len=%d\n", io->flags,
601 io->win[0].base, io->win[0].len);
602 if (!(io->flags & CISTPL_IO_8BIT))
603 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
604 if (!(io->flags & CISTPL_IO_16BIT))
605 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
606 p_dev->io.IOAddrLines = io->flags &
607 CISTPL_IO_LINES_MASK;
608 p_dev->io.BasePort1 = io->win[0].base;
609 p_dev->io.NumPorts1 = io->win[0].len;
610 if (io->nwin > 1) {
611 p_dev->io.Attributes2 = p_dev->io.Attributes1;
612 p_dev->io.BasePort2 = io->win[1].base;
613 p_dev->io.NumPorts2 = io->win[1].len;
614 }
615 }
616
617 /* This reserves IO space but doesn't actually enable it */
618 return pcmcia_request_io(p_dev, &p_dev->io);
619}
620
547static int prism2_config(struct pcmcia_device *link) 621static int prism2_config(struct pcmcia_device *link)
548{ 622{
549 struct net_device *dev; 623 struct net_device *dev;
550 struct hostap_interface *iface; 624 struct hostap_interface *iface;
551 local_info_t *local; 625 local_info_t *local;
552 int ret = 1; 626 int ret = 1;
553 tuple_t tuple;
554 cisparse_t *parse;
555 int last_fn, last_ret; 627 int last_fn, last_ret;
556 u_char buf[64];
557 config_info_t conf;
558 cistpl_cftable_entry_t dflt = { 0 };
559 struct hostap_cs_priv *hw_priv; 628 struct hostap_cs_priv *hw_priv;
560 629
561 PDEBUG(DEBUG_FLOW, "prism2_config()\n"); 630 PDEBUG(DEBUG_FLOW, "prism2_config()\n");
562 631
563 parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL);
564 hw_priv = kzalloc(sizeof(*hw_priv), GFP_KERNEL); 632 hw_priv = kzalloc(sizeof(*hw_priv), GFP_KERNEL);
565 if (parse == NULL || hw_priv == NULL) { 633 if (hw_priv == NULL) {
566 ret = -ENOMEM; 634 ret = -ENOMEM;
567 goto failed; 635 goto failed;
568 } 636 }
569 637
570 tuple.Attributes = 0;
571 tuple.TupleData = buf;
572 tuple.TupleDataMax = sizeof(buf);
573 tuple.TupleOffset = 0;
574
575 CS_CHECK(GetConfigurationInfo,
576 pcmcia_get_configuration_info(link, &conf));
577
578 /* Look for an appropriate configuration table entry in the CIS */ 638 /* Look for an appropriate configuration table entry in the CIS */
579 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 639 last_ret = pcmcia_loop_config(link, prism2_config_check, NULL);
580 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); 640 if (last_ret) {
581 for (;;) { 641 if (!ignore_cis_vcc)
582 cistpl_cftable_entry_t *cfg = &(parse->cftable_entry); 642 printk(KERN_ERR "GetNextTuple(): No matching "
583 CFG_CHECK2(GetTupleData, 643 "CIS configuration. Maybe you need the "
584 pcmcia_get_tuple_data(link, &tuple)); 644 "ignore_cis_vcc=1 parameter.\n");
585 CFG_CHECK2(ParseTuple, 645 cs_error(link, RequestIO, last_ret);
586 pcmcia_parse_tuple(link, &tuple, parse)); 646 goto failed;
587
588 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
589 dflt = *cfg;
590 if (cfg->index == 0)
591 goto next_entry;
592 link->conf.ConfigIndex = cfg->index;
593 PDEBUG(DEBUG_EXTRA, "Checking CFTABLE_ENTRY 0x%02X "
594 "(default 0x%02X)\n", cfg->index, dflt.index);
595
596 /* Does this card need audio output? */
597 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
598 link->conf.Attributes |= CONF_ENABLE_SPKR;
599 link->conf.Status = CCSR_AUDIO_ENA;
600 }
601
602 /* Use power settings for Vcc and Vpp if present */
603 /* Note that the CIS values need to be rescaled */
604 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
605 if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] /
606 10000 && !ignore_cis_vcc) {
607 PDEBUG(DEBUG_EXTRA, " Vcc mismatch - skipping"
608 " this entry\n");
609 goto next_entry;
610 }
611 } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
612 if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] /
613 10000 && !ignore_cis_vcc) {
614 PDEBUG(DEBUG_EXTRA, " Vcc (default) mismatch "
615 "- skipping this entry\n");
616 goto next_entry;
617 }
618 }
619
620 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
621 link->conf.Vpp =
622 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
623 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
624 link->conf.Vpp =
625 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
626
627 /* Do we need to allocate an interrupt? */
628 if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
629 link->conf.Attributes |= CONF_ENABLE_IRQ;
630 else if (!(link->conf.Attributes & CONF_ENABLE_IRQ)) {
631 /* At least Compaq WL200 does not have IRQInfo1 set,
632 * but it does not work without interrupts.. */
633 printk("Config has no IRQ info, but trying to enable "
634 "IRQ anyway..\n");
635 link->conf.Attributes |= CONF_ENABLE_IRQ;
636 }
637
638 /* IO window settings */
639 PDEBUG(DEBUG_EXTRA, "IO window settings: cfg->io.nwin=%d "
640 "dflt.io.nwin=%d\n",
641 cfg->io.nwin, dflt.io.nwin);
642 link->io.NumPorts1 = link->io.NumPorts2 = 0;
643 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
644 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
645 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
646 PDEBUG(DEBUG_EXTRA, "io->flags = 0x%04X, "
647 "io.base=0x%04x, len=%d\n", io->flags,
648 io->win[0].base, io->win[0].len);
649 if (!(io->flags & CISTPL_IO_8BIT))
650 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
651 if (!(io->flags & CISTPL_IO_16BIT))
652 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
653 link->io.IOAddrLines = io->flags &
654 CISTPL_IO_LINES_MASK;
655 link->io.BasePort1 = io->win[0].base;
656 link->io.NumPorts1 = io->win[0].len;
657 if (io->nwin > 1) {
658 link->io.Attributes2 = link->io.Attributes1;
659 link->io.BasePort2 = io->win[1].base;
660 link->io.NumPorts2 = io->win[1].len;
661 }
662 }
663
664 /* This reserves IO space but doesn't actually enable it */
665 CFG_CHECK2(RequestIO,
666 pcmcia_request_io(link, &link->io));
667
668 /* This configuration table entry is OK */
669 break;
670
671 next_entry:
672 CS_CHECK(GetNextTuple,
673 pcmcia_get_next_tuple(link, &tuple));
674 } 647 }
675 648
676 /* Need to allocate net_device before requesting IRQ handler */ 649 /* Need to allocate net_device before requesting IRQ handler */
@@ -738,14 +711,12 @@ static int prism2_config(struct pcmcia_device *link)
738 if (ret == 0 && local->ddev) 711 if (ret == 0 && local->ddev)
739 strcpy(hw_priv->node.dev_name, local->ddev->name); 712 strcpy(hw_priv->node.dev_name, local->ddev->name);
740 } 713 }
741 kfree(parse);
742 return ret; 714 return ret;
743 715
744 cs_failed: 716 cs_failed:
745 cs_error(link, last_fn, last_ret); 717 cs_error(link, last_fn, last_ret);
746 718
747 failed: 719 failed:
748 kfree(parse);
749 kfree(hw_priv); 720 kfree(hw_priv);
750 prism2_release((u_long)link); 721 prism2_release((u_long)link);
751 return ret; 722 return ret;
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
index f6003e7996af..5155b8a760a7 100644
--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
@@ -833,12 +833,12 @@ static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
833 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) { 833 switch (priv->hw_rev & CSR_HW_REV_TYPE_MSK) {
834 case CSR_HW_REV_TYPE_5100: 834 case CSR_HW_REV_TYPE_5100:
835 case CSR_HW_REV_TYPE_5300: 835 case CSR_HW_REV_TYPE_5300:
836 /* 5X00 wants in Celsius */ 836 case CSR_HW_REV_TYPE_5350:
837 /* 5X00 and 5350 wants in Celsius */
837 priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD; 838 priv->hw_params.ct_kill_threshold = CT_KILL_THRESHOLD;
838 break; 839 break;
839 case CSR_HW_REV_TYPE_5150: 840 case CSR_HW_REV_TYPE_5150:
840 case CSR_HW_REV_TYPE_5350: 841 /* 5150 wants in Kelvin */
841 /* 5X50 wants in Kelvin */
842 priv->hw_params.ct_kill_threshold = 842 priv->hw_params.ct_kill_threshold =
843 CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD); 843 CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
844 break; 844 break;
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
index 93944de923ca..e2a58e477036 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
@@ -2422,7 +2422,7 @@ static void rs_free_sta(void *priv_r, struct ieee80211_sta *sta,
2422 void *priv_sta) 2422 void *priv_sta)
2423{ 2423{
2424 struct iwl_lq_sta *lq_sta = priv_sta; 2424 struct iwl_lq_sta *lq_sta = priv_sta;
2425 struct iwl_priv *priv = priv_r; 2425 struct iwl_priv *priv __maybe_unused = priv_r;
2426 2426
2427 IWL_DEBUG_RATE("enter\n"); 2427 IWL_DEBUG_RATE("enter\n");
2428 kfree(lq_sta); 2428 kfree(lq_sta);
diff --git a/drivers/net/wireless/libertas/cmd.c b/drivers/net/wireless/libertas/cmd.c
index a912fb68c099..297696de2da0 100644
--- a/drivers/net/wireless/libertas/cmd.c
+++ b/drivers/net/wireless/libertas/cmd.c
@@ -823,7 +823,9 @@ int lbs_update_channel(struct lbs_private *priv)
823int lbs_set_channel(struct lbs_private *priv, u8 channel) 823int lbs_set_channel(struct lbs_private *priv, u8 channel)
824{ 824{
825 struct cmd_ds_802_11_rf_channel cmd; 825 struct cmd_ds_802_11_rf_channel cmd;
826#ifdef DEBUG
826 u8 old_channel = priv->curbssparams.channel; 827 u8 old_channel = priv->curbssparams.channel;
828#endif
827 int ret = 0; 829 int ret = 0;
828 830
829 lbs_deb_enter(LBS_DEB_CMD); 831 lbs_deb_enter(LBS_DEB_CMD);
diff --git a/drivers/net/wireless/libertas/if_cs.c b/drivers/net/wireless/libertas/if_cs.c
index e3505c110af6..842a08d1f106 100644
--- a/drivers/net/wireless/libertas/if_cs.c
+++ b/drivers/net/wireless/libertas/if_cs.c
@@ -791,7 +791,7 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
791 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 791 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
792 if ((ret = pcmcia_get_first_tuple(p_dev, &tuple)) != 0 || 792 if ((ret = pcmcia_get_first_tuple(p_dev, &tuple)) != 0 ||
793 (ret = pcmcia_get_tuple_data(p_dev, &tuple)) != 0 || 793 (ret = pcmcia_get_tuple_data(p_dev, &tuple)) != 0 ||
794 (ret = pcmcia_parse_tuple(p_dev, &tuple, &parse)) != 0) 794 (ret = pcmcia_parse_tuple(&tuple, &parse)) != 0)
795 { 795 {
796 lbs_pr_err("error in pcmcia_get_first_tuple etc\n"); 796 lbs_pr_err("error in pcmcia_get_first_tuple etc\n");
797 goto out1; 797 goto out1;
diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
index c9e4a435b2fc..1a019e98dac3 100644
--- a/drivers/net/wireless/mac80211_hwsim.c
+++ b/drivers/net/wireless/mac80211_hwsim.c
@@ -533,11 +533,11 @@ static int __init init_mac80211_hwsim(void)
533 data = hw->priv; 533 data = hw->priv;
534 data->hw = hw; 534 data->hw = hw;
535 535
536 data->dev = device_create_drvdata(hwsim_class, NULL, 0, hw, 536 data->dev = device_create(hwsim_class, NULL, 0, hw,
537 "hwsim%d", i); 537 "hwsim%d", i);
538 if (IS_ERR(data->dev)) { 538 if (IS_ERR(data->dev)) {
539 printk(KERN_DEBUG 539 printk(KERN_DEBUG
540 "mac80211_hwsim: device_create_drvdata " 540 "mac80211_hwsim: device_create "
541 "failed (%ld)\n", PTR_ERR(data->dev)); 541 "failed (%ld)\n", PTR_ERR(data->dev));
542 err = -ENOMEM; 542 err = -ENOMEM;
543 goto failed_drvdata; 543 goto failed_drvdata;
diff --git a/drivers/net/wireless/netwave_cs.c b/drivers/net/wireless/netwave_cs.c
index 25bae7933aa5..a670f36b5f3f 100644
--- a/drivers/net/wireless/netwave_cs.c
+++ b/drivers/net/wireless/netwave_cs.c
@@ -749,9 +749,10 @@ static int netwave_pcmcia_config(struct pcmcia_device *link) {
749 for (i = j = 0x0; j < 0x400; j += 0x20) { 749 for (i = j = 0x0; j < 0x400; j += 0x20) {
750 link->io.BasePort1 = j ^ 0x300; 750 link->io.BasePort1 = j ^ 0x300;
751 i = pcmcia_request_io(link, &link->io); 751 i = pcmcia_request_io(link, &link->io);
752 if (i == CS_SUCCESS) break; 752 if (i == 0)
753 break;
753 } 754 }
754 if (i != CS_SUCCESS) { 755 if (i != 0) {
755 cs_error(link, RequestIO, i); 756 cs_error(link, RequestIO, i);
756 goto failed; 757 goto failed;
757 } 758 }
diff --git a/drivers/net/wireless/orinoco_cs.c b/drivers/net/wireless/orinoco_cs.c
index 9eaa252c2430..6fcf2bda7cdf 100644
--- a/drivers/net/wireless/orinoco_cs.c
+++ b/drivers/net/wireless/orinoco_cs.c
@@ -80,7 +80,7 @@ orinoco_cs_hard_reset(struct orinoco_private *priv)
80 /* We need atomic ops here, because we're not holding the lock */ 80 /* We need atomic ops here, because we're not holding the lock */
81 set_bit(0, &card->hard_reset_in_progress); 81 set_bit(0, &card->hard_reset_in_progress);
82 82
83 err = pcmcia_reset_card(link, NULL); 83 err = pcmcia_reset_card(link->socket);
84 if (err) 84 if (err)
85 return err; 85 return err;
86 86
@@ -165,6 +165,70 @@ static void orinoco_cs_detach(struct pcmcia_device *link)
165 last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; \ 165 last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; \
166 } while (0) 166 } while (0)
167 167
168static int orinoco_cs_config_check(struct pcmcia_device *p_dev,
169 cistpl_cftable_entry_t *cfg,
170 cistpl_cftable_entry_t *dflt,
171 unsigned int vcc,
172 void *priv_data)
173{
174 if (cfg->index == 0)
175 goto next_entry;
176
177 /* Use power settings for Vcc and Vpp if present */
178 /* Note that the CIS values need to be rescaled */
179 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
180 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
181 DEBUG(2, "spectrum_cs_config: Vcc mismatch (vcc = %d, CIS = %d)\n", vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
182 if (!ignore_cis_vcc)
183 goto next_entry;
184 }
185 } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
186 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] / 10000) {
187 DEBUG(2, "spectrum_cs_config: Vcc mismatch (vcc = %d, CIS = %d)\n", vcc, dflt->vcc.param[CISTPL_POWER_VNOM] / 10000);
188 if (!ignore_cis_vcc)
189 goto next_entry;
190 }
191 }
192
193 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
194 p_dev->conf.Vpp =
195 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
196 else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
197 p_dev->conf.Vpp =
198 dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
199
200 /* Do we need to allocate an interrupt? */
201 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
202
203 /* IO window settings */
204 p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
205 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
206 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
207 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
208 if (!(io->flags & CISTPL_IO_8BIT))
209 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
210 if (!(io->flags & CISTPL_IO_16BIT))
211 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
212 p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
213 p_dev->io.BasePort1 = io->win[0].base;
214 p_dev->io.NumPorts1 = io->win[0].len;
215 if (io->nwin > 1) {
216 p_dev->io.Attributes2 = p_dev->io.Attributes1;
217 p_dev->io.BasePort2 = io->win[1].base;
218 p_dev->io.NumPorts2 = io->win[1].len;
219 }
220
221 /* This reserves IO space but doesn't actually enable it */
222 if (pcmcia_request_io(p_dev, &p_dev->io) != 0)
223 goto next_entry;
224 }
225 return 0;
226
227next_entry:
228 pcmcia_disable_device(p_dev);
229 return -ENODEV;
230};
231
168static int 232static int
169orinoco_cs_config(struct pcmcia_device *link) 233orinoco_cs_config(struct pcmcia_device *link)
170{ 234{
@@ -173,16 +237,8 @@ orinoco_cs_config(struct pcmcia_device *link)
173 struct orinoco_pccard *card = priv->card; 237 struct orinoco_pccard *card = priv->card;
174 hermes_t *hw = &priv->hw; 238 hermes_t *hw = &priv->hw;
175 int last_fn, last_ret; 239 int last_fn, last_ret;
176 u_char buf[64];
177 config_info_t conf;
178 tuple_t tuple;
179 cisparse_t parse;
180 void __iomem *mem; 240 void __iomem *mem;
181 241
182 /* Look up the current Vcc */
183 CS_CHECK(GetConfigurationInfo,
184 pcmcia_get_configuration_info(link, &conf));
185
186 /* 242 /*
187 * In this loop, we scan the CIS for configuration table 243 * In this loop, we scan the CIS for configuration table
188 * entries, each of which describes a valid card 244 * entries, each of which describes a valid card
@@ -197,94 +253,14 @@ orinoco_cs_config(struct pcmcia_device *link)
197 * and most client drivers will only use the CIS to fill in 253 * and most client drivers will only use the CIS to fill in
198 * implementation-defined details. 254 * implementation-defined details.
199 */ 255 */
200 tuple.Attributes = 0; 256 last_ret = pcmcia_loop_config(link, orinoco_cs_config_check, NULL);
201 tuple.TupleData = buf; 257 if (last_ret) {
202 tuple.TupleDataMax = sizeof(buf); 258 if (!ignore_cis_vcc)
203 tuple.TupleOffset = 0;
204 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
205 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
206 while (1) {
207 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
208 cistpl_cftable_entry_t dflt = { .index = 0 };
209
210 if ( (pcmcia_get_tuple_data(link, &tuple) != 0)
211 || (pcmcia_parse_tuple(link, &tuple, &parse) != 0))
212 goto next_entry;
213
214 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
215 dflt = *cfg;
216 if (cfg->index == 0)
217 goto next_entry;
218 link->conf.ConfigIndex = cfg->index;
219
220 /* Use power settings for Vcc and Vpp if present */
221 /* Note that the CIS values need to be rescaled */
222 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
223 if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
224 DEBUG(2, "orinoco_cs_config: Vcc mismatch (conf.Vcc = %d, cfg CIS = %d)\n", conf.Vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
225 if (!ignore_cis_vcc)
226 goto next_entry;
227 }
228 } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
229 if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / 10000) {
230 DEBUG(2, "orinoco_cs_config: Vcc mismatch (conf.Vcc = %d, dflt CIS = %d)\n", conf.Vcc, dflt.vcc.param[CISTPL_POWER_VNOM] / 10000);
231 if(!ignore_cis_vcc)
232 goto next_entry;
233 }
234 }
235
236 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
237 link->conf.Vpp =
238 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
239 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
240 link->conf.Vpp =
241 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
242
243 /* Do we need to allocate an interrupt? */
244 link->conf.Attributes |= CONF_ENABLE_IRQ;
245
246 /* IO window settings */
247 link->io.NumPorts1 = link->io.NumPorts2 = 0;
248 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
249 cistpl_io_t *io =
250 (cfg->io.nwin) ? &cfg->io : &dflt.io;
251 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
252 if (!(io->flags & CISTPL_IO_8BIT))
253 link->io.Attributes1 =
254 IO_DATA_PATH_WIDTH_16;
255 if (!(io->flags & CISTPL_IO_16BIT))
256 link->io.Attributes1 =
257 IO_DATA_PATH_WIDTH_8;
258 link->io.IOAddrLines =
259 io->flags & CISTPL_IO_LINES_MASK;
260 link->io.BasePort1 = io->win[0].base;
261 link->io.NumPorts1 = io->win[0].len;
262 if (io->nwin > 1) {
263 link->io.Attributes2 =
264 link->io.Attributes1;
265 link->io.BasePort2 = io->win[1].base;
266 link->io.NumPorts2 = io->win[1].len;
267 }
268
269 /* This reserves IO space but doesn't actually enable it */
270 if (pcmcia_request_io(link, &link->io) != 0)
271 goto next_entry;
272 }
273
274
275 /* If we got this far, we're cool! */
276
277 break;
278
279 next_entry:
280 pcmcia_disable_device(link);
281 last_ret = pcmcia_get_next_tuple(link, &tuple);
282 if (last_ret == CS_NO_MORE_ITEMS) {
283 printk(KERN_ERR PFX "GetNextTuple(): No matching " 259 printk(KERN_ERR PFX "GetNextTuple(): No matching "
284 "CIS configuration. Maybe you need the " 260 "CIS configuration. Maybe you need the "
285 "ignore_cis_vcc=1 parameter.\n"); 261 "ignore_cis_vcc=1 parameter.\n");
286 goto cs_failed; 262 cs_error(link, RequestIO, last_ret);
287 } 263 goto failed;
288 } 264 }
289 265
290 /* 266 /*
@@ -335,7 +311,6 @@ orinoco_cs_config(struct pcmcia_device *link)
335 "0x%04x-0x%04x\n", dev->name, dev->dev.parent->bus_id, 311 "0x%04x-0x%04x\n", dev->name, dev->dev.parent->bus_id,
336 link->irq.AssignedIRQ, link->io.BasePort1, 312 link->irq.AssignedIRQ, link->io.BasePort1,
337 link->io.BasePort1 + link->io.NumPorts1 - 1); 313 link->io.BasePort1 + link->io.NumPorts1 - 1);
338
339 return 0; 314 return 0;
340 315
341 cs_failed: 316 cs_failed:
@@ -403,6 +378,7 @@ static int orinoco_cs_resume(struct pcmcia_device *link)
403 struct orinoco_private *priv = netdev_priv(dev); 378 struct orinoco_private *priv = netdev_priv(dev);
404 struct orinoco_pccard *card = priv->card; 379 struct orinoco_pccard *card = priv->card;
405 int err = 0; 380 int err = 0;
381 unsigned long flags;
406 382
407 if (! test_bit(0, &card->hard_reset_in_progress)) { 383 if (! test_bit(0, &card->hard_reset_in_progress)) {
408 err = orinoco_reinit_firmware(dev); 384 err = orinoco_reinit_firmware(dev);
@@ -412,7 +388,7 @@ static int orinoco_cs_resume(struct pcmcia_device *link)
412 return -EIO; 388 return -EIO;
413 } 389 }
414 390
415 spin_lock(&priv->lock); 391 spin_lock_irqsave(&priv->lock, flags);
416 392
417 netif_device_attach(dev); 393 netif_device_attach(dev);
418 priv->hw_unavailable--; 394 priv->hw_unavailable--;
@@ -424,7 +400,7 @@ static int orinoco_cs_resume(struct pcmcia_device *link)
424 dev->name, err); 400 dev->name, err);
425 } 401 }
426 402
427 spin_unlock(&priv->lock); 403 spin_unlock_irqrestore(&priv->lock, flags);
428 } 404 }
429 405
430 return err; 406 return err;
diff --git a/drivers/net/wireless/p54/p54common.c b/drivers/net/wireless/p54/p54common.c
index 1994aa199d37..117c7d3a52b0 100644
--- a/drivers/net/wireless/p54/p54common.c
+++ b/drivers/net/wireless/p54/p54common.c
@@ -479,7 +479,6 @@ static int p54_parse_eeprom(struct ieee80211_hw *dev, void *eeprom, int len)
479 printk(KERN_ERR "p54: eeprom parse failed!\n"); 479 printk(KERN_ERR "p54: eeprom parse failed!\n");
480 return err; 480 return err;
481} 481}
482EXPORT_SYMBOL_GPL(p54_parse_eeprom);
483 482
484static int p54_rssi_to_dbm(struct ieee80211_hw *dev, int rssi) 483static int p54_rssi_to_dbm(struct ieee80211_hw *dev, int rssi)
485{ 484{
diff --git a/drivers/net/wireless/p54/p54usb.c b/drivers/net/wireless/p54/p54usb.c
index 1912f5e9a0a9..75d749bccb0d 100644
--- a/drivers/net/wireless/p54/p54usb.c
+++ b/drivers/net/wireless/p54/p54usb.c
@@ -39,6 +39,7 @@ static struct usb_device_id p54u_table[] __devinitdata = {
39 {USB_DEVICE(0x0846, 0x4200)}, /* Netgear WG121 */ 39 {USB_DEVICE(0x0846, 0x4200)}, /* Netgear WG121 */
40 {USB_DEVICE(0x0846, 0x4210)}, /* Netgear WG121 the second ? */ 40 {USB_DEVICE(0x0846, 0x4210)}, /* Netgear WG121 the second ? */
41 {USB_DEVICE(0x0846, 0x4220)}, /* Netgear WG111 */ 41 {USB_DEVICE(0x0846, 0x4220)}, /* Netgear WG111 */
42 {USB_DEVICE(0x09aa, 0x1000)}, /* Spinnaker Proto board */
42 {USB_DEVICE(0x0cde, 0x0006)}, /* Medion 40900, Roper Europe */ 43 {USB_DEVICE(0x0cde, 0x0006)}, /* Medion 40900, Roper Europe */
43 {USB_DEVICE(0x124a, 0x4023)}, /* Shuttle PN15, Airvast WM168g, IOGear GWU513 */ 44 {USB_DEVICE(0x124a, 0x4023)}, /* Shuttle PN15, Airvast WM168g, IOGear GWU513 */
44 {USB_DEVICE(0x1915, 0x2234)}, /* Linksys WUSB54G OEM */ 45 {USB_DEVICE(0x1915, 0x2234)}, /* Linksys WUSB54G OEM */
@@ -63,8 +64,8 @@ static struct usb_device_id p54u_table[] __devinitdata = {
63 {USB_DEVICE(0x0cde, 0x0006)}, /* Medion MD40900 */ 64 {USB_DEVICE(0x0cde, 0x0006)}, /* Medion MD40900 */
64 {USB_DEVICE(0x0cde, 0x0008)}, /* Sagem XG703A */ 65 {USB_DEVICE(0x0cde, 0x0008)}, /* Sagem XG703A */
65 {USB_DEVICE(0x0d8e, 0x3762)}, /* DLink DWL-G120 Cohiba */ 66 {USB_DEVICE(0x0d8e, 0x3762)}, /* DLink DWL-G120 Cohiba */
66 {USB_DEVICE(0x09aa, 0x1000)}, /* Spinnaker Proto board */
67 {USB_DEVICE(0x124a, 0x4025)}, /* IOGear GWU513 (GW3887IK chip) */ 67 {USB_DEVICE(0x124a, 0x4025)}, /* IOGear GWU513 (GW3887IK chip) */
68 {USB_DEVICE(0x1260, 0xee22)}, /* SMC 2862W-G version 2 */
68 {USB_DEVICE(0x13b1, 0x000a)}, /* Linksys WUSB54G ver 2 */ 69 {USB_DEVICE(0x13b1, 0x000a)}, /* Linksys WUSB54G ver 2 */
69 {USB_DEVICE(0x13B1, 0x000C)}, /* Linksys WUSB54AG */ 70 {USB_DEVICE(0x13B1, 0x000C)}, /* Linksys WUSB54AG */
70 {USB_DEVICE(0x1435, 0x0427)}, /* Inventel UR054G */ 71 {USB_DEVICE(0x1435, 0x0427)}, /* Inventel UR054G */
diff --git a/drivers/net/wireless/ray_cs.c b/drivers/net/wireless/ray_cs.c
index 44da0d19b5c8..1404a5717520 100644
--- a/drivers/net/wireless/ray_cs.c
+++ b/drivers/net/wireless/ray_cs.c
@@ -798,9 +798,9 @@ static void ray_release(struct pcmcia_device *link)
798 iounmap(local->amem); 798 iounmap(local->amem);
799 /* Do bother checking to see if these succeed or not */ 799 /* Do bother checking to see if these succeed or not */
800 i = pcmcia_release_window(local->amem_handle); 800 i = pcmcia_release_window(local->amem_handle);
801 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->amem) ret = %x\n",i); 801 if ( i != 0 ) DEBUG(0,"ReleaseWindow(local->amem) ret = %x\n",i);
802 i = pcmcia_release_window(local->rmem_handle); 802 i = pcmcia_release_window(local->rmem_handle);
803 if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->rmem) ret = %x\n",i); 803 if ( i != 0 ) DEBUG(0,"ReleaseWindow(local->rmem) ret = %x\n",i);
804 pcmcia_disable_device(link); 804 pcmcia_disable_device(link);
805 805
806 DEBUG(2,"ray_release ending\n"); 806 DEBUG(2,"ray_release ending\n");
diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
index 1676ac484790..451d410ecdae 100644
--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
@@ -374,7 +374,7 @@ int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb)
374 struct queue_entry *entry = rt2x00queue_get_entry(queue, Q_INDEX); 374 struct queue_entry *entry = rt2x00queue_get_entry(queue, Q_INDEX);
375 struct txentry_desc txdesc; 375 struct txentry_desc txdesc;
376 struct skb_frame_desc *skbdesc; 376 struct skb_frame_desc *skbdesc;
377 unsigned int iv_len; 377 unsigned int iv_len = 0;
378 378
379 if (unlikely(rt2x00queue_full(queue))) 379 if (unlikely(rt2x00queue_full(queue)))
380 return -EINVAL; 380 return -EINVAL;
@@ -395,6 +395,9 @@ int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb)
395 entry->skb = skb; 395 entry->skb = skb;
396 rt2x00queue_create_tx_descriptor(entry, &txdesc); 396 rt2x00queue_create_tx_descriptor(entry, &txdesc);
397 397
398 if (IEEE80211_SKB_CB(skb)->control.hw_key != NULL)
399 iv_len = IEEE80211_SKB_CB(skb)->control.hw_key->iv_len;
400
398 /* 401 /*
399 * All information is retreived from the skb->cb array, 402 * All information is retreived from the skb->cb array,
400 * now we should claim ownership of the driver part of that 403 * now we should claim ownership of the driver part of that
@@ -410,9 +413,7 @@ int rt2x00queue_write_tx_frame(struct data_queue *queue, struct sk_buff *skb)
410 * the frame so we can provide it to the driver seperately. 413 * the frame so we can provide it to the driver seperately.
411 */ 414 */
412 if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc.flags) && 415 if (test_bit(ENTRY_TXD_ENCRYPT, &txdesc.flags) &&
413 !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc.flags) && 416 !test_bit(ENTRY_TXD_ENCRYPT_IV, &txdesc.flags)) {
414 (IEEE80211_SKB_CB(skb)->control.hw_key != NULL)) {
415 iv_len = IEEE80211_SKB_CB(skb)->control.hw_key->iv_len;
416 rt2x00crypto_tx_remove_iv(skb, iv_len); 417 rt2x00crypto_tx_remove_iv(skb, iv_len);
417 } 418 }
418 419
diff --git a/drivers/net/wireless/rtl8187_dev.c b/drivers/net/wireless/rtl8187_dev.c
index e9902613e2ee..431e3c78bf27 100644
--- a/drivers/net/wireless/rtl8187_dev.c
+++ b/drivers/net/wireless/rtl8187_dev.c
@@ -33,10 +33,13 @@ MODULE_LICENSE("GPL");
33static struct usb_device_id rtl8187_table[] __devinitdata = { 33static struct usb_device_id rtl8187_table[] __devinitdata = {
34 /* Asus */ 34 /* Asus */
35 {USB_DEVICE(0x0b05, 0x171d), .driver_info = DEVICE_RTL8187}, 35 {USB_DEVICE(0x0b05, 0x171d), .driver_info = DEVICE_RTL8187},
36 /* Belkin */
37 {USB_DEVICE(0x050d, 0x705e), .driver_info = DEVICE_RTL8187B},
36 /* Realtek */ 38 /* Realtek */
37 {USB_DEVICE(0x0bda, 0x8187), .driver_info = DEVICE_RTL8187}, 39 {USB_DEVICE(0x0bda, 0x8187), .driver_info = DEVICE_RTL8187},
38 {USB_DEVICE(0x0bda, 0x8189), .driver_info = DEVICE_RTL8187B}, 40 {USB_DEVICE(0x0bda, 0x8189), .driver_info = DEVICE_RTL8187B},
39 {USB_DEVICE(0x0bda, 0x8197), .driver_info = DEVICE_RTL8187B}, 41 {USB_DEVICE(0x0bda, 0x8197), .driver_info = DEVICE_RTL8187B},
42 {USB_DEVICE(0x0bda, 0x8198), .driver_info = DEVICE_RTL8187B},
40 /* Netgear */ 43 /* Netgear */
41 {USB_DEVICE(0x0846, 0x6100), .driver_info = DEVICE_RTL8187}, 44 {USB_DEVICE(0x0846, 0x6100), .driver_info = DEVICE_RTL8187},
42 {USB_DEVICE(0x0846, 0x6a00), .driver_info = DEVICE_RTL8187}, 45 {USB_DEVICE(0x0846, 0x6a00), .driver_info = DEVICE_RTL8187},
diff --git a/drivers/net/wireless/spectrum_cs.c b/drivers/net/wireless/spectrum_cs.c
index 67b26d3c3cd5..852789ad34b3 100644
--- a/drivers/net/wireless/spectrum_cs.c
+++ b/drivers/net/wireless/spectrum_cs.c
@@ -235,6 +235,70 @@ static void spectrum_cs_detach(struct pcmcia_device *link)
235 * device available to the system. 235 * device available to the system.
236 */ 236 */
237 237
238static int spectrum_cs_config_check(struct pcmcia_device *p_dev,
239 cistpl_cftable_entry_t *cfg,
240 cistpl_cftable_entry_t *dflt,
241 unsigned int vcc,
242 void *priv_data)
243{
244 if (cfg->index == 0)
245 goto next_entry;
246
247 /* Use power settings for Vcc and Vpp if present */
248 /* Note that the CIS values need to be rescaled */
249 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
250 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
251 DEBUG(2, "spectrum_cs_config: Vcc mismatch (vcc = %d, CIS = %d)\n", vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
252 if (!ignore_cis_vcc)
253 goto next_entry;
254 }
255 } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
256 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] / 10000) {
257 DEBUG(2, "spectrum_cs_config: Vcc mismatch (vcc = %d, CIS = %d)\n", vcc, dflt->vcc.param[CISTPL_POWER_VNOM] / 10000);
258 if (!ignore_cis_vcc)
259 goto next_entry;
260 }
261 }
262
263 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
264 p_dev->conf.Vpp =
265 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
266 else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
267 p_dev->conf.Vpp =
268 dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
269
270 /* Do we need to allocate an interrupt? */
271 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
272
273 /* IO window settings */
274 p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
275 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
276 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
277 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
278 if (!(io->flags & CISTPL_IO_8BIT))
279 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
280 if (!(io->flags & CISTPL_IO_16BIT))
281 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
282 p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
283 p_dev->io.BasePort1 = io->win[0].base;
284 p_dev->io.NumPorts1 = io->win[0].len;
285 if (io->nwin > 1) {
286 p_dev->io.Attributes2 = p_dev->io.Attributes1;
287 p_dev->io.BasePort2 = io->win[1].base;
288 p_dev->io.NumPorts2 = io->win[1].len;
289 }
290
291 /* This reserves IO space but doesn't actually enable it */
292 if (pcmcia_request_io(p_dev, &p_dev->io) != 0)
293 goto next_entry;
294 }
295 return 0;
296
297next_entry:
298 pcmcia_disable_device(p_dev);
299 return -ENODEV;
300};
301
238static int 302static int
239spectrum_cs_config(struct pcmcia_device *link) 303spectrum_cs_config(struct pcmcia_device *link)
240{ 304{
@@ -243,16 +307,8 @@ spectrum_cs_config(struct pcmcia_device *link)
243 struct orinoco_pccard *card = priv->card; 307 struct orinoco_pccard *card = priv->card;
244 hermes_t *hw = &priv->hw; 308 hermes_t *hw = &priv->hw;
245 int last_fn, last_ret; 309 int last_fn, last_ret;
246 u_char buf[64];
247 config_info_t conf;
248 tuple_t tuple;
249 cisparse_t parse;
250 void __iomem *mem; 310 void __iomem *mem;
251 311
252 /* Look up the current Vcc */
253 CS_CHECK(GetConfigurationInfo,
254 pcmcia_get_configuration_info(link, &conf));
255
256 /* 312 /*
257 * In this loop, we scan the CIS for configuration table 313 * In this loop, we scan the CIS for configuration table
258 * entries, each of which describes a valid card 314 * entries, each of which describes a valid card
@@ -267,94 +323,14 @@ spectrum_cs_config(struct pcmcia_device *link)
267 * and most client drivers will only use the CIS to fill in 323 * and most client drivers will only use the CIS to fill in
268 * implementation-defined details. 324 * implementation-defined details.
269 */ 325 */
270 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 326 last_ret = pcmcia_loop_config(link, spectrum_cs_config_check, NULL);
271 tuple.Attributes = 0; 327 if (last_ret) {
272 tuple.TupleData = buf; 328 if (!ignore_cis_vcc)
273 tuple.TupleDataMax = sizeof(buf);
274 tuple.TupleOffset = 0;
275 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
276 while (1) {
277 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
278 cistpl_cftable_entry_t dflt = { .index = 0 };
279
280 if ( (pcmcia_get_tuple_data(link, &tuple) != 0)
281 || (pcmcia_parse_tuple(link, &tuple, &parse) != 0))
282 goto next_entry;
283
284 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
285 dflt = *cfg;
286 if (cfg->index == 0)
287 goto next_entry;
288 link->conf.ConfigIndex = cfg->index;
289
290 /* Use power settings for Vcc and Vpp if present */
291 /* Note that the CIS values need to be rescaled */
292 if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
293 if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
294 DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
295 if (!ignore_cis_vcc)
296 goto next_entry;
297 }
298 } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
299 if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / 10000) {
300 DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n", conf.Vcc, dflt.vcc.param[CISTPL_POWER_VNOM] / 10000);
301 if(!ignore_cis_vcc)
302 goto next_entry;
303 }
304 }
305
306 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
307 link->conf.Vpp =
308 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
309 else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
310 link->conf.Vpp =
311 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
312
313 /* Do we need to allocate an interrupt? */
314 link->conf.Attributes |= CONF_ENABLE_IRQ;
315
316 /* IO window settings */
317 link->io.NumPorts1 = link->io.NumPorts2 = 0;
318 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
319 cistpl_io_t *io =
320 (cfg->io.nwin) ? &cfg->io : &dflt.io;
321 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
322 if (!(io->flags & CISTPL_IO_8BIT))
323 link->io.Attributes1 =
324 IO_DATA_PATH_WIDTH_16;
325 if (!(io->flags & CISTPL_IO_16BIT))
326 link->io.Attributes1 =
327 IO_DATA_PATH_WIDTH_8;
328 link->io.IOAddrLines =
329 io->flags & CISTPL_IO_LINES_MASK;
330 link->io.BasePort1 = io->win[0].base;
331 link->io.NumPorts1 = io->win[0].len;
332 if (io->nwin > 1) {
333 link->io.Attributes2 =
334 link->io.Attributes1;
335 link->io.BasePort2 = io->win[1].base;
336 link->io.NumPorts2 = io->win[1].len;
337 }
338
339 /* This reserves IO space but doesn't actually enable it */
340 if (pcmcia_request_io(link, &link->io) != 0)
341 goto next_entry;
342 }
343
344
345 /* If we got this far, we're cool! */
346
347 break;
348
349 next_entry:
350 pcmcia_disable_device(link);
351 last_ret = pcmcia_get_next_tuple(link, &tuple);
352 if (last_ret == CS_NO_MORE_ITEMS) {
353 printk(KERN_ERR PFX "GetNextTuple(): No matching " 329 printk(KERN_ERR PFX "GetNextTuple(): No matching "
354 "CIS configuration. Maybe you need the " 330 "CIS configuration. Maybe you need the "
355 "ignore_cis_vcc=1 parameter.\n"); 331 "ignore_cis_vcc=1 parameter.\n");
356 goto cs_failed; 332 cs_error(link, RequestIO, last_ret);
357 } 333 goto failed;
358 } 334 }
359 335
360 /* 336 /*
@@ -450,10 +426,11 @@ spectrum_cs_suspend(struct pcmcia_device *link)
450{ 426{
451 struct net_device *dev = link->priv; 427 struct net_device *dev = link->priv;
452 struct orinoco_private *priv = netdev_priv(dev); 428 struct orinoco_private *priv = netdev_priv(dev);
429 unsigned long flags;
453 int err = 0; 430 int err = 0;
454 431
455 /* Mark the device as stopped, to block IO until later */ 432 /* Mark the device as stopped, to block IO until later */
456 spin_lock(&priv->lock); 433 spin_lock_irqsave(&priv->lock, flags);
457 434
458 err = __orinoco_down(dev); 435 err = __orinoco_down(dev);
459 if (err) 436 if (err)
@@ -463,7 +440,7 @@ spectrum_cs_suspend(struct pcmcia_device *link)
463 netif_device_detach(dev); 440 netif_device_detach(dev);
464 priv->hw_unavailable++; 441 priv->hw_unavailable++;
465 442
466 spin_unlock(&priv->lock); 443 spin_unlock_irqrestore(&priv->lock, flags);
467 444
468 return err; 445 return err;
469} 446}
diff --git a/drivers/net/wireless/wavelan.c b/drivers/net/wireless/wavelan.c
index 136220b5ca81..e939a73ff794 100644
--- a/drivers/net/wireless/wavelan.c
+++ b/drivers/net/wireless/wavelan.c
@@ -4387,7 +4387,7 @@ MODULE_LICENSE("GPL");
4387 * 4387 *
4388 * Thanks go also to: 4388 * Thanks go also to:
4389 * James Ashton (jaa101@syseng.anu.edu.au), 4389 * James Ashton (jaa101@syseng.anu.edu.au),
4390 * Alan Cox (alan@redhat.com), 4390 * Alan Cox (alan@lxorguk.ukuu.org.uk),
4391 * Allan Creighton (allanc@cs.usyd.edu.au), 4391 * Allan Creighton (allanc@cs.usyd.edu.au),
4392 * Matthew Geier (matthew@cs.usyd.edu.au), 4392 * Matthew Geier (matthew@cs.usyd.edu.au),
4393 * Remo di Giovanni (remo@cs.usyd.edu.au), 4393 * Remo di Giovanni (remo@cs.usyd.edu.au),
diff --git a/drivers/net/wireless/wavelan.p.h b/drivers/net/wireless/wavelan.p.h
index b33ac47dd8df..44d31bbf39e4 100644
--- a/drivers/net/wireless/wavelan.p.h
+++ b/drivers/net/wireless/wavelan.p.h
@@ -186,7 +186,7 @@
186 * 186 *
187 * Thanks go also to: 187 * Thanks go also to:
188 * James Ashton <jaa101@syseng.anu.edu.au>, 188 * James Ashton <jaa101@syseng.anu.edu.au>,
189 * Alan Cox <alan@redhat.com>, 189 * Alan Cox <alan@lxorguk.ukuu.org.uk>,
190 * Allan Creighton <allanc@cs.usyd.edu.au>, 190 * Allan Creighton <allanc@cs.usyd.edu.au>,
191 * Matthew Geier <matthew@cs.usyd.edu.au>, 191 * Matthew Geier <matthew@cs.usyd.edu.au>,
192 * Remo di Giovanni <remo@cs.usyd.edu.au>, 192 * Remo di Giovanni <remo@cs.usyd.edu.au>,
diff --git a/drivers/net/wireless/wavelan_cs.c b/drivers/net/wireless/wavelan_cs.c
index b5de38a9b791..e124b1d6267a 100644
--- a/drivers/net/wireless/wavelan_cs.c
+++ b/drivers/net/wireless/wavelan_cs.c
@@ -3702,7 +3702,7 @@ wv_pcmcia_reset(struct net_device * dev)
3702#endif 3702#endif
3703 3703
3704 i = pcmcia_access_configuration_register(link, &reg); 3704 i = pcmcia_access_configuration_register(link, &reg);
3705 if(i != CS_SUCCESS) 3705 if (i != 0)
3706 { 3706 {
3707 cs_error(link, AccessConfigurationRegister, i); 3707 cs_error(link, AccessConfigurationRegister, i);
3708 return FALSE; 3708 return FALSE;
@@ -3716,7 +3716,7 @@ wv_pcmcia_reset(struct net_device * dev)
3716 reg.Action = CS_WRITE; 3716 reg.Action = CS_WRITE;
3717 reg.Value = reg.Value | COR_SW_RESET; 3717 reg.Value = reg.Value | COR_SW_RESET;
3718 i = pcmcia_access_configuration_register(link, &reg); 3718 i = pcmcia_access_configuration_register(link, &reg);
3719 if(i != CS_SUCCESS) 3719 if (i != 0)
3720 { 3720 {
3721 cs_error(link, AccessConfigurationRegister, i); 3721 cs_error(link, AccessConfigurationRegister, i);
3722 return FALSE; 3722 return FALSE;
@@ -3725,7 +3725,7 @@ wv_pcmcia_reset(struct net_device * dev)
3725 reg.Action = CS_WRITE; 3725 reg.Action = CS_WRITE;
3726 reg.Value = COR_LEVEL_IRQ | COR_CONFIG; 3726 reg.Value = COR_LEVEL_IRQ | COR_CONFIG;
3727 i = pcmcia_access_configuration_register(link, &reg); 3727 i = pcmcia_access_configuration_register(link, &reg);
3728 if(i != CS_SUCCESS) 3728 if (i != 0)
3729 { 3729 {
3730 cs_error(link, AccessConfigurationRegister, i); 3730 cs_error(link, AccessConfigurationRegister, i);
3731 return FALSE; 3731 return FALSE;
@@ -3903,7 +3903,7 @@ wv_pcmcia_config(struct pcmcia_device * link)
3903 do 3903 do
3904 { 3904 {
3905 i = pcmcia_request_io(link, &link->io); 3905 i = pcmcia_request_io(link, &link->io);
3906 if(i != CS_SUCCESS) 3906 if (i != 0)
3907 { 3907 {
3908 cs_error(link, RequestIO, i); 3908 cs_error(link, RequestIO, i);
3909 break; 3909 break;
@@ -3914,7 +3914,7 @@ wv_pcmcia_config(struct pcmcia_device * link)
3914 * actually assign a handler to the interrupt. 3914 * actually assign a handler to the interrupt.
3915 */ 3915 */
3916 i = pcmcia_request_irq(link, &link->irq); 3916 i = pcmcia_request_irq(link, &link->irq);
3917 if(i != CS_SUCCESS) 3917 if (i != 0)
3918 { 3918 {
3919 cs_error(link, RequestIRQ, i); 3919 cs_error(link, RequestIRQ, i);
3920 break; 3920 break;
@@ -3926,7 +3926,7 @@ wv_pcmcia_config(struct pcmcia_device * link)
3926 */ 3926 */
3927 link->conf.ConfigIndex = 1; 3927 link->conf.ConfigIndex = 1;
3928 i = pcmcia_request_configuration(link, &link->conf); 3928 i = pcmcia_request_configuration(link, &link->conf);
3929 if(i != CS_SUCCESS) 3929 if (i != 0)
3930 { 3930 {
3931 cs_error(link, RequestConfiguration, i); 3931 cs_error(link, RequestConfiguration, i);
3932 break; 3932 break;
@@ -3942,7 +3942,7 @@ wv_pcmcia_config(struct pcmcia_device * link)
3942 req.Base = req.Size = 0; 3942 req.Base = req.Size = 0;
3943 req.AccessSpeed = mem_speed; 3943 req.AccessSpeed = mem_speed;
3944 i = pcmcia_request_window(&link, &req, &link->win); 3944 i = pcmcia_request_window(&link, &req, &link->win);
3945 if(i != CS_SUCCESS) 3945 if (i != 0)
3946 { 3946 {
3947 cs_error(link, RequestWindow, i); 3947 cs_error(link, RequestWindow, i);
3948 break; 3948 break;
@@ -3954,7 +3954,7 @@ wv_pcmcia_config(struct pcmcia_device * link)
3954 3954
3955 mem.CardOffset = 0; mem.Page = 0; 3955 mem.CardOffset = 0; mem.Page = 0;
3956 i = pcmcia_map_mem_page(link->win, &mem); 3956 i = pcmcia_map_mem_page(link->win, &mem);
3957 if(i != CS_SUCCESS) 3957 if (i != 0)
3958 { 3958 {
3959 cs_error(link, MapMemPage, i); 3959 cs_error(link, MapMemPage, i);
3960 break; 3960 break;
diff --git a/drivers/net/wireless/wl3501_cs.c b/drivers/net/wireless/wl3501_cs.c
index 74a5ad2f1223..68789c6e1ce9 100644
--- a/drivers/net/wireless/wl3501_cs.c
+++ b/drivers/net/wireless/wl3501_cs.c
@@ -1977,10 +1977,10 @@ static int wl3501_config(struct pcmcia_device *link)
1977 link->io.BasePort1 = j; 1977 link->io.BasePort1 = j;
1978 link->io.BasePort2 = link->io.BasePort1 + 0x10; 1978 link->io.BasePort2 = link->io.BasePort1 + 0x10;
1979 i = pcmcia_request_io(link, &link->io); 1979 i = pcmcia_request_io(link, &link->io);
1980 if (i == CS_SUCCESS) 1980 if (i == 0)
1981 break; 1981 break;
1982 } 1982 }
1983 if (i != CS_SUCCESS) { 1983 if (i != 0) {
1984 cs_error(link, RequestIO, i); 1984 cs_error(link, RequestIO, i);
1985 goto failed; 1985 goto failed;
1986 } 1986 }
diff --git a/drivers/net/xen-netfront.c b/drivers/net/xen-netfront.c
index 3c3dd403f5dd..c6948d8f53f6 100644
--- a/drivers/net/xen-netfront.c
+++ b/drivers/net/xen-netfront.c
@@ -239,11 +239,14 @@ static void xennet_alloc_rx_buffers(struct net_device *dev)
239 */ 239 */
240 batch_target = np->rx_target - (req_prod - np->rx.rsp_cons); 240 batch_target = np->rx_target - (req_prod - np->rx.rsp_cons);
241 for (i = skb_queue_len(&np->rx_batch); i < batch_target; i++) { 241 for (i = skb_queue_len(&np->rx_batch); i < batch_target; i++) {
242 skb = __netdev_alloc_skb(dev, RX_COPY_THRESHOLD, 242 skb = __netdev_alloc_skb(dev, RX_COPY_THRESHOLD + NET_IP_ALIGN,
243 GFP_ATOMIC | __GFP_NOWARN); 243 GFP_ATOMIC | __GFP_NOWARN);
244 if (unlikely(!skb)) 244 if (unlikely(!skb))
245 goto no_skb; 245 goto no_skb;
246 246
247 /* Align ip header to a 16 bytes boundary */
248 skb_reserve(skb, NET_IP_ALIGN);
249
247 page = alloc_page(GFP_ATOMIC | __GFP_NOWARN); 250 page = alloc_page(GFP_ATOMIC | __GFP_NOWARN);
248 if (!page) { 251 if (!page) {
249 kfree_skb(skb); 252 kfree_skb(skb);
@@ -471,7 +474,7 @@ static int xennet_start_xmit(struct sk_buff *skb, struct net_device *dev)
471 unsigned int offset = offset_in_page(data); 474 unsigned int offset = offset_in_page(data);
472 unsigned int len = skb_headlen(skb); 475 unsigned int len = skb_headlen(skb);
473 476
474 frags += (offset + len + PAGE_SIZE - 1) / PAGE_SIZE; 477 frags += DIV_ROUND_UP(offset + len, PAGE_SIZE);
475 if (unlikely(frags > MAX_SKB_FRAGS + 1)) { 478 if (unlikely(frags > MAX_SKB_FRAGS + 1)) {
476 printk(KERN_ALERT "xennet: skb rides the rocket: %d frags\n", 479 printk(KERN_ALERT "xennet: skb rides the rocket: %d frags\n",
477 frags); 480 frags);
diff --git a/drivers/nubus/nubus.c b/drivers/nubus/nubus.c
index 2f047e573d86..f5f75844954c 100644
--- a/drivers/nubus/nubus.c
+++ b/drivers/nubus/nubus.c
@@ -126,7 +126,7 @@ static void nubus_advance(unsigned char **ptr, int len, int map)
126 { 126 {
127 while(not_useful(p,map)) 127 while(not_useful(p,map))
128 p++; 128 p++;
129 p++; 129 p++;
130 len--; 130 len--;
131 } 131 }
132 *ptr = p; 132 *ptr = p;
diff --git a/drivers/of/base.c b/drivers/of/base.c
index ad8ac1a8af28..7c79e94a35ea 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -410,7 +410,7 @@ struct of_modalias_table {
410 char *modalias; 410 char *modalias;
411}; 411};
412static struct of_modalias_table of_modalias_table[] = { 412static struct of_modalias_table of_modalias_table[] = {
413 /* Empty for now; add entries as needed */ 413 { "fsl,mcu-mpc8349emitx", "mcu-mpc8349emitx" },
414}; 414};
415 415
416/** 416/**
@@ -420,13 +420,12 @@ static struct of_modalias_table of_modalias_table[] = {
420 * @len: Length of modalias value 420 * @len: Length of modalias value
421 * 421 *
422 * Based on the value of the compatible property, this routine will determine 422 * Based on the value of the compatible property, this routine will determine
423 * an appropriate modalias value for a particular device tree node. Three 423 * an appropriate modalias value for a particular device tree node. Two
424 * separate methods are used to derive a modalias value. 424 * separate methods are attempted to derive a modalias value.
425 * 425 *
426 * First method is to lookup the compatible value in of_modalias_table. 426 * First method is to lookup the compatible value in of_modalias_table.
427 * Second is to look for a "linux,<modalias>" entry in the compatible list 427 * Second is to strip off the manufacturer prefix from the first
428 * and used that for modalias. Third is to strip off the manufacturer 428 * compatible entry and use the remainder as modalias
429 * prefix from the first compatible entry and use the remainder as modalias
430 * 429 *
431 * This routine returns 0 on success 430 * This routine returns 0 on success
432 */ 431 */
@@ -449,21 +448,7 @@ int of_modalias_node(struct device_node *node, char *modalias, int len)
449 if (!compatible) 448 if (!compatible)
450 return -ENODEV; 449 return -ENODEV;
451 450
452 /* 2. search for linux,<modalias> entry */ 451 /* 2. take first compatible entry and strip manufacturer */
453 p = compatible;
454 while (cplen > 0) {
455 if (!strncmp(p, "linux,", 6)) {
456 p += 6;
457 strlcpy(modalias, p, len);
458 return 0;
459 }
460
461 i = strlen(p) + 1;
462 p += i;
463 cplen -= i;
464 }
465
466 /* 3. take first compatible entry and strip manufacturer */
467 p = strchr(compatible, ','); 452 p = strchr(compatible, ',');
468 if (!p) 453 if (!p)
469 return -ENODEV; 454 return -ENODEV;
@@ -473,3 +458,112 @@ int of_modalias_node(struct device_node *node, char *modalias, int len)
473} 458}
474EXPORT_SYMBOL_GPL(of_modalias_node); 459EXPORT_SYMBOL_GPL(of_modalias_node);
475 460
461/**
462 * of_parse_phandles_with_args - Find a node pointed by phandle in a list
463 * @np: pointer to a device tree node containing a list
464 * @list_name: property name that contains a list
465 * @cells_name: property name that specifies phandles' arguments count
466 * @index: index of a phandle to parse out
467 * @out_node: pointer to device_node struct pointer (will be filled)
468 * @out_args: pointer to arguments pointer (will be filled)
469 *
470 * This function is useful to parse lists of phandles and their arguments.
471 * Returns 0 on success and fills out_node and out_args, on error returns
472 * appropriate errno value.
473 *
474 * Example:
475 *
476 * phandle1: node1 {
477 * #list-cells = <2>;
478 * }
479 *
480 * phandle2: node2 {
481 * #list-cells = <1>;
482 * }
483 *
484 * node3 {
485 * list = <&phandle1 1 2 &phandle2 3>;
486 * }
487 *
488 * To get a device_node of the `node2' node you may call this:
489 * of_parse_phandles_with_args(node3, "list", "#list-cells", 2, &node2, &args);
490 */
491int of_parse_phandles_with_args(struct device_node *np, const char *list_name,
492 const char *cells_name, int index,
493 struct device_node **out_node,
494 const void **out_args)
495{
496 int ret = -EINVAL;
497 const u32 *list;
498 const u32 *list_end;
499 int size;
500 int cur_index = 0;
501 struct device_node *node = NULL;
502 const void *args;
503
504 list = of_get_property(np, list_name, &size);
505 if (!list) {
506 ret = -ENOENT;
507 goto err0;
508 }
509 list_end = list + size / sizeof(*list);
510
511 while (list < list_end) {
512 const u32 *cells;
513 const phandle *phandle;
514
515 phandle = list;
516 args = list + 1;
517
518 /* one cell hole in the list = <>; */
519 if (!*phandle) {
520 list++;
521 goto next;
522 }
523
524 node = of_find_node_by_phandle(*phandle);
525 if (!node) {
526 pr_debug("%s: could not find phandle\n",
527 np->full_name);
528 goto err0;
529 }
530
531 cells = of_get_property(node, cells_name, &size);
532 if (!cells || size != sizeof(*cells)) {
533 pr_debug("%s: could not get %s for %s\n",
534 np->full_name, cells_name, node->full_name);
535 goto err1;
536 }
537
538 /* Next phandle is at offset of one phandle cell + #cells */
539 list += 1 + *cells;
540 if (list > list_end) {
541 pr_debug("%s: insufficient arguments length\n",
542 np->full_name);
543 goto err1;
544 }
545next:
546 if (cur_index == index)
547 break;
548
549 of_node_put(node);
550 node = NULL;
551 cur_index++;
552 }
553
554 if (!node) {
555 ret = -ENOENT;
556 goto err0;
557 }
558
559 *out_node = node;
560 *out_args = args;
561
562 return 0;
563err1:
564 of_node_put(node);
565err0:
566 pr_debug("%s failed with status %d\n", __func__, ret);
567 return ret;
568}
569EXPORT_SYMBOL(of_parse_phandles_with_args);
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index 1c9cab844f10..7cd7301b5839 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -28,78 +28,35 @@
28 */ 28 */
29int of_get_gpio(struct device_node *np, int index) 29int of_get_gpio(struct device_node *np, int index)
30{ 30{
31 int ret = -EINVAL; 31 int ret;
32 struct device_node *gc; 32 struct device_node *gc;
33 struct of_gpio_chip *of_gc = NULL; 33 struct of_gpio_chip *of_gc = NULL;
34 int size; 34 int size;
35 const u32 *gpios;
36 u32 nr_cells;
37 int i;
38 const void *gpio_spec; 35 const void *gpio_spec;
39 const u32 *gpio_cells; 36 const u32 *gpio_cells;
40 int gpio_index = 0;
41 37
42 gpios = of_get_property(np, "gpios", &size); 38 ret = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", index,
43 if (!gpios) { 39 &gc, &gpio_spec);
44 ret = -ENOENT; 40 if (ret) {
41 pr_debug("%s: can't parse gpios property\n", __func__);
45 goto err0; 42 goto err0;
46 } 43 }
47 nr_cells = size / sizeof(u32);
48
49 for (i = 0; i < nr_cells; gpio_index++) {
50 const phandle *gpio_phandle;
51
52 gpio_phandle = gpios + i;
53 gpio_spec = gpio_phandle + 1;
54
55 /* one cell hole in the gpios = <>; */
56 if (!*gpio_phandle) {
57 if (gpio_index == index)
58 return -ENOENT;
59 i++;
60 continue;
61 }
62
63 gc = of_find_node_by_phandle(*gpio_phandle);
64 if (!gc) {
65 pr_debug("%s: could not find phandle for gpios\n",
66 np->full_name);
67 goto err0;
68 }
69
70 of_gc = gc->data;
71 if (!of_gc) {
72 pr_debug("%s: gpio controller %s isn't registered\n",
73 np->full_name, gc->full_name);
74 goto err1;
75 }
76
77 gpio_cells = of_get_property(gc, "#gpio-cells", &size);
78 if (!gpio_cells || size != sizeof(*gpio_cells) ||
79 *gpio_cells != of_gc->gpio_cells) {
80 pr_debug("%s: wrong #gpio-cells for %s\n",
81 np->full_name, gc->full_name);
82 goto err1;
83 }
84
85 /* Next phandle is at phandle cells + #gpio-cells */
86 i += sizeof(*gpio_phandle) / sizeof(u32) + *gpio_cells;
87 if (i >= nr_cells + 1) {
88 pr_debug("%s: insufficient gpio-spec length\n",
89 np->full_name);
90 goto err1;
91 }
92
93 if (gpio_index == index)
94 break;
95
96 of_gc = NULL;
97 of_node_put(gc);
98 }
99 44
45 of_gc = gc->data;
100 if (!of_gc) { 46 if (!of_gc) {
101 ret = -ENOENT; 47 pr_debug("%s: gpio controller %s isn't registered\n",
102 goto err0; 48 np->full_name, gc->full_name);
49 ret = -ENODEV;
50 goto err1;
51 }
52
53 gpio_cells = of_get_property(gc, "#gpio-cells", &size);
54 if (!gpio_cells || size != sizeof(*gpio_cells) ||
55 *gpio_cells != of_gc->gpio_cells) {
56 pr_debug("%s: wrong #gpio-cells for %s\n",
57 np->full_name, gc->full_name);
58 ret = -EINVAL;
59 goto err1;
103 } 60 }
104 61
105 ret = of_gc->xlate(of_gc, np, gpio_spec); 62 ret = of_gc->xlate(of_gc, np, gpio_spec);
diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
index 9304c4555079..ed982273fb8b 100644
--- a/drivers/oprofile/buffer_sync.c
+++ b/drivers/oprofile/buffer_sync.c
@@ -5,6 +5,7 @@
5 * @remark Read the file COPYING 5 * @remark Read the file COPYING
6 * 6 *
7 * @author John Levon <levon@movementarian.org> 7 * @author John Levon <levon@movementarian.org>
8 * @author Barry Kasindorf
8 * 9 *
9 * This is the core of the buffer management. Each 10 * This is the core of the buffer management. Each
10 * CPU buffer is processed and entered into the 11 * CPU buffer is processed and entered into the
@@ -33,7 +34,7 @@
33#include "event_buffer.h" 34#include "event_buffer.h"
34#include "cpu_buffer.h" 35#include "cpu_buffer.h"
35#include "buffer_sync.h" 36#include "buffer_sync.h"
36 37
37static LIST_HEAD(dying_tasks); 38static LIST_HEAD(dying_tasks);
38static LIST_HEAD(dead_tasks); 39static LIST_HEAD(dead_tasks);
39static cpumask_t marked_cpus = CPU_MASK_NONE; 40static cpumask_t marked_cpus = CPU_MASK_NONE;
@@ -48,10 +49,11 @@ static void process_task_mortuary(void);
48 * Can be invoked from softirq via RCU callback due to 49 * Can be invoked from softirq via RCU callback due to
49 * call_rcu() of the task struct, hence the _irqsave. 50 * call_rcu() of the task struct, hence the _irqsave.
50 */ 51 */
51static int task_free_notify(struct notifier_block * self, unsigned long val, void * data) 52static int
53task_free_notify(struct notifier_block *self, unsigned long val, void *data)
52{ 54{
53 unsigned long flags; 55 unsigned long flags;
54 struct task_struct * task = data; 56 struct task_struct *task = data;
55 spin_lock_irqsave(&task_mortuary, flags); 57 spin_lock_irqsave(&task_mortuary, flags);
56 list_add(&task->tasks, &dying_tasks); 58 list_add(&task->tasks, &dying_tasks);
57 spin_unlock_irqrestore(&task_mortuary, flags); 59 spin_unlock_irqrestore(&task_mortuary, flags);
@@ -62,13 +64,14 @@ static int task_free_notify(struct notifier_block * self, unsigned long val, voi
62/* The task is on its way out. A sync of the buffer means we can catch 64/* The task is on its way out. A sync of the buffer means we can catch
63 * any remaining samples for this task. 65 * any remaining samples for this task.
64 */ 66 */
65static int task_exit_notify(struct notifier_block * self, unsigned long val, void * data) 67static int
68task_exit_notify(struct notifier_block *self, unsigned long val, void *data)
66{ 69{
67 /* To avoid latency problems, we only process the current CPU, 70 /* To avoid latency problems, we only process the current CPU,
68 * hoping that most samples for the task are on this CPU 71 * hoping that most samples for the task are on this CPU
69 */ 72 */
70 sync_buffer(raw_smp_processor_id()); 73 sync_buffer(raw_smp_processor_id());
71 return 0; 74 return 0;
72} 75}
73 76
74 77
@@ -77,11 +80,12 @@ static int task_exit_notify(struct notifier_block * self, unsigned long val, voi
77 * we don't lose any. This does not have to be exact, it's a QoI issue 80 * we don't lose any. This does not have to be exact, it's a QoI issue
78 * only. 81 * only.
79 */ 82 */
80static int munmap_notify(struct notifier_block * self, unsigned long val, void * data) 83static int
84munmap_notify(struct notifier_block *self, unsigned long val, void *data)
81{ 85{
82 unsigned long addr = (unsigned long)data; 86 unsigned long addr = (unsigned long)data;
83 struct mm_struct * mm = current->mm; 87 struct mm_struct *mm = current->mm;
84 struct vm_area_struct * mpnt; 88 struct vm_area_struct *mpnt;
85 89
86 down_read(&mm->mmap_sem); 90 down_read(&mm->mmap_sem);
87 91
@@ -99,11 +103,12 @@ static int munmap_notify(struct notifier_block * self, unsigned long val, void *
99 return 0; 103 return 0;
100} 104}
101 105
102 106
103/* We need to be told about new modules so we don't attribute to a previously 107/* We need to be told about new modules so we don't attribute to a previously
104 * loaded module, or drop the samples on the floor. 108 * loaded module, or drop the samples on the floor.
105 */ 109 */
106static int module_load_notify(struct notifier_block * self, unsigned long val, void * data) 110static int
111module_load_notify(struct notifier_block *self, unsigned long val, void *data)
107{ 112{
108#ifdef CONFIG_MODULES 113#ifdef CONFIG_MODULES
109 if (val != MODULE_STATE_COMING) 114 if (val != MODULE_STATE_COMING)
@@ -118,7 +123,7 @@ static int module_load_notify(struct notifier_block * self, unsigned long val, v
118 return 0; 123 return 0;
119} 124}
120 125
121 126
122static struct notifier_block task_free_nb = { 127static struct notifier_block task_free_nb = {
123 .notifier_call = task_free_notify, 128 .notifier_call = task_free_notify,
124}; 129};
@@ -135,7 +140,7 @@ static struct notifier_block module_load_nb = {
135 .notifier_call = module_load_notify, 140 .notifier_call = module_load_notify,
136}; 141};
137 142
138 143
139static void end_sync(void) 144static void end_sync(void)
140{ 145{
141 end_cpu_work(); 146 end_cpu_work();
@@ -208,14 +213,14 @@ static inline unsigned long fast_get_dcookie(struct path *path)
208 * not strictly necessary but allows oprofile to associate 213 * not strictly necessary but allows oprofile to associate
209 * shared-library samples with particular applications 214 * shared-library samples with particular applications
210 */ 215 */
211static unsigned long get_exec_dcookie(struct mm_struct * mm) 216static unsigned long get_exec_dcookie(struct mm_struct *mm)
212{ 217{
213 unsigned long cookie = NO_COOKIE; 218 unsigned long cookie = NO_COOKIE;
214 struct vm_area_struct * vma; 219 struct vm_area_struct *vma;
215 220
216 if (!mm) 221 if (!mm)
217 goto out; 222 goto out;
218 223
219 for (vma = mm->mmap; vma; vma = vma->vm_next) { 224 for (vma = mm->mmap; vma; vma = vma->vm_next) {
220 if (!vma->vm_file) 225 if (!vma->vm_file)
221 continue; 226 continue;
@@ -235,13 +240,14 @@ out:
235 * sure to do this lookup before a mm->mmap modification happens so 240 * sure to do this lookup before a mm->mmap modification happens so
236 * we don't lose track. 241 * we don't lose track.
237 */ 242 */
238static unsigned long lookup_dcookie(struct mm_struct * mm, unsigned long addr, off_t * offset) 243static unsigned long
244lookup_dcookie(struct mm_struct *mm, unsigned long addr, off_t *offset)
239{ 245{
240 unsigned long cookie = NO_COOKIE; 246 unsigned long cookie = NO_COOKIE;
241 struct vm_area_struct * vma; 247 struct vm_area_struct *vma;
242 248
243 for (vma = find_vma(mm, addr); vma; vma = vma->vm_next) { 249 for (vma = find_vma(mm, addr); vma; vma = vma->vm_next) {
244 250
245 if (addr < vma->vm_start || addr >= vma->vm_end) 251 if (addr < vma->vm_start || addr >= vma->vm_end)
246 continue; 252 continue;
247 253
@@ -263,9 +269,20 @@ static unsigned long lookup_dcookie(struct mm_struct * mm, unsigned long addr, o
263 return cookie; 269 return cookie;
264} 270}
265 271
272static void increment_tail(struct oprofile_cpu_buffer *b)
273{
274 unsigned long new_tail = b->tail_pos + 1;
275
276 rmb(); /* be sure fifo pointers are synchromized */
277
278 if (new_tail < b->buffer_size)
279 b->tail_pos = new_tail;
280 else
281 b->tail_pos = 0;
282}
266 283
267static unsigned long last_cookie = INVALID_COOKIE; 284static unsigned long last_cookie = INVALID_COOKIE;
268 285
269static void add_cpu_switch(int i) 286static void add_cpu_switch(int i)
270{ 287{
271 add_event_entry(ESCAPE_CODE); 288 add_event_entry(ESCAPE_CODE);
@@ -278,16 +295,16 @@ static void add_kernel_ctx_switch(unsigned int in_kernel)
278{ 295{
279 add_event_entry(ESCAPE_CODE); 296 add_event_entry(ESCAPE_CODE);
280 if (in_kernel) 297 if (in_kernel)
281 add_event_entry(KERNEL_ENTER_SWITCH_CODE); 298 add_event_entry(KERNEL_ENTER_SWITCH_CODE);
282 else 299 else
283 add_event_entry(KERNEL_EXIT_SWITCH_CODE); 300 add_event_entry(KERNEL_EXIT_SWITCH_CODE);
284} 301}
285 302
286static void 303static void
287add_user_ctx_switch(struct task_struct const * task, unsigned long cookie) 304add_user_ctx_switch(struct task_struct const *task, unsigned long cookie)
288{ 305{
289 add_event_entry(ESCAPE_CODE); 306 add_event_entry(ESCAPE_CODE);
290 add_event_entry(CTX_SWITCH_CODE); 307 add_event_entry(CTX_SWITCH_CODE);
291 add_event_entry(task->pid); 308 add_event_entry(task->pid);
292 add_event_entry(cookie); 309 add_event_entry(cookie);
293 /* Another code for daemon back-compat */ 310 /* Another code for daemon back-compat */
@@ -296,7 +313,7 @@ add_user_ctx_switch(struct task_struct const * task, unsigned long cookie)
296 add_event_entry(task->tgid); 313 add_event_entry(task->tgid);
297} 314}
298 315
299 316
300static void add_cookie_switch(unsigned long cookie) 317static void add_cookie_switch(unsigned long cookie)
301{ 318{
302 add_event_entry(ESCAPE_CODE); 319 add_event_entry(ESCAPE_CODE);
@@ -304,13 +321,78 @@ static void add_cookie_switch(unsigned long cookie)
304 add_event_entry(cookie); 321 add_event_entry(cookie);
305} 322}
306 323
307 324
308static void add_trace_begin(void) 325static void add_trace_begin(void)
309{ 326{
310 add_event_entry(ESCAPE_CODE); 327 add_event_entry(ESCAPE_CODE);
311 add_event_entry(TRACE_BEGIN_CODE); 328 add_event_entry(TRACE_BEGIN_CODE);
312} 329}
313 330
331#ifdef CONFIG_OPROFILE_IBS
332
333#define IBS_FETCH_CODE_SIZE 2
334#define IBS_OP_CODE_SIZE 5
335#define IBS_EIP(offset) \
336 (((struct op_sample *)&cpu_buf->buffer[(offset)])->eip)
337#define IBS_EVENT(offset) \
338 (((struct op_sample *)&cpu_buf->buffer[(offset)])->event)
339
340/*
341 * Add IBS fetch and op entries to event buffer
342 */
343static void add_ibs_begin(struct oprofile_cpu_buffer *cpu_buf, int code,
344 int in_kernel, struct mm_struct *mm)
345{
346 unsigned long rip;
347 int i, count;
348 unsigned long ibs_cookie = 0;
349 off_t offset;
350
351 increment_tail(cpu_buf); /* move to RIP entry */
352
353 rip = IBS_EIP(cpu_buf->tail_pos);
354
355#ifdef __LP64__
356 rip += IBS_EVENT(cpu_buf->tail_pos) << 32;
357#endif
358
359 if (mm) {
360 ibs_cookie = lookup_dcookie(mm, rip, &offset);
361
362 if (ibs_cookie == NO_COOKIE)
363 offset = rip;
364 if (ibs_cookie == INVALID_COOKIE) {
365 atomic_inc(&oprofile_stats.sample_lost_no_mapping);
366 offset = rip;
367 }
368 if (ibs_cookie != last_cookie) {
369 add_cookie_switch(ibs_cookie);
370 last_cookie = ibs_cookie;
371 }
372 } else
373 offset = rip;
374
375 add_event_entry(ESCAPE_CODE);
376 add_event_entry(code);
377 add_event_entry(offset); /* Offset from Dcookie */
378
379 /* we send the Dcookie offset, but send the raw Linear Add also*/
380 add_event_entry(IBS_EIP(cpu_buf->tail_pos));
381 add_event_entry(IBS_EVENT(cpu_buf->tail_pos));
382
383 if (code == IBS_FETCH_CODE)
384 count = IBS_FETCH_CODE_SIZE; /*IBS FETCH is 2 int64s*/
385 else
386 count = IBS_OP_CODE_SIZE; /*IBS OP is 5 int64s*/
387
388 for (i = 0; i < count; i++) {
389 increment_tail(cpu_buf);
390 add_event_entry(IBS_EIP(cpu_buf->tail_pos));
391 add_event_entry(IBS_EVENT(cpu_buf->tail_pos));
392 }
393}
394
395#endif
314 396
315static void add_sample_entry(unsigned long offset, unsigned long event) 397static void add_sample_entry(unsigned long offset, unsigned long event)
316{ 398{
@@ -319,13 +401,13 @@ static void add_sample_entry(unsigned long offset, unsigned long event)
319} 401}
320 402
321 403
322static int add_us_sample(struct mm_struct * mm, struct op_sample * s) 404static int add_us_sample(struct mm_struct *mm, struct op_sample *s)
323{ 405{
324 unsigned long cookie; 406 unsigned long cookie;
325 off_t offset; 407 off_t offset;
326 408
327 cookie = lookup_dcookie(mm, s->eip, &offset); 409 cookie = lookup_dcookie(mm, s->eip, &offset);
328 410
329 if (cookie == INVALID_COOKIE) { 411 if (cookie == INVALID_COOKIE) {
330 atomic_inc(&oprofile_stats.sample_lost_no_mapping); 412 atomic_inc(&oprofile_stats.sample_lost_no_mapping);
331 return 0; 413 return 0;
@@ -341,13 +423,13 @@ static int add_us_sample(struct mm_struct * mm, struct op_sample * s)
341 return 1; 423 return 1;
342} 424}
343 425
344 426
345/* Add a sample to the global event buffer. If possible the 427/* Add a sample to the global event buffer. If possible the
346 * sample is converted into a persistent dentry/offset pair 428 * sample is converted into a persistent dentry/offset pair
347 * for later lookup from userspace. 429 * for later lookup from userspace.
348 */ 430 */
349static int 431static int
350add_sample(struct mm_struct * mm, struct op_sample * s, int in_kernel) 432add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
351{ 433{
352 if (in_kernel) { 434 if (in_kernel) {
353 add_sample_entry(s->eip, s->event); 435 add_sample_entry(s->eip, s->event);
@@ -359,9 +441,9 @@ add_sample(struct mm_struct * mm, struct op_sample * s, int in_kernel)
359 } 441 }
360 return 0; 442 return 0;
361} 443}
362
363 444
364static void release_mm(struct mm_struct * mm) 445
446static void release_mm(struct mm_struct *mm)
365{ 447{
366 if (!mm) 448 if (!mm)
367 return; 449 return;
@@ -370,9 +452,9 @@ static void release_mm(struct mm_struct * mm)
370} 452}
371 453
372 454
373static struct mm_struct * take_tasks_mm(struct task_struct * task) 455static struct mm_struct *take_tasks_mm(struct task_struct *task)
374{ 456{
375 struct mm_struct * mm = get_task_mm(task); 457 struct mm_struct *mm = get_task_mm(task);
376 if (mm) 458 if (mm)
377 down_read(&mm->mmap_sem); 459 down_read(&mm->mmap_sem);
378 return mm; 460 return mm;
@@ -383,10 +465,10 @@ static inline int is_code(unsigned long val)
383{ 465{
384 return val == ESCAPE_CODE; 466 return val == ESCAPE_CODE;
385} 467}
386 468
387 469
388/* "acquire" as many cpu buffer slots as we can */ 470/* "acquire" as many cpu buffer slots as we can */
389static unsigned long get_slots(struct oprofile_cpu_buffer * b) 471static unsigned long get_slots(struct oprofile_cpu_buffer *b)
390{ 472{
391 unsigned long head = b->head_pos; 473 unsigned long head = b->head_pos;
392 unsigned long tail = b->tail_pos; 474 unsigned long tail = b->tail_pos;
@@ -412,19 +494,6 @@ static unsigned long get_slots(struct oprofile_cpu_buffer * b)
412} 494}
413 495
414 496
415static void increment_tail(struct oprofile_cpu_buffer * b)
416{
417 unsigned long new_tail = b->tail_pos + 1;
418
419 rmb();
420
421 if (new_tail < b->buffer_size)
422 b->tail_pos = new_tail;
423 else
424 b->tail_pos = 0;
425}
426
427
428/* Move tasks along towards death. Any tasks on dead_tasks 497/* Move tasks along towards death. Any tasks on dead_tasks
429 * will definitely have no remaining references in any 498 * will definitely have no remaining references in any
430 * CPU buffers at this point, because we use two lists, 499 * CPU buffers at this point, because we use two lists,
@@ -435,8 +504,8 @@ static void process_task_mortuary(void)
435{ 504{
436 unsigned long flags; 505 unsigned long flags;
437 LIST_HEAD(local_dead_tasks); 506 LIST_HEAD(local_dead_tasks);
438 struct task_struct * task; 507 struct task_struct *task;
439 struct task_struct * ttask; 508 struct task_struct *ttask;
440 509
441 spin_lock_irqsave(&task_mortuary, flags); 510 spin_lock_irqsave(&task_mortuary, flags);
442 511
@@ -493,7 +562,7 @@ void sync_buffer(int cpu)
493{ 562{
494 struct oprofile_cpu_buffer *cpu_buf = &per_cpu(cpu_buffer, cpu); 563 struct oprofile_cpu_buffer *cpu_buf = &per_cpu(cpu_buffer, cpu);
495 struct mm_struct *mm = NULL; 564 struct mm_struct *mm = NULL;
496 struct task_struct * new; 565 struct task_struct *new;
497 unsigned long cookie = 0; 566 unsigned long cookie = 0;
498 int in_kernel = 1; 567 int in_kernel = 1;
499 unsigned int i; 568 unsigned int i;
@@ -501,7 +570,7 @@ void sync_buffer(int cpu)
501 unsigned long available; 570 unsigned long available;
502 571
503 mutex_lock(&buffer_mutex); 572 mutex_lock(&buffer_mutex);
504 573
505 add_cpu_switch(cpu); 574 add_cpu_switch(cpu);
506 575
507 /* Remember, only we can modify tail_pos */ 576 /* Remember, only we can modify tail_pos */
@@ -509,8 +578,8 @@ void sync_buffer(int cpu)
509 available = get_slots(cpu_buf); 578 available = get_slots(cpu_buf);
510 579
511 for (i = 0; i < available; ++i) { 580 for (i = 0; i < available; ++i) {
512 struct op_sample * s = &cpu_buf->buffer[cpu_buf->tail_pos]; 581 struct op_sample *s = &cpu_buf->buffer[cpu_buf->tail_pos];
513 582
514 if (is_code(s->eip)) { 583 if (is_code(s->eip)) {
515 if (s->event <= CPU_IS_KERNEL) { 584 if (s->event <= CPU_IS_KERNEL) {
516 /* kernel/userspace switch */ 585 /* kernel/userspace switch */
@@ -521,8 +590,18 @@ void sync_buffer(int cpu)
521 } else if (s->event == CPU_TRACE_BEGIN) { 590 } else if (s->event == CPU_TRACE_BEGIN) {
522 state = sb_bt_start; 591 state = sb_bt_start;
523 add_trace_begin(); 592 add_trace_begin();
593#ifdef CONFIG_OPROFILE_IBS
594 } else if (s->event == IBS_FETCH_BEGIN) {
595 state = sb_bt_start;
596 add_ibs_begin(cpu_buf,
597 IBS_FETCH_CODE, in_kernel, mm);
598 } else if (s->event == IBS_OP_BEGIN) {
599 state = sb_bt_start;
600 add_ibs_begin(cpu_buf,
601 IBS_OP_CODE, in_kernel, mm);
602#endif
524 } else { 603 } else {
525 struct mm_struct * oldmm = mm; 604 struct mm_struct *oldmm = mm;
526 605
527 /* userspace context switch */ 606 /* userspace context switch */
528 new = (struct task_struct *)s->event; 607 new = (struct task_struct *)s->event;
@@ -533,13 +612,11 @@ void sync_buffer(int cpu)
533 cookie = get_exec_dcookie(mm); 612 cookie = get_exec_dcookie(mm);
534 add_user_ctx_switch(new, cookie); 613 add_user_ctx_switch(new, cookie);
535 } 614 }
536 } else { 615 } else if (state >= sb_bt_start &&
537 if (state >= sb_bt_start && 616 !add_sample(mm, s, in_kernel)) {
538 !add_sample(mm, s, in_kernel)) { 617 if (state == sb_bt_start) {
539 if (state == sb_bt_start) { 618 state = sb_bt_ignore;
540 state = sb_bt_ignore; 619 atomic_inc(&oprofile_stats.bt_lost_no_mapping);
541 atomic_inc(&oprofile_stats.bt_lost_no_mapping);
542 }
543 } 620 }
544 } 621 }
545 622
diff --git a/drivers/oprofile/cpu_buffer.c b/drivers/oprofile/cpu_buffer.c
index 7ba78e6d210e..e1bd5a937f6c 100644
--- a/drivers/oprofile/cpu_buffer.c
+++ b/drivers/oprofile/cpu_buffer.c
@@ -5,6 +5,7 @@
5 * @remark Read the file COPYING 5 * @remark Read the file COPYING
6 * 6 *
7 * @author John Levon <levon@movementarian.org> 7 * @author John Levon <levon@movementarian.org>
8 * @author Barry Kasindorf <barry.kasindorf@amd.com>
8 * 9 *
9 * Each CPU has a local buffer that stores PC value/event 10 * Each CPU has a local buffer that stores PC value/event
10 * pairs. We also log context switches when we notice them. 11 * pairs. We also log context switches when we notice them.
@@ -209,7 +210,7 @@ static int log_sample(struct oprofile_cpu_buffer * cpu_buf, unsigned long pc,
209 return 1; 210 return 1;
210} 211}
211 212
212static int oprofile_begin_trace(struct oprofile_cpu_buffer * cpu_buf) 213static int oprofile_begin_trace(struct oprofile_cpu_buffer *cpu_buf)
213{ 214{
214 if (nr_available_slots(cpu_buf) < 4) { 215 if (nr_available_slots(cpu_buf) < 4) {
215 cpu_buf->sample_lost_overflow++; 216 cpu_buf->sample_lost_overflow++;
@@ -254,6 +255,75 @@ void oprofile_add_sample(struct pt_regs * const regs, unsigned long event)
254 oprofile_add_ext_sample(pc, regs, event, is_kernel); 255 oprofile_add_ext_sample(pc, regs, event, is_kernel);
255} 256}
256 257
258#ifdef CONFIG_OPROFILE_IBS
259
260#define MAX_IBS_SAMPLE_SIZE 14
261static int log_ibs_sample(struct oprofile_cpu_buffer *cpu_buf,
262 unsigned long pc, int is_kernel, unsigned int *ibs, int ibs_code)
263{
264 struct task_struct *task;
265
266 cpu_buf->sample_received++;
267
268 if (nr_available_slots(cpu_buf) < MAX_IBS_SAMPLE_SIZE) {
269 cpu_buf->sample_lost_overflow++;
270 return 0;
271 }
272
273 is_kernel = !!is_kernel;
274
275 /* notice a switch from user->kernel or vice versa */
276 if (cpu_buf->last_is_kernel != is_kernel) {
277 cpu_buf->last_is_kernel = is_kernel;
278 add_code(cpu_buf, is_kernel);
279 }
280
281 /* notice a task switch */
282 if (!is_kernel) {
283 task = current;
284
285 if (cpu_buf->last_task != task) {
286 cpu_buf->last_task = task;
287 add_code(cpu_buf, (unsigned long)task);
288 }
289 }
290
291 add_code(cpu_buf, ibs_code);
292 add_sample(cpu_buf, ibs[0], ibs[1]);
293 add_sample(cpu_buf, ibs[2], ibs[3]);
294 add_sample(cpu_buf, ibs[4], ibs[5]);
295
296 if (ibs_code == IBS_OP_BEGIN) {
297 add_sample(cpu_buf, ibs[6], ibs[7]);
298 add_sample(cpu_buf, ibs[8], ibs[9]);
299 add_sample(cpu_buf, ibs[10], ibs[11]);
300 }
301
302 return 1;
303}
304
305void oprofile_add_ibs_sample(struct pt_regs *const regs,
306 unsigned int * const ibs_sample, u8 code)
307{
308 int is_kernel = !user_mode(regs);
309 unsigned long pc = profile_pc(regs);
310
311 struct oprofile_cpu_buffer *cpu_buf =
312 &per_cpu(cpu_buffer, smp_processor_id());
313
314 if (!backtrace_depth) {
315 log_ibs_sample(cpu_buf, pc, is_kernel, ibs_sample, code);
316 return;
317 }
318
319 /* if log_sample() fails we can't backtrace since we lost the source
320 * of this event */
321 if (log_ibs_sample(cpu_buf, pc, is_kernel, ibs_sample, code))
322 oprofile_ops.backtrace(regs, backtrace_depth);
323}
324
325#endif
326
257void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event) 327void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event)
258{ 328{
259 struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer); 329 struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer);
@@ -296,7 +366,7 @@ static void wq_sync_buffer(struct work_struct *work)
296 struct oprofile_cpu_buffer * b = 366 struct oprofile_cpu_buffer * b =
297 container_of(work, struct oprofile_cpu_buffer, work.work); 367 container_of(work, struct oprofile_cpu_buffer, work.work);
298 if (b->cpu != smp_processor_id()) { 368 if (b->cpu != smp_processor_id()) {
299 printk("WQ on CPU%d, prefer CPU%d\n", 369 printk(KERN_DEBUG "WQ on CPU%d, prefer CPU%d\n",
300 smp_processor_id(), b->cpu); 370 smp_processor_id(), b->cpu);
301 } 371 }
302 sync_buffer(b->cpu); 372 sync_buffer(b->cpu);
diff --git a/drivers/oprofile/cpu_buffer.h b/drivers/oprofile/cpu_buffer.h
index c3e366b52261..9c44d004da69 100644
--- a/drivers/oprofile/cpu_buffer.h
+++ b/drivers/oprofile/cpu_buffer.h
@@ -55,5 +55,7 @@ void cpu_buffer_reset(struct oprofile_cpu_buffer * cpu_buf);
55/* transient events for the CPU buffer -> event buffer */ 55/* transient events for the CPU buffer -> event buffer */
56#define CPU_IS_KERNEL 1 56#define CPU_IS_KERNEL 1
57#define CPU_TRACE_BEGIN 2 57#define CPU_TRACE_BEGIN 2
58#define IBS_FETCH_BEGIN 3
59#define IBS_OP_BEGIN 4
58 60
59#endif /* OPROFILE_CPU_BUFFER_H */ 61#endif /* OPROFILE_CPU_BUFFER_H */
diff --git a/drivers/parport/ChangeLog b/drivers/parport/ChangeLog
index db717c1d62a5..8565bbbeb6ec 100644
--- a/drivers/parport/ChangeLog
+++ b/drivers/parport/ChangeLog
@@ -311,7 +311,7 @@
311 * ieee1284_ops.c (parport_ieee1284_read_nibble): Reset nAutoFd 311 * ieee1284_ops.c (parport_ieee1284_read_nibble): Reset nAutoFd
312 on timeout. Matches 2.2.x behaviour. 312 on timeout. Matches 2.2.x behaviour.
313 313
3142001-03-02 Andrew Morton <andrewm@uow.edu.au> 3142001-03-02 Andrew Morton
315 315
316 * parport_pc.c (registered_parport): New static variable. 316 * parport_pc.c (registered_parport): New static variable.
317 (parport_pc_find_ports): Set it when we register PCI driver. 317 (parport_pc_find_ports): Set it when we register PCI driver.
diff --git a/drivers/parport/ieee1284.c b/drivers/parport/ieee1284.c
index e97059415ab4..ac2a805ac7ea 100644
--- a/drivers/parport/ieee1284.c
+++ b/drivers/parport/ieee1284.c
@@ -1,4 +1,4 @@
1/* $Id: parport_ieee1284.c,v 1.4 1997/10/19 21:37:21 philip Exp $ 1/*
2 * IEEE-1284 implementation for parport. 2 * IEEE-1284 implementation for parport.
3 * 3 *
4 * Authors: Phil Blundell <philb@gnu.org> 4 * Authors: Phil Blundell <philb@gnu.org>
diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c
index 00e1d9620f7c..b1899e9c1f65 100644
--- a/drivers/parport/parport_cs.c
+++ b/drivers/parport/parport_cs.c
@@ -149,52 +149,44 @@ static void parport_detach(struct pcmcia_device *link)
149#define CS_CHECK(fn, ret) \ 149#define CS_CHECK(fn, ret) \
150do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 150do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
151 151
152static int parport_config_check(struct pcmcia_device *p_dev,
153 cistpl_cftable_entry_t *cfg,
154 cistpl_cftable_entry_t *dflt,
155 unsigned int vcc,
156 void *priv_data)
157{
158 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
159 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
160 if (epp_mode)
161 p_dev->conf.ConfigIndex |= FORCE_EPP_MODE;
162 p_dev->io.BasePort1 = io->win[0].base;
163 p_dev->io.NumPorts1 = io->win[0].len;
164 p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
165 if (io->nwin == 2) {
166 p_dev->io.BasePort2 = io->win[1].base;
167 p_dev->io.NumPorts2 = io->win[1].len;
168 }
169 if (pcmcia_request_io(p_dev, &p_dev->io) != 0)
170 return -ENODEV;
171 return 0;
172 }
173 return -ENODEV;
174}
175
152static int parport_config(struct pcmcia_device *link) 176static int parport_config(struct pcmcia_device *link)
153{ 177{
154 parport_info_t *info = link->priv; 178 parport_info_t *info = link->priv;
155 tuple_t tuple;
156 u_short buf[128];
157 cisparse_t parse;
158 cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
159 cistpl_cftable_entry_t dflt = { 0 };
160 struct parport *p; 179 struct parport *p;
161 int last_ret, last_fn; 180 int last_ret, last_fn;
162 181
163 DEBUG(0, "parport_config(0x%p)\n", link); 182 DEBUG(0, "parport_config(0x%p)\n", link);
164 183
165 tuple.TupleData = (cisdata_t *)buf; 184 last_ret = pcmcia_loop_config(link, parport_config_check, NULL);
166 tuple.TupleOffset = 0; tuple.TupleDataMax = 255; 185 if (last_ret) {
167 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 186 cs_error(link, RequestIO, last_ret);
168 tuple.Attributes = 0; 187 goto failed;
169 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
170 while (1) {
171 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
172 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
173 goto next_entry;
174
175 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
176 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
177 link->conf.ConfigIndex = cfg->index;
178 if (epp_mode)
179 link->conf.ConfigIndex |= FORCE_EPP_MODE;
180 link->io.BasePort1 = io->win[0].base;
181 link->io.NumPorts1 = io->win[0].len;
182 link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
183 if (io->nwin == 2) {
184 link->io.BasePort2 = io->win[1].base;
185 link->io.NumPorts2 = io->win[1].len;
186 }
187 if (pcmcia_request_io(link, &link->io) != 0)
188 goto next_entry;
189 /* If we've got this far, we're done */
190 break;
191 }
192
193 next_entry:
194 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
195 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
196 } 188 }
197 189
198 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 190 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
199 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); 191 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
200 192
diff --git a/drivers/parport/probe.c b/drivers/parport/probe.c
index cd565bb4e1a9..0f6550719bcf 100644
--- a/drivers/parport/probe.c
+++ b/drivers/parport/probe.c
@@ -1,4 +1,4 @@
1/* $Id: parport_probe.c,v 1.1 1999/07/03 08:56:17 davem Exp $ 1/*
2 * Parallel port device probing code 2 * Parallel port device probing code
3 * 3 *
4 * Authors: Carsten Gross, carsten@sol.wohnheim.uni-ulm.de 4 * Authors: Carsten Gross, carsten@sol.wohnheim.uni-ulm.de
diff --git a/drivers/parport/share.c b/drivers/parport/share.c
index a8a62bbbb576..0ebca450ed29 100644
--- a/drivers/parport/share.c
+++ b/drivers/parport/share.c
@@ -1,4 +1,4 @@
1/* $Id: parport_share.c,v 1.15 1998/01/11 12:06:17 philip Exp $ 1/*
2 * Parallel-port resource manager code. 2 * Parallel-port resource manager code.
3 * 3 *
4 * Authors: David Campbell <campbell@tirian.che.curtin.edu.au> 4 * Authors: David Campbell <campbell@tirian.che.curtin.edu.au>
diff --git a/drivers/pci/dma_remapping.h b/drivers/pci/dma_remapping.h
deleted file mode 100644
index bff5c65f81dc..000000000000
--- a/drivers/pci/dma_remapping.h
+++ /dev/null
@@ -1,157 +0,0 @@
1#ifndef _DMA_REMAPPING_H
2#define _DMA_REMAPPING_H
3
4/*
5 * We need a fixed PAGE_SIZE of 4K irrespective of
6 * arch PAGE_SIZE for IOMMU page tables.
7 */
8#define PAGE_SHIFT_4K (12)
9#define PAGE_SIZE_4K (1UL << PAGE_SHIFT_4K)
10#define PAGE_MASK_4K (((u64)-1) << PAGE_SHIFT_4K)
11#define PAGE_ALIGN_4K(addr) (((addr) + PAGE_SIZE_4K - 1) & PAGE_MASK_4K)
12
13#define IOVA_PFN(addr) ((addr) >> PAGE_SHIFT_4K)
14#define DMA_32BIT_PFN IOVA_PFN(DMA_32BIT_MASK)
15#define DMA_64BIT_PFN IOVA_PFN(DMA_64BIT_MASK)
16
17
18/*
19 * 0: Present
20 * 1-11: Reserved
21 * 12-63: Context Ptr (12 - (haw-1))
22 * 64-127: Reserved
23 */
24struct root_entry {
25 u64 val;
26 u64 rsvd1;
27};
28#define ROOT_ENTRY_NR (PAGE_SIZE_4K/sizeof(struct root_entry))
29static inline bool root_present(struct root_entry *root)
30{
31 return (root->val & 1);
32}
33static inline void set_root_present(struct root_entry *root)
34{
35 root->val |= 1;
36}
37static inline void set_root_value(struct root_entry *root, unsigned long value)
38{
39 root->val |= value & PAGE_MASK_4K;
40}
41
42struct context_entry;
43static inline struct context_entry *
44get_context_addr_from_root(struct root_entry *root)
45{
46 return (struct context_entry *)
47 (root_present(root)?phys_to_virt(
48 root->val & PAGE_MASK_4K):
49 NULL);
50}
51
52/*
53 * low 64 bits:
54 * 0: present
55 * 1: fault processing disable
56 * 2-3: translation type
57 * 12-63: address space root
58 * high 64 bits:
59 * 0-2: address width
60 * 3-6: aval
61 * 8-23: domain id
62 */
63struct context_entry {
64 u64 lo;
65 u64 hi;
66};
67#define context_present(c) ((c).lo & 1)
68#define context_fault_disable(c) (((c).lo >> 1) & 1)
69#define context_translation_type(c) (((c).lo >> 2) & 3)
70#define context_address_root(c) ((c).lo & PAGE_MASK_4K)
71#define context_address_width(c) ((c).hi & 7)
72#define context_domain_id(c) (((c).hi >> 8) & ((1 << 16) - 1))
73
74#define context_set_present(c) do {(c).lo |= 1;} while (0)
75#define context_set_fault_enable(c) \
76 do {(c).lo &= (((u64)-1) << 2) | 1;} while (0)
77#define context_set_translation_type(c, val) \
78 do { \
79 (c).lo &= (((u64)-1) << 4) | 3; \
80 (c).lo |= ((val) & 3) << 2; \
81 } while (0)
82#define CONTEXT_TT_MULTI_LEVEL 0
83#define context_set_address_root(c, val) \
84 do {(c).lo |= (val) & PAGE_MASK_4K;} while (0)
85#define context_set_address_width(c, val) do {(c).hi |= (val) & 7;} while (0)
86#define context_set_domain_id(c, val) \
87 do {(c).hi |= ((val) & ((1 << 16) - 1)) << 8;} while (0)
88#define context_clear_entry(c) do {(c).lo = 0; (c).hi = 0;} while (0)
89
90/*
91 * 0: readable
92 * 1: writable
93 * 2-6: reserved
94 * 7: super page
95 * 8-11: available
96 * 12-63: Host physcial address
97 */
98struct dma_pte {
99 u64 val;
100};
101#define dma_clear_pte(p) do {(p).val = 0;} while (0)
102
103#define DMA_PTE_READ (1)
104#define DMA_PTE_WRITE (2)
105
106#define dma_set_pte_readable(p) do {(p).val |= DMA_PTE_READ;} while (0)
107#define dma_set_pte_writable(p) do {(p).val |= DMA_PTE_WRITE;} while (0)
108#define dma_set_pte_prot(p, prot) \
109 do {(p).val = ((p).val & ~3) | ((prot) & 3); } while (0)
110#define dma_pte_addr(p) ((p).val & PAGE_MASK_4K)
111#define dma_set_pte_addr(p, addr) do {\
112 (p).val |= ((addr) & PAGE_MASK_4K); } while (0)
113#define dma_pte_present(p) (((p).val & 3) != 0)
114
115struct intel_iommu;
116
117struct dmar_domain {
118 int id; /* domain id */
119 struct intel_iommu *iommu; /* back pointer to owning iommu */
120
121 struct list_head devices; /* all devices' list */
122 struct iova_domain iovad; /* iova's that belong to this domain */
123
124 struct dma_pte *pgd; /* virtual address */
125 spinlock_t mapping_lock; /* page table lock */
126 int gaw; /* max guest address width */
127
128 /* adjusted guest address width, 0 is level 2 30-bit */
129 int agaw;
130
131#define DOMAIN_FLAG_MULTIPLE_DEVICES 1
132 int flags;
133};
134
135/* PCI domain-device relationship */
136struct device_domain_info {
137 struct list_head link; /* link to domain siblings */
138 struct list_head global; /* link to global list */
139 u8 bus; /* PCI bus numer */
140 u8 devfn; /* PCI devfn number */
141 struct pci_dev *dev; /* it's NULL for PCIE-to-PCI bridge */
142 struct dmar_domain *domain; /* pointer to domain */
143};
144
145extern int init_dmars(void);
146extern void free_dmar_iommu(struct intel_iommu *iommu);
147
148extern int dmar_disabled;
149
150#ifndef CONFIG_DMAR_GFX_WA
151static inline void iommu_prepare_gfx_mapping(void)
152{
153 return;
154}
155#endif /* !CONFIG_DMAR_GFX_WA */
156
157#endif
diff --git a/drivers/pci/dmar.c b/drivers/pci/dmar.c
index bd2c01674f5e..e842e756308a 100644
--- a/drivers/pci/dmar.c
+++ b/drivers/pci/dmar.c
@@ -28,9 +28,9 @@
28 28
29#include <linux/pci.h> 29#include <linux/pci.h>
30#include <linux/dmar.h> 30#include <linux/dmar.h>
31#include <linux/iova.h>
32#include <linux/intel-iommu.h>
31#include <linux/timer.h> 33#include <linux/timer.h>
32#include "iova.h"
33#include "intel-iommu.h"
34 34
35#undef PREFIX 35#undef PREFIX
36#define PREFIX "DMAR:" 36#define PREFIX "DMAR:"
diff --git a/drivers/pci/hotplug/ibmphp_ebda.c b/drivers/pci/hotplug/ibmphp_ebda.c
index 8467d0287325..7d27631e6e62 100644
--- a/drivers/pci/hotplug/ibmphp_ebda.c
+++ b/drivers/pci/hotplug/ibmphp_ebda.c
@@ -276,7 +276,7 @@ int __init ibmphp_access_ebda (void)
276 iounmap (io_mem); 276 iounmap (io_mem);
277 debug ("returned ebda segment: %x\n", ebda_seg); 277 debug ("returned ebda segment: %x\n", ebda_seg);
278 278
279 io_mem = ioremap (ebda_seg<<4, 65000); 279 io_mem = ioremap(ebda_seg<<4, 1024);
280 if (!io_mem ) 280 if (!io_mem )
281 return -ENOMEM; 281 return -ENOMEM;
282 next_offset = 0x180; 282 next_offset = 0x180;
diff --git a/drivers/pci/hotplug/rpaphp_slot.c b/drivers/pci/hotplug/rpaphp_slot.c
index 9b714ea93d20..50884507b8be 100644
--- a/drivers/pci/hotplug/rpaphp_slot.c
+++ b/drivers/pci/hotplug/rpaphp_slot.c
@@ -147,9 +147,5 @@ int rpaphp_register_slot(struct slot *slot)
147 list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head); 147 list_add(&slot->rpaphp_slot_list, &rpaphp_slot_head);
148 info("Slot [%s] registered\n", slot->name); 148 info("Slot [%s] registered\n", slot->name);
149 return 0; 149 return 0;
150
151sysfs_fail:
152 pci_hp_deregister(php_slot);
153 return retval;
154} 150}
155 151
diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c
index 389fdd6f4a9f..fc5f2dbf5323 100644
--- a/drivers/pci/intel-iommu.c
+++ b/drivers/pci/intel-iommu.c
@@ -33,8 +33,8 @@
33#include <linux/dma-mapping.h> 33#include <linux/dma-mapping.h>
34#include <linux/mempool.h> 34#include <linux/mempool.h>
35#include <linux/timer.h> 35#include <linux/timer.h>
36#include "iova.h" 36#include <linux/iova.h>
37#include "intel-iommu.h" 37#include <linux/intel-iommu.h>
38#include <asm/proto.h> /* force_iommu in this header in x86-64*/ 38#include <asm/proto.h> /* force_iommu in this header in x86-64*/
39#include <asm/cacheflush.h> 39#include <asm/cacheflush.h>
40#include <asm/iommu.h> 40#include <asm/iommu.h>
@@ -156,7 +156,7 @@ static inline void *alloc_domain_mem(void)
156 return iommu_kmem_cache_alloc(iommu_domain_cache); 156 return iommu_kmem_cache_alloc(iommu_domain_cache);
157} 157}
158 158
159static inline void free_domain_mem(void *vaddr) 159static void free_domain_mem(void *vaddr)
160{ 160{
161 kmem_cache_free(iommu_domain_cache, vaddr); 161 kmem_cache_free(iommu_domain_cache, vaddr);
162} 162}
@@ -1341,7 +1341,7 @@ static void domain_remove_dev_info(struct dmar_domain *domain)
1341 * find_domain 1341 * find_domain
1342 * Note: we use struct pci_dev->dev.archdata.iommu stores the info 1342 * Note: we use struct pci_dev->dev.archdata.iommu stores the info
1343 */ 1343 */
1344struct dmar_domain * 1344static struct dmar_domain *
1345find_domain(struct pci_dev *pdev) 1345find_domain(struct pci_dev *pdev)
1346{ 1346{
1347 struct device_domain_info *info; 1347 struct device_domain_info *info;
@@ -2318,3 +2318,111 @@ int __init intel_iommu_init(void)
2318 return 0; 2318 return 0;
2319} 2319}
2320 2320
2321void intel_iommu_domain_exit(struct dmar_domain *domain)
2322{
2323 u64 end;
2324
2325 /* Domain 0 is reserved, so dont process it */
2326 if (!domain)
2327 return;
2328
2329 end = DOMAIN_MAX_ADDR(domain->gaw);
2330 end = end & (~PAGE_MASK_4K);
2331
2332 /* clear ptes */
2333 dma_pte_clear_range(domain, 0, end);
2334
2335 /* free page tables */
2336 dma_pte_free_pagetable(domain, 0, end);
2337
2338 iommu_free_domain(domain);
2339 free_domain_mem(domain);
2340}
2341EXPORT_SYMBOL_GPL(intel_iommu_domain_exit);
2342
2343struct dmar_domain *intel_iommu_domain_alloc(struct pci_dev *pdev)
2344{
2345 struct dmar_drhd_unit *drhd;
2346 struct dmar_domain *domain;
2347 struct intel_iommu *iommu;
2348
2349 drhd = dmar_find_matched_drhd_unit(pdev);
2350 if (!drhd) {
2351 printk(KERN_ERR "intel_iommu_domain_alloc: drhd == NULL\n");
2352 return NULL;
2353 }
2354
2355 iommu = drhd->iommu;
2356 if (!iommu) {
2357 printk(KERN_ERR
2358 "intel_iommu_domain_alloc: iommu == NULL\n");
2359 return NULL;
2360 }
2361 domain = iommu_alloc_domain(iommu);
2362 if (!domain) {
2363 printk(KERN_ERR
2364 "intel_iommu_domain_alloc: domain == NULL\n");
2365 return NULL;
2366 }
2367 if (domain_init(domain, DEFAULT_DOMAIN_ADDRESS_WIDTH)) {
2368 printk(KERN_ERR
2369 "intel_iommu_domain_alloc: domain_init() failed\n");
2370 intel_iommu_domain_exit(domain);
2371 return NULL;
2372 }
2373 return domain;
2374}
2375EXPORT_SYMBOL_GPL(intel_iommu_domain_alloc);
2376
2377int intel_iommu_context_mapping(
2378 struct dmar_domain *domain, struct pci_dev *pdev)
2379{
2380 int rc;
2381 rc = domain_context_mapping(domain, pdev);
2382 return rc;
2383}
2384EXPORT_SYMBOL_GPL(intel_iommu_context_mapping);
2385
2386int intel_iommu_page_mapping(
2387 struct dmar_domain *domain, dma_addr_t iova,
2388 u64 hpa, size_t size, int prot)
2389{
2390 int rc;
2391 rc = domain_page_mapping(domain, iova, hpa, size, prot);
2392 return rc;
2393}
2394EXPORT_SYMBOL_GPL(intel_iommu_page_mapping);
2395
2396void intel_iommu_detach_dev(struct dmar_domain *domain, u8 bus, u8 devfn)
2397{
2398 detach_domain_for_dev(domain, bus, devfn);
2399}
2400EXPORT_SYMBOL_GPL(intel_iommu_detach_dev);
2401
2402struct dmar_domain *
2403intel_iommu_find_domain(struct pci_dev *pdev)
2404{
2405 return find_domain(pdev);
2406}
2407EXPORT_SYMBOL_GPL(intel_iommu_find_domain);
2408
2409int intel_iommu_found(void)
2410{
2411 return g_num_of_iommus;
2412}
2413EXPORT_SYMBOL_GPL(intel_iommu_found);
2414
2415u64 intel_iommu_iova_to_pfn(struct dmar_domain *domain, u64 iova)
2416{
2417 struct dma_pte *pte;
2418 u64 pfn;
2419
2420 pfn = 0;
2421 pte = addr_to_dma_pte(domain, iova);
2422
2423 if (pte)
2424 pfn = dma_pte_addr(*pte);
2425
2426 return pfn >> PAGE_SHIFT_4K;
2427}
2428EXPORT_SYMBOL_GPL(intel_iommu_iova_to_pfn);
diff --git a/drivers/pci/intel-iommu.h b/drivers/pci/intel-iommu.h
deleted file mode 100644
index 2142c01e0143..000000000000
--- a/drivers/pci/intel-iommu.h
+++ /dev/null
@@ -1,307 +0,0 @@
1/*
2 * Copyright (c) 2006, Intel Corporation.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
15 * Place - Suite 330, Boston, MA 02111-1307 USA.
16 *
17 * Copyright (C) 2006-2008 Intel Corporation
18 * Author: Ashok Raj <ashok.raj@intel.com>
19 * Author: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
20 */
21
22#ifndef _INTEL_IOMMU_H_
23#define _INTEL_IOMMU_H_
24
25#include <linux/types.h>
26#include <linux/msi.h>
27#include <linux/sysdev.h>
28#include "iova.h"
29#include <linux/io.h>
30#include <asm/cacheflush.h>
31#include "dma_remapping.h"
32
33/*
34 * Intel IOMMU register specification per version 1.0 public spec.
35 */
36
37#define DMAR_VER_REG 0x0 /* Arch version supported by this IOMMU */
38#define DMAR_CAP_REG 0x8 /* Hardware supported capabilities */
39#define DMAR_ECAP_REG 0x10 /* Extended capabilities supported */
40#define DMAR_GCMD_REG 0x18 /* Global command register */
41#define DMAR_GSTS_REG 0x1c /* Global status register */
42#define DMAR_RTADDR_REG 0x20 /* Root entry table */
43#define DMAR_CCMD_REG 0x28 /* Context command reg */
44#define DMAR_FSTS_REG 0x34 /* Fault Status register */
45#define DMAR_FECTL_REG 0x38 /* Fault control register */
46#define DMAR_FEDATA_REG 0x3c /* Fault event interrupt data register */
47#define DMAR_FEADDR_REG 0x40 /* Fault event interrupt addr register */
48#define DMAR_FEUADDR_REG 0x44 /* Upper address register */
49#define DMAR_AFLOG_REG 0x58 /* Advanced Fault control */
50#define DMAR_PMEN_REG 0x64 /* Enable Protected Memory Region */
51#define DMAR_PLMBASE_REG 0x68 /* PMRR Low addr */
52#define DMAR_PLMLIMIT_REG 0x6c /* PMRR low limit */
53#define DMAR_PHMBASE_REG 0x70 /* pmrr high base addr */
54#define DMAR_PHMLIMIT_REG 0x78 /* pmrr high limit */
55#define DMAR_IQH_REG 0x80 /* Invalidation queue head register */
56#define DMAR_IQT_REG 0x88 /* Invalidation queue tail register */
57#define DMAR_IQA_REG 0x90 /* Invalidation queue addr register */
58#define DMAR_ICS_REG 0x98 /* Invalidation complete status register */
59#define DMAR_IRTA_REG 0xb8 /* Interrupt remapping table addr register */
60
61#define OFFSET_STRIDE (9)
62/*
63#define dmar_readl(dmar, reg) readl(dmar + reg)
64#define dmar_readq(dmar, reg) ({ \
65 u32 lo, hi; \
66 lo = readl(dmar + reg); \
67 hi = readl(dmar + reg + 4); \
68 (((u64) hi) << 32) + lo; })
69*/
70static inline u64 dmar_readq(void __iomem *addr)
71{
72 u32 lo, hi;
73 lo = readl(addr);
74 hi = readl(addr + 4);
75 return (((u64) hi) << 32) + lo;
76}
77
78static inline void dmar_writeq(void __iomem *addr, u64 val)
79{
80 writel((u32)val, addr);
81 writel((u32)(val >> 32), addr + 4);
82}
83
84#define DMAR_VER_MAJOR(v) (((v) & 0xf0) >> 4)
85#define DMAR_VER_MINOR(v) ((v) & 0x0f)
86
87/*
88 * Decoding Capability Register
89 */
90#define cap_read_drain(c) (((c) >> 55) & 1)
91#define cap_write_drain(c) (((c) >> 54) & 1)
92#define cap_max_amask_val(c) (((c) >> 48) & 0x3f)
93#define cap_num_fault_regs(c) ((((c) >> 40) & 0xff) + 1)
94#define cap_pgsel_inv(c) (((c) >> 39) & 1)
95
96#define cap_super_page_val(c) (((c) >> 34) & 0xf)
97#define cap_super_offset(c) (((find_first_bit(&cap_super_page_val(c), 4)) \
98 * OFFSET_STRIDE) + 21)
99
100#define cap_fault_reg_offset(c) ((((c) >> 24) & 0x3ff) * 16)
101#define cap_max_fault_reg_offset(c) \
102 (cap_fault_reg_offset(c) + cap_num_fault_regs(c) * 16)
103
104#define cap_zlr(c) (((c) >> 22) & 1)
105#define cap_isoch(c) (((c) >> 23) & 1)
106#define cap_mgaw(c) ((((c) >> 16) & 0x3f) + 1)
107#define cap_sagaw(c) (((c) >> 8) & 0x1f)
108#define cap_caching_mode(c) (((c) >> 7) & 1)
109#define cap_phmr(c) (((c) >> 6) & 1)
110#define cap_plmr(c) (((c) >> 5) & 1)
111#define cap_rwbf(c) (((c) >> 4) & 1)
112#define cap_afl(c) (((c) >> 3) & 1)
113#define cap_ndoms(c) (((unsigned long)1) << (4 + 2 * ((c) & 0x7)))
114/*
115 * Extended Capability Register
116 */
117
118#define ecap_niotlb_iunits(e) ((((e) >> 24) & 0xff) + 1)
119#define ecap_iotlb_offset(e) ((((e) >> 8) & 0x3ff) * 16)
120#define ecap_max_iotlb_offset(e) \
121 (ecap_iotlb_offset(e) + ecap_niotlb_iunits(e) * 16)
122#define ecap_coherent(e) ((e) & 0x1)
123#define ecap_qis(e) ((e) & 0x2)
124#define ecap_eim_support(e) ((e >> 4) & 0x1)
125#define ecap_ir_support(e) ((e >> 3) & 0x1)
126#define ecap_max_handle_mask(e) ((e >> 20) & 0xf)
127
128
129/* IOTLB_REG */
130#define DMA_TLB_GLOBAL_FLUSH (((u64)1) << 60)
131#define DMA_TLB_DSI_FLUSH (((u64)2) << 60)
132#define DMA_TLB_PSI_FLUSH (((u64)3) << 60)
133#define DMA_TLB_IIRG(type) ((type >> 60) & 7)
134#define DMA_TLB_IAIG(val) (((val) >> 57) & 7)
135#define DMA_TLB_READ_DRAIN (((u64)1) << 49)
136#define DMA_TLB_WRITE_DRAIN (((u64)1) << 48)
137#define DMA_TLB_DID(id) (((u64)((id) & 0xffff)) << 32)
138#define DMA_TLB_IVT (((u64)1) << 63)
139#define DMA_TLB_IH_NONLEAF (((u64)1) << 6)
140#define DMA_TLB_MAX_SIZE (0x3f)
141
142/* INVALID_DESC */
143#define DMA_ID_TLB_GLOBAL_FLUSH (((u64)1) << 3)
144#define DMA_ID_TLB_DSI_FLUSH (((u64)2) << 3)
145#define DMA_ID_TLB_PSI_FLUSH (((u64)3) << 3)
146#define DMA_ID_TLB_READ_DRAIN (((u64)1) << 7)
147#define DMA_ID_TLB_WRITE_DRAIN (((u64)1) << 6)
148#define DMA_ID_TLB_DID(id) (((u64)((id & 0xffff) << 16)))
149#define DMA_ID_TLB_IH_NONLEAF (((u64)1) << 6)
150#define DMA_ID_TLB_ADDR(addr) (addr)
151#define DMA_ID_TLB_ADDR_MASK(mask) (mask)
152
153/* PMEN_REG */
154#define DMA_PMEN_EPM (((u32)1)<<31)
155#define DMA_PMEN_PRS (((u32)1)<<0)
156
157/* GCMD_REG */
158#define DMA_GCMD_TE (((u32)1) << 31)
159#define DMA_GCMD_SRTP (((u32)1) << 30)
160#define DMA_GCMD_SFL (((u32)1) << 29)
161#define DMA_GCMD_EAFL (((u32)1) << 28)
162#define DMA_GCMD_WBF (((u32)1) << 27)
163#define DMA_GCMD_QIE (((u32)1) << 26)
164#define DMA_GCMD_SIRTP (((u32)1) << 24)
165#define DMA_GCMD_IRE (((u32) 1) << 25)
166
167/* GSTS_REG */
168#define DMA_GSTS_TES (((u32)1) << 31)
169#define DMA_GSTS_RTPS (((u32)1) << 30)
170#define DMA_GSTS_FLS (((u32)1) << 29)
171#define DMA_GSTS_AFLS (((u32)1) << 28)
172#define DMA_GSTS_WBFS (((u32)1) << 27)
173#define DMA_GSTS_QIES (((u32)1) << 26)
174#define DMA_GSTS_IRTPS (((u32)1) << 24)
175#define DMA_GSTS_IRES (((u32)1) << 25)
176
177/* CCMD_REG */
178#define DMA_CCMD_ICC (((u64)1) << 63)
179#define DMA_CCMD_GLOBAL_INVL (((u64)1) << 61)
180#define DMA_CCMD_DOMAIN_INVL (((u64)2) << 61)
181#define DMA_CCMD_DEVICE_INVL (((u64)3) << 61)
182#define DMA_CCMD_FM(m) (((u64)((m) & 0x3)) << 32)
183#define DMA_CCMD_MASK_NOBIT 0
184#define DMA_CCMD_MASK_1BIT 1
185#define DMA_CCMD_MASK_2BIT 2
186#define DMA_CCMD_MASK_3BIT 3
187#define DMA_CCMD_SID(s) (((u64)((s) & 0xffff)) << 16)
188#define DMA_CCMD_DID(d) ((u64)((d) & 0xffff))
189
190/* FECTL_REG */
191#define DMA_FECTL_IM (((u32)1) << 31)
192
193/* FSTS_REG */
194#define DMA_FSTS_PPF ((u32)2)
195#define DMA_FSTS_PFO ((u32)1)
196#define dma_fsts_fault_record_index(s) (((s) >> 8) & 0xff)
197
198/* FRCD_REG, 32 bits access */
199#define DMA_FRCD_F (((u32)1) << 31)
200#define dma_frcd_type(d) ((d >> 30) & 1)
201#define dma_frcd_fault_reason(c) (c & 0xff)
202#define dma_frcd_source_id(c) (c & 0xffff)
203#define dma_frcd_page_addr(d) (d & (((u64)-1) << 12)) /* low 64 bit */
204
205#define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000) /* 10sec */
206
207#define IOMMU_WAIT_OP(iommu, offset, op, cond, sts) \
208{\
209 cycles_t start_time = get_cycles();\
210 while (1) {\
211 sts = op (iommu->reg + offset);\
212 if (cond)\
213 break;\
214 if (DMAR_OPERATION_TIMEOUT < (get_cycles() - start_time))\
215 panic("DMAR hardware is malfunctioning\n");\
216 cpu_relax();\
217 }\
218}
219
220#define QI_LENGTH 256 /* queue length */
221
222enum {
223 QI_FREE,
224 QI_IN_USE,
225 QI_DONE
226};
227
228#define QI_CC_TYPE 0x1
229#define QI_IOTLB_TYPE 0x2
230#define QI_DIOTLB_TYPE 0x3
231#define QI_IEC_TYPE 0x4
232#define QI_IWD_TYPE 0x5
233
234#define QI_IEC_SELECTIVE (((u64)1) << 4)
235#define QI_IEC_IIDEX(idx) (((u64)(idx & 0xffff) << 32))
236#define QI_IEC_IM(m) (((u64)(m & 0x1f) << 27))
237
238#define QI_IWD_STATUS_DATA(d) (((u64)d) << 32)
239#define QI_IWD_STATUS_WRITE (((u64)1) << 5)
240
241struct qi_desc {
242 u64 low, high;
243};
244
245struct q_inval {
246 spinlock_t q_lock;
247 struct qi_desc *desc; /* invalidation queue */
248 int *desc_status; /* desc status */
249 int free_head; /* first free entry */
250 int free_tail; /* last free entry */
251 int free_cnt;
252};
253
254#ifdef CONFIG_INTR_REMAP
255/* 1MB - maximum possible interrupt remapping table size */
256#define INTR_REMAP_PAGE_ORDER 8
257#define INTR_REMAP_TABLE_REG_SIZE 0xf
258
259#define INTR_REMAP_TABLE_ENTRIES 65536
260
261struct ir_table {
262 struct irte *base;
263};
264#endif
265
266struct intel_iommu {
267 void __iomem *reg; /* Pointer to hardware regs, virtual addr */
268 u64 cap;
269 u64 ecap;
270 int seg;
271 u32 gcmd; /* Holds TE, EAFL. Don't need SRTP, SFL, WBF */
272 spinlock_t register_lock; /* protect register handling */
273 int seq_id; /* sequence id of the iommu */
274
275#ifdef CONFIG_DMAR
276 unsigned long *domain_ids; /* bitmap of domains */
277 struct dmar_domain **domains; /* ptr to domains */
278 spinlock_t lock; /* protect context, domain ids */
279 struct root_entry *root_entry; /* virtual address */
280
281 unsigned int irq;
282 unsigned char name[7]; /* Device Name */
283 struct msi_msg saved_msg;
284 struct sys_device sysdev;
285#endif
286 struct q_inval *qi; /* Queued invalidation info */
287#ifdef CONFIG_INTR_REMAP
288 struct ir_table *ir_table; /* Interrupt remapping info */
289#endif
290};
291
292static inline void __iommu_flush_cache(
293 struct intel_iommu *iommu, void *addr, int size)
294{
295 if (!ecap_coherent(iommu->ecap))
296 clflush_cache_range(addr, size);
297}
298
299extern struct dmar_drhd_unit * dmar_find_matched_drhd_unit(struct pci_dev *dev);
300
301extern int alloc_iommu(struct dmar_drhd_unit *drhd);
302extern void free_iommu(struct intel_iommu *iommu);
303extern int dmar_enable_qi(struct intel_iommu *iommu);
304extern void qi_global_iec(struct intel_iommu *iommu);
305
306extern void qi_submit_sync(struct qi_desc *desc, struct intel_iommu *iommu);
307#endif
diff --git a/drivers/pci/intr_remapping.c b/drivers/pci/intr_remapping.c
index bb642cc5e18c..738d4c89581c 100644
--- a/drivers/pci/intr_remapping.c
+++ b/drivers/pci/intr_remapping.c
@@ -4,7 +4,7 @@
4#include <linux/pci.h> 4#include <linux/pci.h>
5#include <linux/irq.h> 5#include <linux/irq.h>
6#include <asm/io_apic.h> 6#include <asm/io_apic.h>
7#include "intel-iommu.h" 7#include <linux/intel-iommu.h>
8#include "intr_remapping.h" 8#include "intr_remapping.h"
9 9
10static struct ioapic_scope ir_ioapic[MAX_IO_APICS]; 10static struct ioapic_scope ir_ioapic[MAX_IO_APICS];
diff --git a/drivers/pci/intr_remapping.h b/drivers/pci/intr_remapping.h
index 05f2635bbe4e..ca48f0df8ac9 100644
--- a/drivers/pci/intr_remapping.h
+++ b/drivers/pci/intr_remapping.h
@@ -1,4 +1,4 @@
1#include "intel-iommu.h" 1#include <linux/intel-iommu.h>
2 2
3struct ioapic_scope { 3struct ioapic_scope {
4 struct intel_iommu *iommu; 4 struct intel_iommu *iommu;
diff --git a/drivers/pci/iova.c b/drivers/pci/iova.c
index 3ef4ac064315..2287116e9822 100644
--- a/drivers/pci/iova.c
+++ b/drivers/pci/iova.c
@@ -7,7 +7,7 @@
7 * Author: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com> 7 * Author: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
8 */ 8 */
9 9
10#include "iova.h" 10#include <linux/iova.h>
11 11
12void 12void
13init_iova_domain(struct iova_domain *iovad, unsigned long pfn_32bit) 13init_iova_domain(struct iova_domain *iovad, unsigned long pfn_32bit)
diff --git a/drivers/pci/iova.h b/drivers/pci/iova.h
deleted file mode 100644
index 228f6c94b69c..000000000000
--- a/drivers/pci/iova.h
+++ /dev/null
@@ -1,52 +0,0 @@
1/*
2 * Copyright (c) 2006, Intel Corporation.
3 *
4 * This file is released under the GPLv2.
5 *
6 * Copyright (C) 2006-2008 Intel Corporation
7 * Author: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
8 *
9 */
10
11#ifndef _IOVA_H_
12#define _IOVA_H_
13
14#include <linux/types.h>
15#include <linux/kernel.h>
16#include <linux/rbtree.h>
17#include <linux/dma-mapping.h>
18
19/* IO virtual address start page frame number */
20#define IOVA_START_PFN (1)
21
22/* iova structure */
23struct iova {
24 struct rb_node node;
25 unsigned long pfn_hi; /* IOMMU dish out addr hi */
26 unsigned long pfn_lo; /* IOMMU dish out addr lo */
27};
28
29/* holds all the iova translations for a domain */
30struct iova_domain {
31 spinlock_t iova_alloc_lock;/* Lock to protect iova allocation */
32 spinlock_t iova_rbtree_lock; /* Lock to protect update of rbtree */
33 struct rb_root rbroot; /* iova domain rbtree root */
34 struct rb_node *cached32_node; /* Save last alloced node */
35 unsigned long dma_32bit_pfn;
36};
37
38struct iova *alloc_iova_mem(void);
39void free_iova_mem(struct iova *iova);
40void free_iova(struct iova_domain *iovad, unsigned long pfn);
41void __free_iova(struct iova_domain *iovad, struct iova *iova);
42struct iova *alloc_iova(struct iova_domain *iovad, unsigned long size,
43 unsigned long limit_pfn,
44 bool size_aligned);
45struct iova *reserve_iova(struct iova_domain *iovad, unsigned long pfn_lo,
46 unsigned long pfn_hi);
47void copy_reserved_iova(struct iova_domain *from, struct iova_domain *to);
48void init_iova_domain(struct iova_domain *iovad, unsigned long pfn_32bit);
49struct iova *find_iova(struct iova_domain *iovad, unsigned long pfn);
50void put_iova_domain(struct iova_domain *iovad);
51
52#endif
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 36698e57b97f..dd9161a054e1 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1237,8 +1237,11 @@ EXPORT_SYMBOL(pci_scan_bridge);
1237EXPORT_SYMBOL_GPL(pci_scan_child_bus); 1237EXPORT_SYMBOL_GPL(pci_scan_child_bus);
1238#endif 1238#endif
1239 1239
1240static int __init pci_sort_bf_cmp(const struct pci_dev *a, const struct pci_dev *b) 1240static int __init pci_sort_bf_cmp(const struct device *d_a, const struct device *d_b)
1241{ 1241{
1242 const struct pci_dev *a = to_pci_dev(d_a);
1243 const struct pci_dev *b = to_pci_dev(d_b);
1244
1242 if (pci_domain_nr(a->bus) < pci_domain_nr(b->bus)) return -1; 1245 if (pci_domain_nr(a->bus) < pci_domain_nr(b->bus)) return -1;
1243 else if (pci_domain_nr(a->bus) > pci_domain_nr(b->bus)) return 1; 1246 else if (pci_domain_nr(a->bus) > pci_domain_nr(b->bus)) return 1;
1244 1247
@@ -1251,50 +1254,7 @@ static int __init pci_sort_bf_cmp(const struct pci_dev *a, const struct pci_dev
1251 return 0; 1254 return 0;
1252} 1255}
1253 1256
1254/*
1255 * Yes, this forcably breaks the klist abstraction temporarily. It
1256 * just wants to sort the klist, not change reference counts and
1257 * take/drop locks rapidly in the process. It does all this while
1258 * holding the lock for the list, so objects can't otherwise be
1259 * added/removed while we're swizzling.
1260 */
1261static void __init pci_insertion_sort_klist(struct pci_dev *a, struct list_head *list)
1262{
1263 struct list_head *pos;
1264 struct klist_node *n;
1265 struct device *dev;
1266 struct pci_dev *b;
1267
1268 list_for_each(pos, list) {
1269 n = container_of(pos, struct klist_node, n_node);
1270 dev = container_of(n, struct device, knode_bus);
1271 b = to_pci_dev(dev);
1272 if (pci_sort_bf_cmp(a, b) <= 0) {
1273 list_move_tail(&a->dev.knode_bus.n_node, &b->dev.knode_bus.n_node);
1274 return;
1275 }
1276 }
1277 list_move_tail(&a->dev.knode_bus.n_node, list);
1278}
1279
1280void __init pci_sort_breadthfirst(void) 1257void __init pci_sort_breadthfirst(void)
1281{ 1258{
1282 LIST_HEAD(sorted_devices); 1259 bus_sort_breadthfirst(&pci_bus_type, &pci_sort_bf_cmp);
1283 struct list_head *pos, *tmp;
1284 struct klist_node *n;
1285 struct device *dev;
1286 struct pci_dev *pdev;
1287 struct klist *device_klist;
1288
1289 device_klist = bus_get_device_klist(&pci_bus_type);
1290
1291 spin_lock(&device_klist->k_lock);
1292 list_for_each_safe(pos, tmp, &device_klist->k_list) {
1293 n = container_of(pos, struct klist_node, n_node);
1294 dev = container_of(n, struct device, knode_bus);
1295 pdev = to_pci_dev(dev);
1296 pci_insertion_sort_klist(pdev, &sorted_devices);
1297 }
1298 list_splice(&sorted_devices, &device_klist->k_list);
1299 spin_unlock(&device_klist->k_lock);
1300} 1260}
diff --git a/drivers/pci/quirks.c b/drivers/pci/quirks.c
index 9236e7f869c8..e872ac925b4b 100644
--- a/drivers/pci/quirks.c
+++ b/drivers/pci/quirks.c
@@ -1561,8 +1561,7 @@ static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f, struct pci_f
1561 if ((f->vendor == dev->vendor || f->vendor == (u16) PCI_ANY_ID) && 1561 if ((f->vendor == dev->vendor || f->vendor == (u16) PCI_ANY_ID) &&
1562 (f->device == dev->device || f->device == (u16) PCI_ANY_ID)) { 1562 (f->device == dev->device || f->device == (u16) PCI_ANY_ID)) {
1563#ifdef DEBUG 1563#ifdef DEBUG
1564 dev_dbg(&dev->dev, "calling "); 1564 dev_dbg(&dev->dev, "calling %pF\n", f->hook);
1565 print_fn_descriptor_symbol("%s\n", f->hook);
1566#endif 1565#endif
1567 f->hook(dev); 1566 f->hook(dev);
1568 } 1567 }
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 3abbfad9ddab..d5e2106760f8 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -378,11 +378,10 @@ static int pbus_size_mem(struct pci_bus *bus, unsigned long mask, unsigned long
378 align = 0; 378 align = 0;
379 min_align = 0; 379 min_align = 0;
380 for (order = 0; order <= max_order; order++) { 380 for (order = 0; order <= max_order; order++) {
381#ifdef CONFIG_RESOURCES_64BIT 381 resource_size_t align1 = 1;
382 resource_size_t align1 = 1ULL << (order + 20); 382
383#else 383 align1 <<= (order + 20);
384 resource_size_t align1 = 1U << (order + 20); 384
385#endif
386 if (!align) 385 if (!align)
387 min_align = align1; 386 min_align = align1;
388 else if (ALIGN(align + min_align, min_align) < align1) 387 else if (ALIGN(align + min_align, min_align) < align1)
diff --git a/drivers/pcmcia/Makefile b/drivers/pcmcia/Makefile
index a87902de8d3b..b46c60b72708 100644
--- a/drivers/pcmcia/Makefile
+++ b/drivers/pcmcia/Makefile
@@ -2,10 +2,6 @@
2# Makefile for the kernel pcmcia subsystem (c/o David Hinds) 2# Makefile for the kernel pcmcia subsystem (c/o David Hinds)
3# 3#
4 4
5ifeq ($(CONFIG_PCMCIA_DEBUG),y)
6EXTRA_CFLAGS += -DDEBUG
7endif
8
9pcmcia_core-y += cs.o cistpl.o rsrc_mgr.o socket_sysfs.o 5pcmcia_core-y += cs.o cistpl.o rsrc_mgr.o socket_sysfs.o
10pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o 6pcmcia_core-$(CONFIG_CARDBUS) += cardbus.o
11obj-$(CONFIG_PCCARD) += pcmcia_core.o 7obj-$(CONFIG_PCCARD) += pcmcia_core.o
@@ -68,10 +64,11 @@ sa1100_cs-$(CONFIG_SA1100_SHANNON) += sa1100_shannon.o
68sa1100_cs-$(CONFIG_SA1100_SIMPAD) += sa1100_simpad.o 64sa1100_cs-$(CONFIG_SA1100_SIMPAD) += sa1100_simpad.o
69 65
70pxa2xx_lubbock_cs-y += pxa2xx_lubbock.o sa1111_generic.o 66pxa2xx_lubbock_cs-y += pxa2xx_lubbock.o sa1111_generic.o
67pxa2xx_cm_x2xx_cs-y += pxa2xx_cm_x2xx.o pxa2xx_cm_x255.o pxa2xx_cm_x270.o
71pxa2xx-obj-$(CONFIG_ARCH_LUBBOCK) += pxa2xx_lubbock_cs.o 68pxa2xx-obj-$(CONFIG_ARCH_LUBBOCK) += pxa2xx_lubbock_cs.o
72pxa2xx-obj-$(CONFIG_MACH_MAINSTONE) += pxa2xx_mainstone.o 69pxa2xx-obj-$(CONFIG_MACH_MAINSTONE) += pxa2xx_mainstone.o
73pxa2xx-obj-$(CONFIG_PXA_SHARPSL) += pxa2xx_sharpsl.o 70pxa2xx-obj-$(CONFIG_PXA_SHARPSL) += pxa2xx_sharpsl.o
74pxa2xx-obj-$(CONFIG_MACH_ARMCORE) += pxa2xx_cm_x2xx.o pxa2xx_cm_x255.o pxa2xx_cm_x270.o 71pxa2xx-obj-$(CONFIG_MACH_ARMCORE) += pxa2xx_cm_x2xx_cs.o
75pxa2xx-obj-$(CONFIG_ARCH_VIPER) += pxa2xx_viper.o 72pxa2xx-obj-$(CONFIG_ARCH_VIPER) += pxa2xx_viper.o
76pxa2xx-obj-$(CONFIG_TRIZEPS_PCMCIA) += pxa2xx_trizeps.o 73pxa2xx-obj-$(CONFIG_TRIZEPS_PCMCIA) += pxa2xx_trizeps.o
77pxa2xx-obj-$(CONFIG_MACH_PALMTX) += pxa2xx_palmtx.o 74pxa2xx-obj-$(CONFIG_MACH_PALMTX) += pxa2xx_palmtx.o
diff --git a/drivers/pcmcia/au1000_generic.c b/drivers/pcmcia/au1000_generic.c
index 75e8f8505e47..fc1de46fd20a 100644
--- a/drivers/pcmcia/au1000_generic.c
+++ b/drivers/pcmcia/au1000_generic.c
@@ -292,7 +292,7 @@ au1x00_pcmcia_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *map)
292 skt->spd_io[map->map] = speed; 292 skt->spd_io[map->map] = speed;
293 } 293 }
294 294
295 map->start=(ioaddr_t)(u32)skt->virt_io; 295 map->start=(unsigned int)(u32)skt->virt_io;
296 map->stop=map->start+MAP_SIZE; 296 map->stop=map->start+MAP_SIZE;
297 return 0; 297 return 0;
298 298
diff --git a/drivers/pcmcia/au1000_generic.h b/drivers/pcmcia/au1000_generic.h
index a53ef5902518..13a4fbc58711 100644
--- a/drivers/pcmcia/au1000_generic.h
+++ b/drivers/pcmcia/au1000_generic.h
@@ -116,7 +116,7 @@ struct au1000_pcmcia_socket {
116 struct resource res_attr; 116 struct resource res_attr;
117 117
118 void * virt_io; 118 void * virt_io;
119 ioaddr_t phys_io; 119 unsigned int phys_io;
120 unsigned int phys_attr; 120 unsigned int phys_attr;
121 unsigned int phys_mem; 121 unsigned int phys_mem;
122 unsigned short speed_io, speed_attr, speed_mem; 122 unsigned short speed_io, speed_attr, speed_mem;
diff --git a/drivers/pcmcia/au1000_pb1x00.c b/drivers/pcmcia/au1000_pb1x00.c
index aa1cd4d3aa29..d6b4bd1db7d7 100644
--- a/drivers/pcmcia/au1000_pb1x00.c
+++ b/drivers/pcmcia/au1000_pb1x00.c
@@ -37,7 +37,6 @@
37#include <pcmcia/ss.h> 37#include <pcmcia/ss.h>
38#include <pcmcia/cistpl.h> 38#include <pcmcia/cistpl.h>
39#include <pcmcia/bus_ops.h> 39#include <pcmcia/bus_ops.h>
40#include "cs_internal.h"
41 40
42#include <asm/io.h> 41#include <asm/io.h>
43#include <asm/irq.h> 42#include <asm/irq.h>
diff --git a/drivers/pcmcia/au1000_xxs1500.c b/drivers/pcmcia/au1000_xxs1500.c
index 8a9b18cee847..9627390835ca 100644
--- a/drivers/pcmcia/au1000_xxs1500.c
+++ b/drivers/pcmcia/au1000_xxs1500.c
@@ -41,7 +41,6 @@
41#include <pcmcia/ss.h> 41#include <pcmcia/ss.h>
42#include <pcmcia/cistpl.h> 42#include <pcmcia/cistpl.h>
43#include <pcmcia/bus_ops.h> 43#include <pcmcia/bus_ops.h>
44#include "cs_internal.h"
45 44
46#include <asm/io.h> 45#include <asm/io.h>
47#include <asm/irq.h> 46#include <asm/irq.h>
diff --git a/drivers/pcmcia/cardbus.c b/drivers/pcmcia/cardbus.c
index 911ca0e8dfc2..db77e1f3309a 100644
--- a/drivers/pcmcia/cardbus.c
+++ b/drivers/pcmcia/cardbus.c
@@ -238,7 +238,7 @@ int __ref cb_alloc(struct pcmcia_socket * s)
238 pci_bus_add_devices(bus); 238 pci_bus_add_devices(bus);
239 239
240 s->irq.AssignedIRQ = s->pci_irq; 240 s->irq.AssignedIRQ = s->pci_irq;
241 return CS_SUCCESS; 241 return 0;
242} 242}
243 243
244void cb_free(struct pcmcia_socket * s) 244void cb_free(struct pcmcia_socket * s)
diff --git a/drivers/pcmcia/cistpl.c b/drivers/pcmcia/cistpl.c
index 65129b54eb09..dcce9f5d8465 100644
--- a/drivers/pcmcia/cistpl.c
+++ b/drivers/pcmcia/cistpl.c
@@ -92,7 +92,8 @@ set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flag
92 if (!(s->features & SS_CAP_STATIC_MAP) && (mem->res == NULL)) { 92 if (!(s->features & SS_CAP_STATIC_MAP) && (mem->res == NULL)) {
93 mem->res = pcmcia_find_mem_region(0, s->map_size, s->map_size, 0, s); 93 mem->res = pcmcia_find_mem_region(0, s->map_size, s->map_size, 0, s);
94 if (mem->res == NULL) { 94 if (mem->res == NULL) {
95 printk(KERN_NOTICE "cs: unable to map card memory!\n"); 95 dev_printk(KERN_NOTICE, &s->dev,
96 "cs: unable to map card memory!\n");
96 return NULL; 97 return NULL;
97 } 98 }
98 s->cis_virt = NULL; 99 s->cis_virt = NULL;
@@ -265,13 +266,13 @@ EXPORT_SYMBOL(pcmcia_write_cis_mem);
265======================================================================*/ 266======================================================================*/
266 267
267static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr, 268static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr,
268 u_int len, void *ptr) 269 size_t len, void *ptr)
269{ 270{
270 struct cis_cache_entry *cis; 271 struct cis_cache_entry *cis;
271 int ret; 272 int ret;
272 273
273 if (s->fake_cis) { 274 if (s->fake_cis) {
274 if (s->fake_cis_len > addr+len) 275 if (s->fake_cis_len >= addr+len)
275 memcpy(ptr, s->fake_cis+addr, len); 276 memcpy(ptr, s->fake_cis+addr, len);
276 else 277 else
277 memset(ptr, 0xff, len); 278 memset(ptr, 0xff, len);
@@ -351,7 +352,9 @@ int verify_cis_cache(struct pcmcia_socket *s)
351 352
352 buf = kmalloc(256, GFP_KERNEL); 353 buf = kmalloc(256, GFP_KERNEL);
353 if (buf == NULL) 354 if (buf == NULL)
354 return -1; 355 dev_printk(KERN_WARNING, &s->dev,
356 "no memory for verifying CIS\n");
357 return -ENOMEM;
355 list_for_each_entry(cis, &s->cis_cache, node) { 358 list_for_each_entry(cis, &s->cis_cache, node) {
356 int len = cis->len; 359 int len = cis->len;
357 360
@@ -380,18 +383,22 @@ int verify_cis_cache(struct pcmcia_socket *s)
380 383
381======================================================================*/ 384======================================================================*/
382 385
383int pcmcia_replace_cis(struct pcmcia_socket *s, cisdump_t *cis) 386int pcmcia_replace_cis(struct pcmcia_socket *s,
387 const u8 *data, const size_t len)
384{ 388{
385 kfree(s->fake_cis); 389 if (len > CISTPL_MAX_CIS_SIZE) {
386 s->fake_cis = NULL; 390 dev_printk(KERN_WARNING, &s->dev, "replacement CIS too big\n");
387 if (cis->Length > CISTPL_MAX_CIS_SIZE) 391 return -EINVAL;
388 return CS_BAD_SIZE; 392 }
389 s->fake_cis = kmalloc(cis->Length, GFP_KERNEL); 393 kfree(s->fake_cis);
390 if (s->fake_cis == NULL) 394 s->fake_cis = kmalloc(len, GFP_KERNEL);
391 return CS_OUT_OF_RESOURCE; 395 if (s->fake_cis == NULL) {
392 s->fake_cis_len = cis->Length; 396 dev_printk(KERN_WARNING, &s->dev, "no memory to replace CIS\n");
393 memcpy(s->fake_cis, cis->Data, cis->Length); 397 return -ENOMEM;
394 return CS_SUCCESS; 398 }
399 s->fake_cis_len = len;
400 memcpy(s->fake_cis, data, len);
401 return 0;
395} 402}
396EXPORT_SYMBOL(pcmcia_replace_cis); 403EXPORT_SYMBOL(pcmcia_replace_cis);
397 404
@@ -418,9 +425,9 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int func, tuple_t *t
418int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple_t *tuple) 425int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple_t *tuple)
419{ 426{
420 if (!s) 427 if (!s)
421 return CS_BAD_HANDLE; 428 return -EINVAL;
422 if (!(s->state & SOCKET_PRESENT)) 429 if (!(s->state & SOCKET_PRESENT))
423 return CS_NO_CARD; 430 return -ENODEV;
424 tuple->TupleLink = tuple->Flags = 0; 431 tuple->TupleLink = tuple->Flags = 0;
425#ifdef CONFIG_CARDBUS 432#ifdef CONFIG_CARDBUS
426 if (s->state & SOCKET_CARDBUS) { 433 if (s->state & SOCKET_CARDBUS) {
@@ -440,10 +447,10 @@ int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple
440 !(tuple->Attributes & TUPLE_RETURN_COMMON)) { 447 !(tuple->Attributes & TUPLE_RETURN_COMMON)) {
441 cisdata_t req = tuple->DesiredTuple; 448 cisdata_t req = tuple->DesiredTuple;
442 tuple->DesiredTuple = CISTPL_LONGLINK_MFC; 449 tuple->DesiredTuple = CISTPL_LONGLINK_MFC;
443 if (pccard_get_next_tuple(s, function, tuple) == CS_SUCCESS) { 450 if (pccard_get_next_tuple(s, function, tuple) == 0) {
444 tuple->DesiredTuple = CISTPL_LINKTARGET; 451 tuple->DesiredTuple = CISTPL_LINKTARGET;
445 if (pccard_get_next_tuple(s, function, tuple) != CS_SUCCESS) 452 if (pccard_get_next_tuple(s, function, tuple) != 0)
446 return CS_NO_MORE_ITEMS; 453 return -ENOSPC;
447 } else 454 } else
448 tuple->CISOffset = tuple->TupleLink = 0; 455 tuple->CISOffset = tuple->TupleLink = 0;
449 tuple->DesiredTuple = req; 456 tuple->DesiredTuple = req;
@@ -498,9 +505,9 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
498 int ofs, i, attr; 505 int ofs, i, attr;
499 506
500 if (!s) 507 if (!s)
501 return CS_BAD_HANDLE; 508 return -EINVAL;
502 if (!(s->state & SOCKET_PRESENT)) 509 if (!(s->state & SOCKET_PRESENT))
503 return CS_NO_CARD; 510 return -ENODEV;
504 511
505 link[1] = tuple->TupleLink; 512 link[1] = tuple->TupleLink;
506 ofs = tuple->CISOffset + tuple->TupleLink; 513 ofs = tuple->CISOffset + tuple->TupleLink;
@@ -519,7 +526,7 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
519 /* End of chain? Follow long link if possible */ 526 /* End of chain? Follow long link if possible */
520 if (link[0] == CISTPL_END) { 527 if (link[0] == CISTPL_END) {
521 if ((ofs = follow_link(s, tuple)) < 0) 528 if ((ofs = follow_link(s, tuple)) < 0)
522 return CS_NO_MORE_ITEMS; 529 return -ENOSPC;
523 attr = SPACE(tuple->Flags); 530 attr = SPACE(tuple->Flags);
524 read_cis_cache(s, attr, ofs, 2, link); 531 read_cis_cache(s, attr, ofs, 2, link);
525 } 532 }
@@ -577,13 +584,13 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
577 } 584 }
578 if (i == MAX_TUPLES) { 585 if (i == MAX_TUPLES) {
579 cs_dbg(s, 1, "cs: overrun in pcmcia_get_next_tuple\n"); 586 cs_dbg(s, 1, "cs: overrun in pcmcia_get_next_tuple\n");
580 return CS_NO_MORE_ITEMS; 587 return -ENOSPC;
581 } 588 }
582 589
583 tuple->TupleCode = link[0]; 590 tuple->TupleCode = link[0];
584 tuple->TupleLink = link[1]; 591 tuple->TupleLink = link[1];
585 tuple->CISOffset = ofs + 2; 592 tuple->CISOffset = ofs + 2;
586 return CS_SUCCESS; 593 return 0;
587} 594}
588EXPORT_SYMBOL(pccard_get_next_tuple); 595EXPORT_SYMBOL(pccard_get_next_tuple);
589 596
@@ -596,18 +603,18 @@ int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple)
596 u_int len; 603 u_int len;
597 604
598 if (!s) 605 if (!s)
599 return CS_BAD_HANDLE; 606 return -EINVAL;
600 607
601 if (tuple->TupleLink < tuple->TupleOffset) 608 if (tuple->TupleLink < tuple->TupleOffset)
602 return CS_NO_MORE_ITEMS; 609 return -ENOSPC;
603 len = tuple->TupleLink - tuple->TupleOffset; 610 len = tuple->TupleLink - tuple->TupleOffset;
604 tuple->TupleDataLen = tuple->TupleLink; 611 tuple->TupleDataLen = tuple->TupleLink;
605 if (len == 0) 612 if (len == 0)
606 return CS_SUCCESS; 613 return 0;
607 read_cis_cache(s, SPACE(tuple->Flags), 614 read_cis_cache(s, SPACE(tuple->Flags),
608 tuple->CISOffset + tuple->TupleOffset, 615 tuple->CISOffset + tuple->TupleOffset,
609 _MIN(len, tuple->TupleDataMax), tuple->TupleData); 616 _MIN(len, tuple->TupleDataMax), tuple->TupleData);
610 return CS_SUCCESS; 617 return 0;
611} 618}
612EXPORT_SYMBOL(pccard_get_tuple_data); 619EXPORT_SYMBOL(pccard_get_tuple_data);
613 620
@@ -640,25 +647,31 @@ static int parse_device(tuple_t *tuple, cistpl_device_t *device)
640 case 3: device->dev[i].speed = 150; break; 647 case 3: device->dev[i].speed = 150; break;
641 case 4: device->dev[i].speed = 100; break; 648 case 4: device->dev[i].speed = 100; break;
642 case 7: 649 case 7:
643 if (++p == q) return CS_BAD_TUPLE; 650 if (++p == q)
651 return -EINVAL;
644 device->dev[i].speed = SPEED_CVT(*p); 652 device->dev[i].speed = SPEED_CVT(*p);
645 while (*p & 0x80) 653 while (*p & 0x80)
646 if (++p == q) return CS_BAD_TUPLE; 654 if (++p == q)
655 return -EINVAL;
647 break; 656 break;
648 default: 657 default:
649 return CS_BAD_TUPLE; 658 return -EINVAL;
650 } 659 }
651 660
652 if (++p == q) return CS_BAD_TUPLE; 661 if (++p == q)
653 if (*p == 0xff) break; 662 return -EINVAL;
663 if (*p == 0xff)
664 break;
654 scale = *p & 7; 665 scale = *p & 7;
655 if (scale == 7) return CS_BAD_TUPLE; 666 if (scale == 7)
667 return -EINVAL;
656 device->dev[i].size = ((*p >> 3) + 1) * (512 << (scale*2)); 668 device->dev[i].size = ((*p >> 3) + 1) * (512 << (scale*2));
657 device->ndev++; 669 device->ndev++;
658 if (++p == q) break; 670 if (++p == q)
671 break;
659 } 672 }
660 673
661 return CS_SUCCESS; 674 return 0;
662} 675}
663 676
664/*====================================================================*/ 677/*====================================================================*/
@@ -667,12 +680,12 @@ static int parse_checksum(tuple_t *tuple, cistpl_checksum_t *csum)
667{ 680{
668 u_char *p; 681 u_char *p;
669 if (tuple->TupleDataLen < 5) 682 if (tuple->TupleDataLen < 5)
670 return CS_BAD_TUPLE; 683 return -EINVAL;
671 p = (u_char *) tuple->TupleData; 684 p = (u_char *) tuple->TupleData;
672 csum->addr = tuple->CISOffset + get_unaligned_le16(p) - 2; 685 csum->addr = tuple->CISOffset + get_unaligned_le16(p) - 2;
673 csum->len = get_unaligned_le16(p + 2); 686 csum->len = get_unaligned_le16(p + 2);
674 csum->sum = *(p + 4); 687 csum->sum = *(p + 4);
675 return CS_SUCCESS; 688 return 0;
676} 689}
677 690
678/*====================================================================*/ 691/*====================================================================*/
@@ -680,9 +693,9 @@ static int parse_checksum(tuple_t *tuple, cistpl_checksum_t *csum)
680static int parse_longlink(tuple_t *tuple, cistpl_longlink_t *link) 693static int parse_longlink(tuple_t *tuple, cistpl_longlink_t *link)
681{ 694{
682 if (tuple->TupleDataLen < 4) 695 if (tuple->TupleDataLen < 4)
683 return CS_BAD_TUPLE; 696 return -EINVAL;
684 link->addr = get_unaligned_le32(tuple->TupleData); 697 link->addr = get_unaligned_le32(tuple->TupleData);
685 return CS_SUCCESS; 698 return 0;
686} 699}
687 700
688/*====================================================================*/ 701/*====================================================================*/
@@ -697,13 +710,13 @@ static int parse_longlink_mfc(tuple_t *tuple,
697 710
698 link->nfn = *p; p++; 711 link->nfn = *p; p++;
699 if (tuple->TupleDataLen <= link->nfn*5) 712 if (tuple->TupleDataLen <= link->nfn*5)
700 return CS_BAD_TUPLE; 713 return -EINVAL;
701 for (i = 0; i < link->nfn; i++) { 714 for (i = 0; i < link->nfn; i++) {
702 link->fn[i].space = *p; p++; 715 link->fn[i].space = *p; p++;
703 link->fn[i].addr = get_unaligned_le32(p); 716 link->fn[i].addr = get_unaligned_le32(p);
704 p += 4; 717 p += 4;
705 } 718 }
706 return CS_SUCCESS; 719 return 0;
707} 720}
708 721
709/*====================================================================*/ 722/*====================================================================*/
@@ -713,24 +726,27 @@ static int parse_strings(u_char *p, u_char *q, int max,
713{ 726{
714 int i, j, ns; 727 int i, j, ns;
715 728
716 if (p == q) return CS_BAD_TUPLE; 729 if (p == q)
730 return -EINVAL;
717 ns = 0; j = 0; 731 ns = 0; j = 0;
718 for (i = 0; i < max; i++) { 732 for (i = 0; i < max; i++) {
719 if (*p == 0xff) break; 733 if (*p == 0xff)
734 break;
720 ofs[i] = j; 735 ofs[i] = j;
721 ns++; 736 ns++;
722 for (;;) { 737 for (;;) {
723 s[j++] = (*p == 0xff) ? '\0' : *p; 738 s[j++] = (*p == 0xff) ? '\0' : *p;
724 if ((*p == '\0') || (*p == 0xff)) break; 739 if ((*p == '\0') || (*p == 0xff)) break;
725 if (++p == q) return CS_BAD_TUPLE; 740 if (++p == q)
741 return -EINVAL;
726 } 742 }
727 if ((*p == 0xff) || (++p == q)) break; 743 if ((*p == 0xff) || (++p == q)) break;
728 } 744 }
729 if (found) { 745 if (found) {
730 *found = ns; 746 *found = ns;
731 return CS_SUCCESS; 747 return 0;
732 } else { 748 } else {
733 return (ns == max) ? CS_SUCCESS : CS_BAD_TUPLE; 749 return (ns == max) ? 0 : -EINVAL;
734 } 750 }
735} 751}
736 752
@@ -745,7 +761,8 @@ static int parse_vers_1(tuple_t *tuple, cistpl_vers_1_t *vers_1)
745 761
746 vers_1->major = *p; p++; 762 vers_1->major = *p; p++;
747 vers_1->minor = *p; p++; 763 vers_1->minor = *p; p++;
748 if (p >= q) return CS_BAD_TUPLE; 764 if (p >= q)
765 return -EINVAL;
749 766
750 return parse_strings(p, q, CISTPL_VERS_1_MAX_PROD_STRINGS, 767 return parse_strings(p, q, CISTPL_VERS_1_MAX_PROD_STRINGS,
751 vers_1->str, vers_1->ofs, &vers_1->ns); 768 vers_1->str, vers_1->ofs, &vers_1->ns);
@@ -781,7 +798,7 @@ static int parse_jedec(tuple_t *tuple, cistpl_jedec_t *jedec)
781 p += 2; 798 p += 2;
782 } 799 }
783 jedec->nid = nid; 800 jedec->nid = nid;
784 return CS_SUCCESS; 801 return 0;
785} 802}
786 803
787/*====================================================================*/ 804/*====================================================================*/
@@ -789,10 +806,10 @@ static int parse_jedec(tuple_t *tuple, cistpl_jedec_t *jedec)
789static int parse_manfid(tuple_t *tuple, cistpl_manfid_t *m) 806static int parse_manfid(tuple_t *tuple, cistpl_manfid_t *m)
790{ 807{
791 if (tuple->TupleDataLen < 4) 808 if (tuple->TupleDataLen < 4)
792 return CS_BAD_TUPLE; 809 return -EINVAL;
793 m->manf = get_unaligned_le16(tuple->TupleData); 810 m->manf = get_unaligned_le16(tuple->TupleData);
794 m->card = get_unaligned_le16(tuple->TupleData + 2); 811 m->card = get_unaligned_le16(tuple->TupleData + 2);
795 return CS_SUCCESS; 812 return 0;
796} 813}
797 814
798/*====================================================================*/ 815/*====================================================================*/
@@ -801,11 +818,11 @@ static int parse_funcid(tuple_t *tuple, cistpl_funcid_t *f)
801{ 818{
802 u_char *p; 819 u_char *p;
803 if (tuple->TupleDataLen < 2) 820 if (tuple->TupleDataLen < 2)
804 return CS_BAD_TUPLE; 821 return -EINVAL;
805 p = (u_char *)tuple->TupleData; 822 p = (u_char *)tuple->TupleData;
806 f->func = p[0]; 823 f->func = p[0];
807 f->sysinit = p[1]; 824 f->sysinit = p[1];
808 return CS_SUCCESS; 825 return 0;
809} 826}
810 827
811/*====================================================================*/ 828/*====================================================================*/
@@ -815,12 +832,12 @@ static int parse_funce(tuple_t *tuple, cistpl_funce_t *f)
815 u_char *p; 832 u_char *p;
816 int i; 833 int i;
817 if (tuple->TupleDataLen < 1) 834 if (tuple->TupleDataLen < 1)
818 return CS_BAD_TUPLE; 835 return -EINVAL;
819 p = (u_char *)tuple->TupleData; 836 p = (u_char *)tuple->TupleData;
820 f->type = p[0]; 837 f->type = p[0];
821 for (i = 1; i < tuple->TupleDataLen; i++) 838 for (i = 1; i < tuple->TupleDataLen; i++)
822 f->data[i-1] = p[i]; 839 f->data[i-1] = p[i];
823 return CS_SUCCESS; 840 return 0;
824} 841}
825 842
826/*====================================================================*/ 843/*====================================================================*/
@@ -834,7 +851,7 @@ static int parse_config(tuple_t *tuple, cistpl_config_t *config)
834 rasz = *p & 0x03; 851 rasz = *p & 0x03;
835 rmsz = (*p & 0x3c) >> 2; 852 rmsz = (*p & 0x3c) >> 2;
836 if (tuple->TupleDataLen < rasz+rmsz+4) 853 if (tuple->TupleDataLen < rasz+rmsz+4)
837 return CS_BAD_TUPLE; 854 return -EINVAL;
838 config->last_idx = *(++p); 855 config->last_idx = *(++p);
839 p++; 856 p++;
840 config->base = 0; 857 config->base = 0;
@@ -846,7 +863,7 @@ static int parse_config(tuple_t *tuple, cistpl_config_t *config)
846 for (i = 0; i <= rmsz; i++) 863 for (i = 0; i <= rmsz; i++)
847 config->rmask[i>>2] += p[i] << (8*(i%4)); 864 config->rmask[i>>2] += p[i] << (8*(i%4));
848 config->subtuples = tuple->TupleDataLen - (rasz+rmsz+4); 865 config->subtuples = tuple->TupleDataLen - (rasz+rmsz+4);
849 return CS_SUCCESS; 866 return 0;
850} 867}
851 868
852/*====================================================================== 869/*======================================================================
@@ -1002,10 +1019,12 @@ static u_char *parse_mem(u_char *p, u_char *q, cistpl_mem_t *mem)
1002 1019
1003static u_char *parse_irq(u_char *p, u_char *q, cistpl_irq_t *irq) 1020static u_char *parse_irq(u_char *p, u_char *q, cistpl_irq_t *irq)
1004{ 1021{
1005 if (p == q) return NULL; 1022 if (p == q)
1023 return NULL;
1006 irq->IRQInfo1 = *p; p++; 1024 irq->IRQInfo1 = *p; p++;
1007 if (irq->IRQInfo1 & IRQ_INFO2_VALID) { 1025 if (irq->IRQInfo1 & IRQ_INFO2_VALID) {
1008 if (p+2 > q) return NULL; 1026 if (p+2 > q)
1027 return NULL;
1009 irq->IRQInfo2 = (p[1]<<8) + p[0]; 1028 irq->IRQInfo2 = (p[1]<<8) + p[0];
1010 p += 2; 1029 p += 2;
1011 } 1030 }
@@ -1026,7 +1045,8 @@ static int parse_cftable_entry(tuple_t *tuple,
1026 if (*p & 0x40) 1045 if (*p & 0x40)
1027 entry->flags |= CISTPL_CFTABLE_DEFAULT; 1046 entry->flags |= CISTPL_CFTABLE_DEFAULT;
1028 if (*p & 0x80) { 1047 if (*p & 0x80) {
1029 if (++p == q) return CS_BAD_TUPLE; 1048 if (++p == q)
1049 return -EINVAL;
1030 if (*p & 0x10) 1050 if (*p & 0x10)
1031 entry->flags |= CISTPL_CFTABLE_BVDS; 1051 entry->flags |= CISTPL_CFTABLE_BVDS;
1032 if (*p & 0x20) 1052 if (*p & 0x20)
@@ -1040,30 +1060,35 @@ static int parse_cftable_entry(tuple_t *tuple,
1040 entry->interface = 0; 1060 entry->interface = 0;
1041 1061
1042 /* Process optional features */ 1062 /* Process optional features */
1043 if (++p == q) return CS_BAD_TUPLE; 1063 if (++p == q)
1064 return -EINVAL;
1044 features = *p; p++; 1065 features = *p; p++;
1045 1066
1046 /* Power options */ 1067 /* Power options */
1047 if ((features & 3) > 0) { 1068 if ((features & 3) > 0) {
1048 p = parse_power(p, q, &entry->vcc); 1069 p = parse_power(p, q, &entry->vcc);
1049 if (p == NULL) return CS_BAD_TUPLE; 1070 if (p == NULL)
1071 return -EINVAL;
1050 } else 1072 } else
1051 entry->vcc.present = 0; 1073 entry->vcc.present = 0;
1052 if ((features & 3) > 1) { 1074 if ((features & 3) > 1) {
1053 p = parse_power(p, q, &entry->vpp1); 1075 p = parse_power(p, q, &entry->vpp1);
1054 if (p == NULL) return CS_BAD_TUPLE; 1076 if (p == NULL)
1077 return -EINVAL;
1055 } else 1078 } else
1056 entry->vpp1.present = 0; 1079 entry->vpp1.present = 0;
1057 if ((features & 3) > 2) { 1080 if ((features & 3) > 2) {
1058 p = parse_power(p, q, &entry->vpp2); 1081 p = parse_power(p, q, &entry->vpp2);
1059 if (p == NULL) return CS_BAD_TUPLE; 1082 if (p == NULL)
1083 return -EINVAL;
1060 } else 1084 } else
1061 entry->vpp2.present = 0; 1085 entry->vpp2.present = 0;
1062 1086
1063 /* Timing options */ 1087 /* Timing options */
1064 if (features & 0x04) { 1088 if (features & 0x04) {
1065 p = parse_timing(p, q, &entry->timing); 1089 p = parse_timing(p, q, &entry->timing);
1066 if (p == NULL) return CS_BAD_TUPLE; 1090 if (p == NULL)
1091 return -EINVAL;
1067 } else { 1092 } else {
1068 entry->timing.wait = 0; 1093 entry->timing.wait = 0;
1069 entry->timing.ready = 0; 1094 entry->timing.ready = 0;
@@ -1073,14 +1098,16 @@ static int parse_cftable_entry(tuple_t *tuple,
1073 /* I/O window options */ 1098 /* I/O window options */
1074 if (features & 0x08) { 1099 if (features & 0x08) {
1075 p = parse_io(p, q, &entry->io); 1100 p = parse_io(p, q, &entry->io);
1076 if (p == NULL) return CS_BAD_TUPLE; 1101 if (p == NULL)
1102 return -EINVAL;
1077 } else 1103 } else
1078 entry->io.nwin = 0; 1104 entry->io.nwin = 0;
1079 1105
1080 /* Interrupt options */ 1106 /* Interrupt options */
1081 if (features & 0x10) { 1107 if (features & 0x10) {
1082 p = parse_irq(p, q, &entry->irq); 1108 p = parse_irq(p, q, &entry->irq);
1083 if (p == NULL) return CS_BAD_TUPLE; 1109 if (p == NULL)
1110 return -EINVAL;
1084 } else 1111 } else
1085 entry->irq.IRQInfo1 = 0; 1112 entry->irq.IRQInfo1 = 0;
1086 1113
@@ -1094,7 +1121,8 @@ static int parse_cftable_entry(tuple_t *tuple,
1094 entry->mem.win[0].card_addr = 0; 1121 entry->mem.win[0].card_addr = 0;
1095 entry->mem.win[0].host_addr = 0; 1122 entry->mem.win[0].host_addr = 0;
1096 p += 2; 1123 p += 2;
1097 if (p > q) return CS_BAD_TUPLE; 1124 if (p > q)
1125 return -EINVAL;
1098 break; 1126 break;
1099 case 0x40: 1127 case 0x40:
1100 entry->mem.nwin = 1; 1128 entry->mem.nwin = 1;
@@ -1102,26 +1130,30 @@ static int parse_cftable_entry(tuple_t *tuple,
1102 entry->mem.win[0].card_addr = get_unaligned_le16(p + 2) << 8; 1130 entry->mem.win[0].card_addr = get_unaligned_le16(p + 2) << 8;
1103 entry->mem.win[0].host_addr = 0; 1131 entry->mem.win[0].host_addr = 0;
1104 p += 4; 1132 p += 4;
1105 if (p > q) return CS_BAD_TUPLE; 1133 if (p > q)
1134 return -EINVAL;
1106 break; 1135 break;
1107 case 0x60: 1136 case 0x60:
1108 p = parse_mem(p, q, &entry->mem); 1137 p = parse_mem(p, q, &entry->mem);
1109 if (p == NULL) return CS_BAD_TUPLE; 1138 if (p == NULL)
1139 return -EINVAL;
1110 break; 1140 break;
1111 } 1141 }
1112 1142
1113 /* Misc features */ 1143 /* Misc features */
1114 if (features & 0x80) { 1144 if (features & 0x80) {
1115 if (p == q) return CS_BAD_TUPLE; 1145 if (p == q)
1146 return -EINVAL;
1116 entry->flags |= (*p << 8); 1147 entry->flags |= (*p << 8);
1117 while (*p & 0x80) 1148 while (*p & 0x80)
1118 if (++p == q) return CS_BAD_TUPLE; 1149 if (++p == q)
1150 return -EINVAL;
1119 p++; 1151 p++;
1120 } 1152 }
1121 1153
1122 entry->subtuples = q-p; 1154 entry->subtuples = q-p;
1123 1155
1124 return CS_SUCCESS; 1156 return 0;
1125} 1157}
1126 1158
1127/*====================================================================*/ 1159/*====================================================================*/
@@ -1132,12 +1164,12 @@ static int parse_bar(tuple_t *tuple, cistpl_bar_t *bar)
1132{ 1164{
1133 u_char *p; 1165 u_char *p;
1134 if (tuple->TupleDataLen < 6) 1166 if (tuple->TupleDataLen < 6)
1135 return CS_BAD_TUPLE; 1167 return -EINVAL;
1136 p = (u_char *)tuple->TupleData; 1168 p = (u_char *)tuple->TupleData;
1137 bar->attr = *p; 1169 bar->attr = *p;
1138 p += 2; 1170 p += 2;
1139 bar->size = get_unaligned_le32(p); 1171 bar->size = get_unaligned_le32(p);
1140 return CS_SUCCESS; 1172 return 0;
1141} 1173}
1142 1174
1143static int parse_config_cb(tuple_t *tuple, cistpl_config_t *config) 1175static int parse_config_cb(tuple_t *tuple, cistpl_config_t *config)
@@ -1146,12 +1178,12 @@ static int parse_config_cb(tuple_t *tuple, cistpl_config_t *config)
1146 1178
1147 p = (u_char *)tuple->TupleData; 1179 p = (u_char *)tuple->TupleData;
1148 if ((*p != 3) || (tuple->TupleDataLen < 6)) 1180 if ((*p != 3) || (tuple->TupleDataLen < 6))
1149 return CS_BAD_TUPLE; 1181 return -EINVAL;
1150 config->last_idx = *(++p); 1182 config->last_idx = *(++p);
1151 p++; 1183 p++;
1152 config->base = get_unaligned_le32(p); 1184 config->base = get_unaligned_le32(p);
1153 config->subtuples = tuple->TupleDataLen - 6; 1185 config->subtuples = tuple->TupleDataLen - 6;
1154 return CS_SUCCESS; 1186 return 0;
1155} 1187}
1156 1188
1157static int parse_cftable_entry_cb(tuple_t *tuple, 1189static int parse_cftable_entry_cb(tuple_t *tuple,
@@ -1167,29 +1199,34 @@ static int parse_cftable_entry_cb(tuple_t *tuple,
1167 entry->flags |= CISTPL_CFTABLE_DEFAULT; 1199 entry->flags |= CISTPL_CFTABLE_DEFAULT;
1168 1200
1169 /* Process optional features */ 1201 /* Process optional features */
1170 if (++p == q) return CS_BAD_TUPLE; 1202 if (++p == q)
1203 return -EINVAL;
1171 features = *p; p++; 1204 features = *p; p++;
1172 1205
1173 /* Power options */ 1206 /* Power options */
1174 if ((features & 3) > 0) { 1207 if ((features & 3) > 0) {
1175 p = parse_power(p, q, &entry->vcc); 1208 p = parse_power(p, q, &entry->vcc);
1176 if (p == NULL) return CS_BAD_TUPLE; 1209 if (p == NULL)
1210 return -EINVAL;
1177 } else 1211 } else
1178 entry->vcc.present = 0; 1212 entry->vcc.present = 0;
1179 if ((features & 3) > 1) { 1213 if ((features & 3) > 1) {
1180 p = parse_power(p, q, &entry->vpp1); 1214 p = parse_power(p, q, &entry->vpp1);
1181 if (p == NULL) return CS_BAD_TUPLE; 1215 if (p == NULL)
1216 return -EINVAL;
1182 } else 1217 } else
1183 entry->vpp1.present = 0; 1218 entry->vpp1.present = 0;
1184 if ((features & 3) > 2) { 1219 if ((features & 3) > 2) {
1185 p = parse_power(p, q, &entry->vpp2); 1220 p = parse_power(p, q, &entry->vpp2);
1186 if (p == NULL) return CS_BAD_TUPLE; 1221 if (p == NULL)
1222 return -EINVAL;
1187 } else 1223 } else
1188 entry->vpp2.present = 0; 1224 entry->vpp2.present = 0;
1189 1225
1190 /* I/O window options */ 1226 /* I/O window options */
1191 if (features & 0x08) { 1227 if (features & 0x08) {
1192 if (p == q) return CS_BAD_TUPLE; 1228 if (p == q)
1229 return -EINVAL;
1193 entry->io = *p; p++; 1230 entry->io = *p; p++;
1194 } else 1231 } else
1195 entry->io = 0; 1232 entry->io = 0;
@@ -1197,32 +1234,37 @@ static int parse_cftable_entry_cb(tuple_t *tuple,
1197 /* Interrupt options */ 1234 /* Interrupt options */
1198 if (features & 0x10) { 1235 if (features & 0x10) {
1199 p = parse_irq(p, q, &entry->irq); 1236 p = parse_irq(p, q, &entry->irq);
1200 if (p == NULL) return CS_BAD_TUPLE; 1237 if (p == NULL)
1238 return -EINVAL;
1201 } else 1239 } else
1202 entry->irq.IRQInfo1 = 0; 1240 entry->irq.IRQInfo1 = 0;
1203 1241
1204 if (features & 0x20) { 1242 if (features & 0x20) {
1205 if (p == q) return CS_BAD_TUPLE; 1243 if (p == q)
1244 return -EINVAL;
1206 entry->mem = *p; p++; 1245 entry->mem = *p; p++;
1207 } else 1246 } else
1208 entry->mem = 0; 1247 entry->mem = 0;
1209 1248
1210 /* Misc features */ 1249 /* Misc features */
1211 if (features & 0x80) { 1250 if (features & 0x80) {
1212 if (p == q) return CS_BAD_TUPLE; 1251 if (p == q)
1252 return -EINVAL;
1213 entry->flags |= (*p << 8); 1253 entry->flags |= (*p << 8);
1214 if (*p & 0x80) { 1254 if (*p & 0x80) {
1215 if (++p == q) return CS_BAD_TUPLE; 1255 if (++p == q)
1256 return -EINVAL;
1216 entry->flags |= (*p << 16); 1257 entry->flags |= (*p << 16);
1217 } 1258 }
1218 while (*p & 0x80) 1259 while (*p & 0x80)
1219 if (++p == q) return CS_BAD_TUPLE; 1260 if (++p == q)
1261 return -EINVAL;
1220 p++; 1262 p++;
1221 } 1263 }
1222 1264
1223 entry->subtuples = q-p; 1265 entry->subtuples = q-p;
1224 1266
1225 return CS_SUCCESS; 1267 return 0;
1226} 1268}
1227 1269
1228#endif 1270#endif
@@ -1248,7 +1290,7 @@ static int parse_device_geo(tuple_t *tuple, cistpl_device_geo_t *geo)
1248 p += 6; 1290 p += 6;
1249 } 1291 }
1250 geo->ngeo = n; 1292 geo->ngeo = n;
1251 return CS_SUCCESS; 1293 return 0;
1252} 1294}
1253 1295
1254/*====================================================================*/ 1296/*====================================================================*/
@@ -1258,7 +1300,7 @@ static int parse_vers_2(tuple_t *tuple, cistpl_vers_2_t *v2)
1258 u_char *p, *q; 1300 u_char *p, *q;
1259 1301
1260 if (tuple->TupleDataLen < 10) 1302 if (tuple->TupleDataLen < 10)
1261 return CS_BAD_TUPLE; 1303 return -EINVAL;
1262 1304
1263 p = tuple->TupleData; 1305 p = tuple->TupleData;
1264 q = p + tuple->TupleDataLen; 1306 q = p + tuple->TupleDataLen;
@@ -1282,15 +1324,18 @@ static int parse_org(tuple_t *tuple, cistpl_org_t *org)
1282 1324
1283 p = tuple->TupleData; 1325 p = tuple->TupleData;
1284 q = p + tuple->TupleDataLen; 1326 q = p + tuple->TupleDataLen;
1285 if (p == q) return CS_BAD_TUPLE; 1327 if (p == q)
1328 return -EINVAL;
1286 org->data_org = *p; 1329 org->data_org = *p;
1287 if (++p == q) return CS_BAD_TUPLE; 1330 if (++p == q)
1331 return -EINVAL;
1288 for (i = 0; i < 30; i++) { 1332 for (i = 0; i < 30; i++) {
1289 org->desc[i] = *p; 1333 org->desc[i] = *p;
1290 if (*p == '\0') break; 1334 if (*p == '\0') break;
1291 if (++p == q) return CS_BAD_TUPLE; 1335 if (++p == q)
1336 return -EINVAL;
1292 } 1337 }
1293 return CS_SUCCESS; 1338 return 0;
1294} 1339}
1295 1340
1296/*====================================================================*/ 1341/*====================================================================*/
@@ -1300,7 +1345,7 @@ static int parse_format(tuple_t *tuple, cistpl_format_t *fmt)
1300 u_char *p; 1345 u_char *p;
1301 1346
1302 if (tuple->TupleDataLen < 10) 1347 if (tuple->TupleDataLen < 10)
1303 return CS_BAD_TUPLE; 1348 return -EINVAL;
1304 1349
1305 p = tuple->TupleData; 1350 p = tuple->TupleData;
1306 1351
@@ -1309,17 +1354,17 @@ static int parse_format(tuple_t *tuple, cistpl_format_t *fmt)
1309 fmt->offset = get_unaligned_le32(p + 2); 1354 fmt->offset = get_unaligned_le32(p + 2);
1310 fmt->length = get_unaligned_le32(p + 6); 1355 fmt->length = get_unaligned_le32(p + 6);
1311 1356
1312 return CS_SUCCESS; 1357 return 0;
1313} 1358}
1314 1359
1315/*====================================================================*/ 1360/*====================================================================*/
1316 1361
1317int pccard_parse_tuple(tuple_t *tuple, cisparse_t *parse) 1362int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse)
1318{ 1363{
1319 int ret = CS_SUCCESS; 1364 int ret = 0;
1320 1365
1321 if (tuple->TupleDataLen > tuple->TupleDataMax) 1366 if (tuple->TupleDataLen > tuple->TupleDataMax)
1322 return CS_BAD_TUPLE; 1367 return -EINVAL;
1323 switch (tuple->TupleCode) { 1368 switch (tuple->TupleCode) {
1324 case CISTPL_DEVICE: 1369 case CISTPL_DEVICE:
1325 case CISTPL_DEVICE_A: 1370 case CISTPL_DEVICE_A:
@@ -1387,15 +1432,17 @@ int pccard_parse_tuple(tuple_t *tuple, cisparse_t *parse)
1387 break; 1432 break;
1388 case CISTPL_NO_LINK: 1433 case CISTPL_NO_LINK:
1389 case CISTPL_LINKTARGET: 1434 case CISTPL_LINKTARGET:
1390 ret = CS_SUCCESS; 1435 ret = 0;
1391 break; 1436 break;
1392 default: 1437 default:
1393 ret = CS_UNSUPPORTED_FUNCTION; 1438 ret = -EINVAL;
1394 break; 1439 break;
1395 } 1440 }
1441 if (ret)
1442 __cs_dbg(0, "parse_tuple failed %d\n", ret);
1396 return ret; 1443 return ret;
1397} 1444}
1398EXPORT_SYMBOL(pccard_parse_tuple); 1445EXPORT_SYMBOL(pcmcia_parse_tuple);
1399 1446
1400/*====================================================================== 1447/*======================================================================
1401 1448
@@ -1410,18 +1457,22 @@ int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, cisdata_t
1410 int ret; 1457 int ret;
1411 1458
1412 buf = kmalloc(256, GFP_KERNEL); 1459 buf = kmalloc(256, GFP_KERNEL);
1413 if (buf == NULL) 1460 if (buf == NULL) {
1414 return CS_OUT_OF_RESOURCE; 1461 dev_printk(KERN_WARNING, &s->dev, "no memory to read tuple\n");
1462 return -ENOMEM;
1463 }
1415 tuple.DesiredTuple = code; 1464 tuple.DesiredTuple = code;
1416 tuple.Attributes = TUPLE_RETURN_COMMON; 1465 tuple.Attributes = TUPLE_RETURN_COMMON;
1417 ret = pccard_get_first_tuple(s, function, &tuple); 1466 ret = pccard_get_first_tuple(s, function, &tuple);
1418 if (ret != CS_SUCCESS) goto done; 1467 if (ret != 0)
1468 goto done;
1419 tuple.TupleData = buf; 1469 tuple.TupleData = buf;
1420 tuple.TupleOffset = 0; 1470 tuple.TupleOffset = 0;
1421 tuple.TupleDataMax = 255; 1471 tuple.TupleDataMax = 255;
1422 ret = pccard_get_tuple_data(s, &tuple); 1472 ret = pccard_get_tuple_data(s, &tuple);
1423 if (ret != CS_SUCCESS) goto done; 1473 if (ret != 0)
1424 ret = pccard_parse_tuple(&tuple, parse); 1474 goto done;
1475 ret = pcmcia_parse_tuple(&tuple, parse);
1425done: 1476done:
1426 kfree(buf); 1477 kfree(buf);
1427 return ret; 1478 return ret;
@@ -1446,37 +1497,40 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, unsigned
1446 int ret, reserved, dev_ok = 0, ident_ok = 0; 1497 int ret, reserved, dev_ok = 0, ident_ok = 0;
1447 1498
1448 if (!s) 1499 if (!s)
1449 return CS_BAD_HANDLE; 1500 return -EINVAL;
1450 1501
1451 tuple = kmalloc(sizeof(*tuple), GFP_KERNEL); 1502 tuple = kmalloc(sizeof(*tuple), GFP_KERNEL);
1452 if (tuple == NULL) 1503 if (tuple == NULL) {
1453 return CS_OUT_OF_RESOURCE; 1504 dev_printk(KERN_WARNING, &s->dev, "no memory to validate CIS\n");
1505 return -ENOMEM;
1506 }
1454 p = kmalloc(sizeof(*p), GFP_KERNEL); 1507 p = kmalloc(sizeof(*p), GFP_KERNEL);
1455 if (p == NULL) { 1508 if (p == NULL) {
1456 kfree(tuple); 1509 kfree(tuple);
1457 return CS_OUT_OF_RESOURCE; 1510 dev_printk(KERN_WARNING, &s->dev, "no memory to validate CIS\n");
1511 return -ENOMEM;
1458 } 1512 }
1459 1513
1460 count = reserved = 0; 1514 count = reserved = 0;
1461 tuple->DesiredTuple = RETURN_FIRST_TUPLE; 1515 tuple->DesiredTuple = RETURN_FIRST_TUPLE;
1462 tuple->Attributes = TUPLE_RETURN_COMMON; 1516 tuple->Attributes = TUPLE_RETURN_COMMON;
1463 ret = pccard_get_first_tuple(s, function, tuple); 1517 ret = pccard_get_first_tuple(s, function, tuple);
1464 if (ret != CS_SUCCESS) 1518 if (ret != 0)
1465 goto done; 1519 goto done;
1466 1520
1467 /* First tuple should be DEVICE; we should really have either that 1521 /* First tuple should be DEVICE; we should really have either that
1468 or a CFTABLE_ENTRY of some sort */ 1522 or a CFTABLE_ENTRY of some sort */
1469 if ((tuple->TupleCode == CISTPL_DEVICE) || 1523 if ((tuple->TupleCode == CISTPL_DEVICE) ||
1470 (pccard_read_tuple(s, function, CISTPL_CFTABLE_ENTRY, p) == CS_SUCCESS) || 1524 (pccard_read_tuple(s, function, CISTPL_CFTABLE_ENTRY, p) == 0) ||
1471 (pccard_read_tuple(s, function, CISTPL_CFTABLE_ENTRY_CB, p) == CS_SUCCESS)) 1525 (pccard_read_tuple(s, function, CISTPL_CFTABLE_ENTRY_CB, p) == 0))
1472 dev_ok++; 1526 dev_ok++;
1473 1527
1474 /* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2 1528 /* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2
1475 tuple, for card identification. Certain old D-Link and Linksys 1529 tuple, for card identification. Certain old D-Link and Linksys
1476 cards have only a broken VERS_2 tuple; hence the bogus test. */ 1530 cards have only a broken VERS_2 tuple; hence the bogus test. */
1477 if ((pccard_read_tuple(s, function, CISTPL_MANFID, p) == CS_SUCCESS) || 1531 if ((pccard_read_tuple(s, function, CISTPL_MANFID, p) == 0) ||
1478 (pccard_read_tuple(s, function, CISTPL_VERS_1, p) == CS_SUCCESS) || 1532 (pccard_read_tuple(s, function, CISTPL_VERS_1, p) == 0) ||
1479 (pccard_read_tuple(s, function, CISTPL_VERS_2, p) != CS_NO_MORE_ITEMS)) 1533 (pccard_read_tuple(s, function, CISTPL_VERS_2, p) != -ENOSPC))
1480 ident_ok++; 1534 ident_ok++;
1481 1535
1482 if (!dev_ok && !ident_ok) 1536 if (!dev_ok && !ident_ok)
@@ -1484,7 +1538,8 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, unsigned
1484 1538
1485 for (count = 1; count < MAX_TUPLES; count++) { 1539 for (count = 1; count < MAX_TUPLES; count++) {
1486 ret = pccard_get_next_tuple(s, function, tuple); 1540 ret = pccard_get_next_tuple(s, function, tuple);
1487 if (ret != CS_SUCCESS) break; 1541 if (ret != 0)
1542 break;
1488 if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) || 1543 if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) ||
1489 ((tuple->TupleCode > 0x47) && (tuple->TupleCode < 0x80)) || 1544 ((tuple->TupleCode > 0x47) && (tuple->TupleCode < 0x80)) ||
1490 ((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff))) 1545 ((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff)))
@@ -1499,6 +1554,6 @@ done:
1499 *info = count; 1554 *info = count;
1500 kfree(tuple); 1555 kfree(tuple);
1501 kfree(p); 1556 kfree(p);
1502 return CS_SUCCESS; 1557 return 0;
1503} 1558}
1504EXPORT_SYMBOL(pccard_validate_cis); 1559EXPORT_SYMBOL(pccard_validate_cis);
diff --git a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c
index d1207393fc3e..c68c5d338285 100644
--- a/drivers/pcmcia/cs.c
+++ b/drivers/pcmcia/cs.c
@@ -61,7 +61,7 @@ INT_MODULE_PARM(unreset_limit, 30); /* unreset_check's */
61/* Access speed for attribute memory windows */ 61/* Access speed for attribute memory windows */
62INT_MODULE_PARM(cis_speed, 300); /* ns */ 62INT_MODULE_PARM(cis_speed, 300); /* ns */
63 63
64#ifdef DEBUG 64#ifdef CONFIG_PCMCIA_DEBUG
65static int pc_debug; 65static int pc_debug;
66 66
67module_param(pc_debug, int, 0644); 67module_param(pc_debug, int, 0644);
@@ -247,7 +247,8 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)
247 247
248 wait_for_completion(&socket->thread_done); 248 wait_for_completion(&socket->thread_done);
249 if (!socket->thread) { 249 if (!socket->thread) {
250 printk(KERN_WARNING "PCMCIA: warning: socket thread for socket %p did not start\n", socket); 250 dev_printk(KERN_WARNING, &socket->dev,
251 "PCMCIA: warning: socket thread did not start\n");
251 return -EIO; 252 return -EIO;
252 } 253 }
253 254
@@ -366,16 +367,16 @@ static int socket_reset(struct pcmcia_socket *skt)
366 skt->ops->get_status(skt, &status); 367 skt->ops->get_status(skt, &status);
367 368
368 if (!(status & SS_DETECT)) 369 if (!(status & SS_DETECT))
369 return CS_NO_CARD; 370 return -ENODEV;
370 371
371 if (status & SS_READY) 372 if (status & SS_READY)
372 return CS_SUCCESS; 373 return 0;
373 374
374 msleep(unreset_check * 10); 375 msleep(unreset_check * 10);
375 } 376 }
376 377
377 cs_err(skt, "time out after reset.\n"); 378 cs_err(skt, "time out after reset.\n");
378 return CS_GENERAL_FAILURE; 379 return -ETIMEDOUT;
379} 380}
380 381
381/* 382/*
@@ -412,7 +413,8 @@ static void socket_shutdown(struct pcmcia_socket *s)
412 413
413 s->ops->get_status(s, &status); 414 s->ops->get_status(s, &status);
414 if (status & SS_POWERON) { 415 if (status & SS_POWERON) {
415 printk(KERN_ERR "PCMCIA: socket %p: *** DANGER *** unable to remove socket power\n", s); 416 dev_printk(KERN_ERR, &s->dev,
417 "*** DANGER *** unable to remove socket power\n");
416 } 418 }
417 419
418 cs_socket_put(s); 420 cs_socket_put(s);
@@ -426,14 +428,14 @@ static int socket_setup(struct pcmcia_socket *skt, int initial_delay)
426 428
427 skt->ops->get_status(skt, &status); 429 skt->ops->get_status(skt, &status);
428 if (!(status & SS_DETECT)) 430 if (!(status & SS_DETECT))
429 return CS_NO_CARD; 431 return -ENODEV;
430 432
431 msleep(initial_delay * 10); 433 msleep(initial_delay * 10);
432 434
433 for (i = 0; i < 100; i++) { 435 for (i = 0; i < 100; i++) {
434 skt->ops->get_status(skt, &status); 436 skt->ops->get_status(skt, &status);
435 if (!(status & SS_DETECT)) 437 if (!(status & SS_DETECT))
436 return CS_NO_CARD; 438 return -ENODEV;
437 439
438 if (!(status & SS_PENDING)) 440 if (!(status & SS_PENDING))
439 break; 441 break;
@@ -443,13 +445,13 @@ static int socket_setup(struct pcmcia_socket *skt, int initial_delay)
443 445
444 if (status & SS_PENDING) { 446 if (status & SS_PENDING) {
445 cs_err(skt, "voltage interrogation timed out.\n"); 447 cs_err(skt, "voltage interrogation timed out.\n");
446 return CS_GENERAL_FAILURE; 448 return -ETIMEDOUT;
447 } 449 }
448 450
449 if (status & SS_CARDBUS) { 451 if (status & SS_CARDBUS) {
450 if (!(skt->features & SS_CAP_CARDBUS)) { 452 if (!(skt->features & SS_CAP_CARDBUS)) {
451 cs_err(skt, "cardbus cards are not supported.\n"); 453 cs_err(skt, "cardbus cards are not supported.\n");
452 return CS_BAD_TYPE; 454 return -EINVAL;
453 } 455 }
454 skt->state |= SOCKET_CARDBUS; 456 skt->state |= SOCKET_CARDBUS;
455 } 457 }
@@ -463,7 +465,7 @@ static int socket_setup(struct pcmcia_socket *skt, int initial_delay)
463 skt->socket.Vcc = skt->socket.Vpp = 50; 465 skt->socket.Vcc = skt->socket.Vpp = 50;
464 else { 466 else {
465 cs_err(skt, "unsupported voltage key.\n"); 467 cs_err(skt, "unsupported voltage key.\n");
466 return CS_BAD_TYPE; 468 return -EIO;
467 } 469 }
468 470
469 if (skt->power_hook) 471 if (skt->power_hook)
@@ -480,7 +482,7 @@ static int socket_setup(struct pcmcia_socket *skt, int initial_delay)
480 skt->ops->get_status(skt, &status); 482 skt->ops->get_status(skt, &status);
481 if (!(status & SS_POWERON)) { 483 if (!(status & SS_POWERON)) {
482 cs_err(skt, "unable to apply power.\n"); 484 cs_err(skt, "unable to apply power.\n");
483 return CS_BAD_TYPE; 485 return -EIO;
484 } 486 }
485 487
486 status = socket_reset(skt); 488 status = socket_reset(skt);
@@ -502,15 +504,16 @@ static int socket_insert(struct pcmcia_socket *skt)
502 cs_dbg(skt, 4, "insert\n"); 504 cs_dbg(skt, 4, "insert\n");
503 505
504 if (!cs_socket_get(skt)) 506 if (!cs_socket_get(skt))
505 return CS_NO_CARD; 507 return -ENODEV;
506 508
507 ret = socket_setup(skt, setup_delay); 509 ret = socket_setup(skt, setup_delay);
508 if (ret == CS_SUCCESS) { 510 if (ret == 0) {
509 skt->state |= SOCKET_PRESENT; 511 skt->state |= SOCKET_PRESENT;
510 512
511 printk(KERN_NOTICE "pccard: %s card inserted into slot %d\n", 513 dev_printk(KERN_NOTICE, &skt->dev,
512 (skt->state & SOCKET_CARDBUS) ? "CardBus" : "PCMCIA", 514 "pccard: %s card inserted into slot %d\n",
513 skt->sock); 515 (skt->state & SOCKET_CARDBUS) ? "CardBus" : "PCMCIA",
516 skt->sock);
514 517
515#ifdef CONFIG_CARDBUS 518#ifdef CONFIG_CARDBUS
516 if (skt->state & SOCKET_CARDBUS) { 519 if (skt->state & SOCKET_CARDBUS) {
@@ -531,7 +534,7 @@ static int socket_insert(struct pcmcia_socket *skt)
531static int socket_suspend(struct pcmcia_socket *skt) 534static int socket_suspend(struct pcmcia_socket *skt)
532{ 535{
533 if (skt->state & SOCKET_SUSPEND) 536 if (skt->state & SOCKET_SUSPEND)
534 return CS_IN_USE; 537 return -EBUSY;
535 538
536 send_event(skt, CS_EVENT_PM_SUSPEND, CS_EVENT_PRI_LOW); 539 send_event(skt, CS_EVENT_PM_SUSPEND, CS_EVENT_PRI_LOW);
537 skt->socket = dead_socket; 540 skt->socket = dead_socket;
@@ -540,7 +543,7 @@ static int socket_suspend(struct pcmcia_socket *skt)
540 skt->ops->suspend(skt); 543 skt->ops->suspend(skt);
541 skt->state |= SOCKET_SUSPEND; 544 skt->state |= SOCKET_SUSPEND;
542 545
543 return CS_SUCCESS; 546 return 0;
544} 547}
545 548
546/* 549/*
@@ -553,7 +556,7 @@ static int socket_resume(struct pcmcia_socket *skt)
553 int ret; 556 int ret;
554 557
555 if (!(skt->state & SOCKET_SUSPEND)) 558 if (!(skt->state & SOCKET_SUSPEND))
556 return CS_IN_USE; 559 return -EBUSY;
557 560
558 skt->socket = dead_socket; 561 skt->socket = dead_socket;
559 skt->ops->init(skt); 562 skt->ops->init(skt);
@@ -565,7 +568,7 @@ static int socket_resume(struct pcmcia_socket *skt)
565 } 568 }
566 569
567 ret = socket_setup(skt, resume_delay); 570 ret = socket_setup(skt, resume_delay);
568 if (ret == CS_SUCCESS) { 571 if (ret == 0) {
569 /* 572 /*
570 * FIXME: need a better check here for cardbus cards. 573 * FIXME: need a better check here for cardbus cards.
571 */ 574 */
@@ -590,12 +593,13 @@ static int socket_resume(struct pcmcia_socket *skt)
590 593
591 skt->state &= ~SOCKET_SUSPEND; 594 skt->state &= ~SOCKET_SUSPEND;
592 595
593 return CS_SUCCESS; 596 return 0;
594} 597}
595 598
596static void socket_remove(struct pcmcia_socket *skt) 599static void socket_remove(struct pcmcia_socket *skt)
597{ 600{
598 printk(KERN_NOTICE "pccard: card ejected from slot %d\n", skt->sock); 601 dev_printk(KERN_NOTICE, &skt->dev,
602 "pccard: card ejected from slot %d\n", skt->sock);
599 socket_shutdown(skt); 603 socket_shutdown(skt);
600} 604}
601 605
@@ -641,8 +645,8 @@ static int pccardd(void *__skt)
641 /* register with the device core */ 645 /* register with the device core */
642 ret = device_register(&skt->dev); 646 ret = device_register(&skt->dev);
643 if (ret) { 647 if (ret) {
644 printk(KERN_WARNING "PCMCIA: unable to register socket 0x%p\n", 648 dev_printk(KERN_WARNING, &skt->dev,
645 skt); 649 "PCMCIA: unable to register socket\n");
646 skt->thread = NULL; 650 skt->thread = NULL;
647 complete(&skt->thread_done); 651 complete(&skt->thread_done);
648 return 0; 652 return 0;
@@ -748,7 +752,7 @@ EXPORT_SYMBOL(pccard_register_pcmcia);
748 * CIS register. 752 * CIS register.
749 */ 753 */
750 754
751int pccard_reset_card(struct pcmcia_socket *skt) 755int pcmcia_reset_card(struct pcmcia_socket *skt)
752{ 756{
753 int ret; 757 int ret;
754 758
@@ -757,15 +761,15 @@ int pccard_reset_card(struct pcmcia_socket *skt)
757 mutex_lock(&skt->skt_mutex); 761 mutex_lock(&skt->skt_mutex);
758 do { 762 do {
759 if (!(skt->state & SOCKET_PRESENT)) { 763 if (!(skt->state & SOCKET_PRESENT)) {
760 ret = CS_NO_CARD; 764 ret = -ENODEV;
761 break; 765 break;
762 } 766 }
763 if (skt->state & SOCKET_SUSPEND) { 767 if (skt->state & SOCKET_SUSPEND) {
764 ret = CS_IN_USE; 768 ret = -EBUSY;
765 break; 769 break;
766 } 770 }
767 if (skt->state & SOCKET_CARDBUS) { 771 if (skt->state & SOCKET_CARDBUS) {
768 ret = CS_UNSUPPORTED_FUNCTION; 772 ret = -EPERM;
769 break; 773 break;
770 } 774 }
771 775
@@ -774,20 +778,20 @@ int pccard_reset_card(struct pcmcia_socket *skt)
774 send_event(skt, CS_EVENT_RESET_PHYSICAL, CS_EVENT_PRI_LOW); 778 send_event(skt, CS_EVENT_RESET_PHYSICAL, CS_EVENT_PRI_LOW);
775 if (skt->callback) 779 if (skt->callback)
776 skt->callback->suspend(skt); 780 skt->callback->suspend(skt);
777 if (socket_reset(skt) == CS_SUCCESS) { 781 if (socket_reset(skt) == 0) {
778 send_event(skt, CS_EVENT_CARD_RESET, CS_EVENT_PRI_LOW); 782 send_event(skt, CS_EVENT_CARD_RESET, CS_EVENT_PRI_LOW);
779 if (skt->callback) 783 if (skt->callback)
780 skt->callback->resume(skt); 784 skt->callback->resume(skt);
781 } 785 }
782 } 786 }
783 787
784 ret = CS_SUCCESS; 788 ret = 0;
785 } while (0); 789 } while (0);
786 mutex_unlock(&skt->skt_mutex); 790 mutex_unlock(&skt->skt_mutex);
787 791
788 return ret; 792 return ret;
789} /* reset_card */ 793} /* reset_card */
790EXPORT_SYMBOL(pccard_reset_card); 794EXPORT_SYMBOL(pcmcia_reset_card);
791 795
792 796
793/* These shut down or wake up a socket. They are sort of user 797/* These shut down or wake up a socket. They are sort of user
@@ -802,11 +806,11 @@ int pcmcia_suspend_card(struct pcmcia_socket *skt)
802 mutex_lock(&skt->skt_mutex); 806 mutex_lock(&skt->skt_mutex);
803 do { 807 do {
804 if (!(skt->state & SOCKET_PRESENT)) { 808 if (!(skt->state & SOCKET_PRESENT)) {
805 ret = CS_NO_CARD; 809 ret = -ENODEV;
806 break; 810 break;
807 } 811 }
808 if (skt->state & SOCKET_CARDBUS) { 812 if (skt->state & SOCKET_CARDBUS) {
809 ret = CS_UNSUPPORTED_FUNCTION; 813 ret = -EPERM;
810 break; 814 break;
811 } 815 }
812 if (skt->callback) { 816 if (skt->callback) {
@@ -832,11 +836,11 @@ int pcmcia_resume_card(struct pcmcia_socket *skt)
832 mutex_lock(&skt->skt_mutex); 836 mutex_lock(&skt->skt_mutex);
833 do { 837 do {
834 if (!(skt->state & SOCKET_PRESENT)) { 838 if (!(skt->state & SOCKET_PRESENT)) {
835 ret = CS_NO_CARD; 839 ret = -ENODEV;
836 break; 840 break;
837 } 841 }
838 if (skt->state & SOCKET_CARDBUS) { 842 if (skt->state & SOCKET_CARDBUS) {
839 ret = CS_UNSUPPORTED_FUNCTION; 843 ret = -EPERM;
840 break; 844 break;
841 } 845 }
842 ret = socket_resume(skt); 846 ret = socket_resume(skt);
@@ -892,7 +896,7 @@ int pcmcia_insert_card(struct pcmcia_socket *skt)
892 ret = -EBUSY; 896 ret = -EBUSY;
893 break; 897 break;
894 } 898 }
895 if (socket_insert(skt) == CS_NO_CARD) { 899 if (socket_insert(skt) == -ENODEV) {
896 ret = -ENODEV; 900 ret = -ENODEV;
897 break; 901 break;
898 } 902 }
diff --git a/drivers/pcmcia/cs_internal.h b/drivers/pcmcia/cs_internal.h
index 63dc1a28bda2..79615e6d540b 100644
--- a/drivers/pcmcia/cs_internal.h
+++ b/drivers/pcmcia/cs_internal.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * cs_internal.h 2 * cs_internal.h -- definitions internal to the PCMCIA core modules
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as 5 * it under the terms of the GNU General Public License version 2 as
@@ -10,6 +10,12 @@
10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved. 10 * are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
11 * 11 *
12 * (C) 1999 David A. Hinds 12 * (C) 1999 David A. Hinds
13 * (C) 2003 - 2008 Dominik Brodowski
14 *
15 *
16 * This file contains definitions _only_ needed by the PCMCIA core modules.
17 * It must not be included by PCMCIA socket drivers or by PCMCIA device
18 * drivers.
13 */ 19 */
14 20
15#ifndef _LINUX_CS_INTERNAL_H 21#ifndef _LINUX_CS_INTERNAL_H
@@ -18,29 +24,24 @@
18#include <linux/kref.h> 24#include <linux/kref.h>
19 25
20/* Flags in client state */ 26/* Flags in client state */
21#define CLIENT_CONFIG_LOCKED 0x0001
22#define CLIENT_IRQ_REQ 0x0002
23#define CLIENT_IO_REQ 0x0004
24#define CLIENT_UNBOUND 0x0008
25#define CLIENT_STALE 0x0010
26#define CLIENT_WIN_REQ(i) (0x1<<(i)) 27#define CLIENT_WIN_REQ(i) (0x1<<(i))
27#define CLIENT_CARDBUS 0x8000
28 28
29/* Each card function gets one of these guys */ 29/* Each card function gets one of these guys */
30typedef struct config_t { 30typedef struct config_t {
31 struct kref ref; 31 struct kref ref;
32 u_int state; 32 unsigned int state;
33 u_int Attributes; 33 unsigned int Attributes;
34 u_int IntType; 34 unsigned int IntType;
35 u_int ConfigBase; 35 unsigned int ConfigBase;
36 u_char Status, Pin, Copy, Option, ExtStatus; 36 unsigned char Status, Pin, Copy, Option, ExtStatus;
37 u_int CardValues; 37 unsigned int CardValues;
38 io_req_t io; 38 io_req_t io;
39 struct { 39 struct {
40 u_int Attributes; 40 u_int Attributes;
41 } irq; 41 } irq;
42} config_t; 42} config_t;
43 43
44
44struct cis_cache_entry { 45struct cis_cache_entry {
45 struct list_head node; 46 struct list_head node;
46 unsigned int addr; 47 unsigned int addr;
@@ -49,6 +50,30 @@ struct cis_cache_entry {
49 unsigned char cache[0]; 50 unsigned char cache[0];
50}; 51};
51 52
53struct pccard_resource_ops {
54 int (*validate_mem) (struct pcmcia_socket *s);
55 int (*adjust_io_region) (struct resource *res,
56 unsigned long r_start,
57 unsigned long r_end,
58 struct pcmcia_socket *s);
59 struct resource* (*find_io) (unsigned long base, int num,
60 unsigned long align,
61 struct pcmcia_socket *s);
62 struct resource* (*find_mem) (unsigned long base, unsigned long num,
63 unsigned long align, int low,
64 struct pcmcia_socket *s);
65 int (*add_io) (struct pcmcia_socket *s,
66 unsigned int action,
67 unsigned long r_start,
68 unsigned long r_end);
69 int (*add_mem) (struct pcmcia_socket *s,
70 unsigned int action,
71 unsigned long r_start,
72 unsigned long r_end);
73 int (*init) (struct pcmcia_socket *s);
74 void (*exit) (struct pcmcia_socket *s);
75};
76
52/* Flags in config state */ 77/* Flags in config state */
53#define CONFIG_LOCKED 0x01 78#define CONFIG_LOCKED 0x01
54#define CONFIG_IRQ_REQ 0x02 79#define CONFIG_IRQ_REQ 0x02
@@ -59,7 +84,6 @@ struct cis_cache_entry {
59#define SOCKET_INUSE 0x0010 84#define SOCKET_INUSE 0x0010
60#define SOCKET_SUSPEND 0x0080 85#define SOCKET_SUSPEND 0x0080
61#define SOCKET_WIN_REQ(i) (0x0100<<(i)) 86#define SOCKET_WIN_REQ(i) (0x0100<<(i))
62#define SOCKET_REGION_INFO 0x4000
63#define SOCKET_CARDBUS 0x8000 87#define SOCKET_CARDBUS 0x8000
64#define SOCKET_CARDBUS_CONFIG 0x10000 88#define SOCKET_CARDBUS_CONFIG 0x10000
65 89
@@ -83,69 +107,153 @@ static inline void cs_socket_put(struct pcmcia_socket *skt)
83 } 107 }
84} 108}
85 109
86/* In cardbus.c */ 110#ifdef CONFIG_PCMCIA_DEBUG
87int cb_alloc(struct pcmcia_socket *s); 111extern int cs_debug_level(int);
88void cb_free(struct pcmcia_socket *s);
89int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len, void *ptr);
90 112
91/* In cistpl.c */ 113#define cs_dbg(skt, lvl, fmt, arg...) do { \
92int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr, 114 if (cs_debug_level(lvl)) \
93 u_int addr, u_int len, void *ptr); 115 dev_printk(KERN_DEBUG, &skt->dev, \
94void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr, 116 "cs: " fmt, ## arg); \
95 u_int addr, u_int len, void *ptr); 117} while (0)
96void release_cis_mem(struct pcmcia_socket *s); 118#define __cs_dbg(lvl, fmt, arg...) do { \
97void destroy_cis_cache(struct pcmcia_socket *s); 119 if (cs_debug_level(lvl)) \
120 printk(KERN_DEBUG \
121 "cs: " fmt, ## arg); \
122} while (0)
123
124#else
125#define cs_dbg(skt, lvl, fmt, arg...) do { } while (0)
126#define __cs_dbg(lvl, fmt, arg...) do { } while (0)
127#endif
128
129#define cs_err(skt, fmt, arg...) \
130 dev_printk(KERN_ERR, &skt->dev, "cs: " fmt, ## arg)
131
132
133/*
134 * Stuff internal to module "pcmcia_core":
135 */
136
137/* cistpl.c */
98int verify_cis_cache(struct pcmcia_socket *s); 138int verify_cis_cache(struct pcmcia_socket *s);
99int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, cisdata_t code, void *parse);
100 139
101/* In rsrc_mgr */ 140/* rsrc_mgr.c */
102int pcmcia_validate_mem(struct pcmcia_socket *s);
103struct resource *pcmcia_find_io_region(unsigned long base, int num, unsigned long align,
104 struct pcmcia_socket *s);
105int pcmcia_adjust_io_region(struct resource *res, unsigned long r_start,
106 unsigned long r_end, struct pcmcia_socket *s);
107struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
108 int low, struct pcmcia_socket *s);
109void release_resource_db(struct pcmcia_socket *s); 141void release_resource_db(struct pcmcia_socket *s);
110 142
111/* In socket_sysfs.c */ 143/* socket_sysfs.c */
112extern int pccard_sysfs_add_socket(struct device *dev); 144extern int pccard_sysfs_add_socket(struct device *dev);
113extern void pccard_sysfs_remove_socket(struct device *dev); 145extern void pccard_sysfs_remove_socket(struct device *dev);
114 146
115/* In cs.c */ 147/* cardbus.c */
116extern struct rw_semaphore pcmcia_socket_list_rwsem; 148int cb_alloc(struct pcmcia_socket *s);
117extern struct list_head pcmcia_socket_list; 149void cb_free(struct pcmcia_socket *s);
118int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, int idx, win_req_t *req); 150int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len,
119int pccard_get_configuration_info(struct pcmcia_socket *s, struct pcmcia_device *p_dev, config_info_t *config); 151 void *ptr);
120int pccard_reset_card(struct pcmcia_socket *skt); 152
121 153
122 154
155/*
156 * Stuff exported by module "pcmcia_core" to module "pcmcia"
157 */
158
123struct pcmcia_callback{ 159struct pcmcia_callback{
124 struct module *owner; 160 struct module *owner;
125 int (*event) (struct pcmcia_socket *s, event_t event, int priority); 161 int (*event) (struct pcmcia_socket *s,
162 event_t event, int priority);
126 void (*requery) (struct pcmcia_socket *s, int new_cis); 163 void (*requery) (struct pcmcia_socket *s, int new_cis);
127 int (*suspend) (struct pcmcia_socket *s); 164 int (*suspend) (struct pcmcia_socket *s);
128 int (*resume) (struct pcmcia_socket *s); 165 int (*resume) (struct pcmcia_socket *s);
129}; 166};
130 167
168/* cs.c */
169extern struct rw_semaphore pcmcia_socket_list_rwsem;
170extern struct list_head pcmcia_socket_list;
171extern struct class pcmcia_socket_class;
172
173int pcmcia_get_window(struct pcmcia_socket *s,
174 window_handle_t *handle,
175 int idx,
176 win_req_t *req);
131int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c); 177int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c);
178struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr);
132 179
133#define cs_socket_name(skt) ((skt)->dev.bus_id) 180int pcmcia_suspend_card(struct pcmcia_socket *skt);
181int pcmcia_resume_card(struct pcmcia_socket *skt);
134 182
135#ifdef DEBUG 183int pcmcia_eject_card(struct pcmcia_socket *skt);
136extern int cs_debug_level(int); 184int pcmcia_insert_card(struct pcmcia_socket *skt);
137 185
138#define cs_dbg(skt, lvl, fmt, arg...) do { \ 186struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt);
139 if (cs_debug_level(lvl)) \ 187void pcmcia_put_socket(struct pcmcia_socket *skt);
140 printk(KERN_DEBUG "cs: %s: " fmt, \
141 cs_socket_name(skt) , ## arg); \
142} while (0)
143 188
144#else 189/* cistpl.c */
145#define cs_dbg(skt, lvl, fmt, arg...) do { } while (0) 190int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr,
146#endif 191 u_int addr, u_int len, void *ptr);
192void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr,
193 u_int addr, u_int len, void *ptr);
194void release_cis_mem(struct pcmcia_socket *s);
195void destroy_cis_cache(struct pcmcia_socket *s);
196int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function,
197 cisdata_t code, void *parse);
198int pcmcia_replace_cis(struct pcmcia_socket *s,
199 const u8 *data, const size_t len);
200int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function,
201 unsigned int *count);
147 202
148#define cs_err(skt, fmt, arg...) \ 203/* rsrc_mgr.c */
149 printk(KERN_ERR "cs: %s: " fmt, (skt)->dev.bus_id , ## arg) 204int pcmcia_validate_mem(struct pcmcia_socket *s);
205struct resource *pcmcia_find_io_region(unsigned long base,
206 int num,
207 unsigned long align,
208 struct pcmcia_socket *s);
209int pcmcia_adjust_io_region(struct resource *res,
210 unsigned long r_start,
211 unsigned long r_end,
212 struct pcmcia_socket *s);
213struct resource *pcmcia_find_mem_region(u_long base,
214 u_long num,
215 u_long align,
216 int low,
217 struct pcmcia_socket *s);
218
219/*
220 * Stuff internal to module "pcmcia".
221 */
222/* ds.c */
223extern struct bus_type pcmcia_bus_type;
224
225/* pcmcia_resource.c */
226extern int pcmcia_release_configuration(struct pcmcia_device *p_dev);
227
228#ifdef CONFIG_PCMCIA_IOCTL
229/* ds.c */
230extern spinlock_t pcmcia_dev_list_lock;
231
232extern struct pcmcia_device *pcmcia_get_dev(struct pcmcia_device *p_dev);
233extern void pcmcia_put_dev(struct pcmcia_device *p_dev);
234
235struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s,
236 unsigned int function);
237
238/* pcmcia_ioctl.c */
239extern void __init pcmcia_setup_ioctl(void);
240extern void __exit pcmcia_cleanup_ioctl(void);
241extern void handle_event(struct pcmcia_socket *s, event_t event);
242extern int handle_request(struct pcmcia_socket *s, event_t event);
243
244#else /* CONFIG_PCMCIA_IOCTL */
245
246static inline void __init pcmcia_setup_ioctl(void) { return; }
247static inline void __exit pcmcia_cleanup_ioctl(void) { return; }
248static inline void handle_event(struct pcmcia_socket *s, event_t event)
249{
250 return;
251}
252static inline int handle_request(struct pcmcia_socket *s, event_t event)
253{
254 return 0;
255}
256
257#endif /* CONFIG_PCMCIA_IOCTL */
150 258
151#endif /* _LINUX_CS_INTERNAL_H */ 259#endif /* _LINUX_CS_INTERNAL_H */
diff --git a/drivers/pcmcia/ds.c b/drivers/pcmcia/ds.c
index 34c83d3ca0fa..795660255490 100644
--- a/drivers/pcmcia/ds.c
+++ b/drivers/pcmcia/ds.c
@@ -32,7 +32,6 @@
32#include <pcmcia/ss.h> 32#include <pcmcia/ss.h>
33 33
34#include "cs_internal.h" 34#include "cs_internal.h"
35#include "ds_internal.h"
36 35
37/*====================================================================*/ 36/*====================================================================*/
38 37
@@ -42,17 +41,22 @@ MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
42MODULE_DESCRIPTION("PCMCIA Driver Services"); 41MODULE_DESCRIPTION("PCMCIA Driver Services");
43MODULE_LICENSE("GPL"); 42MODULE_LICENSE("GPL");
44 43
45#ifdef DEBUG 44#ifdef CONFIG_PCMCIA_DEBUG
46int ds_pc_debug; 45int ds_pc_debug;
47 46
48module_param_named(pc_debug, ds_pc_debug, int, 0644); 47module_param_named(pc_debug, ds_pc_debug, int, 0644);
49 48
50#define ds_dbg(lvl, fmt, arg...) do { \ 49#define ds_dbg(lvl, fmt, arg...) do { \
51 if (ds_pc_debug > (lvl)) \ 50 if (ds_pc_debug > (lvl)) \
52 printk(KERN_DEBUG "ds: " fmt , ## arg); \ 51 printk(KERN_DEBUG "ds: " fmt , ## arg); \
53} while (0) 52} while (0)
53#define ds_dev_dbg(lvl, dev, fmt, arg...) do { \
54 if (ds_pc_debug > (lvl)) \
55 dev_printk(KERN_DEBUG, dev, "ds: " fmt , ## arg); \
56} while (0)
54#else 57#else
55#define ds_dbg(lvl, fmt, arg...) do { } while (0) 58#define ds_dbg(lvl, fmt, arg...) do { } while (0)
59#define ds_dev_dbg(lvl, dev, fmt, arg...) do { } while (0)
56#endif 60#endif
57 61
58spinlock_t pcmcia_dev_list_lock; 62spinlock_t pcmcia_dev_list_lock;
@@ -64,42 +68,19 @@ spinlock_t pcmcia_dev_list_lock;
64/* String tables for error messages */ 68/* String tables for error messages */
65 69
66typedef struct lookup_t { 70typedef struct lookup_t {
67 int key; 71 const int key;
68 char *msg; 72 const char *msg;
69} lookup_t; 73} lookup_t;
70 74
71static const lookup_t error_table[] = { 75static const lookup_t error_table[] = {
72 { CS_SUCCESS, "Operation succeeded" }, 76 { 0, "Operation succeeded" },
73 { CS_BAD_ADAPTER, "Bad adapter" }, 77 { -EIO, "Input/Output error" },
74 { CS_BAD_ATTRIBUTE, "Bad attribute", }, 78 { -ENODEV, "No card present" },
75 { CS_BAD_BASE, "Bad base address" }, 79 { -EINVAL, "Bad parameter" },
76 { CS_BAD_EDC, "Bad EDC" }, 80 { -EACCES, "Configuration locked" },
77 { CS_BAD_IRQ, "Bad IRQ" }, 81 { -EBUSY, "Resource in use" },
78 { CS_BAD_OFFSET, "Bad offset" }, 82 { -ENOSPC, "No more items" },
79 { CS_BAD_PAGE, "Bad page number" }, 83 { -ENOMEM, "Out of resource" },
80 { CS_READ_FAILURE, "Read failure" },
81 { CS_BAD_SIZE, "Bad size" },
82 { CS_BAD_SOCKET, "Bad socket" },
83 { CS_BAD_TYPE, "Bad type" },
84 { CS_BAD_VCC, "Bad Vcc" },
85 { CS_BAD_VPP, "Bad Vpp" },
86 { CS_BAD_WINDOW, "Bad window" },
87 { CS_WRITE_FAILURE, "Write failure" },
88 { CS_NO_CARD, "No card present" },
89 { CS_UNSUPPORTED_FUNCTION, "Usupported function" },
90 { CS_UNSUPPORTED_MODE, "Unsupported mode" },
91 { CS_BAD_SPEED, "Bad speed" },
92 { CS_BUSY, "Resource busy" },
93 { CS_GENERAL_FAILURE, "General failure" },
94 { CS_WRITE_PROTECTED, "Write protected" },
95 { CS_BAD_ARG_LENGTH, "Bad argument length" },
96 { CS_BAD_ARGS, "Bad arguments" },
97 { CS_CONFIGURATION_LOCKED, "Configuration locked" },
98 { CS_IN_USE, "Resource in use" },
99 { CS_NO_MORE_ITEMS, "No more items" },
100 { CS_OUT_OF_RESOURCE, "Out of resource" },
101 { CS_BAD_HANDLE, "Bad handle" },
102 { CS_BAD_TUPLE, "Bad CIS tuple" }
103}; 84};
104 85
105 86
@@ -155,46 +136,32 @@ static const lookup_t service_table[] = {
155 { ReplaceCIS, "ReplaceCIS" } 136 { ReplaceCIS, "ReplaceCIS" }
156}; 137};
157 138
158 139const char *pcmcia_error_func(int func)
159static int pcmcia_report_error(struct pcmcia_device *p_dev, error_info_t *err)
160{ 140{
161 int i; 141 int i;
162 char *serv;
163
164 if (!p_dev)
165 printk(KERN_NOTICE);
166 else
167 printk(KERN_NOTICE "%s: ", p_dev->dev.bus_id);
168 142
169 for (i = 0; i < ARRAY_SIZE(service_table); i++) 143 for (i = 0; i < ARRAY_SIZE(service_table); i++)
170 if (service_table[i].key == err->func) 144 if (service_table[i].key == func)
171 break; 145 return service_table[i].msg;
172 if (i < ARRAY_SIZE(service_table))
173 serv = service_table[i].msg;
174 else
175 serv = "Unknown service number";
176 146
177 for (i = 0; i < ARRAY_SIZE(error_table); i++) 147 return "Unknown service number";
178 if (error_table[i].key == err->retcode) 148}
179 break; 149EXPORT_SYMBOL(pcmcia_error_func);
180 if (i < ARRAY_SIZE(error_table))
181 printk("%s: %s\n", serv, error_table[i].msg);
182 else
183 printk("%s: Unknown error code %#x\n", serv, err->retcode);
184 150
185 return CS_SUCCESS; 151const char *pcmcia_error_ret(int ret)
186} /* report_error */ 152{
153 int i;
154
155 for (i = 0; i < ARRAY_SIZE(error_table); i++)
156 if (error_table[i].key == ret)
157 return error_table[i].msg;
187 158
188/* end of code which was in cs.c before */ 159 return "unknown";
160}
161EXPORT_SYMBOL(pcmcia_error_ret);
189 162
190/*======================================================================*/ 163/*======================================================================*/
191 164
192void cs_error(struct pcmcia_device *p_dev, int func, int ret)
193{
194 error_info_t err = { func, ret };
195 pcmcia_report_error(p_dev, &err);
196}
197EXPORT_SYMBOL(cs_error);
198 165
199 166
200static void pcmcia_check_driver(struct pcmcia_driver *p_drv) 167static void pcmcia_check_driver(struct pcmcia_driver *p_drv)
@@ -391,7 +358,7 @@ static void pcmcia_release_function(struct kref *ref)
391static void pcmcia_release_dev(struct device *dev) 358static void pcmcia_release_dev(struct device *dev)
392{ 359{
393 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 360 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
394 ds_dbg(1, "releasing device %s\n", p_dev->dev.bus_id); 361 ds_dev_dbg(1, dev, "releasing device\n");
395 pcmcia_put_socket(p_dev->socket); 362 pcmcia_put_socket(p_dev->socket);
396 kfree(p_dev->devname); 363 kfree(p_dev->devname);
397 kref_put(&p_dev->function_config->ref, pcmcia_release_function); 364 kref_put(&p_dev->function_config->ref, pcmcia_release_function);
@@ -401,7 +368,7 @@ static void pcmcia_release_dev(struct device *dev)
401static void pcmcia_add_device_later(struct pcmcia_socket *s, int mfc) 368static void pcmcia_add_device_later(struct pcmcia_socket *s, int mfc)
402{ 369{
403 if (!s->pcmcia_state.device_add_pending) { 370 if (!s->pcmcia_state.device_add_pending) {
404 ds_dbg(1, "scheduling to add %s secondary" 371 ds_dev_dbg(1, &s->dev, "scheduling to add %s secondary"
405 " device to %d\n", mfc ? "mfc" : "pfc", s->sock); 372 " device to %d\n", mfc ? "mfc" : "pfc", s->sock);
406 s->pcmcia_state.device_add_pending = 1; 373 s->pcmcia_state.device_add_pending = 1;
407 s->pcmcia_state.mfc_pfc = mfc; 374 s->pcmcia_state.mfc_pfc = mfc;
@@ -439,8 +406,7 @@ static int pcmcia_device_probe(struct device * dev)
439 */ 406 */
440 did = p_dev->dev.driver_data; 407 did = p_dev->dev.driver_data;
441 408
442 ds_dbg(1, "trying to bind %s to %s\n", p_dev->dev.bus_id, 409 ds_dev_dbg(1, dev, "trying to bind to %s\n", p_drv->drv.name);
443 p_drv->drv.name);
444 410
445 if ((!p_drv->probe) || (!p_dev->function_config) || 411 if ((!p_drv->probe) || (!p_dev->function_config) ||
446 (!try_module_get(p_drv->owner))) { 412 (!try_module_get(p_drv->owner))) {
@@ -455,15 +421,16 @@ static int pcmcia_device_probe(struct device * dev)
455 p_dev->conf.ConfigBase = cis_config.base; 421 p_dev->conf.ConfigBase = cis_config.base;
456 p_dev->conf.Present = cis_config.rmask[0]; 422 p_dev->conf.Present = cis_config.rmask[0];
457 } else { 423 } else {
458 printk(KERN_INFO "pcmcia: could not parse base and rmask0 of CIS\n"); 424 dev_printk(KERN_INFO, dev,
425 "pcmcia: could not parse base and rmask0 of CIS\n");
459 p_dev->conf.ConfigBase = 0; 426 p_dev->conf.ConfigBase = 0;
460 p_dev->conf.Present = 0; 427 p_dev->conf.Present = 0;
461 } 428 }
462 429
463 ret = p_drv->probe(p_dev); 430 ret = p_drv->probe(p_dev);
464 if (ret) { 431 if (ret) {
465 ds_dbg(1, "binding %s to %s failed with %d\n", 432 ds_dev_dbg(1, dev, "binding to %s failed with %d\n",
466 p_dev->dev.bus_id, p_drv->drv.name, ret); 433 p_drv->drv.name, ret);
467 goto put_module; 434 goto put_module;
468 } 435 }
469 436
@@ -490,8 +457,9 @@ static void pcmcia_card_remove(struct pcmcia_socket *s, struct pcmcia_device *le
490 struct pcmcia_device *tmp; 457 struct pcmcia_device *tmp;
491 unsigned long flags; 458 unsigned long flags;
492 459
493 ds_dbg(2, "pcmcia_card_remove(%d) %s\n", s->sock, 460 ds_dev_dbg(2, leftover ? &leftover->dev : &s->dev,
494 leftover ? leftover->devname : ""); 461 "pcmcia_card_remove(%d) %s\n", s->sock,
462 leftover ? leftover->devname : "");
495 463
496 if (!leftover) 464 if (!leftover)
497 s->device_count = 0; 465 s->device_count = 0;
@@ -508,7 +476,7 @@ static void pcmcia_card_remove(struct pcmcia_socket *s, struct pcmcia_device *le
508 p_dev->_removed=1; 476 p_dev->_removed=1;
509 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 477 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
510 478
511 ds_dbg(2, "unregistering device %s\n", p_dev->dev.bus_id); 479 ds_dev_dbg(2, &p_dev->dev, "unregistering device\n");
512 device_unregister(&p_dev->dev); 480 device_unregister(&p_dev->dev);
513 } 481 }
514 482
@@ -525,7 +493,7 @@ static int pcmcia_device_remove(struct device * dev)
525 p_dev = to_pcmcia_dev(dev); 493 p_dev = to_pcmcia_dev(dev);
526 p_drv = to_pcmcia_drv(dev->driver); 494 p_drv = to_pcmcia_drv(dev->driver);
527 495
528 ds_dbg(1, "removing device %s\n", p_dev->dev.bus_id); 496 ds_dev_dbg(1, dev, "removing device\n");
529 497
530 /* If we're removing the primary module driving a 498 /* If we're removing the primary module driving a
531 * pseudo multi-function card, we need to unbind 499 * pseudo multi-function card, we need to unbind
@@ -548,13 +516,15 @@ static int pcmcia_device_remove(struct device * dev)
548 516
549 /* check for proper unloading */ 517 /* check for proper unloading */
550 if (p_dev->_irq || p_dev->_io || p_dev->_locked) 518 if (p_dev->_irq || p_dev->_io || p_dev->_locked)
551 printk(KERN_INFO "pcmcia: driver %s did not release config properly\n", 519 dev_printk(KERN_INFO, dev,
552 p_drv->drv.name); 520 "pcmcia: driver %s did not release config properly\n",
521 p_drv->drv.name);
553 522
554 for (i = 0; i < MAX_WIN; i++) 523 for (i = 0; i < MAX_WIN; i++)
555 if (p_dev->_win & CLIENT_WIN_REQ(i)) 524 if (p_dev->_win & CLIENT_WIN_REQ(i))
556 printk(KERN_INFO "pcmcia: driver %s did not release windows properly\n", 525 dev_printk(KERN_INFO, dev,
557 p_drv->drv.name); 526 "pcmcia: driver %s did not release window properly\n",
527 p_drv->drv.name);
558 528
559 /* references from pcmcia_probe_device */ 529 /* references from pcmcia_probe_device */
560 pcmcia_put_dev(p_dev); 530 pcmcia_put_dev(p_dev);
@@ -603,8 +573,9 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev)
603 } 573 }
604 if (!pccard_read_tuple(p_dev->socket, p_dev->func, 574 if (!pccard_read_tuple(p_dev->socket, p_dev->func,
605 CISTPL_DEVICE_GEO, devgeo)) { 575 CISTPL_DEVICE_GEO, devgeo)) {
606 ds_dbg(0, "mem device geometry probably means " 576 ds_dev_dbg(0, &p_dev->dev,
607 "FUNCID_MEMORY\n"); 577 "mem device geometry probably means "
578 "FUNCID_MEMORY\n");
608 p_dev->func_id = CISTPL_FUNCID_MEMORY; 579 p_dev->func_id = CISTPL_FUNCID_MEMORY;
609 p_dev->has_func_id = 1; 580 p_dev->has_func_id = 1;
610 } 581 }
@@ -685,7 +656,7 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
685 if (!p_dev->devname) 656 if (!p_dev->devname)
686 goto err_free; 657 goto err_free;
687 sprintf (p_dev->devname, "pcmcia%s", p_dev->dev.bus_id); 658 sprintf (p_dev->devname, "pcmcia%s", p_dev->dev.bus_id);
688 ds_dbg(3, "devname is %s\n", p_dev->devname); 659 ds_dev_dbg(3, &p_dev->dev, "devname is %s\n", p_dev->devname);
689 660
690 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 661 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
691 662
@@ -706,7 +677,7 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
706 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags); 677 spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
707 678
708 if (!p_dev->function_config) { 679 if (!p_dev->function_config) {
709 ds_dbg(3, "creating config_t for %s\n", p_dev->dev.bus_id); 680 ds_dev_dbg(3, &p_dev->dev, "creating config_t\n");
710 p_dev->function_config = kzalloc(sizeof(struct config_t), 681 p_dev->function_config = kzalloc(sizeof(struct config_t),
711 GFP_KERNEL); 682 GFP_KERNEL);
712 if (!p_dev->function_config) 683 if (!p_dev->function_config)
@@ -714,8 +685,9 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
714 kref_init(&p_dev->function_config->ref); 685 kref_init(&p_dev->function_config->ref);
715 } 686 }
716 687
717 printk(KERN_NOTICE "pcmcia: registering new device %s\n", 688 dev_printk(KERN_NOTICE, &p_dev->dev,
718 p_dev->devname); 689 "pcmcia: registering new device %s\n",
690 p_dev->devname);
719 691
720 pcmcia_device_query(p_dev); 692 pcmcia_device_query(p_dev);
721 693
@@ -750,19 +722,20 @@ static int pcmcia_card_add(struct pcmcia_socket *s)
750 int ret = 0; 722 int ret = 0;
751 723
752 if (!(s->resource_setup_done)) { 724 if (!(s->resource_setup_done)) {
753 ds_dbg(3, "no resources available, delaying card_add\n"); 725 ds_dev_dbg(3, &s->dev,
726 "no resources available, delaying card_add\n");
754 return -EAGAIN; /* try again, but later... */ 727 return -EAGAIN; /* try again, but later... */
755 } 728 }
756 729
757 if (pcmcia_validate_mem(s)) { 730 if (pcmcia_validate_mem(s)) {
758 ds_dbg(3, "validating mem resources failed, " 731 ds_dev_dbg(3, &s->dev, "validating mem resources failed, "
759 "delaying card_add\n"); 732 "delaying card_add\n");
760 return -EAGAIN; /* try again, but later... */ 733 return -EAGAIN; /* try again, but later... */
761 } 734 }
762 735
763 ret = pccard_validate_cis(s, BIND_FN_ALL, &no_chains); 736 ret = pccard_validate_cis(s, BIND_FN_ALL, &no_chains);
764 if (ret || !no_chains) { 737 if (ret || !no_chains) {
765 ds_dbg(0, "invalid CIS or invalid resources\n"); 738 ds_dev_dbg(0, &s->dev, "invalid CIS or invalid resources\n");
766 return -ENODEV; 739 return -ENODEV;
767 } 740 }
768 741
@@ -783,7 +756,7 @@ static void pcmcia_delayed_add_device(struct work_struct *work)
783{ 756{
784 struct pcmcia_socket *s = 757 struct pcmcia_socket *s =
785 container_of(work, struct pcmcia_socket, device_add); 758 container_of(work, struct pcmcia_socket, device_add);
786 ds_dbg(1, "adding additional device to %d\n", s->sock); 759 ds_dev_dbg(1, &s->dev, "adding additional device to %d\n", s->sock);
787 pcmcia_device_add(s, s->pcmcia_state.mfc_pfc); 760 pcmcia_device_add(s, s->pcmcia_state.mfc_pfc);
788 s->pcmcia_state.device_add_pending = 0; 761 s->pcmcia_state.device_add_pending = 0;
789 s->pcmcia_state.mfc_pfc = 0; 762 s->pcmcia_state.mfc_pfc = 0;
@@ -793,8 +766,7 @@ static int pcmcia_requery(struct device *dev, void * _data)
793{ 766{
794 struct pcmcia_device *p_dev = to_pcmcia_dev(dev); 767 struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
795 if (!p_dev->dev.driver) { 768 if (!p_dev->dev.driver) {
796 ds_dbg(1, "update device information for %s\n", 769 ds_dev_dbg(1, dev, "update device information\n");
797 p_dev->dev.bus_id);
798 pcmcia_device_query(p_dev); 770 pcmcia_device_query(p_dev);
799 } 771 }
800 772
@@ -808,7 +780,7 @@ static void pcmcia_bus_rescan(struct pcmcia_socket *skt, int new_cis)
808 unsigned long flags; 780 unsigned long flags;
809 781
810 /* must be called with skt_mutex held */ 782 /* must be called with skt_mutex held */
811 ds_dbg(0, "re-scanning socket %d\n", skt->sock); 783 ds_dev_dbg(0, &skt->dev, "re-scanning socket %d\n", skt->sock);
812 784
813 spin_lock_irqsave(&pcmcia_dev_list_lock, flags); 785 spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
814 if (list_empty(&skt->devices_list)) 786 if (list_empty(&skt->devices_list))
@@ -859,17 +831,17 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
859 int ret = -ENOMEM; 831 int ret = -ENOMEM;
860 int no_funcs; 832 int no_funcs;
861 int old_funcs; 833 int old_funcs;
862 cisdump_t *cis;
863 cistpl_longlink_mfc_t mfc; 834 cistpl_longlink_mfc_t mfc;
864 835
865 if (!filename) 836 if (!filename)
866 return -EINVAL; 837 return -EINVAL;
867 838
868 ds_dbg(1, "trying to load CIS file %s\n", filename); 839 ds_dev_dbg(1, &dev->dev, "trying to load CIS file %s\n", filename);
869 840
870 if (strlen(filename) > (FIRMWARE_NAME_MAX - 1)) { 841 if (strlen(filename) > (FIRMWARE_NAME_MAX - 1)) {
871 printk(KERN_WARNING "pcmcia: CIS filename is too long [%s]\n", 842 dev_printk(KERN_WARNING, &dev->dev,
872 filename); 843 "pcmcia: CIS filename is too long [%s]\n",
844 filename);
873 return -EINVAL; 845 return -EINVAL;
874 } 846 }
875 847
@@ -878,23 +850,16 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
878 if (request_firmware(&fw, path, &dev->dev) == 0) { 850 if (request_firmware(&fw, path, &dev->dev) == 0) {
879 if (fw->size >= CISTPL_MAX_CIS_SIZE) { 851 if (fw->size >= CISTPL_MAX_CIS_SIZE) {
880 ret = -EINVAL; 852 ret = -EINVAL;
881 printk(KERN_ERR "pcmcia: CIS override is too big\n"); 853 dev_printk(KERN_ERR, &dev->dev,
854 "pcmcia: CIS override is too big\n");
882 goto release; 855 goto release;
883 } 856 }
884 857
885 cis = kzalloc(sizeof(cisdump_t), GFP_KERNEL); 858 if (!pcmcia_replace_cis(s, fw->data, fw->size))
886 if (!cis) {
887 ret = -ENOMEM;
888 goto release;
889 }
890
891 cis->Length = fw->size + 1;
892 memcpy(cis->Data, fw->data, fw->size);
893
894 if (!pcmcia_replace_cis(s, cis))
895 ret = 0; 859 ret = 0;
896 else { 860 else {
897 printk(KERN_ERR "pcmcia: CIS override failed\n"); 861 dev_printk(KERN_ERR, &dev->dev,
862 "pcmcia: CIS override failed\n");
898 goto release; 863 goto release;
899 } 864 }
900 865
@@ -998,14 +963,14 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev,
998 * after it has re-checked that there is no possible module 963 * after it has re-checked that there is no possible module
999 * with a prod_id/manf_id/card_id match. 964 * with a prod_id/manf_id/card_id match.
1000 */ 965 */
1001 ds_dbg(0, "skipping FUNC_ID match for %s until userspace " 966 ds_dev_dbg(0, &dev->dev,
1002 "interaction\n", dev->dev.bus_id); 967 "skipping FUNC_ID match until userspace interaction\n");
1003 if (!dev->allow_func_id_match) 968 if (!dev->allow_func_id_match)
1004 return 0; 969 return 0;
1005 } 970 }
1006 971
1007 if (did->match_flags & PCMCIA_DEV_ID_MATCH_FAKE_CIS) { 972 if (did->match_flags & PCMCIA_DEV_ID_MATCH_FAKE_CIS) {
1008 ds_dbg(0, "device %s needs a fake CIS\n", dev->dev.bus_id); 973 ds_dev_dbg(0, &dev->dev, "device needs a fake CIS\n");
1009 if (!dev->socket->fake_cis) 974 if (!dev->socket->fake_cis)
1010 pcmcia_load_firmware(dev, did->cisfile); 975 pcmcia_load_firmware(dev, did->cisfile);
1011 976
@@ -1037,11 +1002,9 @@ static int pcmcia_bus_match(struct device * dev, struct device_driver * drv) {
1037 /* match dynamic devices first */ 1002 /* match dynamic devices first */
1038 spin_lock(&p_drv->dynids.lock); 1003 spin_lock(&p_drv->dynids.lock);
1039 list_for_each_entry(dynid, &p_drv->dynids.list, node) { 1004 list_for_each_entry(dynid, &p_drv->dynids.list, node) {
1040 ds_dbg(3, "trying to match %s to %s\n", dev->bus_id, 1005 ds_dev_dbg(3, dev, "trying to match to %s\n", drv->name);
1041 drv->name);
1042 if (pcmcia_devmatch(p_dev, &dynid->id)) { 1006 if (pcmcia_devmatch(p_dev, &dynid->id)) {
1043 ds_dbg(0, "matched %s to %s\n", dev->bus_id, 1007 ds_dev_dbg(0, dev, "matched to %s\n", drv->name);
1044 drv->name);
1045 spin_unlock(&p_drv->dynids.lock); 1008 spin_unlock(&p_drv->dynids.lock);
1046 return 1; 1009 return 1;
1047 } 1010 }
@@ -1051,18 +1014,15 @@ static int pcmcia_bus_match(struct device * dev, struct device_driver * drv) {
1051#ifdef CONFIG_PCMCIA_IOCTL 1014#ifdef CONFIG_PCMCIA_IOCTL
1052 /* matching by cardmgr */ 1015 /* matching by cardmgr */
1053 if (p_dev->cardmgr == p_drv) { 1016 if (p_dev->cardmgr == p_drv) {
1054 ds_dbg(0, "cardmgr matched %s to %s\n", dev->bus_id, 1017 ds_dev_dbg(0, dev, "cardmgr matched to %s\n", drv->name);
1055 drv->name);
1056 return 1; 1018 return 1;
1057 } 1019 }
1058#endif 1020#endif
1059 1021
1060 while (did && did->match_flags) { 1022 while (did && did->match_flags) {
1061 ds_dbg(3, "trying to match %s to %s\n", dev->bus_id, 1023 ds_dev_dbg(3, dev, "trying to match to %s\n", drv->name);
1062 drv->name);
1063 if (pcmcia_devmatch(p_dev, did)) { 1024 if (pcmcia_devmatch(p_dev, did)) {
1064 ds_dbg(0, "matched %s to %s\n", dev->bus_id, 1025 ds_dev_dbg(0, dev, "matched to %s\n", drv->name);
1065 drv->name);
1066 return 1; 1026 return 1;
1067 } 1027 }
1068 did++; 1028 did++;
@@ -1268,7 +1228,7 @@ static int pcmcia_dev_suspend(struct device * dev, pm_message_t state)
1268 if (p_dev->suspended) 1228 if (p_dev->suspended)
1269 return 0; 1229 return 0;
1270 1230
1271 ds_dbg(2, "suspending %s\n", dev->bus_id); 1231 ds_dev_dbg(2, dev, "suspending\n");
1272 1232
1273 if (dev->driver) 1233 if (dev->driver)
1274 p_drv = to_pcmcia_drv(dev->driver); 1234 p_drv = to_pcmcia_drv(dev->driver);
@@ -1279,15 +1239,16 @@ static int pcmcia_dev_suspend(struct device * dev, pm_message_t state)
1279 if (p_drv->suspend) { 1239 if (p_drv->suspend) {
1280 ret = p_drv->suspend(p_dev); 1240 ret = p_drv->suspend(p_dev);
1281 if (ret) { 1241 if (ret) {
1282 printk(KERN_ERR "pcmcia: device %s (driver %s) did " 1242 dev_printk(KERN_ERR, dev,
1283 "not want to go to sleep (%d)\n", 1243 "pcmcia: device %s (driver %s) did "
1284 p_dev->devname, p_drv->drv.name, ret); 1244 "not want to go to sleep (%d)\n",
1245 p_dev->devname, p_drv->drv.name, ret);
1285 goto out; 1246 goto out;
1286 } 1247 }
1287 } 1248 }
1288 1249
1289 if (p_dev->device_no == p_dev->func) { 1250 if (p_dev->device_no == p_dev->func) {
1290 ds_dbg(2, "releasing configuration for %s\n", dev->bus_id); 1251 ds_dev_dbg(2, dev, "releasing configuration\n");
1291 pcmcia_release_configuration(p_dev); 1252 pcmcia_release_configuration(p_dev);
1292 } 1253 }
1293 1254
@@ -1307,7 +1268,7 @@ static int pcmcia_dev_resume(struct device * dev)
1307 if (!p_dev->suspended) 1268 if (!p_dev->suspended)
1308 return 0; 1269 return 0;
1309 1270
1310 ds_dbg(2, "resuming %s\n", dev->bus_id); 1271 ds_dev_dbg(2, dev, "resuming\n");
1311 1272
1312 if (dev->driver) 1273 if (dev->driver)
1313 p_drv = to_pcmcia_drv(dev->driver); 1274 p_drv = to_pcmcia_drv(dev->driver);
@@ -1316,7 +1277,7 @@ static int pcmcia_dev_resume(struct device * dev)
1316 goto out; 1277 goto out;
1317 1278
1318 if (p_dev->device_no == p_dev->func) { 1279 if (p_dev->device_no == p_dev->func) {
1319 ds_dbg(2, "requesting configuration for %s\n", dev->bus_id); 1280 ds_dev_dbg(2, dev, "requesting configuration\n");
1320 ret = pcmcia_request_configuration(p_dev, &p_dev->conf); 1281 ret = pcmcia_request_configuration(p_dev, &p_dev->conf);
1321 if (ret) 1282 if (ret)
1322 goto out; 1283 goto out;
@@ -1358,14 +1319,14 @@ static int pcmcia_bus_resume_callback(struct device *dev, void * _data)
1358 1319
1359static int pcmcia_bus_resume(struct pcmcia_socket *skt) 1320static int pcmcia_bus_resume(struct pcmcia_socket *skt)
1360{ 1321{
1361 ds_dbg(2, "resuming socket %d\n", skt->sock); 1322 ds_dev_dbg(2, &skt->dev, "resuming socket %d\n", skt->sock);
1362 bus_for_each_dev(&pcmcia_bus_type, NULL, skt, pcmcia_bus_resume_callback); 1323 bus_for_each_dev(&pcmcia_bus_type, NULL, skt, pcmcia_bus_resume_callback);
1363 return 0; 1324 return 0;
1364} 1325}
1365 1326
1366static int pcmcia_bus_suspend(struct pcmcia_socket *skt) 1327static int pcmcia_bus_suspend(struct pcmcia_socket *skt)
1367{ 1328{
1368 ds_dbg(2, "suspending socket %d\n", skt->sock); 1329 ds_dev_dbg(2, &skt->dev, "suspending socket %d\n", skt->sock);
1369 if (bus_for_each_dev(&pcmcia_bus_type, NULL, skt, 1330 if (bus_for_each_dev(&pcmcia_bus_type, NULL, skt,
1370 pcmcia_bus_suspend_callback)) { 1331 pcmcia_bus_suspend_callback)) {
1371 pcmcia_bus_resume(skt); 1332 pcmcia_bus_resume(skt);
@@ -1391,13 +1352,14 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
1391 struct pcmcia_socket *s = pcmcia_get_socket(skt); 1352 struct pcmcia_socket *s = pcmcia_get_socket(skt);
1392 1353
1393 if (!s) { 1354 if (!s) {
1394 printk(KERN_ERR "PCMCIA obtaining reference to socket %p " \ 1355 dev_printk(KERN_ERR, &skt->dev,
1395 "failed, event 0x%x lost!\n", skt, event); 1356 "PCMCIA obtaining reference to socket " \
1357 "failed, event 0x%x lost!\n", event);
1396 return -ENODEV; 1358 return -ENODEV;
1397 } 1359 }
1398 1360
1399 ds_dbg(1, "ds_event(0x%06x, %d, 0x%p)\n", 1361 ds_dev_dbg(1, &skt->dev, "ds_event(0x%06x, %d, 0x%p)\n",
1400 event, priority, skt); 1362 event, priority, skt);
1401 1363
1402 switch (event) { 1364 switch (event) {
1403 case CS_EVENT_CARD_REMOVAL: 1365 case CS_EVENT_CARD_REMOVAL:
@@ -1472,7 +1434,8 @@ static int __devinit pcmcia_bus_add_socket(struct device *dev,
1472 1434
1473 socket = pcmcia_get_socket(socket); 1435 socket = pcmcia_get_socket(socket);
1474 if (!socket) { 1436 if (!socket) {
1475 printk(KERN_ERR "PCMCIA obtaining reference to socket %p failed\n", socket); 1437 dev_printk(KERN_ERR, dev,
1438 "PCMCIA obtaining reference to socket failed\n");
1476 return -ENODEV; 1439 return -ENODEV;
1477 } 1440 }
1478 1441
@@ -1492,7 +1455,7 @@ static int __devinit pcmcia_bus_add_socket(struct device *dev,
1492 1455
1493 ret = pccard_register_pcmcia(socket, &pcmcia_bus_callback); 1456 ret = pccard_register_pcmcia(socket, &pcmcia_bus_callback);
1494 if (ret) { 1457 if (ret) {
1495 printk(KERN_ERR "PCMCIA registration PCCard core failed for socket %p\n", socket); 1458 dev_printk(KERN_ERR, dev, "PCMCIA registration failed\n");
1496 pcmcia_put_socket(socket); 1459 pcmcia_put_socket(socket);
1497 return (ret); 1460 return (ret);
1498 } 1461 }
diff --git a/drivers/pcmcia/ds_internal.h b/drivers/pcmcia/ds_internal.h
deleted file mode 100644
index 3a2b25e6ed73..000000000000
--- a/drivers/pcmcia/ds_internal.h
+++ /dev/null
@@ -1,23 +0,0 @@
1/* ds_internal.h - internal header for 16-bit PCMCIA devices management */
2
3extern spinlock_t pcmcia_dev_list_lock;
4extern struct bus_type pcmcia_bus_type;
5
6extern struct pcmcia_device * pcmcia_get_dev(struct pcmcia_device *p_dev);
7extern void pcmcia_put_dev(struct pcmcia_device *p_dev);
8
9struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function);
10
11extern int pcmcia_release_configuration(struct pcmcia_device *p_dev);
12
13#ifdef CONFIG_PCMCIA_IOCTL
14extern void __init pcmcia_setup_ioctl(void);
15extern void __exit pcmcia_cleanup_ioctl(void);
16extern void handle_event(struct pcmcia_socket *s, event_t event);
17extern int handle_request(struct pcmcia_socket *s, event_t event);
18#else
19static inline void __init pcmcia_setup_ioctl(void) { return; }
20static inline void __exit pcmcia_cleanup_ioctl(void) { return; }
21static inline void handle_event(struct pcmcia_socket *s, event_t event) { return; }
22static inline int handle_request(struct pcmcia_socket *s, event_t event) { return CS_SUCCESS; }
23#endif
diff --git a/drivers/pcmcia/hd64465_ss.c b/drivers/pcmcia/hd64465_ss.c
index fb2bc1fb015d..117dc12ab438 100644
--- a/drivers/pcmcia/hd64465_ss.c
+++ b/drivers/pcmcia/hd64465_ss.c
@@ -46,7 +46,6 @@
46#include <pcmcia/cistpl.h> 46#include <pcmcia/cistpl.h>
47#include <pcmcia/ds.h> 47#include <pcmcia/ds.h>
48#include <pcmcia/ss.h> 48#include <pcmcia/ss.h>
49#include "cs_internal.h"
50 49
51#define MODNAME "hd64465_ss" 50#define MODNAME "hd64465_ss"
52 51
diff --git a/drivers/pcmcia/i82365.c b/drivers/pcmcia/i82365.c
index 68f6b2702bc4..71653ab84890 100644
--- a/drivers/pcmcia/i82365.c
+++ b/drivers/pcmcia/i82365.c
@@ -63,7 +63,7 @@
63#include "vg468.h" 63#include "vg468.h"
64#include "ricoh.h" 64#include "ricoh.h"
65 65
66#ifdef DEBUG 66#ifdef CONFIG_PCMCIA_DEBUG
67static const char version[] = 67static const char version[] =
68"i82365.c 1.265 1999/11/10 18:36:21 (David Hinds)"; 68"i82365.c 1.265 1999/11/10 18:36:21 (David Hinds)";
69 69
diff --git a/drivers/pcmcia/m32r_cfc.c b/drivers/pcmcia/m32r_cfc.c
index 3616da227152..2ab4f22c21de 100644
--- a/drivers/pcmcia/m32r_cfc.c
+++ b/drivers/pcmcia/m32r_cfc.c
@@ -38,7 +38,7 @@
38 38
39#include "m32r_cfc.h" 39#include "m32r_cfc.h"
40 40
41#ifdef DEBUG 41#ifdef CONFIG_PCMCIA_DEBUG
42static int m32r_cfc_debug; 42static int m32r_cfc_debug;
43module_param(m32r_cfc_debug, int, 0644); 43module_param(m32r_cfc_debug, int, 0644);
44#define debug(lvl, fmt, arg...) do { \ 44#define debug(lvl, fmt, arg...) do { \
@@ -505,7 +505,7 @@ static int _pcc_set_socket(u_short sock, socket_state_t *state)
505 pcc_set(sock,(unsigned int)PLD_CFBUFCR,1); 505 pcc_set(sock,(unsigned int)PLD_CFBUFCR,1);
506 } 506 }
507 507
508#ifdef DEBUG 508#ifdef CONFIG_PCMCIA_DEBUG
509 if(state->flags & SS_IOCARD){ 509 if(state->flags & SS_IOCARD){
510 debug(3, ":IOCARD"); 510 debug(3, ":IOCARD");
511 } 511 }
diff --git a/drivers/pcmcia/m32r_pcc.c b/drivers/pcmcia/m32r_pcc.c
index 2b42b7155e34..2f108c23dbd9 100644
--- a/drivers/pcmcia/m32r_pcc.c
+++ b/drivers/pcmcia/m32r_pcc.c
@@ -45,7 +45,7 @@
45 45
46#define PCC_DEBUG_DBEX 46#define PCC_DEBUG_DBEX
47 47
48#ifdef DEBUG 48#ifdef CONFIG_PCMCIA_DEBUG
49static int m32r_pcc_debug; 49static int m32r_pcc_debug;
50module_param(m32r_pcc_debug, int, 0644); 50module_param(m32r_pcc_debug, int, 0644);
51#define debug(lvl, fmt, arg...) do { \ 51#define debug(lvl, fmt, arg...) do { \
@@ -460,7 +460,7 @@ static int _pcc_set_socket(u_short sock, socket_state_t *state)
460 460
461 pcc_set(sock,PCCSIGCR,reg); 461 pcc_set(sock,PCCSIGCR,reg);
462 462
463#ifdef DEBUG 463#ifdef CONFIG_PCMCIA_DEBUG
464 if(state->flags & SS_IOCARD){ 464 if(state->flags & SS_IOCARD){
465 debug(3, ":IOCARD"); 465 debug(3, ":IOCARD");
466 } 466 }
diff --git a/drivers/pcmcia/m8xx_pcmcia.c b/drivers/pcmcia/m8xx_pcmcia.c
index ff66604e90d4..d1ad0966392d 100644
--- a/drivers/pcmcia/m8xx_pcmcia.c
+++ b/drivers/pcmcia/m8xx_pcmcia.c
@@ -64,8 +64,8 @@
64#include <pcmcia/cs.h> 64#include <pcmcia/cs.h>
65#include <pcmcia/ss.h> 65#include <pcmcia/ss.h>
66 66
67#ifdef PCMCIA_DEBUG 67#ifdef CONFIG_PCMCIA_DEBUG
68static int pc_debug = PCMCIA_DEBUG; 68static int pc_debug;
69module_param(pc_debug, int, 0); 69module_param(pc_debug, int, 0);
70#define dprintk(args...) printk(KERN_DEBUG "m8xx_pcmcia: " args); 70#define dprintk(args...) printk(KERN_DEBUG "m8xx_pcmcia: " args);
71#else 71#else
diff --git a/drivers/pcmcia/o2micro.h b/drivers/pcmcia/o2micro.h
index a234ce1967a3..5554015a7813 100644
--- a/drivers/pcmcia/o2micro.h
+++ b/drivers/pcmcia/o2micro.h
@@ -140,7 +140,8 @@ static int o2micro_override(struct yenta_socket *socket)
140 a = config_readb(socket, O2_RESERVED1); 140 a = config_readb(socket, O2_RESERVED1);
141 b = config_readb(socket, O2_RESERVED2); 141 b = config_readb(socket, O2_RESERVED2);
142 142
143 printk(KERN_INFO "Yenta O2: res at 0x94/0xD4: %02x/%02x\n", a, b); 143 dev_printk(KERN_INFO, &socket->dev->dev,
144 "O2: res at 0x94/0xD4: %02x/%02x\n", a, b);
144 145
145 switch (socket->dev->device) { 146 switch (socket->dev->device) {
146 /* 147 /*
@@ -153,7 +154,9 @@ static int o2micro_override(struct yenta_socket *socket)
153 case PCI_DEVICE_ID_O2_6812: 154 case PCI_DEVICE_ID_O2_6812:
154 case PCI_DEVICE_ID_O2_6832: 155 case PCI_DEVICE_ID_O2_6832:
155 case PCI_DEVICE_ID_O2_6836: 156 case PCI_DEVICE_ID_O2_6836:
156 printk(KERN_INFO "Yenta O2: old bridge, disabling read prefetch/write burst\n"); 157 dev_printk(KERN_INFO, &socket->dev->dev,
158 "Yenta O2: old bridge, disabling read "
159 "prefetch/write burst\n");
157 config_writeb(socket, O2_RESERVED1, 160 config_writeb(socket, O2_RESERVED1,
158 a & ~(O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST)); 161 a & ~(O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST));
159 config_writeb(socket, O2_RESERVED2, 162 config_writeb(socket, O2_RESERVED2,
@@ -161,7 +164,8 @@ static int o2micro_override(struct yenta_socket *socket)
161 break; 164 break;
162 165
163 default: 166 default:
164 printk(KERN_INFO "Yenta O2: enabling read prefetch/write burst\n"); 167 dev_printk(KERN_INFO , &socket->dev->dev,
168 "O2: enabling read prefetch/write burst\n");
165 config_writeb(socket, O2_RESERVED1, 169 config_writeb(socket, O2_RESERVED1,
166 a | O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST); 170 a | O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST);
167 config_writeb(socket, O2_RESERVED2, 171 config_writeb(socket, O2_RESERVED2,
diff --git a/drivers/pcmcia/pcmcia_ioctl.c b/drivers/pcmcia/pcmcia_ioctl.c
index 419f97fc9a62..1703b20cad5d 100644
--- a/drivers/pcmcia/pcmcia_ioctl.c
+++ b/drivers/pcmcia/pcmcia_ioctl.c
@@ -38,7 +38,6 @@
38#include <pcmcia/ss.h> 38#include <pcmcia/ss.h>
39 39
40#include "cs_internal.h" 40#include "cs_internal.h"
41#include "ds_internal.h"
42 41
43static int major_dev = -1; 42static int major_dev = -1;
44 43
@@ -58,7 +57,7 @@ typedef struct user_info_t {
58} user_info_t; 57} user_info_t;
59 58
60 59
61#ifdef DEBUG 60#ifdef CONFIG_PCMCIA_DEBUG
62extern int ds_pc_debug; 61extern int ds_pc_debug;
63 62
64#define ds_dbg(lvl, fmt, arg...) do { \ 63#define ds_dbg(lvl, fmt, arg...) do { \
@@ -149,7 +148,7 @@ static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj)
149 148
150 irq = adj->resource.irq.IRQ; 149 irq = adj->resource.irq.IRQ;
151 if ((irq < 0) || (irq > 15)) 150 if ((irq < 0) || (irq > 15))
152 return CS_BAD_IRQ; 151 return -EINVAL;
153 152
154 if (adj->Action != REMOVE_MANAGED_RESOURCE) 153 if (adj->Action != REMOVE_MANAGED_RESOURCE)
155 return 0; 154 return 0;
@@ -167,7 +166,7 @@ static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj)
167#else 166#else
168 167
169static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) { 168static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) {
170 return CS_SUCCESS; 169 return 0;
171} 170}
172 171
173#endif 172#endif
@@ -175,7 +174,7 @@ static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) {
175static int pcmcia_adjust_resource_info(adjust_t *adj) 174static int pcmcia_adjust_resource_info(adjust_t *adj)
176{ 175{
177 struct pcmcia_socket *s; 176 struct pcmcia_socket *s;
178 int ret = CS_UNSUPPORTED_FUNCTION; 177 int ret = -ENOSYS;
179 unsigned long flags; 178 unsigned long flags;
180 179
181 down_read(&pcmcia_socket_list_rwsem); 180 down_read(&pcmcia_socket_list_rwsem);
@@ -248,7 +247,7 @@ static int pccard_get_status(struct pcmcia_socket *s,
248 if (s->state & SOCKET_SUSPEND) 247 if (s->state & SOCKET_SUSPEND)
249 status->CardState |= CS_EVENT_PM_SUSPEND; 248 status->CardState |= CS_EVENT_PM_SUSPEND;
250 if (!(s->state & SOCKET_PRESENT)) 249 if (!(s->state & SOCKET_PRESENT))
251 return CS_NO_CARD; 250 return -ENODEV;
252 251
253 c = (p_dev) ? p_dev->function_config : NULL; 252 c = (p_dev) ? p_dev->function_config : NULL;
254 253
@@ -274,7 +273,7 @@ static int pccard_get_status(struct pcmcia_socket *s,
274 status->CardState |= 273 status->CardState |=
275 (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0; 274 (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0;
276 } 275 }
277 return CS_SUCCESS; 276 return 0;
278 } 277 }
279 status->CardState |= 278 status->CardState |=
280 (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0; 279 (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0;
@@ -284,9 +283,81 @@ static int pccard_get_status(struct pcmcia_socket *s,
284 (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0; 283 (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0;
285 status->CardState |= 284 status->CardState |=
286 (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0; 285 (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0;
287 return CS_SUCCESS; 286 return 0;
288} /* pccard_get_status */ 287} /* pccard_get_status */
289 288
289int pccard_get_configuration_info(struct pcmcia_socket *s,
290 struct pcmcia_device *p_dev,
291 config_info_t *config)
292{
293 config_t *c;
294
295 if (!(s->state & SOCKET_PRESENT))
296 return -ENODEV;
297
298
299#ifdef CONFIG_CARDBUS
300 if (s->state & SOCKET_CARDBUS) {
301 memset(config, 0, sizeof(config_info_t));
302 config->Vcc = s->socket.Vcc;
303 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
304 config->Option = s->cb_dev->subordinate->number;
305 if (s->state & SOCKET_CARDBUS_CONFIG) {
306 config->Attributes = CONF_VALID_CLIENT;
307 config->IntType = INT_CARDBUS;
308 config->AssignedIRQ = s->irq.AssignedIRQ;
309 if (config->AssignedIRQ)
310 config->Attributes |= CONF_ENABLE_IRQ;
311 if (s->io[0].res) {
312 config->BasePort1 = s->io[0].res->start;
313 config->NumPorts1 = s->io[0].res->end -
314 config->BasePort1 + 1;
315 }
316 }
317 return 0;
318 }
319#endif
320
321 if (p_dev) {
322 c = p_dev->function_config;
323 config->Function = p_dev->func;
324 } else {
325 c = NULL;
326 config->Function = 0;
327 }
328
329 if ((c == NULL) || !(c->state & CONFIG_LOCKED)) {
330 config->Attributes = 0;
331 config->Vcc = s->socket.Vcc;
332 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
333 return 0;
334 }
335
336 config->Attributes = c->Attributes | CONF_VALID_CLIENT;
337 config->Vcc = s->socket.Vcc;
338 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
339 config->IntType = c->IntType;
340 config->ConfigBase = c->ConfigBase;
341 config->Status = c->Status;
342 config->Pin = c->Pin;
343 config->Copy = c->Copy;
344 config->Option = c->Option;
345 config->ExtStatus = c->ExtStatus;
346 config->Present = config->CardValues = c->CardValues;
347 config->IRQAttributes = c->irq.Attributes;
348 config->AssignedIRQ = s->irq.AssignedIRQ;
349 config->BasePort1 = c->io.BasePort1;
350 config->NumPorts1 = c->io.NumPorts1;
351 config->Attributes1 = c->io.Attributes1;
352 config->BasePort2 = c->io.BasePort2;
353 config->NumPorts2 = c->io.NumPorts2;
354 config->Attributes2 = c->io.Attributes2;
355 config->IOAddrLines = c->io.IOAddrLines;
356
357 return 0;
358} /* pccard_get_configuration_info */
359
360
290/*====================================================================== 361/*======================================================================
291 362
292 These manage a ring buffer of events pending for one user process 363 These manage a ring buffer of events pending for one user process
@@ -764,7 +835,7 @@ static int ds_ioctl(struct inode * inode, struct file * file,
764 case DS_GET_CONFIGURATION_INFO: 835 case DS_GET_CONFIGURATION_INFO:
765 if (buf->config.Function && 836 if (buf->config.Function &&
766 (buf->config.Function >= s->functions)) 837 (buf->config.Function >= s->functions))
767 ret = CS_BAD_ARGS; 838 ret = -EINVAL;
768 else { 839 else {
769 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->config.Function); 840 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->config.Function);
770 ret = pccard_get_configuration_info(s, p_dev, &buf->config); 841 ret = pccard_get_configuration_info(s, p_dev, &buf->config);
@@ -787,15 +858,15 @@ static int ds_ioctl(struct inode * inode, struct file * file,
787 break; 858 break;
788 case DS_PARSE_TUPLE: 859 case DS_PARSE_TUPLE:
789 buf->tuple.TupleData = buf->tuple_parse.data; 860 buf->tuple.TupleData = buf->tuple_parse.data;
790 ret = pccard_parse_tuple(&buf->tuple, &buf->tuple_parse.parse); 861 ret = pcmcia_parse_tuple(&buf->tuple, &buf->tuple_parse.parse);
791 break; 862 break;
792 case DS_RESET_CARD: 863 case DS_RESET_CARD:
793 ret = pccard_reset_card(s); 864 ret = pcmcia_reset_card(s);
794 break; 865 break;
795 case DS_GET_STATUS: 866 case DS_GET_STATUS:
796 if (buf->status.Function && 867 if (buf->status.Function &&
797 (buf->status.Function >= s->functions)) 868 (buf->status.Function >= s->functions))
798 ret = CS_BAD_ARGS; 869 ret = -EINVAL;
799 else { 870 else {
800 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->status.Function); 871 struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->status.Function);
801 ret = pccard_get_status(s, p_dev, &buf->status); 872 ret = pccard_get_status(s, p_dev, &buf->status);
@@ -826,7 +897,7 @@ static int ds_ioctl(struct inode * inode, struct file * file,
826 goto free_out; 897 goto free_out;
827 } 898 }
828 899
829 ret = CS_BAD_ARGS; 900 ret = -EINVAL;
830 901
831 if (!(buf->conf_reg.Function && 902 if (!(buf->conf_reg.Function &&
832 (buf->conf_reg.Function >= s->functions))) { 903 (buf->conf_reg.Function >= s->functions))) {
@@ -867,7 +938,7 @@ static int ds_ioctl(struct inode * inode, struct file * file,
867 &buf->win_info.map); 938 &buf->win_info.map);
868 break; 939 break;
869 case DS_REPLACE_CIS: 940 case DS_REPLACE_CIS:
870 ret = pcmcia_replace_cis(s, &buf->cisdump); 941 ret = pcmcia_replace_cis(s, buf->cisdump.Data, buf->cisdump.Length);
871 break; 942 break;
872 case DS_BIND_REQUEST: 943 case DS_BIND_REQUEST:
873 if (!capable(CAP_SYS_ADMIN)) { 944 if (!capable(CAP_SYS_ADMIN)) {
@@ -889,22 +960,19 @@ static int ds_ioctl(struct inode * inode, struct file * file,
889 err = -EINVAL; 960 err = -EINVAL;
890 } 961 }
891 962
892 if ((err == 0) && (ret != CS_SUCCESS)) { 963 if ((err == 0) && (ret != 0)) {
893 ds_dbg(2, "ds_ioctl: ret = %d\n", ret); 964 ds_dbg(2, "ds_ioctl: ret = %d\n", ret);
894 switch (ret) { 965 switch (ret) {
895 case CS_BAD_SOCKET: case CS_NO_CARD: 966 case -ENODEV:
896 err = -ENODEV; break; 967 case -EINVAL:
897 case CS_BAD_ARGS: case CS_BAD_ATTRIBUTE: case CS_BAD_IRQ: 968 case -EBUSY:
898 case CS_BAD_TUPLE: 969 case -ENOSYS:
899 err = -EINVAL; break; 970 err = ret;
900 case CS_IN_USE: 971 break;
901 err = -EBUSY; break; 972 case -ENOMEM:
902 case CS_OUT_OF_RESOURCE:
903 err = -ENOSPC; break; 973 err = -ENOSPC; break;
904 case CS_NO_MORE_ITEMS: 974 case -ENOSPC:
905 err = -ENODATA; break; 975 err = -ENODATA; break;
906 case CS_UNSUPPORTED_FUNCTION:
907 err = -ENOSYS; break;
908 default: 976 default:
909 err = -EIO; break; 977 err = -EIO; break;
910 } 978 }
diff --git a/drivers/pcmcia/pcmcia_resource.c b/drivers/pcmcia/pcmcia_resource.c
index 4884a18cf9e6..afea2b2558b5 100644
--- a/drivers/pcmcia/pcmcia_resource.c
+++ b/drivers/pcmcia/pcmcia_resource.c
@@ -29,7 +29,6 @@
29#include <pcmcia/ds.h> 29#include <pcmcia/ds.h>
30 30
31#include "cs_internal.h" 31#include "cs_internal.h"
32#include "ds_internal.h"
33 32
34 33
35/* Access speed for IO windows */ 34/* Access speed for IO windows */
@@ -44,16 +43,17 @@ static u8 pcmcia_used_irq[NR_IRQS];
44#endif 43#endif
45 44
46 45
47#ifdef DEBUG 46#ifdef CONFIG_PCMCIA_DEBUG
48extern int ds_pc_debug; 47extern int ds_pc_debug;
49 48
50#define ds_dbg(skt, lvl, fmt, arg...) do { \ 49#define ds_dbg(skt, lvl, fmt, arg...) do { \
51 if (ds_pc_debug >= lvl) \ 50 if (ds_pc_debug >= lvl) \
52 printk(KERN_DEBUG "pcmcia_resource: %s: " fmt, \ 51 dev_printk(KERN_DEBUG, &skt->dev, \
53 cs_socket_name(skt) , ## arg); \ 52 "pcmcia_resource: " fmt, \
53 ## arg); \
54} while (0) 54} while (0)
55#else 55#else
56#define ds_dbg(lvl, fmt, arg...) do { } while (0) 56#define ds_dbg(skt, lvl, fmt, arg...) do { } while (0)
57#endif 57#endif
58 58
59 59
@@ -168,13 +168,13 @@ int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
168 u_char val; 168 u_char val;
169 169
170 if (!p_dev || !p_dev->function_config) 170 if (!p_dev || !p_dev->function_config)
171 return CS_NO_CARD; 171 return -EINVAL;
172 172
173 s = p_dev->socket; 173 s = p_dev->socket;
174 c = p_dev->function_config; 174 c = p_dev->function_config;
175 175
176 if (!(c->state & CONFIG_LOCKED)) 176 if (!(c->state & CONFIG_LOCKED))
177 return CS_CONFIGURATION_LOCKED; 177 return -EACCES;
178 178
179 addr = (c->ConfigBase + reg->Offset) >> 1; 179 addr = (c->ConfigBase + reg->Offset) >> 1;
180 180
@@ -188,93 +188,14 @@ int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
188 pcmcia_write_cis_mem(s, 1, addr, 1, &val); 188 pcmcia_write_cis_mem(s, 1, addr, 1, &val);
189 break; 189 break;
190 default: 190 default:
191 return CS_BAD_ARGS; 191 return -EINVAL;
192 break; 192 break;
193 } 193 }
194 return CS_SUCCESS; 194 return 0;
195} /* pcmcia_access_configuration_register */ 195} /* pcmcia_access_configuration_register */
196EXPORT_SYMBOL(pcmcia_access_configuration_register); 196EXPORT_SYMBOL(pcmcia_access_configuration_register);
197 197
198 198
199int pccard_get_configuration_info(struct pcmcia_socket *s,
200 struct pcmcia_device *p_dev,
201 config_info_t *config)
202{
203 config_t *c;
204
205 if (!(s->state & SOCKET_PRESENT))
206 return CS_NO_CARD;
207
208
209#ifdef CONFIG_CARDBUS
210 if (s->state & SOCKET_CARDBUS) {
211 memset(config, 0, sizeof(config_info_t));
212 config->Vcc = s->socket.Vcc;
213 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
214 config->Option = s->cb_dev->subordinate->number;
215 if (s->state & SOCKET_CARDBUS_CONFIG) {
216 config->Attributes = CONF_VALID_CLIENT;
217 config->IntType = INT_CARDBUS;
218 config->AssignedIRQ = s->irq.AssignedIRQ;
219 if (config->AssignedIRQ)
220 config->Attributes |= CONF_ENABLE_IRQ;
221 if (s->io[0].res) {
222 config->BasePort1 = s->io[0].res->start;
223 config->NumPorts1 = s->io[0].res->end - config->BasePort1 + 1;
224 }
225 }
226 return CS_SUCCESS;
227 }
228#endif
229
230 if (p_dev) {
231 c = p_dev->function_config;
232 config->Function = p_dev->func;
233 } else {
234 c = NULL;
235 config->Function = 0;
236 }
237
238 if ((c == NULL) || !(c->state & CONFIG_LOCKED)) {
239 config->Attributes = 0;
240 config->Vcc = s->socket.Vcc;
241 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
242 return CS_SUCCESS;
243 }
244
245 config->Attributes = c->Attributes | CONF_VALID_CLIENT;
246 config->Vcc = s->socket.Vcc;
247 config->Vpp1 = config->Vpp2 = s->socket.Vpp;
248 config->IntType = c->IntType;
249 config->ConfigBase = c->ConfigBase;
250 config->Status = c->Status;
251 config->Pin = c->Pin;
252 config->Copy = c->Copy;
253 config->Option = c->Option;
254 config->ExtStatus = c->ExtStatus;
255 config->Present = config->CardValues = c->CardValues;
256 config->IRQAttributes = c->irq.Attributes;
257 config->AssignedIRQ = s->irq.AssignedIRQ;
258 config->BasePort1 = c->io.BasePort1;
259 config->NumPorts1 = c->io.NumPorts1;
260 config->Attributes1 = c->io.Attributes1;
261 config->BasePort2 = c->io.BasePort2;
262 config->NumPorts2 = c->io.NumPorts2;
263 config->Attributes2 = c->io.Attributes2;
264 config->IOAddrLines = c->io.IOAddrLines;
265
266 return CS_SUCCESS;
267} /* pccard_get_configuration_info */
268
269int pcmcia_get_configuration_info(struct pcmcia_device *p_dev,
270 config_info_t *config)
271{
272 return pccard_get_configuration_info(p_dev->socket, p_dev,
273 config);
274}
275EXPORT_SYMBOL(pcmcia_get_configuration_info);
276
277
278/** pcmcia_get_window 199/** pcmcia_get_window
279 */ 200 */
280int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, 201int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
@@ -284,12 +205,12 @@ int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
284 int w; 205 int w;
285 206
286 if (!s || !(s->state & SOCKET_PRESENT)) 207 if (!s || !(s->state & SOCKET_PRESENT))
287 return CS_NO_CARD; 208 return -ENODEV;
288 for (w = idx; w < MAX_WIN; w++) 209 for (w = idx; w < MAX_WIN; w++)
289 if (s->state & SOCKET_WIN_REQ(w)) 210 if (s->state & SOCKET_WIN_REQ(w))
290 break; 211 break;
291 if (w == MAX_WIN) 212 if (w == MAX_WIN)
292 return CS_NO_MORE_ITEMS; 213 return -EINVAL;
293 win = &s->win[w]; 214 win = &s->win[w];
294 req->Base = win->ctl.res->start; 215 req->Base = win->ctl.res->start;
295 req->Size = win->ctl.res->end - win->ctl.res->start + 1; 216 req->Size = win->ctl.res->end - win->ctl.res->start + 1;
@@ -304,7 +225,7 @@ int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
304 if (win->ctl.flags & MAP_USE_WAIT) 225 if (win->ctl.flags & MAP_USE_WAIT)
305 req->Attributes |= WIN_USE_WAIT; 226 req->Attributes |= WIN_USE_WAIT;
306 *handle = win; 227 *handle = win;
307 return CS_SUCCESS; 228 return 0;
308} /* pcmcia_get_window */ 229} /* pcmcia_get_window */
309EXPORT_SYMBOL(pcmcia_get_window); 230EXPORT_SYMBOL(pcmcia_get_window);
310 231
@@ -316,10 +237,10 @@ EXPORT_SYMBOL(pcmcia_get_window);
316int pcmcia_get_mem_page(window_handle_t win, memreq_t *req) 237int pcmcia_get_mem_page(window_handle_t win, memreq_t *req)
317{ 238{
318 if ((win == NULL) || (win->magic != WINDOW_MAGIC)) 239 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
319 return CS_BAD_HANDLE; 240 return -EINVAL;
320 req->Page = 0; 241 req->Page = 0;
321 req->CardOffset = win->ctl.card_start; 242 req->CardOffset = win->ctl.card_start;
322 return CS_SUCCESS; 243 return 0;
323} /* pcmcia_get_mem_page */ 244} /* pcmcia_get_mem_page */
324EXPORT_SYMBOL(pcmcia_get_mem_page); 245EXPORT_SYMBOL(pcmcia_get_mem_page);
325 246
@@ -328,14 +249,18 @@ int pcmcia_map_mem_page(window_handle_t win, memreq_t *req)
328{ 249{
329 struct pcmcia_socket *s; 250 struct pcmcia_socket *s;
330 if ((win == NULL) || (win->magic != WINDOW_MAGIC)) 251 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
331 return CS_BAD_HANDLE; 252 return -EINVAL;
332 if (req->Page != 0)
333 return CS_BAD_PAGE;
334 s = win->sock; 253 s = win->sock;
254 if (req->Page != 0) {
255 ds_dbg(s, 0, "failure: requested page is zero\n");
256 return -EINVAL;
257 }
335 win->ctl.card_start = req->CardOffset; 258 win->ctl.card_start = req->CardOffset;
336 if (s->ops->set_mem_map(s, &win->ctl) != 0) 259 if (s->ops->set_mem_map(s, &win->ctl) != 0) {
337 return CS_BAD_OFFSET; 260 ds_dbg(s, 0, "failed to set_mem_map\n");
338 return CS_SUCCESS; 261 return -EIO;
262 }
263 return 0;
339} /* pcmcia_map_mem_page */ 264} /* pcmcia_map_mem_page */
340EXPORT_SYMBOL(pcmcia_map_mem_page); 265EXPORT_SYMBOL(pcmcia_map_mem_page);
341 266
@@ -354,9 +279,9 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
354 c = p_dev->function_config; 279 c = p_dev->function_config;
355 280
356 if (!(s->state & SOCKET_PRESENT)) 281 if (!(s->state & SOCKET_PRESENT))
357 return CS_NO_CARD; 282 return -ENODEV;
358 if (!(c->state & CONFIG_LOCKED)) 283 if (!(c->state & CONFIG_LOCKED))
359 return CS_CONFIGURATION_LOCKED; 284 return -EACCES;
360 285
361 if (mod->Attributes & CONF_IRQ_CHANGE_VALID) { 286 if (mod->Attributes & CONF_IRQ_CHANGE_VALID) {
362 if (mod->Attributes & CONF_ENABLE_IRQ) { 287 if (mod->Attributes & CONF_ENABLE_IRQ) {
@@ -369,20 +294,28 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
369 s->ops->set_socket(s, &s->socket); 294 s->ops->set_socket(s, &s->socket);
370 } 295 }
371 296
372 if (mod->Attributes & CONF_VCC_CHANGE_VALID) 297 if (mod->Attributes & CONF_VCC_CHANGE_VALID) {
373 return CS_BAD_VCC; 298 ds_dbg(s, 0, "changing Vcc is not allowed at this time\n");
299 return -EINVAL;
300 }
374 301
375 /* We only allow changing Vpp1 and Vpp2 to the same value */ 302 /* We only allow changing Vpp1 and Vpp2 to the same value */
376 if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) && 303 if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) &&
377 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) { 304 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
378 if (mod->Vpp1 != mod->Vpp2) 305 if (mod->Vpp1 != mod->Vpp2)
379 return CS_BAD_VPP; 306 ds_dbg(s, 0, "Vpp1 and Vpp2 must be the same\n");
307 return -EINVAL;
380 s->socket.Vpp = mod->Vpp1; 308 s->socket.Vpp = mod->Vpp1;
381 if (s->ops->set_socket(s, &s->socket)) 309 if (s->ops->set_socket(s, &s->socket)) {
382 return CS_BAD_VPP; 310 dev_printk(KERN_WARNING, &s->dev,
311 "Unable to set VPP\n");
312 return -EIO;
313 }
383 } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) || 314 } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) ||
384 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) 315 (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
385 return CS_BAD_VPP; 316 ds_dbg(s, 0, "changing Vcc is not allowed at this time\n");
317 return -EINVAL;
318 }
386 319
387 if (mod->Attributes & CONF_IO_CHANGE_WIDTH) { 320 if (mod->Attributes & CONF_IO_CHANGE_WIDTH) {
388 pccard_io_map io_off = { 0, 0, 0, 0, 1 }; 321 pccard_io_map io_off = { 0, 0, 0, 0, 1 };
@@ -406,7 +339,7 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
406 } 339 }
407 } 340 }
408 341
409 return CS_SUCCESS; 342 return 0;
410} /* modify_configuration */ 343} /* modify_configuration */
411EXPORT_SYMBOL(pcmcia_modify_configuration); 344EXPORT_SYMBOL(pcmcia_modify_configuration);
412 345
@@ -441,7 +374,7 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev)
441 } 374 }
442 } 375 }
443 376
444 return CS_SUCCESS; 377 return 0;
445} /* pcmcia_release_configuration */ 378} /* pcmcia_release_configuration */
446 379
447 380
@@ -459,7 +392,7 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
459 config_t *c = p_dev->function_config; 392 config_t *c = p_dev->function_config;
460 393
461 if (!p_dev->_io ) 394 if (!p_dev->_io )
462 return CS_BAD_HANDLE; 395 return -EINVAL;
463 396
464 p_dev->_io = 0; 397 p_dev->_io = 0;
465 398
@@ -467,7 +400,7 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
467 (c->io.NumPorts1 != req->NumPorts1) || 400 (c->io.NumPorts1 != req->NumPorts1) ||
468 (c->io.BasePort2 != req->BasePort2) || 401 (c->io.BasePort2 != req->BasePort2) ||
469 (c->io.NumPorts2 != req->NumPorts2)) 402 (c->io.NumPorts2 != req->NumPorts2))
470 return CS_BAD_ARGS; 403 return -EINVAL;
471 404
472 c->state &= ~CONFIG_IO_REQ; 405 c->state &= ~CONFIG_IO_REQ;
473 406
@@ -475,7 +408,7 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
475 if (req->NumPorts2) 408 if (req->NumPorts2)
476 release_io_space(s, req->BasePort2, req->NumPorts2); 409 release_io_space(s, req->BasePort2, req->NumPorts2);
477 410
478 return CS_SUCCESS; 411 return 0;
479} /* pcmcia_release_io */ 412} /* pcmcia_release_io */
480 413
481 414
@@ -485,15 +418,19 @@ static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
485 config_t *c= p_dev->function_config; 418 config_t *c= p_dev->function_config;
486 419
487 if (!p_dev->_irq) 420 if (!p_dev->_irq)
488 return CS_BAD_HANDLE; 421 return -EINVAL;
489 p_dev->_irq = 0; 422 p_dev->_irq = 0;
490 423
491 if (c->state & CONFIG_LOCKED) 424 if (c->state & CONFIG_LOCKED)
492 return CS_CONFIGURATION_LOCKED; 425 return -EACCES;
493 if (c->irq.Attributes != req->Attributes) 426 if (c->irq.Attributes != req->Attributes) {
494 return CS_BAD_ATTRIBUTE; 427 ds_dbg(s, 0, "IRQ attributes must match assigned ones\n");
495 if (s->irq.AssignedIRQ != req->AssignedIRQ) 428 return -EINVAL;
496 return CS_BAD_IRQ; 429 }
430 if (s->irq.AssignedIRQ != req->AssignedIRQ) {
431 ds_dbg(s, 0, "IRQ must match assigned one\n");
432 return -EINVAL;
433 }
497 if (--s->irq.Config == 0) { 434 if (--s->irq.Config == 0) {
498 c->state &= ~CONFIG_IRQ_REQ; 435 c->state &= ~CONFIG_IRQ_REQ;
499 s->irq.AssignedIRQ = 0; 436 s->irq.AssignedIRQ = 0;
@@ -507,7 +444,7 @@ static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
507 pcmcia_used_irq[req->AssignedIRQ]--; 444 pcmcia_used_irq[req->AssignedIRQ]--;
508#endif 445#endif
509 446
510 return CS_SUCCESS; 447 return 0;
511} /* pcmcia_release_irq */ 448} /* pcmcia_release_irq */
512 449
513 450
@@ -516,10 +453,10 @@ int pcmcia_release_window(window_handle_t win)
516 struct pcmcia_socket *s; 453 struct pcmcia_socket *s;
517 454
518 if ((win == NULL) || (win->magic != WINDOW_MAGIC)) 455 if ((win == NULL) || (win->magic != WINDOW_MAGIC))
519 return CS_BAD_HANDLE; 456 return -EINVAL;
520 s = win->sock; 457 s = win->sock;
521 if (!(win->handle->_win & CLIENT_WIN_REQ(win->index))) 458 if (!(win->handle->_win & CLIENT_WIN_REQ(win->index)))
522 return CS_BAD_HANDLE; 459 return -EINVAL;
523 460
524 /* Shut down memory window */ 461 /* Shut down memory window */
525 win->ctl.flags &= ~MAP_ACTIVE; 462 win->ctl.flags &= ~MAP_ACTIVE;
@@ -536,7 +473,7 @@ int pcmcia_release_window(window_handle_t win)
536 473
537 win->magic = 0; 474 win->magic = 0;
538 475
539 return CS_SUCCESS; 476 return 0;
540} /* pcmcia_release_window */ 477} /* pcmcia_release_window */
541EXPORT_SYMBOL(pcmcia_release_window); 478EXPORT_SYMBOL(pcmcia_release_window);
542 479
@@ -551,18 +488,23 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
551 pccard_io_map iomap; 488 pccard_io_map iomap;
552 489
553 if (!(s->state & SOCKET_PRESENT)) 490 if (!(s->state & SOCKET_PRESENT))
554 return CS_NO_CARD; 491 return -ENODEV;;
555 492
556 if (req->IntType & INT_CARDBUS) 493 if (req->IntType & INT_CARDBUS) {
557 return CS_UNSUPPORTED_MODE; 494 ds_dbg(p_dev->socket, 0, "IntType may not be INT_CARDBUS\n");
495 return -EINVAL;
496 }
558 c = p_dev->function_config; 497 c = p_dev->function_config;
559 if (c->state & CONFIG_LOCKED) 498 if (c->state & CONFIG_LOCKED)
560 return CS_CONFIGURATION_LOCKED; 499 return -EACCES;
561 500
562 /* Do power control. We don't allow changes in Vcc. */ 501 /* Do power control. We don't allow changes in Vcc. */
563 s->socket.Vpp = req->Vpp; 502 s->socket.Vpp = req->Vpp;
564 if (s->ops->set_socket(s, &s->socket)) 503 if (s->ops->set_socket(s, &s->socket)) {
565 return CS_BAD_VPP; 504 dev_printk(KERN_WARNING, &s->dev,
505 "Unable to set socket state\n");
506 return -EINVAL;
507 }
566 508
567 /* Pick memory or I/O card, DMA mode, interrupt */ 509 /* Pick memory or I/O card, DMA mode, interrupt */
568 c->IntType = req->IntType; 510 c->IntType = req->IntType;
@@ -651,7 +593,7 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
651 593
652 c->state |= CONFIG_LOCKED; 594 c->state |= CONFIG_LOCKED;
653 p_dev->_locked = 1; 595 p_dev->_locked = 1;
654 return CS_SUCCESS; 596 return 0;
655} /* pcmcia_request_configuration */ 597} /* pcmcia_request_configuration */
656EXPORT_SYMBOL(pcmcia_request_configuration); 598EXPORT_SYMBOL(pcmcia_request_configuration);
657 599
@@ -667,37 +609,48 @@ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
667 config_t *c; 609 config_t *c;
668 610
669 if (!(s->state & SOCKET_PRESENT)) 611 if (!(s->state & SOCKET_PRESENT))
670 return CS_NO_CARD; 612 return -ENODEV;
671 613
672 if (!req) 614 if (!req)
673 return CS_UNSUPPORTED_MODE; 615 return -EINVAL;
674 c = p_dev->function_config; 616 c = p_dev->function_config;
675 if (c->state & CONFIG_LOCKED) 617 if (c->state & CONFIG_LOCKED)
676 return CS_CONFIGURATION_LOCKED; 618 return -EACCES;
677 if (c->state & CONFIG_IO_REQ) 619 if (c->state & CONFIG_IO_REQ) {
678 return CS_IN_USE; 620 ds_dbg(s, 0, "IO already configured\n");
679 if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)) 621 return -EBUSY;
680 return CS_BAD_ATTRIBUTE; 622 }
623 if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)) {
624 ds_dbg(s, 0, "bad attribute setting for IO region 1\n");
625 return -EINVAL;
626 }
681 if ((req->NumPorts2 > 0) && 627 if ((req->NumPorts2 > 0) &&
682 (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))) 628 (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))) {
683 return CS_BAD_ATTRIBUTE; 629 ds_dbg(s, 0, "bad attribute setting for IO region 2\n");
630 return -EINVAL;
631 }
684 632
633 ds_dbg(s, 1, "trying to allocate resource 1\n");
685 if (alloc_io_space(s, req->Attributes1, &req->BasePort1, 634 if (alloc_io_space(s, req->Attributes1, &req->BasePort1,
686 req->NumPorts1, req->IOAddrLines)) 635 req->NumPorts1, req->IOAddrLines)) {
687 return CS_IN_USE; 636 ds_dbg(s, 0, "allocation of resource 1 failed\n");
637 return -EBUSY;
638 }
688 639
689 if (req->NumPorts2) { 640 if (req->NumPorts2) {
641 ds_dbg(s, 1, "trying to allocate resource 2\n");
690 if (alloc_io_space(s, req->Attributes2, &req->BasePort2, 642 if (alloc_io_space(s, req->Attributes2, &req->BasePort2,
691 req->NumPorts2, req->IOAddrLines)) { 643 req->NumPorts2, req->IOAddrLines)) {
644 ds_dbg(s, 0, "allocation of resource 2 failed\n");
692 release_io_space(s, req->BasePort1, req->NumPorts1); 645 release_io_space(s, req->BasePort1, req->NumPorts1);
693 return CS_IN_USE; 646 return -EBUSY;
694 } 647 }
695 } 648 }
696 649
697 c->io = *req; 650 c->io = *req;
698 c->state |= CONFIG_IO_REQ; 651 c->state |= CONFIG_IO_REQ;
699 p_dev->_io = 1; 652 p_dev->_io = 1;
700 return CS_SUCCESS; 653 return 0;
701} /* pcmcia_request_io */ 654} /* pcmcia_request_io */
702EXPORT_SYMBOL(pcmcia_request_io); 655EXPORT_SYMBOL(pcmcia_request_io);
703 656
@@ -723,16 +676,18 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
723{ 676{
724 struct pcmcia_socket *s = p_dev->socket; 677 struct pcmcia_socket *s = p_dev->socket;
725 config_t *c; 678 config_t *c;
726 int ret = CS_IN_USE, irq = 0; 679 int ret = -EINVAL, irq = 0;
727 int type; 680 int type;
728 681
729 if (!(s->state & SOCKET_PRESENT)) 682 if (!(s->state & SOCKET_PRESENT))
730 return CS_NO_CARD; 683 return -ENODEV;
731 c = p_dev->function_config; 684 c = p_dev->function_config;
732 if (c->state & CONFIG_LOCKED) 685 if (c->state & CONFIG_LOCKED)
733 return CS_CONFIGURATION_LOCKED; 686 return -EACCES;
734 if (c->state & CONFIG_IRQ_REQ) 687 if (c->state & CONFIG_IRQ_REQ) {
735 return CS_IN_USE; 688 ds_dbg(s, 0, "IRQ already configured\n");
689 return -EBUSY;
690 }
736 691
737 /* Decide what type of interrupt we are registering */ 692 /* Decide what type of interrupt we are registering */
738 type = 0; 693 type = 0;
@@ -795,15 +750,19 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
795 } 750 }
796 751
797 if (ret && (req->Attributes & IRQ_HANDLE_PRESENT)) { 752 if (ret && (req->Attributes & IRQ_HANDLE_PRESENT)) {
798 if (request_irq(irq, req->Handler, type, p_dev->devname, req->Instance)) 753 ret = request_irq(irq, req->Handler, type,
799 return CS_IN_USE; 754 p_dev->devname, req->Instance);
755 if (ret)
756 return ret;
800 } 757 }
801 758
802 /* Make sure the fact the request type was overridden is passed back */ 759 /* Make sure the fact the request type was overridden is passed back */
803 if (type == IRQF_SHARED && !(req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)) { 760 if (type == IRQF_SHARED && !(req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)) {
804 req->Attributes |= IRQ_TYPE_DYNAMIC_SHARING; 761 req->Attributes |= IRQ_TYPE_DYNAMIC_SHARING;
805 printk(KERN_WARNING "pcmcia: request for exclusive IRQ could not be fulfilled.\n"); 762 dev_printk(KERN_WARNING, &p_dev->dev, "pcmcia: "
806 printk(KERN_WARNING "pcmcia: the driver needs updating to supported shared IRQ lines.\n"); 763 "request for exclusive IRQ could not be fulfilled.\n");
764 dev_printk(KERN_WARNING, &p_dev->dev, "pcmcia: the driver "
765 "needs updating to supported shared IRQ lines.\n");
807 } 766 }
808 c->irq.Attributes = req->Attributes; 767 c->irq.Attributes = req->Attributes;
809 s->irq.AssignedIRQ = req->AssignedIRQ = irq; 768 s->irq.AssignedIRQ = req->AssignedIRQ = irq;
@@ -816,7 +775,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
816 pcmcia_used_irq[irq]++; 775 pcmcia_used_irq[irq]++;
817#endif 776#endif
818 777
819 return CS_SUCCESS; 778 return 0;
820} /* pcmcia_request_irq */ 779} /* pcmcia_request_irq */
821EXPORT_SYMBOL(pcmcia_request_irq); 780EXPORT_SYMBOL(pcmcia_request_irq);
822 781
@@ -834,9 +793,11 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
834 int w; 793 int w;
835 794
836 if (!(s->state & SOCKET_PRESENT)) 795 if (!(s->state & SOCKET_PRESENT))
837 return CS_NO_CARD; 796 return -ENODEV;
838 if (req->Attributes & (WIN_PAGED | WIN_SHARED)) 797 if (req->Attributes & (WIN_PAGED | WIN_SHARED)) {
839 return CS_BAD_ATTRIBUTE; 798 ds_dbg(s, 0, "bad attribute setting for iomem region\n");
799 return -EINVAL;
800 }
840 801
841 /* Window size defaults to smallest available */ 802 /* Window size defaults to smallest available */
842 if (req->Size == 0) 803 if (req->Size == 0)
@@ -844,19 +805,25 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
844 align = (((s->features & SS_CAP_MEM_ALIGN) || 805 align = (((s->features & SS_CAP_MEM_ALIGN) ||
845 (req->Attributes & WIN_STRICT_ALIGN)) ? 806 (req->Attributes & WIN_STRICT_ALIGN)) ?
846 req->Size : s->map_size); 807 req->Size : s->map_size);
847 if (req->Size & (s->map_size-1)) 808 if (req->Size & (s->map_size-1)) {
848 return CS_BAD_SIZE; 809 ds_dbg(s, 0, "invalid map size\n");
810 return -EINVAL;
811 }
849 if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) || 812 if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) ||
850 (req->Base & (align-1))) 813 (req->Base & (align-1))) {
851 return CS_BAD_BASE; 814 ds_dbg(s, 0, "invalid base address\n");
815 return -EINVAL;
816 }
852 if (req->Base) 817 if (req->Base)
853 align = 0; 818 align = 0;
854 819
855 /* Allocate system memory window */ 820 /* Allocate system memory window */
856 for (w = 0; w < MAX_WIN; w++) 821 for (w = 0; w < MAX_WIN; w++)
857 if (!(s->state & SOCKET_WIN_REQ(w))) break; 822 if (!(s->state & SOCKET_WIN_REQ(w))) break;
858 if (w == MAX_WIN) 823 if (w == MAX_WIN) {
859 return CS_OUT_OF_RESOURCE; 824 ds_dbg(s, 0, "all windows are used already\n");
825 return -EINVAL;
826 }
860 827
861 win = &s->win[w]; 828 win = &s->win[w];
862 win->magic = WINDOW_MAGIC; 829 win->magic = WINDOW_MAGIC;
@@ -867,8 +834,10 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
867 if (!(s->features & SS_CAP_STATIC_MAP)) { 834 if (!(s->features & SS_CAP_STATIC_MAP)) {
868 win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align, 835 win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align,
869 (req->Attributes & WIN_MAP_BELOW_1MB), s); 836 (req->Attributes & WIN_MAP_BELOW_1MB), s);
870 if (!win->ctl.res) 837 if (!win->ctl.res) {
871 return CS_IN_USE; 838 ds_dbg(s, 0, "allocating mem region failed\n");
839 return -EINVAL;
840 }
872 } 841 }
873 (*p_dev)->_win |= CLIENT_WIN_REQ(w); 842 (*p_dev)->_win |= CLIENT_WIN_REQ(w);
874 843
@@ -885,8 +854,10 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
885 if (req->Attributes & WIN_USE_WAIT) 854 if (req->Attributes & WIN_USE_WAIT)
886 win->ctl.flags |= MAP_USE_WAIT; 855 win->ctl.flags |= MAP_USE_WAIT;
887 win->ctl.card_start = 0; 856 win->ctl.card_start = 0;
888 if (s->ops->set_mem_map(s, &win->ctl) != 0) 857 if (s->ops->set_mem_map(s, &win->ctl) != 0) {
889 return CS_BAD_ARGS; 858 ds_dbg(s, 0, "failed to set memory mapping\n");
859 return -EIO;
860 }
890 s->state |= SOCKET_WIN_REQ(w); 861 s->state |= SOCKET_WIN_REQ(w);
891 862
892 /* Return window handle */ 863 /* Return window handle */
@@ -897,7 +868,7 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
897 } 868 }
898 *wh = win; 869 *wh = win;
899 870
900 return CS_SUCCESS; 871 return 0;
901} /* pcmcia_request_window */ 872} /* pcmcia_request_window */
902EXPORT_SYMBOL(pcmcia_request_window); 873EXPORT_SYMBOL(pcmcia_request_window);
903 874
@@ -909,3 +880,79 @@ void pcmcia_disable_device(struct pcmcia_device *p_dev) {
909 pcmcia_release_window(p_dev->win); 880 pcmcia_release_window(p_dev->win);
910} 881}
911EXPORT_SYMBOL(pcmcia_disable_device); 882EXPORT_SYMBOL(pcmcia_disable_device);
883
884
885struct pcmcia_cfg_mem {
886 tuple_t tuple;
887 cisparse_t parse;
888 u8 buf[256];
889 cistpl_cftable_entry_t dflt;
890};
891
892/**
893 * pcmcia_loop_config() - loop over configuration options
894 * @p_dev: the struct pcmcia_device which we need to loop for.
895 * @conf_check: function to call for each configuration option.
896 * It gets passed the struct pcmcia_device, the CIS data
897 * describing the configuration option, and private data
898 * being passed to pcmcia_loop_config()
899 * @priv_data: private data to be passed to the conf_check function.
900 *
901 * pcmcia_loop_config() loops over all configuration options, and calls
902 * the driver-specific conf_check() for each one, checking whether
903 * it is a valid one.
904 */
905int pcmcia_loop_config(struct pcmcia_device *p_dev,
906 int (*conf_check) (struct pcmcia_device *p_dev,
907 cistpl_cftable_entry_t *cfg,
908 cistpl_cftable_entry_t *dflt,
909 unsigned int vcc,
910 void *priv_data),
911 void *priv_data)
912{
913 struct pcmcia_cfg_mem *cfg_mem;
914
915 tuple_t *tuple;
916 int ret = -ENODEV;
917 unsigned int vcc;
918
919 cfg_mem = kzalloc(sizeof(struct pcmcia_cfg_mem), GFP_KERNEL);
920 if (cfg_mem == NULL)
921 return -ENOMEM;
922
923 /* get the current Vcc setting */
924 vcc = p_dev->socket->socket.Vcc;
925
926 tuple = &cfg_mem->tuple;
927 tuple->TupleData = cfg_mem->buf;
928 tuple->TupleDataMax = 255;
929 tuple->TupleOffset = 0;
930 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
931 tuple->Attributes = 0;
932
933 ret = pcmcia_get_first_tuple(p_dev, tuple);
934 while (!ret) {
935 cistpl_cftable_entry_t *cfg = &cfg_mem->parse.cftable_entry;
936
937 if (pcmcia_get_tuple_data(p_dev, tuple))
938 goto next_entry;
939
940 if (pcmcia_parse_tuple(tuple, &cfg_mem->parse))
941 goto next_entry;
942
943 /* default values */
944 p_dev->conf.ConfigIndex = cfg->index;
945 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
946 cfg_mem->dflt = *cfg;
947
948 ret = conf_check(p_dev, cfg, &cfg_mem->dflt, vcc, priv_data);
949 if (!ret)
950 break;
951
952next_entry:
953 ret = pcmcia_get_next_tuple(p_dev, tuple);
954 }
955
956 return ret;
957}
958EXPORT_SYMBOL(pcmcia_loop_config);
diff --git a/drivers/pcmcia/pxa2xx_base.c b/drivers/pcmcia/pxa2xx_base.c
index 13f1e0fd3f31..bb9ddb9532e3 100644
--- a/drivers/pcmcia/pxa2xx_base.c
+++ b/drivers/pcmcia/pxa2xx_base.c
@@ -36,7 +36,6 @@
36#include <pcmcia/ss.h> 36#include <pcmcia/ss.h>
37#include <pcmcia/cistpl.h> 37#include <pcmcia/cistpl.h>
38 38
39#include "cs_internal.h"
40#include "soc_common.h" 39#include "soc_common.h"
41#include "pxa2xx_base.h" 40#include "pxa2xx_base.h"
42 41
diff --git a/drivers/pcmcia/rsrc_nonstatic.c b/drivers/pcmcia/rsrc_nonstatic.c
index 203e579ebbd2..17f4ecf1c0c5 100644
--- a/drivers/pcmcia/rsrc_nonstatic.c
+++ b/drivers/pcmcia/rsrc_nonstatic.c
@@ -122,19 +122,22 @@ static void free_region(struct resource *res)
122 122
123static int add_interval(struct resource_map *map, u_long base, u_long num) 123static int add_interval(struct resource_map *map, u_long base, u_long num)
124{ 124{
125 struct resource_map *p, *q; 125 struct resource_map *p, *q;
126 126
127 for (p = map; ; p = p->next) { 127 for (p = map; ; p = p->next) {
128 if ((p != map) && (p->base+p->num-1 >= base)) 128 if ((p != map) && (p->base+p->num-1 >= base))
129 return -1; 129 return -1;
130 if ((p->next == map) || (p->next->base > base+num-1)) 130 if ((p->next == map) || (p->next->base > base+num-1))
131 break; 131 break;
132 } 132 }
133 q = kmalloc(sizeof(struct resource_map), GFP_KERNEL); 133 q = kmalloc(sizeof(struct resource_map), GFP_KERNEL);
134 if (!q) return CS_OUT_OF_RESOURCE; 134 if (!q) {
135 q->base = base; q->num = num; 135 printk(KERN_WARNING "out of memory to update resources\n");
136 q->next = p->next; p->next = q; 136 return -ENOMEM;
137 return CS_SUCCESS; 137 }
138 q->base = base; q->num = num;
139 q->next = p->next; p->next = q;
140 return 0;
138} 141}
139 142
140/*====================================================================*/ 143/*====================================================================*/
@@ -166,7 +169,10 @@ static int sub_interval(struct resource_map *map, u_long base, u_long num)
166 } else { 169 } else {
167 /* Split the block into two pieces */ 170 /* Split the block into two pieces */
168 p = kmalloc(sizeof(struct resource_map), GFP_KERNEL); 171 p = kmalloc(sizeof(struct resource_map), GFP_KERNEL);
169 if (!p) return CS_OUT_OF_RESOURCE; 172 if (!p) {
173 printk(KERN_WARNING "out of memory to update resources\n");
174 return -ENOMEM;
175 }
170 p->base = base+num; 176 p->base = base+num;
171 p->num = q->base+q->num - p->base; 177 p->num = q->base+q->num - p->base;
172 q->num = base - q->base; 178 q->num = base - q->base;
@@ -174,7 +180,7 @@ static int sub_interval(struct resource_map *map, u_long base, u_long num)
174 } 180 }
175 } 181 }
176 } 182 }
177 return CS_SUCCESS; 183 return 0;
178} 184}
179 185
180/*====================================================================== 186/*======================================================================
@@ -194,13 +200,14 @@ static void do_io_probe(struct pcmcia_socket *s, unsigned int base,
194 int any; 200 int any;
195 u_char *b, hole, most; 201 u_char *b, hole, most;
196 202
197 printk(KERN_INFO "cs: IO port probe %#x-%#x:", 203 dev_printk(KERN_INFO, &s->dev, "cs: IO port probe %#x-%#x:",
198 base, base+num-1); 204 base, base+num-1);
199 205
200 /* First, what does a floating port look like? */ 206 /* First, what does a floating port look like? */
201 b = kzalloc(256, GFP_KERNEL); 207 b = kzalloc(256, GFP_KERNEL);
202 if (!b) { 208 if (!b) {
203 printk(KERN_ERR "do_io_probe: unable to kmalloc 256 bytes"); 209 dev_printk(KERN_ERR, &s->dev,
210 "do_io_probe: unable to kmalloc 256 bytes");
204 return; 211 return;
205 } 212 }
206 for (i = base, most = 0; i < base+num; i += 8) { 213 for (i = base, most = 0; i < base+num; i += 8) {
@@ -366,8 +373,8 @@ static int do_mem_probe(u_long base, u_long num, struct pcmcia_socket *s)
366 struct socket_data *s_data = s->resource_data; 373 struct socket_data *s_data = s->resource_data;
367 u_long i, j, bad, fail, step; 374 u_long i, j, bad, fail, step;
368 375
369 printk(KERN_INFO "cs: memory probe 0x%06lx-0x%06lx:", 376 dev_printk(KERN_INFO, &s->dev, "cs: memory probe 0x%06lx-0x%06lx:",
370 base, base+num-1); 377 base, base+num-1);
371 bad = fail = 0; 378 bad = fail = 0;
372 step = (num < 0x20000) ? 0x2000 : ((num>>4) & ~0x1fff); 379 step = (num < 0x20000) ? 0x2000 : ((num>>4) & ~0x1fff);
373 /* don't allow too large steps */ 380 /* don't allow too large steps */
@@ -431,8 +438,8 @@ static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask)
431 if (probe_mask & MEM_PROBE_HIGH) { 438 if (probe_mask & MEM_PROBE_HIGH) {
432 if (inv_probe(s_data->mem_db.next, s) > 0) 439 if (inv_probe(s_data->mem_db.next, s) > 0)
433 return 0; 440 return 0;
434 printk(KERN_NOTICE "cs: warning: no high memory space " 441 dev_printk(KERN_NOTICE, &s->dev,
435 "available!\n"); 442 "cs: warning: no high memory space available!\n");
436 return -ENODEV; 443 return -ENODEV;
437 } 444 }
438 445
@@ -794,10 +801,11 @@ static int nonstatic_autoadd_resources(struct pcmcia_socket *s)
794 if (res->flags & IORESOURCE_IO) { 801 if (res->flags & IORESOURCE_IO) {
795 if (res == &ioport_resource) 802 if (res == &ioport_resource)
796 continue; 803 continue;
797 printk(KERN_INFO "pcmcia: parent PCI bridge I/O " 804 dev_printk(KERN_INFO, &s->cb_dev->dev,
798 "window: 0x%llx - 0x%llx\n", 805 "pcmcia: parent PCI bridge I/O "
799 (unsigned long long)res->start, 806 "window: 0x%llx - 0x%llx\n",
800 (unsigned long long)res->end); 807 (unsigned long long)res->start,
808 (unsigned long long)res->end);
801 if (!adjust_io(s, ADD_MANAGED_RESOURCE, res->start, res->end)) 809 if (!adjust_io(s, ADD_MANAGED_RESOURCE, res->start, res->end))
802 done |= IORESOURCE_IO; 810 done |= IORESOURCE_IO;
803 811
@@ -806,10 +814,11 @@ static int nonstatic_autoadd_resources(struct pcmcia_socket *s)
806 if (res->flags & IORESOURCE_MEM) { 814 if (res->flags & IORESOURCE_MEM) {
807 if (res == &iomem_resource) 815 if (res == &iomem_resource)
808 continue; 816 continue;
809 printk(KERN_INFO "pcmcia: parent PCI bridge Memory " 817 dev_printk(KERN_INFO, &s->cb_dev->dev,
810 "window: 0x%llx - 0x%llx\n", 818 "pcmcia: parent PCI bridge Memory "
811 (unsigned long long)res->start, 819 "window: 0x%llx - 0x%llx\n",
812 (unsigned long long)res->end); 820 (unsigned long long)res->start,
821 (unsigned long long)res->end);
813 if (!adjust_memory(s, ADD_MANAGED_RESOURCE, res->start, res->end)) 822 if (!adjust_memory(s, ADD_MANAGED_RESOURCE, res->start, res->end))
814 done |= IORESOURCE_MEM; 823 done |= IORESOURCE_MEM;
815 } 824 }
diff --git a/drivers/pcmcia/soc_common.c b/drivers/pcmcia/soc_common.c
index da3972153226..f49ac6666153 100644
--- a/drivers/pcmcia/soc_common.c
+++ b/drivers/pcmcia/soc_common.c
@@ -54,7 +54,7 @@
54#include <mach/pxa-regs.h> 54#include <mach/pxa-regs.h>
55#endif 55#endif
56 56
57#ifdef DEBUG 57#ifdef CONFIG_PCMCIA_DEBUG
58 58
59static int pc_debug; 59static int pc_debug;
60module_param(pc_debug, int, 0644); 60module_param(pc_debug, int, 0644);
diff --git a/drivers/pcmcia/soc_common.h b/drivers/pcmcia/soc_common.h
index 91ef6a0da3ab..38c67375f363 100644
--- a/drivers/pcmcia/soc_common.h
+++ b/drivers/pcmcia/soc_common.h
@@ -15,7 +15,6 @@
15#include <pcmcia/cs.h> 15#include <pcmcia/cs.h>
16#include <pcmcia/ss.h> 16#include <pcmcia/ss.h>
17#include <pcmcia/cistpl.h> 17#include <pcmcia/cistpl.h>
18#include "cs_internal.h"
19 18
20 19
21struct device; 20struct device;
@@ -137,7 +136,7 @@ extern int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_lev
137extern int soc_common_drv_pcmcia_remove(struct device *dev); 136extern int soc_common_drv_pcmcia_remove(struct device *dev);
138 137
139 138
140#ifdef DEBUG 139#ifdef CONFIG_PCMCIA_DEBUG
141 140
142extern void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func, 141extern void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func,
143 int lvl, const char *fmt, ...); 142 int lvl, const char *fmt, ...);
diff --git a/drivers/pcmcia/socket_sysfs.c b/drivers/pcmcia/socket_sysfs.c
index 006a29e91d83..ff9a3bb3c88d 100644
--- a/drivers/pcmcia/socket_sysfs.c
+++ b/drivers/pcmcia/socket_sysfs.c
@@ -316,27 +316,18 @@ static ssize_t pccard_store_cis(struct kobject *kobj,
316 char *buf, loff_t off, size_t count) 316 char *buf, loff_t off, size_t count)
317{ 317{
318 struct pcmcia_socket *s = to_socket(container_of(kobj, struct device, kobj)); 318 struct pcmcia_socket *s = to_socket(container_of(kobj, struct device, kobj));
319 cisdump_t *cis;
320 int error; 319 int error;
321 320
322 if (off) 321 if (off)
323 return -EINVAL; 322 return -EINVAL;
324 323
325 if (count >= 0x200) 324 if (count >= CISTPL_MAX_CIS_SIZE)
326 return -EINVAL; 325 return -EINVAL;
327 326
328 if (!(s->state & SOCKET_PRESENT)) 327 if (!(s->state & SOCKET_PRESENT))
329 return -ENODEV; 328 return -ENODEV;
330 329
331 cis = kzalloc(sizeof(cisdump_t), GFP_KERNEL); 330 error = pcmcia_replace_cis(s, buf, count);
332 if (!cis)
333 return -ENOMEM;
334
335 cis->Length = count + 1;
336 memcpy(cis->Data, buf, count);
337
338 error = pcmcia_replace_cis(s, cis);
339 kfree(cis);
340 if (error) 331 if (error)
341 return -EIO; 332 return -EIO;
342 333
diff --git a/drivers/pcmcia/tcic.c b/drivers/pcmcia/tcic.c
index 5792bd5c54f9..2a613e920fd4 100644
--- a/drivers/pcmcia/tcic.c
+++ b/drivers/pcmcia/tcic.c
@@ -55,7 +55,7 @@
55#include <pcmcia/ss.h> 55#include <pcmcia/ss.h>
56#include "tcic.h" 56#include "tcic.h"
57 57
58#ifdef DEBUG 58#ifdef CONFIG_PCMCIA_DEBUG
59static int pc_debug; 59static int pc_debug;
60 60
61module_param(pc_debug, int, 0644); 61module_param(pc_debug, int, 0644);
diff --git a/drivers/pcmcia/ti113x.h b/drivers/pcmcia/ti113x.h
index 129db7bd06c3..aaa70227bfb0 100644
--- a/drivers/pcmcia/ti113x.h
+++ b/drivers/pcmcia/ti113x.h
@@ -339,8 +339,8 @@ static void ti12xx_irqroute_func0(struct yenta_socket *socket)
339 339
340 mfunc = mfunc_old = config_readl(socket, TI122X_MFUNC); 340 mfunc = mfunc_old = config_readl(socket, TI122X_MFUNC);
341 devctl = config_readb(socket, TI113X_DEVICE_CONTROL); 341 devctl = config_readb(socket, TI113X_DEVICE_CONTROL);
342 printk(KERN_INFO "Yenta TI: socket %s, mfunc 0x%08x, devctl 0x%02x\n", 342 dev_printk(KERN_INFO, &socket->dev->dev,
343 pci_name(socket->dev), mfunc, devctl); 343 "TI: mfunc 0x%08x, devctl 0x%02x\n", mfunc, devctl);
344 344
345 /* make sure PCI interrupts are enabled before probing */ 345 /* make sure PCI interrupts are enabled before probing */
346 ti_init(socket); 346 ti_init(socket);
@@ -354,8 +354,8 @@ static void ti12xx_irqroute_func0(struct yenta_socket *socket)
354 * We're here which means PCI interrupts are _not_ delivered. try to 354 * We're here which means PCI interrupts are _not_ delivered. try to
355 * find the right setting (all serial or parallel) 355 * find the right setting (all serial or parallel)
356 */ 356 */
357 printk(KERN_INFO "Yenta TI: socket %s probing PCI interrupt failed, trying to fix\n", 357 dev_printk(KERN_INFO, &socket->dev->dev,
358 pci_name(socket->dev)); 358 "TI: probing PCI interrupt failed, trying to fix\n");
359 359
360 /* for serial PCI make sure MFUNC3 is set to IRQSER */ 360 /* for serial PCI make sure MFUNC3 is set to IRQSER */
361 if ((devctl & TI113X_DCR_IMODE_MASK) == TI12XX_DCR_IMODE_ALL_SERIAL) { 361 if ((devctl & TI113X_DCR_IMODE_MASK) == TI12XX_DCR_IMODE_ALL_SERIAL) {
@@ -379,8 +379,8 @@ static void ti12xx_irqroute_func0(struct yenta_socket *socket)
379 379
380 pci_irq_status = yenta_probe_cb_irq(socket); 380 pci_irq_status = yenta_probe_cb_irq(socket);
381 if (pci_irq_status == 1) { 381 if (pci_irq_status == 1) {
382 printk(KERN_INFO "Yenta TI: socket %s all-serial interrupts ok\n", 382 dev_printk(KERN_INFO, &socket->dev->dev,
383 pci_name(socket->dev)); 383 "TI: all-serial interrupts ok\n");
384 mfunc_old = mfunc; 384 mfunc_old = mfunc;
385 goto out; 385 goto out;
386 } 386 }
@@ -395,8 +395,8 @@ static void ti12xx_irqroute_func0(struct yenta_socket *socket)
395 } 395 }
396 396
397 /* serial PCI interrupts not working fall back to parallel */ 397 /* serial PCI interrupts not working fall back to parallel */
398 printk(KERN_INFO "Yenta TI: socket %s falling back to parallel PCI interrupts\n", 398 dev_printk(KERN_INFO, &socket->dev->dev,
399 pci_name(socket->dev)); 399 "TI: falling back to parallel PCI interrupts\n");
400 devctl &= ~TI113X_DCR_IMODE_MASK; 400 devctl &= ~TI113X_DCR_IMODE_MASK;
401 devctl |= TI113X_DCR_IMODE_SERIAL; /* serial ISA could be right */ 401 devctl |= TI113X_DCR_IMODE_SERIAL; /* serial ISA could be right */
402 config_writeb(socket, TI113X_DEVICE_CONTROL, devctl); 402 config_writeb(socket, TI113X_DEVICE_CONTROL, devctl);
@@ -427,8 +427,8 @@ static void ti12xx_irqroute_func0(struct yenta_socket *socket)
427 pci_irq_status = yenta_probe_cb_irq(socket); 427 pci_irq_status = yenta_probe_cb_irq(socket);
428 if (pci_irq_status == 1) { 428 if (pci_irq_status == 1) {
429 mfunc_old = mfunc; 429 mfunc_old = mfunc;
430 printk(KERN_INFO "Yenta TI: socket %s parallel PCI interrupts ok\n", 430 dev_printk(KERN_INFO, &socket->dev->dev,
431 pci_name(socket->dev)); 431 "TI: parallel PCI interrupts ok\n");
432 } else { 432 } else {
433 /* not working, back to old value */ 433 /* not working, back to old value */
434 mfunc = mfunc_old; 434 mfunc = mfunc_old;
@@ -440,8 +440,9 @@ static void ti12xx_irqroute_func0(struct yenta_socket *socket)
440out: 440out:
441 if (pci_irq_status < 1) { 441 if (pci_irq_status < 1) {
442 socket->cb_irq = 0; 442 socket->cb_irq = 0;
443 printk(KERN_INFO "Yenta TI: socket %s no PCI interrupts. Fish. Please report.\n", 443 dev_printk(KERN_INFO, &socket->dev->dev,
444 pci_name(socket->dev)); 444 "Yenta TI: no PCI interrupts. Fish. "
445 "Please report.\n");
445 } 446 }
446} 447}
447 448
@@ -513,8 +514,9 @@ static void ti12xx_irqroute_func1(struct yenta_socket *socket)
513 514
514 mfunc = mfunc_old = config_readl(socket, TI122X_MFUNC); 515 mfunc = mfunc_old = config_readl(socket, TI122X_MFUNC);
515 devctl = config_readb(socket, TI113X_DEVICE_CONTROL); 516 devctl = config_readb(socket, TI113X_DEVICE_CONTROL);
516 printk(KERN_INFO "Yenta TI: socket %s, mfunc 0x%08x, devctl 0x%02x\n", 517 dev_printk(KERN_INFO, &socket->dev->dev,
517 pci_name(socket->dev), mfunc, devctl); 518 "TI: mfunc 0x%08x, devctl 0x%02x\n",
519 mfunc, devctl);
518 520
519 /* if IRQs are configured as tied, align irq of func1 with func0 */ 521 /* if IRQs are configured as tied, align irq of func1 with func0 */
520 sysctl = config_readl(socket, TI113X_SYSTEM_CONTROL); 522 sysctl = config_readl(socket, TI113X_SYSTEM_CONTROL);
@@ -533,9 +535,8 @@ static void ti12xx_irqroute_func1(struct yenta_socket *socket)
533 * We're here which means PCI interrupts are _not_ delivered. try to 535 * We're here which means PCI interrupts are _not_ delivered. try to
534 * find the right setting 536 * find the right setting
535 */ 537 */
536 printk(KERN_INFO "Yenta TI: socket %s probing PCI interrupt failed, trying to fix\n", 538 dev_printk(KERN_INFO, &socket->dev->dev,
537 pci_name(socket->dev)); 539 "TI: probing PCI interrupt failed, trying to fix\n");
538
539 540
540 /* if all serial: set INTRTIE, probe again */ 541 /* if all serial: set INTRTIE, probe again */
541 if ((devctl & TI113X_DCR_IMODE_MASK) == TI12XX_DCR_IMODE_ALL_SERIAL) { 542 if ((devctl & TI113X_DCR_IMODE_MASK) == TI12XX_DCR_IMODE_ALL_SERIAL) {
@@ -544,8 +545,8 @@ static void ti12xx_irqroute_func1(struct yenta_socket *socket)
544 if (ti12xx_tie_interrupts(socket, &old_irq)) { 545 if (ti12xx_tie_interrupts(socket, &old_irq)) {
545 pci_irq_status = yenta_probe_cb_irq(socket); 546 pci_irq_status = yenta_probe_cb_irq(socket);
546 if (pci_irq_status == 1) { 547 if (pci_irq_status == 1) {
547 printk(KERN_INFO "Yenta TI: socket %s all-serial interrupts, tied ok\n", 548 dev_printk(KERN_INFO, &socket->dev->dev,
548 pci_name(socket->dev)); 549 "TI: all-serial interrupts, tied ok\n");
549 goto out; 550 goto out;
550 } 551 }
551 552
@@ -582,8 +583,8 @@ static void ti12xx_irqroute_func1(struct yenta_socket *socket)
582 583
583 pci_irq_status = yenta_probe_cb_irq(socket); 584 pci_irq_status = yenta_probe_cb_irq(socket);
584 if (pci_irq_status == 1) { 585 if (pci_irq_status == 1) {
585 printk(KERN_INFO "Yenta TI: socket %s parallel PCI interrupts ok\n", 586 dev_printk(KERN_INFO, &socket->dev->dev,
586 pci_name(socket->dev)); 587 "TI: parallel PCI interrupts ok\n");
587 goto out; 588 goto out;
588 } 589 }
589 590
@@ -593,13 +594,13 @@ static void ti12xx_irqroute_func1(struct yenta_socket *socket)
593 if (pci_irq_status == -1) 594 if (pci_irq_status == -1)
594 goto out; 595 goto out;
595 } 596 }
596 597
597 /* still nothing: set INTRTIE */ 598 /* still nothing: set INTRTIE */
598 if (ti12xx_tie_interrupts(socket, &old_irq)) { 599 if (ti12xx_tie_interrupts(socket, &old_irq)) {
599 pci_irq_status = yenta_probe_cb_irq(socket); 600 pci_irq_status = yenta_probe_cb_irq(socket);
600 if (pci_irq_status == 1) { 601 if (pci_irq_status == 1) {
601 printk(KERN_INFO "Yenta TI: socket %s parallel PCI interrupts, tied ok\n", 602 dev_printk(KERN_INFO, &socket->dev->dev,
602 pci_name(socket->dev)); 603 "TI: parallel PCI interrupts, tied ok\n");
603 goto out; 604 goto out;
604 } 605 }
605 606
@@ -610,8 +611,8 @@ static void ti12xx_irqroute_func1(struct yenta_socket *socket)
610out: 611out:
611 if (pci_irq_status < 1) { 612 if (pci_irq_status < 1) {
612 socket->cb_irq = 0; 613 socket->cb_irq = 0;
613 printk(KERN_INFO "Yenta TI: socket %s no PCI interrupts. Fish. Please report.\n", 614 dev_printk(KERN_INFO, &socket->dev->dev,
614 pci_name(socket->dev)); 615 "TI: no PCI interrupts. Fish. Please report.\n");
615 } 616 }
616} 617}
617 618
@@ -815,11 +816,13 @@ static int ti12xx_override(struct yenta_socket *socket)
815 /* make sure that memory burst is active */ 816 /* make sure that memory burst is active */
816 val_orig = val = config_readl(socket, TI113X_SYSTEM_CONTROL); 817 val_orig = val = config_readl(socket, TI113X_SYSTEM_CONTROL);
817 if (disable_clkrun && PCI_FUNC(socket->dev->devfn) == 0) { 818 if (disable_clkrun && PCI_FUNC(socket->dev->devfn) == 0) {
818 printk(KERN_INFO "Yenta: Disabling CLKRUN feature\n"); 819 dev_printk(KERN_INFO, &socket->dev->dev,
820 "Disabling CLKRUN feature\n");
819 val |= TI113X_SCR_KEEPCLK; 821 val |= TI113X_SCR_KEEPCLK;
820 } 822 }
821 if (!(val & TI122X_SCR_MRBURSTUP)) { 823 if (!(val & TI122X_SCR_MRBURSTUP)) {
822 printk(KERN_INFO "Yenta: Enabling burst memory read transactions\n"); 824 dev_printk(KERN_INFO, &socket->dev->dev,
825 "Enabling burst memory read transactions\n");
823 val |= TI122X_SCR_MRBURSTUP; 826 val |= TI122X_SCR_MRBURSTUP;
824 } 827 }
825 if (val_orig != val) 828 if (val_orig != val)
@@ -830,10 +833,12 @@ static int ti12xx_override(struct yenta_socket *socket)
830 * CSC interrupts to PCI rather than INTVAL. 833 * CSC interrupts to PCI rather than INTVAL.
831 */ 834 */
832 val = config_readb(socket, TI1250_DIAGNOSTIC); 835 val = config_readb(socket, TI1250_DIAGNOSTIC);
833 printk(KERN_INFO "Yenta: Using %s to route CSC interrupts to PCI\n", 836 dev_printk(KERN_INFO, &socket->dev->dev,
834 (val & TI1250_DIAG_PCI_CSC) ? "CSCINT" : "INTVAL"); 837 "Using %s to route CSC interrupts to PCI\n",
835 printk(KERN_INFO "Yenta: Routing CardBus interrupts to %s\n", 838 (val & TI1250_DIAG_PCI_CSC) ? "CSCINT" : "INTVAL");
836 (val & TI1250_DIAG_PCI_IREQ) ? "PCI" : "ISA"); 839 dev_printk(KERN_INFO, &socket->dev->dev,
840 "Routing CardBus interrupts to %s\n",
841 (val & TI1250_DIAG_PCI_IREQ) ? "PCI" : "ISA");
837 842
838 /* do irqrouting, depending on function */ 843 /* do irqrouting, depending on function */
839 if (PCI_FUNC(socket->dev->devfn) == 0) 844 if (PCI_FUNC(socket->dev->devfn) == 0)
@@ -858,8 +863,9 @@ static int ti1250_override(struct yenta_socket *socket)
858 diag |= TI1250_DIAG_PCI_CSC | TI1250_DIAG_PCI_IREQ; 863 diag |= TI1250_DIAG_PCI_CSC | TI1250_DIAG_PCI_IREQ;
859 864
860 if (diag != old) { 865 if (diag != old) {
861 printk(KERN_INFO "Yenta: adjusting diagnostic: %02x -> %02x\n", 866 dev_printk(KERN_INFO, &socket->dev->dev,
862 old, diag); 867 "adjusting diagnostic: %02x -> %02x\n",
868 old, diag);
863 config_writeb(socket, TI1250_DIAGNOSTIC, diag); 869 config_writeb(socket, TI1250_DIAGNOSTIC, diag);
864 } 870 }
865 871
@@ -924,7 +930,9 @@ static void ene_tune_bridge(struct pcmcia_socket *sock, struct pci_bus *bus)
924 /* default to clear TLTEnable bit, old behaviour */ 930 /* default to clear TLTEnable bit, old behaviour */
925 test_c9 &= ~ENE_TEST_C9_TLTENABLE; 931 test_c9 &= ~ENE_TEST_C9_TLTENABLE;
926 932
927 printk(KERN_INFO "yenta EnE: chaning testregister 0xC9, %02x -> %02x\n", old_c9, test_c9); 933 dev_printk(KERN_INFO, &socket->dev->dev,
934 "EnE: chaning testregister 0xC9, %02x -> %02x\n",
935 old_c9, test_c9);
928 config_writeb(socket, ENE_TEST_C9, test_c9); 936 config_writeb(socket, ENE_TEST_C9, test_c9);
929} 937}
930 938
diff --git a/drivers/pcmcia/yenta_socket.c b/drivers/pcmcia/yenta_socket.c
index 0ab1fb65cdc3..3ecd7c99d8eb 100644
--- a/drivers/pcmcia/yenta_socket.c
+++ b/drivers/pcmcia/yenta_socket.c
@@ -38,11 +38,7 @@ static int pwr_irqs_off;
38module_param(pwr_irqs_off, bool, 0644); 38module_param(pwr_irqs_off, bool, 0644);
39MODULE_PARM_DESC(pwr_irqs_off, "Force IRQs off during power-on of slot. Use only when seeing IRQ storms!"); 39MODULE_PARM_DESC(pwr_irqs_off, "Force IRQs off during power-on of slot. Use only when seeing IRQ storms!");
40 40
41#if 0 41#define debug(x, s, args...) dev_dbg(&s->dev->dev, x, ##args)
42#define debug(x,args...) printk(KERN_DEBUG "%s: " x, __func__ , ##args)
43#else
44#define debug(x,args...)
45#endif
46 42
47/* Don't ask.. */ 43/* Don't ask.. */
48#define to_cycles(ns) ((ns)/120) 44#define to_cycles(ns) ((ns)/120)
@@ -69,13 +65,13 @@ MODULE_PARM_DESC (override_bios, "yenta ignore bios resource allocation");
69static inline u32 cb_readl(struct yenta_socket *socket, unsigned reg) 65static inline u32 cb_readl(struct yenta_socket *socket, unsigned reg)
70{ 66{
71 u32 val = readl(socket->base + reg); 67 u32 val = readl(socket->base + reg);
72 debug("%p %04x %08x\n", socket, reg, val); 68 debug("%04x %08x\n", socket, reg, val);
73 return val; 69 return val;
74} 70}
75 71
76static inline void cb_writel(struct yenta_socket *socket, unsigned reg, u32 val) 72static inline void cb_writel(struct yenta_socket *socket, unsigned reg, u32 val)
77{ 73{
78 debug("%p %04x %08x\n", socket, reg, val); 74 debug("%04x %08x\n", socket, reg, val);
79 writel(val, socket->base + reg); 75 writel(val, socket->base + reg);
80 readl(socket->base + reg); /* avoid problems with PCI write posting */ 76 readl(socket->base + reg); /* avoid problems with PCI write posting */
81} 77}
@@ -84,7 +80,7 @@ static inline u8 config_readb(struct yenta_socket *socket, unsigned offset)
84{ 80{
85 u8 val; 81 u8 val;
86 pci_read_config_byte(socket->dev, offset, &val); 82 pci_read_config_byte(socket->dev, offset, &val);
87 debug("%p %04x %02x\n", socket, offset, val); 83 debug("%04x %02x\n", socket, offset, val);
88 return val; 84 return val;
89} 85}
90 86
@@ -92,7 +88,7 @@ static inline u16 config_readw(struct yenta_socket *socket, unsigned offset)
92{ 88{
93 u16 val; 89 u16 val;
94 pci_read_config_word(socket->dev, offset, &val); 90 pci_read_config_word(socket->dev, offset, &val);
95 debug("%p %04x %04x\n", socket, offset, val); 91 debug("%04x %04x\n", socket, offset, val);
96 return val; 92 return val;
97} 93}
98 94
@@ -100,32 +96,32 @@ static inline u32 config_readl(struct yenta_socket *socket, unsigned offset)
100{ 96{
101 u32 val; 97 u32 val;
102 pci_read_config_dword(socket->dev, offset, &val); 98 pci_read_config_dword(socket->dev, offset, &val);
103 debug("%p %04x %08x\n", socket, offset, val); 99 debug("%04x %08x\n", socket, offset, val);
104 return val; 100 return val;
105} 101}
106 102
107static inline void config_writeb(struct yenta_socket *socket, unsigned offset, u8 val) 103static inline void config_writeb(struct yenta_socket *socket, unsigned offset, u8 val)
108{ 104{
109 debug("%p %04x %02x\n", socket, offset, val); 105 debug("%04x %02x\n", socket, offset, val);
110 pci_write_config_byte(socket->dev, offset, val); 106 pci_write_config_byte(socket->dev, offset, val);
111} 107}
112 108
113static inline void config_writew(struct yenta_socket *socket, unsigned offset, u16 val) 109static inline void config_writew(struct yenta_socket *socket, unsigned offset, u16 val)
114{ 110{
115 debug("%p %04x %04x\n", socket, offset, val); 111 debug("%04x %04x\n", socket, offset, val);
116 pci_write_config_word(socket->dev, offset, val); 112 pci_write_config_word(socket->dev, offset, val);
117} 113}
118 114
119static inline void config_writel(struct yenta_socket *socket, unsigned offset, u32 val) 115static inline void config_writel(struct yenta_socket *socket, unsigned offset, u32 val)
120{ 116{
121 debug("%p %04x %08x\n", socket, offset, val); 117 debug("%04x %08x\n", socket, offset, val);
122 pci_write_config_dword(socket->dev, offset, val); 118 pci_write_config_dword(socket->dev, offset, val);
123} 119}
124 120
125static inline u8 exca_readb(struct yenta_socket *socket, unsigned reg) 121static inline u8 exca_readb(struct yenta_socket *socket, unsigned reg)
126{ 122{
127 u8 val = readb(socket->base + 0x800 + reg); 123 u8 val = readb(socket->base + 0x800 + reg);
128 debug("%p %04x %02x\n", socket, reg, val); 124 debug("%04x %02x\n", socket, reg, val);
129 return val; 125 return val;
130} 126}
131 127
@@ -134,20 +130,20 @@ static inline u8 exca_readw(struct yenta_socket *socket, unsigned reg)
134 u16 val; 130 u16 val;
135 val = readb(socket->base + 0x800 + reg); 131 val = readb(socket->base + 0x800 + reg);
136 val |= readb(socket->base + 0x800 + reg + 1) << 8; 132 val |= readb(socket->base + 0x800 + reg + 1) << 8;
137 debug("%p %04x %04x\n", socket, reg, val); 133 debug("%04x %04x\n", socket, reg, val);
138 return val; 134 return val;
139} 135}
140 136
141static inline void exca_writeb(struct yenta_socket *socket, unsigned reg, u8 val) 137static inline void exca_writeb(struct yenta_socket *socket, unsigned reg, u8 val)
142{ 138{
143 debug("%p %04x %02x\n", socket, reg, val); 139 debug("%04x %02x\n", socket, reg, val);
144 writeb(val, socket->base + 0x800 + reg); 140 writeb(val, socket->base + 0x800 + reg);
145 readb(socket->base + 0x800 + reg); /* PCI write posting... */ 141 readb(socket->base + 0x800 + reg); /* PCI write posting... */
146} 142}
147 143
148static void exca_writew(struct yenta_socket *socket, unsigned reg, u16 val) 144static void exca_writew(struct yenta_socket *socket, unsigned reg, u16 val)
149{ 145{
150 debug("%p %04x %04x\n", socket, reg, val); 146 debug("%04x %04x\n", socket, reg, val);
151 writeb(val, socket->base + 0x800 + reg); 147 writeb(val, socket->base + 0x800 + reg);
152 writeb(val >> 8, socket->base + 0x800 + reg + 1); 148 writeb(val >> 8, socket->base + 0x800 + reg + 1);
153 149
@@ -207,7 +203,7 @@ static int yenta_get_status(struct pcmcia_socket *sock, unsigned int *value)
207 203
208 204
209 if (state & CB_CBCARD) { 205 if (state & CB_CBCARD) {
210 val |= SS_CARDBUS; 206 val |= SS_CARDBUS;
211 val |= (state & CB_CARDSTS) ? SS_STSCHG : 0; 207 val |= (state & CB_CARDSTS) ? SS_STSCHG : 0;
212 val |= (state & (CB_CDETECT1 | CB_CDETECT2)) ? 0 : SS_DETECT; 208 val |= (state & (CB_CDETECT1 | CB_CDETECT2)) ? 0 : SS_DETECT;
213 val |= (state & CB_PWRCYCLE) ? SS_POWERON | SS_READY : 0; 209 val |= (state & CB_PWRCYCLE) ? SS_POWERON | SS_READY : 0;
@@ -650,8 +646,10 @@ static int yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type
650 root = pci_find_parent_resource(socket->dev, res); 646 root = pci_find_parent_resource(socket->dev, res);
651 if (root && (request_resource(root, res) == 0)) 647 if (root && (request_resource(root, res) == 0))
652 return 0; 648 return 0;
653 printk(KERN_INFO "yenta %s: Preassigned resource %d busy or not available, reconfiguring...\n", 649 dev_printk(KERN_INFO, &socket->dev->dev,
654 pci_name(socket->dev), nr); 650 "Preassigned resource %d busy or not available, "
651 "reconfiguring...\n",
652 nr);
655 } 653 }
656 654
657 if (type & IORESOURCE_IO) { 655 if (type & IORESOURCE_IO) {
@@ -674,8 +672,9 @@ static int yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type
674 return 1; 672 return 1;
675 } 673 }
676 674
677 printk(KERN_INFO "yenta %s: no resource of type %x available, trying to continue...\n", 675 dev_printk(KERN_INFO, &socket->dev->dev,
678 pci_name(socket->dev), type); 676 "no resource of type %x available, trying to continue...\n",
677 type);
679 res->start = res->end = res->flags = 0; 678 res->start = res->end = res->flags = 0;
680 return 0; 679 return 0;
681} 680}
@@ -923,7 +922,8 @@ static int yenta_probe_cb_irq(struct yenta_socket *socket)
923 socket->probe_status = 0; 922 socket->probe_status = 0;
924 923
925 if (request_irq(socket->cb_irq, yenta_probe_handler, IRQF_SHARED, "yenta", socket)) { 924 if (request_irq(socket->cb_irq, yenta_probe_handler, IRQF_SHARED, "yenta", socket)) {
926 printk(KERN_WARNING "Yenta: request_irq() in yenta_probe_cb_irq() failed!\n"); 925 dev_printk(KERN_WARNING, &socket->dev->dev,
926 "request_irq() in yenta_probe_cb_irq() failed!\n");
927 return -1; 927 return -1;
928 } 928 }
929 929
@@ -960,8 +960,9 @@ static void yenta_get_socket_capabilities(struct yenta_socket *socket, u32 isa_i
960 else 960 else
961 socket->socket.irq_mask = 0; 961 socket->socket.irq_mask = 0;
962 962
963 printk(KERN_INFO "Yenta: ISA IRQ mask 0x%04x, PCI irq %d\n", 963 dev_printk(KERN_INFO, &socket->dev->dev,
964 socket->socket.irq_mask, socket->cb_irq); 964 "ISA IRQ mask 0x%04x, PCI irq %d\n",
965 socket->socket.irq_mask, socket->cb_irq);
965} 966}
966 967
967/* 968/*
@@ -1051,8 +1052,9 @@ static void yenta_fixup_parent_bridge(struct pci_bus *cardbus_bridge)
1051 1052
1052 /* Show that the wanted subordinate number is not possible: */ 1053 /* Show that the wanted subordinate number is not possible: */
1053 if (cardbus_bridge->subordinate > upper_limit) 1054 if (cardbus_bridge->subordinate > upper_limit)
1054 printk(KERN_WARNING "Yenta: Upper limit for fixing this " 1055 dev_printk(KERN_WARNING, &cardbus_bridge->dev,
1055 "bridge's parent bridge: #%02x\n", upper_limit); 1056 "Upper limit for fixing this "
1057 "bridge's parent bridge: #%02x\n", upper_limit);
1056 1058
1057 /* If we have room to increase the bridge's subordinate number, */ 1059 /* If we have room to increase the bridge's subordinate number, */
1058 if (bridge_to_fix->subordinate < upper_limit) { 1060 if (bridge_to_fix->subordinate < upper_limit) {
@@ -1061,10 +1063,11 @@ static void yenta_fixup_parent_bridge(struct pci_bus *cardbus_bridge)
1061 unsigned char subordinate_to_assign = 1063 unsigned char subordinate_to_assign =
1062 min(cardbus_bridge->subordinate, upper_limit); 1064 min(cardbus_bridge->subordinate, upper_limit);
1063 1065
1064 printk(KERN_INFO "Yenta: Raising subordinate bus# of parent " 1066 dev_printk(KERN_INFO, &bridge_to_fix->dev,
1065 "bus (#%02x) from #%02x to #%02x\n", 1067 "Raising subordinate bus# of parent "
1066 bridge_to_fix->number, 1068 "bus (#%02x) from #%02x to #%02x\n",
1067 bridge_to_fix->subordinate, subordinate_to_assign); 1069 bridge_to_fix->number,
1070 bridge_to_fix->subordinate, subordinate_to_assign);
1068 1071
1069 /* Save the new subordinate in the bus struct of the bridge */ 1072 /* Save the new subordinate in the bus struct of the bridge */
1070 bridge_to_fix->subordinate = subordinate_to_assign; 1073 bridge_to_fix->subordinate = subordinate_to_assign;
@@ -1091,8 +1094,8 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
1091 * Bail out if so. 1094 * Bail out if so.
1092 */ 1095 */
1093 if (!dev->subordinate) { 1096 if (!dev->subordinate) {
1094 printk(KERN_ERR "Yenta: no bus associated with %s! " 1097 dev_printk(KERN_ERR, &dev->dev, "no bus associated! "
1095 "(try 'pci=assign-busses')\n", pci_name(dev)); 1098 "(try 'pci=assign-busses')\n");
1096 return -ENODEV; 1099 return -ENODEV;
1097 } 1100 }
1098 1101
@@ -1127,7 +1130,7 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
1127 goto disable; 1130 goto disable;
1128 1131
1129 if (!pci_resource_start(dev, 0)) { 1132 if (!pci_resource_start(dev, 0)) {
1130 printk(KERN_ERR "No cardbus resource!\n"); 1133 dev_printk(KERN_ERR, &dev->dev, "No cardbus resource!\n");
1131 ret = -ENODEV; 1134 ret = -ENODEV;
1132 goto release; 1135 goto release;
1133 } 1136 }
@@ -1146,8 +1149,8 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
1146 * report the subsystem vendor and device for help debugging 1149 * report the subsystem vendor and device for help debugging
1147 * the irq stuff... 1150 * the irq stuff...
1148 */ 1151 */
1149 printk(KERN_INFO "Yenta: CardBus bridge found at %s [%04x:%04x]\n", 1152 dev_printk(KERN_INFO, &dev->dev, "CardBus bridge found [%04x:%04x]\n",
1150 pci_name(dev), dev->subsystem_vendor, dev->subsystem_device); 1153 dev->subsystem_vendor, dev->subsystem_device);
1151 1154
1152 yenta_config_init(socket); 1155 yenta_config_init(socket);
1153 1156
@@ -1179,8 +1182,12 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
1179 socket->poll_timer.data = (unsigned long)socket; 1182 socket->poll_timer.data = (unsigned long)socket;
1180 socket->poll_timer.expires = jiffies + HZ; 1183 socket->poll_timer.expires = jiffies + HZ;
1181 add_timer(&socket->poll_timer); 1184 add_timer(&socket->poll_timer);
1182 printk(KERN_INFO "Yenta: no PCI IRQ, CardBus support disabled for this socket.\n" 1185 dev_printk(KERN_INFO, &dev->dev,
1183 KERN_INFO "Yenta: check your BIOS CardBus, BIOS IRQ or ACPI settings.\n"); 1186 "no PCI IRQ, CardBus support disabled for this "
1187 "socket.\n");
1188 dev_printk(KERN_INFO, &dev->dev,
1189 "check your BIOS CardBus, BIOS IRQ or ACPI "
1190 "settings.\n");
1184 } else { 1191 } else {
1185 socket->socket.features |= SS_CAP_CARDBUS; 1192 socket->socket.features |= SS_CAP_CARDBUS;
1186 } 1193 }
@@ -1188,7 +1195,8 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
1188 /* Figure out what the dang thing can do for the PCMCIA layer... */ 1195 /* Figure out what the dang thing can do for the PCMCIA layer... */
1189 yenta_interrogate(socket); 1196 yenta_interrogate(socket);
1190 yenta_get_socket_capabilities(socket, isa_interrupts); 1197 yenta_get_socket_capabilities(socket, isa_interrupts);
1191 printk(KERN_INFO "Socket status: %08x\n", cb_readl(socket, CB_SOCKET_STATE)); 1198 dev_printk(KERN_INFO, &dev->dev,
1199 "Socket status: %08x\n", cb_readl(socket, CB_SOCKET_STATE));
1192 1200
1193 yenta_fixup_parent_bridge(dev->subordinate); 1201 yenta_fixup_parent_bridge(dev->subordinate);
1194 1202
diff --git a/drivers/pnp/base.h b/drivers/pnp/base.h
index 9fd7bb9b7dce..3b8b9d3cb03d 100644
--- a/drivers/pnp/base.h
+++ b/drivers/pnp/base.h
@@ -4,6 +4,7 @@
4 */ 4 */
5 5
6extern spinlock_t pnp_lock; 6extern spinlock_t pnp_lock;
7extern struct device_attribute pnp_interface_attrs[];
7void *pnp_alloc(long size); 8void *pnp_alloc(long size);
8 9
9int pnp_register_protocol(struct pnp_protocol *protocol); 10int pnp_register_protocol(struct pnp_protocol *protocol);
@@ -16,7 +17,6 @@ struct pnp_card *pnp_alloc_card(struct pnp_protocol *, int id, char *pnpid);
16 17
17int pnp_add_device(struct pnp_dev *dev); 18int pnp_add_device(struct pnp_dev *dev);
18struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id); 19struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
19int pnp_interface_attach_device(struct pnp_dev *dev);
20 20
21int pnp_add_card(struct pnp_card *card); 21int pnp_add_card(struct pnp_card *card);
22void pnp_remove_card(struct pnp_card *card); 22void pnp_remove_card(struct pnp_card *card);
@@ -147,7 +147,7 @@ char *pnp_resource_type_name(struct resource *res);
147void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc); 147void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc);
148 148
149void pnp_free_resources(struct pnp_dev *dev); 149void pnp_free_resources(struct pnp_dev *dev);
150int pnp_resource_type(struct resource *res); 150unsigned long pnp_resource_type(struct resource *res);
151 151
152struct pnp_resource { 152struct pnp_resource {
153 struct list_head list; 153 struct list_head list;
diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c
index a411582bcd72..817fe626e15b 100644
--- a/drivers/pnp/core.c
+++ b/drivers/pnp/core.c
@@ -159,21 +159,13 @@ struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid
159 159
160int __pnp_add_device(struct pnp_dev *dev) 160int __pnp_add_device(struct pnp_dev *dev)
161{ 161{
162 int ret;
163
164 pnp_fixup_device(dev); 162 pnp_fixup_device(dev);
165 dev->status = PNP_READY; 163 dev->status = PNP_READY;
166 spin_lock(&pnp_lock); 164 spin_lock(&pnp_lock);
167 list_add_tail(&dev->global_list, &pnp_global); 165 list_add_tail(&dev->global_list, &pnp_global);
168 list_add_tail(&dev->protocol_list, &dev->protocol->devices); 166 list_add_tail(&dev->protocol_list, &dev->protocol->devices);
169 spin_unlock(&pnp_lock); 167 spin_unlock(&pnp_lock);
170 168 return device_register(&dev->dev);
171 ret = device_register(&dev->dev);
172 if (ret)
173 return ret;
174
175 pnp_interface_attach_device(dev);
176 return 0;
177} 169}
178 170
179/* 171/*
@@ -218,7 +210,6 @@ void __pnp_remove_device(struct pnp_dev *dev)
218 210
219static int __init pnp_init(void) 211static int __init pnp_init(void)
220{ 212{
221 printk(KERN_INFO "Linux Plug and Play Support v0.97 (c) Adam Belay\n");
222 return bus_register(&pnp_bus_type); 213 return bus_register(&pnp_bus_type);
223} 214}
224 215
diff --git a/drivers/pnp/driver.c b/drivers/pnp/driver.c
index d3f869ee1d92..e3f7e89c4dfb 100644
--- a/drivers/pnp/driver.c
+++ b/drivers/pnp/driver.c
@@ -206,6 +206,7 @@ struct bus_type pnp_bus_type = {
206 .remove = pnp_device_remove, 206 .remove = pnp_device_remove,
207 .suspend = pnp_bus_suspend, 207 .suspend = pnp_bus_suspend,
208 .resume = pnp_bus_resume, 208 .resume = pnp_bus_resume,
209 .dev_attrs = pnp_interface_attrs,
209}; 210};
210 211
211int pnp_register_driver(struct pnp_driver *drv) 212int pnp_register_driver(struct pnp_driver *drv)
diff --git a/drivers/pnp/interface.c b/drivers/pnp/interface.c
index a876ecf7028c..478a4a739c00 100644
--- a/drivers/pnp/interface.c
+++ b/drivers/pnp/interface.c
@@ -243,8 +243,6 @@ static ssize_t pnp_show_options(struct device *dmdev,
243 return ret; 243 return ret;
244} 244}
245 245
246static DEVICE_ATTR(options, S_IRUGO, pnp_show_options, NULL);
247
248static ssize_t pnp_show_current_resources(struct device *dmdev, 246static ssize_t pnp_show_current_resources(struct device *dmdev,
249 struct device_attribute *attr, 247 struct device_attribute *attr,
250 char *buf) 248 char *buf)
@@ -420,9 +418,6 @@ done:
420 return count; 418 return count;
421} 419}
422 420
423static DEVICE_ATTR(resources, S_IRUGO | S_IWUSR,
424 pnp_show_current_resources, pnp_set_current_resources);
425
426static ssize_t pnp_show_current_ids(struct device *dmdev, 421static ssize_t pnp_show_current_ids(struct device *dmdev,
427 struct device_attribute *attr, char *buf) 422 struct device_attribute *attr, char *buf)
428{ 423{
@@ -437,27 +432,11 @@ static ssize_t pnp_show_current_ids(struct device *dmdev,
437 return (str - buf); 432 return (str - buf);
438} 433}
439 434
440static DEVICE_ATTR(id, S_IRUGO, pnp_show_current_ids, NULL); 435struct device_attribute pnp_interface_attrs[] = {
441 436 __ATTR(resources, S_IRUGO | S_IWUSR,
442int pnp_interface_attach_device(struct pnp_dev *dev) 437 pnp_show_current_resources,
443{ 438 pnp_set_current_resources),
444 int rc = device_create_file(&dev->dev, &dev_attr_options); 439 __ATTR(options, S_IRUGO, pnp_show_options, NULL),
445 440 __ATTR(id, S_IRUGO, pnp_show_current_ids, NULL),
446 if (rc) 441 __ATTR_NULL,
447 goto err; 442};
448 rc = device_create_file(&dev->dev, &dev_attr_resources);
449 if (rc)
450 goto err_opt;
451 rc = device_create_file(&dev->dev, &dev_attr_id);
452 if (rc)
453 goto err_res;
454
455 return 0;
456
457err_res:
458 device_remove_file(&dev->dev, &dev_attr_resources);
459err_opt:
460 device_remove_file(&dev->dev, &dev_attr_options);
461err:
462 return rc;
463}
diff --git a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c
index 101a835e8759..46455fbab6d5 100644
--- a/drivers/pnp/isapnp/core.c
+++ b/drivers/pnp/isapnp/core.c
@@ -1012,7 +1012,7 @@ static int __init isapnp_init(void)
1012 printk(KERN_INFO "isapnp: ISA Plug & Play support disabled\n"); 1012 printk(KERN_INFO "isapnp: ISA Plug & Play support disabled\n");
1013 return 0; 1013 return 0;
1014 } 1014 }
1015#ifdef CONFIG_PPC_MERGE 1015#ifdef CONFIG_PPC
1016 if (check_legacy_ioport(_PIDXR) || check_legacy_ioport(_PNPWRP)) 1016 if (check_legacy_ioport(_PIDXR) || check_legacy_ioport(_PNPWRP))
1017 return -EINVAL; 1017 return -EINVAL;
1018#endif 1018#endif
diff --git a/drivers/pnp/pnpbios/core.c b/drivers/pnp/pnpbios/core.c
index 662dfcddedc6..2bfe13369df5 100644
--- a/drivers/pnp/pnpbios/core.c
+++ b/drivers/pnp/pnpbios/core.c
@@ -519,7 +519,7 @@ static int __init pnpbios_init(void)
519{ 519{
520 int ret; 520 int ret;
521 521
522#if defined(CONFIG_PPC_MERGE) 522#if defined(CONFIG_PPC)
523 if (check_legacy_ioport(PNPBIOS_BASE)) 523 if (check_legacy_ioport(PNPBIOS_BASE))
524 return -ENODEV; 524 return -ENODEV;
525#endif 525#endif
@@ -577,7 +577,7 @@ static int __init pnpbios_thread_init(void)
577{ 577{
578 struct task_struct *task; 578 struct task_struct *task;
579 579
580#if defined(CONFIG_PPC_MERGE) 580#if defined(CONFIG_PPC)
581 if (check_legacy_ioport(PNPBIOS_BASE)) 581 if (check_legacy_ioport(PNPBIOS_BASE))
582 return 0; 582 return 0;
583#endif 583#endif
diff --git a/drivers/pnp/quirks.c b/drivers/pnp/quirks.c
index 0bdf9b8a5e58..c144bd575611 100644
--- a/drivers/pnp/quirks.c
+++ b/drivers/pnp/quirks.c
@@ -245,7 +245,7 @@ static void quirk_system_pci_resources(struct pnp_dev *dev)
245 */ 245 */
246 for_each_pci_dev(pdev) { 246 for_each_pci_dev(pdev) {
247 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { 247 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
248 unsigned int type; 248 unsigned long type;
249 249
250 type = pci_resource_flags(pdev, i) & 250 type = pci_resource_flags(pdev, i) &
251 (IORESOURCE_IO | IORESOURCE_MEM); 251 (IORESOURCE_IO | IORESOURCE_MEM);
@@ -338,8 +338,7 @@ void pnp_fixup_device(struct pnp_dev *dev)
338 if (!compare_pnp_id(dev->id, f->id)) 338 if (!compare_pnp_id(dev->id, f->id))
339 continue; 339 continue;
340#ifdef DEBUG 340#ifdef DEBUG
341 dev_dbg(&dev->dev, "%s: calling ", f->id); 341 dev_dbg(&dev->dev, "%s: calling %pF\n", f->id, f->quirk_function);
342 print_fn_descriptor_symbol("%s\n", f->quirk_function);
343#endif 342#endif
344 f->quirk_function(dev); 343 f->quirk_function(dev);
345 } 344 }
diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
index 4cfe3a1efdfb..dbae23acdd5b 100644
--- a/drivers/pnp/resource.c
+++ b/drivers/pnp/resource.c
@@ -467,14 +467,14 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
467#endif 467#endif
468} 468}
469 469
470int pnp_resource_type(struct resource *res) 470unsigned long pnp_resource_type(struct resource *res)
471{ 471{
472 return res->flags & (IORESOURCE_IO | IORESOURCE_MEM | 472 return res->flags & (IORESOURCE_IO | IORESOURCE_MEM |
473 IORESOURCE_IRQ | IORESOURCE_DMA); 473 IORESOURCE_IRQ | IORESOURCE_DMA);
474} 474}
475 475
476struct resource *pnp_get_resource(struct pnp_dev *dev, 476struct resource *pnp_get_resource(struct pnp_dev *dev,
477 unsigned int type, unsigned int num) 477 unsigned long type, unsigned int num)
478{ 478{
479 struct pnp_resource *pnp_res; 479 struct pnp_resource *pnp_res;
480 struct resource *res; 480 struct resource *res;
diff --git a/drivers/power/olpc_battery.c b/drivers/power/olpc_battery.c
index 32570af3c5c9..5fbca2681baa 100644
--- a/drivers/power/olpc_battery.c
+++ b/drivers/power/olpc_battery.c
@@ -205,9 +205,9 @@ static int olpc_bat_get_property(struct power_supply *psy,
205 union power_supply_propval *val) 205 union power_supply_propval *val)
206{ 206{
207 int ret = 0; 207 int ret = 0;
208 int16_t ec_word; 208 __be16 ec_word;
209 uint8_t ec_byte; 209 uint8_t ec_byte;
210 uint64_t ser_buf; 210 __be64 ser_buf;
211 211
212 ret = olpc_ec_cmd(EC_BAT_STATUS, NULL, 0, &ec_byte, 1); 212 ret = olpc_ec_cmd(EC_BAT_STATUS, NULL, 0, &ec_byte, 1);
213 if (ret) 213 if (ret)
@@ -257,16 +257,14 @@ static int olpc_bat_get_property(struct power_supply *psy,
257 if (ret) 257 if (ret)
258 return ret; 258 return ret;
259 259
260 ec_word = be16_to_cpu(ec_word); 260 val->intval = (int)be16_to_cpu(ec_word) * 9760L / 32;
261 val->intval = ec_word * 9760L / 32;
262 break; 261 break;
263 case POWER_SUPPLY_PROP_CURRENT_AVG: 262 case POWER_SUPPLY_PROP_CURRENT_AVG:
264 ret = olpc_ec_cmd(EC_BAT_CURRENT, NULL, 0, (void *)&ec_word, 2); 263 ret = olpc_ec_cmd(EC_BAT_CURRENT, NULL, 0, (void *)&ec_word, 2);
265 if (ret) 264 if (ret)
266 return ret; 265 return ret;
267 266
268 ec_word = be16_to_cpu(ec_word); 267 val->intval = (int)be16_to_cpu(ec_word) * 15625L / 120;
269 val->intval = ec_word * 15625L / 120;
270 break; 268 break;
271 case POWER_SUPPLY_PROP_CAPACITY: 269 case POWER_SUPPLY_PROP_CAPACITY:
272 ret = olpc_ec_cmd(EC_BAT_SOC, NULL, 0, &ec_byte, 1); 270 ret = olpc_ec_cmd(EC_BAT_SOC, NULL, 0, &ec_byte, 1);
@@ -278,24 +276,22 @@ static int olpc_bat_get_property(struct power_supply *psy,
278 ret = olpc_ec_cmd(EC_BAT_TEMP, NULL, 0, (void *)&ec_word, 2); 276 ret = olpc_ec_cmd(EC_BAT_TEMP, NULL, 0, (void *)&ec_word, 2);
279 if (ret) 277 if (ret)
280 return ret; 278 return ret;
281 ec_word = be16_to_cpu(ec_word); 279
282 val->intval = ec_word * 100 / 256; 280 val->intval = (int)be16_to_cpu(ec_word) * 100 / 256;
283 break; 281 break;
284 case POWER_SUPPLY_PROP_TEMP_AMBIENT: 282 case POWER_SUPPLY_PROP_TEMP_AMBIENT:
285 ret = olpc_ec_cmd(EC_AMB_TEMP, NULL, 0, (void *)&ec_word, 2); 283 ret = olpc_ec_cmd(EC_AMB_TEMP, NULL, 0, (void *)&ec_word, 2);
286 if (ret) 284 if (ret)
287 return ret; 285 return ret;
288 286
289 ec_word = be16_to_cpu(ec_word); 287 val->intval = (int)be16_to_cpu(ec_word) * 100 / 256;
290 val->intval = ec_word * 100 / 256;
291 break; 288 break;
292 case POWER_SUPPLY_PROP_CHARGE_COUNTER: 289 case POWER_SUPPLY_PROP_CHARGE_COUNTER:
293 ret = olpc_ec_cmd(EC_BAT_ACR, NULL, 0, (void *)&ec_word, 2); 290 ret = olpc_ec_cmd(EC_BAT_ACR, NULL, 0, (void *)&ec_word, 2);
294 if (ret) 291 if (ret)
295 return ret; 292 return ret;
296 293
297 ec_word = be16_to_cpu(ec_word); 294 val->intval = (int)be16_to_cpu(ec_word) * 6250 / 15;
298 val->intval = ec_word * 6250 / 15;
299 break; 295 break;
300 case POWER_SUPPLY_PROP_SERIAL_NUMBER: 296 case POWER_SUPPLY_PROP_SERIAL_NUMBER:
301 ret = olpc_ec_cmd(EC_BAT_SERIAL, NULL, 0, (void *)&ser_buf, 8); 297 ret = olpc_ec_cmd(EC_BAT_SERIAL, NULL, 0, (void *)&ser_buf, 8);
diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
index cb1ccb472921..3007695f90c8 100644
--- a/drivers/power/power_supply_core.c
+++ b/drivers/power/power_supply_core.c
@@ -91,8 +91,8 @@ int power_supply_register(struct device *parent, struct power_supply *psy)
91{ 91{
92 int rc = 0; 92 int rc = 0;
93 93
94 psy->dev = device_create_drvdata(power_supply_class, parent, 0, 94 psy->dev = device_create(power_supply_class, parent, 0, psy,
95 psy, "%s", psy->name); 95 "%s", psy->name);
96 if (IS_ERR(psy->dev)) { 96 if (IS_ERR(psy->dev)) {
97 rc = PTR_ERR(psy->dev); 97 rc = PTR_ERR(psy->dev);
98 goto dev_create_failed; 98 goto dev_create_failed;
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index a656128f1fdd..4dada6ee1119 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -56,4 +56,28 @@ config REGULATOR_BQ24022
56 charging select between 100 mA and 500 mA charging current 56 charging select between 100 mA and 500 mA charging current
57 limit. 57 limit.
58 58
59config REGULATOR_WM8350
60 tristate "Wolfson Microelectroncis WM8350 AudioPlus PMIC"
61 depends on MFD_WM8350
62 select REGULATOR
63 help
64 This driver provides support for the voltage and current regulators
65 of the WM8350 AudioPlus PMIC.
66
67config REGULATOR_WM8400
68 tristate "Wolfson Microelectroncis WM8400 AudioPlus PMIC"
69 depends on MFD_WM8400
70 select REGULATOR
71 help
72 This driver provides support for the voltage regulators of the
73 WM8400 AudioPlus PMIC.
74
75config REGULATOR_DA903X
76 tristate "Support regulators on Dialog Semiconductor DA9030/DA9034 PMIC"
77 depends on PMIC_DA903X
78 select REGULATOR
79 help
80 Say y here to support the BUCKs and LDOs regulators found on
81 Dialog Semiconductor DA9030/DA9034 PMIC.
82
59endmenu 83endmenu
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index ac2c64efe65c..254d40c02ee8 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -8,5 +8,8 @@ obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
8obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o 8obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
9 9
10obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o 10obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o
11obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o
12obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o
13obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
11 14
12ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG 15ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG
diff --git a/drivers/regulator/bq24022.c b/drivers/regulator/bq24022.c
index 263699d6152d..366565aba865 100644
--- a/drivers/regulator/bq24022.c
+++ b/drivers/regulator/bq24022.c
@@ -18,13 +18,13 @@
18#include <linux/regulator/bq24022.h> 18#include <linux/regulator/bq24022.h>
19#include <linux/regulator/driver.h> 19#include <linux/regulator/driver.h>
20 20
21
21static int bq24022_set_current_limit(struct regulator_dev *rdev, 22static int bq24022_set_current_limit(struct regulator_dev *rdev,
22 int min_uA, int max_uA) 23 int min_uA, int max_uA)
23{ 24{
24 struct platform_device *pdev = rdev_get_drvdata(rdev); 25 struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev);
25 struct bq24022_mach_info *pdata = pdev->dev.platform_data;
26 26
27 dev_dbg(&pdev->dev, "setting current limit to %s mA\n", 27 dev_dbg(rdev_get_dev(rdev), "setting current limit to %s mA\n",
28 max_uA >= 500000 ? "500" : "100"); 28 max_uA >= 500000 ? "500" : "100");
29 29
30 /* REVISIT: maybe return error if min_uA != 0 ? */ 30 /* REVISIT: maybe return error if min_uA != 0 ? */
@@ -34,18 +34,16 @@ static int bq24022_set_current_limit(struct regulator_dev *rdev,
34 34
35static int bq24022_get_current_limit(struct regulator_dev *rdev) 35static int bq24022_get_current_limit(struct regulator_dev *rdev)
36{ 36{
37 struct platform_device *pdev = rdev_get_drvdata(rdev); 37 struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev);
38 struct bq24022_mach_info *pdata = pdev->dev.platform_data;
39 38
40 return gpio_get_value(pdata->gpio_iset2) ? 500000 : 100000; 39 return gpio_get_value(pdata->gpio_iset2) ? 500000 : 100000;
41} 40}
42 41
43static int bq24022_enable(struct regulator_dev *rdev) 42static int bq24022_enable(struct regulator_dev *rdev)
44{ 43{
45 struct platform_device *pdev = rdev_get_drvdata(rdev); 44 struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev);
46 struct bq24022_mach_info *pdata = pdev->dev.platform_data;
47 45
48 dev_dbg(&pdev->dev, "enabling charger\n"); 46 dev_dbg(rdev_get_dev(rdev), "enabling charger\n");
49 47
50 gpio_set_value(pdata->gpio_nce, 0); 48 gpio_set_value(pdata->gpio_nce, 0);
51 return 0; 49 return 0;
@@ -53,10 +51,9 @@ static int bq24022_enable(struct regulator_dev *rdev)
53 51
54static int bq24022_disable(struct regulator_dev *rdev) 52static int bq24022_disable(struct regulator_dev *rdev)
55{ 53{
56 struct platform_device *pdev = rdev_get_drvdata(rdev); 54 struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev);
57 struct bq24022_mach_info *pdata = pdev->dev.platform_data;
58 55
59 dev_dbg(&pdev->dev, "disabling charger\n"); 56 dev_dbg(rdev_get_dev(rdev), "disabling charger\n");
60 57
61 gpio_set_value(pdata->gpio_nce, 1); 58 gpio_set_value(pdata->gpio_nce, 1);
62 return 0; 59 return 0;
@@ -108,7 +105,7 @@ static int __init bq24022_probe(struct platform_device *pdev)
108 ret = gpio_direction_output(pdata->gpio_iset2, 0); 105 ret = gpio_direction_output(pdata->gpio_iset2, 0);
109 ret = gpio_direction_output(pdata->gpio_nce, 1); 106 ret = gpio_direction_output(pdata->gpio_nce, 1);
110 107
111 bq24022 = regulator_register(&bq24022_desc, pdev); 108 bq24022 = regulator_register(&bq24022_desc, &pdev->dev, pdata);
112 if (IS_ERR(bq24022)) { 109 if (IS_ERR(bq24022)) {
113 dev_dbg(&pdev->dev, "couldn't register regulator\n"); 110 dev_dbg(&pdev->dev, "couldn't register regulator\n");
114 ret = PTR_ERR(bq24022); 111 ret = PTR_ERR(bq24022);
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 9c7986261568..02a774424e8d 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2,8 +2,9 @@
2 * core.c -- Voltage/Current Regulator framework. 2 * core.c -- Voltage/Current Regulator framework.
3 * 3 *
4 * Copyright 2007, 2008 Wolfson Microelectronics PLC. 4 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
5 * Copyright 2008 SlimLogic Ltd.
5 * 6 *
6 * Author: Liam Girdwood <liam.girdwood@wolfsonmicro.com> 7 * Author: Liam Girdwood <lrg@slimlogic.co.uk>
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify it 9 * 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 * under the terms of the GNU General Public License as published by the
@@ -64,14 +65,9 @@ struct regulator_map {
64 struct list_head list; 65 struct list_head list;
65 struct device *dev; 66 struct device *dev;
66 const char *supply; 67 const char *supply;
67 const char *regulator; 68 struct regulator_dev *regulator;
68}; 69};
69 70
70static inline struct regulator_dev *to_rdev(struct device *d)
71{
72 return container_of(d, struct regulator_dev, dev);
73}
74
75/* 71/*
76 * struct regulator 72 * struct regulator
77 * 73 *
@@ -227,7 +223,7 @@ static ssize_t device_requested_uA_show(struct device *dev,
227static ssize_t regulator_uV_show(struct device *dev, 223static ssize_t regulator_uV_show(struct device *dev,
228 struct device_attribute *attr, char *buf) 224 struct device_attribute *attr, char *buf)
229{ 225{
230 struct regulator_dev *rdev = to_rdev(dev); 226 struct regulator_dev *rdev = dev_get_drvdata(dev);
231 ssize_t ret; 227 ssize_t ret;
232 228
233 mutex_lock(&rdev->mutex); 229 mutex_lock(&rdev->mutex);
@@ -240,15 +236,31 @@ static ssize_t regulator_uV_show(struct device *dev,
240static ssize_t regulator_uA_show(struct device *dev, 236static ssize_t regulator_uA_show(struct device *dev,
241 struct device_attribute *attr, char *buf) 237 struct device_attribute *attr, char *buf)
242{ 238{
243 struct regulator_dev *rdev = to_rdev(dev); 239 struct regulator_dev *rdev = dev_get_drvdata(dev);
244 240
245 return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev)); 241 return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev));
246} 242}
247 243
244static ssize_t regulator_name_show(struct device *dev,
245 struct device_attribute *attr, char *buf)
246{
247 struct regulator_dev *rdev = dev_get_drvdata(dev);
248 const char *name;
249
250 if (rdev->constraints->name)
251 name = rdev->constraints->name;
252 else if (rdev->desc->name)
253 name = rdev->desc->name;
254 else
255 name = "";
256
257 return sprintf(buf, "%s\n", name);
258}
259
248static ssize_t regulator_opmode_show(struct device *dev, 260static ssize_t regulator_opmode_show(struct device *dev,
249 struct device_attribute *attr, char *buf) 261 struct device_attribute *attr, char *buf)
250{ 262{
251 struct regulator_dev *rdev = to_rdev(dev); 263 struct regulator_dev *rdev = dev_get_drvdata(dev);
252 int mode = _regulator_get_mode(rdev); 264 int mode = _regulator_get_mode(rdev);
253 265
254 switch (mode) { 266 switch (mode) {
@@ -267,7 +279,7 @@ static ssize_t regulator_opmode_show(struct device *dev,
267static ssize_t regulator_state_show(struct device *dev, 279static ssize_t regulator_state_show(struct device *dev,
268 struct device_attribute *attr, char *buf) 280 struct device_attribute *attr, char *buf)
269{ 281{
270 struct regulator_dev *rdev = to_rdev(dev); 282 struct regulator_dev *rdev = dev_get_drvdata(dev);
271 int state = _regulator_is_enabled(rdev); 283 int state = _regulator_is_enabled(rdev);
272 284
273 if (state > 0) 285 if (state > 0)
@@ -281,7 +293,7 @@ static ssize_t regulator_state_show(struct device *dev,
281static ssize_t regulator_min_uA_show(struct device *dev, 293static ssize_t regulator_min_uA_show(struct device *dev,
282 struct device_attribute *attr, char *buf) 294 struct device_attribute *attr, char *buf)
283{ 295{
284 struct regulator_dev *rdev = to_rdev(dev); 296 struct regulator_dev *rdev = dev_get_drvdata(dev);
285 297
286 if (!rdev->constraints) 298 if (!rdev->constraints)
287 return sprintf(buf, "constraint not defined\n"); 299 return sprintf(buf, "constraint not defined\n");
@@ -292,7 +304,7 @@ static ssize_t regulator_min_uA_show(struct device *dev,
292static ssize_t regulator_max_uA_show(struct device *dev, 304static ssize_t regulator_max_uA_show(struct device *dev,
293 struct device_attribute *attr, char *buf) 305 struct device_attribute *attr, char *buf)
294{ 306{
295 struct regulator_dev *rdev = to_rdev(dev); 307 struct regulator_dev *rdev = dev_get_drvdata(dev);
296 308
297 if (!rdev->constraints) 309 if (!rdev->constraints)
298 return sprintf(buf, "constraint not defined\n"); 310 return sprintf(buf, "constraint not defined\n");
@@ -303,7 +315,7 @@ static ssize_t regulator_max_uA_show(struct device *dev,
303static ssize_t regulator_min_uV_show(struct device *dev, 315static ssize_t regulator_min_uV_show(struct device *dev,
304 struct device_attribute *attr, char *buf) 316 struct device_attribute *attr, char *buf)
305{ 317{
306 struct regulator_dev *rdev = to_rdev(dev); 318 struct regulator_dev *rdev = dev_get_drvdata(dev);
307 319
308 if (!rdev->constraints) 320 if (!rdev->constraints)
309 return sprintf(buf, "constraint not defined\n"); 321 return sprintf(buf, "constraint not defined\n");
@@ -314,7 +326,7 @@ static ssize_t regulator_min_uV_show(struct device *dev,
314static ssize_t regulator_max_uV_show(struct device *dev, 326static ssize_t regulator_max_uV_show(struct device *dev,
315 struct device_attribute *attr, char *buf) 327 struct device_attribute *attr, char *buf)
316{ 328{
317 struct regulator_dev *rdev = to_rdev(dev); 329 struct regulator_dev *rdev = dev_get_drvdata(dev);
318 330
319 if (!rdev->constraints) 331 if (!rdev->constraints)
320 return sprintf(buf, "constraint not defined\n"); 332 return sprintf(buf, "constraint not defined\n");
@@ -325,7 +337,7 @@ static ssize_t regulator_max_uV_show(struct device *dev,
325static ssize_t regulator_total_uA_show(struct device *dev, 337static ssize_t regulator_total_uA_show(struct device *dev,
326 struct device_attribute *attr, char *buf) 338 struct device_attribute *attr, char *buf)
327{ 339{
328 struct regulator_dev *rdev = to_rdev(dev); 340 struct regulator_dev *rdev = dev_get_drvdata(dev);
329 struct regulator *regulator; 341 struct regulator *regulator;
330 int uA = 0; 342 int uA = 0;
331 343
@@ -339,14 +351,14 @@ static ssize_t regulator_total_uA_show(struct device *dev,
339static ssize_t regulator_num_users_show(struct device *dev, 351static ssize_t regulator_num_users_show(struct device *dev,
340 struct device_attribute *attr, char *buf) 352 struct device_attribute *attr, char *buf)
341{ 353{
342 struct regulator_dev *rdev = to_rdev(dev); 354 struct regulator_dev *rdev = dev_get_drvdata(dev);
343 return sprintf(buf, "%d\n", rdev->use_count); 355 return sprintf(buf, "%d\n", rdev->use_count);
344} 356}
345 357
346static ssize_t regulator_type_show(struct device *dev, 358static ssize_t regulator_type_show(struct device *dev,
347 struct device_attribute *attr, char *buf) 359 struct device_attribute *attr, char *buf)
348{ 360{
349 struct regulator_dev *rdev = to_rdev(dev); 361 struct regulator_dev *rdev = dev_get_drvdata(dev);
350 362
351 switch (rdev->desc->type) { 363 switch (rdev->desc->type) {
352 case REGULATOR_VOLTAGE: 364 case REGULATOR_VOLTAGE:
@@ -360,7 +372,7 @@ static ssize_t regulator_type_show(struct device *dev,
360static ssize_t regulator_suspend_mem_uV_show(struct device *dev, 372static ssize_t regulator_suspend_mem_uV_show(struct device *dev,
361 struct device_attribute *attr, char *buf) 373 struct device_attribute *attr, char *buf)
362{ 374{
363 struct regulator_dev *rdev = to_rdev(dev); 375 struct regulator_dev *rdev = dev_get_drvdata(dev);
364 376
365 if (!rdev->constraints) 377 if (!rdev->constraints)
366 return sprintf(buf, "not defined\n"); 378 return sprintf(buf, "not defined\n");
@@ -370,7 +382,7 @@ static ssize_t regulator_suspend_mem_uV_show(struct device *dev,
370static ssize_t regulator_suspend_disk_uV_show(struct device *dev, 382static ssize_t regulator_suspend_disk_uV_show(struct device *dev,
371 struct device_attribute *attr, char *buf) 383 struct device_attribute *attr, char *buf)
372{ 384{
373 struct regulator_dev *rdev = to_rdev(dev); 385 struct regulator_dev *rdev = dev_get_drvdata(dev);
374 386
375 if (!rdev->constraints) 387 if (!rdev->constraints)
376 return sprintf(buf, "not defined\n"); 388 return sprintf(buf, "not defined\n");
@@ -380,7 +392,7 @@ static ssize_t regulator_suspend_disk_uV_show(struct device *dev,
380static ssize_t regulator_suspend_standby_uV_show(struct device *dev, 392static ssize_t regulator_suspend_standby_uV_show(struct device *dev,
381 struct device_attribute *attr, char *buf) 393 struct device_attribute *attr, char *buf)
382{ 394{
383 struct regulator_dev *rdev = to_rdev(dev); 395 struct regulator_dev *rdev = dev_get_drvdata(dev);
384 396
385 if (!rdev->constraints) 397 if (!rdev->constraints)
386 return sprintf(buf, "not defined\n"); 398 return sprintf(buf, "not defined\n");
@@ -406,7 +418,7 @@ static ssize_t suspend_opmode_show(struct regulator_dev *rdev,
406static ssize_t regulator_suspend_mem_mode_show(struct device *dev, 418static ssize_t regulator_suspend_mem_mode_show(struct device *dev,
407 struct device_attribute *attr, char *buf) 419 struct device_attribute *attr, char *buf)
408{ 420{
409 struct regulator_dev *rdev = to_rdev(dev); 421 struct regulator_dev *rdev = dev_get_drvdata(dev);
410 422
411 if (!rdev->constraints) 423 if (!rdev->constraints)
412 return sprintf(buf, "not defined\n"); 424 return sprintf(buf, "not defined\n");
@@ -417,7 +429,7 @@ static ssize_t regulator_suspend_mem_mode_show(struct device *dev,
417static ssize_t regulator_suspend_disk_mode_show(struct device *dev, 429static ssize_t regulator_suspend_disk_mode_show(struct device *dev,
418 struct device_attribute *attr, char *buf) 430 struct device_attribute *attr, char *buf)
419{ 431{
420 struct regulator_dev *rdev = to_rdev(dev); 432 struct regulator_dev *rdev = dev_get_drvdata(dev);
421 433
422 if (!rdev->constraints) 434 if (!rdev->constraints)
423 return sprintf(buf, "not defined\n"); 435 return sprintf(buf, "not defined\n");
@@ -428,7 +440,7 @@ static ssize_t regulator_suspend_disk_mode_show(struct device *dev,
428static ssize_t regulator_suspend_standby_mode_show(struct device *dev, 440static ssize_t regulator_suspend_standby_mode_show(struct device *dev,
429 struct device_attribute *attr, char *buf) 441 struct device_attribute *attr, char *buf)
430{ 442{
431 struct regulator_dev *rdev = to_rdev(dev); 443 struct regulator_dev *rdev = dev_get_drvdata(dev);
432 444
433 if (!rdev->constraints) 445 if (!rdev->constraints)
434 return sprintf(buf, "not defined\n"); 446 return sprintf(buf, "not defined\n");
@@ -439,7 +451,7 @@ static ssize_t regulator_suspend_standby_mode_show(struct device *dev,
439static ssize_t regulator_suspend_mem_state_show(struct device *dev, 451static ssize_t regulator_suspend_mem_state_show(struct device *dev,
440 struct device_attribute *attr, char *buf) 452 struct device_attribute *attr, char *buf)
441{ 453{
442 struct regulator_dev *rdev = to_rdev(dev); 454 struct regulator_dev *rdev = dev_get_drvdata(dev);
443 455
444 if (!rdev->constraints) 456 if (!rdev->constraints)
445 return sprintf(buf, "not defined\n"); 457 return sprintf(buf, "not defined\n");
@@ -453,7 +465,7 @@ static ssize_t regulator_suspend_mem_state_show(struct device *dev,
453static ssize_t regulator_suspend_disk_state_show(struct device *dev, 465static ssize_t regulator_suspend_disk_state_show(struct device *dev,
454 struct device_attribute *attr, char *buf) 466 struct device_attribute *attr, char *buf)
455{ 467{
456 struct regulator_dev *rdev = to_rdev(dev); 468 struct regulator_dev *rdev = dev_get_drvdata(dev);
457 469
458 if (!rdev->constraints) 470 if (!rdev->constraints)
459 return sprintf(buf, "not defined\n"); 471 return sprintf(buf, "not defined\n");
@@ -467,7 +479,7 @@ static ssize_t regulator_suspend_disk_state_show(struct device *dev,
467static ssize_t regulator_suspend_standby_state_show(struct device *dev, 479static ssize_t regulator_suspend_standby_state_show(struct device *dev,
468 struct device_attribute *attr, char *buf) 480 struct device_attribute *attr, char *buf)
469{ 481{
470 struct regulator_dev *rdev = to_rdev(dev); 482 struct regulator_dev *rdev = dev_get_drvdata(dev);
471 483
472 if (!rdev->constraints) 484 if (!rdev->constraints)
473 return sprintf(buf, "not defined\n"); 485 return sprintf(buf, "not defined\n");
@@ -477,7 +489,9 @@ static ssize_t regulator_suspend_standby_state_show(struct device *dev,
477 else 489 else
478 return sprintf(buf, "disabled\n"); 490 return sprintf(buf, "disabled\n");
479} 491}
492
480static struct device_attribute regulator_dev_attrs[] = { 493static struct device_attribute regulator_dev_attrs[] = {
494 __ATTR(name, 0444, regulator_name_show, NULL),
481 __ATTR(microvolts, 0444, regulator_uV_show, NULL), 495 __ATTR(microvolts, 0444, regulator_uV_show, NULL),
482 __ATTR(microamps, 0444, regulator_uA_show, NULL), 496 __ATTR(microamps, 0444, regulator_uA_show, NULL),
483 __ATTR(opmode, 0444, regulator_opmode_show, NULL), 497 __ATTR(opmode, 0444, regulator_opmode_show, NULL),
@@ -512,7 +526,7 @@ static struct device_attribute regulator_dev_attrs[] = {
512 526
513static void regulator_dev_release(struct device *dev) 527static void regulator_dev_release(struct device *dev)
514{ 528{
515 struct regulator_dev *rdev = to_rdev(dev); 529 struct regulator_dev *rdev = dev_get_drvdata(dev);
516 kfree(rdev); 530 kfree(rdev);
517} 531}
518 532
@@ -569,8 +583,11 @@ static int suspend_set_state(struct regulator_dev *rdev,
569 583
570 /* enable & disable are mandatory for suspend control */ 584 /* enable & disable are mandatory for suspend control */
571 if (!rdev->desc->ops->set_suspend_enable || 585 if (!rdev->desc->ops->set_suspend_enable ||
572 !rdev->desc->ops->set_suspend_disable) 586 !rdev->desc->ops->set_suspend_disable) {
587 printk(KERN_ERR "%s: no way to set suspend state\n",
588 __func__);
573 return -EINVAL; 589 return -EINVAL;
590 }
574 591
575 if (rstate->enabled) 592 if (rstate->enabled)
576 ret = rdev->desc->ops->set_suspend_enable(rdev); 593 ret = rdev->desc->ops->set_suspend_enable(rdev);
@@ -656,6 +673,155 @@ static void print_constraints(struct regulator_dev *rdev)
656 printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf); 673 printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf);
657} 674}
658 675
676/**
677 * set_machine_constraints - sets regulator constraints
678 * @regulator: regulator source
679 *
680 * Allows platform initialisation code to define and constrain
681 * regulator circuits e.g. valid voltage/current ranges, etc. NOTE:
682 * Constraints *must* be set by platform code in order for some
683 * regulator operations to proceed i.e. set_voltage, set_current_limit,
684 * set_mode.
685 */
686static int set_machine_constraints(struct regulator_dev *rdev,
687 struct regulation_constraints *constraints)
688{
689 int ret = 0;
690 const char *name;
691 struct regulator_ops *ops = rdev->desc->ops;
692
693 if (constraints->name)
694 name = constraints->name;
695 else if (rdev->desc->name)
696 name = rdev->desc->name;
697 else
698 name = "regulator";
699
700 rdev->constraints = constraints;
701
702 /* do we need to apply the constraint voltage */
703 if (rdev->constraints->apply_uV &&
704 rdev->constraints->min_uV == rdev->constraints->max_uV &&
705 ops->set_voltage) {
706 ret = ops->set_voltage(rdev,
707 rdev->constraints->min_uV, rdev->constraints->max_uV);
708 if (ret < 0) {
709 printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n",
710 __func__,
711 rdev->constraints->min_uV, name);
712 rdev->constraints = NULL;
713 goto out;
714 }
715 }
716
717 /* are we enabled at boot time by firmware / bootloader */
718 if (rdev->constraints->boot_on)
719 rdev->use_count = 1;
720
721 /* do we need to setup our suspend state */
722 if (constraints->initial_state) {
723 ret = suspend_prepare(rdev, constraints->initial_state);
724 if (ret < 0) {
725 printk(KERN_ERR "%s: failed to set suspend state for %s\n",
726 __func__, name);
727 rdev->constraints = NULL;
728 goto out;
729 }
730 }
731
732 /* if always_on is set then turn the regulator on if it's not
733 * already on. */
734 if (constraints->always_on && ops->enable &&
735 ((ops->is_enabled && !ops->is_enabled(rdev)) ||
736 (!ops->is_enabled && !constraints->boot_on))) {
737 ret = ops->enable(rdev);
738 if (ret < 0) {
739 printk(KERN_ERR "%s: failed to enable %s\n",
740 __func__, name);
741 rdev->constraints = NULL;
742 goto out;
743 }
744 }
745
746 print_constraints(rdev);
747out:
748 return ret;
749}
750
751/**
752 * set_supply - set regulator supply regulator
753 * @regulator: regulator name
754 * @supply: supply regulator name
755 *
756 * Called by platform initialisation code to set the supply regulator for this
757 * regulator. This ensures that a regulators supply will also be enabled by the
758 * core if it's child is enabled.
759 */
760static int set_supply(struct regulator_dev *rdev,
761 struct regulator_dev *supply_rdev)
762{
763 int err;
764
765 err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj,
766 "supply");
767 if (err) {
768 printk(KERN_ERR
769 "%s: could not add device link %s err %d\n",
770 __func__, supply_rdev->dev.kobj.name, err);
771 goto out;
772 }
773 rdev->supply = supply_rdev;
774 list_add(&rdev->slist, &supply_rdev->supply_list);
775out:
776 return err;
777}
778
779/**
780 * set_consumer_device_supply: Bind a regulator to a symbolic supply
781 * @regulator: regulator source
782 * @dev: device the supply applies to
783 * @supply: symbolic name for supply
784 *
785 * Allows platform initialisation code to map physical regulator
786 * sources to symbolic names for supplies for use by devices. Devices
787 * should use these symbolic names to request regulators, avoiding the
788 * need to provide board-specific regulator names as platform data.
789 */
790static int set_consumer_device_supply(struct regulator_dev *rdev,
791 struct device *consumer_dev, const char *supply)
792{
793 struct regulator_map *node;
794
795 if (supply == NULL)
796 return -EINVAL;
797
798 node = kmalloc(sizeof(struct regulator_map), GFP_KERNEL);
799 if (node == NULL)
800 return -ENOMEM;
801
802 node->regulator = rdev;
803 node->dev = consumer_dev;
804 node->supply = supply;
805
806 list_add(&node->list, &regulator_map_list);
807 return 0;
808}
809
810static void unset_consumer_device_supply(struct regulator_dev *rdev,
811 struct device *consumer_dev)
812{
813 struct regulator_map *node, *n;
814
815 list_for_each_entry_safe(node, n, &regulator_map_list, list) {
816 if (rdev == node->regulator &&
817 consumer_dev == node->dev) {
818 list_del(&node->list);
819 kfree(node);
820 return;
821 }
822 }
823}
824
659#define REG_STR_SIZE 32 825#define REG_STR_SIZE 32
660 826
661static struct regulator *create_regulator(struct regulator_dev *rdev, 827static struct regulator *create_regulator(struct regulator_dev *rdev,
@@ -746,7 +912,6 @@ struct regulator *regulator_get(struct device *dev, const char *id)
746 struct regulator_dev *rdev; 912 struct regulator_dev *rdev;
747 struct regulator_map *map; 913 struct regulator_map *map;
748 struct regulator *regulator = ERR_PTR(-ENODEV); 914 struct regulator *regulator = ERR_PTR(-ENODEV);
749 const char *supply = id;
750 915
751 if (id == NULL) { 916 if (id == NULL) {
752 printk(KERN_ERR "regulator: get() with no identifier\n"); 917 printk(KERN_ERR "regulator: get() with no identifier\n");
@@ -758,15 +923,9 @@ struct regulator *regulator_get(struct device *dev, const char *id)
758 list_for_each_entry(map, &regulator_map_list, list) { 923 list_for_each_entry(map, &regulator_map_list, list) {
759 if (dev == map->dev && 924 if (dev == map->dev &&
760 strcmp(map->supply, id) == 0) { 925 strcmp(map->supply, id) == 0) {
761 supply = map->regulator; 926 rdev = map->regulator;
762 break;
763 }
764 }
765
766 list_for_each_entry(rdev, &regulator_list, list) {
767 if (strcmp(supply, rdev->desc->name) == 0 &&
768 try_module_get(rdev->owner))
769 goto found; 927 goto found;
928 }
770 } 929 }
771 printk(KERN_ERR "regulator: Unable to get requested regulator: %s\n", 930 printk(KERN_ERR "regulator: Unable to get requested regulator: %s\n",
772 id); 931 id);
@@ -774,12 +933,16 @@ struct regulator *regulator_get(struct device *dev, const char *id)
774 return regulator; 933 return regulator;
775 934
776found: 935found:
936 if (!try_module_get(rdev->owner))
937 goto out;
938
777 regulator = create_regulator(rdev, dev, id); 939 regulator = create_regulator(rdev, dev, id);
778 if (regulator == NULL) { 940 if (regulator == NULL) {
779 regulator = ERR_PTR(-ENOMEM); 941 regulator = ERR_PTR(-ENOMEM);
780 module_put(rdev->owner); 942 module_put(rdev->owner);
781 } 943 }
782 944
945out:
783 mutex_unlock(&regulator_list_mutex); 946 mutex_unlock(&regulator_list_mutex);
784 return regulator; 947 return regulator;
785} 948}
@@ -1559,11 +1722,12 @@ EXPORT_SYMBOL_GPL(regulator_notifier_call_chain);
1559 * Returns 0 on success. 1722 * Returns 0 on success.
1560 */ 1723 */
1561struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, 1724struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
1562 void *reg_data) 1725 struct device *dev, void *driver_data)
1563{ 1726{
1564 static atomic_t regulator_no = ATOMIC_INIT(0); 1727 static atomic_t regulator_no = ATOMIC_INIT(0);
1565 struct regulator_dev *rdev; 1728 struct regulator_dev *rdev;
1566 int ret; 1729 struct regulator_init_data *init_data = dev->platform_data;
1730 int ret, i;
1567 1731
1568 if (regulator_desc == NULL) 1732 if (regulator_desc == NULL)
1569 return ERR_PTR(-EINVAL); 1733 return ERR_PTR(-EINVAL);
@@ -1575,6 +1739,9 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
1575 !regulator_desc->type == REGULATOR_CURRENT) 1739 !regulator_desc->type == REGULATOR_CURRENT)
1576 return ERR_PTR(-EINVAL); 1740 return ERR_PTR(-EINVAL);
1577 1741
1742 if (!init_data)
1743 return ERR_PTR(-EINVAL);
1744
1578 rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL); 1745 rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
1579 if (rdev == NULL) 1746 if (rdev == NULL)
1580 return ERR_PTR(-ENOMEM); 1747 return ERR_PTR(-ENOMEM);
@@ -1582,7 +1749,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
1582 mutex_lock(&regulator_list_mutex); 1749 mutex_lock(&regulator_list_mutex);
1583 1750
1584 mutex_init(&rdev->mutex); 1751 mutex_init(&rdev->mutex);
1585 rdev->reg_data = reg_data; 1752 rdev->reg_data = driver_data;
1586 rdev->owner = regulator_desc->owner; 1753 rdev->owner = regulator_desc->owner;
1587 rdev->desc = regulator_desc; 1754 rdev->desc = regulator_desc;
1588 INIT_LIST_HEAD(&rdev->consumer_list); 1755 INIT_LIST_HEAD(&rdev->consumer_list);
@@ -1591,20 +1758,68 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
1591 INIT_LIST_HEAD(&rdev->slist); 1758 INIT_LIST_HEAD(&rdev->slist);
1592 BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier); 1759 BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier);
1593 1760
1761 /* preform any regulator specific init */
1762 if (init_data->regulator_init) {
1763 ret = init_data->regulator_init(rdev->reg_data);
1764 if (ret < 0) {
1765 kfree(rdev);
1766 rdev = ERR_PTR(ret);
1767 goto out;
1768 }
1769 }
1770
1771 /* set regulator constraints */
1772 ret = set_machine_constraints(rdev, &init_data->constraints);
1773 if (ret < 0) {
1774 kfree(rdev);
1775 rdev = ERR_PTR(ret);
1776 goto out;
1777 }
1778
1779 /* register with sysfs */
1594 rdev->dev.class = &regulator_class; 1780 rdev->dev.class = &regulator_class;
1595 device_initialize(&rdev->dev); 1781 rdev->dev.parent = dev;
1596 snprintf(rdev->dev.bus_id, sizeof(rdev->dev.bus_id), 1782 snprintf(rdev->dev.bus_id, sizeof(rdev->dev.bus_id),
1597 "regulator_%ld_%s", 1783 "regulator.%d", atomic_inc_return(&regulator_no) - 1);
1598 (unsigned long)atomic_inc_return(&regulator_no) - 1, 1784 ret = device_register(&rdev->dev);
1599 regulator_desc->name); 1785 if (ret != 0) {
1600
1601 ret = device_add(&rdev->dev);
1602 if (ret == 0)
1603 list_add(&rdev->list, &regulator_list);
1604 else {
1605 kfree(rdev); 1786 kfree(rdev);
1606 rdev = ERR_PTR(ret); 1787 rdev = ERR_PTR(ret);
1788 goto out;
1789 }
1790
1791 dev_set_drvdata(&rdev->dev, rdev);
1792
1793 /* set supply regulator if it exists */
1794 if (init_data->supply_regulator_dev) {
1795 ret = set_supply(rdev,
1796 dev_get_drvdata(init_data->supply_regulator_dev));
1797 if (ret < 0) {
1798 device_unregister(&rdev->dev);
1799 kfree(rdev);
1800 rdev = ERR_PTR(ret);
1801 goto out;
1802 }
1607 } 1803 }
1804
1805 /* add consumers devices */
1806 for (i = 0; i < init_data->num_consumer_supplies; i++) {
1807 ret = set_consumer_device_supply(rdev,
1808 init_data->consumer_supplies[i].dev,
1809 init_data->consumer_supplies[i].supply);
1810 if (ret < 0) {
1811 for (--i; i >= 0; i--)
1812 unset_consumer_device_supply(rdev,
1813 init_data->consumer_supplies[i].dev);
1814 device_unregister(&rdev->dev);
1815 kfree(rdev);
1816 rdev = ERR_PTR(ret);
1817 goto out;
1818 }
1819 }
1820
1821 list_add(&rdev->list, &regulator_list);
1822out:
1608 mutex_unlock(&regulator_list_mutex); 1823 mutex_unlock(&regulator_list_mutex);
1609 return rdev; 1824 return rdev;
1610} 1825}
@@ -1631,187 +1846,6 @@ void regulator_unregister(struct regulator_dev *rdev)
1631EXPORT_SYMBOL_GPL(regulator_unregister); 1846EXPORT_SYMBOL_GPL(regulator_unregister);
1632 1847
1633/** 1848/**
1634 * regulator_set_supply - set regulator supply regulator
1635 * @regulator: regulator name
1636 * @supply: supply regulator name
1637 *
1638 * Called by platform initialisation code to set the supply regulator for this
1639 * regulator. This ensures that a regulators supply will also be enabled by the
1640 * core if it's child is enabled.
1641 */
1642int regulator_set_supply(const char *regulator, const char *supply)
1643{
1644 struct regulator_dev *rdev, *supply_rdev;
1645 int err;
1646
1647 if (regulator == NULL || supply == NULL)
1648 return -EINVAL;
1649
1650 mutex_lock(&regulator_list_mutex);
1651
1652 list_for_each_entry(rdev, &regulator_list, list) {
1653 if (!strcmp(rdev->desc->name, regulator))
1654 goto found_regulator;
1655 }
1656 mutex_unlock(&regulator_list_mutex);
1657 return -ENODEV;
1658
1659found_regulator:
1660 list_for_each_entry(supply_rdev, &regulator_list, list) {
1661 if (!strcmp(supply_rdev->desc->name, supply))
1662 goto found_supply;
1663 }
1664 mutex_unlock(&regulator_list_mutex);
1665 return -ENODEV;
1666
1667found_supply:
1668 err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj,
1669 "supply");
1670 if (err) {
1671 printk(KERN_ERR
1672 "%s: could not add device link %s err %d\n",
1673 __func__, supply_rdev->dev.kobj.name, err);
1674 goto out;
1675 }
1676 rdev->supply = supply_rdev;
1677 list_add(&rdev->slist, &supply_rdev->supply_list);
1678out:
1679 mutex_unlock(&regulator_list_mutex);
1680 return err;
1681}
1682EXPORT_SYMBOL_GPL(regulator_set_supply);
1683
1684/**
1685 * regulator_get_supply - get regulator supply regulator
1686 * @regulator: regulator name
1687 *
1688 * Returns the supply supply regulator name or NULL if no supply regulator
1689 * exists (i.e the regulator is supplied directly from USB, Line, Battery, etc)
1690 */
1691const char *regulator_get_supply(const char *regulator)
1692{
1693 struct regulator_dev *rdev;
1694
1695 if (regulator == NULL)
1696 return NULL;
1697
1698 mutex_lock(&regulator_list_mutex);
1699 list_for_each_entry(rdev, &regulator_list, list) {
1700 if (!strcmp(rdev->desc->name, regulator))
1701 goto found;
1702 }
1703 mutex_unlock(&regulator_list_mutex);
1704 return NULL;
1705
1706found:
1707 mutex_unlock(&regulator_list_mutex);
1708 if (rdev->supply)
1709 return rdev->supply->desc->name;
1710 else
1711 return NULL;
1712}
1713EXPORT_SYMBOL_GPL(regulator_get_supply);
1714
1715/**
1716 * regulator_set_machine_constraints - sets regulator constraints
1717 * @regulator: regulator source
1718 *
1719 * Allows platform initialisation code to define and constrain
1720 * regulator circuits e.g. valid voltage/current ranges, etc. NOTE:
1721 * Constraints *must* be set by platform code in order for some
1722 * regulator operations to proceed i.e. set_voltage, set_current_limit,
1723 * set_mode.
1724 */
1725int regulator_set_machine_constraints(const char *regulator_name,
1726 struct regulation_constraints *constraints)
1727{
1728 struct regulator_dev *rdev;
1729 int ret = 0;
1730
1731 if (regulator_name == NULL)
1732 return -EINVAL;
1733
1734 mutex_lock(&regulator_list_mutex);
1735
1736 list_for_each_entry(rdev, &regulator_list, list) {
1737 if (!strcmp(regulator_name, rdev->desc->name))
1738 goto found;
1739 }
1740 ret = -ENODEV;
1741 goto out;
1742
1743found:
1744 mutex_lock(&rdev->mutex);
1745 rdev->constraints = constraints;
1746
1747 /* do we need to apply the constraint voltage */
1748 if (rdev->constraints->apply_uV &&
1749 rdev->constraints->min_uV == rdev->constraints->max_uV &&
1750 rdev->desc->ops->set_voltage) {
1751 ret = rdev->desc->ops->set_voltage(rdev,
1752 rdev->constraints->min_uV, rdev->constraints->max_uV);
1753 if (ret < 0) {
1754 printk(KERN_ERR "%s: failed to apply %duV"
1755 " constraint\n", __func__,
1756 rdev->constraints->min_uV);
1757 rdev->constraints = NULL;
1758 goto out;
1759 }
1760 }
1761
1762 /* are we enabled at boot time by firmware / bootloader */
1763 if (rdev->constraints->boot_on)
1764 rdev->use_count = 1;
1765
1766 /* do we need to setup our suspend state */
1767 if (constraints->initial_state)
1768 ret = suspend_prepare(rdev, constraints->initial_state);
1769
1770 print_constraints(rdev);
1771 mutex_unlock(&rdev->mutex);
1772
1773out:
1774 mutex_unlock(&regulator_list_mutex);
1775 return ret;
1776}
1777EXPORT_SYMBOL_GPL(regulator_set_machine_constraints);
1778
1779
1780/**
1781 * regulator_set_device_supply: Bind a regulator to a symbolic supply
1782 * @regulator: regulator source
1783 * @dev: device the supply applies to
1784 * @supply: symbolic name for supply
1785 *
1786 * Allows platform initialisation code to map physical regulator
1787 * sources to symbolic names for supplies for use by devices. Devices
1788 * should use these symbolic names to request regulators, avoiding the
1789 * need to provide board-specific regulator names as platform data.
1790 */
1791int regulator_set_device_supply(const char *regulator, struct device *dev,
1792 const char *supply)
1793{
1794 struct regulator_map *node;
1795
1796 if (regulator == NULL || supply == NULL)
1797 return -EINVAL;
1798
1799 node = kmalloc(sizeof(struct regulator_map), GFP_KERNEL);
1800 if (node == NULL)
1801 return -ENOMEM;
1802
1803 node->regulator = regulator;
1804 node->dev = dev;
1805 node->supply = supply;
1806
1807 mutex_lock(&regulator_list_mutex);
1808 list_add(&node->list, &regulator_map_list);
1809 mutex_unlock(&regulator_list_mutex);
1810 return 0;
1811}
1812EXPORT_SYMBOL_GPL(regulator_set_device_supply);
1813
1814/**
1815 * regulator_suspend_prepare: prepare regulators for system wide suspend 1849 * regulator_suspend_prepare: prepare regulators for system wide suspend
1816 * @state: system suspend state 1850 * @state: system suspend state
1817 * 1851 *
@@ -1893,6 +1927,18 @@ int rdev_get_id(struct regulator_dev *rdev)
1893} 1927}
1894EXPORT_SYMBOL_GPL(rdev_get_id); 1928EXPORT_SYMBOL_GPL(rdev_get_id);
1895 1929
1930struct device *rdev_get_dev(struct regulator_dev *rdev)
1931{
1932 return &rdev->dev;
1933}
1934EXPORT_SYMBOL_GPL(rdev_get_dev);
1935
1936void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data)
1937{
1938 return reg_init_data->driver_data;
1939}
1940EXPORT_SYMBOL_GPL(regulator_get_init_drvdata);
1941
1896static int __init regulator_init(void) 1942static int __init regulator_init(void)
1897{ 1943{
1898 printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION); 1944 printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION);
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
new file mode 100644
index 000000000000..3688e339db87
--- /dev/null
+++ b/drivers/regulator/da903x.c
@@ -0,0 +1,513 @@
1/*
2 * Regulators driver for Dialog Semiconductor DA903x
3 *
4 * Copyright (C) 2006-2008 Marvell International Ltd.
5 * Copyright (C) 2008 Compulab Ltd.
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/kernel.h>
13#include <linux/init.h>
14#include <linux/err.h>
15#include <linux/platform_device.h>
16#include <linux/regulator/driver.h>
17#include <linux/regulator/machine.h>
18#include <linux/mfd/da903x.h>
19
20/* DA9030 Registers */
21#define DA9030_INVAL (-1)
22#define DA9030_LDO1011 (0x10)
23#define DA9030_LDO15 (0x11)
24#define DA9030_LDO1416 (0x12)
25#define DA9030_LDO1819 (0x13)
26#define DA9030_LDO17 (0x14)
27#define DA9030_BUCK2DVM1 (0x15)
28#define DA9030_BUCK2DVM2 (0x16)
29#define DA9030_RCTL11 (0x17)
30#define DA9030_RCTL21 (0x18)
31#define DA9030_LDO1 (0x90)
32#define DA9030_LDO23 (0x91)
33#define DA9030_LDO45 (0x92)
34#define DA9030_LDO6 (0x93)
35#define DA9030_LDO78 (0x94)
36#define DA9030_LDO912 (0x95)
37#define DA9030_BUCK (0x96)
38#define DA9030_RCTL12 (0x97)
39#define DA9030_RCTL22 (0x98)
40#define DA9030_LDO_UNLOCK (0xa0)
41#define DA9030_LDO_UNLOCK_MASK (0xe0)
42#define DA9034_OVER1 (0x10)
43
44/* DA9034 Registers */
45#define DA9034_INVAL (-1)
46#define DA9034_OVER2 (0x11)
47#define DA9034_OVER3 (0x12)
48#define DA9034_LDO643 (0x13)
49#define DA9034_LDO987 (0x14)
50#define DA9034_LDO1110 (0x15)
51#define DA9034_LDO1312 (0x16)
52#define DA9034_LDO1514 (0x17)
53#define DA9034_VCC1 (0x20)
54#define DA9034_ADTV1 (0x23)
55#define DA9034_ADTV2 (0x24)
56#define DA9034_AVRC (0x25)
57#define DA9034_CDTV1 (0x26)
58#define DA9034_CDTV2 (0x27)
59#define DA9034_CVRC (0x28)
60#define DA9034_SDTV1 (0x29)
61#define DA9034_SDTV2 (0x2a)
62#define DA9034_SVRC (0x2b)
63#define DA9034_MDTV1 (0x32)
64#define DA9034_MDTV2 (0x33)
65#define DA9034_MVRC (0x34)
66
67struct da903x_regulator_info {
68 struct regulator_desc desc;
69
70 int min_uV;
71 int max_uV;
72 int step_uV;
73 int vol_reg;
74 int vol_shift;
75 int vol_nbits;
76 int update_reg;
77 int update_bit;
78 int enable_reg;
79 int enable_bit;
80};
81
82static inline int check_range(struct da903x_regulator_info *info,
83 int min_uV, int max_uV)
84{
85 if (min_uV < info->min_uV || min_uV > info->max_uV)
86 return -EINVAL;
87
88 return 0;
89}
90
91/* DA9030/DA9034 common operations */
92static int da903x_set_ldo_voltage(struct regulator_dev *rdev,
93 int min_uV, int max_uV)
94{
95 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
96 struct device *da9034_dev = rdev_get_dev(rdev)->parent;
97 uint8_t val, mask;
98
99 if (check_range(info, min_uV, max_uV)) {
100 pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV);
101 return -EINVAL;
102 }
103
104 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
105 val <<= info->vol_shift;
106 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
107
108 return da903x_update(da9034_dev, info->vol_reg, val, mask);
109}
110
111static int da903x_get_voltage(struct regulator_dev *rdev)
112{
113 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
114 struct device *da9034_dev = rdev_get_dev(rdev)->parent;
115 uint8_t val, mask;
116 int ret;
117
118 ret = da903x_read(da9034_dev, info->vol_reg, &val);
119 if (ret)
120 return ret;
121
122 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
123 val = (val & mask) >> info->vol_shift;
124
125 return info->min_uV + info->step_uV * val;
126}
127
128static int da903x_enable(struct regulator_dev *rdev)
129{
130 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
131 struct device *da9034_dev = rdev_get_dev(rdev)->parent;
132
133 return da903x_set_bits(da9034_dev, info->enable_reg,
134 1 << info->enable_bit);
135}
136
137static int da903x_disable(struct regulator_dev *rdev)
138{
139 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
140 struct device *da9034_dev = rdev_get_dev(rdev)->parent;
141
142 return da903x_clr_bits(da9034_dev, info->enable_reg,
143 1 << info->enable_bit);
144}
145
146static int da903x_is_enabled(struct regulator_dev *rdev)
147{
148 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
149 struct device *da9034_dev = rdev_get_dev(rdev)->parent;
150 uint8_t reg_val;
151 int ret;
152
153 ret = da903x_read(da9034_dev, info->enable_reg, &reg_val);
154 if (ret)
155 return ret;
156
157 return reg_val & (1 << info->enable_bit);
158}
159
160/* DA9030 specific operations */
161static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
162 int min_uV, int max_uV)
163{
164 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
165 struct device *da903x_dev = rdev_get_dev(rdev)->parent;
166 uint8_t val, mask;
167 int ret;
168
169 if (check_range(info, min_uV, max_uV)) {
170 pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV);
171 return -EINVAL;
172 }
173
174 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
175 val <<= info->vol_shift;
176 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
177 val |= DA9030_LDO_UNLOCK; /* have to set UNLOCK bits */
178 mask |= DA9030_LDO_UNLOCK_MASK;
179
180 /* write twice */
181 ret = da903x_update(da903x_dev, info->vol_reg, val, mask);
182 if (ret)
183 return ret;
184
185 return da903x_update(da903x_dev, info->vol_reg, val, mask);
186}
187
188static int da9030_set_ldo14_voltage(struct regulator_dev *rdev,
189 int min_uV, int max_uV)
190{
191 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
192 struct device *da903x_dev = rdev_get_dev(rdev)->parent;
193 uint8_t val, mask;
194 int thresh;
195
196 if (check_range(info, min_uV, max_uV)) {
197 pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV);
198 return -EINVAL;
199 }
200
201 thresh = (info->max_uV + info->min_uV) / 2;
202 if (min_uV < thresh) {
203 val = (thresh - min_uV + info->step_uV - 1) / info->step_uV;
204 val |= 0x4;
205 } else {
206 val = (min_uV - thresh + info->step_uV - 1) / info->step_uV;
207 }
208
209 val <<= info->vol_shift;
210 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
211
212 return da903x_update(da903x_dev, info->vol_reg, val, mask);
213}
214
215static int da9030_get_ldo14_voltage(struct regulator_dev *rdev)
216{
217 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
218 struct device *da903x_dev = rdev_get_dev(rdev)->parent;
219 uint8_t val, mask;
220 int ret;
221
222 ret = da903x_read(da903x_dev, info->vol_reg, &val);
223 if (ret)
224 return ret;
225
226 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
227 val = (val & mask) >> info->vol_shift;
228
229 if (val & 0x4)
230 return info->min_uV + info->step_uV * (3 - (val & ~0x4));
231 else
232 return (info->max_uV + info->min_uV) / 2 +
233 info->step_uV * (val & ~0x4);
234}
235
236/* DA9034 specific operations */
237static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
238 int min_uV, int max_uV)
239{
240 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
241 struct device *da9034_dev = rdev_get_dev(rdev)->parent;
242 uint8_t val, mask;
243 int ret;
244
245 if (check_range(info, min_uV, max_uV)) {
246 pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV);
247 return -EINVAL;
248 }
249
250 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
251 val <<= info->vol_shift;
252 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
253
254 ret = da903x_update(da9034_dev, info->vol_reg, val, mask);
255 if (ret)
256 return ret;
257
258 ret = da903x_set_bits(da9034_dev, info->update_reg,
259 1 << info->update_bit);
260 return ret;
261}
262
263static int da9034_set_ldo12_voltage(struct regulator_dev *rdev,
264 int min_uV, int max_uV)
265{
266 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
267 struct device *da9034_dev = rdev_get_dev(rdev)->parent;
268 uint8_t val, mask;
269
270 if (check_range(info, min_uV, max_uV)) {
271 pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV);
272 return -EINVAL;
273 }
274
275 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
276 val = (val > 7 || val < 20) ? 8 : val - 12;
277 val <<= info->vol_shift;
278 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
279
280 return da903x_update(da9034_dev, info->vol_reg, val, mask);
281}
282
283static int da9034_get_ldo12_voltage(struct regulator_dev *rdev)
284{
285 struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
286 struct device *da9034_dev = rdev_get_dev(rdev)->parent;
287 uint8_t val, mask;
288 int ret;
289
290 ret = da903x_read(da9034_dev, info->vol_reg, &val);
291 if (ret)
292 return ret;
293
294 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift;
295 val = (val & mask) >> info->vol_shift;
296
297 if (val >= 8)
298 return 2700000 + info->step_uV * (val - 8);
299
300 return info->min_uV + info->step_uV * val;
301}
302
303static struct regulator_ops da903x_regulator_ldo_ops = {
304 .set_voltage = da903x_set_ldo_voltage,
305 .get_voltage = da903x_get_voltage,
306 .enable = da903x_enable,
307 .disable = da903x_disable,
308 .is_enabled = da903x_is_enabled,
309};
310
311/* NOTE: this is dedicated for the insane DA9030 LDO14 */
312static struct regulator_ops da9030_regulator_ldo14_ops = {
313 .set_voltage = da9030_set_ldo14_voltage,
314 .get_voltage = da9030_get_ldo14_voltage,
315 .enable = da903x_enable,
316 .disable = da903x_disable,
317 .is_enabled = da903x_is_enabled,
318};
319
320/* NOTE: this is dedicated for the DA9030 LDO1 and LDO15 that have locks */
321static struct regulator_ops da9030_regulator_ldo1_15_ops = {
322 .set_voltage = da9030_set_ldo1_15_voltage,
323 .get_voltage = da903x_get_voltage,
324 .enable = da903x_enable,
325 .disable = da903x_disable,
326 .is_enabled = da903x_is_enabled,
327};
328
329static struct regulator_ops da9034_regulator_dvc_ops = {
330 .set_voltage = da9034_set_dvc_voltage,
331 .get_voltage = da903x_get_voltage,
332 .enable = da903x_enable,
333 .disable = da903x_disable,
334 .is_enabled = da903x_is_enabled,
335};
336
337/* NOTE: this is dedicated for the insane LDO12 */
338static struct regulator_ops da9034_regulator_ldo12_ops = {
339 .set_voltage = da9034_set_ldo12_voltage,
340 .get_voltage = da9034_get_ldo12_voltage,
341 .enable = da903x_enable,
342 .disable = da903x_disable,
343 .is_enabled = da903x_is_enabled,
344};
345
346#define DA903x_LDO(_pmic, _id, min, max, step, vreg, shift, nbits, ereg, ebit) \
347{ \
348 .desc = { \
349 .name = "LDO" #_id, \
350 .ops = &da903x_regulator_ldo_ops, \
351 .type = REGULATOR_VOLTAGE, \
352 .id = _pmic##_ID_LDO##_id, \
353 .owner = THIS_MODULE, \
354 }, \
355 .min_uV = (min) * 1000, \
356 .max_uV = (max) * 1000, \
357 .step_uV = (step) * 1000, \
358 .vol_reg = _pmic##_##vreg, \
359 .vol_shift = (shift), \
360 .vol_nbits = (nbits), \
361 .enable_reg = _pmic##_##ereg, \
362 .enable_bit = (ebit), \
363}
364
365#define DA9034_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \
366{ \
367 .desc = { \
368 .name = #_id, \
369 .ops = &da9034_regulator_dvc_ops, \
370 .type = REGULATOR_VOLTAGE, \
371 .id = DA9034_ID_##_id, \
372 .owner = THIS_MODULE, \
373 }, \
374 .min_uV = (min) * 1000, \
375 .max_uV = (max) * 1000, \
376 .step_uV = (step) * 1000, \
377 .vol_reg = DA9034_##vreg, \
378 .vol_shift = (0), \
379 .vol_nbits = (nbits), \
380 .update_reg = DA9034_##ureg, \
381 .update_bit = (ubit), \
382 .enable_reg = DA9034_##ereg, \
383 .enable_bit = (ebit), \
384}
385
386#define DA9034_LDO(_id, min, max, step, vreg, shift, nbits, ereg, ebit) \
387 DA903x_LDO(DA9034, _id, min, max, step, vreg, shift, nbits, ereg, ebit)
388
389#define DA9030_LDO(_id, min, max, step, vreg, shift, nbits, ereg, ebit) \
390 DA903x_LDO(DA9030, _id, min, max, step, vreg, shift, nbits, ereg, ebit)
391
392static struct da903x_regulator_info da903x_regulator_info[] = {
393 /* DA9030 */
394 DA9030_LDO( 1, 1200, 3200, 100, LDO1, 0, 5, RCTL12, 1),
395 DA9030_LDO( 2, 1800, 3200, 100, LDO23, 0, 4, RCTL12, 2),
396 DA9030_LDO( 3, 1800, 3200, 100, LDO23, 4, 4, RCTL12, 3),
397 DA9030_LDO( 4, 1800, 3200, 100, LDO45, 0, 4, RCTL12, 4),
398 DA9030_LDO( 5, 1800, 3200, 100, LDO45, 4, 4, RCTL12, 5),
399 DA9030_LDO( 6, 1800, 3200, 100, LDO6, 0, 4, RCTL12, 6),
400 DA9030_LDO( 7, 1800, 3200, 100, LDO78, 0, 4, RCTL12, 7),
401 DA9030_LDO( 8, 1800, 3200, 100, LDO78, 4, 4, RCTL22, 0),
402 DA9030_LDO( 9, 1800, 3200, 100, LDO912, 0, 4, RCTL22, 1),
403 DA9030_LDO(10, 1800, 3200, 100, LDO1011, 0, 4, RCTL22, 2),
404 DA9030_LDO(11, 1800, 3200, 100, LDO1011, 4, 4, RCTL22, 3),
405 DA9030_LDO(12, 1800, 3200, 100, LDO912, 4, 4, RCTL22, 4),
406 DA9030_LDO(14, 2760, 2940, 30, LDO1416, 0, 3, RCTL11, 4),
407 DA9030_LDO(15, 1100, 2650, 50, LDO15, 0, 5, RCTL11, 5),
408 DA9030_LDO(16, 1100, 2650, 50, LDO1416, 3, 5, RCTL11, 6),
409 DA9030_LDO(17, 1800, 3200, 100, LDO17, 0, 4, RCTL11, 7),
410 DA9030_LDO(18, 1800, 3200, 100, LDO1819, 0, 4, RCTL21, 2),
411 DA9030_LDO(19, 1800, 3200, 100, LDO1819, 4, 4, RCTL21, 1),
412 DA9030_LDO(13, 2100, 2100, 0, INVAL, 0, 0, RCTL11, 3), /* fixed @2.1V */
413
414 /* DA9034 */
415 DA9034_DVC(BUCK1, 725, 1500, 25, ADTV1, 5, VCC1, 0, OVER1, 0),
416 DA9034_DVC(BUCK2, 725, 1500, 25, CDTV1, 5, VCC1, 2, OVER1, 1),
417 DA9034_DVC(LDO2, 725, 1500, 25, SDTV1, 5, VCC1, 4, OVER1, 2),
418 DA9034_DVC(LDO1, 1700, 2075, 25, MDTV1, 4, VCC1, 6, OVER3, 4),
419
420 DA9034_LDO( 3, 1800, 3300, 100, LDO643, 0, 4, OVER3, 5),
421 DA9034_LDO( 4, 1800, 2900,1100, LDO643, 4, 1, OVER3, 6),
422 DA9034_LDO( 6, 2500, 2850, 50, LDO643, 5, 3, OVER2, 0),
423 DA9034_LDO( 7, 2700, 3050, 50, LDO987, 0, 3, OVER2, 1),
424 DA9034_LDO( 8, 2700, 2850, 50, LDO987, 3, 2, OVER2, 2),
425 DA9034_LDO( 9, 2700, 3050, 50, LDO987, 5, 3, OVER2, 3),
426 DA9034_LDO(10, 2700, 3050, 50, LDO1110, 0, 3, OVER2, 4),
427 DA9034_LDO(11, 1800, 3300, 100, LDO1110, 4, 4, OVER2, 5),
428 DA9034_LDO(12, 1700, 3050, 50, LDO1312, 0, 4, OVER3, 6),
429 DA9034_LDO(13, 1800, 3300, 100, LDO1312, 4, 4, OVER2, 7),
430 DA9034_LDO(14, 1800, 3300, 100, LDO1514, 0, 4, OVER3, 0),
431 DA9034_LDO(15, 1800, 3300, 100, LDO1514, 4, 4, OVER3, 1),
432 DA9034_LDO(5, 3100, 3100, 0, INVAL, 0, 0, OVER3, 7), /* fixed @3.1V */
433};
434
435static inline struct da903x_regulator_info *find_regulator_info(int id)
436{
437 struct da903x_regulator_info *ri;
438 int i;
439
440 for (i = 0; i < ARRAY_SIZE(da903x_regulator_info); i++) {
441 ri = &da903x_regulator_info[i];
442 if (ri->desc.id == id)
443 return ri;
444 }
445 return NULL;
446}
447
448static int __devinit da903x_regulator_probe(struct platform_device *pdev)
449{
450 struct da903x_regulator_info *ri = NULL;
451 struct regulator_dev *rdev;
452
453 ri = find_regulator_info(pdev->id);
454 if (ri == NULL) {
455 dev_err(&pdev->dev, "invalid regulator ID specified\n");
456 return -EINVAL;
457 }
458
459 /* Workaround for the weird LDO12 voltage setting */
460 if (ri->desc.id == DA9034_ID_LDO12)
461 ri->desc.ops = &da9034_regulator_ldo12_ops;
462
463 if (ri->desc.id == DA9030_ID_LDO14)
464 ri->desc.ops = &da9030_regulator_ldo14_ops;
465
466 if (ri->desc.id == DA9030_ID_LDO1 || ri->desc.id == DA9030_ID_LDO15)
467 ri->desc.ops = &da9030_regulator_ldo1_15_ops;
468
469 rdev = regulator_register(&ri->desc, pdev->dev.parent, ri);
470 if (IS_ERR(rdev)) {
471 dev_err(&pdev->dev, "failed to register regulator %s\n",
472 ri->desc.name);
473 return PTR_ERR(rdev);
474 }
475
476 platform_set_drvdata(pdev, rdev);
477 return 0;
478}
479
480static int __devexit da903x_regulator_remove(struct platform_device *pdev)
481{
482 struct regulator_dev *rdev = platform_get_drvdata(pdev);
483
484 regulator_unregister(rdev);
485 return 0;
486}
487
488static struct platform_driver da903x_regulator_driver = {
489 .driver = {
490 .name = "da903x-regulator",
491 .owner = THIS_MODULE,
492 },
493 .probe = da903x_regulator_probe,
494 .remove = da903x_regulator_remove,
495};
496
497static int __init da903x_regulator_init(void)
498{
499 return platform_driver_register(&da903x_regulator_driver);
500}
501module_init(da903x_regulator_init);
502
503static void __exit da903x_regulator_exit(void)
504{
505 platform_driver_unregister(&da903x_regulator_driver);
506}
507module_exit(da903x_regulator_exit);
508
509MODULE_LICENSE("GPL");
510MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>"
511 "Mike Rapoport <mike@compulab.co.il>");
512MODULE_DESCRIPTION("Regulator Driver for Dialog Semiconductor DA903X PMIC");
513MODULE_ALIAS("platform:da903x-regulator");
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c
new file mode 100644
index 000000000000..1f44b17e23b1
--- /dev/null
+++ b/drivers/regulator/wm8350-regulator.c
@@ -0,0 +1,1431 @@
1/*
2 * wm8350.c -- Voltage and current regulation for the Wolfson WM8350 PMIC
3 *
4 * Copyright 2007, 2008 Wolfson Microelectronics PLC.
5 *
6 * Author: Liam Girdwood
7 * linux@wolfsonmicro.com
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
15#include <linux/module.h>
16#include <linux/moduleparam.h>
17#include <linux/init.h>
18#include <linux/bitops.h>
19#include <linux/err.h>
20#include <linux/i2c.h>
21#include <linux/mfd/wm8350/core.h>
22#include <linux/mfd/wm8350/pmic.h>
23#include <linux/platform_device.h>
24#include <linux/regulator/driver.h>
25#include <linux/regulator/machine.h>
26
27/* Microamps */
28static const int isink_cur[] = {
29 4,
30 5,
31 6,
32 7,
33 8,
34 10,
35 11,
36 14,
37 16,
38 19,
39 23,
40 27,
41 32,
42 39,
43 46,
44 54,
45 65,
46 77,
47 92,
48 109,
49 130,
50 154,
51 183,
52 218,
53 259,
54 308,
55 367,
56 436,
57 518,
58 616,
59 733,
60 872,
61 1037,
62 1233,
63 1466,
64 1744,
65 2073,
66 2466,
67 2933,
68 3487,
69 4147,
70 4932,
71 5865,
72 6975,
73 8294,
74 9864,
75 11730,
76 13949,
77 16589,
78 19728,
79 23460,
80 27899,
81 33178,
82 39455,
83 46920,
84 55798,
85 66355,
86 78910,
87 93840,
88 111596,
89 132710,
90 157820,
91 187681,
92 223191
93};
94
95static int get_isink_val(int min_uA, int max_uA, u16 *setting)
96{
97 int i;
98
99 for (i = ARRAY_SIZE(isink_cur) - 1; i >= 0; i--) {
100 if (min_uA <= isink_cur[i] && max_uA >= isink_cur[i]) {
101 *setting = i;
102 return 0;
103 }
104 }
105 return -EINVAL;
106}
107
108static inline int wm8350_ldo_val_to_mvolts(unsigned int val)
109{
110 if (val < 16)
111 return (val * 50) + 900;
112 else
113 return ((val - 16) * 100) + 1800;
114
115}
116
117static inline unsigned int wm8350_ldo_mvolts_to_val(int mV)
118{
119 if (mV < 1800)
120 return (mV - 900) / 50;
121 else
122 return ((mV - 1800) / 100) + 16;
123}
124
125static inline int wm8350_dcdc_val_to_mvolts(unsigned int val)
126{
127 return (val * 25) + 850;
128}
129
130static inline unsigned int wm8350_dcdc_mvolts_to_val(int mV)
131{
132 return (mV - 850) / 25;
133}
134
135static int wm8350_isink_set_current(struct regulator_dev *rdev, int min_uA,
136 int max_uA)
137{
138 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
139 int isink = rdev_get_id(rdev);
140 u16 val, setting;
141 int ret;
142
143 ret = get_isink_val(min_uA, max_uA, &setting);
144 if (ret != 0)
145 return ret;
146
147 switch (isink) {
148 case WM8350_ISINK_A:
149 val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) &
150 ~WM8350_CS1_ISEL_MASK;
151 wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_A,
152 val | setting);
153 break;
154 case WM8350_ISINK_B:
155 val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) &
156 ~WM8350_CS1_ISEL_MASK;
157 wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_B,
158 val | setting);
159 break;
160 default:
161 return -EINVAL;
162 }
163
164 return 0;
165}
166
167static int wm8350_isink_get_current(struct regulator_dev *rdev)
168{
169 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
170 int isink = rdev_get_id(rdev);
171 u16 val;
172
173 switch (isink) {
174 case WM8350_ISINK_A:
175 val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) &
176 WM8350_CS1_ISEL_MASK;
177 break;
178 case WM8350_ISINK_B:
179 val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) &
180 WM8350_CS1_ISEL_MASK;
181 break;
182 default:
183 return 0;
184 }
185
186 return (isink_cur[val] + 50) / 100;
187}
188
189/* turn on ISINK followed by DCDC */
190static int wm8350_isink_enable(struct regulator_dev *rdev)
191{
192 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
193 int isink = rdev_get_id(rdev);
194
195 switch (isink) {
196 case WM8350_ISINK_A:
197 switch (wm8350->pmic.isink_A_dcdc) {
198 case WM8350_DCDC_2:
199 case WM8350_DCDC_5:
200 wm8350_set_bits(wm8350, WM8350_POWER_MGMT_7,
201 WM8350_CS1_ENA);
202 wm8350_set_bits(wm8350, WM8350_CSA_FLASH_CONTROL,
203 WM8350_CS1_DRIVE);
204 wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED,
205 1 << (wm8350->pmic.isink_A_dcdc -
206 WM8350_DCDC_1));
207 break;
208 default:
209 return -EINVAL;
210 }
211 break;
212 case WM8350_ISINK_B:
213 switch (wm8350->pmic.isink_B_dcdc) {
214 case WM8350_DCDC_2:
215 case WM8350_DCDC_5:
216 wm8350_set_bits(wm8350, WM8350_POWER_MGMT_7,
217 WM8350_CS2_ENA);
218 wm8350_set_bits(wm8350, WM8350_CSB_FLASH_CONTROL,
219 WM8350_CS2_DRIVE);
220 wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED,
221 1 << (wm8350->pmic.isink_B_dcdc -
222 WM8350_DCDC_1));
223 break;
224 default:
225 return -EINVAL;
226 }
227 break;
228 default:
229 return -EINVAL;
230 }
231 return 0;
232}
233
234static int wm8350_isink_disable(struct regulator_dev *rdev)
235{
236 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
237 int isink = rdev_get_id(rdev);
238
239 switch (isink) {
240 case WM8350_ISINK_A:
241 switch (wm8350->pmic.isink_A_dcdc) {
242 case WM8350_DCDC_2:
243 case WM8350_DCDC_5:
244 wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED,
245 1 << (wm8350->pmic.isink_A_dcdc -
246 WM8350_DCDC_1));
247 wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_7,
248 WM8350_CS1_ENA);
249 break;
250 default:
251 return -EINVAL;
252 }
253 break;
254 case WM8350_ISINK_B:
255 switch (wm8350->pmic.isink_B_dcdc) {
256 case WM8350_DCDC_2:
257 case WM8350_DCDC_5:
258 wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED,
259 1 << (wm8350->pmic.isink_B_dcdc -
260 WM8350_DCDC_1));
261 wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_7,
262 WM8350_CS2_ENA);
263 break;
264 default:
265 return -EINVAL;
266 }
267 break;
268 default:
269 return -EINVAL;
270 }
271 return 0;
272}
273
274static int wm8350_isink_is_enabled(struct regulator_dev *rdev)
275{
276 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
277 int isink = rdev_get_id(rdev);
278
279 switch (isink) {
280 case WM8350_ISINK_A:
281 return wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) &
282 0x8000;
283 case WM8350_ISINK_B:
284 return wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) &
285 0x8000;
286 }
287 return -EINVAL;
288}
289
290int wm8350_isink_set_flash(struct wm8350 *wm8350, int isink, u16 mode,
291 u16 trigger, u16 duration, u16 on_ramp, u16 off_ramp,
292 u16 drive)
293{
294 switch (isink) {
295 case WM8350_ISINK_A:
296 wm8350_reg_write(wm8350, WM8350_CSA_FLASH_CONTROL,
297 (mode ? WM8350_CS1_FLASH_MODE : 0) |
298 (trigger ? WM8350_CS1_TRIGSRC : 0) |
299 duration | on_ramp | off_ramp | drive);
300 break;
301 case WM8350_ISINK_B:
302 wm8350_reg_write(wm8350, WM8350_CSB_FLASH_CONTROL,
303 (mode ? WM8350_CS2_FLASH_MODE : 0) |
304 (trigger ? WM8350_CS2_TRIGSRC : 0) |
305 duration | on_ramp | off_ramp | drive);
306 break;
307 default:
308 return -EINVAL;
309 }
310 return 0;
311}
312EXPORT_SYMBOL_GPL(wm8350_isink_set_flash);
313
314static int wm8350_dcdc_set_voltage(struct regulator_dev *rdev, int min_uV,
315 int max_uV)
316{
317 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
318 int volt_reg, dcdc = rdev_get_id(rdev), mV,
319 min_mV = min_uV / 1000, max_mV = max_uV / 1000;
320 u16 val;
321
322 if (min_mV < 850 || min_mV > 4025)
323 return -EINVAL;
324 if (max_mV < 850 || max_mV > 4025)
325 return -EINVAL;
326
327 /* step size is 25mV */
328 mV = (min_mV - 826) / 25;
329 if (wm8350_dcdc_val_to_mvolts(mV) > max_mV)
330 return -EINVAL;
331 BUG_ON(wm8350_dcdc_val_to_mvolts(mV) < min_mV);
332
333 switch (dcdc) {
334 case WM8350_DCDC_1:
335 volt_reg = WM8350_DCDC1_CONTROL;
336 break;
337 case WM8350_DCDC_3:
338 volt_reg = WM8350_DCDC3_CONTROL;
339 break;
340 case WM8350_DCDC_4:
341 volt_reg = WM8350_DCDC4_CONTROL;
342 break;
343 case WM8350_DCDC_6:
344 volt_reg = WM8350_DCDC6_CONTROL;
345 break;
346 case WM8350_DCDC_2:
347 case WM8350_DCDC_5:
348 default:
349 return -EINVAL;
350 }
351
352 /* all DCDCs have same mV bits */
353 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK;
354 wm8350_reg_write(wm8350, volt_reg, val | mV);
355 return 0;
356}
357
358static int wm8350_dcdc_get_voltage(struct regulator_dev *rdev)
359{
360 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
361 int volt_reg, dcdc = rdev_get_id(rdev);
362 u16 val;
363
364 switch (dcdc) {
365 case WM8350_DCDC_1:
366 volt_reg = WM8350_DCDC1_CONTROL;
367 break;
368 case WM8350_DCDC_3:
369 volt_reg = WM8350_DCDC3_CONTROL;
370 break;
371 case WM8350_DCDC_4:
372 volt_reg = WM8350_DCDC4_CONTROL;
373 break;
374 case WM8350_DCDC_6:
375 volt_reg = WM8350_DCDC6_CONTROL;
376 break;
377 case WM8350_DCDC_2:
378 case WM8350_DCDC_5:
379 default:
380 return -EINVAL;
381 }
382
383 /* all DCDCs have same mV bits */
384 val = wm8350_reg_read(wm8350, volt_reg) & WM8350_DC1_VSEL_MASK;
385 return wm8350_dcdc_val_to_mvolts(val) * 1000;
386}
387
388static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV)
389{
390 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
391 int volt_reg, mV = uV / 1000, dcdc = rdev_get_id(rdev);
392 u16 val;
393
394 dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, dcdc, mV);
395
396 if (mV && (mV < 850 || mV > 4025)) {
397 dev_err(wm8350->dev,
398 "DCDC%d suspend voltage %d mV out of range\n",
399 dcdc, mV);
400 return -EINVAL;
401 }
402 if (mV == 0)
403 mV = 850;
404
405 switch (dcdc) {
406 case WM8350_DCDC_1:
407 volt_reg = WM8350_DCDC1_LOW_POWER;
408 break;
409 case WM8350_DCDC_3:
410 volt_reg = WM8350_DCDC3_LOW_POWER;
411 break;
412 case WM8350_DCDC_4:
413 volt_reg = WM8350_DCDC4_LOW_POWER;
414 break;
415 case WM8350_DCDC_6:
416 volt_reg = WM8350_DCDC6_LOW_POWER;
417 break;
418 case WM8350_DCDC_2:
419 case WM8350_DCDC_5:
420 default:
421 return -EINVAL;
422 }
423
424 /* all DCDCs have same mV bits */
425 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK;
426 wm8350_reg_write(wm8350, volt_reg,
427 val | wm8350_dcdc_mvolts_to_val(mV));
428 return 0;
429}
430
431static int wm8350_dcdc_set_suspend_enable(struct regulator_dev *rdev)
432{
433 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
434 int dcdc = rdev_get_id(rdev);
435 u16 val;
436
437 switch (dcdc) {
438 case WM8350_DCDC_1:
439 val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER)
440 & ~WM8350_DCDC_HIB_MODE_MASK;
441 wm8350_reg_write(wm8350, WM8350_DCDC1_LOW_POWER,
442 wm8350->pmic.dcdc1_hib_mode);
443 break;
444 case WM8350_DCDC_3:
445 val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER)
446 & ~WM8350_DCDC_HIB_MODE_MASK;
447 wm8350_reg_write(wm8350, WM8350_DCDC3_LOW_POWER,
448 wm8350->pmic.dcdc3_hib_mode);
449 break;
450 case WM8350_DCDC_4:
451 val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER)
452 & ~WM8350_DCDC_HIB_MODE_MASK;
453 wm8350_reg_write(wm8350, WM8350_DCDC4_LOW_POWER,
454 wm8350->pmic.dcdc4_hib_mode);
455 break;
456 case WM8350_DCDC_6:
457 val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER)
458 & ~WM8350_DCDC_HIB_MODE_MASK;
459 wm8350_reg_write(wm8350, WM8350_DCDC6_LOW_POWER,
460 wm8350->pmic.dcdc6_hib_mode);
461 break;
462 case WM8350_DCDC_2:
463 case WM8350_DCDC_5:
464 default:
465 return -EINVAL;
466 }
467
468 return 0;
469}
470
471static int wm8350_dcdc_set_suspend_disable(struct regulator_dev *rdev)
472{
473 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
474 int dcdc = rdev_get_id(rdev);
475 u16 val;
476
477 switch (dcdc) {
478 case WM8350_DCDC_1:
479 val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER);
480 wm8350->pmic.dcdc1_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
481 wm8350_reg_write(wm8350, WM8350_DCDC1_LOW_POWER,
482 WM8350_DCDC_HIB_MODE_DIS);
483 break;
484 case WM8350_DCDC_3:
485 val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER);
486 wm8350->pmic.dcdc3_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
487 wm8350_reg_write(wm8350, WM8350_DCDC3_LOW_POWER,
488 WM8350_DCDC_HIB_MODE_DIS);
489 break;
490 case WM8350_DCDC_4:
491 val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER);
492 wm8350->pmic.dcdc4_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
493 wm8350_reg_write(wm8350, WM8350_DCDC4_LOW_POWER,
494 WM8350_DCDC_HIB_MODE_DIS);
495 break;
496 case WM8350_DCDC_6:
497 val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER);
498 wm8350->pmic.dcdc6_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
499 wm8350_reg_write(wm8350, WM8350_DCDC6_LOW_POWER,
500 WM8350_DCDC_HIB_MODE_DIS);
501 break;
502 case WM8350_DCDC_2:
503 case WM8350_DCDC_5:
504 default:
505 return -EINVAL;
506 }
507
508 return 0;
509}
510
511static int wm8350_dcdc25_set_suspend_enable(struct regulator_dev *rdev)
512{
513 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
514 int dcdc = rdev_get_id(rdev);
515 u16 val;
516
517 switch (dcdc) {
518 case WM8350_DCDC_2:
519 val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL)
520 & ~WM8350_DC2_HIB_MODE_MASK;
521 wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val |
522 WM8350_DC2_HIB_MODE_ACTIVE);
523 break;
524 case WM8350_DCDC_5:
525 val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL)
526 & ~WM8350_DC2_HIB_MODE_MASK;
527 wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val |
528 WM8350_DC5_HIB_MODE_ACTIVE);
529 break;
530 default:
531 return -EINVAL;
532 }
533 return 0;
534}
535
536static int wm8350_dcdc25_set_suspend_disable(struct regulator_dev *rdev)
537{
538 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
539 int dcdc = rdev_get_id(rdev);
540 u16 val;
541
542 switch (dcdc) {
543 case WM8350_DCDC_2:
544 val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL)
545 & ~WM8350_DC2_HIB_MODE_MASK;
546 wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val |
547 WM8350_DC2_HIB_MODE_DISABLE);
548 break;
549 case WM8350_DCDC_5:
550 val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL)
551 & ~WM8350_DC2_HIB_MODE_MASK;
552 wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val |
553 WM8350_DC2_HIB_MODE_DISABLE);
554 break;
555 default:
556 return -EINVAL;
557 }
558 return 0;
559}
560
561static int wm8350_dcdc_set_suspend_mode(struct regulator_dev *rdev,
562 unsigned int mode)
563{
564 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
565 int dcdc = rdev_get_id(rdev);
566 u16 *hib_mode;
567
568 switch (dcdc) {
569 case WM8350_DCDC_1:
570 hib_mode = &wm8350->pmic.dcdc1_hib_mode;
571 break;
572 case WM8350_DCDC_3:
573 hib_mode = &wm8350->pmic.dcdc3_hib_mode;
574 break;
575 case WM8350_DCDC_4:
576 hib_mode = &wm8350->pmic.dcdc4_hib_mode;
577 break;
578 case WM8350_DCDC_6:
579 hib_mode = &wm8350->pmic.dcdc6_hib_mode;
580 break;
581 case WM8350_DCDC_2:
582 case WM8350_DCDC_5:
583 default:
584 return -EINVAL;
585 }
586
587 switch (mode) {
588 case REGULATOR_MODE_NORMAL:
589 *hib_mode = WM8350_DCDC_HIB_MODE_IMAGE;
590 break;
591 case REGULATOR_MODE_IDLE:
592 *hib_mode = WM8350_DCDC_HIB_MODE_STANDBY;
593 break;
594 case REGULATOR_MODE_STANDBY:
595 *hib_mode = WM8350_DCDC_HIB_MODE_LDO_IM;
596 break;
597 default:
598 return -EINVAL;
599 }
600
601 return 0;
602}
603
604static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV)
605{
606 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
607 int volt_reg, mV = uV / 1000, ldo = rdev_get_id(rdev);
608 u16 val;
609
610 dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, ldo, mV);
611
612 if (mV < 900 || mV > 3300) {
613 dev_err(wm8350->dev, "LDO%d voltage %d mV out of range\n",
614 ldo, mV);
615 return -EINVAL;
616 }
617
618 switch (ldo) {
619 case WM8350_LDO_1:
620 volt_reg = WM8350_LDO1_LOW_POWER;
621 break;
622 case WM8350_LDO_2:
623 volt_reg = WM8350_LDO2_LOW_POWER;
624 break;
625 case WM8350_LDO_3:
626 volt_reg = WM8350_LDO3_LOW_POWER;
627 break;
628 case WM8350_LDO_4:
629 volt_reg = WM8350_LDO4_LOW_POWER;
630 break;
631 default:
632 return -EINVAL;
633 }
634
635 /* all LDOs have same mV bits */
636 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK;
637 wm8350_reg_write(wm8350, volt_reg,
638 val | wm8350_ldo_mvolts_to_val(mV));
639 return 0;
640}
641
642static int wm8350_ldo_set_suspend_enable(struct regulator_dev *rdev)
643{
644 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
645 int volt_reg, ldo = rdev_get_id(rdev);
646 u16 val;
647
648 switch (ldo) {
649 case WM8350_LDO_1:
650 volt_reg = WM8350_LDO1_LOW_POWER;
651 break;
652 case WM8350_LDO_2:
653 volt_reg = WM8350_LDO2_LOW_POWER;
654 break;
655 case WM8350_LDO_3:
656 volt_reg = WM8350_LDO3_LOW_POWER;
657 break;
658 case WM8350_LDO_4:
659 volt_reg = WM8350_LDO4_LOW_POWER;
660 break;
661 default:
662 return -EINVAL;
663 }
664
665 /* all LDOs have same mV bits */
666 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_HIB_MODE_MASK;
667 wm8350_reg_write(wm8350, volt_reg, val);
668 return 0;
669}
670
671static int wm8350_ldo_set_suspend_disable(struct regulator_dev *rdev)
672{
673 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
674 int volt_reg, ldo = rdev_get_id(rdev);
675 u16 val;
676
677 switch (ldo) {
678 case WM8350_LDO_1:
679 volt_reg = WM8350_LDO1_LOW_POWER;
680 break;
681 case WM8350_LDO_2:
682 volt_reg = WM8350_LDO2_LOW_POWER;
683 break;
684 case WM8350_LDO_3:
685 volt_reg = WM8350_LDO3_LOW_POWER;
686 break;
687 case WM8350_LDO_4:
688 volt_reg = WM8350_LDO4_LOW_POWER;
689 break;
690 default:
691 return -EINVAL;
692 }
693
694 /* all LDOs have same mV bits */
695 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_HIB_MODE_MASK;
696 wm8350_reg_write(wm8350, volt_reg, WM8350_LDO1_HIB_MODE_DIS);
697 return 0;
698}
699
700static int wm8350_ldo_set_voltage(struct regulator_dev *rdev, int min_uV,
701 int max_uV)
702{
703 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
704 int volt_reg, ldo = rdev_get_id(rdev), mV, min_mV = min_uV / 1000,
705 max_mV = max_uV / 1000;
706 u16 val;
707
708 if (min_mV < 900 || min_mV > 3300)
709 return -EINVAL;
710 if (max_mV < 900 || max_mV > 3300)
711 return -EINVAL;
712
713 if (min_mV < 1800) {
714 /* step size is 50mV < 1800mV */
715 mV = (min_mV - 851) / 50;
716 if (wm8350_ldo_val_to_mvolts(mV) > max_mV)
717 return -EINVAL;
718 BUG_ON(wm8350_ldo_val_to_mvolts(mV) < min_mV);
719 } else {
720 /* step size is 100mV > 1800mV */
721 mV = ((min_mV - 1701) / 100) + 16;
722 if (wm8350_ldo_val_to_mvolts(mV) > max_mV)
723 return -EINVAL;
724 BUG_ON(wm8350_ldo_val_to_mvolts(mV) < min_mV);
725 }
726
727 switch (ldo) {
728 case WM8350_LDO_1:
729 volt_reg = WM8350_LDO1_CONTROL;
730 break;
731 case WM8350_LDO_2:
732 volt_reg = WM8350_LDO2_CONTROL;
733 break;
734 case WM8350_LDO_3:
735 volt_reg = WM8350_LDO3_CONTROL;
736 break;
737 case WM8350_LDO_4:
738 volt_reg = WM8350_LDO4_CONTROL;
739 break;
740 default:
741 return -EINVAL;
742 }
743
744 /* all LDOs have same mV bits */
745 val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK;
746 wm8350_reg_write(wm8350, volt_reg, val | mV);
747 return 0;
748}
749
750static int wm8350_ldo_get_voltage(struct regulator_dev *rdev)
751{
752 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
753 int volt_reg, ldo = rdev_get_id(rdev);
754 u16 val;
755
756 switch (ldo) {
757 case WM8350_LDO_1:
758 volt_reg = WM8350_LDO1_CONTROL;
759 break;
760 case WM8350_LDO_2:
761 volt_reg = WM8350_LDO2_CONTROL;
762 break;
763 case WM8350_LDO_3:
764 volt_reg = WM8350_LDO3_CONTROL;
765 break;
766 case WM8350_LDO_4:
767 volt_reg = WM8350_LDO4_CONTROL;
768 break;
769 default:
770 return -EINVAL;
771 }
772
773 /* all LDOs have same mV bits */
774 val = wm8350_reg_read(wm8350, volt_reg) & WM8350_LDO1_VSEL_MASK;
775 return wm8350_ldo_val_to_mvolts(val) * 1000;
776}
777
778int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start,
779 u16 stop, u16 fault)
780{
781 int slot_reg;
782 u16 val;
783
784 dev_dbg(wm8350->dev, "%s %d start %d stop %d\n",
785 __func__, dcdc, start, stop);
786
787 /* slot valid ? */
788 if (start > 15 || stop > 15)
789 return -EINVAL;
790
791 switch (dcdc) {
792 case WM8350_DCDC_1:
793 slot_reg = WM8350_DCDC1_TIMEOUTS;
794 break;
795 case WM8350_DCDC_2:
796 slot_reg = WM8350_DCDC2_TIMEOUTS;
797 break;
798 case WM8350_DCDC_3:
799 slot_reg = WM8350_DCDC3_TIMEOUTS;
800 break;
801 case WM8350_DCDC_4:
802 slot_reg = WM8350_DCDC4_TIMEOUTS;
803 break;
804 case WM8350_DCDC_5:
805 slot_reg = WM8350_DCDC5_TIMEOUTS;
806 break;
807 case WM8350_DCDC_6:
808 slot_reg = WM8350_DCDC6_TIMEOUTS;
809 break;
810 default:
811 return -EINVAL;
812 }
813
814 val = wm8350_reg_read(wm8350, slot_reg) &
815 ~(WM8350_DC1_ENSLOT_MASK | WM8350_DC1_SDSLOT_MASK |
816 WM8350_DC1_ERRACT_MASK);
817 wm8350_reg_write(wm8350, slot_reg,
818 val | (start << WM8350_DC1_ENSLOT_SHIFT) |
819 (stop << WM8350_DC1_SDSLOT_SHIFT) |
820 (fault << WM8350_DC1_ERRACT_SHIFT));
821
822 return 0;
823}
824EXPORT_SYMBOL_GPL(wm8350_dcdc_set_slot);
825
826int wm8350_ldo_set_slot(struct wm8350 *wm8350, int ldo, u16 start, u16 stop)
827{
828 int slot_reg;
829 u16 val;
830
831 dev_dbg(wm8350->dev, "%s %d start %d stop %d\n",
832 __func__, ldo, start, stop);
833
834 /* slot valid ? */
835 if (start > 15 || stop > 15)
836 return -EINVAL;
837
838 switch (ldo) {
839 case WM8350_LDO_1:
840 slot_reg = WM8350_LDO1_TIMEOUTS;
841 break;
842 case WM8350_LDO_2:
843 slot_reg = WM8350_LDO2_TIMEOUTS;
844 break;
845 case WM8350_LDO_3:
846 slot_reg = WM8350_LDO3_TIMEOUTS;
847 break;
848 case WM8350_LDO_4:
849 slot_reg = WM8350_LDO4_TIMEOUTS;
850 break;
851 default:
852 return -EINVAL;
853 }
854
855 val = wm8350_reg_read(wm8350, slot_reg) & ~WM8350_LDO1_SDSLOT_MASK;
856 wm8350_reg_write(wm8350, slot_reg, val | ((start << 10) | (stop << 6)));
857 return 0;
858}
859EXPORT_SYMBOL_GPL(wm8350_ldo_set_slot);
860
861int wm8350_dcdc25_set_mode(struct wm8350 *wm8350, int dcdc, u16 mode,
862 u16 ilim, u16 ramp, u16 feedback)
863{
864 u16 val;
865
866 dev_dbg(wm8350->dev, "%s %d mode: %s %s\n", __func__, dcdc,
867 mode ? "normal" : "boost", ilim ? "low" : "normal");
868
869 switch (dcdc) {
870 case WM8350_DCDC_2:
871 val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL)
872 & ~(WM8350_DC2_MODE_MASK | WM8350_DC2_ILIM_MASK |
873 WM8350_DC2_RMP_MASK | WM8350_DC2_FBSRC_MASK);
874 wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val |
875 (mode << WM8350_DC2_MODE_SHIFT) |
876 (ilim << WM8350_DC2_ILIM_SHIFT) |
877 (ramp << WM8350_DC2_RMP_SHIFT) |
878 (feedback << WM8350_DC2_FBSRC_SHIFT));
879 break;
880 case WM8350_DCDC_5:
881 val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL)
882 & ~(WM8350_DC5_MODE_MASK | WM8350_DC5_ILIM_MASK |
883 WM8350_DC5_RMP_MASK | WM8350_DC5_FBSRC_MASK);
884 wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val |
885 (mode << WM8350_DC5_MODE_SHIFT) |
886 (ilim << WM8350_DC5_ILIM_SHIFT) |
887 (ramp << WM8350_DC5_RMP_SHIFT) |
888 (feedback << WM8350_DC5_FBSRC_SHIFT));
889 break;
890 default:
891 return -EINVAL;
892 }
893
894 return 0;
895}
896EXPORT_SYMBOL_GPL(wm8350_dcdc25_set_mode);
897
898static int wm8350_dcdc_enable(struct regulator_dev *rdev)
899{
900 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
901 int dcdc = rdev_get_id(rdev);
902 u16 shift;
903
904 if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
905 return -EINVAL;
906
907 shift = dcdc - WM8350_DCDC_1;
908 wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift);
909 return 0;
910}
911
912static int wm8350_dcdc_disable(struct regulator_dev *rdev)
913{
914 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
915 int dcdc = rdev_get_id(rdev);
916 u16 shift;
917
918 if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
919 return -EINVAL;
920
921 shift = dcdc - WM8350_DCDC_1;
922 wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift);
923
924 return 0;
925}
926
927static int wm8350_ldo_enable(struct regulator_dev *rdev)
928{
929 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
930 int ldo = rdev_get_id(rdev);
931 u16 shift;
932
933 if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4)
934 return -EINVAL;
935
936 shift = (ldo - WM8350_LDO_1) + 8;
937 wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift);
938 return 0;
939}
940
941static int wm8350_ldo_disable(struct regulator_dev *rdev)
942{
943 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
944 int ldo = rdev_get_id(rdev);
945 u16 shift;
946
947 if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4)
948 return -EINVAL;
949
950 shift = (ldo - WM8350_LDO_1) + 8;
951 wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift);
952 return 0;
953}
954
955static int force_continuous_enable(struct wm8350 *wm8350, int dcdc, int enable)
956{
957 int reg = 0, ret;
958
959 switch (dcdc) {
960 case WM8350_DCDC_1:
961 reg = WM8350_DCDC1_FORCE_PWM;
962 break;
963 case WM8350_DCDC_3:
964 reg = WM8350_DCDC3_FORCE_PWM;
965 break;
966 case WM8350_DCDC_4:
967 reg = WM8350_DCDC4_FORCE_PWM;
968 break;
969 case WM8350_DCDC_6:
970 reg = WM8350_DCDC6_FORCE_PWM;
971 break;
972 default:
973 return -EINVAL;
974 }
975
976 if (enable)
977 ret = wm8350_set_bits(wm8350, reg,
978 WM8350_DCDC1_FORCE_PWM_ENA);
979 else
980 ret = wm8350_clear_bits(wm8350, reg,
981 WM8350_DCDC1_FORCE_PWM_ENA);
982 return ret;
983}
984
985static int wm8350_dcdc_set_mode(struct regulator_dev *rdev, unsigned int mode)
986{
987 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
988 int dcdc = rdev_get_id(rdev);
989 u16 val;
990
991 if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
992 return -EINVAL;
993
994 if (dcdc == WM8350_DCDC_2 || dcdc == WM8350_DCDC_5)
995 return -EINVAL;
996
997 val = 1 << (dcdc - WM8350_DCDC_1);
998
999 switch (mode) {
1000 case REGULATOR_MODE_FAST:
1001 /* force continuous mode */
1002 wm8350_set_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val);
1003 wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val);
1004 force_continuous_enable(wm8350, dcdc, 1);
1005 break;
1006 case REGULATOR_MODE_NORMAL:
1007 /* active / pulse skipping */
1008 wm8350_set_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val);
1009 wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val);
1010 force_continuous_enable(wm8350, dcdc, 0);
1011 break;
1012 case REGULATOR_MODE_IDLE:
1013 /* standby mode */
1014 force_continuous_enable(wm8350, dcdc, 0);
1015 wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val);
1016 wm8350_clear_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val);
1017 break;
1018 case REGULATOR_MODE_STANDBY:
1019 /* LDO mode */
1020 force_continuous_enable(wm8350, dcdc, 0);
1021 wm8350_set_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val);
1022 break;
1023 }
1024
1025 return 0;
1026}
1027
1028static unsigned int wm8350_dcdc_get_mode(struct regulator_dev *rdev)
1029{
1030 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
1031 int dcdc = rdev_get_id(rdev);
1032 u16 mask, sleep, active, force;
1033 int mode = REGULATOR_MODE_NORMAL;
1034
1035 if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
1036 return -EINVAL;
1037
1038 if (dcdc == WM8350_DCDC_2 || dcdc == WM8350_DCDC_5)
1039 return -EINVAL;
1040
1041 mask = 1 << (dcdc - WM8350_DCDC_1);
1042 active = wm8350_reg_read(wm8350, WM8350_DCDC_ACTIVE_OPTIONS) & mask;
1043 sleep = wm8350_reg_read(wm8350, WM8350_DCDC_SLEEP_OPTIONS) & mask;
1044 force = wm8350_reg_read(wm8350, WM8350_DCDC1_FORCE_PWM)
1045 & WM8350_DCDC1_FORCE_PWM_ENA;
1046 dev_dbg(wm8350->dev, "mask %x active %x sleep %x force %x",
1047 mask, active, sleep, force);
1048
1049 if (active && !sleep) {
1050 if (force)
1051 mode = REGULATOR_MODE_FAST;
1052 else
1053 mode = REGULATOR_MODE_NORMAL;
1054 } else if (!active && !sleep)
1055 mode = REGULATOR_MODE_IDLE;
1056 else if (!sleep)
1057 mode = REGULATOR_MODE_STANDBY;
1058
1059 return mode;
1060}
1061
1062static unsigned int wm8350_ldo_get_mode(struct regulator_dev *rdev)
1063{
1064 return REGULATOR_MODE_NORMAL;
1065}
1066
1067struct wm8350_dcdc_efficiency {
1068 int uA_load_min;
1069 int uA_load_max;
1070 unsigned int mode;
1071};
1072
1073static const struct wm8350_dcdc_efficiency dcdc1_6_efficiency[] = {
1074 {0, 10000, REGULATOR_MODE_STANDBY}, /* 0 - 10mA - LDO */
1075 {10000, 100000, REGULATOR_MODE_IDLE}, /* 10mA - 100mA - Standby */
1076 {100000, 1000000, REGULATOR_MODE_NORMAL}, /* > 100mA - Active */
1077 {-1, -1, REGULATOR_MODE_NORMAL},
1078};
1079
1080static const struct wm8350_dcdc_efficiency dcdc3_4_efficiency[] = {
1081 {0, 10000, REGULATOR_MODE_STANDBY}, /* 0 - 10mA - LDO */
1082 {10000, 100000, REGULATOR_MODE_IDLE}, /* 10mA - 100mA - Standby */
1083 {100000, 800000, REGULATOR_MODE_NORMAL}, /* > 100mA - Active */
1084 {-1, -1, REGULATOR_MODE_NORMAL},
1085};
1086
1087static unsigned int get_mode(int uA, const struct wm8350_dcdc_efficiency *eff)
1088{
1089 int i = 0;
1090
1091 while (eff[i].uA_load_min != -1) {
1092 if (uA >= eff[i].uA_load_min && uA <= eff[i].uA_load_max)
1093 return eff[i].mode;
1094 }
1095 return REGULATOR_MODE_NORMAL;
1096}
1097
1098/* Query the regulator for it's most efficient mode @ uV,uA
1099 * WM8350 regulator efficiency is pretty similar over
1100 * different input and output uV.
1101 */
1102static unsigned int wm8350_dcdc_get_optimum_mode(struct regulator_dev *rdev,
1103 int input_uV, int output_uV,
1104 int output_uA)
1105{
1106 int dcdc = rdev_get_id(rdev), mode;
1107
1108 switch (dcdc) {
1109 case WM8350_DCDC_1:
1110 case WM8350_DCDC_6:
1111 mode = get_mode(output_uA, dcdc1_6_efficiency);
1112 break;
1113 case WM8350_DCDC_3:
1114 case WM8350_DCDC_4:
1115 mode = get_mode(output_uA, dcdc3_4_efficiency);
1116 break;
1117 default:
1118 mode = REGULATOR_MODE_NORMAL;
1119 break;
1120 }
1121 return mode;
1122}
1123
1124static int wm8350_dcdc_is_enabled(struct regulator_dev *rdev)
1125{
1126 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
1127 int dcdc = rdev_get_id(rdev), shift;
1128
1129 if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
1130 return -EINVAL;
1131
1132 shift = dcdc - WM8350_DCDC_1;
1133 return wm8350_reg_read(wm8350, WM8350_DCDC_LDO_REQUESTED)
1134 & (1 << shift);
1135}
1136
1137static int wm8350_ldo_is_enabled(struct regulator_dev *rdev)
1138{
1139 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
1140 int ldo = rdev_get_id(rdev), shift;
1141
1142 if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4)
1143 return -EINVAL;
1144
1145 shift = (ldo - WM8350_LDO_1) + 8;
1146 return wm8350_reg_read(wm8350, WM8350_DCDC_LDO_REQUESTED)
1147 & (1 << shift);
1148}
1149
1150static struct regulator_ops wm8350_dcdc_ops = {
1151 .set_voltage = wm8350_dcdc_set_voltage,
1152 .get_voltage = wm8350_dcdc_get_voltage,
1153 .enable = wm8350_dcdc_enable,
1154 .disable = wm8350_dcdc_disable,
1155 .get_mode = wm8350_dcdc_get_mode,
1156 .set_mode = wm8350_dcdc_set_mode,
1157 .get_optimum_mode = wm8350_dcdc_get_optimum_mode,
1158 .is_enabled = wm8350_dcdc_is_enabled,
1159 .set_suspend_voltage = wm8350_dcdc_set_suspend_voltage,
1160 .set_suspend_enable = wm8350_dcdc_set_suspend_enable,
1161 .set_suspend_disable = wm8350_dcdc_set_suspend_disable,
1162 .set_suspend_mode = wm8350_dcdc_set_suspend_mode,
1163};
1164
1165static struct regulator_ops wm8350_dcdc2_5_ops = {
1166 .enable = wm8350_dcdc_enable,
1167 .disable = wm8350_dcdc_disable,
1168 .is_enabled = wm8350_dcdc_is_enabled,
1169 .set_suspend_enable = wm8350_dcdc25_set_suspend_enable,
1170 .set_suspend_disable = wm8350_dcdc25_set_suspend_disable,
1171};
1172
1173static struct regulator_ops wm8350_ldo_ops = {
1174 .set_voltage = wm8350_ldo_set_voltage,
1175 .get_voltage = wm8350_ldo_get_voltage,
1176 .enable = wm8350_ldo_enable,
1177 .disable = wm8350_ldo_disable,
1178 .is_enabled = wm8350_ldo_is_enabled,
1179 .get_mode = wm8350_ldo_get_mode,
1180 .set_suspend_voltage = wm8350_ldo_set_suspend_voltage,
1181 .set_suspend_enable = wm8350_ldo_set_suspend_enable,
1182 .set_suspend_disable = wm8350_ldo_set_suspend_disable,
1183};
1184
1185static struct regulator_ops wm8350_isink_ops = {
1186 .set_current_limit = wm8350_isink_set_current,
1187 .get_current_limit = wm8350_isink_get_current,
1188 .enable = wm8350_isink_enable,
1189 .disable = wm8350_isink_disable,
1190 .is_enabled = wm8350_isink_is_enabled,
1191};
1192
1193static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
1194 {
1195 .name = "DCDC1",
1196 .id = WM8350_DCDC_1,
1197 .ops = &wm8350_dcdc_ops,
1198 .irq = WM8350_IRQ_UV_DC1,
1199 .type = REGULATOR_VOLTAGE,
1200 .owner = THIS_MODULE,
1201 },
1202 {
1203 .name = "DCDC2",
1204 .id = WM8350_DCDC_2,
1205 .ops = &wm8350_dcdc2_5_ops,
1206 .irq = WM8350_IRQ_UV_DC2,
1207 .type = REGULATOR_VOLTAGE,
1208 .owner = THIS_MODULE,
1209 },
1210 {
1211 .name = "DCDC3",
1212 .id = WM8350_DCDC_3,
1213 .ops = &wm8350_dcdc_ops,
1214 .irq = WM8350_IRQ_UV_DC3,
1215 .type = REGULATOR_VOLTAGE,
1216 .owner = THIS_MODULE,
1217 },
1218 {
1219 .name = "DCDC4",
1220 .id = WM8350_DCDC_4,
1221 .ops = &wm8350_dcdc_ops,
1222 .irq = WM8350_IRQ_UV_DC4,
1223 .type = REGULATOR_VOLTAGE,
1224 .owner = THIS_MODULE,
1225 },
1226 {
1227 .name = "DCDC5",
1228 .id = WM8350_DCDC_5,
1229 .ops = &wm8350_dcdc2_5_ops,
1230 .irq = WM8350_IRQ_UV_DC5,
1231 .type = REGULATOR_VOLTAGE,
1232 .owner = THIS_MODULE,
1233 },
1234 {
1235 .name = "DCDC6",
1236 .id = WM8350_DCDC_6,
1237 .ops = &wm8350_dcdc_ops,
1238 .irq = WM8350_IRQ_UV_DC6,
1239 .type = REGULATOR_VOLTAGE,
1240 .owner = THIS_MODULE,
1241 },
1242 {
1243 .name = "LDO1",
1244 .id = WM8350_LDO_1,
1245 .ops = &wm8350_ldo_ops,
1246 .irq = WM8350_IRQ_UV_LDO1,
1247 .type = REGULATOR_VOLTAGE,
1248 .owner = THIS_MODULE,
1249 },
1250 {
1251 .name = "LDO2",
1252 .id = WM8350_LDO_2,
1253 .ops = &wm8350_ldo_ops,
1254 .irq = WM8350_IRQ_UV_LDO2,
1255 .type = REGULATOR_VOLTAGE,
1256 .owner = THIS_MODULE,
1257 },
1258 {
1259 .name = "LDO3",
1260 .id = WM8350_LDO_3,
1261 .ops = &wm8350_ldo_ops,
1262 .irq = WM8350_IRQ_UV_LDO3,
1263 .type = REGULATOR_VOLTAGE,
1264 .owner = THIS_MODULE,
1265 },
1266 {
1267 .name = "LDO4",
1268 .id = WM8350_LDO_4,
1269 .ops = &wm8350_ldo_ops,
1270 .irq = WM8350_IRQ_UV_LDO4,
1271 .type = REGULATOR_VOLTAGE,
1272 .owner = THIS_MODULE,
1273 },
1274 {
1275 .name = "ISINKA",
1276 .id = WM8350_ISINK_A,
1277 .ops = &wm8350_isink_ops,
1278 .irq = WM8350_IRQ_CS1,
1279 .type = REGULATOR_CURRENT,
1280 .owner = THIS_MODULE,
1281 },
1282 {
1283 .name = "ISINKB",
1284 .id = WM8350_ISINK_B,
1285 .ops = &wm8350_isink_ops,
1286 .irq = WM8350_IRQ_CS2,
1287 .type = REGULATOR_CURRENT,
1288 .owner = THIS_MODULE,
1289 },
1290};
1291
1292static void pmic_uv_handler(struct wm8350 *wm8350, int irq, void *data)
1293{
1294 struct regulator_dev *rdev = (struct regulator_dev *)data;
1295
1296 if (irq == WM8350_IRQ_CS1 || irq == WM8350_IRQ_CS2)
1297 regulator_notifier_call_chain(rdev,
1298 REGULATOR_EVENT_REGULATION_OUT,
1299 wm8350);
1300 else
1301 regulator_notifier_call_chain(rdev,
1302 REGULATOR_EVENT_UNDER_VOLTAGE,
1303 wm8350);
1304}
1305
1306static int wm8350_regulator_probe(struct platform_device *pdev)
1307{
1308 struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev);
1309 struct regulator_dev *rdev;
1310 int ret;
1311 u16 val;
1312
1313 if (pdev->id < WM8350_DCDC_1 || pdev->id > WM8350_ISINK_B)
1314 return -ENODEV;
1315
1316 /* do any regulatior specific init */
1317 switch (pdev->id) {
1318 case WM8350_DCDC_1:
1319 val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER);
1320 wm8350->pmic.dcdc1_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
1321 break;
1322 case WM8350_DCDC_3:
1323 val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER);
1324 wm8350->pmic.dcdc3_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
1325 break;
1326 case WM8350_DCDC_4:
1327 val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER);
1328 wm8350->pmic.dcdc4_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
1329 break;
1330 case WM8350_DCDC_6:
1331 val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER);
1332 wm8350->pmic.dcdc6_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
1333 break;
1334 }
1335
1336
1337 /* register regulator */
1338 rdev = regulator_register(&wm8350_reg[pdev->id], &pdev->dev,
1339 dev_get_drvdata(&pdev->dev));
1340 if (IS_ERR(rdev)) {
1341 dev_err(&pdev->dev, "failed to register %s\n",
1342 wm8350_reg[pdev->id].name);
1343 return PTR_ERR(rdev);
1344 }
1345
1346 /* register regulator IRQ */
1347 ret = wm8350_register_irq(wm8350, wm8350_reg[pdev->id].irq,
1348 pmic_uv_handler, rdev);
1349 if (ret < 0) {
1350 regulator_unregister(rdev);
1351 dev_err(&pdev->dev, "failed to register regulator %s IRQ\n",
1352 wm8350_reg[pdev->id].name);
1353 return ret;
1354 }
1355
1356 wm8350_unmask_irq(wm8350, wm8350_reg[pdev->id].irq);
1357
1358 return 0;
1359}
1360
1361static int wm8350_regulator_remove(struct platform_device *pdev)
1362{
1363 struct regulator_dev *rdev = platform_get_drvdata(pdev);
1364 struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
1365
1366 wm8350_mask_irq(wm8350, wm8350_reg[pdev->id].irq);
1367 wm8350_free_irq(wm8350, wm8350_reg[pdev->id].irq);
1368
1369 regulator_unregister(rdev);
1370
1371 return 0;
1372}
1373
1374int wm8350_register_regulator(struct wm8350 *wm8350, int reg,
1375 struct regulator_init_data *initdata)
1376{
1377 struct platform_device *pdev;
1378 int ret;
1379
1380 if (wm8350->pmic.pdev[reg])
1381 return -EBUSY;
1382
1383 pdev = platform_device_alloc("wm8350-regulator", reg);
1384 if (!pdev)
1385 return -ENOMEM;
1386
1387 wm8350->pmic.pdev[reg] = pdev;
1388
1389 initdata->driver_data = wm8350;
1390
1391 pdev->dev.platform_data = initdata;
1392 pdev->dev.parent = wm8350->dev;
1393 platform_set_drvdata(pdev, wm8350);
1394
1395 ret = platform_device_add(pdev);
1396
1397 if (ret != 0) {
1398 dev_err(wm8350->dev, "Failed to register regulator %d: %d\n",
1399 reg, ret);
1400 platform_device_del(pdev);
1401 wm8350->pmic.pdev[reg] = NULL;
1402 }
1403
1404 return ret;
1405}
1406EXPORT_SYMBOL_GPL(wm8350_register_regulator);
1407
1408static struct platform_driver wm8350_regulator_driver = {
1409 .probe = wm8350_regulator_probe,
1410 .remove = wm8350_regulator_remove,
1411 .driver = {
1412 .name = "wm8350-regulator",
1413 },
1414};
1415
1416static int __init wm8350_regulator_init(void)
1417{
1418 return platform_driver_register(&wm8350_regulator_driver);
1419}
1420subsys_initcall(wm8350_regulator_init);
1421
1422static void __exit wm8350_regulator_exit(void)
1423{
1424 platform_driver_unregister(&wm8350_regulator_driver);
1425}
1426module_exit(wm8350_regulator_exit);
1427
1428/* Module information */
1429MODULE_AUTHOR("Liam Girdwood");
1430MODULE_DESCRIPTION("WM8350 voltage and current regulator driver");
1431MODULE_LICENSE("GPL");
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c
new file mode 100644
index 000000000000..48b372e038a8
--- /dev/null
+++ b/drivers/regulator/wm8400-regulator.c
@@ -0,0 +1,368 @@
1/*
2 * Regulator support for WM8400
3 *
4 * Copyright 2008 Wolfson Microelectronics PLC.
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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 the
11 * License, or (at your option) any later version.
12 *
13 */
14
15#include <linux/bug.h>
16#include <linux/err.h>
17#include <linux/kernel.h>
18#include <linux/regulator/driver.h>
19#include <linux/mfd/wm8400-private.h>
20
21static int wm8400_ldo_is_enabled(struct regulator_dev *dev)
22{
23 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
24 u16 val;
25
26 val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev));
27 return (val & WM8400_LDO1_ENA) != 0;
28}
29
30static int wm8400_ldo_enable(struct regulator_dev *dev)
31{
32 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
33
34 return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev),
35 WM8400_LDO1_ENA, WM8400_LDO1_ENA);
36}
37
38static int wm8400_ldo_disable(struct regulator_dev *dev)
39{
40 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
41
42 return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev),
43 WM8400_LDO1_ENA, 0);
44}
45
46static int wm8400_ldo_get_voltage(struct regulator_dev *dev)
47{
48 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
49 u16 val;
50
51 val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev));
52 val &= WM8400_LDO1_VSEL_MASK;
53
54 if (val < 15)
55 return 900000 + (val * 50000);
56 else
57 return 1600000 + ((val - 14) * 100000);
58}
59
60static int wm8400_ldo_set_voltage(struct regulator_dev *dev,
61 int min_uV, int max_uV)
62{
63 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
64 u16 val;
65
66 if (min_uV < 900000 || min_uV > 3300000)
67 return -EINVAL;
68
69 if (min_uV < 1700000) {
70 /* Steps of 50mV from 900mV; */
71 val = (min_uV - 850001) / 50000;
72
73 if ((val * 50000) + 900000 > max_uV)
74 return -EINVAL;
75 BUG_ON((val * 50000) + 900000 < min_uV);
76 } else {
77 /* Steps of 100mV from 1700mV */
78 val = ((min_uV - 1600001) / 100000);
79
80 if ((val * 100000) + 1700000 > max_uV)
81 return -EINVAL;
82 BUG_ON((val * 100000) + 1700000 < min_uV);
83
84 val += 0xf;
85 }
86
87 return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev),
88 WM8400_LDO1_VSEL_MASK, val);
89}
90
91static struct regulator_ops wm8400_ldo_ops = {
92 .is_enabled = wm8400_ldo_is_enabled,
93 .enable = wm8400_ldo_enable,
94 .disable = wm8400_ldo_disable,
95 .get_voltage = wm8400_ldo_get_voltage,
96 .set_voltage = wm8400_ldo_set_voltage,
97};
98
99static int wm8400_dcdc_is_enabled(struct regulator_dev *dev)
100{
101 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
102 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
103 u16 val;
104
105 val = wm8400_reg_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset);
106 return (val & WM8400_DC1_ENA) != 0;
107}
108
109static int wm8400_dcdc_enable(struct regulator_dev *dev)
110{
111 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
112 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
113
114 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
115 WM8400_DC1_ENA, WM8400_DC1_ENA);
116}
117
118static int wm8400_dcdc_disable(struct regulator_dev *dev)
119{
120 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
121 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
122
123 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
124 WM8400_DC1_ENA, 0);
125}
126
127static int wm8400_dcdc_get_voltage(struct regulator_dev *dev)
128{
129 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
130 u16 val;
131 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
132
133 val = wm8400_reg_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset);
134 val &= WM8400_DC1_VSEL_MASK;
135
136 return 850000 + (25000 * val);
137}
138
139static int wm8400_dcdc_set_voltage(struct regulator_dev *dev,
140 int min_uV, int max_uV)
141{
142 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
143 u16 val;
144 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
145
146 if (min_uV < 850000)
147 return -EINVAL;
148
149 val = (min_uV - 825001) / 25000;
150
151 if (850000 + (25000 * val) > max_uV)
152 return -EINVAL;
153 BUG_ON(850000 + (25000 * val) < min_uV);
154
155 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
156 WM8400_DC1_VSEL_MASK, val);
157}
158
159static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev)
160{
161 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
162 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
163 u16 data[2];
164 int ret;
165
166 ret = wm8400_block_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset, 2,
167 data);
168 if (ret != 0)
169 return 0;
170
171 /* Datasheet: hibernate */
172 if (data[0] & WM8400_DC1_SLEEP)
173 return REGULATOR_MODE_STANDBY;
174
175 /* Datasheet: standby */
176 if (!(data[0] & WM8400_DC1_ACTIVE))
177 return REGULATOR_MODE_IDLE;
178
179 /* Datasheet: active with or without force PWM */
180 if (data[1] & WM8400_DC1_FRC_PWM)
181 return REGULATOR_MODE_FAST;
182 else
183 return REGULATOR_MODE_NORMAL;
184}
185
186static int wm8400_dcdc_set_mode(struct regulator_dev *dev, unsigned int mode)
187{
188 struct wm8400 *wm8400 = rdev_get_drvdata(dev);
189 int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
190 int ret;
191
192 switch (mode) {
193 case REGULATOR_MODE_FAST:
194 /* Datasheet: active with force PWM */
195 ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_2 + offset,
196 WM8400_DC1_FRC_PWM, WM8400_DC1_FRC_PWM);
197 if (ret != 0)
198 return ret;
199
200 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
201 WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP,
202 WM8400_DC1_ACTIVE);
203
204 case REGULATOR_MODE_NORMAL:
205 /* Datasheet: active */
206 ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_2 + offset,
207 WM8400_DC1_FRC_PWM, 0);
208 if (ret != 0)
209 return ret;
210
211 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
212 WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP,
213 WM8400_DC1_ACTIVE);
214
215 case REGULATOR_MODE_IDLE:
216 /* Datasheet: standby */
217 ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
218 WM8400_DC1_ACTIVE, 0);
219 if (ret != 0)
220 return ret;
221 return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
222 WM8400_DC1_SLEEP, 0);
223
224 default:
225 return -EINVAL;
226 }
227}
228
229static unsigned int wm8400_dcdc_get_optimum_mode(struct regulator_dev *dev,
230 int input_uV, int output_uV,
231 int load_uA)
232{
233 return REGULATOR_MODE_NORMAL;
234}
235
236static struct regulator_ops wm8400_dcdc_ops = {
237 .is_enabled = wm8400_dcdc_is_enabled,
238 .enable = wm8400_dcdc_enable,
239 .disable = wm8400_dcdc_disable,
240 .get_voltage = wm8400_dcdc_get_voltage,
241 .set_voltage = wm8400_dcdc_set_voltage,
242 .get_mode = wm8400_dcdc_get_mode,
243 .set_mode = wm8400_dcdc_set_mode,
244 .get_optimum_mode = wm8400_dcdc_get_optimum_mode,
245};
246
247static struct regulator_desc regulators[] = {
248 {
249 .name = "LDO1",
250 .id = WM8400_LDO1,
251 .ops = &wm8400_ldo_ops,
252 .type = REGULATOR_VOLTAGE,
253 .owner = THIS_MODULE,
254 },
255 {
256 .name = "LDO2",
257 .id = WM8400_LDO2,
258 .ops = &wm8400_ldo_ops,
259 .type = REGULATOR_VOLTAGE,
260 .owner = THIS_MODULE,
261 },
262 {
263 .name = "LDO3",
264 .id = WM8400_LDO3,
265 .ops = &wm8400_ldo_ops,
266 .type = REGULATOR_VOLTAGE,
267 .owner = THIS_MODULE,
268 },
269 {
270 .name = "LDO4",
271 .id = WM8400_LDO4,
272 .ops = &wm8400_ldo_ops,
273 .type = REGULATOR_VOLTAGE,
274 .owner = THIS_MODULE,
275 },
276 {
277 .name = "DCDC1",
278 .id = WM8400_DCDC1,
279 .ops = &wm8400_dcdc_ops,
280 .type = REGULATOR_VOLTAGE,
281 .owner = THIS_MODULE,
282 },
283 {
284 .name = "DCDC2",
285 .id = WM8400_DCDC2,
286 .ops = &wm8400_dcdc_ops,
287 .type = REGULATOR_VOLTAGE,
288 .owner = THIS_MODULE,
289 },
290};
291
292static int __init wm8400_regulator_probe(struct platform_device *pdev)
293{
294 struct regulator_dev *rdev;
295
296 rdev = regulator_register(&regulators[pdev->id], &pdev->dev,
297 pdev->dev.driver_data);
298
299 if (IS_ERR(rdev))
300 return PTR_ERR(rdev);
301
302 return 0;
303}
304
305static int __devexit wm8400_regulator_remove(struct platform_device *pdev)
306{
307 struct regulator_dev *rdev = platform_get_drvdata(pdev);
308
309 regulator_unregister(rdev);
310
311 return 0;
312}
313
314static struct platform_driver wm8400_regulator_driver = {
315 .driver = {
316 .name = "wm8400-regulator",
317 },
318 .probe = wm8400_regulator_probe,
319 .remove = __devexit_p(wm8400_regulator_remove),
320};
321
322/**
323 * wm8400_register_regulator - enable software control of a WM8400 regulator
324 *
325 * This function enables software control of a WM8400 regulator via
326 * the regulator API. It is intended to be called from the
327 * platform_init() callback of the WM8400 MFD driver.
328 *
329 * @param dev The WM8400 device to operate on.
330 * @param reg The regulator to control.
331 * @param initdata Regulator initdata for the regulator.
332 */
333int wm8400_register_regulator(struct device *dev, int reg,
334 struct regulator_init_data *initdata)
335{
336 struct wm8400 *wm8400 = dev->driver_data;
337
338 if (wm8400->regulators[reg].name)
339 return -EBUSY;
340
341 initdata->driver_data = wm8400;
342
343 wm8400->regulators[reg].name = "wm8400-regulator";
344 wm8400->regulators[reg].id = reg;
345 wm8400->regulators[reg].dev.parent = dev;
346 wm8400->regulators[reg].dev.driver_data = wm8400;
347 wm8400->regulators[reg].dev.platform_data = initdata;
348
349 return platform_device_register(&wm8400->regulators[reg]);
350}
351EXPORT_SYMBOL_GPL(wm8400_register_regulator);
352
353static int __init wm8400_regulator_init(void)
354{
355 return platform_driver_register(&wm8400_regulator_driver);
356}
357module_init(wm8400_regulator_init);
358
359static void __exit wm8400_regulator_exit(void)
360{
361 platform_driver_unregister(&wm8400_regulator_driver);
362}
363module_exit(wm8400_regulator_exit);
364
365MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
366MODULE_DESCRIPTION("WM8400 regulator driver");
367MODULE_LICENSE("GPL");
368MODULE_ALIAS("platform:wm8400-regulator");
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index b57fba5c6d02..f660ef3e5b29 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -220,22 +220,22 @@ config RTC_DRV_PCF8583
220 will be called rtc-pcf8583. 220 will be called rtc-pcf8583.
221 221
222config RTC_DRV_M41T80 222config RTC_DRV_M41T80
223 tristate "ST M41T80/81/82/83/84/85/87" 223 tristate "ST M41T65/M41T80/81/82/83/84/85/87"
224 help 224 help
225 If you say Y here you will get support for the 225 If you say Y here you will get support for the ST M41T60
226 ST M41T80 RTC chips series. Currently following chips are 226 and M41T80 RTC chips series. Currently, the following chips are
227 supported: M41T80, M41T81, M41T82, M41T83, M41ST84, M41ST85 227 supported: M41T65, M41T80, M41T81, M41T82, M41T83, M41ST84,
228 and M41ST87. 228 M41ST85, and M41ST87.
229 229
230 This driver can also be built as a module. If so, the module 230 This driver can also be built as a module. If so, the module
231 will be called rtc-m41t80. 231 will be called rtc-m41t80.
232 232
233config RTC_DRV_M41T80_WDT 233config RTC_DRV_M41T80_WDT
234 bool "ST M41T80 series RTC watchdog timer" 234 bool "ST M41T65/M41T80 series RTC watchdog timer"
235 depends on RTC_DRV_M41T80 235 depends on RTC_DRV_M41T80
236 help 236 help
237 If you say Y here you will get support for the 237 If you say Y here you will get support for the
238 watchdog timer in ST M41T80 RTC chips series. 238 watchdog timer in the ST M41T60 and M41T80 RTC chips series.
239 239
240config RTC_DRV_TWL92330 240config RTC_DRV_TWL92330
241 boolean "TI TWL92330/Menelaus" 241 boolean "TI TWL92330/Menelaus"
@@ -319,6 +319,15 @@ config RTC_DRV_RS5C348
319 This driver can also be built as a module. If so, the module 319 This driver can also be built as a module. If so, the module
320 will be called rtc-rs5c348. 320 will be called rtc-rs5c348.
321 321
322config RTC_DRV_DS3234
323 tristate "Maxim/Dallas DS3234"
324 help
325 If you say yes here you get support for the
326 Maxim/Dallas DS3234 SPI RTC chip.
327
328 This driver can also be built as a module. If so, the module
329 will be called rtc-ds3234.
330
322endif # SPI_MASTER 331endif # SPI_MASTER
323 332
324comment "Platform RTC drivers" 333comment "Platform RTC drivers"
@@ -352,6 +361,11 @@ config RTC_DRV_DS1216
352 help 361 help
353 If you say yes here you get support for the Dallas DS1216 RTC chips. 362 If you say yes here you get support for the Dallas DS1216 RTC chips.
354 363
364config RTC_DRV_DS1286
365 tristate "Dallas DS1286"
366 help
367 If you say yes here you get support for the Dallas DS1286 RTC chips.
368
355config RTC_DRV_DS1302 369config RTC_DRV_DS1302
356 tristate "Dallas DS1302" 370 tristate "Dallas DS1302"
357 depends on SH_SECUREEDGE5410 371 depends on SH_SECUREEDGE5410
@@ -405,6 +419,15 @@ config RTC_DRV_M48T86
405 This driver can also be built as a module. If so, the module 419 This driver can also be built as a module. If so, the module
406 will be called rtc-m48t86. 420 will be called rtc-m48t86.
407 421
422config RTC_DRV_M48T35
423 tristate "ST M48T35"
424 help
425 If you say Y here you will get support for the
426 ST M48T35 RTC chip.
427
428 This driver can also be built as a module, if so, the module
429 will be called "rtc-m48t35".
430
408config RTC_DRV_M48T59 431config RTC_DRV_M48T59
409 tristate "ST M48T59/M48T08/M48T02" 432 tristate "ST M48T59/M48T08/M48T02"
410 help 433 help
@@ -589,7 +612,7 @@ config RTC_DRV_RS5C313
589 612
590config RTC_DRV_PPC 613config RTC_DRV_PPC
591 tristate "PowerPC machine dependent RTC support" 614 tristate "PowerPC machine dependent RTC support"
592 depends on PPC_MERGE 615 depends on PPC
593 help 616 help
594 The PowerPC kernel has machine-specific functions for accessing 617 The PowerPC kernel has machine-specific functions for accessing
595 the RTC. This exposes that functionality through the generic RTC 618 the RTC. This exposes that functionality through the generic RTC
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index 10f41f85c38a..d05928b3ca94 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_RTC_DRV_AT91SAM9) += rtc-at91sam9.o
23obj-$(CONFIG_RTC_DRV_BFIN) += rtc-bfin.o 23obj-$(CONFIG_RTC_DRV_BFIN) += rtc-bfin.o
24obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o 24obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
25obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o 25obj-$(CONFIG_RTC_DRV_DS1216) += rtc-ds1216.o
26obj-$(CONFIG_RTC_DRV_DS1286) += rtc-ds1286.o
26obj-$(CONFIG_RTC_DRV_DS1302) += rtc-ds1302.o 27obj-$(CONFIG_RTC_DRV_DS1302) += rtc-ds1302.o
27obj-$(CONFIG_RTC_DRV_DS1305) += rtc-ds1305.o 28obj-$(CONFIG_RTC_DRV_DS1305) += rtc-ds1305.o
28obj-$(CONFIG_RTC_DRV_DS1307) += rtc-ds1307.o 29obj-$(CONFIG_RTC_DRV_DS1307) += rtc-ds1307.o
@@ -31,11 +32,13 @@ obj-$(CONFIG_RTC_DRV_DS1511) += rtc-ds1511.o
31obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o 32obj-$(CONFIG_RTC_DRV_DS1553) += rtc-ds1553.o
32obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o 33obj-$(CONFIG_RTC_DRV_DS1672) += rtc-ds1672.o
33obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o 34obj-$(CONFIG_RTC_DRV_DS1742) += rtc-ds1742.o
35obj-$(CONFIG_RTC_DRV_DS3234) += rtc-ds3234.o
34obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o 36obj-$(CONFIG_RTC_DRV_EP93XX) += rtc-ep93xx.o
35obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o 37obj-$(CONFIG_RTC_DRV_FM3130) += rtc-fm3130.o
36obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o 38obj-$(CONFIG_RTC_DRV_ISL1208) += rtc-isl1208.o
37obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o 39obj-$(CONFIG_RTC_DRV_M41T80) += rtc-m41t80.o
38obj-$(CONFIG_RTC_DRV_M41T94) += rtc-m41t94.o 40obj-$(CONFIG_RTC_DRV_M41T94) += rtc-m41t94.o
41obj-$(CONFIG_RTC_DRV_M48T35) += rtc-m48t35.o
39obj-$(CONFIG_RTC_DRV_M48T59) += rtc-m48t59.o 42obj-$(CONFIG_RTC_DRV_M48T59) += rtc-m48t59.o
40obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o 43obj-$(CONFIG_RTC_DRV_M48T86) += rtc-m48t86.o
41obj-$(CONFIG_RTC_DRV_BQ4802) += rtc-bq4802.o 44obj-$(CONFIG_RTC_DRV_BQ4802) += rtc-bq4802.o
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index 4e888cc8be5b..37082616482b 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -29,10 +29,10 @@
29#include <linux/completion.h> 29#include <linux/completion.h>
30 30
31#include <asm/uaccess.h> 31#include <asm/uaccess.h>
32
32#include <mach/at91_rtc.h> 33#include <mach/at91_rtc.h>
33 34
34 35
35#define AT91_RTC_FREQ 1
36#define AT91_RTC_EPOCH 1900UL /* just like arch/arm/common/rtctime.c */ 36#define AT91_RTC_EPOCH 1900UL /* just like arch/arm/common/rtctime.c */
37 37
38static DECLARE_COMPLETION(at91_rtc_updated); 38static DECLARE_COMPLETION(at91_rtc_updated);
@@ -228,8 +228,6 @@ static int at91_rtc_proc(struct device *dev, struct seq_file *seq)
228 (imr & AT91_RTC_ACKUPD) ? "yes" : "no"); 228 (imr & AT91_RTC_ACKUPD) ? "yes" : "no");
229 seq_printf(seq, "periodic_IRQ\t: %s\n", 229 seq_printf(seq, "periodic_IRQ\t: %s\n",
230 (imr & AT91_RTC_SECEV) ? "yes" : "no"); 230 (imr & AT91_RTC_SECEV) ? "yes" : "no");
231 seq_printf(seq, "periodic_freq\t: %ld\n",
232 (unsigned long) AT91_RTC_FREQ);
233 231
234 return 0; 232 return 0;
235} 233}
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index b23af0c2a869..963ad0b6a4e9 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -913,6 +913,92 @@ static inline int cmos_poweroff(struct device *dev)
913 * predate even PNPBIOS should set up platform_bus devices. 913 * predate even PNPBIOS should set up platform_bus devices.
914 */ 914 */
915 915
916#ifdef CONFIG_ACPI
917
918#include <linux/acpi.h>
919
920#ifdef CONFIG_PM
921static u32 rtc_handler(void *context)
922{
923 acpi_clear_event(ACPI_EVENT_RTC);
924 acpi_disable_event(ACPI_EVENT_RTC, 0);
925 return ACPI_INTERRUPT_HANDLED;
926}
927
928static inline void rtc_wake_setup(void)
929{
930 acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL);
931 /*
932 * After the RTC handler is installed, the Fixed_RTC event should
933 * be disabled. Only when the RTC alarm is set will it be enabled.
934 */
935 acpi_clear_event(ACPI_EVENT_RTC);
936 acpi_disable_event(ACPI_EVENT_RTC, 0);
937}
938
939static void rtc_wake_on(struct device *dev)
940{
941 acpi_clear_event(ACPI_EVENT_RTC);
942 acpi_enable_event(ACPI_EVENT_RTC, 0);
943}
944
945static void rtc_wake_off(struct device *dev)
946{
947 acpi_disable_event(ACPI_EVENT_RTC, 0);
948}
949#else
950#define rtc_wake_setup() do{}while(0)
951#define rtc_wake_on NULL
952#define rtc_wake_off NULL
953#endif
954
955/* Every ACPI platform has a mc146818 compatible "cmos rtc". Here we find
956 * its device node and pass extra config data. This helps its driver use
957 * capabilities that the now-obsolete mc146818 didn't have, and informs it
958 * that this board's RTC is wakeup-capable (per ACPI spec).
959 */
960static struct cmos_rtc_board_info acpi_rtc_info;
961
962static void __devinit
963cmos_wake_setup(struct device *dev)
964{
965 if (acpi_disabled)
966 return;
967
968 rtc_wake_setup();
969 acpi_rtc_info.wake_on = rtc_wake_on;
970 acpi_rtc_info.wake_off = rtc_wake_off;
971
972 /* workaround bug in some ACPI tables */
973 if (acpi_gbl_FADT.month_alarm && !acpi_gbl_FADT.day_alarm) {
974 dev_dbg(dev, "bogus FADT month_alarm (%d)\n",
975 acpi_gbl_FADT.month_alarm);
976 acpi_gbl_FADT.month_alarm = 0;
977 }
978
979 acpi_rtc_info.rtc_day_alarm = acpi_gbl_FADT.day_alarm;
980 acpi_rtc_info.rtc_mon_alarm = acpi_gbl_FADT.month_alarm;
981 acpi_rtc_info.rtc_century = acpi_gbl_FADT.century;
982
983 /* NOTE: S4_RTC_WAKE is NOT currently useful to Linux */
984 if (acpi_gbl_FADT.flags & ACPI_FADT_S4_RTC_WAKE)
985 dev_info(dev, "RTC can wake from S4\n");
986
987 dev->platform_data = &acpi_rtc_info;
988
989 /* RTC always wakes from S1/S2/S3, and often S4/STD */
990 device_init_wakeup(dev, 1);
991}
992
993#else
994
995static void __devinit
996cmos_wake_setup(struct device *dev)
997{
998}
999
1000#endif
1001
916#ifdef CONFIG_PNP 1002#ifdef CONFIG_PNP
917 1003
918#include <linux/pnp.h> 1004#include <linux/pnp.h>
@@ -920,6 +1006,8 @@ static inline int cmos_poweroff(struct device *dev)
920static int __devinit 1006static int __devinit
921cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id) 1007cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
922{ 1008{
1009 cmos_wake_setup(&pnp->dev);
1010
923 if (pnp_port_start(pnp,0) == 0x70 && !pnp_irq_valid(pnp,0)) 1011 if (pnp_port_start(pnp,0) == 0x70 && !pnp_irq_valid(pnp,0))
924 /* Some machines contain a PNP entry for the RTC, but 1012 /* Some machines contain a PNP entry for the RTC, but
925 * don't define the IRQ. It should always be safe to 1013 * don't define the IRQ. It should always be safe to
@@ -997,6 +1085,7 @@ static struct pnp_driver cmos_pnp_driver = {
997 1085
998static int __init cmos_platform_probe(struct platform_device *pdev) 1086static int __init cmos_platform_probe(struct platform_device *pdev)
999{ 1087{
1088 cmos_wake_setup(&pdev->dev);
1000 return cmos_do_probe(&pdev->dev, 1089 return cmos_do_probe(&pdev->dev,
1001 platform_get_resource(pdev, IORESOURCE_IO, 0), 1090 platform_get_resource(pdev, IORESOURCE_IO, 0),
1002 platform_get_irq(pdev, 0)); 1091 platform_get_irq(pdev, 0));
@@ -1031,29 +1120,32 @@ static struct platform_driver cmos_platform_driver = {
1031 1120
1032static int __init cmos_init(void) 1121static int __init cmos_init(void)
1033{ 1122{
1123 int retval = 0;
1124
1034#ifdef CONFIG_PNP 1125#ifdef CONFIG_PNP
1035 if (pnp_platform_devices) 1126 pnp_register_driver(&cmos_pnp_driver);
1036 return pnp_register_driver(&cmos_pnp_driver); 1127#endif
1037 else 1128
1038 return platform_driver_probe(&cmos_platform_driver, 1129 if (!cmos_rtc.dev)
1039 cmos_platform_probe); 1130 retval = platform_driver_probe(&cmos_platform_driver,
1040#else 1131 cmos_platform_probe);
1041 return platform_driver_probe(&cmos_platform_driver, 1132
1042 cmos_platform_probe); 1133 if (retval == 0)
1043#endif /* CONFIG_PNP */ 1134 return 0;
1135
1136#ifdef CONFIG_PNP
1137 pnp_unregister_driver(&cmos_pnp_driver);
1138#endif
1139 return retval;
1044} 1140}
1045module_init(cmos_init); 1141module_init(cmos_init);
1046 1142
1047static void __exit cmos_exit(void) 1143static void __exit cmos_exit(void)
1048{ 1144{
1049#ifdef CONFIG_PNP 1145#ifdef CONFIG_PNP
1050 if (pnp_platform_devices) 1146 pnp_unregister_driver(&cmos_pnp_driver);
1051 pnp_unregister_driver(&cmos_pnp_driver); 1147#endif
1052 else
1053 platform_driver_unregister(&cmos_platform_driver);
1054#else
1055 platform_driver_unregister(&cmos_platform_driver); 1148 platform_driver_unregister(&cmos_platform_driver);
1056#endif /* CONFIG_PNP */
1057} 1149}
1058module_exit(cmos_exit); 1150module_exit(cmos_exit);
1059 1151
diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
index 52e2743b04ec..079e9ed907e0 100644
--- a/drivers/rtc/rtc-dev.c
+++ b/drivers/rtc/rtc-dev.c
@@ -432,9 +432,15 @@ static int rtc_dev_release(struct inode *inode, struct file *file)
432{ 432{
433 struct rtc_device *rtc = file->private_data; 433 struct rtc_device *rtc = file->private_data;
434 434
435#ifdef CONFIG_RTC_INTF_DEV_UIE_EMUL 435 /* We shut down the repeating IRQs that userspace enabled,
436 clear_uie(rtc); 436 * since nothing is listening to them.
437#endif 437 * - Update (UIE) ... currently only managed through ioctls
438 * - Periodic (PIE) ... also used through rtc_*() interface calls
439 *
440 * Leave the alarm alone; it may be set to trigger a system wakeup
441 * later, or be used by kernel code, and is a one-shot event anyway.
442 */
443 rtc_dev_ioctl(file, RTC_UIE_OFF, 0);
438 rtc_irq_set_state(rtc, NULL, 0); 444 rtc_irq_set_state(rtc, NULL, 0);
439 445
440 if (rtc->ops->release) 446 if (rtc->ops->release)
diff --git a/drivers/rtc/rtc-ds1286.c b/drivers/rtc/rtc-ds1286.c
new file mode 100644
index 000000000000..4fcb16bbff4a
--- /dev/null
+++ b/drivers/rtc/rtc-ds1286.c
@@ -0,0 +1,410 @@
1/*
2 * DS1286 Real Time Clock interface for Linux
3 *
4 * Copyright (C) 1998, 1999, 2000 Ralf Baechle
5 * Copyright (C) 2008 Thomas Bogendoerfer
6 *
7 * Based on code written by Paul Gortmaker.
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
15#include <linux/module.h>
16#include <linux/rtc.h>
17#include <linux/platform_device.h>
18#include <linux/bcd.h>
19#include <linux/ds1286.h>
20#include <linux/io.h>
21
22#define DRV_VERSION "1.0"
23
24struct ds1286_priv {
25 struct rtc_device *rtc;
26 u32 __iomem *rtcregs;
27 size_t size;
28 unsigned long baseaddr;
29 spinlock_t lock;
30};
31
32static inline u8 ds1286_rtc_read(struct ds1286_priv *priv, int reg)
33{
34 return __raw_readl(&priv->rtcregs[reg]) & 0xff;
35}
36
37static inline void ds1286_rtc_write(struct ds1286_priv *priv, u8 data, int reg)
38{
39 __raw_writel(data, &priv->rtcregs[reg]);
40}
41
42#ifdef CONFIG_RTC_INTF_DEV
43
44static int ds1286_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
45{
46 struct ds1286_priv *priv = dev_get_drvdata(dev);
47 unsigned long flags;
48 unsigned char val;
49
50 switch (cmd) {
51 case RTC_AIE_OFF:
52 /* Mask alarm int. enab. bit */
53 spin_lock_irqsave(&priv->lock, flags);
54 val = ds1286_rtc_read(priv, RTC_CMD);
55 val |= RTC_TDM;
56 ds1286_rtc_write(priv, val, RTC_CMD);
57 spin_unlock_irqrestore(&priv->lock, flags);
58 break;
59 case RTC_AIE_ON:
60 /* Allow alarm interrupts. */
61 spin_lock_irqsave(&priv->lock, flags);
62 val = ds1286_rtc_read(priv, RTC_CMD);
63 val &= ~RTC_TDM;
64 ds1286_rtc_write(priv, val, RTC_CMD);
65 spin_unlock_irqrestore(&priv->lock, flags);
66 break;
67 case RTC_WIE_OFF:
68 /* Mask watchdog int. enab. bit */
69 spin_lock_irqsave(&priv->lock, flags);
70 val = ds1286_rtc_read(priv, RTC_CMD);
71 val |= RTC_WAM;
72 ds1286_rtc_write(priv, val, RTC_CMD);
73 spin_unlock_irqrestore(&priv->lock, flags);
74 break;
75 case RTC_WIE_ON:
76 /* Allow watchdog interrupts. */
77 spin_lock_irqsave(&priv->lock, flags);
78 val = ds1286_rtc_read(priv, RTC_CMD);
79 val &= ~RTC_WAM;
80 ds1286_rtc_write(priv, val, RTC_CMD);
81 spin_unlock_irqrestore(&priv->lock, flags);
82 break;
83 default:
84 return -ENOIOCTLCMD;
85 }
86 return 0;
87}
88
89#else
90#define ds1286_ioctl NULL
91#endif
92
93#ifdef CONFIG_PROC_FS
94
95static int ds1286_proc(struct device *dev, struct seq_file *seq)
96{
97 struct ds1286_priv *priv = dev_get_drvdata(dev);
98 unsigned char month, cmd, amode;
99 const char *s;
100
101 month = ds1286_rtc_read(priv, RTC_MONTH);
102 seq_printf(seq,
103 "oscillator\t: %s\n"
104 "square_wave\t: %s\n",
105 (month & RTC_EOSC) ? "disabled" : "enabled",
106 (month & RTC_ESQW) ? "disabled" : "enabled");
107
108 amode = ((ds1286_rtc_read(priv, RTC_MINUTES_ALARM) & 0x80) >> 5) |
109 ((ds1286_rtc_read(priv, RTC_HOURS_ALARM) & 0x80) >> 6) |
110 ((ds1286_rtc_read(priv, RTC_DAY_ALARM) & 0x80) >> 7);
111 switch (amode) {
112 case 7:
113 s = "each minute";
114 break;
115 case 3:
116 s = "minutes match";
117 break;
118 case 1:
119 s = "hours and minutes match";
120 break;
121 case 0:
122 s = "days, hours and minutes match";
123 break;
124 default:
125 s = "invalid";
126 break;
127 }
128 seq_printf(seq, "alarm_mode\t: %s\n", s);
129
130 cmd = ds1286_rtc_read(priv, RTC_CMD);
131 seq_printf(seq,
132 "alarm_enable\t: %s\n"
133 "wdog_alarm\t: %s\n"
134 "alarm_mask\t: %s\n"
135 "wdog_alarm_mask\t: %s\n"
136 "interrupt_mode\t: %s\n"
137 "INTB_mode\t: %s_active\n"
138 "interrupt_pins\t: %s\n",
139 (cmd & RTC_TDF) ? "yes" : "no",
140 (cmd & RTC_WAF) ? "yes" : "no",
141 (cmd & RTC_TDM) ? "disabled" : "enabled",
142 (cmd & RTC_WAM) ? "disabled" : "enabled",
143 (cmd & RTC_PU_LVL) ? "pulse" : "level",
144 (cmd & RTC_IBH_LO) ? "low" : "high",
145 (cmd & RTC_IPSW) ? "unswapped" : "swapped");
146 return 0;
147}
148
149#else
150#define ds1286_proc NULL
151#endif
152
153static int ds1286_read_time(struct device *dev, struct rtc_time *tm)
154{
155 struct ds1286_priv *priv = dev_get_drvdata(dev);
156 unsigned char save_control;
157 unsigned long flags;
158 unsigned long uip_watchdog = jiffies;
159
160 /*
161 * read RTC once any update in progress is done. The update
162 * can take just over 2ms. We wait 10 to 20ms. There is no need to
163 * to poll-wait (up to 1s - eeccch) for the falling edge of RTC_UIP.
164 * If you need to know *exactly* when a second has started, enable
165 * periodic update complete interrupts, (via ioctl) and then
166 * immediately read /dev/rtc which will block until you get the IRQ.
167 * Once the read clears, read the RTC time (again via ioctl). Easy.
168 */
169
170 if (ds1286_rtc_read(priv, RTC_CMD) & RTC_TE)
171 while (time_before(jiffies, uip_watchdog + 2*HZ/100))
172 barrier();
173
174 /*
175 * Only the values that we read from the RTC are set. We leave
176 * tm_wday, tm_yday and tm_isdst untouched. Even though the
177 * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated
178 * by the RTC when initially set to a non-zero value.
179 */
180 spin_lock_irqsave(&priv->lock, flags);
181 save_control = ds1286_rtc_read(priv, RTC_CMD);
182 ds1286_rtc_write(priv, (save_control|RTC_TE), RTC_CMD);
183
184 tm->tm_sec = ds1286_rtc_read(priv, RTC_SECONDS);
185 tm->tm_min = ds1286_rtc_read(priv, RTC_MINUTES);
186 tm->tm_hour = ds1286_rtc_read(priv, RTC_HOURS) & 0x3f;
187 tm->tm_mday = ds1286_rtc_read(priv, RTC_DATE);
188 tm->tm_mon = ds1286_rtc_read(priv, RTC_MONTH) & 0x1f;
189 tm->tm_year = ds1286_rtc_read(priv, RTC_YEAR);
190
191 ds1286_rtc_write(priv, save_control, RTC_CMD);
192 spin_unlock_irqrestore(&priv->lock, flags);
193
194 tm->tm_sec = bcd2bin(tm->tm_sec);
195 tm->tm_min = bcd2bin(tm->tm_min);
196 tm->tm_hour = bcd2bin(tm->tm_hour);
197 tm->tm_mday = bcd2bin(tm->tm_mday);
198 tm->tm_mon = bcd2bin(tm->tm_mon);
199 tm->tm_year = bcd2bin(tm->tm_year);
200
201 /*
202 * Account for differences between how the RTC uses the values
203 * and how they are defined in a struct rtc_time;
204 */
205 if (tm->tm_year < 45)
206 tm->tm_year += 30;
207 tm->tm_year += 40;
208 if (tm->tm_year < 70)
209 tm->tm_year += 100;
210
211 tm->tm_mon--;
212
213 return rtc_valid_tm(tm);
214}
215
216static int ds1286_set_time(struct device *dev, struct rtc_time *tm)
217{
218 struct ds1286_priv *priv = dev_get_drvdata(dev);
219 unsigned char mon, day, hrs, min, sec;
220 unsigned char save_control;
221 unsigned int yrs;
222 unsigned long flags;
223
224 yrs = tm->tm_year + 1900;
225 mon = tm->tm_mon + 1; /* tm_mon starts at zero */
226 day = tm->tm_mday;
227 hrs = tm->tm_hour;
228 min = tm->tm_min;
229 sec = tm->tm_sec;
230
231 if (yrs < 1970)
232 return -EINVAL;
233
234 yrs -= 1940;
235 if (yrs > 255) /* They are unsigned */
236 return -EINVAL;
237
238 if (yrs >= 100)
239 yrs -= 100;
240
241 sec = bin2bcd(sec);
242 min = bin2bcd(min);
243 hrs = bin2bcd(hrs);
244 day = bin2bcd(day);
245 mon = bin2bcd(mon);
246 yrs = bin2bcd(yrs);
247
248 spin_lock_irqsave(&priv->lock, flags);
249 save_control = ds1286_rtc_read(priv, RTC_CMD);
250 ds1286_rtc_write(priv, (save_control|RTC_TE), RTC_CMD);
251
252 ds1286_rtc_write(priv, yrs, RTC_YEAR);
253 ds1286_rtc_write(priv, mon, RTC_MONTH);
254 ds1286_rtc_write(priv, day, RTC_DATE);
255 ds1286_rtc_write(priv, hrs, RTC_HOURS);
256 ds1286_rtc_write(priv, min, RTC_MINUTES);
257 ds1286_rtc_write(priv, sec, RTC_SECONDS);
258 ds1286_rtc_write(priv, 0, RTC_HUNDREDTH_SECOND);
259
260 ds1286_rtc_write(priv, save_control, RTC_CMD);
261 spin_unlock_irqrestore(&priv->lock, flags);
262 return 0;
263}
264
265static int ds1286_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
266{
267 struct ds1286_priv *priv = dev_get_drvdata(dev);
268 unsigned char cmd;
269 unsigned long flags;
270
271 /*
272 * Only the values that we read from the RTC are set. That
273 * means only tm_wday, tm_hour, tm_min.
274 */
275 spin_lock_irqsave(&priv->lock, flags);
276 alm->time.tm_min = ds1286_rtc_read(priv, RTC_MINUTES_ALARM) & 0x7f;
277 alm->time.tm_hour = ds1286_rtc_read(priv, RTC_HOURS_ALARM) & 0x1f;
278 alm->time.tm_wday = ds1286_rtc_read(priv, RTC_DAY_ALARM) & 0x07;
279 cmd = ds1286_rtc_read(priv, RTC_CMD);
280 spin_unlock_irqrestore(&priv->lock, flags);
281
282 alm->time.tm_min = bcd2bin(alm->time.tm_min);
283 alm->time.tm_hour = bcd2bin(alm->time.tm_hour);
284 alm->time.tm_sec = 0;
285 return 0;
286}
287
288static int ds1286_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
289{
290 struct ds1286_priv *priv = dev_get_drvdata(dev);
291 unsigned char hrs, min, sec;
292
293 hrs = alm->time.tm_hour;
294 min = alm->time.tm_min;
295 sec = alm->time.tm_sec;
296
297 if (hrs >= 24)
298 hrs = 0xff;
299
300 if (min >= 60)
301 min = 0xff;
302
303 if (sec != 0)
304 return -EINVAL;
305
306 min = bin2bcd(min);
307 hrs = bin2bcd(hrs);
308
309 spin_lock(&priv->lock);
310 ds1286_rtc_write(priv, hrs, RTC_HOURS_ALARM);
311 ds1286_rtc_write(priv, min, RTC_MINUTES_ALARM);
312 spin_unlock(&priv->lock);
313
314 return 0;
315}
316
317static const struct rtc_class_ops ds1286_ops = {
318 .ioctl = ds1286_ioctl,
319 .proc = ds1286_proc,
320 .read_time = ds1286_read_time,
321 .set_time = ds1286_set_time,
322 .read_alarm = ds1286_read_alarm,
323 .set_alarm = ds1286_set_alarm,
324};
325
326static int __devinit ds1286_probe(struct platform_device *pdev)
327{
328 struct rtc_device *rtc;
329 struct resource *res;
330 struct ds1286_priv *priv;
331 int ret = 0;
332
333 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
334 if (!res)
335 return -ENODEV;
336 priv = kzalloc(sizeof(struct ds1286_priv), GFP_KERNEL);
337 if (!priv)
338 return -ENOMEM;
339
340 priv->size = res->end - res->start + 1;
341 if (!request_mem_region(res->start, priv->size, pdev->name)) {
342 ret = -EBUSY;
343 goto out;
344 }
345 priv->baseaddr = res->start;
346 priv->rtcregs = ioremap(priv->baseaddr, priv->size);
347 if (!priv->rtcregs) {
348 ret = -ENOMEM;
349 goto out;
350 }
351 spin_lock_init(&priv->lock);
352 rtc = rtc_device_register("ds1286", &pdev->dev,
353 &ds1286_ops, THIS_MODULE);
354 if (IS_ERR(rtc)) {
355 ret = PTR_ERR(rtc);
356 goto out;
357 }
358 priv->rtc = rtc;
359 platform_set_drvdata(pdev, priv);
360 return 0;
361
362out:
363 if (priv->rtc)
364 rtc_device_unregister(priv->rtc);
365 if (priv->rtcregs)
366 iounmap(priv->rtcregs);
367 if (priv->baseaddr)
368 release_mem_region(priv->baseaddr, priv->size);
369 kfree(priv);
370 return ret;
371}
372
373static int __devexit ds1286_remove(struct platform_device *pdev)
374{
375 struct ds1286_priv *priv = platform_get_drvdata(pdev);
376
377 rtc_device_unregister(priv->rtc);
378 iounmap(priv->rtcregs);
379 release_mem_region(priv->baseaddr, priv->size);
380 kfree(priv);
381 return 0;
382}
383
384static struct platform_driver ds1286_platform_driver = {
385 .driver = {
386 .name = "rtc-ds1286",
387 .owner = THIS_MODULE,
388 },
389 .probe = ds1286_probe,
390 .remove = __devexit_p(ds1286_remove),
391};
392
393static int __init ds1286_init(void)
394{
395 return platform_driver_register(&ds1286_platform_driver);
396}
397
398static void __exit ds1286_exit(void)
399{
400 platform_driver_unregister(&ds1286_platform_driver);
401}
402
403MODULE_AUTHOR("Thomas Bogendoerfer <tsbogend@alpha.franken.de>");
404MODULE_DESCRIPTION("DS1286 RTC driver");
405MODULE_LICENSE("GPL");
406MODULE_VERSION(DRV_VERSION);
407MODULE_ALIAS("platform:rtc-ds1286");
408
409module_init(ds1286_init);
410module_exit(ds1286_exit);
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index bbf97e65202a..4fcf0734a6ef 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -23,10 +23,6 @@
23 * to have set the chip up as a clock (turning on the oscillator and 23 * to have set the chip up as a clock (turning on the oscillator and
24 * setting the date and time), Linux can ignore the non-clock features. 24 * setting the date and time), Linux can ignore the non-clock features.
25 * That's a natural job for a factory or repair bench. 25 * That's a natural job for a factory or repair bench.
26 *
27 * This is currently a simple no-alarms driver. If your board has the
28 * alarm irq wired up on a ds1337 or ds1339, and you want to use that,
29 * then look at the rtc-rs5c372 driver for code to steal...
30 */ 26 */
31enum ds_type { 27enum ds_type {
32 ds_1307, 28 ds_1307,
@@ -67,6 +63,7 @@ enum ds_type {
67# define DS1307_BIT_RS0 0x01 63# define DS1307_BIT_RS0 0x01
68#define DS1337_REG_CONTROL 0x0e 64#define DS1337_REG_CONTROL 0x0e
69# define DS1337_BIT_nEOSC 0x80 65# define DS1337_BIT_nEOSC 0x80
66# define DS1339_BIT_BBSQI 0x20
70# define DS1337_BIT_RS2 0x10 67# define DS1337_BIT_RS2 0x10
71# define DS1337_BIT_RS1 0x08 68# define DS1337_BIT_RS1 0x08
72# define DS1337_BIT_INTCN 0x04 69# define DS1337_BIT_INTCN 0x04
@@ -83,19 +80,22 @@ enum ds_type {
83# define DS1337_BIT_OSF 0x80 80# define DS1337_BIT_OSF 0x80
84# define DS1337_BIT_A2I 0x02 81# define DS1337_BIT_A2I 0x02
85# define DS1337_BIT_A1I 0x01 82# define DS1337_BIT_A1I 0x01
83#define DS1339_REG_ALARM1_SECS 0x07
86#define DS1339_REG_TRICKLE 0x10 84#define DS1339_REG_TRICKLE 0x10
87 85
88 86
89 87
90struct ds1307 { 88struct ds1307 {
91 u8 reg_addr; 89 u8 reg_addr;
92 bool has_nvram; 90 u8 regs[11];
93 u8 regs[8];
94 enum ds_type type; 91 enum ds_type type;
92 unsigned long flags;
93#define HAS_NVRAM 0 /* bit 0 == sysfs file active */
94#define HAS_ALARM 1 /* bit 1 == irq claimed */
95 struct i2c_msg msg[2]; 95 struct i2c_msg msg[2];
96 struct i2c_client *client; 96 struct i2c_client *client;
97 struct i2c_client dev;
98 struct rtc_device *rtc; 97 struct rtc_device *rtc;
98 struct work_struct work;
99}; 99};
100 100
101struct chip_desc { 101struct chip_desc {
@@ -132,12 +132,79 @@ static const struct i2c_device_id ds1307_id[] = {
132}; 132};
133MODULE_DEVICE_TABLE(i2c, ds1307_id); 133MODULE_DEVICE_TABLE(i2c, ds1307_id);
134 134
135/*----------------------------------------------------------------------*/
136
137/*
138 * The IRQ logic includes a "real" handler running in IRQ context just
139 * long enough to schedule this workqueue entry. We need a task context
140 * to talk to the RTC, since I2C I/O calls require that; and disable the
141 * IRQ until we clear its status on the chip, so that this handler can
142 * work with any type of triggering (not just falling edge).
143 *
144 * The ds1337 and ds1339 both have two alarms, but we only use the first
145 * one (with a "seconds" field). For ds1337 we expect nINTA is our alarm
146 * signal; ds1339 chips have only one alarm signal.
147 */
148static void ds1307_work(struct work_struct *work)
149{
150 struct ds1307 *ds1307;
151 struct i2c_client *client;
152 struct mutex *lock;
153 int stat, control;
154
155 ds1307 = container_of(work, struct ds1307, work);
156 client = ds1307->client;
157 lock = &ds1307->rtc->ops_lock;
158
159 mutex_lock(lock);
160 stat = i2c_smbus_read_byte_data(client, DS1337_REG_STATUS);
161 if (stat < 0)
162 goto out;
163
164 if (stat & DS1337_BIT_A1I) {
165 stat &= ~DS1337_BIT_A1I;
166 i2c_smbus_write_byte_data(client, DS1337_REG_STATUS, stat);
167
168 control = i2c_smbus_read_byte_data(client, DS1337_REG_CONTROL);
169 if (control < 0)
170 goto out;
171
172 control &= ~DS1337_BIT_A1IE;
173 i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, control);
174
175 /* rtc_update_irq() assumes that it is called
176 * from IRQ-disabled context.
177 */
178 local_irq_disable();
179 rtc_update_irq(ds1307->rtc, 1, RTC_AF | RTC_IRQF);
180 local_irq_enable();
181 }
182
183out:
184 if (test_bit(HAS_ALARM, &ds1307->flags))
185 enable_irq(client->irq);
186 mutex_unlock(lock);
187}
188
189static irqreturn_t ds1307_irq(int irq, void *dev_id)
190{
191 struct i2c_client *client = dev_id;
192 struct ds1307 *ds1307 = i2c_get_clientdata(client);
193
194 disable_irq_nosync(irq);
195 schedule_work(&ds1307->work);
196 return IRQ_HANDLED;
197}
198
199/*----------------------------------------------------------------------*/
200
135static int ds1307_get_time(struct device *dev, struct rtc_time *t) 201static int ds1307_get_time(struct device *dev, struct rtc_time *t)
136{ 202{
137 struct ds1307 *ds1307 = dev_get_drvdata(dev); 203 struct ds1307 *ds1307 = dev_get_drvdata(dev);
138 int tmp; 204 int tmp;
139 205
140 /* read the RTC date and time registers all at once */ 206 /* read the RTC date and time registers all at once */
207 ds1307->reg_addr = 0;
141 ds1307->msg[1].flags = I2C_M_RD; 208 ds1307->msg[1].flags = I2C_M_RD;
142 ds1307->msg[1].len = 7; 209 ds1307->msg[1].len = 7;
143 210
@@ -231,9 +298,186 @@ static int ds1307_set_time(struct device *dev, struct rtc_time *t)
231 return 0; 298 return 0;
232} 299}
233 300
301static int ds1307_read_alarm(struct device *dev, struct rtc_wkalrm *t)
302{
303 struct i2c_client *client = to_i2c_client(dev);
304 struct ds1307 *ds1307 = i2c_get_clientdata(client);
305 int ret;
306
307 if (!test_bit(HAS_ALARM, &ds1307->flags))
308 return -EINVAL;
309
310 /* read all ALARM1, ALARM2, and status registers at once */
311 ds1307->reg_addr = DS1339_REG_ALARM1_SECS;
312 ds1307->msg[1].flags = I2C_M_RD;
313 ds1307->msg[1].len = 9;
314
315 ret = i2c_transfer(to_i2c_adapter(client->dev.parent),
316 ds1307->msg, 2);
317 if (ret != 2) {
318 dev_err(dev, "%s error %d\n", "alarm read", ret);
319 return -EIO;
320 }
321
322 dev_dbg(dev, "%s: %02x %02x %02x %02x, %02x %02x %02x, %02x %02x\n",
323 "alarm read",
324 ds1307->regs[0], ds1307->regs[1],
325 ds1307->regs[2], ds1307->regs[3],
326 ds1307->regs[4], ds1307->regs[5],
327 ds1307->regs[6], ds1307->regs[7],
328 ds1307->regs[8]);
329
330 /* report alarm time (ALARM1); assume 24 hour and day-of-month modes,
331 * and that all four fields are checked matches
332 */
333 t->time.tm_sec = bcd2bin(ds1307->regs[0] & 0x7f);
334 t->time.tm_min = bcd2bin(ds1307->regs[1] & 0x7f);
335 t->time.tm_hour = bcd2bin(ds1307->regs[2] & 0x3f);
336 t->time.tm_mday = bcd2bin(ds1307->regs[3] & 0x3f);
337 t->time.tm_mon = -1;
338 t->time.tm_year = -1;
339 t->time.tm_wday = -1;
340 t->time.tm_yday = -1;
341 t->time.tm_isdst = -1;
342
343 /* ... and status */
344 t->enabled = !!(ds1307->regs[7] & DS1337_BIT_A1IE);
345 t->pending = !!(ds1307->regs[8] & DS1337_BIT_A1I);
346
347 dev_dbg(dev, "%s secs=%d, mins=%d, "
348 "hours=%d, mday=%d, enabled=%d, pending=%d\n",
349 "alarm read", t->time.tm_sec, t->time.tm_min,
350 t->time.tm_hour, t->time.tm_mday,
351 t->enabled, t->pending);
352
353 return 0;
354}
355
356static int ds1307_set_alarm(struct device *dev, struct rtc_wkalrm *t)
357{
358 struct i2c_client *client = to_i2c_client(dev);
359 struct ds1307 *ds1307 = i2c_get_clientdata(client);
360 unsigned char *buf = ds1307->regs;
361 u8 control, status;
362 int ret;
363
364 if (!test_bit(HAS_ALARM, &ds1307->flags))
365 return -EINVAL;
366
367 dev_dbg(dev, "%s secs=%d, mins=%d, "
368 "hours=%d, mday=%d, enabled=%d, pending=%d\n",
369 "alarm set", t->time.tm_sec, t->time.tm_min,
370 t->time.tm_hour, t->time.tm_mday,
371 t->enabled, t->pending);
372
373 /* read current status of both alarms and the chip */
374 ds1307->reg_addr = DS1339_REG_ALARM1_SECS;
375 ds1307->msg[1].flags = I2C_M_RD;
376 ds1307->msg[1].len = 9;
377
378 ret = i2c_transfer(to_i2c_adapter(client->dev.parent),
379 ds1307->msg, 2);
380 if (ret != 2) {
381 dev_err(dev, "%s error %d\n", "alarm write", ret);
382 return -EIO;
383 }
384 control = ds1307->regs[7];
385 status = ds1307->regs[8];
386
387 dev_dbg(dev, "%s: %02x %02x %02x %02x, %02x %02x %02x, %02x %02x\n",
388 "alarm set (old status)",
389 ds1307->regs[0], ds1307->regs[1],
390 ds1307->regs[2], ds1307->regs[3],
391 ds1307->regs[4], ds1307->regs[5],
392 ds1307->regs[6], control, status);
393
394 /* set ALARM1, using 24 hour and day-of-month modes */
395 *buf++ = DS1339_REG_ALARM1_SECS; /* first register addr */
396 buf[0] = bin2bcd(t->time.tm_sec);
397 buf[1] = bin2bcd(t->time.tm_min);
398 buf[2] = bin2bcd(t->time.tm_hour);
399 buf[3] = bin2bcd(t->time.tm_mday);
400
401 /* set ALARM2 to non-garbage */
402 buf[4] = 0;
403 buf[5] = 0;
404 buf[6] = 0;
405
406 /* optionally enable ALARM1 */
407 buf[7] = control & ~(DS1337_BIT_A1IE | DS1337_BIT_A2IE);
408 if (t->enabled) {
409 dev_dbg(dev, "alarm IRQ armed\n");
410 buf[7] |= DS1337_BIT_A1IE; /* only ALARM1 is used */
411 }
412 buf[8] = status & ~(DS1337_BIT_A1I | DS1337_BIT_A2I);
413
414 ds1307->msg[1].flags = 0;
415 ds1307->msg[1].len = 10;
416
417 ret = i2c_transfer(to_i2c_adapter(client->dev.parent),
418 &ds1307->msg[1], 1);
419 if (ret != 1) {
420 dev_err(dev, "can't set alarm time\n");
421 return -EIO;
422 }
423
424 return 0;
425}
426
427static int ds1307_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
428{
429 struct i2c_client *client = to_i2c_client(dev);
430 struct ds1307 *ds1307 = i2c_get_clientdata(client);
431 int ret;
432
433 switch (cmd) {
434 case RTC_AIE_OFF:
435 if (!test_bit(HAS_ALARM, &ds1307->flags))
436 return -ENOTTY;
437
438 ret = i2c_smbus_read_byte_data(client, DS1337_REG_CONTROL);
439 if (ret < 0)
440 return ret;
441
442 ret &= ~DS1337_BIT_A1IE;
443
444 ret = i2c_smbus_write_byte_data(client,
445 DS1337_REG_CONTROL, ret);
446 if (ret < 0)
447 return ret;
448
449 break;
450
451 case RTC_AIE_ON:
452 if (!test_bit(HAS_ALARM, &ds1307->flags))
453 return -ENOTTY;
454
455 ret = i2c_smbus_read_byte_data(client, DS1337_REG_CONTROL);
456 if (ret < 0)
457 return ret;
458
459 ret |= DS1337_BIT_A1IE;
460
461 ret = i2c_smbus_write_byte_data(client,
462 DS1337_REG_CONTROL, ret);
463 if (ret < 0)
464 return ret;
465
466 break;
467
468 default:
469 return -ENOIOCTLCMD;
470 }
471
472 return 0;
473}
474
234static const struct rtc_class_ops ds13xx_rtc_ops = { 475static const struct rtc_class_ops ds13xx_rtc_ops = {
235 .read_time = ds1307_get_time, 476 .read_time = ds1307_get_time,
236 .set_time = ds1307_set_time, 477 .set_time = ds1307_set_time,
478 .read_alarm = ds1307_read_alarm,
479 .set_alarm = ds1307_set_alarm,
480 .ioctl = ds1307_ioctl,
237}; 481};
238 482
239/*----------------------------------------------------------------------*/ 483/*----------------------------------------------------------------------*/
@@ -327,6 +571,7 @@ static int __devinit ds1307_probe(struct i2c_client *client,
327 int tmp; 571 int tmp;
328 const struct chip_desc *chip = &chips[id->driver_data]; 572 const struct chip_desc *chip = &chips[id->driver_data];
329 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 573 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
574 int want_irq = false;
330 575
331 if (!i2c_check_functionality(adapter, 576 if (!i2c_check_functionality(adapter,
332 I2C_FUNC_I2C | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) 577 I2C_FUNC_I2C | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
@@ -353,6 +598,12 @@ static int __devinit ds1307_probe(struct i2c_client *client,
353 switch (ds1307->type) { 598 switch (ds1307->type) {
354 case ds_1337: 599 case ds_1337:
355 case ds_1339: 600 case ds_1339:
601 /* has IRQ? */
602 if (ds1307->client->irq > 0 && chip->alarm) {
603 INIT_WORK(&ds1307->work, ds1307_work);
604 want_irq = true;
605 }
606
356 ds1307->reg_addr = DS1337_REG_CONTROL; 607 ds1307->reg_addr = DS1337_REG_CONTROL;
357 ds1307->msg[1].len = 2; 608 ds1307->msg[1].len = 2;
358 609
@@ -369,8 +620,20 @@ static int __devinit ds1307_probe(struct i2c_client *client,
369 620
370 /* oscillator off? turn it on, so clock can tick. */ 621 /* oscillator off? turn it on, so clock can tick. */
371 if (ds1307->regs[0] & DS1337_BIT_nEOSC) 622 if (ds1307->regs[0] & DS1337_BIT_nEOSC)
372 i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL, 623 ds1307->regs[0] &= ~DS1337_BIT_nEOSC;
373 ds1307->regs[0] & ~DS1337_BIT_nEOSC); 624
625 /* Using IRQ? Disable the square wave and both alarms.
626 * For ds1339, be sure alarms can trigger when we're
627 * running on Vbackup (BBSQI); we assume ds1337 will
628 * ignore that bit
629 */
630 if (want_irq) {
631 ds1307->regs[0] |= DS1337_BIT_INTCN | DS1339_BIT_BBSQI;
632 ds1307->regs[0] &= ~(DS1337_BIT_A2IE | DS1337_BIT_A1IE);
633 }
634
635 i2c_smbus_write_byte_data(client, DS1337_REG_CONTROL,
636 ds1307->regs[0]);
374 637
375 /* oscillator fault? clear flag, and warn */ 638 /* oscillator fault? clear flag, and warn */
376 if (ds1307->regs[1] & DS1337_BIT_OSF) { 639 if (ds1307->regs[1] & DS1337_BIT_OSF) {
@@ -495,10 +758,22 @@ read_rtc:
495 goto exit_free; 758 goto exit_free;
496 } 759 }
497 760
761 if (want_irq) {
762 err = request_irq(client->irq, ds1307_irq, 0,
763 ds1307->rtc->name, client);
764 if (err) {
765 dev_err(&client->dev,
766 "unable to request IRQ!\n");
767 goto exit_irq;
768 }
769 set_bit(HAS_ALARM, &ds1307->flags);
770 dev_dbg(&client->dev, "got IRQ %d\n", client->irq);
771 }
772
498 if (chip->nvram56) { 773 if (chip->nvram56) {
499 err = sysfs_create_bin_file(&client->dev.kobj, &nvram); 774 err = sysfs_create_bin_file(&client->dev.kobj, &nvram);
500 if (err == 0) { 775 if (err == 0) {
501 ds1307->has_nvram = true; 776 set_bit(HAS_NVRAM, &ds1307->flags);
502 dev_info(&client->dev, "56 bytes nvram\n"); 777 dev_info(&client->dev, "56 bytes nvram\n");
503 } 778 }
504 } 779 }
@@ -512,7 +787,9 @@ exit_bad:
512 ds1307->regs[2], ds1307->regs[3], 787 ds1307->regs[2], ds1307->regs[3],
513 ds1307->regs[4], ds1307->regs[5], 788 ds1307->regs[4], ds1307->regs[5],
514 ds1307->regs[6]); 789 ds1307->regs[6]);
515 790exit_irq:
791 if (ds1307->rtc)
792 rtc_device_unregister(ds1307->rtc);
516exit_free: 793exit_free:
517 kfree(ds1307); 794 kfree(ds1307);
518 return err; 795 return err;
@@ -520,9 +797,14 @@ exit_free:
520 797
521static int __devexit ds1307_remove(struct i2c_client *client) 798static int __devexit ds1307_remove(struct i2c_client *client)
522{ 799{
523 struct ds1307 *ds1307 = i2c_get_clientdata(client); 800 struct ds1307 *ds1307 = i2c_get_clientdata(client);
801
802 if (test_and_clear_bit(HAS_ALARM, &ds1307->flags)) {
803 free_irq(client->irq, client);
804 cancel_work_sync(&ds1307->work);
805 }
524 806
525 if (ds1307->has_nvram) 807 if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags))
526 sysfs_remove_bin_file(&client->dev.kobj, &nvram); 808 sysfs_remove_bin_file(&client->dev.kobj, &nvram);
527 809
528 rtc_device_unregister(ds1307->rtc); 810 rtc_device_unregister(ds1307->rtc);
diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c
index a150418fba76..a5b0fc09f0c6 100644
--- a/drivers/rtc/rtc-ds1374.c
+++ b/drivers/rtc/rtc-ds1374.c
@@ -429,12 +429,33 @@ static int __devexit ds1374_remove(struct i2c_client *client)
429 return 0; 429 return 0;
430} 430}
431 431
432#ifdef CONFIG_PM
433static int ds1374_suspend(struct i2c_client *client, pm_message_t state)
434{
435 if (client->irq >= 0 && device_may_wakeup(&client->dev))
436 enable_irq_wake(client->irq);
437 return 0;
438}
439
440static int ds1374_resume(struct i2c_client *client)
441{
442 if (client->irq >= 0 && device_may_wakeup(&client->dev))
443 disable_irq_wake(client->irq);
444 return 0;
445}
446#else
447#define ds1374_suspend NULL
448#define ds1374_resume NULL
449#endif
450
432static struct i2c_driver ds1374_driver = { 451static struct i2c_driver ds1374_driver = {
433 .driver = { 452 .driver = {
434 .name = "rtc-ds1374", 453 .name = "rtc-ds1374",
435 .owner = THIS_MODULE, 454 .owner = THIS_MODULE,
436 }, 455 },
437 .probe = ds1374_probe, 456 .probe = ds1374_probe,
457 .suspend = ds1374_suspend,
458 .resume = ds1374_resume,
438 .remove = __devexit_p(ds1374_remove), 459 .remove = __devexit_p(ds1374_remove),
439 .id_table = ds1374_id, 460 .id_table = ds1374_id,
440}; 461};
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index 0f0d27d1c4ca..86981d34fbb6 100644
--- a/drivers/rtc/rtc-ds1511.c
+++ b/drivers/rtc/rtc-ds1511.c
@@ -379,18 +379,6 @@ ds1511_interrupt(int irq, void *dev_id)
379 return IRQ_HANDLED; 379 return IRQ_HANDLED;
380} 380}
381 381
382 static void
383ds1511_rtc_release(struct device *dev)
384{
385 struct platform_device *pdev = to_platform_device(dev);
386 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
387
388 if (pdata->irq >= 0) {
389 pdata->irqen = 0;
390 ds1511_rtc_update_alarm(pdata);
391 }
392}
393
394 static int 382 static int
395ds1511_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 383ds1511_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
396{ 384{
@@ -428,7 +416,6 @@ static const struct rtc_class_ops ds1511_rtc_ops = {
428 .set_time = ds1511_rtc_set_time, 416 .set_time = ds1511_rtc_set_time,
429 .read_alarm = ds1511_rtc_read_alarm, 417 .read_alarm = ds1511_rtc_read_alarm,
430 .set_alarm = ds1511_rtc_set_alarm, 418 .set_alarm = ds1511_rtc_set_alarm,
431 .release = ds1511_rtc_release,
432 .ioctl = ds1511_rtc_ioctl, 419 .ioctl = ds1511_rtc_ioctl,
433}; 420};
434 421
diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index a19f11415540..4ef59285b489 100644
--- a/drivers/rtc/rtc-ds1553.c
+++ b/drivers/rtc/rtc-ds1553.c
@@ -207,17 +207,6 @@ static irqreturn_t ds1553_rtc_interrupt(int irq, void *dev_id)
207 return IRQ_HANDLED; 207 return IRQ_HANDLED;
208} 208}
209 209
210static void ds1553_rtc_release(struct device *dev)
211{
212 struct platform_device *pdev = to_platform_device(dev);
213 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
214
215 if (pdata->irq >= 0) {
216 pdata->irqen = 0;
217 ds1553_rtc_update_alarm(pdata);
218 }
219}
220
221static int ds1553_rtc_ioctl(struct device *dev, unsigned int cmd, 210static int ds1553_rtc_ioctl(struct device *dev, unsigned int cmd,
222 unsigned long arg) 211 unsigned long arg)
223{ 212{
@@ -254,7 +243,6 @@ static const struct rtc_class_ops ds1553_rtc_ops = {
254 .set_time = ds1553_rtc_set_time, 243 .set_time = ds1553_rtc_set_time,
255 .read_alarm = ds1553_rtc_read_alarm, 244 .read_alarm = ds1553_rtc_read_alarm,
256 .set_alarm = ds1553_rtc_set_alarm, 245 .set_alarm = ds1553_rtc_set_alarm,
257 .release = ds1553_rtc_release,
258 .ioctl = ds1553_rtc_ioctl, 246 .ioctl = ds1553_rtc_ioctl,
259}; 247};
260 248
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c
index 6fa4556f5f5c..341d7a5b45a2 100644
--- a/drivers/rtc/rtc-ds1672.c
+++ b/drivers/rtc/rtc-ds1672.c
@@ -9,17 +9,10 @@
9 * published by the Free Software Foundation. 9 * published by the Free Software Foundation.
10 */ 10 */
11 11
12#include <linux/module.h>
13#include <linux/i2c.h> 12#include <linux/i2c.h>
14#include <linux/rtc.h> 13#include <linux/rtc.h>
15 14
16#define DRV_VERSION "0.3" 15#define DRV_VERSION "0.4"
17
18/* Addresses to scan: none. This chip cannot be detected. */
19static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
20
21/* Insmod parameters */
22I2C_CLIENT_INSMOD;
23 16
24/* Registers */ 17/* Registers */
25 18
@@ -29,8 +22,7 @@ I2C_CLIENT_INSMOD;
29 22
30#define DS1672_REG_CONTROL_EOSC 0x80 23#define DS1672_REG_CONTROL_EOSC 0x80
31 24
32/* Prototypes */ 25static struct i2c_driver ds1672_driver;
33static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind);
34 26
35/* 27/*
36 * In the routines that deal directly with the ds1672 hardware, we use 28 * In the routines that deal directly with the ds1672 hardware, we use
@@ -44,8 +36,8 @@ static int ds1672_get_datetime(struct i2c_client *client, struct rtc_time *tm)
44 unsigned char buf[4]; 36 unsigned char buf[4];
45 37
46 struct i2c_msg msgs[] = { 38 struct i2c_msg msgs[] = {
47 { client->addr, 0, 1, &addr }, /* setup read ptr */ 39 {client->addr, 0, 1, &addr}, /* setup read ptr */
48 { client->addr, I2C_M_RD, 4, buf }, /* read date */ 40 {client->addr, I2C_M_RD, 4, buf}, /* read date */
49 }; 41 };
50 42
51 /* read date registers */ 43 /* read date registers */
@@ -80,7 +72,7 @@ static int ds1672_set_mmss(struct i2c_client *client, unsigned long secs)
80 buf[2] = (secs & 0x0000FF00) >> 8; 72 buf[2] = (secs & 0x0000FF00) >> 8;
81 buf[3] = (secs & 0x00FF0000) >> 16; 73 buf[3] = (secs & 0x00FF0000) >> 16;
82 buf[4] = (secs & 0xFF000000) >> 24; 74 buf[4] = (secs & 0xFF000000) >> 24;
83 buf[5] = 0; /* set control reg to enable counting */ 75 buf[5] = 0; /* set control reg to enable counting */
84 76
85 xfer = i2c_master_send(client, buf, 6); 77 xfer = i2c_master_send(client, buf, 6);
86 if (xfer != 6) { 78 if (xfer != 6) {
@@ -127,8 +119,8 @@ static int ds1672_get_control(struct i2c_client *client, u8 *status)
127 unsigned char addr = DS1672_REG_CONTROL; 119 unsigned char addr = DS1672_REG_CONTROL;
128 120
129 struct i2c_msg msgs[] = { 121 struct i2c_msg msgs[] = {
130 { client->addr, 0, 1, &addr }, /* setup read ptr */ 122 {client->addr, 0, 1, &addr}, /* setup read ptr */
131 { client->addr, I2C_M_RD, 1, status }, /* read control */ 123 {client->addr, I2C_M_RD, 1, status}, /* read control */
132 }; 124 };
133 125
134 /* read control register */ 126 /* read control register */
@@ -141,7 +133,8 @@ static int ds1672_get_control(struct i2c_client *client, u8 *status)
141} 133}
142 134
143/* following are the sysfs callback functions */ 135/* following are the sysfs callback functions */
144static ssize_t show_control(struct device *dev, struct device_attribute *attr, char *buf) 136static ssize_t show_control(struct device *dev, struct device_attribute *attr,
137 char *buf)
145{ 138{
146 struct i2c_client *client = to_i2c_client(dev); 139 struct i2c_client *client = to_i2c_client(dev);
147 u8 control; 140 u8 control;
@@ -152,85 +145,46 @@ static ssize_t show_control(struct device *dev, struct device_attribute *attr, c
152 return err; 145 return err;
153 146
154 return sprintf(buf, "%s\n", (control & DS1672_REG_CONTROL_EOSC) 147 return sprintf(buf, "%s\n", (control & DS1672_REG_CONTROL_EOSC)
155 ? "disabled" : "enabled"); 148 ? "disabled" : "enabled");
156} 149}
150
157static DEVICE_ATTR(control, S_IRUGO, show_control, NULL); 151static DEVICE_ATTR(control, S_IRUGO, show_control, NULL);
158 152
159static const struct rtc_class_ops ds1672_rtc_ops = { 153static const struct rtc_class_ops ds1672_rtc_ops = {
160 .read_time = ds1672_rtc_read_time, 154 .read_time = ds1672_rtc_read_time,
161 .set_time = ds1672_rtc_set_time, 155 .set_time = ds1672_rtc_set_time,
162 .set_mmss = ds1672_rtc_set_mmss, 156 .set_mmss = ds1672_rtc_set_mmss,
163}; 157};
164 158
165static int ds1672_attach(struct i2c_adapter *adapter) 159static int ds1672_remove(struct i2c_client *client)
166{ 160{
167 return i2c_probe(adapter, &addr_data, ds1672_probe);
168}
169
170static int ds1672_detach(struct i2c_client *client)
171{
172 int err;
173 struct rtc_device *rtc = i2c_get_clientdata(client); 161 struct rtc_device *rtc = i2c_get_clientdata(client);
174 162
175 if (rtc) 163 if (rtc)
176 rtc_device_unregister(rtc); 164 rtc_device_unregister(rtc);
177 165
178 if ((err = i2c_detach_client(client)))
179 return err;
180
181 kfree(client);
182
183 return 0; 166 return 0;
184} 167}
185 168
186static struct i2c_driver ds1672_driver = { 169static int ds1672_probe(struct i2c_client *client,
187 .driver = { 170 const struct i2c_device_id *id)
188 .name = "ds1672",
189 },
190 .id = I2C_DRIVERID_DS1672,
191 .attach_adapter = &ds1672_attach,
192 .detach_client = &ds1672_detach,
193};
194
195static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind)
196{ 171{
197 int err = 0; 172 int err = 0;
198 u8 control; 173 u8 control;
199 struct i2c_client *client;
200 struct rtc_device *rtc; 174 struct rtc_device *rtc;
201 175
202 dev_dbg(&adapter->dev, "%s\n", __func__); 176 dev_dbg(&client->dev, "%s\n", __func__);
203 177
204 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { 178 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
205 err = -ENODEV; 179 return -ENODEV;
206 goto exit;
207 }
208
209 if (!(client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
210 err = -ENOMEM;
211 goto exit;
212 }
213
214 /* I2C client */
215 client->addr = address;
216 client->driver = &ds1672_driver;
217 client->adapter = adapter;
218
219 strlcpy(client->name, ds1672_driver.driver.name, I2C_NAME_SIZE);
220
221 /* Inform the i2c layer */
222 if ((err = i2c_attach_client(client)))
223 goto exit_kfree;
224 180
225 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 181 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
226 182
227 rtc = rtc_device_register(ds1672_driver.driver.name, &client->dev, 183 rtc = rtc_device_register(ds1672_driver.driver.name, &client->dev,
228 &ds1672_rtc_ops, THIS_MODULE); 184 &ds1672_rtc_ops, THIS_MODULE);
229 185
230 if (IS_ERR(rtc)) { 186 if (IS_ERR(rtc))
231 err = PTR_ERR(rtc); 187 return PTR_ERR(rtc);
232 goto exit_detach;
233 }
234 188
235 i2c_set_clientdata(client, rtc); 189 i2c_set_clientdata(client, rtc);
236 190
@@ -241,7 +195,7 @@ static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind)
241 195
242 if (control & DS1672_REG_CONTROL_EOSC) 196 if (control & DS1672_REG_CONTROL_EOSC)
243 dev_warn(&client->dev, "Oscillator not enabled. " 197 dev_warn(&client->dev, "Oscillator not enabled. "
244 "Set time to enable.\n"); 198 "Set time to enable.\n");
245 199
246 /* Register sysfs hooks */ 200 /* Register sysfs hooks */
247 err = device_create_file(&client->dev, &dev_attr_control); 201 err = device_create_file(&client->dev, &dev_attr_control);
@@ -250,19 +204,19 @@ static int ds1672_probe(struct i2c_adapter *adapter, int address, int kind)
250 204
251 return 0; 205 return 0;
252 206
253exit_devreg: 207 exit_devreg:
254 rtc_device_unregister(rtc); 208 rtc_device_unregister(rtc);
255
256exit_detach:
257 i2c_detach_client(client);
258
259exit_kfree:
260 kfree(client);
261
262exit:
263 return err; 209 return err;
264} 210}
265 211
212static struct i2c_driver ds1672_driver = {
213 .driver = {
214 .name = "rtc-ds1672",
215 },
216 .probe = &ds1672_probe,
217 .remove = &ds1672_remove,
218};
219
266static int __init ds1672_init(void) 220static int __init ds1672_init(void)
267{ 221{
268 return i2c_add_driver(&ds1672_driver); 222 return i2c_add_driver(&ds1672_driver);
diff --git a/drivers/rtc/rtc-ds3234.c b/drivers/rtc/rtc-ds3234.c
new file mode 100644
index 000000000000..37d131d03f33
--- /dev/null
+++ b/drivers/rtc/rtc-ds3234.c
@@ -0,0 +1,290 @@
1/* drivers/rtc/rtc-ds3234.c
2 *
3 * Driver for Dallas Semiconductor (DS3234) SPI RTC with Integrated Crystal
4 * and SRAM.
5 *
6 * Copyright (C) 2008 MIMOMax Wireless Ltd.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * Changelog:
13 *
14 * 07-May-2008: Dennis Aberilla <denzzzhome@yahoo.com>
15 * - Created based on the max6902 code. Only implements the
16 * date/time keeping functions; no SRAM yet.
17 */
18
19#include <linux/device.h>
20#include <linux/platform_device.h>
21#include <linux/rtc.h>
22#include <linux/spi/spi.h>
23#include <linux/bcd.h>
24
25#define DS3234_REG_SECONDS 0x00
26#define DS3234_REG_MINUTES 0x01
27#define DS3234_REG_HOURS 0x02
28#define DS3234_REG_DAY 0x03
29#define DS3234_REG_DATE 0x04
30#define DS3234_REG_MONTH 0x05
31#define DS3234_REG_YEAR 0x06
32#define DS3234_REG_CENTURY (1 << 7) /* Bit 7 of the Month register */
33
34#define DS3234_REG_CONTROL 0x0E
35#define DS3234_REG_CONT_STAT 0x0F
36
37#undef DS3234_DEBUG
38
39struct ds3234 {
40 struct rtc_device *rtc;
41 u8 buf[8]; /* Burst read: addr + 7 regs */
42 u8 tx_buf[2];
43 u8 rx_buf[2];
44};
45
46static void ds3234_set_reg(struct device *dev, unsigned char address,
47 unsigned char data)
48{
49 struct spi_device *spi = to_spi_device(dev);
50 unsigned char buf[2];
51
52 /* MSB must be '1' to indicate write */
53 buf[0] = address | 0x80;
54 buf[1] = data;
55
56 spi_write(spi, buf, 2);
57}
58
59static int ds3234_get_reg(struct device *dev, unsigned char address,
60 unsigned char *data)
61{
62 struct spi_device *spi = to_spi_device(dev);
63 struct ds3234 *chip = dev_get_drvdata(dev);
64 struct spi_message message;
65 struct spi_transfer xfer;
66 int status;
67
68 if (!data)
69 return -EINVAL;
70
71 /* Build our spi message */
72 spi_message_init(&message);
73 memset(&xfer, 0, sizeof(xfer));
74
75 /* Address + dummy tx byte */
76 xfer.len = 2;
77 xfer.tx_buf = chip->tx_buf;
78 xfer.rx_buf = chip->rx_buf;
79
80 chip->tx_buf[0] = address;
81 chip->tx_buf[1] = 0xff;
82
83 spi_message_add_tail(&xfer, &message);
84
85 /* do the i/o */
86 status = spi_sync(spi, &message);
87 if (status == 0)
88 status = message.status;
89 else
90 return status;
91
92 *data = chip->rx_buf[1];
93
94 return status;
95}
96
97static int ds3234_get_datetime(struct device *dev, struct rtc_time *dt)
98{
99 struct spi_device *spi = to_spi_device(dev);
100 struct ds3234 *chip = dev_get_drvdata(dev);
101 struct spi_message message;
102 struct spi_transfer xfer;
103 int status;
104
105 /* build the message */
106 spi_message_init(&message);
107 memset(&xfer, 0, sizeof(xfer));
108 xfer.len = 1 + 7; /* Addr + 7 registers */
109 xfer.tx_buf = chip->buf;
110 xfer.rx_buf = chip->buf;
111 chip->buf[0] = 0x00; /* Start address */
112 spi_message_add_tail(&xfer, &message);
113
114 /* do the i/o */
115 status = spi_sync(spi, &message);
116 if (status == 0)
117 status = message.status;
118 else
119 return status;
120
121 /* Seconds, Minutes, Hours, Day, Date, Month, Year */
122 dt->tm_sec = bcd2bin(chip->buf[1]);
123 dt->tm_min = bcd2bin(chip->buf[2]);
124 dt->tm_hour = bcd2bin(chip->buf[3] & 0x3f);
125 dt->tm_wday = bcd2bin(chip->buf[4]) - 1; /* 0 = Sun */
126 dt->tm_mday = bcd2bin(chip->buf[5]);
127 dt->tm_mon = bcd2bin(chip->buf[6] & 0x1f) - 1; /* 0 = Jan */
128 dt->tm_year = bcd2bin(chip->buf[7] & 0xff) + 100; /* Assume 20YY */
129
130#ifdef DS3234_DEBUG
131 dev_dbg(dev, "\n%s : Read RTC values\n", __func__);
132 dev_dbg(dev, "tm_hour: %i\n", dt->tm_hour);
133 dev_dbg(dev, "tm_min : %i\n", dt->tm_min);
134 dev_dbg(dev, "tm_sec : %i\n", dt->tm_sec);
135 dev_dbg(dev, "tm_wday: %i\n", dt->tm_wday);
136 dev_dbg(dev, "tm_mday: %i\n", dt->tm_mday);
137 dev_dbg(dev, "tm_mon : %i\n", dt->tm_mon);
138 dev_dbg(dev, "tm_year: %i\n", dt->tm_year);
139#endif
140
141 return 0;
142}
143
144static int ds3234_set_datetime(struct device *dev, struct rtc_time *dt)
145{
146#ifdef DS3234_DEBUG
147 dev_dbg(dev, "\n%s : Setting RTC values\n", __func__);
148 dev_dbg(dev, "tm_sec : %i\n", dt->tm_sec);
149 dev_dbg(dev, "tm_min : %i\n", dt->tm_min);
150 dev_dbg(dev, "tm_hour: %i\n", dt->tm_hour);
151 dev_dbg(dev, "tm_wday: %i\n", dt->tm_wday);
152 dev_dbg(dev, "tm_mday: %i\n", dt->tm_mday);
153 dev_dbg(dev, "tm_mon : %i\n", dt->tm_mon);
154 dev_dbg(dev, "tm_year: %i\n", dt->tm_year);
155#endif
156
157 ds3234_set_reg(dev, DS3234_REG_SECONDS, bin2bcd(dt->tm_sec));
158 ds3234_set_reg(dev, DS3234_REG_MINUTES, bin2bcd(dt->tm_min));
159 ds3234_set_reg(dev, DS3234_REG_HOURS, bin2bcd(dt->tm_hour) & 0x3f);
160
161 /* 0 = Sun */
162 ds3234_set_reg(dev, DS3234_REG_DAY, bin2bcd(dt->tm_wday + 1));
163 ds3234_set_reg(dev, DS3234_REG_DATE, bin2bcd(dt->tm_mday));
164
165 /* 0 = Jan */
166 ds3234_set_reg(dev, DS3234_REG_MONTH, bin2bcd(dt->tm_mon + 1));
167
168 /* Assume 20YY although we just want to make sure not to go negative. */
169 if (dt->tm_year > 100)
170 dt->tm_year -= 100;
171
172 ds3234_set_reg(dev, DS3234_REG_YEAR, bin2bcd(dt->tm_year));
173
174 return 0;
175}
176
177static int ds3234_read_time(struct device *dev, struct rtc_time *tm)
178{
179 return ds3234_get_datetime(dev, tm);
180}
181
182static int ds3234_set_time(struct device *dev, struct rtc_time *tm)
183{
184 return ds3234_set_datetime(dev, tm);
185}
186
187static const struct rtc_class_ops ds3234_rtc_ops = {
188 .read_time = ds3234_read_time,
189 .set_time = ds3234_set_time,
190};
191
192static int ds3234_probe(struct spi_device *spi)
193{
194 struct rtc_device *rtc;
195 unsigned char tmp;
196 struct ds3234 *chip;
197 int res;
198
199 rtc = rtc_device_register("ds3234",
200 &spi->dev, &ds3234_rtc_ops, THIS_MODULE);
201 if (IS_ERR(rtc))
202 return PTR_ERR(rtc);
203
204 spi->mode = SPI_MODE_3;
205 spi->bits_per_word = 8;
206 spi_setup(spi);
207
208 chip = kzalloc(sizeof(struct ds3234), GFP_KERNEL);
209 if (!chip) {
210 rtc_device_unregister(rtc);
211 return -ENOMEM;
212 }
213 chip->rtc = rtc;
214 dev_set_drvdata(&spi->dev, chip);
215
216 res = ds3234_get_reg(&spi->dev, DS3234_REG_SECONDS, &tmp);
217 if (res) {
218 rtc_device_unregister(rtc);
219 return res;
220 }
221
222 /* Control settings
223 *
224 * CONTROL_REG
225 * BIT 7 6 5 4 3 2 1 0
226 * EOSC BBSQW CONV RS2 RS1 INTCN A2IE A1IE
227 *
228 * 0 0 0 1 1 1 0 0
229 *
230 * CONTROL_STAT_REG
231 * BIT 7 6 5 4 3 2 1 0
232 * OSF BB32kHz CRATE1 CRATE0 EN32kHz BSY A2F A1F
233 *
234 * 1 0 0 0 1 0 0 0
235 */
236 ds3234_get_reg(&spi->dev, DS3234_REG_CONTROL, &tmp);
237 ds3234_set_reg(&spi->dev, DS3234_REG_CONTROL, tmp & 0x1c);
238
239 ds3234_get_reg(&spi->dev, DS3234_REG_CONT_STAT, &tmp);
240 ds3234_set_reg(&spi->dev, DS3234_REG_CONT_STAT, tmp & 0x88);
241
242 /* Print our settings */
243 ds3234_get_reg(&spi->dev, DS3234_REG_CONTROL, &tmp);
244 dev_info(&spi->dev, "Control Reg: 0x%02x\n", tmp);
245
246 ds3234_get_reg(&spi->dev, DS3234_REG_CONT_STAT, &tmp);
247 dev_info(&spi->dev, "Ctrl/Stat Reg: 0x%02x\n", tmp);
248
249 return 0;
250}
251
252static int __exit ds3234_remove(struct spi_device *spi)
253{
254 struct ds3234 *chip = platform_get_drvdata(spi);
255 struct rtc_device *rtc = chip->rtc;
256
257 if (rtc)
258 rtc_device_unregister(rtc);
259
260 kfree(chip);
261
262 return 0;
263}
264
265static struct spi_driver ds3234_driver = {
266 .driver = {
267 .name = "ds3234",
268 .bus = &spi_bus_type,
269 .owner = THIS_MODULE,
270 },
271 .probe = ds3234_probe,
272 .remove = __devexit_p(ds3234_remove),
273};
274
275static __init int ds3234_init(void)
276{
277 printk(KERN_INFO "DS3234 SPI RTC Driver\n");
278 return spi_register_driver(&ds3234_driver);
279}
280module_init(ds3234_init);
281
282static __exit void ds3234_exit(void)
283{
284 spi_unregister_driver(&ds3234_driver);
285}
286module_exit(ds3234_exit);
287
288MODULE_DESCRIPTION("DS3234 SPI RTC driver");
289MODULE_AUTHOR("Dennis Aberilla <denzzzhome@yahoo.com>");
290MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index 24bc1689fc74..470fb2d29545 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -56,21 +56,27 @@
56#define M41T80_ALHOUR_HT (1 << 6) /* HT: Halt Update Bit */ 56#define M41T80_ALHOUR_HT (1 << 6) /* HT: Halt Update Bit */
57#define M41T80_FLAGS_AF (1 << 6) /* AF: Alarm Flag Bit */ 57#define M41T80_FLAGS_AF (1 << 6) /* AF: Alarm Flag Bit */
58#define M41T80_FLAGS_BATT_LOW (1 << 4) /* BL: Battery Low Bit */ 58#define M41T80_FLAGS_BATT_LOW (1 << 4) /* BL: Battery Low Bit */
59#define M41T80_WATCHDOG_RB2 (1 << 7) /* RB: Watchdog resolution */
60#define M41T80_WATCHDOG_RB1 (1 << 1) /* RB: Watchdog resolution */
61#define M41T80_WATCHDOG_RB0 (1 << 0) /* RB: Watchdog resolution */
59 62
60#define M41T80_FEATURE_HT (1 << 0) 63#define M41T80_FEATURE_HT (1 << 0) /* Halt feature */
61#define M41T80_FEATURE_BL (1 << 1) 64#define M41T80_FEATURE_BL (1 << 1) /* Battery low indicator */
65#define M41T80_FEATURE_SQ (1 << 2) /* Squarewave feature */
66#define M41T80_FEATURE_WD (1 << 3) /* Extra watchdog resolution */
62 67
63#define DRV_VERSION "0.05" 68#define DRV_VERSION "0.05"
64 69
65static const struct i2c_device_id m41t80_id[] = { 70static const struct i2c_device_id m41t80_id[] = {
66 { "m41t80", 0 }, 71 { "m41t65", M41T80_FEATURE_HT | M41T80_FEATURE_WD },
67 { "m41t81", M41T80_FEATURE_HT }, 72 { "m41t80", M41T80_FEATURE_SQ },
68 { "m41t81s", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, 73 { "m41t81", M41T80_FEATURE_HT | M41T80_FEATURE_SQ},
69 { "m41t82", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, 74 { "m41t81s", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
70 { "m41t83", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, 75 { "m41t82", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
71 { "m41st84", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, 76 { "m41t83", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
72 { "m41st85", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, 77 { "m41st84", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
73 { "m41st87", M41T80_FEATURE_HT | M41T80_FEATURE_BL }, 78 { "m41st85", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
79 { "m41st87", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ },
74 { } 80 { }
75}; 81};
76MODULE_DEVICE_TABLE(i2c, m41t80_id); 82MODULE_DEVICE_TABLE(i2c, m41t80_id);
@@ -386,8 +392,12 @@ static ssize_t m41t80_sysfs_show_sqwfreq(struct device *dev,
386 struct device_attribute *attr, char *buf) 392 struct device_attribute *attr, char *buf)
387{ 393{
388 struct i2c_client *client = to_i2c_client(dev); 394 struct i2c_client *client = to_i2c_client(dev);
395 struct m41t80_data *clientdata = i2c_get_clientdata(client);
389 int val; 396 int val;
390 397
398 if (!(clientdata->features & M41T80_FEATURE_SQ))
399 return -EINVAL;
400
391 val = i2c_smbus_read_byte_data(client, M41T80_REG_SQW); 401 val = i2c_smbus_read_byte_data(client, M41T80_REG_SQW);
392 if (val < 0) 402 if (val < 0)
393 return -EIO; 403 return -EIO;
@@ -408,9 +418,13 @@ static ssize_t m41t80_sysfs_set_sqwfreq(struct device *dev,
408 const char *buf, size_t count) 418 const char *buf, size_t count)
409{ 419{
410 struct i2c_client *client = to_i2c_client(dev); 420 struct i2c_client *client = to_i2c_client(dev);
421 struct m41t80_data *clientdata = i2c_get_clientdata(client);
411 int almon, sqw; 422 int almon, sqw;
412 int val = simple_strtoul(buf, NULL, 0); 423 int val = simple_strtoul(buf, NULL, 0);
413 424
425 if (!(clientdata->features & M41T80_FEATURE_SQ))
426 return -EINVAL;
427
414 if (val) { 428 if (val) {
415 if (!is_power_of_2(val)) 429 if (!is_power_of_2(val))
416 return -EINVAL; 430 return -EINVAL;
@@ -499,6 +513,8 @@ static void wdt_ping(void)
499 .buf = i2c_data, 513 .buf = i2c_data,
500 }, 514 },
501 }; 515 };
516 struct m41t80_data *clientdata = i2c_get_clientdata(save_client);
517
502 i2c_data[0] = 0x09; /* watchdog register */ 518 i2c_data[0] = 0x09; /* watchdog register */
503 519
504 if (wdt_margin > 31) 520 if (wdt_margin > 31)
@@ -509,6 +525,13 @@ static void wdt_ping(void)
509 */ 525 */
510 i2c_data[1] = wdt_margin<<2 | 0x82; 526 i2c_data[1] = wdt_margin<<2 | 0x82;
511 527
528 /*
529 * M41T65 has three bits for watchdog resolution. Don't set bit 7, as
530 * that would be an invalid resolution.
531 */
532 if (clientdata->features & M41T80_FEATURE_WD)
533 i2c_data[1] &= ~M41T80_WATCHDOG_RB2;
534
512 i2c_transfer(save_client->adapter, msgs1, 1); 535 i2c_transfer(save_client->adapter, msgs1, 1);
513} 536}
514 537
diff --git a/drivers/rtc/rtc-m48t35.c b/drivers/rtc/rtc-m48t35.c
new file mode 100644
index 000000000000..0b2197559940
--- /dev/null
+++ b/drivers/rtc/rtc-m48t35.c
@@ -0,0 +1,235 @@
1/*
2 * Driver for the SGS-Thomson M48T35 Timekeeper RAM chip
3 *
4 * Copyright (C) 2000 Silicon Graphics, Inc.
5 * Written by Ulf Carlsson (ulfc@engr.sgi.com)
6 *
7 * Copyright (C) 2008 Thomas Bogendoerfer
8 *
9 * Based on code written by Paul Gortmaker.
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 */
16
17#include <linux/module.h>
18#include <linux/rtc.h>
19#include <linux/platform_device.h>
20#include <linux/bcd.h>
21#include <linux/io.h>
22
23#define DRV_VERSION "1.0"
24
25struct m48t35_rtc {
26 u8 pad[0x7ff8]; /* starts at 0x7ff8 */
27 u8 control;
28 u8 sec;
29 u8 min;
30 u8 hour;
31 u8 day;
32 u8 date;
33 u8 month;
34 u8 year;
35};
36
37#define M48T35_RTC_SET 0x80
38#define M48T35_RTC_READ 0x40
39
40struct m48t35_priv {
41 struct rtc_device *rtc;
42 struct m48t35_rtc __iomem *reg;
43 size_t size;
44 unsigned long baseaddr;
45 spinlock_t lock;
46};
47
48static int m48t35_read_time(struct device *dev, struct rtc_time *tm)
49{
50 struct m48t35_priv *priv = dev_get_drvdata(dev);
51 u8 control;
52
53 /*
54 * Only the values that we read from the RTC are set. We leave
55 * tm_wday, tm_yday and tm_isdst untouched. Even though the
56 * RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated
57 * by the RTC when initially set to a non-zero value.
58 */
59 spin_lock_irq(&priv->lock);
60 control = readb(&priv->reg->control);
61 writeb(control | M48T35_RTC_READ, &priv->reg->control);
62 tm->tm_sec = readb(&priv->reg->sec);
63 tm->tm_min = readb(&priv->reg->min);
64 tm->tm_hour = readb(&priv->reg->hour);
65 tm->tm_mday = readb(&priv->reg->date);
66 tm->tm_mon = readb(&priv->reg->month);
67 tm->tm_year = readb(&priv->reg->year);
68 writeb(control, &priv->reg->control);
69 spin_unlock_irq(&priv->lock);
70
71 tm->tm_sec = bcd2bin(tm->tm_sec);
72 tm->tm_min = bcd2bin(tm->tm_min);
73 tm->tm_hour = bcd2bin(tm->tm_hour);
74 tm->tm_mday = bcd2bin(tm->tm_mday);
75 tm->tm_mon = bcd2bin(tm->tm_mon);
76 tm->tm_year = bcd2bin(tm->tm_year);
77
78 /*
79 * Account for differences between how the RTC uses the values
80 * and how they are defined in a struct rtc_time;
81 */
82 tm->tm_year += 70;
83 if (tm->tm_year <= 69)
84 tm->tm_year += 100;
85
86 tm->tm_mon--;
87 return rtc_valid_tm(tm);
88}
89
90static int m48t35_set_time(struct device *dev, struct rtc_time *tm)
91{
92 struct m48t35_priv *priv = dev_get_drvdata(dev);
93 unsigned char mon, day, hrs, min, sec;
94 unsigned int yrs;
95 u8 control;
96
97 yrs = tm->tm_year + 1900;
98 mon = tm->tm_mon + 1; /* tm_mon starts at zero */
99 day = tm->tm_mday;
100 hrs = tm->tm_hour;
101 min = tm->tm_min;
102 sec = tm->tm_sec;
103
104 if (yrs < 1970)
105 return -EINVAL;
106
107 yrs -= 1970;
108 if (yrs > 255) /* They are unsigned */
109 return -EINVAL;
110
111 if (yrs > 169)
112 return -EINVAL;
113
114 if (yrs >= 100)
115 yrs -= 100;
116
117 sec = bin2bcd(sec);
118 min = bin2bcd(min);
119 hrs = bin2bcd(hrs);
120 day = bin2bcd(day);
121 mon = bin2bcd(mon);
122 yrs = bin2bcd(yrs);
123
124 spin_lock_irq(&priv->lock);
125 control = readb(&priv->reg->control);
126 writeb(control | M48T35_RTC_SET, &priv->reg->control);
127 writeb(yrs, &priv->reg->year);
128 writeb(mon, &priv->reg->month);
129 writeb(day, &priv->reg->date);
130 writeb(hrs, &priv->reg->hour);
131 writeb(min, &priv->reg->min);
132 writeb(sec, &priv->reg->sec);
133 writeb(control, &priv->reg->control);
134 spin_unlock_irq(&priv->lock);
135 return 0;
136}
137
138static const struct rtc_class_ops m48t35_ops = {
139 .read_time = m48t35_read_time,
140 .set_time = m48t35_set_time,
141};
142
143static int __devinit m48t35_probe(struct platform_device *pdev)
144{
145 struct rtc_device *rtc;
146 struct resource *res;
147 struct m48t35_priv *priv;
148 int ret = 0;
149
150 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
151 if (!res)
152 return -ENODEV;
153 priv = kzalloc(sizeof(struct m48t35_priv), GFP_KERNEL);
154 if (!priv)
155 return -ENOMEM;
156
157 priv->size = res->end - res->start + 1;
158 /*
159 * kludge: remove the #ifndef after ioc3 resource
160 * conflicts are resolved
161 */
162#ifndef CONFIG_SGI_IP27
163 if (!request_mem_region(res->start, priv->size, pdev->name)) {
164 ret = -EBUSY;
165 goto out;
166 }
167#endif
168 priv->baseaddr = res->start;
169 priv->reg = ioremap(priv->baseaddr, priv->size);
170 if (!priv->reg) {
171 ret = -ENOMEM;
172 goto out;
173 }
174 spin_lock_init(&priv->lock);
175 rtc = rtc_device_register("m48t35", &pdev->dev,
176 &m48t35_ops, THIS_MODULE);
177 if (IS_ERR(rtc)) {
178 ret = PTR_ERR(rtc);
179 goto out;
180 }
181 priv->rtc = rtc;
182 platform_set_drvdata(pdev, priv);
183 return 0;
184
185out:
186 if (priv->rtc)
187 rtc_device_unregister(priv->rtc);
188 if (priv->reg)
189 iounmap(priv->reg);
190 if (priv->baseaddr)
191 release_mem_region(priv->baseaddr, priv->size);
192 kfree(priv);
193 return ret;
194}
195
196static int __devexit m48t35_remove(struct platform_device *pdev)
197{
198 struct m48t35_priv *priv = platform_get_drvdata(pdev);
199
200 rtc_device_unregister(priv->rtc);
201 iounmap(priv->reg);
202#ifndef CONFIG_SGI_IP27
203 release_mem_region(priv->baseaddr, priv->size);
204#endif
205 kfree(priv);
206 return 0;
207}
208
209static struct platform_driver m48t35_platform_driver = {
210 .driver = {
211 .name = "rtc-m48t35",
212 .owner = THIS_MODULE,
213 },
214 .probe = m48t35_probe,
215 .remove = __devexit_p(m48t35_remove),
216};
217
218static int __init m48t35_init(void)
219{
220 return platform_driver_register(&m48t35_platform_driver);
221}
222
223static void __exit m48t35_exit(void)
224{
225 platform_driver_unregister(&m48t35_platform_driver);
226}
227
228MODULE_AUTHOR("Thomas Bogendoerfer <tsbogend@alpha.franken.de>");
229MODULE_DESCRIPTION("M48T35 RTC driver");
230MODULE_LICENSE("GPL");
231MODULE_VERSION(DRV_VERSION);
232MODULE_ALIAS("platform:rtc-m48t35");
233
234module_init(m48t35_init);
235module_exit(m48t35_exit);
diff --git a/drivers/rtc/rtc-max6900.c b/drivers/rtc/rtc-max6900.c
index ded3c0abad83..12c9cd25cad8 100644
--- a/drivers/rtc/rtc-max6900.c
+++ b/drivers/rtc/rtc-max6900.c
@@ -17,19 +17,18 @@
17#include <linux/rtc.h> 17#include <linux/rtc.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19 19
20#define DRV_NAME "max6900" 20#define DRV_VERSION "0.2"
21#define DRV_VERSION "0.1"
22 21
23/* 22/*
24 * register indices 23 * register indices
25 */ 24 */
26#define MAX6900_REG_SC 0 /* seconds 00-59 */ 25#define MAX6900_REG_SC 0 /* seconds 00-59 */
27#define MAX6900_REG_MN 1 /* minutes 00-59 */ 26#define MAX6900_REG_MN 1 /* minutes 00-59 */
28#define MAX6900_REG_HR 2 /* hours 00-23 */ 27#define MAX6900_REG_HR 2 /* hours 00-23 */
29#define MAX6900_REG_DT 3 /* day of month 00-31 */ 28#define MAX6900_REG_DT 3 /* day of month 00-31 */
30#define MAX6900_REG_MO 4 /* month 01-12 */ 29#define MAX6900_REG_MO 4 /* month 01-12 */
31#define MAX6900_REG_DW 5 /* day of week 1-7 */ 30#define MAX6900_REG_DW 5 /* day of week 1-7 */
32#define MAX6900_REG_YR 6 /* year 00-99 */ 31#define MAX6900_REG_YR 6 /* year 00-99 */
33#define MAX6900_REG_CT 7 /* control */ 32#define MAX6900_REG_CT 7 /* control */
34 /* register 8 is undocumented */ 33 /* register 8 is undocumented */
35#define MAX6900_REG_CENTURY 9 /* century */ 34#define MAX6900_REG_CENTURY 9 /* century */
@@ -39,7 +38,6 @@
39 38
40#define MAX6900_REG_CT_WP (1 << 7) /* Write Protect */ 39#define MAX6900_REG_CT_WP (1 << 7) /* Write Protect */
41 40
42
43/* 41/*
44 * register read/write commands 42 * register read/write commands
45 */ 43 */
@@ -52,16 +50,7 @@
52 50
53#define MAX6900_IDLE_TIME_AFTER_WRITE 3 /* specification says 2.5 mS */ 51#define MAX6900_IDLE_TIME_AFTER_WRITE 3 /* specification says 2.5 mS */
54 52
55#define MAX6900_I2C_ADDR 0xa0 53static struct i2c_driver max6900_driver;
56
57static const unsigned short normal_i2c[] = {
58 MAX6900_I2C_ADDR >> 1,
59 I2C_CLIENT_END
60};
61
62I2C_CLIENT_INSMOD; /* defines addr_data */
63
64static int max6900_probe(struct i2c_adapter *adapter, int addr, int kind);
65 54
66static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf) 55static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf)
67{ 56{
@@ -69,36 +58,35 @@ static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf)
69 u8 reg_century_read[1] = { MAX6900_REG_CENTURY_READ }; 58 u8 reg_century_read[1] = { MAX6900_REG_CENTURY_READ };
70 struct i2c_msg msgs[4] = { 59 struct i2c_msg msgs[4] = {
71 { 60 {
72 .addr = client->addr, 61 .addr = client->addr,
73 .flags = 0, /* write */ 62 .flags = 0, /* write */
74 .len = sizeof(reg_burst_read), 63 .len = sizeof(reg_burst_read),
75 .buf = reg_burst_read 64 .buf = reg_burst_read}
76 }, 65 ,
77 { 66 {
78 .addr = client->addr, 67 .addr = client->addr,
79 .flags = I2C_M_RD, 68 .flags = I2C_M_RD,
80 .len = MAX6900_BURST_LEN, 69 .len = MAX6900_BURST_LEN,
81 .buf = buf 70 .buf = buf}
82 }, 71 ,
83 { 72 {
84 .addr = client->addr, 73 .addr = client->addr,
85 .flags = 0, /* write */ 74 .flags = 0, /* write */
86 .len = sizeof(reg_century_read), 75 .len = sizeof(reg_century_read),
87 .buf = reg_century_read 76 .buf = reg_century_read}
88 }, 77 ,
89 { 78 {
90 .addr = client->addr, 79 .addr = client->addr,
91 .flags = I2C_M_RD, 80 .flags = I2C_M_RD,
92 .len = sizeof(buf[MAX6900_REG_CENTURY]), 81 .len = sizeof(buf[MAX6900_REG_CENTURY]),
93 .buf = &buf[MAX6900_REG_CENTURY] 82 .buf = &buf[MAX6900_REG_CENTURY]
94 } 83 }
95 }; 84 };
96 int rc; 85 int rc;
97 86
98 rc = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs)); 87 rc = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
99 if (rc != ARRAY_SIZE(msgs)) { 88 if (rc != ARRAY_SIZE(msgs)) {
100 dev_err(&client->dev, "%s: register read failed\n", 89 dev_err(&client->dev, "%s: register read failed\n", __func__);
101 __func__);
102 return -EIO; 90 return -EIO;
103 } 91 }
104 return 0; 92 return 0;
@@ -109,20 +97,18 @@ static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf)
109 u8 i2c_century_buf[1 + 1] = { MAX6900_REG_CENTURY_WRITE }; 97 u8 i2c_century_buf[1 + 1] = { MAX6900_REG_CENTURY_WRITE };
110 struct i2c_msg century_msgs[1] = { 98 struct i2c_msg century_msgs[1] = {
111 { 99 {
112 .addr = client->addr, 100 .addr = client->addr,
113 .flags = 0, /* write */ 101 .flags = 0, /* write */
114 .len = sizeof(i2c_century_buf), 102 .len = sizeof(i2c_century_buf),
115 .buf = i2c_century_buf 103 .buf = i2c_century_buf}
116 }
117 }; 104 };
118 u8 i2c_burst_buf[MAX6900_BURST_LEN + 1] = { MAX6900_REG_BURST_WRITE }; 105 u8 i2c_burst_buf[MAX6900_BURST_LEN + 1] = { MAX6900_REG_BURST_WRITE };
119 struct i2c_msg burst_msgs[1] = { 106 struct i2c_msg burst_msgs[1] = {
120 { 107 {
121 .addr = client->addr, 108 .addr = client->addr,
122 .flags = 0, /* write */ 109 .flags = 0, /* write */
123 .len = sizeof(i2c_burst_buf), 110 .len = sizeof(i2c_burst_buf),
124 .buf = i2c_burst_buf 111 .buf = i2c_burst_buf}
125 }
126 }; 112 };
127 int rc; 113 int rc;
128 114
@@ -133,10 +119,12 @@ static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf)
133 * bit as part of the burst write. 119 * bit as part of the burst write.
134 */ 120 */
135 i2c_century_buf[1] = buf[MAX6900_REG_CENTURY]; 121 i2c_century_buf[1] = buf[MAX6900_REG_CENTURY];
122
136 rc = i2c_transfer(client->adapter, century_msgs, 123 rc = i2c_transfer(client->adapter, century_msgs,
137 ARRAY_SIZE(century_msgs)); 124 ARRAY_SIZE(century_msgs));
138 if (rc != ARRAY_SIZE(century_msgs)) 125 if (rc != ARRAY_SIZE(century_msgs))
139 goto write_failed; 126 goto write_failed;
127
140 msleep(MAX6900_IDLE_TIME_AFTER_WRITE); 128 msleep(MAX6900_IDLE_TIME_AFTER_WRITE);
141 129
142 memcpy(&i2c_burst_buf[1], buf, MAX6900_BURST_LEN); 130 memcpy(&i2c_burst_buf[1], buf, MAX6900_BURST_LEN);
@@ -148,45 +136,11 @@ static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf)
148 136
149 return 0; 137 return 0;
150 138
151write_failed: 139 write_failed:
152 dev_err(&client->dev, "%s: register write failed\n", 140 dev_err(&client->dev, "%s: register write failed\n", __func__);
153 __func__);
154 return -EIO; 141 return -EIO;
155} 142}
156 143
157static int max6900_i2c_validate_client(struct i2c_client *client)
158{
159 u8 regs[MAX6900_REG_LEN];
160 u8 zero_mask[] = {
161 0x80, /* seconds */
162 0x80, /* minutes */
163 0x40, /* hours */
164 0xc0, /* day of month */
165 0xe0, /* month */
166 0xf8, /* day of week */
167 0x00, /* year */
168 0x7f, /* control */
169 };
170 int i;
171 int rc;
172 int reserved;
173
174 reserved = i2c_smbus_read_byte_data(client, MAX6900_REG_RESERVED_READ);
175 if (reserved != 0x07)
176 return -ENODEV;
177
178 rc = max6900_i2c_read_regs(client, regs);
179 if (rc < 0)
180 return rc;
181
182 for (i = 0; i < ARRAY_SIZE(zero_mask); ++i) {
183 if (regs[i] & zero_mask[i])
184 return -ENODEV;
185 }
186
187 return 0;
188}
189
190static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm) 144static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
191{ 145{
192 int rc; 146 int rc;
@@ -202,7 +156,7 @@ static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
202 tm->tm_mday = BCD2BIN(regs[MAX6900_REG_DT]); 156 tm->tm_mday = BCD2BIN(regs[MAX6900_REG_DT]);
203 tm->tm_mon = BCD2BIN(regs[MAX6900_REG_MO]) - 1; 157 tm->tm_mon = BCD2BIN(regs[MAX6900_REG_MO]) - 1;
204 tm->tm_year = BCD2BIN(regs[MAX6900_REG_YR]) + 158 tm->tm_year = BCD2BIN(regs[MAX6900_REG_YR]) +
205 BCD2BIN(regs[MAX6900_REG_CENTURY]) * 100 - 1900; 159 BCD2BIN(regs[MAX6900_REG_CENTURY]) * 100 - 1900;
206 tm->tm_wday = BCD2BIN(regs[MAX6900_REG_DW]); 160 tm->tm_wday = BCD2BIN(regs[MAX6900_REG_DW]);
207 161
208 return 0; 162 return 0;
@@ -211,7 +165,7 @@ static int max6900_i2c_read_time(struct i2c_client *client, struct rtc_time *tm)
211static int max6900_i2c_clear_write_protect(struct i2c_client *client) 165static int max6900_i2c_clear_write_protect(struct i2c_client *client)
212{ 166{
213 int rc; 167 int rc;
214 rc = i2c_smbus_write_byte_data (client, MAX6900_REG_CONTROL_WRITE, 0); 168 rc = i2c_smbus_write_byte_data(client, MAX6900_REG_CONTROL_WRITE, 0);
215 if (rc < 0) { 169 if (rc < 0) {
216 dev_err(&client->dev, "%s: control register write failed\n", 170 dev_err(&client->dev, "%s: control register write failed\n",
217 __func__); 171 __func__);
@@ -220,8 +174,8 @@ static int max6900_i2c_clear_write_protect(struct i2c_client *client)
220 return 0; 174 return 0;
221} 175}
222 176
223static int max6900_i2c_set_time(struct i2c_client *client, 177static int
224 struct rtc_time const *tm) 178max6900_i2c_set_time(struct i2c_client *client, struct rtc_time const *tm)
225{ 179{
226 u8 regs[MAX6900_REG_LEN]; 180 u8 regs[MAX6900_REG_LEN];
227 int rc; 181 int rc;
@@ -258,89 +212,49 @@ static int max6900_rtc_set_time(struct device *dev, struct rtc_time *tm)
258 return max6900_i2c_set_time(to_i2c_client(dev), tm); 212 return max6900_i2c_set_time(to_i2c_client(dev), tm);
259} 213}
260 214
261static int max6900_attach_adapter(struct i2c_adapter *adapter) 215static int max6900_remove(struct i2c_client *client)
262{
263 return i2c_probe(adapter, &addr_data, max6900_probe);
264}
265
266static int max6900_detach_client(struct i2c_client *client)
267{ 216{
268 struct rtc_device *const rtc = i2c_get_clientdata(client); 217 struct rtc_device *rtc = i2c_get_clientdata(client);
269 218
270 if (rtc) 219 if (rtc)
271 rtc_device_unregister(rtc); 220 rtc_device_unregister(rtc);
272 221
273 return i2c_detach_client(client); 222 return 0;
274} 223}
275 224
276static struct i2c_driver max6900_driver = {
277 .driver = {
278 .name = DRV_NAME,
279 },
280 .id = I2C_DRIVERID_MAX6900,
281 .attach_adapter = max6900_attach_adapter,
282 .detach_client = max6900_detach_client,
283};
284
285static const struct rtc_class_ops max6900_rtc_ops = { 225static const struct rtc_class_ops max6900_rtc_ops = {
286 .read_time = max6900_rtc_read_time, 226 .read_time = max6900_rtc_read_time,
287 .set_time = max6900_rtc_set_time, 227 .set_time = max6900_rtc_set_time,
288}; 228};
289 229
290static int max6900_probe(struct i2c_adapter *adapter, int addr, int kind) 230static int
231max6900_probe(struct i2c_client *client, const struct i2c_device_id *id)
291{ 232{
292 int rc = 0; 233 struct rtc_device *rtc;
293 struct i2c_client *client = NULL;
294 struct rtc_device *rtc = NULL;
295
296 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
297 rc = -ENODEV;
298 goto failout;
299 }
300
301 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
302 if (client == NULL) {
303 rc = -ENOMEM;
304 goto failout;
305 }
306
307 client->addr = addr;
308 client->adapter = adapter;
309 client->driver = &max6900_driver;
310 strlcpy(client->name, DRV_NAME, I2C_NAME_SIZE);
311
312 if (kind < 0) {
313 rc = max6900_i2c_validate_client(client);
314 if (rc < 0)
315 goto failout;
316 }
317 234
318 rc = i2c_attach_client(client); 235 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
319 if (rc < 0) 236 return -ENODEV;
320 goto failout;
321 237
322 dev_info(&client->dev, 238 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
323 "chip found, driver version " DRV_VERSION "\n");
324 239
325 rtc = rtc_device_register(max6900_driver.driver.name, 240 rtc = rtc_device_register(max6900_driver.driver.name,
326 &client->dev, 241 &client->dev, &max6900_rtc_ops, THIS_MODULE);
327 &max6900_rtc_ops, THIS_MODULE); 242 if (IS_ERR(rtc))
328 if (IS_ERR(rtc)) { 243 return PTR_ERR(rtc);
329 rc = PTR_ERR(rtc);
330 goto failout_detach;
331 }
332 244
333 i2c_set_clientdata(client, rtc); 245 i2c_set_clientdata(client, rtc);
334 246
335 return 0; 247 return 0;
336
337failout_detach:
338 i2c_detach_client(client);
339failout:
340 kfree(client);
341 return rc;
342} 248}
343 249
250static struct i2c_driver max6900_driver = {
251 .driver = {
252 .name = "rtc-max6900",
253 },
254 .probe = max6900_probe,
255 .remove = max6900_remove,
256};
257
344static int __init max6900_init(void) 258static int __init max6900_init(void)
345{ 259{
346 return i2c_add_driver(&max6900_driver); 260 return i2c_add_driver(&max6900_driver);
@@ -352,6 +266,7 @@ static void __exit max6900_exit(void)
352} 266}
353 267
354MODULE_DESCRIPTION("Maxim MAX6900 RTC driver"); 268MODULE_DESCRIPTION("Maxim MAX6900 RTC driver");
269MODULE_AUTHOR("Dale Farnsworth <dale@farnsworth.org>");
355MODULE_LICENSE("GPL"); 270MODULE_LICENSE("GPL");
356MODULE_VERSION(DRV_VERSION); 271MODULE_VERSION(DRV_VERSION);
357 272
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index 748a502a6355..a829f20ad6d6 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -179,58 +179,6 @@ struct pcf8563_limit
179 unsigned char max; 179 unsigned char max;
180}; 180};
181 181
182static int pcf8563_validate_client(struct i2c_client *client)
183{
184 int i;
185
186 static const struct pcf8563_limit pattern[] = {
187 /* register, mask, min, max */
188 { PCF8563_REG_SC, 0x7F, 0, 59 },
189 { PCF8563_REG_MN, 0x7F, 0, 59 },
190 { PCF8563_REG_HR, 0x3F, 0, 23 },
191 { PCF8563_REG_DM, 0x3F, 0, 31 },
192 { PCF8563_REG_MO, 0x1F, 0, 12 },
193 };
194
195 /* check limits (only registers with bcd values) */
196 for (i = 0; i < ARRAY_SIZE(pattern); i++) {
197 int xfer;
198 unsigned char value;
199 unsigned char buf = pattern[i].reg;
200
201 struct i2c_msg msgs[] = {
202 { client->addr, 0, 1, &buf },
203 { client->addr, I2C_M_RD, 1, &buf },
204 };
205
206 xfer = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
207
208 if (xfer != ARRAY_SIZE(msgs)) {
209 dev_err(&client->dev,
210 "%s: could not read register 0x%02X\n",
211 __func__, pattern[i].reg);
212
213 return -EIO;
214 }
215
216 value = BCD2BIN(buf & pattern[i].mask);
217
218 if (value > pattern[i].max ||
219 value < pattern[i].min) {
220 dev_dbg(&client->dev,
221 "%s: pattern=%d, reg=%x, mask=0x%02x, min=%d, "
222 "max=%d, value=%d, raw=0x%02X\n",
223 __func__, i, pattern[i].reg, pattern[i].mask,
224 pattern[i].min, pattern[i].max,
225 value, buf);
226
227 return -ENODEV;
228 }
229 }
230
231 return 0;
232}
233
234static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm) 182static int pcf8563_rtc_read_time(struct device *dev, struct rtc_time *tm)
235{ 183{
236 return pcf8563_get_datetime(to_i2c_client(dev), tm); 184 return pcf8563_get_datetime(to_i2c_client(dev), tm);
@@ -262,12 +210,6 @@ static int pcf8563_probe(struct i2c_client *client,
262 if (!pcf8563) 210 if (!pcf8563)
263 return -ENOMEM; 211 return -ENOMEM;
264 212
265 /* Verify the chip is really an PCF8563 */
266 if (pcf8563_validate_client(client) < 0) {
267 err = -ENODEV;
268 goto exit_kfree;
269 }
270
271 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 213 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
272 214
273 pcf8563->rtc = rtc_device_register(pcf8563_driver.driver.name, 215 pcf8563->rtc = rtc_device_register(pcf8563_driver.driver.name,
diff --git a/drivers/rtc/rtc-pl030.c b/drivers/rtc/rtc-pl030.c
index 8448eeb9d675..826153552157 100644
--- a/drivers/rtc/rtc-pl030.c
+++ b/drivers/rtc/rtc-pl030.c
@@ -34,15 +34,6 @@ static irqreturn_t pl030_interrupt(int irq, void *dev_id)
34 return IRQ_HANDLED; 34 return IRQ_HANDLED;
35} 35}
36 36
37static int pl030_open(struct device *dev)
38{
39 return 0;
40}
41
42static void pl030_release(struct device *dev)
43{
44}
45
46static int pl030_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 37static int pl030_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
47{ 38{
48 return -ENOIOCTLCMD; 39 return -ENOIOCTLCMD;
@@ -104,8 +95,6 @@ static int pl030_set_time(struct device *dev, struct rtc_time *tm)
104} 95}
105 96
106static const struct rtc_class_ops pl030_ops = { 97static const struct rtc_class_ops pl030_ops = {
107 .open = pl030_open,
108 .release = pl030_release,
109 .ioctl = pl030_ioctl, 98 .ioctl = pl030_ioctl,
110 .read_time = pl030_read_time, 99 .read_time = pl030_read_time,
111 .set_time = pl030_set_time, 100 .set_time = pl030_set_time,
diff --git a/drivers/rtc/rtc-pl031.c b/drivers/rtc/rtc-pl031.c
index 08b4610ec5a6..333eec689d2f 100644
--- a/drivers/rtc/rtc-pl031.c
+++ b/drivers/rtc/rtc-pl031.c
@@ -45,18 +45,6 @@ static irqreturn_t pl031_interrupt(int irq, void *dev_id)
45 return IRQ_HANDLED; 45 return IRQ_HANDLED;
46} 46}
47 47
48static int pl031_open(struct device *dev)
49{
50 /*
51 * We request IRQ in pl031_probe, so nothing to do here...
52 */
53 return 0;
54}
55
56static void pl031_release(struct device *dev)
57{
58}
59
60static int pl031_ioctl(struct device *dev, unsigned int cmd, unsigned long arg) 48static int pl031_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
61{ 49{
62 struct pl031_local *ldata = dev_get_drvdata(dev); 50 struct pl031_local *ldata = dev_get_drvdata(dev);
@@ -118,8 +106,6 @@ static int pl031_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
118} 106}
119 107
120static const struct rtc_class_ops pl031_ops = { 108static const struct rtc_class_ops pl031_ops = {
121 .open = pl031_open,
122 .release = pl031_release,
123 .ioctl = pl031_ioctl, 109 .ioctl = pl031_ioctl,
124 .read_time = pl031_read_time, 110 .read_time = pl031_read_time,
125 .set_time = pl031_set_time, 111 .set_time = pl031_set_time,
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
index 56caf6b2c3e5..8b561958fb1e 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -1,8 +1,9 @@
1/* 1/*
2 * An I2C driver for Ricoh RS5C372 and RV5C38[67] RTCs 2 * An I2C driver for Ricoh RS5C372, R2025S/D and RV5C38[67] RTCs
3 * 3 *
4 * Copyright (C) 2005 Pavel Mironchik <pmironchik@optifacio.net> 4 * Copyright (C) 2005 Pavel Mironchik <pmironchik@optifacio.net>
5 * Copyright (C) 2006 Tower Technologies 5 * Copyright (C) 2006 Tower Technologies
6 * Copyright (C) 2008 Paul Mundt
6 * 7 *
7 * This program is free software; you can redistribute it and/or modify 8 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as 9 * it under the terms of the GNU General Public License version 2 as
@@ -13,7 +14,7 @@
13#include <linux/rtc.h> 14#include <linux/rtc.h>
14#include <linux/bcd.h> 15#include <linux/bcd.h>
15 16
16#define DRV_VERSION "0.5" 17#define DRV_VERSION "0.6"
17 18
18 19
19/* 20/*
@@ -51,7 +52,8 @@
51# define RS5C_CTRL1_CT4 (4 << 0) /* 1 Hz level irq */ 52# define RS5C_CTRL1_CT4 (4 << 0) /* 1 Hz level irq */
52#define RS5C_REG_CTRL2 15 53#define RS5C_REG_CTRL2 15
53# define RS5C372_CTRL2_24 (1 << 5) 54# define RS5C372_CTRL2_24 (1 << 5)
54# define RS5C_CTRL2_XSTP (1 << 4) 55# define R2025_CTRL2_XST (1 << 5)
56# define RS5C_CTRL2_XSTP (1 << 4) /* only if !R2025S/D */
55# define RS5C_CTRL2_CTFG (1 << 2) 57# define RS5C_CTRL2_CTFG (1 << 2)
56# define RS5C_CTRL2_AAFG (1 << 1) /* or WAFG */ 58# define RS5C_CTRL2_AAFG (1 << 1) /* or WAFG */
57# define RS5C_CTRL2_BAFG (1 << 0) /* or DAFG */ 59# define RS5C_CTRL2_BAFG (1 << 0) /* or DAFG */
@@ -63,6 +65,7 @@
63 65
64enum rtc_type { 66enum rtc_type {
65 rtc_undef = 0, 67 rtc_undef = 0,
68 rtc_r2025sd,
66 rtc_rs5c372a, 69 rtc_rs5c372a,
67 rtc_rs5c372b, 70 rtc_rs5c372b,
68 rtc_rv5c386, 71 rtc_rv5c386,
@@ -70,6 +73,7 @@ enum rtc_type {
70}; 73};
71 74
72static const struct i2c_device_id rs5c372_id[] = { 75static const struct i2c_device_id rs5c372_id[] = {
76 { "r2025sd", rtc_r2025sd },
73 { "rs5c372a", rtc_rs5c372a }, 77 { "rs5c372a", rtc_rs5c372a },
74 { "rs5c372b", rtc_rs5c372b }, 78 { "rs5c372b", rtc_rs5c372b },
75 { "rv5c386", rtc_rv5c386 }, 79 { "rv5c386", rtc_rv5c386 },
@@ -89,6 +93,7 @@ struct rs5c372 {
89 enum rtc_type type; 93 enum rtc_type type;
90 unsigned time24:1; 94 unsigned time24:1;
91 unsigned has_irq:1; 95 unsigned has_irq:1;
96 unsigned smbus:1;
92 char buf[17]; 97 char buf[17];
93 char *regs; 98 char *regs;
94}; 99};
@@ -106,10 +111,25 @@ static int rs5c_get_regs(struct rs5c372 *rs5c)
106 * 111 *
107 * The first method doesn't work with the iop3xx adapter driver, on at 112 * The first method doesn't work with the iop3xx adapter driver, on at
108 * least 80219 chips; this works around that bug. 113 * least 80219 chips; this works around that bug.
114 *
115 * The third method on the other hand doesn't work for the SMBus-only
116 * configurations, so we use the the first method there, stripping off
117 * the extra register in the process.
109 */ 118 */
110 if ((i2c_transfer(client->adapter, msgs, 1)) != 1) { 119 if (rs5c->smbus) {
111 dev_warn(&client->dev, "can't read registers\n"); 120 int addr = RS5C_ADDR(RS5C372_REG_SECS);
112 return -EIO; 121 int size = sizeof(rs5c->buf) - 1;
122
123 if (i2c_smbus_read_i2c_block_data(client, addr, size,
124 rs5c->buf + 1) != size) {
125 dev_warn(&client->dev, "can't read registers\n");
126 return -EIO;
127 }
128 } else {
129 if ((i2c_transfer(client->adapter, msgs, 1)) != 1) {
130 dev_warn(&client->dev, "can't read registers\n");
131 return -EIO;
132 }
113 } 133 }
114 134
115 dev_dbg(&client->dev, 135 dev_dbg(&client->dev,
@@ -187,6 +207,7 @@ static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm)
187{ 207{
188 struct rs5c372 *rs5c = i2c_get_clientdata(client); 208 struct rs5c372 *rs5c = i2c_get_clientdata(client);
189 unsigned char buf[8]; 209 unsigned char buf[8];
210 int addr;
190 211
191 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d " 212 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d "
192 "mday=%d, mon=%d, year=%d, wday=%d\n", 213 "mday=%d, mon=%d, year=%d, wday=%d\n",
@@ -194,16 +215,16 @@ static int rs5c372_set_datetime(struct i2c_client *client, struct rtc_time *tm)
194 tm->tm_sec, tm->tm_min, tm->tm_hour, 215 tm->tm_sec, tm->tm_min, tm->tm_hour,
195 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday); 216 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
196 217
197 buf[0] = RS5C_ADDR(RS5C372_REG_SECS); 218 addr = RS5C_ADDR(RS5C372_REG_SECS);
198 buf[1] = BIN2BCD(tm->tm_sec); 219 buf[0] = BIN2BCD(tm->tm_sec);
199 buf[2] = BIN2BCD(tm->tm_min); 220 buf[1] = BIN2BCD(tm->tm_min);
200 buf[3] = rs5c_hr2reg(rs5c, tm->tm_hour); 221 buf[2] = rs5c_hr2reg(rs5c, tm->tm_hour);
201 buf[4] = BIN2BCD(tm->tm_wday); 222 buf[3] = BIN2BCD(tm->tm_wday);
202 buf[5] = BIN2BCD(tm->tm_mday); 223 buf[4] = BIN2BCD(tm->tm_mday);
203 buf[6] = BIN2BCD(tm->tm_mon + 1); 224 buf[5] = BIN2BCD(tm->tm_mon + 1);
204 buf[7] = BIN2BCD(tm->tm_year - 100); 225 buf[6] = BIN2BCD(tm->tm_year - 100);
205 226
206 if ((i2c_master_send(client, buf, 8)) != 8) { 227 if (i2c_smbus_write_i2c_block_data(client, addr, sizeof(buf), buf) < 0) {
207 dev_err(&client->dev, "%s: write error\n", __func__); 228 dev_err(&client->dev, "%s: write error\n", __func__);
208 return -EIO; 229 return -EIO;
209 } 230 }
@@ -266,16 +287,16 @@ rs5c_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
266{ 287{
267 struct i2c_client *client = to_i2c_client(dev); 288 struct i2c_client *client = to_i2c_client(dev);
268 struct rs5c372 *rs5c = i2c_get_clientdata(client); 289 struct rs5c372 *rs5c = i2c_get_clientdata(client);
269 unsigned char buf[2]; 290 unsigned char buf;
270 int status; 291 int status, addr;
271 292
272 buf[1] = rs5c->regs[RS5C_REG_CTRL1]; 293 buf = rs5c->regs[RS5C_REG_CTRL1];
273 switch (cmd) { 294 switch (cmd) {
274 case RTC_UIE_OFF: 295 case RTC_UIE_OFF:
275 case RTC_UIE_ON: 296 case RTC_UIE_ON:
276 /* some 327a modes use a different IRQ pin for 1Hz irqs */ 297 /* some 327a modes use a different IRQ pin for 1Hz irqs */
277 if (rs5c->type == rtc_rs5c372a 298 if (rs5c->type == rtc_rs5c372a
278 && (buf[1] & RS5C372A_CTRL1_SL1)) 299 && (buf & RS5C372A_CTRL1_SL1))
279 return -ENOIOCTLCMD; 300 return -ENOIOCTLCMD;
280 case RTC_AIE_OFF: 301 case RTC_AIE_OFF:
281 case RTC_AIE_ON: 302 case RTC_AIE_ON:
@@ -293,28 +314,30 @@ rs5c_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
293 if (status < 0) 314 if (status < 0)
294 return status; 315 return status;
295 316
296 buf[0] = RS5C_ADDR(RS5C_REG_CTRL1); 317 addr = RS5C_ADDR(RS5C_REG_CTRL1);
297 switch (cmd) { 318 switch (cmd) {
298 case RTC_AIE_OFF: /* alarm off */ 319 case RTC_AIE_OFF: /* alarm off */
299 buf[1] &= ~RS5C_CTRL1_AALE; 320 buf &= ~RS5C_CTRL1_AALE;
300 break; 321 break;
301 case RTC_AIE_ON: /* alarm on */ 322 case RTC_AIE_ON: /* alarm on */
302 buf[1] |= RS5C_CTRL1_AALE; 323 buf |= RS5C_CTRL1_AALE;
303 break; 324 break;
304 case RTC_UIE_OFF: /* update off */ 325 case RTC_UIE_OFF: /* update off */
305 buf[1] &= ~RS5C_CTRL1_CT_MASK; 326 buf &= ~RS5C_CTRL1_CT_MASK;
306 break; 327 break;
307 case RTC_UIE_ON: /* update on */ 328 case RTC_UIE_ON: /* update on */
308 buf[1] &= ~RS5C_CTRL1_CT_MASK; 329 buf &= ~RS5C_CTRL1_CT_MASK;
309 buf[1] |= RS5C_CTRL1_CT4; 330 buf |= RS5C_CTRL1_CT4;
310 break; 331 break;
311 } 332 }
312 if ((i2c_master_send(client, buf, 2)) != 2) { 333
334 if (i2c_smbus_write_byte_data(client, addr, buf) < 0) {
313 printk(KERN_WARNING "%s: can't update alarm\n", 335 printk(KERN_WARNING "%s: can't update alarm\n",
314 rs5c->rtc->name); 336 rs5c->rtc->name);
315 status = -EIO; 337 status = -EIO;
316 } else 338 } else
317 rs5c->regs[RS5C_REG_CTRL1] = buf[1]; 339 rs5c->regs[RS5C_REG_CTRL1] = buf;
340
318 return status; 341 return status;
319} 342}
320 343
@@ -364,8 +387,8 @@ static int rs5c_set_alarm(struct device *dev, struct rtc_wkalrm *t)
364{ 387{
365 struct i2c_client *client = to_i2c_client(dev); 388 struct i2c_client *client = to_i2c_client(dev);
366 struct rs5c372 *rs5c = i2c_get_clientdata(client); 389 struct rs5c372 *rs5c = i2c_get_clientdata(client);
367 int status; 390 int status, addr, i;
368 unsigned char buf[4]; 391 unsigned char buf[3];
369 392
370 /* only handle up to 24 hours in the future, like RTC_ALM_SET */ 393 /* only handle up to 24 hours in the future, like RTC_ALM_SET */
371 if (t->time.tm_mday != -1 394 if (t->time.tm_mday != -1
@@ -380,33 +403,36 @@ static int rs5c_set_alarm(struct device *dev, struct rtc_wkalrm *t)
380 if (status < 0) 403 if (status < 0)
381 return status; 404 return status;
382 if (rs5c->regs[RS5C_REG_CTRL1] & RS5C_CTRL1_AALE) { 405 if (rs5c->regs[RS5C_REG_CTRL1] & RS5C_CTRL1_AALE) {
383 buf[0] = RS5C_ADDR(RS5C_REG_CTRL1); 406 addr = RS5C_ADDR(RS5C_REG_CTRL1);
384 buf[1] = rs5c->regs[RS5C_REG_CTRL1] & ~RS5C_CTRL1_AALE; 407 buf[0] = rs5c->regs[RS5C_REG_CTRL1] & ~RS5C_CTRL1_AALE;
385 if (i2c_master_send(client, buf, 2) != 2) { 408 if (i2c_smbus_write_byte_data(client, addr, buf[0]) < 0) {
386 pr_debug("%s: can't disable alarm\n", rs5c->rtc->name); 409 pr_debug("%s: can't disable alarm\n", rs5c->rtc->name);
387 return -EIO; 410 return -EIO;
388 } 411 }
389 rs5c->regs[RS5C_REG_CTRL1] = buf[1]; 412 rs5c->regs[RS5C_REG_CTRL1] = buf[0];
390 } 413 }
391 414
392 /* set alarm */ 415 /* set alarm */
393 buf[0] = RS5C_ADDR(RS5C_REG_ALARM_A_MIN); 416 buf[0] = BIN2BCD(t->time.tm_min);
394 buf[1] = BIN2BCD(t->time.tm_min); 417 buf[1] = rs5c_hr2reg(rs5c, t->time.tm_hour);
395 buf[2] = rs5c_hr2reg(rs5c, t->time.tm_hour); 418 buf[2] = 0x7f; /* any/all days */
396 buf[3] = 0x7f; /* any/all days */ 419
397 if ((i2c_master_send(client, buf, 4)) != 4) { 420 for (i = 0; i < sizeof(buf); i++) {
398 pr_debug("%s: can't set alarm time\n", rs5c->rtc->name); 421 addr = RS5C_ADDR(RS5C_REG_ALARM_A_MIN + i);
399 return -EIO; 422 if (i2c_smbus_write_byte_data(client, addr, buf[i]) < 0) {
423 pr_debug("%s: can't set alarm time\n", rs5c->rtc->name);
424 return -EIO;
425 }
400 } 426 }
401 427
402 /* ... and maybe enable its irq */ 428 /* ... and maybe enable its irq */
403 if (t->enabled) { 429 if (t->enabled) {
404 buf[0] = RS5C_ADDR(RS5C_REG_CTRL1); 430 addr = RS5C_ADDR(RS5C_REG_CTRL1);
405 buf[1] = rs5c->regs[RS5C_REG_CTRL1] | RS5C_CTRL1_AALE; 431 buf[0] = rs5c->regs[RS5C_REG_CTRL1] | RS5C_CTRL1_AALE;
406 if ((i2c_master_send(client, buf, 2)) != 2) 432 if (i2c_smbus_write_byte_data(client, addr, buf[0]) < 0)
407 printk(KERN_WARNING "%s: can't enable alarm\n", 433 printk(KERN_WARNING "%s: can't enable alarm\n",
408 rs5c->rtc->name); 434 rs5c->rtc->name);
409 rs5c->regs[RS5C_REG_CTRL1] = buf[1]; 435 rs5c->regs[RS5C_REG_CTRL1] = buf[0];
410 } 436 }
411 437
412 return 0; 438 return 0;
@@ -503,18 +529,81 @@ static void rs5c_sysfs_unregister(struct device *dev)
503 529
504static struct i2c_driver rs5c372_driver; 530static struct i2c_driver rs5c372_driver;
505 531
532static int rs5c_oscillator_setup(struct rs5c372 *rs5c372)
533{
534 unsigned char buf[2];
535 int addr, i, ret = 0;
536
537 if (rs5c372->type == rtc_r2025sd) {
538 if (!(rs5c372->regs[RS5C_REG_CTRL2] & R2025_CTRL2_XST))
539 return ret;
540 rs5c372->regs[RS5C_REG_CTRL2] &= ~R2025_CTRL2_XST;
541 } else {
542 if (!(rs5c372->regs[RS5C_REG_CTRL2] & RS5C_CTRL2_XSTP))
543 return ret;
544 rs5c372->regs[RS5C_REG_CTRL2] &= ~RS5C_CTRL2_XSTP;
545 }
546
547 addr = RS5C_ADDR(RS5C_REG_CTRL1);
548 buf[0] = rs5c372->regs[RS5C_REG_CTRL1];
549 buf[1] = rs5c372->regs[RS5C_REG_CTRL2];
550
551 /* use 24hr mode */
552 switch (rs5c372->type) {
553 case rtc_rs5c372a:
554 case rtc_rs5c372b:
555 buf[1] |= RS5C372_CTRL2_24;
556 rs5c372->time24 = 1;
557 break;
558 case rtc_r2025sd:
559 case rtc_rv5c386:
560 case rtc_rv5c387a:
561 buf[0] |= RV5C387_CTRL1_24;
562 rs5c372->time24 = 1;
563 break;
564 default:
565 /* impossible */
566 break;
567 }
568
569 for (i = 0; i < sizeof(buf); i++) {
570 addr = RS5C_ADDR(RS5C_REG_CTRL1 + i);
571 ret = i2c_smbus_write_byte_data(rs5c372->client, addr, buf[i]);
572 if (unlikely(ret < 0))
573 return ret;
574 }
575
576 rs5c372->regs[RS5C_REG_CTRL1] = buf[0];
577 rs5c372->regs[RS5C_REG_CTRL2] = buf[1];
578
579 return 0;
580}
581
506static int rs5c372_probe(struct i2c_client *client, 582static int rs5c372_probe(struct i2c_client *client,
507 const struct i2c_device_id *id) 583 const struct i2c_device_id *id)
508{ 584{
509 int err = 0; 585 int err = 0;
586 int smbus_mode = 0;
510 struct rs5c372 *rs5c372; 587 struct rs5c372 *rs5c372;
511 struct rtc_time tm; 588 struct rtc_time tm;
512 589
513 dev_dbg(&client->dev, "%s\n", __func__); 590 dev_dbg(&client->dev, "%s\n", __func__);
514 591
515 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { 592 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C |
516 err = -ENODEV; 593 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_I2C_BLOCK)) {
517 goto exit; 594 /*
595 * If we don't have any master mode adapter, try breaking
596 * it down in to the barest of capabilities.
597 */
598 if (i2c_check_functionality(client->adapter,
599 I2C_FUNC_SMBUS_BYTE_DATA |
600 I2C_FUNC_SMBUS_I2C_BLOCK))
601 smbus_mode = 1;
602 else {
603 /* Still no good, give up */
604 err = -ENODEV;
605 goto exit;
606 }
518 } 607 }
519 608
520 if (!(rs5c372 = kzalloc(sizeof(struct rs5c372), GFP_KERNEL))) { 609 if (!(rs5c372 = kzalloc(sizeof(struct rs5c372), GFP_KERNEL))) {
@@ -528,6 +617,7 @@ static int rs5c372_probe(struct i2c_client *client,
528 617
529 /* we read registers 0x0f then 0x00-0x0f; skip the first one */ 618 /* we read registers 0x0f then 0x00-0x0f; skip the first one */
530 rs5c372->regs = &rs5c372->buf[1]; 619 rs5c372->regs = &rs5c372->buf[1];
620 rs5c372->smbus = smbus_mode;
531 621
532 err = rs5c_get_regs(rs5c372); 622 err = rs5c_get_regs(rs5c372);
533 if (err < 0) 623 if (err < 0)
@@ -543,6 +633,7 @@ static int rs5c372_probe(struct i2c_client *client,
543 if (rs5c372->regs[RS5C_REG_CTRL2] & RS5C372_CTRL2_24) 633 if (rs5c372->regs[RS5C_REG_CTRL2] & RS5C372_CTRL2_24)
544 rs5c372->time24 = 1; 634 rs5c372->time24 = 1;
545 break; 635 break;
636 case rtc_r2025sd:
546 case rtc_rv5c386: 637 case rtc_rv5c386:
547 case rtc_rv5c387a: 638 case rtc_rv5c387a:
548 if (rs5c372->regs[RS5C_REG_CTRL1] & RV5C387_CTRL1_24) 639 if (rs5c372->regs[RS5C_REG_CTRL1] & RV5C387_CTRL1_24)
@@ -558,39 +649,14 @@ static int rs5c372_probe(struct i2c_client *client,
558 649
559 /* if the oscillator lost power and no other software (like 650 /* if the oscillator lost power and no other software (like
560 * the bootloader) set it up, do it here. 651 * the bootloader) set it up, do it here.
652 *
653 * The R2025S/D does this a little differently than the other
654 * parts, so we special case that..
561 */ 655 */
562 if (rs5c372->regs[RS5C_REG_CTRL2] & RS5C_CTRL2_XSTP) { 656 err = rs5c_oscillator_setup(rs5c372);
563 unsigned char buf[3]; 657 if (unlikely(err < 0)) {
564 658 dev_err(&client->dev, "setup error\n");
565 rs5c372->regs[RS5C_REG_CTRL2] &= ~RS5C_CTRL2_XSTP; 659 goto exit_kfree;
566
567 buf[0] = RS5C_ADDR(RS5C_REG_CTRL1);
568 buf[1] = rs5c372->regs[RS5C_REG_CTRL1];
569 buf[2] = rs5c372->regs[RS5C_REG_CTRL2];
570
571 /* use 24hr mode */
572 switch (rs5c372->type) {
573 case rtc_rs5c372a:
574 case rtc_rs5c372b:
575 buf[2] |= RS5C372_CTRL2_24;
576 rs5c372->time24 = 1;
577 break;
578 case rtc_rv5c386:
579 case rtc_rv5c387a:
580 buf[1] |= RV5C387_CTRL1_24;
581 rs5c372->time24 = 1;
582 break;
583 default:
584 /* impossible */
585 break;
586 }
587
588 if ((i2c_master_send(client, buf, 3)) != 3) {
589 dev_err(&client->dev, "setup error\n");
590 goto exit_kfree;
591 }
592 rs5c372->regs[RS5C_REG_CTRL1] = buf[1];
593 rs5c372->regs[RS5C_REG_CTRL2] = buf[2];
594 } 660 }
595 661
596 if (rs5c372_get_datetime(client, &tm) < 0) 662 if (rs5c372_get_datetime(client, &tm) < 0)
@@ -598,6 +664,7 @@ static int rs5c372_probe(struct i2c_client *client,
598 664
599 dev_info(&client->dev, "%s found, %s, driver version " DRV_VERSION "\n", 665 dev_info(&client->dev, "%s found, %s, driver version " DRV_VERSION "\n",
600 ({ char *s; switch (rs5c372->type) { 666 ({ char *s; switch (rs5c372->type) {
667 case rtc_r2025sd: s = "r2025sd"; break;
601 case rtc_rs5c372a: s = "rs5c372a"; break; 668 case rtc_rs5c372a: s = "rs5c372a"; break;
602 case rtc_rs5c372b: s = "rs5c372b"; break; 669 case rtc_rs5c372b: s = "rs5c372b"; break;
603 case rtc_rv5c386: s = "rv5c386"; break; 670 case rtc_rv5c386: s = "rv5c386"; break;
@@ -667,7 +734,8 @@ module_exit(rs5c372_exit);
667 734
668MODULE_AUTHOR( 735MODULE_AUTHOR(
669 "Pavel Mironchik <pmironchik@optifacio.net>, " 736 "Pavel Mironchik <pmironchik@optifacio.net>, "
670 "Alessandro Zummo <a.zummo@towertech.it>"); 737 "Alessandro Zummo <a.zummo@towertech.it>, "
738 "Paul Mundt <lethal@linux-sh.org>");
671MODULE_DESCRIPTION("Ricoh RS5C372 RTC driver"); 739MODULE_DESCRIPTION("Ricoh RS5C372 RTC driver");
672MODULE_LICENSE("GPL"); 740MODULE_LICENSE("GPL");
673MODULE_VERSION(DRV_VERSION); 741MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index 1f88e9e914ec..fcead4c4cd1f 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -257,12 +257,6 @@ static inline void sh_rtc_setaie(struct device *dev, unsigned int enable)
257 spin_unlock_irq(&rtc->lock); 257 spin_unlock_irq(&rtc->lock);
258} 258}
259 259
260static void sh_rtc_release(struct device *dev)
261{
262 sh_rtc_setpie(dev, 0);
263 sh_rtc_setaie(dev, 0);
264}
265
266static int sh_rtc_proc(struct device *dev, struct seq_file *seq) 260static int sh_rtc_proc(struct device *dev, struct seq_file *seq)
267{ 261{
268 struct sh_rtc *rtc = dev_get_drvdata(dev); 262 struct sh_rtc *rtc = dev_get_drvdata(dev);
@@ -559,7 +553,6 @@ static int sh_rtc_irq_set_freq(struct device *dev, int freq)
559} 553}
560 554
561static struct rtc_class_ops sh_rtc_ops = { 555static struct rtc_class_ops sh_rtc_ops = {
562 .release = sh_rtc_release,
563 .ioctl = sh_rtc_ioctl, 556 .ioctl = sh_rtc_ioctl,
564 .read_time = sh_rtc_read_time, 557 .read_time = sh_rtc_read_time,
565 .set_time = sh_rtc_set_time, 558 .set_time = sh_rtc_set_time,
diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c
index 31d3c8c28588..9a7e920315fa 100644
--- a/drivers/rtc/rtc-stk17ta8.c
+++ b/drivers/rtc/rtc-stk17ta8.c
@@ -215,17 +215,6 @@ static irqreturn_t stk17ta8_rtc_interrupt(int irq, void *dev_id)
215 return IRQ_HANDLED; 215 return IRQ_HANDLED;
216} 216}
217 217
218static void stk17ta8_rtc_release(struct device *dev)
219{
220 struct platform_device *pdev = to_platform_device(dev);
221 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
222
223 if (pdata->irq >= 0) {
224 pdata->irqen = 0;
225 stk17ta8_rtc_update_alarm(pdata);
226 }
227}
228
229static int stk17ta8_rtc_ioctl(struct device *dev, unsigned int cmd, 218static int stk17ta8_rtc_ioctl(struct device *dev, unsigned int cmd,
230 unsigned long arg) 219 unsigned long arg)
231{ 220{
@@ -254,7 +243,6 @@ static const struct rtc_class_ops stk17ta8_rtc_ops = {
254 .set_time = stk17ta8_rtc_set_time, 243 .set_time = stk17ta8_rtc_set_time,
255 .read_alarm = stk17ta8_rtc_read_alarm, 244 .read_alarm = stk17ta8_rtc_read_alarm,
256 .set_alarm = stk17ta8_rtc_set_alarm, 245 .set_alarm = stk17ta8_rtc_set_alarm,
257 .release = stk17ta8_rtc_release,
258 .ioctl = stk17ta8_rtc_ioctl, 246 .ioctl = stk17ta8_rtc_ioctl,
259}; 247};
260 248
diff --git a/drivers/s390/char/fs3270.c b/drivers/s390/char/fs3270.c
index d18e6d2e0b49..40759c33477d 100644
--- a/drivers/s390/char/fs3270.c
+++ b/drivers/s390/char/fs3270.c
@@ -418,25 +418,22 @@ fs3270_open(struct inode *inode, struct file *filp)
418{ 418{
419 struct fs3270 *fp; 419 struct fs3270 *fp;
420 struct idal_buffer *ib; 420 struct idal_buffer *ib;
421 int minor, rc; 421 int minor, rc = 0;
422 422
423 if (imajor(filp->f_path.dentry->d_inode) != IBM_FS3270_MAJOR) 423 if (imajor(filp->f_path.dentry->d_inode) != IBM_FS3270_MAJOR)
424 return -ENODEV; 424 return -ENODEV;
425 lock_kernel();
426 minor = iminor(filp->f_path.dentry->d_inode); 425 minor = iminor(filp->f_path.dentry->d_inode);
427 /* Check for minor 0 multiplexer. */ 426 /* Check for minor 0 multiplexer. */
428 if (minor == 0) { 427 if (minor == 0) {
429 struct tty_struct *tty; 428 struct tty_struct *tty = get_current_tty();
430 mutex_lock(&tty_mutex);
431 tty = get_current_tty();
432 if (!tty || tty->driver->major != IBM_TTY3270_MAJOR) { 429 if (!tty || tty->driver->major != IBM_TTY3270_MAJOR) {
433 mutex_unlock(&tty_mutex); 430 tty_kref_put(tty);
434 rc = -ENODEV; 431 return -ENODEV;
435 goto out;
436 } 432 }
437 minor = tty->index + RAW3270_FIRSTMINOR; 433 minor = tty->index + RAW3270_FIRSTMINOR;
438 mutex_unlock(&tty_mutex); 434 tty_kref_put(tty);
439 } 435 }
436 lock_kernel();
440 /* Check if some other program is already using fullscreen mode. */ 437 /* Check if some other program is already using fullscreen mode. */
441 fp = (struct fs3270 *) raw3270_find_view(&fs3270_fn, minor); 438 fp = (struct fs3270 *) raw3270_find_view(&fs3270_fn, minor);
442 if (!IS_ERR(fp)) { 439 if (!IS_ERR(fp)) {
@@ -478,7 +475,7 @@ fs3270_open(struct inode *inode, struct file *filp)
478 filp->private_data = fp; 475 filp->private_data = fp;
479out: 476out:
480 unlock_kernel(); 477 unlock_kernel();
481 return 0; 478 return rc;
482} 479}
483 480
484/* 481/*
diff --git a/drivers/s390/char/raw3270.c b/drivers/s390/char/raw3270.c
index 1792b2c0130e..0b15cf107ec9 100644
--- a/drivers/s390/char/raw3270.c
+++ b/drivers/s390/char/raw3270.c
@@ -1168,19 +1168,17 @@ static int raw3270_create_attributes(struct raw3270 *rp)
1168 if (rc) 1168 if (rc)
1169 goto out; 1169 goto out;
1170 1170
1171 rp->clttydev = device_create_drvdata(class3270, &rp->cdev->dev, 1171 rp->clttydev = device_create(class3270, &rp->cdev->dev,
1172 MKDEV(IBM_TTY3270_MAJOR, rp->minor), 1172 MKDEV(IBM_TTY3270_MAJOR, rp->minor), NULL,
1173 NULL, 1173 "tty%s", dev_name(&rp->cdev->dev));
1174 "tty%s", dev_name(&rp->cdev->dev));
1175 if (IS_ERR(rp->clttydev)) { 1174 if (IS_ERR(rp->clttydev)) {
1176 rc = PTR_ERR(rp->clttydev); 1175 rc = PTR_ERR(rp->clttydev);
1177 goto out_ttydev; 1176 goto out_ttydev;
1178 } 1177 }
1179 1178
1180 rp->cltubdev = device_create_drvdata(class3270, &rp->cdev->dev, 1179 rp->cltubdev = device_create(class3270, &rp->cdev->dev,
1181 MKDEV(IBM_FS3270_MAJOR, rp->minor), 1180 MKDEV(IBM_FS3270_MAJOR, rp->minor), NULL,
1182 NULL, 1181 "tub%s", dev_name(&rp->cdev->dev));
1183 "tub%s", dev_name(&rp->cdev->dev));
1184 if (!IS_ERR(rp->cltubdev)) 1182 if (!IS_ERR(rp->cltubdev))
1185 goto out; 1183 goto out;
1186 1184
diff --git a/drivers/s390/char/tape_class.c b/drivers/s390/char/tape_class.c
index 12c2a5aaf31b..ddc914ccea8f 100644
--- a/drivers/s390/char/tape_class.c
+++ b/drivers/s390/char/tape_class.c
@@ -69,9 +69,9 @@ struct tape_class_device *register_tape_dev(
69 if (rc) 69 if (rc)
70 goto fail_with_cdev; 70 goto fail_with_cdev;
71 71
72 tcd->class_device = device_create_drvdata(tape_class, device, 72 tcd->class_device = device_create(tape_class, device,
73 tcd->char_device->dev, 73 tcd->char_device->dev, NULL,
74 NULL, "%s", tcd->device_name); 74 "%s", tcd->device_name);
75 rc = IS_ERR(tcd->class_device) ? PTR_ERR(tcd->class_device) : 0; 75 rc = IS_ERR(tcd->class_device) ? PTR_ERR(tcd->class_device) : 0;
76 if (rc) 76 if (rc)
77 goto fail_with_cdev; 77 goto fail_with_cdev;
diff --git a/drivers/s390/char/vmlogrdr.c b/drivers/s390/char/vmlogrdr.c
index 42173cc34610..24762727bc27 100644
--- a/drivers/s390/char/vmlogrdr.c
+++ b/drivers/s390/char/vmlogrdr.c
@@ -747,10 +747,10 @@ static int vmlogrdr_register_device(struct vmlogrdr_priv_t *priv)
747 device_unregister(dev); 747 device_unregister(dev);
748 return ret; 748 return ret;
749 } 749 }
750 priv->class_device = device_create_drvdata(vmlogrdr_class, dev, 750 priv->class_device = device_create(vmlogrdr_class, dev,
751 MKDEV(vmlogrdr_major, 751 MKDEV(vmlogrdr_major,
752 priv->minor_num), 752 priv->minor_num),
753 priv, "%s", dev_name(dev)); 753 priv, "%s", dev_name(dev));
754 if (IS_ERR(priv->class_device)) { 754 if (IS_ERR(priv->class_device)) {
755 ret = PTR_ERR(priv->class_device); 755 ret = PTR_ERR(priv->class_device);
756 priv->class_device=NULL; 756 priv->class_device=NULL;
diff --git a/drivers/s390/char/vmur.c b/drivers/s390/char/vmur.c
index 6fdfa5ddeca8..9020eba620ee 100644
--- a/drivers/s390/char/vmur.c
+++ b/drivers/s390/char/vmur.c
@@ -896,9 +896,8 @@ static int ur_set_online(struct ccw_device *cdev)
896 goto fail_free_cdev; 896 goto fail_free_cdev;
897 } 897 }
898 898
899 urd->device = device_create_drvdata(vmur_class, NULL, 899 urd->device = device_create(vmur_class, NULL, urd->char_device->dev,
900 urd->char_device->dev, NULL, 900 NULL, "%s", node_id);
901 "%s", node_id);
902 if (IS_ERR(urd->device)) { 901 if (IS_ERR(urd->device)) {
903 rc = PTR_ERR(urd->device); 902 rc = PTR_ERR(urd->device);
904 TRACE("ur_set_online: device_create rc=%d\n", rc); 903 TRACE("ur_set_online: device_create rc=%d\n", rc);
diff --git a/drivers/s390/net/claw.c b/drivers/s390/net/claw.c
index 8f83fc994f50..f5e618562c5f 100644
--- a/drivers/s390/net/claw.c
+++ b/drivers/s390/net/claw.c
@@ -2913,7 +2913,7 @@ claw_new_device(struct ccwgroup_device *cgdev)
2913 if (ret != 0) { 2913 if (ret != 0) {
2914 printk(KERN_WARNING 2914 printk(KERN_WARNING
2915 "claw: ccw_device_set_online %s WRITE failed " 2915 "claw: ccw_device_set_online %s WRITE failed "
2916 "with ret = %d\n", dev_name(&cgdev->cdev[WRITE]->dev) 2916 "with ret = %d\n", dev_name(&cgdev->cdev[WRITE]->dev),
2917 ret); 2917 ret);
2918 goto out; 2918 goto out;
2919 } 2919 }
diff --git a/drivers/s390/net/ctcm_mpc.c b/drivers/s390/net/ctcm_mpc.c
index cbe470493bf0..19f5d5ed85e0 100644
--- a/drivers/s390/net/ctcm_mpc.c
+++ b/drivers/s390/net/ctcm_mpc.c
@@ -1673,7 +1673,7 @@ static int mpc_validate_xid(struct mpcg_info *mpcginfo)
1673 1673
1674done: 1674done:
1675 if (rc) { 1675 if (rc) {
1676 ctcm_pr_info("ctcmpc : %s() failed\n", __FUNCTION__); 1676 ctcm_pr_info("ctcmpc : %s() failed\n", __func__);
1677 priv->xid->xid2_flag2 = 0x40; 1677 priv->xid->xid2_flag2 = 0x40;
1678 grp->saved_xid2->xid2_flag2 = 0x40; 1678 grp->saved_xid2->xid2_flag2 = 0x40;
1679 } 1679 }
diff --git a/drivers/scsi/Kconfig b/drivers/scsi/Kconfig
index d3b211af4e1c..403ecad48d4b 100644
--- a/drivers/scsi/Kconfig
+++ b/drivers/scsi/Kconfig
@@ -1640,6 +1640,7 @@ config ATARI_SCSI
1640 tristate "Atari native SCSI support" 1640 tristate "Atari native SCSI support"
1641 depends on ATARI && SCSI 1641 depends on ATARI && SCSI
1642 select SCSI_SPI_ATTRS 1642 select SCSI_SPI_ATTRS
1643 select NVRAM
1643 ---help--- 1644 ---help---
1644 If you have an Atari with built-in NCR5380 SCSI controller (TT, 1645 If you have an Atari with built-in NCR5380 SCSI controller (TT,
1645 Falcon, ...) say Y to get it supported. Of course also, if you have 1646 Falcon, ...) say Y to get it supported. Of course also, if you have
@@ -1670,14 +1671,6 @@ config ATARI_SCSI_RESET_BOOT
1670 boot process fractionally longer but may assist recovery from errors 1671 boot process fractionally longer but may assist recovery from errors
1671 that leave the devices with SCSI operations partway completed. 1672 that leave the devices with SCSI operations partway completed.
1672 1673
1673config TT_DMA_EMUL
1674 bool "Hades SCSI DMA emulator"
1675 depends on ATARI_SCSI && HADES
1676 help
1677 This option enables code which emulates the TT SCSI DMA chip on the
1678 Hades. This increases the SCSI transfer rates at least ten times
1679 compared to PIO transfers.
1680
1681config MAC_SCSI 1674config MAC_SCSI
1682 bool "Macintosh NCR5380 SCSI" 1675 bool "Macintosh NCR5380 SCSI"
1683 depends on MAC && SCSI=y 1676 depends on MAC && SCSI=y
diff --git a/drivers/scsi/atari_dma_emul.c b/drivers/scsi/atari_dma_emul.c
deleted file mode 100644
index cdc710ea00fa..000000000000
--- a/drivers/scsi/atari_dma_emul.c
+++ /dev/null
@@ -1,468 +0,0 @@
1/*
2 * atari_dma_emul.c -- TT SCSI DMA emulator for the Hades.
3 *
4 * Copyright 1997 Wout Klaren <W.Klaren@inter.nl.net>
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 *
10 * This code was written using the Hades TOS source code as a
11 * reference. This source code can be found on the home page
12 * of Medusa Computer Systems.
13 *
14 * Version 0.1, 1997-09-24.
15 *
16 * This code should be considered experimental. It has only been
17 * tested on a Hades with a 68060. It might not work on a Hades
18 * with a 68040. Make backups of your hard drives before using
19 * this code.
20 */
21
22#include <linux/compiler.h>
23#include <asm/thread_info.h>
24#include <asm/uaccess.h>
25
26#define hades_dma_ctrl (*(unsigned char *) 0xffff8717)
27#define hades_psdm_reg (*(unsigned char *) 0xffff8741)
28
29#define TRANSFER_SIZE 16
30
31struct m68040_frame {
32 unsigned long effaddr; /* effective address */
33 unsigned short ssw; /* special status word */
34 unsigned short wb3s; /* write back 3 status */
35 unsigned short wb2s; /* write back 2 status */
36 unsigned short wb1s; /* write back 1 status */
37 unsigned long faddr; /* fault address */
38 unsigned long wb3a; /* write back 3 address */
39 unsigned long wb3d; /* write back 3 data */
40 unsigned long wb2a; /* write back 2 address */
41 unsigned long wb2d; /* write back 2 data */
42 unsigned long wb1a; /* write back 1 address */
43 unsigned long wb1dpd0; /* write back 1 data/push data 0*/
44 unsigned long pd1; /* push data 1*/
45 unsigned long pd2; /* push data 2*/
46 unsigned long pd3; /* push data 3*/
47};
48
49static void writeback (unsigned short wbs, unsigned long wba,
50 unsigned long wbd, void *old_buserr)
51{
52 mm_segment_t fs = get_fs();
53 static void *save_buserr;
54
55 __asm__ __volatile__ ("movec.l %%vbr,%%a0\n\t"
56 "move.l %0,8(%%a0)\n\t"
57 :
58 : "r" (&&bus_error)
59 : "a0" );
60
61 save_buserr = old_buserr;
62
63 set_fs (MAKE_MM_SEG(wbs & WBTM_040));
64
65 switch (wbs & WBSIZ_040) {
66 case BA_SIZE_BYTE:
67 put_user (wbd & 0xff, (char *)wba);
68 break;
69 case BA_SIZE_WORD:
70 put_user (wbd & 0xffff, (short *)wba);
71 break;
72 case BA_SIZE_LONG:
73 put_user (wbd, (int *)wba);
74 break;
75 }
76
77 set_fs (fs);
78 return;
79
80bus_error:
81 __asm__ __volatile__ ("cmp.l %0,2(%%sp)\n\t"
82 "bcs.s .jump_old\n\t"
83 "cmp.l %1,2(%%sp)\n\t"
84 "bls.s .restore_old\n"
85 ".jump_old:\n\t"
86 "move.l %2,-(%%sp)\n\t"
87 "rts\n"
88 ".restore_old:\n\t"
89 "move.l %%a0,-(%%sp)\n\t"
90 "movec.l %%vbr,%%a0\n\t"
91 "move.l %2,8(%%a0)\n\t"
92 "move.l (%%sp)+,%%a0\n\t"
93 "rte\n\t"
94 :
95 : "i" (writeback), "i" (&&bus_error),
96 "m" (save_buserr) );
97}
98
99/*
100 * static inline void set_restdata_reg(unsigned char *cur_addr)
101 *
102 * Set the rest data register if necessary.
103 */
104
105static inline void set_restdata_reg(unsigned char *cur_addr)
106{
107 if (((long) cur_addr & ~3) != 0)
108 tt_scsi_dma.dma_restdata =
109 *((unsigned long *) ((long) cur_addr & ~3));
110}
111
112/*
113 * void hades_dma_emulator(int irq, void *dummy)
114 *
115 * This code emulates TT SCSI DMA on the Hades.
116 *
117 * Note the following:
118 *
119 * 1. When there is no byte available to read from the SCSI bus, or
120 * when a byte cannot yet bet written to the SCSI bus, a bus
121 * error occurs when reading or writing the pseudo DMA data
122 * register (hades_psdm_reg). We have to catch this bus error
123 * and try again to read or write the byte. If after several tries
124 * we still get a bus error, the interrupt handler is left. When
125 * the byte can be read or written, the interrupt handler is
126 * called again.
127 *
128 * 2. The SCSI interrupt must be disabled in this interrupt handler.
129 *
130 * 3. If we set the EOP signal, the SCSI controller still expects one
131 * byte to be read or written. Therefore the last byte is transferred
132 * separately, after setting the EOP signal.
133 *
134 * 4. When this function is left, the address pointer (start_addr) is
135 * converted to a physical address. Because it points one byte
136 * further than the last transferred byte, it can point outside the
137 * current page. If virt_to_phys() is called with this address we
138 * might get an access error. Therefore virt_to_phys() is called with
139 * start_addr - 1 if the count has reached zero. The result is
140 * increased with one.
141 */
142
143static irqreturn_t hades_dma_emulator(int irq, void *dummy)
144{
145 unsigned long dma_base;
146 register unsigned long dma_cnt asm ("d3");
147 static long save_buserr;
148 register unsigned long save_sp asm ("d4");
149 register int tries asm ("d5");
150 register unsigned char *start_addr asm ("a3"), *end_addr asm ("a4");
151 register unsigned char *eff_addr;
152 register unsigned char *psdm_reg;
153 unsigned long rem;
154
155 atari_disable_irq(IRQ_TT_MFP_SCSI);
156
157 /*
158 * Read the dma address and count registers.
159 */
160
161 dma_base = SCSI_DMA_READ_P(dma_addr);
162 dma_cnt = SCSI_DMA_READ_P(dma_cnt);
163
164 /*
165 * Check if DMA is still enabled.
166 */
167
168 if ((tt_scsi_dma.dma_ctrl & 2) == 0)
169 {
170 atari_enable_irq(IRQ_TT_MFP_SCSI);
171 return IRQ_HANDLED;
172 }
173
174 if (dma_cnt == 0)
175 {
176 printk(KERN_NOTICE "DMA emulation: count is zero.\n");
177 tt_scsi_dma.dma_ctrl &= 0xfd; /* DMA ready. */
178 atari_enable_irq(IRQ_TT_MFP_SCSI);
179 return IRQ_HANDLED;
180 }
181
182 /*
183 * Install new bus error routine.
184 */
185
186 __asm__ __volatile__ ("movec.l %%vbr,%%a0\n\t"
187 "move.l 8(%%a0),%0\n\t"
188 "move.l %1,8(%%a0)\n\t"
189 : "=&r" (save_buserr)
190 : "r" (&&scsi_bus_error)
191 : "a0" );
192
193 hades_dma_ctrl &= 0xfc; /* Bus error and EOP off. */
194
195 /*
196 * Save the stack pointer.
197 */
198
199 __asm__ __volatile__ ("move.l %%sp,%0\n\t"
200 : "=&r" (save_sp) );
201
202 tries = 100; /* Maximum number of bus errors. */
203 start_addr = phys_to_virt(dma_base);
204 end_addr = start_addr + dma_cnt;
205
206scsi_loop:
207 dma_cnt--;
208 rem = dma_cnt & (TRANSFER_SIZE - 1);
209 dma_cnt &= ~(TRANSFER_SIZE - 1);
210 psdm_reg = &hades_psdm_reg;
211
212 if (tt_scsi_dma.dma_ctrl & 1) /* Read or write? */
213 {
214 /*
215 * SCSI write. Abort when count is zero.
216 */
217
218 switch (rem)
219 {
220 case 0:
221 while (dma_cnt > 0)
222 {
223 dma_cnt -= TRANSFER_SIZE;
224
225 *psdm_reg = *start_addr++;
226 case 15:
227 *psdm_reg = *start_addr++;
228 case 14:
229 *psdm_reg = *start_addr++;
230 case 13:
231 *psdm_reg = *start_addr++;
232 case 12:
233 *psdm_reg = *start_addr++;
234 case 11:
235 *psdm_reg = *start_addr++;
236 case 10:
237 *psdm_reg = *start_addr++;
238 case 9:
239 *psdm_reg = *start_addr++;
240 case 8:
241 *psdm_reg = *start_addr++;
242 case 7:
243 *psdm_reg = *start_addr++;
244 case 6:
245 *psdm_reg = *start_addr++;
246 case 5:
247 *psdm_reg = *start_addr++;
248 case 4:
249 *psdm_reg = *start_addr++;
250 case 3:
251 *psdm_reg = *start_addr++;
252 case 2:
253 *psdm_reg = *start_addr++;
254 case 1:
255 *psdm_reg = *start_addr++;
256 }
257 }
258
259 hades_dma_ctrl |= 1; /* Set EOP. */
260 udelay(10);
261 *psdm_reg = *start_addr++; /* Dummy byte. */
262 tt_scsi_dma.dma_ctrl &= 0xfd; /* DMA ready. */
263 }
264 else
265 {
266 /*
267 * SCSI read. Abort when count is zero.
268 */
269
270 switch (rem)
271 {
272 case 0:
273 while (dma_cnt > 0)
274 {
275 dma_cnt -= TRANSFER_SIZE;
276
277 *start_addr++ = *psdm_reg;
278 case 15:
279 *start_addr++ = *psdm_reg;
280 case 14:
281 *start_addr++ = *psdm_reg;
282 case 13:
283 *start_addr++ = *psdm_reg;
284 case 12:
285 *start_addr++ = *psdm_reg;
286 case 11:
287 *start_addr++ = *psdm_reg;
288 case 10:
289 *start_addr++ = *psdm_reg;
290 case 9:
291 *start_addr++ = *psdm_reg;
292 case 8:
293 *start_addr++ = *psdm_reg;
294 case 7:
295 *start_addr++ = *psdm_reg;
296 case 6:
297 *start_addr++ = *psdm_reg;
298 case 5:
299 *start_addr++ = *psdm_reg;
300 case 4:
301 *start_addr++ = *psdm_reg;
302 case 3:
303 *start_addr++ = *psdm_reg;
304 case 2:
305 *start_addr++ = *psdm_reg;
306 case 1:
307 *start_addr++ = *psdm_reg;
308 }
309 }
310
311 hades_dma_ctrl |= 1; /* Set EOP. */
312 udelay(10);
313 *start_addr++ = *psdm_reg;
314 tt_scsi_dma.dma_ctrl &= 0xfd; /* DMA ready. */
315
316 set_restdata_reg(start_addr);
317 }
318
319 if (start_addr != end_addr)
320 printk(KERN_CRIT "DMA emulation: FATAL: Count is not zero at end of transfer.\n");
321
322 dma_cnt = end_addr - start_addr;
323
324scsi_end:
325 dma_base = (dma_cnt == 0) ? virt_to_phys(start_addr - 1) + 1 :
326 virt_to_phys(start_addr);
327
328 SCSI_DMA_WRITE_P(dma_addr, dma_base);
329 SCSI_DMA_WRITE_P(dma_cnt, dma_cnt);
330
331 /*
332 * Restore old bus error routine.
333 */
334
335 __asm__ __volatile__ ("movec.l %%vbr,%%a0\n\t"
336 "move.l %0,8(%%a0)\n\t"
337 :
338 : "r" (save_buserr)
339 : "a0" );
340
341 atari_enable_irq(IRQ_TT_MFP_SCSI);
342
343 return IRQ_HANDLED;
344
345scsi_bus_error:
346 /*
347 * First check if the bus error is caused by our code.
348 * If not, call the original handler.
349 */
350
351 __asm__ __volatile__ ("cmp.l %0,2(%%sp)\n\t"
352 "bcs.s .old_vector\n\t"
353 "cmp.l %1,2(%%sp)\n\t"
354 "bls.s .scsi_buserr\n"
355 ".old_vector:\n\t"
356 "move.l %2,-(%%sp)\n\t"
357 "rts\n"
358 ".scsi_buserr:\n\t"
359 :
360 : "i" (&&scsi_loop), "i" (&&scsi_end),
361 "m" (save_buserr) );
362
363 if (CPU_IS_060)
364 {
365 /*
366 * Get effective address and restore the stack.
367 */
368
369 __asm__ __volatile__ ("move.l 8(%%sp),%0\n\t"
370 "move.l %1,%%sp\n\t"
371 : "=a&" (eff_addr)
372 : "r" (save_sp) );
373 }
374 else
375 {
376 register struct m68040_frame *frame;
377
378 __asm__ __volatile__ ("lea 8(%%sp),%0\n\t"
379 : "=a&" (frame) );
380
381 if (tt_scsi_dma.dma_ctrl & 1)
382 {
383 /*
384 * Bus error while writing.
385 */
386
387 if (frame->wb3s & WBV_040)
388 {
389 if (frame->wb3a == (long) &hades_psdm_reg)
390 start_addr--;
391 else
392 writeback(frame->wb3s, frame->wb3a,
393 frame->wb3d, &&scsi_bus_error);
394 }
395
396 if (frame->wb2s & WBV_040)
397 {
398 if (frame->wb2a == (long) &hades_psdm_reg)
399 start_addr--;
400 else
401 writeback(frame->wb2s, frame->wb2a,
402 frame->wb2d, &&scsi_bus_error);
403 }
404
405 if (frame->wb1s & WBV_040)
406 {
407 if (frame->wb1a == (long) &hades_psdm_reg)
408 start_addr--;
409 }
410 }
411 else
412 {
413 /*
414 * Bus error while reading.
415 */
416
417 if (frame->wb3s & WBV_040)
418 writeback(frame->wb3s, frame->wb3a,
419 frame->wb3d, &&scsi_bus_error);
420 }
421
422 eff_addr = (unsigned char *) frame->faddr;
423
424 __asm__ __volatile__ ("move.l %0,%%sp\n\t"
425 :
426 : "r" (save_sp) );
427 }
428
429 dma_cnt = end_addr - start_addr;
430
431 if (eff_addr == &hades_psdm_reg)
432 {
433 /*
434 * Bus error occurred while reading the pseudo
435 * DMA register. Time out.
436 */
437
438 tries--;
439
440 if (tries <= 0)
441 {
442 if ((tt_scsi_dma.dma_ctrl & 1) == 0) /* Read or write? */
443 set_restdata_reg(start_addr);
444
445 if (dma_cnt <= 1)
446 printk(KERN_CRIT "DMA emulation: Fatal "
447 "error while %s the last byte.\n",
448 (tt_scsi_dma.dma_ctrl & 1)
449 ? "writing" : "reading");
450
451 goto scsi_end;
452 }
453 else
454 goto scsi_loop;
455 }
456 else
457 {
458 /*
459 * Bus error during pseudo DMA transfer.
460 * Terminate the DMA transfer.
461 */
462
463 hades_dma_ctrl |= 3; /* Set EOP and bus error. */
464 if ((tt_scsi_dma.dma_ctrl & 1) == 0) /* Read or write? */
465 set_restdata_reg(start_addr);
466 goto scsi_end;
467 }
468}
diff --git a/drivers/scsi/atari_scsi.c b/drivers/scsi/atari_scsi.c
index f5732d8f67fe..21fe07f9df87 100644
--- a/drivers/scsi/atari_scsi.c
+++ b/drivers/scsi/atari_scsi.c
@@ -249,10 +249,6 @@ static int setup_hostid = -1;
249module_param(setup_hostid, int, 0); 249module_param(setup_hostid, int, 0);
250 250
251 251
252#if defined(CONFIG_TT_DMA_EMUL)
253#include "atari_dma_emul.c"
254#endif
255
256#if defined(REAL_DMA) 252#if defined(REAL_DMA)
257 253
258static int scsi_dma_is_ignored_buserr(unsigned char dma_stat) 254static int scsi_dma_is_ignored_buserr(unsigned char dma_stat)
@@ -695,21 +691,8 @@ int atari_scsi_detect(struct scsi_host_template *host)
695#ifdef REAL_DMA 691#ifdef REAL_DMA
696 tt_scsi_dma.dma_ctrl = 0; 692 tt_scsi_dma.dma_ctrl = 0;
697 atari_dma_residual = 0; 693 atari_dma_residual = 0;
698#ifdef CONFIG_TT_DMA_EMUL 694
699 if (MACH_IS_HADES) { 695 if (MACH_IS_MEDUSA) {
700 if (request_irq(IRQ_AUTO_2, hades_dma_emulator,
701 IRQ_TYPE_PRIO, "Hades DMA emulator",
702 hades_dma_emulator)) {
703 printk(KERN_ERR "atari_scsi_detect: cannot allocate irq %d, aborting (MACH_IS_HADES)",IRQ_AUTO_2);
704 free_irq(IRQ_TT_MFP_SCSI, instance);
705 scsi_unregister(atari_scsi_host);
706 atari_stram_free(atari_dma_buffer);
707 atari_dma_buffer = 0;
708 return 0;
709 }
710 }
711#endif
712 if (MACH_IS_MEDUSA || MACH_IS_HADES) {
713 /* While the read overruns (described by Drew Eckhardt in 696 /* While the read overruns (described by Drew Eckhardt in
714 * NCR5380.c) never happened on TTs, they do in fact on the Medusa 697 * NCR5380.c) never happened on TTs, they do in fact on the Medusa
715 * (This was the cause why SCSI didn't work right for so long 698 * (This was the cause why SCSI didn't work right for so long
@@ -1007,11 +990,7 @@ static unsigned long atari_dma_xfer_len(unsigned long wanted_len,
1007 Scsi_Cmnd *cmd, int write_flag) 990 Scsi_Cmnd *cmd, int write_flag)
1008{ 991{
1009 unsigned long possible_len, limit; 992 unsigned long possible_len, limit;
1010#ifndef CONFIG_TT_DMA_EMUL 993
1011 if (MACH_IS_HADES)
1012 /* Hades has no SCSI DMA at all :-( Always force use of PIO */
1013 return 0;
1014#endif
1015 if (IS_A_TT()) 994 if (IS_A_TT())
1016 /* TT SCSI DMA can transfer arbitrary #bytes */ 995 /* TT SCSI DMA can transfer arbitrary #bytes */
1017 return wanted_len; 996 return wanted_len;
diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
index 3c257fe0893e..88ecf94ad979 100644
--- a/drivers/scsi/ch.c
+++ b/drivers/scsi/ch.c
@@ -914,9 +914,9 @@ static int ch_probe(struct device *dev)
914 ch->minor = minor; 914 ch->minor = minor;
915 sprintf(ch->name,"ch%d",ch->minor); 915 sprintf(ch->name,"ch%d",ch->minor);
916 916
917 class_dev = device_create_drvdata(ch_sysfs_class, dev, 917 class_dev = device_create(ch_sysfs_class, dev,
918 MKDEV(SCSI_CHANGER_MAJOR, ch->minor), 918 MKDEV(SCSI_CHANGER_MAJOR, ch->minor), ch,
919 ch, "s%s", ch->name); 919 "s%s", ch->name);
920 if (IS_ERR(class_dev)) { 920 if (IS_ERR(class_dev)) {
921 printk(KERN_WARNING "ch%d: device_create failed\n", 921 printk(KERN_WARNING "ch%d: device_create failed\n",
922 ch->minor); 922 ch->minor);
diff --git a/drivers/scsi/dpt_i2o.c b/drivers/scsi/dpt_i2o.c
index 1fe0901e8119..8aba4fdfb522 100644
--- a/drivers/scsi/dpt_i2o.c
+++ b/drivers/scsi/dpt_i2o.c
@@ -271,7 +271,7 @@ rebuild_sys_tab:
271 pHba->initialized = TRUE; 271 pHba->initialized = TRUE;
272 pHba->state &= ~DPTI_STATE_RESET; 272 pHba->state &= ~DPTI_STATE_RESET;
273 if (adpt_sysfs_class) { 273 if (adpt_sysfs_class) {
274 struct device *dev = device_create_drvdata(adpt_sysfs_class, 274 struct device *dev = device_create(adpt_sysfs_class,
275 NULL, MKDEV(DPTI_I2O_MAJOR, pHba->unit), NULL, 275 NULL, MKDEV(DPTI_I2O_MAJOR, pHba->unit), NULL,
276 "dpti%d", pHba->unit); 276 "dpti%d", pHba->unit);
277 if (IS_ERR(dev)) { 277 if (IS_ERR(dev)) {
diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c
index 90212ac33be3..740bad435995 100644
--- a/drivers/scsi/ide-scsi.c
+++ b/drivers/scsi/ide-scsi.c
@@ -82,7 +82,6 @@ typedef struct ide_scsi_obj {
82 struct gendisk *disk; 82 struct gendisk *disk;
83 struct Scsi_Host *host; 83 struct Scsi_Host *host;
84 84
85 struct ide_atapi_pc *pc; /* Current packet command */
86 unsigned long transform; /* SCSI cmd translation layer */ 85 unsigned long transform; /* SCSI cmd translation layer */
87 unsigned long log; /* log flags */ 86 unsigned long log; /* log flags */
88} idescsi_scsi_t; 87} idescsi_scsi_t;
@@ -137,10 +136,10 @@ static void ide_scsi_hex_dump(u8 *data, int len)
137 136
138static int idescsi_end_request(ide_drive_t *, int, int); 137static int idescsi_end_request(ide_drive_t *, int, int);
139 138
140static void ide_scsi_callback(ide_drive_t *drive) 139static void ide_scsi_callback(ide_drive_t *drive, int dsc)
141{ 140{
142 idescsi_scsi_t *scsi = drive_to_idescsi(drive); 141 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
143 struct ide_atapi_pc *pc = scsi->pc; 142 struct ide_atapi_pc *pc = drive->pc;
144 143
145 if (pc->flags & PC_FLAG_TIMEDOUT) 144 if (pc->flags & PC_FLAG_TIMEDOUT)
146 debug_log("%s: got timed out packet %lu at %lu\n", __func__, 145 debug_log("%s: got timed out packet %lu at %lu\n", __func__,
@@ -267,49 +266,10 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
267 spin_unlock_irqrestore(host->host_lock, flags); 266 spin_unlock_irqrestore(host->host_lock, flags);
268 kfree(pc); 267 kfree(pc);
269 blk_put_request(rq); 268 blk_put_request(rq);
270 scsi->pc = NULL; 269 drive->pc = NULL;
271 return 0; 270 return 0;
272} 271}
273 272
274static inline unsigned long get_timeout(struct ide_atapi_pc *pc)
275{
276 return max_t(unsigned long, WAIT_CMD, pc->timeout - jiffies);
277}
278
279static int idescsi_expiry(ide_drive_t *drive)
280{
281 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
282 struct ide_atapi_pc *pc = scsi->pc;
283
284 debug_log("%s called for %lu at %lu\n", __func__,
285 pc->scsi_cmd->serial_number, jiffies);
286
287 pc->flags |= PC_FLAG_TIMEDOUT;
288
289 return 0; /* we do not want the ide subsystem to retry */
290}
291
292/*
293 * Our interrupt handler.
294 */
295static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
296{
297 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
298 struct ide_atapi_pc *pc = scsi->pc;
299
300 return ide_pc_intr(drive, pc, idescsi_pc_intr, get_timeout(pc),
301 idescsi_expiry, NULL, NULL, NULL,
302 ide_io_buffers);
303}
304
305static ide_startstop_t idescsi_transfer_pc(ide_drive_t *drive)
306{
307 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
308
309 return ide_transfer_pc(drive, scsi->pc, idescsi_pc_intr,
310 get_timeout(scsi->pc), idescsi_expiry);
311}
312
313static inline int idescsi_set_direction(struct ide_atapi_pc *pc) 273static inline int idescsi_set_direction(struct ide_atapi_pc *pc)
314{ 274{
315 switch (pc->c[0]) { 275 switch (pc->c[0]) {
@@ -352,13 +312,10 @@ static int idescsi_map_sg(ide_drive_t *drive, struct ide_atapi_pc *pc)
352static ide_startstop_t idescsi_issue_pc(ide_drive_t *drive, 312static ide_startstop_t idescsi_issue_pc(ide_drive_t *drive,
353 struct ide_atapi_pc *pc) 313 struct ide_atapi_pc *pc)
354{ 314{
355 idescsi_scsi_t *scsi = drive_to_idescsi(drive);
356
357 /* Set the current packet command */ 315 /* Set the current packet command */
358 scsi->pc = pc; 316 drive->pc = pc;
359 317
360 return ide_issue_pc(drive, pc, idescsi_transfer_pc, 318 return ide_issue_pc(drive, ide_scsi_get_timeout(pc), ide_scsi_expiry);
361 get_timeout(pc), idescsi_expiry);
362} 319}
363 320
364/* 321/*
@@ -374,7 +331,8 @@ static ide_startstop_t idescsi_do_request (ide_drive_t *drive, struct request *r
374 if (blk_sense_request(rq) || blk_special_request(rq)) { 331 if (blk_sense_request(rq) || blk_special_request(rq)) {
375 struct ide_atapi_pc *pc = (struct ide_atapi_pc *)rq->special; 332 struct ide_atapi_pc *pc = (struct ide_atapi_pc *)rq->special;
376 333
377 if (drive->using_dma && !idescsi_map_sg(drive, pc)) 334 if ((drive->dev_flags & IDE_DFLAG_USING_DMA) &&
335 idescsi_map_sg(drive, pc) == 0)
378 pc->flags |= PC_FLAG_DMA_OK; 336 pc->flags |= PC_FLAG_DMA_OK;
379 337
380 return idescsi_issue_pc(drive, pc); 338 return idescsi_issue_pc(drive, pc);
@@ -427,14 +385,14 @@ static const struct ide_proc_devset idescsi_settings[] = {
427 */ 385 */
428static void idescsi_setup (ide_drive_t *drive, idescsi_scsi_t *scsi) 386static void idescsi_setup (ide_drive_t *drive, idescsi_scsi_t *scsi)
429{ 387{
430 if ((drive->id[ATA_ID_CONFIG] & 0x0060) == 0x20)
431 set_bit(IDE_AFLAG_DRQ_INTERRUPT, &drive->atapi_flags);
432 clear_bit(IDESCSI_SG_TRANSFORM, &scsi->transform); 388 clear_bit(IDESCSI_SG_TRANSFORM, &scsi->transform);
433#if IDESCSI_DEBUG_LOG 389#if IDESCSI_DEBUG_LOG
434 set_bit(IDESCSI_LOG_CMD, &scsi->log); 390 set_bit(IDESCSI_LOG_CMD, &scsi->log);
435#endif /* IDESCSI_DEBUG_LOG */ 391#endif /* IDESCSI_DEBUG_LOG */
436 392
437 drive->pc_callback = ide_scsi_callback; 393 drive->pc_callback = ide_scsi_callback;
394 drive->pc_update_buffers = NULL;
395 drive->pc_io_buffers = ide_io_buffers;
438 396
439 ide_proc_register_driver(drive, scsi->driver); 397 ide_proc_register_driver(drive, scsi->driver);
440} 398}
@@ -456,7 +414,7 @@ static void ide_scsi_remove(ide_drive_t *drive)
456 414
457 ide_scsi_put(scsi); 415 ide_scsi_put(scsi);
458 416
459 drive->scsi = 0; 417 drive->dev_flags &= ~IDE_DFLAG_SCSI;
460} 418}
461 419
462static int ide_scsi_probe(ide_drive_t *); 420static int ide_scsi_probe(ide_drive_t *);
@@ -477,7 +435,6 @@ static ide_driver_t idescsi_driver = {
477 .probe = ide_scsi_probe, 435 .probe = ide_scsi_probe,
478 .remove = ide_scsi_remove, 436 .remove = ide_scsi_remove,
479 .version = IDESCSI_VERSION, 437 .version = IDESCSI_VERSION,
480 .media = ide_scsi,
481 .do_request = idescsi_do_request, 438 .do_request = idescsi_do_request,
482 .end_request = idescsi_end_request, 439 .end_request = idescsi_end_request,
483 .error = idescsi_atapi_error, 440 .error = idescsi_atapi_error,
@@ -622,6 +579,8 @@ static int idescsi_eh_abort (struct scsi_cmnd *cmd)
622 int busy; 579 int busy;
623 int ret = FAILED; 580 int ret = FAILED;
624 581
582 struct ide_atapi_pc *pc;
583
625 /* In idescsi_eh_abort we try to gently pry our command from the ide subsystem */ 584 /* In idescsi_eh_abort we try to gently pry our command from the ide subsystem */
626 585
627 if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) 586 if (test_bit(IDESCSI_LOG_CMD, &scsi->log))
@@ -642,26 +601,27 @@ static int idescsi_eh_abort (struct scsi_cmnd *cmd)
642 spin_lock_irq(&ide_lock); 601 spin_lock_irq(&ide_lock);
643 602
644 /* If there is no pc running we're done (our interrupt took care of it) */ 603 /* If there is no pc running we're done (our interrupt took care of it) */
645 if (!scsi->pc) { 604 pc = drive->pc;
605 if (pc == NULL) {
646 ret = SUCCESS; 606 ret = SUCCESS;
647 goto ide_unlock; 607 goto ide_unlock;
648 } 608 }
649 609
650 /* It's somewhere in flight. Does ide subsystem agree? */ 610 /* It's somewhere in flight. Does ide subsystem agree? */
651 if (scsi->pc->scsi_cmd->serial_number == cmd->serial_number && !busy && 611 if (pc->scsi_cmd->serial_number == cmd->serial_number && !busy &&
652 elv_queue_empty(drive->queue) && HWGROUP(drive)->rq != scsi->pc->rq) { 612 elv_queue_empty(drive->queue) && HWGROUP(drive)->rq != pc->rq) {
653 /* 613 /*
654 * FIXME - not sure this condition can ever occur 614 * FIXME - not sure this condition can ever occur
655 */ 615 */
656 printk (KERN_ERR "ide-scsi: cmd aborted!\n"); 616 printk (KERN_ERR "ide-scsi: cmd aborted!\n");
657 617
658 if (blk_sense_request(scsi->pc->rq)) 618 if (blk_sense_request(pc->rq))
659 kfree(scsi->pc->buf); 619 kfree(pc->buf);
660 /* we need to call blk_put_request twice. */ 620 /* we need to call blk_put_request twice. */
661 blk_put_request(scsi->pc->rq); 621 blk_put_request(pc->rq);
662 blk_put_request(scsi->pc->rq); 622 blk_put_request(pc->rq);
663 kfree(scsi->pc); 623 kfree(pc);
664 scsi->pc = NULL; 624 drive->pc = NULL;
665 625
666 ret = SUCCESS; 626 ret = SUCCESS;
667 } 627 }
@@ -683,6 +643,8 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
683 int ready = 0; 643 int ready = 0;
684 int ret = SUCCESS; 644 int ret = SUCCESS;
685 645
646 struct ide_atapi_pc *pc;
647
686 /* In idescsi_eh_reset we forcefully remove the command from the ide subsystem and reset the device. */ 648 /* In idescsi_eh_reset we forcefully remove the command from the ide subsystem and reset the device. */
687 649
688 if (test_bit(IDESCSI_LOG_CMD, &scsi->log)) 650 if (test_bit(IDESCSI_LOG_CMD, &scsi->log))
@@ -697,7 +659,9 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
697 spin_lock_irq(cmd->device->host->host_lock); 659 spin_lock_irq(cmd->device->host->host_lock);
698 spin_lock(&ide_lock); 660 spin_lock(&ide_lock);
699 661
700 if (!scsi->pc || (req = scsi->pc->rq) != HWGROUP(drive)->rq || !HWGROUP(drive)->handler) { 662 pc = drive->pc;
663
664 if (pc == NULL || (req = pc->rq) != HWGROUP(drive)->rq || !HWGROUP(drive)->handler) {
701 printk (KERN_WARNING "ide-scsi: No active request in idescsi_eh_reset\n"); 665 printk (KERN_WARNING "ide-scsi: No active request in idescsi_eh_reset\n");
702 spin_unlock(&ide_lock); 666 spin_unlock(&ide_lock);
703 spin_unlock_irq(cmd->device->host->host_lock); 667 spin_unlock_irq(cmd->device->host->host_lock);
@@ -708,9 +672,9 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
708 if (__blk_end_request(req, -EIO, 0)) 672 if (__blk_end_request(req, -EIO, 0))
709 BUG(); 673 BUG();
710 if (blk_sense_request(req)) 674 if (blk_sense_request(req))
711 kfree(scsi->pc->buf); 675 kfree(pc->buf);
712 kfree(scsi->pc); 676 kfree(pc);
713 scsi->pc = NULL; 677 drive->pc = NULL;
714 blk_put_request(req); 678 blk_put_request(req);
715 679
716 /* now nuke the drive queue */ 680 /* now nuke the drive queue */
@@ -801,7 +765,7 @@ static int ide_scsi_probe(ide_drive_t *drive)
801 !(host = scsi_host_alloc(&idescsi_template,sizeof(idescsi_scsi_t)))) 765 !(host = scsi_host_alloc(&idescsi_template,sizeof(idescsi_scsi_t))))
802 return -ENODEV; 766 return -ENODEV;
803 767
804 drive->scsi = 1; 768 drive->dev_flags |= IDE_DFLAG_SCSI;
805 769
806 g = alloc_disk(1 << PARTN_BITS); 770 g = alloc_disk(1 << PARTN_BITS);
807 if (!g) 771 if (!g)
@@ -842,7 +806,7 @@ static int ide_scsi_probe(ide_drive_t *drive)
842 806
843 put_disk(g); 807 put_disk(g);
844out_host_put: 808out_host_put:
845 drive->scsi = 0; 809 drive->dev_flags &= ~IDE_DFLAG_SCSI;
846 scsi_host_put(host); 810 scsi_host_put(host);
847 return err; 811 return err;
848} 812}
diff --git a/drivers/scsi/osst.c b/drivers/scsi/osst.c
index 1c79f9794f4e..0ea78d9a37db 100644
--- a/drivers/scsi/osst.c
+++ b/drivers/scsi/osst.c
@@ -5708,7 +5708,8 @@ static int osst_sysfs_add(dev_t dev, struct device *device, struct osst_tape * S
5708 struct device *osst_member; 5708 struct device *osst_member;
5709 int err; 5709 int err;
5710 5710
5711 osst_member = device_create_drvdata(osst_sysfs_class, device, dev, STp, "%s", name); 5711 osst_member = device_create(osst_sysfs_class, device, dev, STp,
5712 "%s", name);
5712 if (IS_ERR(osst_member)) { 5713 if (IS_ERR(osst_member)) {
5713 printk(KERN_WARNING "osst :W: Unable to add sysfs class member %s\n", name); 5714 printk(KERN_WARNING "osst :W: Unable to add sysfs class member %s\n", name);
5714 return PTR_ERR(osst_member); 5715 return PTR_ERR(osst_member);
diff --git a/drivers/scsi/pcmcia/aha152x_stub.c b/drivers/scsi/pcmcia/aha152x_stub.c
index 2dd0dc9a9aed..165ff884f48e 100644
--- a/drivers/scsi/pcmcia/aha152x_stub.c
+++ b/drivers/scsi/pcmcia/aha152x_stub.c
@@ -140,44 +140,41 @@ static void aha152x_detach(struct pcmcia_device *link)
140#define CS_CHECK(fn, ret) \ 140#define CS_CHECK(fn, ret) \
141do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 141do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
142 142
143static int aha152x_config_check(struct pcmcia_device *p_dev,
144 cistpl_cftable_entry_t *cfg,
145 cistpl_cftable_entry_t *dflt,
146 unsigned int vcc,
147 void *priv_data)
148{
149 /* For New Media T&J, look for a SCSI window */
150 if (cfg->io.win[0].len >= 0x20)
151 p_dev->io.BasePort1 = cfg->io.win[0].base;
152 else if ((cfg->io.nwin > 1) &&
153 (cfg->io.win[1].len >= 0x20))
154 p_dev->io.BasePort1 = cfg->io.win[1].base;
155 if ((cfg->io.nwin > 0) &&
156 (p_dev->io.BasePort1 < 0xffff)) {
157 if (!pcmcia_request_io(p_dev, &p_dev->io))
158 return 0;
159 }
160 return -EINVAL;
161}
162
143static int aha152x_config_cs(struct pcmcia_device *link) 163static int aha152x_config_cs(struct pcmcia_device *link)
144{ 164{
145 scsi_info_t *info = link->priv; 165 scsi_info_t *info = link->priv;
146 struct aha152x_setup s; 166 struct aha152x_setup s;
147 tuple_t tuple; 167 int last_ret, last_fn;
148 cisparse_t parse;
149 int i, last_ret, last_fn;
150 u_char tuple_data[64];
151 struct Scsi_Host *host; 168 struct Scsi_Host *host;
152 169
153 DEBUG(0, "aha152x_config(0x%p)\n", link); 170 DEBUG(0, "aha152x_config(0x%p)\n", link);
154 171
155 tuple.TupleData = tuple_data; 172 last_ret = pcmcia_loop_config(link, aha152x_config_check, NULL);
156 tuple.TupleDataMax = 64; 173 if (last_ret) {
157 tuple.TupleOffset = 0; 174 cs_error(link, RequestIO, last_ret);
158 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 175 goto failed;
159 tuple.Attributes = 0;
160 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
161 while (1) {
162 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
163 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
164 goto next_entry;
165 /* For New Media T&J, look for a SCSI window */
166 if (parse.cftable_entry.io.win[0].len >= 0x20)
167 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
168 else if ((parse.cftable_entry.io.nwin > 1) &&
169 (parse.cftable_entry.io.win[1].len >= 0x20))
170 link->io.BasePort1 = parse.cftable_entry.io.win[1].base;
171 if ((parse.cftable_entry.io.nwin > 0) &&
172 (link->io.BasePort1 < 0xffff)) {
173 link->conf.ConfigIndex = parse.cftable_entry.index;
174 i = pcmcia_request_io(link, &link->io);
175 if (i == CS_SUCCESS) break;
176 }
177 next_entry:
178 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
179 } 176 }
180 177
181 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 178 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
182 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); 179 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
183 180
@@ -208,6 +205,7 @@ static int aha152x_config_cs(struct pcmcia_device *link)
208 205
209cs_failed: 206cs_failed:
210 cs_error(link, last_fn, last_ret); 207 cs_error(link, last_fn, last_ret);
208failed:
211 aha152x_release_cs(link); 209 aha152x_release_cs(link);
212 return -ENODEV; 210 return -ENODEV;
213} 211}
diff --git a/drivers/scsi/pcmcia/fdomain_stub.c b/drivers/scsi/pcmcia/fdomain_stub.c
index d8b99351b053..06254f46a0dd 100644
--- a/drivers/scsi/pcmcia/fdomain_stub.c
+++ b/drivers/scsi/pcmcia/fdomain_stub.c
@@ -123,34 +123,30 @@ static void fdomain_detach(struct pcmcia_device *link)
123#define CS_CHECK(fn, ret) \ 123#define CS_CHECK(fn, ret) \
124do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 124do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
125 125
126static int fdomain_config_check(struct pcmcia_device *p_dev,
127 cistpl_cftable_entry_t *cfg,
128 cistpl_cftable_entry_t *dflt,
129 unsigned int vcc,
130 void *priv_data)
131{
132 p_dev->io.BasePort1 = cfg->io.win[0].base;
133 return pcmcia_request_io(p_dev, &p_dev->io);
134}
135
136
126static int fdomain_config(struct pcmcia_device *link) 137static int fdomain_config(struct pcmcia_device *link)
127{ 138{
128 scsi_info_t *info = link->priv; 139 scsi_info_t *info = link->priv;
129 tuple_t tuple; 140 int last_ret, last_fn;
130 cisparse_t parse;
131 int i, last_ret, last_fn;
132 u_char tuple_data[64];
133 char str[22]; 141 char str[22];
134 struct Scsi_Host *host; 142 struct Scsi_Host *host;
135 143
136 DEBUG(0, "fdomain_config(0x%p)\n", link); 144 DEBUG(0, "fdomain_config(0x%p)\n", link);
137 145
138 tuple.TupleData = tuple_data; 146 last_ret = pcmcia_loop_config(link, fdomain_config_check, NULL);
139 tuple.TupleDataMax = 64; 147 if (last_ret) {
140 tuple.TupleOffset = 0; 148 cs_error(link, RequestIO, last_ret);
141 149 goto failed;
142 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
143 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
144 while (1) {
145 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
146 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
147 goto next_entry;
148 link->conf.ConfigIndex = parse.cftable_entry.index;
149 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
150 i = pcmcia_request_io(link, &link->io);
151 if (i == CS_SUCCESS) break;
152 next_entry:
153 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
154 } 150 }
155 151
156 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 152 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
@@ -181,6 +177,7 @@ static int fdomain_config(struct pcmcia_device *link)
181 177
182cs_failed: 178cs_failed:
183 cs_error(link, last_fn, last_ret); 179 cs_error(link, last_fn, last_ret);
180failed:
184 fdomain_release(link); 181 fdomain_release(link);
185 return -ENODEV; 182 return -ENODEV;
186} /* fdomain_config */ 183} /* fdomain_config */
diff --git a/drivers/scsi/pcmcia/nsp_cs.c b/drivers/scsi/pcmcia/nsp_cs.c
index 24e6cb8396e3..11a61ea8d5d9 100644
--- a/drivers/scsi/pcmcia/nsp_cs.c
+++ b/drivers/scsi/pcmcia/nsp_cs.c
@@ -1606,133 +1606,129 @@ static void nsp_cs_detach(struct pcmcia_device *link)
1606 is received, to configure the PCMCIA socket, and to make the 1606 is received, to configure the PCMCIA socket, and to make the
1607 ethernet device available to the system. 1607 ethernet device available to the system.
1608======================================================================*/ 1608======================================================================*/
1609#define CS_CHECK(fn, ret) \
1610do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
1611/*====================================================================*/
1612static int nsp_cs_config(struct pcmcia_device *link)
1613{
1614 int ret;
1615 scsi_info_t *info = link->priv;
1616 tuple_t tuple;
1617 cisparse_t parse;
1618 int last_ret, last_fn;
1619 unsigned char tuple_data[64];
1620 config_info_t conf;
1621 win_req_t req;
1622 memreq_t map;
1623 cistpl_cftable_entry_t dflt = { 0 };
1624 struct Scsi_Host *host;
1625 nsp_hw_data *data = &nsp_data_base;
1626
1627 nsp_dbg(NSP_DEBUG_INIT, "in");
1628
1629 tuple.Attributes = 0;
1630 tuple.TupleData = tuple_data;
1631 tuple.TupleDataMax = sizeof(tuple_data);
1632 tuple.TupleOffset = 0;
1633
1634 /* Look up the current Vcc */
1635 CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &conf));
1636 1609
1637 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; 1610struct nsp_cs_configdata {
1638 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple)); 1611 nsp_hw_data *data;
1639 while (1) { 1612 win_req_t req;
1640 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry); 1613};
1641 1614
1642 if (pcmcia_get_tuple_data(link, &tuple) != 0 || 1615static int nsp_cs_config_check(struct pcmcia_device *p_dev,
1643 pcmcia_parse_tuple(link, &tuple, &parse) != 0) 1616 cistpl_cftable_entry_t *cfg,
1644 goto next_entry; 1617 cistpl_cftable_entry_t *dflt,
1618 unsigned int vcc,
1619 void *priv_data)
1620{
1621 struct nsp_cs_configdata *cfg_mem = priv_data;
1645 1622
1646 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) { dflt = *cfg; } 1623 if (cfg->index == 0)
1647 if (cfg->index == 0) { goto next_entry; } 1624 return -ENODEV;
1648 link->conf.ConfigIndex = cfg->index;
1649 1625
1650 /* Does this card need audio output? */ 1626 /* Does this card need audio output? */
1651 if (cfg->flags & CISTPL_CFTABLE_AUDIO) { 1627 if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
1652 link->conf.Attributes |= CONF_ENABLE_SPKR; 1628 p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
1653 link->conf.Status = CCSR_AUDIO_ENA; 1629 p_dev->conf.Status = CCSR_AUDIO_ENA;
1654 } 1630 }
1655 1631
1656 /* Use power settings for Vcc and Vpp if present */ 1632 /* Use power settings for Vcc and Vpp if present */
1657 /* Note that the CIS values need to be rescaled */ 1633 /* Note that the CIS values need to be rescaled */
1658 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) { 1634 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
1659 if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000) { 1635 if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000)
1660 goto next_entry; 1636 return -ENODEV;
1661 } 1637 else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) {
1662 } else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM)) { 1638 if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM]/10000)
1663 if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM]/10000) { 1639 return -ENODEV;
1664 goto next_entry;
1665 }
1666 } 1640 }
1667 1641
1668 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) { 1642 if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) {
1669 link->conf.Vpp = 1643 p_dev->conf.Vpp =
1670 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; 1644 cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
1671 } else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) { 1645 } else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM)) {
1672 link->conf.Vpp = 1646 p_dev->conf.Vpp =
1673 dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; 1647 dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
1674 } 1648 }
1675 1649
1676 /* Do we need to allocate an interrupt? */ 1650 /* Do we need to allocate an interrupt? */
1677 if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) { 1651 if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
1678 link->conf.Attributes |= CONF_ENABLE_IRQ; 1652 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
1679 }
1680 1653
1681 /* IO window settings */ 1654 /* IO window settings */
1682 link->io.NumPorts1 = link->io.NumPorts2 = 0; 1655 p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
1683 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { 1656 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
1684 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; 1657 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
1685 link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; 1658 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
1686 if (!(io->flags & CISTPL_IO_8BIT)) 1659 if (!(io->flags & CISTPL_IO_8BIT))
1687 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; 1660 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
1688 if (!(io->flags & CISTPL_IO_16BIT)) 1661 if (!(io->flags & CISTPL_IO_16BIT))
1689 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; 1662 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
1690 link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; 1663 p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
1691 link->io.BasePort1 = io->win[0].base; 1664 p_dev->io.BasePort1 = io->win[0].base;
1692 link->io.NumPorts1 = io->win[0].len; 1665 p_dev->io.NumPorts1 = io->win[0].len;
1693 if (io->nwin > 1) { 1666 if (io->nwin > 1) {
1694 link->io.Attributes2 = link->io.Attributes1; 1667 p_dev->io.Attributes2 = p_dev->io.Attributes1;
1695 link->io.BasePort2 = io->win[1].base; 1668 p_dev->io.BasePort2 = io->win[1].base;
1696 link->io.NumPorts2 = io->win[1].len; 1669 p_dev->io.NumPorts2 = io->win[1].len;
1697 } 1670 }
1698 /* This reserves IO space but doesn't actually enable it */ 1671 /* This reserves IO space but doesn't actually enable it */
1699 if (pcmcia_request_io(link, &link->io) != 0) 1672 if (pcmcia_request_io(p_dev, &p_dev->io) != 0)
1700 goto next_entry; 1673 goto next_entry;
1701 } 1674 }
1702 1675
1703 if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) { 1676 if ((cfg->mem.nwin > 0) || (dflt->mem.nwin > 0)) {
1704 cistpl_mem_t *mem = 1677 memreq_t map;
1705 (cfg->mem.nwin) ? &cfg->mem : &dflt.mem; 1678 cistpl_mem_t *mem =
1706 req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM; 1679 (cfg->mem.nwin) ? &cfg->mem : &dflt->mem;
1707 req.Attributes |= WIN_ENABLE; 1680 cfg_mem->req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
1708 req.Base = mem->win[0].host_addr; 1681 cfg_mem->req.Attributes |= WIN_ENABLE;
1709 req.Size = mem->win[0].len; 1682 cfg_mem->req.Base = mem->win[0].host_addr;
1710 if (req.Size < 0x1000) { 1683 cfg_mem->req.Size = mem->win[0].len;
1711 req.Size = 0x1000; 1684 if (cfg_mem->req.Size < 0x1000)
1712 } 1685 cfg_mem->req.Size = 0x1000;
1713 req.AccessSpeed = 0; 1686 cfg_mem->req.AccessSpeed = 0;
1714 if (pcmcia_request_window(&link, &req, &link->win) != 0) 1687 if (pcmcia_request_window(&p_dev, &cfg_mem->req, &p_dev->win) != 0)
1715 goto next_entry; 1688 goto next_entry;
1716 map.Page = 0; map.CardOffset = mem->win[0].card_addr; 1689 map.Page = 0; map.CardOffset = mem->win[0].card_addr;
1717 if (pcmcia_map_mem_page(link->win, &map) != 0) 1690 if (pcmcia_map_mem_page(p_dev->win, &map) != 0)
1718 goto next_entry; 1691 goto next_entry;
1719 1692
1720 data->MmioAddress = (unsigned long)ioremap_nocache(req.Base, req.Size); 1693 cfg_mem->data->MmioAddress = (unsigned long) ioremap_nocache(cfg_mem->req.Base, cfg_mem->req.Size);
1721 data->MmioLength = req.Size; 1694 cfg_mem->data->MmioLength = cfg_mem->req.Size;
1722 } 1695 }
1723 /* If we got this far, we're cool! */ 1696 /* If we got this far, we're cool! */
1724 break; 1697 return 0;
1725
1726 next_entry:
1727 nsp_dbg(NSP_DEBUG_INIT, "next");
1728 pcmcia_disable_device(link);
1729 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
1730 } 1698 }
1731 1699
1700next_entry:
1701 nsp_dbg(NSP_DEBUG_INIT, "next");
1702 pcmcia_disable_device(p_dev);
1703 return -ENODEV;
1704}
1705
1706static int nsp_cs_config(struct pcmcia_device *link)
1707{
1708 int ret;
1709 scsi_info_t *info = link->priv;
1710 struct nsp_cs_configdata *cfg_mem;
1711 struct Scsi_Host *host;
1712 nsp_hw_data *data = &nsp_data_base;
1713
1714 nsp_dbg(NSP_DEBUG_INIT, "in");
1715
1716 cfg_mem = kzalloc(sizeof(cfg_mem), GFP_KERNEL);
1717 if (!cfg_mem)
1718 return -ENOMEM;
1719 cfg_mem->data = data;
1720
1721 ret = pcmcia_loop_config(link, nsp_cs_config_check, cfg_mem);
1722 goto cs_failed;
1723
1732 if (link->conf.Attributes & CONF_ENABLE_IRQ) { 1724 if (link->conf.Attributes & CONF_ENABLE_IRQ) {
1733 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 1725 if (pcmcia_request_irq(link, &link->irq))
1726 goto cs_failed;
1734 } 1727 }
1735 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); 1728
1729 ret = pcmcia_request_configuration(link, &link->conf);
1730 if (ret)
1731 goto cs_failed;
1736 1732
1737 if (free_ports) { 1733 if (free_ports) {
1738 if (link->io.BasePort1) { 1734 if (link->io.BasePort1) {
@@ -1790,20 +1786,20 @@ static int nsp_cs_config(struct pcmcia_device *link)
1790 printk(" & 0x%04x-0x%04x", link->io.BasePort2, 1786 printk(" & 0x%04x-0x%04x", link->io.BasePort2,
1791 link->io.BasePort2+link->io.NumPorts2-1); 1787 link->io.BasePort2+link->io.NumPorts2-1);
1792 if (link->win) 1788 if (link->win)
1793 printk(", mem 0x%06lx-0x%06lx", req.Base, 1789 printk(", mem 0x%06lx-0x%06lx", cfg_mem->req.Base,
1794 req.Base+req.Size-1); 1790 cfg_mem->req.Base+cfg_mem->req.Size-1);
1795 printk("\n"); 1791 printk("\n");
1796 1792
1793 kfree(cfg_mem);
1797 return 0; 1794 return 0;
1798 1795
1799 cs_failed: 1796 cs_failed:
1800 nsp_dbg(NSP_DEBUG_INIT, "config fail"); 1797 nsp_dbg(NSP_DEBUG_INIT, "config fail");
1801 cs_error(link, last_fn, last_ret);
1802 nsp_cs_release(link); 1798 nsp_cs_release(link);
1799 kfree(cfg_mem);
1803 1800
1804 return -ENODEV; 1801 return -ENODEV;
1805} /* nsp_cs_config */ 1802} /* nsp_cs_config */
1806#undef CS_CHECK
1807 1803
1808 1804
1809/*====================================================================== 1805/*======================================================================
diff --git a/drivers/scsi/pcmcia/qlogic_stub.c b/drivers/scsi/pcmcia/qlogic_stub.c
index 67c5a58d17df..20c3e5e6d88a 100644
--- a/drivers/scsi/pcmcia/qlogic_stub.c
+++ b/drivers/scsi/pcmcia/qlogic_stub.c
@@ -195,39 +195,33 @@ static void qlogic_detach(struct pcmcia_device *link)
195#define CS_CHECK(fn, ret) \ 195#define CS_CHECK(fn, ret) \
196do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 196do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
197 197
198static int qlogic_config_check(struct pcmcia_device *p_dev,
199 cistpl_cftable_entry_t *cfg,
200 cistpl_cftable_entry_t *dflt,
201 unsigned int vcc,
202 void *priv_data)
203{
204 p_dev->io.BasePort1 = cfg->io.win[0].base;
205 p_dev->io.NumPorts1 = cfg->io.win[0].len;
206
207 if (p_dev->io.BasePort1 == 0)
208 return -ENODEV;
209
210 return pcmcia_request_io(p_dev, &p_dev->io);
211}
212
198static int qlogic_config(struct pcmcia_device * link) 213static int qlogic_config(struct pcmcia_device * link)
199{ 214{
200 scsi_info_t *info = link->priv; 215 scsi_info_t *info = link->priv;
201 tuple_t tuple; 216 int last_ret, last_fn;
202 cisparse_t parse;
203 int i, last_ret, last_fn;
204 unsigned short tuple_data[32];
205 struct Scsi_Host *host; 217 struct Scsi_Host *host;
206 218
207 DEBUG(0, "qlogic_config(0x%p)\n", link); 219 DEBUG(0, "qlogic_config(0x%p)\n", link);
208 220
209 info->manf_id = link->manf_id; 221 last_ret = pcmcia_loop_config(link, qlogic_config_check, NULL);
210 222 if (last_ret) {
211 tuple.TupleData = (cisdata_t *) tuple_data; 223 cs_error(link, RequestIO, last_ret);
212 tuple.TupleDataMax = 64; 224 goto failed;
213 tuple.TupleOffset = 0;
214
215 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
216 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
217 while (1) {
218 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
219 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
220 goto next_entry;
221 link->conf.ConfigIndex = parse.cftable_entry.index;
222 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
223 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
224 if (link->io.BasePort1 != 0) {
225 i = pcmcia_request_io(link, &link->io);
226 if (i == CS_SUCCESS)
227 break;
228 }
229 next_entry:
230 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
231 } 225 }
232 226
233 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 227 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
@@ -262,6 +256,7 @@ static int qlogic_config(struct pcmcia_device * link)
262cs_failed: 256cs_failed:
263 cs_error(link, last_fn, last_ret); 257 cs_error(link, last_fn, last_ret);
264 pcmcia_disable_device(link); 258 pcmcia_disable_device(link);
259failed:
265 return -ENODEV; 260 return -ENODEV;
266 261
267} /* qlogic_config */ 262} /* qlogic_config */
diff --git a/drivers/scsi/pcmcia/sym53c500_cs.c b/drivers/scsi/pcmcia/sym53c500_cs.c
index 0be232b58ffb..b330c11a1752 100644
--- a/drivers/scsi/pcmcia/sym53c500_cs.c
+++ b/drivers/scsi/pcmcia/sym53c500_cs.c
@@ -700,15 +700,27 @@ static struct scsi_host_template sym53c500_driver_template = {
700#define CS_CHECK(fn, ret) \ 700#define CS_CHECK(fn, ret) \
701do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) 701do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
702 702
703static int SYM53C500_config_check(struct pcmcia_device *p_dev,
704 cistpl_cftable_entry_t *cfg,
705 cistpl_cftable_entry_t *dflt,
706 unsigned int vcc,
707 void *priv_data)
708{
709 p_dev->io.BasePort1 = cfg->io.win[0].base;
710 p_dev->io.NumPorts1 = cfg->io.win[0].len;
711
712 if (p_dev->io.BasePort1 == 0)
713 return -ENODEV;
714
715 return pcmcia_request_io(p_dev, &p_dev->io);
716}
717
703static int 718static int
704SYM53C500_config(struct pcmcia_device *link) 719SYM53C500_config(struct pcmcia_device *link)
705{ 720{
706 struct scsi_info_t *info = link->priv; 721 struct scsi_info_t *info = link->priv;
707 tuple_t tuple; 722 int last_ret, last_fn;
708 cisparse_t parse;
709 int i, last_ret, last_fn;
710 int irq_level, port_base; 723 int irq_level, port_base;
711 unsigned short tuple_data[32];
712 struct Scsi_Host *host; 724 struct Scsi_Host *host;
713 struct scsi_host_template *tpnt = &sym53c500_driver_template; 725 struct scsi_host_template *tpnt = &sym53c500_driver_template;
714 struct sym53c500_data *data; 726 struct sym53c500_data *data;
@@ -717,27 +729,10 @@ SYM53C500_config(struct pcmcia_device *link)
717 729
718 info->manf_id = link->manf_id; 730 info->manf_id = link->manf_id;
719 731
720 tuple.TupleData = (cisdata_t *)tuple_data; 732 last_ret = pcmcia_loop_config(link, SYM53C500_config_check, NULL);
721 tuple.TupleDataMax = 64; 733 if (last_ret) {
722 tuple.TupleOffset = 0; 734 cs_error(link, RequestIO, last_ret);
723 735 goto failed;
724 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
725 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
726 while (1) {
727 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
728 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
729 goto next_entry;
730 link->conf.ConfigIndex = parse.cftable_entry.index;
731 link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
732 link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
733
734 if (link->io.BasePort1 != 0) {
735 i = pcmcia_request_io(link, &link->io);
736 if (i == CS_SUCCESS)
737 break;
738 }
739next_entry:
740 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
741 } 736 }
742 737
743 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq)); 738 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
@@ -831,6 +826,7 @@ err_release:
831 826
832cs_failed: 827cs_failed:
833 cs_error(link, last_fn, last_ret); 828 cs_error(link, last_fn, last_ret);
829failed:
834 SYM53C500_release(link); 830 SYM53C500_release(link);
835 return -ENODEV; 831 return -ENODEV;
836} /* SYM53C500_config */ 832} /* SYM53C500_config */
diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
index ba9b9bbd4e73..93bd59a1ed79 100644
--- a/drivers/scsi/sg.c
+++ b/drivers/scsi/sg.c
@@ -1450,12 +1450,10 @@ sg_add(struct device *cl_dev, struct class_interface *cl_intf)
1450 if (sg_sysfs_valid) { 1450 if (sg_sysfs_valid) {
1451 struct device *sg_class_member; 1451 struct device *sg_class_member;
1452 1452
1453 sg_class_member = device_create_drvdata(sg_sysfs_class, 1453 sg_class_member = device_create(sg_sysfs_class, cl_dev->parent,
1454 cl_dev->parent, 1454 MKDEV(SCSI_GENERIC_MAJOR,
1455 MKDEV(SCSI_GENERIC_MAJOR, 1455 sdp->index),
1456 sdp->index), 1456 sdp, "%s", disk->disk_name);
1457 sdp,
1458 "%s", disk->disk_name);
1459 if (IS_ERR(sg_class_member)) { 1457 if (IS_ERR(sg_class_member)) {
1460 printk(KERN_ERR "sg_add: " 1458 printk(KERN_ERR "sg_add: "
1461 "device_create failed\n"); 1459 "device_create failed\n");
diff --git a/drivers/scsi/st.c b/drivers/scsi/st.c
index c2bb53e3d941..5c28d08f18f4 100644
--- a/drivers/scsi/st.c
+++ b/drivers/scsi/st.c
@@ -4428,13 +4428,10 @@ static int do_create_class_files(struct scsi_tape *STp, int dev_num, int mode)
4428 snprintf(name, 10, "%s%s%s", rew ? "n" : "", 4428 snprintf(name, 10, "%s%s%s", rew ? "n" : "",
4429 STp->disk->disk_name, st_formats[i]); 4429 STp->disk->disk_name, st_formats[i]);
4430 st_class_member = 4430 st_class_member =
4431 device_create_drvdata(st_sysfs_class, 4431 device_create(st_sysfs_class, &STp->device->sdev_gendev,
4432 &STp->device->sdev_gendev, 4432 MKDEV(SCSI_TAPE_MAJOR,
4433 MKDEV(SCSI_TAPE_MAJOR, 4433 TAPE_MINOR(dev_num, mode, rew)),
4434 TAPE_MINOR(dev_num, 4434 &STp->modes[mode], "%s", name);
4435 mode, rew)),
4436 &STp->modes[mode],
4437 "%s", name);
4438 if (IS_ERR(st_class_member)) { 4435 if (IS_ERR(st_class_member)) {
4439 printk(KERN_WARNING "st%d: device_create failed\n", 4436 printk(KERN_WARNING "st%d: device_create failed\n",
4440 dev_num); 4437 dev_num);
diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c
index 9ccc563d8730..1528de23a650 100644
--- a/drivers/serial/8250.c
+++ b/drivers/serial/8250.c
@@ -44,6 +44,10 @@
44 44
45#include "8250.h" 45#include "8250.h"
46 46
47#ifdef CONFIG_SPARC
48#include "suncore.h"
49#endif
50
47/* 51/*
48 * Configuration: 52 * Configuration:
49 * share_irqs - whether we pass IRQF_SHARED to request_irq(). This option 53 * share_irqs - whether we pass IRQF_SHARED to request_irq(). This option
@@ -53,6 +57,13 @@ static unsigned int share_irqs = SERIAL8250_SHARE_IRQS;
53 57
54static unsigned int nr_uarts = CONFIG_SERIAL_8250_RUNTIME_UARTS; 58static unsigned int nr_uarts = CONFIG_SERIAL_8250_RUNTIME_UARTS;
55 59
60static struct uart_driver serial8250_reg;
61
62static int serial_index(struct uart_port *port)
63{
64 return (serial8250_reg.minor - 64) + port->line;
65}
66
56/* 67/*
57 * Debugging. 68 * Debugging.
58 */ 69 */
@@ -536,7 +547,7 @@ static unsigned int serial_icr_read(struct uart_8250_port *up, int offset)
536/* 547/*
537 * FIFO support. 548 * FIFO support.
538 */ 549 */
539static inline void serial8250_clear_fifos(struct uart_8250_port *p) 550static void serial8250_clear_fifos(struct uart_8250_port *p)
540{ 551{
541 if (p->capabilities & UART_CAP_FIFO) { 552 if (p->capabilities & UART_CAP_FIFO) {
542 serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO); 553 serial_outp(p, UART_FCR, UART_FCR_ENABLE_FIFO);
@@ -551,7 +562,7 @@ static inline void serial8250_clear_fifos(struct uart_8250_port *p)
551 * capability" bit enabled. Note that on XR16C850s, we need to 562 * capability" bit enabled. Note that on XR16C850s, we need to
552 * reset LCR to write to IER. 563 * reset LCR to write to IER.
553 */ 564 */
554static inline void serial8250_set_sleep(struct uart_8250_port *p, int sleep) 565static void serial8250_set_sleep(struct uart_8250_port *p, int sleep)
555{ 566{
556 if (p->capabilities & UART_CAP_SLEEP) { 567 if (p->capabilities & UART_CAP_SLEEP) {
557 if (p->capabilities & UART_CAP_EFR) { 568 if (p->capabilities & UART_CAP_EFR) {
@@ -993,7 +1004,7 @@ static void autoconfig(struct uart_8250_port *up, unsigned int probeflags)
993 return; 1004 return;
994 1005
995 DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04x, 0x%p): ", 1006 DEBUG_AUTOCONF("ttyS%d: autoconf (0x%04x, 0x%p): ",
996 up->port.line, up->port.iobase, up->port.membase); 1007 serial_index(&up->port), up->port.iobase, up->port.membase);
997 1008
998 /* 1009 /*
999 * We really do need global IRQs disabled here - we're going to 1010 * We really do need global IRQs disabled here - we're going to
@@ -1128,8 +1139,8 @@ static void autoconfig(struct uart_8250_port *up, unsigned int probeflags)
1128 if (up->capabilities != uart_config[up->port.type].flags) { 1139 if (up->capabilities != uart_config[up->port.type].flags) {
1129 printk(KERN_WARNING 1140 printk(KERN_WARNING
1130 "ttyS%d: detected caps %08x should be %08x\n", 1141 "ttyS%d: detected caps %08x should be %08x\n",
1131 up->port.line, up->capabilities, 1142 serial_index(&up->port), up->capabilities,
1132 uart_config[up->port.type].flags); 1143 uart_config[up->port.type].flags);
1133 } 1144 }
1134 1145
1135 up->port.fifosize = uart_config[up->port.type].fifo_size; 1146 up->port.fifosize = uart_config[up->port.type].fifo_size;
@@ -1424,8 +1435,7 @@ static unsigned int check_modem_status(struct uart_8250_port *up)
1424/* 1435/*
1425 * This handles the interrupt from one port. 1436 * This handles the interrupt from one port.
1426 */ 1437 */
1427static inline void 1438static void serial8250_handle_port(struct uart_8250_port *up)
1428serial8250_handle_port(struct uart_8250_port *up)
1429{ 1439{
1430 unsigned int status; 1440 unsigned int status;
1431 unsigned long flags; 1441 unsigned long flags;
@@ -1719,7 +1729,7 @@ static void serial8250_break_ctl(struct uart_port *port, int break_state)
1719/* 1729/*
1720 * Wait for transmitter & holding register to empty 1730 * Wait for transmitter & holding register to empty
1721 */ 1731 */
1722static inline void wait_for_xmitr(struct uart_8250_port *up, int bits) 1732static void wait_for_xmitr(struct uart_8250_port *up, int bits)
1723{ 1733{
1724 unsigned int status, tmout = 10000; 1734 unsigned int status, tmout = 10000;
1725 1735
@@ -1854,7 +1864,8 @@ static int serial8250_startup(struct uart_port *port)
1854 */ 1864 */
1855 if (!(up->port.flags & UPF_BUGGY_UART) && 1865 if (!(up->port.flags & UPF_BUGGY_UART) &&
1856 (serial_inp(up, UART_LSR) == 0xff)) { 1866 (serial_inp(up, UART_LSR) == 0xff)) {
1857 printk("ttyS%d: LSR safety check engaged!\n", up->port.line); 1867 printk(KERN_INFO "ttyS%d: LSR safety check engaged!\n",
1868 serial_index(&up->port));
1858 return -ENODEV; 1869 return -ENODEV;
1859 } 1870 }
1860 1871
@@ -1909,7 +1920,8 @@ static int serial8250_startup(struct uart_port *port)
1909 */ 1920 */
1910 if (!(iir1 & UART_IIR_NO_INT) && (iir & UART_IIR_NO_INT)) { 1921 if (!(iir1 & UART_IIR_NO_INT) && (iir & UART_IIR_NO_INT)) {
1911 up->bugs |= UART_BUG_THRE; 1922 up->bugs |= UART_BUG_THRE;
1912 pr_debug("ttyS%d - using backup timer\n", port->line); 1923 pr_debug("ttyS%d - using backup timer\n",
1924 serial_index(port));
1913 } 1925 }
1914 } 1926 }
1915 1927
@@ -1969,7 +1981,7 @@ static int serial8250_startup(struct uart_port *port)
1969 if (!(up->bugs & UART_BUG_TXEN)) { 1981 if (!(up->bugs & UART_BUG_TXEN)) {
1970 up->bugs |= UART_BUG_TXEN; 1982 up->bugs |= UART_BUG_TXEN;
1971 pr_debug("ttyS%d - enabling bad tx status workarounds\n", 1983 pr_debug("ttyS%d - enabling bad tx status workarounds\n",
1972 port->line); 1984 serial_index(port));
1973 } 1985 }
1974 } else { 1986 } else {
1975 up->bugs &= ~UART_BUG_TXEN; 1987 up->bugs &= ~UART_BUG_TXEN;
@@ -2211,9 +2223,9 @@ serial8250_set_termios(struct uart_port *port, struct ktermios *termios,
2211 serial_outp(up, UART_EFR, efr); 2223 serial_outp(up, UART_EFR, efr);
2212 } 2224 }
2213 2225
2214#ifdef CONFIG_ARCH_OMAP15XX 2226#ifdef CONFIG_ARCH_OMAP
2215 /* Workaround to enable 115200 baud on OMAP1510 internal ports */ 2227 /* Workaround to enable 115200 baud on OMAP1510 internal ports */
2216 if (cpu_is_omap1510() && is_omap_port((unsigned int)up->port.membase)) { 2228 if (cpu_is_omap1510() && is_omap_port(up)) {
2217 if (baud == 115200) { 2229 if (baud == 115200) {
2218 quot = 1; 2230 quot = 1;
2219 serial_out(up, UART_OMAP_OSC_12M_SEL, 1); 2231 serial_out(up, UART_OMAP_OSC_12M_SEL, 1);
@@ -2266,18 +2278,27 @@ serial8250_pm(struct uart_port *port, unsigned int state,
2266 p->pm(port, state, oldstate); 2278 p->pm(port, state, oldstate);
2267} 2279}
2268 2280
2281static unsigned int serial8250_port_size(struct uart_8250_port *pt)
2282{
2283 if (pt->port.iotype == UPIO_AU)
2284 return 0x100000;
2285#ifdef CONFIG_ARCH_OMAP
2286 if (is_omap_port(pt))
2287 return 0x16 << pt->port.regshift;
2288#endif
2289 return 8 << pt->port.regshift;
2290}
2291
2269/* 2292/*
2270 * Resource handling. 2293 * Resource handling.
2271 */ 2294 */
2272static int serial8250_request_std_resource(struct uart_8250_port *up) 2295static int serial8250_request_std_resource(struct uart_8250_port *up)
2273{ 2296{
2274 unsigned int size = 8 << up->port.regshift; 2297 unsigned int size = serial8250_port_size(up);
2275 int ret = 0; 2298 int ret = 0;
2276 2299
2277 switch (up->port.iotype) { 2300 switch (up->port.iotype) {
2278 case UPIO_AU: 2301 case UPIO_AU:
2279 size = 0x100000;
2280 /* fall thru */
2281 case UPIO_TSI: 2302 case UPIO_TSI:
2282 case UPIO_MEM32: 2303 case UPIO_MEM32:
2283 case UPIO_MEM: 2304 case UPIO_MEM:
@@ -2311,12 +2332,10 @@ static int serial8250_request_std_resource(struct uart_8250_port *up)
2311 2332
2312static void serial8250_release_std_resource(struct uart_8250_port *up) 2333static void serial8250_release_std_resource(struct uart_8250_port *up)
2313{ 2334{
2314 unsigned int size = 8 << up->port.regshift; 2335 unsigned int size = serial8250_port_size(up);
2315 2336
2316 switch (up->port.iotype) { 2337 switch (up->port.iotype) {
2317 case UPIO_AU: 2338 case UPIO_AU:
2318 size = 0x100000;
2319 /* fall thru */
2320 case UPIO_TSI: 2339 case UPIO_TSI:
2321 case UPIO_MEM32: 2340 case UPIO_MEM32:
2322 case UPIO_MEM: 2341 case UPIO_MEM:
@@ -2630,7 +2649,6 @@ static int serial8250_console_early_setup(void)
2630 return serial8250_find_port_for_earlycon(); 2649 return serial8250_find_port_for_earlycon();
2631} 2650}
2632 2651
2633static struct uart_driver serial8250_reg;
2634static struct console serial8250_console = { 2652static struct console serial8250_console = {
2635 .name = "ttyS", 2653 .name = "ttyS",
2636 .write = serial8250_console_write, 2654 .write = serial8250_console_write,
@@ -2677,7 +2695,6 @@ static struct uart_driver serial8250_reg = {
2677 .dev_name = "ttyS", 2695 .dev_name = "ttyS",
2678 .major = TTY_MAJOR, 2696 .major = TTY_MAJOR,
2679 .minor = 64, 2697 .minor = 64,
2680 .nr = UART_NR,
2681 .cons = SERIAL8250_CONSOLE, 2698 .cons = SERIAL8250_CONSOLE,
2682}; 2699};
2683 2700
@@ -2962,7 +2979,12 @@ static int __init serial8250_init(void)
2962 for (i = 0; i < NR_IRQS; i++) 2979 for (i = 0; i < NR_IRQS; i++)
2963 spin_lock_init(&irq_lists[i].lock); 2980 spin_lock_init(&irq_lists[i].lock);
2964 2981
2982#ifdef CONFIG_SPARC
2983 ret = sunserial_register_minors(&serial8250_reg, UART_NR);
2984#else
2985 serial8250_reg.nr = UART_NR;
2965 ret = uart_register_driver(&serial8250_reg); 2986 ret = uart_register_driver(&serial8250_reg);
2987#endif
2966 if (ret) 2988 if (ret)
2967 goto out; 2989 goto out;
2968 2990
@@ -2987,7 +3009,11 @@ static int __init serial8250_init(void)
2987 put_dev: 3009 put_dev:
2988 platform_device_put(serial8250_isa_devs); 3010 platform_device_put(serial8250_isa_devs);
2989 unreg_uart_drv: 3011 unreg_uart_drv:
3012#ifdef CONFIG_SPARC
3013 sunserial_unregister_minors(&serial8250_reg, UART_NR);
3014#else
2990 uart_unregister_driver(&serial8250_reg); 3015 uart_unregister_driver(&serial8250_reg);
3016#endif
2991 out: 3017 out:
2992 return ret; 3018 return ret;
2993} 3019}
@@ -3006,7 +3032,11 @@ static void __exit serial8250_exit(void)
3006 platform_driver_unregister(&serial8250_isa_driver); 3032 platform_driver_unregister(&serial8250_isa_driver);
3007 platform_device_unregister(isa_dev); 3033 platform_device_unregister(isa_dev);
3008 3034
3035#ifdef CONFIG_SPARC
3036 sunserial_unregister_minors(&serial8250_reg, UART_NR);
3037#else
3009 uart_unregister_driver(&serial8250_reg); 3038 uart_unregister_driver(&serial8250_reg);
3039#endif
3010} 3040}
3011 3041
3012module_init(serial8250_init); 3042module_init(serial8250_init);
diff --git a/drivers/serial/8250_pci.c b/drivers/serial/8250_pci.c
index c2f23933155b..c014ffb110e9 100644
--- a/drivers/serial/8250_pci.c
+++ b/drivers/serial/8250_pci.c
@@ -2041,9 +2041,9 @@ static int pciserial_resume_one(struct pci_dev *dev)
2041 * The device may have been disabled. Re-enable it. 2041 * The device may have been disabled. Re-enable it.
2042 */ 2042 */
2043 err = pci_enable_device(dev); 2043 err = pci_enable_device(dev);
2044 /* FIXME: We cannot simply error out here */
2044 if (err) 2045 if (err)
2045 return err; 2046 printk(KERN_ERR "pciserial: Unable to re-enable ports, trying to continue.\n");
2046
2047 pciserial_resume_ports(priv); 2047 pciserial_resume_ports(priv);
2048 } 2048 }
2049 return 0; 2049 return 0;
diff --git a/drivers/serial/Kconfig b/drivers/serial/Kconfig
index 77cb34270fc1..db783b77a881 100644
--- a/drivers/serial/Kconfig
+++ b/drivers/serial/Kconfig
@@ -9,7 +9,6 @@ menu "Serial drivers"
9# The new 8250/16550 serial drivers 9# The new 8250/16550 serial drivers
10config SERIAL_8250 10config SERIAL_8250
11 tristate "8250/16550 and compatible serial support" 11 tristate "8250/16550 and compatible serial support"
12 depends on (BROKEN || !SPARC)
13 select SERIAL_CORE 12 select SERIAL_CORE
14 ---help--- 13 ---help---
15 This selects whether you want to include the driver for the standard 14 This selects whether you want to include the driver for the standard
@@ -994,24 +993,12 @@ config SERIAL_68328_RTS_CTS
994 bool "Support RTS/CTS on 68328 serial port" 993 bool "Support RTS/CTS on 68328 serial port"
995 depends on SERIAL_68328 994 depends on SERIAL_68328
996 995
997config SERIAL_COLDFIRE
998 bool "ColdFire serial support (DEPRECATED)"
999 depends on COLDFIRE
1000 help
1001 This driver supports the built-in serial ports of the Motorola ColdFire
1002 family of CPUs.
1003 This driver is deprecated because it supports only the old interface
1004 for serial drivers and features like magic keys are not working.
1005 Please switch to the new style driver because this driver will be
1006 removed soon.
1007
1008config SERIAL_MCF 996config SERIAL_MCF
1009 bool "Coldfire serial support (new style driver)" 997 bool "Coldfire serial support"
1010 depends on COLDFIRE 998 depends on COLDFIRE
1011 select SERIAL_CORE 999 select SERIAL_CORE
1012 help 1000 help
1013 This new serial driver supports the Freescale Coldfire serial ports 1001 This serial driver supports the Freescale Coldfire serial ports.
1014 using the new serial driver subsystem.
1015 1002
1016config SERIAL_MCF_BAUDRATE 1003config SERIAL_MCF_BAUDRATE
1017 int "Default baudrate for Coldfire serial ports" 1004 int "Default baudrate for Coldfire serial ports"
@@ -1136,42 +1123,6 @@ config SERIAL_CPM_CONSOLE
1136 your boot loader (lilo or loadlin) about how to pass options to the 1123 your boot loader (lilo or loadlin) about how to pass options to the
1137 kernel at boot time.) 1124 kernel at boot time.)
1138 1125
1139config SERIAL_CPM_SCC1
1140 bool "Support for SCC1 serial port"
1141 depends on SERIAL_CPM=y
1142 help
1143 Select this option to use SCC1 as a serial port
1144
1145config SERIAL_CPM_SCC2
1146 bool "Support for SCC2 serial port"
1147 depends on SERIAL_CPM=y
1148 help
1149 Select this option to use SCC2 as a serial port
1150
1151config SERIAL_CPM_SCC3
1152 bool "Support for SCC3 serial port"
1153 depends on SERIAL_CPM=y
1154 help
1155 Select this option to use SCC3 as a serial port
1156
1157config SERIAL_CPM_SCC4
1158 bool "Support for SCC4 serial port"
1159 depends on SERIAL_CPM=y
1160 help
1161 Select this option to use SCC4 as a serial port
1162
1163config SERIAL_CPM_SMC1
1164 bool "Support for SMC1 serial port"
1165 depends on SERIAL_CPM=y
1166 help
1167 Select this option to use SMC1 as a serial port
1168
1169config SERIAL_CPM_SMC2
1170 bool "Support for SMC2 serial port"
1171 depends on SERIAL_CPM=y
1172 help
1173 Select this option to use SMC2 as a serial port
1174
1175config SERIAL_SGI_L1_CONSOLE 1126config SERIAL_SGI_L1_CONSOLE
1176 bool "SGI Altix L1 serial console support" 1127 bool "SGI Altix L1 serial console support"
1177 depends on IA64_GENERIC || IA64_SGI_SN2 1128 depends on IA64_GENERIC || IA64_SGI_SN2
diff --git a/drivers/serial/Makefile b/drivers/serial/Makefile
index 7e7383e890d8..0c17c8ddb19d 100644
--- a/drivers/serial/Makefile
+++ b/drivers/serial/Makefile
@@ -4,6 +4,16 @@
4 4
5obj-$(CONFIG_SERIAL_CORE) += serial_core.o 5obj-$(CONFIG_SERIAL_CORE) += serial_core.o
6obj-$(CONFIG_SERIAL_21285) += 21285.o 6obj-$(CONFIG_SERIAL_21285) += 21285.o
7
8# These Sparc drivers have to appear before others such as 8250
9# which share ttySx minor node space. Otherwise console device
10# names change and other unplesantries.
11obj-$(CONFIG_SERIAL_SUNCORE) += suncore.o
12obj-$(CONFIG_SERIAL_SUNHV) += sunhv.o
13obj-$(CONFIG_SERIAL_SUNZILOG) += sunzilog.o
14obj-$(CONFIG_SERIAL_SUNSU) += sunsu.o
15obj-$(CONFIG_SERIAL_SUNSAB) += sunsab.o
16
7obj-$(CONFIG_SERIAL_8250) += 8250.o 17obj-$(CONFIG_SERIAL_8250) += 8250.o
8obj-$(CONFIG_SERIAL_8250_PNP) += 8250_pnp.o 18obj-$(CONFIG_SERIAL_8250_PNP) += 8250_pnp.o
9obj-$(CONFIG_SERIAL_8250_GSC) += 8250_gsc.o 19obj-$(CONFIG_SERIAL_8250_GSC) += 8250_gsc.o
@@ -31,16 +41,10 @@ obj-$(CONFIG_SERIAL_S3C2400) += s3c2400.o
31obj-$(CONFIG_SERIAL_S3C2410) += s3c2410.o 41obj-$(CONFIG_SERIAL_S3C2410) += s3c2410.o
32obj-$(CONFIG_SERIAL_S3C2412) += s3c2412.o 42obj-$(CONFIG_SERIAL_S3C2412) += s3c2412.o
33obj-$(CONFIG_SERIAL_S3C2440) += s3c2440.o 43obj-$(CONFIG_SERIAL_S3C2440) += s3c2440.o
34obj-$(CONFIG_SERIAL_SUNCORE) += suncore.o
35obj-$(CONFIG_SERIAL_SUNHV) += sunhv.o
36obj-$(CONFIG_SERIAL_SUNZILOG) += sunzilog.o
37obj-$(CONFIG_SERIAL_IP22_ZILOG) += ip22zilog.o 44obj-$(CONFIG_SERIAL_IP22_ZILOG) += ip22zilog.o
38obj-$(CONFIG_SERIAL_SUNSU) += sunsu.o
39obj-$(CONFIG_SERIAL_SUNSAB) += sunsab.o
40obj-$(CONFIG_SERIAL_MUX) += mux.o 45obj-$(CONFIG_SERIAL_MUX) += mux.o
41obj-$(CONFIG_SERIAL_68328) += 68328serial.o 46obj-$(CONFIG_SERIAL_68328) += 68328serial.o
42obj-$(CONFIG_SERIAL_68360) += 68360serial.o 47obj-$(CONFIG_SERIAL_68360) += 68360serial.o
43obj-$(CONFIG_SERIAL_COLDFIRE) += mcfserial.o
44obj-$(CONFIG_SERIAL_MCF) += mcf.o 48obj-$(CONFIG_SERIAL_MCF) += mcf.o
45obj-$(CONFIG_SERIAL_PMACZILOG) += pmac_zilog.o 49obj-$(CONFIG_SERIAL_PMACZILOG) += pmac_zilog.o
46obj-$(CONFIG_SERIAL_LH7A40X) += serial_lh7a40x.o 50obj-$(CONFIG_SERIAL_LH7A40X) += serial_lh7a40x.o
diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c
index 4a0d30bed9f1..569f0e2476c6 100644
--- a/drivers/serial/bfin_5xx.c
+++ b/drivers/serial/bfin_5xx.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * Blackfin On-Chip Serial Driver 2 * Blackfin On-Chip Serial Driver
3 * 3 *
4 * Copyright 2006-2007 Analog Devices Inc. 4 * Copyright 2006-2008 Analog Devices Inc.
5 * 5 *
6 * Enter bugs at http://blackfin.uclinux.org/ 6 * Enter bugs at http://blackfin.uclinux.org/
7 * 7 *
@@ -42,6 +42,9 @@
42#define BFIN_SERIAL_MAJOR 204 42#define BFIN_SERIAL_MAJOR 204
43#define BFIN_SERIAL_MINOR 64 43#define BFIN_SERIAL_MINOR 64
44 44
45static struct bfin_serial_port bfin_serial_ports[BFIN_UART_NR_PORTS];
46static int nr_active_ports = ARRAY_SIZE(bfin_serial_resource);
47
45/* 48/*
46 * Setup for console. Argument comes from the menuconfig 49 * Setup for console. Argument comes from the menuconfig
47 */ 50 */
@@ -126,13 +129,13 @@ static int kgdb_entry_state;
126void kgdb_put_debug_char(int chr) 129void kgdb_put_debug_char(int chr)
127{ 130{
128 struct bfin_serial_port *uart; 131 struct bfin_serial_port *uart;
129 132
130 if (CONFIG_KGDB_UART_PORT < 0 133 if (CONFIG_KGDB_UART_PORT < 0
131 || CONFIG_KGDB_UART_PORT >= BFIN_UART_NR_PORTS) 134 || CONFIG_KGDB_UART_PORT >= BFIN_UART_NR_PORTS)
132 uart = &bfin_serial_ports[0]; 135 uart = &bfin_serial_ports[0];
133 else 136 else
134 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT]; 137 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
135 138
136 while (!(UART_GET_LSR(uart) & THRE)) { 139 while (!(UART_GET_LSR(uart) & THRE)) {
137 SSYNC(); 140 SSYNC();
138 } 141 }
@@ -152,7 +155,7 @@ int kgdb_get_debug_char(void)
152 uart = &bfin_serial_ports[0]; 155 uart = &bfin_serial_ports[0];
153 else 156 else
154 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT]; 157 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
155 158
156 while(!(UART_GET_LSR(uart) & DR)) { 159 while(!(UART_GET_LSR(uart) & DR)) {
157 SSYNC(); 160 SSYNC();
158 } 161 }
@@ -298,7 +301,11 @@ static void bfin_serial_tx_chars(struct bfin_serial_port *uart)
298 bfin_serial_mctrl_check(uart); 301 bfin_serial_mctrl_check(uart);
299 302
300 if (uart_circ_empty(xmit) || uart_tx_stopped(&uart->port)) { 303 if (uart_circ_empty(xmit) || uart_tx_stopped(&uart->port)) {
301 bfin_serial_stop_tx(&uart->port); 304#ifdef CONFIG_BF54x
305 /* Clear TFI bit */
306 UART_PUT_LSR(uart, TFI);
307#endif
308 UART_CLEAR_IER(uart, ETBEI);
302 return; 309 return;
303 } 310 }
304 311
@@ -317,9 +324,6 @@ static void bfin_serial_tx_chars(struct bfin_serial_port *uart)
317 324
318 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS) 325 if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
319 uart_write_wakeup(&uart->port); 326 uart_write_wakeup(&uart->port);
320
321 if (uart_circ_empty(xmit))
322 bfin_serial_stop_tx(&uart->port);
323} 327}
324 328
325static irqreturn_t bfin_serial_rx_int(int irq, void *dev_id) 329static irqreturn_t bfin_serial_rx_int(int irq, void *dev_id)
@@ -645,6 +649,42 @@ static int bfin_serial_startup(struct uart_port *port)
645 free_irq(uart->port.irq, uart); 649 free_irq(uart->port.irq, uart);
646 return -EBUSY; 650 return -EBUSY;
647 } 651 }
652
653# ifdef CONFIG_BF54x
654 {
655 unsigned uart_dma_ch_rx, uart_dma_ch_tx;
656
657 switch (uart->port.irq) {
658 case IRQ_UART3_RX:
659 uart_dma_ch_rx = CH_UART3_RX;
660 uart_dma_ch_tx = CH_UART3_TX;
661 break;
662 case IRQ_UART2_RX:
663 uart_dma_ch_rx = CH_UART2_RX;
664 uart_dma_ch_tx = CH_UART2_TX;
665 break;
666 default:
667 uart_dma_ch_rx = uart_dma_ch_tx = 0;
668 break;
669 };
670
671 if (uart_dma_ch_rx &&
672 request_dma(uart_dma_ch_rx, "BFIN_UART_RX") < 0) {
673 printk(KERN_NOTICE"Fail to attach UART interrupt\n");
674 free_irq(uart->port.irq, uart);
675 free_irq(uart->port.irq + 1, uart);
676 return -EBUSY;
677 }
678 if (uart_dma_ch_tx &&
679 request_dma(uart_dma_ch_tx, "BFIN_UART_TX") < 0) {
680 printk(KERN_NOTICE "Fail to attach UART interrupt\n");
681 free_dma(uart_dma_ch_rx);
682 free_irq(uart->port.irq, uart);
683 free_irq(uart->port.irq + 1, uart);
684 return -EBUSY;
685 }
686 }
687# endif
648#endif 688#endif
649 UART_SET_IER(uart, ERBFI); 689 UART_SET_IER(uart, ERBFI);
650 return 0; 690 return 0;
@@ -662,6 +702,20 @@ static void bfin_serial_shutdown(struct uart_port *port)
662 del_timer(&(uart->rx_dma_timer)); 702 del_timer(&(uart->rx_dma_timer));
663 dma_free_coherent(NULL, PAGE_SIZE, uart->rx_dma_buf.buf, 0); 703 dma_free_coherent(NULL, PAGE_SIZE, uart->rx_dma_buf.buf, 0);
664#else 704#else
705#ifdef CONFIG_BF54x
706 switch (uart->port.irq) {
707 case IRQ_UART3_RX:
708 free_dma(CH_UART3_RX);
709 free_dma(CH_UART3_TX);
710 break;
711 case IRQ_UART2_RX:
712 free_dma(CH_UART2_RX);
713 free_dma(CH_UART2_TX);
714 break;
715 default:
716 break;
717 };
718#endif
665#ifdef CONFIG_KGDB_UART 719#ifdef CONFIG_KGDB_UART
666 if (uart->port.line != CONFIG_KGDB_UART_PORT) 720 if (uart->port.line != CONFIG_KGDB_UART_PORT)
667#endif 721#endif
@@ -757,6 +811,9 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
757 val |= UCEN; 811 val |= UCEN;
758 UART_PUT_GCTL(uart, val); 812 UART_PUT_GCTL(uart, val);
759 813
814 /* Port speed changed, update the per-port timeout. */
815 uart_update_timeout(port, termios->c_cflag, baud);
816
760 spin_unlock_irqrestore(&uart->port.lock, flags); 817 spin_unlock_irqrestore(&uart->port.lock, flags);
761} 818}
762 819
@@ -859,8 +916,9 @@ static void __init bfin_serial_init_ports(void)
859 return; 916 return;
860 first = 0; 917 first = 0;
861 918
862 for (i = 0; i < nr_ports; i++) { 919 for (i = 0; i < nr_active_ports; i++) {
863 bfin_serial_ports[i].port.uartclk = get_sclk(); 920 bfin_serial_ports[i].port.uartclk = get_sclk();
921 bfin_serial_ports[i].port.fifosize = BFIN_UART_TX_FIFO_SIZE;
864 bfin_serial_ports[i].port.ops = &bfin_serial_pops; 922 bfin_serial_ports[i].port.ops = &bfin_serial_pops;
865 bfin_serial_ports[i].port.line = i; 923 bfin_serial_ports[i].port.line = i;
866 bfin_serial_ports[i].port.iotype = UPIO_MEM; 924 bfin_serial_ports[i].port.iotype = UPIO_MEM;
@@ -961,7 +1019,7 @@ bfin_serial_console_setup(struct console *co, char *options)
961 * if so, search for the first available port that does have 1019 * if so, search for the first available port that does have
962 * console support. 1020 * console support.
963 */ 1021 */
964 if (co->index == -1 || co->index >= nr_ports) 1022 if (co->index == -1 || co->index >= nr_active_ports)
965 co->index = 0; 1023 co->index = 0;
966 uart = &bfin_serial_ports[co->index]; 1024 uart = &bfin_serial_ports[co->index];
967 1025
@@ -1056,7 +1114,7 @@ static __init void early_serial_write(struct console *con, const char *s,
1056 } 1114 }
1057} 1115}
1058 1116
1059static struct __init console bfin_early_serial_console = { 1117static struct __initdata console bfin_early_serial_console = {
1060 .name = "early_BFuart", 1118 .name = "early_BFuart",
1061 .write = early_serial_write, 1119 .write = early_serial_write,
1062 .device = uart_console_device, 1120 .device = uart_console_device,
@@ -1072,7 +1130,7 @@ struct console __init *bfin_earlyserial_init(unsigned int port,
1072 struct bfin_serial_port *uart; 1130 struct bfin_serial_port *uart;
1073 struct ktermios t; 1131 struct ktermios t;
1074 1132
1075 if (port == -1 || port >= nr_ports) 1133 if (port == -1 || port >= nr_active_ports)
1076 port = 0; 1134 port = 0;
1077 bfin_serial_init_ports(); 1135 bfin_serial_init_ports();
1078 bfin_early_serial_console.index = port; 1136 bfin_early_serial_console.index = port;
@@ -1100,20 +1158,26 @@ static struct uart_driver bfin_serial_reg = {
1100 1158
1101static int bfin_serial_suspend(struct platform_device *dev, pm_message_t state) 1159static int bfin_serial_suspend(struct platform_device *dev, pm_message_t state)
1102{ 1160{
1103 struct bfin_serial_port *uart = platform_get_drvdata(dev); 1161 int i;
1104 1162
1105 if (uart) 1163 for (i = 0; i < nr_active_ports; i++) {
1106 uart_suspend_port(&bfin_serial_reg, &uart->port); 1164 if (bfin_serial_ports[i].port.dev != &dev->dev)
1165 continue;
1166 uart_suspend_port(&bfin_serial_reg, &bfin_serial_ports[i].port);
1167 }
1107 1168
1108 return 0; 1169 return 0;
1109} 1170}
1110 1171
1111static int bfin_serial_resume(struct platform_device *dev) 1172static int bfin_serial_resume(struct platform_device *dev)
1112{ 1173{
1113 struct bfin_serial_port *uart = platform_get_drvdata(dev); 1174 int i;
1114 1175
1115 if (uart) 1176 for (i = 0; i < nr_active_ports; i++) {
1116 uart_resume_port(&bfin_serial_reg, &uart->port); 1177 if (bfin_serial_ports[i].port.dev != &dev->dev)
1178 continue;
1179 uart_resume_port(&bfin_serial_reg, &bfin_serial_ports[i].port);
1180 }
1117 1181
1118 return 0; 1182 return 0;
1119} 1183}
@@ -1128,32 +1192,31 @@ static int bfin_serial_probe(struct platform_device *dev)
1128 break; 1192 break;
1129 1193
1130 if (i < dev->num_resources) { 1194 if (i < dev->num_resources) {
1131 for (i = 0; i < nr_ports; i++, res++) { 1195 for (i = 0; i < nr_active_ports; i++, res++) {
1132 if (bfin_serial_ports[i].port.mapbase != res->start) 1196 if (bfin_serial_ports[i].port.mapbase != res->start)
1133 continue; 1197 continue;
1134 bfin_serial_ports[i].port.dev = &dev->dev; 1198 bfin_serial_ports[i].port.dev = &dev->dev;
1135 uart_add_one_port(&bfin_serial_reg, &bfin_serial_ports[i].port); 1199 uart_add_one_port(&bfin_serial_reg, &bfin_serial_ports[i].port);
1136 platform_set_drvdata(dev, &bfin_serial_ports[i]);
1137 } 1200 }
1138 } 1201 }
1139 1202
1140 return 0; 1203 return 0;
1141} 1204}
1142 1205
1143static int bfin_serial_remove(struct platform_device *pdev) 1206static int bfin_serial_remove(struct platform_device *dev)
1144{ 1207{
1145 struct bfin_serial_port *uart = platform_get_drvdata(pdev); 1208 int i;
1146
1147 1209
1210 for (i = 0; i < nr_active_ports; i++) {
1211 if (bfin_serial_ports[i].port.dev != &dev->dev)
1212 continue;
1213 uart_remove_one_port(&bfin_serial_reg, &bfin_serial_ports[i].port);
1214 bfin_serial_ports[i].port.dev = NULL;
1148#ifdef CONFIG_SERIAL_BFIN_CTSRTS 1215#ifdef CONFIG_SERIAL_BFIN_CTSRTS
1149 gpio_free(uart->cts_pin); 1216 gpio_free(bfin_serial_ports[i].cts_pin);
1150 gpio_free(uart->rts_pin); 1217 gpio_free(bfin_serial_ports[i].rts_pin);
1151#endif 1218#endif
1152 1219 }
1153 platform_set_drvdata(pdev, NULL);
1154
1155 if (uart)
1156 uart_remove_one_port(&bfin_serial_reg, &uart->port);
1157 1220
1158 return 0; 1221 return 0;
1159} 1222}
diff --git a/drivers/serial/cpm_uart/cpm_uart_core.c b/drivers/serial/cpm_uart/cpm_uart_core.c
index 25efca5a7a1f..a6c4d744495e 100644
--- a/drivers/serial/cpm_uart/cpm_uart_core.c
+++ b/drivers/serial/cpm_uart/cpm_uart_core.c
@@ -1333,6 +1333,9 @@ static int __devinit cpm_uart_probe(struct of_device *ofdev,
1333 if (ret) 1333 if (ret)
1334 return ret; 1334 return ret;
1335 1335
1336 /* initialize the device pointer for the port */
1337 pinfo->port.dev = &ofdev->dev;
1338
1336 return uart_add_one_port(&cpm_reg, &pinfo->port); 1339 return uart_add_one_port(&cpm_reg, &pinfo->port);
1337} 1340}
1338 1341
diff --git a/drivers/serial/cpm_uart/cpm_uart_cpm1.c b/drivers/serial/cpm_uart/cpm_uart_cpm1.c
index 0f0aff06c596..1b94c56ec239 100644
--- a/drivers/serial/cpm_uart/cpm_uart_cpm1.c
+++ b/drivers/serial/cpm_uart/cpm_uart_cpm1.c
@@ -100,7 +100,7 @@ int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
100 mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8)); 100 mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8));
101 dma_addr = (u32)cpm_dpram_phys(mem_addr); 101 dma_addr = (u32)cpm_dpram_phys(mem_addr);
102 } else 102 } else
103 mem_addr = dma_alloc_coherent(NULL, memsz, &dma_addr, 103 mem_addr = dma_alloc_coherent(pinfo->port.dev, memsz, &dma_addr,
104 GFP_KERNEL); 104 GFP_KERNEL);
105 105
106 if (mem_addr == NULL) { 106 if (mem_addr == NULL) {
@@ -127,8 +127,8 @@ int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
127 127
128void cpm_uart_freebuf(struct uart_cpm_port *pinfo) 128void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
129{ 129{
130 dma_free_coherent(NULL, L1_CACHE_ALIGN(pinfo->rx_nrfifos * 130 dma_free_coherent(pinfo->port.dev, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
131 pinfo->rx_fifosize) + 131 pinfo->rx_fifosize) +
132 L1_CACHE_ALIGN(pinfo->tx_nrfifos * 132 L1_CACHE_ALIGN(pinfo->tx_nrfifos *
133 pinfo->tx_fifosize), pinfo->mem_addr, 133 pinfo->tx_fifosize), pinfo->mem_addr,
134 pinfo->dma_addr); 134 pinfo->dma_addr);
diff --git a/drivers/serial/cpm_uart/cpm_uart_cpm2.c b/drivers/serial/cpm_uart/cpm_uart_cpm2.c
index b8db4d3eed36..141c0a3333ad 100644
--- a/drivers/serial/cpm_uart/cpm_uart_cpm2.c
+++ b/drivers/serial/cpm_uart/cpm_uart_cpm2.c
@@ -136,7 +136,7 @@ int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
136 dma_addr = virt_to_bus(mem_addr); 136 dma_addr = virt_to_bus(mem_addr);
137 } 137 }
138 else 138 else
139 mem_addr = dma_alloc_coherent(NULL, memsz, &dma_addr, 139 mem_addr = dma_alloc_coherent(pinfo->port.dev, memsz, &dma_addr,
140 GFP_KERNEL); 140 GFP_KERNEL);
141 141
142 if (mem_addr == NULL) { 142 if (mem_addr == NULL) {
@@ -163,8 +163,8 @@ int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
163 163
164void cpm_uart_freebuf(struct uart_cpm_port *pinfo) 164void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
165{ 165{
166 dma_free_coherent(NULL, L1_CACHE_ALIGN(pinfo->rx_nrfifos * 166 dma_free_coherent(pinfo->port.dev, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
167 pinfo->rx_fifosize) + 167 pinfo->rx_fifosize) +
168 L1_CACHE_ALIGN(pinfo->tx_nrfifos * 168 L1_CACHE_ALIGN(pinfo->tx_nrfifos *
169 pinfo->tx_fifosize), (void __force *)pinfo->mem_addr, 169 pinfo->tx_fifosize), (void __force *)pinfo->mem_addr,
170 pinfo->dma_addr); 170 pinfo->dma_addr);
diff --git a/drivers/serial/crisv10.c b/drivers/serial/crisv10.c
index bf94a770bb44..211c21797ce0 100644
--- a/drivers/serial/crisv10.c
+++ b/drivers/serial/crisv10.c
@@ -457,7 +457,6 @@ static struct e100_serial rs_table[] = {
457#define NR_PORTS (sizeof(rs_table)/sizeof(struct e100_serial)) 457#define NR_PORTS (sizeof(rs_table)/sizeof(struct e100_serial))
458 458
459static struct ktermios *serial_termios[NR_PORTS]; 459static struct ktermios *serial_termios[NR_PORTS];
460static struct ktermios *serial_termios_locked[NR_PORTS];
461#ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER 460#ifdef CONFIG_ETRAX_SERIAL_FAST_TIMER
462static struct fast_timer fast_timers[NR_PORTS]; 461static struct fast_timer fast_timers[NR_PORTS];
463#endif 462#endif
@@ -4419,6 +4418,7 @@ rs_init(void)
4419 rs485_pa_bit)) { 4418 rs485_pa_bit)) {
4420 printk(KERN_CRIT "ETRAX100LX serial: Could not allocate " 4419 printk(KERN_CRIT "ETRAX100LX serial: Could not allocate "
4421 "RS485 pin\n"); 4420 "RS485 pin\n");
4421 put_tty_driver(driver);
4422 return -EBUSY; 4422 return -EBUSY;
4423 } 4423 }
4424#endif 4424#endif
@@ -4427,6 +4427,7 @@ rs_init(void)
4427 rs485_port_g_bit)) { 4427 rs485_port_g_bit)) {
4428 printk(KERN_CRIT "ETRAX100LX serial: Could not allocate " 4428 printk(KERN_CRIT "ETRAX100LX serial: Could not allocate "
4429 "RS485 pin\n"); 4429 "RS485 pin\n");
4430 put_tty_driver(driver);
4430 return -EBUSY; 4431 return -EBUSY;
4431 } 4432 }
4432#endif 4433#endif
@@ -4446,8 +4447,6 @@ rs_init(void)
4446 driver->init_termios.c_ispeed = 115200; 4447 driver->init_termios.c_ispeed = 115200;
4447 driver->init_termios.c_ospeed = 115200; 4448 driver->init_termios.c_ospeed = 115200;
4448 driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; 4449 driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
4449 driver->termios = serial_termios;
4450 driver->termios_locked = serial_termios_locked;
4451 4450
4452 tty_set_operations(driver, &rs_ops); 4451 tty_set_operations(driver, &rs_ops);
4453 serial_driver = driver; 4452 serial_driver = driver;
diff --git a/drivers/serial/mcfserial.c b/drivers/serial/mcfserial.c
deleted file mode 100644
index fbe3835f6b77..000000000000
--- a/drivers/serial/mcfserial.c
+++ /dev/null
@@ -1,1965 +0,0 @@
1#warning This driver is deprecated. Check Kconfig for details.
2/*
3 * mcfserial.c -- serial driver for ColdFire internal UARTS.
4 *
5 * Copyright (C) 1999-2003 Greg Ungerer <gerg@snapgear.com>
6 * Copyright (c) 2000-2001 Lineo, Inc. <www.lineo.com>
7 * Copyright (C) 2001-2002 SnapGear Inc. <www.snapgear.com>
8 *
9 * Based on code from 68332serial.c which was:
10 *
11 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
12 * Copyright (C) 1998 TSHG
13 * Copyright (c) 1999 Rt-Control Inc. <jeff@uclinux.org>
14 *
15 * Changes:
16 * 08/07/2003 Daniele Bellucci <bellucda@tiscali.it>
17 * some cleanups in mcfrs_write.
18 *
19 */
20
21#include <linux/module.h>
22#include <linux/errno.h>
23#include <linux/signal.h>
24#include <linux/sched.h>
25#include <linux/timer.h>
26#include <linux/wait.h>
27#include <linux/interrupt.h>
28#include <linux/tty.h>
29#include <linux/tty_flip.h>
30#include <linux/string.h>
31#include <linux/fcntl.h>
32#include <linux/mm.h>
33#include <linux/kernel.h>
34#include <linux/serial.h>
35#include <linux/serialP.h>
36#include <linux/console.h>
37#include <linux/init.h>
38#include <linux/bitops.h>
39#include <linux/delay.h>
40
41#include <asm/io.h>
42#include <asm/irq.h>
43#include <asm/system.h>
44#include <asm/delay.h>
45#include <asm/coldfire.h>
46#include <asm/mcfsim.h>
47#include <asm/mcfuart.h>
48#include <asm/nettel.h>
49#include <asm/uaccess.h>
50#include "mcfserial.h"
51
52struct timer_list mcfrs_timer_struct;
53
54/*
55 * Default console baud rate, we use this as the default
56 * for all ports so init can just open /dev/console and
57 * keep going. Perhaps one day the cflag settings for the
58 * console can be used instead.
59 */
60#if defined(CONFIG_HW_FEITH)
61#define CONSOLE_BAUD_RATE 38400
62#define DEFAULT_CBAUD B38400
63#elif defined(CONFIG_MOD5272) || defined(CONFIG_M5208EVB) || \
64 defined(CONFIG_M5329EVB) || defined(CONFIG_GILBARCO)
65#define CONSOLE_BAUD_RATE 115200
66#define DEFAULT_CBAUD B115200
67#elif defined(CONFIG_ARNEWSH) || defined(CONFIG_FREESCALE) || \
68 defined(CONFIG_senTec) || defined(CONFIG_SNEHA) || defined(CONFIG_AVNET)
69#define CONSOLE_BAUD_RATE 19200
70#define DEFAULT_CBAUD B19200
71#endif
72
73#ifndef CONSOLE_BAUD_RATE
74#define CONSOLE_BAUD_RATE 9600
75#define DEFAULT_CBAUD B9600
76#endif
77
78int mcfrs_console_inited = 0;
79int mcfrs_console_port = -1;
80int mcfrs_console_baud = CONSOLE_BAUD_RATE;
81int mcfrs_console_cbaud = DEFAULT_CBAUD;
82
83/*
84 * Driver data structures.
85 */
86static struct tty_driver *mcfrs_serial_driver;
87
88/* number of characters left in xmit buffer before we ask for more */
89#define WAKEUP_CHARS 256
90
91/* Debugging...
92 */
93#undef SERIAL_DEBUG_OPEN
94#undef SERIAL_DEBUG_FLOW
95
96#if defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x) || \
97 defined(CONFIG_M520x) || defined(CONFIG_M532x)
98#define IRQBASE (MCFINT_VECBASE+MCFINT_UART0)
99#else
100#define IRQBASE 73
101#endif
102
103/*
104 * Configuration table, UARTs to look for at startup.
105 */
106static struct mcf_serial mcfrs_table[] = {
107 { /* ttyS0 */
108 .magic = 0,
109 .addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE1),
110 .irq = IRQBASE,
111 .flags = ASYNC_BOOT_AUTOCONF,
112 },
113#ifdef MCFUART_BASE2
114 { /* ttyS1 */
115 .magic = 0,
116 .addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE2),
117 .irq = IRQBASE+1,
118 .flags = ASYNC_BOOT_AUTOCONF,
119 },
120#endif
121#ifdef MCFUART_BASE3
122 { /* ttyS2 */
123 .magic = 0,
124 .addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE3),
125 .irq = IRQBASE+2,
126 .flags = ASYNC_BOOT_AUTOCONF,
127 },
128#endif
129#ifdef MCFUART_BASE4
130 { /* ttyS3 */
131 .magic = 0,
132 .addr = (volatile unsigned char *) (MCF_MBAR+MCFUART_BASE4),
133 .irq = IRQBASE+3,
134 .flags = ASYNC_BOOT_AUTOCONF,
135 },
136#endif
137};
138
139
140#define NR_PORTS (sizeof(mcfrs_table) / sizeof(struct mcf_serial))
141
142/*
143 * This is used to figure out the divisor speeds and the timeouts.
144 */
145static int mcfrs_baud_table[] = {
146 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
147 9600, 19200, 38400, 57600, 115200, 230400, 460800, 0
148};
149#define MCFRS_BAUD_TABLE_SIZE \
150 (sizeof(mcfrs_baud_table)/sizeof(mcfrs_baud_table[0]))
151
152
153#ifdef CONFIG_MAGIC_SYSRQ
154/*
155 * Magic system request keys. Used for debugging...
156 */
157extern int magic_sysrq_key(int ch);
158#endif
159
160
161/*
162 * Forware declarations...
163 */
164static void mcfrs_change_speed(struct mcf_serial *info);
165static void mcfrs_wait_until_sent(struct tty_struct *tty, int timeout);
166
167
168static inline int serial_paranoia_check(struct mcf_serial *info,
169 char *name, const char *routine)
170{
171#ifdef SERIAL_PARANOIA_CHECK
172 static const char badmagic[] =
173 "MCFRS(warning): bad magic number for serial struct %s in %s\n";
174 static const char badinfo[] =
175 "MCFRS(warning): null mcf_serial for %s in %s\n";
176
177 if (!info) {
178 printk(badinfo, name, routine);
179 return 1;
180 }
181 if (info->magic != SERIAL_MAGIC) {
182 printk(badmagic, name, routine);
183 return 1;
184 }
185#endif
186 return 0;
187}
188
189/*
190 * Sets or clears DTR and RTS on the requested line.
191 */
192static void mcfrs_setsignals(struct mcf_serial *info, int dtr, int rts)
193{
194 volatile unsigned char *uartp;
195 unsigned long flags;
196
197#if 0
198 printk("%s(%d): mcfrs_setsignals(info=%x,dtr=%d,rts=%d)\n",
199 __FILE__, __LINE__, info, dtr, rts);
200#endif
201
202 local_irq_save(flags);
203 if (dtr >= 0) {
204#ifdef MCFPP_DTR0
205 if (info->line)
206 mcf_setppdata(MCFPP_DTR1, (dtr ? 0 : MCFPP_DTR1));
207 else
208 mcf_setppdata(MCFPP_DTR0, (dtr ? 0 : MCFPP_DTR0));
209#endif
210 }
211 if (rts >= 0) {
212 uartp = info->addr;
213 if (rts) {
214 info->sigs |= TIOCM_RTS;
215 uartp[MCFUART_UOP1] = MCFUART_UOP_RTS;
216 } else {
217 info->sigs &= ~TIOCM_RTS;
218 uartp[MCFUART_UOP0] = MCFUART_UOP_RTS;
219 }
220 }
221 local_irq_restore(flags);
222 return;
223}
224
225/*
226 * Gets values of serial signals.
227 */
228static int mcfrs_getsignals(struct mcf_serial *info)
229{
230 volatile unsigned char *uartp;
231 unsigned long flags;
232 int sigs;
233#if defined(CONFIG_NETtel) && defined(CONFIG_M5307)
234 unsigned short ppdata;
235#endif
236
237#if 0
238 printk("%s(%d): mcfrs_getsignals(info=%x)\n", __FILE__, __LINE__);
239#endif
240
241 local_irq_save(flags);
242 uartp = info->addr;
243 sigs = (uartp[MCFUART_UIPR] & MCFUART_UIPR_CTS) ? 0 : TIOCM_CTS;
244 sigs |= (info->sigs & TIOCM_RTS);
245
246#ifdef MCFPP_DCD0
247{
248 unsigned int ppdata;
249 ppdata = mcf_getppdata();
250 if (info->line == 0) {
251 sigs |= (ppdata & MCFPP_DCD0) ? 0 : TIOCM_CD;
252 sigs |= (ppdata & MCFPP_DTR0) ? 0 : TIOCM_DTR;
253 } else if (info->line == 1) {
254 sigs |= (ppdata & MCFPP_DCD1) ? 0 : TIOCM_CD;
255 sigs |= (ppdata & MCFPP_DTR1) ? 0 : TIOCM_DTR;
256 }
257}
258#endif
259
260 local_irq_restore(flags);
261 return(sigs);
262}
263
264/*
265 * ------------------------------------------------------------
266 * mcfrs_stop() and mcfrs_start()
267 *
268 * This routines are called before setting or resetting tty->stopped.
269 * They enable or disable transmitter interrupts, as necessary.
270 * ------------------------------------------------------------
271 */
272static void mcfrs_stop(struct tty_struct *tty)
273{
274 volatile unsigned char *uartp;
275 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
276 unsigned long flags;
277
278 if (serial_paranoia_check(info, tty->name, "mcfrs_stop"))
279 return;
280
281 local_irq_save(flags);
282 uartp = info->addr;
283 info->imr &= ~MCFUART_UIR_TXREADY;
284 uartp[MCFUART_UIMR] = info->imr;
285 local_irq_restore(flags);
286}
287
288static void mcfrs_start(struct tty_struct *tty)
289{
290 volatile unsigned char *uartp;
291 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
292 unsigned long flags;
293
294 if (serial_paranoia_check(info, tty->name, "mcfrs_start"))
295 return;
296
297 local_irq_save(flags);
298 if (info->xmit_cnt && info->xmit_buf) {
299 uartp = info->addr;
300 info->imr |= MCFUART_UIR_TXREADY;
301 uartp[MCFUART_UIMR] = info->imr;
302 }
303 local_irq_restore(flags);
304}
305
306/*
307 * ----------------------------------------------------------------------
308 *
309 * Here starts the interrupt handling routines. All of the following
310 * subroutines are declared as inline and are folded into
311 * mcfrs_interrupt(). They were separated out for readability's sake.
312 *
313 * Note: mcfrs_interrupt() is a "fast" interrupt, which means that it
314 * runs with interrupts turned off. People who may want to modify
315 * mcfrs_interrupt() should try to keep the interrupt handler as fast as
316 * possible. After you are done making modifications, it is not a bad
317 * idea to do:
318 *
319 * gcc -S -DKERNEL -Wall -Wstrict-prototypes -O6 -fomit-frame-pointer serial.c
320 *
321 * and look at the resulting assemble code in serial.s.
322 *
323 * - Ted Ts'o (tytso@mit.edu), 7-Mar-93
324 * -----------------------------------------------------------------------
325 */
326
327static inline void receive_chars(struct mcf_serial *info)
328{
329 volatile unsigned char *uartp;
330 struct tty_struct *tty = info->port.tty;
331 unsigned char status, ch, flag;
332
333 if (!tty)
334 return;
335
336 uartp = info->addr;
337
338 while ((status = uartp[MCFUART_USR]) & MCFUART_USR_RXREADY) {
339 ch = uartp[MCFUART_URB];
340 info->stats.rx++;
341
342#ifdef CONFIG_MAGIC_SYSRQ
343 if (mcfrs_console_inited && (info->line == mcfrs_console_port)) {
344 if (magic_sysrq_key(ch))
345 continue;
346 }
347#endif
348
349 flag = TTY_NORMAL;
350 if (status & MCFUART_USR_RXERR) {
351 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETERR;
352 if (status & MCFUART_USR_RXBREAK) {
353 info->stats.rxbreak++;
354 flag = TTY_BREAK;
355 } else if (status & MCFUART_USR_RXPARITY) {
356 info->stats.rxparity++;
357 flag = TTY_PARITY;
358 } else if (status & MCFUART_USR_RXOVERRUN) {
359 info->stats.rxoverrun++;
360 flag = TTY_OVERRUN;
361 } else if (status & MCFUART_USR_RXFRAMING) {
362 info->stats.rxframing++;
363 flag = TTY_FRAME;
364 }
365 }
366 tty_insert_flip_char(tty, ch, flag);
367 }
368 tty_schedule_flip(tty);
369 return;
370}
371
372static inline void transmit_chars(struct mcf_serial *info)
373{
374 volatile unsigned char *uartp;
375
376 uartp = info->addr;
377
378 if (info->x_char) {
379 /* Send special char - probably flow control */
380 uartp[MCFUART_UTB] = info->x_char;
381 info->x_char = 0;
382 info->stats.tx++;
383 }
384
385 if ((info->xmit_cnt <= 0) || info->port.tty->stopped) {
386 info->imr &= ~MCFUART_UIR_TXREADY;
387 uartp[MCFUART_UIMR] = info->imr;
388 return;
389 }
390
391 while (uartp[MCFUART_USR] & MCFUART_USR_TXREADY) {
392 uartp[MCFUART_UTB] = info->xmit_buf[info->xmit_tail++];
393 info->xmit_tail = info->xmit_tail & (SERIAL_XMIT_SIZE-1);
394 info->stats.tx++;
395 if (--info->xmit_cnt <= 0)
396 break;
397 }
398
399 if (info->xmit_cnt < WAKEUP_CHARS)
400 schedule_work(&info->tqueue);
401 return;
402}
403
404/*
405 * This is the serial driver's generic interrupt routine
406 */
407irqreturn_t mcfrs_interrupt(int irq, void *dev_id)
408{
409 struct mcf_serial *info;
410 unsigned char isr;
411
412 info = &mcfrs_table[(irq - IRQBASE)];
413 isr = info->addr[MCFUART_UISR] & info->imr;
414
415 if (isr & MCFUART_UIR_RXREADY)
416 receive_chars(info);
417 if (isr & MCFUART_UIR_TXREADY)
418 transmit_chars(info);
419 return IRQ_HANDLED;
420}
421
422/*
423 * -------------------------------------------------------------------
424 * Here ends the serial interrupt routines.
425 * -------------------------------------------------------------------
426 */
427
428static void mcfrs_offintr(struct work_struct *work)
429{
430 struct mcf_serial *info = container_of(work, struct mcf_serial, tqueue);
431 struct tty_struct *tty = info->port.tty;
432
433 if (tty)
434 tty_wakeup(tty);
435}
436
437
438/*
439 * Change of state on a DCD line.
440 */
441void mcfrs_modem_change(struct mcf_serial *info, int dcd)
442{
443 if (info->count == 0)
444 return;
445
446 if (info->flags & ASYNC_CHECK_CD) {
447 if (dcd)
448 wake_up_interruptible(&info->open_wait);
449 else
450 schedule_work(&info->tqueue_hangup);
451 }
452}
453
454
455#ifdef MCFPP_DCD0
456
457unsigned short mcfrs_ppstatus;
458
459/*
460 * This subroutine is called when the RS_TIMER goes off. It is used
461 * to monitor the state of the DCD lines - since they have no edge
462 * sensors and interrupt generators.
463 */
464static void mcfrs_timer(void)
465{
466 unsigned int ppstatus, dcdval, i;
467
468 ppstatus = mcf_getppdata() & (MCFPP_DCD0 | MCFPP_DCD1);
469
470 if (ppstatus != mcfrs_ppstatus) {
471 for (i = 0; (i < 2); i++) {
472 dcdval = (i ? MCFPP_DCD1 : MCFPP_DCD0);
473 if ((ppstatus & dcdval) != (mcfrs_ppstatus & dcdval)) {
474 mcfrs_modem_change(&mcfrs_table[i],
475 ((ppstatus & dcdval) ? 0 : 1));
476 }
477 }
478 }
479 mcfrs_ppstatus = ppstatus;
480
481 /* Re-arm timer */
482 mcfrs_timer_struct.expires = jiffies + HZ/25;
483 add_timer(&mcfrs_timer_struct);
484}
485
486#endif /* MCFPP_DCD0 */
487
488
489/*
490 * This routine is called from the scheduler tqueue when the interrupt
491 * routine has signalled that a hangup has occurred. The path of
492 * hangup processing is:
493 *
494 * serial interrupt routine -> (scheduler tqueue) ->
495 * do_serial_hangup() -> tty->hangup() -> mcfrs_hangup()
496 *
497 */
498static void do_serial_hangup(struct work_struct *work)
499{
500 struct mcf_serial *info = container_of(work, struct mcf_serial, tqueue_hangup);
501 struct tty_struct *tty = info->port.tty;
502
503 if (tty)
504 tty_hangup(tty);
505}
506
507static int startup(struct mcf_serial * info)
508{
509 volatile unsigned char *uartp;
510 unsigned long flags;
511
512 if (info->flags & ASYNC_INITIALIZED)
513 return 0;
514
515 if (!info->xmit_buf) {
516 info->xmit_buf = (unsigned char *) __get_free_page(GFP_KERNEL);
517 if (!info->xmit_buf)
518 return -ENOMEM;
519 }
520
521 local_irq_save(flags);
522
523#ifdef SERIAL_DEBUG_OPEN
524 printk("starting up ttyS%d (irq %d)...\n", info->line, info->irq);
525#endif
526
527 /*
528 * Reset UART, get it into known state...
529 */
530 uartp = info->addr;
531 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
532 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
533 mcfrs_setsignals(info, 1, 1);
534
535 if (info->port.tty)
536 clear_bit(TTY_IO_ERROR, &info->port.tty->flags);
537 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
538
539 /*
540 * and set the speed of the serial port
541 */
542 mcfrs_change_speed(info);
543
544 /*
545 * Lastly enable the UART transmitter and receiver, and
546 * interrupt enables.
547 */
548 info->imr = MCFUART_UIR_RXREADY;
549 uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
550 uartp[MCFUART_UIMR] = info->imr;
551
552 info->flags |= ASYNC_INITIALIZED;
553 local_irq_restore(flags);
554 return 0;
555}
556
557/*
558 * This routine will shutdown a serial port; interrupts are disabled, and
559 * DTR is dropped if the hangup on close termio flag is on.
560 */
561static void shutdown(struct mcf_serial * info)
562{
563 volatile unsigned char *uartp;
564 unsigned long flags;
565
566 if (!(info->flags & ASYNC_INITIALIZED))
567 return;
568
569#ifdef SERIAL_DEBUG_OPEN
570 printk("Shutting down serial port %d (irq %d)....\n", info->line,
571 info->irq);
572#endif
573
574 local_irq_save(flags);
575
576 uartp = info->addr;
577 uartp[MCFUART_UIMR] = 0; /* mask all interrupts */
578 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
579 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
580
581 if (!info->port.tty || (info->port.tty->termios->c_cflag & HUPCL))
582 mcfrs_setsignals(info, 0, 0);
583
584 if (info->xmit_buf) {
585 free_page((unsigned long) info->xmit_buf);
586 info->xmit_buf = 0;
587 }
588
589 if (info->port.tty)
590 set_bit(TTY_IO_ERROR, &info->port.tty->flags);
591
592 info->flags &= ~ASYNC_INITIALIZED;
593 local_irq_restore(flags);
594}
595
596
597/*
598 * This routine is called to set the UART divisor registers to match
599 * the specified baud rate for a serial port.
600 */
601static void mcfrs_change_speed(struct mcf_serial *info)
602{
603 volatile unsigned char *uartp;
604 unsigned int baudclk, cflag;
605 unsigned long flags;
606 unsigned char mr1, mr2;
607 int i;
608#ifdef CONFIG_M5272
609 unsigned int fraction;
610#endif
611
612 if (!info->port.tty || !info->port.tty->termios)
613 return;
614 cflag = info->port.tty->termios->c_cflag;
615 if (info->addr == 0)
616 return;
617
618#if 0
619 printk("%s(%d): mcfrs_change_speed()\n", __FILE__, __LINE__);
620#endif
621
622 i = cflag & CBAUD;
623 if (i & CBAUDEX) {
624 i &= ~CBAUDEX;
625 if (i < 1 || i > 4)
626 info->port.tty->termios->c_cflag &= ~CBAUDEX;
627 else
628 i += 15;
629 }
630 if (i == 0) {
631 mcfrs_setsignals(info, 0, -1);
632 return;
633 }
634
635 /* compute the baudrate clock */
636#ifdef CONFIG_M5272
637 /*
638 * For the MCF5272, also compute the baudrate fraction.
639 */
640 baudclk = (MCF_BUSCLK / mcfrs_baud_table[i]) / 32;
641 fraction = MCF_BUSCLK - (baudclk * 32 * mcfrs_baud_table[i]);
642 fraction *= 16;
643 fraction /= (32 * mcfrs_baud_table[i]);
644#else
645 baudclk = ((MCF_BUSCLK / mcfrs_baud_table[i]) + 16) / 32;
646#endif
647
648 info->baud = mcfrs_baud_table[i];
649
650 mr1 = MCFUART_MR1_RXIRQRDY | MCFUART_MR1_RXERRCHAR;
651 mr2 = 0;
652
653 switch (cflag & CSIZE) {
654 case CS5: mr1 |= MCFUART_MR1_CS5; break;
655 case CS6: mr1 |= MCFUART_MR1_CS6; break;
656 case CS7: mr1 |= MCFUART_MR1_CS7; break;
657 case CS8:
658 default: mr1 |= MCFUART_MR1_CS8; break;
659 }
660
661 if (cflag & PARENB) {
662 if (cflag & CMSPAR) {
663 if (cflag & PARODD)
664 mr1 |= MCFUART_MR1_PARITYMARK;
665 else
666 mr1 |= MCFUART_MR1_PARITYSPACE;
667 } else {
668 if (cflag & PARODD)
669 mr1 |= MCFUART_MR1_PARITYODD;
670 else
671 mr1 |= MCFUART_MR1_PARITYEVEN;
672 }
673 } else {
674 mr1 |= MCFUART_MR1_PARITYNONE;
675 }
676
677 if (cflag & CSTOPB)
678 mr2 |= MCFUART_MR2_STOP2;
679 else
680 mr2 |= MCFUART_MR2_STOP1;
681
682 if (cflag & CRTSCTS) {
683 mr1 |= MCFUART_MR1_RXRTS;
684 mr2 |= MCFUART_MR2_TXCTS;
685 }
686
687 if (cflag & CLOCAL)
688 info->flags &= ~ASYNC_CHECK_CD;
689 else
690 info->flags |= ASYNC_CHECK_CD;
691
692 uartp = info->addr;
693
694 local_irq_save(flags);
695#if 0
696 printk("%s(%d): mr1=%x mr2=%x baudclk=%x\n", __FILE__, __LINE__,
697 mr1, mr2, baudclk);
698#endif
699 /*
700 Note: pg 12-16 of MCF5206e User's Manual states that a
701 software reset should be performed prior to changing
702 UMR1,2, UCSR, UACR, bit 7
703 */
704 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
705 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
706 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
707 uartp[MCFUART_UMR] = mr1;
708 uartp[MCFUART_UMR] = mr2;
709 uartp[MCFUART_UBG1] = (baudclk & 0xff00) >> 8; /* set msb byte */
710 uartp[MCFUART_UBG2] = (baudclk & 0xff); /* set lsb byte */
711#ifdef CONFIG_M5272
712 uartp[MCFUART_UFPD] = (fraction & 0xf); /* set fraction */
713#endif
714 uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER;
715 uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
716 mcfrs_setsignals(info, 1, -1);
717 local_irq_restore(flags);
718 return;
719}
720
721static void mcfrs_flush_chars(struct tty_struct *tty)
722{
723 volatile unsigned char *uartp;
724 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
725 unsigned long flags;
726
727 if (serial_paranoia_check(info, tty->name, "mcfrs_flush_chars"))
728 return;
729
730 uartp = (volatile unsigned char *) info->addr;
731
732 /*
733 * re-enable receiver interrupt
734 */
735 local_irq_save(flags);
736 if ((!(info->imr & MCFUART_UIR_RXREADY)) &&
737 (info->flags & ASYNC_INITIALIZED) ) {
738 info->imr |= MCFUART_UIR_RXREADY;
739 uartp[MCFUART_UIMR] = info->imr;
740 }
741 local_irq_restore(flags);
742
743 if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
744 !info->xmit_buf)
745 return;
746
747 /* Enable transmitter */
748 local_irq_save(flags);
749 info->imr |= MCFUART_UIR_TXREADY;
750 uartp[MCFUART_UIMR] = info->imr;
751 local_irq_restore(flags);
752}
753
754static int mcfrs_write(struct tty_struct * tty,
755 const unsigned char *buf, int count)
756{
757 volatile unsigned char *uartp;
758 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
759 unsigned long flags;
760 int c, total = 0;
761
762#if 0
763 printk("%s(%d): mcfrs_write(tty=%x,buf=%x,count=%d)\n",
764 __FILE__, __LINE__, (int)tty, (int)buf, count);
765#endif
766
767 if (serial_paranoia_check(info, tty->name, "mcfrs_write"))
768 return 0;
769
770 if (!tty || !info->xmit_buf)
771 return 0;
772
773 local_save_flags(flags);
774 while (1) {
775 local_irq_disable();
776 c = min(count, (int) min(((int)SERIAL_XMIT_SIZE) - info->xmit_cnt - 1,
777 ((int)SERIAL_XMIT_SIZE) - info->xmit_head));
778 local_irq_restore(flags);
779
780 if (c <= 0)
781 break;
782
783 memcpy(info->xmit_buf + info->xmit_head, buf, c);
784
785 local_irq_disable();
786 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
787 info->xmit_cnt += c;
788 local_irq_restore(flags);
789
790 buf += c;
791 count -= c;
792 total += c;
793 }
794
795 local_irq_disable();
796 uartp = info->addr;
797 info->imr |= MCFUART_UIR_TXREADY;
798 uartp[MCFUART_UIMR] = info->imr;
799 local_irq_restore(flags);
800
801 return total;
802}
803
804static int mcfrs_write_room(struct tty_struct *tty)
805{
806 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
807 int ret;
808
809 if (serial_paranoia_check(info, tty->name, "mcfrs_write_room"))
810 return 0;
811 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
812 if (ret < 0)
813 ret = 0;
814 return ret;
815}
816
817static int mcfrs_chars_in_buffer(struct tty_struct *tty)
818{
819 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
820
821 if (serial_paranoia_check(info, tty->name, "mcfrs_chars_in_buffer"))
822 return 0;
823 return info->xmit_cnt;
824}
825
826static void mcfrs_flush_buffer(struct tty_struct *tty)
827{
828 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
829 unsigned long flags;
830
831 if (serial_paranoia_check(info, tty->name, "mcfrs_flush_buffer"))
832 return;
833
834 local_irq_save(flags);
835 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
836 local_irq_restore(flags);
837
838 tty_wakeup(tty);
839}
840
841/*
842 * ------------------------------------------------------------
843 * mcfrs_throttle()
844 *
845 * This routine is called by the upper-layer tty layer to signal that
846 * incoming characters should be throttled.
847 * ------------------------------------------------------------
848 */
849static void mcfrs_throttle(struct tty_struct * tty)
850{
851 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
852#ifdef SERIAL_DEBUG_THROTTLE
853 char buf[64];
854
855 printk("throttle %s: %d....\n", tty_name(tty, buf),
856 tty->ldisc.chars_in_buffer(tty));
857#endif
858
859 if (serial_paranoia_check(info, tty->name, "mcfrs_throttle"))
860 return;
861
862 if (I_IXOFF(tty))
863 info->x_char = STOP_CHAR(tty);
864
865 /* Turn off RTS line (do this atomic) */
866}
867
868static void mcfrs_unthrottle(struct tty_struct * tty)
869{
870 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
871#ifdef SERIAL_DEBUG_THROTTLE
872 char buf[64];
873
874 printk("unthrottle %s: %d....\n", tty_name(tty, buf),
875 tty->ldisc.chars_in_buffer(tty));
876#endif
877
878 if (serial_paranoia_check(info, tty->name, "mcfrs_unthrottle"))
879 return;
880
881 if (I_IXOFF(tty)) {
882 if (info->x_char)
883 info->x_char = 0;
884 else
885 info->x_char = START_CHAR(tty);
886 }
887
888 /* Assert RTS line (do this atomic) */
889}
890
891/*
892 * ------------------------------------------------------------
893 * mcfrs_ioctl() and friends
894 * ------------------------------------------------------------
895 */
896
897static int get_serial_info(struct mcf_serial * info,
898 struct serial_struct * retinfo)
899{
900 struct serial_struct tmp;
901
902 if (!retinfo)
903 return -EFAULT;
904 memset(&tmp, 0, sizeof(tmp));
905 tmp.type = info->type;
906 tmp.line = info->line;
907 tmp.port = (unsigned int) info->addr;
908 tmp.irq = info->irq;
909 tmp.flags = info->flags;
910 tmp.baud_base = info->baud_base;
911 tmp.close_delay = info->close_delay;
912 tmp.closing_wait = info->closing_wait;
913 tmp.custom_divisor = info->custom_divisor;
914 return copy_to_user(retinfo,&tmp,sizeof(*retinfo)) ? -EFAULT : 0;
915}
916
917static int set_serial_info(struct mcf_serial * info,
918 struct serial_struct * new_info)
919{
920 struct serial_struct new_serial;
921 struct mcf_serial old_info;
922 int retval = 0;
923
924 if (!new_info)
925 return -EFAULT;
926 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
927 return -EFAULT;
928 old_info = *info;
929
930 if (!capable(CAP_SYS_ADMIN)) {
931 if ((new_serial.baud_base != info->baud_base) ||
932 (new_serial.type != info->type) ||
933 (new_serial.close_delay != info->close_delay) ||
934 ((new_serial.flags & ~ASYNC_USR_MASK) !=
935 (info->flags & ~ASYNC_USR_MASK)))
936 return -EPERM;
937 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
938 (new_serial.flags & ASYNC_USR_MASK));
939 info->custom_divisor = new_serial.custom_divisor;
940 goto check_and_exit;
941 }
942
943 if (info->count > 1)
944 return -EBUSY;
945
946 /*
947 * OK, past this point, all the error checking has been done.
948 * At this point, we start making changes.....
949 */
950
951 info->baud_base = new_serial.baud_base;
952 info->flags = ((info->flags & ~ASYNC_FLAGS) |
953 (new_serial.flags & ASYNC_FLAGS));
954 info->type = new_serial.type;
955 info->close_delay = new_serial.close_delay;
956 info->closing_wait = new_serial.closing_wait;
957
958check_and_exit:
959 retval = startup(info);
960 return retval;
961}
962
963/*
964 * get_lsr_info - get line status register info
965 *
966 * Purpose: Let user call ioctl() to get info when the UART physically
967 * is emptied. On bus types like RS485, the transmitter must
968 * release the bus after transmitting. This must be done when
969 * the transmit shift register is empty, not be done when the
970 * transmit holding register is empty. This functionality
971 * allows an RS485 driver to be written in user space.
972 */
973static int get_lsr_info(struct mcf_serial * info, unsigned int *value)
974{
975 volatile unsigned char *uartp;
976 unsigned long flags;
977 unsigned char status;
978
979 local_irq_save(flags);
980 uartp = info->addr;
981 status = (uartp[MCFUART_USR] & MCFUART_USR_TXEMPTY) ? TIOCSER_TEMT : 0;
982 local_irq_restore(flags);
983
984 return put_user(status,value);
985}
986
987/*
988 * This routine sends a break character out the serial port.
989 */
990static void send_break( struct mcf_serial * info, int duration)
991{
992 volatile unsigned char *uartp;
993 unsigned long flags;
994
995 if (!info->addr)
996 return;
997 set_current_state(TASK_INTERRUPTIBLE);
998 uartp = info->addr;
999
1000 local_irq_save(flags);
1001 uartp[MCFUART_UCR] = MCFUART_UCR_CMDBREAKSTART;
1002 schedule_timeout(duration);
1003 uartp[MCFUART_UCR] = MCFUART_UCR_CMDBREAKSTOP;
1004 local_irq_restore(flags);
1005}
1006
1007static int mcfrs_tiocmget(struct tty_struct *tty, struct file *file)
1008{
1009 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1010
1011 if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
1012 return -ENODEV;
1013 if (tty->flags & (1 << TTY_IO_ERROR))
1014 return -EIO;
1015
1016 return mcfrs_getsignals(info);
1017}
1018
1019static int mcfrs_tiocmset(struct tty_struct *tty, struct file *file,
1020 unsigned int set, unsigned int clear)
1021{
1022 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1023 int rts = -1, dtr = -1;
1024
1025 if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
1026 return -ENODEV;
1027 if (tty->flags & (1 << TTY_IO_ERROR))
1028 return -EIO;
1029
1030 if (set & TIOCM_RTS)
1031 rts = 1;
1032 if (set & TIOCM_DTR)
1033 dtr = 1;
1034 if (clear & TIOCM_RTS)
1035 rts = 0;
1036 if (clear & TIOCM_DTR)
1037 dtr = 0;
1038
1039 mcfrs_setsignals(info, dtr, rts);
1040
1041 return 0;
1042}
1043
1044static int mcfrs_ioctl(struct tty_struct *tty, struct file * file,
1045 unsigned int cmd, unsigned long arg)
1046{
1047 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1048 int retval, error;
1049
1050 if (serial_paranoia_check(info, tty->name, "mcfrs_ioctl"))
1051 return -ENODEV;
1052
1053 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1054 (cmd != TIOCSERCONFIG) && (cmd != TIOCSERGWILD) &&
1055 (cmd != TIOCSERSWILD) && (cmd != TIOCSERGSTRUCT)) {
1056 if (tty->flags & (1 << TTY_IO_ERROR))
1057 return -EIO;
1058 }
1059
1060 switch (cmd) {
1061 case TCSBRK: /* SVID version: non-zero arg --> no break */
1062 retval = tty_check_change(tty);
1063 if (retval)
1064 return retval;
1065 tty_wait_until_sent(tty, 0);
1066 if (!arg)
1067 send_break(info, HZ/4); /* 1/4 second */
1068 return 0;
1069 case TCSBRKP: /* support for POSIX tcsendbreak() */
1070 retval = tty_check_change(tty);
1071 if (retval)
1072 return retval;
1073 tty_wait_until_sent(tty, 0);
1074 send_break(info, arg ? arg*(HZ/10) : HZ/4);
1075 return 0;
1076 case TIOCGSERIAL:
1077 if (access_ok(VERIFY_WRITE, (void *) arg,
1078 sizeof(struct serial_struct)))
1079 return get_serial_info(info,
1080 (struct serial_struct *) arg);
1081 return -EFAULT;
1082 case TIOCSSERIAL:
1083 return set_serial_info(info,
1084 (struct serial_struct *) arg);
1085 case TIOCSERGETLSR: /* Get line status register */
1086 if (access_ok(VERIFY_WRITE, (void *) arg,
1087 sizeof(unsigned int)))
1088 return get_lsr_info(info, (unsigned int *) arg);
1089 return -EFAULT;
1090 case TIOCSERGSTRUCT:
1091 error = copy_to_user((struct mcf_serial *) arg,
1092 info, sizeof(struct mcf_serial));
1093 if (error)
1094 return -EFAULT;
1095 return 0;
1096
1097#ifdef TIOCSET422
1098 case TIOCSET422: {
1099 unsigned int val;
1100 get_user(val, (unsigned int *) arg);
1101 mcf_setpa(MCFPP_PA11, (val ? 0 : MCFPP_PA11));
1102 break;
1103 }
1104 case TIOCGET422: {
1105 unsigned int val;
1106 val = (mcf_getpa() & MCFPP_PA11) ? 0 : 1;
1107 put_user(val, (unsigned int *) arg);
1108 break;
1109 }
1110#endif
1111
1112 default:
1113 return -ENOIOCTLCMD;
1114 }
1115 return 0;
1116}
1117
1118static void mcfrs_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
1119{
1120 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
1121
1122 if (tty->termios->c_cflag == old_termios->c_cflag)
1123 return;
1124
1125 mcfrs_change_speed(info);
1126
1127 if ((old_termios->c_cflag & CRTSCTS) &&
1128 !(tty->termios->c_cflag & CRTSCTS)) {
1129 tty->hw_stopped = 0;
1130 mcfrs_setsignals(info, -1, 1);
1131#if 0
1132 mcfrs_start(tty);
1133#endif
1134 }
1135}
1136
1137/*
1138 * ------------------------------------------------------------
1139 * mcfrs_close()
1140 *
1141 * This routine is called when the serial port gets closed. First, we
1142 * wait for the last remaining data to be sent. Then, we unlink its
1143 * S structure from the interrupt chain if necessary, and we free
1144 * that IRQ if nothing is left in the chain.
1145 * ------------------------------------------------------------
1146 */
1147static void mcfrs_close(struct tty_struct *tty, struct file * filp)
1148{
1149 volatile unsigned char *uartp;
1150 struct mcf_serial *info = (struct mcf_serial *)tty->driver_data;
1151 unsigned long flags;
1152
1153 if (!info || serial_paranoia_check(info, tty->name, "mcfrs_close"))
1154 return;
1155
1156 local_irq_save(flags);
1157
1158 if (tty_hung_up_p(filp)) {
1159 local_irq_restore(flags);
1160 return;
1161 }
1162
1163#ifdef SERIAL_DEBUG_OPEN
1164 printk("mcfrs_close ttyS%d, count = %d\n", info->line, info->count);
1165#endif
1166 if ((tty->count == 1) && (info->count != 1)) {
1167 /*
1168 * Uh, oh. tty->count is 1, which means that the tty
1169 * structure will be freed. Info->count should always
1170 * be one in these conditions. If it's greater than
1171 * one, we've got real problems, since it means the
1172 * serial port won't be shutdown.
1173 */
1174 printk("MCFRS: bad serial port count; tty->count is 1, "
1175 "info->count is %d\n", info->count);
1176 info->count = 1;
1177 }
1178 if (--info->count < 0) {
1179 printk("MCFRS: bad serial port count for ttyS%d: %d\n",
1180 info->line, info->count);
1181 info->count = 0;
1182 }
1183 if (info->count) {
1184 local_irq_restore(flags);
1185 return;
1186 }
1187 info->flags |= ASYNC_CLOSING;
1188
1189 /*
1190 * Now we wait for the transmit buffer to clear; and we notify
1191 * the line discipline to only process XON/XOFF characters.
1192 */
1193 tty->closing = 1;
1194 if (info->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1195 tty_wait_until_sent(tty, info->closing_wait);
1196
1197 /*
1198 * At this point we stop accepting input. To do this, we
1199 * disable the receive line status interrupts, and tell the
1200 * interrupt driver to stop checking the data ready bit in the
1201 * line status register.
1202 */
1203 info->imr &= ~MCFUART_UIR_RXREADY;
1204 uartp = info->addr;
1205 uartp[MCFUART_UIMR] = info->imr;
1206
1207#if 0
1208 /* FIXME: do we need to keep this enabled for console?? */
1209 if (mcfrs_console_inited && (mcfrs_console_port == info->line)) {
1210 /* Do not disable the UART */ ;
1211 } else
1212#endif
1213 shutdown(info);
1214 mcfrs_flush_buffer(tty);
1215 tty_ldisc_flush(tty);
1216
1217 tty->closing = 0;
1218 info->event = 0;
1219 info->port.tty = NULL;
1220#if 0
1221 if (tty->ldisc.num != ldiscs[N_TTY].num) {
1222 if (tty->ldisc.close)
1223 (tty->ldisc.close)(tty);
1224 tty->ldisc = ldiscs[N_TTY];
1225 tty->termios->c_line = N_TTY;
1226 if (tty->ldisc.open)
1227 (tty->ldisc.open)(tty);
1228 }
1229#endif
1230 if (info->blocked_open) {
1231 if (info->close_delay) {
1232 msleep_interruptible(jiffies_to_msecs(info->close_delay));
1233 }
1234 wake_up_interruptible(&info->open_wait);
1235 }
1236 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1237 wake_up_interruptible(&info->close_wait);
1238 local_irq_restore(flags);
1239}
1240
1241/*
1242 * mcfrs_wait_until_sent() --- wait until the transmitter is empty
1243 */
1244static void
1245mcfrs_wait_until_sent(struct tty_struct *tty, int timeout)
1246{
1247#ifdef CONFIG_M5272
1248#define MCF5272_FIFO_SIZE 25 /* fifo size + shift reg */
1249
1250 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1251 volatile unsigned char *uartp;
1252 unsigned long orig_jiffies, fifo_time, char_time, fifo_cnt;
1253
1254 if (serial_paranoia_check(info, tty->name, "mcfrs_wait_until_sent"))
1255 return;
1256
1257 orig_jiffies = jiffies;
1258
1259 /*
1260 * Set the check interval to be 1/5 of the approximate time
1261 * to send the entire fifo, and make it at least 1. The check
1262 * interval should also be less than the timeout.
1263 *
1264 * Note: we have to use pretty tight timings here to satisfy
1265 * the NIST-PCTS.
1266 */
1267 lock_kernel();
1268
1269 fifo_time = (MCF5272_FIFO_SIZE * HZ * 10) / info->baud;
1270 char_time = fifo_time / 5;
1271 if (char_time == 0)
1272 char_time = 1;
1273 if (timeout && timeout < char_time)
1274 char_time = timeout;
1275
1276 /*
1277 * Clamp the timeout period at 2 * the time to empty the
1278 * fifo. Just to be safe, set the minimum at .5 seconds.
1279 */
1280 fifo_time *= 2;
1281 if (fifo_time < (HZ/2))
1282 fifo_time = HZ/2;
1283 if (!timeout || timeout > fifo_time)
1284 timeout = fifo_time;
1285
1286 /*
1287 * Account for the number of bytes in the UART
1288 * transmitter FIFO plus any byte being shifted out.
1289 */
1290 uartp = (volatile unsigned char *) info->addr;
1291 for (;;) {
1292 fifo_cnt = (uartp[MCFUART_UTF] & MCFUART_UTF_TXB);
1293 if ((uartp[MCFUART_USR] & (MCFUART_USR_TXREADY|
1294 MCFUART_USR_TXEMPTY)) ==
1295 MCFUART_USR_TXREADY)
1296 fifo_cnt++;
1297 if (fifo_cnt == 0)
1298 break;
1299 msleep_interruptible(jiffies_to_msecs(char_time));
1300 if (signal_pending(current))
1301 break;
1302 if (timeout && time_after(jiffies, orig_jiffies + timeout))
1303 break;
1304 }
1305 unlock_kernel();
1306#else
1307 /*
1308 * For the other coldfire models, assume all data has been sent
1309 */
1310#endif
1311}
1312
1313/*
1314 * mcfrs_hangup() --- called by tty_hangup() when a hangup is signaled.
1315 */
1316void mcfrs_hangup(struct tty_struct *tty)
1317{
1318 struct mcf_serial * info = (struct mcf_serial *)tty->driver_data;
1319
1320 if (serial_paranoia_check(info, tty->name, "mcfrs_hangup"))
1321 return;
1322
1323 mcfrs_flush_buffer(tty);
1324 shutdown(info);
1325 info->event = 0;
1326 info->count = 0;
1327 info->flags &= ~ASYNC_NORMAL_ACTIVE;
1328 info->port.tty = NULL;
1329 wake_up_interruptible(&info->open_wait);
1330}
1331
1332/*
1333 * ------------------------------------------------------------
1334 * mcfrs_open() and friends
1335 * ------------------------------------------------------------
1336 */
1337static int block_til_ready(struct tty_struct *tty, struct file * filp,
1338 struct mcf_serial *info)
1339{
1340 DECLARE_WAITQUEUE(wait, current);
1341 int retval;
1342 int do_clocal = 0;
1343
1344 /*
1345 * If the device is in the middle of being closed, then block
1346 * until it's done, and then try again.
1347 */
1348 if (info->flags & ASYNC_CLOSING) {
1349 interruptible_sleep_on(&info->close_wait);
1350#ifdef SERIAL_DO_RESTART
1351 if (info->flags & ASYNC_HUP_NOTIFY)
1352 return -EAGAIN;
1353 else
1354 return -ERESTARTSYS;
1355#else
1356 return -EAGAIN;
1357#endif
1358 }
1359
1360 /*
1361 * If non-blocking mode is set, or the port is not enabled,
1362 * then make the check up front and then exit.
1363 */
1364 if ((filp->f_flags & O_NONBLOCK) ||
1365 (tty->flags & (1 << TTY_IO_ERROR))) {
1366 info->flags |= ASYNC_NORMAL_ACTIVE;
1367 return 0;
1368 }
1369
1370 if (tty->termios->c_cflag & CLOCAL)
1371 do_clocal = 1;
1372
1373 /*
1374 * Block waiting for the carrier detect and the line to become
1375 * free (i.e., not in use by the callout). While we are in
1376 * this loop, info->count is dropped by one, so that
1377 * mcfrs_close() knows when to free things. We restore it upon
1378 * exit, either normal or abnormal.
1379 */
1380 retval = 0;
1381 add_wait_queue(&info->open_wait, &wait);
1382#ifdef SERIAL_DEBUG_OPEN
1383 printk("block_til_ready before block: ttyS%d, count = %d\n",
1384 info->line, info->count);
1385#endif
1386 info->count--;
1387 info->blocked_open++;
1388 while (1) {
1389 local_irq_disable();
1390 mcfrs_setsignals(info, 1, 1);
1391 local_irq_enable();
1392 current->state = TASK_INTERRUPTIBLE;
1393 if (tty_hung_up_p(filp) ||
1394 !(info->flags & ASYNC_INITIALIZED)) {
1395#ifdef SERIAL_DO_RESTART
1396 if (info->flags & ASYNC_HUP_NOTIFY)
1397 retval = -EAGAIN;
1398 else
1399 retval = -ERESTARTSYS;
1400#else
1401 retval = -EAGAIN;
1402#endif
1403 break;
1404 }
1405 if (!(info->flags & ASYNC_CLOSING) &&
1406 (do_clocal || (mcfrs_getsignals(info) & TIOCM_CD)))
1407 break;
1408 if (signal_pending(current)) {
1409 retval = -ERESTARTSYS;
1410 break;
1411 }
1412#ifdef SERIAL_DEBUG_OPEN
1413 printk("block_til_ready blocking: ttyS%d, count = %d\n",
1414 info->line, info->count);
1415#endif
1416 schedule();
1417 }
1418 current->state = TASK_RUNNING;
1419 remove_wait_queue(&info->open_wait, &wait);
1420 if (!tty_hung_up_p(filp))
1421 info->count++;
1422 info->blocked_open--;
1423#ifdef SERIAL_DEBUG_OPEN
1424 printk("block_til_ready after blocking: ttyS%d, count = %d\n",
1425 info->line, info->count);
1426#endif
1427 if (retval)
1428 return retval;
1429 info->flags |= ASYNC_NORMAL_ACTIVE;
1430 return 0;
1431}
1432
1433/*
1434 * This routine is called whenever a serial port is opened. It
1435 * enables interrupts for a serial port, linking in its structure into
1436 * the IRQ chain. It also performs the serial-specific
1437 * initialization for the tty structure.
1438 */
1439int mcfrs_open(struct tty_struct *tty, struct file * filp)
1440{
1441 struct mcf_serial *info;
1442 int retval, line;
1443
1444 line = tty->index;
1445 if ((line < 0) || (line >= NR_PORTS))
1446 return -ENODEV;
1447 info = mcfrs_table + line;
1448 if (serial_paranoia_check(info, tty->name, "mcfrs_open"))
1449 return -ENODEV;
1450#ifdef SERIAL_DEBUG_OPEN
1451 printk("mcfrs_open %s, count = %d\n", tty->name, info->count);
1452#endif
1453 info->count++;
1454 tty->driver_data = info;
1455 info->port.tty = tty;
1456
1457 /*
1458 * Start up serial port
1459 */
1460 retval = startup(info);
1461 if (retval)
1462 return retval;
1463
1464 retval = block_til_ready(tty, filp, info);
1465 if (retval) {
1466#ifdef SERIAL_DEBUG_OPEN
1467 printk("mcfrs_open returning after block_til_ready with %d\n",
1468 retval);
1469#endif
1470 return retval;
1471 }
1472
1473#ifdef SERIAL_DEBUG_OPEN
1474 printk("mcfrs_open %s successful...\n", tty->name);
1475#endif
1476 return 0;
1477}
1478
1479/*
1480 * Based on the line number set up the internal interrupt stuff.
1481 */
1482static void mcfrs_irqinit(struct mcf_serial *info)
1483{
1484#if defined(CONFIG_M5272)
1485 volatile unsigned long *icrp;
1486 volatile unsigned long *portp;
1487 volatile unsigned char *uartp;
1488
1489 uartp = info->addr;
1490 icrp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_ICR2);
1491
1492 switch (info->line) {
1493 case 0:
1494 *icrp = 0xe0000000;
1495 break;
1496 case 1:
1497 *icrp = 0x0e000000;
1498 break;
1499 default:
1500 printk("MCFRS: don't know how to handle UART %d interrupt?\n",
1501 info->line);
1502 return;
1503 }
1504
1505 /* Enable the output lines for the serial ports */
1506 portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PBCNT);
1507 *portp = (*portp & ~0x000000ff) | 0x00000055;
1508 portp = (volatile unsigned long *) (MCF_MBAR + MCFSIM_PDCNT);
1509 *portp = (*portp & ~0x000003fc) | 0x000002a8;
1510#elif defined(CONFIG_M523x) || defined(CONFIG_M527x) || defined(CONFIG_M528x)
1511 volatile unsigned char *icrp, *uartp;
1512 volatile unsigned long *imrp;
1513
1514 uartp = info->addr;
1515
1516 icrp = (volatile unsigned char *) (MCF_MBAR + MCFICM_INTC0 +
1517 MCFINTC_ICR0 + MCFINT_UART0 + info->line);
1518 *icrp = 0x30 + info->line; /* level 6, line based priority */
1519
1520 imrp = (volatile unsigned long *) (MCF_MBAR + MCFICM_INTC0 +
1521 MCFINTC_IMRL);
1522 *imrp &= ~((1 << (info->irq - MCFINT_VECBASE)) | 1);
1523#if defined(CONFIG_M527x)
1524 {
1525 /*
1526 * External Pin Mask Setting & Enable External Pin for Interface
1527 * mrcbis@aliceposta.it
1528 */
1529 u16 *serpin_enable_mask;
1530 serpin_enable_mask = (u16 *) (MCF_IPSBAR + MCF_GPIO_PAR_UART);
1531 if (info->line == 0)
1532 *serpin_enable_mask |= UART0_ENABLE_MASK;
1533 else if (info->line == 1)
1534 *serpin_enable_mask |= UART1_ENABLE_MASK;
1535 else if (info->line == 2)
1536 *serpin_enable_mask |= UART2_ENABLE_MASK;
1537 }
1538#endif
1539#if defined(CONFIG_M528x)
1540 /* make sure PUAPAR is set for UART0 and UART1 */
1541 if (info->line < 2) {
1542 volatile unsigned char *portp = (volatile unsigned char *) (MCF_MBAR + MCF5282_GPIO_PUAPAR);
1543 *portp |= (0x03 << (info->line * 2));
1544 }
1545#endif
1546#elif defined(CONFIG_M520x)
1547 volatile unsigned char *icrp, *uartp;
1548 volatile unsigned long *imrp;
1549
1550 uartp = info->addr;
1551
1552 icrp = (volatile unsigned char *) (MCF_MBAR + MCFICM_INTC0 +
1553 MCFINTC_ICR0 + MCFINT_UART0 + info->line);
1554 *icrp = 0x03;
1555
1556 imrp = (volatile unsigned long *) (MCF_MBAR + MCFICM_INTC0 +
1557 MCFINTC_IMRL);
1558 *imrp &= ~((1 << (info->irq - MCFINT_VECBASE)) | 1);
1559 if (info->line < 2) {
1560 unsigned short *uart_par;
1561 uart_par = (unsigned short *)(MCF_IPSBAR + MCF_GPIO_PAR_UART);
1562 if (info->line == 0)
1563 *uart_par |= MCF_GPIO_PAR_UART_PAR_UTXD0
1564 | MCF_GPIO_PAR_UART_PAR_URXD0;
1565 else if (info->line == 1)
1566 *uart_par |= MCF_GPIO_PAR_UART_PAR_UTXD1
1567 | MCF_GPIO_PAR_UART_PAR_URXD1;
1568 } else if (info->line == 2) {
1569 unsigned char *feci2c_par;
1570 feci2c_par = (unsigned char *)(MCF_IPSBAR + MCF_GPIO_PAR_FECI2C);
1571 *feci2c_par &= ~0x0F;
1572 *feci2c_par |= MCF_GPIO_PAR_FECI2C_PAR_SCL_UTXD2
1573 | MCF_GPIO_PAR_FECI2C_PAR_SDA_URXD2;
1574 }
1575#elif defined(CONFIG_M532x)
1576 volatile unsigned char *uartp;
1577 uartp = info->addr;
1578 switch (info->line) {
1579 case 0:
1580 MCF_INTC0_ICR26 = 0x3;
1581 MCF_INTC0_CIMR = 26;
1582 /* GPIO initialization */
1583 MCF_GPIO_PAR_UART |= 0x000F;
1584 break;
1585 case 1:
1586 MCF_INTC0_ICR27 = 0x3;
1587 MCF_INTC0_CIMR = 27;
1588 /* GPIO initialization */
1589 MCF_GPIO_PAR_UART |= 0x0FF0;
1590 break;
1591 case 2:
1592 MCF_INTC0_ICR28 = 0x3;
1593 MCF_INTC0_CIMR = 28;
1594 /* GPIOs also must be initalized, depends on board */
1595 break;
1596 }
1597#else
1598 volatile unsigned char *icrp, *uartp;
1599
1600 switch (info->line) {
1601 case 0:
1602 icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_UART1ICR);
1603 *icrp = /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6 |
1604 MCFSIM_ICR_PRI1;
1605 mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART1);
1606 break;
1607 case 1:
1608 icrp = (volatile unsigned char *) (MCF_MBAR + MCFSIM_UART2ICR);
1609 *icrp = /*MCFSIM_ICR_AUTOVEC |*/ MCFSIM_ICR_LEVEL6 |
1610 MCFSIM_ICR_PRI2;
1611 mcf_setimr(mcf_getimr() & ~MCFSIM_IMR_UART2);
1612 break;
1613 default:
1614 printk("MCFRS: don't know how to handle UART %d interrupt?\n",
1615 info->line);
1616 return;
1617 }
1618
1619 uartp = info->addr;
1620 uartp[MCFUART_UIVR] = info->irq;
1621#endif
1622
1623 /* Clear mask, so no surprise interrupts. */
1624 uartp[MCFUART_UIMR] = 0;
1625
1626 if (request_irq(info->irq, mcfrs_interrupt, IRQF_DISABLED,
1627 "ColdFire UART", NULL)) {
1628 printk("MCFRS: Unable to attach ColdFire UART %d interrupt "
1629 "vector=%d\n", info->line, info->irq);
1630 }
1631
1632 return;
1633}
1634
1635
1636char *mcfrs_drivername = "ColdFire internal UART serial driver version 1.00\n";
1637
1638
1639/*
1640 * Serial stats reporting...
1641 */
1642int mcfrs_readproc(char *page, char **start, off_t off, int count,
1643 int *eof, void *data)
1644{
1645 struct mcf_serial *info;
1646 char str[20];
1647 int len, sigs, i;
1648
1649 len = sprintf(page, mcfrs_drivername);
1650 for (i = 0; (i < NR_PORTS); i++) {
1651 info = &mcfrs_table[i];
1652 len += sprintf((page + len), "%d: port:%x irq=%d baud:%d ",
1653 i, (unsigned int) info->addr, info->irq, info->baud);
1654 if (info->stats.rx || info->stats.tx)
1655 len += sprintf((page + len), "tx:%d rx:%d ",
1656 info->stats.tx, info->stats.rx);
1657 if (info->stats.rxframing)
1658 len += sprintf((page + len), "fe:%d ",
1659 info->stats.rxframing);
1660 if (info->stats.rxparity)
1661 len += sprintf((page + len), "pe:%d ",
1662 info->stats.rxparity);
1663 if (info->stats.rxbreak)
1664 len += sprintf((page + len), "brk:%d ",
1665 info->stats.rxbreak);
1666 if (info->stats.rxoverrun)
1667 len += sprintf((page + len), "oe:%d ",
1668 info->stats.rxoverrun);
1669
1670 str[0] = str[1] = 0;
1671 if ((sigs = mcfrs_getsignals(info))) {
1672 if (sigs & TIOCM_RTS)
1673 strcat(str, "|RTS");
1674 if (sigs & TIOCM_CTS)
1675 strcat(str, "|CTS");
1676 if (sigs & TIOCM_DTR)
1677 strcat(str, "|DTR");
1678 if (sigs & TIOCM_CD)
1679 strcat(str, "|CD");
1680 }
1681
1682 len += sprintf((page + len), "%s\n", &str[1]);
1683 }
1684
1685 return(len);
1686}
1687
1688
1689/* Finally, routines used to initialize the serial driver. */
1690
1691static void show_serial_version(void)
1692{
1693 printk(mcfrs_drivername);
1694}
1695
1696static const struct tty_operations mcfrs_ops = {
1697 .open = mcfrs_open,
1698 .close = mcfrs_close,
1699 .write = mcfrs_write,
1700 .flush_chars = mcfrs_flush_chars,
1701 .write_room = mcfrs_write_room,
1702 .chars_in_buffer = mcfrs_chars_in_buffer,
1703 .flush_buffer = mcfrs_flush_buffer,
1704 .ioctl = mcfrs_ioctl,
1705 .throttle = mcfrs_throttle,
1706 .unthrottle = mcfrs_unthrottle,
1707 .set_termios = mcfrs_set_termios,
1708 .stop = mcfrs_stop,
1709 .start = mcfrs_start,
1710 .hangup = mcfrs_hangup,
1711 .read_proc = mcfrs_readproc,
1712 .wait_until_sent = mcfrs_wait_until_sent,
1713 .tiocmget = mcfrs_tiocmget,
1714 .tiocmset = mcfrs_tiocmset,
1715};
1716
1717/* mcfrs_init inits the driver */
1718static int __init
1719mcfrs_init(void)
1720{
1721 struct mcf_serial *info;
1722 unsigned long flags;
1723 int i;
1724
1725 /* Setup base handler, and timer table. */
1726#ifdef MCFPP_DCD0
1727 init_timer(&mcfrs_timer_struct);
1728 mcfrs_timer_struct.function = mcfrs_timer;
1729 mcfrs_timer_struct.data = 0;
1730 mcfrs_timer_struct.expires = jiffies + HZ/25;
1731 add_timer(&mcfrs_timer_struct);
1732 mcfrs_ppstatus = mcf_getppdata() & (MCFPP_DCD0 | MCFPP_DCD1);
1733#endif
1734 mcfrs_serial_driver = alloc_tty_driver(NR_PORTS);
1735 if (!mcfrs_serial_driver)
1736 return -ENOMEM;
1737
1738 show_serial_version();
1739
1740 /* Initialize the tty_driver structure */
1741 mcfrs_serial_driver->owner = THIS_MODULE;
1742 mcfrs_serial_driver->name = "ttyS";
1743 mcfrs_serial_driver->driver_name = "mcfserial";
1744 mcfrs_serial_driver->major = TTY_MAJOR;
1745 mcfrs_serial_driver->minor_start = 64;
1746 mcfrs_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
1747 mcfrs_serial_driver->subtype = SERIAL_TYPE_NORMAL;
1748 mcfrs_serial_driver->init_termios = tty_std_termios;
1749
1750 mcfrs_serial_driver->init_termios.c_cflag =
1751 mcfrs_console_cbaud | CS8 | CREAD | HUPCL | CLOCAL;
1752 mcfrs_serial_driver->flags = TTY_DRIVER_REAL_RAW;
1753
1754 tty_set_operations(mcfrs_serial_driver, &mcfrs_ops);
1755
1756 if (tty_register_driver(mcfrs_serial_driver)) {
1757 printk("MCFRS: Couldn't register serial driver\n");
1758 put_tty_driver(mcfrs_serial_driver);
1759 return(-EBUSY);
1760 }
1761
1762 local_irq_save(flags);
1763
1764 /*
1765 * Configure all the attached serial ports.
1766 */
1767 for (i = 0, info = mcfrs_table; (i < NR_PORTS); i++, info++) {
1768 info->magic = SERIAL_MAGIC;
1769 info->line = i;
1770 info->port.tty = NULL;
1771 info->custom_divisor = 16;
1772 info->close_delay = 50;
1773 info->closing_wait = 3000;
1774 info->x_char = 0;
1775 info->event = 0;
1776 info->count = 0;
1777 info->blocked_open = 0;
1778 INIT_WORK(&info->tqueue, mcfrs_offintr);
1779 INIT_WORK(&info->tqueue_hangup, do_serial_hangup);
1780 init_waitqueue_head(&info->open_wait);
1781 init_waitqueue_head(&info->close_wait);
1782
1783 info->imr = 0;
1784 mcfrs_setsignals(info, 0, 0);
1785 mcfrs_irqinit(info);
1786
1787 printk("ttyS%d at 0x%04x (irq = %d)", info->line,
1788 (unsigned int) info->addr, info->irq);
1789 printk(" is a builtin ColdFire UART\n");
1790 }
1791
1792 local_irq_restore(flags);
1793 return 0;
1794}
1795
1796module_init(mcfrs_init);
1797
1798/****************************************************************************/
1799/* Serial Console */
1800/****************************************************************************/
1801
1802/*
1803 * Quick and dirty UART initialization, for console output.
1804 */
1805
1806void mcfrs_init_console(void)
1807{
1808 volatile unsigned char *uartp;
1809 unsigned int clk;
1810
1811 /*
1812 * Reset UART, get it into known state...
1813 */
1814 uartp = (volatile unsigned char *) (MCF_MBAR +
1815 (mcfrs_console_port ? MCFUART_BASE2 : MCFUART_BASE1));
1816
1817 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
1818 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
1819 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
1820
1821 /*
1822 * Set port for defined baud , 8 data bits, 1 stop bit, no parity.
1823 */
1824 uartp[MCFUART_UMR] = MCFUART_MR1_PARITYNONE | MCFUART_MR1_CS8;
1825 uartp[MCFUART_UMR] = MCFUART_MR2_STOP1;
1826
1827#ifdef CONFIG_M5272
1828{
1829 /*
1830 * For the MCF5272, also compute the baudrate fraction.
1831 */
1832 int fraction = MCF_BUSCLK - (clk * 32 * mcfrs_console_baud);
1833 fraction *= 16;
1834 fraction /= (32 * mcfrs_console_baud);
1835 uartp[MCFUART_UFPD] = (fraction & 0xf); /* set fraction */
1836 clk = (MCF_BUSCLK / mcfrs_console_baud) / 32;
1837}
1838#else
1839 clk = ((MCF_BUSCLK / mcfrs_console_baud) + 16) / 32; /* set baud */
1840#endif
1841
1842 uartp[MCFUART_UBG1] = (clk & 0xff00) >> 8; /* set msb baud */
1843 uartp[MCFUART_UBG2] = (clk & 0xff); /* set lsb baud */
1844 uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER;
1845 uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
1846
1847 mcfrs_console_inited++;
1848 return;
1849}
1850
1851
1852/*
1853 * Setup for console. Argument comes from the boot command line.
1854 */
1855
1856int mcfrs_console_setup(struct console *cp, char *arg)
1857{
1858 int i, n = CONSOLE_BAUD_RATE;
1859
1860 if (!cp)
1861 return(-1);
1862
1863 if (!strncmp(cp->name, "ttyS", 4))
1864 mcfrs_console_port = cp->index;
1865 else if (!strncmp(cp->name, "cua", 3))
1866 mcfrs_console_port = cp->index;
1867 else
1868 return(-1);
1869
1870 if (arg)
1871 n = simple_strtoul(arg,NULL,0);
1872 for (i = 0; i < MCFRS_BAUD_TABLE_SIZE; i++)
1873 if (mcfrs_baud_table[i] == n)
1874 break;
1875 if (i < MCFRS_BAUD_TABLE_SIZE) {
1876 mcfrs_console_baud = n;
1877 mcfrs_console_cbaud = 0;
1878 if (i > 15) {
1879 mcfrs_console_cbaud |= CBAUDEX;
1880 i -= 15;
1881 }
1882 mcfrs_console_cbaud |= i;
1883 }
1884 mcfrs_init_console(); /* make sure baud rate changes */
1885 return(0);
1886}
1887
1888
1889static struct tty_driver *mcfrs_console_device(struct console *c, int *index)
1890{
1891 *index = c->index;
1892 return mcfrs_serial_driver;
1893}
1894
1895
1896/*
1897 * Output a single character, using UART polled mode.
1898 * This is used for console output.
1899 */
1900
1901int mcfrs_put_char(char ch)
1902{
1903 volatile unsigned char *uartp;
1904 unsigned long flags;
1905 int i;
1906
1907 uartp = (volatile unsigned char *) (MCF_MBAR +
1908 (mcfrs_console_port ? MCFUART_BASE2 : MCFUART_BASE1));
1909
1910 local_irq_save(flags);
1911 for (i = 0; (i < 0x10000); i++) {
1912 if (uartp[MCFUART_USR] & MCFUART_USR_TXREADY)
1913 break;
1914 }
1915 if (i < 0x10000) {
1916 uartp[MCFUART_UTB] = ch;
1917 for (i = 0; (i < 0x10000); i++)
1918 if (uartp[MCFUART_USR] & MCFUART_USR_TXEMPTY)
1919 break;
1920 }
1921 if (i >= 0x10000)
1922 mcfrs_init_console(); /* try and get it back */
1923 local_irq_restore(flags);
1924
1925 return 1;
1926}
1927
1928
1929/*
1930 * rs_console_write is registered for printk output.
1931 */
1932
1933void mcfrs_console_write(struct console *cp, const char *p, unsigned len)
1934{
1935 if (!mcfrs_console_inited)
1936 mcfrs_init_console();
1937 while (len-- > 0) {
1938 if (*p == '\n')
1939 mcfrs_put_char('\r');
1940 mcfrs_put_char(*p++);
1941 }
1942}
1943
1944/*
1945 * declare our consoles
1946 */
1947
1948struct console mcfrs_console = {
1949 .name = "ttyS",
1950 .write = mcfrs_console_write,
1951 .device = mcfrs_console_device,
1952 .setup = mcfrs_console_setup,
1953 .flags = CON_PRINTBUFFER,
1954 .index = -1,
1955};
1956
1957static int __init mcfrs_console_init(void)
1958{
1959 register_console(&mcfrs_console);
1960 return 0;
1961}
1962
1963console_initcall(mcfrs_console_init);
1964
1965/****************************************************************************/
diff --git a/drivers/serial/mcfserial.h b/drivers/serial/mcfserial.h
deleted file mode 100644
index 56420e2cb110..000000000000
--- a/drivers/serial/mcfserial.h
+++ /dev/null
@@ -1,74 +0,0 @@
1/*
2 * mcfserial.c -- serial driver for ColdFire internal UARTS.
3 *
4 * Copyright (c) 1999 Greg Ungerer <gerg@snapgear.com>
5 * Copyright (c) 2000-2001 Lineo, Inc. <www.lineo.com>
6 * Copyright (c) 2002 SnapGear Inc., <www.snapgear.com>
7 *
8 * Based on code from 68332serial.c which was:
9 *
10 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
11 * Copyright (C) 1998 TSHG
12 * Copyright (c) 1999 Rt-Control Inc. <jeff@uclinux.org>
13 */
14#ifndef _MCF_SERIAL_H
15#define _MCF_SERIAL_H
16
17#include <linux/serial.h>
18
19#ifdef __KERNEL__
20
21/*
22 * Define a local serial stats structure.
23 */
24
25struct mcf_stats {
26 unsigned int rx;
27 unsigned int tx;
28 unsigned int rxbreak;
29 unsigned int rxframing;
30 unsigned int rxparity;
31 unsigned int rxoverrun;
32};
33
34
35/*
36 * This is our internal structure for each serial port's state.
37 * Each serial port has one of these structures associated with it.
38 */
39
40struct mcf_serial {
41 int magic;
42 volatile unsigned char *addr; /* UART memory address */
43 int irq;
44 int flags; /* defined in tty.h */
45 int type; /* UART type */
46 struct tty_struct *tty;
47 unsigned char imr; /* Software imr register */
48 unsigned int baud;
49 int sigs;
50 int custom_divisor;
51 int x_char; /* xon/xoff character */
52 int baud_base;
53 int close_delay;
54 unsigned short closing_wait;
55 unsigned short closing_wait2;
56 unsigned long event;
57 int line;
58 int count; /* # of fd on device */
59 int blocked_open; /* # of blocked opens */
60 unsigned char *xmit_buf;
61 int xmit_head;
62 int xmit_tail;
63 int xmit_cnt;
64 struct mcf_stats stats;
65 struct work_struct tqueue;
66 struct work_struct tqueue_hangup;
67 wait_queue_head_t open_wait;
68 wait_queue_head_t close_wait;
69
70};
71
72#endif /* __KERNEL__ */
73
74#endif /* _MCF_SERIAL_H */
diff --git a/drivers/serial/mpc52xx_uart.c b/drivers/serial/mpc52xx_uart.c
index 36126070d9af..6117d3db0b66 100644
--- a/drivers/serial/mpc52xx_uart.c
+++ b/drivers/serial/mpc52xx_uart.c
@@ -72,13 +72,8 @@
72#include <linux/console.h> 72#include <linux/console.h>
73#include <linux/delay.h> 73#include <linux/delay.h>
74#include <linux/io.h> 74#include <linux/io.h>
75
76#if defined(CONFIG_PPC_MERGE)
77#include <linux/of.h> 75#include <linux/of.h>
78#include <linux/of_platform.h> 76#include <linux/of_platform.h>
79#else
80#include <linux/platform_device.h>
81#endif
82 77
83#include <asm/mpc52xx.h> 78#include <asm/mpc52xx.h>
84#include <asm/mpc512x.h> 79#include <asm/mpc512x.h>
@@ -107,12 +102,11 @@ static struct uart_port mpc52xx_uart_ports[MPC52xx_PSC_MAXNUM];
107 * it's cleared, then a memset(...,0,...) should be added to 102 * it's cleared, then a memset(...,0,...) should be added to
108 * the console_init 103 * the console_init
109 */ 104 */
110#if defined(CONFIG_PPC_MERGE) 105
111/* lookup table for matching device nodes to index numbers */ 106/* lookup table for matching device nodes to index numbers */
112static struct device_node *mpc52xx_uart_nodes[MPC52xx_PSC_MAXNUM]; 107static struct device_node *mpc52xx_uart_nodes[MPC52xx_PSC_MAXNUM];
113 108
114static void mpc52xx_uart_of_enumerate(void); 109static void mpc52xx_uart_of_enumerate(void);
115#endif
116 110
117 111
118#define PSC(port) ((struct mpc52xx_psc __iomem *)((port)->membase)) 112#define PSC(port) ((struct mpc52xx_psc __iomem *)((port)->membase))
@@ -255,17 +249,12 @@ static void mpc52xx_psc_cw_restore_ints(struct uart_port *port)
255/* Search for bus-frequency property in this node or a parent */ 249/* Search for bus-frequency property in this node or a parent */
256static unsigned long mpc52xx_getuartclk(void *p) 250static unsigned long mpc52xx_getuartclk(void *p)
257{ 251{
258#if defined(CONFIG_PPC_MERGE)
259 /* 252 /*
260 * 5200 UARTs have a / 32 prescaler 253 * 5200 UARTs have a / 32 prescaler
261 * but the generic serial code assumes 16 254 * but the generic serial code assumes 16
262 * so return ipb freq / 2 255 * so return ipb freq / 2
263 */ 256 */
264 return mpc52xx_find_ipb_freq(p) / 2; 257 return mpc52xx_find_ipb_freq(p) / 2;
265#else
266 pr_debug("unexpected call to mpc52xx_getuartclk with arch/ppc\n");
267 return NULL;
268#endif
269} 258}
270 259
271static struct psc_ops mpc52xx_psc_ops = { 260static struct psc_ops mpc52xx_psc_ops = {
@@ -886,10 +875,6 @@ mpc52xx_console_get_options(struct uart_port *port,
886 875
887 /* CT{U,L}R are write-only ! */ 876 /* CT{U,L}R are write-only ! */
888 *baud = CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD; 877 *baud = CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD;
889#if !defined(CONFIG_PPC_MERGE)
890 if (__res.bi_baudrate)
891 *baud = __res.bi_baudrate;
892#endif
893 878
894 /* Parse them */ 879 /* Parse them */
895 switch (mr1 & MPC52xx_PSC_MODE_BITS_MASK) { 880 switch (mr1 & MPC52xx_PSC_MODE_BITS_MASK) {
@@ -946,42 +931,6 @@ mpc52xx_console_write(struct console *co, const char *s, unsigned int count)
946 psc_ops->cw_restore_ints(port); 931 psc_ops->cw_restore_ints(port);
947} 932}
948 933
949#if !defined(CONFIG_PPC_MERGE)
950static int __init
951mpc52xx_console_setup(struct console *co, char *options)
952{
953 struct uart_port *port = &mpc52xx_uart_ports[co->index];
954
955 int baud = CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD;
956 int bits = 8;
957 int parity = 'n';
958 int flow = 'n';
959
960 if (co->index < 0 || co->index >= MPC52xx_PSC_MAXNUM)
961 return -EINVAL;
962
963 /* Basic port init. Needed since we use some uart_??? func before
964 * real init for early access */
965 spin_lock_init(&port->lock);
966 port->uartclk = __res.bi_ipbfreq / 2; /* Look at CTLR doc */
967 port->ops = &mpc52xx_uart_ops;
968 port->mapbase = MPC52xx_PA(MPC52xx_PSCx_OFFSET(co->index+1));
969
970 /* We ioremap ourself */
971 port->membase = ioremap(port->mapbase, MPC52xx_PSC_SIZE);
972 if (port->membase == NULL)
973 return -EINVAL;
974
975 /* Setup the port parameters accoding to options */
976 if (options)
977 uart_parse_options(options, &baud, &parity, &bits, &flow);
978 else
979 mpc52xx_console_get_options(port, &baud, &parity, &bits, &flow);
980
981 return uart_set_options(port, co, baud, parity, bits, flow);
982}
983
984#else
985 934
986static int __init 935static int __init
987mpc52xx_console_setup(struct console *co, char *options) 936mpc52xx_console_setup(struct console *co, char *options)
@@ -1053,7 +1002,6 @@ mpc52xx_console_setup(struct console *co, char *options)
1053 1002
1054 return uart_set_options(port, co, baud, parity, bits, flow); 1003 return uart_set_options(port, co, baud, parity, bits, flow);
1055} 1004}
1056#endif /* defined(CONFIG_PPC_MERGE) */
1057 1005
1058 1006
1059static struct uart_driver mpc52xx_uart_driver; 1007static struct uart_driver mpc52xx_uart_driver;
@@ -1072,9 +1020,7 @@ static struct console mpc52xx_console = {
1072static int __init 1020static int __init
1073mpc52xx_console_init(void) 1021mpc52xx_console_init(void)
1074{ 1022{
1075#if defined(CONFIG_PPC_MERGE)
1076 mpc52xx_uart_of_enumerate(); 1023 mpc52xx_uart_of_enumerate();
1077#endif
1078 register_console(&mpc52xx_console); 1024 register_console(&mpc52xx_console);
1079 return 0; 1025 return 0;
1080} 1026}
@@ -1100,115 +1046,6 @@ static struct uart_driver mpc52xx_uart_driver = {
1100 .cons = MPC52xx_PSC_CONSOLE, 1046 .cons = MPC52xx_PSC_CONSOLE,
1101}; 1047};
1102 1048
1103
1104#if !defined(CONFIG_PPC_MERGE)
1105/* ======================================================================== */
1106/* Platform Driver */
1107/* ======================================================================== */
1108
1109static int __devinit
1110mpc52xx_uart_probe(struct platform_device *dev)
1111{
1112 struct resource *res = dev->resource;
1113
1114 struct uart_port *port = NULL;
1115 int i, idx, ret;
1116
1117 /* Check validity & presence */
1118 idx = dev->id;
1119 if (idx < 0 || idx >= MPC52xx_PSC_MAXNUM)
1120 return -EINVAL;
1121
1122 if (!mpc52xx_match_psc_function(idx, "uart"))
1123 return -ENODEV;
1124
1125 /* Init the port structure */
1126 port = &mpc52xx_uart_ports[idx];
1127
1128 spin_lock_init(&port->lock);
1129 port->uartclk = __res.bi_ipbfreq / 2; /* Look at CTLR doc */
1130 port->fifosize = 512;
1131 port->iotype = UPIO_MEM;
1132 port->flags = UPF_BOOT_AUTOCONF |
1133 (uart_console(port) ? 0 : UPF_IOREMAP);
1134 port->line = idx;
1135 port->ops = &mpc52xx_uart_ops;
1136 port->dev = &dev->dev;
1137
1138 /* Search for IRQ and mapbase */
1139 for (i = 0 ; i < dev->num_resources ; i++, res++) {
1140 if (res->flags & IORESOURCE_MEM)
1141 port->mapbase = res->start;
1142 else if (res->flags & IORESOURCE_IRQ)
1143 port->irq = res->start;
1144 }
1145 if (!port->irq || !port->mapbase)
1146 return -EINVAL;
1147
1148 /* Add the port to the uart sub-system */
1149 ret = uart_add_one_port(&mpc52xx_uart_driver, port);
1150 if (!ret)
1151 platform_set_drvdata(dev, (void *)port);
1152
1153 return ret;
1154}
1155
1156static int
1157mpc52xx_uart_remove(struct platform_device *dev)
1158{
1159 struct uart_port *port = (struct uart_port *) platform_get_drvdata(dev);
1160
1161 platform_set_drvdata(dev, NULL);
1162
1163 if (port)
1164 uart_remove_one_port(&mpc52xx_uart_driver, port);
1165
1166 return 0;
1167}
1168
1169#ifdef CONFIG_PM
1170static int
1171mpc52xx_uart_suspend(struct platform_device *dev, pm_message_t state)
1172{
1173 struct uart_port *port = (struct uart_port *) platform_get_drvdata(dev);
1174
1175 if (port)
1176 uart_suspend_port(&mpc52xx_uart_driver, port);
1177
1178 return 0;
1179}
1180
1181static int
1182mpc52xx_uart_resume(struct platform_device *dev)
1183{
1184 struct uart_port *port = (struct uart_port *) platform_get_drvdata(dev);
1185
1186 if (port)
1187 uart_resume_port(&mpc52xx_uart_driver, port);
1188
1189 return 0;
1190}
1191#endif
1192
1193/* work with hotplug and coldplug */
1194MODULE_ALIAS("platform:mpc52xx-psc");
1195
1196static struct platform_driver mpc52xx_uart_platform_driver = {
1197 .probe = mpc52xx_uart_probe,
1198 .remove = mpc52xx_uart_remove,
1199#ifdef CONFIG_PM
1200 .suspend = mpc52xx_uart_suspend,
1201 .resume = mpc52xx_uart_resume,
1202#endif
1203 .driver = {
1204 .owner = THIS_MODULE,
1205 .name = "mpc52xx-psc",
1206 },
1207};
1208#endif /* !defined(CONFIG_PPC_MERGE) */
1209
1210
1211#if defined(CONFIG_PPC_MERGE)
1212/* ======================================================================== */ 1049/* ======================================================================== */
1213/* OF Platform Driver */ 1050/* OF Platform Driver */
1214/* ======================================================================== */ 1051/* ======================================================================== */
@@ -1402,7 +1239,6 @@ static struct of_platform_driver mpc52xx_uart_of_driver = {
1402 .name = "mpc52xx-psc-uart", 1239 .name = "mpc52xx-psc-uart",
1403 }, 1240 },
1404}; 1241};
1405#endif /* defined(CONFIG_PPC_MERGE) */
1406 1242
1407 1243
1408/* ======================================================================== */ 1244/* ======================================================================== */
@@ -1423,7 +1259,6 @@ mpc52xx_uart_init(void)
1423 return ret; 1259 return ret;
1424 } 1260 }
1425 1261
1426#if defined(CONFIG_PPC_MERGE)
1427 mpc52xx_uart_of_enumerate(); 1262 mpc52xx_uart_of_enumerate();
1428 1263
1429 ret = of_register_platform_driver(&mpc52xx_uart_of_driver); 1264 ret = of_register_platform_driver(&mpc52xx_uart_of_driver);
@@ -1433,16 +1268,6 @@ mpc52xx_uart_init(void)
1433 uart_unregister_driver(&mpc52xx_uart_driver); 1268 uart_unregister_driver(&mpc52xx_uart_driver);
1434 return ret; 1269 return ret;
1435 } 1270 }
1436#else
1437 psc_ops = &mpc52xx_psc_ops;
1438 ret = platform_driver_register(&mpc52xx_uart_platform_driver);
1439 if (ret) {
1440 printk(KERN_ERR "%s: platform_driver_register failed (%i)\n",
1441 __FILE__, ret);
1442 uart_unregister_driver(&mpc52xx_uart_driver);
1443 return ret;
1444 }
1445#endif
1446 1271
1447 return 0; 1272 return 0;
1448} 1273}
@@ -1450,11 +1275,7 @@ mpc52xx_uart_init(void)
1450static void __exit 1275static void __exit
1451mpc52xx_uart_exit(void) 1276mpc52xx_uart_exit(void)
1452{ 1277{
1453#if defined(CONFIG_PPC_MERGE)
1454 of_unregister_platform_driver(&mpc52xx_uart_of_driver); 1278 of_unregister_platform_driver(&mpc52xx_uart_of_driver);
1455#else
1456 platform_driver_unregister(&mpc52xx_uart_platform_driver);
1457#endif
1458 uart_unregister_driver(&mpc52xx_uart_driver); 1279 uart_unregister_driver(&mpc52xx_uart_driver);
1459} 1280}
1460 1281
diff --git a/drivers/serial/s3c2400.c b/drivers/serial/s3c2400.c
index c8b4266ac35f..4873f2978bd2 100644
--- a/drivers/serial/s3c2400.c
+++ b/drivers/serial/s3c2400.c
@@ -19,7 +19,7 @@
19 19
20#include <mach/hardware.h> 20#include <mach/hardware.h>
21 21
22#include <asm/plat-s3c/regs-serial.h> 22#include <plat/regs-serial.h>
23#include <mach/regs-gpio.h> 23#include <mach/regs-gpio.h>
24 24
25#include "samsung.h" 25#include "samsung.h"
diff --git a/drivers/serial/s3c2410.c b/drivers/serial/s3c2410.c
index 40a2531b5541..87c182ef71b8 100644
--- a/drivers/serial/s3c2410.c
+++ b/drivers/serial/s3c2410.c
@@ -21,7 +21,7 @@
21#include <asm/irq.h> 21#include <asm/irq.h>
22#include <mach/hardware.h> 22#include <mach/hardware.h>
23 23
24#include <asm/plat-s3c/regs-serial.h> 24#include <plat/regs-serial.h>
25#include <mach/regs-gpio.h> 25#include <mach/regs-gpio.h>
26 26
27#include "samsung.h" 27#include "samsung.h"
diff --git a/drivers/serial/s3c2412.c b/drivers/serial/s3c2412.c
index d0170319c729..fd017b375568 100644
--- a/drivers/serial/s3c2412.c
+++ b/drivers/serial/s3c2412.c
@@ -21,7 +21,7 @@
21#include <asm/irq.h> 21#include <asm/irq.h>
22#include <mach/hardware.h> 22#include <mach/hardware.h>
23 23
24#include <asm/plat-s3c/regs-serial.h> 24#include <plat/regs-serial.h>
25#include <mach/regs-gpio.h> 25#include <mach/regs-gpio.h>
26 26
27#include "samsung.h" 27#include "samsung.h"
diff --git a/drivers/serial/s3c2440.c b/drivers/serial/s3c2440.c
index d4a2b17b2498..317d239ab740 100644
--- a/drivers/serial/s3c2440.c
+++ b/drivers/serial/s3c2440.c
@@ -21,7 +21,7 @@
21#include <asm/irq.h> 21#include <asm/irq.h>
22#include <mach/hardware.h> 22#include <mach/hardware.h>
23 23
24#include <asm/plat-s3c/regs-serial.h> 24#include <plat/regs-serial.h>
25#include <mach/regs-gpio.h> 25#include <mach/regs-gpio.h>
26 26
27#include "samsung.h" 27#include "samsung.h"
diff --git a/drivers/serial/samsung.c b/drivers/serial/samsung.c
index 5a88b3f9fe9b..1e219d3d0352 100644
--- a/drivers/serial/samsung.c
+++ b/drivers/serial/samsung.c
@@ -47,7 +47,7 @@
47 47
48#include <mach/hardware.h> 48#include <mach/hardware.h>
49 49
50#include <asm/plat-s3c/regs-serial.h> 50#include <plat/regs-serial.h>
51#include <mach/regs-gpio.h> 51#include <mach/regs-gpio.h>
52 52
53#include "samsung.h" 53#include "samsung.h"
diff --git a/drivers/serial/serial_core.c b/drivers/serial/serial_core.c
index f977c98cfa95..6bdf3362e3b1 100644
--- a/drivers/serial/serial_core.c
+++ b/drivers/serial/serial_core.c
@@ -2051,7 +2051,8 @@ int uart_suspend_port(struct uart_driver *drv, struct uart_port *port)
2051 "transmitter\n", 2051 "transmitter\n",
2052 port->dev ? port->dev->bus_id : "", 2052 port->dev ? port->dev->bus_id : "",
2053 port->dev ? ": " : "", 2053 port->dev ? ": " : "",
2054 drv->dev_name, port->line); 2054 drv->dev_name,
2055 drv->tty_driver->name_base + port->line);
2055 2056
2056 ops->shutdown(port); 2057 ops->shutdown(port);
2057 } 2058 }
@@ -2154,12 +2155,11 @@ uart_report_port(struct uart_driver *drv, struct uart_port *port)
2154 2155
2155 switch (port->iotype) { 2156 switch (port->iotype) {
2156 case UPIO_PORT: 2157 case UPIO_PORT:
2157 snprintf(address, sizeof(address), 2158 snprintf(address, sizeof(address), "I/O 0x%lx", port->iobase);
2158 "I/O 0x%x", port->iobase);
2159 break; 2159 break;
2160 case UPIO_HUB6: 2160 case UPIO_HUB6:
2161 snprintf(address, sizeof(address), 2161 snprintf(address, sizeof(address),
2162 "I/O 0x%x offset 0x%x", port->iobase, port->hub6); 2162 "I/O 0x%lx offset 0x%x", port->iobase, port->hub6);
2163 break; 2163 break;
2164 case UPIO_MEM: 2164 case UPIO_MEM:
2165 case UPIO_MEM32: 2165 case UPIO_MEM32:
@@ -2177,7 +2177,9 @@ uart_report_port(struct uart_driver *drv, struct uart_port *port)
2177 printk(KERN_INFO "%s%s%s%d at %s (irq = %d) is a %s\n", 2177 printk(KERN_INFO "%s%s%s%d at %s (irq = %d) is a %s\n",
2178 port->dev ? port->dev->bus_id : "", 2178 port->dev ? port->dev->bus_id : "",
2179 port->dev ? ": " : "", 2179 port->dev ? ": " : "",
2180 drv->dev_name, port->line, address, port->irq, uart_type(port)); 2180 drv->dev_name,
2181 drv->tty_driver->name_base + port->line,
2182 address, port->irq, uart_type(port));
2181} 2183}
2182 2184
2183static void 2185static void
diff --git a/drivers/serial/serial_cs.c b/drivers/serial/serial_cs.c
index 164d2a42eb59..7546aa887fa7 100644
--- a/drivers/serial/serial_cs.c
+++ b/drivers/serial/serial_cs.c
@@ -431,131 +431,103 @@ first_tuple(struct pcmcia_device *handle, tuple_t * tuple, cisparse_t * parse)
431{ 431{
432 int i; 432 int i;
433 i = pcmcia_get_first_tuple(handle, tuple); 433 i = pcmcia_get_first_tuple(handle, tuple);
434 if (i != CS_SUCCESS) 434 if (i != 0)
435 return CS_NO_MORE_ITEMS;
436 i = pcmcia_get_tuple_data(handle, tuple);
437 if (i != CS_SUCCESS)
438 return i; 435 return i;
439 return pcmcia_parse_tuple(handle, tuple, parse);
440}
441
442static int
443next_tuple(struct pcmcia_device *handle, tuple_t * tuple, cisparse_t * parse)
444{
445 int i;
446 i = pcmcia_get_next_tuple(handle, tuple);
447 if (i != CS_SUCCESS)
448 return CS_NO_MORE_ITEMS;
449 i = pcmcia_get_tuple_data(handle, tuple); 436 i = pcmcia_get_tuple_data(handle, tuple);
450 if (i != CS_SUCCESS) 437 if (i != 0)
451 return i; 438 return i;
452 return pcmcia_parse_tuple(handle, tuple, parse); 439 return pcmcia_parse_tuple(tuple, parse);
453} 440}
454 441
455/*====================================================================*/ 442/*====================================================================*/
456 443
457static int simple_config(struct pcmcia_device *link) 444static int simple_config_check(struct pcmcia_device *p_dev,
445 cistpl_cftable_entry_t *cf,
446 cistpl_cftable_entry_t *dflt,
447 unsigned int vcc,
448 void *priv_data)
458{ 449{
459 static const unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
460 static const int size_table[2] = { 8, 16 }; 450 static const int size_table[2] = { 8, 16 };
461 struct serial_info *info = link->priv; 451 int *try = priv_data;
462 struct serial_cfg_mem *cfg_mem; 452
463 tuple_t *tuple; 453 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
464 u_char *buf; 454 p_dev->conf.Vpp =
465 cisparse_t *parse; 455 cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
466 cistpl_cftable_entry_t *cf; 456
467 config_info_t config; 457 if ((cf->io.nwin > 0) && (cf->io.win[0].len == size_table[(*try >> 1)])
468 int i, j, try; 458 && (cf->io.win[0].base != 0)) {
469 int s; 459 p_dev->io.BasePort1 = cf->io.win[0].base;
460 p_dev->io.IOAddrLines = ((*try & 0x1) == 0) ?
461 16 : cf->io.flags & CISTPL_IO_LINES_MASK;
462 if (!pcmcia_request_io(p_dev, &p_dev->io))
463 return 0;
464 }
465 return -EINVAL;
466}
470 467
471 cfg_mem = kmalloc(sizeof(struct serial_cfg_mem), GFP_KERNEL); 468static int simple_config_check_notpicky(struct pcmcia_device *p_dev,
472 if (!cfg_mem) 469 cistpl_cftable_entry_t *cf,
473 return -1; 470 cistpl_cftable_entry_t *dflt,
471 unsigned int vcc,
472 void *priv_data)
473{
474 static const unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
475 int j;
476
477 if ((cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
478 for (j = 0; j < 5; j++) {
479 p_dev->io.BasePort1 = base[j];
480 p_dev->io.IOAddrLines = base[j] ? 16 : 3;
481 if (!pcmcia_request_io(p_dev, &p_dev->io))
482 return 0;
483 }
484 }
485 return -ENODEV;
486}
474 487
475 tuple = &cfg_mem->tuple; 488static int simple_config(struct pcmcia_device *link)
476 parse = &cfg_mem->parse; 489{
477 cf = &parse->cftable_entry; 490 struct serial_info *info = link->priv;
478 buf = cfg_mem->buf; 491 int i = -ENODEV, try;
479 492
480 /* If the card is already configured, look up the port and irq */ 493 /* If the card is already configured, look up the port and irq */
481 i = pcmcia_get_configuration_info(link, &config); 494 if (link->function_config) {
482 if ((i == CS_SUCCESS) && (config.Attributes & CONF_VALID_CLIENT)) {
483 unsigned int port = 0; 495 unsigned int port = 0;
484 if ((config.BasePort2 != 0) && (config.NumPorts2 == 8)) { 496 if ((link->io.BasePort2 != 0) &&
485 port = config.BasePort2; 497 (link->io.NumPorts2 == 8)) {
498 port = link->io.BasePort2;
486 info->slave = 1; 499 info->slave = 1;
487 } else if ((info->manfid == MANFID_OSITECH) && 500 } else if ((info->manfid == MANFID_OSITECH) &&
488 (config.NumPorts1 == 0x40)) { 501 (link->io.NumPorts1 == 0x40)) {
489 port = config.BasePort1 + 0x28; 502 port = link->io.BasePort1 + 0x28;
490 info->slave = 1; 503 info->slave = 1;
491 } 504 }
492 if (info->slave) { 505 if (info->slave) {
493 kfree(cfg_mem); 506 return setup_serial(link, info, port,
494 return setup_serial(link, info, port, config.AssignedIRQ); 507 link->irq.AssignedIRQ);
495 } 508 }
496 } 509 }
497 510
498 /* First pass: look for a config entry that looks normal. */ 511 /* First pass: look for a config entry that looks normal.
499 tuple->TupleData = (cisdata_t *) buf; 512 * Two tries: without IO aliases, then with aliases */
500 tuple->TupleOffset = 0; 513 for (try = 0; try < 4; try++)
501 tuple->TupleDataMax = 255; 514 if (!pcmcia_loop_config(link, simple_config_check, &try))
502 tuple->Attributes = 0; 515 goto found_port;
503 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY; 516
504 /* Two tries: without IO aliases, then with aliases */
505 for (s = 0; s < 2; s++) {
506 for (try = 0; try < 2; try++) {
507 i = first_tuple(link, tuple, parse);
508 while (i != CS_NO_MORE_ITEMS) {
509 if (i != CS_SUCCESS)
510 goto next_entry;
511 if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
512 link->conf.Vpp =
513 cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
514 if ((cf->io.nwin > 0) && (cf->io.win[0].len == size_table[s]) &&
515 (cf->io.win[0].base != 0)) {
516 link->conf.ConfigIndex = cf->index;
517 link->io.BasePort1 = cf->io.win[0].base;
518 link->io.IOAddrLines = (try == 0) ?
519 16 : cf->io.flags & CISTPL_IO_LINES_MASK;
520 i = pcmcia_request_io(link, &link->io);
521 if (i == CS_SUCCESS)
522 goto found_port;
523 }
524next_entry:
525 i = next_tuple(link, tuple, parse);
526 }
527 }
528 }
529 /* Second pass: try to find an entry that isn't picky about 517 /* Second pass: try to find an entry that isn't picky about
530 its base address, then try to grab any standard serial port 518 its base address, then try to grab any standard serial port
531 address, and finally try to get any free port. */ 519 address, and finally try to get any free port. */
532 i = first_tuple(link, tuple, parse); 520 if (!pcmcia_loop_config(link, simple_config_check_notpicky, NULL))
533 while (i != CS_NO_MORE_ITEMS) { 521 goto found_port;
534 if ((i == CS_SUCCESS) && (cf->io.nwin > 0) &&
535 ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
536 link->conf.ConfigIndex = cf->index;
537 for (j = 0; j < 5; j++) {
538 link->io.BasePort1 = base[j];
539 link->io.IOAddrLines = base[j] ? 16 : 3;
540 i = pcmcia_request_io(link, &link->io);
541 if (i == CS_SUCCESS)
542 goto found_port;
543 }
544 }
545 i = next_tuple(link, tuple, parse);
546 }
547 522
548 found_port: 523 printk(KERN_NOTICE
549 if (i != CS_SUCCESS) { 524 "serial_cs: no usable port range found, giving up\n");
550 printk(KERN_NOTICE 525 cs_error(link, RequestIO, i);
551 "serial_cs: no usable port range found, giving up\n"); 526 return -1;
552 cs_error(link, RequestIO, i);
553 kfree(cfg_mem);
554 return -1;
555 }
556 527
528found_port:
557 i = pcmcia_request_irq(link, &link->irq); 529 i = pcmcia_request_irq(link, &link->irq);
558 if (i != CS_SUCCESS) { 530 if (i != 0) {
559 cs_error(link, RequestIRQ, i); 531 cs_error(link, RequestIRQ, i);
560 link->irq.AssignedIRQ = 0; 532 link->irq.AssignedIRQ = 0;
561 } 533 }
@@ -569,88 +541,76 @@ next_entry:
569 info->quirk->config(link); 541 info->quirk->config(link);
570 542
571 i = pcmcia_request_configuration(link, &link->conf); 543 i = pcmcia_request_configuration(link, &link->conf);
572 if (i != CS_SUCCESS) { 544 if (i != 0) {
573 cs_error(link, RequestConfiguration, i); 545 cs_error(link, RequestConfiguration, i);
574 kfree(cfg_mem);
575 return -1; 546 return -1;
576 } 547 }
577 kfree(cfg_mem);
578 return setup_serial(link, info, link->io.BasePort1, link->irq.AssignedIRQ); 548 return setup_serial(link, info, link->io.BasePort1, link->irq.AssignedIRQ);
579} 549}
580 550
581static int multi_config(struct pcmcia_device * link) 551static int multi_config_check(struct pcmcia_device *p_dev,
552 cistpl_cftable_entry_t *cf,
553 cistpl_cftable_entry_t *dflt,
554 unsigned int vcc,
555 void *priv_data)
582{ 556{
583 struct serial_info *info = link->priv; 557 int *base2 = priv_data;
584 struct serial_cfg_mem *cfg_mem; 558
585 tuple_t *tuple; 559 /* The quad port cards have bad CIS's, so just look for a
586 u_char *buf; 560 window larger than 8 ports and assume it will be right */
587 cisparse_t *parse; 561 if ((cf->io.nwin == 1) && (cf->io.win[0].len > 8)) {
588 cistpl_cftable_entry_t *cf; 562 p_dev->io.BasePort1 = cf->io.win[0].base;
589 int i, rc, base2 = 0; 563 p_dev->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
564 if (!pcmcia_request_io(p_dev, &p_dev->io)) {
565 *base2 = p_dev->io.BasePort1 + 8;
566 return 0;
567 }
568 }
569 return -ENODEV;
570}
590 571
591 cfg_mem = kmalloc(sizeof(struct serial_cfg_mem), GFP_KERNEL); 572static int multi_config_check_notpicky(struct pcmcia_device *p_dev,
592 if (!cfg_mem) 573 cistpl_cftable_entry_t *cf,
593 return -1; 574 cistpl_cftable_entry_t *dflt,
594 tuple = &cfg_mem->tuple; 575 unsigned int vcc,
595 parse = &cfg_mem->parse; 576 void *priv_data)
596 cf = &parse->cftable_entry; 577{
597 buf = cfg_mem->buf; 578 int *base2 = priv_data;
579
580 if (cf->io.nwin == 2) {
581 p_dev->io.BasePort1 = cf->io.win[0].base;
582 p_dev->io.BasePort2 = cf->io.win[1].base;
583 p_dev->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
584 if (!pcmcia_request_io(p_dev, &p_dev->io)) {
585 *base2 = p_dev->io.BasePort2;
586 return 0;
587 }
588 }
589 return -ENODEV;
590}
598 591
599 tuple->TupleData = (cisdata_t *) buf; 592static int multi_config(struct pcmcia_device *link)
600 tuple->TupleOffset = 0; 593{
601 tuple->TupleDataMax = 255; 594 struct serial_info *info = link->priv;
602 tuple->Attributes = 0; 595 int i, base2 = 0;
603 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
604 596
605 /* First, look for a generic full-sized window */ 597 /* First, look for a generic full-sized window */
606 link->io.NumPorts1 = info->multi * 8; 598 link->io.NumPorts1 = info->multi * 8;
607 i = first_tuple(link, tuple, parse); 599 if (pcmcia_loop_config(link, multi_config_check, &base2)) {
608 while (i != CS_NO_MORE_ITEMS) { 600 /* If that didn't work, look for two windows */
609 /* The quad port cards have bad CIS's, so just look for a
610 window larger than 8 ports and assume it will be right */
611 if ((i == CS_SUCCESS) && (cf->io.nwin == 1) &&
612 (cf->io.win[0].len > 8)) {
613 link->conf.ConfigIndex = cf->index;
614 link->io.BasePort1 = cf->io.win[0].base;
615 link->io.IOAddrLines =
616 cf->io.flags & CISTPL_IO_LINES_MASK;
617 i = pcmcia_request_io(link, &link->io);
618 base2 = link->io.BasePort1 + 8;
619 if (i == CS_SUCCESS)
620 break;
621 }
622 i = next_tuple(link, tuple, parse);
623 }
624
625 /* If that didn't work, look for two windows */
626 if (i != CS_SUCCESS) {
627 link->io.NumPorts1 = link->io.NumPorts2 = 8; 601 link->io.NumPorts1 = link->io.NumPorts2 = 8;
628 info->multi = 2; 602 info->multi = 2;
629 i = first_tuple(link, tuple, parse); 603 if (pcmcia_loop_config(link, multi_config_check_notpicky,
630 while (i != CS_NO_MORE_ITEMS) { 604 &base2)) {
631 if ((i == CS_SUCCESS) && (cf->io.nwin == 2)) { 605 printk(KERN_NOTICE "serial_cs: no usable port range"
632 link->conf.ConfigIndex = cf->index; 606 "found, giving up\n");
633 link->io.BasePort1 = cf->io.win[0].base; 607 return -ENODEV;
634 link->io.BasePort2 = cf->io.win[1].base;
635 link->io.IOAddrLines =
636 cf->io.flags & CISTPL_IO_LINES_MASK;
637 i = pcmcia_request_io(link, &link->io);
638 base2 = link->io.BasePort2;
639 if (i == CS_SUCCESS)
640 break;
641 }
642 i = next_tuple(link, tuple, parse);
643 } 608 }
644 } 609 }
645 610
646 if (i != CS_SUCCESS) {
647 cs_error(link, RequestIO, i);
648 rc = -1;
649 goto free_cfg_mem;
650 }
651
652 i = pcmcia_request_irq(link, &link->irq); 611 i = pcmcia_request_irq(link, &link->irq);
653 if (i != CS_SUCCESS) { 612 if (i != 0) {
613 /* FIXME: comment does not fit, error handling does not fit */
654 printk(KERN_NOTICE 614 printk(KERN_NOTICE
655 "serial_cs: no usable port range found, giving up\n"); 615 "serial_cs: no usable port range found, giving up\n");
656 cs_error(link, RequestIRQ, i); 616 cs_error(link, RequestIRQ, i);
@@ -664,10 +624,9 @@ static int multi_config(struct pcmcia_device * link)
664 info->quirk->config(link); 624 info->quirk->config(link);
665 625
666 i = pcmcia_request_configuration(link, &link->conf); 626 i = pcmcia_request_configuration(link, &link->conf);
667 if (i != CS_SUCCESS) { 627 if (i != 0) {
668 cs_error(link, RequestConfiguration, i); 628 cs_error(link, RequestConfiguration, i);
669 rc = -1; 629 return -ENODEV;
670 goto free_cfg_mem;
671 } 630 }
672 631
673 /* The Oxford Semiconductor OXCF950 cards are in fact single-port: 632 /* The Oxford Semiconductor OXCF950 cards are in fact single-port:
@@ -678,7 +637,8 @@ static int multi_config(struct pcmcia_device * link)
678 info->prodid == PRODID_POSSIO_GCC)) { 637 info->prodid == PRODID_POSSIO_GCC)) {
679 int err; 638 int err;
680 639
681 if (cf->index == 1 || cf->index == 3) { 640 if (link->conf.ConfigIndex == 1 ||
641 link->conf.ConfigIndex == 3) {
682 err = setup_serial(link, info, base2, 642 err = setup_serial(link, info, base2,
683 link->irq.AssignedIRQ); 643 link->irq.AssignedIRQ);
684 base2 = link->io.BasePort1; 644 base2 = link->io.BasePort1;
@@ -695,18 +655,14 @@ static int multi_config(struct pcmcia_device * link)
695 if (info->quirk && info->quirk->wakeup) 655 if (info->quirk && info->quirk->wakeup)
696 info->quirk->wakeup(link); 656 info->quirk->wakeup(link);
697 657
698 rc = 0; 658 return 0;
699 goto free_cfg_mem;
700 } 659 }
701 660
702 setup_serial(link, info, link->io.BasePort1, link->irq.AssignedIRQ); 661 setup_serial(link, info, link->io.BasePort1, link->irq.AssignedIRQ);
703 for (i = 0; i < info->multi - 1; i++) 662 for (i = 0; i < info->multi - 1; i++)
704 setup_serial(link, info, base2 + (8 * i), 663 setup_serial(link, info, base2 + (8 * i),
705 link->irq.AssignedIRQ); 664 link->irq.AssignedIRQ);
706 rc = 0; 665 return 0;
707free_cfg_mem:
708 kfree(cfg_mem);
709 return rc;
710} 666}
711 667
712/*====================================================================== 668/*======================================================================
@@ -746,7 +702,7 @@ static int serial_config(struct pcmcia_device * link)
746 /* Is this a compliant multifunction card? */ 702 /* Is this a compliant multifunction card? */
747 tuple->DesiredTuple = CISTPL_LONGLINK_MFC; 703 tuple->DesiredTuple = CISTPL_LONGLINK_MFC;
748 tuple->Attributes = TUPLE_RETURN_COMMON | TUPLE_RETURN_LINK; 704 tuple->Attributes = TUPLE_RETURN_COMMON | TUPLE_RETURN_LINK;
749 info->multi = (first_tuple(link, tuple, parse) == CS_SUCCESS); 705 info->multi = (first_tuple(link, tuple, parse) == 0);
750 706
751 /* Is this a multiport card? */ 707 /* Is this a multiport card? */
752 tuple->DesiredTuple = CISTPL_MANFID; 708 tuple->DesiredTuple = CISTPL_MANFID;
@@ -770,7 +726,7 @@ static int serial_config(struct pcmcia_device * link)
770 ((link->func_id == CISTPL_FUNCID_MULTI) || 726 ((link->func_id == CISTPL_FUNCID_MULTI) ||
771 (link->func_id == CISTPL_FUNCID_SERIAL))) { 727 (link->func_id == CISTPL_FUNCID_SERIAL))) {
772 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY; 728 tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
773 if (first_tuple(link, tuple, parse) == CS_SUCCESS) { 729 if (first_tuple(link, tuple, parse) == 0) {
774 if ((cf->io.nwin == 1) && (cf->io.win[0].len % 8 == 0)) 730 if ((cf->io.nwin == 1) && (cf->io.win[0].len % 8 == 0))
775 info->multi = cf->io.win[0].len >> 3; 731 info->multi = cf->io.win[0].len >> 3;
776 if ((cf->io.nwin == 2) && (cf->io.win[0].len == 8) && 732 if ((cf->io.nwin == 2) && (cf->io.win[0].len == 8) &&
diff --git a/drivers/serial/ucc_uart.c b/drivers/serial/ucc_uart.c
index 5c5d18dcb6ac..539c933b335f 100644
--- a/drivers/serial/ucc_uart.c
+++ b/drivers/serial/ucc_uart.c
@@ -1009,7 +1009,7 @@ static int qe_uart_request_port(struct uart_port *port)
1009 rx_size = L1_CACHE_ALIGN(qe_port->rx_nrfifos * qe_port->rx_fifosize); 1009 rx_size = L1_CACHE_ALIGN(qe_port->rx_nrfifos * qe_port->rx_fifosize);
1010 tx_size = L1_CACHE_ALIGN(qe_port->tx_nrfifos * qe_port->tx_fifosize); 1010 tx_size = L1_CACHE_ALIGN(qe_port->tx_nrfifos * qe_port->tx_fifosize);
1011 1011
1012 bd_virt = dma_alloc_coherent(NULL, rx_size + tx_size, &bd_dma_addr, 1012 bd_virt = dma_alloc_coherent(port->dev, rx_size + tx_size, &bd_dma_addr,
1013 GFP_KERNEL); 1013 GFP_KERNEL);
1014 if (!bd_virt) { 1014 if (!bd_virt) {
1015 dev_err(port->dev, "could not allocate buffer descriptors\n"); 1015 dev_err(port->dev, "could not allocate buffer descriptors\n");
@@ -1051,7 +1051,7 @@ static void qe_uart_release_port(struct uart_port *port)
1051 container_of(port, struct uart_qe_port, port); 1051 container_of(port, struct uart_qe_port, port);
1052 struct ucc_slow_private *uccs = qe_port->us_private; 1052 struct ucc_slow_private *uccs = qe_port->us_private;
1053 1053
1054 dma_free_coherent(NULL, qe_port->bd_size, qe_port->bd_virt, 1054 dma_free_coherent(port->dev, qe_port->bd_size, qe_port->bd_virt,
1055 qe_port->bd_dma_addr); 1055 qe_port->bd_dma_addr);
1056 1056
1057 ucc_slow_free(uccs); 1057 ucc_slow_free(uccs);
diff --git a/drivers/spi/mpc52xx_psc_spi.c b/drivers/spi/mpc52xx_psc_spi.c
index 25eda71f4bf4..0debe11b67b4 100644
--- a/drivers/spi/mpc52xx_psc_spi.c
+++ b/drivers/spi/mpc52xx_psc_spi.c
@@ -15,13 +15,7 @@
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/errno.h> 16#include <linux/errno.h>
17#include <linux/interrupt.h> 17#include <linux/interrupt.h>
18
19#if defined(CONFIG_PPC_MERGE)
20#include <linux/of_platform.h> 18#include <linux/of_platform.h>
21#else
22#include <linux/platform_device.h>
23#endif
24
25#include <linux/workqueue.h> 19#include <linux/workqueue.h>
26#include <linux/completion.h> 20#include <linux/completion.h>
27#include <linux/io.h> 21#include <linux/io.h>
@@ -108,13 +102,13 @@ static void mpc52xx_psc_spi_activate_cs(struct spi_device *spi)
108 * Because psc->ccr is defined as 16bit register instead of 32bit 102 * Because psc->ccr is defined as 16bit register instead of 32bit
109 * just set the lower byte of BitClkDiv 103 * just set the lower byte of BitClkDiv
110 */ 104 */
111 ccr = in_be16(&psc->ccr); 105 ccr = in_be16((u16 __iomem *)&psc->ccr);
112 ccr &= 0xFF00; 106 ccr &= 0xFF00;
113 if (cs->speed_hz) 107 if (cs->speed_hz)
114 ccr |= (MCLK / cs->speed_hz - 1) & 0xFF; 108 ccr |= (MCLK / cs->speed_hz - 1) & 0xFF;
115 else /* by default SPI Clk 1MHz */ 109 else /* by default SPI Clk 1MHz */
116 ccr |= (MCLK / 1000000 - 1) & 0xFF; 110 ccr |= (MCLK / 1000000 - 1) & 0xFF;
117 out_be16(&psc->ccr, ccr); 111 out_be16((u16 __iomem *)&psc->ccr, ccr);
118 mps->bits_per_word = cs->bits_per_word; 112 mps->bits_per_word = cs->bits_per_word;
119 113
120 if (mps->activate_cs) 114 if (mps->activate_cs)
@@ -347,7 +341,7 @@ static int mpc52xx_psc_spi_port_config(int psc_id, struct mpc52xx_psc_spi *mps)
347 /* Configure 8bit codec mode as a SPI master and use EOF flags */ 341 /* Configure 8bit codec mode as a SPI master and use EOF flags */
348 /* SICR_SIM_CODEC8|SICR_GENCLK|SICR_SPI|SICR_MSTR|SICR_USEEOF */ 342 /* SICR_SIM_CODEC8|SICR_GENCLK|SICR_SPI|SICR_MSTR|SICR_USEEOF */
349 out_be32(&psc->sicr, 0x0180C800); 343 out_be32(&psc->sicr, 0x0180C800);
350 out_be16(&psc->ccr, 0x070F); /* by default SPI Clk 1MHz */ 344 out_be16((u16 __iomem *)&psc->ccr, 0x070F); /* default SPI Clk 1MHz */
351 345
352 /* Set 2ms DTL delay */ 346 /* Set 2ms DTL delay */
353 out_8(&psc->ctur, 0x00); 347 out_8(&psc->ctur, 0x00);
@@ -471,53 +465,6 @@ static int __exit mpc52xx_psc_spi_do_remove(struct device *dev)
471 return 0; 465 return 0;
472} 466}
473 467
474#if !defined(CONFIG_PPC_MERGE)
475static int __init mpc52xx_psc_spi_probe(struct platform_device *dev)
476{
477 switch(dev->id) {
478 case 1:
479 case 2:
480 case 3:
481 case 6:
482 return mpc52xx_psc_spi_do_probe(&dev->dev,
483 MPC52xx_PA(MPC52xx_PSCx_OFFSET(dev->id)),
484 MPC52xx_PSC_SIZE, platform_get_irq(dev, 0), dev->id);
485 default:
486 return -EINVAL;
487 }
488}
489
490static int __exit mpc52xx_psc_spi_remove(struct platform_device *dev)
491{
492 return mpc52xx_psc_spi_do_remove(&dev->dev);
493}
494
495/* work with hotplug and coldplug */
496MODULE_ALIAS("platform:mpc52xx-psc-spi");
497
498static struct platform_driver mpc52xx_psc_spi_platform_driver = {
499 .remove = __exit_p(mpc52xx_psc_spi_remove),
500 .driver = {
501 .name = "mpc52xx-psc-spi",
502 .owner = THIS_MODULE,
503 },
504};
505
506static int __init mpc52xx_psc_spi_init(void)
507{
508 return platform_driver_probe(&mpc52xx_psc_spi_platform_driver,
509 mpc52xx_psc_spi_probe);
510}
511module_init(mpc52xx_psc_spi_init);
512
513static void __exit mpc52xx_psc_spi_exit(void)
514{
515 platform_driver_unregister(&mpc52xx_psc_spi_platform_driver);
516}
517module_exit(mpc52xx_psc_spi_exit);
518
519#else /* defined(CONFIG_PPC_MERGE) */
520
521static int __init mpc52xx_psc_spi_of_probe(struct of_device *op, 468static int __init mpc52xx_psc_spi_of_probe(struct of_device *op,
522 const struct of_device_id *match) 469 const struct of_device_id *match)
523{ 470{
@@ -586,8 +533,6 @@ static void __exit mpc52xx_psc_spi_exit(void)
586} 533}
587module_exit(mpc52xx_psc_spi_exit); 534module_exit(mpc52xx_psc_spi_exit);
588 535
589#endif /* defined(CONFIG_PPC_MERGE) */
590
591MODULE_AUTHOR("Dragos Carp"); 536MODULE_AUTHOR("Dragos Carp");
592MODULE_DESCRIPTION("MPC52xx PSC SPI Driver"); 537MODULE_DESCRIPTION("MPC52xx PSC SPI Driver");
593MODULE_LICENSE("GPL"); 538MODULE_LICENSE("GPL");
diff --git a/drivers/spi/omap2_mcspi.c b/drivers/spi/omap2_mcspi.c
index 9d2186fd74aa..454a2712e629 100644
--- a/drivers/spi/omap2_mcspi.c
+++ b/drivers/spi/omap2_mcspi.c
@@ -119,12 +119,14 @@ struct omap2_mcspi {
119 struct clk *fck; 119 struct clk *fck;
120 /* Virtual base address of the controller */ 120 /* Virtual base address of the controller */
121 void __iomem *base; 121 void __iomem *base;
122 unsigned long phys;
122 /* SPI1 has 4 channels, while SPI2 has 2 */ 123 /* SPI1 has 4 channels, while SPI2 has 2 */
123 struct omap2_mcspi_dma *dma_channels; 124 struct omap2_mcspi_dma *dma_channels;
124}; 125};
125 126
126struct omap2_mcspi_cs { 127struct omap2_mcspi_cs {
127 void __iomem *base; 128 void __iomem *base;
129 unsigned long phys;
128 int word_len; 130 int word_len;
129}; 131};
130 132
@@ -233,7 +235,7 @@ omap2_mcspi_txrx_dma(struct spi_device *spi, struct spi_transfer *xfer)
233 c = count; 235 c = count;
234 word_len = cs->word_len; 236 word_len = cs->word_len;
235 237
236 base = (unsigned long) io_v2p(cs->base); 238 base = cs->phys;
237 tx_reg = base + OMAP2_MCSPI_TX0; 239 tx_reg = base + OMAP2_MCSPI_TX0;
238 rx_reg = base + OMAP2_MCSPI_RX0; 240 rx_reg = base + OMAP2_MCSPI_RX0;
239 rx = xfer->rx_buf; 241 rx = xfer->rx_buf;
@@ -633,6 +635,7 @@ static int omap2_mcspi_setup(struct spi_device *spi)
633 if (!cs) 635 if (!cs)
634 return -ENOMEM; 636 return -ENOMEM;
635 cs->base = mcspi->base + spi->chip_select * 0x14; 637 cs->base = mcspi->base + spi->chip_select * 0x14;
638 cs->phys = mcspi->phys + spi->chip_select * 0x14;
636 spi->controller_state = cs; 639 spi->controller_state = cs;
637 } 640 }
638 641
@@ -1005,7 +1008,13 @@ static int __init omap2_mcspi_probe(struct platform_device *pdev)
1005 goto err1; 1008 goto err1;
1006 } 1009 }
1007 1010
1008 mcspi->base = (void __iomem *) io_p2v(r->start); 1011 mcspi->phys = r->start;
1012 mcspi->base = ioremap(r->start, r->end - r->start + 1);
1013 if (!mcspi->base) {
1014 dev_dbg(&pdev->dev, "can't ioremap MCSPI\n");
1015 status = -ENOMEM;
1016 goto err1aa;
1017 }
1009 1018
1010 INIT_WORK(&mcspi->work, omap2_mcspi_work); 1019 INIT_WORK(&mcspi->work, omap2_mcspi_work);
1011 1020
@@ -1055,6 +1064,8 @@ err3:
1055err2: 1064err2:
1056 clk_put(mcspi->ick); 1065 clk_put(mcspi->ick);
1057err1a: 1066err1a:
1067 iounmap(mcspi->base);
1068err1aa:
1058 release_mem_region(r->start, (r->end - r->start) + 1); 1069 release_mem_region(r->start, (r->end - r->start) + 1);
1059err1: 1070err1:
1060 spi_master_put(master); 1071 spi_master_put(master);
@@ -1067,6 +1078,7 @@ static int __exit omap2_mcspi_remove(struct platform_device *pdev)
1067 struct omap2_mcspi *mcspi; 1078 struct omap2_mcspi *mcspi;
1068 struct omap2_mcspi_dma *dma_channels; 1079 struct omap2_mcspi_dma *dma_channels;
1069 struct resource *r; 1080 struct resource *r;
1081 void __iomem *base;
1070 1082
1071 master = dev_get_drvdata(&pdev->dev); 1083 master = dev_get_drvdata(&pdev->dev);
1072 mcspi = spi_master_get_devdata(master); 1084 mcspi = spi_master_get_devdata(master);
@@ -1078,7 +1090,9 @@ static int __exit omap2_mcspi_remove(struct platform_device *pdev)
1078 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1090 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1079 release_mem_region(r->start, (r->end - r->start) + 1); 1091 release_mem_region(r->start, (r->end - r->start) + 1);
1080 1092
1093 base = mcspi->base;
1081 spi_unregister_master(master); 1094 spi_unregister_master(master);
1095 iounmap(base);
1082 kfree(dma_channels); 1096 kfree(dma_channels);
1083 1097
1084 return 0; 1098 return 0;
diff --git a/drivers/spi/omap_uwire.c b/drivers/spi/omap_uwire.c
index 5515eb97d7c5..bab6ff061e91 100644
--- a/drivers/spi/omap_uwire.c
+++ b/drivers/spi/omap_uwire.c
@@ -59,7 +59,6 @@
59 * and irqs should show there too... 59 * and irqs should show there too...
60 */ 60 */
61#define UWIRE_BASE_PHYS 0xFFFB3000 61#define UWIRE_BASE_PHYS 0xFFFB3000
62#define UWIRE_BASE ((void *__iomem)IO_ADDRESS(UWIRE_BASE_PHYS))
63 62
64/* uWire Registers: */ 63/* uWire Registers: */
65#define UWIRE_IO_SIZE 0x20 64#define UWIRE_IO_SIZE 0x20
@@ -103,16 +102,21 @@ struct uwire_state {
103}; 102};
104 103
105/* REVISIT compile time constant for idx_shift? */ 104/* REVISIT compile time constant for idx_shift? */
105/*
106 * Or, put it in a structure which is used throughout the driver;
107 * that avoids having to issue two loads for each bit of static data.
108 */
106static unsigned int uwire_idx_shift; 109static unsigned int uwire_idx_shift;
110static void __iomem *uwire_base;
107 111
108static inline void uwire_write_reg(int idx, u16 val) 112static inline void uwire_write_reg(int idx, u16 val)
109{ 113{
110 __raw_writew(val, UWIRE_BASE + (idx << uwire_idx_shift)); 114 __raw_writew(val, uwire_base + (idx << uwire_idx_shift));
111} 115}
112 116
113static inline u16 uwire_read_reg(int idx) 117static inline u16 uwire_read_reg(int idx)
114{ 118{
115 return __raw_readw(UWIRE_BASE + (idx << uwire_idx_shift)); 119 return __raw_readw(uwire_base + (idx << uwire_idx_shift));
116} 120}
117 121
118static inline void omap_uwire_configure_mode(u8 cs, unsigned long flags) 122static inline void omap_uwire_configure_mode(u8 cs, unsigned long flags)
@@ -492,6 +496,14 @@ static int __init uwire_probe(struct platform_device *pdev)
492 return -ENODEV; 496 return -ENODEV;
493 497
494 uwire = spi_master_get_devdata(master); 498 uwire = spi_master_get_devdata(master);
499
500 uwire_base = ioremap(UWIRE_BASE_PHYS, UWIRE_IO_SIZE);
501 if (!uwire_base) {
502 dev_dbg(&pdev->dev, "can't ioremap UWIRE\n");
503 spi_master_put(master);
504 return -ENOMEM;
505 }
506
495 dev_set_drvdata(&pdev->dev, uwire); 507 dev_set_drvdata(&pdev->dev, uwire);
496 508
497 uwire->ck = clk_get(&pdev->dev, "armxor_ck"); 509 uwire->ck = clk_get(&pdev->dev, "armxor_ck");
@@ -520,8 +532,10 @@ static int __init uwire_probe(struct platform_device *pdev)
520 uwire->bitbang.txrx_bufs = uwire_txrx; 532 uwire->bitbang.txrx_bufs = uwire_txrx;
521 533
522 status = spi_bitbang_start(&uwire->bitbang); 534 status = spi_bitbang_start(&uwire->bitbang);
523 if (status < 0) 535 if (status < 0) {
524 uwire_off(uwire); 536 uwire_off(uwire);
537 iounmap(uwire_base);
538 }
525 return status; 539 return status;
526} 540}
527 541
@@ -534,6 +548,7 @@ static int __exit uwire_remove(struct platform_device *pdev)
534 548
535 status = spi_bitbang_stop(&uwire->bitbang); 549 status = spi_bitbang_stop(&uwire->bitbang);
536 uwire_off(uwire); 550 uwire_off(uwire);
551 iounmap(uwire_base);
537 return status; 552 return status;
538} 553}
539 554
diff --git a/drivers/spi/orion_spi.c b/drivers/spi/orion_spi.c
index b872bfaf4bd2..014becb7d530 100644
--- a/drivers/spi/orion_spi.c
+++ b/drivers/spi/orion_spi.c
@@ -364,6 +364,11 @@ static int orion_spi_setup(struct spi_device *spi)
364 return -EINVAL; 364 return -EINVAL;
365 } 365 }
366 366
367 /* Fix ac timing if required. */
368 if (orion_spi->spi_info->enable_clock_fix)
369 orion_spi_setbits(orion_spi, ORION_SPI_IF_CONFIG_REG,
370 (1 << 14));
371
367 if (spi->bits_per_word == 0) 372 if (spi->bits_per_word == 0)
368 spi->bits_per_word = 8; 373 spi->bits_per_word = 8;
369 374
diff --git a/drivers/spi/pxa2xx_spi.c b/drivers/spi/pxa2xx_spi.c
index d47d3636227f..dae87b1a4c6e 100644
--- a/drivers/spi/pxa2xx_spi.c
+++ b/drivers/spi/pxa2xx_spi.c
@@ -47,6 +47,10 @@ MODULE_ALIAS("platform:pxa2xx-spi");
47 47
48#define MAX_BUSES 3 48#define MAX_BUSES 3
49 49
50#define RX_THRESH_DFLT 8
51#define TX_THRESH_DFLT 8
52#define TIMOUT_DFLT 1000
53
50#define DMA_INT_MASK (DCSR_ENDINTR | DCSR_STARTINTR | DCSR_BUSERR) 54#define DMA_INT_MASK (DCSR_ENDINTR | DCSR_STARTINTR | DCSR_BUSERR)
51#define RESET_DMA_CHANNEL (DCSR_NODESC | DMA_INT_MASK) 55#define RESET_DMA_CHANNEL (DCSR_NODESC | DMA_INT_MASK)
52#define IS_DMA_ALIGNED(x) ((((u32)(x)) & 0x07) == 0) 56#define IS_DMA_ALIGNED(x) ((((u32)(x)) & 0x07) == 0)
@@ -1171,6 +1175,8 @@ static int setup(struct spi_device *spi)
1171 struct driver_data *drv_data = spi_master_get_devdata(spi->master); 1175 struct driver_data *drv_data = spi_master_get_devdata(spi->master);
1172 struct ssp_device *ssp = drv_data->ssp; 1176 struct ssp_device *ssp = drv_data->ssp;
1173 unsigned int clk_div; 1177 unsigned int clk_div;
1178 uint tx_thres = TX_THRESH_DFLT;
1179 uint rx_thres = RX_THRESH_DFLT;
1174 1180
1175 if (!spi->bits_per_word) 1181 if (!spi->bits_per_word)
1176 spi->bits_per_word = 8; 1182 spi->bits_per_word = 8;
@@ -1209,8 +1215,7 @@ static int setup(struct spi_device *spi)
1209 1215
1210 chip->cs_control = null_cs_control; 1216 chip->cs_control = null_cs_control;
1211 chip->enable_dma = 0; 1217 chip->enable_dma = 0;
1212 chip->timeout = 1000; 1218 chip->timeout = TIMOUT_DFLT;
1213 chip->threshold = SSCR1_RxTresh(1) | SSCR1_TxTresh(1);
1214 chip->dma_burst_size = drv_data->master_info->enable_dma ? 1219 chip->dma_burst_size = drv_data->master_info->enable_dma ?
1215 DCMD_BURST8 : 0; 1220 DCMD_BURST8 : 0;
1216 } 1221 }
@@ -1224,22 +1229,21 @@ static int setup(struct spi_device *spi)
1224 if (chip_info) { 1229 if (chip_info) {
1225 if (chip_info->cs_control) 1230 if (chip_info->cs_control)
1226 chip->cs_control = chip_info->cs_control; 1231 chip->cs_control = chip_info->cs_control;
1227 1232 if (chip_info->timeout)
1228 chip->timeout = chip_info->timeout; 1233 chip->timeout = chip_info->timeout;
1229 1234 if (chip_info->tx_threshold)
1230 chip->threshold = (SSCR1_RxTresh(chip_info->rx_threshold) & 1235 tx_thres = chip_info->tx_threshold;
1231 SSCR1_RFT) | 1236 if (chip_info->rx_threshold)
1232 (SSCR1_TxTresh(chip_info->tx_threshold) & 1237 rx_thres = chip_info->rx_threshold;
1233 SSCR1_TFT); 1238 chip->enable_dma = drv_data->master_info->enable_dma;
1234
1235 chip->enable_dma = chip_info->dma_burst_size != 0
1236 && drv_data->master_info->enable_dma;
1237 chip->dma_threshold = 0; 1239 chip->dma_threshold = 0;
1238
1239 if (chip_info->enable_loopback) 1240 if (chip_info->enable_loopback)
1240 chip->cr1 = SSCR1_LBM; 1241 chip->cr1 = SSCR1_LBM;
1241 } 1242 }
1242 1243
1244 chip->threshold = (SSCR1_RxTresh(rx_thres) & SSCR1_RFT) |
1245 (SSCR1_TxTresh(tx_thres) & SSCR1_TFT);
1246
1243 /* set dma burst and threshold outside of chip_info path so that if 1247 /* set dma burst and threshold outside of chip_info path so that if
1244 * chip_info goes away after setting chip->enable_dma, the 1248 * chip_info goes away after setting chip->enable_dma, the
1245 * burst and threshold can still respond to changes in bits_per_word */ 1249 * burst and threshold can still respond to changes in bits_per_word */
@@ -1268,17 +1272,19 @@ static int setup(struct spi_device *spi)
1268 1272
1269 /* NOTE: PXA25x_SSP _could_ use external clocking ... */ 1273 /* NOTE: PXA25x_SSP _could_ use external clocking ... */
1270 if (drv_data->ssp_type != PXA25x_SSP) 1274 if (drv_data->ssp_type != PXA25x_SSP)
1271 dev_dbg(&spi->dev, "%d bits/word, %ld Hz, mode %d\n", 1275 dev_dbg(&spi->dev, "%d bits/word, %ld Hz, mode %d, %s\n",
1272 spi->bits_per_word, 1276 spi->bits_per_word,
1273 clk_get_rate(ssp->clk) 1277 clk_get_rate(ssp->clk)
1274 / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)), 1278 / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)),
1275 spi->mode & 0x3); 1279 spi->mode & 0x3,
1280 chip->enable_dma ? "DMA" : "PIO");
1276 else 1281 else
1277 dev_dbg(&spi->dev, "%d bits/word, %ld Hz, mode %d\n", 1282 dev_dbg(&spi->dev, "%d bits/word, %ld Hz, mode %d, %s\n",
1278 spi->bits_per_word, 1283 spi->bits_per_word,
1279 clk_get_rate(ssp->clk) 1284 clk_get_rate(ssp->clk) / 2
1280 / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)), 1285 / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)),
1281 spi->mode & 0x3); 1286 spi->mode & 0x3,
1287 chip->enable_dma ? "DMA" : "PIO");
1282 1288
1283 if (spi->bits_per_word <= 8) { 1289 if (spi->bits_per_word <= 8) {
1284 chip->n_bytes = 1; 1290 chip->n_bytes = 1;
@@ -1407,9 +1413,9 @@ static int __init pxa2xx_spi_probe(struct platform_device *pdev)
1407 struct device *dev = &pdev->dev; 1413 struct device *dev = &pdev->dev;
1408 struct pxa2xx_spi_master *platform_info; 1414 struct pxa2xx_spi_master *platform_info;
1409 struct spi_master *master; 1415 struct spi_master *master;
1410 struct driver_data *drv_data = NULL; 1416 struct driver_data *drv_data;
1411 struct ssp_device *ssp; 1417 struct ssp_device *ssp;
1412 int status = 0; 1418 int status;
1413 1419
1414 platform_info = dev->platform_data; 1420 platform_info = dev->platform_data;
1415 1421
@@ -1422,7 +1428,7 @@ static int __init pxa2xx_spi_probe(struct platform_device *pdev)
1422 /* Allocate master with space for drv_data and null dma buffer */ 1428 /* Allocate master with space for drv_data and null dma buffer */
1423 master = spi_alloc_master(dev, sizeof(struct driver_data) + 16); 1429 master = spi_alloc_master(dev, sizeof(struct driver_data) + 16);
1424 if (!master) { 1430 if (!master) {
1425 dev_err(&pdev->dev, "can not alloc spi_master\n"); 1431 dev_err(&pdev->dev, "cannot alloc spi_master\n");
1426 ssp_free(ssp); 1432 ssp_free(ssp);
1427 return -ENOMEM; 1433 return -ENOMEM;
1428 } 1434 }
@@ -1458,7 +1464,7 @@ static int __init pxa2xx_spi_probe(struct platform_device *pdev)
1458 1464
1459 status = request_irq(ssp->irq, ssp_int, 0, dev->bus_id, drv_data); 1465 status = request_irq(ssp->irq, ssp_int, 0, dev->bus_id, drv_data);
1460 if (status < 0) { 1466 if (status < 0) {
1461 dev_err(&pdev->dev, "can not get IRQ\n"); 1467 dev_err(&pdev->dev, "cannot get IRQ %d\n", ssp->irq);
1462 goto out_error_master_alloc; 1468 goto out_error_master_alloc;
1463 } 1469 }
1464 1470
@@ -1498,7 +1504,9 @@ static int __init pxa2xx_spi_probe(struct platform_device *pdev)
1498 1504
1499 /* Load default SSP configuration */ 1505 /* Load default SSP configuration */
1500 write_SSCR0(0, drv_data->ioaddr); 1506 write_SSCR0(0, drv_data->ioaddr);
1501 write_SSCR1(SSCR1_RxTresh(4) | SSCR1_TxTresh(12), drv_data->ioaddr); 1507 write_SSCR1(SSCR1_RxTresh(RX_THRESH_DFLT) |
1508 SSCR1_TxTresh(TX_THRESH_DFLT),
1509 drv_data->ioaddr);
1502 write_SSCR0(SSCR0_SerClkDiv(2) 1510 write_SSCR0(SSCR0_SerClkDiv(2)
1503 | SSCR0_Motorola 1511 | SSCR0_Motorola
1504 | SSCR0_DataSize(8), 1512 | SSCR0_DataSize(8),
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 75e86865234c..3734dc9708e1 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -660,7 +660,7 @@ int spi_write_then_read(struct spi_device *spi,
660 660
661 int status; 661 int status;
662 struct spi_message message; 662 struct spi_message message;
663 struct spi_transfer x[2]; 663 struct spi_transfer x;
664 u8 *local_buf; 664 u8 *local_buf;
665 665
666 /* Use preallocated DMA-safe buffer. We can't avoid copying here, 666 /* Use preallocated DMA-safe buffer. We can't avoid copying here,
@@ -671,15 +671,9 @@ int spi_write_then_read(struct spi_device *spi,
671 return -EINVAL; 671 return -EINVAL;
672 672
673 spi_message_init(&message); 673 spi_message_init(&message);
674 memset(x, 0, sizeof x); 674 memset(&x, 0, sizeof x);
675 if (n_tx) { 675 x.len = n_tx + n_rx;
676 x[0].len = n_tx; 676 spi_message_add_tail(&x, &message);
677 spi_message_add_tail(&x[0], &message);
678 }
679 if (n_rx) {
680 x[1].len = n_rx;
681 spi_message_add_tail(&x[1], &message);
682 }
683 677
684 /* ... unless someone else is using the pre-allocated buffer */ 678 /* ... unless someone else is using the pre-allocated buffer */
685 if (!mutex_trylock(&lock)) { 679 if (!mutex_trylock(&lock)) {
@@ -690,15 +684,15 @@ int spi_write_then_read(struct spi_device *spi,
690 local_buf = buf; 684 local_buf = buf;
691 685
692 memcpy(local_buf, txbuf, n_tx); 686 memcpy(local_buf, txbuf, n_tx);
693 x[0].tx_buf = local_buf; 687 x.tx_buf = local_buf;
694 x[1].rx_buf = local_buf + n_tx; 688 x.rx_buf = local_buf;
695 689
696 /* do the i/o */ 690 /* do the i/o */
697 status = spi_sync(spi, &message); 691 status = spi_sync(spi, &message);
698 if (status == 0) 692 if (status == 0)
699 memcpy(rxbuf, x[1].rx_buf, n_rx); 693 memcpy(rxbuf, x.rx_buf + n_tx, n_rx);
700 694
701 if (x[0].tx_buf == buf) 695 if (x.tx_buf == buf)
702 mutex_unlock(&lock); 696 mutex_unlock(&lock);
703 else 697 else
704 kfree(local_buf); 698 kfree(local_buf);
@@ -744,5 +738,5 @@ err0:
744 * driver registration) _could_ be dynamically linked (modular) ... costs 738 * driver registration) _could_ be dynamically linked (modular) ... costs
745 * include needing to have boardinfo data structures be much more public. 739 * include needing to have boardinfo data structures be much more public.
746 */ 740 */
747subsys_initcall(spi_init); 741postcore_initcall(spi_init);
748 742
diff --git a/drivers/spi/spi_s3c24xx.c b/drivers/spi/spi_s3c24xx.c
index 3eb414b84a9d..c252cbac00f1 100644
--- a/drivers/spi/spi_s3c24xx.c
+++ b/drivers/spi/spi_s3c24xx.c
@@ -247,6 +247,9 @@ static void s3c24xx_spi_initialsetup(struct s3c24xx_spi *hw)
247 writeb(0xff, hw->regs + S3C2410_SPPRE); 247 writeb(0xff, hw->regs + S3C2410_SPPRE);
248 writeb(SPPIN_DEFAULT, hw->regs + S3C2410_SPPIN); 248 writeb(SPPIN_DEFAULT, hw->regs + S3C2410_SPPIN);
249 writeb(SPCON_DEFAULT, hw->regs + S3C2410_SPCON); 249 writeb(SPCON_DEFAULT, hw->regs + S3C2410_SPCON);
250
251 if (hw->pdata && hw->pdata->gpio_setup)
252 hw->pdata->gpio_setup(hw->pdata, 1);
250} 253}
251 254
252static int __init s3c24xx_spi_probe(struct platform_device *pdev) 255static int __init s3c24xx_spi_probe(struct platform_device *pdev)
@@ -412,6 +415,9 @@ static int s3c24xx_spi_suspend(struct platform_device *pdev, pm_message_t msg)
412{ 415{
413 struct s3c24xx_spi *hw = platform_get_drvdata(pdev); 416 struct s3c24xx_spi *hw = platform_get_drvdata(pdev);
414 417
418 if (hw->pdata && hw->pdata->gpio_setup)
419 hw->pdata->gpio_setup(hw->pdata, 0);
420
415 clk_disable(hw->clk); 421 clk_disable(hw->clk);
416 return 0; 422 return 0;
417} 423}
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index e5e0cfed5e3b..89a43755a453 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -583,10 +583,9 @@ static int spidev_probe(struct spi_device *spi)
583 struct device *dev; 583 struct device *dev;
584 584
585 spidev->devt = MKDEV(SPIDEV_MAJOR, minor); 585 spidev->devt = MKDEV(SPIDEV_MAJOR, minor);
586 dev = device_create_drvdata(spidev_class, &spi->dev, 586 dev = device_create(spidev_class, &spi->dev, spidev->devt,
587 spidev->devt, spidev, 587 spidev, "spidev%d.%d",
588 "spidev%d.%d", 588 spi->master->bus_num, spi->chip_select);
589 spi->master->bus_num, spi->chip_select);
590 status = IS_ERR(dev) ? PTR_ERR(dev) : 0; 589 status = IS_ERR(dev) ? PTR_ERR(dev) : 0;
591 } else { 590 } else {
592 dev_dbg(&spi->dev, "no minor number available!\n"); 591 dev_dbg(&spi->dev, "no minor number available!\n");
diff --git a/drivers/ssb/pcmcia.c b/drivers/ssb/pcmcia.c
index 24c2a46c1476..fbfadbac67e8 100644
--- a/drivers/ssb/pcmcia.c
+++ b/drivers/ssb/pcmcia.c
@@ -80,7 +80,7 @@ static int ssb_pcmcia_cfg_write(struct ssb_bus *bus, u8 offset, u8 value)
80 reg.Action = CS_WRITE; 80 reg.Action = CS_WRITE;
81 reg.Value = value; 81 reg.Value = value;
82 res = pcmcia_access_configuration_register(bus->host_pcmcia, &reg); 82 res = pcmcia_access_configuration_register(bus->host_pcmcia, &reg);
83 if (unlikely(res != CS_SUCCESS)) 83 if (unlikely(res != 0))
84 return -EBUSY; 84 return -EBUSY;
85 85
86 return 0; 86 return 0;
@@ -96,7 +96,7 @@ static int ssb_pcmcia_cfg_read(struct ssb_bus *bus, u8 offset, u8 *value)
96 reg.Offset = offset; 96 reg.Offset = offset;
97 reg.Action = CS_READ; 97 reg.Action = CS_READ;
98 res = pcmcia_access_configuration_register(bus->host_pcmcia, &reg); 98 res = pcmcia_access_configuration_register(bus->host_pcmcia, &reg);
99 if (unlikely(res != CS_SUCCESS)) 99 if (unlikely(res != 0))
100 return -EBUSY; 100 return -EBUSY;
101 *value = reg.Value; 101 *value = reg.Value;
102 102
@@ -638,17 +638,17 @@ int ssb_pcmcia_get_invariants(struct ssb_bus *bus,
638 tuple.TupleData = buf; 638 tuple.TupleData = buf;
639 tuple.TupleDataMax = sizeof(buf); 639 tuple.TupleDataMax = sizeof(buf);
640 res = pcmcia_get_first_tuple(bus->host_pcmcia, &tuple); 640 res = pcmcia_get_first_tuple(bus->host_pcmcia, &tuple);
641 GOTO_ERROR_ON(res != CS_SUCCESS, "MAC first tpl"); 641 GOTO_ERROR_ON(res != 0, "MAC first tpl");
642 res = pcmcia_get_tuple_data(bus->host_pcmcia, &tuple); 642 res = pcmcia_get_tuple_data(bus->host_pcmcia, &tuple);
643 GOTO_ERROR_ON(res != CS_SUCCESS, "MAC first tpl data"); 643 GOTO_ERROR_ON(res != 0, "MAC first tpl data");
644 while (1) { 644 while (1) {
645 GOTO_ERROR_ON(tuple.TupleDataLen < 1, "MAC tpl < 1"); 645 GOTO_ERROR_ON(tuple.TupleDataLen < 1, "MAC tpl < 1");
646 if (tuple.TupleData[0] == CISTPL_FUNCE_LAN_NODE_ID) 646 if (tuple.TupleData[0] == CISTPL_FUNCE_LAN_NODE_ID)
647 break; 647 break;
648 res = pcmcia_get_next_tuple(bus->host_pcmcia, &tuple); 648 res = pcmcia_get_next_tuple(bus->host_pcmcia, &tuple);
649 GOTO_ERROR_ON(res != CS_SUCCESS, "MAC next tpl"); 649 GOTO_ERROR_ON(res != 0, "MAC next tpl");
650 res = pcmcia_get_tuple_data(bus->host_pcmcia, &tuple); 650 res = pcmcia_get_tuple_data(bus->host_pcmcia, &tuple);
651 GOTO_ERROR_ON(res != CS_SUCCESS, "MAC next tpl data"); 651 GOTO_ERROR_ON(res != 0, "MAC next tpl data");
652 } 652 }
653 GOTO_ERROR_ON(tuple.TupleDataLen != ETH_ALEN + 2, "MAC tpl size"); 653 GOTO_ERROR_ON(tuple.TupleDataLen != ETH_ALEN + 2, "MAC tpl size");
654 memcpy(sprom->il0mac, &tuple.TupleData[2], ETH_ALEN); 654 memcpy(sprom->il0mac, &tuple.TupleData[2], ETH_ALEN);
@@ -659,9 +659,9 @@ int ssb_pcmcia_get_invariants(struct ssb_bus *bus,
659 tuple.TupleData = buf; 659 tuple.TupleData = buf;
660 tuple.TupleDataMax = sizeof(buf); 660 tuple.TupleDataMax = sizeof(buf);
661 res = pcmcia_get_first_tuple(bus->host_pcmcia, &tuple); 661 res = pcmcia_get_first_tuple(bus->host_pcmcia, &tuple);
662 GOTO_ERROR_ON(res != CS_SUCCESS, "VEN first tpl"); 662 GOTO_ERROR_ON(res != 0, "VEN first tpl");
663 res = pcmcia_get_tuple_data(bus->host_pcmcia, &tuple); 663 res = pcmcia_get_tuple_data(bus->host_pcmcia, &tuple);
664 GOTO_ERROR_ON(res != CS_SUCCESS, "VEN first tpl data"); 664 GOTO_ERROR_ON(res != 0, "VEN first tpl data");
665 while (1) { 665 while (1) {
666 GOTO_ERROR_ON(tuple.TupleDataLen < 1, "VEN tpl < 1"); 666 GOTO_ERROR_ON(tuple.TupleDataLen < 1, "VEN tpl < 1");
667 switch (tuple.TupleData[0]) { 667 switch (tuple.TupleData[0]) {
@@ -733,11 +733,11 @@ int ssb_pcmcia_get_invariants(struct ssb_bus *bus,
733 break; 733 break;
734 } 734 }
735 res = pcmcia_get_next_tuple(bus->host_pcmcia, &tuple); 735 res = pcmcia_get_next_tuple(bus->host_pcmcia, &tuple);
736 if (res == CS_NO_MORE_ITEMS) 736 if (res == -ENOSPC)
737 break; 737 break;
738 GOTO_ERROR_ON(res != CS_SUCCESS, "VEN next tpl"); 738 GOTO_ERROR_ON(res != 0, "VEN next tpl");
739 res = pcmcia_get_tuple_data(bus->host_pcmcia, &tuple); 739 res = pcmcia_get_tuple_data(bus->host_pcmcia, &tuple);
740 GOTO_ERROR_ON(res != CS_SUCCESS, "VEN next tpl data"); 740 GOTO_ERROR_ON(res != 0, "VEN next tpl data");
741 } 741 }
742 742
743 return 0; 743 return 0;
diff --git a/drivers/telephony/ixj.c b/drivers/telephony/ixj.c
index ec7aeb502d15..41b6530b8f25 100644
--- a/drivers/telephony/ixj.c
+++ b/drivers/telephony/ixj.c
@@ -42,8 +42,6 @@
42 ***************************************************************************/ 42 ***************************************************************************/
43 43
44/* 44/*
45 * $Log: ixj.c,v $
46 *
47 * Revision 4.8 2003/07/09 19:39:00 Daniele Bellucci 45 * Revision 4.8 2003/07/09 19:39:00 Daniele Bellucci
48 * Audit some copy_*_user and minor cleanup. 46 * Audit some copy_*_user and minor cleanup.
49 * 47 *
diff --git a/drivers/telephony/ixj_pcmcia.c b/drivers/telephony/ixj_pcmcia.c
index ff9a29b76336..347c3ed1d9f1 100644
--- a/drivers/telephony/ixj_pcmcia.c
+++ b/drivers/telephony/ixj_pcmcia.c
@@ -124,65 +124,53 @@ static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
124 return; 124 return;
125} 125}
126 126
127static int ixj_config_check(struct pcmcia_device *p_dev,
128 cistpl_cftable_entry_t *cfg,
129 cistpl_cftable_entry_t *dflt,
130 unsigned int vcc,
131 void *priv_data)
132{
133 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
134 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
135 p_dev->io.BasePort1 = io->win[0].base;
136 p_dev->io.NumPorts1 = io->win[0].len;
137 if (io->nwin == 2) {
138 p_dev->io.BasePort2 = io->win[1].base;
139 p_dev->io.NumPorts2 = io->win[1].len;
140 }
141 if (!pcmcia_request_io(p_dev, &p_dev->io))
142 return 0;
143 }
144 return -ENODEV;
145}
146
127static int ixj_config(struct pcmcia_device * link) 147static int ixj_config(struct pcmcia_device * link)
128{ 148{
129 IXJ *j; 149 IXJ *j;
130 ixj_info_t *info; 150 ixj_info_t *info;
131 tuple_t tuple; 151 cistpl_cftable_entry_t dflt = { 0 };
132 u_short buf[128]; 152
133 cisparse_t parse;
134 cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
135 cistpl_cftable_entry_t dflt =
136 {
137 0
138 };
139 int last_ret, last_fn;
140 info = link->priv; 153 info = link->priv;
141 DEBUG(0, "ixj_config(0x%p)\n", link); 154 DEBUG(0, "ixj_config(0x%p)\n", link);
142 tuple.TupleData = (cisdata_t *) buf;
143 tuple.TupleOffset = 0;
144 tuple.TupleDataMax = 255;
145 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
146 tuple.Attributes = 0;
147 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
148 while (1) {
149 if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
150 pcmcia_parse_tuple(link, &tuple, &parse) != 0)
151 goto next_entry;
152 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
153 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
154 link->conf.ConfigIndex = cfg->index;
155 link->io.BasePort1 = io->win[0].base;
156 link->io.NumPorts1 = io->win[0].len;
157 if (io->nwin == 2) {
158 link->io.BasePort2 = io->win[1].base;
159 link->io.NumPorts2 = io->win[1].len;
160 }
161 if (pcmcia_request_io(link, &link->io) != 0)
162 goto next_entry;
163 /* If we've got this far, we're done */
164 break;
165 }
166 next_entry:
167 if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
168 dflt = *cfg;
169 CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
170 }
171 155
172 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf)); 156 if (pcmcia_loop_config(link, ixj_config_check, &dflt))
157 goto cs_failed;
158
159 if (pcmcia_request_configuration(link, &link->conf))
160 goto cs_failed;
173 161
174 /* 162 /*
175 * Register the card with the core. 163 * Register the card with the core.
176 */ 164 */
177 j=ixj_pcmcia_probe(link->io.BasePort1,link->io.BasePort1 + 0x10); 165 j = ixj_pcmcia_probe(link->io.BasePort1, link->io.BasePort1 + 0x10);
178 166
179 info->ndev = 1; 167 info->ndev = 1;
180 info->node.major = PHONE_MAJOR; 168 info->node.major = PHONE_MAJOR;
181 link->dev_node = &info->node; 169 link->dev_node = &info->node;
182 ixj_get_serial(link, j); 170 ixj_get_serial(link, j);
183 return 0; 171 return 0;
172
184 cs_failed: 173 cs_failed:
185 cs_error(link, last_fn, last_ret);
186 ixj_cs_release(link); 174 ixj_cs_release(link);
187 return -ENODEV; 175 return -ENODEV;
188} 176}
diff --git a/drivers/uio/Kconfig b/drivers/uio/Kconfig
index 4190be64917f..04b954cfce76 100644
--- a/drivers/uio/Kconfig
+++ b/drivers/uio/Kconfig
@@ -58,4 +58,17 @@ config UIO_SMX
58 58
59 If you compile this as a module, it will be called uio_smx. 59 If you compile this as a module, it will be called uio_smx.
60 60
61config UIO_SERCOS3
62 tristate "Automata Sercos III PCI card driver"
63 default n
64 help
65 Userspace I/O interface for the Sercos III PCI card from
66 Automata GmbH. The userspace part of this driver will be
67 available for download from the Automata GmbH web site.
68
69 Automata GmbH: http://www.automataweb.com
70 Sercos III interface: http://www.sercos.com
71
72 If you compile this as a module, it will be called uio_sercos3.
73
61endif 74endif
diff --git a/drivers/uio/Makefile b/drivers/uio/Makefile
index 8667bbdef904..e69558149859 100644
--- a/drivers/uio/Makefile
+++ b/drivers/uio/Makefile
@@ -3,3 +3,4 @@ obj-$(CONFIG_UIO_CIF) += uio_cif.o
3obj-$(CONFIG_UIO_PDRV) += uio_pdrv.o 3obj-$(CONFIG_UIO_PDRV) += uio_pdrv.o
4obj-$(CONFIG_UIO_PDRV_GENIRQ) += uio_pdrv_genirq.o 4obj-$(CONFIG_UIO_PDRV_GENIRQ) += uio_pdrv_genirq.o
5obj-$(CONFIG_UIO_SMX) += uio_smx.o 5obj-$(CONFIG_UIO_SMX) += uio_smx.o
6obj-$(CONFIG_UIO_SERCOS3) += uio_sercos3.o
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index 3a6934bf7131..5dccf057a7dd 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -67,6 +67,11 @@ static ssize_t map_size_show(struct uio_mem *mem, char *buf)
67 return sprintf(buf, "0x%lx\n", mem->size); 67 return sprintf(buf, "0x%lx\n", mem->size);
68} 68}
69 69
70static ssize_t map_offset_show(struct uio_mem *mem, char *buf)
71{
72 return sprintf(buf, "0x%lx\n", mem->addr & ~PAGE_MASK);
73}
74
70struct uio_sysfs_entry { 75struct uio_sysfs_entry {
71 struct attribute attr; 76 struct attribute attr;
72 ssize_t (*show)(struct uio_mem *, char *); 77 ssize_t (*show)(struct uio_mem *, char *);
@@ -77,10 +82,13 @@ static struct uio_sysfs_entry addr_attribute =
77 __ATTR(addr, S_IRUGO, map_addr_show, NULL); 82 __ATTR(addr, S_IRUGO, map_addr_show, NULL);
78static struct uio_sysfs_entry size_attribute = 83static struct uio_sysfs_entry size_attribute =
79 __ATTR(size, S_IRUGO, map_size_show, NULL); 84 __ATTR(size, S_IRUGO, map_size_show, NULL);
85static struct uio_sysfs_entry offset_attribute =
86 __ATTR(offset, S_IRUGO, map_offset_show, NULL);
80 87
81static struct attribute *attrs[] = { 88static struct attribute *attrs[] = {
82 &addr_attribute.attr, 89 &addr_attribute.attr,
83 &size_attribute.attr, 90 &size_attribute.attr,
91 &offset_attribute.attr,
84 NULL, /* need to NULL terminate the list of attributes */ 92 NULL, /* need to NULL terminate the list of attributes */
85}; 93};
86 94
@@ -482,15 +490,23 @@ static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
482{ 490{
483 struct uio_device *idev = vma->vm_private_data; 491 struct uio_device *idev = vma->vm_private_data;
484 struct page *page; 492 struct page *page;
493 unsigned long offset;
485 494
486 int mi = uio_find_mem_index(vma); 495 int mi = uio_find_mem_index(vma);
487 if (mi < 0) 496 if (mi < 0)
488 return VM_FAULT_SIGBUS; 497 return VM_FAULT_SIGBUS;
489 498
499 /*
500 * We need to subtract mi because userspace uses offset = N*PAGE_SIZE
501 * to use mem[N].
502 */
503 offset = (vmf->pgoff - mi) << PAGE_SHIFT;
504
490 if (idev->info->mem[mi].memtype == UIO_MEM_LOGICAL) 505 if (idev->info->mem[mi].memtype == UIO_MEM_LOGICAL)
491 page = virt_to_page(idev->info->mem[mi].addr); 506 page = virt_to_page(idev->info->mem[mi].addr + offset);
492 else 507 else
493 page = vmalloc_to_page((void*)idev->info->mem[mi].addr); 508 page = vmalloc_to_page((void *)idev->info->mem[mi].addr
509 + offset);
494 get_page(page); 510 get_page(page);
495 vmf->page = page; 511 vmf->page = page;
496 return 0; 512 return 0;
@@ -682,9 +698,9 @@ int __uio_register_device(struct module *owner,
682 if (ret) 698 if (ret)
683 goto err_get_minor; 699 goto err_get_minor;
684 700
685 idev->dev = device_create_drvdata(uio_class->class, parent, 701 idev->dev = device_create(uio_class->class, parent,
686 MKDEV(uio_major, idev->minor), idev, 702 MKDEV(uio_major, idev->minor), idev,
687 "uio%d", idev->minor); 703 "uio%d", idev->minor);
688 if (IS_ERR(idev->dev)) { 704 if (IS_ERR(idev->dev)) {
689 printk(KERN_ERR "UIO: device register failed\n"); 705 printk(KERN_ERR "UIO: device register failed\n");
690 ret = PTR_ERR(idev->dev); 706 ret = PTR_ERR(idev->dev);
diff --git a/drivers/uio/uio_pdrv.c b/drivers/uio/uio_pdrv.c
index 0b4ef39cd85d..d494ce9288c3 100644
--- a/drivers/uio/uio_pdrv.c
+++ b/drivers/uio/uio_pdrv.c
@@ -12,7 +12,7 @@
12#include <linux/uio_driver.h> 12#include <linux/uio_driver.h>
13#include <linux/stringify.h> 13#include <linux/stringify.h>
14 14
15#define DRIVER_NAME "uio" 15#define DRIVER_NAME "uio_pdrv"
16 16
17struct uio_platdata { 17struct uio_platdata {
18 struct uio_info *uioinfo; 18 struct uio_info *uioinfo;
diff --git a/drivers/uio/uio_sercos3.c b/drivers/uio/uio_sercos3.c
new file mode 100644
index 000000000000..a6d1b2bc47f3
--- /dev/null
+++ b/drivers/uio/uio_sercos3.c
@@ -0,0 +1,243 @@
1/* sercos3: UIO driver for the Automata Sercos III PCI card
2
3 Copyright (C) 2008 Linutronix GmbH
4 Author: John Ogness <john.ogness@linutronix.de>
5
6 This is a straight-forward UIO driver, where interrupts are disabled
7 by the interrupt handler and re-enabled via a write to the UIO device
8 by the userspace-part.
9
10 The only part that may seem odd is the use of a logical OR when
11 storing and restoring enabled interrupts. This is done because the
12 userspace-part could directly modify the Interrupt Enable Register
13 at any time. To reduce possible conflicts, the kernel driver uses
14 a logical OR to make more controlled changes (rather than blindly
15 overwriting previous values).
16
17 Race conditions exist if the userspace-part directly modifies the
18 Interrupt Enable Register while in operation. The consequences are
19 that certain interrupts would fail to be enabled or disabled. For
20 this reason, the userspace-part should only directly modify the
21 Interrupt Enable Register at the beginning (to get things going).
22 The userspace-part can safely disable interrupts at any time using
23 a write to the UIO device.
24*/
25
26#include <linux/device.h>
27#include <linux/module.h>
28#include <linux/pci.h>
29#include <linux/uio_driver.h>
30#include <linux/io.h>
31
32/* ID's for SERCOS III PCI card (PLX 9030) */
33#define SERCOS_SUB_VENDOR_ID 0x1971
34#define SERCOS_SUB_SYSID_3530 0x3530
35#define SERCOS_SUB_SYSID_3535 0x3535
36#define SERCOS_SUB_SYSID_3780 0x3780
37
38/* Interrupt Enable Register */
39#define IER0_OFFSET 0x08
40
41/* Interrupt Status Register */
42#define ISR0_OFFSET 0x18
43
44struct sercos3_priv {
45 u32 ier0_cache;
46 spinlock_t ier0_cache_lock;
47};
48
49/* this function assumes ier0_cache_lock is locked! */
50static void sercos3_disable_interrupts(struct uio_info *info,
51 struct sercos3_priv *priv)
52{
53 void __iomem *ier0 = info->mem[3].internal_addr + IER0_OFFSET;
54
55 /* add enabled interrupts to cache */
56 priv->ier0_cache |= ioread32(ier0);
57
58 /* disable interrupts */
59 iowrite32(0, ier0);
60}
61
62/* this function assumes ier0_cache_lock is locked! */
63static void sercos3_enable_interrupts(struct uio_info *info,
64 struct sercos3_priv *priv)
65{
66 void __iomem *ier0 = info->mem[3].internal_addr + IER0_OFFSET;
67
68 /* restore previously enabled interrupts */
69 iowrite32(ioread32(ier0) | priv->ier0_cache, ier0);
70 priv->ier0_cache = 0;
71}
72
73static irqreturn_t sercos3_handler(int irq, struct uio_info *info)
74{
75 struct sercos3_priv *priv = info->priv;
76 void __iomem *isr0 = info->mem[3].internal_addr + ISR0_OFFSET;
77 void __iomem *ier0 = info->mem[3].internal_addr + IER0_OFFSET;
78
79 if (!(ioread32(isr0) & ioread32(ier0)))
80 return IRQ_NONE;
81
82 spin_lock(&priv->ier0_cache_lock);
83 sercos3_disable_interrupts(info, priv);
84 spin_unlock(&priv->ier0_cache_lock);
85
86 return IRQ_HANDLED;
87}
88
89static int sercos3_irqcontrol(struct uio_info *info, s32 irq_on)
90{
91 struct sercos3_priv *priv = info->priv;
92
93 spin_lock_irq(&priv->ier0_cache_lock);
94 if (irq_on)
95 sercos3_enable_interrupts(info, priv);
96 else
97 sercos3_disable_interrupts(info, priv);
98 spin_unlock_irq(&priv->ier0_cache_lock);
99
100 return 0;
101}
102
103static int sercos3_setup_iomem(struct pci_dev *dev, struct uio_info *info,
104 int n, int pci_bar)
105{
106 info->mem[n].addr = pci_resource_start(dev, pci_bar);
107 if (!info->mem[n].addr)
108 return -1;
109 info->mem[n].internal_addr = ioremap(pci_resource_start(dev, pci_bar),
110 pci_resource_len(dev, pci_bar));
111 if (!info->mem[n].internal_addr)
112 return -1;
113 info->mem[n].size = pci_resource_len(dev, pci_bar);
114 info->mem[n].memtype = UIO_MEM_PHYS;
115 return 0;
116}
117
118static int __devinit sercos3_pci_probe(struct pci_dev *dev,
119 const struct pci_device_id *id)
120{
121 struct uio_info *info;
122 struct sercos3_priv *priv;
123 int i;
124
125 info = kzalloc(sizeof(struct uio_info), GFP_KERNEL);
126 if (!info)
127 return -ENOMEM;
128
129 priv = kzalloc(sizeof(struct sercos3_priv), GFP_KERNEL);
130 if (!priv)
131 goto out_free;
132
133 if (pci_enable_device(dev))
134 goto out_free_priv;
135
136 if (pci_request_regions(dev, "sercos3"))
137 goto out_disable;
138
139 /* we only need PCI BAR's 0, 2, 3, 4, 5 */
140 if (sercos3_setup_iomem(dev, info, 0, 0))
141 goto out_unmap;
142 if (sercos3_setup_iomem(dev, info, 1, 2))
143 goto out_unmap;
144 if (sercos3_setup_iomem(dev, info, 2, 3))
145 goto out_unmap;
146 if (sercos3_setup_iomem(dev, info, 3, 4))
147 goto out_unmap;
148 if (sercos3_setup_iomem(dev, info, 4, 5))
149 goto out_unmap;
150
151 spin_lock_init(&priv->ier0_cache_lock);
152 info->priv = priv;
153 info->name = "Sercos_III_PCI";
154 info->version = "0.0.1";
155 info->irq = dev->irq;
156 info->irq_flags = IRQF_DISABLED | IRQF_SHARED;
157 info->handler = sercos3_handler;
158 info->irqcontrol = sercos3_irqcontrol;
159
160 pci_set_drvdata(dev, info);
161
162 if (uio_register_device(&dev->dev, info))
163 goto out_unmap;
164
165 return 0;
166
167out_unmap:
168 for (i = 0; i < 5; i++) {
169 if (info->mem[i].internal_addr)
170 iounmap(info->mem[i].internal_addr);
171 }
172 pci_release_regions(dev);
173out_disable:
174 pci_disable_device(dev);
175out_free_priv:
176 kfree(priv);
177out_free:
178 kfree(info);
179 return -ENODEV;
180}
181
182static void sercos3_pci_remove(struct pci_dev *dev)
183{
184 struct uio_info *info = pci_get_drvdata(dev);
185 int i;
186
187 uio_unregister_device(info);
188 pci_release_regions(dev);
189 pci_disable_device(dev);
190 pci_set_drvdata(dev, NULL);
191 for (i = 0; i < 5; i++) {
192 if (info->mem[i].internal_addr)
193 iounmap(info->mem[i].internal_addr);
194 }
195 kfree(info->priv);
196 kfree(info);
197}
198
199static struct pci_device_id sercos3_pci_ids[] __devinitdata = {
200 {
201 .vendor = PCI_VENDOR_ID_PLX,
202 .device = PCI_DEVICE_ID_PLX_9030,
203 .subvendor = SERCOS_SUB_VENDOR_ID,
204 .subdevice = SERCOS_SUB_SYSID_3530,
205 },
206 {
207 .vendor = PCI_VENDOR_ID_PLX,
208 .device = PCI_DEVICE_ID_PLX_9030,
209 .subvendor = SERCOS_SUB_VENDOR_ID,
210 .subdevice = SERCOS_SUB_SYSID_3535,
211 },
212 {
213 .vendor = PCI_VENDOR_ID_PLX,
214 .device = PCI_DEVICE_ID_PLX_9030,
215 .subvendor = SERCOS_SUB_VENDOR_ID,
216 .subdevice = SERCOS_SUB_SYSID_3780,
217 },
218 { 0, }
219};
220
221static struct pci_driver sercos3_pci_driver = {
222 .name = "sercos3",
223 .id_table = sercos3_pci_ids,
224 .probe = sercos3_pci_probe,
225 .remove = sercos3_pci_remove,
226};
227
228static int __init sercos3_init_module(void)
229{
230 return pci_register_driver(&sercos3_pci_driver);
231}
232
233static void __exit sercos3_exit_module(void)
234{
235 pci_unregister_driver(&sercos3_pci_driver);
236}
237
238module_init(sercos3_init_module);
239module_exit(sercos3_exit_module);
240
241MODULE_DESCRIPTION("UIO driver for the Automata Sercos III PCI card");
242MODULE_AUTHOR("John Ogness <john.ogness@linutronix.de>");
243MODULE_LICENSE("GPL v2");
diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
index 20290c5b1562..7a4fa791dc19 100644
--- a/drivers/usb/core/devio.c
+++ b/drivers/usb/core/devio.c
@@ -1729,9 +1729,9 @@ static int usb_classdev_add(struct usb_device *dev)
1729{ 1729{
1730 struct device *cldev; 1730 struct device *cldev;
1731 1731
1732 cldev = device_create_drvdata(usb_classdev_class, &dev->dev, 1732 cldev = device_create(usb_classdev_class, &dev->dev, dev->dev.devt,
1733 dev->dev.devt, NULL, "usbdev%d.%d", 1733 NULL, "usbdev%d.%d", dev->bus->busnum,
1734 dev->bus->busnum, dev->devnum); 1734 dev->devnum);
1735 if (IS_ERR(cldev)) 1735 if (IS_ERR(cldev))
1736 return PTR_ERR(cldev); 1736 return PTR_ERR(cldev);
1737 dev->usb_classdev = cldev; 1737 dev->usb_classdev = cldev;
diff --git a/drivers/usb/core/file.c b/drivers/usb/core/file.c
index 6b1b229e38cd..55f7f310924b 100644
--- a/drivers/usb/core/file.c
+++ b/drivers/usb/core/file.c
@@ -196,9 +196,9 @@ int usb_register_dev(struct usb_interface *intf,
196 ++temp; 196 ++temp;
197 else 197 else
198 temp = name; 198 temp = name;
199 intf->usb_dev = device_create_drvdata(usb_class->class, &intf->dev, 199 intf->usb_dev = device_create(usb_class->class, &intf->dev,
200 MKDEV(USB_MAJOR, minor), NULL, 200 MKDEV(USB_MAJOR, minor), NULL,
201 "%s", temp); 201 "%s", temp);
202 if (IS_ERR(intf->usb_dev)) { 202 if (IS_ERR(intf->usb_dev)) {
203 down_write(&minor_rwsem); 203 down_write(&minor_rwsem);
204 usb_minors[intf->minor] = NULL; 204 usb_minors[intf->minor] = NULL;
diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
index 8ab389dca2b9..c8035a8216bd 100644
--- a/drivers/usb/core/hcd.c
+++ b/drivers/usb/core/hcd.c
@@ -818,9 +818,8 @@ static int usb_register_bus(struct usb_bus *bus)
818 set_bit (busnum, busmap.busmap); 818 set_bit (busnum, busmap.busmap);
819 bus->busnum = busnum; 819 bus->busnum = busnum;
820 820
821 bus->dev = device_create_drvdata(usb_host_class, bus->controller, 821 bus->dev = device_create(usb_host_class, bus->controller, MKDEV(0, 0),
822 MKDEV(0, 0), bus, 822 bus, "usb_host%d", busnum);
823 "usb_host%d", busnum);
824 result = PTR_ERR(bus->dev); 823 result = PTR_ERR(bus->dev);
825 if (IS_ERR(bus->dev)) 824 if (IS_ERR(bus->dev))
826 goto error_create_class_dev; 825 goto error_create_class_dev;
diff --git a/drivers/usb/core/inode.c b/drivers/usb/core/inode.c
index db410e92c80d..77fa7a080801 100644
--- a/drivers/usb/core/inode.c
+++ b/drivers/usb/core/inode.c
@@ -97,7 +97,7 @@ enum {
97 Opt_err, 97 Opt_err,
98}; 98};
99 99
100static match_table_t tokens = { 100static const match_table_t tokens = {
101 {Opt_devuid, "devuid=%u"}, 101 {Opt_devuid, "devuid=%u"},
102 {Opt_devgid, "devgid=%u"}, 102 {Opt_devgid, "devgid=%u"},
103 {Opt_devmode, "devmode=%o"}, 103 {Opt_devmode, "devmode=%o"},
diff --git a/drivers/usb/gadget/Makefile b/drivers/usb/gadget/Makefile
index fcb5cb9094d9..2267fa0b51b2 100644
--- a/drivers/usb/gadget/Makefile
+++ b/drivers/usb/gadget/Makefile
@@ -22,24 +22,15 @@ obj-$(CONFIG_USB_M66592) += m66592-udc.o
22# 22#
23# USB gadget drivers 23# USB gadget drivers
24# 24#
25C_UTILS = composite.o usbstring.o config.o epautoconf.o 25g_zero-objs := zero.o
26 26g_ether-objs := ether.o
27g_zero-objs := zero.o f_sourcesink.o f_loopback.o $(C_UTILS) 27g_serial-objs := serial.o
28g_ether-objs := ether.o u_ether.o f_subset.o f_ecm.o $(C_UTILS) 28g_midi-objs := gmidi.o
29g_serial-objs := serial.o u_serial.o f_acm.o f_serial.o $(C_UTILS)
30g_midi-objs := gmidi.o usbstring.o config.o epautoconf.o
31gadgetfs-objs := inode.o 29gadgetfs-objs := inode.o
32g_file_storage-objs := file_storage.o usbstring.o config.o \ 30g_file_storage-objs := file_storage.o
33 epautoconf.o 31g_printer-objs := printer.o
34g_printer-objs := printer.o usbstring.o config.o \ 32g_cdc-objs := cdc2.o
35 epautoconf.o
36g_cdc-objs := cdc2.o u_ether.o f_ecm.o \
37 u_serial.o f_acm.o $(C_UTILS)
38 33
39ifeq ($(CONFIG_USB_ETH_RNDIS),y)
40 g_ether-objs += f_rndis.o rndis.o
41endif
42
43obj-$(CONFIG_USB_ZERO) += g_zero.o 34obj-$(CONFIG_USB_ZERO) += g_zero.o
44obj-$(CONFIG_USB_ETH) += g_ether.o 35obj-$(CONFIG_USB_ETH) += g_ether.o
45obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o 36obj-$(CONFIG_USB_GADGETFS) += gadgetfs.o
diff --git a/drivers/usb/gadget/cdc2.c b/drivers/usb/gadget/cdc2.c
index a39a4b940c33..a724fc149850 100644
--- a/drivers/usb/gadget/cdc2.c
+++ b/drivers/usb/gadget/cdc2.c
@@ -43,6 +43,25 @@
43 43
44/*-------------------------------------------------------------------------*/ 44/*-------------------------------------------------------------------------*/
45 45
46/*
47 * Kbuild is not very cooperative with respect to linking separately
48 * compiled library objects into one module. So for now we won't use
49 * separate compilation ... ensuring init/exit sections work to shrink
50 * the runtime footprint, and giving us at least some parts of what
51 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
52 */
53
54#include "composite.c"
55#include "usbstring.c"
56#include "config.c"
57#include "epautoconf.c"
58#include "u_serial.c"
59#include "f_acm.c"
60#include "f_ecm.c"
61#include "u_ether.c"
62
63/*-------------------------------------------------------------------------*/
64
46static struct usb_device_descriptor device_desc = { 65static struct usb_device_descriptor device_desc = {
47 .bLength = sizeof device_desc, 66 .bLength = sizeof device_desc,
48 .bDescriptorType = USB_DT_DEVICE, 67 .bDescriptorType = USB_DT_DEVICE,
@@ -148,7 +167,8 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
148 int status; 167 int status;
149 168
150 if (!can_support_ecm(cdev->gadget)) { 169 if (!can_support_ecm(cdev->gadget)) {
151 ERROR(cdev, "controller '%s' not usable\n", gadget->name); 170 dev_err(&gadget->dev, "controller '%s' not usable\n",
171 gadget->name);
152 return -EINVAL; 172 return -EINVAL;
153 } 173 }
154 174
@@ -203,7 +223,8 @@ static int __init cdc_bind(struct usb_composite_dev *cdev)
203 if (status < 0) 223 if (status < 0)
204 goto fail1; 224 goto fail1;
205 225
206 INFO(cdev, "%s, version: " DRIVER_VERSION "\n", DRIVER_DESC); 226 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
227 DRIVER_DESC);
207 228
208 return 0; 229 return 0;
209 230
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index bcac2e68660d..944c8e889ab4 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -96,6 +96,28 @@ static inline bool has_rndis(void)
96 96
97/*-------------------------------------------------------------------------*/ 97/*-------------------------------------------------------------------------*/
98 98
99/*
100 * Kbuild is not very cooperative with respect to linking separately
101 * compiled library objects into one module. So for now we won't use
102 * separate compilation ... ensuring init/exit sections work to shrink
103 * the runtime footprint, and giving us at least some parts of what
104 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
105 */
106#include "composite.c"
107#include "usbstring.c"
108#include "config.c"
109#include "epautoconf.c"
110
111#include "f_ecm.c"
112#include "f_subset.c"
113#ifdef CONFIG_USB_ETH_RNDIS
114#include "f_rndis.c"
115#include "rndis.c"
116#endif
117#include "u_ether.c"
118
119/*-------------------------------------------------------------------------*/
120
99/* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! 121/* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
100 * Instead: allocate your own, using normal USB-IF procedures. 122 * Instead: allocate your own, using normal USB-IF procedures.
101 */ 123 */
@@ -293,7 +315,8 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
293 * but if the controller isn't recognized at all then 315 * but if the controller isn't recognized at all then
294 * that assumption is a bit more likely to be wrong. 316 * that assumption is a bit more likely to be wrong.
295 */ 317 */
296 WARNING(cdev, "controller '%s' not recognized; trying %s\n", 318 dev_warn(&gadget->dev,
319 "controller '%s' not recognized; trying %s\n",
297 gadget->name, 320 gadget->name,
298 eth_config_driver.label); 321 eth_config_driver.label);
299 device_desc.bcdDevice = 322 device_desc.bcdDevice =
@@ -332,7 +355,8 @@ static int __init eth_bind(struct usb_composite_dev *cdev)
332 if (status < 0) 355 if (status < 0)
333 goto fail; 356 goto fail;
334 357
335 INFO(cdev, "%s, version: " DRIVER_VERSION "\n", DRIVER_DESC); 358 dev_info(&gadget->dev, "%s, version: " DRIVER_VERSION "\n",
359 DRIVER_DESC);
336 360
337 return 0; 361 return 0;
338 362
diff --git a/drivers/usb/gadget/f_ecm.c b/drivers/usb/gadget/f_ecm.c
index a2b5c092bda0..4ae579948e54 100644
--- a/drivers/usb/gadget/f_ecm.c
+++ b/drivers/usb/gadget/f_ecm.c
@@ -83,7 +83,7 @@ static inline struct f_ecm *func_to_ecm(struct usb_function *f)
83} 83}
84 84
85/* peak (theoretical) bulk transfer rate in bits-per-second */ 85/* peak (theoretical) bulk transfer rate in bits-per-second */
86static inline unsigned bitrate(struct usb_gadget *g) 86static inline unsigned ecm_bitrate(struct usb_gadget *g)
87{ 87{
88 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH) 88 if (gadget_is_dualspeed(g) && g->speed == USB_SPEED_HIGH)
89 return 13 * 512 * 8 * 1000 * 8; 89 return 13 * 512 * 8 * 1000 * 8;
@@ -107,7 +107,7 @@ static inline unsigned bitrate(struct usb_gadget *g)
107 */ 107 */
108 108
109#define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */ 109#define LOG2_STATUS_INTERVAL_MSEC 5 /* 1 << 5 == 32 msec */
110#define STATUS_BYTECOUNT 16 /* 8 byte header + data */ 110#define ECM_STATUS_BYTECOUNT 16 /* 8 byte header + data */
111 111
112 112
113/* interface descriptor: */ 113/* interface descriptor: */
@@ -125,8 +125,8 @@ static struct usb_interface_descriptor ecm_control_intf __initdata = {
125 /* .iInterface = DYNAMIC */ 125 /* .iInterface = DYNAMIC */
126}; 126};
127 127
128static struct usb_cdc_header_desc header_desc __initdata = { 128static struct usb_cdc_header_desc ecm_header_desc __initdata = {
129 .bLength = sizeof header_desc, 129 .bLength = sizeof ecm_header_desc,
130 .bDescriptorType = USB_DT_CS_INTERFACE, 130 .bDescriptorType = USB_DT_CS_INTERFACE,
131 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 131 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
132 132
@@ -141,8 +141,8 @@ static struct usb_cdc_union_desc ecm_union_desc __initdata = {
141 /* .bSlaveInterface0 = DYNAMIC */ 141 /* .bSlaveInterface0 = DYNAMIC */
142}; 142};
143 143
144static struct usb_cdc_ether_desc ether_desc __initdata = { 144static struct usb_cdc_ether_desc ecm_desc __initdata = {
145 .bLength = sizeof ether_desc, 145 .bLength = sizeof ecm_desc,
146 .bDescriptorType = USB_DT_CS_INTERFACE, 146 .bDescriptorType = USB_DT_CS_INTERFACE,
147 .bDescriptorSubType = USB_CDC_ETHERNET_TYPE, 147 .bDescriptorSubType = USB_CDC_ETHERNET_TYPE,
148 148
@@ -186,17 +186,17 @@ static struct usb_interface_descriptor ecm_data_intf __initdata = {
186 186
187/* full speed support: */ 187/* full speed support: */
188 188
189static struct usb_endpoint_descriptor fs_notify_desc __initdata = { 189static struct usb_endpoint_descriptor fs_ecm_notify_desc __initdata = {
190 .bLength = USB_DT_ENDPOINT_SIZE, 190 .bLength = USB_DT_ENDPOINT_SIZE,
191 .bDescriptorType = USB_DT_ENDPOINT, 191 .bDescriptorType = USB_DT_ENDPOINT,
192 192
193 .bEndpointAddress = USB_DIR_IN, 193 .bEndpointAddress = USB_DIR_IN,
194 .bmAttributes = USB_ENDPOINT_XFER_INT, 194 .bmAttributes = USB_ENDPOINT_XFER_INT,
195 .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT), 195 .wMaxPacketSize = __constant_cpu_to_le16(ECM_STATUS_BYTECOUNT),
196 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC, 196 .bInterval = 1 << LOG2_STATUS_INTERVAL_MSEC,
197}; 197};
198 198
199static struct usb_endpoint_descriptor fs_in_desc __initdata = { 199static struct usb_endpoint_descriptor fs_ecm_in_desc __initdata = {
200 .bLength = USB_DT_ENDPOINT_SIZE, 200 .bLength = USB_DT_ENDPOINT_SIZE,
201 .bDescriptorType = USB_DT_ENDPOINT, 201 .bDescriptorType = USB_DT_ENDPOINT,
202 202
@@ -204,7 +204,7 @@ static struct usb_endpoint_descriptor fs_in_desc __initdata = {
204 .bmAttributes = USB_ENDPOINT_XFER_BULK, 204 .bmAttributes = USB_ENDPOINT_XFER_BULK,
205}; 205};
206 206
207static struct usb_endpoint_descriptor fs_out_desc __initdata = { 207static struct usb_endpoint_descriptor fs_ecm_out_desc __initdata = {
208 .bLength = USB_DT_ENDPOINT_SIZE, 208 .bLength = USB_DT_ENDPOINT_SIZE,
209 .bDescriptorType = USB_DT_ENDPOINT, 209 .bDescriptorType = USB_DT_ENDPOINT,
210 210
@@ -212,34 +212,34 @@ static struct usb_endpoint_descriptor fs_out_desc __initdata = {
212 .bmAttributes = USB_ENDPOINT_XFER_BULK, 212 .bmAttributes = USB_ENDPOINT_XFER_BULK,
213}; 213};
214 214
215static struct usb_descriptor_header *eth_fs_function[] __initdata = { 215static struct usb_descriptor_header *ecm_fs_function[] __initdata = {
216 /* CDC ECM control descriptors */ 216 /* CDC ECM control descriptors */
217 (struct usb_descriptor_header *) &ecm_control_intf, 217 (struct usb_descriptor_header *) &ecm_control_intf,
218 (struct usb_descriptor_header *) &header_desc, 218 (struct usb_descriptor_header *) &ecm_header_desc,
219 (struct usb_descriptor_header *) &ecm_union_desc, 219 (struct usb_descriptor_header *) &ecm_union_desc,
220 (struct usb_descriptor_header *) &ether_desc, 220 (struct usb_descriptor_header *) &ecm_desc,
221 /* NOTE: status endpoint might need to be removed */ 221 /* NOTE: status endpoint might need to be removed */
222 (struct usb_descriptor_header *) &fs_notify_desc, 222 (struct usb_descriptor_header *) &fs_ecm_notify_desc,
223 /* data interface, altsettings 0 and 1 */ 223 /* data interface, altsettings 0 and 1 */
224 (struct usb_descriptor_header *) &ecm_data_nop_intf, 224 (struct usb_descriptor_header *) &ecm_data_nop_intf,
225 (struct usb_descriptor_header *) &ecm_data_intf, 225 (struct usb_descriptor_header *) &ecm_data_intf,
226 (struct usb_descriptor_header *) &fs_in_desc, 226 (struct usb_descriptor_header *) &fs_ecm_in_desc,
227 (struct usb_descriptor_header *) &fs_out_desc, 227 (struct usb_descriptor_header *) &fs_ecm_out_desc,
228 NULL, 228 NULL,
229}; 229};
230 230
231/* high speed support: */ 231/* high speed support: */
232 232
233static struct usb_endpoint_descriptor hs_notify_desc __initdata = { 233static struct usb_endpoint_descriptor hs_ecm_notify_desc __initdata = {
234 .bLength = USB_DT_ENDPOINT_SIZE, 234 .bLength = USB_DT_ENDPOINT_SIZE,
235 .bDescriptorType = USB_DT_ENDPOINT, 235 .bDescriptorType = USB_DT_ENDPOINT,
236 236
237 .bEndpointAddress = USB_DIR_IN, 237 .bEndpointAddress = USB_DIR_IN,
238 .bmAttributes = USB_ENDPOINT_XFER_INT, 238 .bmAttributes = USB_ENDPOINT_XFER_INT,
239 .wMaxPacketSize = __constant_cpu_to_le16(STATUS_BYTECOUNT), 239 .wMaxPacketSize = __constant_cpu_to_le16(ECM_STATUS_BYTECOUNT),
240 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4, 240 .bInterval = LOG2_STATUS_INTERVAL_MSEC + 4,
241}; 241};
242static struct usb_endpoint_descriptor hs_in_desc __initdata = { 242static struct usb_endpoint_descriptor hs_ecm_in_desc __initdata = {
243 .bLength = USB_DT_ENDPOINT_SIZE, 243 .bLength = USB_DT_ENDPOINT_SIZE,
244 .bDescriptorType = USB_DT_ENDPOINT, 244 .bDescriptorType = USB_DT_ENDPOINT,
245 245
@@ -248,7 +248,7 @@ static struct usb_endpoint_descriptor hs_in_desc __initdata = {
248 .wMaxPacketSize = __constant_cpu_to_le16(512), 248 .wMaxPacketSize = __constant_cpu_to_le16(512),
249}; 249};
250 250
251static struct usb_endpoint_descriptor hs_out_desc __initdata = { 251static struct usb_endpoint_descriptor hs_ecm_out_desc __initdata = {
252 .bLength = USB_DT_ENDPOINT_SIZE, 252 .bLength = USB_DT_ENDPOINT_SIZE,
253 .bDescriptorType = USB_DT_ENDPOINT, 253 .bDescriptorType = USB_DT_ENDPOINT,
254 254
@@ -257,19 +257,19 @@ static struct usb_endpoint_descriptor hs_out_desc __initdata = {
257 .wMaxPacketSize = __constant_cpu_to_le16(512), 257 .wMaxPacketSize = __constant_cpu_to_le16(512),
258}; 258};
259 259
260static struct usb_descriptor_header *eth_hs_function[] __initdata = { 260static struct usb_descriptor_header *ecm_hs_function[] __initdata = {
261 /* CDC ECM control descriptors */ 261 /* CDC ECM control descriptors */
262 (struct usb_descriptor_header *) &ecm_control_intf, 262 (struct usb_descriptor_header *) &ecm_control_intf,
263 (struct usb_descriptor_header *) &header_desc, 263 (struct usb_descriptor_header *) &ecm_header_desc,
264 (struct usb_descriptor_header *) &ecm_union_desc, 264 (struct usb_descriptor_header *) &ecm_union_desc,
265 (struct usb_descriptor_header *) &ether_desc, 265 (struct usb_descriptor_header *) &ecm_desc,
266 /* NOTE: status endpoint might need to be removed */ 266 /* NOTE: status endpoint might need to be removed */
267 (struct usb_descriptor_header *) &hs_notify_desc, 267 (struct usb_descriptor_header *) &hs_ecm_notify_desc,
268 /* data interface, altsettings 0 and 1 */ 268 /* data interface, altsettings 0 and 1 */
269 (struct usb_descriptor_header *) &ecm_data_nop_intf, 269 (struct usb_descriptor_header *) &ecm_data_nop_intf,
270 (struct usb_descriptor_header *) &ecm_data_intf, 270 (struct usb_descriptor_header *) &ecm_data_intf,
271 (struct usb_descriptor_header *) &hs_in_desc, 271 (struct usb_descriptor_header *) &hs_ecm_in_desc,
272 (struct usb_descriptor_header *) &hs_out_desc, 272 (struct usb_descriptor_header *) &hs_ecm_out_desc,
273 NULL, 273 NULL,
274}; 274};
275 275
@@ -329,14 +329,14 @@ static void ecm_do_notify(struct f_ecm *ecm)
329 event->bNotificationType = USB_CDC_NOTIFY_SPEED_CHANGE; 329 event->bNotificationType = USB_CDC_NOTIFY_SPEED_CHANGE;
330 event->wValue = cpu_to_le16(0); 330 event->wValue = cpu_to_le16(0);
331 event->wLength = cpu_to_le16(8); 331 event->wLength = cpu_to_le16(8);
332 req->length = STATUS_BYTECOUNT; 332 req->length = ECM_STATUS_BYTECOUNT;
333 333
334 /* SPEED_CHANGE data is up/down speeds in bits/sec */ 334 /* SPEED_CHANGE data is up/down speeds in bits/sec */
335 data = req->buf + sizeof *event; 335 data = req->buf + sizeof *event;
336 data[0] = cpu_to_le32(bitrate(cdev->gadget)); 336 data[0] = cpu_to_le32(ecm_bitrate(cdev->gadget));
337 data[1] = data[0]; 337 data[1] = data[0];
338 338
339 DBG(cdev, "notify speed %d\n", bitrate(cdev->gadget)); 339 DBG(cdev, "notify speed %d\n", ecm_bitrate(cdev->gadget));
340 ecm->notify_state = ECM_NOTIFY_NONE; 340 ecm->notify_state = ECM_NOTIFY_NONE;
341 break; 341 break;
342 } 342 }
@@ -628,13 +628,13 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f)
628 status = -ENODEV; 628 status = -ENODEV;
629 629
630 /* allocate instance-specific endpoints */ 630 /* allocate instance-specific endpoints */
631 ep = usb_ep_autoconfig(cdev->gadget, &fs_in_desc); 631 ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_in_desc);
632 if (!ep) 632 if (!ep)
633 goto fail; 633 goto fail;
634 ecm->port.in_ep = ep; 634 ecm->port.in_ep = ep;
635 ep->driver_data = cdev; /* claim */ 635 ep->driver_data = cdev; /* claim */
636 636
637 ep = usb_ep_autoconfig(cdev->gadget, &fs_out_desc); 637 ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_out_desc);
638 if (!ep) 638 if (!ep)
639 goto fail; 639 goto fail;
640 ecm->port.out_ep = ep; 640 ecm->port.out_ep = ep;
@@ -644,7 +644,7 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f)
644 * don't treat it that way. It's simpler, and some newer CDC 644 * don't treat it that way. It's simpler, and some newer CDC
645 * profiles (wireless handsets) no longer treat it as optional. 645 * profiles (wireless handsets) no longer treat it as optional.
646 */ 646 */
647 ep = usb_ep_autoconfig(cdev->gadget, &fs_notify_desc); 647 ep = usb_ep_autoconfig(cdev->gadget, &fs_ecm_notify_desc);
648 if (!ep) 648 if (!ep)
649 goto fail; 649 goto fail;
650 ecm->notify = ep; 650 ecm->notify = ep;
@@ -656,47 +656,47 @@ ecm_bind(struct usb_configuration *c, struct usb_function *f)
656 ecm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL); 656 ecm->notify_req = usb_ep_alloc_request(ep, GFP_KERNEL);
657 if (!ecm->notify_req) 657 if (!ecm->notify_req)
658 goto fail; 658 goto fail;
659 ecm->notify_req->buf = kmalloc(STATUS_BYTECOUNT, GFP_KERNEL); 659 ecm->notify_req->buf = kmalloc(ECM_STATUS_BYTECOUNT, GFP_KERNEL);
660 if (!ecm->notify_req->buf) 660 if (!ecm->notify_req->buf)
661 goto fail; 661 goto fail;
662 ecm->notify_req->context = ecm; 662 ecm->notify_req->context = ecm;
663 ecm->notify_req->complete = ecm_notify_complete; 663 ecm->notify_req->complete = ecm_notify_complete;
664 664
665 /* copy descriptors, and track endpoint copies */ 665 /* copy descriptors, and track endpoint copies */
666 f->descriptors = usb_copy_descriptors(eth_fs_function); 666 f->descriptors = usb_copy_descriptors(ecm_fs_function);
667 if (!f->descriptors) 667 if (!f->descriptors)
668 goto fail; 668 goto fail;
669 669
670 ecm->fs.in = usb_find_endpoint(eth_fs_function, 670 ecm->fs.in = usb_find_endpoint(ecm_fs_function,
671 f->descriptors, &fs_in_desc); 671 f->descriptors, &fs_ecm_in_desc);
672 ecm->fs.out = usb_find_endpoint(eth_fs_function, 672 ecm->fs.out = usb_find_endpoint(ecm_fs_function,
673 f->descriptors, &fs_out_desc); 673 f->descriptors, &fs_ecm_out_desc);
674 ecm->fs.notify = usb_find_endpoint(eth_fs_function, 674 ecm->fs.notify = usb_find_endpoint(ecm_fs_function,
675 f->descriptors, &fs_notify_desc); 675 f->descriptors, &fs_ecm_notify_desc);
676 676
677 /* support all relevant hardware speeds... we expect that when 677 /* support all relevant hardware speeds... we expect that when
678 * hardware is dual speed, all bulk-capable endpoints work at 678 * hardware is dual speed, all bulk-capable endpoints work at
679 * both speeds 679 * both speeds
680 */ 680 */
681 if (gadget_is_dualspeed(c->cdev->gadget)) { 681 if (gadget_is_dualspeed(c->cdev->gadget)) {
682 hs_in_desc.bEndpointAddress = 682 hs_ecm_in_desc.bEndpointAddress =
683 fs_in_desc.bEndpointAddress; 683 fs_ecm_in_desc.bEndpointAddress;
684 hs_out_desc.bEndpointAddress = 684 hs_ecm_out_desc.bEndpointAddress =
685 fs_out_desc.bEndpointAddress; 685 fs_ecm_out_desc.bEndpointAddress;
686 hs_notify_desc.bEndpointAddress = 686 hs_ecm_notify_desc.bEndpointAddress =
687 fs_notify_desc.bEndpointAddress; 687 fs_ecm_notify_desc.bEndpointAddress;
688 688
689 /* copy descriptors, and track endpoint copies */ 689 /* copy descriptors, and track endpoint copies */
690 f->hs_descriptors = usb_copy_descriptors(eth_hs_function); 690 f->hs_descriptors = usb_copy_descriptors(ecm_hs_function);
691 if (!f->hs_descriptors) 691 if (!f->hs_descriptors)
692 goto fail; 692 goto fail;
693 693
694 ecm->hs.in = usb_find_endpoint(eth_hs_function, 694 ecm->hs.in = usb_find_endpoint(ecm_hs_function,
695 f->hs_descriptors, &hs_in_desc); 695 f->hs_descriptors, &hs_ecm_in_desc);
696 ecm->hs.out = usb_find_endpoint(eth_hs_function, 696 ecm->hs.out = usb_find_endpoint(ecm_hs_function,
697 f->hs_descriptors, &hs_out_desc); 697 f->hs_descriptors, &hs_ecm_out_desc);
698 ecm->hs.notify = usb_find_endpoint(eth_hs_function, 698 ecm->hs.notify = usb_find_endpoint(ecm_hs_function,
699 f->hs_descriptors, &hs_notify_desc); 699 f->hs_descriptors, &hs_ecm_notify_desc);
700 } 700 }
701 701
702 /* NOTE: all that is done without knowing or caring about 702 /* NOTE: all that is done without knowing or caring about
@@ -795,7 +795,7 @@ int __init ecm_bind_config(struct usb_configuration *c, u8 ethaddr[ETH_ALEN])
795 if (status < 0) 795 if (status < 0)
796 return status; 796 return status;
797 ecm_string_defs[1].id = status; 797 ecm_string_defs[1].id = status;
798 ether_desc.iMACAddress = status; 798 ecm_desc.iMACAddress = status;
799 } 799 }
800 800
801 /* allocate and initialize one new instance */ 801 /* allocate and initialize one new instance */
diff --git a/drivers/usb/gadget/f_loopback.c b/drivers/usb/gadget/f_loopback.c
index eda4cde72c82..87dde012dacc 100644
--- a/drivers/usb/gadget/f_loopback.c
+++ b/drivers/usb/gadget/f_loopback.c
@@ -70,7 +70,7 @@ static struct usb_interface_descriptor loopback_intf = {
70 70
71/* full speed support: */ 71/* full speed support: */
72 72
73static struct usb_endpoint_descriptor fs_source_desc = { 73static struct usb_endpoint_descriptor fs_loop_source_desc = {
74 .bLength = USB_DT_ENDPOINT_SIZE, 74 .bLength = USB_DT_ENDPOINT_SIZE,
75 .bDescriptorType = USB_DT_ENDPOINT, 75 .bDescriptorType = USB_DT_ENDPOINT,
76 76
@@ -78,7 +78,7 @@ static struct usb_endpoint_descriptor fs_source_desc = {
78 .bmAttributes = USB_ENDPOINT_XFER_BULK, 78 .bmAttributes = USB_ENDPOINT_XFER_BULK,
79}; 79};
80 80
81static struct usb_endpoint_descriptor fs_sink_desc = { 81static struct usb_endpoint_descriptor fs_loop_sink_desc = {
82 .bLength = USB_DT_ENDPOINT_SIZE, 82 .bLength = USB_DT_ENDPOINT_SIZE,
83 .bDescriptorType = USB_DT_ENDPOINT, 83 .bDescriptorType = USB_DT_ENDPOINT,
84 84
@@ -88,14 +88,14 @@ static struct usb_endpoint_descriptor fs_sink_desc = {
88 88
89static struct usb_descriptor_header *fs_loopback_descs[] = { 89static struct usb_descriptor_header *fs_loopback_descs[] = {
90 (struct usb_descriptor_header *) &loopback_intf, 90 (struct usb_descriptor_header *) &loopback_intf,
91 (struct usb_descriptor_header *) &fs_sink_desc, 91 (struct usb_descriptor_header *) &fs_loop_sink_desc,
92 (struct usb_descriptor_header *) &fs_source_desc, 92 (struct usb_descriptor_header *) &fs_loop_source_desc,
93 NULL, 93 NULL,
94}; 94};
95 95
96/* high speed support: */ 96/* high speed support: */
97 97
98static struct usb_endpoint_descriptor hs_source_desc = { 98static struct usb_endpoint_descriptor hs_loop_source_desc = {
99 .bLength = USB_DT_ENDPOINT_SIZE, 99 .bLength = USB_DT_ENDPOINT_SIZE,
100 .bDescriptorType = USB_DT_ENDPOINT, 100 .bDescriptorType = USB_DT_ENDPOINT,
101 101
@@ -103,7 +103,7 @@ static struct usb_endpoint_descriptor hs_source_desc = {
103 .wMaxPacketSize = __constant_cpu_to_le16(512), 103 .wMaxPacketSize = __constant_cpu_to_le16(512),
104}; 104};
105 105
106static struct usb_endpoint_descriptor hs_sink_desc = { 106static struct usb_endpoint_descriptor hs_loop_sink_desc = {
107 .bLength = USB_DT_ENDPOINT_SIZE, 107 .bLength = USB_DT_ENDPOINT_SIZE,
108 .bDescriptorType = USB_DT_ENDPOINT, 108 .bDescriptorType = USB_DT_ENDPOINT,
109 109
@@ -113,8 +113,8 @@ static struct usb_endpoint_descriptor hs_sink_desc = {
113 113
114static struct usb_descriptor_header *hs_loopback_descs[] = { 114static struct usb_descriptor_header *hs_loopback_descs[] = {
115 (struct usb_descriptor_header *) &loopback_intf, 115 (struct usb_descriptor_header *) &loopback_intf,
116 (struct usb_descriptor_header *) &hs_source_desc, 116 (struct usb_descriptor_header *) &hs_loop_source_desc,
117 (struct usb_descriptor_header *) &hs_sink_desc, 117 (struct usb_descriptor_header *) &hs_loop_sink_desc,
118 NULL, 118 NULL,
119}; 119};
120 120
@@ -152,7 +152,7 @@ loopback_bind(struct usb_configuration *c, struct usb_function *f)
152 152
153 /* allocate endpoints */ 153 /* allocate endpoints */
154 154
155 loop->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_source_desc); 155 loop->in_ep = usb_ep_autoconfig(cdev->gadget, &fs_loop_source_desc);
156 if (!loop->in_ep) { 156 if (!loop->in_ep) {
157autoconf_fail: 157autoconf_fail:
158 ERROR(cdev, "%s: can't autoconfigure on %s\n", 158 ERROR(cdev, "%s: can't autoconfigure on %s\n",
@@ -161,17 +161,17 @@ autoconf_fail:
161 } 161 }
162 loop->in_ep->driver_data = cdev; /* claim */ 162 loop->in_ep->driver_data = cdev; /* claim */
163 163
164 loop->out_ep = usb_ep_autoconfig(cdev->gadget, &fs_sink_desc); 164 loop->out_ep = usb_ep_autoconfig(cdev->gadget, &fs_loop_sink_desc);
165 if (!loop->out_ep) 165 if (!loop->out_ep)
166 goto autoconf_fail; 166 goto autoconf_fail;
167 loop->out_ep->driver_data = cdev; /* claim */ 167 loop->out_ep->driver_data = cdev; /* claim */
168 168
169 /* support high speed hardware */ 169 /* support high speed hardware */
170 if (gadget_is_dualspeed(c->cdev->gadget)) { 170 if (gadget_is_dualspeed(c->cdev->gadget)) {
171 hs_source_desc.bEndpointAddress = 171 hs_loop_source_desc.bEndpointAddress =
172 fs_source_desc.bEndpointAddress; 172 fs_loop_source_desc.bEndpointAddress;
173 hs_sink_desc.bEndpointAddress = 173 hs_loop_sink_desc.bEndpointAddress =
174 fs_sink_desc.bEndpointAddress; 174 fs_loop_sink_desc.bEndpointAddress;
175 f->hs_descriptors = hs_loopback_descs; 175 f->hs_descriptors = hs_loopback_descs;
176 } 176 }
177 177
@@ -255,8 +255,10 @@ enable_loopback(struct usb_composite_dev *cdev, struct f_loopback *loop)
255 struct usb_request *req; 255 struct usb_request *req;
256 unsigned i; 256 unsigned i;
257 257
258 src = ep_choose(cdev->gadget, &hs_source_desc, &fs_source_desc); 258 src = ep_choose(cdev->gadget,
259 sink = ep_choose(cdev->gadget, &hs_sink_desc, &fs_sink_desc); 259 &hs_loop_source_desc, &fs_loop_source_desc);
260 sink = ep_choose(cdev->gadget,
261 &hs_loop_sink_desc, &fs_loop_sink_desc);
260 262
261 /* one endpoint writes data back IN to the host */ 263 /* one endpoint writes data back IN to the host */
262 ep = loop->in_ep; 264 ep = loop->in_ep;
diff --git a/drivers/usb/gadget/f_subset.c b/drivers/usb/gadget/f_subset.c
index acb8d233aa1d..fe1832875771 100644
--- a/drivers/usb/gadget/f_subset.c
+++ b/drivers/usb/gadget/f_subset.c
@@ -103,8 +103,8 @@ static struct usb_interface_descriptor subset_data_intf __initdata = {
103 /* .iInterface = DYNAMIC */ 103 /* .iInterface = DYNAMIC */
104}; 104};
105 105
106static struct usb_cdc_header_desc header_desc __initdata = { 106static struct usb_cdc_header_desc mdlm_header_desc __initdata = {
107 .bLength = sizeof header_desc, 107 .bLength = sizeof mdlm_header_desc,
108 .bDescriptorType = USB_DT_CS_INTERFACE, 108 .bDescriptorType = USB_DT_CS_INTERFACE,
109 .bDescriptorSubType = USB_CDC_HEADER_TYPE, 109 .bDescriptorSubType = USB_CDC_HEADER_TYPE,
110 110
@@ -152,7 +152,7 @@ static struct usb_cdc_ether_desc ether_desc __initdata = {
152 152
153/* full speed support: */ 153/* full speed support: */
154 154
155static struct usb_endpoint_descriptor fs_in_desc __initdata = { 155static struct usb_endpoint_descriptor fs_subset_in_desc __initdata = {
156 .bLength = USB_DT_ENDPOINT_SIZE, 156 .bLength = USB_DT_ENDPOINT_SIZE,
157 .bDescriptorType = USB_DT_ENDPOINT, 157 .bDescriptorType = USB_DT_ENDPOINT,
158 158
@@ -160,7 +160,7 @@ static struct usb_endpoint_descriptor fs_in_desc __initdata = {
160 .bmAttributes = USB_ENDPOINT_XFER_BULK, 160 .bmAttributes = USB_ENDPOINT_XFER_BULK,
161}; 161};
162 162
163static struct usb_endpoint_descriptor fs_out_desc __initdata = { 163static struct usb_endpoint_descriptor fs_subset_out_desc __initdata = {
164 .bLength = USB_DT_ENDPOINT_SIZE, 164 .bLength = USB_DT_ENDPOINT_SIZE,
165 .bDescriptorType = USB_DT_ENDPOINT, 165 .bDescriptorType = USB_DT_ENDPOINT,
166 166
@@ -170,18 +170,18 @@ static struct usb_endpoint_descriptor fs_out_desc __initdata = {
170 170
171static struct usb_descriptor_header *fs_eth_function[] __initdata = { 171static struct usb_descriptor_header *fs_eth_function[] __initdata = {
172 (struct usb_descriptor_header *) &subset_data_intf, 172 (struct usb_descriptor_header *) &subset_data_intf,
173 (struct usb_descriptor_header *) &header_desc, 173 (struct usb_descriptor_header *) &mdlm_header_desc,
174 (struct usb_descriptor_header *) &mdlm_desc, 174 (struct usb_descriptor_header *) &mdlm_desc,
175 (struct usb_descriptor_header *) &mdlm_detail_desc, 175 (struct usb_descriptor_header *) &mdlm_detail_desc,
176 (struct usb_descriptor_header *) &ether_desc, 176 (struct usb_descriptor_header *) &ether_desc,
177 (struct usb_descriptor_header *) &fs_in_desc, 177 (struct usb_descriptor_header *) &fs_subset_in_desc,
178 (struct usb_descriptor_header *) &fs_out_desc, 178 (struct usb_descriptor_header *) &fs_subset_out_desc,
179 NULL, 179 NULL,
180}; 180};
181 181
182/* high speed support: */ 182/* high speed support: */
183 183
184static struct usb_endpoint_descriptor hs_in_desc __initdata = { 184static struct usb_endpoint_descriptor hs_subset_in_desc __initdata = {
185 .bLength = USB_DT_ENDPOINT_SIZE, 185 .bLength = USB_DT_ENDPOINT_SIZE,
186 .bDescriptorType = USB_DT_ENDPOINT, 186 .bDescriptorType = USB_DT_ENDPOINT,
187 187
@@ -189,7 +189,7 @@ static struct usb_endpoint_descriptor hs_in_desc __initdata = {
189 .wMaxPacketSize = __constant_cpu_to_le16(512), 189 .wMaxPacketSize = __constant_cpu_to_le16(512),
190}; 190};
191 191
192static struct usb_endpoint_descriptor hs_out_desc __initdata = { 192static struct usb_endpoint_descriptor hs_subset_out_desc __initdata = {
193 .bLength = USB_DT_ENDPOINT_SIZE, 193 .bLength = USB_DT_ENDPOINT_SIZE,
194 .bDescriptorType = USB_DT_ENDPOINT, 194 .bDescriptorType = USB_DT_ENDPOINT,
195 195
@@ -199,12 +199,12 @@ static struct usb_endpoint_descriptor hs_out_desc __initdata = {
199 199
200static struct usb_descriptor_header *hs_eth_function[] __initdata = { 200static struct usb_descriptor_header *hs_eth_function[] __initdata = {
201 (struct usb_descriptor_header *) &subset_data_intf, 201 (struct usb_descriptor_header *) &subset_data_intf,
202 (struct usb_descriptor_header *) &header_desc, 202 (struct usb_descriptor_header *) &mdlm_header_desc,
203 (struct usb_descriptor_header *) &mdlm_desc, 203 (struct usb_descriptor_header *) &mdlm_desc,
204 (struct usb_descriptor_header *) &mdlm_detail_desc, 204 (struct usb_descriptor_header *) &mdlm_detail_desc,
205 (struct usb_descriptor_header *) &ether_desc, 205 (struct usb_descriptor_header *) &ether_desc,
206 (struct usb_descriptor_header *) &hs_in_desc, 206 (struct usb_descriptor_header *) &hs_subset_in_desc,
207 (struct usb_descriptor_header *) &hs_out_desc, 207 (struct usb_descriptor_header *) &hs_subset_out_desc,
208 NULL, 208 NULL,
209}; 209};
210 210
@@ -281,13 +281,13 @@ geth_bind(struct usb_configuration *c, struct usb_function *f)
281 status = -ENODEV; 281 status = -ENODEV;
282 282
283 /* allocate instance-specific endpoints */ 283 /* allocate instance-specific endpoints */
284 ep = usb_ep_autoconfig(cdev->gadget, &fs_in_desc); 284 ep = usb_ep_autoconfig(cdev->gadget, &fs_subset_in_desc);
285 if (!ep) 285 if (!ep)
286 goto fail; 286 goto fail;
287 geth->port.in_ep = ep; 287 geth->port.in_ep = ep;
288 ep->driver_data = cdev; /* claim */ 288 ep->driver_data = cdev; /* claim */
289 289
290 ep = usb_ep_autoconfig(cdev->gadget, &fs_out_desc); 290 ep = usb_ep_autoconfig(cdev->gadget, &fs_subset_out_desc);
291 if (!ep) 291 if (!ep)
292 goto fail; 292 goto fail;
293 geth->port.out_ep = ep; 293 geth->port.out_ep = ep;
@@ -297,9 +297,9 @@ geth_bind(struct usb_configuration *c, struct usb_function *f)
297 f->descriptors = usb_copy_descriptors(fs_eth_function); 297 f->descriptors = usb_copy_descriptors(fs_eth_function);
298 298
299 geth->fs.in = usb_find_endpoint(fs_eth_function, 299 geth->fs.in = usb_find_endpoint(fs_eth_function,
300 f->descriptors, &fs_in_desc); 300 f->descriptors, &fs_subset_in_desc);
301 geth->fs.out = usb_find_endpoint(fs_eth_function, 301 geth->fs.out = usb_find_endpoint(fs_eth_function,
302 f->descriptors, &fs_out_desc); 302 f->descriptors, &fs_subset_out_desc);
303 303
304 304
305 /* support all relevant hardware speeds... we expect that when 305 /* support all relevant hardware speeds... we expect that when
@@ -307,18 +307,18 @@ geth_bind(struct usb_configuration *c, struct usb_function *f)
307 * both speeds 307 * both speeds
308 */ 308 */
309 if (gadget_is_dualspeed(c->cdev->gadget)) { 309 if (gadget_is_dualspeed(c->cdev->gadget)) {
310 hs_in_desc.bEndpointAddress = 310 hs_subset_in_desc.bEndpointAddress =
311 fs_in_desc.bEndpointAddress; 311 fs_subset_in_desc.bEndpointAddress;
312 hs_out_desc.bEndpointAddress = 312 hs_subset_out_desc.bEndpointAddress =
313 fs_out_desc.bEndpointAddress; 313 fs_subset_out_desc.bEndpointAddress;
314 314
315 /* copy descriptors, and track endpoint copies */ 315 /* copy descriptors, and track endpoint copies */
316 f->hs_descriptors = usb_copy_descriptors(hs_eth_function); 316 f->hs_descriptors = usb_copy_descriptors(hs_eth_function);
317 317
318 geth->hs.in = usb_find_endpoint(hs_eth_function, 318 geth->hs.in = usb_find_endpoint(hs_eth_function,
319 f->hs_descriptors, &hs_in_desc); 319 f->hs_descriptors, &hs_subset_in_desc);
320 geth->hs.out = usb_find_endpoint(hs_eth_function, 320 geth->hs.out = usb_find_endpoint(hs_eth_function,
321 f->hs_descriptors, &hs_out_desc); 321 f->hs_descriptors, &hs_subset_out_desc);
322 } 322 }
323 323
324 /* NOTE: all that is done without knowing or caring about 324 /* NOTE: all that is done without knowing or caring about
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index ea2c31d18080..0c632d22a631 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -245,6 +245,18 @@
245#include "gadget_chips.h" 245#include "gadget_chips.h"
246 246
247 247
248
249/*
250 * Kbuild is not very cooperative with respect to linking separately
251 * compiled library objects into one module. So for now we won't use
252 * separate compilation ... ensuring init/exit sections work to shrink
253 * the runtime footprint, and giving us at least some parts of what
254 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
255 */
256#include "usbstring.c"
257#include "config.c"
258#include "epautoconf.c"
259
248/*-------------------------------------------------------------------------*/ 260/*-------------------------------------------------------------------------*/
249 261
250#define DRIVER_DESC "File-backed Storage Gadget" 262#define DRIVER_DESC "File-backed Storage Gadget"
diff --git a/drivers/usb/gadget/gmidi.c b/drivers/usb/gadget/gmidi.c
index ea8651e3da1a..6eee760410d6 100644
--- a/drivers/usb/gadget/gmidi.c
+++ b/drivers/usb/gadget/gmidi.c
@@ -35,6 +35,21 @@
35 35
36#include "gadget_chips.h" 36#include "gadget_chips.h"
37 37
38
39/*
40 * Kbuild is not very cooperative with respect to linking separately
41 * compiled library objects into one module. So for now we won't use
42 * separate compilation ... ensuring init/exit sections work to shrink
43 * the runtime footprint, and giving us at least some parts of what
44 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
45 */
46#include "usbstring.c"
47#include "config.c"
48#include "epautoconf.c"
49
50/*-------------------------------------------------------------------------*/
51
52
38MODULE_AUTHOR("Ben Williamson"); 53MODULE_AUTHOR("Ben Williamson");
39MODULE_LICENSE("GPL v2"); 54MODULE_LICENSE("GPL v2");
40 55
diff --git a/drivers/usb/gadget/printer.c b/drivers/usb/gadget/printer.c
index e0090085b78e..2b3b9e1dd2ee 100644
--- a/drivers/usb/gadget/printer.c
+++ b/drivers/usb/gadget/printer.c
@@ -53,6 +53,20 @@
53 53
54#include "gadget_chips.h" 54#include "gadget_chips.h"
55 55
56
57/*
58 * Kbuild is not very cooperative with respect to linking separately
59 * compiled library objects into one module. So for now we won't use
60 * separate compilation ... ensuring init/exit sections work to shrink
61 * the runtime footprint, and giving us at least some parts of what
62 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
63 */
64#include "usbstring.c"
65#include "config.c"
66#include "epautoconf.c"
67
68/*-------------------------------------------------------------------------*/
69
56#define DRIVER_DESC "Printer Gadget" 70#define DRIVER_DESC "Printer Gadget"
57#define DRIVER_VERSION "2007 OCT 06" 71#define DRIVER_VERSION "2007 OCT 06"
58 72
@@ -1360,8 +1374,8 @@ printer_bind(struct usb_gadget *gadget)
1360 1374
1361 1375
1362 /* Setup the sysfs files for the printer gadget. */ 1376 /* Setup the sysfs files for the printer gadget. */
1363 dev->pdev = device_create_drvdata(usb_gadget_class, NULL, 1377 dev->pdev = device_create(usb_gadget_class, NULL, g_printer_devno,
1364 g_printer_devno, NULL, "g_printer"); 1378 NULL, "g_printer");
1365 if (IS_ERR(dev->pdev)) { 1379 if (IS_ERR(dev->pdev)) {
1366 ERROR(dev, "Failed to create device: g_printer\n"); 1380 ERROR(dev, "Failed to create device: g_printer\n");
1367 goto fail; 1381 goto fail;
diff --git a/drivers/usb/gadget/rndis.c b/drivers/usb/gadget/rndis.c
index 7228e8562236..8c26f5ea2b83 100644
--- a/drivers/usb/gadget/rndis.c
+++ b/drivers/usb/gadget/rndis.c
@@ -57,11 +57,6 @@ MODULE_PARM_DESC (rndis_debug, "enable debugging");
57#define rndis_debug 0 57#define rndis_debug 0
58#endif 58#endif
59 59
60#define DBG(str,args...) do { \
61 if (rndis_debug) \
62 pr_debug(str , ## args); \
63 } while (0)
64
65#define RNDIS_MAX_CONFIGS 1 60#define RNDIS_MAX_CONFIGS 1
66 61
67 62
@@ -183,9 +178,9 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
183 if (!resp) return -ENOMEM; 178 if (!resp) return -ENOMEM;
184 179
185 if (buf_len && rndis_debug > 1) { 180 if (buf_len && rndis_debug > 1) {
186 DBG("query OID %08x value, len %d:\n", OID, buf_len); 181 pr_debug("query OID %08x value, len %d:\n", OID, buf_len);
187 for (i = 0; i < buf_len; i += 16) { 182 for (i = 0; i < buf_len; i += 16) {
188 DBG("%03d: %08x %08x %08x %08x\n", i, 183 pr_debug("%03d: %08x %08x %08x %08x\n", i,
189 get_unaligned_le32(&buf[i]), 184 get_unaligned_le32(&buf[i]),
190 get_unaligned_le32(&buf[i + 4]), 185 get_unaligned_le32(&buf[i + 4]),
191 get_unaligned_le32(&buf[i + 8]), 186 get_unaligned_le32(&buf[i + 8]),
@@ -209,7 +204,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
209 204
210 /* mandatory */ 205 /* mandatory */
211 case OID_GEN_SUPPORTED_LIST: 206 case OID_GEN_SUPPORTED_LIST:
212 DBG("%s: OID_GEN_SUPPORTED_LIST\n", __func__); 207 pr_debug("%s: OID_GEN_SUPPORTED_LIST\n", __func__);
213 length = sizeof (oid_supported_list); 208 length = sizeof (oid_supported_list);
214 count = length / sizeof (u32); 209 count = length / sizeof (u32);
215 for (i = 0; i < count; i++) 210 for (i = 0; i < count; i++)
@@ -219,7 +214,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
219 214
220 /* mandatory */ 215 /* mandatory */
221 case OID_GEN_HARDWARE_STATUS: 216 case OID_GEN_HARDWARE_STATUS:
222 DBG("%s: OID_GEN_HARDWARE_STATUS\n", __func__); 217 pr_debug("%s: OID_GEN_HARDWARE_STATUS\n", __func__);
223 /* Bogus question! 218 /* Bogus question!
224 * Hardware must be ready to receive high level protocols. 219 * Hardware must be ready to receive high level protocols.
225 * BTW: 220 * BTW:
@@ -232,14 +227,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
232 227
233 /* mandatory */ 228 /* mandatory */
234 case OID_GEN_MEDIA_SUPPORTED: 229 case OID_GEN_MEDIA_SUPPORTED:
235 DBG("%s: OID_GEN_MEDIA_SUPPORTED\n", __func__); 230 pr_debug("%s: OID_GEN_MEDIA_SUPPORTED\n", __func__);
236 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); 231 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
237 retval = 0; 232 retval = 0;
238 break; 233 break;
239 234
240 /* mandatory */ 235 /* mandatory */
241 case OID_GEN_MEDIA_IN_USE: 236 case OID_GEN_MEDIA_IN_USE:
242 DBG("%s: OID_GEN_MEDIA_IN_USE\n", __func__); 237 pr_debug("%s: OID_GEN_MEDIA_IN_USE\n", __func__);
243 /* one medium, one transport... (maybe you do it better) */ 238 /* one medium, one transport... (maybe you do it better) */
244 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium); 239 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr].medium);
245 retval = 0; 240 retval = 0;
@@ -247,7 +242,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
247 242
248 /* mandatory */ 243 /* mandatory */
249 case OID_GEN_MAXIMUM_FRAME_SIZE: 244 case OID_GEN_MAXIMUM_FRAME_SIZE:
250 DBG("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__); 245 pr_debug("%s: OID_GEN_MAXIMUM_FRAME_SIZE\n", __func__);
251 if (rndis_per_dev_params [configNr].dev) { 246 if (rndis_per_dev_params [configNr].dev) {
252 *outbuf = cpu_to_le32 ( 247 *outbuf = cpu_to_le32 (
253 rndis_per_dev_params [configNr].dev->mtu); 248 rndis_per_dev_params [configNr].dev->mtu);
@@ -258,7 +253,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
258 /* mandatory */ 253 /* mandatory */
259 case OID_GEN_LINK_SPEED: 254 case OID_GEN_LINK_SPEED:
260 if (rndis_debug > 1) 255 if (rndis_debug > 1)
261 DBG("%s: OID_GEN_LINK_SPEED\n", __func__); 256 pr_debug("%s: OID_GEN_LINK_SPEED\n", __func__);
262 if (rndis_per_dev_params [configNr].media_state 257 if (rndis_per_dev_params [configNr].media_state
263 == NDIS_MEDIA_STATE_DISCONNECTED) 258 == NDIS_MEDIA_STATE_DISCONNECTED)
264 *outbuf = __constant_cpu_to_le32 (0); 259 *outbuf = __constant_cpu_to_le32 (0);
@@ -270,7 +265,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
270 265
271 /* mandatory */ 266 /* mandatory */
272 case OID_GEN_TRANSMIT_BLOCK_SIZE: 267 case OID_GEN_TRANSMIT_BLOCK_SIZE:
273 DBG("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__); 268 pr_debug("%s: OID_GEN_TRANSMIT_BLOCK_SIZE\n", __func__);
274 if (rndis_per_dev_params [configNr].dev) { 269 if (rndis_per_dev_params [configNr].dev) {
275 *outbuf = cpu_to_le32 ( 270 *outbuf = cpu_to_le32 (
276 rndis_per_dev_params [configNr].dev->mtu); 271 rndis_per_dev_params [configNr].dev->mtu);
@@ -280,7 +275,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
280 275
281 /* mandatory */ 276 /* mandatory */
282 case OID_GEN_RECEIVE_BLOCK_SIZE: 277 case OID_GEN_RECEIVE_BLOCK_SIZE:
283 DBG("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__); 278 pr_debug("%s: OID_GEN_RECEIVE_BLOCK_SIZE\n", __func__);
284 if (rndis_per_dev_params [configNr].dev) { 279 if (rndis_per_dev_params [configNr].dev) {
285 *outbuf = cpu_to_le32 ( 280 *outbuf = cpu_to_le32 (
286 rndis_per_dev_params [configNr].dev->mtu); 281 rndis_per_dev_params [configNr].dev->mtu);
@@ -290,7 +285,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
290 285
291 /* mandatory */ 286 /* mandatory */
292 case OID_GEN_VENDOR_ID: 287 case OID_GEN_VENDOR_ID:
293 DBG("%s: OID_GEN_VENDOR_ID\n", __func__); 288 pr_debug("%s: OID_GEN_VENDOR_ID\n", __func__);
294 *outbuf = cpu_to_le32 ( 289 *outbuf = cpu_to_le32 (
295 rndis_per_dev_params [configNr].vendorID); 290 rndis_per_dev_params [configNr].vendorID);
296 retval = 0; 291 retval = 0;
@@ -298,7 +293,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
298 293
299 /* mandatory */ 294 /* mandatory */
300 case OID_GEN_VENDOR_DESCRIPTION: 295 case OID_GEN_VENDOR_DESCRIPTION:
301 DBG("%s: OID_GEN_VENDOR_DESCRIPTION\n", __func__); 296 pr_debug("%s: OID_GEN_VENDOR_DESCRIPTION\n", __func__);
302 length = strlen (rndis_per_dev_params [configNr].vendorDescr); 297 length = strlen (rndis_per_dev_params [configNr].vendorDescr);
303 memcpy (outbuf, 298 memcpy (outbuf,
304 rndis_per_dev_params [configNr].vendorDescr, length); 299 rndis_per_dev_params [configNr].vendorDescr, length);
@@ -306,7 +301,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
306 break; 301 break;
307 302
308 case OID_GEN_VENDOR_DRIVER_VERSION: 303 case OID_GEN_VENDOR_DRIVER_VERSION:
309 DBG("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __func__); 304 pr_debug("%s: OID_GEN_VENDOR_DRIVER_VERSION\n", __func__);
310 /* Created as LE */ 305 /* Created as LE */
311 *outbuf = rndis_driver_version; 306 *outbuf = rndis_driver_version;
312 retval = 0; 307 retval = 0;
@@ -314,14 +309,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
314 309
315 /* mandatory */ 310 /* mandatory */
316 case OID_GEN_CURRENT_PACKET_FILTER: 311 case OID_GEN_CURRENT_PACKET_FILTER:
317 DBG("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __func__); 312 pr_debug("%s: OID_GEN_CURRENT_PACKET_FILTER\n", __func__);
318 *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter); 313 *outbuf = cpu_to_le32 (*rndis_per_dev_params[configNr].filter);
319 retval = 0; 314 retval = 0;
320 break; 315 break;
321 316
322 /* mandatory */ 317 /* mandatory */
323 case OID_GEN_MAXIMUM_TOTAL_SIZE: 318 case OID_GEN_MAXIMUM_TOTAL_SIZE:
324 DBG("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __func__); 319 pr_debug("%s: OID_GEN_MAXIMUM_TOTAL_SIZE\n", __func__);
325 *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE); 320 *outbuf = __constant_cpu_to_le32(RNDIS_MAX_TOTAL_SIZE);
326 retval = 0; 321 retval = 0;
327 break; 322 break;
@@ -329,14 +324,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
329 /* mandatory */ 324 /* mandatory */
330 case OID_GEN_MEDIA_CONNECT_STATUS: 325 case OID_GEN_MEDIA_CONNECT_STATUS:
331 if (rndis_debug > 1) 326 if (rndis_debug > 1)
332 DBG("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __func__); 327 pr_debug("%s: OID_GEN_MEDIA_CONNECT_STATUS\n", __func__);
333 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr] 328 *outbuf = cpu_to_le32 (rndis_per_dev_params [configNr]
334 .media_state); 329 .media_state);
335 retval = 0; 330 retval = 0;
336 break; 331 break;
337 332
338 case OID_GEN_PHYSICAL_MEDIUM: 333 case OID_GEN_PHYSICAL_MEDIUM:
339 DBG("%s: OID_GEN_PHYSICAL_MEDIUM\n", __func__); 334 pr_debug("%s: OID_GEN_PHYSICAL_MEDIUM\n", __func__);
340 *outbuf = __constant_cpu_to_le32 (0); 335 *outbuf = __constant_cpu_to_le32 (0);
341 retval = 0; 336 retval = 0;
342 break; 337 break;
@@ -346,7 +341,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
346 * versions emit undefined RNDIS messages. DOCUMENT ALL THESE! 341 * versions emit undefined RNDIS messages. DOCUMENT ALL THESE!
347 */ 342 */
348 case OID_GEN_MAC_OPTIONS: /* from WinME */ 343 case OID_GEN_MAC_OPTIONS: /* from WinME */
349 DBG("%s: OID_GEN_MAC_OPTIONS\n", __func__); 344 pr_debug("%s: OID_GEN_MAC_OPTIONS\n", __func__);
350 *outbuf = __constant_cpu_to_le32( 345 *outbuf = __constant_cpu_to_le32(
351 NDIS_MAC_OPTION_RECEIVE_SERIALIZED 346 NDIS_MAC_OPTION_RECEIVE_SERIALIZED
352 | NDIS_MAC_OPTION_FULL_DUPLEX); 347 | NDIS_MAC_OPTION_FULL_DUPLEX);
@@ -358,7 +353,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
358 /* mandatory */ 353 /* mandatory */
359 case OID_GEN_XMIT_OK: 354 case OID_GEN_XMIT_OK:
360 if (rndis_debug > 1) 355 if (rndis_debug > 1)
361 DBG("%s: OID_GEN_XMIT_OK\n", __func__); 356 pr_debug("%s: OID_GEN_XMIT_OK\n", __func__);
362 if (stats) { 357 if (stats) {
363 *outbuf = cpu_to_le32(stats->tx_packets 358 *outbuf = cpu_to_le32(stats->tx_packets
364 - stats->tx_errors - stats->tx_dropped); 359 - stats->tx_errors - stats->tx_dropped);
@@ -369,7 +364,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
369 /* mandatory */ 364 /* mandatory */
370 case OID_GEN_RCV_OK: 365 case OID_GEN_RCV_OK:
371 if (rndis_debug > 1) 366 if (rndis_debug > 1)
372 DBG("%s: OID_GEN_RCV_OK\n", __func__); 367 pr_debug("%s: OID_GEN_RCV_OK\n", __func__);
373 if (stats) { 368 if (stats) {
374 *outbuf = cpu_to_le32(stats->rx_packets 369 *outbuf = cpu_to_le32(stats->rx_packets
375 - stats->rx_errors - stats->rx_dropped); 370 - stats->rx_errors - stats->rx_dropped);
@@ -380,7 +375,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
380 /* mandatory */ 375 /* mandatory */
381 case OID_GEN_XMIT_ERROR: 376 case OID_GEN_XMIT_ERROR:
382 if (rndis_debug > 1) 377 if (rndis_debug > 1)
383 DBG("%s: OID_GEN_XMIT_ERROR\n", __func__); 378 pr_debug("%s: OID_GEN_XMIT_ERROR\n", __func__);
384 if (stats) { 379 if (stats) {
385 *outbuf = cpu_to_le32(stats->tx_errors); 380 *outbuf = cpu_to_le32(stats->tx_errors);
386 retval = 0; 381 retval = 0;
@@ -390,7 +385,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
390 /* mandatory */ 385 /* mandatory */
391 case OID_GEN_RCV_ERROR: 386 case OID_GEN_RCV_ERROR:
392 if (rndis_debug > 1) 387 if (rndis_debug > 1)
393 DBG("%s: OID_GEN_RCV_ERROR\n", __func__); 388 pr_debug("%s: OID_GEN_RCV_ERROR\n", __func__);
394 if (stats) { 389 if (stats) {
395 *outbuf = cpu_to_le32(stats->rx_errors); 390 *outbuf = cpu_to_le32(stats->rx_errors);
396 retval = 0; 391 retval = 0;
@@ -399,7 +394,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
399 394
400 /* mandatory */ 395 /* mandatory */
401 case OID_GEN_RCV_NO_BUFFER: 396 case OID_GEN_RCV_NO_BUFFER:
402 DBG("%s: OID_GEN_RCV_NO_BUFFER\n", __func__); 397 pr_debug("%s: OID_GEN_RCV_NO_BUFFER\n", __func__);
403 if (stats) { 398 if (stats) {
404 *outbuf = cpu_to_le32(stats->rx_dropped); 399 *outbuf = cpu_to_le32(stats->rx_dropped);
405 retval = 0; 400 retval = 0;
@@ -410,7 +405,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
410 405
411 /* mandatory */ 406 /* mandatory */
412 case OID_802_3_PERMANENT_ADDRESS: 407 case OID_802_3_PERMANENT_ADDRESS:
413 DBG("%s: OID_802_3_PERMANENT_ADDRESS\n", __func__); 408 pr_debug("%s: OID_802_3_PERMANENT_ADDRESS\n", __func__);
414 if (rndis_per_dev_params [configNr].dev) { 409 if (rndis_per_dev_params [configNr].dev) {
415 length = ETH_ALEN; 410 length = ETH_ALEN;
416 memcpy (outbuf, 411 memcpy (outbuf,
@@ -422,7 +417,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
422 417
423 /* mandatory */ 418 /* mandatory */
424 case OID_802_3_CURRENT_ADDRESS: 419 case OID_802_3_CURRENT_ADDRESS:
425 DBG("%s: OID_802_3_CURRENT_ADDRESS\n", __func__); 420 pr_debug("%s: OID_802_3_CURRENT_ADDRESS\n", __func__);
426 if (rndis_per_dev_params [configNr].dev) { 421 if (rndis_per_dev_params [configNr].dev) {
427 length = ETH_ALEN; 422 length = ETH_ALEN;
428 memcpy (outbuf, 423 memcpy (outbuf,
@@ -434,7 +429,7 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
434 429
435 /* mandatory */ 430 /* mandatory */
436 case OID_802_3_MULTICAST_LIST: 431 case OID_802_3_MULTICAST_LIST:
437 DBG("%s: OID_802_3_MULTICAST_LIST\n", __func__); 432 pr_debug("%s: OID_802_3_MULTICAST_LIST\n", __func__);
438 /* Multicast base address only */ 433 /* Multicast base address only */
439 *outbuf = __constant_cpu_to_le32 (0xE0000000); 434 *outbuf = __constant_cpu_to_le32 (0xE0000000);
440 retval = 0; 435 retval = 0;
@@ -442,21 +437,21 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
442 437
443 /* mandatory */ 438 /* mandatory */
444 case OID_802_3_MAXIMUM_LIST_SIZE: 439 case OID_802_3_MAXIMUM_LIST_SIZE:
445 DBG("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __func__); 440 pr_debug("%s: OID_802_3_MAXIMUM_LIST_SIZE\n", __func__);
446 /* Multicast base address only */ 441 /* Multicast base address only */
447 *outbuf = __constant_cpu_to_le32 (1); 442 *outbuf = __constant_cpu_to_le32 (1);
448 retval = 0; 443 retval = 0;
449 break; 444 break;
450 445
451 case OID_802_3_MAC_OPTIONS: 446 case OID_802_3_MAC_OPTIONS:
452 DBG("%s: OID_802_3_MAC_OPTIONS\n", __func__); 447 pr_debug("%s: OID_802_3_MAC_OPTIONS\n", __func__);
453 break; 448 break;
454 449
455 /* ieee802.3 statistics OIDs (table 4-4) */ 450 /* ieee802.3 statistics OIDs (table 4-4) */
456 451
457 /* mandatory */ 452 /* mandatory */
458 case OID_802_3_RCV_ERROR_ALIGNMENT: 453 case OID_802_3_RCV_ERROR_ALIGNMENT:
459 DBG("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__); 454 pr_debug("%s: OID_802_3_RCV_ERROR_ALIGNMENT\n", __func__);
460 if (stats) { 455 if (stats) {
461 *outbuf = cpu_to_le32(stats->rx_frame_errors); 456 *outbuf = cpu_to_le32(stats->rx_frame_errors);
462 retval = 0; 457 retval = 0;
@@ -465,14 +460,14 @@ gen_ndis_query_resp (int configNr, u32 OID, u8 *buf, unsigned buf_len,
465 460
466 /* mandatory */ 461 /* mandatory */
467 case OID_802_3_XMIT_ONE_COLLISION: 462 case OID_802_3_XMIT_ONE_COLLISION:
468 DBG("%s: OID_802_3_XMIT_ONE_COLLISION\n", __func__); 463 pr_debug("%s: OID_802_3_XMIT_ONE_COLLISION\n", __func__);
469 *outbuf = __constant_cpu_to_le32 (0); 464 *outbuf = __constant_cpu_to_le32 (0);
470 retval = 0; 465 retval = 0;
471 break; 466 break;
472 467
473 /* mandatory */ 468 /* mandatory */
474 case OID_802_3_XMIT_MORE_COLLISIONS: 469 case OID_802_3_XMIT_MORE_COLLISIONS:
475 DBG("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __func__); 470 pr_debug("%s: OID_802_3_XMIT_MORE_COLLISIONS\n", __func__);
476 *outbuf = __constant_cpu_to_le32 (0); 471 *outbuf = __constant_cpu_to_le32 (0);
477 retval = 0; 472 retval = 0;
478 break; 473 break;
@@ -504,9 +499,9 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
504 return -ENOMEM; 499 return -ENOMEM;
505 500
506 if (buf_len && rndis_debug > 1) { 501 if (buf_len && rndis_debug > 1) {
507 DBG("set OID %08x value, len %d:\n", OID, buf_len); 502 pr_debug("set OID %08x value, len %d:\n", OID, buf_len);
508 for (i = 0; i < buf_len; i += 16) { 503 for (i = 0; i < buf_len; i += 16) {
509 DBG("%03d: %08x %08x %08x %08x\n", i, 504 pr_debug("%03d: %08x %08x %08x %08x\n", i,
510 get_unaligned_le32(&buf[i]), 505 get_unaligned_le32(&buf[i]),
511 get_unaligned_le32(&buf[i + 4]), 506 get_unaligned_le32(&buf[i + 4]),
512 get_unaligned_le32(&buf[i + 8]), 507 get_unaligned_le32(&buf[i + 8]),
@@ -525,7 +520,7 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
525 * MULTICAST, ALL_MULTICAST, BROADCAST 520 * MULTICAST, ALL_MULTICAST, BROADCAST
526 */ 521 */
527 *params->filter = (u16)get_unaligned_le32(buf); 522 *params->filter = (u16)get_unaligned_le32(buf);
528 DBG("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n", 523 pr_debug("%s: OID_GEN_CURRENT_PACKET_FILTER %08x\n",
529 __func__, *params->filter); 524 __func__, *params->filter);
530 525
531 /* this call has a significant side effect: it's 526 /* this call has a significant side effect: it's
@@ -547,7 +542,7 @@ static int gen_ndis_set_resp (u8 configNr, u32 OID, u8 *buf, u32 buf_len,
547 542
548 case OID_802_3_MULTICAST_LIST: 543 case OID_802_3_MULTICAST_LIST:
549 /* I think we can ignore this */ 544 /* I think we can ignore this */
550 DBG("%s: OID_802_3_MULTICAST_LIST\n", __func__); 545 pr_debug("%s: OID_802_3_MULTICAST_LIST\n", __func__);
551 retval = 0; 546 retval = 0;
552 break; 547 break;
553 548
@@ -606,7 +601,7 @@ static int rndis_query_response (int configNr, rndis_query_msg_type *buf)
606 rndis_resp_t *r; 601 rndis_resp_t *r;
607 struct rndis_params *params = rndis_per_dev_params + configNr; 602 struct rndis_params *params = rndis_per_dev_params + configNr;
608 603
609 // DBG("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); 604 /* pr_debug("%s: OID = %08X\n", __func__, cpu_to_le32(buf->OID)); */
610 if (!params->dev) 605 if (!params->dev)
611 return -ENOTSUPP; 606 return -ENOTSUPP;
612 607
@@ -659,15 +654,15 @@ static int rndis_set_response (int configNr, rndis_set_msg_type *buf)
659 BufOffset = le32_to_cpu (buf->InformationBufferOffset); 654 BufOffset = le32_to_cpu (buf->InformationBufferOffset);
660 655
661#ifdef VERBOSE_DEBUG 656#ifdef VERBOSE_DEBUG
662 DBG("%s: Length: %d\n", __func__, BufLength); 657 pr_debug("%s: Length: %d\n", __func__, BufLength);
663 DBG("%s: Offset: %d\n", __func__, BufOffset); 658 pr_debug("%s: Offset: %d\n", __func__, BufOffset);
664 DBG("%s: InfoBuffer: ", __func__); 659 pr_debug("%s: InfoBuffer: ", __func__);
665 660
666 for (i = 0; i < BufLength; i++) { 661 for (i = 0; i < BufLength; i++) {
667 DBG("%02x ", *(((u8 *) buf) + i + 8 + BufOffset)); 662 pr_debug("%02x ", *(((u8 *) buf) + i + 8 + BufOffset));
668 } 663 }
669 664
670 DBG("\n"); 665 pr_debug("\n");
671#endif 666#endif
672 667
673 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_SET_CMPLT); 668 resp->MessageType = __constant_cpu_to_le32 (REMOTE_NDIS_SET_CMPLT);
@@ -821,14 +816,14 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
821 /* For USB: responses may take up to 10 seconds */ 816 /* For USB: responses may take up to 10 seconds */
822 switch (MsgType) { 817 switch (MsgType) {
823 case REMOTE_NDIS_INITIALIZE_MSG: 818 case REMOTE_NDIS_INITIALIZE_MSG:
824 DBG("%s: REMOTE_NDIS_INITIALIZE_MSG\n", 819 pr_debug("%s: REMOTE_NDIS_INITIALIZE_MSG\n",
825 __func__ ); 820 __func__ );
826 params->state = RNDIS_INITIALIZED; 821 params->state = RNDIS_INITIALIZED;
827 return rndis_init_response (configNr, 822 return rndis_init_response (configNr,
828 (rndis_init_msg_type *) buf); 823 (rndis_init_msg_type *) buf);
829 824
830 case REMOTE_NDIS_HALT_MSG: 825 case REMOTE_NDIS_HALT_MSG:
831 DBG("%s: REMOTE_NDIS_HALT_MSG\n", 826 pr_debug("%s: REMOTE_NDIS_HALT_MSG\n",
832 __func__ ); 827 __func__ );
833 params->state = RNDIS_UNINITIALIZED; 828 params->state = RNDIS_UNINITIALIZED;
834 if (params->dev) { 829 if (params->dev) {
@@ -846,7 +841,7 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
846 (rndis_set_msg_type *) buf); 841 (rndis_set_msg_type *) buf);
847 842
848 case REMOTE_NDIS_RESET_MSG: 843 case REMOTE_NDIS_RESET_MSG:
849 DBG("%s: REMOTE_NDIS_RESET_MSG\n", 844 pr_debug("%s: REMOTE_NDIS_RESET_MSG\n",
850 __func__ ); 845 __func__ );
851 return rndis_reset_response (configNr, 846 return rndis_reset_response (configNr,
852 (rndis_reset_msg_type *) buf); 847 (rndis_reset_msg_type *) buf);
@@ -854,7 +849,7 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
854 case REMOTE_NDIS_KEEPALIVE_MSG: 849 case REMOTE_NDIS_KEEPALIVE_MSG:
855 /* For USB: host does this every 5 seconds */ 850 /* For USB: host does this every 5 seconds */
856 if (rndis_debug > 1) 851 if (rndis_debug > 1)
857 DBG("%s: REMOTE_NDIS_KEEPALIVE_MSG\n", 852 pr_debug("%s: REMOTE_NDIS_KEEPALIVE_MSG\n",
858 __func__ ); 853 __func__ );
859 return rndis_keepalive_response (configNr, 854 return rndis_keepalive_response (configNr,
860 (rndis_keepalive_msg_type *) 855 (rndis_keepalive_msg_type *)
@@ -870,7 +865,7 @@ int rndis_msg_parser (u8 configNr, u8 *buf)
870 { 865 {
871 unsigned i; 866 unsigned i;
872 for (i = 0; i < MsgLength; i += 16) { 867 for (i = 0; i < MsgLength; i += 16) {
873 DBG("%03d: " 868 pr_debug("%03d: "
874 " %02x %02x %02x %02x" 869 " %02x %02x %02x %02x"
875 " %02x %02x %02x %02x" 870 " %02x %02x %02x %02x"
876 " %02x %02x %02x %02x" 871 " %02x %02x %02x %02x"
@@ -905,18 +900,18 @@ int rndis_register(void (*resp_avail)(void *v), void *v)
905 rndis_per_dev_params [i].used = 1; 900 rndis_per_dev_params [i].used = 1;
906 rndis_per_dev_params [i].resp_avail = resp_avail; 901 rndis_per_dev_params [i].resp_avail = resp_avail;
907 rndis_per_dev_params [i].v = v; 902 rndis_per_dev_params [i].v = v;
908 DBG("%s: configNr = %d\n", __func__, i); 903 pr_debug("%s: configNr = %d\n", __func__, i);
909 return i; 904 return i;
910 } 905 }
911 } 906 }
912 DBG("failed\n"); 907 pr_debug("failed\n");
913 908
914 return -ENODEV; 909 return -ENODEV;
915} 910}
916 911
917void rndis_deregister (int configNr) 912void rndis_deregister (int configNr)
918{ 913{
919 DBG("%s: \n", __func__ ); 914 pr_debug("%s: \n", __func__);
920 915
921 if (configNr >= RNDIS_MAX_CONFIGS) return; 916 if (configNr >= RNDIS_MAX_CONFIGS) return;
922 rndis_per_dev_params [configNr].used = 0; 917 rndis_per_dev_params [configNr].used = 0;
@@ -926,7 +921,7 @@ void rndis_deregister (int configNr)
926 921
927int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter) 922int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter)
928{ 923{
929 DBG("%s:\n", __func__ ); 924 pr_debug("%s:\n", __func__);
930 if (!dev) 925 if (!dev)
931 return -EINVAL; 926 return -EINVAL;
932 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 927 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
@@ -939,7 +934,7 @@ int rndis_set_param_dev(u8 configNr, struct net_device *dev, u16 *cdc_filter)
939 934
940int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr) 935int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr)
941{ 936{
942 DBG("%s:\n", __func__ ); 937 pr_debug("%s:\n", __func__);
943 if (!vendorDescr) return -1; 938 if (!vendorDescr) return -1;
944 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 939 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
945 940
@@ -951,7 +946,7 @@ int rndis_set_param_vendor (u8 configNr, u32 vendorID, const char *vendorDescr)
951 946
952int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed) 947int rndis_set_param_medium (u8 configNr, u32 medium, u32 speed)
953{ 948{
954 DBG("%s: %u %u\n", __func__, medium, speed); 949 pr_debug("%s: %u %u\n", __func__, medium, speed);
955 if (configNr >= RNDIS_MAX_CONFIGS) return -1; 950 if (configNr >= RNDIS_MAX_CONFIGS) return -1;
956 951
957 rndis_per_dev_params [configNr].medium = medium; 952 rndis_per_dev_params [configNr].medium = medium;
@@ -1114,7 +1109,7 @@ static ssize_t rndis_proc_write(struct file *file, const char __user *buffer,
1114 break; 1109 break;
1115 default: 1110 default:
1116 if (fl_speed) p->speed = speed; 1111 if (fl_speed) p->speed = speed;
1117 else DBG("%c is not valid\n", c); 1112 else pr_debug("%c is not valid\n", c);
1118 break; 1113 break;
1119 } 1114 }
1120 1115
@@ -1159,12 +1154,12 @@ int __init rndis_init (void)
1159 &rndis_proc_fops, 1154 &rndis_proc_fops,
1160 (void *)(rndis_per_dev_params + i)))) 1155 (void *)(rndis_per_dev_params + i))))
1161 { 1156 {
1162 DBG("%s :remove entries", __func__); 1157 pr_debug("%s :remove entries", __func__);
1163 while (i) { 1158 while (i) {
1164 sprintf (name, NAME_TEMPLATE, --i); 1159 sprintf (name, NAME_TEMPLATE, --i);
1165 remove_proc_entry (name, NULL); 1160 remove_proc_entry (name, NULL);
1166 } 1161 }
1167 DBG("\n"); 1162 pr_debug("\n");
1168 return -EIO; 1163 return -EIO;
1169 } 1164 }
1170#endif 1165#endif
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index b3699afff002..3faa7a7022df 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -30,6 +30,24 @@
30 30
31/*-------------------------------------------------------------------------*/ 31/*-------------------------------------------------------------------------*/
32 32
33/*
34 * Kbuild is not very cooperative with respect to linking separately
35 * compiled library objects into one module. So for now we won't use
36 * separate compilation ... ensuring init/exit sections work to shrink
37 * the runtime footprint, and giving us at least some parts of what
38 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
39 */
40#include "composite.c"
41#include "usbstring.c"
42#include "config.c"
43#include "epautoconf.c"
44
45#include "f_acm.c"
46#include "f_serial.c"
47#include "u_serial.c"
48
49/*-------------------------------------------------------------------------*/
50
33/* Thanks to NetChip Technologies for donating this product ID. 51/* Thanks to NetChip Technologies for donating this product ID.
34* 52*
35* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!! 53* DO NOT REUSE THESE IDs with a protocol-incompatible driver!! Ever!!
diff --git a/drivers/usb/gadget/u_ether.c b/drivers/usb/gadget/u_ether.c
index 3791e6271903..dbd575a194f3 100644
--- a/drivers/usb/gadget/u_ether.c
+++ b/drivers/usb/gadget/u_ether.c
@@ -52,7 +52,7 @@
52 * this single "physical" link to be used by multiple virtual links.) 52 * this single "physical" link to be used by multiple virtual links.)
53 */ 53 */
54 54
55#define DRIVER_VERSION "29-May-2008" 55#define UETH__VERSION "29-May-2008"
56 56
57struct eth_dev { 57struct eth_dev {
58 /* lock is held while accessing port_usb 58 /* lock is held while accessing port_usb
@@ -170,7 +170,7 @@ static void eth_get_drvinfo(struct net_device *net, struct ethtool_drvinfo *p)
170 struct eth_dev *dev = netdev_priv(net); 170 struct eth_dev *dev = netdev_priv(net);
171 171
172 strlcpy(p->driver, "g_ether", sizeof p->driver); 172 strlcpy(p->driver, "g_ether", sizeof p->driver);
173 strlcpy(p->version, DRIVER_VERSION, sizeof p->version); 173 strlcpy(p->version, UETH__VERSION, sizeof p->version);
174 strlcpy(p->fw_version, dev->gadget->name, sizeof p->fw_version); 174 strlcpy(p->fw_version, dev->gadget->name, sizeof p->fw_version);
175 strlcpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof p->bus_info); 175 strlcpy(p->bus_info, dev_name(&dev->gadget->dev), sizeof p->bus_info);
176} 176}
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index aa0bd4f126a1..361d9659ac48 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -59,6 +59,23 @@
59 59
60/*-------------------------------------------------------------------------*/ 60/*-------------------------------------------------------------------------*/
61 61
62/*
63 * Kbuild is not very cooperative with respect to linking separately
64 * compiled library objects into one module. So for now we won't use
65 * separate compilation ... ensuring init/exit sections work to shrink
66 * the runtime footprint, and giving us at least some parts of what
67 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
68 */
69#include "composite.c"
70#include "usbstring.c"
71#include "config.c"
72#include "epautoconf.c"
73
74#include "f_sourcesink.c"
75#include "f_loopback.c"
76
77/*-------------------------------------------------------------------------*/
78
62#define DRIVER_VERSION "Cinco de Mayo 2008" 79#define DRIVER_VERSION "Cinco de Mayo 2008"
63 80
64static const char longname[] = "Gadget Zero"; 81static const char longname[] = "Gadget Zero";
diff --git a/drivers/usb/host/ohci-omap.c b/drivers/usb/host/ohci-omap.c
index 95b3ec89c126..522185629624 100644
--- a/drivers/usb/host/ohci-omap.c
+++ b/drivers/usb/host/ohci-omap.c
@@ -344,7 +344,12 @@ static int usb_hcd_omap_probe (const struct hc_driver *driver,
344 goto err1; 344 goto err1;
345 } 345 }
346 346
347 hcd->regs = (void __iomem *) (int) IO_ADDRESS(hcd->rsrc_start); 347 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
348 if (!hcd->regs) {
349 dev_err(&pdev->dev, "can't ioremap OHCI HCD\n");
350 retval = -ENOMEM;
351 goto err2;
352 }
348 353
349 ohci = hcd_to_ohci(hcd); 354 ohci = hcd_to_ohci(hcd);
350 ohci_hcd_init(ohci); 355 ohci_hcd_init(ohci);
@@ -355,11 +360,11 @@ static int usb_hcd_omap_probe (const struct hc_driver *driver,
355 irq = platform_get_irq(pdev, 0); 360 irq = platform_get_irq(pdev, 0);
356 if (irq < 0) { 361 if (irq < 0) {
357 retval = -ENXIO; 362 retval = -ENXIO;
358 goto err2; 363 goto err3;
359 } 364 }
360 retval = usb_add_hcd(hcd, irq, IRQF_DISABLED); 365 retval = usb_add_hcd(hcd, irq, IRQF_DISABLED);
361 if (retval) 366 if (retval)
362 goto err2; 367 goto err3;
363 368
364 host_initialized = 1; 369 host_initialized = 1;
365 370
@@ -367,6 +372,8 @@ static int usb_hcd_omap_probe (const struct hc_driver *driver,
367 omap_ohci_clock_power(0); 372 omap_ohci_clock_power(0);
368 373
369 return 0; 374 return 0;
375err3:
376 iounmap(hcd->regs);
370err2: 377err2:
371 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 378 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
372err1: 379err1:
@@ -401,6 +408,7 @@ usb_hcd_omap_remove (struct usb_hcd *hcd, struct platform_device *pdev)
401 } 408 }
402 if (machine_is_omap_osk()) 409 if (machine_is_omap_osk())
403 omap_free_gpio(9); 410 omap_free_gpio(9);
411 iounmap(hcd->regs);
404 release_mem_region(hcd->rsrc_start, hcd->rsrc_len); 412 release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
405 usb_put_hcd(hcd); 413 usb_put_hcd(hcd);
406 clk_put(usb_dc_ck); 414 clk_put(usb_dc_ck);
diff --git a/drivers/usb/host/sl811_cs.c b/drivers/usb/host/sl811_cs.c
index 5da63f535005..516848dd9b48 100644
--- a/drivers/usb/host/sl811_cs.c
+++ b/drivers/usb/host/sl811_cs.c
@@ -112,7 +112,8 @@ static struct platform_device platform_dev = {
112 .num_resources = ARRAY_SIZE(resources), 112 .num_resources = ARRAY_SIZE(resources),
113}; 113};
114 114
115static int sl811_hc_init(struct device *parent, ioaddr_t base_addr, int irq) 115static int sl811_hc_init(struct device *parent, resource_size_t base_addr,
116 int irq)
116{ 117{
117 if (platform_dev.dev.parent) 118 if (platform_dev.dev.parent)
118 return -EBUSY; 119 return -EBUSY;
@@ -155,97 +156,72 @@ static void sl811_cs_release(struct pcmcia_device * link)
155 platform_device_unregister(&platform_dev); 156 platform_device_unregister(&platform_dev);
156} 157}
157 158
159static int sl811_cs_config_check(struct pcmcia_device *p_dev,
160 cistpl_cftable_entry_t *cfg,
161 cistpl_cftable_entry_t *dflt,
162 unsigned int vcc,
163 void *priv_data)
164{
165 if (cfg->index == 0)
166 return -ENODEV;
167
168 /* Use power settings for Vcc and Vpp if present */
169 /* Note that the CIS values need to be rescaled */
170 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
171 if (cfg->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc)
172 return -ENODEV;
173 } else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) {
174 if (dflt->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc)
175 return -ENODEV;
176 }
177
178 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
179 p_dev->conf.Vpp =
180 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
181 else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
182 p_dev->conf.Vpp =
183 dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
184
185 /* we need an interrupt */
186 if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
187 p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
188
189 /* IO window settings */
190 p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
191 if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
192 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
193
194 p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
195 p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
196 p_dev->io.BasePort1 = io->win[0].base;
197 p_dev->io.NumPorts1 = io->win[0].len;
198
199 return pcmcia_request_io(p_dev, &p_dev->io);
200 }
201 pcmcia_disable_device(p_dev);
202 return -ENODEV;
203}
204
205
158static int sl811_cs_config(struct pcmcia_device *link) 206static int sl811_cs_config(struct pcmcia_device *link)
159{ 207{
160 struct device *parent = &handle_to_dev(link); 208 struct device *parent = &handle_to_dev(link);
161 local_info_t *dev = link->priv; 209 local_info_t *dev = link->priv;
162 tuple_t tuple;
163 cisparse_t parse;
164 int last_fn, last_ret; 210 int last_fn, last_ret;
165 u_char buf[64];
166 config_info_t conf;
167 cistpl_cftable_entry_t dflt = { 0 };
168 211
169 DBG(0, "sl811_cs_config(0x%p)\n", link); 212 DBG(0, "sl811_cs_config(0x%p)\n", link);
170 213
171 /* Look up the current Vcc */ 214 if (pcmcia_loop_config(link, sl811_cs_config_check, NULL))
172 CS_CHECK(GetConfigurationInfo, 215 goto failed;
173 pcmcia_get_configuration_info(link, &conf));
174
175 tuple.Attributes = 0;
176 tuple.TupleData = buf;
177 tuple.TupleDataMax = sizeof(buf);
178 tuple.TupleOffset = 0;
179 tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
180 CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
181 while (1) {
182 cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
183
184 if (pcmcia_get_tuple_data(link, &tuple) != 0
185 || pcmcia_parse_tuple(link, &tuple, &parse)
186 != 0)
187 goto next_entry;
188
189 if (cfg->flags & CISTPL_CFTABLE_DEFAULT) {
190 dflt = *cfg;
191 }
192
193 if (cfg->index == 0)
194 goto next_entry;
195
196 link->conf.ConfigIndex = cfg->index;
197
198 /* Use power settings for Vcc and Vpp if present */
199 /* Note that the CIS values need to be rescaled */
200 if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
201 if (cfg->vcc.param[CISTPL_POWER_VNOM]/10000
202 != conf.Vcc)
203 goto next_entry;
204 } else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM)) {
205 if (dflt.vcc.param[CISTPL_POWER_VNOM]/10000
206 != conf.Vcc)
207 goto next_entry;
208 }
209
210 if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
211 link->conf.Vpp =
212 cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
213 else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
214 link->conf.Vpp =
215 dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
216
217 /* we need an interrupt */
218 if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
219 link->conf.Attributes |= CONF_ENABLE_IRQ;
220
221 /* IO window settings */
222 link->io.NumPorts1 = link->io.NumPorts2 = 0;
223 if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
224 cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
225
226 link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
227 link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
228 link->io.BasePort1 = io->win[0].base;
229 link->io.NumPorts1 = io->win[0].len;
230
231 if (pcmcia_request_io(link, &link->io) != 0)
232 goto next_entry;
233 }
234 break;
235
236next_entry:
237 pcmcia_disable_device(link);
238 last_ret = pcmcia_get_next_tuple(link, &tuple);
239 }
240 216
241 /* require an IRQ and two registers */ 217 /* require an IRQ and two registers */
242 if (!link->io.NumPorts1 || link->io.NumPorts1 < 2) 218 if (!link->io.NumPorts1 || link->io.NumPorts1 < 2)
243 goto cs_failed; 219 goto failed;
244 if (link->conf.Attributes & CONF_ENABLE_IRQ) 220 if (link->conf.Attributes & CONF_ENABLE_IRQ)
245 CS_CHECK(RequestIRQ, 221 CS_CHECK(RequestIRQ,
246 pcmcia_request_irq(link, &link->irq)); 222 pcmcia_request_irq(link, &link->irq));
247 else 223 else
248 goto cs_failed; 224 goto failed;
249 225
250 CS_CHECK(RequestConfiguration, 226 CS_CHECK(RequestConfiguration,
251 pcmcia_request_configuration(link, &link->conf)); 227 pcmcia_request_configuration(link, &link->conf));
@@ -266,8 +242,9 @@ next_entry:
266 if (sl811_hc_init(parent, link->io.BasePort1, link->irq.AssignedIRQ) 242 if (sl811_hc_init(parent, link->io.BasePort1, link->irq.AssignedIRQ)
267 < 0) { 243 < 0) {
268cs_failed: 244cs_failed:
269 printk("sl811_cs_config failed\n");
270 cs_error(link, last_fn, last_ret); 245 cs_error(link, last_fn, last_ret);
246failed:
247 printk(KERN_WARNING "sl811_cs_config failed\n");
271 sl811_cs_release(link); 248 sl811_cs_release(link);
272 return -ENODEV; 249 return -ENODEV;
273 } 250 }
diff --git a/drivers/usb/host/uhci-q.c b/drivers/usb/host/uhci-q.c
index db645936eedd..1f0c2cf26e5d 100644
--- a/drivers/usb/host/uhci-q.c
+++ b/drivers/usb/host/uhci-q.c
@@ -123,14 +123,10 @@ static struct uhci_td *uhci_alloc_td(struct uhci_hcd *uhci)
123 123
124static void uhci_free_td(struct uhci_hcd *uhci, struct uhci_td *td) 124static void uhci_free_td(struct uhci_hcd *uhci, struct uhci_td *td)
125{ 125{
126 if (!list_empty(&td->list)) { 126 if (!list_empty(&td->list))
127 dev_warn(uhci_dev(uhci), "td %p still in list!\n", td); 127 dev_WARN(uhci_dev(uhci), "td %p still in list!\n", td);
128 WARN_ON(1); 128 if (!list_empty(&td->fl_list))
129 } 129 dev_WARN(uhci_dev(uhci), "td %p still in fl_list!\n", td);
130 if (!list_empty(&td->fl_list)) {
131 dev_warn(uhci_dev(uhci), "td %p still in fl_list!\n", td);
132 WARN_ON(1);
133 }
134 130
135 dma_pool_free(uhci->td_pool, td, td->dma_handle); 131 dma_pool_free(uhci->td_pool, td, td->dma_handle);
136} 132}
@@ -295,10 +291,8 @@ static struct uhci_qh *uhci_alloc_qh(struct uhci_hcd *uhci,
295static void uhci_free_qh(struct uhci_hcd *uhci, struct uhci_qh *qh) 291static void uhci_free_qh(struct uhci_hcd *uhci, struct uhci_qh *qh)
296{ 292{
297 WARN_ON(qh->state != QH_STATE_IDLE && qh->udev); 293 WARN_ON(qh->state != QH_STATE_IDLE && qh->udev);
298 if (!list_empty(&qh->queue)) { 294 if (!list_empty(&qh->queue))
299 dev_warn(uhci_dev(uhci), "qh %p list not empty!\n", qh); 295 dev_WARN(uhci_dev(uhci), "qh %p list not empty!\n", qh);
300 WARN_ON(1);
301 }
302 296
303 list_del(&qh->node); 297 list_del(&qh->node);
304 if (qh->udev) { 298 if (qh->udev) {
@@ -746,11 +740,9 @@ static void uhci_free_urb_priv(struct uhci_hcd *uhci,
746{ 740{
747 struct uhci_td *td, *tmp; 741 struct uhci_td *td, *tmp;
748 742
749 if (!list_empty(&urbp->node)) { 743 if (!list_empty(&urbp->node))
750 dev_warn(uhci_dev(uhci), "urb %p still on QH's list!\n", 744 dev_WARN(uhci_dev(uhci), "urb %p still on QH's list!\n",
751 urbp->urb); 745 urbp->urb);
752 WARN_ON(1);
753 }
754 746
755 list_for_each_entry_safe(td, tmp, &urbp->td_list, list) { 747 list_for_each_entry_safe(td, tmp, &urbp->td_list, list) {
756 uhci_remove_td_from_urbp(td); 748 uhci_remove_td_from_urbp(td);
diff --git a/drivers/usb/misc/phidgetkit.c b/drivers/usb/misc/phidgetkit.c
index 4cfa25b0f44e..cc8e0a926f99 100644
--- a/drivers/usb/misc/phidgetkit.c
+++ b/drivers/usb/misc/phidgetkit.c
@@ -595,9 +595,8 @@ static int interfacekit_probe(struct usb_interface *intf, const struct usb_devic
595 } while(value); 595 } while(value);
596 kit->dev_no = bit; 596 kit->dev_no = bit;
597 597
598 kit->dev = device_create_drvdata(phidget_class, &kit->udev->dev, 598 kit->dev = device_create(phidget_class, &kit->udev->dev, MKDEV(0, 0),
599 MKDEV(0, 0), kit, 599 kit, "interfacekit%d", kit->dev_no);
600 "interfacekit%d", kit->dev_no);
601 if (IS_ERR(kit->dev)) { 600 if (IS_ERR(kit->dev)) {
602 rc = PTR_ERR(kit->dev); 601 rc = PTR_ERR(kit->dev);
603 kit->dev = NULL; 602 kit->dev = NULL;
diff --git a/drivers/usb/misc/phidgetmotorcontrol.c b/drivers/usb/misc/phidgetmotorcontrol.c
index 9b4696f21b22..38088b44349e 100644
--- a/drivers/usb/misc/phidgetmotorcontrol.c
+++ b/drivers/usb/misc/phidgetmotorcontrol.c
@@ -365,9 +365,8 @@ static int motorcontrol_probe(struct usb_interface *intf, const struct usb_devic
365 } while(value); 365 } while(value);
366 mc->dev_no = bit; 366 mc->dev_no = bit;
367 367
368 mc->dev = device_create_drvdata(phidget_class, &mc->udev->dev, 368 mc->dev = device_create(phidget_class, &mc->udev->dev, MKDEV(0, 0), mc,
369 MKDEV(0, 0), mc, 369 "motorcontrol%d", mc->dev_no);
370 "motorcontrol%d", mc->dev_no);
371 if (IS_ERR(mc->dev)) { 370 if (IS_ERR(mc->dev)) {
372 rc = PTR_ERR(mc->dev); 371 rc = PTR_ERR(mc->dev);
373 mc->dev = NULL; 372 mc->dev = NULL;
diff --git a/drivers/usb/misc/phidgetservo.c b/drivers/usb/misc/phidgetservo.c
index 1ca7ddb41d4d..bef6fe16364b 100644
--- a/drivers/usb/misc/phidgetservo.c
+++ b/drivers/usb/misc/phidgetservo.c
@@ -275,9 +275,8 @@ servo_probe(struct usb_interface *interface, const struct usb_device_id *id)
275 } while (value); 275 } while (value);
276 dev->dev_no = bit; 276 dev->dev_no = bit;
277 277
278 dev->dev = device_create_drvdata(phidget_class, &dev->udev->dev, 278 dev->dev = device_create(phidget_class, &dev->udev->dev, MKDEV(0, 0),
279 MKDEV(0, 0), dev, 279 dev, "servo%d", dev->dev_no);
280 "servo%d", dev->dev_no);
281 if (IS_ERR(dev->dev)) { 280 if (IS_ERR(dev->dev)) {
282 rc = PTR_ERR(dev->dev); 281 rc = PTR_ERR(dev->dev);
283 dev->dev = NULL; 282 dev->dev = NULL;
diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index 6566fc0a3228..c9de3f027aab 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -1162,9 +1162,9 @@ int mon_bin_add(struct mon_bus *mbus, const struct usb_bus *ubus)
1162 if (minor >= MON_BIN_MAX_MINOR) 1162 if (minor >= MON_BIN_MAX_MINOR)
1163 return 0; 1163 return 0;
1164 1164
1165 dev = device_create_drvdata(mon_bin_class, ubus? ubus->controller: NULL, 1165 dev = device_create(mon_bin_class, ubus ? ubus->controller : NULL,
1166 MKDEV(MAJOR(mon_bin_dev0), minor), NULL, 1166 MKDEV(MAJOR(mon_bin_dev0), minor), NULL,
1167 "usbmon%d", minor); 1167 "usbmon%d", minor);
1168 if (IS_ERR(dev)) 1168 if (IS_ERR(dev))
1169 return 0; 1169 return 0;
1170 1170
diff --git a/drivers/usb/serial/aircable.c b/drivers/usb/serial/aircable.c
index 79ea98c66fa8..99fb7dc59c45 100644
--- a/drivers/usb/serial/aircable.c
+++ b/drivers/usb/serial/aircable.c
@@ -272,7 +272,7 @@ static void aircable_read(struct work_struct *work)
272 * 64 bytes, to ensure I do not get throttled. 272 * 64 bytes, to ensure I do not get throttled.
273 * Ask USB mailing list for better aproach. 273 * Ask USB mailing list for better aproach.
274 */ 274 */
275 tty = port->port.tty; 275 tty = tty_port_tty_get(&port->port);
276 276
277 if (!tty) { 277 if (!tty) {
278 schedule_work(&priv->rx_work); 278 schedule_work(&priv->rx_work);
@@ -283,12 +283,13 @@ static void aircable_read(struct work_struct *work)
283 count = min(64, serial_buf_data_avail(priv->rx_buf)); 283 count = min(64, serial_buf_data_avail(priv->rx_buf));
284 284
285 if (count <= 0) 285 if (count <= 0)
286 return; /* We have finished sending everything. */ 286 goto out; /* We have finished sending everything. */
287 287
288 tty_prepare_flip_string(tty, &data, count); 288 tty_prepare_flip_string(tty, &data, count);
289 if (!data) { 289 if (!data) {
290 err("%s- kzalloc(%d) failed.", __func__, count); 290 dev_err(&port->dev, "%s- kzalloc(%d) failed.",
291 return; 291 __func__, count);
292 goto out;
292 } 293 }
293 294
294 serial_buf_get(priv->rx_buf, data, count); 295 serial_buf_get(priv->rx_buf, data, count);
@@ -297,7 +298,8 @@ static void aircable_read(struct work_struct *work)
297 298
298 if (serial_buf_data_avail(priv->rx_buf)) 299 if (serial_buf_data_avail(priv->rx_buf))
299 schedule_work(&priv->rx_work); 300 schedule_work(&priv->rx_work);
300 301out:
302 tty_kref_put(tty);
301 return; 303 return;
302} 304}
303/* End of private methods */ 305/* End of private methods */
@@ -495,7 +497,7 @@ static void aircable_read_bulk_callback(struct urb *urb)
495 usb_serial_debug_data(debug, &port->dev, __func__, 497 usb_serial_debug_data(debug, &port->dev, __func__,
496 urb->actual_length, urb->transfer_buffer); 498 urb->actual_length, urb->transfer_buffer);
497 499
498 tty = port->port.tty; 500 tty = tty_port_tty_get(&port->port);
499 if (tty && urb->actual_length) { 501 if (tty && urb->actual_length) {
500 if (urb->actual_length <= 2) { 502 if (urb->actual_length <= 2) {
501 /* This is an incomplete package */ 503 /* This is an incomplete package */
@@ -527,6 +529,7 @@ static void aircable_read_bulk_callback(struct urb *urb)
527 } 529 }
528 aircable_read(&priv->rx_work); 530 aircable_read(&priv->rx_work);
529 } 531 }
532 tty_kref_put(tty);
530 533
531 /* Schedule the next read _if_ we are still open */ 534 /* Schedule the next read _if_ we are still open */
532 if (port->port.count) { 535 if (port->port.count) {
diff --git a/drivers/usb/serial/belkin_sa.c b/drivers/usb/serial/belkin_sa.c
index 2ebe06c3405a..1913bc7c5f0b 100644
--- a/drivers/usb/serial/belkin_sa.c
+++ b/drivers/usb/serial/belkin_sa.c
@@ -322,7 +322,7 @@ static void belkin_sa_read_int_callback(struct urb *urb)
322 * to look in to this before committing any code. 322 * to look in to this before committing any code.
323 */ 323 */
324 if (priv->last_lsr & BELKIN_SA_LSR_ERR) { 324 if (priv->last_lsr & BELKIN_SA_LSR_ERR) {
325 tty = port->port.tty; 325 tty = tty_port_tty_get(&port->port);
326 /* Overrun Error */ 326 /* Overrun Error */
327 if (priv->last_lsr & BELKIN_SA_LSR_OE) { 327 if (priv->last_lsr & BELKIN_SA_LSR_OE) {
328 } 328 }
@@ -335,6 +335,7 @@ static void belkin_sa_read_int_callback(struct urb *urb)
335 /* Break Indicator */ 335 /* Break Indicator */
336 if (priv->last_lsr & BELKIN_SA_LSR_BI) { 336 if (priv->last_lsr & BELKIN_SA_LSR_BI) {
337 } 337 }
338 tty_kref_put(tty);
338 } 339 }
339#endif 340#endif
340 spin_unlock_irqrestore(&priv->lock, flags); 341 spin_unlock_irqrestore(&priv->lock, flags);
diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
index e980766bb84b..5b20de130e08 100644
--- a/drivers/usb/serial/console.c
+++ b/drivers/usb/serial/console.c
@@ -117,7 +117,7 @@ static int usb_console_setup(struct console *co, char *options)
117 } 117 }
118 118
119 port = serial->port[0]; 119 port = serial->port[0];
120 port->port.tty = NULL; 120 tty_port_tty_set(&port->port, NULL);
121 121
122 info->port = port; 122 info->port = port;
123 123
@@ -143,7 +143,7 @@ static int usb_console_setup(struct console *co, char *options)
143 } 143 }
144 memset(&dummy, 0, sizeof(struct ktermios)); 144 memset(&dummy, 0, sizeof(struct ktermios));
145 tty->termios = termios; 145 tty->termios = termios;
146 port->port.tty = tty; 146 tty_port_tty_set(&port->port, tty);
147 } 147 }
148 148
149 /* only call the device specific open if this 149 /* only call the device specific open if this
@@ -163,7 +163,7 @@ static int usb_console_setup(struct console *co, char *options)
163 tty_termios_encode_baud_rate(termios, baud, baud); 163 tty_termios_encode_baud_rate(termios, baud, baud);
164 serial->type->set_termios(tty, port, &dummy); 164 serial->type->set_termios(tty, port, &dummy);
165 165
166 port->port.tty = NULL; 166 tty_port_tty_set(&port->port, NULL);
167 kfree(termios); 167 kfree(termios);
168 kfree(tty); 168 kfree(tty);
169 } 169 }
@@ -176,7 +176,7 @@ out:
176 return retval; 176 return retval;
177free_termios: 177free_termios:
178 kfree(termios); 178 kfree(termios);
179 port->port.tty = NULL; 179 tty_port_tty_set(&port->port, NULL);
180free_tty: 180free_tty:
181 kfree(tty); 181 kfree(tty);
182reset_open_count: 182reset_open_count:
diff --git a/drivers/usb/serial/cyberjack.c b/drivers/usb/serial/cyberjack.c
index b4d72351cb96..94ef36c4764b 100644
--- a/drivers/usb/serial/cyberjack.c
+++ b/drivers/usb/serial/cyberjack.c
@@ -384,7 +384,7 @@ static void cyberjack_read_bulk_callback(struct urb *urb)
384 return; 384 return;
385 } 385 }
386 386
387 tty = port->port.tty; 387 tty = tty_port_tty_get(&port->port);
388 if (!tty) { 388 if (!tty) {
389 dbg("%s - ignoring since device not open\n", __func__); 389 dbg("%s - ignoring since device not open\n", __func__);
390 return; 390 return;
@@ -394,6 +394,7 @@ static void cyberjack_read_bulk_callback(struct urb *urb)
394 tty_insert_flip_string(tty, data, urb->actual_length); 394 tty_insert_flip_string(tty, data, urb->actual_length);
395 tty_flip_buffer_push(tty); 395 tty_flip_buffer_push(tty);
396 } 396 }
397 tty_kref_put(tty);
397 398
398 spin_lock(&priv->lock); 399 spin_lock(&priv->lock);
399 400
diff --git a/drivers/usb/serial/cypress_m8.c b/drivers/usb/serial/cypress_m8.c
index 22837a3f2f89..f3514a91f915 100644
--- a/drivers/usb/serial/cypress_m8.c
+++ b/drivers/usb/serial/cypress_m8.c
@@ -1286,7 +1286,7 @@ static void cypress_read_int_callback(struct urb *urb)
1286 } 1286 }
1287 spin_unlock_irqrestore(&priv->lock, flags); 1287 spin_unlock_irqrestore(&priv->lock, flags);
1288 1288
1289 tty = port->port.tty; 1289 tty = tty_port_tty_get(&port->port);
1290 if (!tty) { 1290 if (!tty) {
1291 dbg("%s - bad tty pointer - exiting", __func__); 1291 dbg("%s - bad tty pointer - exiting", __func__);
1292 return; 1292 return;
@@ -1362,7 +1362,7 @@ static void cypress_read_int_callback(struct urb *urb)
1362 data[i]); 1362 data[i]);
1363 tty_insert_flip_char(tty, data[i], tty_flag); 1363 tty_insert_flip_char(tty, data[i], tty_flag);
1364 } 1364 }
1365 tty_flip_buffer_push(port->port.tty); 1365 tty_flip_buffer_push(tty);
1366 } 1366 }
1367 1367
1368 spin_lock_irqsave(&priv->lock, flags); 1368 spin_lock_irqsave(&priv->lock, flags);
@@ -1371,6 +1371,7 @@ static void cypress_read_int_callback(struct urb *urb)
1371 spin_unlock_irqrestore(&priv->lock, flags); 1371 spin_unlock_irqrestore(&priv->lock, flags);
1372 1372
1373continue_read: 1373continue_read:
1374 tty_kref_put(tty);
1374 1375
1375 /* Continue trying to always read... unless the port has closed. */ 1376 /* Continue trying to always read... unless the port has closed. */
1376 1377
diff --git a/drivers/usb/serial/digi_acceleport.c b/drivers/usb/serial/digi_acceleport.c
index 240aad1acaab..5756ac6d6c92 100644
--- a/drivers/usb/serial/digi_acceleport.c
+++ b/drivers/usb/serial/digi_acceleport.c
@@ -604,7 +604,9 @@ static void digi_wakeup_write_lock(struct work_struct *work)
604 604
605static void digi_wakeup_write(struct usb_serial_port *port) 605static void digi_wakeup_write(struct usb_serial_port *port)
606{ 606{
607 tty_wakeup(port->port.tty); 607 struct tty_struct *tty = tty_port_tty_get(&port->port);
608 tty_wakeup(tty);
609 tty_kref_put(tty);
608} 610}
609 611
610 612
@@ -1668,7 +1670,7 @@ static int digi_read_inb_callback(struct urb *urb)
1668{ 1670{
1669 1671
1670 struct usb_serial_port *port = urb->context; 1672 struct usb_serial_port *port = urb->context;
1671 struct tty_struct *tty = port->port.tty; 1673 struct tty_struct *tty;
1672 struct digi_port *priv = usb_get_serial_port_data(port); 1674 struct digi_port *priv = usb_get_serial_port_data(port);
1673 int opcode = ((unsigned char *)urb->transfer_buffer)[0]; 1675 int opcode = ((unsigned char *)urb->transfer_buffer)[0];
1674 int len = ((unsigned char *)urb->transfer_buffer)[1]; 1676 int len = ((unsigned char *)urb->transfer_buffer)[1];
@@ -1692,6 +1694,7 @@ static int digi_read_inb_callback(struct urb *urb)
1692 return -1; 1694 return -1;
1693 } 1695 }
1694 1696
1697 tty = tty_port_tty_get(&port->port);
1695 spin_lock(&priv->dp_port_lock); 1698 spin_lock(&priv->dp_port_lock);
1696 1699
1697 /* check for throttle; if set, do not resubmit read urb */ 1700 /* check for throttle; if set, do not resubmit read urb */
@@ -1735,6 +1738,7 @@ static int digi_read_inb_callback(struct urb *urb)
1735 } 1738 }
1736 } 1739 }
1737 spin_unlock(&priv->dp_port_lock); 1740 spin_unlock(&priv->dp_port_lock);
1741 tty_kref_put(tty);
1738 1742
1739 if (opcode == DIGI_CMD_RECEIVE_DISABLE) 1743 if (opcode == DIGI_CMD_RECEIVE_DISABLE)
1740 dbg("%s: got RECEIVE_DISABLE", __func__); 1744 dbg("%s: got RECEIVE_DISABLE", __func__);
@@ -1760,6 +1764,7 @@ static int digi_read_oob_callback(struct urb *urb)
1760 1764
1761 struct usb_serial_port *port = urb->context; 1765 struct usb_serial_port *port = urb->context;
1762 struct usb_serial *serial = port->serial; 1766 struct usb_serial *serial = port->serial;
1767 struct tty_struct *tty;
1763 struct digi_port *priv = usb_get_serial_port_data(port); 1768 struct digi_port *priv = usb_get_serial_port_data(port);
1764 int opcode, line, status, val; 1769 int opcode, line, status, val;
1765 int i; 1770 int i;
@@ -1787,10 +1792,11 @@ static int digi_read_oob_callback(struct urb *urb)
1787 if (priv == NULL) 1792 if (priv == NULL)
1788 return -1; 1793 return -1;
1789 1794
1795 tty = tty_port_tty_get(&port->port);
1790 rts = 0; 1796 rts = 0;
1791 if (port->port.count) 1797 if (port->port.count)
1792 rts = port->port.tty->termios->c_cflag & CRTSCTS; 1798 rts = tty->termios->c_cflag & CRTSCTS;
1793 1799
1794 if (opcode == DIGI_CMD_READ_INPUT_SIGNALS) { 1800 if (opcode == DIGI_CMD_READ_INPUT_SIGNALS) {
1795 spin_lock(&priv->dp_port_lock); 1801 spin_lock(&priv->dp_port_lock);
1796 /* convert from digi flags to termiox flags */ 1802 /* convert from digi flags to termiox flags */
@@ -1798,14 +1804,14 @@ static int digi_read_oob_callback(struct urb *urb)
1798 priv->dp_modem_signals |= TIOCM_CTS; 1804 priv->dp_modem_signals |= TIOCM_CTS;
1799 /* port must be open to use tty struct */ 1805 /* port must be open to use tty struct */
1800 if (rts) { 1806 if (rts) {
1801 port->port.tty->hw_stopped = 0; 1807 tty->hw_stopped = 0;
1802 digi_wakeup_write(port); 1808 digi_wakeup_write(port);
1803 } 1809 }
1804 } else { 1810 } else {
1805 priv->dp_modem_signals &= ~TIOCM_CTS; 1811 priv->dp_modem_signals &= ~TIOCM_CTS;
1806 /* port must be open to use tty struct */ 1812 /* port must be open to use tty struct */
1807 if (rts) 1813 if (rts)
1808 port->port.tty->hw_stopped = 1; 1814 tty->hw_stopped = 1;
1809 } 1815 }
1810 if (val & DIGI_READ_INPUT_SIGNALS_DSR) 1816 if (val & DIGI_READ_INPUT_SIGNALS_DSR)
1811 priv->dp_modem_signals |= TIOCM_DSR; 1817 priv->dp_modem_signals |= TIOCM_DSR;
@@ -1830,6 +1836,7 @@ static int digi_read_oob_callback(struct urb *urb)
1830 } else if (opcode == DIGI_CMD_IFLUSH_FIFO) { 1836 } else if (opcode == DIGI_CMD_IFLUSH_FIFO) {
1831 wake_up_interruptible(&priv->dp_flush_wait); 1837 wake_up_interruptible(&priv->dp_flush_wait);
1832 } 1838 }
1839 tty_kref_put(tty);
1833 } 1840 }
1834 return 0; 1841 return 0;
1835 1842
diff --git a/drivers/usb/serial/empeg.c b/drivers/usb/serial/empeg.c
index a6ab5b58d9ca..1072e847280f 100644
--- a/drivers/usb/serial/empeg.c
+++ b/drivers/usb/serial/empeg.c
@@ -33,9 +33,8 @@
33 * Moved MOD_DEC_USE_COUNT to end of empeg_close(). 33 * Moved MOD_DEC_USE_COUNT to end of empeg_close().
34 * 34 *
35 * (12/03/2000) gb 35 * (12/03/2000) gb
36 * Added port->port.tty->ldisc.set_termios(port->port.tty, NULL) to 36 * Added tty->ldisc.set_termios(port, tty, NULL) to empeg_open().
37 * empeg_open(). This notifies the tty driver that the termios have 37 * This notifies the tty driver that the termios have changed.
38 * changed.
39 * 38 *
40 * (11/13/2000) gb 39 * (11/13/2000) gb
41 * Moved tty->low_latency = 1 from empeg_read_bulk_callback() to 40 * Moved tty->low_latency = 1 from empeg_read_bulk_callback() to
@@ -354,7 +353,7 @@ static void empeg_read_bulk_callback(struct urb *urb)
354 353
355 usb_serial_debug_data(debug, &port->dev, __func__, 354 usb_serial_debug_data(debug, &port->dev, __func__,
356 urb->actual_length, data); 355 urb->actual_length, data);
357 tty = port->port.tty; 356 tty = tty_port_tty_get(&port->port);
358 357
359 if (urb->actual_length) { 358 if (urb->actual_length) {
360 tty_buffer_request_room(tty, urb->actual_length); 359 tty_buffer_request_room(tty, urb->actual_length);
@@ -362,6 +361,7 @@ static void empeg_read_bulk_callback(struct urb *urb)
362 tty_flip_buffer_push(tty); 361 tty_flip_buffer_push(tty);
363 bytes_in += urb->actual_length; 362 bytes_in += urb->actual_length;
364 } 363 }
364 tty_kref_put(tty);
365 365
366 /* Continue trying to always read */ 366 /* Continue trying to always read */
367 usb_fill_bulk_urb( 367 usb_fill_bulk_urb(
diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index 3dc93b542b30..c2ac129557aa 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -860,7 +860,7 @@ static int update_mctrl(struct usb_serial_port *port, unsigned int set,
860 860
861 kfree(buf); 861 kfree(buf);
862 if (rv < 0) { 862 if (rv < 0) {
863 err("%s Error from MODEM_CTRL urb: DTR %s, RTS %s", 863 dbg("%s Error from MODEM_CTRL urb: DTR %s, RTS %s",
864 __func__, 864 __func__,
865 (set & TIOCM_DTR) ? "HIGH" : 865 (set & TIOCM_DTR) ? "HIGH" :
866 (clear & TIOCM_DTR) ? "LOW" : "unchanged", 866 (clear & TIOCM_DTR) ? "LOW" : "unchanged",
@@ -1808,7 +1808,7 @@ static void ftdi_read_bulk_callback(struct urb *urb)
1808 if (port->port.count <= 0) 1808 if (port->port.count <= 0)
1809 return; 1809 return;
1810 1810
1811 tty = port->port.tty; 1811 tty = tty_port_tty_get(&port->port);
1812 if (!tty) { 1812 if (!tty) {
1813 dbg("%s - bad tty pointer - exiting", __func__); 1813 dbg("%s - bad tty pointer - exiting", __func__);
1814 return; 1814 return;
@@ -1817,7 +1817,7 @@ static void ftdi_read_bulk_callback(struct urb *urb)
1817 priv = usb_get_serial_port_data(port); 1817 priv = usb_get_serial_port_data(port);
1818 if (!priv) { 1818 if (!priv) {
1819 dbg("%s - bad port private data pointer - exiting", __func__); 1819 dbg("%s - bad port private data pointer - exiting", __func__);
1820 return; 1820 goto out;
1821 } 1821 }
1822 1822
1823 if (urb != port->read_urb) 1823 if (urb != port->read_urb)
@@ -1827,7 +1827,7 @@ static void ftdi_read_bulk_callback(struct urb *urb)
1827 /* This will happen at close every time so it is a dbg not an 1827 /* This will happen at close every time so it is a dbg not an
1828 err */ 1828 err */
1829 dbg("(this is ok on close) nonzero read bulk status received: %d", status); 1829 dbg("(this is ok on close) nonzero read bulk status received: %d", status);
1830 return; 1830 goto out;
1831 } 1831 }
1832 1832
1833 /* count data bytes, but not status bytes */ 1833 /* count data bytes, but not status bytes */
@@ -1838,7 +1838,8 @@ static void ftdi_read_bulk_callback(struct urb *urb)
1838 spin_unlock_irqrestore(&priv->rx_lock, flags); 1838 spin_unlock_irqrestore(&priv->rx_lock, flags);
1839 1839
1840 ftdi_process_read(&priv->rx_work.work); 1840 ftdi_process_read(&priv->rx_work.work);
1841 1841out:
1842 tty_kref_put(tty);
1842} /* ftdi_read_bulk_callback */ 1843} /* ftdi_read_bulk_callback */
1843 1844
1844 1845
@@ -1863,7 +1864,7 @@ static void ftdi_process_read(struct work_struct *work)
1863 if (port->port.count <= 0) 1864 if (port->port.count <= 0)
1864 return; 1865 return;
1865 1866
1866 tty = port->port.tty; 1867 tty = tty_port_tty_get(&port->port);
1867 if (!tty) { 1868 if (!tty) {
1868 dbg("%s - bad tty pointer - exiting", __func__); 1869 dbg("%s - bad tty pointer - exiting", __func__);
1869 return; 1870 return;
@@ -1872,13 +1873,13 @@ static void ftdi_process_read(struct work_struct *work)
1872 priv = usb_get_serial_port_data(port); 1873 priv = usb_get_serial_port_data(port);
1873 if (!priv) { 1874 if (!priv) {
1874 dbg("%s - bad port private data pointer - exiting", __func__); 1875 dbg("%s - bad port private data pointer - exiting", __func__);
1875 return; 1876 goto out;
1876 } 1877 }
1877 1878
1878 urb = port->read_urb; 1879 urb = port->read_urb;
1879 if (!urb) { 1880 if (!urb) {
1880 dbg("%s - bad read_urb pointer - exiting", __func__); 1881 dbg("%s - bad read_urb pointer - exiting", __func__);
1881 return; 1882 goto out;
1882 } 1883 }
1883 1884
1884 data = urb->transfer_buffer; 1885 data = urb->transfer_buffer;
@@ -2020,7 +2021,7 @@ static void ftdi_process_read(struct work_struct *work)
2020 schedule_delayed_work(&priv->rx_work, 1); 2021 schedule_delayed_work(&priv->rx_work, 1);
2021 else 2022 else
2022 dbg("%s - port is closed", __func__); 2023 dbg("%s - port is closed", __func__);
2023 return; 2024 goto out;
2024 } 2025 }
2025 2026
2026 /* urb is completely processed */ 2027 /* urb is completely processed */
@@ -2041,6 +2042,8 @@ static void ftdi_process_read(struct work_struct *work)
2041 err("%s - failed resubmitting read urb, error %d", 2042 err("%s - failed resubmitting read urb, error %d",
2042 __func__, result); 2043 __func__, result);
2043 } 2044 }
2045out:
2046 tty_kref_put(tty);
2044} /* ftdi_process_read */ 2047} /* ftdi_process_read */
2045 2048
2046 2049
@@ -2256,7 +2259,7 @@ static int ftdi_tiocmget(struct tty_struct *tty, struct file *file)
2256 0, 0, 2259 0, 0,
2257 buf, 1, WDR_TIMEOUT); 2260 buf, 1, WDR_TIMEOUT);
2258 if (ret < 0) { 2261 if (ret < 0) {
2259 err("%s Could not get modem status of device - err: %d", __func__, 2262 dbg("%s Could not get modem status of device - err: %d", __func__,
2260 ret); 2263 ret);
2261 return ret; 2264 return ret;
2262 } 2265 }
@@ -2275,7 +2278,7 @@ static int ftdi_tiocmget(struct tty_struct *tty, struct file *file)
2275 0, priv->interface, 2278 0, priv->interface,
2276 buf, 2, WDR_TIMEOUT); 2279 buf, 2, WDR_TIMEOUT);
2277 if (ret < 0) { 2280 if (ret < 0) {
2278 err("%s Could not get modem status of device - err: %d", __func__, 2281 dbg("%s Could not get modem status of device - err: %d", __func__,
2279 ret); 2282 ret);
2280 return ret; 2283 return ret;
2281 } 2284 }
diff --git a/drivers/usb/serial/garmin_gps.c b/drivers/usb/serial/garmin_gps.c
index d95382088075..2ad0569bcf19 100644
--- a/drivers/usb/serial/garmin_gps.c
+++ b/drivers/usb/serial/garmin_gps.c
@@ -276,7 +276,7 @@ static inline int isAbortTrfCmnd(const unsigned char *buf)
276static void send_to_tty(struct usb_serial_port *port, 276static void send_to_tty(struct usb_serial_port *port,
277 char *data, unsigned int actual_length) 277 char *data, unsigned int actual_length)
278{ 278{
279 struct tty_struct *tty = port->port.tty; 279 struct tty_struct *tty = tty_port_tty_get(&port->port);
280 280
281 if (tty && actual_length) { 281 if (tty && actual_length) {
282 282
@@ -287,6 +287,7 @@ static void send_to_tty(struct usb_serial_port *port,
287 tty_insert_flip_string(tty, data, actual_length); 287 tty_insert_flip_string(tty, data, actual_length);
288 tty_flip_buffer_push(tty); 288 tty_flip_buffer_push(tty);
289 } 289 }
290 tty_kref_put(tty);
290} 291}
291 292
292 293
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index fe84c88ec20c..814909f1ee63 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -330,7 +330,7 @@ static void resubmit_read_urb(struct usb_serial_port *port, gfp_t mem_flags)
330static void flush_and_resubmit_read_urb(struct usb_serial_port *port) 330static void flush_and_resubmit_read_urb(struct usb_serial_port *port)
331{ 331{
332 struct urb *urb = port->read_urb; 332 struct urb *urb = port->read_urb;
333 struct tty_struct *tty = port->port.tty; 333 struct tty_struct *tty = tty_port_tty_get(&port->port);
334 int room; 334 int room;
335 335
336 /* Push data to tty */ 336 /* Push data to tty */
@@ -341,6 +341,7 @@ static void flush_and_resubmit_read_urb(struct usb_serial_port *port)
341 tty_flip_buffer_push(tty); 341 tty_flip_buffer_push(tty);
342 } 342 }
343 } 343 }
344 tty_kref_put(tty);
344 345
345 resubmit_read_urb(port, GFP_ATOMIC); 346 resubmit_read_urb(port, GFP_ATOMIC);
346} 347}
diff --git a/drivers/usb/serial/io_edgeport.c b/drivers/usb/serial/io_edgeport.c
index bfa508ddb0fe..611f97fd62f1 100644
--- a/drivers/usb/serial/io_edgeport.c
+++ b/drivers/usb/serial/io_edgeport.c
@@ -600,6 +600,7 @@ static void edge_interrupt_callback(struct urb *urb)
600 struct edgeport_serial *edge_serial = urb->context; 600 struct edgeport_serial *edge_serial = urb->context;
601 struct edgeport_port *edge_port; 601 struct edgeport_port *edge_port;
602 struct usb_serial_port *port; 602 struct usb_serial_port *port;
603 struct tty_struct *tty;
603 unsigned char *data = urb->transfer_buffer; 604 unsigned char *data = urb->transfer_buffer;
604 int length = urb->actual_length; 605 int length = urb->actual_length;
605 int bytes_avail; 606 int bytes_avail;
@@ -675,9 +676,12 @@ static void edge_interrupt_callback(struct urb *urb)
675 676
676 /* tell the tty driver that something 677 /* tell the tty driver that something
677 has changed */ 678 has changed */
678 if (edge_port->port->port.tty) 679 tty = tty_port_tty_get(
679 tty_wakeup(edge_port->port->port.tty); 680 &edge_port->port->port);
680 681 if (tty) {
682 tty_wakeup(tty);
683 tty_kref_put(tty);
684 }
681 /* Since we have more credit, check 685 /* Since we have more credit, check
682 if more data can be sent */ 686 if more data can be sent */
683 send_more_port_data(edge_serial, 687 send_more_port_data(edge_serial,
@@ -778,13 +782,14 @@ static void edge_bulk_out_data_callback(struct urb *urb)
778 __func__, status); 782 __func__, status);
779 } 783 }
780 784
781 tty = edge_port->port->port.tty; 785 tty = tty_port_tty_get(&edge_port->port->port);
782 786
783 if (tty && edge_port->open) { 787 if (tty && edge_port->open) {
784 /* let the tty driver wakeup if it has a special 788 /* let the tty driver wakeup if it has a special
785 write_wakeup function */ 789 write_wakeup function */
786 tty_wakeup(tty); 790 tty_wakeup(tty);
787 } 791 }
792 tty_kref_put(tty);
788 793
789 /* Release the Write URB */ 794 /* Release the Write URB */
790 edge_port->write_in_progress = false; 795 edge_port->write_in_progress = false;
@@ -826,11 +831,12 @@ static void edge_bulk_out_cmd_callback(struct urb *urb)
826 } 831 }
827 832
828 /* Get pointer to tty */ 833 /* Get pointer to tty */
829 tty = edge_port->port->port.tty; 834 tty = tty_port_tty_get(&edge_port->port->port);
830 835
831 /* tell the tty driver that something has changed */ 836 /* tell the tty driver that something has changed */
832 if (tty && edge_port->open) 837 if (tty && edge_port->open)
833 tty_wakeup(tty); 838 tty_wakeup(tty);
839 tty_kref_put(tty);
834 840
835 /* we have completed the command */ 841 /* we have completed the command */
836 edge_port->commandPending = false; 842 edge_port->commandPending = false;
@@ -1932,11 +1938,13 @@ static void process_rcvd_data(struct edgeport_serial *edge_serial,
1932 edge_serial->rxPort]; 1938 edge_serial->rxPort];
1933 edge_port = usb_get_serial_port_data(port); 1939 edge_port = usb_get_serial_port_data(port);
1934 if (edge_port->open) { 1940 if (edge_port->open) {
1935 tty = edge_port->port->port.tty; 1941 tty = tty_port_tty_get(
1942 &edge_port->port->port);
1936 if (tty) { 1943 if (tty) {
1937 dbg("%s - Sending %d bytes to TTY for port %d", 1944 dbg("%s - Sending %d bytes to TTY for port %d",
1938 __func__, rxLen, edge_serial->rxPort); 1945 __func__, rxLen, edge_serial->rxPort);
1939 edge_tty_recv(&edge_serial->serial->dev->dev, tty, buffer, rxLen); 1946 edge_tty_recv(&edge_serial->serial->dev->dev, tty, buffer, rxLen);
1947 tty_kref_put(tty);
1940 } 1948 }
1941 edge_port->icount.rx += rxLen; 1949 edge_port->icount.rx += rxLen;
1942 } 1950 }
@@ -1971,6 +1979,7 @@ static void process_rcvd_status(struct edgeport_serial *edge_serial,
1971{ 1979{
1972 struct usb_serial_port *port; 1980 struct usb_serial_port *port;
1973 struct edgeport_port *edge_port; 1981 struct edgeport_port *edge_port;
1982 struct tty_struct *tty;
1974 __u8 code = edge_serial->rxStatusCode; 1983 __u8 code = edge_serial->rxStatusCode;
1975 1984
1976 /* switch the port pointer to the one being currently talked about */ 1985 /* switch the port pointer to the one being currently talked about */
@@ -2020,10 +2029,12 @@ static void process_rcvd_status(struct edgeport_serial *edge_serial,
2020 2029
2021 /* send the current line settings to the port so we are 2030 /* send the current line settings to the port so we are
2022 in sync with any further termios calls */ 2031 in sync with any further termios calls */
2023 /* FIXME: locking on tty */ 2032 tty = tty_port_tty_get(&edge_port->port->port);
2024 if (edge_port->port->port.tty) 2033 if (tty) {
2025 change_port_settings(edge_port->port->port.tty, 2034 change_port_settings(tty,
2026 edge_port, edge_port->port->port.tty->termios); 2035 edge_port, tty->termios);
2036 tty_kref_put(tty);
2037 }
2027 2038
2028 /* we have completed the open */ 2039 /* we have completed the open */
2029 edge_port->openPending = false; 2040 edge_port->openPending = false;
@@ -2163,10 +2174,14 @@ static void handle_new_lsr(struct edgeport_port *edge_port, __u8 lsrData,
2163 } 2174 }
2164 2175
2165 /* Place LSR data byte into Rx buffer */ 2176 /* Place LSR data byte into Rx buffer */
2166 if (lsrData && edge_port->port->port.tty) 2177 if (lsrData) {
2167 edge_tty_recv(&edge_port->port->dev, 2178 struct tty_struct *tty =
2168 edge_port->port->port.tty, &data, 1); 2179 tty_port_tty_get(&edge_port->port->port);
2169 2180 if (tty) {
2181 edge_tty_recv(&edge_port->port->dev, tty, &data, 1);
2182 tty_kref_put(tty);
2183 }
2184 }
2170 /* update input line counters */ 2185 /* update input line counters */
2171 icount = &edge_port->icount; 2186 icount = &edge_port->icount;
2172 if (newLsr & LSR_BREAK) 2187 if (newLsr & LSR_BREAK)
diff --git a/drivers/usb/serial/io_ti.c b/drivers/usb/serial/io_ti.c
index cb4c54316cf5..541dd8e6e7a2 100644
--- a/drivers/usb/serial/io_ti.c
+++ b/drivers/usb/serial/io_ti.c
@@ -572,7 +572,7 @@ static void chase_port(struct edgeport_port *port, unsigned long timeout,
572 int flush) 572 int flush)
573{ 573{
574 int baud_rate; 574 int baud_rate;
575 struct tty_struct *tty = port->port->port.tty; 575 struct tty_struct *tty = tty_port_tty_get(&port->port->port);
576 wait_queue_t wait; 576 wait_queue_t wait;
577 unsigned long flags; 577 unsigned long flags;
578 578
@@ -599,6 +599,7 @@ static void chase_port(struct edgeport_port *port, unsigned long timeout,
599 if (flush) 599 if (flush)
600 edge_buf_clear(port->ep_out_buf); 600 edge_buf_clear(port->ep_out_buf);
601 spin_unlock_irqrestore(&port->ep_lock, flags); 601 spin_unlock_irqrestore(&port->ep_lock, flags);
602 tty_kref_put(tty);
602 603
603 /* wait for data to drain from the device */ 604 /* wait for data to drain from the device */
604 timeout += jiffies; 605 timeout += jiffies;
@@ -1554,7 +1555,7 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr)
1554 /* Save the new modem status */ 1555 /* Save the new modem status */
1555 edge_port->shadow_msr = msr & 0xf0; 1556 edge_port->shadow_msr = msr & 0xf0;
1556 1557
1557 tty = edge_port->port->port.tty; 1558 tty = tty_port_tty_get(&edge_port->port->port);
1558 /* handle CTS flow control */ 1559 /* handle CTS flow control */
1559 if (tty && C_CRTSCTS(tty)) { 1560 if (tty && C_CRTSCTS(tty)) {
1560 if (msr & EDGEPORT_MSR_CTS) { 1561 if (msr & EDGEPORT_MSR_CTS) {
@@ -1564,6 +1565,7 @@ static void handle_new_msr(struct edgeport_port *edge_port, __u8 msr)
1564 tty->hw_stopped = 1; 1565 tty->hw_stopped = 1;
1565 } 1566 }
1566 } 1567 }
1568 tty_kref_put(tty);
1567 1569
1568 return; 1570 return;
1569} 1571}
@@ -1574,6 +1576,7 @@ static void handle_new_lsr(struct edgeport_port *edge_port, int lsr_data,
1574 struct async_icount *icount; 1576 struct async_icount *icount;
1575 __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR | 1577 __u8 new_lsr = (__u8)(lsr & (__u8)(LSR_OVER_ERR | LSR_PAR_ERR |
1576 LSR_FRM_ERR | LSR_BREAK)); 1578 LSR_FRM_ERR | LSR_BREAK));
1579 struct tty_struct *tty;
1577 1580
1578 dbg("%s - %02x", __func__, new_lsr); 1581 dbg("%s - %02x", __func__, new_lsr);
1579 1582
@@ -1587,8 +1590,13 @@ static void handle_new_lsr(struct edgeport_port *edge_port, int lsr_data,
1587 new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK); 1590 new_lsr &= (__u8)(LSR_OVER_ERR | LSR_BREAK);
1588 1591
1589 /* Place LSR data byte into Rx buffer */ 1592 /* Place LSR data byte into Rx buffer */
1590 if (lsr_data && edge_port->port->port.tty) 1593 if (lsr_data) {
1591 edge_tty_recv(&edge_port->port->dev, edge_port->port->port.tty, &data, 1); 1594 tty = tty_port_tty_get(&edge_port->port->port);
1595 if (tty) {
1596 edge_tty_recv(&edge_port->port->dev, tty, &data, 1);
1597 tty_kref_put(tty);
1598 }
1599 }
1592 1600
1593 /* update input line counters */ 1601 /* update input line counters */
1594 icount = &edge_port->icount; 1602 icount = &edge_port->icount;
@@ -1749,7 +1757,7 @@ static void edge_bulk_in_callback(struct urb *urb)
1749 ++data; 1757 ++data;
1750 } 1758 }
1751 1759
1752 tty = edge_port->port->port.tty; 1760 tty = tty_port_tty_get(&edge_port->port->port);
1753 if (tty && urb->actual_length) { 1761 if (tty && urb->actual_length) {
1754 usb_serial_debug_data(debug, &edge_port->port->dev, 1762 usb_serial_debug_data(debug, &edge_port->port->dev,
1755 __func__, urb->actual_length, data); 1763 __func__, urb->actual_length, data);
@@ -1761,6 +1769,7 @@ static void edge_bulk_in_callback(struct urb *urb)
1761 urb->actual_length); 1769 urb->actual_length);
1762 edge_port->icount.rx += urb->actual_length; 1770 edge_port->icount.rx += urb->actual_length;
1763 } 1771 }
1772 tty_kref_put(tty);
1764 1773
1765exit: 1774exit:
1766 /* continue read unless stopped */ 1775 /* continue read unless stopped */
@@ -1796,6 +1805,7 @@ static void edge_bulk_out_callback(struct urb *urb)
1796 struct usb_serial_port *port = urb->context; 1805 struct usb_serial_port *port = urb->context;
1797 struct edgeport_port *edge_port = usb_get_serial_port_data(port); 1806 struct edgeport_port *edge_port = usb_get_serial_port_data(port);
1798 int status = urb->status; 1807 int status = urb->status;
1808 struct tty_struct *tty;
1799 1809
1800 dbg("%s - port %d", __func__, port->number); 1810 dbg("%s - port %d", __func__, port->number);
1801 1811
@@ -1818,7 +1828,9 @@ static void edge_bulk_out_callback(struct urb *urb)
1818 } 1828 }
1819 1829
1820 /* send any buffered data */ 1830 /* send any buffered data */
1821 edge_send(port->port.tty); 1831 tty = tty_port_tty_get(&port->port);
1832 edge_send(tty);
1833 tty_kref_put(tty);
1822} 1834}
1823 1835
1824static int edge_open(struct tty_struct *tty, 1836static int edge_open(struct tty_struct *tty,
@@ -1876,7 +1888,7 @@ static int edge_open(struct tty_struct *tty,
1876 1888
1877 /* set up the port settings */ 1889 /* set up the port settings */
1878 if (tty) 1890 if (tty)
1879 edge_set_termios(tty, port, port->port.tty->termios); 1891 edge_set_termios(tty, port, tty->termios);
1880 1892
1881 /* open up the port */ 1893 /* open up the port */
1882 1894
diff --git a/drivers/usb/serial/ipaq.c b/drivers/usb/serial/ipaq.c
index cd9a2e138c8b..2affa9c118b2 100644
--- a/drivers/usb/serial/ipaq.c
+++ b/drivers/usb/serial/ipaq.c
@@ -764,13 +764,14 @@ static void ipaq_read_bulk_callback(struct urb *urb)
764 usb_serial_debug_data(debug, &port->dev, __func__, 764 usb_serial_debug_data(debug, &port->dev, __func__,
765 urb->actual_length, data); 765 urb->actual_length, data);
766 766
767 tty = port->port.tty; 767 tty = tty_port_tty_get(&port->port);
768 if (tty && urb->actual_length) { 768 if (tty && urb->actual_length) {
769 tty_buffer_request_room(tty, urb->actual_length); 769 tty_buffer_request_room(tty, urb->actual_length);
770 tty_insert_flip_string(tty, data, urb->actual_length); 770 tty_insert_flip_string(tty, data, urb->actual_length);
771 tty_flip_buffer_push(tty); 771 tty_flip_buffer_push(tty);
772 bytes_in += urb->actual_length; 772 bytes_in += urb->actual_length;
773 } 773 }
774 tty_kref_put(tty);
774 775
775 /* Continue trying to always read */ 776 /* Continue trying to always read */
776 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 777 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
diff --git a/drivers/usb/serial/ipw.c b/drivers/usb/serial/ipw.c
index a842025b9b57..480cac27d646 100644
--- a/drivers/usb/serial/ipw.c
+++ b/drivers/usb/serial/ipw.c
@@ -170,12 +170,13 @@ static void ipw_read_bulk_callback(struct urb *urb)
170 usb_serial_debug_data(debug, &port->dev, __func__, 170 usb_serial_debug_data(debug, &port->dev, __func__,
171 urb->actual_length, data); 171 urb->actual_length, data);
172 172
173 tty = port->port.tty; 173 tty = tty_port_tty_get(&port->port);
174 if (tty && urb->actual_length) { 174 if (tty && urb->actual_length) {
175 tty_buffer_request_room(tty, urb->actual_length); 175 tty_buffer_request_room(tty, urb->actual_length);
176 tty_insert_flip_string(tty, data, urb->actual_length); 176 tty_insert_flip_string(tty, data, urb->actual_length);
177 tty_flip_buffer_push(tty); 177 tty_flip_buffer_push(tty);
178 } 178 }
179 tty_kref_put(tty);
179 180
180 /* Continue trying to always read */ 181 /* Continue trying to always read */
181 usb_fill_bulk_urb(port->read_urb, port->serial->dev, 182 usb_fill_bulk_urb(port->read_urb, port->serial->dev,
diff --git a/drivers/usb/serial/ir-usb.c b/drivers/usb/serial/ir-usb.c
index e59155c6607d..45d4043e04ab 100644
--- a/drivers/usb/serial/ir-usb.c
+++ b/drivers/usb/serial/ir-usb.c
@@ -465,11 +465,12 @@ static void ir_read_bulk_callback(struct urb *urb)
465 ir_baud = *data & 0x0f; 465 ir_baud = *data & 0x0f;
466 usb_serial_debug_data(debug, &port->dev, __func__, 466 usb_serial_debug_data(debug, &port->dev, __func__,
467 urb->actual_length, data); 467 urb->actual_length, data);
468 tty = port->port.tty; 468 tty = tty_port_tty_get(&port->port);
469 if (tty_buffer_request_room(tty, urb->actual_length - 1)) { 469 if (tty_buffer_request_room(tty, urb->actual_length - 1)) {
470 tty_insert_flip_string(tty, data+1, urb->actual_length - 1); 470 tty_insert_flip_string(tty, data+1, urb->actual_length - 1);
471 tty_flip_buffer_push(tty); 471 tty_flip_buffer_push(tty);
472 } 472 }
473 tty_kref_put(tty);
473 474
474 /* 475 /*
475 * No break here. 476 * No break here.
diff --git a/drivers/usb/serial/iuu_phoenix.c b/drivers/usb/serial/iuu_phoenix.c
index ddff37fa6339..53710aa7eadd 100644
--- a/drivers/usb/serial/iuu_phoenix.c
+++ b/drivers/usb/serial/iuu_phoenix.c
@@ -629,13 +629,14 @@ static void read_buf_callback(struct urb *urb)
629 } 629 }
630 630
631 dbg("%s - %i chars to write", __func__, urb->actual_length); 631 dbg("%s - %i chars to write", __func__, urb->actual_length);
632 tty = port->port.tty; 632 tty = tty_port_tty_get(&port->port);
633 if (data == NULL) 633 if (data == NULL)
634 dbg("%s - data is NULL !!!", __func__); 634 dbg("%s - data is NULL !!!", __func__);
635 if (tty && urb->actual_length && data) { 635 if (tty && urb->actual_length && data) {
636 tty_insert_flip_string(tty, data, urb->actual_length); 636 tty_insert_flip_string(tty, data, urb->actual_length);
637 tty_flip_buffer_push(tty); 637 tty_flip_buffer_push(tty);
638 } 638 }
639 tty_kref_put(tty);
639 iuu_led_activity_on(urb); 640 iuu_led_activity_on(urb);
640} 641}
641 642
diff --git a/drivers/usb/serial/keyspan.c b/drivers/usb/serial/keyspan.c
index 704716f6f6d3..15447af48691 100644
--- a/drivers/usb/serial/keyspan.c
+++ b/drivers/usb/serial/keyspan.c
@@ -430,7 +430,7 @@ static void usa26_indat_callback(struct urb *urb)
430 } 430 }
431 431
432 port = urb->context; 432 port = urb->context;
433 tty = port->port.tty; 433 tty = tty_port_tty_get(&port->port);
434 if (tty && urb->actual_length) { 434 if (tty && urb->actual_length) {
435 /* 0x80 bit is error flag */ 435 /* 0x80 bit is error flag */
436 if ((data[0] & 0x80) == 0) { 436 if ((data[0] & 0x80) == 0) {
@@ -459,6 +459,7 @@ static void usa26_indat_callback(struct urb *urb)
459 } 459 }
460 tty_flip_buffer_push(tty); 460 tty_flip_buffer_push(tty);
461 } 461 }
462 tty_kref_put(tty);
462 463
463 /* Resubmit urb so we continue receiving */ 464 /* Resubmit urb so we continue receiving */
464 urb->dev = port->serial->dev; 465 urb->dev = port->serial->dev;
@@ -513,6 +514,7 @@ static void usa26_instat_callback(struct urb *urb)
513 struct usb_serial *serial; 514 struct usb_serial *serial;
514 struct usb_serial_port *port; 515 struct usb_serial_port *port;
515 struct keyspan_port_private *p_priv; 516 struct keyspan_port_private *p_priv;
517 struct tty_struct *tty;
516 int old_dcd_state, err; 518 int old_dcd_state, err;
517 int status = urb->status; 519 int status = urb->status;
518 520
@@ -553,12 +555,11 @@ static void usa26_instat_callback(struct urb *urb)
553 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0); 555 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
554 p_priv->ri_state = ((msg->ri) ? 1 : 0); 556 p_priv->ri_state = ((msg->ri) ? 1 : 0);
555 557
556 if (port->port.tty && !C_CLOCAL(port->port.tty) 558 if (old_dcd_state != p_priv->dcd_state) {
557 && old_dcd_state != p_priv->dcd_state) { 559 tty = tty_port_tty_get(&port->port);
558 if (old_dcd_state) 560 if (tty && !C_CLOCAL(tty))
559 tty_hangup(port->port.tty); 561 tty_hangup(tty);
560 /* else */ 562 tty_kref_put(tty);
561 /* wake_up_interruptible(&p_priv->open_wait); */
562 } 563 }
563 564
564 /* Resubmit urb so we continue receiving */ 565 /* Resubmit urb so we continue receiving */
@@ -604,11 +605,12 @@ static void usa28_indat_callback(struct urb *urb)
604 p_priv = usb_get_serial_port_data(port); 605 p_priv = usb_get_serial_port_data(port);
605 data = urb->transfer_buffer; 606 data = urb->transfer_buffer;
606 607
607 tty = port->port.tty; 608 tty =tty_port_tty_get(&port->port);
608 if (urb->actual_length) { 609 if (tty && urb->actual_length) {
609 tty_insert_flip_string(tty, data, urb->actual_length); 610 tty_insert_flip_string(tty, data, urb->actual_length);
610 tty_flip_buffer_push(tty); 611 tty_flip_buffer_push(tty);
611 } 612 }
613 tty_kref_put(tty);
612 614
613 /* Resubmit urb so we continue receiving */ 615 /* Resubmit urb so we continue receiving */
614 urb->dev = port->serial->dev; 616 urb->dev = port->serial->dev;
@@ -652,6 +654,7 @@ static void usa28_instat_callback(struct urb *urb)
652 struct usb_serial *serial; 654 struct usb_serial *serial;
653 struct usb_serial_port *port; 655 struct usb_serial_port *port;
654 struct keyspan_port_private *p_priv; 656 struct keyspan_port_private *p_priv;
657 struct tty_struct *tty;
655 int old_dcd_state; 658 int old_dcd_state;
656 int status = urb->status; 659 int status = urb->status;
657 660
@@ -689,12 +692,11 @@ static void usa28_instat_callback(struct urb *urb)
689 p_priv->dcd_state = ((msg->dcd) ? 1 : 0); 692 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
690 p_priv->ri_state = ((msg->ri) ? 1 : 0); 693 p_priv->ri_state = ((msg->ri) ? 1 : 0);
691 694
692 if (port->port.tty && !C_CLOCAL(port->port.tty) 695 if( old_dcd_state != p_priv->dcd_state && old_dcd_state) {
693 && old_dcd_state != p_priv->dcd_state) { 696 tty = tty_port_tty_get(&port->port);
694 if (old_dcd_state) 697 if (tty && !C_CLOCAL(tty))
695 tty_hangup(port->port.tty); 698 tty_hangup(tty);
696 /* else */ 699 tty_kref_put(tty);
697 /* wake_up_interruptible(&p_priv->open_wait); */
698 } 700 }
699 701
700 /* Resubmit urb so we continue receiving */ 702 /* Resubmit urb so we continue receiving */
@@ -785,12 +787,11 @@ static void usa49_instat_callback(struct urb *urb)
785 p_priv->dcd_state = ((msg->dcd) ? 1 : 0); 787 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
786 p_priv->ri_state = ((msg->ri) ? 1 : 0); 788 p_priv->ri_state = ((msg->ri) ? 1 : 0);
787 789
788 if (port->port.tty && !C_CLOCAL(port->port.tty) 790 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
789 && old_dcd_state != p_priv->dcd_state) { 791 struct tty_struct *tty = tty_port_tty_get(&port->port);
790 if (old_dcd_state) 792 if (tty && !C_CLOCAL(tty))
791 tty_hangup(port->port.tty); 793 tty_hangup(tty);
792 /* else */ 794 tty_kref_put(tty);
793 /* wake_up_interruptible(&p_priv->open_wait); */
794 } 795 }
795 796
796 /* Resubmit urb so we continue receiving */ 797 /* Resubmit urb so we continue receiving */
@@ -827,7 +828,7 @@ static void usa49_indat_callback(struct urb *urb)
827 } 828 }
828 829
829 port = urb->context; 830 port = urb->context;
830 tty = port->port.tty; 831 tty = tty_port_tty_get(&port->port);
831 if (tty && urb->actual_length) { 832 if (tty && urb->actual_length) {
832 /* 0x80 bit is error flag */ 833 /* 0x80 bit is error flag */
833 if ((data[0] & 0x80) == 0) { 834 if ((data[0] & 0x80) == 0) {
@@ -850,6 +851,7 @@ static void usa49_indat_callback(struct urb *urb)
850 } 851 }
851 tty_flip_buffer_push(tty); 852 tty_flip_buffer_push(tty);
852 } 853 }
854 tty_kref_put(tty);
853 855
854 /* Resubmit urb so we continue receiving */ 856 /* Resubmit urb so we continue receiving */
855 urb->dev = port->serial->dev; 857 urb->dev = port->serial->dev;
@@ -893,7 +895,7 @@ static void usa49wg_indat_callback(struct urb *urb)
893 return; 895 return;
894 } 896 }
895 port = serial->port[data[i++]]; 897 port = serial->port[data[i++]];
896 tty = port->port.tty; 898 tty = tty_port_tty_get(&port->port);
897 len = data[i++]; 899 len = data[i++];
898 900
899 /* 0x80 bit is error flag */ 901 /* 0x80 bit is error flag */
@@ -927,6 +929,7 @@ static void usa49wg_indat_callback(struct urb *urb)
927 } 929 }
928 if (port->port.count) 930 if (port->port.count)
929 tty_flip_buffer_push(tty); 931 tty_flip_buffer_push(tty);
932 tty_kref_put(tty);
930 } 933 }
931 } 934 }
932 935
@@ -967,8 +970,8 @@ static void usa90_indat_callback(struct urb *urb)
967 port = urb->context; 970 port = urb->context;
968 p_priv = usb_get_serial_port_data(port); 971 p_priv = usb_get_serial_port_data(port);
969 972
970 tty = port->port.tty;
971 if (urb->actual_length) { 973 if (urb->actual_length) {
974 tty = tty_port_tty_get(&port->port);
972 /* if current mode is DMA, looks like usa28 format 975 /* if current mode is DMA, looks like usa28 format
973 otherwise looks like usa26 data format */ 976 otherwise looks like usa26 data format */
974 977
@@ -1004,6 +1007,7 @@ static void usa90_indat_callback(struct urb *urb)
1004 } 1007 }
1005 } 1008 }
1006 tty_flip_buffer_push(tty); 1009 tty_flip_buffer_push(tty);
1010 tty_kref_put(tty);
1007 } 1011 }
1008 1012
1009 /* Resubmit urb so we continue receiving */ 1013 /* Resubmit urb so we continue receiving */
@@ -1025,6 +1029,7 @@ static void usa90_instat_callback(struct urb *urb)
1025 struct usb_serial *serial; 1029 struct usb_serial *serial;
1026 struct usb_serial_port *port; 1030 struct usb_serial_port *port;
1027 struct keyspan_port_private *p_priv; 1031 struct keyspan_port_private *p_priv;
1032 struct tty_struct *tty;
1028 int old_dcd_state, err; 1033 int old_dcd_state, err;
1029 int status = urb->status; 1034 int status = urb->status;
1030 1035
@@ -1053,12 +1058,11 @@ static void usa90_instat_callback(struct urb *urb)
1053 p_priv->dcd_state = ((msg->dcd) ? 1 : 0); 1058 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
1054 p_priv->ri_state = ((msg->ri) ? 1 : 0); 1059 p_priv->ri_state = ((msg->ri) ? 1 : 0);
1055 1060
1056 if (port->port.tty && !C_CLOCAL(port->port.tty) 1061 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
1057 && old_dcd_state != p_priv->dcd_state) { 1062 tty = tty_port_tty_get(&port->port);
1058 if (old_dcd_state) 1063 if (tty && !C_CLOCAL(tty))
1059 tty_hangup(port->port.tty); 1064 tty_hangup(tty);
1060 /* else */ 1065 tty_kref_put(tty);
1061 /* wake_up_interruptible(&p_priv->open_wait); */
1062 } 1066 }
1063 1067
1064 /* Resubmit urb so we continue receiving */ 1068 /* Resubmit urb so we continue receiving */
@@ -1130,12 +1134,11 @@ static void usa67_instat_callback(struct urb *urb)
1130 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0); 1134 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
1131 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0); 1135 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
1132 1136
1133 if (port->port.tty && !C_CLOCAL(port->port.tty) 1137 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
1134 && old_dcd_state != p_priv->dcd_state) { 1138 struct tty_struct *tty = tty_port_tty_get(&port->port);
1135 if (old_dcd_state) 1139 if (tty && !C_CLOCAL(tty))
1136 tty_hangup(port->port.tty); 1140 tty_hangup(tty);
1137 /* else */ 1141 tty_kref_put(tty);
1138 /* wake_up_interruptible(&p_priv->open_wait); */
1139 } 1142 }
1140 1143
1141 /* Resubmit urb so we continue receiving */ 1144 /* Resubmit urb so we continue receiving */
@@ -1332,7 +1335,7 @@ static void keyspan_close(struct tty_struct *tty,
1332 stop_urb(p_priv->out_urbs[i]); 1335 stop_urb(p_priv->out_urbs[i]);
1333 } 1336 }
1334 } 1337 }
1335 port->port.tty = NULL; 1338 tty_port_tty_set(&port->port, NULL);
1336} 1339}
1337 1340
1338/* download the firmware to a pre-renumeration device */ 1341/* download the firmware to a pre-renumeration device */
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index 040040a267d9..99e9a14c5bf6 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -172,8 +172,9 @@ static void keyspan_pda_wakeup_write(struct work_struct *work)
172 struct keyspan_pda_private *priv = 172 struct keyspan_pda_private *priv =
173 container_of(work, struct keyspan_pda_private, wakeup_work); 173 container_of(work, struct keyspan_pda_private, wakeup_work);
174 struct usb_serial_port *port = priv->port; 174 struct usb_serial_port *port = priv->port;
175 175 struct tty_struct *tty = tty_port_tty_get(&port->port);
176 tty_wakeup(port->port.tty); 176 tty_wakeup(tty);
177 tty_kref_put(tty);
177} 178}
178 179
179static void keyspan_pda_request_unthrottle(struct work_struct *work) 180static void keyspan_pda_request_unthrottle(struct work_struct *work)
@@ -205,7 +206,7 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work)
205static void keyspan_pda_rx_interrupt(struct urb *urb) 206static void keyspan_pda_rx_interrupt(struct urb *urb)
206{ 207{
207 struct usb_serial_port *port = urb->context; 208 struct usb_serial_port *port = urb->context;
208 struct tty_struct *tty = port->port.tty; 209 struct tty_struct *tty = tty_port_tty_get(&port->port);
209 unsigned char *data = urb->transfer_buffer; 210 unsigned char *data = urb->transfer_buffer;
210 int retval; 211 int retval;
211 int status = urb->status; 212 int status = urb->status;
@@ -222,7 +223,7 @@ static void keyspan_pda_rx_interrupt(struct urb *urb)
222 /* this urb is terminated, clean up */ 223 /* this urb is terminated, clean up */
223 dbg("%s - urb shutting down with status: %d", 224 dbg("%s - urb shutting down with status: %d",
224 __func__, status); 225 __func__, status);
225 return; 226 goto out;
226 default: 227 default:
227 dbg("%s - nonzero urb status received: %d", 228 dbg("%s - nonzero urb status received: %d",
228 __func__, status); 229 __func__, status);
@@ -261,8 +262,11 @@ static void keyspan_pda_rx_interrupt(struct urb *urb)
261exit: 262exit:
262 retval = usb_submit_urb(urb, GFP_ATOMIC); 263 retval = usb_submit_urb(urb, GFP_ATOMIC);
263 if (retval) 264 if (retval)
264 err("%s - usb_submit_urb failed with result %d", 265 dev_err(&port->dev,
265 __func__, retval); 266 "%s - usb_submit_urb failed with result %d",
267 __func__, retval);
268out:
269 tty_kref_put(tty);
266} 270}
267 271
268 272
diff --git a/drivers/usb/serial/kl5kusb105.c b/drivers/usb/serial/kl5kusb105.c
index b84dddc71124..ff3a07f5102f 100644
--- a/drivers/usb/serial/kl5kusb105.c
+++ b/drivers/usb/serial/kl5kusb105.c
@@ -658,7 +658,7 @@ static void klsi_105_read_bulk_callback(struct urb *urb)
658 } else { 658 } else {
659 int bytes_sent = ((__u8 *) data)[0] + 659 int bytes_sent = ((__u8 *) data)[0] +
660 ((unsigned int) ((__u8 *) data)[1] << 8); 660 ((unsigned int) ((__u8 *) data)[1] << 8);
661 tty = port->port.tty; 661 tty = tty_port_tty_get(&port->port);
662 /* we should immediately resubmit the URB, before attempting 662 /* we should immediately resubmit the URB, before attempting
663 * to pass the data on to the tty layer. But that needs locking 663 * to pass the data on to the tty layer. But that needs locking
664 * against re-entry an then mixed-up data because of 664 * against re-entry an then mixed-up data because of
@@ -679,6 +679,7 @@ static void klsi_105_read_bulk_callback(struct urb *urb)
679 tty_buffer_request_room(tty, bytes_sent); 679 tty_buffer_request_room(tty, bytes_sent);
680 tty_insert_flip_string(tty, data + 2, bytes_sent); 680 tty_insert_flip_string(tty, data + 2, bytes_sent);
681 tty_flip_buffer_push(tty); 681 tty_flip_buffer_push(tty);
682 tty_kref_put(tty);
682 683
683 /* again lockless, but debug info only */ 684 /* again lockless, but debug info only */
684 priv->bytes_in += bytes_sent; 685 priv->bytes_in += bytes_sent;
diff --git a/drivers/usb/serial/kobil_sct.c b/drivers/usb/serial/kobil_sct.c
index deba28ec77e8..cfcf37c2b957 100644
--- a/drivers/usb/serial/kobil_sct.c
+++ b/drivers/usb/serial/kobil_sct.c
@@ -383,7 +383,7 @@ static void kobil_read_int_callback(struct urb *urb)
383 return; 383 return;
384 } 384 }
385 385
386 tty = port->port.tty; 386 tty = tty_port_tty_get(&port->port);
387 if (urb->actual_length) { 387 if (urb->actual_length) {
388 388
389 /* BEGIN DEBUG */ 389 /* BEGIN DEBUG */
@@ -405,6 +405,7 @@ static void kobil_read_int_callback(struct urb *urb)
405 tty_insert_flip_string(tty, data, urb->actual_length); 405 tty_insert_flip_string(tty, data, urb->actual_length);
406 tty_flip_buffer_push(tty); 406 tty_flip_buffer_push(tty);
407 } 407 }
408 tty_kref_put(tty);
408 /* someone sets the dev to 0 if the close method has been called */ 409 /* someone sets the dev to 0 if the close method has been called */
409 port->interrupt_in_urb->dev = port->serial->dev; 410 port->interrupt_in_urb->dev = port->serial->dev;
410 411
diff --git a/drivers/usb/serial/mct_u232.c b/drivers/usb/serial/mct_u232.c
index 0ded8bd6ec85..9b2cef81cde0 100644
--- a/drivers/usb/serial/mct_u232.c
+++ b/drivers/usb/serial/mct_u232.c
@@ -563,10 +563,11 @@ static void mct_u232_read_int_callback(struct urb *urb)
563 * Work-a-round: handle the 'usual' bulk-in pipe here 563 * Work-a-round: handle the 'usual' bulk-in pipe here
564 */ 564 */
565 if (urb->transfer_buffer_length > 2) { 565 if (urb->transfer_buffer_length > 2) {
566 tty = port->port.tty; 566 tty = tty_port_tty_get(&port->port);
567 if (urb->actual_length) { 567 if (urb->actual_length) {
568 tty_insert_flip_string(tty, data, urb->actual_length); 568 tty_insert_flip_string(tty, data, urb->actual_length);
569 tty_flip_buffer_push(tty); 569 tty_flip_buffer_push(tty);
570 tty_kref_put(tty);
570 } 571 }
571 goto exit; 572 goto exit;
572 } 573 }
@@ -591,7 +592,7 @@ static void mct_u232_read_int_callback(struct urb *urb)
591 * to look in to this before committing any code. 592 * to look in to this before committing any code.
592 */ 593 */
593 if (priv->last_lsr & MCT_U232_LSR_ERR) { 594 if (priv->last_lsr & MCT_U232_LSR_ERR) {
594 tty = port->port.tty; 595 tty = tty_port_tty_get(&port->port);
595 /* Overrun Error */ 596 /* Overrun Error */
596 if (priv->last_lsr & MCT_U232_LSR_OE) { 597 if (priv->last_lsr & MCT_U232_LSR_OE) {
597 } 598 }
@@ -604,6 +605,7 @@ static void mct_u232_read_int_callback(struct urb *urb)
604 /* Break Indicator */ 605 /* Break Indicator */
605 if (priv->last_lsr & MCT_U232_LSR_BI) { 606 if (priv->last_lsr & MCT_U232_LSR_BI) {
606 } 607 }
608 tty_kref_put(tty);
607 } 609 }
608#endif 610#endif
609 spin_unlock_irqrestore(&priv->lock, flags); 611 spin_unlock_irqrestore(&priv->lock, flags);
diff --git a/drivers/usb/serial/mos7720.c b/drivers/usb/serial/mos7720.c
index 7c4917d77c0a..7b538caec37f 100644
--- a/drivers/usb/serial/mos7720.c
+++ b/drivers/usb/serial/mos7720.c
@@ -216,12 +216,13 @@ static void mos7720_bulk_in_callback(struct urb *urb)
216 216
217 data = urb->transfer_buffer; 217 data = urb->transfer_buffer;
218 218
219 tty = port->port.tty; 219 tty = tty_port_tty_get(&port->port);
220 if (tty && urb->actual_length) { 220 if (tty && urb->actual_length) {
221 tty_buffer_request_room(tty, urb->actual_length); 221 tty_buffer_request_room(tty, urb->actual_length);
222 tty_insert_flip_string(tty, data, urb->actual_length); 222 tty_insert_flip_string(tty, data, urb->actual_length);
223 tty_flip_buffer_push(tty); 223 tty_flip_buffer_push(tty);
224 } 224 }
225 tty_kref_put(tty);
225 226
226 if (!port->read_urb) { 227 if (!port->read_urb) {
227 dbg("URB KILLED !!!"); 228 dbg("URB KILLED !!!");
@@ -262,10 +263,11 @@ static void mos7720_bulk_out_data_callback(struct urb *urb)
262 263
263 dbg("Entering ........."); 264 dbg("Entering .........");
264 265
265 tty = mos7720_port->port->port.tty; 266 tty = tty_port_tty_get(&mos7720_port->port->port);
266 267
267 if (tty && mos7720_port->open) 268 if (tty && mos7720_port->open)
268 tty_wakeup(tty); 269 tty_wakeup(tty);
270 tty_kref_put(tty);
269} 271}
270 272
271/* 273/*
@@ -1267,29 +1269,6 @@ static int get_lsr_info(struct tty_struct *tty,
1267 return 0; 1269 return 0;
1268} 1270}
1269 1271
1270/*
1271 * get_number_bytes_avail - get number of bytes available
1272 *
1273 * Purpose: Let user call ioctl to get the count of number of bytes available.
1274 */
1275static int get_number_bytes_avail(struct moschip_port *mos7720_port,
1276 unsigned int __user *value)
1277{
1278 unsigned int result = 0;
1279 struct tty_struct *tty = mos7720_port->port->port.tty;
1280
1281 if (!tty)
1282 return -ENOIOCTLCMD;
1283
1284 result = tty->read_cnt;
1285
1286 dbg("%s(%d) = %d", __func__, mos7720_port->port->number, result);
1287 if (copy_to_user(value, &result, sizeof(int)))
1288 return -EFAULT;
1289
1290 return -ENOIOCTLCMD;
1291}
1292
1293static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd, 1272static int set_modem_info(struct moschip_port *mos7720_port, unsigned int cmd,
1294 unsigned int __user *value) 1273 unsigned int __user *value)
1295{ 1274{
@@ -1409,13 +1388,6 @@ static int mos7720_ioctl(struct tty_struct *tty, struct file *file,
1409 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd); 1388 dbg("%s - port %d, cmd = 0x%x", __func__, port->number, cmd);
1410 1389
1411 switch (cmd) { 1390 switch (cmd) {
1412 case TIOCINQ:
1413 /* return number of bytes available */
1414 dbg("%s (%d) TIOCINQ", __func__, port->number);
1415 return get_number_bytes_avail(mos7720_port,
1416 (unsigned int __user *)arg);
1417 break;
1418
1419 case TIOCSERGETLSR: 1391 case TIOCSERGETLSR:
1420 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number); 1392 dbg("%s (%d) TIOCSERGETLSR", __func__, port->number);
1421 return get_lsr_info(tty, mos7720_port, 1393 return get_lsr_info(tty, mos7720_port,
diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
index 09d82062b973..60543d79ef56 100644
--- a/drivers/usb/serial/mos7840.c
+++ b/drivers/usb/serial/mos7840.c
@@ -709,12 +709,13 @@ static void mos7840_bulk_in_callback(struct urb *urb)
709 dbg("%s", "Entering ........... \n"); 709 dbg("%s", "Entering ........... \n");
710 710
711 if (urb->actual_length) { 711 if (urb->actual_length) {
712 tty = mos7840_port->port->port.tty; 712 tty = tty_port_tty_get(&mos7840_port->port->port);
713 if (tty) { 713 if (tty) {
714 tty_buffer_request_room(tty, urb->actual_length); 714 tty_buffer_request_room(tty, urb->actual_length);
715 tty_insert_flip_string(tty, data, urb->actual_length); 715 tty_insert_flip_string(tty, data, urb->actual_length);
716 dbg(" %s \n", data); 716 dbg(" %s \n", data);
717 tty_flip_buffer_push(tty); 717 tty_flip_buffer_push(tty);
718 tty_kref_put(tty);
718 } 719 }
719 mos7840_port->icount.rx += urb->actual_length; 720 mos7840_port->icount.rx += urb->actual_length;
720 smp_wmb(); 721 smp_wmb();
@@ -773,10 +774,10 @@ static void mos7840_bulk_out_data_callback(struct urb *urb)
773 774
774 dbg("%s \n", "Entering ........."); 775 dbg("%s \n", "Entering .........");
775 776
776 tty = mos7840_port->port->port.tty; 777 tty = tty_port_tty_get(&mos7840_port->port->port);
777
778 if (tty && mos7840_port->open) 778 if (tty && mos7840_port->open)
779 tty_wakeup(tty); 779 tty_wakeup(tty);
780 tty_kref_put(tty);
780 781
781} 782}
782 783
diff --git a/drivers/usb/serial/navman.c b/drivers/usb/serial/navman.c
index d6736531a0fa..bcdcbb822705 100644
--- a/drivers/usb/serial/navman.c
+++ b/drivers/usb/serial/navman.c
@@ -64,12 +64,13 @@ static void navman_read_int_callback(struct urb *urb)
64 usb_serial_debug_data(debug, &port->dev, __func__, 64 usb_serial_debug_data(debug, &port->dev, __func__,
65 urb->actual_length, data); 65 urb->actual_length, data);
66 66
67 tty = port->port.tty; 67 tty = tty_port_tty_get(&port->port);
68 if (tty && urb->actual_length) { 68 if (tty && urb->actual_length) {
69 tty_buffer_request_room(tty, urb->actual_length); 69 tty_buffer_request_room(tty, urb->actual_length);
70 tty_insert_flip_string(tty, data, urb->actual_length); 70 tty_insert_flip_string(tty, data, urb->actual_length);
71 tty_flip_buffer_push(tty); 71 tty_flip_buffer_push(tty);
72 } 72 }
73 tty_kref_put(tty);
73 74
74exit: 75exit:
75 result = usb_submit_urb(urb, GFP_ATOMIC); 76 result = usb_submit_urb(urb, GFP_ATOMIC);
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index ae8e227f3db2..c4d70b0f1e48 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -172,7 +172,7 @@ static int omninet_open(struct tty_struct *tty,
172 dbg("%s - port %d", __func__, port->number); 172 dbg("%s - port %d", __func__, port->number);
173 173
174 wport = serial->port[1]; 174 wport = serial->port[1];
175 wport->port.tty = tty; /* FIXME */ 175 tty_port_tty_set(&wport->port, tty);
176 176
177 /* Start reading from the device */ 177 /* Start reading from the device */
178 usb_fill_bulk_urb(port->read_urb, serial->dev, 178 usb_fill_bulk_urb(port->read_urb, serial->dev,
@@ -229,9 +229,11 @@ static void omninet_read_bulk_callback(struct urb *urb)
229 } 229 }
230 230
231 if (urb->actual_length && header->oh_len) { 231 if (urb->actual_length && header->oh_len) {
232 tty_insert_flip_string(port->port.tty, 232 struct tty_struct *tty = tty_port_tty_get(&port->port);
233 data + OMNINET_DATAOFFSET, header->oh_len); 233 tty_insert_flip_string(tty, data + OMNINET_DATAOFFSET,
234 tty_flip_buffer_push(port->port.tty); 234 header->oh_len);
235 tty_flip_buffer_push(tty);
236 tty_kref_put(tty);
235 } 237 }
236 238
237 /* Continue trying to always read */ 239 /* Continue trying to always read */
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index 73f8277f88f2..6b1727e751e3 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -571,14 +571,14 @@ static void option_indat_callback(struct urb *urb)
571 dbg("%s: nonzero status: %d on endpoint %02x.", 571 dbg("%s: nonzero status: %d on endpoint %02x.",
572 __func__, status, endpoint); 572 __func__, status, endpoint);
573 } else { 573 } else {
574 tty = port->port.tty; 574 tty = tty_port_tty_get(&port->port);
575 if (urb->actual_length) { 575 if (urb->actual_length) {
576 tty_buffer_request_room(tty, urb->actual_length); 576 tty_buffer_request_room(tty, urb->actual_length);
577 tty_insert_flip_string(tty, data, urb->actual_length); 577 tty_insert_flip_string(tty, data, urb->actual_length);
578 tty_flip_buffer_push(tty); 578 tty_flip_buffer_push(tty);
579 } else { 579 } else
580 dbg("%s: empty read urb received", __func__); 580 dbg("%s: empty read urb received", __func__);
581 } 581 tty_kref_put(tty);
582 582
583 /* Resubmit urb so we continue receiving */ 583 /* Resubmit urb so we continue receiving */
584 if (port->port.count && status != -ESHUTDOWN) { 584 if (port->port.count && status != -ESHUTDOWN) {
@@ -647,9 +647,13 @@ static void option_instat_callback(struct urb *urb)
647 portdata->dsr_state = ((signals & 0x02) ? 1 : 0); 647 portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
648 portdata->ri_state = ((signals & 0x08) ? 1 : 0); 648 portdata->ri_state = ((signals & 0x08) ? 1 : 0);
649 649
650 if (port->port.tty && !C_CLOCAL(port->port.tty) && 650 if (old_dcd_state && !portdata->dcd_state) {
651 old_dcd_state && !portdata->dcd_state) 651 struct tty_struct *tty =
652 tty_hangup(port->port.tty); 652 tty_port_tty_get(&port->port);
653 if (tty && !C_CLOCAL(tty))
654 tty_hangup(tty);
655 tty_kref_put(tty);
656 }
653 } else { 657 } else {
654 dbg("%s: type %x req %x", __func__, 658 dbg("%s: type %x req %x", __func__,
655 req_pkt->bRequestType, req_pkt->bRequest); 659 req_pkt->bRequestType, req_pkt->bRequest);
@@ -793,7 +797,7 @@ static void option_close(struct tty_struct *tty,
793 for (i = 0; i < N_OUT_URB; i++) 797 for (i = 0; i < N_OUT_URB; i++)
794 usb_kill_urb(portdata->out_urbs[i]); 798 usb_kill_urb(portdata->out_urbs[i]);
795 } 799 }
796 port->port.tty = NULL; /* FIXME */ 800 tty_port_tty_set(&port->port, NULL);
797} 801}
798 802
799/* Helper functions used by option_setup_urbs */ 803/* Helper functions used by option_setup_urbs */
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c
index 81db5715ee25..ba551f00f16f 100644
--- a/drivers/usb/serial/oti6858.c
+++ b/drivers/usb/serial/oti6858.c
@@ -224,10 +224,6 @@ struct oti6858_private {
224 struct usb_serial_port *port; /* USB port with which associated */ 224 struct usb_serial_port *port; /* USB port with which associated */
225}; 225};
226 226
227#undef dbg
228/* #define dbg(format, arg...) printk(KERN_INFO "%s: " format "\n", __FILE__, ## arg) */
229#define dbg(format, arg...) printk(KERN_INFO "" format "\n", ## arg)
230
231static void setup_line(struct work_struct *work) 227static void setup_line(struct work_struct *work)
232{ 228{
233 struct oti6858_private *priv = container_of(work, 229 struct oti6858_private *priv = container_of(work,
@@ -1002,11 +998,12 @@ static void oti6858_read_bulk_callback(struct urb *urb)
1002 return; 998 return;
1003 } 999 }
1004 1000
1005 tty = port->port.tty; 1001 tty = tty_port_tty_get(&port->port);
1006 if (tty != NULL && urb->actual_length > 0) { 1002 if (tty != NULL && urb->actual_length > 0) {
1007 tty_insert_flip_string(tty, data, urb->actual_length); 1003 tty_insert_flip_string(tty, data, urb->actual_length);
1008 tty_flip_buffer_push(tty); 1004 tty_flip_buffer_push(tty);
1009 } 1005 }
1006 tty_kref_put(tty);
1010 1007
1011 /* schedule the interrupt urb if we are still open */ 1008 /* schedule the interrupt urb if we are still open */
1012 if (port->port.count != 0) { 1009 if (port->port.count != 0) {
diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
index 1ede1441cb1b..908437847165 100644
--- a/drivers/usb/serial/pl2303.c
+++ b/drivers/usb/serial/pl2303.c
@@ -154,7 +154,6 @@ struct pl2303_private {
154 wait_queue_head_t delta_msr_wait; 154 wait_queue_head_t delta_msr_wait;
155 u8 line_control; 155 u8 line_control;
156 u8 line_status; 156 u8 line_status;
157 u8 termios_initialized;
158 enum pl2303_type type; 157 enum pl2303_type type;
159}; 158};
160 159
@@ -526,16 +525,6 @@ static void pl2303_set_termios(struct tty_struct *tty,
526 525
527 dbg("%s - port %d", __func__, port->number); 526 dbg("%s - port %d", __func__, port->number);
528 527
529 spin_lock_irqsave(&priv->lock, flags);
530 if (!priv->termios_initialized) {
531 *(tty->termios) = tty_std_termios;
532 tty->termios->c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
533 tty->termios->c_ispeed = 9600;
534 tty->termios->c_ospeed = 9600;
535 priv->termios_initialized = 1;
536 }
537 spin_unlock_irqrestore(&priv->lock, flags);
538
539 /* The PL2303 is reported to lose bytes if you change 528 /* The PL2303 is reported to lose bytes if you change
540 serial settings even to the same values as before. Thus 529 serial settings even to the same values as before. Thus
541 we actually need to filter in this specific case */ 530 we actually need to filter in this specific case */
@@ -1057,7 +1046,7 @@ static void pl2303_read_bulk_callback(struct urb *urb)
1057 tty_flag = TTY_FRAME; 1046 tty_flag = TTY_FRAME;
1058 dbg("%s - tty_flag = %d", __func__, tty_flag); 1047 dbg("%s - tty_flag = %d", __func__, tty_flag);
1059 1048
1060 tty = port->port.tty; 1049 tty = tty_port_tty_get(&port->port);
1061 if (tty && urb->actual_length) { 1050 if (tty && urb->actual_length) {
1062 tty_buffer_request_room(tty, urb->actual_length + 1); 1051 tty_buffer_request_room(tty, urb->actual_length + 1);
1063 /* overrun is special, not associated with a char */ 1052 /* overrun is special, not associated with a char */
@@ -1067,7 +1056,7 @@ static void pl2303_read_bulk_callback(struct urb *urb)
1067 tty_insert_flip_char(tty, data[i], tty_flag); 1056 tty_insert_flip_char(tty, data[i], tty_flag);
1068 tty_flip_buffer_push(tty); 1057 tty_flip_buffer_push(tty);
1069 } 1058 }
1070 1059 tty_kref_put(tty);
1071 /* Schedule the next read _if_ we are still open */ 1060 /* Schedule the next read _if_ we are still open */
1072 if (port->port.count) { 1061 if (port->port.count) {
1073 urb->dev = port->serial->dev; 1062 urb->dev = port->serial->dev;
diff --git a/drivers/usb/serial/safe_serial.c b/drivers/usb/serial/safe_serial.c
index def52d07a4ea..72903ac9f5c0 100644
--- a/drivers/usb/serial/safe_serial.c
+++ b/drivers/usb/serial/safe_serial.c
@@ -217,6 +217,7 @@ static void safe_read_bulk_callback(struct urb *urb)
217 struct usb_serial_port *port = urb->context; 217 struct usb_serial_port *port = urb->context;
218 unsigned char *data = urb->transfer_buffer; 218 unsigned char *data = urb->transfer_buffer;
219 unsigned char length = urb->actual_length; 219 unsigned char length = urb->actual_length;
220 struct tty_struct *tty;
220 int result; 221 int result;
221 int status = urb->status; 222 int status = urb->status;
222 223
@@ -242,6 +243,7 @@ static void safe_read_bulk_callback(struct urb *urb)
242 printk("\n"); 243 printk("\n");
243 } 244 }
244#endif 245#endif
246 tty = tty_port_tty_get(&port->port);
245 if (safe) { 247 if (safe) {
246 __u16 fcs; 248 __u16 fcs;
247 fcs = fcs_compute10(data, length, CRC10_INITFCS); 249 fcs = fcs_compute10(data, length, CRC10_INITFCS);
@@ -250,9 +252,9 @@ static void safe_read_bulk_callback(struct urb *urb)
250 if (actual_length <= (length - 2)) { 252 if (actual_length <= (length - 2)) {
251 info("%s - actual: %d", __func__, 253 info("%s - actual: %d", __func__,
252 actual_length); 254 actual_length);
253 tty_insert_flip_string(port->port.tty, 255 tty_insert_flip_string(tty,
254 data, actual_length); 256 data, actual_length);
255 tty_flip_buffer_push(port->port.tty); 257 tty_flip_buffer_push(tty);
256 } else { 258 } else {
257 err("%s - inconsistent lengths %d:%d", 259 err("%s - inconsistent lengths %d:%d",
258 __func__, actual_length, length); 260 __func__, actual_length, length);
@@ -261,9 +263,10 @@ static void safe_read_bulk_callback(struct urb *urb)
261 err("%s - bad CRC %x", __func__, fcs); 263 err("%s - bad CRC %x", __func__, fcs);
262 } 264 }
263 } else { 265 } else {
264 tty_insert_flip_string(port->port.tty, data, length); 266 tty_insert_flip_string(tty, data, length);
265 tty_flip_buffer_push(port->port.tty); 267 tty_flip_buffer_push(tty);
266 } 268 }
269 tty_kref_put(tty);
267 270
268 /* Continue trying to always read */ 271 /* Continue trying to always read */
269 usb_fill_bulk_urb(urb, port->serial->dev, 272 usb_fill_bulk_urb(urb, port->serial->dev,
diff --git a/drivers/usb/serial/sierra.c b/drivers/usb/serial/sierra.c
index ea1a103c99be..8b9eaf383679 100644
--- a/drivers/usb/serial/sierra.c
+++ b/drivers/usb/serial/sierra.c
@@ -440,14 +440,14 @@ static void sierra_indat_callback(struct urb *urb)
440 dbg("%s: nonzero status: %d on endpoint %02x.", 440 dbg("%s: nonzero status: %d on endpoint %02x.",
441 __func__, status, endpoint); 441 __func__, status, endpoint);
442 } else { 442 } else {
443 tty = port->port.tty;
444 if (urb->actual_length) { 443 if (urb->actual_length) {
444 tty = tty_port_tty_get(&port->port);
445 tty_buffer_request_room(tty, urb->actual_length); 445 tty_buffer_request_room(tty, urb->actual_length);
446 tty_insert_flip_string(tty, data, urb->actual_length); 446 tty_insert_flip_string(tty, data, urb->actual_length);
447 tty_flip_buffer_push(tty); 447 tty_flip_buffer_push(tty);
448 } else { 448 tty_kref_put(tty);
449 } else
449 dbg("%s: empty read urb received", __func__); 450 dbg("%s: empty read urb received", __func__);
450 }
451 451
452 /* Resubmit urb so we continue receiving */ 452 /* Resubmit urb so we continue receiving */
453 if (port->port.count && status != -ESHUTDOWN) { 453 if (port->port.count && status != -ESHUTDOWN) {
@@ -485,6 +485,7 @@ static void sierra_instat_callback(struct urb *urb)
485 unsigned char signals = *((unsigned char *) 485 unsigned char signals = *((unsigned char *)
486 urb->transfer_buffer + 486 urb->transfer_buffer +
487 sizeof(struct usb_ctrlrequest)); 487 sizeof(struct usb_ctrlrequest));
488 struct tty_struct *tty;
488 489
489 dbg("%s: signal x%x", __func__, signals); 490 dbg("%s: signal x%x", __func__, signals);
490 491
@@ -494,9 +495,11 @@ static void sierra_instat_callback(struct urb *urb)
494 portdata->dsr_state = ((signals & 0x02) ? 1 : 0); 495 portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
495 portdata->ri_state = ((signals & 0x08) ? 1 : 0); 496 portdata->ri_state = ((signals & 0x08) ? 1 : 0);
496 497
497 if (port->port.tty && !C_CLOCAL(port->port.tty) && 498 tty = tty_port_tty_get(&port->port);
499 if (tty && !C_CLOCAL(tty) &&
498 old_dcd_state && !portdata->dcd_state) 500 old_dcd_state && !portdata->dcd_state)
499 tty_hangup(port->port.tty); 501 tty_hangup(tty);
502 tty_kref_put(tty);
500 } else { 503 } else {
501 dbg("%s: type %x req %x", __func__, 504 dbg("%s: type %x req %x", __func__,
502 req_pkt->bRequestType, req_pkt->bRequest); 505 req_pkt->bRequestType, req_pkt->bRequest);
@@ -616,8 +619,7 @@ static void sierra_close(struct tty_struct *tty,
616 } 619 }
617 620
618 usb_kill_urb(port->interrupt_in_urb); 621 usb_kill_urb(port->interrupt_in_urb);
619 622 tty_port_tty_set(&port->port, NULL);
620 port->port.tty = NULL; /* FIXME */
621} 623}
622 624
623static int sierra_startup(struct usb_serial *serial) 625static int sierra_startup(struct usb_serial *serial)
diff --git a/drivers/usb/serial/spcp8x5.c b/drivers/usb/serial/spcp8x5.c
index 283cf6b36b2c..1533d6e12238 100644
--- a/drivers/usb/serial/spcp8x5.c
+++ b/drivers/usb/serial/spcp8x5.c
@@ -755,7 +755,7 @@ static void spcp8x5_read_bulk_callback(struct urb *urb)
755 tty_flag = TTY_FRAME; 755 tty_flag = TTY_FRAME;
756 dev_dbg(&port->dev, "tty_flag = %d\n", tty_flag); 756 dev_dbg(&port->dev, "tty_flag = %d\n", tty_flag);
757 757
758 tty = port->port.tty; 758 tty = tty_port_tty_get(&port->port);
759 if (tty && urb->actual_length) { 759 if (tty && urb->actual_length) {
760 tty_buffer_request_room(tty, urb->actual_length + 1); 760 tty_buffer_request_room(tty, urb->actual_length + 1);
761 /* overrun is special, not associated with a char */ 761 /* overrun is special, not associated with a char */
@@ -765,6 +765,7 @@ static void spcp8x5_read_bulk_callback(struct urb *urb)
765 tty_insert_flip_char(tty, data[i], tty_flag); 765 tty_insert_flip_char(tty, data[i], tty_flag);
766 tty_flip_buffer_push(tty); 766 tty_flip_buffer_push(tty);
767 } 767 }
768 tty_kref_put(tty);
768 769
769 /* Schedule the next read _if_ we are still open */ 770 /* Schedule the next read _if_ we are still open */
770 if (port->port.count) { 771 if (port->port.count) {
diff --git a/drivers/usb/serial/ti_usb_3410_5052.c b/drivers/usb/serial/ti_usb_3410_5052.c
index 9a3e495c769c..c90237d48b0e 100644
--- a/drivers/usb/serial/ti_usb_3410_5052.c
+++ b/drivers/usb/serial/ti_usb_3410_5052.c
@@ -179,7 +179,7 @@ static int ti_set_mcr(struct ti_port *tport, unsigned int mcr);
179static int ti_get_lsr(struct ti_port *tport); 179static int ti_get_lsr(struct ti_port *tport);
180static int ti_get_serial_info(struct ti_port *tport, 180static int ti_get_serial_info(struct ti_port *tport,
181 struct serial_struct __user *ret_arg); 181 struct serial_struct __user *ret_arg);
182static int ti_set_serial_info(struct ti_port *tport, 182static int ti_set_serial_info(struct tty_struct *tty, struct ti_port *tport,
183 struct serial_struct __user *new_arg); 183 struct serial_struct __user *new_arg);
184static void ti_handle_new_msr(struct ti_port *tport, __u8 msr); 184static void ti_handle_new_msr(struct ti_port *tport, __u8 msr);
185 185
@@ -857,8 +857,8 @@ static int ti_ioctl(struct tty_struct *tty, struct file *file,
857 (struct serial_struct __user *)arg); 857 (struct serial_struct __user *)arg);
858 case TIOCSSERIAL: 858 case TIOCSSERIAL:
859 dbg("%s - (%d) TIOCSSERIAL", __func__, port->number); 859 dbg("%s - (%d) TIOCSSERIAL", __func__, port->number);
860 return ti_set_serial_info(tport, 860 return ti_set_serial_info(tty, tport,
861 (struct serial_struct __user *)arg); 861 (struct serial_struct __user *)arg);
862 case TIOCMIWAIT: 862 case TIOCMIWAIT:
863 dbg("%s - (%d) TIOCMIWAIT", __func__, port->number); 863 dbg("%s - (%d) TIOCMIWAIT", __func__, port->number);
864 cprev = tport->tp_icount; 864 cprev = tport->tp_icount;
@@ -1211,6 +1211,7 @@ static void ti_bulk_in_callback(struct urb *urb)
1211 struct device *dev = &urb->dev->dev; 1211 struct device *dev = &urb->dev->dev;
1212 int status = urb->status; 1212 int status = urb->status;
1213 int retval = 0; 1213 int retval = 0;
1214 struct tty_struct *tty;
1214 1215
1215 dbg("%s", __func__); 1216 dbg("%s", __func__);
1216 1217
@@ -1239,20 +1240,22 @@ static void ti_bulk_in_callback(struct urb *urb)
1239 return; 1240 return;
1240 } 1241 }
1241 1242
1242 if (port->port.tty && urb->actual_length) { 1243 tty = tty_port_tty_get(&port->port);
1244 if (tty && urb->actual_length) {
1243 usb_serial_debug_data(debug, dev, __func__, 1245 usb_serial_debug_data(debug, dev, __func__,
1244 urb->actual_length, urb->transfer_buffer); 1246 urb->actual_length, urb->transfer_buffer);
1245 1247
1246 if (!tport->tp_is_open) 1248 if (!tport->tp_is_open)
1247 dbg("%s - port closed, dropping data", __func__); 1249 dbg("%s - port closed, dropping data", __func__);
1248 else 1250 else
1249 ti_recv(&urb->dev->dev, port->port.tty, 1251 ti_recv(&urb->dev->dev, tty,
1250 urb->transfer_buffer, 1252 urb->transfer_buffer,
1251 urb->actual_length); 1253 urb->actual_length);
1252 1254
1253 spin_lock(&tport->tp_lock); 1255 spin_lock(&tport->tp_lock);
1254 tport->tp_icount.rx += urb->actual_length; 1256 tport->tp_icount.rx += urb->actual_length;
1255 spin_unlock(&tport->tp_lock); 1257 spin_unlock(&tport->tp_lock);
1258 tty_kref_put(tty);
1256 } 1259 }
1257 1260
1258exit: 1261exit:
@@ -1330,7 +1333,7 @@ static void ti_send(struct ti_port *tport)
1330{ 1333{
1331 int count, result; 1334 int count, result;
1332 struct usb_serial_port *port = tport->tp_port; 1335 struct usb_serial_port *port = tport->tp_port;
1333 struct tty_struct *tty = port->port.tty; /* FIXME */ 1336 struct tty_struct *tty = tty_port_tty_get(&port->port); /* FIXME */
1334 unsigned long flags; 1337 unsigned long flags;
1335 1338
1336 1339
@@ -1338,19 +1341,15 @@ static void ti_send(struct ti_port *tport)
1338 1341
1339 spin_lock_irqsave(&tport->tp_lock, flags); 1342 spin_lock_irqsave(&tport->tp_lock, flags);
1340 1343
1341 if (tport->tp_write_urb_in_use) { 1344 if (tport->tp_write_urb_in_use)
1342 spin_unlock_irqrestore(&tport->tp_lock, flags); 1345 goto unlock;
1343 return;
1344 }
1345 1346
1346 count = ti_buf_get(tport->tp_write_buf, 1347 count = ti_buf_get(tport->tp_write_buf,
1347 port->write_urb->transfer_buffer, 1348 port->write_urb->transfer_buffer,
1348 port->bulk_out_size); 1349 port->bulk_out_size);
1349 1350
1350 if (count == 0) { 1351 if (count == 0)
1351 spin_unlock_irqrestore(&tport->tp_lock, flags); 1352 goto unlock;
1352 return;
1353 }
1354 1353
1355 tport->tp_write_urb_in_use = 1; 1354 tport->tp_write_urb_in_use = 1;
1356 1355
@@ -1380,7 +1379,13 @@ static void ti_send(struct ti_port *tport)
1380 /* more room in the buffer for new writes, wakeup */ 1379 /* more room in the buffer for new writes, wakeup */
1381 if (tty) 1380 if (tty)
1382 tty_wakeup(tty); 1381 tty_wakeup(tty);
1382 tty_kref_put(tty);
1383 wake_up_interruptible(&tport->tp_write_wait); 1383 wake_up_interruptible(&tport->tp_write_wait);
1384 return;
1385unlock:
1386 spin_unlock_irqrestore(&tport->tp_lock, flags);
1387 tty_kref_put(tty);
1388 return;
1384} 1389}
1385 1390
1386 1391
@@ -1464,20 +1469,16 @@ static int ti_get_serial_info(struct ti_port *tport,
1464} 1469}
1465 1470
1466 1471
1467static int ti_set_serial_info(struct ti_port *tport, 1472static int ti_set_serial_info(struct tty_struct *tty, struct ti_port *tport,
1468 struct serial_struct __user *new_arg) 1473 struct serial_struct __user *new_arg)
1469{ 1474{
1470 struct usb_serial_port *port = tport->tp_port;
1471 struct serial_struct new_serial; 1475 struct serial_struct new_serial;
1472 1476
1473 if (copy_from_user(&new_serial, new_arg, sizeof(new_serial))) 1477 if (copy_from_user(&new_serial, new_arg, sizeof(new_serial)))
1474 return -EFAULT; 1478 return -EFAULT;
1475 1479
1476 tport->tp_flags = new_serial.flags & TI_SET_SERIAL_FLAGS; 1480 tport->tp_flags = new_serial.flags & TI_SET_SERIAL_FLAGS;
1477 /* FIXME */ 1481 tty->low_latency = (tport->tp_flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1478 if (port->port.tty)
1479 port->port.tty->low_latency =
1480 (tport->tp_flags & ASYNC_LOW_LATENCY) ? 1 : 0;
1481 tport->tp_closing_wait = new_serial.closing_wait; 1482 tport->tp_closing_wait = new_serial.closing_wait;
1482 1483
1483 return 0; 1484 return 0;
@@ -1510,7 +1511,7 @@ static void ti_handle_new_msr(struct ti_port *tport, __u8 msr)
1510 tport->tp_msr = msr & TI_MSR_MASK; 1511 tport->tp_msr = msr & TI_MSR_MASK;
1511 1512
1512 /* handle CTS flow control */ 1513 /* handle CTS flow control */
1513 tty = tport->tp_port->port.tty; 1514 tty = tty_port_tty_get(&tport->tp_port->port);
1514 if (tty && C_CRTSCTS(tty)) { 1515 if (tty && C_CRTSCTS(tty)) {
1515 if (msr & TI_MSR_CTS) { 1516 if (msr & TI_MSR_CTS) {
1516 tty->hw_stopped = 0; 1517 tty->hw_stopped = 0;
@@ -1519,6 +1520,7 @@ static void ti_handle_new_msr(struct ti_port *tport, __u8 msr)
1519 tty->hw_stopped = 1; 1520 tty->hw_stopped = 1;
1520 } 1521 }
1521 } 1522 }
1523 tty_kref_put(tty);
1522} 1524}
1523 1525
1524 1526
diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
index 4f7f9e3ae0a4..e7d4246027b2 100644
--- a/drivers/usb/serial/usb-serial.c
+++ b/drivers/usb/serial/usb-serial.c
@@ -214,7 +214,7 @@ static int serial_open (struct tty_struct *tty, struct file *filp)
214 /* set up our port structure making the tty driver 214 /* set up our port structure making the tty driver
215 * remember our port object, and us it */ 215 * remember our port object, and us it */
216 tty->driver_data = port; 216 tty->driver_data = port;
217 port->port.tty = tty; 217 tty_port_tty_set(&port->port, tty);
218 218
219 if (port->port.count == 1) { 219 if (port->port.count == 1) {
220 220
@@ -246,7 +246,7 @@ bailout_module_put:
246bailout_mutex_unlock: 246bailout_mutex_unlock:
247 port->port.count = 0; 247 port->port.count = 0;
248 tty->driver_data = NULL; 248 tty->driver_data = NULL;
249 port->port.tty = NULL; 249 tty_port_tty_set(&port->port, NULL);
250 mutex_unlock(&port->mutex); 250 mutex_unlock(&port->mutex);
251bailout_kref_put: 251bailout_kref_put:
252 usb_serial_put(serial); 252 usb_serial_put(serial);
@@ -276,10 +276,11 @@ static void serial_close(struct tty_struct *tty, struct file *filp)
276 port->serial->type->close(tty, port, filp); 276 port->serial->type->close(tty, port, filp);
277 277
278 if (port->port.count == (port->console? 1 : 0)) { 278 if (port->port.count == (port->console? 1 : 0)) {
279 if (port->port.tty) { 279 struct tty_struct *tty = tty_port_tty_get(&port->port);
280 if (port->port.tty->driver_data) 280 if (tty) {
281 port->port.tty->driver_data = NULL; 281 if (tty->driver_data)
282 port->port.tty = NULL; 282 tty->driver_data = NULL;
283 tty_port_tty_set(&port->port, NULL);
283 } 284 }
284 } 285 }
285 286
@@ -508,11 +509,12 @@ static void usb_serial_port_work(struct work_struct *work)
508 if (!port) 509 if (!port)
509 return; 510 return;
510 511
511 tty = port->port.tty; 512 tty = tty_port_tty_get(&port->port);
512 if (!tty) 513 if (!tty)
513 return; 514 return;
514 515
515 tty_wakeup(tty); 516 tty_wakeup(tty);
517 tty_kref_put(tty);
516} 518}
517 519
518static void port_release(struct device *dev) 520static void port_release(struct device *dev)
@@ -819,6 +821,7 @@ int usb_serial_probe(struct usb_interface *interface,
819 port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL); 821 port = kzalloc(sizeof(struct usb_serial_port), GFP_KERNEL);
820 if (!port) 822 if (!port)
821 goto probe_error; 823 goto probe_error;
824 tty_port_init(&port->port);
822 port->serial = serial; 825 port->serial = serial;
823 spin_lock_init(&port->lock); 826 spin_lock_init(&port->lock);
824 mutex_init(&port->mutex); 827 mutex_init(&port->mutex);
@@ -1040,8 +1043,11 @@ void usb_serial_disconnect(struct usb_interface *interface)
1040 for (i = 0; i < serial->num_ports; ++i) { 1043 for (i = 0; i < serial->num_ports; ++i) {
1041 port = serial->port[i]; 1044 port = serial->port[i];
1042 if (port) { 1045 if (port) {
1043 if (port->port.tty) 1046 struct tty_struct *tty = tty_port_tty_get(&port->port);
1044 tty_hangup(port->port.tty); 1047 if (tty) {
1048 tty_hangup(tty);
1049 tty_kref_put(tty);
1050 }
1045 kill_traffic(port); 1051 kill_traffic(port);
1046 } 1052 }
1047 } 1053 }
diff --git a/drivers/usb/serial/visor.c b/drivers/usb/serial/visor.c
index cf8924f9a2cc..a6d1c75a1c89 100644
--- a/drivers/usb/serial/visor.c
+++ b/drivers/usb/serial/visor.c
@@ -499,7 +499,7 @@ static void visor_read_bulk_callback(struct urb *urb)
499 int status = urb->status; 499 int status = urb->status;
500 struct tty_struct *tty; 500 struct tty_struct *tty;
501 int result; 501 int result;
502 int available_room; 502 int available_room = 0;
503 503
504 dbg("%s - port %d", __func__, port->number); 504 dbg("%s - port %d", __func__, port->number);
505 505
@@ -512,13 +512,17 @@ static void visor_read_bulk_callback(struct urb *urb)
512 usb_serial_debug_data(debug, &port->dev, __func__, 512 usb_serial_debug_data(debug, &port->dev, __func__,
513 urb->actual_length, data); 513 urb->actual_length, data);
514 514
515 tty = port->port.tty; 515 if (urb->actual_length) {
516 if (tty && urb->actual_length) { 516 tty = tty_port_tty_get(&port->port);
517 available_room = tty_buffer_request_room(tty, 517 if (tty) {
518 available_room = tty_buffer_request_room(tty,
518 urb->actual_length); 519 urb->actual_length);
519 if (available_room) { 520 if (available_room) {
520 tty_insert_flip_string(tty, data, available_room); 521 tty_insert_flip_string(tty, data,
521 tty_flip_buffer_push(tty); 522 available_room);
523 tty_flip_buffer_push(tty);
524 }
525 tty_kref_put(tty);
522 } 526 }
523 spin_lock(&priv->lock); 527 spin_lock(&priv->lock);
524 priv->bytes_in += available_room; 528 priv->bytes_in += available_room;
diff --git a/drivers/usb/serial/whiteheat.c b/drivers/usb/serial/whiteheat.c
index 3a9d14384a43..11c8b97a5177 100644
--- a/drivers/usb/serial/whiteheat.c
+++ b/drivers/usb/serial/whiteheat.c
@@ -1481,7 +1481,7 @@ static void rx_data_softint(struct work_struct *work)
1481 struct whiteheat_private *info = 1481 struct whiteheat_private *info =
1482 container_of(work, struct whiteheat_private, rx_work); 1482 container_of(work, struct whiteheat_private, rx_work);
1483 struct usb_serial_port *port = info->port; 1483 struct usb_serial_port *port = info->port;
1484 struct tty_struct *tty = port->port.tty; 1484 struct tty_struct *tty = tty_port_tty_get(&port->port);
1485 struct whiteheat_urb_wrap *wrap; 1485 struct whiteheat_urb_wrap *wrap;
1486 struct urb *urb; 1486 struct urb *urb;
1487 unsigned long flags; 1487 unsigned long flags;
@@ -1493,7 +1493,7 @@ static void rx_data_softint(struct work_struct *work)
1493 spin_lock_irqsave(&info->lock, flags); 1493 spin_lock_irqsave(&info->lock, flags);
1494 if (info->flags & THROTTLED) { 1494 if (info->flags & THROTTLED) {
1495 spin_unlock_irqrestore(&info->lock, flags); 1495 spin_unlock_irqrestore(&info->lock, flags);
1496 return; 1496 goto out;
1497 } 1497 }
1498 1498
1499 list_for_each_safe(tmp, tmp2, &info->rx_urb_q) { 1499 list_for_each_safe(tmp, tmp2, &info->rx_urb_q) {
@@ -1513,7 +1513,7 @@ static void rx_data_softint(struct work_struct *work)
1513 spin_unlock_irqrestore(&info->lock, flags); 1513 spin_unlock_irqrestore(&info->lock, flags);
1514 tty_flip_buffer_push(tty); 1514 tty_flip_buffer_push(tty);
1515 schedule_work(&info->rx_work); 1515 schedule_work(&info->rx_work);
1516 return; 1516 goto out;
1517 } 1517 }
1518 tty_insert_flip_string(tty, urb->transfer_buffer, len); 1518 tty_insert_flip_string(tty, urb->transfer_buffer, len);
1519 sent += len; 1519 sent += len;
@@ -1536,6 +1536,8 @@ static void rx_data_softint(struct work_struct *work)
1536 1536
1537 if (sent) 1537 if (sent)
1538 tty_flip_buffer_push(tty); 1538 tty_flip_buffer_push(tty);
1539out:
1540 tty_kref_put(tty);
1539} 1541}
1540 1542
1541 1543
diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index f79c2040758b..0f13448c6f79 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -76,6 +76,14 @@ config FB_DDC
76 select I2C 76 select I2C
77 default n 77 default n
78 78
79config FB_BOOT_VESA_SUPPORT
80 bool
81 depends on FB
82 default n
83 ---help---
84 If true, at least one selected framebuffer driver can take advantage
85 of VESA video modes set at an early boot stage via the vga= parameter.
86
79config FB_CFB_FILLRECT 87config FB_CFB_FILLRECT
80 tristate 88 tristate
81 depends on FB 89 depends on FB
@@ -254,16 +262,24 @@ config FB_PM2
254 select FB_CFB_COPYAREA 262 select FB_CFB_COPYAREA
255 select FB_CFB_IMAGEBLIT 263 select FB_CFB_IMAGEBLIT
256 help 264 help
257 This is the frame buffer device driver for the Permedia2 AGP frame 265 This is the frame buffer device driver for cards based on
258 buffer card from ASK, aka `Graphic Blaster Exxtreme'. There is a 266 the 3D Labs Permedia, Permedia 2 and Permedia 2V chips.
259 product page at 267 The driver was tested on the following cards:
260 <http://www.ask.com.hk/product/Permedia%202/permedia2.htm>. 268 Diamond FireGL 1000 PRO AGP
269 ELSA Gloria Synergy PCI
270 Appian Jeronimo PRO (both heads) PCI
271 3DLabs Oxygen ACX aka EONtronics Picasso P2 PCI
272 Techsource Raptor GFX-8P (aka Sun PGX-32) on SPARC
273 ASK Graphic Blaster Exxtreme AGP
274
275 To compile this driver as a module, choose M here: the
276 module will be called pm2fb.
261 277
262config FB_PM2_FIFO_DISCONNECT 278config FB_PM2_FIFO_DISCONNECT
263 bool "enable FIFO disconnect feature" 279 bool "enable FIFO disconnect feature"
264 depends on FB_PM2 && PCI 280 depends on FB_PM2 && PCI
265 help 281 help
266 Support the Permedia2 FIFO disconnect feature (see CONFIG_FB_PM2). 282 Support the Permedia2 FIFO disconnect feature.
267 283
268config FB_ARMCLCD 284config FB_ARMCLCD
269 tristate "ARM PrimeCell PL110 support" 285 tristate "ARM PrimeCell PL110 support"
@@ -673,6 +689,7 @@ config FB_VESA
673 select FB_CFB_FILLRECT 689 select FB_CFB_FILLRECT
674 select FB_CFB_COPYAREA 690 select FB_CFB_COPYAREA
675 select FB_CFB_IMAGEBLIT 691 select FB_CFB_IMAGEBLIT
692 select FB_BOOT_VESA_SUPPORT
676 help 693 help
677 This is the frame buffer device driver for generic VESA 2.0 694 This is the frame buffer device driver for generic VESA 2.0
678 compliant graphic cards. The older VESA 1.2 cards are not supported. 695 compliant graphic cards. The older VESA 1.2 cards are not supported.
@@ -681,23 +698,14 @@ config FB_VESA
681 698
682config FB_EFI 699config FB_EFI
683 bool "EFI-based Framebuffer Support" 700 bool "EFI-based Framebuffer Support"
684 depends on (FB = y) && X86
685 select FB_CFB_FILLRECT
686 select FB_CFB_COPYAREA
687 select FB_CFB_IMAGEBLIT
688 help
689 This is the EFI frame buffer device driver. If the firmware on
690 your platform is UEFI2.0, select Y to add support for
691 Graphics Output Protocol for early console messages to appear.
692
693config FB_IMAC
694 bool "Intel-based Macintosh Framebuffer Support"
695 depends on (FB = y) && X86 && EFI 701 depends on (FB = y) && X86 && EFI
696 select FB_CFB_FILLRECT 702 select FB_CFB_FILLRECT
697 select FB_CFB_COPYAREA 703 select FB_CFB_COPYAREA
698 select FB_CFB_IMAGEBLIT 704 select FB_CFB_IMAGEBLIT
699 help 705 help
700 This is the frame buffer device driver for the Intel-based Macintosh 706 This is the EFI frame buffer device driver. If the firmware on
707 your platform is EFI 1.10 or UEFI 2.0, select Y to add support for
708 using the EFI framebuffer as your console.
701 709
702config FB_N411 710config FB_N411
703 tristate "N411 Apollo/Hecuba devkit support" 711 tristate "N411 Apollo/Hecuba devkit support"
@@ -1118,6 +1126,7 @@ config FB_INTEL
1118 select FB_CFB_FILLRECT 1126 select FB_CFB_FILLRECT
1119 select FB_CFB_COPYAREA 1127 select FB_CFB_COPYAREA
1120 select FB_CFB_IMAGEBLIT 1128 select FB_CFB_IMAGEBLIT
1129 select FB_BOOT_VESA_SUPPORT
1121 help 1130 help
1122 This driver supports the on-board graphics built in to the Intel 1131 This driver supports the on-board graphics built in to the Intel
1123 830M/845G/852GM/855GM/865G/915G/915GM/945G/945GM/965G/965GM chipsets. 1132 830M/845G/852GM/855GM/865G/915G/915GM/945G/945GM/965G/965GM chipsets.
@@ -1470,6 +1479,7 @@ config FB_SIS
1470 select FB_CFB_FILLRECT 1479 select FB_CFB_FILLRECT
1471 select FB_CFB_COPYAREA 1480 select FB_CFB_COPYAREA
1472 select FB_CFB_IMAGEBLIT 1481 select FB_CFB_IMAGEBLIT
1482 select FB_BOOT_VESA_SUPPORT
1473 help 1483 help
1474 This is the frame buffer device driver for the SiS 300, 315, 330 1484 This is the frame buffer device driver for the SiS 300, 315, 330
1475 and 340 series as well as XGI V3XT, V5, V8, Z7 graphics chipsets. 1485 and 340 series as well as XGI V3XT, V5, V8, Z7 graphics chipsets.
@@ -1492,6 +1502,24 @@ config FB_SIS_315
1492 (315/H/PRO, 55x, 650, 651, 740, 330, 661, 741, 760, 761) as well 1502 (315/H/PRO, 55x, 650, 651, 740, 330, 661, 741, 760, 761) as well
1493 as XGI V3XT, V5, V8 and Z7. 1503 as XGI V3XT, V5, V8 and Z7.
1494 1504
1505config FB_VIA
1506 tristate "VIA UniChrome (Pro) and Chrome9 display support"
1507 depends on FB && PCI
1508 select FB_CFB_FILLRECT
1509 select FB_CFB_COPYAREA
1510 select FB_CFB_IMAGEBLIT
1511 select FB_SOFT_CURSOR
1512 select I2C_ALGOBIT
1513 select I2C
1514 help
1515 This is the frame buffer device driver for Graphics chips of VIA
1516 UniChrome (Pro) Family (CLE266,PM800/CN400,P4M800CE/P4M800Pro/
1517 CN700/VN800,CX700/VX700,P4M890) and Chrome9 Family (K8M890,CN896
1518 /P4M900,VX800)
1519 Say Y if you have a VIA UniChrome graphics board.
1520
1521 To compile this driver as a module, choose M here: the
1522 module will be called viafb.
1495config FB_NEOMAGIC 1523config FB_NEOMAGIC
1496 tristate "NeoMagic display support" 1524 tristate "NeoMagic display support"
1497 depends on FB && PCI 1525 depends on FB && PCI
@@ -1521,25 +1549,25 @@ config FB_KYRO
1521 module will be called kyrofb. 1549 module will be called kyrofb.
1522 1550
1523config FB_3DFX 1551config FB_3DFX
1524 tristate "3Dfx Banshee/Voodoo3 display support" 1552 tristate "3Dfx Banshee/Voodoo3/Voodoo5 display support"
1525 depends on FB && PCI 1553 depends on FB && PCI
1526 select FB_CFB_IMAGEBLIT 1554 select FB_CFB_IMAGEBLIT
1527 select FB_CFB_FILLRECT 1555 select FB_CFB_FILLRECT
1528 select FB_CFB_COPYAREA 1556 select FB_CFB_COPYAREA
1529 help 1557 help
1530 This driver supports graphics boards with the 3Dfx Banshee/Voodoo3 1558 This driver supports graphics boards with the 3Dfx Banshee,
1531 chips. Say Y if you have such a graphics board. 1559 Voodoo3 or VSA-100 (aka Voodoo4/5) chips. Say Y if you have
1560 such a graphics board.
1532 1561
1533 To compile this driver as a module, choose M here: the 1562 To compile this driver as a module, choose M here: the
1534 module will be called tdfxfb. 1563 module will be called tdfxfb.
1535 1564
1536config FB_3DFX_ACCEL 1565config FB_3DFX_ACCEL
1537 bool "3Dfx Banshee/Voodoo3 Acceleration functions (EXPERIMENTAL)" 1566 bool "3Dfx Acceleration functions (EXPERIMENTAL)"
1538 depends on FB_3DFX && EXPERIMENTAL 1567 depends on FB_3DFX && EXPERIMENTAL
1539 ---help--- 1568 ---help---
1540 This will compile the 3Dfx Banshee/Voodoo3 frame buffer device 1569 This will compile the 3Dfx Banshee/Voodoo3/VSA-100 frame buffer
1541 with acceleration functions. 1570 device driver with acceleration functions.
1542
1543 1571
1544config FB_VOODOO1 1572config FB_VOODOO1
1545 tristate "3Dfx Voodoo Graphics (sst1) support" 1573 tristate "3Dfx Voodoo Graphics (sst1) support"
@@ -1604,17 +1632,16 @@ config FB_TRIDENT
1604 select FB_CFB_COPYAREA 1632 select FB_CFB_COPYAREA
1605 select FB_CFB_IMAGEBLIT 1633 select FB_CFB_IMAGEBLIT
1606 ---help--- 1634 ---help---
1607 This driver is supposed to support graphics boards with the 1635 This is the frame buffer device driver for Trident PCI/AGP chipsets.
1608 Trident CyberXXXX/Image/CyberBlade chips mostly found in laptops 1636 Supported chipset families are TGUI 9440/96XX, 3DImage, Blade3D
1637 and Blade XP.
1638 There are also integrated versions of these chips called CyberXXXX,
1639 CyberImage or CyberBlade. These chips are mostly found in laptops
1609 but also on some motherboards. For more information, read 1640 but also on some motherboards. For more information, read
1610 <file:Documentation/fb/tridentfb.txt> 1641 <file:Documentation/fb/tridentfb.txt>
1611 1642
1612 Cyberblade/i1 support will be removed soon, use the cyblafb driver
1613 instead.
1614
1615 Say Y if you have such a graphics board. 1643 Say Y if you have such a graphics board.
1616 1644
1617
1618 To compile this driver as a module, choose M here: the 1645 To compile this driver as a module, choose M here: the
1619 module will be called tridentfb. 1646 module will be called tridentfb.
1620 1647
@@ -1869,6 +1896,28 @@ config FB_SH_MOBILE_LCDC
1869 ---help--- 1896 ---help---
1870 Frame buffer driver for the on-chip SH-Mobile LCD controller. 1897 Frame buffer driver for the on-chip SH-Mobile LCD controller.
1871 1898
1899config FB_TMIO
1900 tristate "Toshiba Mobile IO FrameBuffer support"
1901 depends on FB && MFD_CORE
1902 select FB_CFB_FILLRECT
1903 select FB_CFB_COPYAREA
1904 select FB_CFB_IMAGEBLIT
1905 ---help---
1906 Frame buffer driver for the Toshiba Mobile IO integrated as found
1907 on the Sharp SL-6000 series
1908
1909 This driver is also available as a module ( = code which can be
1910 inserted and removed from the running kernel whenever you want). The
1911 module will be called tmiofb. If you want to compile it as a module,
1912 say M here and read <file:Documentation/kbuild/modules.txt>.
1913
1914 If unsure, say N.
1915
1916config FB_TMIO_ACCELL
1917 bool "tmiofb acceleration"
1918 depends on FB_TMIO
1919 default y
1920
1872config FB_S3C2410 1921config FB_S3C2410
1873 tristate "S3C2410 LCD framebuffer support" 1922 tristate "S3C2410 LCD framebuffer support"
1874 depends on FB && ARCH_S3C2410 1923 depends on FB && ARCH_S3C2410
diff --git a/drivers/video/Makefile b/drivers/video/Makefile
index ad0330bf9be3..248bddc8d0b0 100644
--- a/drivers/video/Makefile
+++ b/drivers/video/Makefile
@@ -42,6 +42,7 @@ obj-$(CONFIG_FB_ATY) += aty/ macmodes.o
42obj-$(CONFIG_FB_ATY128) += aty/ macmodes.o 42obj-$(CONFIG_FB_ATY128) += aty/ macmodes.o
43obj-$(CONFIG_FB_RADEON) += aty/ 43obj-$(CONFIG_FB_RADEON) += aty/
44obj-$(CONFIG_FB_SIS) += sis/ 44obj-$(CONFIG_FB_SIS) += sis/
45obj-$(CONFIG_FB_VIA) += via/
45obj-$(CONFIG_FB_KYRO) += kyro/ 46obj-$(CONFIG_FB_KYRO) += kyro/
46obj-$(CONFIG_FB_SAVAGE) += savage/ 47obj-$(CONFIG_FB_SAVAGE) += savage/
47obj-$(CONFIG_FB_GEODE) += geode/ 48obj-$(CONFIG_FB_GEODE) += geode/
@@ -97,6 +98,7 @@ obj-$(CONFIG_FB_CIRRUS) += cirrusfb.o
97obj-$(CONFIG_FB_ASILIANT) += asiliantfb.o 98obj-$(CONFIG_FB_ASILIANT) += asiliantfb.o
98obj-$(CONFIG_FB_PXA) += pxafb.o 99obj-$(CONFIG_FB_PXA) += pxafb.o
99obj-$(CONFIG_FB_W100) += w100fb.o 100obj-$(CONFIG_FB_W100) += w100fb.o
101obj-$(CONFIG_FB_TMIO) += tmiofb.o
100obj-$(CONFIG_FB_AU1100) += au1100fb.o 102obj-$(CONFIG_FB_AU1100) += au1100fb.o
101obj-$(CONFIG_FB_AU1200) += au1200fb.o 103obj-$(CONFIG_FB_AU1200) += au1200fb.o
102obj-$(CONFIG_FB_PMAG_AA) += pmag-aa-fb.o 104obj-$(CONFIG_FB_PMAG_AA) += pmag-aa-fb.o
@@ -124,7 +126,6 @@ obj-$(CONFIG_FB_CARMINE) += carminefb.o
124# Platform or fallback drivers go here 126# Platform or fallback drivers go here
125obj-$(CONFIG_FB_UVESA) += uvesafb.o 127obj-$(CONFIG_FB_UVESA) += uvesafb.o
126obj-$(CONFIG_FB_VESA) += vesafb.o 128obj-$(CONFIG_FB_VESA) += vesafb.o
127obj-$(CONFIG_FB_IMAC) += imacfb.o
128obj-$(CONFIG_FB_EFI) += efifb.o 129obj-$(CONFIG_FB_EFI) += efifb.o
129obj-$(CONFIG_FB_VGA16) += vga16fb.o 130obj-$(CONFIG_FB_VGA16) += vga16fb.o
130obj-$(CONFIG_FB_OF) += offb.o 131obj-$(CONFIG_FB_OF) += offb.o
diff --git a/drivers/video/atmel_lcdfb.c b/drivers/video/atmel_lcdfb.c
index d38fd5217422..f8d0a57a07cb 100644
--- a/drivers/video/atmel_lcdfb.c
+++ b/drivers/video/atmel_lcdfb.c
@@ -372,6 +372,13 @@ static int atmel_lcdfb_check_var(struct fb_var_screeninfo *var,
372 var->transp.offset = var->transp.length = 0; 372 var->transp.offset = var->transp.length = 0;
373 var->xoffset = var->yoffset = 0; 373 var->xoffset = var->yoffset = 0;
374 374
375 if (info->fix.smem_len) {
376 unsigned int smem_len = (var->xres_virtual * var->yres_virtual
377 * ((var->bits_per_pixel + 7) / 8));
378 if (smem_len > info->fix.smem_len)
379 return -EINVAL;
380 }
381
375 /* Saturate vertical and horizontal timings at maximum values */ 382 /* Saturate vertical and horizontal timings at maximum values */
376 var->vsync_len = min_t(u32, var->vsync_len, 383 var->vsync_len = min_t(u32, var->vsync_len,
377 (ATMEL_LCDC_VPW >> ATMEL_LCDC_VPW_OFFSET) + 1); 384 (ATMEL_LCDC_VPW >> ATMEL_LCDC_VPW_OFFSET) + 1);
diff --git a/drivers/video/aty/radeon_accel.c b/drivers/video/aty/radeon_accel.c
index aa95f8350242..8718f7349d6b 100644
--- a/drivers/video/aty/radeon_accel.c
+++ b/drivers/video/aty/radeon_accel.c
@@ -5,61 +5,61 @@
5 * --dte 5 * --dte
6 */ 6 */
7 7
8static void radeon_fixup_offset(struct radeonfb_info *rinfo) 8#define FLUSH_CACHE_WORKAROUND 1
9
10void radeon_fifo_update_and_wait(struct radeonfb_info *rinfo, int entries)
9{ 11{
10 u32 local_base; 12 int i;
11
12 /* *** Ugly workaround *** */
13 /*
14 * On some platforms, the video memory is mapped at 0 in radeon chip space
15 * (like PPCs) by the firmware. X will always move it up so that it's seen
16 * by the chip to be at the same address as the PCI BAR.
17 * That means that when switching back from X, there is a mismatch between
18 * the offsets programmed into the engine. This means that potentially,
19 * accel operations done before radeonfb has a chance to re-init the engine
20 * will have incorrect offsets, and potentially trash system memory !
21 *
22 * The correct fix is for fbcon to never call any accel op before the engine
23 * has properly been re-initialized (by a call to set_var), but this is a
24 * complex fix. This workaround in the meantime, called before every accel
25 * operation, makes sure the offsets are in sync.
26 */
27 13
28 radeon_fifo_wait (1); 14 for (i=0; i<2000000; i++) {
29 local_base = INREG(MC_FB_LOCATION) << 16; 15 rinfo->fifo_free = INREG(RBBM_STATUS) & 0x7f;
30 if (local_base == rinfo->fb_local_base) 16 if (rinfo->fifo_free >= entries)
31 return; 17 return;
18 udelay(10);
19 }
20 printk(KERN_ERR "radeonfb: FIFO Timeout !\n");
21 /* XXX Todo: attempt to reset the engine */
22}
32 23
33 rinfo->fb_local_base = local_base; 24static inline void radeon_fifo_wait(struct radeonfb_info *rinfo, int entries)
25{
26 if (entries <= rinfo->fifo_free)
27 rinfo->fifo_free -= entries;
28 else
29 radeon_fifo_update_and_wait(rinfo, entries);
30}
34 31
35 radeon_fifo_wait (3); 32static inline void radeonfb_set_creg(struct radeonfb_info *rinfo, u32 reg,
36 OUTREG(DEFAULT_PITCH_OFFSET, (rinfo->pitch << 0x16) | 33 u32 *cache, u32 new_val)
37 (rinfo->fb_local_base >> 10)); 34{
38 OUTREG(DST_PITCH_OFFSET, (rinfo->pitch << 0x16) | (rinfo->fb_local_base >> 10)); 35 if (new_val == *cache)
39 OUTREG(SRC_PITCH_OFFSET, (rinfo->pitch << 0x16) | (rinfo->fb_local_base >> 10)); 36 return;
37 *cache = new_val;
38 radeon_fifo_wait(rinfo, 1);
39 OUTREG(reg, new_val);
40} 40}
41 41
42static void radeonfb_prim_fillrect(struct radeonfb_info *rinfo, 42static void radeonfb_prim_fillrect(struct radeonfb_info *rinfo,
43 const struct fb_fillrect *region) 43 const struct fb_fillrect *region)
44{ 44{
45 radeon_fifo_wait(4); 45 radeonfb_set_creg(rinfo, DP_GUI_MASTER_CNTL, &rinfo->dp_gui_mc_cache,
46 46 rinfo->dp_gui_mc_base | GMC_BRUSH_SOLID_COLOR | ROP3_P);
47 OUTREG(DP_GUI_MASTER_CNTL, 47 radeonfb_set_creg(rinfo, DP_CNTL, &rinfo->dp_cntl_cache,
48 rinfo->dp_gui_master_cntl /* contains, like GMC_DST_32BPP */ 48 DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM);
49 | GMC_BRUSH_SOLID_COLOR 49 radeonfb_set_creg(rinfo, DP_BRUSH_FRGD_CLR, &rinfo->dp_brush_fg_cache,
50 | ROP3_P); 50 region->color);
51 if (radeon_get_dstbpp(rinfo->depth) != DST_8BPP) 51
52 OUTREG(DP_BRUSH_FRGD_CLR, rinfo->pseudo_palette[region->color]); 52 /* Ensure the dst cache is flushed and the engine idle before
53 else 53 * issuing the operation.
54 OUTREG(DP_BRUSH_FRGD_CLR, region->color); 54 *
55 OUTREG(DP_WRITE_MSK, 0xffffffff); 55 * This works around engine lockups on some cards
56 OUTREG(DP_CNTL, (DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM)); 56 */
57 57#if FLUSH_CACHE_WORKAROUND
58 radeon_fifo_wait(2); 58 radeon_fifo_wait(rinfo, 2);
59 OUTREG(DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL); 59 OUTREG(DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL);
60 OUTREG(WAIT_UNTIL, (WAIT_2D_IDLECLEAN | WAIT_DMA_GUI_IDLE)); 60 OUTREG(WAIT_UNTIL, (WAIT_2D_IDLECLEAN | WAIT_DMA_GUI_IDLE));
61 61#endif
62 radeon_fifo_wait(2); 62 radeon_fifo_wait(rinfo, 2);
63 OUTREG(DST_Y_X, (region->dy << 16) | region->dx); 63 OUTREG(DST_Y_X, (region->dy << 16) | region->dx);
64 OUTREG(DST_WIDTH_HEIGHT, (region->width << 16) | region->height); 64 OUTREG(DST_WIDTH_HEIGHT, (region->width << 16) | region->height);
65} 65}
@@ -70,15 +70,14 @@ void radeonfb_fillrect(struct fb_info *info, const struct fb_fillrect *region)
70 struct fb_fillrect modded; 70 struct fb_fillrect modded;
71 int vxres, vyres; 71 int vxres, vyres;
72 72
73 if (info->state != FBINFO_STATE_RUNNING) 73 WARN_ON(rinfo->gfx_mode);
74 if (info->state != FBINFO_STATE_RUNNING || rinfo->gfx_mode)
74 return; 75 return;
75 if (info->flags & FBINFO_HWACCEL_DISABLED) { 76 if (info->flags & FBINFO_HWACCEL_DISABLED) {
76 cfb_fillrect(info, region); 77 cfb_fillrect(info, region);
77 return; 78 return;
78 } 79 }
79 80
80 radeon_fixup_offset(rinfo);
81
82 vxres = info->var.xres_virtual; 81 vxres = info->var.xres_virtual;
83 vyres = info->var.yres_virtual; 82 vyres = info->var.yres_virtual;
84 83
@@ -91,6 +90,10 @@ void radeonfb_fillrect(struct fb_info *info, const struct fb_fillrect *region)
91 if(modded.dx + modded.width > vxres) modded.width = vxres - modded.dx; 90 if(modded.dx + modded.width > vxres) modded.width = vxres - modded.dx;
92 if(modded.dy + modded.height > vyres) modded.height = vyres - modded.dy; 91 if(modded.dy + modded.height > vyres) modded.height = vyres - modded.dy;
93 92
93 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
94 info->fix.visual == FB_VISUAL_DIRECTCOLOR )
95 modded.color = ((u32 *) (info->pseudo_palette))[region->color];
96
94 radeonfb_prim_fillrect(rinfo, &modded); 97 radeonfb_prim_fillrect(rinfo, &modded);
95} 98}
96 99
@@ -109,22 +112,22 @@ static void radeonfb_prim_copyarea(struct radeonfb_info *rinfo,
109 if ( xdir < 0 ) { sx += w-1; dx += w-1; } 112 if ( xdir < 0 ) { sx += w-1; dx += w-1; }
110 if ( ydir < 0 ) { sy += h-1; dy += h-1; } 113 if ( ydir < 0 ) { sy += h-1; dy += h-1; }
111 114
112 radeon_fifo_wait(3); 115 radeonfb_set_creg(rinfo, DP_GUI_MASTER_CNTL, &rinfo->dp_gui_mc_cache,
113 OUTREG(DP_GUI_MASTER_CNTL, 116 rinfo->dp_gui_mc_base |
114 rinfo->dp_gui_master_cntl /* i.e. GMC_DST_32BPP */ 117 GMC_BRUSH_NONE |
115 | GMC_BRUSH_NONE 118 GMC_SRC_DATATYPE_COLOR |
116 | GMC_SRC_DSTCOLOR 119 ROP3_S |
117 | ROP3_S 120 DP_SRC_SOURCE_MEMORY);
118 | DP_SRC_SOURCE_MEMORY ); 121 radeonfb_set_creg(rinfo, DP_CNTL, &rinfo->dp_cntl_cache,
119 OUTREG(DP_WRITE_MSK, 0xffffffff); 122 (xdir>=0 ? DST_X_LEFT_TO_RIGHT : 0) |
120 OUTREG(DP_CNTL, (xdir>=0 ? DST_X_LEFT_TO_RIGHT : 0) 123 (ydir>=0 ? DST_Y_TOP_TO_BOTTOM : 0));
121 | (ydir>=0 ? DST_Y_TOP_TO_BOTTOM : 0)); 124
122 125#if FLUSH_CACHE_WORKAROUND
123 radeon_fifo_wait(2); 126 radeon_fifo_wait(rinfo, 2);
124 OUTREG(DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL); 127 OUTREG(DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL);
125 OUTREG(WAIT_UNTIL, (WAIT_2D_IDLECLEAN | WAIT_DMA_GUI_IDLE)); 128 OUTREG(WAIT_UNTIL, (WAIT_2D_IDLECLEAN | WAIT_DMA_GUI_IDLE));
126 129#endif
127 radeon_fifo_wait(3); 130 radeon_fifo_wait(rinfo, 3);
128 OUTREG(SRC_Y_X, (sy << 16) | sx); 131 OUTREG(SRC_Y_X, (sy << 16) | sx);
129 OUTREG(DST_Y_X, (dy << 16) | dx); 132 OUTREG(DST_Y_X, (dy << 16) | dx);
130 OUTREG(DST_HEIGHT_WIDTH, (h << 16) | w); 133 OUTREG(DST_HEIGHT_WIDTH, (h << 16) | w);
@@ -143,15 +146,14 @@ void radeonfb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
143 modded.width = area->width; 146 modded.width = area->width;
144 modded.height = area->height; 147 modded.height = area->height;
145 148
146 if (info->state != FBINFO_STATE_RUNNING) 149 WARN_ON(rinfo->gfx_mode);
150 if (info->state != FBINFO_STATE_RUNNING || rinfo->gfx_mode)
147 return; 151 return;
148 if (info->flags & FBINFO_HWACCEL_DISABLED) { 152 if (info->flags & FBINFO_HWACCEL_DISABLED) {
149 cfb_copyarea(info, area); 153 cfb_copyarea(info, area);
150 return; 154 return;
151 } 155 }
152 156
153 radeon_fixup_offset(rinfo);
154
155 vxres = info->var.xres_virtual; 157 vxres = info->var.xres_virtual;
156 vyres = info->var.yres_virtual; 158 vyres = info->var.yres_virtual;
157 159
@@ -168,13 +170,112 @@ void radeonfb_copyarea(struct fb_info *info, const struct fb_copyarea *area)
168 radeonfb_prim_copyarea(rinfo, &modded); 170 radeonfb_prim_copyarea(rinfo, &modded);
169} 171}
170 172
173static void radeonfb_prim_imageblit(struct radeonfb_info *rinfo,
174 const struct fb_image *image,
175 u32 fg, u32 bg)
176{
177 unsigned int src_bytes, dwords;
178 u32 *bits;
179
180 radeonfb_set_creg(rinfo, DP_GUI_MASTER_CNTL, &rinfo->dp_gui_mc_cache,
181 rinfo->dp_gui_mc_base |
182 GMC_BRUSH_NONE |
183 GMC_SRC_DATATYPE_MONO_FG_BG |
184 ROP3_S |
185 GMC_BYTE_ORDER_MSB_TO_LSB |
186 DP_SRC_SOURCE_HOST_DATA);
187 radeonfb_set_creg(rinfo, DP_CNTL, &rinfo->dp_cntl_cache,
188 DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM);
189 radeonfb_set_creg(rinfo, DP_SRC_FRGD_CLR, &rinfo->dp_src_fg_cache, fg);
190 radeonfb_set_creg(rinfo, DP_SRC_BKGD_CLR, &rinfo->dp_src_bg_cache, bg);
191
192 radeon_fifo_wait(rinfo, 1);
193 OUTREG(DST_Y_X, (image->dy << 16) | image->dx);
194
195 /* Ensure the dst cache is flushed and the engine idle before
196 * issuing the operation.
197 *
198 * This works around engine lockups on some cards
199 */
200#if FLUSH_CACHE_WORKAROUND
201 radeon_fifo_wait(rinfo, 2);
202 OUTREG(DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL);
203 OUTREG(WAIT_UNTIL, (WAIT_2D_IDLECLEAN | WAIT_DMA_GUI_IDLE));
204#endif
205
206 /* X here pads width to a multiple of 32 and uses the clipper to
207 * adjust the result. Is that really necessary ? Things seem to
208 * work ok for me without that and the doco doesn't seem to imply
209 * there is such a restriction.
210 */
211 OUTREG(DST_WIDTH_HEIGHT, (image->width << 16) | image->height);
212
213 src_bytes = (((image->width * image->depth) + 7) / 8) * image->height;
214 dwords = (src_bytes + 3) / 4;
215 bits = (u32*)(image->data);
216
217 while(dwords >= 8) {
218 radeon_fifo_wait(rinfo, 8);
219#if BITS_PER_LONG == 64
220 __raw_writeq(*((u64 *)(bits)), rinfo->mmio_base + HOST_DATA0);
221 __raw_writeq(*((u64 *)(bits+2)), rinfo->mmio_base + HOST_DATA2);
222 __raw_writeq(*((u64 *)(bits+4)), rinfo->mmio_base + HOST_DATA4);
223 __raw_writeq(*((u64 *)(bits+6)), rinfo->mmio_base + HOST_DATA6);
224 bits += 8;
225#else
226 __raw_writel(*(bits++), rinfo->mmio_base + HOST_DATA0);
227 __raw_writel(*(bits++), rinfo->mmio_base + HOST_DATA1);
228 __raw_writel(*(bits++), rinfo->mmio_base + HOST_DATA2);
229 __raw_writel(*(bits++), rinfo->mmio_base + HOST_DATA3);
230 __raw_writel(*(bits++), rinfo->mmio_base + HOST_DATA4);
231 __raw_writel(*(bits++), rinfo->mmio_base + HOST_DATA5);
232 __raw_writel(*(bits++), rinfo->mmio_base + HOST_DATA6);
233 __raw_writel(*(bits++), rinfo->mmio_base + HOST_DATA7);
234#endif
235 dwords -= 8;
236 }
237 while(dwords--) {
238 radeon_fifo_wait(rinfo, 1);
239 __raw_writel(*(bits++), rinfo->mmio_base + HOST_DATA0);
240 }
241}
242
171void radeonfb_imageblit(struct fb_info *info, const struct fb_image *image) 243void radeonfb_imageblit(struct fb_info *info, const struct fb_image *image)
172{ 244{
173 struct radeonfb_info *rinfo = info->par; 245 struct radeonfb_info *rinfo = info->par;
246 u32 fg, bg;
174 247
175 if (info->state != FBINFO_STATE_RUNNING) 248 WARN_ON(rinfo->gfx_mode);
249 if (info->state != FBINFO_STATE_RUNNING || rinfo->gfx_mode)
250 return;
251
252 if (!image->width || !image->height)
176 return; 253 return;
177 radeon_engine_idle(); 254
255 /* We only do 1 bpp color expansion for now */
256 if (info->flags & FBINFO_HWACCEL_DISABLED || image->depth != 1)
257 goto fallback;
258
259 /* Fallback if running out of the screen. We may do clipping
260 * in the future */
261 if ((image->dx + image->width) > info->var.xres_virtual ||
262 (image->dy + image->height) > info->var.yres_virtual)
263 goto fallback;
264
265 if (info->fix.visual == FB_VISUAL_TRUECOLOR ||
266 info->fix.visual == FB_VISUAL_DIRECTCOLOR) {
267 fg = ((u32*)(info->pseudo_palette))[image->fg_color];
268 bg = ((u32*)(info->pseudo_palette))[image->bg_color];
269 } else {
270 fg = image->fg_color;
271 bg = image->bg_color;
272 }
273
274 radeonfb_prim_imageblit(rinfo, image, fg, bg);
275 return;
276
277 fallback:
278 radeon_engine_idle(rinfo);
178 279
179 cfb_imageblit(info, image); 280 cfb_imageblit(info, image);
180} 281}
@@ -185,7 +286,8 @@ int radeonfb_sync(struct fb_info *info)
185 286
186 if (info->state != FBINFO_STATE_RUNNING) 287 if (info->state != FBINFO_STATE_RUNNING)
187 return 0; 288 return 0;
188 radeon_engine_idle(); 289
290 radeon_engine_idle(rinfo);
189 291
190 return 0; 292 return 0;
191} 293}
@@ -211,9 +313,7 @@ void radeonfb_engine_reset(struct radeonfb_info *rinfo)
211 host_path_cntl = INREG(HOST_PATH_CNTL); 313 host_path_cntl = INREG(HOST_PATH_CNTL);
212 rbbm_soft_reset = INREG(RBBM_SOFT_RESET); 314 rbbm_soft_reset = INREG(RBBM_SOFT_RESET);
213 315
214 if (rinfo->family == CHIP_FAMILY_R300 || 316 if (IS_R300_VARIANT(rinfo)) {
215 rinfo->family == CHIP_FAMILY_R350 ||
216 rinfo->family == CHIP_FAMILY_RV350) {
217 u32 tmp; 317 u32 tmp;
218 318
219 OUTREG(RBBM_SOFT_RESET, (rbbm_soft_reset | 319 OUTREG(RBBM_SOFT_RESET, (rbbm_soft_reset |
@@ -249,9 +349,7 @@ void radeonfb_engine_reset(struct radeonfb_info *rinfo)
249 INREG(HOST_PATH_CNTL); 349 INREG(HOST_PATH_CNTL);
250 OUTREG(HOST_PATH_CNTL, host_path_cntl); 350 OUTREG(HOST_PATH_CNTL, host_path_cntl);
251 351
252 if (rinfo->family != CHIP_FAMILY_R300 && 352 if (!IS_R300_VARIANT(rinfo))
253 rinfo->family != CHIP_FAMILY_R350 &&
254 rinfo->family != CHIP_FAMILY_RV350)
255 OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset); 353 OUTREG(RBBM_SOFT_RESET, rbbm_soft_reset);
256 354
257 OUTREG(CLOCK_CNTL_INDEX, clock_cntl_index); 355 OUTREG(CLOCK_CNTL_INDEX, clock_cntl_index);
@@ -265,15 +363,24 @@ void radeonfb_engine_init (struct radeonfb_info *rinfo)
265 /* disable 3D engine */ 363 /* disable 3D engine */
266 OUTREG(RB3D_CNTL, 0); 364 OUTREG(RB3D_CNTL, 0);
267 365
366 rinfo->fifo_free = 0;
268 radeonfb_engine_reset(rinfo); 367 radeonfb_engine_reset(rinfo);
269 368
270 radeon_fifo_wait (1); 369 radeon_fifo_wait(rinfo, 1);
271 if ((rinfo->family != CHIP_FAMILY_R300) && 370 if (IS_R300_VARIANT(rinfo)) {
272 (rinfo->family != CHIP_FAMILY_R350) && 371 OUTREG(RB2D_DSTCACHE_MODE, INREG(RB2D_DSTCACHE_MODE) |
273 (rinfo->family != CHIP_FAMILY_RV350)) 372 RB2D_DC_AUTOFLUSH_ENABLE |
373 RB2D_DC_DC_DISABLE_IGNORE_PE);
374 } else {
375 /* This needs to be double checked with ATI. Latest X driver
376 * completely "forgets" to set this register on < r3xx, and
377 * we used to just write 0 there... I'll keep the 0 and update
378 * that when we have sorted things out on X side.
379 */
274 OUTREG(RB2D_DSTCACHE_MODE, 0); 380 OUTREG(RB2D_DSTCACHE_MODE, 0);
381 }
275 382
276 radeon_fifo_wait (3); 383 radeon_fifo_wait(rinfo, 3);
277 /* We re-read MC_FB_LOCATION from card as it can have been 384 /* We re-read MC_FB_LOCATION from card as it can have been
278 * modified by XFree drivers (ouch !) 385 * modified by XFree drivers (ouch !)
279 */ 386 */
@@ -284,41 +391,57 @@ void radeonfb_engine_init (struct radeonfb_info *rinfo)
284 OUTREG(DST_PITCH_OFFSET, (rinfo->pitch << 0x16) | (rinfo->fb_local_base >> 10)); 391 OUTREG(DST_PITCH_OFFSET, (rinfo->pitch << 0x16) | (rinfo->fb_local_base >> 10));
285 OUTREG(SRC_PITCH_OFFSET, (rinfo->pitch << 0x16) | (rinfo->fb_local_base >> 10)); 392 OUTREG(SRC_PITCH_OFFSET, (rinfo->pitch << 0x16) | (rinfo->fb_local_base >> 10));
286 393
287 radeon_fifo_wait (1); 394 radeon_fifo_wait(rinfo, 1);
288#if defined(__BIG_ENDIAN) 395#ifdef __BIG_ENDIAN
289 OUTREGP(DP_DATATYPE, HOST_BIG_ENDIAN_EN, ~HOST_BIG_ENDIAN_EN); 396 OUTREGP(DP_DATATYPE, HOST_BIG_ENDIAN_EN, ~HOST_BIG_ENDIAN_EN);
290#else 397#else
291 OUTREGP(DP_DATATYPE, 0, ~HOST_BIG_ENDIAN_EN); 398 OUTREGP(DP_DATATYPE, 0, ~HOST_BIG_ENDIAN_EN);
292#endif 399#endif
293 radeon_fifo_wait (2); 400 radeon_fifo_wait(rinfo, 2);
294 OUTREG(DEFAULT_SC_TOP_LEFT, 0); 401 OUTREG(DEFAULT_SC_TOP_LEFT, 0);
295 OUTREG(DEFAULT_SC_BOTTOM_RIGHT, (DEFAULT_SC_RIGHT_MAX | 402 OUTREG(DEFAULT_SC_BOTTOM_RIGHT, (DEFAULT_SC_RIGHT_MAX |
296 DEFAULT_SC_BOTTOM_MAX)); 403 DEFAULT_SC_BOTTOM_MAX));
297 404
405 /* set default DP_GUI_MASTER_CNTL */
298 temp = radeon_get_dstbpp(rinfo->depth); 406 temp = radeon_get_dstbpp(rinfo->depth);
299 rinfo->dp_gui_master_cntl = ((temp << 8) | GMC_CLR_CMP_CNTL_DIS); 407 rinfo->dp_gui_mc_base = ((temp << 8) | GMC_CLR_CMP_CNTL_DIS);
300 408
301 radeon_fifo_wait (1); 409 rinfo->dp_gui_mc_cache = rinfo->dp_gui_mc_base |
302 OUTREG(DP_GUI_MASTER_CNTL, (rinfo->dp_gui_master_cntl | 410 GMC_BRUSH_SOLID_COLOR |
303 GMC_BRUSH_SOLID_COLOR | 411 GMC_SRC_DATATYPE_COLOR;
304 GMC_SRC_DATATYPE_COLOR)); 412 radeon_fifo_wait(rinfo, 1);
413 OUTREG(DP_GUI_MASTER_CNTL, rinfo->dp_gui_mc_cache);
305 414
306 radeon_fifo_wait (7);
307 415
308 /* clear line drawing regs */ 416 /* clear line drawing regs */
417 radeon_fifo_wait(rinfo, 2);
309 OUTREG(DST_LINE_START, 0); 418 OUTREG(DST_LINE_START, 0);
310 OUTREG(DST_LINE_END, 0); 419 OUTREG(DST_LINE_END, 0);
311 420
312 /* set brush color regs */ 421 /* set brush and source color regs */
313 OUTREG(DP_BRUSH_FRGD_CLR, 0xffffffff); 422 rinfo->dp_brush_fg_cache = 0xffffffff;
314 OUTREG(DP_BRUSH_BKGD_CLR, 0x00000000); 423 rinfo->dp_brush_bg_cache = 0x00000000;
315 424 rinfo->dp_src_fg_cache = 0xffffffff;
316 /* set source color regs */ 425 rinfo->dp_src_bg_cache = 0x00000000;
317 OUTREG(DP_SRC_FRGD_CLR, 0xffffffff); 426 radeon_fifo_wait(rinfo, 4);
318 OUTREG(DP_SRC_BKGD_CLR, 0x00000000); 427 OUTREG(DP_BRUSH_FRGD_CLR, rinfo->dp_brush_fg_cache);
428 OUTREG(DP_BRUSH_BKGD_CLR, rinfo->dp_brush_bg_cache);
429 OUTREG(DP_SRC_FRGD_CLR, rinfo->dp_src_fg_cache);
430 OUTREG(DP_SRC_BKGD_CLR, rinfo->dp_src_bg_cache);
431
432 /* Default direction */
433 rinfo->dp_cntl_cache = DST_X_LEFT_TO_RIGHT | DST_Y_TOP_TO_BOTTOM;
434 radeon_fifo_wait(rinfo, 1);
435 OUTREG(DP_CNTL, rinfo->dp_cntl_cache);
319 436
320 /* default write mask */ 437 /* default write mask */
438 radeon_fifo_wait(rinfo, 1);
321 OUTREG(DP_WRITE_MSK, 0xffffffff); 439 OUTREG(DP_WRITE_MSK, 0xffffffff);
322 440
323 radeon_engine_idle (); 441 /* Default to no swapping of host data */
442 radeon_fifo_wait(rinfo, 1);
443 OUTREG(RBBM_GUICNTL, RBBM_GUICNTL_HOST_DATA_SWAP_NONE);
444
445 /* Make sure it's settled */
446 radeon_engine_idle(rinfo);
324} 447}
diff --git a/drivers/video/aty/radeon_backlight.c b/drivers/video/aty/radeon_backlight.c
index 1a056adb61c8..f343ba83f0ae 100644
--- a/drivers/video/aty/radeon_backlight.c
+++ b/drivers/video/aty/radeon_backlight.c
@@ -66,7 +66,7 @@ static int radeon_bl_update_status(struct backlight_device *bd)
66 level = bd->props.brightness; 66 level = bd->props.brightness;
67 67
68 del_timer_sync(&rinfo->lvds_timer); 68 del_timer_sync(&rinfo->lvds_timer);
69 radeon_engine_idle(); 69 radeon_engine_idle(rinfo);
70 70
71 lvds_gen_cntl = INREG(LVDS_GEN_CNTL); 71 lvds_gen_cntl = INREG(LVDS_GEN_CNTL);
72 if (level > 0) { 72 if (level > 0) {
diff --git a/drivers/video/aty/radeon_base.c b/drivers/video/aty/radeon_base.c
index 652273e9f5f9..9a5821c65ebf 100644
--- a/drivers/video/aty/radeon_base.c
+++ b/drivers/video/aty/radeon_base.c
@@ -852,7 +852,6 @@ static int radeonfb_pan_display (struct fb_var_screeninfo *var,
852 if (rinfo->asleep) 852 if (rinfo->asleep)
853 return 0; 853 return 0;
854 854
855 radeon_fifo_wait(2);
856 OUTREG(CRTC_OFFSET, ((var->yoffset * var->xres_virtual + var->xoffset) 855 OUTREG(CRTC_OFFSET, ((var->yoffset * var->xres_virtual + var->xoffset)
857 * var->bits_per_pixel / 8) & ~7); 856 * var->bits_per_pixel / 8) & ~7);
858 return 0; 857 return 0;
@@ -882,7 +881,6 @@ static int radeonfb_ioctl (struct fb_info *info, unsigned int cmd,
882 if (rc) 881 if (rc)
883 return rc; 882 return rc;
884 883
885 radeon_fifo_wait(2);
886 if (value & 0x01) { 884 if (value & 0x01) {
887 tmp = INREG(LVDS_GEN_CNTL); 885 tmp = INREG(LVDS_GEN_CNTL);
888 886
@@ -940,7 +938,7 @@ int radeon_screen_blank(struct radeonfb_info *rinfo, int blank, int mode_switch)
940 if (rinfo->lock_blank) 938 if (rinfo->lock_blank)
941 return 0; 939 return 0;
942 940
943 radeon_engine_idle(); 941 radeon_engine_idle(rinfo);
944 942
945 val = INREG(CRTC_EXT_CNTL); 943 val = INREG(CRTC_EXT_CNTL);
946 val &= ~(CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS | 944 val &= ~(CRTC_DISPLAY_DIS | CRTC_HSYNC_DIS |
@@ -1048,7 +1046,7 @@ static int radeonfb_blank (int blank, struct fb_info *info)
1048 1046
1049 if (rinfo->asleep) 1047 if (rinfo->asleep)
1050 return 0; 1048 return 0;
1051 1049
1052 return radeon_screen_blank(rinfo, blank, 0); 1050 return radeon_screen_blank(rinfo, blank, 0);
1053} 1051}
1054 1052
@@ -1074,8 +1072,6 @@ static int radeon_setcolreg (unsigned regno, unsigned red, unsigned green,
1074 pindex = regno; 1072 pindex = regno;
1075 1073
1076 if (!rinfo->asleep) { 1074 if (!rinfo->asleep) {
1077 radeon_fifo_wait(9);
1078
1079 if (rinfo->bpp == 16) { 1075 if (rinfo->bpp == 16) {
1080 pindex = regno * 8; 1076 pindex = regno * 8;
1081 1077
@@ -1244,8 +1240,6 @@ static void radeon_write_pll_regs(struct radeonfb_info *rinfo, struct radeon_reg
1244{ 1240{
1245 int i; 1241 int i;
1246 1242
1247 radeon_fifo_wait(20);
1248
1249 /* Workaround from XFree */ 1243 /* Workaround from XFree */
1250 if (rinfo->is_mobility) { 1244 if (rinfo->is_mobility) {
1251 /* A temporal workaround for the occational blanking on certain laptop 1245 /* A temporal workaround for the occational blanking on certain laptop
@@ -1286,11 +1280,10 @@ static void radeon_write_pll_regs(struct radeonfb_info *rinfo, struct radeon_reg
1286 radeon_pll_errata_after_data(rinfo); 1280 radeon_pll_errata_after_data(rinfo);
1287 1281
1288 /* Set PPLL ref. div */ 1282 /* Set PPLL ref. div */
1289 if (rinfo->family == CHIP_FAMILY_R300 || 1283 if (IS_R300_VARIANT(rinfo) ||
1290 rinfo->family == CHIP_FAMILY_RS300 || 1284 rinfo->family == CHIP_FAMILY_RS300 ||
1291 rinfo->family == CHIP_FAMILY_R350 || 1285 rinfo->family == CHIP_FAMILY_RS400 ||
1292 rinfo->family == CHIP_FAMILY_RV350 || 1286 rinfo->family == CHIP_FAMILY_RS480) {
1293 rinfo->family == CHIP_FAMILY_RV380 ) {
1294 if (mode->ppll_ref_div & R300_PPLL_REF_DIV_ACC_MASK) { 1287 if (mode->ppll_ref_div & R300_PPLL_REF_DIV_ACC_MASK) {
1295 /* When restoring console mode, use saved PPLL_REF_DIV 1288 /* When restoring console mode, use saved PPLL_REF_DIV
1296 * setting. 1289 * setting.
@@ -1342,7 +1335,7 @@ static void radeon_lvds_timer_func(unsigned long data)
1342{ 1335{
1343 struct radeonfb_info *rinfo = (struct radeonfb_info *)data; 1336 struct radeonfb_info *rinfo = (struct radeonfb_info *)data;
1344 1337
1345 radeon_engine_idle(); 1338 radeon_engine_idle(rinfo);
1346 1339
1347 OUTREG(LVDS_GEN_CNTL, rinfo->pending_lvds_gen_cntl); 1340 OUTREG(LVDS_GEN_CNTL, rinfo->pending_lvds_gen_cntl);
1348} 1341}
@@ -1360,10 +1353,11 @@ void radeon_write_mode (struct radeonfb_info *rinfo, struct radeon_regs *mode,
1360 if (nomodeset) 1353 if (nomodeset)
1361 return; 1354 return;
1362 1355
1356 radeon_engine_idle(rinfo);
1357
1363 if (!regs_only) 1358 if (!regs_only)
1364 radeon_screen_blank(rinfo, FB_BLANK_NORMAL, 0); 1359 radeon_screen_blank(rinfo, FB_BLANK_NORMAL, 0);
1365 1360
1366 radeon_fifo_wait(31);
1367 for (i=0; i<10; i++) 1361 for (i=0; i<10; i++)
1368 OUTREG(common_regs[i].reg, common_regs[i].val); 1362 OUTREG(common_regs[i].reg, common_regs[i].val);
1369 1363
@@ -1391,7 +1385,6 @@ void radeon_write_mode (struct radeonfb_info *rinfo, struct radeon_regs *mode,
1391 radeon_write_pll_regs(rinfo, mode); 1385 radeon_write_pll_regs(rinfo, mode);
1392 1386
1393 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) { 1387 if ((primary_mon == MT_DFP) || (primary_mon == MT_LCD)) {
1394 radeon_fifo_wait(10);
1395 OUTREG(FP_CRTC_H_TOTAL_DISP, mode->fp_crtc_h_total_disp); 1388 OUTREG(FP_CRTC_H_TOTAL_DISP, mode->fp_crtc_h_total_disp);
1396 OUTREG(FP_CRTC_V_TOTAL_DISP, mode->fp_crtc_v_total_disp); 1389 OUTREG(FP_CRTC_V_TOTAL_DISP, mode->fp_crtc_v_total_disp);
1397 OUTREG(FP_H_SYNC_STRT_WID, mode->fp_h_sync_strt_wid); 1390 OUTREG(FP_H_SYNC_STRT_WID, mode->fp_h_sync_strt_wid);
@@ -1406,7 +1399,6 @@ void radeon_write_mode (struct radeonfb_info *rinfo, struct radeon_regs *mode,
1406 if (!regs_only) 1399 if (!regs_only)
1407 radeon_screen_blank(rinfo, FB_BLANK_UNBLANK, 0); 1400 radeon_screen_blank(rinfo, FB_BLANK_UNBLANK, 0);
1408 1401
1409 radeon_fifo_wait(2);
1410 OUTPLL(VCLK_ECP_CNTL, mode->vclk_ecp_cntl); 1402 OUTPLL(VCLK_ECP_CNTL, mode->vclk_ecp_cntl);
1411 1403
1412 return; 1404 return;
@@ -1461,10 +1453,7 @@ static void radeon_calc_pll_regs(struct radeonfb_info *rinfo, struct radeon_regs
1461 /* Not all chip revs have the same format for this register, 1453 /* Not all chip revs have the same format for this register,
1462 * extract the source selection 1454 * extract the source selection
1463 */ 1455 */
1464 if (rinfo->family == CHIP_FAMILY_R200 || 1456 if (rinfo->family == CHIP_FAMILY_R200 || IS_R300_VARIANT(rinfo)) {
1465 rinfo->family == CHIP_FAMILY_R300 ||
1466 rinfo->family == CHIP_FAMILY_R350 ||
1467 rinfo->family == CHIP_FAMILY_RV350) {
1468 source = (fp2_gen_cntl >> 10) & 0x3; 1457 source = (fp2_gen_cntl >> 10) & 0x3;
1469 /* sourced from transform unit, check for transform unit 1458 /* sourced from transform unit, check for transform unit
1470 * own source 1459 * own source
@@ -1560,7 +1549,7 @@ static int radeonfb_set_par(struct fb_info *info)
1560 /* We always want engine to be idle on a mode switch, even 1549 /* We always want engine to be idle on a mode switch, even
1561 * if we won't actually change the mode 1550 * if we won't actually change the mode
1562 */ 1551 */
1563 radeon_engine_idle(); 1552 radeon_engine_idle(rinfo);
1564 1553
1565 hSyncStart = mode->xres + mode->right_margin; 1554 hSyncStart = mode->xres + mode->right_margin;
1566 hSyncEnd = hSyncStart + mode->hsync_len; 1555 hSyncEnd = hSyncStart + mode->hsync_len;
@@ -1855,7 +1844,6 @@ static int radeonfb_set_par(struct fb_info *info)
1855 return 0; 1844 return 0;
1856} 1845}
1857 1846
1858
1859static struct fb_ops radeonfb_ops = { 1847static struct fb_ops radeonfb_ops = {
1860 .owner = THIS_MODULE, 1848 .owner = THIS_MODULE,
1861 .fb_check_var = radeonfb_check_var, 1849 .fb_check_var = radeonfb_check_var,
@@ -1879,6 +1867,7 @@ static int __devinit radeon_set_fbinfo (struct radeonfb_info *rinfo)
1879 info->par = rinfo; 1867 info->par = rinfo;
1880 info->pseudo_palette = rinfo->pseudo_palette; 1868 info->pseudo_palette = rinfo->pseudo_palette;
1881 info->flags = FBINFO_DEFAULT 1869 info->flags = FBINFO_DEFAULT
1870 | FBINFO_HWACCEL_IMAGEBLIT
1882 | FBINFO_HWACCEL_COPYAREA 1871 | FBINFO_HWACCEL_COPYAREA
1883 | FBINFO_HWACCEL_FILLRECT 1872 | FBINFO_HWACCEL_FILLRECT
1884 | FBINFO_HWACCEL_XPAN 1873 | FBINFO_HWACCEL_XPAN
@@ -2005,11 +1994,11 @@ static void radeon_identify_vram(struct radeonfb_info *rinfo)
2005 (rinfo->family == CHIP_FAMILY_RS200) || 1994 (rinfo->family == CHIP_FAMILY_RS200) ||
2006 (rinfo->family == CHIP_FAMILY_RS300) || 1995 (rinfo->family == CHIP_FAMILY_RS300) ||
2007 (rinfo->family == CHIP_FAMILY_RC410) || 1996 (rinfo->family == CHIP_FAMILY_RC410) ||
1997 (rinfo->family == CHIP_FAMILY_RS400) ||
2008 (rinfo->family == CHIP_FAMILY_RS480) ) { 1998 (rinfo->family == CHIP_FAMILY_RS480) ) {
2009 u32 tom = INREG(NB_TOM); 1999 u32 tom = INREG(NB_TOM);
2010 tmp = ((((tom >> 16) - (tom & 0xffff) + 1) << 6) * 1024); 2000 tmp = ((((tom >> 16) - (tom & 0xffff) + 1) << 6) * 1024);
2011 2001
2012 radeon_fifo_wait(6);
2013 OUTREG(MC_FB_LOCATION, tom); 2002 OUTREG(MC_FB_LOCATION, tom);
2014 OUTREG(DISPLAY_BASE_ADDR, (tom & 0xffff) << 16); 2003 OUTREG(DISPLAY_BASE_ADDR, (tom & 0xffff) << 16);
2015 OUTREG(CRTC2_DISPLAY_BASE_ADDR, (tom & 0xffff) << 16); 2004 OUTREG(CRTC2_DISPLAY_BASE_ADDR, (tom & 0xffff) << 16);
diff --git a/drivers/video/aty/radeon_i2c.c b/drivers/video/aty/radeon_i2c.c
index 8c8fa35f1b7c..2c5567175dca 100644
--- a/drivers/video/aty/radeon_i2c.c
+++ b/drivers/video/aty/radeon_i2c.c
@@ -139,12 +139,8 @@ void radeon_delete_i2c_busses(struct radeonfb_info *rinfo)
139int radeon_probe_i2c_connector(struct radeonfb_info *rinfo, int conn, 139int radeon_probe_i2c_connector(struct radeonfb_info *rinfo, int conn,
140 u8 **out_edid) 140 u8 **out_edid)
141{ 141{
142 u32 reg = rinfo->i2c[conn-1].ddc_reg;
143 u8 *edid; 142 u8 *edid;
144 143
145 OUTREG(reg, INREG(reg) &
146 ~(VGA_DDC_DATA_OUTPUT | VGA_DDC_CLK_OUTPUT));
147
148 edid = fb_ddc_read(&rinfo->i2c[conn-1].adapter); 144 edid = fb_ddc_read(&rinfo->i2c[conn-1].adapter);
149 145
150 if (out_edid) 146 if (out_edid)
diff --git a/drivers/video/aty/radeon_pm.c b/drivers/video/aty/radeon_pm.c
index 675abdafc2d8..3df5015f1d13 100644
--- a/drivers/video/aty/radeon_pm.c
+++ b/drivers/video/aty/radeon_pm.c
@@ -2653,9 +2653,9 @@ int radeonfb_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
2653 2653
2654 if (!(info->flags & FBINFO_HWACCEL_DISABLED)) { 2654 if (!(info->flags & FBINFO_HWACCEL_DISABLED)) {
2655 /* Make sure engine is reset */ 2655 /* Make sure engine is reset */
2656 radeon_engine_idle(); 2656 radeon_engine_idle(rinfo);
2657 radeonfb_engine_reset(rinfo); 2657 radeonfb_engine_reset(rinfo);
2658 radeon_engine_idle(); 2658 radeon_engine_idle(rinfo);
2659 } 2659 }
2660 2660
2661 /* Blank display and LCD */ 2661 /* Blank display and LCD */
@@ -2767,7 +2767,7 @@ int radeonfb_pci_resume(struct pci_dev *pdev)
2767 2767
2768 rinfo->asleep = 0; 2768 rinfo->asleep = 0;
2769 } else 2769 } else
2770 radeon_engine_idle(); 2770 radeon_engine_idle(rinfo);
2771 2771
2772 /* Restore display & engine */ 2772 /* Restore display & engine */
2773 radeon_write_mode (rinfo, &rinfo->state, 1); 2773 radeon_write_mode (rinfo, &rinfo->state, 1);
diff --git a/drivers/video/aty/radeonfb.h b/drivers/video/aty/radeonfb.h
index ccbfffd12805..ea0b5b47acaf 100644
--- a/drivers/video/aty/radeonfb.h
+++ b/drivers/video/aty/radeonfb.h
@@ -53,6 +53,7 @@ enum radeon_family {
53 CHIP_FAMILY_RV380, /* RV370/RV380/M22/M24 */ 53 CHIP_FAMILY_RV380, /* RV370/RV380/M22/M24 */
54 CHIP_FAMILY_R420, /* R420/R423/M18 */ 54 CHIP_FAMILY_R420, /* R420/R423/M18 */
55 CHIP_FAMILY_RC410, 55 CHIP_FAMILY_RC410,
56 CHIP_FAMILY_RS400,
56 CHIP_FAMILY_RS480, 57 CHIP_FAMILY_RS480,
57 CHIP_FAMILY_LAST, 58 CHIP_FAMILY_LAST,
58}; 59};
@@ -335,7 +336,15 @@ struct radeonfb_info {
335 int mon2_type; 336 int mon2_type;
336 u8 *mon2_EDID; 337 u8 *mon2_EDID;
337 338
338 u32 dp_gui_master_cntl; 339 /* accel bits */
340 u32 dp_gui_mc_base;
341 u32 dp_gui_mc_cache;
342 u32 dp_cntl_cache;
343 u32 dp_brush_fg_cache;
344 u32 dp_brush_bg_cache;
345 u32 dp_src_fg_cache;
346 u32 dp_src_bg_cache;
347 u32 fifo_free;
339 348
340 struct pll_info pll; 349 struct pll_info pll;
341 350
@@ -347,6 +356,7 @@ struct radeonfb_info {
347 int lock_blank; 356 int lock_blank;
348 int dynclk; 357 int dynclk;
349 int no_schedule; 358 int no_schedule;
359 int gfx_mode;
350 enum radeon_pm_mode pm_mode; 360 enum radeon_pm_mode pm_mode;
351 reinit_function_ptr reinit_func; 361 reinit_function_ptr reinit_func;
352 362
@@ -391,8 +401,14 @@ static inline void _radeon_msleep(struct radeonfb_info *rinfo, unsigned long ms)
391#define OUTREG8(addr,val) writeb(val, (rinfo->mmio_base)+addr) 401#define OUTREG8(addr,val) writeb(val, (rinfo->mmio_base)+addr)
392#define INREG16(addr) readw((rinfo->mmio_base)+addr) 402#define INREG16(addr) readw((rinfo->mmio_base)+addr)
393#define OUTREG16(addr,val) writew(val, (rinfo->mmio_base)+addr) 403#define OUTREG16(addr,val) writew(val, (rinfo->mmio_base)+addr)
404
405#ifdef CONFIG_PPC
406#define INREG(addr) ({ eieio(); ld_le32(rinfo->mmio_base+(addr)); })
407#define OUTREG(addr,val) do { eieio(); st_le32(rinfo->mmio_base+(addr),(val)); } while(0)
408#else
394#define INREG(addr) readl((rinfo->mmio_base)+addr) 409#define INREG(addr) readl((rinfo->mmio_base)+addr)
395#define OUTREG(addr,val) writel(val, (rinfo->mmio_base)+addr) 410#define OUTREG(addr,val) writel(val, (rinfo->mmio_base)+addr)
411#endif
396 412
397static inline void _OUTREGP(struct radeonfb_info *rinfo, u32 addr, 413static inline void _OUTREGP(struct radeonfb_info *rinfo, u32 addr,
398 u32 val, u32 mask) 414 u32 val, u32 mask)
@@ -533,16 +549,25 @@ static inline u32 radeon_get_dstbpp(u16 depth)
533/* 549/*
534 * 2D Engine helper routines 550 * 2D Engine helper routines
535 */ 551 */
552
553extern void radeon_fifo_update_and_wait(struct radeonfb_info *rinfo, int entries);
554
536static inline void radeon_engine_flush (struct radeonfb_info *rinfo) 555static inline void radeon_engine_flush (struct radeonfb_info *rinfo)
537{ 556{
538 int i; 557 int i;
539 558
540 /* initiate flush */ 559 /* Initiate flush */
541 OUTREGP(RB2D_DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL, 560 OUTREGP(DSTCACHE_CTLSTAT, RB2D_DC_FLUSH_ALL,
542 ~RB2D_DC_FLUSH_ALL); 561 ~RB2D_DC_FLUSH_ALL);
543 562
563 /* Ensure FIFO is empty, ie, make sure the flush commands
564 * has reached the cache
565 */
566 radeon_fifo_update_and_wait(rinfo, 64);
567
568 /* Wait for the flush to complete */
544 for (i=0; i < 2000000; i++) { 569 for (i=0; i < 2000000; i++) {
545 if (!(INREG(RB2D_DSTCACHE_CTLSTAT) & RB2D_DC_BUSY)) 570 if (!(INREG(DSTCACHE_CTLSTAT) & RB2D_DC_BUSY))
546 return; 571 return;
547 udelay(1); 572 udelay(1);
548 } 573 }
@@ -550,25 +575,12 @@ static inline void radeon_engine_flush (struct radeonfb_info *rinfo)
550} 575}
551 576
552 577
553static inline void _radeon_fifo_wait(struct radeonfb_info *rinfo, int entries) 578static inline void radeon_engine_idle(struct radeonfb_info *rinfo)
554{
555 int i;
556
557 for (i=0; i<2000000; i++) {
558 if ((INREG(RBBM_STATUS) & 0x7f) >= entries)
559 return;
560 udelay(1);
561 }
562 printk(KERN_ERR "radeonfb: FIFO Timeout !\n");
563}
564
565
566static inline void _radeon_engine_idle(struct radeonfb_info *rinfo)
567{ 579{
568 int i; 580 int i;
569 581
570 /* ensure FIFO is empty before waiting for idle */ 582 /* ensure FIFO is empty before waiting for idle */
571 _radeon_fifo_wait (rinfo, 64); 583 radeon_fifo_update_and_wait (rinfo, 64);
572 584
573 for (i=0; i<2000000; i++) { 585 for (i=0; i<2000000; i++) {
574 if (((INREG(RBBM_STATUS) & GUI_ACTIVE)) == 0) { 586 if (((INREG(RBBM_STATUS) & GUI_ACTIVE)) == 0) {
@@ -581,8 +593,6 @@ static inline void _radeon_engine_idle(struct radeonfb_info *rinfo)
581} 593}
582 594
583 595
584#define radeon_engine_idle() _radeon_engine_idle(rinfo)
585#define radeon_fifo_wait(entries) _radeon_fifo_wait(rinfo,entries)
586#define radeon_msleep(ms) _radeon_msleep(rinfo,ms) 596#define radeon_msleep(ms) _radeon_msleep(rinfo,ms)
587 597
588 598
@@ -612,6 +622,7 @@ extern void radeonfb_imageblit(struct fb_info *p, const struct fb_image *image);
612extern int radeonfb_sync(struct fb_info *info); 622extern int radeonfb_sync(struct fb_info *info);
613extern void radeonfb_engine_init (struct radeonfb_info *rinfo); 623extern void radeonfb_engine_init (struct radeonfb_info *rinfo);
614extern void radeonfb_engine_reset(struct radeonfb_info *rinfo); 624extern void radeonfb_engine_reset(struct radeonfb_info *rinfo);
625extern void radeon_fixup_mem_offset(struct radeonfb_info *rinfo);
615 626
616/* Other functions */ 627/* Other functions */
617extern int radeon_screen_blank(struct radeonfb_info *rinfo, int blank, int mode_switch); 628extern int radeon_screen_blank(struct radeonfb_info *rinfo, int blank, int mode_switch);
diff --git a/drivers/video/backlight/mbp_nvidia_bl.c b/drivers/video/backlight/mbp_nvidia_bl.c
index 385cba40ea87..06964af761c6 100644
--- a/drivers/video/backlight/mbp_nvidia_bl.c
+++ b/drivers/video/backlight/mbp_nvidia_bl.c
@@ -111,6 +111,4 @@ module_exit(mbp_exit);
111MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>"); 111MODULE_AUTHOR("Matthew Garrett <mjg@redhat.com>");
112MODULE_DESCRIPTION("Nvidia-based Macbook Pro Backlight Driver"); 112MODULE_DESCRIPTION("Nvidia-based Macbook Pro Backlight Driver");
113MODULE_LICENSE("GPL"); 113MODULE_LICENSE("GPL");
114MODULE_ALIAS("svnAppleInc.:pnMacBookPro3,1"); 114MODULE_DEVICE_TABLE(dmi, mbp_device_table);
115MODULE_ALIAS("svnAppleInc.:pnMacBookPro3,2");
116MODULE_ALIAS("svnAppleInc.:pnMacBookPro4,1");
diff --git a/drivers/video/carminefb.c b/drivers/video/carminefb.c
index e15bb447440a..c9b191319a9a 100644
--- a/drivers/video/carminefb.c
+++ b/drivers/video/carminefb.c
@@ -535,7 +535,7 @@ static struct fb_ops carminefb_ops = {
535 .fb_setcolreg = carmine_setcolreg, 535 .fb_setcolreg = carmine_setcolreg,
536}; 536};
537 537
538static int alloc_carmine_fb(void __iomem *regs, void __iomem *smem_base, 538static int __devinit alloc_carmine_fb(void __iomem *regs, void __iomem *smem_base,
539 int smem_offset, struct device *device, struct fb_info **rinfo) 539 int smem_offset, struct device *device, struct fb_info **rinfo)
540{ 540{
541 int ret; 541 int ret;
diff --git a/drivers/video/cirrusfb.c b/drivers/video/cirrusfb.c
index e729fb279645..048b139f0e50 100644
--- a/drivers/video/cirrusfb.c
+++ b/drivers/video/cirrusfb.c
@@ -327,29 +327,7 @@ static const struct {
327#endif /* CONFIG_ZORRO */ 327#endif /* CONFIG_ZORRO */
328 328
329struct cirrusfb_regs { 329struct cirrusfb_regs {
330 long freq; 330 int multiplexing;
331 long nom;
332 long den;
333 long div;
334 long multiplexing;
335 long mclk;
336 long divMCLK;
337
338 long HorizRes; /* The x resolution in pixel */
339 long HorizTotal;
340 long HorizDispEnd;
341 long HorizBlankStart;
342 long HorizBlankEnd;
343 long HorizSyncStart;
344 long HorizSyncEnd;
345
346 long VertRes; /* the physical y resolution in scanlines */
347 long VertTotal;
348 long VertDispEnd;
349 long VertSyncStart;
350 long VertSyncEnd;
351 long VertBlankStart;
352 long VertBlankEnd;
353}; 331};
354 332
355#ifdef CIRRUSFB_DEBUG 333#ifdef CIRRUSFB_DEBUG
@@ -367,110 +345,13 @@ struct cirrusfb_info {
367 345
368 struct cirrusfb_regs currentmode; 346 struct cirrusfb_regs currentmode;
369 int blank_mode; 347 int blank_mode;
348 u32 pseudo_palette[16];
370 349
371 u32 pseudo_palette[16];
372
373#ifdef CONFIG_ZORRO
374 struct zorro_dev *zdev;
375#endif
376#ifdef CONFIG_PCI
377 struct pci_dev *pdev;
378#endif
379 void (*unmap)(struct fb_info *info); 350 void (*unmap)(struct fb_info *info);
380}; 351};
381 352
382static unsigned cirrusfb_def_mode = 1; 353static int noaccel __devinitdata;
383static int noaccel; 354static char *mode_option __devinitdata = "640x480@60";
384
385/*
386 * Predefined Video Modes
387 */
388
389static const struct {
390 const char *name;
391 struct fb_var_screeninfo var;
392} cirrusfb_predefined[] = {
393 {
394 /* autodetect mode */
395 .name = "Autodetect",
396 }, {
397 /* 640x480, 31.25 kHz, 60 Hz, 25 MHz PixClock */
398 .name = "640x480",
399 .var = {
400 .xres = 640,
401 .yres = 480,
402 .xres_virtual = 640,
403 .yres_virtual = 480,
404 .bits_per_pixel = 8,
405 .red = { .length = 8 },
406 .green = { .length = 8 },
407 .blue = { .length = 8 },
408 .width = -1,
409 .height = -1,
410 .pixclock = 40000,
411 .left_margin = 48,
412 .right_margin = 16,
413 .upper_margin = 32,
414 .lower_margin = 8,
415 .hsync_len = 96,
416 .vsync_len = 4,
417 .sync = FB_SYNC_HOR_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
418 .vmode = FB_VMODE_NONINTERLACED
419 }
420 }, {
421 /* 800x600, 48 kHz, 76 Hz, 50 MHz PixClock */
422 .name = "800x600",
423 .var = {
424 .xres = 800,
425 .yres = 600,
426 .xres_virtual = 800,
427 .yres_virtual = 600,
428 .bits_per_pixel = 8,
429 .red = { .length = 8 },
430 .green = { .length = 8 },
431 .blue = { .length = 8 },
432 .width = -1,
433 .height = -1,
434 .pixclock = 20000,
435 .left_margin = 128,
436 .right_margin = 16,
437 .upper_margin = 24,
438 .lower_margin = 2,
439 .hsync_len = 96,
440 .vsync_len = 6,
441 .vmode = FB_VMODE_NONINTERLACED
442 }
443 }, {
444 /*
445 * Modeline from XF86Config:
446 * Mode "1024x768" 80 1024 1136 1340 1432 768 770 774 805
447 */
448 /* 1024x768, 55.8 kHz, 70 Hz, 80 MHz PixClock */
449 .name = "1024x768",
450 .var = {
451 .xres = 1024,
452 .yres = 768,
453 .xres_virtual = 1024,
454 .yres_virtual = 768,
455 .bits_per_pixel = 8,
456 .red = { .length = 8 },
457 .green = { .length = 8 },
458 .blue = { .length = 8 },
459 .width = -1,
460 .height = -1,
461 .pixclock = 12500,
462 .left_margin = 144,
463 .right_margin = 32,
464 .upper_margin = 30,
465 .lower_margin = 2,
466 .hsync_len = 192,
467 .vsync_len = 6,
468 .vmode = FB_VMODE_NONINTERLACED
469 }
470 }
471};
472
473#define NUM_TOTAL_MODES ARRAY_SIZE(cirrusfb_predefined)
474 355
475/****************************************************************************/ 356/****************************************************************************/
476/**** BEGIN PROTOTYPES ******************************************************/ 357/**** BEGIN PROTOTYPES ******************************************************/
@@ -514,10 +395,6 @@ static struct fb_ops cirrusfb_ops = {
514 .fb_imageblit = cirrusfb_imageblit, 395 .fb_imageblit = cirrusfb_imageblit,
515}; 396};
516 397
517/*--- Hardware Specific Routines -------------------------------------------*/
518static int cirrusfb_decode_var(const struct fb_var_screeninfo *var,
519 struct cirrusfb_regs *regs,
520 struct fb_info *info);
521/*--- Internal routines ----------------------------------------------------*/ 398/*--- Internal routines ----------------------------------------------------*/
522static void init_vgachip(struct fb_info *info); 399static void init_vgachip(struct fb_info *info);
523static void switch_monitor(struct cirrusfb_info *cinfo, int on); 400static void switch_monitor(struct cirrusfb_info *cinfo, int on);
@@ -546,9 +423,7 @@ static void cirrusfb_RectFill(u8 __iomem *regbase, int bits_per_pixel,
546 u_short width, u_short height, 423 u_short width, u_short height,
547 u_char color, u_short line_length); 424 u_char color, u_short line_length);
548 425
549static void bestclock(long freq, long *best, 426static void bestclock(long freq, int *nom, int *den, int *div);
550 long *nom, long *den,
551 long *div, long maxfreq);
552 427
553#ifdef CIRRUSFB_DEBUG 428#ifdef CIRRUSFB_DEBUG
554static void cirrusfb_dump(void); 429static void cirrusfb_dump(void);
@@ -584,45 +459,28 @@ static int cirrusfb_release(struct fb_info *info, int user)
584/****************************************************************************/ 459/****************************************************************************/
585/**** BEGIN Hardware specific Routines **************************************/ 460/**** BEGIN Hardware specific Routines **************************************/
586 461
587/* Get a good MCLK value */ 462/* Check if the MCLK is not a better clock source */
588static long cirrusfb_get_mclk(long freq, int bpp, long *div) 463static int cirrusfb_check_mclk(struct cirrusfb_info *cinfo, long freq)
589{ 464{
590 long mclk; 465 long mclk = vga_rseq(cinfo->regbase, CL_SEQR1F) & 0x3f;
591 466
592 assert(div != NULL); 467 /* Read MCLK value */
593 468 mclk = (14318 * mclk) >> 3;
594 /* Calculate MCLK, in case VCLK is high enough to require > 50MHz. 469 DPRINTK("Read MCLK of %ld kHz\n", mclk);
595 * Assume a 64-bit data path for now. The formula is:
596 * ((B * PCLK * 2)/W) * 1.2
597 * B = bytes per pixel, PCLK = pixclock, W = data width in bytes */
598 mclk = ((bpp / 8) * freq * 2) / 4;
599 mclk = (mclk * 12) / 10;
600 if (mclk < 50000)
601 mclk = 50000;
602 DPRINTK("Use MCLK of %ld kHz\n", mclk);
603
604 /* Calculate value for SR1F. Multiply by 2 so we can round up. */
605 mclk = ((mclk * 16) / 14318);
606 mclk = (mclk + 1) / 2;
607 DPRINTK("Set SR1F[5:0] to 0x%lx\n", mclk);
608 470
609 /* Determine if we should use MCLK instead of VCLK, and if so, what we 471 /* Determine if we should use MCLK instead of VCLK, and if so, what we
610 * should divide it by to get VCLK */ 472 * should divide it by to get VCLK
611 switch (freq) { 473 */
612 case 24751 ... 25249: 474
613 *div = 2; 475 if (abs(freq - mclk) < 250) {
614 DPRINTK("Using VCLK = MCLK/2\n");
615 break;
616 case 49501 ... 50499:
617 *div = 1;
618 DPRINTK("Using VCLK = MCLK\n"); 476 DPRINTK("Using VCLK = MCLK\n");
619 break; 477 return 1;
620 default: 478 } else if (abs(freq - (mclk / 2)) < 250) {
621 *div = 0; 479 DPRINTK("Using VCLK = MCLK/2\n");
622 break; 480 return 2;
623 } 481 }
624 482
625 return mclk; 483 return 0;
626} 484}
627 485
628static int cirrusfb_check_var(struct fb_var_screeninfo *var, 486static int cirrusfb_check_var(struct fb_var_screeninfo *var,
@@ -638,7 +496,6 @@ static int cirrusfb_check_var(struct fb_var_screeninfo *var,
638 break; /* 8 pixel per byte, only 1/4th of mem usable */ 496 break; /* 8 pixel per byte, only 1/4th of mem usable */
639 case 8: 497 case 8:
640 case 16: 498 case 16:
641 case 24:
642 case 32: 499 case 32:
643 break; /* 1 pixel == 1 byte */ 500 break; /* 1 pixel == 1 byte */
644 default: 501 default:
@@ -713,7 +570,6 @@ static int cirrusfb_check_var(struct fb_var_screeninfo *var,
713 var->blue.length = 5; 570 var->blue.length = 5;
714 break; 571 break;
715 572
716 case 24:
717 case 32: 573 case 32:
718 if (isPReP) { 574 if (isPReP) {
719 var->red.offset = 8; 575 var->red.offset = 8;
@@ -767,8 +623,6 @@ static int cirrusfb_decode_var(const struct fb_var_screeninfo *var,
767 long maxclock; 623 long maxclock;
768 int maxclockidx = var->bits_per_pixel >> 3; 624 int maxclockidx = var->bits_per_pixel >> 3;
769 struct cirrusfb_info *cinfo = info->par; 625 struct cirrusfb_info *cinfo = info->par;
770 int xres, hfront, hsync, hback;
771 int yres, vfront, vsync, vback;
772 626
773 switch (var->bits_per_pixel) { 627 switch (var->bits_per_pixel) {
774 case 1: 628 case 1:
@@ -782,10 +636,9 @@ static int cirrusfb_decode_var(const struct fb_var_screeninfo *var,
782 break; 636 break;
783 637
784 case 16: 638 case 16:
785 case 24:
786 case 32: 639 case 32:
787 info->fix.line_length = var->xres_virtual * maxclockidx; 640 info->fix.line_length = var->xres_virtual * maxclockidx;
788 info->fix.visual = FB_VISUAL_DIRECTCOLOR; 641 info->fix.visual = FB_VISUAL_TRUECOLOR;
789 break; 642 break;
790 643
791 default: 644 default:
@@ -827,90 +680,33 @@ static int cirrusfb_decode_var(const struct fb_var_screeninfo *var,
827 switch (var->bits_per_pixel) { 680 switch (var->bits_per_pixel) {
828 case 16: 681 case 16:
829 case 32: 682 case 32:
830 if (regs->HorizRes <= 800) 683 if (var->xres <= 800)
831 /* Xbh has this type of clock for 32-bit */ 684 /* Xbh has this type of clock for 32-bit */
832 freq /= 2; 685 freq /= 2;
833 break; 686 break;
834 } 687 }
835#endif 688#endif
836
837 bestclock(freq, &regs->freq, &regs->nom, &regs->den, &regs->div,
838 maxclock);
839 regs->mclk = cirrusfb_get_mclk(freq, var->bits_per_pixel,
840 &regs->divMCLK);
841
842 xres = var->xres;
843 hfront = var->right_margin;
844 hsync = var->hsync_len;
845 hback = var->left_margin;
846
847 yres = var->yres;
848 vfront = var->lower_margin;
849 vsync = var->vsync_len;
850 vback = var->upper_margin;
851
852 if (var->vmode & FB_VMODE_DOUBLE) {
853 yres *= 2;
854 vfront *= 2;
855 vsync *= 2;
856 vback *= 2;
857 } else if (var->vmode & FB_VMODE_INTERLACED) {
858 yres = (yres + 1) / 2;
859 vfront = (vfront + 1) / 2;
860 vsync = (vsync + 1) / 2;
861 vback = (vback + 1) / 2;
862 }
863 regs->HorizRes = xres;
864 regs->HorizTotal = (xres + hfront + hsync + hback) / 8 - 5;
865 regs->HorizDispEnd = xres / 8 - 1;
866 regs->HorizBlankStart = xres / 8;
867 /* does not count with "-5" */
868 regs->HorizBlankEnd = regs->HorizTotal + 5;
869 regs->HorizSyncStart = (xres + hfront) / 8 + 1;
870 regs->HorizSyncEnd = (xres + hfront + hsync) / 8 + 1;
871
872 regs->VertRes = yres;
873 regs->VertTotal = yres + vfront + vsync + vback - 2;
874 regs->VertDispEnd = yres - 1;
875 regs->VertBlankStart = yres;
876 regs->VertBlankEnd = regs->VertTotal;
877 regs->VertSyncStart = yres + vfront - 1;
878 regs->VertSyncEnd = yres + vfront + vsync - 1;
879
880 if (regs->VertRes >= 1024) {
881 regs->VertTotal /= 2;
882 regs->VertSyncStart /= 2;
883 regs->VertSyncEnd /= 2;
884 regs->VertDispEnd /= 2;
885 }
886 if (regs->multiplexing) {
887 regs->HorizTotal /= 2;
888 regs->HorizSyncStart /= 2;
889 regs->HorizSyncEnd /= 2;
890 regs->HorizDispEnd /= 2;
891 }
892
893 return 0; 689 return 0;
894} 690}
895 691
896static void cirrusfb_set_mclk(const struct cirrusfb_info *cinfo, int val, 692static void cirrusfb_set_mclk_as_source(const struct cirrusfb_info *cinfo,
897 int div) 693 int div)
898{ 694{
695 unsigned char old1f, old1e;
899 assert(cinfo != NULL); 696 assert(cinfo != NULL);
697 old1f = vga_rseq(cinfo->regbase, CL_SEQR1F) & ~0x40;
900 698
901 if (div == 2) { 699 if (div) {
902 /* VCLK = MCLK/2 */ 700 DPRINTK("Set %s as pixclock source.\n",
903 unsigned char old = vga_rseq(cinfo->regbase, CL_SEQR1E); 701 (div == 2) ? "MCLK/2" : "MCLK");
904 vga_wseq(cinfo->regbase, CL_SEQR1E, old | 0x1); 702 old1f |= 0x40;
905 vga_wseq(cinfo->regbase, CL_SEQR1F, 0x40 | (val & 0x3f)); 703 old1e = vga_rseq(cinfo->regbase, CL_SEQR1E) & ~0x1;
906 } else if (div == 1) { 704 if (div == 2)
907 /* VCLK = MCLK */ 705 old1e |= 1;
908 unsigned char old = vga_rseq(cinfo->regbase, CL_SEQR1E); 706
909 vga_wseq(cinfo->regbase, CL_SEQR1E, old & ~0x1); 707 vga_wseq(cinfo->regbase, CL_SEQR1E, old1e);
910 vga_wseq(cinfo->regbase, CL_SEQR1F, 0x40 | (val & 0x3f));
911 } else {
912 vga_wseq(cinfo->regbase, CL_SEQR1F, val & 0x3f);
913 } 708 }
709 vga_wseq(cinfo->regbase, CL_SEQR1F, old1f);
914} 710}
915 711
916/************************************************************************* 712/*************************************************************************
@@ -927,6 +723,10 @@ static int cirrusfb_set_par_foo(struct fb_info *info)
927 unsigned char tmp; 723 unsigned char tmp;
928 int offset = 0, err; 724 int offset = 0, err;
929 const struct cirrusfb_board_info_rec *bi; 725 const struct cirrusfb_board_info_rec *bi;
726 int hdispend, hsyncstart, hsyncend, htotal;
727 int yres, vdispend, vsyncstart, vsyncend, vtotal;
728 long freq;
729 int nom, den, div;
930 730
931 DPRINTK("ENTER\n"); 731 DPRINTK("ENTER\n");
932 DPRINTK("Requested mode: %dx%dx%d\n", 732 DPRINTK("Requested mode: %dx%dx%d\n",
@@ -944,76 +744,117 @@ static int cirrusfb_set_par_foo(struct fb_info *info)
944 744
945 bi = &cirrusfb_board_info[cinfo->btype]; 745 bi = &cirrusfb_board_info[cinfo->btype];
946 746
747 hsyncstart = var->xres + var->right_margin;
748 hsyncend = hsyncstart + var->hsync_len;
749 htotal = (hsyncend + var->left_margin) / 8 - 5;
750 hdispend = var->xres / 8 - 1;
751 hsyncstart = hsyncstart / 8 + 1;
752 hsyncend = hsyncend / 8 + 1;
753
754 yres = var->yres;
755 vsyncstart = yres + var->lower_margin;
756 vsyncend = vsyncstart + var->vsync_len;
757 vtotal = vsyncend + var->upper_margin;
758 vdispend = yres - 1;
759
760 if (var->vmode & FB_VMODE_DOUBLE) {
761 yres *= 2;
762 vsyncstart *= 2;
763 vsyncend *= 2;
764 vtotal *= 2;
765 } else if (var->vmode & FB_VMODE_INTERLACED) {
766 yres = (yres + 1) / 2;
767 vsyncstart = (vsyncstart + 1) / 2;
768 vsyncend = (vsyncend + 1) / 2;
769 vtotal = (vtotal + 1) / 2;
770 }
771
772 vtotal -= 2;
773 vsyncstart -= 1;
774 vsyncend -= 1;
775
776 if (yres >= 1024) {
777 vtotal /= 2;
778 vsyncstart /= 2;
779 vsyncend /= 2;
780 vdispend /= 2;
781 }
782 if (regs.multiplexing) {
783 htotal /= 2;
784 hsyncstart /= 2;
785 hsyncend /= 2;
786 hdispend /= 2;
787 }
947 /* unlock register VGA_CRTC_H_TOTAL..CRT7 */ 788 /* unlock register VGA_CRTC_H_TOTAL..CRT7 */
948 vga_wcrt(regbase, VGA_CRTC_V_SYNC_END, 0x20); /* previously: 0x00) */ 789 vga_wcrt(regbase, VGA_CRTC_V_SYNC_END, 0x20); /* previously: 0x00) */
949 790
950 /* if debugging is enabled, all parameters get output before writing */ 791 /* if debugging is enabled, all parameters get output before writing */
951 DPRINTK("CRT0: %ld\n", regs.HorizTotal); 792 DPRINTK("CRT0: %d\n", htotal);
952 vga_wcrt(regbase, VGA_CRTC_H_TOTAL, regs.HorizTotal); 793 vga_wcrt(regbase, VGA_CRTC_H_TOTAL, htotal);
953 794
954 DPRINTK("CRT1: %ld\n", regs.HorizDispEnd); 795 DPRINTK("CRT1: %d\n", hdispend);
955 vga_wcrt(regbase, VGA_CRTC_H_DISP, regs.HorizDispEnd); 796 vga_wcrt(regbase, VGA_CRTC_H_DISP, hdispend);
956 797
957 DPRINTK("CRT2: %ld\n", regs.HorizBlankStart); 798 DPRINTK("CRT2: %d\n", var->xres / 8);
958 vga_wcrt(regbase, VGA_CRTC_H_BLANK_START, regs.HorizBlankStart); 799 vga_wcrt(regbase, VGA_CRTC_H_BLANK_START, var->xres / 8);
959 800
960 /* + 128: Compatible read */ 801 /* + 128: Compatible read */
961 DPRINTK("CRT3: 128+%ld\n", regs.HorizBlankEnd % 32); 802 DPRINTK("CRT3: 128+%d\n", (htotal + 5) % 32);
962 vga_wcrt(regbase, VGA_CRTC_H_BLANK_END, 803 vga_wcrt(regbase, VGA_CRTC_H_BLANK_END,
963 128 + (regs.HorizBlankEnd % 32)); 804 128 + ((htotal + 5) % 32));
964 805
965 DPRINTK("CRT4: %ld\n", regs.HorizSyncStart); 806 DPRINTK("CRT4: %d\n", hsyncstart);
966 vga_wcrt(regbase, VGA_CRTC_H_SYNC_START, regs.HorizSyncStart); 807 vga_wcrt(regbase, VGA_CRTC_H_SYNC_START, hsyncstart);
967 808
968 tmp = regs.HorizSyncEnd % 32; 809 tmp = hsyncend % 32;
969 if (regs.HorizBlankEnd & 32) 810 if ((htotal + 5) & 32)
970 tmp += 128; 811 tmp += 128;
971 DPRINTK("CRT5: %d\n", tmp); 812 DPRINTK("CRT5: %d\n", tmp);
972 vga_wcrt(regbase, VGA_CRTC_H_SYNC_END, tmp); 813 vga_wcrt(regbase, VGA_CRTC_H_SYNC_END, tmp);
973 814
974 DPRINTK("CRT6: %ld\n", regs.VertTotal & 0xff); 815 DPRINTK("CRT6: %d\n", vtotal & 0xff);
975 vga_wcrt(regbase, VGA_CRTC_V_TOTAL, (regs.VertTotal & 0xff)); 816 vga_wcrt(regbase, VGA_CRTC_V_TOTAL, vtotal & 0xff);
976 817
977 tmp = 16; /* LineCompare bit #9 */ 818 tmp = 16; /* LineCompare bit #9 */
978 if (regs.VertTotal & 256) 819 if (vtotal & 256)
979 tmp |= 1; 820 tmp |= 1;
980 if (regs.VertDispEnd & 256) 821 if (vdispend & 256)
981 tmp |= 2; 822 tmp |= 2;
982 if (regs.VertSyncStart & 256) 823 if (vsyncstart & 256)
983 tmp |= 4; 824 tmp |= 4;
984 if (regs.VertBlankStart & 256) 825 if ((vdispend + 1) & 256)
985 tmp |= 8; 826 tmp |= 8;
986 if (regs.VertTotal & 512) 827 if (vtotal & 512)
987 tmp |= 32; 828 tmp |= 32;
988 if (regs.VertDispEnd & 512) 829 if (vdispend & 512)
989 tmp |= 64; 830 tmp |= 64;
990 if (regs.VertSyncStart & 512) 831 if (vsyncstart & 512)
991 tmp |= 128; 832 tmp |= 128;
992 DPRINTK("CRT7: %d\n", tmp); 833 DPRINTK("CRT7: %d\n", tmp);
993 vga_wcrt(regbase, VGA_CRTC_OVERFLOW, tmp); 834 vga_wcrt(regbase, VGA_CRTC_OVERFLOW, tmp);
994 835
995 tmp = 0x40; /* LineCompare bit #8 */ 836 tmp = 0x40; /* LineCompare bit #8 */
996 if (regs.VertBlankStart & 512) 837 if ((vdispend + 1) & 512)
997 tmp |= 0x20; 838 tmp |= 0x20;
998 if (var->vmode & FB_VMODE_DOUBLE) 839 if (var->vmode & FB_VMODE_DOUBLE)
999 tmp |= 0x80; 840 tmp |= 0x80;
1000 DPRINTK("CRT9: %d\n", tmp); 841 DPRINTK("CRT9: %d\n", tmp);
1001 vga_wcrt(regbase, VGA_CRTC_MAX_SCAN, tmp); 842 vga_wcrt(regbase, VGA_CRTC_MAX_SCAN, tmp);
1002 843
1003 DPRINTK("CRT10: %ld\n", regs.VertSyncStart & 0xff); 844 DPRINTK("CRT10: %d\n", vsyncstart & 0xff);
1004 vga_wcrt(regbase, VGA_CRTC_V_SYNC_START, regs.VertSyncStart & 0xff); 845 vga_wcrt(regbase, VGA_CRTC_V_SYNC_START, vsyncstart & 0xff);
1005 846
1006 DPRINTK("CRT11: 64+32+%ld\n", regs.VertSyncEnd % 16); 847 DPRINTK("CRT11: 64+32+%d\n", vsyncend % 16);
1007 vga_wcrt(regbase, VGA_CRTC_V_SYNC_END, regs.VertSyncEnd % 16 + 64 + 32); 848 vga_wcrt(regbase, VGA_CRTC_V_SYNC_END, vsyncend % 16 + 64 + 32);
1008 849
1009 DPRINTK("CRT12: %ld\n", regs.VertDispEnd & 0xff); 850 DPRINTK("CRT12: %d\n", vdispend & 0xff);
1010 vga_wcrt(regbase, VGA_CRTC_V_DISP_END, regs.VertDispEnd & 0xff); 851 vga_wcrt(regbase, VGA_CRTC_V_DISP_END, vdispend & 0xff);
1011 852
1012 DPRINTK("CRT15: %ld\n", regs.VertBlankStart & 0xff); 853 DPRINTK("CRT15: %d\n", (vdispend + 1) & 0xff);
1013 vga_wcrt(regbase, VGA_CRTC_V_BLANK_START, regs.VertBlankStart & 0xff); 854 vga_wcrt(regbase, VGA_CRTC_V_BLANK_START, (vdispend + 1) & 0xff);
1014 855
1015 DPRINTK("CRT16: %ld\n", regs.VertBlankEnd & 0xff); 856 DPRINTK("CRT16: %d\n", vtotal & 0xff);
1016 vga_wcrt(regbase, VGA_CRTC_V_BLANK_END, regs.VertBlankEnd & 0xff); 857 vga_wcrt(regbase, VGA_CRTC_V_BLANK_END, vtotal & 0xff);
1017 858
1018 DPRINTK("CRT18: 0xff\n"); 859 DPRINTK("CRT18: 0xff\n");
1019 vga_wcrt(regbase, VGA_CRTC_LINE_COMPARE, 0xff); 860 vga_wcrt(regbase, VGA_CRTC_LINE_COMPARE, 0xff);
@@ -1021,38 +862,53 @@ static int cirrusfb_set_par_foo(struct fb_info *info)
1021 tmp = 0; 862 tmp = 0;
1022 if (var->vmode & FB_VMODE_INTERLACED) 863 if (var->vmode & FB_VMODE_INTERLACED)
1023 tmp |= 1; 864 tmp |= 1;
1024 if (regs.HorizBlankEnd & 64) 865 if ((htotal + 5) & 64)
1025 tmp |= 16; 866 tmp |= 16;
1026 if (regs.HorizBlankEnd & 128) 867 if ((htotal + 5) & 128)
1027 tmp |= 32; 868 tmp |= 32;
1028 if (regs.VertBlankEnd & 256) 869 if (vtotal & 256)
1029 tmp |= 64; 870 tmp |= 64;
1030 if (regs.VertBlankEnd & 512) 871 if (vtotal & 512)
1031 tmp |= 128; 872 tmp |= 128;
1032 873
1033 DPRINTK("CRT1a: %d\n", tmp); 874 DPRINTK("CRT1a: %d\n", tmp);
1034 vga_wcrt(regbase, CL_CRT1A, tmp); 875 vga_wcrt(regbase, CL_CRT1A, tmp);
1035 876
877 freq = PICOS2KHZ(var->pixclock);
878 bestclock(freq, &nom, &den, &div);
879
1036 /* set VCLK0 */ 880 /* set VCLK0 */
1037 /* hardware RefClock: 14.31818 MHz */ 881 /* hardware RefClock: 14.31818 MHz */
1038 /* formula: VClk = (OSC * N) / (D * (1+P)) */ 882 /* formula: VClk = (OSC * N) / (D * (1+P)) */
1039 /* Example: VClk = (14.31818 * 91) / (23 * (1+1)) = 28.325 MHz */ 883 /* Example: VClk = (14.31818 * 91) / (23 * (1+1)) = 28.325 MHz */
1040 884
1041 vga_wseq(regbase, CL_SEQRB, regs.nom); 885 if (cinfo->btype == BT_ALPINE) {
1042 tmp = regs.den << 1; 886 /* if freq is close to mclk or mclk/2 select mclk
1043 if (regs.div != 0) 887 * as clock source
1044 tmp |= 1; 888 */
889 int divMCLK = cirrusfb_check_mclk(cinfo, freq);
890 if (divMCLK) {
891 nom = 0;
892 cirrusfb_set_mclk_as_source(cinfo, divMCLK);
893 }
894 }
895 if (nom) {
896 vga_wseq(regbase, CL_SEQRB, nom);
897 tmp = den << 1;
898 if (div != 0)
899 tmp |= 1;
1045 900
1046 /* 6 bit denom; ONLY 5434!!! (bugged me 10 days) */ 901 /* 6 bit denom; ONLY 5434!!! (bugged me 10 days) */
1047 if ((cinfo->btype == BT_SD64) || 902 if ((cinfo->btype == BT_SD64) ||
1048 (cinfo->btype == BT_ALPINE) || 903 (cinfo->btype == BT_ALPINE) ||
1049 (cinfo->btype == BT_GD5480)) 904 (cinfo->btype == BT_GD5480))
1050 tmp |= 0x80; 905 tmp |= 0x80;
1051 906
1052 DPRINTK("CL_SEQR1B: %ld\n", (long) tmp); 907 DPRINTK("CL_SEQR1B: %ld\n", (long) tmp);
1053 vga_wseq(regbase, CL_SEQR1B, tmp); 908 vga_wseq(regbase, CL_SEQR1B, tmp);
909 }
1054 910
1055 if (regs.VertRes >= 1024) 911 if (yres >= 1024)
1056 /* 1280x1024 */ 912 /* 1280x1024 */
1057 vga_wcrt(regbase, VGA_CRTC_MODE, 0xc7); 913 vga_wcrt(regbase, VGA_CRTC_MODE, 0xc7);
1058 else 914 else
@@ -1066,7 +922,7 @@ static int cirrusfb_set_par_foo(struct fb_info *info)
1066 /* don't know if it would hurt to also program this if no interlaced */ 922 /* don't know if it would hurt to also program this if no interlaced */
1067 /* mode is used, but I feel better this way.. :-) */ 923 /* mode is used, but I feel better this way.. :-) */
1068 if (var->vmode & FB_VMODE_INTERLACED) 924 if (var->vmode & FB_VMODE_INTERLACED)
1069 vga_wcrt(regbase, VGA_CRTC_REGS, regs.HorizTotal / 2); 925 vga_wcrt(regbase, VGA_CRTC_REGS, htotal / 2);
1070 else 926 else
1071 vga_wcrt(regbase, VGA_CRTC_REGS, 0x00); /* interlace control */ 927 vga_wcrt(regbase, VGA_CRTC_REGS, 0x00); /* interlace control */
1072 928
@@ -1240,7 +1096,6 @@ static int cirrusfb_set_par_foo(struct fb_info *info)
1240 1096
1241 case BT_ALPINE: 1097 case BT_ALPINE:
1242 DPRINTK(" (for GD543x)\n"); 1098 DPRINTK(" (for GD543x)\n");
1243 cirrusfb_set_mclk(cinfo, regs.mclk, regs.divMCLK);
1244 /* We already set SRF and SR1F */ 1099 /* We already set SRF and SR1F */
1245 break; 1100 break;
1246 1101
@@ -1312,11 +1167,7 @@ static int cirrusfb_set_par_foo(struct fb_info *info)
1312 1167
1313 case BT_ALPINE: 1168 case BT_ALPINE:
1314 DPRINTK(" (for GD543x)\n"); 1169 DPRINTK(" (for GD543x)\n");
1315 if (regs.HorizRes >= 1024) 1170 vga_wseq(regbase, CL_SEQR7, 0xa7);
1316 vga_wseq(regbase, CL_SEQR7, 0xa7);
1317 else
1318 vga_wseq(regbase, CL_SEQR7, 0xa3);
1319 cirrusfb_set_mclk(cinfo, regs.mclk, regs.divMCLK);
1320 break; 1171 break;
1321 1172
1322 case BT_GD5480: 1173 case BT_GD5480:
@@ -1360,7 +1211,7 @@ static int cirrusfb_set_par_foo(struct fb_info *info)
1360 */ 1211 */
1361 1212
1362 else if (var->bits_per_pixel == 32) { 1213 else if (var->bits_per_pixel == 32) {
1363 DPRINTK("cirrusfb: preparing for 24/32 bit deep display\n"); 1214 DPRINTK("cirrusfb: preparing for 32 bit deep display\n");
1364 switch (cinfo->btype) { 1215 switch (cinfo->btype) {
1365 case BT_SD64: 1216 case BT_SD64:
1366 /* Extended Sequencer Mode: 256c col. mode */ 1217 /* Extended Sequencer Mode: 256c col. mode */
@@ -1394,7 +1245,6 @@ static int cirrusfb_set_par_foo(struct fb_info *info)
1394 case BT_ALPINE: 1245 case BT_ALPINE:
1395 DPRINTK(" (for GD543x)\n"); 1246 DPRINTK(" (for GD543x)\n");
1396 vga_wseq(regbase, CL_SEQR7, 0xa9); 1247 vga_wseq(regbase, CL_SEQR7, 0xa9);
1397 cirrusfb_set_mclk(cinfo, regs.mclk, regs.divMCLK);
1398 break; 1248 break;
1399 1249
1400 case BT_GD5480: 1250 case BT_GD5480:
@@ -1949,8 +1799,6 @@ static void init_vgachip(struct fb_info *info)
1949 /* misc... */ 1799 /* misc... */
1950 WHDR(cinfo, 0); /* Hidden DAC register: - */ 1800 WHDR(cinfo, 0); /* Hidden DAC register: - */
1951 1801
1952 printk(KERN_DEBUG "cirrusfb: This board has %ld bytes of DRAM memory\n",
1953 info->screen_size);
1954 DPRINTK("EXIT\n"); 1802 DPRINTK("EXIT\n");
1955 return; 1803 return;
1956} 1804}
@@ -2122,7 +1970,7 @@ static int release_io_ports;
2122 * based on the DRAM bandwidth bit and DRAM bank switching bit. This 1970 * based on the DRAM bandwidth bit and DRAM bank switching bit. This
2123 * works with 1MB, 2MB and 4MB configurations (which the Motorola boards 1971 * works with 1MB, 2MB and 4MB configurations (which the Motorola boards
2124 * seem to have. */ 1972 * seem to have. */
2125static unsigned int cirrusfb_get_memsize(u8 __iomem *regbase) 1973static unsigned int __devinit cirrusfb_get_memsize(u8 __iomem *regbase)
2126{ 1974{
2127 unsigned long mem; 1975 unsigned long mem;
2128 unsigned char SRF; 1976 unsigned char SRF;
@@ -2188,8 +2036,7 @@ static void get_pci_addrs(const struct pci_dev *pdev,
2188 2036
2189static void cirrusfb_pci_unmap(struct fb_info *info) 2037static void cirrusfb_pci_unmap(struct fb_info *info)
2190{ 2038{
2191 struct cirrusfb_info *cinfo = info->par; 2039 struct pci_dev *pdev = to_pci_dev(info->device);
2192 struct pci_dev *pdev = cinfo->pdev;
2193 2040
2194 iounmap(info->screen_base); 2041 iounmap(info->screen_base);
2195#if 0 /* if system didn't claim this region, we would... */ 2042#if 0 /* if system didn't claim this region, we would... */
@@ -2205,20 +2052,22 @@ static void cirrusfb_pci_unmap(struct fb_info *info)
2205static void __devexit cirrusfb_zorro_unmap(struct fb_info *info) 2052static void __devexit cirrusfb_zorro_unmap(struct fb_info *info)
2206{ 2053{
2207 struct cirrusfb_info *cinfo = info->par; 2054 struct cirrusfb_info *cinfo = info->par;
2208 zorro_release_device(cinfo->zdev); 2055 struct zorro_dev *zdev = to_zorro_dev(info->device);
2056
2057 zorro_release_device(zdev);
2209 2058
2210 if (cinfo->btype == BT_PICASSO4) { 2059 if (cinfo->btype == BT_PICASSO4) {
2211 cinfo->regbase -= 0x600000; 2060 cinfo->regbase -= 0x600000;
2212 iounmap((void *)cinfo->regbase); 2061 iounmap((void *)cinfo->regbase);
2213 iounmap(info->screen_base); 2062 iounmap(info->screen_base);
2214 } else { 2063 } else {
2215 if (zorro_resource_start(cinfo->zdev) > 0x01000000) 2064 if (zorro_resource_start(zdev) > 0x01000000)
2216 iounmap(info->screen_base); 2065 iounmap(info->screen_base);
2217 } 2066 }
2218} 2067}
2219#endif /* CONFIG_ZORRO */ 2068#endif /* CONFIG_ZORRO */
2220 2069
2221static int cirrusfb_set_fbinfo(struct fb_info *info) 2070static int __devinit cirrusfb_set_fbinfo(struct fb_info *info)
2222{ 2071{
2223 struct cirrusfb_info *cinfo = info->par; 2072 struct cirrusfb_info *cinfo = info->par;
2224 struct fb_var_screeninfo *var = &info->var; 2073 struct fb_var_screeninfo *var = &info->var;
@@ -2235,7 +2084,7 @@ static int cirrusfb_set_fbinfo(struct fb_info *info)
2235 if (cinfo->btype == BT_GD5480) { 2084 if (cinfo->btype == BT_GD5480) {
2236 if (var->bits_per_pixel == 16) 2085 if (var->bits_per_pixel == 16)
2237 info->screen_base += 1 * MB_; 2086 info->screen_base += 1 * MB_;
2238 if (var->bits_per_pixel == 24 || var->bits_per_pixel == 32) 2087 if (var->bits_per_pixel == 32)
2239 info->screen_base += 2 * MB_; 2088 info->screen_base += 2 * MB_;
2240 } 2089 }
2241 2090
@@ -2262,7 +2111,7 @@ static int cirrusfb_set_fbinfo(struct fb_info *info)
2262 return 0; 2111 return 0;
2263} 2112}
2264 2113
2265static int cirrusfb_register(struct fb_info *info) 2114static int __devinit cirrusfb_register(struct fb_info *info)
2266{ 2115{
2267 struct cirrusfb_info *cinfo = info->par; 2116 struct cirrusfb_info *cinfo = info->par;
2268 int err; 2117 int err;
@@ -2278,23 +2127,27 @@ static int cirrusfb_register(struct fb_info *info)
2278 /* sanity checks */ 2127 /* sanity checks */
2279 assert(btype != BT_NONE); 2128 assert(btype != BT_NONE);
2280 2129
2130 /* set all the vital stuff */
2131 cirrusfb_set_fbinfo(info);
2132
2281 DPRINTK("cirrusfb: (RAM start set to: 0x%p)\n", info->screen_base); 2133 DPRINTK("cirrusfb: (RAM start set to: 0x%p)\n", info->screen_base);
2282 2134
2283 /* Make pretend we've set the var so our structures are in a "good" */ 2135 err = fb_find_mode(&info->var, info, mode_option, NULL, 0, NULL, 8);
2284 /* state, even though we haven't written the mode to the hw yet... */ 2136 if (!err) {
2285 info->var = cirrusfb_predefined[cirrusfb_def_mode].var; 2137 DPRINTK("wrong initial video mode\n");
2138 err = -EINVAL;
2139 goto err_dealloc_cmap;
2140 }
2141
2286 info->var.activate = FB_ACTIVATE_NOW; 2142 info->var.activate = FB_ACTIVATE_NOW;
2287 2143
2288 err = cirrusfb_decode_var(&info->var, &cinfo->currentmode, info); 2144 err = cirrusfb_decode_var(&info->var, &cinfo->currentmode, info);
2289 if (err < 0) { 2145 if (err < 0) {
2290 /* should never happen */ 2146 /* should never happen */
2291 DPRINTK("choking on default var... umm, no good.\n"); 2147 DPRINTK("choking on default var... umm, no good.\n");
2292 goto err_unmap_cirrusfb; 2148 goto err_dealloc_cmap;
2293 } 2149 }
2294 2150
2295 /* set all the vital stuff */
2296 cirrusfb_set_fbinfo(info);
2297
2298 err = register_framebuffer(info); 2151 err = register_framebuffer(info);
2299 if (err < 0) { 2152 if (err < 0) {
2300 printk(KERN_ERR "cirrusfb: could not register " 2153 printk(KERN_ERR "cirrusfb: could not register "
@@ -2307,7 +2160,6 @@ static int cirrusfb_register(struct fb_info *info)
2307 2160
2308err_dealloc_cmap: 2161err_dealloc_cmap:
2309 fb_dealloc_cmap(&info->cmap); 2162 fb_dealloc_cmap(&info->cmap);
2310err_unmap_cirrusfb:
2311 cinfo->unmap(info); 2163 cinfo->unmap(info);
2312 framebuffer_release(info); 2164 framebuffer_release(info);
2313 return err; 2165 return err;
@@ -2330,8 +2182,8 @@ static void __devexit cirrusfb_cleanup(struct fb_info *info)
2330} 2182}
2331 2183
2332#ifdef CONFIG_PCI 2184#ifdef CONFIG_PCI
2333static int cirrusfb_pci_register(struct pci_dev *pdev, 2185static int __devinit cirrusfb_pci_register(struct pci_dev *pdev,
2334 const struct pci_device_id *ent) 2186 const struct pci_device_id *ent)
2335{ 2187{
2336 struct cirrusfb_info *cinfo; 2188 struct cirrusfb_info *cinfo;
2337 struct fb_info *info; 2189 struct fb_info *info;
@@ -2353,7 +2205,6 @@ static int cirrusfb_pci_register(struct pci_dev *pdev,
2353 } 2205 }
2354 2206
2355 cinfo = info->par; 2207 cinfo = info->par;
2356 cinfo->pdev = pdev;
2357 cinfo->btype = btype = (enum cirrus_board) ent->driver_data; 2208 cinfo->btype = btype = (enum cirrus_board) ent->driver_data;
2358 2209
2359 DPRINTK(" Found PCI device, base address 0 is 0x%x, btype set to %d\n", 2210 DPRINTK(" Found PCI device, base address 0 is 0x%x, btype set to %d\n",
@@ -2459,8 +2310,8 @@ static struct pci_driver cirrusfb_pci_driver = {
2459#endif /* CONFIG_PCI */ 2310#endif /* CONFIG_PCI */
2460 2311
2461#ifdef CONFIG_ZORRO 2312#ifdef CONFIG_ZORRO
2462static int cirrusfb_zorro_register(struct zorro_dev *z, 2313static int __devinit cirrusfb_zorro_register(struct zorro_dev *z,
2463 const struct zorro_device_id *ent) 2314 const struct zorro_device_id *ent)
2464{ 2315{
2465 struct cirrusfb_info *cinfo; 2316 struct cirrusfb_info *cinfo;
2466 struct fb_info *info; 2317 struct fb_info *info;
@@ -2489,7 +2340,6 @@ static int cirrusfb_zorro_register(struct zorro_dev *z,
2489 assert(z); 2340 assert(z);
2490 assert(btype != BT_NONE); 2341 assert(btype != BT_NONE);
2491 2342
2492 cinfo->zdev = z;
2493 board_addr = zorro_resource_start(z); 2343 board_addr = zorro_resource_start(z);
2494 board_size = zorro_resource_len(z); 2344 board_size = zorro_resource_len(z);
2495 info->screen_size = size; 2345 info->screen_size = size;
@@ -2621,17 +2471,17 @@ static int __init cirrusfb_setup(char *options) {
2621 return 0; 2471 return 0;
2622 2472
2623 while ((this_opt = strsep(&options, ",")) != NULL) { 2473 while ((this_opt = strsep(&options, ",")) != NULL) {
2624 if (!*this_opt) continue; 2474 if (!*this_opt)
2475 continue;
2625 2476
2626 DPRINTK("cirrusfb_setup: option '%s'\n", this_opt); 2477 DPRINTK("cirrusfb_setup: option '%s'\n", this_opt);
2627 2478
2628 for (i = 0; i < NUM_TOTAL_MODES; i++) {
2629 sprintf(s, "mode:%s", cirrusfb_predefined[i].name);
2630 if (strcmp(this_opt, s) == 0)
2631 cirrusfb_def_mode = i;
2632 }
2633 if (!strcmp(this_opt, "noaccel")) 2479 if (!strcmp(this_opt, "noaccel"))
2634 noaccel = 1; 2480 noaccel = 1;
2481 else if (!strncmp(this_opt, "mode:", 5))
2482 mode_option = this_opt + 5;
2483 else
2484 mode_option = this_opt;
2635 } 2485 }
2636 return 0; 2486 return 0;
2637} 2487}
@@ -2657,6 +2507,11 @@ static void __exit cirrusfb_exit(void)
2657 2507
2658module_init(cirrusfb_init); 2508module_init(cirrusfb_init);
2659 2509
2510module_param(mode_option, charp, 0);
2511MODULE_PARM_DESC(mode_option, "Initial video mode e.g. '648x480-8@60'");
2512module_param(noaccel, bool, 0);
2513MODULE_PARM_DESC(noaccel, "Disable acceleration");
2514
2660#ifdef MODULE 2515#ifdef MODULE
2661module_exit(cirrusfb_exit); 2516module_exit(cirrusfb_exit);
2662#endif 2517#endif
@@ -3050,16 +2905,14 @@ static void cirrusfb_RectFill(u8 __iomem *regbase, int bits_per_pixel,
3050 * bestclock() - determine closest possible clock lower(?) than the 2905 * bestclock() - determine closest possible clock lower(?) than the
3051 * desired pixel clock 2906 * desired pixel clock
3052 **************************************************************************/ 2907 **************************************************************************/
3053static void bestclock(long freq, long *best, long *nom, 2908static void bestclock(long freq, int *nom, int *den, int *div)
3054 long *den, long *div, long maxfreq)
3055{ 2909{
3056 long n, h, d, f; 2910 int n, d;
2911 long h, diff;
3057 2912
3058 assert(best != NULL);
3059 assert(nom != NULL); 2913 assert(nom != NULL);
3060 assert(den != NULL); 2914 assert(den != NULL);
3061 assert(div != NULL); 2915 assert(div != NULL);
3062 assert(maxfreq > 0);
3063 2916
3064 *nom = 0; 2917 *nom = 0;
3065 *den = 0; 2918 *den = 0;
@@ -3070,51 +2923,47 @@ static void bestclock(long freq, long *best, long *nom,
3070 if (freq < 8000) 2923 if (freq < 8000)
3071 freq = 8000; 2924 freq = 8000;
3072 2925
3073 if (freq > maxfreq) 2926 diff = freq;
3074 freq = maxfreq;
3075
3076 *best = 0;
3077 f = freq * 10;
3078 2927
3079 for (n = 32; n < 128; n++) { 2928 for (n = 32; n < 128; n++) {
3080 d = (143181 * n) / f; 2929 int s = 0;
2930
2931 d = (14318 * n) / freq;
3081 if ((d >= 7) && (d <= 63)) { 2932 if ((d >= 7) && (d <= 63)) {
3082 if (d > 31) 2933 int temp = d;
3083 d = (d / 2) * 2; 2934
3084 h = (14318 * n) / d; 2935 if (temp > 31) {
3085 if (abs(h - freq) < abs(*best - freq)) { 2936 s = 1;
3086 *best = h; 2937 temp >>= 1;
2938 }
2939 h = ((14318 * n) / temp) >> s;
2940 h = h > freq ? h - freq : freq - h;
2941 if (h < diff) {
2942 diff = h;
3087 *nom = n; 2943 *nom = n;
3088 if (d < 32) { 2944 *den = temp;
3089 *den = d; 2945 *div = s;
3090 *div = 0;
3091 } else {
3092 *den = d / 2;
3093 *div = 1;
3094 }
3095 } 2946 }
3096 } 2947 }
3097 d = DIV_ROUND_UP(143181 * n, f); 2948 d++;
3098 if ((d >= 7) && (d <= 63)) { 2949 if ((d >= 7) && (d <= 63)) {
3099 if (d > 31) 2950 if (d > 31) {
3100 d = (d / 2) * 2; 2951 s = 1;
3101 h = (14318 * n) / d; 2952 d >>= 1;
3102 if (abs(h - freq) < abs(*best - freq)) { 2953 }
3103 *best = h; 2954 h = ((14318 * n) / d) >> s;
2955 h = h > freq ? h - freq : freq - h;
2956 if (h < diff) {
2957 diff = h;
3104 *nom = n; 2958 *nom = n;
3105 if (d < 32) { 2959 *den = d;
3106 *den = d; 2960 *div = s;
3107 *div = 0;
3108 } else {
3109 *den = d / 2;
3110 *div = 1;
3111 }
3112 } 2961 }
3113 } 2962 }
3114 } 2963 }
3115 2964
3116 DPRINTK("Best possible values for given frequency:\n"); 2965 DPRINTK("Best possible values for given frequency:\n");
3117 DPRINTK(" best: %ld kHz nom: %ld den: %ld div: %ld\n", 2966 DPRINTK(" freq: %ld kHz nom: %d den: %d div: %d\n",
3118 freq, *nom, *den, *div); 2967 freq, *nom, *den, *div);
3119 2968
3120 DPRINTK("EXIT\n"); 2969 DPRINTK("EXIT\n");
diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
index 9cbff84b787d..64b3d30027b8 100644
--- a/drivers/video/console/fbcon.c
+++ b/drivers/video/console/fbcon.c
@@ -1855,8 +1855,6 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1855 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]]; 1855 struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
1856 struct display *p = &fb_display[vc->vc_num]; 1856 struct display *p = &fb_display[vc->vc_num];
1857 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK; 1857 int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
1858 unsigned short saved_ec;
1859 int ret;
1860 1858
1861 if (fbcon_is_inactive(vc, info)) 1859 if (fbcon_is_inactive(vc, info))
1862 return -EINVAL; 1860 return -EINVAL;
@@ -1869,11 +1867,6 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1869 * whole screen (prevents flicker). 1867 * whole screen (prevents flicker).
1870 */ 1868 */
1871 1869
1872 saved_ec = vc->vc_video_erase_char;
1873 vc->vc_video_erase_char = vc->vc_scrl_erase_char;
1874
1875 ret = 0;
1876
1877 switch (dir) { 1870 switch (dir) {
1878 case SM_UP: 1871 case SM_UP:
1879 if (count > vc->vc_rows) /* Maximum realistic size */ 1872 if (count > vc->vc_rows) /* Maximum realistic size */
@@ -1890,9 +1883,9 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1890 scr_memsetw((unsigned short *) (vc->vc_origin + 1883 scr_memsetw((unsigned short *) (vc->vc_origin +
1891 vc->vc_size_row * 1884 vc->vc_size_row *
1892 (b - count)), 1885 (b - count)),
1893 vc->vc_scrl_erase_char, 1886 vc->vc_video_erase_char,
1894 vc->vc_size_row * count); 1887 vc->vc_size_row * count);
1895 ret = 1; 1888 return 1;
1896 break; 1889 break;
1897 1890
1898 case SCROLL_WRAP_MOVE: 1891 case SCROLL_WRAP_MOVE:
@@ -1962,10 +1955,9 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1962 scr_memsetw((unsigned short *) (vc->vc_origin + 1955 scr_memsetw((unsigned short *) (vc->vc_origin +
1963 vc->vc_size_row * 1956 vc->vc_size_row *
1964 (b - count)), 1957 (b - count)),
1965 vc->vc_scrl_erase_char, 1958 vc->vc_video_erase_char,
1966 vc->vc_size_row * count); 1959 vc->vc_size_row * count);
1967 ret = 1; 1960 return 1;
1968 break;
1969 } 1961 }
1970 break; 1962 break;
1971 1963
@@ -1982,9 +1974,9 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
1982 scr_memsetw((unsigned short *) (vc->vc_origin + 1974 scr_memsetw((unsigned short *) (vc->vc_origin +
1983 vc->vc_size_row * 1975 vc->vc_size_row *
1984 t), 1976 t),
1985 vc->vc_scrl_erase_char, 1977 vc->vc_video_erase_char,
1986 vc->vc_size_row * count); 1978 vc->vc_size_row * count);
1987 ret = 1; 1979 return 1;
1988 break; 1980 break;
1989 1981
1990 case SCROLL_WRAP_MOVE: 1982 case SCROLL_WRAP_MOVE:
@@ -2052,15 +2044,12 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
2052 scr_memsetw((unsigned short *) (vc->vc_origin + 2044 scr_memsetw((unsigned short *) (vc->vc_origin +
2053 vc->vc_size_row * 2045 vc->vc_size_row *
2054 t), 2046 t),
2055 vc->vc_scrl_erase_char, 2047 vc->vc_video_erase_char,
2056 vc->vc_size_row * count); 2048 vc->vc_size_row * count);
2057 ret = 1; 2049 return 1;
2058 break;
2059 } 2050 }
2060 break;
2061 } 2051 }
2062 vc->vc_video_erase_char = saved_ec; 2052 return 0;
2063 return ret;
2064} 2053}
2065 2054
2066 2055
@@ -2522,9 +2511,6 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2522 c = vc->vc_video_erase_char; 2511 c = vc->vc_video_erase_char;
2523 vc->vc_video_erase_char = 2512 vc->vc_video_erase_char =
2524 ((c & 0xfe00) >> 1) | (c & 0xff); 2513 ((c & 0xfe00) >> 1) | (c & 0xff);
2525 c = vc->vc_scrl_erase_char;
2526 vc->vc_scrl_erase_char =
2527 ((c & 0xFE00) >> 1) | (c & 0xFF);
2528 vc->vc_attr >>= 1; 2514 vc->vc_attr >>= 1;
2529 } 2515 }
2530 } else if (!vc->vc_hi_font_mask && cnt == 512) { 2516 } else if (!vc->vc_hi_font_mask && cnt == 512) {
@@ -2555,14 +2541,9 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
2555 if (vc->vc_can_do_color) { 2541 if (vc->vc_can_do_color) {
2556 vc->vc_video_erase_char = 2542 vc->vc_video_erase_char =
2557 ((c & 0xff00) << 1) | (c & 0xff); 2543 ((c & 0xff00) << 1) | (c & 0xff);
2558 c = vc->vc_scrl_erase_char;
2559 vc->vc_scrl_erase_char =
2560 ((c & 0xFF00) << 1) | (c & 0xFF);
2561 vc->vc_attr <<= 1; 2544 vc->vc_attr <<= 1;
2562 } else { 2545 } else
2563 vc->vc_video_erase_char = c & ~0x100; 2546 vc->vc_video_erase_char = c & ~0x100;
2564 vc->vc_scrl_erase_char = c & ~0x100;
2565 }
2566 } 2547 }
2567 2548
2568 } 2549 }
@@ -2996,8 +2977,8 @@ static void fbcon_set_all_vcs(struct fb_info *info)
2996 p = &fb_display[vc->vc_num]; 2977 p = &fb_display[vc->vc_num];
2997 set_blitting_type(vc, info); 2978 set_blitting_type(vc, info);
2998 var_to_display(p, &info->var, info); 2979 var_to_display(p, &info->var, info);
2999 cols = FBCON_SWAP(p->rotate, info->var.xres, info->var.yres); 2980 cols = FBCON_SWAP(ops->rotate, info->var.xres, info->var.yres);
3000 rows = FBCON_SWAP(p->rotate, info->var.yres, info->var.xres); 2981 rows = FBCON_SWAP(ops->rotate, info->var.yres, info->var.xres);
3001 cols /= vc->vc_font.width; 2982 cols /= vc->vc_font.width;
3002 rows /= vc->vc_font.height; 2983 rows /= vc->vc_font.height;
3003 vc_resize(vc, cols, rows); 2984 vc_resize(vc, cols, rows);
@@ -3592,8 +3573,8 @@ static int __init fb_console_init(void)
3592 3573
3593 acquire_console_sem(); 3574 acquire_console_sem();
3594 fb_register_client(&fbcon_event_notifier); 3575 fb_register_client(&fbcon_event_notifier);
3595 fbcon_device = device_create_drvdata(fb_class, NULL, MKDEV(0, 0), 3576 fbcon_device = device_create(fb_class, NULL, MKDEV(0, 0), NULL,
3596 NULL, "fbcon"); 3577 "fbcon");
3597 3578
3598 if (IS_ERR(fbcon_device)) { 3579 if (IS_ERR(fbcon_device)) {
3599 printk(KERN_WARNING "Unable to create device " 3580 printk(KERN_WARNING "Unable to create device "
diff --git a/drivers/video/console/mdacon.c b/drivers/video/console/mdacon.c
index 9901064199bd..dd3eaaad4441 100644
--- a/drivers/video/console/mdacon.c
+++ b/drivers/video/console/mdacon.c
@@ -533,7 +533,7 @@ static void mdacon_cursor(struct vc_data *c, int mode)
533 533
534static int mdacon_scroll(struct vc_data *c, int t, int b, int dir, int lines) 534static int mdacon_scroll(struct vc_data *c, int t, int b, int dir, int lines)
535{ 535{
536 u16 eattr = mda_convert_attr(c->vc_scrl_erase_char); 536 u16 eattr = mda_convert_attr(c->vc_video_erase_char);
537 537
538 if (!lines) 538 if (!lines)
539 return 0; 539 return 0;
diff --git a/drivers/video/console/sticon.c b/drivers/video/console/sticon.c
index 4055dbdd1b42..491c1c1baf4c 100644
--- a/drivers/video/console/sticon.c
+++ b/drivers/video/console/sticon.c
@@ -170,12 +170,12 @@ static int sticon_scroll(struct vc_data *conp, int t, int b, int dir, int count)
170 switch (dir) { 170 switch (dir) {
171 case SM_UP: 171 case SM_UP:
172 sti_bmove(sti, t + count, 0, t, 0, b - t - count, conp->vc_cols); 172 sti_bmove(sti, t + count, 0, t, 0, b - t - count, conp->vc_cols);
173 sti_clear(sti, b - count, 0, count, conp->vc_cols, conp->vc_scrl_erase_char); 173 sti_clear(sti, b - count, 0, count, conp->vc_cols, conp->vc_video_erase_char);
174 break; 174 break;
175 175
176 case SM_DOWN: 176 case SM_DOWN:
177 sti_bmove(sti, t, 0, t + count, 0, b - t - count, conp->vc_cols); 177 sti_bmove(sti, t, 0, t + count, 0, b - t - count, conp->vc_cols);
178 sti_clear(sti, t, 0, count, conp->vc_cols, conp->vc_scrl_erase_char); 178 sti_clear(sti, t, 0, count, conp->vc_cols, conp->vc_video_erase_char);
179 break; 179 break;
180 } 180 }
181 181
diff --git a/drivers/video/console/vgacon.c b/drivers/video/console/vgacon.c
index bd1f57b259d9..448d209a0bf2 100644
--- a/drivers/video/console/vgacon.c
+++ b/drivers/video/console/vgacon.c
@@ -239,8 +239,7 @@ static void vgacon_restore_screen(struct vc_data *c)
239 239
240static int vgacon_scrolldelta(struct vc_data *c, int lines) 240static int vgacon_scrolldelta(struct vc_data *c, int lines)
241{ 241{
242 int start, end, count, soff, diff; 242 int start, end, count, soff;
243 void *d, *s;
244 243
245 if (!lines) { 244 if (!lines) {
246 c->vc_visible_origin = c->vc_origin; 245 c->vc_visible_origin = c->vc_origin;
@@ -287,29 +286,29 @@ static int vgacon_scrolldelta(struct vc_data *c, int lines)
287 if (count > c->vc_rows) 286 if (count > c->vc_rows)
288 count = c->vc_rows; 287 count = c->vc_rows;
289 288
290 diff = c->vc_rows - count; 289 if (count) {
290 int copysize;
291 291
292 d = (void *) c->vc_origin; 292 int diff = c->vc_rows - count;
293 s = (void *) c->vc_screenbuf; 293 void *d = (void *) c->vc_origin;
294 void *s = (void *) c->vc_screenbuf;
294 295
295 while (count--) { 296 count *= c->vc_size_row;
296 scr_memcpyw(d, vgacon_scrollback + soff, c->vc_size_row); 297 /* how much memory to end of buffer left? */
297 d += c->vc_size_row; 298 copysize = min(count, vgacon_scrollback_size - soff);
298 soff += c->vc_size_row; 299 scr_memcpyw(d, vgacon_scrollback + soff, copysize);
300 d += copysize;
301 count -= copysize;
299 302
300 if (soff >= vgacon_scrollback_size) 303 if (count) {
301 soff = 0; 304 scr_memcpyw(d, vgacon_scrollback, count);
302 } 305 d += count;
306 }
303 307
304 if (diff == c->vc_rows) { 308 if (diff)
309 scr_memcpyw(d, s, diff * c->vc_size_row);
310 } else
305 vgacon_cursor(c, CM_MOVE); 311 vgacon_cursor(c, CM_MOVE);
306 } else {
307 while (diff--) {
308 scr_memcpyw(d, s, c->vc_size_row);
309 d += c->vc_size_row;
310 s += c->vc_size_row;
311 }
312 }
313 312
314 return 1; 313 return 1;
315} 314}
@@ -1350,7 +1349,7 @@ static int vgacon_scroll(struct vc_data *c, int t, int b, int dir,
1350 } else 1349 } else
1351 c->vc_origin += delta; 1350 c->vc_origin += delta;
1352 scr_memsetw((u16 *) (c->vc_origin + c->vc_screenbuf_size - 1351 scr_memsetw((u16 *) (c->vc_origin + c->vc_screenbuf_size -
1353 delta), c->vc_scrl_erase_char, 1352 delta), c->vc_video_erase_char,
1354 delta); 1353 delta);
1355 } else { 1354 } else {
1356 if (oldo - delta < vga_vram_base) { 1355 if (oldo - delta < vga_vram_base) {
@@ -1363,7 +1362,7 @@ static int vgacon_scroll(struct vc_data *c, int t, int b, int dir,
1363 } else 1362 } else
1364 c->vc_origin -= delta; 1363 c->vc_origin -= delta;
1365 c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size; 1364 c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
1366 scr_memsetw((u16 *) (c->vc_origin), c->vc_scrl_erase_char, 1365 scr_memsetw((u16 *) (c->vc_origin), c->vc_video_erase_char,
1367 delta); 1366 delta);
1368 } 1367 }
1369 c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size; 1368 c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
diff --git a/drivers/video/display/display-sysfs.c b/drivers/video/display/display-sysfs.c
index 6ef800bdf482..4830b1bf51e5 100644
--- a/drivers/video/display/display-sysfs.c
+++ b/drivers/video/display/display-sysfs.c
@@ -153,12 +153,9 @@ struct display_device *display_device_register(struct display_driver *driver,
153 mutex_unlock(&allocated_dsp_lock); 153 mutex_unlock(&allocated_dsp_lock);
154 154
155 if (!ret) { 155 if (!ret) {
156 new_dev->dev = device_create_drvdata(display_class, 156 new_dev->dev = device_create(display_class, parent,
157 parent, 157 MKDEV(0, 0), new_dev,
158 MKDEV(0,0), 158 "display%d", new_dev->idx);
159 new_dev,
160 "display%d",
161 new_dev->idx);
162 if (!IS_ERR(new_dev->dev)) { 159 if (!IS_ERR(new_dev->dev)) {
163 new_dev->parent = parent; 160 new_dev->parent = parent;
164 new_dev->driver = driver; 161 new_dev->driver = driver;
diff --git a/drivers/video/efifb.c b/drivers/video/efifb.c
index bd779ae44b1e..daf9b81878a4 100644
--- a/drivers/video/efifb.c
+++ b/drivers/video/efifb.c
@@ -12,6 +12,7 @@
12#include <linux/fb.h> 12#include <linux/fb.h>
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/screen_info.h> 14#include <linux/screen_info.h>
15#include <linux/dmi.h>
15 16
16#include <video/vga.h> 17#include <video/vga.h>
17 18
@@ -33,6 +34,105 @@ static struct fb_fix_screeninfo efifb_fix __initdata = {
33 .visual = FB_VISUAL_TRUECOLOR, 34 .visual = FB_VISUAL_TRUECOLOR,
34}; 35};
35 36
37enum {
38 M_I17, /* 17-Inch iMac */
39 M_I20, /* 20-Inch iMac */
40 M_I20_SR, /* 20-Inch iMac (Santa Rosa) */
41 M_I24, /* 24-Inch iMac */
42 M_MINI, /* Mac Mini */
43 M_MB, /* MacBook */
44 M_MB_2, /* MacBook, 2nd rev. */
45 M_MB_3, /* MacBook, 3rd rev. */
46 M_MB_SR, /* MacBook, 2nd gen, (Santa Rosa) */
47 M_MBA, /* MacBook Air */
48 M_MBP, /* MacBook Pro */
49 M_MBP_2, /* MacBook Pro 2nd gen */
50 M_MBP_SR, /* MacBook Pro (Santa Rosa) */
51 M_MBP_4, /* MacBook Pro, 4th gen */
52 M_UNKNOWN /* placeholder */
53};
54
55static struct efifb_dmi_info {
56 char *optname;
57 unsigned long base;
58 int stride;
59 int width;
60 int height;
61} dmi_list[] = {
62 [M_I17] = { "i17", 0x80010000, 1472 * 4, 1440, 900 },
63 [M_I20] = { "i20", 0x80010000, 1728 * 4, 1680, 1050 }, /* guess */
64 [M_I20_SR] = { "imac7", 0x40010000, 1728 * 4, 1680, 1050 },
65 [M_I24] = { "i24", 0x80010000, 2048 * 4, 1920, 1200 }, /* guess */
66 [M_MINI]= { "mini", 0x80000000, 2048 * 4, 1024, 768 },
67 [M_MB] = { "macbook", 0x80000000, 2048 * 4, 1280, 800 },
68 [M_MBA] = { "mba", 0x80000000, 2048 * 4, 1280, 800 },
69 [M_MBP] = { "mbp", 0x80010000, 1472 * 4, 1440, 900 },
70 [M_MBP_2] = { "mbp2", 0, 0, 0, 0 }, /* placeholder */
71 [M_MBP_SR] = { "mbp3", 0x80030000, 2048 * 4, 1440, 900 },
72 [M_MBP_4] = { "mbp4", 0xc0060000, 2048 * 4, 1920, 1200 },
73 [M_UNKNOWN] = { NULL, 0, 0, 0, 0 }
74};
75
76static int set_system(const struct dmi_system_id *id);
77
78#define EFIFB_DMI_SYSTEM_ID(vendor, name, enumid) \
79 { set_system, name, { \
80 DMI_MATCH(DMI_BIOS_VENDOR, vendor), \
81 DMI_MATCH(DMI_PRODUCT_NAME, name) }, \
82 &dmi_list[enumid] }
83
84static struct dmi_system_id __initdata dmi_system_table[] = {
85 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac4,1", M_I17),
86 /* At least one of these two will be right; maybe both? */
87 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac5,1", M_I20),
88 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac5,1", M_I20),
89 /* At least one of these two will be right; maybe both? */
90 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "iMac6,1", M_I24),
91 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac6,1", M_I24),
92 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "iMac7,1", M_I20_SR),
93 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "Macmini1,1", M_MINI),
94 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook1,1", M_MB),
95 /* At least one of these two will be right; maybe both? */
96 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook2,1", M_MB),
97 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook2,1", M_MB),
98 /* At least one of these two will be right; maybe both? */
99 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBook3,1", M_MB),
100 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook3,1", M_MB),
101 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBook4,1", M_MB),
102 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookAir1,1", M_MBA),
103 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro1,1", M_MBP),
104 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro2,1", M_MBP_2),
105 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro2,1", M_MBP_2),
106 EFIFB_DMI_SYSTEM_ID("Apple Computer, Inc.", "MacBookPro3,1", M_MBP_SR),
107 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro3,1", M_MBP_SR),
108 EFIFB_DMI_SYSTEM_ID("Apple Inc.", "MacBookPro4,1", M_MBP_4),
109 {},
110};
111
112static int set_system(const struct dmi_system_id *id)
113{
114 struct efifb_dmi_info *info = id->driver_data;
115 if (info->base == 0)
116 return -ENODEV;
117
118 printk(KERN_INFO "efifb: dmi detected %s - framebuffer at %p "
119 "(%dx%d, stride %d)\n", id->ident,
120 (void *)info->base, info->width, info->height,
121 info->stride);
122
123 /* Trust the bootloader over the DMI tables */
124 if (screen_info.lfb_base == 0)
125 screen_info.lfb_base = info->base;
126 if (screen_info.lfb_linelength == 0)
127 screen_info.lfb_linelength = info->stride;
128 if (screen_info.lfb_width == 0)
129 screen_info.lfb_width = info->width;
130 if (screen_info.lfb_height == 0)
131 screen_info.lfb_height = info->height;
132
133 return 0;
134}
135
36static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green, 136static int efifb_setcolreg(unsigned regno, unsigned red, unsigned green,
37 unsigned blue, unsigned transp, 137 unsigned blue, unsigned transp,
38 struct fb_info *info) 138 struct fb_info *info)
@@ -67,6 +167,38 @@ static struct fb_ops efifb_ops = {
67 .fb_imageblit = cfb_imageblit, 167 .fb_imageblit = cfb_imageblit,
68}; 168};
69 169
170static int __init efifb_setup(char *options)
171{
172 char *this_opt;
173 int i;
174
175 if (!options || !*options)
176 return 0;
177
178 while ((this_opt = strsep(&options, ",")) != NULL) {
179 if (!*this_opt) continue;
180
181 for (i = 0; i < M_UNKNOWN; i++) {
182 if (!strcmp(this_opt, dmi_list[i].optname) &&
183 dmi_list[i].base != 0) {
184 screen_info.lfb_base = dmi_list[i].base;
185 screen_info.lfb_linelength = dmi_list[i].stride;
186 screen_info.lfb_width = dmi_list[i].width;
187 screen_info.lfb_height = dmi_list[i].height;
188 }
189 }
190 if (!strncmp(this_opt, "base:", 5))
191 screen_info.lfb_base = simple_strtoul(this_opt+5, NULL, 0);
192 else if (!strncmp(this_opt, "stride:", 7))
193 screen_info.lfb_linelength = simple_strtoul(this_opt+7, NULL, 0) * 4;
194 else if (!strncmp(this_opt, "height:", 7))
195 screen_info.lfb_height = simple_strtoul(this_opt+7, NULL, 0);
196 else if (!strncmp(this_opt, "width:", 6))
197 screen_info.lfb_width = simple_strtoul(this_opt+6, NULL, 0);
198 }
199 return 0;
200}
201
70static int __init efifb_probe(struct platform_device *dev) 202static int __init efifb_probe(struct platform_device *dev)
71{ 203{
72 struct fb_info *info; 204 struct fb_info *info;
@@ -74,6 +206,26 @@ static int __init efifb_probe(struct platform_device *dev)
74 unsigned int size_vmode; 206 unsigned int size_vmode;
75 unsigned int size_remap; 207 unsigned int size_remap;
76 unsigned int size_total; 208 unsigned int size_total;
209 int request_succeeded = 0;
210
211 printk(KERN_INFO "efifb: probing for efifb\n");
212
213 if (!screen_info.lfb_depth)
214 screen_info.lfb_depth = 32;
215 if (!screen_info.pages)
216 screen_info.pages = 1;
217
218 /* just assume they're all unset if any are */
219 if (!screen_info.blue_size) {
220 screen_info.blue_size = 8;
221 screen_info.blue_pos = 0;
222 screen_info.green_size = 8;
223 screen_info.green_pos = 8;
224 screen_info.red_size = 8;
225 screen_info.red_pos = 16;
226 screen_info.rsvd_size = 8;
227 screen_info.rsvd_pos = 24;
228 }
77 229
78 efifb_fix.smem_start = screen_info.lfb_base; 230 efifb_fix.smem_start = screen_info.lfb_base;
79 efifb_defined.bits_per_pixel = screen_info.lfb_depth; 231 efifb_defined.bits_per_pixel = screen_info.lfb_depth;
@@ -98,21 +250,25 @@ static int __init efifb_probe(struct platform_device *dev)
98 * option to simply use size_total as that 250 * option to simply use size_total as that
99 * wastes plenty of kernel address space. */ 251 * wastes plenty of kernel address space. */
100 size_remap = size_vmode * 2; 252 size_remap = size_vmode * 2;
101 if (size_remap < size_vmode)
102 size_remap = size_vmode;
103 if (size_remap > size_total) 253 if (size_remap > size_total)
104 size_remap = size_total; 254 size_remap = size_total;
255 if (size_remap % PAGE_SIZE)
256 size_remap += PAGE_SIZE - (size_remap % PAGE_SIZE);
105 efifb_fix.smem_len = size_remap; 257 efifb_fix.smem_len = size_remap;
106 258
107 if (!request_mem_region(efifb_fix.smem_start, size_total, "efifb")) 259 if (request_mem_region(efifb_fix.smem_start, size_remap, "efifb")) {
260 request_succeeded = 1;
261 } else {
108 /* We cannot make this fatal. Sometimes this comes from magic 262 /* We cannot make this fatal. Sometimes this comes from magic
109 spaces our resource handlers simply don't know about */ 263 spaces our resource handlers simply don't know about */
110 printk(KERN_WARNING 264 printk(KERN_WARNING
111 "efifb: cannot reserve video memory at 0x%lx\n", 265 "efifb: cannot reserve video memory at 0x%lx\n",
112 efifb_fix.smem_start); 266 efifb_fix.smem_start);
267 }
113 268
114 info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev); 269 info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev);
115 if (!info) { 270 if (!info) {
271 printk(KERN_ERR "efifb: cannot allocate framebuffer\n");
116 err = -ENOMEM; 272 err = -ENOMEM;
117 goto err_release_mem; 273 goto err_release_mem;
118 } 274 }
@@ -125,7 +281,7 @@ static int __init efifb_probe(struct platform_device *dev)
125 "0x%x @ 0x%lx\n", 281 "0x%x @ 0x%lx\n",
126 efifb_fix.smem_len, efifb_fix.smem_start); 282 efifb_fix.smem_len, efifb_fix.smem_start);
127 err = -EIO; 283 err = -EIO;
128 goto err_unmap; 284 goto err_release_fb;
129 } 285 }
130 286
131 printk(KERN_INFO "efifb: framebuffer at 0x%lx, mapped to 0x%p, " 287 printk(KERN_INFO "efifb: framebuffer at 0x%lx, mapped to 0x%p, "
@@ -178,25 +334,27 @@ static int __init efifb_probe(struct platform_device *dev)
178 info->fix = efifb_fix; 334 info->fix = efifb_fix;
179 info->flags = FBINFO_FLAG_DEFAULT; 335 info->flags = FBINFO_FLAG_DEFAULT;
180 336
181 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) { 337 if ((err = fb_alloc_cmap(&info->cmap, 256, 0)) < 0) {
182 err = -ENOMEM; 338 printk(KERN_ERR "efifb: cannot allocate colormap\n");
183 goto err_unmap; 339 goto err_unmap;
184 } 340 }
185 if (register_framebuffer(info) < 0) { 341 if ((err = register_framebuffer(info)) < 0) {
186 err = -EINVAL; 342 printk(KERN_ERR "efifb: cannot register framebuffer\n");
187 goto err_fb_dealoc; 343 goto err_fb_dealoc;
188 } 344 }
189 printk(KERN_INFO "fb%d: %s frame buffer device\n", 345 printk(KERN_INFO "fb%d: %s frame buffer device\n",
190 info->node, info->fix.id); 346 info->node, info->fix.id);
191 return 0; 347 return 0;
192 348
193err_fb_dealoc: 349err_fb_dealoc:
194 fb_dealloc_cmap(&info->cmap); 350 fb_dealloc_cmap(&info->cmap);
195err_unmap: 351err_unmap:
196 iounmap(info->screen_base); 352 iounmap(info->screen_base);
353err_release_fb:
197 framebuffer_release(info); 354 framebuffer_release(info);
198err_release_mem: 355err_release_mem:
199 release_mem_region(efifb_fix.smem_start, size_total); 356 if (request_succeeded)
357 release_mem_region(efifb_fix.smem_start, size_total);
200 return err; 358 return err;
201} 359}
202 360
@@ -214,9 +372,22 @@ static struct platform_device efifb_device = {
214static int __init efifb_init(void) 372static int __init efifb_init(void)
215{ 373{
216 int ret; 374 int ret;
375 char *option = NULL;
217 376
218 if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI) 377 if (screen_info.orig_video_isVGA != VIDEO_TYPE_EFI)
219 return -ENODEV; 378 return -ENODEV;
379 dmi_check_system(dmi_system_table);
380
381 if (fb_get_options("efifb", &option))
382 return -ENODEV;
383 efifb_setup(option);
384
385 /* We don't get linelength from UGA Draw Protocol, only from
386 * EFI Graphics Protocol. So if it's not in DMI, and it's not
387 * passed in from the user, we really can't use the framebuffer.
388 */
389 if (!screen_info.lfb_linelength)
390 return -ENODEV;
220 391
221 ret = platform_driver_register(&efifb_driver); 392 ret = platform_driver_register(&efifb_driver);
222 393
diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
index 0737570030f5..217c5118ae9e 100644
--- a/drivers/video/fbmem.c
+++ b/drivers/video/fbmem.c
@@ -28,9 +28,7 @@
28#include <linux/proc_fs.h> 28#include <linux/proc_fs.h>
29#include <linux/seq_file.h> 29#include <linux/seq_file.h>
30#include <linux/console.h> 30#include <linux/console.h>
31#ifdef CONFIG_KMOD
32#include <linux/kmod.h> 31#include <linux/kmod.h>
33#endif
34#include <linux/err.h> 32#include <linux/err.h>
35#include <linux/device.h> 33#include <linux/device.h>
36#include <linux/efi.h> 34#include <linux/efi.h>
@@ -837,13 +835,6 @@ fb_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
837 return (cnt) ? cnt : err; 835 return (cnt) ? cnt : err;
838} 836}
839 837
840#ifdef CONFIG_KMOD
841static void try_to_load(int fb)
842{
843 request_module("fb%d", fb);
844}
845#endif /* CONFIG_KMOD */
846
847int 838int
848fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var) 839fb_pan_display(struct fb_info *info, struct fb_var_screeninfo *var)
849{ 840{
@@ -1086,10 +1077,8 @@ fb_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
1086 return -EINVAL; 1077 return -EINVAL;
1087 if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX) 1078 if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
1088 return -EINVAL; 1079 return -EINVAL;
1089#ifdef CONFIG_KMOD
1090 if (!registered_fb[con2fb.framebuffer]) 1080 if (!registered_fb[con2fb.framebuffer])
1091 try_to_load(con2fb.framebuffer); 1081 request_module("fb%d", con2fb.framebuffer);
1092#endif /* CONFIG_KMOD */
1093 if (!registered_fb[con2fb.framebuffer]) 1082 if (!registered_fb[con2fb.framebuffer])
1094 return -EINVAL; 1083 return -EINVAL;
1095 event.info = info; 1084 event.info = info;
@@ -1327,10 +1316,8 @@ fb_open(struct inode *inode, struct file *file)
1327 if (fbidx >= FB_MAX) 1316 if (fbidx >= FB_MAX)
1328 return -ENODEV; 1317 return -ENODEV;
1329 lock_kernel(); 1318 lock_kernel();
1330#ifdef CONFIG_KMOD
1331 if (!(info = registered_fb[fbidx])) 1319 if (!(info = registered_fb[fbidx]))
1332 try_to_load(fbidx); 1320 request_module("fb%d", fbidx);
1333#endif /* CONFIG_KMOD */
1334 if (!(info = registered_fb[fbidx])) { 1321 if (!(info = registered_fb[fbidx])) {
1335 res = -ENODEV; 1322 res = -ENODEV;
1336 goto out; 1323 goto out;
@@ -1443,9 +1430,8 @@ register_framebuffer(struct fb_info *fb_info)
1443 break; 1430 break;
1444 fb_info->node = i; 1431 fb_info->node = i;
1445 1432
1446 fb_info->dev = device_create_drvdata(fb_class, fb_info->device, 1433 fb_info->dev = device_create(fb_class, fb_info->device,
1447 MKDEV(FB_MAJOR, i), NULL, 1434 MKDEV(FB_MAJOR, i), NULL, "fb%d", i);
1448 "fb%d", i);
1449 if (IS_ERR(fb_info->dev)) { 1435 if (IS_ERR(fb_info->dev)) {
1450 /* Not fatal */ 1436 /* Not fatal */
1451 printk(KERN_WARNING "Unable to create device for framebuffer %d; errno = %ld\n", i, PTR_ERR(fb_info->dev)); 1437 printk(KERN_WARNING "Unable to create device for framebuffer %d; errno = %ld\n", i, PTR_ERR(fb_info->dev));
diff --git a/drivers/video/fbmon.c b/drivers/video/fbmon.c
index 6a0aa180c266..5c1a2c01778f 100644
--- a/drivers/video/fbmon.c
+++ b/drivers/video/fbmon.c
@@ -564,7 +564,13 @@ static void get_detailed_timing(unsigned char *block,
564 mode->sync |= FB_SYNC_VERT_HIGH_ACT; 564 mode->sync |= FB_SYNC_VERT_HIGH_ACT;
565 mode->refresh = PIXEL_CLOCK/((H_ACTIVE + H_BLANKING) * 565 mode->refresh = PIXEL_CLOCK/((H_ACTIVE + H_BLANKING) *
566 (V_ACTIVE + V_BLANKING)); 566 (V_ACTIVE + V_BLANKING));
567 mode->vmode = 0; 567 if (INTERLACED) {
568 mode->yres *= 2;
569 mode->upper_margin *= 2;
570 mode->lower_margin *= 2;
571 mode->vsync_len *= 2;
572 mode->vmode |= FB_VMODE_INTERLACED;
573 }
568 mode->flag = FB_MODE_IS_DETAILED; 574 mode->flag = FB_MODE_IS_DETAILED;
569 575
570 DPRINTK(" %d MHz ", PIXEL_CLOCK/1000000); 576 DPRINTK(" %d MHz ", PIXEL_CLOCK/1000000);
diff --git a/drivers/video/imacfb.c b/drivers/video/imacfb.c
index 9366ef2bb5f7..e69de29bb2d1 100644
--- a/drivers/video/imacfb.c
+++ b/drivers/video/imacfb.c
@@ -1,376 +0,0 @@
1/*
2 * framebuffer driver for Intel Based Mac's
3 *
4 * (c) 2006 Edgar Hucek <gimli@dark-green.com>
5 * Original imac driver written by Gerd Knorr <kraxel@goldbach.in-berlin.de>
6 *
7 */
8
9#include <linux/delay.h>
10#include <linux/errno.h>
11#include <linux/fb.h>
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/ioport.h>
15#include <linux/mm.h>
16#include <linux/module.h>
17#include <linux/platform_device.h>
18#include <linux/screen_info.h>
19#include <linux/slab.h>
20#include <linux/string.h>
21#include <linux/dmi.h>
22#include <linux/efi.h>
23
24#include <asm/io.h>
25
26#include <video/vga.h>
27
28typedef enum _MAC_TYPE {
29 M_I17,
30 M_I20,
31 M_MINI,
32 M_MACBOOK,
33 M_UNKNOWN
34} MAC_TYPE;
35
36/* --------------------------------------------------------------------- */
37
38static struct fb_var_screeninfo imacfb_defined __initdata = {
39 .activate = FB_ACTIVATE_NOW,
40 .height = -1,
41 .width = -1,
42 .right_margin = 32,
43 .upper_margin = 16,
44 .lower_margin = 4,
45 .vsync_len = 4,
46 .vmode = FB_VMODE_NONINTERLACED,
47};
48
49static struct fb_fix_screeninfo imacfb_fix __initdata = {
50 .id = "IMAC VGA",
51 .type = FB_TYPE_PACKED_PIXELS,
52 .accel = FB_ACCEL_NONE,
53 .visual = FB_VISUAL_TRUECOLOR,
54};
55
56static int inverse;
57static int model = M_UNKNOWN;
58static int manual_height;
59static int manual_width;
60
61static int set_system(const struct dmi_system_id *id)
62{
63 printk(KERN_INFO "imacfb: %s detected - set system to %ld\n",
64 id->ident, (long)id->driver_data);
65
66 model = (long)id->driver_data;
67
68 return 0;
69}
70
71static struct dmi_system_id __initdata dmi_system_table[] = {
72 { set_system, "iMac4,1", {
73 DMI_MATCH(DMI_BIOS_VENDOR,"Apple Computer, Inc."),
74 DMI_MATCH(DMI_PRODUCT_NAME,"iMac4,1") }, (void*)M_I17},
75 { set_system, "MacBookPro1,1", {
76 DMI_MATCH(DMI_BIOS_VENDOR,"Apple Computer, Inc."),
77 DMI_MATCH(DMI_PRODUCT_NAME,"MacBookPro1,1") }, (void*)M_I17},
78 { set_system, "MacBook1,1", {
79 DMI_MATCH(DMI_BIOS_VENDOR,"Apple Computer, Inc."),
80 DMI_MATCH(DMI_PRODUCT_NAME,"MacBook1,1")}, (void *)M_MACBOOK},
81 { set_system, "Macmini1,1", {
82 DMI_MATCH(DMI_BIOS_VENDOR,"Apple Computer, Inc."),
83 DMI_MATCH(DMI_PRODUCT_NAME,"Macmini1,1")}, (void *)M_MINI},
84 {},
85};
86
87#define DEFAULT_FB_MEM 1024*1024*16
88
89/* --------------------------------------------------------------------- */
90
91static int imacfb_setcolreg(unsigned regno, unsigned red, unsigned green,
92 unsigned blue, unsigned transp,
93 struct fb_info *info)
94{
95 /*
96 * Set a single color register. The values supplied are
97 * already rounded down to the hardware's capabilities
98 * (according to the entries in the `var' structure). Return
99 * != 0 for invalid regno.
100 */
101
102 if (regno >= info->cmap.len)
103 return 1;
104
105 if (regno < 16) {
106 red >>= 8;
107 green >>= 8;
108 blue >>= 8;
109 ((u32 *)(info->pseudo_palette))[regno] =
110 (red << info->var.red.offset) |
111 (green << info->var.green.offset) |
112 (blue << info->var.blue.offset);
113 }
114 return 0;
115}
116
117static struct fb_ops imacfb_ops = {
118 .owner = THIS_MODULE,
119 .fb_setcolreg = imacfb_setcolreg,
120 .fb_fillrect = cfb_fillrect,
121 .fb_copyarea = cfb_copyarea,
122 .fb_imageblit = cfb_imageblit,
123};
124
125static int __init imacfb_setup(char *options)
126{
127 char *this_opt;
128
129 if (!options || !*options)
130 return 0;
131
132 while ((this_opt = strsep(&options, ",")) != NULL) {
133 if (!*this_opt) continue;
134
135 if (!strcmp(this_opt, "inverse"))
136 inverse = 1;
137 else if (!strcmp(this_opt, "i17"))
138 model = M_I17;
139 else if (!strcmp(this_opt, "i20"))
140 model = M_I20;
141 else if (!strcmp(this_opt, "mini"))
142 model = M_MINI;
143 else if (!strcmp(this_opt, "macbook"))
144 model = M_MACBOOK;
145 else if (!strncmp(this_opt, "height:", 7))
146 manual_height = simple_strtoul(this_opt+7, NULL, 0);
147 else if (!strncmp(this_opt, "width:", 6))
148 manual_width = simple_strtoul(this_opt+6, NULL, 0);
149 }
150 return 0;
151}
152
153static int __init imacfb_probe(struct platform_device *dev)
154{
155 struct fb_info *info;
156 int err;
157 unsigned int size_vmode;
158 unsigned int size_remap;
159 unsigned int size_total;
160
161 screen_info.lfb_depth = 32;
162 screen_info.lfb_size = DEFAULT_FB_MEM / 0x10000;
163 screen_info.pages=1;
164 screen_info.blue_size = 8;
165 screen_info.blue_pos = 0;
166 screen_info.green_size = 8;
167 screen_info.green_pos = 8;
168 screen_info.red_size = 8;
169 screen_info.red_pos = 16;
170 screen_info.rsvd_size = 8;
171 screen_info.rsvd_pos = 24;
172
173 switch (model) {
174 case M_I17:
175 screen_info.lfb_width = 1440;
176 screen_info.lfb_height = 900;
177 screen_info.lfb_linelength = 1472 * 4;
178 screen_info.lfb_base = 0x80010000;
179 break;
180 case M_I20:
181 screen_info.lfb_width = 1680;
182 screen_info.lfb_height = 1050;
183 screen_info.lfb_linelength = 1728 * 4;
184 screen_info.lfb_base = 0x80010000;
185 break;
186 case M_MINI:
187 screen_info.lfb_width = 1024;
188 screen_info.lfb_height = 768;
189 screen_info.lfb_linelength = 2048 * 4;
190 screen_info.lfb_base = 0x80000000;
191 break;
192 case M_MACBOOK:
193 screen_info.lfb_width = 1280;
194 screen_info.lfb_height = 800;
195 screen_info.lfb_linelength = 2048 * 4;
196 screen_info.lfb_base = 0x80000000;
197 break;
198 }
199
200 /* if the user wants to manually specify height/width,
201 we will override the defaults */
202 /* TODO: eventually get auto-detection working */
203 if (manual_height > 0)
204 screen_info.lfb_height = manual_height;
205 if (manual_width > 0)
206 screen_info.lfb_width = manual_width;
207
208 imacfb_fix.smem_start = screen_info.lfb_base;
209 imacfb_defined.bits_per_pixel = screen_info.lfb_depth;
210 imacfb_defined.xres = screen_info.lfb_width;
211 imacfb_defined.yres = screen_info.lfb_height;
212 imacfb_fix.line_length = screen_info.lfb_linelength;
213
214 /* size_vmode -- that is the amount of memory needed for the
215 * used video mode, i.e. the minimum amount of
216 * memory we need. */
217 size_vmode = imacfb_defined.yres * imacfb_fix.line_length;
218
219 /* size_total -- all video memory we have. Used for
220 * entries, ressource allocation and bounds
221 * checking. */
222 size_total = screen_info.lfb_size * 65536;
223 if (size_total < size_vmode)
224 size_total = size_vmode;
225
226 /* size_remap -- the amount of video memory we are going to
227 * use for imacfb. With modern cards it is no
228 * option to simply use size_total as that
229 * wastes plenty of kernel address space. */
230 size_remap = size_vmode * 2;
231 if (size_remap < size_vmode)
232 size_remap = size_vmode;
233 if (size_remap > size_total)
234 size_remap = size_total;
235 imacfb_fix.smem_len = size_remap;
236
237 if (!request_mem_region(imacfb_fix.smem_start, size_total, "imacfb")) {
238 printk(KERN_WARNING
239 "imacfb: cannot reserve video memory at 0x%lx\n",
240 imacfb_fix.smem_start);
241 /* We cannot make this fatal. Sometimes this comes from magic
242 spaces our resource handlers simply don't know about */
243 }
244
245 info = framebuffer_alloc(sizeof(u32) * 16, &dev->dev);
246 if (!info) {
247 err = -ENOMEM;
248 goto err_release_mem;
249 }
250 info->pseudo_palette = info->par;
251 info->par = NULL;
252
253 info->screen_base = ioremap(imacfb_fix.smem_start, imacfb_fix.smem_len);
254 if (!info->screen_base) {
255 printk(KERN_ERR "imacfb: abort, cannot ioremap video memory "
256 "0x%x @ 0x%lx\n",
257 imacfb_fix.smem_len, imacfb_fix.smem_start);
258 err = -EIO;
259 goto err_unmap;
260 }
261
262 printk(KERN_INFO "imacfb: framebuffer at 0x%lx, mapped to 0x%p, "
263 "using %dk, total %dk\n",
264 imacfb_fix.smem_start, info->screen_base,
265 size_remap/1024, size_total/1024);
266 printk(KERN_INFO "imacfb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
267 imacfb_defined.xres, imacfb_defined.yres,
268 imacfb_defined.bits_per_pixel, imacfb_fix.line_length,
269 screen_info.pages);
270
271 imacfb_defined.xres_virtual = imacfb_defined.xres;
272 imacfb_defined.yres_virtual = imacfb_fix.smem_len /
273 imacfb_fix.line_length;
274 printk(KERN_INFO "imacfb: scrolling: redraw\n");
275 imacfb_defined.yres_virtual = imacfb_defined.yres;
276
277 /* some dummy values for timing to make fbset happy */
278 imacfb_defined.pixclock = 10000000 / imacfb_defined.xres *
279 1000 / imacfb_defined.yres;
280 imacfb_defined.left_margin = (imacfb_defined.xres / 8) & 0xf8;
281 imacfb_defined.hsync_len = (imacfb_defined.xres / 8) & 0xf8;
282
283 imacfb_defined.red.offset = screen_info.red_pos;
284 imacfb_defined.red.length = screen_info.red_size;
285 imacfb_defined.green.offset = screen_info.green_pos;
286 imacfb_defined.green.length = screen_info.green_size;
287 imacfb_defined.blue.offset = screen_info.blue_pos;
288 imacfb_defined.blue.length = screen_info.blue_size;
289 imacfb_defined.transp.offset = screen_info.rsvd_pos;
290 imacfb_defined.transp.length = screen_info.rsvd_size;
291
292 printk(KERN_INFO "imacfb: %s: "
293 "size=%d:%d:%d:%d, shift=%d:%d:%d:%d\n",
294 "Truecolor",
295 screen_info.rsvd_size,
296 screen_info.red_size,
297 screen_info.green_size,
298 screen_info.blue_size,
299 screen_info.rsvd_pos,
300 screen_info.red_pos,
301 screen_info.green_pos,
302 screen_info.blue_pos);
303
304 imacfb_fix.ypanstep = 0;
305 imacfb_fix.ywrapstep = 0;
306
307 /* request failure does not faze us, as vgacon probably has this
308 * region already (FIXME) */
309 request_region(0x3c0, 32, "imacfb");
310
311 info->fbops = &imacfb_ops;
312 info->var = imacfb_defined;
313 info->fix = imacfb_fix;
314 info->flags = FBINFO_FLAG_DEFAULT;
315
316 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
317 err = -ENOMEM;
318 goto err_unmap;
319 }
320 if (register_framebuffer(info)<0) {
321 err = -EINVAL;
322 goto err_fb_dealoc;
323 }
324 printk(KERN_INFO "fb%d: %s frame buffer device\n",
325 info->node, info->fix.id);
326 return 0;
327
328err_fb_dealoc:
329 fb_dealloc_cmap(&info->cmap);
330err_unmap:
331 iounmap(info->screen_base);
332 framebuffer_release(info);
333err_release_mem:
334 release_mem_region(imacfb_fix.smem_start, size_total);
335 return err;
336}
337
338static struct platform_driver imacfb_driver = {
339 .probe = imacfb_probe,
340 .driver = {
341 .name = "imacfb",
342 },
343};
344
345static struct platform_device imacfb_device = {
346 .name = "imacfb",
347};
348
349static int __init imacfb_init(void)
350{
351 int ret;
352 char *option = NULL;
353
354 if (!efi_enabled)
355 return -ENODEV;
356 if (!dmi_check_system(dmi_system_table))
357 return -ENODEV;
358 if (model == M_UNKNOWN)
359 return -ENODEV;
360
361 if (fb_get_options("imacfb", &option))
362 return -ENODEV;
363
364 imacfb_setup(option);
365 ret = platform_driver_register(&imacfb_driver);
366
367 if (!ret) {
368 ret = platform_device_register(&imacfb_device);
369 if (ret)
370 platform_driver_unregister(&imacfb_driver);
371 }
372 return ret;
373}
374module_init(imacfb_init);
375
376MODULE_LICENSE("GPL");
diff --git a/drivers/video/intelfb/intelfb.h b/drivers/video/intelfb/intelfb.h
index 3325fbd68ab3..a50bea614804 100644
--- a/drivers/video/intelfb/intelfb.h
+++ b/drivers/video/intelfb/intelfb.h
@@ -12,9 +12,9 @@
12#endif 12#endif
13 13
14/*** Version/name ***/ 14/*** Version/name ***/
15#define INTELFB_VERSION "0.9.5" 15#define INTELFB_VERSION "0.9.6"
16#define INTELFB_MODULE_NAME "intelfb" 16#define INTELFB_MODULE_NAME "intelfb"
17#define SUPPORTED_CHIPSETS "830M/845G/852GM/855GM/865G/915G/915GM/945G/945GM/965G/965GM" 17#define SUPPORTED_CHIPSETS "830M/845G/852GM/855GM/865G/915G/915GM/945G/945GM/945GME/965G/965GM"
18 18
19 19
20/*** Debug/feature defines ***/ 20/*** Debug/feature defines ***/
@@ -58,6 +58,7 @@
58#define PCI_DEVICE_ID_INTEL_915GM 0x2592 58#define PCI_DEVICE_ID_INTEL_915GM 0x2592
59#define PCI_DEVICE_ID_INTEL_945G 0x2772 59#define PCI_DEVICE_ID_INTEL_945G 0x2772
60#define PCI_DEVICE_ID_INTEL_945GM 0x27A2 60#define PCI_DEVICE_ID_INTEL_945GM 0x27A2
61#define PCI_DEVICE_ID_INTEL_945GME 0x27AE
61#define PCI_DEVICE_ID_INTEL_965G 0x29A2 62#define PCI_DEVICE_ID_INTEL_965G 0x29A2
62#define PCI_DEVICE_ID_INTEL_965GM 0x2A02 63#define PCI_DEVICE_ID_INTEL_965GM 0x2A02
63 64
@@ -160,6 +161,7 @@ enum intel_chips {
160 INTEL_915GM, 161 INTEL_915GM,
161 INTEL_945G, 162 INTEL_945G,
162 INTEL_945GM, 163 INTEL_945GM,
164 INTEL_945GME,
163 INTEL_965G, 165 INTEL_965G,
164 INTEL_965GM, 166 INTEL_965GM,
165}; 167};
@@ -363,6 +365,7 @@ struct intelfb_info {
363 ((dinfo)->chipset == INTEL_915GM) || \ 365 ((dinfo)->chipset == INTEL_915GM) || \
364 ((dinfo)->chipset == INTEL_945G) || \ 366 ((dinfo)->chipset == INTEL_945G) || \
365 ((dinfo)->chipset == INTEL_945GM) || \ 367 ((dinfo)->chipset == INTEL_945GM) || \
368 ((dinfo)->chipset == INTEL_945GME) || \
366 ((dinfo)->chipset == INTEL_965G) || \ 369 ((dinfo)->chipset == INTEL_965G) || \
367 ((dinfo)->chipset == INTEL_965GM)) 370 ((dinfo)->chipset == INTEL_965GM))
368 371
diff --git a/drivers/video/intelfb/intelfb_i2c.c b/drivers/video/intelfb/intelfb_i2c.c
index fcf9fadbf572..5d896b81f4e0 100644
--- a/drivers/video/intelfb/intelfb_i2c.c
+++ b/drivers/video/intelfb/intelfb_i2c.c
@@ -171,6 +171,7 @@ void intelfb_create_i2c_busses(struct intelfb_info *dinfo)
171 /* has some LVDS + tv-out */ 171 /* has some LVDS + tv-out */
172 case INTEL_945G: 172 case INTEL_945G:
173 case INTEL_945GM: 173 case INTEL_945GM:
174 case INTEL_945GME:
174 case INTEL_965G: 175 case INTEL_965G:
175 case INTEL_965GM: 176 case INTEL_965GM:
176 /* SDVO ports have a single control bus - 2 devices */ 177 /* SDVO ports have a single control bus - 2 devices */
diff --git a/drivers/video/intelfb/intelfbdrv.c b/drivers/video/intelfb/intelfbdrv.c
index e44303f9bc52..a09e23649357 100644
--- a/drivers/video/intelfb/intelfbdrv.c
+++ b/drivers/video/intelfb/intelfbdrv.c
@@ -2,7 +2,7 @@
2 * intelfb 2 * intelfb
3 * 3 *
4 * Linux framebuffer driver for Intel(R) 830M/845G/852GM/855GM/865G/915G/915GM/ 4 * Linux framebuffer driver for Intel(R) 830M/845G/852GM/855GM/865G/915G/915GM/
5 * 945G/945GM/965G/965GM integrated graphics chips. 5 * 945G/945GM/945GME/965G/965GM integrated graphics chips.
6 * 6 *
7 * Copyright © 2002, 2003 David Dawes <dawes@xfree86.org> 7 * Copyright © 2002, 2003 David Dawes <dawes@xfree86.org>
8 * 2004 Sylvain Meyer 8 * 2004 Sylvain Meyer
@@ -102,6 +102,9 @@
102 * 102 *
103 * 04/2008 - Version 0.9.5 103 * 04/2008 - Version 0.9.5
104 * Add support for 965G/965GM. (Maik Broemme <mbroemme@plusserver.de>) 104 * Add support for 965G/965GM. (Maik Broemme <mbroemme@plusserver.de>)
105 *
106 * 08/2008 - Version 0.9.6
107 * Add support for 945GME. (Phil Endecott <spam_from_intelfb@chezphil.org>)
105 */ 108 */
106 109
107#include <linux/module.h> 110#include <linux/module.h>
@@ -183,6 +186,7 @@ static struct pci_device_id intelfb_pci_table[] __devinitdata = {
183 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_915GM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_915GM }, 186 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_915GM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_915GM },
184 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_945G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_945G }, 187 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_945G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_945G },
185 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_945GM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_945GM }, 188 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_945GM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_945GM },
189 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_945GME, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_945GME },
186 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_965G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_965G }, 190 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_965G, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_965G },
187 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_965GM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_965GM }, 191 { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_965GM, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, INTELFB_CLASS_MASK, INTEL_965GM },
188 { 0, } 192 { 0, }
@@ -555,6 +559,7 @@ static int __devinit intelfb_pci_register(struct pci_dev *pdev,
555 (ent->device == PCI_DEVICE_ID_INTEL_915GM) || 559 (ent->device == PCI_DEVICE_ID_INTEL_915GM) ||
556 (ent->device == PCI_DEVICE_ID_INTEL_945G) || 560 (ent->device == PCI_DEVICE_ID_INTEL_945G) ||
557 (ent->device == PCI_DEVICE_ID_INTEL_945GM) || 561 (ent->device == PCI_DEVICE_ID_INTEL_945GM) ||
562 (ent->device == PCI_DEVICE_ID_INTEL_945GME) ||
558 (ent->device == PCI_DEVICE_ID_INTEL_965G) || 563 (ent->device == PCI_DEVICE_ID_INTEL_965G) ||
559 (ent->device == PCI_DEVICE_ID_INTEL_965GM)) { 564 (ent->device == PCI_DEVICE_ID_INTEL_965GM)) {
560 565
diff --git a/drivers/video/intelfb/intelfbhw.c b/drivers/video/intelfb/intelfbhw.c
index 8e6d6a4db0ad..8b26b27c2db6 100644
--- a/drivers/video/intelfb/intelfbhw.c
+++ b/drivers/video/intelfb/intelfbhw.c
@@ -143,6 +143,12 @@ int intelfbhw_get_chipset(struct pci_dev *pdev, struct intelfb_info *dinfo)
143 dinfo->mobile = 1; 143 dinfo->mobile = 1;
144 dinfo->pll_index = PLLS_I9xx; 144 dinfo->pll_index = PLLS_I9xx;
145 return 0; 145 return 0;
146 case PCI_DEVICE_ID_INTEL_945GME:
147 dinfo->name = "Intel(R) 945GME";
148 dinfo->chipset = INTEL_945GME;
149 dinfo->mobile = 1;
150 dinfo->pll_index = PLLS_I9xx;
151 return 0;
146 case PCI_DEVICE_ID_INTEL_965G: 152 case PCI_DEVICE_ID_INTEL_965G:
147 dinfo->name = "Intel(R) 965G"; 153 dinfo->name = "Intel(R) 965G";
148 dinfo->chipset = INTEL_965G; 154 dinfo->chipset = INTEL_965G;
@@ -186,6 +192,7 @@ int intelfbhw_get_memory(struct pci_dev *pdev, int *aperture_size,
186 case PCI_DEVICE_ID_INTEL_915GM: 192 case PCI_DEVICE_ID_INTEL_915GM:
187 case PCI_DEVICE_ID_INTEL_945G: 193 case PCI_DEVICE_ID_INTEL_945G:
188 case PCI_DEVICE_ID_INTEL_945GM: 194 case PCI_DEVICE_ID_INTEL_945GM:
195 case PCI_DEVICE_ID_INTEL_945GME:
189 case PCI_DEVICE_ID_INTEL_965G: 196 case PCI_DEVICE_ID_INTEL_965G:
190 case PCI_DEVICE_ID_INTEL_965GM: 197 case PCI_DEVICE_ID_INTEL_965GM:
191 /* 915, 945 and 965 chipsets support a 256MB aperture. 198 /* 915, 945 and 965 chipsets support a 256MB aperture.
diff --git a/drivers/video/matrox/matroxfb_base.c b/drivers/video/matrox/matroxfb_base.c
index c02136202792..8e7a275df50c 100644
--- a/drivers/video/matrox/matroxfb_base.c
+++ b/drivers/video/matrox/matroxfb_base.c
@@ -1453,6 +1453,13 @@ static struct board {
1453 MGA_G100, 1453 MGA_G100,
1454 &vbG100, 1454 &vbG100,
1455 "MGA-G100 (AGP)"}, 1455 "MGA-G100 (AGP)"},
1456 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200EV_PCI, 0xFF,
1457 0, 0,
1458 DEVF_G200,
1459 230000,
1460 MGA_G200,
1461 &vbG200,
1462 "MGA-G200eV (PCI)"},
1456 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_PCI, 0xFF, 1463 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_PCI, 0xFF,
1457 0, 0, 1464 0, 0,
1458 DEVF_G200, 1465 DEVF_G200,
@@ -2118,6 +2125,8 @@ static struct pci_device_id matroxfb_devices[] = {
2118 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 2125 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2119 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G100_AGP, 2126 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G100_AGP,
2120 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 2127 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2128 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200EV_PCI,
2129 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2121 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_PCI, 2130 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_PCI,
2122 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, 2131 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
2123 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP, 2132 {PCI_VENDOR_ID_MATROX, PCI_DEVICE_ID_MATROX_G200_AGP,
diff --git a/drivers/video/metronomefb.c b/drivers/video/metronomefb.c
index afeed0611e3e..df1f757a6161 100644
--- a/drivers/video/metronomefb.c
+++ b/drivers/video/metronomefb.c
@@ -188,7 +188,7 @@ static int __devinit load_waveform(u8 *mem, size_t size, int m, int t,
188 epd_frame_table[par->dt].wfm_size = user_wfm_size; 188 epd_frame_table[par->dt].wfm_size = user_wfm_size;
189 189
190 if (size != epd_frame_table[par->dt].wfm_size) { 190 if (size != epd_frame_table[par->dt].wfm_size) {
191 dev_err(dev, "Error: unexpected size %d != %d\n", size, 191 dev_err(dev, "Error: unexpected size %Zd != %d\n", size,
192 epd_frame_table[par->dt].wfm_size); 192 epd_frame_table[par->dt].wfm_size);
193 return -EINVAL; 193 return -EINVAL;
194 } 194 }
diff --git a/drivers/video/neofb.c b/drivers/video/neofb.c
index 25172b2a2a94..bfb802d26d5a 100644
--- a/drivers/video/neofb.c
+++ b/drivers/video/neofb.c
@@ -426,11 +426,11 @@ static void vgaHWProtect(int on)
426{ 426{
427 unsigned char tmp; 427 unsigned char tmp;
428 428
429 tmp = vga_rseq(NULL, 0x01);
429 if (on) { 430 if (on) {
430 /* 431 /*
431 * Turn off screen and disable sequencer. 432 * Turn off screen and disable sequencer.
432 */ 433 */
433 tmp = vga_rseq(NULL, 0x01);
434 vga_wseq(NULL, 0x00, 0x01); /* Synchronous Reset */ 434 vga_wseq(NULL, 0x00, 0x01); /* Synchronous Reset */
435 vga_wseq(NULL, 0x01, tmp | 0x20); /* disable the display */ 435 vga_wseq(NULL, 0x01, tmp | 0x20); /* disable the display */
436 436
@@ -439,7 +439,6 @@ static void vgaHWProtect(int on)
439 /* 439 /*
440 * Reenable sequencer, then turn on screen. 440 * Reenable sequencer, then turn on screen.
441 */ 441 */
442 tmp = vga_rseq(NULL, 0x01);
443 vga_wseq(NULL, 0x01, tmp & ~0x20); /* reenable display */ 442 vga_wseq(NULL, 0x01, tmp & ~0x20); /* reenable display */
444 vga_wseq(NULL, 0x00, 0x03); /* clear synchronousreset */ 443 vga_wseq(NULL, 0x00, 0x03); /* clear synchronousreset */
445 444
@@ -558,14 +557,12 @@ neofb_open(struct fb_info *info, int user)
558{ 557{
559 struct neofb_par *par = info->par; 558 struct neofb_par *par = info->par;
560 559
561 mutex_lock(&par->open_lock);
562 if (!par->ref_count) { 560 if (!par->ref_count) {
563 memset(&par->state, 0, sizeof(struct vgastate)); 561 memset(&par->state, 0, sizeof(struct vgastate));
564 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS; 562 par->state.flags = VGA_SAVE_MODE | VGA_SAVE_FONTS;
565 save_vga(&par->state); 563 save_vga(&par->state);
566 } 564 }
567 par->ref_count++; 565 par->ref_count++;
568 mutex_unlock(&par->open_lock);
569 566
570 return 0; 567 return 0;
571} 568}
@@ -575,16 +572,13 @@ neofb_release(struct fb_info *info, int user)
575{ 572{
576 struct neofb_par *par = info->par; 573 struct neofb_par *par = info->par;
577 574
578 mutex_lock(&par->open_lock); 575 if (!par->ref_count)
579 if (!par->ref_count) {
580 mutex_unlock(&par->open_lock);
581 return -EINVAL; 576 return -EINVAL;
582 } 577
583 if (par->ref_count == 1) { 578 if (par->ref_count == 1) {
584 restore_vga(&par->state); 579 restore_vga(&par->state);
585 } 580 }
586 par->ref_count--; 581 par->ref_count--;
587 mutex_unlock(&par->open_lock);
588 582
589 return 0; 583 return 0;
590} 584}
@@ -648,10 +642,10 @@ neofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
648 var->blue.msb_right = 0; 642 var->blue.msb_right = 0;
649 var->transp.msb_right = 0; 643 var->transp.msb_right = 0;
650 644
645 var->transp.offset = 0;
646 var->transp.length = 0;
651 switch (var->bits_per_pixel) { 647 switch (var->bits_per_pixel) {
652 case 8: /* PSEUDOCOLOUR, 256 */ 648 case 8: /* PSEUDOCOLOUR, 256 */
653 var->transp.offset = 0;
654 var->transp.length = 0;
655 var->red.offset = 0; 649 var->red.offset = 0;
656 var->red.length = 8; 650 var->red.length = 8;
657 var->green.offset = 0; 651 var->green.offset = 0;
@@ -661,8 +655,6 @@ neofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
661 break; 655 break;
662 656
663 case 16: /* DIRECTCOLOUR, 64k */ 657 case 16: /* DIRECTCOLOUR, 64k */
664 var->transp.offset = 0;
665 var->transp.length = 0;
666 var->red.offset = 11; 658 var->red.offset = 11;
667 var->red.length = 5; 659 var->red.length = 5;
668 var->green.offset = 5; 660 var->green.offset = 5;
@@ -672,8 +664,6 @@ neofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
672 break; 664 break;
673 665
674 case 24: /* TRUECOLOUR, 16m */ 666 case 24: /* TRUECOLOUR, 16m */
675 var->transp.offset = 0;
676 var->transp.length = 0;
677 var->red.offset = 16; 667 var->red.offset = 16;
678 var->red.length = 8; 668 var->red.length = 8;
679 var->green.offset = 8; 669 var->green.offset = 8;
@@ -704,8 +694,6 @@ neofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
704 if (vramlen > 4 * 1024 * 1024) 694 if (vramlen > 4 * 1024 * 1024)
705 vramlen = 4 * 1024 * 1024; 695 vramlen = 4 * 1024 * 1024;
706 696
707 if (var->yres_virtual < var->yres)
708 var->yres_virtual = var->yres;
709 if (var->xres_virtual < var->xres) 697 if (var->xres_virtual < var->xres)
710 var->xres_virtual = var->xres; 698 var->xres_virtual = var->xres;
711 699
@@ -722,8 +710,6 @@ neofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
722 if it was possible. We should return -EINVAL, but I disagree */ 710 if it was possible. We should return -EINVAL, but I disagree */
723 if (var->yres_virtual < var->yres) 711 if (var->yres_virtual < var->yres)
724 var->yres = var->yres_virtual; 712 var->yres = var->yres_virtual;
725 if (var->xres_virtual < var->xres)
726 var->xres = var->xres_virtual;
727 if (var->xoffset + var->xres > var->xres_virtual) 713 if (var->xoffset + var->xres > var->xres_virtual)
728 var->xoffset = var->xres_virtual - var->xres; 714 var->xoffset = var->xres_virtual - var->xres;
729 if (var->yoffset + var->yres > var->yres_virtual) 715 if (var->yoffset + var->yres > var->yres_virtual)
@@ -1186,8 +1172,11 @@ static int neofb_set_par(struct fb_info *info)
1186 return 0; 1172 return 0;
1187} 1173}
1188 1174
1189static void neofb_update_start(struct fb_info *info, 1175/*
1190 struct fb_var_screeninfo *var) 1176 * Pan or Wrap the Display
1177 */
1178static int neofb_pan_display(struct fb_var_screeninfo *var,
1179 struct fb_info *info)
1191{ 1180{
1192 struct neofb_par *par = info->par; 1181 struct neofb_par *par = info->par;
1193 struct vgastate *state = &par->state; 1182 struct vgastate *state = &par->state;
@@ -1216,35 +1205,7 @@ static void neofb_update_start(struct fb_info *info,
1216 vga_wgfx(state->vgabase, 0x0E, (((Base >> 16) & 0x0f) | (oldExtCRTDispAddr & 0xf0))); 1205 vga_wgfx(state->vgabase, 0x0E, (((Base >> 16) & 0x0f) | (oldExtCRTDispAddr & 0xf0)));
1217 1206
1218 neoLock(state); 1207 neoLock(state);
1219}
1220
1221/*
1222 * Pan or Wrap the Display
1223 */
1224static int neofb_pan_display(struct fb_var_screeninfo *var,
1225 struct fb_info *info)
1226{
1227 u_int y_bottom;
1228
1229 y_bottom = var->yoffset;
1230
1231 if (!(var->vmode & FB_VMODE_YWRAP))
1232 y_bottom += var->yres;
1233 1208
1234 if (var->xoffset > (var->xres_virtual - var->xres))
1235 return -EINVAL;
1236 if (y_bottom > info->var.yres_virtual)
1237 return -EINVAL;
1238
1239 neofb_update_start(info, var);
1240
1241 info->var.xoffset = var->xoffset;
1242 info->var.yoffset = var->yoffset;
1243
1244 if (var->vmode & FB_VMODE_YWRAP)
1245 info->var.vmode |= FB_VMODE_YWRAP;
1246 else
1247 info->var.vmode &= ~FB_VMODE_YWRAP;
1248 return 0; 1209 return 0;
1249} 1210}
1250 1211
@@ -1992,7 +1953,6 @@ static struct fb_info *__devinit neo_alloc_fb_info(struct pci_dev *dev, const st
1992 1953
1993 info->fix.accel = id->driver_data; 1954 info->fix.accel = id->driver_data;
1994 1955
1995 mutex_init(&par->open_lock);
1996 par->pci_burst = !nopciburst; 1956 par->pci_burst = !nopciburst;
1997 par->lcd_stretch = !nostretch; 1957 par->lcd_stretch = !nostretch;
1998 par->libretto = libretto; 1958 par->libretto = libretto;
diff --git a/drivers/video/omap/dispc.c b/drivers/video/omap/dispc.c
index 6efcf89e7fbe..dfb72f5e4c96 100644
--- a/drivers/video/omap/dispc.c
+++ b/drivers/video/omap/dispc.c
@@ -156,7 +156,7 @@ struct resmap {
156}; 156};
157 157
158static struct { 158static struct {
159 u32 base; 159 void __iomem *base;
160 160
161 struct omapfb_mem_desc mem_desc; 161 struct omapfb_mem_desc mem_desc;
162 struct resmap *res_map[DISPC_MEMTYPE_NUM]; 162 struct resmap *res_map[DISPC_MEMTYPE_NUM];
@@ -212,9 +212,9 @@ static void enable_rfbi_mode(int enable)
212 dispc_write_reg(DISPC_CONTROL, l); 212 dispc_write_reg(DISPC_CONTROL, l);
213 213
214 /* Set bypass mode in RFBI module */ 214 /* Set bypass mode in RFBI module */
215 l = __raw_readl(io_p2v(RFBI_CONTROL)); 215 l = __raw_readl(IO_ADDRESS(RFBI_CONTROL));
216 l |= enable ? 0 : (1 << 1); 216 l |= enable ? 0 : (1 << 1);
217 __raw_writel(l, io_p2v(RFBI_CONTROL)); 217 __raw_writel(l, IO_ADDRESS(RFBI_CONTROL));
218} 218}
219 219
220static void set_lcd_data_lines(int data_lines) 220static void set_lcd_data_lines(int data_lines)
@@ -1349,14 +1349,19 @@ static int omap_dispc_init(struct omapfb_device *fbdev, int ext_mode,
1349 1349
1350 memset(&dispc, 0, sizeof(dispc)); 1350 memset(&dispc, 0, sizeof(dispc));
1351 1351
1352 dispc.base = io_p2v(DISPC_BASE); 1352 dispc.base = ioremap(DISPC_BASE, SZ_1K);
1353 if (!dispc.base) {
1354 dev_err(fbdev->dev, "can't ioremap DISPC\n");
1355 return -ENOMEM;
1356 }
1357
1353 dispc.fbdev = fbdev; 1358 dispc.fbdev = fbdev;
1354 dispc.ext_mode = ext_mode; 1359 dispc.ext_mode = ext_mode;
1355 1360
1356 init_completion(&dispc.frame_done); 1361 init_completion(&dispc.frame_done);
1357 1362
1358 if ((r = get_dss_clocks()) < 0) 1363 if ((r = get_dss_clocks()) < 0)
1359 return r; 1364 goto fail0;
1360 1365
1361 enable_interface_clocks(1); 1366 enable_interface_clocks(1);
1362 enable_lcd_clocks(1); 1367 enable_lcd_clocks(1);
@@ -1414,7 +1419,7 @@ static int omap_dispc_init(struct omapfb_device *fbdev, int ext_mode,
1414 } 1419 }
1415 1420
1416 /* L3 firewall setting: enable access to OCM RAM */ 1421 /* L3 firewall setting: enable access to OCM RAM */
1417 __raw_writel(0x402000b0, io_p2v(0x680050a0)); 1422 __raw_writel(0x402000b0, IO_ADDRESS(0x680050a0));
1418 1423
1419 if ((r = alloc_palette_ram()) < 0) 1424 if ((r = alloc_palette_ram()) < 0)
1420 goto fail2; 1425 goto fail2;
@@ -1464,7 +1469,8 @@ fail1:
1464 enable_lcd_clocks(0); 1469 enable_lcd_clocks(0);
1465 enable_interface_clocks(0); 1470 enable_interface_clocks(0);
1466 put_dss_clocks(); 1471 put_dss_clocks();
1467 1472fail0:
1473 iounmap(dispc.base);
1468 return r; 1474 return r;
1469} 1475}
1470 1476
@@ -1481,6 +1487,7 @@ static void omap_dispc_cleanup(void)
1481 free_irq(INT_24XX_DSS_IRQ, dispc.fbdev); 1487 free_irq(INT_24XX_DSS_IRQ, dispc.fbdev);
1482 enable_interface_clocks(0); 1488 enable_interface_clocks(0);
1483 put_dss_clocks(); 1489 put_dss_clocks();
1490 iounmap(dispc.base);
1484} 1491}
1485 1492
1486const struct lcd_ctrl omap2_int_ctrl = { 1493const struct lcd_ctrl omap2_int_ctrl = {
diff --git a/drivers/video/omap/dispc.h b/drivers/video/omap/dispc.h
index eb1512b56ce8..ef720a78f6d5 100644
--- a/drivers/video/omap/dispc.h
+++ b/drivers/video/omap/dispc.h
@@ -40,4 +40,6 @@ extern void omap_dispc_enable_digit_out(int enable);
40extern int omap_dispc_request_irq(void (*callback)(void *data), void *data); 40extern int omap_dispc_request_irq(void (*callback)(void *data), void *data);
41extern void omap_dispc_free_irq(void); 41extern void omap_dispc_free_irq(void);
42 42
43extern const struct lcd_ctrl omap2_int_ctrl;
44
43#endif 45#endif
diff --git a/drivers/video/omap/lcd_h4.c b/drivers/video/omap/lcd_h4.c
index 88c19d424ef7..6ff56430341b 100644
--- a/drivers/video/omap/lcd_h4.c
+++ b/drivers/video/omap/lcd_h4.c
@@ -47,7 +47,7 @@ static unsigned long h4_panel_get_caps(struct lcd_panel *panel)
47 return 0; 47 return 0;
48} 48}
49 49
50struct lcd_panel h4_panel = { 50static struct lcd_panel h4_panel = {
51 .name = "h4", 51 .name = "h4",
52 .config = OMAP_LCDC_PANEL_TFT, 52 .config = OMAP_LCDC_PANEL_TFT,
53 53
@@ -91,7 +91,7 @@ static int h4_panel_resume(struct platform_device *pdev)
91 return 0; 91 return 0;
92} 92}
93 93
94struct platform_driver h4_panel_driver = { 94static struct platform_driver h4_panel_driver = {
95 .probe = h4_panel_probe, 95 .probe = h4_panel_probe,
96 .remove = h4_panel_remove, 96 .remove = h4_panel_remove,
97 .suspend = h4_panel_suspend, 97 .suspend = h4_panel_suspend,
diff --git a/drivers/video/omap/lcd_inn1610.c b/drivers/video/omap/lcd_inn1610.c
index 6a42c6a0cd99..4c4f7ee6d733 100644
--- a/drivers/video/omap/lcd_inn1610.c
+++ b/drivers/video/omap/lcd_inn1610.c
@@ -32,43 +32,43 @@ static int innovator1610_panel_init(struct lcd_panel *panel,
32{ 32{
33 int r = 0; 33 int r = 0;
34 34
35 if (omap_request_gpio(14)) { 35 if (gpio_request(14, "lcd_en0")) {
36 pr_err(MODULE_NAME ": can't request GPIO 14\n"); 36 pr_err(MODULE_NAME ": can't request GPIO 14\n");
37 r = -1; 37 r = -1;
38 goto exit; 38 goto exit;
39 } 39 }
40 if (omap_request_gpio(15)) { 40 if (gpio_request(15, "lcd_en1")) {
41 pr_err(MODULE_NAME ": can't request GPIO 15\n"); 41 pr_err(MODULE_NAME ": can't request GPIO 15\n");
42 omap_free_gpio(14); 42 gpio_free(14);
43 r = -1; 43 r = -1;
44 goto exit; 44 goto exit;
45 } 45 }
46 /* configure GPIO(14, 15) as outputs */ 46 /* configure GPIO(14, 15) as outputs */
47 omap_set_gpio_direction(14, 0); 47 gpio_direction_output(14, 0);
48 omap_set_gpio_direction(15, 0); 48 gpio_direction_output(15, 0);
49exit: 49exit:
50 return r; 50 return r;
51} 51}
52 52
53static void innovator1610_panel_cleanup(struct lcd_panel *panel) 53static void innovator1610_panel_cleanup(struct lcd_panel *panel)
54{ 54{
55 omap_free_gpio(15); 55 gpio_free(15);
56 omap_free_gpio(14); 56 gpio_free(14);
57} 57}
58 58
59static int innovator1610_panel_enable(struct lcd_panel *panel) 59static int innovator1610_panel_enable(struct lcd_panel *panel)
60{ 60{
61 /* set GPIO14 and GPIO15 high */ 61 /* set GPIO14 and GPIO15 high */
62 omap_set_gpio_dataout(14, 1); 62 gpio_set_value(14, 1);
63 omap_set_gpio_dataout(15, 1); 63 gpio_set_value(15, 1);
64 return 0; 64 return 0;
65} 65}
66 66
67static void innovator1610_panel_disable(struct lcd_panel *panel) 67static void innovator1610_panel_disable(struct lcd_panel *panel)
68{ 68{
69 /* set GPIO13, GPIO14 and GPIO15 low */ 69 /* set GPIO13, GPIO14 and GPIO15 low */
70 omap_set_gpio_dataout(14, 0); 70 gpio_set_value(14, 0);
71 omap_set_gpio_dataout(15, 0); 71 gpio_set_value(15, 0);
72} 72}
73 73
74static unsigned long innovator1610_panel_get_caps(struct lcd_panel *panel) 74static unsigned long innovator1610_panel_get_caps(struct lcd_panel *panel)
diff --git a/drivers/video/omap/lcd_osk.c b/drivers/video/omap/lcd_osk.c
index a4a725f427a4..379c96d36da5 100644
--- a/drivers/video/omap/lcd_osk.c
+++ b/drivers/video/omap/lcd_osk.c
@@ -29,6 +29,7 @@
29 29
30static int osk_panel_init(struct lcd_panel *panel, struct omapfb_device *fbdev) 30static int osk_panel_init(struct lcd_panel *panel, struct omapfb_device *fbdev)
31{ 31{
32 /* gpio2 was allocated in board init */
32 return 0; 33 return 0;
33} 34}
34 35
@@ -47,11 +48,8 @@ static int osk_panel_enable(struct lcd_panel *panel)
47 /* Set PWL level */ 48 /* Set PWL level */
48 omap_writeb(0xFF, OMAP_PWL_ENABLE); 49 omap_writeb(0xFF, OMAP_PWL_ENABLE);
49 50
50 /* configure GPIO2 as output */ 51 /* set GPIO2 high (lcd power enabled) */
51 omap_set_gpio_direction(2, 0); 52 gpio_set_value(2, 1);
52
53 /* set GPIO2 high */
54 omap_set_gpio_dataout(2, 1);
55 53
56 return 0; 54 return 0;
57} 55}
@@ -65,7 +63,7 @@ static void osk_panel_disable(struct lcd_panel *panel)
65 omap_writeb(0x00, OMAP_PWL_CLK_ENABLE); 63 omap_writeb(0x00, OMAP_PWL_CLK_ENABLE);
66 64
67 /* set GPIO2 low */ 65 /* set GPIO2 low */
68 omap_set_gpio_dataout(2, 0); 66 gpio_set_value(2, 0);
69} 67}
70 68
71static unsigned long osk_panel_get_caps(struct lcd_panel *panel) 69static unsigned long osk_panel_get_caps(struct lcd_panel *panel)
diff --git a/drivers/video/omap/lcd_sx1.c b/drivers/video/omap/lcd_sx1.c
index caa6a896cb8b..e55de201b8ff 100644
--- a/drivers/video/omap/lcd_sx1.c
+++ b/drivers/video/omap/lcd_sx1.c
@@ -81,21 +81,21 @@ static void epson_sendbyte(int flag, unsigned char byte)
81 int i, shifter = 0x80; 81 int i, shifter = 0x80;
82 82
83 if (!flag) 83 if (!flag)
84 omap_set_gpio_dataout(_A_LCD_SSC_A0, 0); 84 gpio_set_value(_A_LCD_SSC_A0, 0);
85 mdelay(2); 85 mdelay(2);
86 omap_set_gpio_dataout(A_LCD_SSC_RD, 1); 86 gpio_set_value(A_LCD_SSC_RD, 1);
87 87
88 omap_set_gpio_dataout(A_LCD_SSC_SD, flag); 88 gpio_set_value(A_LCD_SSC_SD, flag);
89 89
90 OMAP_MCBSP_WRITE(OMAP1510_MCBSP3_BASE, PCR0, 0x2200); 90 OMAP_MCBSP_WRITE(OMAP1510_MCBSP3_BASE, PCR0, 0x2200);
91 OMAP_MCBSP_WRITE(OMAP1510_MCBSP3_BASE, PCR0, 0x2202); 91 OMAP_MCBSP_WRITE(OMAP1510_MCBSP3_BASE, PCR0, 0x2202);
92 for (i = 0; i < 8; i++) { 92 for (i = 0; i < 8; i++) {
93 OMAP_MCBSP_WRITE(OMAP1510_MCBSP3_BASE, PCR0, 0x2200); 93 OMAP_MCBSP_WRITE(OMAP1510_MCBSP3_BASE, PCR0, 0x2200);
94 omap_set_gpio_dataout(A_LCD_SSC_SD, shifter & byte); 94 gpio_set_value(A_LCD_SSC_SD, shifter & byte);
95 OMAP_MCBSP_WRITE(OMAP1510_MCBSP3_BASE, PCR0, 0x2202); 95 OMAP_MCBSP_WRITE(OMAP1510_MCBSP3_BASE, PCR0, 0x2202);
96 shifter >>= 1; 96 shifter >>= 1;
97 } 97 }
98 omap_set_gpio_dataout(_A_LCD_SSC_A0, 1); 98 gpio_set_value(_A_LCD_SSC_A0, 1);
99} 99}
100 100
101static void init_system(void) 101static void init_system(void)
@@ -107,25 +107,18 @@ static void init_system(void)
107static void setup_GPIO(void) 107static void setup_GPIO(void)
108{ 108{
109 /* new wave */ 109 /* new wave */
110 omap_request_gpio(A_LCD_SSC_RD); 110 gpio_request(A_LCD_SSC_RD, "lcd_ssc_rd");
111 omap_request_gpio(A_LCD_SSC_SD); 111 gpio_request(A_LCD_SSC_SD, "lcd_ssc_sd");
112 omap_request_gpio(_A_LCD_RESET); 112 gpio_request(_A_LCD_RESET, "lcd_reset");
113 omap_request_gpio(_A_LCD_SSC_CS); 113 gpio_request(_A_LCD_SSC_CS, "lcd_ssc_cs");
114 omap_request_gpio(_A_LCD_SSC_A0); 114 gpio_request(_A_LCD_SSC_A0, "lcd_ssc_a0");
115 115
116 /* set all GPIOs to output */ 116 /* set GPIOs to output, with initial data */
117 omap_set_gpio_direction(A_LCD_SSC_RD, 0); 117 gpio_direction_output(A_LCD_SSC_RD, 1);
118 omap_set_gpio_direction(A_LCD_SSC_SD, 0); 118 gpio_direction_output(A_LCD_SSC_SD, 0);
119 omap_set_gpio_direction(_A_LCD_RESET, 0); 119 gpio_direction_output(_A_LCD_RESET, 0);
120 omap_set_gpio_direction(_A_LCD_SSC_CS, 0); 120 gpio_direction_output(_A_LCD_SSC_CS, 1);
121 omap_set_gpio_direction(_A_LCD_SSC_A0, 0); 121 gpio_direction_output(_A_LCD_SSC_A0, 1);
122
123 /* set GPIO data */
124 omap_set_gpio_dataout(A_LCD_SSC_RD, 1);
125 omap_set_gpio_dataout(A_LCD_SSC_SD, 0);
126 omap_set_gpio_dataout(_A_LCD_RESET, 0);
127 omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
128 omap_set_gpio_dataout(_A_LCD_SSC_A0, 1);
129} 122}
130 123
131static void display_init(void) 124static void display_init(void)
@@ -139,61 +132,61 @@ static void display_init(void)
139 mdelay(2); 132 mdelay(2);
140 133
141 /* reset LCD */ 134 /* reset LCD */
142 omap_set_gpio_dataout(A_LCD_SSC_SD, 1); 135 gpio_set_value(A_LCD_SSC_SD, 1);
143 epson_sendbyte(0, 0x25); 136 epson_sendbyte(0, 0x25);
144 137
145 omap_set_gpio_dataout(_A_LCD_RESET, 0); 138 gpio_set_value(_A_LCD_RESET, 0);
146 mdelay(10); 139 mdelay(10);
147 omap_set_gpio_dataout(_A_LCD_RESET, 1); 140 gpio_set_value(_A_LCD_RESET, 1);
148 141
149 omap_set_gpio_dataout(_A_LCD_SSC_CS, 1); 142 gpio_set_value(_A_LCD_SSC_CS, 1);
150 mdelay(2); 143 mdelay(2);
151 omap_set_gpio_dataout(_A_LCD_SSC_CS, 0); 144 gpio_set_value(_A_LCD_SSC_CS, 0);
152 145
153 /* init LCD, phase 1 */ 146 /* init LCD, phase 1 */
154 epson_sendbyte(0, 0xCA); 147 epson_sendbyte(0, 0xCA);
155 for (i = 0; i < 10; i++) 148 for (i = 0; i < 10; i++)
156 epson_sendbyte(1, INIT_1[i]); 149 epson_sendbyte(1, INIT_1[i]);
157 omap_set_gpio_dataout(_A_LCD_SSC_CS, 1); 150 gpio_set_value(_A_LCD_SSC_CS, 1);
158 omap_set_gpio_dataout(_A_LCD_SSC_CS, 0); 151 gpio_set_value(_A_LCD_SSC_CS, 0);
159 152
160 /* init LCD phase 2 */ 153 /* init LCD phase 2 */
161 epson_sendbyte(0, 0xCB); 154 epson_sendbyte(0, 0xCB);
162 for (i = 0; i < 125; i++) 155 for (i = 0; i < 125; i++)
163 epson_sendbyte(1, INIT_2[i]); 156 epson_sendbyte(1, INIT_2[i]);
164 omap_set_gpio_dataout(_A_LCD_SSC_CS, 1); 157 gpio_set_value(_A_LCD_SSC_CS, 1);
165 omap_set_gpio_dataout(_A_LCD_SSC_CS, 0); 158 gpio_set_value(_A_LCD_SSC_CS, 0);
166 159
167 /* init LCD phase 2a */ 160 /* init LCD phase 2a */
168 epson_sendbyte(0, 0xCC); 161 epson_sendbyte(0, 0xCC);
169 for (i = 0; i < 14; i++) 162 for (i = 0; i < 14; i++)
170 epson_sendbyte(1, INIT_3[i]); 163 epson_sendbyte(1, INIT_3[i]);
171 omap_set_gpio_dataout(_A_LCD_SSC_CS, 1); 164 gpio_set_value(_A_LCD_SSC_CS, 1);
172 omap_set_gpio_dataout(_A_LCD_SSC_CS, 0); 165 gpio_set_value(_A_LCD_SSC_CS, 0);
173 166
174 /* init LCD phase 3 */ 167 /* init LCD phase 3 */
175 epson_sendbyte(0, 0xBC); 168 epson_sendbyte(0, 0xBC);
176 epson_sendbyte(1, 0x08); 169 epson_sendbyte(1, 0x08);
177 omap_set_gpio_dataout(_A_LCD_SSC_CS, 1); 170 gpio_set_value(_A_LCD_SSC_CS, 1);
178 omap_set_gpio_dataout(_A_LCD_SSC_CS, 0); 171 gpio_set_value(_A_LCD_SSC_CS, 0);
179 172
180 /* init LCD phase 4 */ 173 /* init LCD phase 4 */
181 epson_sendbyte(0, 0x07); 174 epson_sendbyte(0, 0x07);
182 epson_sendbyte(1, 0x05); 175 epson_sendbyte(1, 0x05);
183 omap_set_gpio_dataout(_A_LCD_SSC_CS, 1); 176 gpio_set_value(_A_LCD_SSC_CS, 1);
184 omap_set_gpio_dataout(_A_LCD_SSC_CS, 0); 177 gpio_set_value(_A_LCD_SSC_CS, 0);
185 178
186 /* init LCD phase 5 */ 179 /* init LCD phase 5 */
187 epson_sendbyte(0, 0x94); 180 epson_sendbyte(0, 0x94);
188 omap_set_gpio_dataout(_A_LCD_SSC_CS, 1); 181 gpio_set_value(_A_LCD_SSC_CS, 1);
189 omap_set_gpio_dataout(_A_LCD_SSC_CS, 0); 182 gpio_set_value(_A_LCD_SSC_CS, 0);
190 183
191 /* init LCD phase 6 */ 184 /* init LCD phase 6 */
192 epson_sendbyte(0, 0xC6); 185 epson_sendbyte(0, 0xC6);
193 epson_sendbyte(1, 0x80); 186 epson_sendbyte(1, 0x80);
194 omap_set_gpio_dataout(_A_LCD_SSC_CS, 1); 187 gpio_set_value(_A_LCD_SSC_CS, 1);
195 mdelay(100); /* used to be 1000 */ 188 mdelay(100); /* used to be 1000 */
196 omap_set_gpio_dataout(_A_LCD_SSC_CS, 0); 189 gpio_set_value(_A_LCD_SSC_CS, 0);
197 190
198 /* init LCD phase 7 */ 191 /* init LCD phase 7 */
199 epson_sendbyte(0, 0x16); 192 epson_sendbyte(0, 0x16);
@@ -201,8 +194,8 @@ static void display_init(void)
201 epson_sendbyte(1, 0x00); 194 epson_sendbyte(1, 0x00);
202 epson_sendbyte(1, 0xB1); 195 epson_sendbyte(1, 0xB1);
203 epson_sendbyte(1, 0x00); 196 epson_sendbyte(1, 0x00);
204 omap_set_gpio_dataout(_A_LCD_SSC_CS, 1); 197 gpio_set_value(_A_LCD_SSC_CS, 1);
205 omap_set_gpio_dataout(_A_LCD_SSC_CS, 0); 198 gpio_set_value(_A_LCD_SSC_CS, 0);
206 199
207 /* init LCD phase 8 */ 200 /* init LCD phase 8 */
208 epson_sendbyte(0, 0x76); 201 epson_sendbyte(0, 0x76);
@@ -210,12 +203,12 @@ static void display_init(void)
210 epson_sendbyte(1, 0x00); 203 epson_sendbyte(1, 0x00);
211 epson_sendbyte(1, 0xDB); 204 epson_sendbyte(1, 0xDB);
212 epson_sendbyte(1, 0x00); 205 epson_sendbyte(1, 0x00);
213 omap_set_gpio_dataout(_A_LCD_SSC_CS, 1); 206 gpio_set_value(_A_LCD_SSC_CS, 1);
214 omap_set_gpio_dataout(_A_LCD_SSC_CS, 0); 207 gpio_set_value(_A_LCD_SSC_CS, 0);
215 208
216 /* init LCD phase 9 */ 209 /* init LCD phase 9 */
217 epson_sendbyte(0, 0xAF); 210 epson_sendbyte(0, 0xAF);
218 omap_set_gpio_dataout(_A_LCD_SSC_CS, 1); 211 gpio_set_value(_A_LCD_SSC_CS, 1);
219} 212}
220 213
221static int sx1_panel_init(struct lcd_panel *panel, struct omapfb_device *fbdev) 214static int sx1_panel_init(struct lcd_panel *panel, struct omapfb_device *fbdev)
@@ -231,18 +224,18 @@ static void sx1_panel_disable(struct lcd_panel *panel)
231{ 224{
232 printk(KERN_INFO "SX1: LCD panel disable\n"); 225 printk(KERN_INFO "SX1: LCD panel disable\n");
233 sx1_setmmipower(0); 226 sx1_setmmipower(0);
234 omap_set_gpio_dataout(_A_LCD_SSC_CS, 1); 227 gpio_set_value(_A_LCD_SSC_CS, 1);
235 228
236 epson_sendbyte(0, 0x25); 229 epson_sendbyte(0, 0x25);
237 omap_set_gpio_dataout(_A_LCD_SSC_CS, 0); 230 gpio_set_value(_A_LCD_SSC_CS, 0);
238 231
239 epson_sendbyte(0, 0xAE); 232 epson_sendbyte(0, 0xAE);
240 omap_set_gpio_dataout(_A_LCD_SSC_CS, 1); 233 gpio_set_value(_A_LCD_SSC_CS, 1);
241 mdelay(100); 234 mdelay(100);
242 omap_set_gpio_dataout(_A_LCD_SSC_CS, 0); 235 gpio_set_value(_A_LCD_SSC_CS, 0);
243 236
244 epson_sendbyte(0, 0x95); 237 epson_sendbyte(0, 0x95);
245 omap_set_gpio_dataout(_A_LCD_SSC_CS, 1); 238 gpio_set_value(_A_LCD_SSC_CS, 1);
246} 239}
247 240
248static int sx1_panel_enable(struct lcd_panel *panel) 241static int sx1_panel_enable(struct lcd_panel *panel)
diff --git a/drivers/video/omap/lcdc.c b/drivers/video/omap/lcdc.c
index 83514f066712..6e2ea7518761 100644
--- a/drivers/video/omap/lcdc.c
+++ b/drivers/video/omap/lcdc.c
@@ -34,6 +34,8 @@
34 34
35#include <asm/mach-types.h> 35#include <asm/mach-types.h>
36 36
37#include "lcdc.h"
38
37#define MODULE_NAME "lcdc" 39#define MODULE_NAME "lcdc"
38 40
39#define OMAP_LCDC_BASE 0xfffec000 41#define OMAP_LCDC_BASE 0xfffec000
diff --git a/drivers/video/omap/lcdc.h b/drivers/video/omap/lcdc.h
index adb731e5314a..845222270db3 100644
--- a/drivers/video/omap/lcdc.h
+++ b/drivers/video/omap/lcdc.h
@@ -4,4 +4,6 @@
4int omap_lcdc_set_dma_callback(void (*callback)(void *data), void *data); 4int omap_lcdc_set_dma_callback(void (*callback)(void *data), void *data);
5void omap_lcdc_free_dma_callback(void); 5void omap_lcdc_free_dma_callback(void);
6 6
7extern const struct lcd_ctrl omap1_int_ctrl;
8
7#endif 9#endif
diff --git a/drivers/video/omap/omapfb_main.c b/drivers/video/omap/omapfb_main.c
index 51a138bd113c..5a5e407dc45f 100644
--- a/drivers/video/omap/omapfb_main.c
+++ b/drivers/video/omap/omapfb_main.c
@@ -31,11 +31,14 @@
31#include <mach/dma.h> 31#include <mach/dma.h>
32#include <mach/omapfb.h> 32#include <mach/omapfb.h>
33 33
34#include "lcdc.h"
35#include "dispc.h"
36
34#define MODULE_NAME "omapfb" 37#define MODULE_NAME "omapfb"
35 38
36static unsigned int def_accel; 39static unsigned int def_accel;
37static unsigned long def_vram[OMAPFB_PLANE_NUM]; 40static unsigned long def_vram[OMAPFB_PLANE_NUM];
38static int def_vram_cnt; 41static unsigned int def_vram_cnt;
39static unsigned long def_vxres; 42static unsigned long def_vxres;
40static unsigned long def_vyres; 43static unsigned long def_vyres;
41static unsigned int def_rotate; 44static unsigned int def_rotate;
@@ -84,12 +87,10 @@ static struct caps_table_struct color_caps[] = {
84 * LCD panel 87 * LCD panel
85 * --------------------------------------------------------------------------- 88 * ---------------------------------------------------------------------------
86 */ 89 */
87extern struct lcd_ctrl omap1_int_ctrl;
88extern struct lcd_ctrl omap2_int_ctrl;
89extern struct lcd_ctrl hwa742_ctrl; 90extern struct lcd_ctrl hwa742_ctrl;
90extern struct lcd_ctrl blizzard_ctrl; 91extern struct lcd_ctrl blizzard_ctrl;
91 92
92static struct lcd_ctrl *ctrls[] = { 93static const struct lcd_ctrl *ctrls[] = {
93#ifdef CONFIG_ARCH_OMAP1 94#ifdef CONFIG_ARCH_OMAP1
94 &omap1_int_ctrl, 95 &omap1_int_ctrl,
95#else 96#else
@@ -740,7 +741,7 @@ static int omapfb_update_win(struct fb_info *fbi,
740 int ret; 741 int ret;
741 742
742 omapfb_rqueue_lock(plane->fbdev); 743 omapfb_rqueue_lock(plane->fbdev);
743 ret = omapfb_update_window_async(fbi, win, NULL, 0); 744 ret = omapfb_update_window_async(fbi, win, NULL, NULL);
744 omapfb_rqueue_unlock(plane->fbdev); 745 omapfb_rqueue_unlock(plane->fbdev);
745 746
746 return ret; 747 return ret;
@@ -768,7 +769,7 @@ static int omapfb_update_full_screen(struct fb_info *fbi)
768 win.format = 0; 769 win.format = 0;
769 770
770 omapfb_rqueue_lock(fbdev); 771 omapfb_rqueue_lock(fbdev);
771 r = fbdev->ctrl->update_window(fbi, &win, NULL, 0); 772 r = fbdev->ctrl->update_window(fbi, &win, NULL, NULL);
772 omapfb_rqueue_unlock(fbdev); 773 omapfb_rqueue_unlock(fbdev);
773 774
774 return r; 775 return r;
@@ -1047,7 +1048,7 @@ void omapfb_write_first_pixel(struct omapfb_device *fbdev, u16 pixval)
1047 win.height = 2; 1048 win.height = 2;
1048 win.out_width = 2; 1049 win.out_width = 2;
1049 win.out_height = 2; 1050 win.out_height = 2;
1050 fbdev->ctrl->update_window(fbdev->fb_info[0], &win, NULL, 0); 1051 fbdev->ctrl->update_window(fbdev->fb_info[0], &win, NULL, NULL);
1051 } 1052 }
1052 omapfb_rqueue_unlock(fbdev); 1053 omapfb_rqueue_unlock(fbdev);
1053} 1054}
diff --git a/drivers/video/omap/rfbi.c b/drivers/video/omap/rfbi.c
index 4a6f13d3facf..a13c8dcad2a8 100644
--- a/drivers/video/omap/rfbi.c
+++ b/drivers/video/omap/rfbi.c
@@ -59,7 +59,7 @@
59#define DISPC_CONTROL 0x0040 59#define DISPC_CONTROL 0x0040
60 60
61static struct { 61static struct {
62 u32 base; 62 void __iomem *base;
63 void (*lcdc_callback)(void *data); 63 void (*lcdc_callback)(void *data);
64 void *lcdc_callback_data; 64 void *lcdc_callback_data;
65 unsigned long l4_khz; 65 unsigned long l4_khz;
@@ -518,7 +518,11 @@ static int rfbi_init(struct omapfb_device *fbdev)
518 int r; 518 int r;
519 519
520 rfbi.fbdev = fbdev; 520 rfbi.fbdev = fbdev;
521 rfbi.base = io_p2v(RFBI_BASE); 521 rfbi.base = ioremap(RFBI_BASE, SZ_1K);
522 if (!rfbi.base) {
523 dev_err(fbdev->dev, "can't ioremap RFBI\n");
524 return -ENOMEM;
525 }
522 526
523 if ((r = rfbi_get_clocks()) < 0) 527 if ((r = rfbi_get_clocks()) < 0)
524 return r; 528 return r;
@@ -566,6 +570,7 @@ static void rfbi_cleanup(void)
566{ 570{
567 omap_dispc_free_irq(); 571 omap_dispc_free_irq();
568 rfbi_put_clocks(); 572 rfbi_put_clocks();
573 iounmap(rfbi.base);
569} 574}
570 575
571const struct lcd_ctrl_extif omap2_ext_if = { 576const struct lcd_ctrl_extif omap2_ext_if = {
diff --git a/drivers/video/omap/sossi.c b/drivers/video/omap/sossi.c
index 6359353c2c67..a76946220249 100644
--- a/drivers/video/omap/sossi.c
+++ b/drivers/video/omap/sossi.c
@@ -574,7 +574,12 @@ static int sossi_init(struct omapfb_device *fbdev)
574 struct clk *dpll1out_ck; 574 struct clk *dpll1out_ck;
575 int r; 575 int r;
576 576
577 sossi.base = (void __iomem *)IO_ADDRESS(OMAP_SOSSI_BASE); 577 sossi.base = ioremap(OMAP_SOSSI_BASE, SZ_1K);
578 if (!sossi.base) {
579 dev_err(fbdev->dev, "can't ioremap SoSSI\n");
580 return -ENOMEM;
581 }
582
578 sossi.fbdev = fbdev; 583 sossi.fbdev = fbdev;
579 spin_lock_init(&sossi.lock); 584 spin_lock_init(&sossi.lock);
580 585
@@ -665,6 +670,7 @@ static void sossi_cleanup(void)
665{ 670{
666 omap_lcdc_free_dma_callback(); 671 omap_lcdc_free_dma_callback();
667 clk_put(sossi.fck); 672 clk_put(sossi.fck);
673 iounmap(sossi.base);
668} 674}
669 675
670struct lcd_ctrl_extif omap1_ext_if = { 676struct lcd_ctrl_extif omap1_ext_if = {
diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
index b829dc7c5edf..a7b01d2724b5 100644
--- a/drivers/video/s1d13xxxfb.c
+++ b/drivers/video/s1d13xxxfb.c
@@ -50,6 +50,11 @@
50#define dbg(fmt, args...) do { } while (0) 50#define dbg(fmt, args...) do { } while (0)
51#endif 51#endif
52 52
53static const int __devinitconst s1d13xxxfb_revisions[] = {
54 S1D13506_CHIP_REV, /* Rev.4 on HP Jornada 7xx S1D13506 */
55 S1D13806_CHIP_REV, /* Rev.7 on .. */
56};
57
53/* 58/*
54 * Here we define the default struct fb_fix_screeninfo 59 * Here we define the default struct fb_fix_screeninfo
55 */ 60 */
@@ -538,6 +543,7 @@ s1d13xxxfb_probe(struct platform_device *pdev)
538 struct fb_info *info; 543 struct fb_info *info;
539 struct s1d13xxxfb_pdata *pdata = NULL; 544 struct s1d13xxxfb_pdata *pdata = NULL;
540 int ret = 0; 545 int ret = 0;
546 int i;
541 u8 revision; 547 u8 revision;
542 548
543 dbg("probe called: device is %p\n", pdev); 549 dbg("probe called: device is %p\n", pdev);
@@ -607,10 +613,19 @@ s1d13xxxfb_probe(struct platform_device *pdev)
607 goto bail; 613 goto bail;
608 } 614 }
609 615
610 revision = s1d13xxxfb_readreg(default_par, S1DREG_REV_CODE); 616 revision = s1d13xxxfb_readreg(default_par, S1DREG_REV_CODE) >> 2;
611 if ((revision >> 2) != S1D_CHIP_REV) { 617
612 printk(KERN_INFO PFX "chip not found: %i\n", (revision >> 2)); 618 ret = -ENODEV;
613 ret = -ENODEV; 619
620 for (i = 0; i < ARRAY_SIZE(s1d13xxxfb_revisions); i++) {
621 if (revision == s1d13xxxfb_revisions[i])
622 ret = 0;
623 }
624
625 if (!ret)
626 printk(KERN_INFO PFX "chip revision %i\n", revision);
627 else {
628 printk(KERN_INFO PFX "unknown chip revision %i\n", revision);
614 goto bail; 629 goto bail;
615 } 630 }
616 631
diff --git a/drivers/video/tdfxfb.c b/drivers/video/tdfxfb.c
index 4599a4385bc9..14bd3f3680b8 100644
--- a/drivers/video/tdfxfb.c
+++ b/drivers/video/tdfxfb.c
@@ -1195,57 +1195,58 @@ static int __devinit tdfxfb_probe(struct pci_dev *pdev,
1195 return -ENOMEM; 1195 return -ENOMEM;
1196 1196
1197 default_par = info->par; 1197 default_par = info->par;
1198 info->fix = tdfx_fix;
1198 1199
1199 /* Configure the default fb_fix_screeninfo first */ 1200 /* Configure the default fb_fix_screeninfo first */
1200 switch (pdev->device) { 1201 switch (pdev->device) {
1201 case PCI_DEVICE_ID_3DFX_BANSHEE: 1202 case PCI_DEVICE_ID_3DFX_BANSHEE:
1202 strcpy(tdfx_fix.id, "3Dfx Banshee"); 1203 strcpy(info->fix.id, "3Dfx Banshee");
1203 default_par->max_pixclock = BANSHEE_MAX_PIXCLOCK; 1204 default_par->max_pixclock = BANSHEE_MAX_PIXCLOCK;
1204 break; 1205 break;
1205 case PCI_DEVICE_ID_3DFX_VOODOO3: 1206 case PCI_DEVICE_ID_3DFX_VOODOO3:
1206 strcpy(tdfx_fix.id, "3Dfx Voodoo3"); 1207 strcpy(info->fix.id, "3Dfx Voodoo3");
1207 default_par->max_pixclock = VOODOO3_MAX_PIXCLOCK; 1208 default_par->max_pixclock = VOODOO3_MAX_PIXCLOCK;
1208 break; 1209 break;
1209 case PCI_DEVICE_ID_3DFX_VOODOO5: 1210 case PCI_DEVICE_ID_3DFX_VOODOO5:
1210 strcpy(tdfx_fix.id, "3Dfx Voodoo5"); 1211 strcpy(info->fix.id, "3Dfx Voodoo5");
1211 default_par->max_pixclock = VOODOO5_MAX_PIXCLOCK; 1212 default_par->max_pixclock = VOODOO5_MAX_PIXCLOCK;
1212 break; 1213 break;
1213 } 1214 }
1214 1215
1215 tdfx_fix.mmio_start = pci_resource_start(pdev, 0); 1216 info->fix.mmio_start = pci_resource_start(pdev, 0);
1216 tdfx_fix.mmio_len = pci_resource_len(pdev, 0); 1217 info->fix.mmio_len = pci_resource_len(pdev, 0);
1217 if (!request_mem_region(tdfx_fix.mmio_start, tdfx_fix.mmio_len, 1218 if (!request_mem_region(info->fix.mmio_start, info->fix.mmio_len,
1218 "tdfx regbase")) { 1219 "tdfx regbase")) {
1219 printk(KERN_ERR "tdfxfb: Can't reserve regbase\n"); 1220 printk(KERN_ERR "tdfxfb: Can't reserve regbase\n");
1220 goto out_err; 1221 goto out_err;
1221 } 1222 }
1222 1223
1223 default_par->regbase_virt = 1224 default_par->regbase_virt =
1224 ioremap_nocache(tdfx_fix.mmio_start, tdfx_fix.mmio_len); 1225 ioremap_nocache(info->fix.mmio_start, info->fix.mmio_len);
1225 if (!default_par->regbase_virt) { 1226 if (!default_par->regbase_virt) {
1226 printk(KERN_ERR "fb: Can't remap %s register area.\n", 1227 printk(KERN_ERR "fb: Can't remap %s register area.\n",
1227 tdfx_fix.id); 1228 info->fix.id);
1228 goto out_err_regbase; 1229 goto out_err_regbase;
1229 } 1230 }
1230 1231
1231 tdfx_fix.smem_start = pci_resource_start(pdev, 1); 1232 info->fix.smem_start = pci_resource_start(pdev, 1);
1232 tdfx_fix.smem_len = do_lfb_size(default_par, pdev->device); 1233 info->fix.smem_len = do_lfb_size(default_par, pdev->device);
1233 if (!tdfx_fix.smem_len) { 1234 if (!info->fix.smem_len) {
1234 printk(KERN_ERR "fb: Can't count %s memory.\n", tdfx_fix.id); 1235 printk(KERN_ERR "fb: Can't count %s memory.\n", info->fix.id);
1235 goto out_err_regbase; 1236 goto out_err_regbase;
1236 } 1237 }
1237 1238
1238 if (!request_mem_region(tdfx_fix.smem_start, 1239 if (!request_mem_region(info->fix.smem_start,
1239 pci_resource_len(pdev, 1), "tdfx smem")) { 1240 pci_resource_len(pdev, 1), "tdfx smem")) {
1240 printk(KERN_ERR "tdfxfb: Can't reserve smem\n"); 1241 printk(KERN_ERR "tdfxfb: Can't reserve smem\n");
1241 goto out_err_regbase; 1242 goto out_err_regbase;
1242 } 1243 }
1243 1244
1244 info->screen_base = ioremap_nocache(tdfx_fix.smem_start, 1245 info->screen_base = ioremap_nocache(info->fix.smem_start,
1245 tdfx_fix.smem_len); 1246 info->fix.smem_len);
1246 if (!info->screen_base) { 1247 if (!info->screen_base) {
1247 printk(KERN_ERR "fb: Can't remap %s framebuffer.\n", 1248 printk(KERN_ERR "fb: Can't remap %s framebuffer.\n",
1248 tdfx_fix.id); 1249 info->fix.id);
1249 goto out_err_screenbase; 1250 goto out_err_screenbase;
1250 } 1251 }
1251 1252
@@ -1257,20 +1258,19 @@ static int __devinit tdfxfb_probe(struct pci_dev *pdev,
1257 goto out_err_screenbase; 1258 goto out_err_screenbase;
1258 } 1259 }
1259 1260
1260 printk(KERN_INFO "fb: %s memory = %dK\n", tdfx_fix.id, 1261 printk(KERN_INFO "fb: %s memory = %dK\n", info->fix.id,
1261 tdfx_fix.smem_len >> 10); 1262 info->fix.smem_len >> 10);
1262 1263
1263 default_par->mtrr_handle = -1; 1264 default_par->mtrr_handle = -1;
1264 if (!nomtrr) 1265 if (!nomtrr)
1265 default_par->mtrr_handle = 1266 default_par->mtrr_handle =
1266 mtrr_add(tdfx_fix.smem_start, tdfx_fix.smem_len, 1267 mtrr_add(info->fix.smem_start, info->fix.smem_len,
1267 MTRR_TYPE_WRCOMB, 1); 1268 MTRR_TYPE_WRCOMB, 1);
1268 1269
1269 tdfx_fix.ypanstep = nopan ? 0 : 1; 1270 info->fix.ypanstep = nopan ? 0 : 1;
1270 tdfx_fix.ywrapstep = nowrap ? 0 : 1; 1271 info->fix.ywrapstep = nowrap ? 0 : 1;
1271 1272
1272 info->fbops = &tdfxfb_ops; 1273 info->fbops = &tdfxfb_ops;
1273 info->fix = tdfx_fix;
1274 info->pseudo_palette = default_par->palette; 1274 info->pseudo_palette = default_par->palette;
1275 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN; 1275 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
1276#ifdef CONFIG_FB_3DFX_ACCEL 1276#ifdef CONFIG_FB_3DFX_ACCEL
@@ -1323,14 +1323,14 @@ out_err_iobase:
1323out_err_screenbase: 1323out_err_screenbase:
1324 if (info->screen_base) 1324 if (info->screen_base)
1325 iounmap(info->screen_base); 1325 iounmap(info->screen_base);
1326 release_mem_region(tdfx_fix.smem_start, pci_resource_len(pdev, 1)); 1326 release_mem_region(info->fix.smem_start, pci_resource_len(pdev, 1));
1327out_err_regbase: 1327out_err_regbase:
1328 /* 1328 /*
1329 * Cleanup after anything that was remapped/allocated. 1329 * Cleanup after anything that was remapped/allocated.
1330 */ 1330 */
1331 if (default_par->regbase_virt) 1331 if (default_par->regbase_virt)
1332 iounmap(default_par->regbase_virt); 1332 iounmap(default_par->regbase_virt);
1333 release_mem_region(tdfx_fix.mmio_start, tdfx_fix.mmio_len); 1333 release_mem_region(info->fix.mmio_start, info->fix.mmio_len);
1334out_err: 1334out_err:
1335 framebuffer_release(info); 1335 framebuffer_release(info);
1336 return -ENXIO; 1336 return -ENXIO;
diff --git a/drivers/video/tmiofb.c b/drivers/video/tmiofb.c
new file mode 100644
index 000000000000..2a380011e9ba
--- /dev/null
+++ b/drivers/video/tmiofb.c
@@ -0,0 +1,1050 @@
1/*
2 * Frame Buffer Device for Toshiba Mobile IO(TMIO) controller
3 *
4 * Copyright(C) 2005-2006 Chris Humbert
5 * Copyright(C) 2005 Dirk Opfer
6 * Copytight(C) 2007,2008 Dmitry Baryshkov
7 *
8 * Based on:
9 * drivers/video/w100fb.c
10 * code written by Sharp/Lineo for 2.4 kernels
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
14 * as published by the Free Software Foundation;
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */
21
22#include <linux/kernel.h>
23#include <linux/module.h>
24#include <linux/platform_device.h>
25#include <linux/fb.h>
26#include <linux/interrupt.h>
27#include <linux/delay.h>
28/* Why should fb driver call console functions? because acquire_console_sem() */
29#include <linux/console.h>
30#include <linux/mfd/core.h>
31#include <linux/mfd/tmio.h>
32#include <linux/uaccess.h>
33
34/*
35 * accelerator commands
36 */
37#define TMIOFB_ACC_CSADR(x) (0x00000000 | ((x) & 0x001ffffe))
38#define TMIOFB_ACC_CHPIX(x) (0x01000000 | ((x) & 0x000003ff))
39#define TMIOFB_ACC_CVPIX(x) (0x02000000 | ((x) & 0x000003ff))
40#define TMIOFB_ACC_PSADR(x) (0x03000000 | ((x) & 0x00fffffe))
41#define TMIOFB_ACC_PHPIX(x) (0x04000000 | ((x) & 0x000003ff))
42#define TMIOFB_ACC_PVPIX(x) (0x05000000 | ((x) & 0x000003ff))
43#define TMIOFB_ACC_PHOFS(x) (0x06000000 | ((x) & 0x000003ff))
44#define TMIOFB_ACC_PVOFS(x) (0x07000000 | ((x) & 0x000003ff))
45#define TMIOFB_ACC_POADR(x) (0x08000000 | ((x) & 0x00fffffe))
46#define TMIOFB_ACC_RSTR(x) (0x09000000 | ((x) & 0x000000ff))
47#define TMIOFB_ACC_TCLOR(x) (0x0A000000 | ((x) & 0x0000ffff))
48#define TMIOFB_ACC_FILL(x) (0x0B000000 | ((x) & 0x0000ffff))
49#define TMIOFB_ACC_DSADR(x) (0x0C000000 | ((x) & 0x00fffffe))
50#define TMIOFB_ACC_SSADR(x) (0x0D000000 | ((x) & 0x00fffffe))
51#define TMIOFB_ACC_DHPIX(x) (0x0E000000 | ((x) & 0x000003ff))
52#define TMIOFB_ACC_DVPIX(x) (0x0F000000 | ((x) & 0x000003ff))
53#define TMIOFB_ACC_SHPIX(x) (0x10000000 | ((x) & 0x000003ff))
54#define TMIOFB_ACC_SVPIX(x) (0x11000000 | ((x) & 0x000003ff))
55#define TMIOFB_ACC_LBINI(x) (0x12000000 | ((x) & 0x0000ffff))
56#define TMIOFB_ACC_LBK2(x) (0x13000000 | ((x) & 0x0000ffff))
57#define TMIOFB_ACC_SHBINI(x) (0x14000000 | ((x) & 0x0000ffff))
58#define TMIOFB_ACC_SHBK2(x) (0x15000000 | ((x) & 0x0000ffff))
59#define TMIOFB_ACC_SVBINI(x) (0x16000000 | ((x) & 0x0000ffff))
60#define TMIOFB_ACC_SVBK2(x) (0x17000000 | ((x) & 0x0000ffff))
61
62#define TMIOFB_ACC_CMGO 0x20000000
63#define TMIOFB_ACC_CMGO_CEND 0x00000001
64#define TMIOFB_ACC_CMGO_INT 0x00000002
65#define TMIOFB_ACC_CMGO_CMOD 0x00000010
66#define TMIOFB_ACC_CMGO_CDVRV 0x00000020
67#define TMIOFB_ACC_CMGO_CDHRV 0x00000040
68#define TMIOFB_ACC_CMGO_RUND 0x00008000
69#define TMIOFB_ACC_SCGO 0x21000000
70#define TMIOFB_ACC_SCGO_CEND 0x00000001
71#define TMIOFB_ACC_SCGO_INT 0x00000002
72#define TMIOFB_ACC_SCGO_ROP3 0x00000004
73#define TMIOFB_ACC_SCGO_TRNS 0x00000008
74#define TMIOFB_ACC_SCGO_DVRV 0x00000010
75#define TMIOFB_ACC_SCGO_DHRV 0x00000020
76#define TMIOFB_ACC_SCGO_SVRV 0x00000040
77#define TMIOFB_ACC_SCGO_SHRV 0x00000080
78#define TMIOFB_ACC_SCGO_DSTXY 0x00008000
79#define TMIOFB_ACC_SBGO 0x22000000
80#define TMIOFB_ACC_SBGO_CEND 0x00000001
81#define TMIOFB_ACC_SBGO_INT 0x00000002
82#define TMIOFB_ACC_SBGO_DVRV 0x00000010
83#define TMIOFB_ACC_SBGO_DHRV 0x00000020
84#define TMIOFB_ACC_SBGO_SVRV 0x00000040
85#define TMIOFB_ACC_SBGO_SHRV 0x00000080
86#define TMIOFB_ACC_SBGO_SBMD 0x00000100
87#define TMIOFB_ACC_FLGO 0x23000000
88#define TMIOFB_ACC_FLGO_CEND 0x00000001
89#define TMIOFB_ACC_FLGO_INT 0x00000002
90#define TMIOFB_ACC_FLGO_ROP3 0x00000004
91#define TMIOFB_ACC_LDGO 0x24000000
92#define TMIOFB_ACC_LDGO_CEND 0x00000001
93#define TMIOFB_ACC_LDGO_INT 0x00000002
94#define TMIOFB_ACC_LDGO_ROP3 0x00000004
95#define TMIOFB_ACC_LDGO_ENDPX 0x00000008
96#define TMIOFB_ACC_LDGO_LVRV 0x00000010
97#define TMIOFB_ACC_LDGO_LHRV 0x00000020
98#define TMIOFB_ACC_LDGO_LDMOD 0x00000040
99
100/* a FIFO is always allocated, even if acceleration is not used */
101#define TMIOFB_FIFO_SIZE 512
102
103/*
104 * LCD Host Controller Configuration Register
105 *
106 * This iomem area supports only 16-bit IO.
107 */
108#define CCR_CMD 0x04 /* Command */
109#define CCR_REVID 0x08 /* Revision ID */
110#define CCR_BASEL 0x10 /* LCD Control Reg Base Addr Low */
111#define CCR_BASEH 0x12 /* LCD Control Reg Base Addr High */
112#define CCR_UGCC 0x40 /* Unified Gated Clock Control */
113#define CCR_GCC 0x42 /* Gated Clock Control */
114#define CCR_USC 0x50 /* Unified Software Clear */
115#define CCR_VRAMRTC 0x60 /* VRAM Timing Control */
116 /* 0x61 VRAM Refresh Control */
117#define CCR_VRAMSAC 0x62 /* VRAM Access Control */
118 /* 0x63 VRAM Status */
119#define CCR_VRAMBC 0x64 /* VRAM Block Control */
120
121/*
122 * LCD Control Register
123 *
124 * This iomem area supports only 16-bit IO.
125 */
126#define LCR_UIS 0x000 /* Unified Interrupt Status */
127#define LCR_VHPN 0x008 /* VRAM Horizontal Pixel Number */
128#define LCR_CFSAL 0x00a /* Command FIFO Start Address Low */
129#define LCR_CFSAH 0x00c /* Command FIFO Start Address High */
130#define LCR_CFS 0x00e /* Command FIFO Size */
131#define LCR_CFWS 0x010 /* Command FIFO Writeable Size */
132#define LCR_BBIE 0x012 /* BitBLT Interrupt Enable */
133#define LCR_BBISC 0x014 /* BitBLT Interrupt Status and Clear */
134#define LCR_CCS 0x016 /* Command Count Status */
135#define LCR_BBES 0x018 /* BitBLT Execution Status */
136#define LCR_CMDL 0x01c /* Command Low */
137#define LCR_CMDH 0x01e /* Command High */
138#define LCR_CFC 0x022 /* Command FIFO Clear */
139#define LCR_CCIFC 0x024 /* CMOS Camera IF Control */
140#define LCR_HWT 0x026 /* Hardware Test */
141#define LCR_LCDCCRC 0x100 /* LCDC Clock and Reset Control */
142#define LCR_LCDCC 0x102 /* LCDC Control */
143#define LCR_LCDCOPC 0x104 /* LCDC Output Pin Control */
144#define LCR_LCDIS 0x108 /* LCD Interrupt Status */
145#define LCR_LCDIM 0x10a /* LCD Interrupt Mask */
146#define LCR_LCDIE 0x10c /* LCD Interrupt Enable */
147#define LCR_GDSAL 0x122 /* Graphics Display Start Address Low */
148#define LCR_GDSAH 0x124 /* Graphics Display Start Address High */
149#define LCR_VHPCL 0x12a /* VRAM Horizontal Pixel Count Low */
150#define LCR_VHPCH 0x12c /* VRAM Horizontal Pixel Count High */
151#define LCR_GM 0x12e /* Graphic Mode(VRAM access enable) */
152#define LCR_HT 0x140 /* Horizontal Total */
153#define LCR_HDS 0x142 /* Horizontal Display Start */
154#define LCR_HSS 0x144 /* H-Sync Start */
155#define LCR_HSE 0x146 /* H-Sync End */
156#define LCR_HNP 0x14c /* Horizontal Number of Pixels */
157#define LCR_VT 0x150 /* Vertical Total */
158#define LCR_VDS 0x152 /* Vertical Display Start */
159#define LCR_VSS 0x154 /* V-Sync Start */
160#define LCR_VSE 0x156 /* V-Sync End */
161#define LCR_CDLN 0x160 /* Current Display Line Number */
162#define LCR_ILN 0x162 /* Interrupt Line Number */
163#define LCR_SP 0x164 /* Sync Polarity */
164#define LCR_MISC 0x166 /* MISC(RGB565 mode) */
165#define LCR_VIHSS 0x16a /* Video Interface H-Sync Start */
166#define LCR_VIVS 0x16c /* Video Interface Vertical Start */
167#define LCR_VIVE 0x16e /* Video Interface Vertical End */
168#define LCR_VIVSS 0x170 /* Video Interface V-Sync Start */
169#define LCR_VCCIS 0x17e /* Video / CMOS Camera Interface Select */
170#define LCR_VIDWSAL 0x180 /* VI Data Write Start Address Low */
171#define LCR_VIDWSAH 0x182 /* VI Data Write Start Address High */
172#define LCR_VIDRSAL 0x184 /* VI Data Read Start Address Low */
173#define LCR_VIDRSAH 0x186 /* VI Data Read Start Address High */
174#define LCR_VIPDDST 0x188 /* VI Picture Data Display Start Timing */
175#define LCR_VIPDDET 0x186 /* VI Picture Data Display End Timing */
176#define LCR_VIE 0x18c /* Video Interface Enable */
177#define LCR_VCS 0x18e /* Video/Camera Select */
178#define LCR_VPHWC 0x194 /* Video Picture Horizontal Wait Count */
179#define LCR_VPHS 0x196 /* Video Picture Horizontal Size */
180#define LCR_VPVWC 0x198 /* Video Picture Vertical Wait Count */
181#define LCR_VPVS 0x19a /* Video Picture Vertical Size */
182#define LCR_PLHPIX 0x1a0 /* PLHPIX */
183#define LCR_XS 0x1a2 /* XStart */
184#define LCR_XCKHW 0x1a4 /* XCK High Width */
185#define LCR_STHS 0x1a8 /* STH Start */
186#define LCR_VT2 0x1aa /* Vertical Total */
187#define LCR_YCKSW 0x1ac /* YCK Start Wait */
188#define LCR_YSTS 0x1ae /* YST Start */
189#define LCR_PPOLS 0x1b0 /* #PPOL Start */
190#define LCR_PRECW 0x1b2 /* PREC Width */
191#define LCR_VCLKHW 0x1b4 /* VCLK High Width */
192#define LCR_OC 0x1b6 /* Output Control */
193
194static char *mode_option __devinitdata;
195
196struct tmiofb_par {
197 u32 pseudo_palette[16];
198
199#ifdef CONFIG_FB_TMIO_ACCELL
200 wait_queue_head_t wait_acc;
201 bool use_polling;
202#endif
203
204 void __iomem *ccr;
205 void __iomem *lcr;
206};
207
208/*--------------------------------------------------------------------------*/
209
210/*
211 * reasons for an interrupt:
212 * uis bbisc lcdis
213 * 0100 0001 accelerator command completed
214 * 2000 0001 vsync start
215 * 2000 0002 display start
216 * 2000 0004 line number match(0x1ff mask???)
217 */
218static irqreturn_t tmiofb_irq(int irq, void *__info)
219{
220 struct fb_info *info = __info;
221 struct tmiofb_par *par = info->par;
222 unsigned int bbisc = tmio_ioread16(par->lcr + LCR_BBISC);
223
224
225 /*
226 * We were in polling mode and now we got correct irq.
227 * Switch back to IRQ-based sync of command FIFO
228 */
229 if (unlikely(par->use_polling && irq != -1)) {
230 printk(KERN_INFO "tmiofb: switching to waitq\n");
231 par->use_polling = false;
232 }
233
234 tmio_iowrite16(bbisc, par->lcr + LCR_BBISC);
235
236#ifdef CONFIG_FB_TMIO_ACCELL
237 if (bbisc & 1)
238 wake_up(&par->wait_acc);
239#endif
240
241 return IRQ_HANDLED;
242}
243
244
245/*--------------------------------------------------------------------------*/
246
247
248/*
249 * Turns off the LCD controller and LCD host controller.
250 */
251static int tmiofb_hw_stop(struct platform_device *dev)
252{
253 struct mfd_cell *cell = dev->dev.platform_data;
254 struct tmio_fb_data *data = cell->driver_data;
255 struct fb_info *info = platform_get_drvdata(dev);
256 struct tmiofb_par *par = info->par;
257
258 tmio_iowrite16(0, par->ccr + CCR_UGCC);
259 tmio_iowrite16(0, par->lcr + LCR_GM);
260 data->lcd_set_power(dev, 0);
261 tmio_iowrite16(0x0010, par->lcr + LCR_LCDCCRC);
262
263 return 0;
264}
265
266/*
267 * Initializes the LCD host controller.
268 */
269static int tmiofb_hw_init(struct platform_device *dev)
270{
271 struct mfd_cell *cell = dev->dev.platform_data;
272 struct fb_info *info = platform_get_drvdata(dev);
273 struct tmiofb_par *par = info->par;
274 const struct resource *nlcr = &cell->resources[0];
275 const struct resource *vram = &cell->resources[2];
276 unsigned long base;
277
278 if (nlcr == NULL || vram == NULL)
279 return -EINVAL;
280
281 base = nlcr->start;
282
283 tmio_iowrite16(0x003a, par->ccr + CCR_UGCC);
284 tmio_iowrite16(0x003a, par->ccr + CCR_GCC);
285 tmio_iowrite16(0x3f00, par->ccr + CCR_USC);
286
287 msleep(2); /* wait for device to settle */
288
289 tmio_iowrite16(0x0000, par->ccr + CCR_USC);
290 tmio_iowrite16(base >> 16, par->ccr + CCR_BASEH);
291 tmio_iowrite16(base, par->ccr + CCR_BASEL);
292 tmio_iowrite16(0x0002, par->ccr + CCR_CMD); /* base address enable */
293 tmio_iowrite16(0x40a8, par->ccr + CCR_VRAMRTC); /* VRAMRC, VRAMTC */
294 tmio_iowrite16(0x0018, par->ccr + CCR_VRAMSAC); /* VRAMSTS, VRAMAC */
295 tmio_iowrite16(0x0002, par->ccr + CCR_VRAMBC);
296 msleep(2); /* wait for device to settle */
297 tmio_iowrite16(0x000b, par->ccr + CCR_VRAMBC);
298
299 base = vram->start + info->screen_size;
300 tmio_iowrite16(base >> 16, par->lcr + LCR_CFSAH);
301 tmio_iowrite16(base, par->lcr + LCR_CFSAL);
302 tmio_iowrite16(TMIOFB_FIFO_SIZE - 1, par->lcr + LCR_CFS);
303 tmio_iowrite16(1, par->lcr + LCR_CFC);
304 tmio_iowrite16(1, par->lcr + LCR_BBIE);
305 tmio_iowrite16(0, par->lcr + LCR_CFWS);
306
307 return 0;
308}
309
310/*
311 * Sets the LCD controller's output resolution and pixel clock
312 */
313static void tmiofb_hw_mode(struct platform_device *dev)
314{
315 struct mfd_cell *cell = dev->dev.platform_data;
316 struct tmio_fb_data *data = cell->driver_data;
317 struct fb_info *info = platform_get_drvdata(dev);
318 struct fb_videomode *mode = info->mode;
319 struct tmiofb_par *par = info->par;
320 unsigned int i;
321
322 tmio_iowrite16(0, par->lcr + LCR_GM);
323 data->lcd_set_power(dev, 0);
324 tmio_iowrite16(0x0010, par->lcr + LCR_LCDCCRC);
325 data->lcd_mode(dev, mode);
326 data->lcd_set_power(dev, 1);
327
328 tmio_iowrite16(info->fix.line_length, par->lcr + LCR_VHPN);
329 tmio_iowrite16(0, par->lcr + LCR_GDSAH);
330 tmio_iowrite16(0, par->lcr + LCR_GDSAL);
331 tmio_iowrite16(info->fix.line_length >> 16, par->lcr + LCR_VHPCH);
332 tmio_iowrite16(info->fix.line_length, par->lcr + LCR_VHPCL);
333 tmio_iowrite16(i = 0, par->lcr + LCR_HSS);
334 tmio_iowrite16(i += mode->hsync_len, par->lcr + LCR_HSE);
335 tmio_iowrite16(i += mode->left_margin, par->lcr + LCR_HDS);
336 tmio_iowrite16(i += mode->xres + mode->right_margin, par->lcr + LCR_HT);
337 tmio_iowrite16(mode->xres, par->lcr + LCR_HNP);
338 tmio_iowrite16(i = 0, par->lcr + LCR_VSS);
339 tmio_iowrite16(i += mode->vsync_len, par->lcr + LCR_VSE);
340 tmio_iowrite16(i += mode->upper_margin, par->lcr + LCR_VDS);
341 tmio_iowrite16(i += mode->yres, par->lcr + LCR_ILN);
342 tmio_iowrite16(i += mode->lower_margin, par->lcr + LCR_VT);
343 tmio_iowrite16(3, par->lcr + LCR_MISC); /* RGB565 mode */
344 tmio_iowrite16(1, par->lcr + LCR_GM); /* VRAM enable */
345 tmio_iowrite16(0x4007, par->lcr + LCR_LCDCC);
346 tmio_iowrite16(3, par->lcr + LCR_SP); /* sync polarity */
347
348 tmio_iowrite16(0x0010, par->lcr + LCR_LCDCCRC);
349 msleep(5); /* wait for device to settle */
350 tmio_iowrite16(0x0014, par->lcr + LCR_LCDCCRC); /* STOP_CKP */
351 msleep(5); /* wait for device to settle */
352 tmio_iowrite16(0x0015, par->lcr + LCR_LCDCCRC); /* STOP_CKP|SOFT_RESET*/
353 tmio_iowrite16(0xfffa, par->lcr + LCR_VCS);
354}
355
356/*--------------------------------------------------------------------------*/
357
358#ifdef CONFIG_FB_TMIO_ACCELL
359static int __must_check
360tmiofb_acc_wait(struct fb_info *info, unsigned int ccs)
361{
362 struct tmiofb_par *par = info->par;
363 /*
364 * This code can be called whith interrupts disabled.
365 * So instead of relaying on irq to trigger the event,
366 * poll the state till the necessary command is executed.
367 */
368 if (irqs_disabled() || par->use_polling) {
369 int i = 0;
370 while (tmio_ioread16(par->lcr + LCR_CCS) > ccs) {
371 udelay(1);
372 i++;
373 if (i > 10000) {
374 pr_err("tmiofb: timeout waiting for %d\n",
375 ccs);
376 return -ETIMEDOUT;
377 }
378 tmiofb_irq(-1, info);
379 }
380 } else {
381 if (!wait_event_interruptible_timeout(par->wait_acc,
382 tmio_ioread16(par->lcr + LCR_CCS) <= ccs,
383 1000)) {
384 pr_err("tmiofb: timeout waiting for %d\n", ccs);
385 return -ETIMEDOUT;
386 }
387 }
388
389 return 0;
390}
391
392/*
393 * Writes an accelerator command to the accelerator's FIFO.
394 */
395static int
396tmiofb_acc_write(struct fb_info *info, const u32 *cmd, unsigned int count)
397{
398 struct tmiofb_par *par = info->par;
399 int ret;
400
401 ret = tmiofb_acc_wait(info, TMIOFB_FIFO_SIZE - count);
402 if (ret)
403 return ret;
404
405 for (; count; count--, cmd++) {
406 tmio_iowrite16(*cmd >> 16, par->lcr + LCR_CMDH);
407 tmio_iowrite16(*cmd, par->lcr + LCR_CMDL);
408 }
409
410 return ret;
411}
412
413/*
414 * Wait for the accelerator to finish its operations before writing
415 * to the framebuffer for consistent display output.
416 */
417static int tmiofb_sync(struct fb_info *fbi)
418{
419 struct tmiofb_par *par = fbi->par;
420
421 int ret;
422 int i = 0;
423
424 ret = tmiofb_acc_wait(fbi, 0);
425
426 while (tmio_ioread16(par->lcr + LCR_BBES) & 2) { /* blit active */
427 udelay(1);
428 i++ ;
429 if (i > 10000) {
430 printk(KERN_ERR "timeout waiting for blit to end!\n");
431 return -ETIMEDOUT;
432 }
433 }
434
435 return ret;
436}
437
438static void
439tmiofb_fillrect(struct fb_info *fbi, const struct fb_fillrect *rect)
440{
441 const u32 cmd[] = {
442 TMIOFB_ACC_DSADR((rect->dy * fbi->mode->xres + rect->dx) * 2),
443 TMIOFB_ACC_DHPIX(rect->width - 1),
444 TMIOFB_ACC_DVPIX(rect->height - 1),
445 TMIOFB_ACC_FILL(rect->color),
446 TMIOFB_ACC_FLGO,
447 };
448
449 if (fbi->state != FBINFO_STATE_RUNNING ||
450 fbi->flags & FBINFO_HWACCEL_DISABLED) {
451 cfb_fillrect(fbi, rect);
452 return;
453 }
454
455 tmiofb_acc_write(fbi, cmd, ARRAY_SIZE(cmd));
456}
457
458static void
459tmiofb_copyarea(struct fb_info *fbi, const struct fb_copyarea *area)
460{
461 const u32 cmd[] = {
462 TMIOFB_ACC_DSADR((area->dy * fbi->mode->xres + area->dx) * 2),
463 TMIOFB_ACC_DHPIX(area->width - 1),
464 TMIOFB_ACC_DVPIX(area->height - 1),
465 TMIOFB_ACC_SSADR((area->sy * fbi->mode->xres + area->sx) * 2),
466 TMIOFB_ACC_SCGO,
467 };
468
469 if (fbi->state != FBINFO_STATE_RUNNING ||
470 fbi->flags & FBINFO_HWACCEL_DISABLED) {
471 cfb_copyarea(fbi, area);
472 return;
473 }
474
475 tmiofb_acc_write(fbi, cmd, ARRAY_SIZE(cmd));
476}
477#endif
478
479static void tmiofb_clearscreen(struct fb_info *info)
480{
481 const struct fb_fillrect rect = {
482 .dx = 0,
483 .dy = 0,
484 .width = info->mode->xres,
485 .height = info->mode->yres,
486 .color = 0,
487 .rop = ROP_COPY,
488 };
489
490 info->fbops->fb_fillrect(info, &rect);
491}
492
493static int tmiofb_vblank(struct fb_info *fbi, struct fb_vblank *vblank)
494{
495 struct tmiofb_par *par = fbi->par;
496 struct fb_videomode *mode = fbi->mode;
497 unsigned int vcount = tmio_ioread16(par->lcr + LCR_CDLN);
498 unsigned int vds = mode->vsync_len + mode->upper_margin;
499
500 vblank->vcount = vcount;
501 vblank->flags = FB_VBLANK_HAVE_VBLANK | FB_VBLANK_HAVE_VCOUNT
502 | FB_VBLANK_HAVE_VSYNC;
503
504 if (vcount < mode->vsync_len)
505 vblank->flags |= FB_VBLANK_VSYNCING;
506
507 if (vcount < vds || vcount > vds + mode->yres)
508 vblank->flags |= FB_VBLANK_VBLANKING;
509
510 return 0;
511}
512
513
514static int tmiofb_ioctl(struct fb_info *fbi,
515 unsigned int cmd, unsigned long arg)
516{
517 switch (cmd) {
518 case FBIOGET_VBLANK: {
519 struct fb_vblank vblank = {0};
520 void __user *argp = (void __user *) arg;
521
522 tmiofb_vblank(fbi, &vblank);
523 if (copy_to_user(argp, &vblank, sizeof vblank))
524 return -EFAULT;
525 return 0;
526 }
527
528#ifdef CONFIG_FB_TMIO_ACCELL
529 case FBIO_TMIO_ACC_SYNC:
530 tmiofb_sync(fbi);
531 return 0;
532
533 case FBIO_TMIO_ACC_WRITE: {
534 u32 __user *argp = (void __user *) arg;
535 u32 len;
536 u32 acc[16];
537
538 if (get_user(len, argp))
539 return -EFAULT;
540 if (len > ARRAY_SIZE(acc))
541 return -EINVAL;
542 if (copy_from_user(acc, argp + 1, sizeof(u32) * len))
543 return -EFAULT;
544
545 return tmiofb_acc_write(fbi, acc, len);
546 }
547#endif
548 }
549
550 return -ENOTTY;
551}
552
553/*--------------------------------------------------------------------------*/
554
555/* Select the smallest mode that allows the desired resolution to be
556 * displayed. If desired, the x and y parameters can be rounded up to
557 * match the selected mode.
558 */
559static struct fb_videomode *
560tmiofb_find_mode(struct fb_info *info, struct fb_var_screeninfo *var)
561{
562 struct mfd_cell *cell =
563 info->device->platform_data;
564 struct tmio_fb_data *data = cell->driver_data;
565 struct fb_videomode *best = NULL;
566 int i;
567
568 for (i = 0; i < data->num_modes; i++) {
569 struct fb_videomode *mode = data->modes + i;
570
571 if (mode->xres >= var->xres && mode->yres >= var->yres
572 && (!best || (mode->xres < best->xres
573 && mode->yres < best->yres)))
574 best = mode;
575 }
576
577 return best;
578}
579
580static int tmiofb_check_var(struct fb_var_screeninfo *var, struct fb_info *info)
581{
582
583 struct fb_videomode *mode;
584 struct mfd_cell *cell =
585 info->device->platform_data;
586 struct tmio_fb_data *data = cell->driver_data;
587
588 mode = tmiofb_find_mode(info, var);
589 if (!mode || var->bits_per_pixel > 16)
590 return -EINVAL;
591
592 fb_videomode_to_var(var, mode);
593
594 var->xres_virtual = mode->xres;
595 var->yres_virtual = info->screen_size / (mode->xres * 2);
596
597 if (var->yres_virtual < var->yres)
598 return -EINVAL;
599
600 var->xoffset = 0;
601 var->yoffset = 0;
602 var->bits_per_pixel = 16;
603 var->grayscale = 0;
604 var->red.offset = 11;
605 var->red.length = 5;
606 var->green.offset = 5;
607 var->green.length = 6;
608 var->blue.offset = 0;
609 var->blue.length = 5;
610 var->transp.offset = 0;
611 var->transp.length = 0;
612 var->nonstd = 0;
613 var->height = data->height; /* mm */
614 var->width = data->width; /* mm */
615 var->rotate = 0;
616 return 0;
617}
618
619static int tmiofb_set_par(struct fb_info *info)
620{
621 struct fb_var_screeninfo *var = &info->var;
622 struct fb_videomode *mode;
623
624 mode = tmiofb_find_mode(info, var);
625 if (!mode)
626 return -EINVAL;
627
628 info->mode = mode;
629 info->fix.line_length = info->mode->xres *
630 var->bits_per_pixel / 8;
631
632 tmiofb_hw_mode(to_platform_device(info->device));
633 tmiofb_clearscreen(info);
634 return 0;
635}
636
637static int tmiofb_setcolreg(unsigned regno, unsigned red, unsigned green,
638 unsigned blue, unsigned transp,
639 struct fb_info *info)
640{
641 struct tmiofb_par *par = info->par;
642
643 if (regno < ARRAY_SIZE(par->pseudo_palette)) {
644 par->pseudo_palette[regno] =
645 ((red & 0xf800)) |
646 ((green & 0xfc00) >> 5) |
647 ((blue & 0xf800) >> 11);
648 return 0;
649 }
650
651 return -EINVAL;
652}
653
654static int tmiofb_blank(int blank, struct fb_info *info)
655{
656 /*
657 * everything is done in lcd/bl drivers.
658 * this is purely to make sysfs happy and work.
659 */
660 return 0;
661}
662
663static struct fb_ops tmiofb_ops = {
664 .owner = THIS_MODULE,
665
666 .fb_ioctl = tmiofb_ioctl,
667 .fb_check_var = tmiofb_check_var,
668 .fb_set_par = tmiofb_set_par,
669 .fb_setcolreg = tmiofb_setcolreg,
670 .fb_blank = tmiofb_blank,
671 .fb_imageblit = cfb_imageblit,
672#ifdef CONFIG_FB_TMIO_ACCELL
673 .fb_sync = tmiofb_sync,
674 .fb_fillrect = tmiofb_fillrect,
675 .fb_copyarea = tmiofb_copyarea,
676#else
677 .fb_fillrect = cfb_fillrect,
678 .fb_copyarea = cfb_copyarea,
679#endif
680};
681
682/*--------------------------------------------------------------------------*/
683
684static int __devinit tmiofb_probe(struct platform_device *dev)
685{
686 struct mfd_cell *cell = dev->dev.platform_data;
687 struct tmio_fb_data *data = cell->driver_data;
688 struct resource *ccr = platform_get_resource(dev, IORESOURCE_MEM, 1);
689 struct resource *lcr = platform_get_resource(dev, IORESOURCE_MEM, 0);
690 struct resource *vram = platform_get_resource(dev, IORESOURCE_MEM, 2);
691 int irq = platform_get_irq(dev, 0);
692 struct fb_info *info;
693 struct tmiofb_par *par;
694 int retval;
695
696 /*
697 * This is the only way ATM to disable the fb
698 */
699 if (data == NULL) {
700 dev_err(&dev->dev, "NULL platform data!\n");
701 return -EINVAL;
702 }
703
704 info = framebuffer_alloc(sizeof(struct tmiofb_par), &dev->dev);
705
706 if (!info)
707 return -ENOMEM;
708
709 par = info->par;
710
711#ifdef CONFIG_FB_TMIO_ACCELL
712 init_waitqueue_head(&par->wait_acc);
713
714 par->use_polling = true;
715
716 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_COPYAREA
717 | FBINFO_HWACCEL_FILLRECT;
718#else
719 info->flags = FBINFO_DEFAULT;
720#endif
721
722 info->fbops = &tmiofb_ops;
723
724 strcpy(info->fix.id, "tmio-fb");
725 info->fix.smem_start = vram->start;
726 info->fix.smem_len = resource_size(vram);
727 info->fix.type = FB_TYPE_PACKED_PIXELS;
728 info->fix.visual = FB_VISUAL_TRUECOLOR;
729 info->fix.mmio_start = lcr->start;
730 info->fix.mmio_len = resource_size(lcr);
731 info->fix.accel = FB_ACCEL_NONE;
732 info->screen_size = info->fix.smem_len - (4 * TMIOFB_FIFO_SIZE);
733 info->pseudo_palette = par->pseudo_palette;
734
735 par->ccr = ioremap(ccr->start, resource_size(ccr));
736 if (!par->ccr) {
737 retval = -ENOMEM;
738 goto err_ioremap_ccr;
739 }
740
741 par->lcr = ioremap(info->fix.mmio_start, info->fix.mmio_len);
742 if (!par->lcr) {
743 retval = -ENOMEM;
744 goto err_ioremap_lcr;
745 }
746
747 info->screen_base = ioremap(info->fix.smem_start, info->fix.smem_len);
748 if (!info->screen_base) {
749 retval = -ENOMEM;
750 goto err_ioremap_vram;
751 }
752
753 retval = request_irq(irq, &tmiofb_irq, IRQF_DISABLED,
754 dev->dev.bus_id, info);
755
756 if (retval)
757 goto err_request_irq;
758
759 platform_set_drvdata(dev, info);
760
761 retval = fb_find_mode(&info->var, info, mode_option,
762 data->modes, data->num_modes,
763 data->modes, 16);
764 if (!retval) {
765 retval = -EINVAL;
766 goto err_find_mode;
767 }
768
769 if (cell->enable) {
770 retval = cell->enable(dev);
771 if (retval)
772 goto err_enable;
773 }
774
775 retval = tmiofb_hw_init(dev);
776 if (retval)
777 goto err_hw_init;
778
779 fb_videomode_to_modelist(data->modes, data->num_modes,
780 &info->modelist);
781
782 retval = register_framebuffer(info);
783 if (retval < 0)
784 goto err_register_framebuffer;
785
786 printk(KERN_INFO "fb%d: %s frame buffer device\n",
787 info->node, info->fix.id);
788
789 return 0;
790
791err_register_framebuffer:
792/*err_set_par:*/
793 tmiofb_hw_stop(dev);
794err_hw_init:
795 if (cell->disable)
796 cell->disable(dev);
797err_enable:
798err_find_mode:
799 platform_set_drvdata(dev, NULL);
800 free_irq(irq, info);
801err_request_irq:
802 iounmap(info->screen_base);
803err_ioremap_vram:
804 iounmap(par->lcr);
805err_ioremap_lcr:
806 iounmap(par->ccr);
807err_ioremap_ccr:
808 framebuffer_release(info);
809 return retval;
810}
811
812static int __devexit tmiofb_remove(struct platform_device *dev)
813{
814 struct mfd_cell *cell = dev->dev.platform_data;
815 struct fb_info *info = platform_get_drvdata(dev);
816 int irq = platform_get_irq(dev, 0);
817 struct tmiofb_par *par;
818
819 if (info) {
820 par = info->par;
821 unregister_framebuffer(info);
822
823 tmiofb_hw_stop(dev);
824
825 if (cell->disable)
826 cell->disable(dev);
827
828 platform_set_drvdata(dev, NULL);
829
830 free_irq(irq, info);
831
832 iounmap(info->screen_base);
833 iounmap(par->lcr);
834 iounmap(par->ccr);
835
836 framebuffer_release(info);
837 }
838
839 return 0;
840}
841
842#ifdef DEBUG
843static void tmiofb_dump_regs(struct platform_device *dev)
844{
845 struct fb_info *info = platform_get_drvdata(dev);
846 struct tmiofb_par *par = info->par;
847
848 printk(KERN_DEBUG "lhccr:\n");
849#define CCR_PR(n) printk(KERN_DEBUG "\t" #n " = \t%04x\n",\
850 tmio_ioread16(par->ccr + CCR_ ## n));
851 CCR_PR(CMD);
852 CCR_PR(REVID);
853 CCR_PR(BASEL);
854 CCR_PR(BASEH);
855 CCR_PR(UGCC);
856 CCR_PR(GCC);
857 CCR_PR(USC);
858 CCR_PR(VRAMRTC);
859 CCR_PR(VRAMSAC);
860 CCR_PR(VRAMBC);
861#undef CCR_PR
862
863 printk(KERN_DEBUG "lcr: \n");
864#define LCR_PR(n) printk(KERN_DEBUG "\t" #n " = \t%04x\n",\
865 tmio_ioread16(par->lcr + LCR_ ## n));
866 LCR_PR(UIS);
867 LCR_PR(VHPN);
868 LCR_PR(CFSAL);
869 LCR_PR(CFSAH);
870 LCR_PR(CFS);
871 LCR_PR(CFWS);
872 LCR_PR(BBIE);
873 LCR_PR(BBISC);
874 LCR_PR(CCS);
875 LCR_PR(BBES);
876 LCR_PR(CMDL);
877 LCR_PR(CMDH);
878 LCR_PR(CFC);
879 LCR_PR(CCIFC);
880 LCR_PR(HWT);
881 LCR_PR(LCDCCRC);
882 LCR_PR(LCDCC);
883 LCR_PR(LCDCOPC);
884 LCR_PR(LCDIS);
885 LCR_PR(LCDIM);
886 LCR_PR(LCDIE);
887 LCR_PR(GDSAL);
888 LCR_PR(GDSAH);
889 LCR_PR(VHPCL);
890 LCR_PR(VHPCH);
891 LCR_PR(GM);
892 LCR_PR(HT);
893 LCR_PR(HDS);
894 LCR_PR(HSS);
895 LCR_PR(HSE);
896 LCR_PR(HNP);
897 LCR_PR(VT);
898 LCR_PR(VDS);
899 LCR_PR(VSS);
900 LCR_PR(VSE);
901 LCR_PR(CDLN);
902 LCR_PR(ILN);
903 LCR_PR(SP);
904 LCR_PR(MISC);
905 LCR_PR(VIHSS);
906 LCR_PR(VIVS);
907 LCR_PR(VIVE);
908 LCR_PR(VIVSS);
909 LCR_PR(VCCIS);
910 LCR_PR(VIDWSAL);
911 LCR_PR(VIDWSAH);
912 LCR_PR(VIDRSAL);
913 LCR_PR(VIDRSAH);
914 LCR_PR(VIPDDST);
915 LCR_PR(VIPDDET);
916 LCR_PR(VIE);
917 LCR_PR(VCS);
918 LCR_PR(VPHWC);
919 LCR_PR(VPHS);
920 LCR_PR(VPVWC);
921 LCR_PR(VPVS);
922 LCR_PR(PLHPIX);
923 LCR_PR(XS);
924 LCR_PR(XCKHW);
925 LCR_PR(STHS);
926 LCR_PR(VT2);
927 LCR_PR(YCKSW);
928 LCR_PR(YSTS);
929 LCR_PR(PPOLS);
930 LCR_PR(PRECW);
931 LCR_PR(VCLKHW);
932 LCR_PR(OC);
933#undef LCR_PR
934}
935#endif
936
937#ifdef CONFIG_PM
938static int tmiofb_suspend(struct platform_device *dev, pm_message_t state)
939{
940 struct fb_info *info = platform_get_drvdata(dev);
941 struct tmiofb_par *par = info->par;
942 struct mfd_cell *cell = dev->dev.platform_data;
943 int retval = 0;
944
945 acquire_console_sem();
946
947 fb_set_suspend(info, 1);
948
949 if (info->fbops->fb_sync)
950 info->fbops->fb_sync(info);
951
952
953 /*
954 * The fb should be usable even if interrupts are disabled (and they are
955 * during suspend/resume). Switch temporary to forced polling.
956 */
957 printk(KERN_INFO "tmiofb: switching to polling\n");
958 par->use_polling = true;
959 tmiofb_hw_stop(dev);
960
961 if (cell->suspend)
962 retval = cell->suspend(dev);
963
964 release_console_sem();
965
966 return retval;
967}
968
969static int tmiofb_resume(struct platform_device *dev)
970{
971 struct fb_info *info = platform_get_drvdata(dev);
972 struct mfd_cell *cell = dev->dev.platform_data;
973 int retval;
974
975 acquire_console_sem();
976
977 if (cell->resume) {
978 retval = cell->resume(dev);
979 if (retval)
980 goto out;
981 }
982
983 tmiofb_irq(-1, info);
984
985 tmiofb_hw_init(dev);
986
987 tmiofb_hw_mode(dev);
988
989 fb_set_suspend(info, 0);
990out:
991 release_console_sem();
992 return retval;
993}
994#else
995#define tmiofb_suspend NULL
996#define tmiofb_resume NULL
997#endif
998
999static struct platform_driver tmiofb_driver = {
1000 .driver.name = "tmio-fb",
1001 .driver.owner = THIS_MODULE,
1002 .probe = tmiofb_probe,
1003 .remove = __devexit_p(tmiofb_remove),
1004 .suspend = tmiofb_suspend,
1005 .resume = tmiofb_resume,
1006};
1007
1008/*--------------------------------------------------------------------------*/
1009
1010#ifndef MODULE
1011static void __init tmiofb_setup(char *options)
1012{
1013 char *this_opt;
1014
1015 if (!options || !*options)
1016 return;
1017
1018 while ((this_opt = strsep(&options, ",")) != NULL) {
1019 if (!*this_opt)
1020 continue;
1021 /*
1022 * FIXME
1023 */
1024 }
1025}
1026#endif
1027
1028static int __init tmiofb_init(void)
1029{
1030#ifndef MODULE
1031 char *option = NULL;
1032
1033 if (fb_get_options("tmiofb", &option))
1034 return -ENODEV;
1035 tmiofb_setup(option);
1036#endif
1037 return platform_driver_register(&tmiofb_driver);
1038}
1039
1040static void __exit tmiofb_cleanup(void)
1041{
1042 platform_driver_unregister(&tmiofb_driver);
1043}
1044
1045module_init(tmiofb_init);
1046module_exit(tmiofb_cleanup);
1047
1048MODULE_DESCRIPTION("TMIO framebuffer driver");
1049MODULE_AUTHOR("Chris Humbert, Dirk Opfer, Dmitry Baryshkov");
1050MODULE_LICENSE("GPL");
diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
index 50744229c7a9..6c2d37fdd3b9 100644
--- a/drivers/video/uvesafb.c
+++ b/drivers/video/uvesafb.c
@@ -516,10 +516,12 @@ static int __devinit uvesafb_vbe_getmodes(struct uvesafb_ktask *task,
516 516
517 err = uvesafb_exec(task); 517 err = uvesafb_exec(task);
518 if (err || (task->t.regs.eax & 0xffff) != 0x004f) { 518 if (err || (task->t.regs.eax & 0xffff) != 0x004f) {
519 printk(KERN_ERR "uvesafb: Getting mode info block " 519 printk(KERN_WARNING "uvesafb: Getting mode info block "
520 "for mode 0x%x failed (eax=0x%x, err=%d)\n", 520 "for mode 0x%x failed (eax=0x%x, err=%d)\n",
521 *mode, (u32)task->t.regs.eax, err); 521 *mode, (u32)task->t.regs.eax, err);
522 return -EINVAL; 522 mode++;
523 par->vbe_modes_cnt--;
524 continue;
523 } 525 }
524 526
525 mib = task->buf; 527 mib = task->buf;
@@ -548,7 +550,10 @@ static int __devinit uvesafb_vbe_getmodes(struct uvesafb_ktask *task,
548 mib->depth = mib->bits_per_pixel; 550 mib->depth = mib->bits_per_pixel;
549 } 551 }
550 552
551 return 0; 553 if (par->vbe_modes_cnt > 0)
554 return 0;
555 else
556 return -EINVAL;
552} 557}
553 558
554/* 559/*
diff --git a/drivers/video/vga16fb.c b/drivers/video/vga16fb.c
index e31bca8a0cb2..5b2938903ac2 100644
--- a/drivers/video/vga16fb.c
+++ b/drivers/video/vga16fb.c
@@ -58,7 +58,6 @@ struct vga16fb_par {
58 unsigned char ClockingMode; /* Seq-Controller:01h */ 58 unsigned char ClockingMode; /* Seq-Controller:01h */
59 } vga_state; 59 } vga_state;
60 struct vgastate state; 60 struct vgastate state;
61 struct mutex open_lock;
62 unsigned int ref_count; 61 unsigned int ref_count;
63 int palette_blanked, vesa_blanked, mode, isVGA; 62 int palette_blanked, vesa_blanked, mode, isVGA;
64 u8 misc, pel_msk, vss, clkdiv; 63 u8 misc, pel_msk, vss, clkdiv;
@@ -286,7 +285,6 @@ static int vga16fb_open(struct fb_info *info, int user)
286{ 285{
287 struct vga16fb_par *par = info->par; 286 struct vga16fb_par *par = info->par;
288 287
289 mutex_lock(&par->open_lock);
290 if (!par->ref_count) { 288 if (!par->ref_count) {
291 memset(&par->state, 0, sizeof(struct vgastate)); 289 memset(&par->state, 0, sizeof(struct vgastate));
292 par->state.flags = VGA_SAVE_FONTS | VGA_SAVE_MODE | 290 par->state.flags = VGA_SAVE_FONTS | VGA_SAVE_MODE |
@@ -294,7 +292,6 @@ static int vga16fb_open(struct fb_info *info, int user)
294 save_vga(&par->state); 292 save_vga(&par->state);
295 } 293 }
296 par->ref_count++; 294 par->ref_count++;
297 mutex_unlock(&par->open_lock);
298 295
299 return 0; 296 return 0;
300} 297}
@@ -303,15 +300,12 @@ static int vga16fb_release(struct fb_info *info, int user)
303{ 300{
304 struct vga16fb_par *par = info->par; 301 struct vga16fb_par *par = info->par;
305 302
306 mutex_lock(&par->open_lock); 303 if (!par->ref_count)
307 if (!par->ref_count) {
308 mutex_unlock(&par->open_lock);
309 return -EINVAL; 304 return -EINVAL;
310 } 305
311 if (par->ref_count == 1) 306 if (par->ref_count == 1)
312 restore_vga(&par->state); 307 restore_vga(&par->state);
313 par->ref_count--; 308 par->ref_count--;
314 mutex_unlock(&par->open_lock);
315 309
316 return 0; 310 return 0;
317} 311}
@@ -1326,7 +1320,6 @@ static int __init vga16fb_probe(struct platform_device *dev)
1326 printk(KERN_INFO "vga16fb: mapped to 0x%p\n", info->screen_base); 1320 printk(KERN_INFO "vga16fb: mapped to 0x%p\n", info->screen_base);
1327 par = info->par; 1321 par = info->par;
1328 1322
1329 mutex_init(&par->open_lock);
1330 par->isVGA = screen_info.orig_video_isVGA; 1323 par->isVGA = screen_info.orig_video_isVGA;
1331 par->palette_blanked = 0; 1324 par->palette_blanked = 0;
1332 par->vesa_blanked = 0; 1325 par->vesa_blanked = 0;
diff --git a/drivers/video/via/Makefile b/drivers/video/via/Makefile
new file mode 100644
index 000000000000..e533b4b6aba4
--- /dev/null
+++ b/drivers/video/via/Makefile
@@ -0,0 +1,7 @@
1#
2# Makefile for the VIA framebuffer driver (for Linux Kernel 2.6)
3#
4
5obj-$(CONFIG_FB_VIA) += viafb.o
6
7viafb-y :=viafbdev.o hw.o iface.o via_i2c.o dvi.o lcd.o ioctl.o accel.o via_utility.o vt1636.o global.o tblDPASetting.o viamode.o tbl1636.o
diff --git a/drivers/video/via/accel.c b/drivers/video/via/accel.c
new file mode 100644
index 000000000000..632523ff1fb7
--- /dev/null
+++ b/drivers/video/via/accel.c
@@ -0,0 +1,279 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21#include "global.h"
22
23void viafb_init_accel(void)
24{
25 viaparinfo->fbmem_free -= CURSOR_SIZE;
26 viaparinfo->cursor_start = viaparinfo->fbmem_free;
27 viaparinfo->fbmem_used += CURSOR_SIZE;
28
29 /* Reverse 8*1024 memory space for cursor image */
30 viaparinfo->fbmem_free -= (CURSOR_SIZE + VQ_SIZE);
31 viaparinfo->VQ_start = viaparinfo->fbmem_free;
32 viaparinfo->VQ_end = viaparinfo->VQ_start + VQ_SIZE - 1;
33 viaparinfo->fbmem_used += (CURSOR_SIZE + VQ_SIZE); }
34
35void viafb_init_2d_engine(void)
36{
37 u32 dwVQStartAddr, dwVQEndAddr;
38 u32 dwVQLen, dwVQStartL, dwVQEndL, dwVQStartEndH;
39
40 /* init 2D engine regs to reset 2D engine */
41 writel(0x0, viaparinfo->io_virt + VIA_REG_GEMODE);
42 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCPOS);
43 writel(0x0, viaparinfo->io_virt + VIA_REG_DSTPOS);
44 writel(0x0, viaparinfo->io_virt + VIA_REG_DIMENSION);
45 writel(0x0, viaparinfo->io_virt + VIA_REG_PATADDR);
46 writel(0x0, viaparinfo->io_virt + VIA_REG_FGCOLOR);
47 writel(0x0, viaparinfo->io_virt + VIA_REG_BGCOLOR);
48 writel(0x0, viaparinfo->io_virt + VIA_REG_CLIPTL);
49 writel(0x0, viaparinfo->io_virt + VIA_REG_CLIPBR);
50 writel(0x0, viaparinfo->io_virt + VIA_REG_OFFSET);
51 writel(0x0, viaparinfo->io_virt + VIA_REG_KEYCONTROL);
52 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCBASE);
53 writel(0x0, viaparinfo->io_virt + VIA_REG_DSTBASE);
54 writel(0x0, viaparinfo->io_virt + VIA_REG_PITCH);
55 writel(0x0, viaparinfo->io_virt + VIA_REG_MONOPAT1);
56
57 /* Init AGP and VQ regs */
58 switch (viaparinfo->chip_info->gfx_chip_name) {
59 case UNICHROME_K8M890:
60 case UNICHROME_P4M900:
61 writel(0x00100000, viaparinfo->io_virt + VIA_REG_CR_TRANSET);
62 writel(0x680A0000, viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
63 writel(0x02000000, viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
64 break;
65
66 default:
67 writel(0x00100000, viaparinfo->io_virt + VIA_REG_TRANSET);
68 writel(0x00000000, viaparinfo->io_virt + VIA_REG_TRANSPACE);
69 writel(0x00333004, viaparinfo->io_virt + VIA_REG_TRANSPACE);
70 writel(0x60000000, viaparinfo->io_virt + VIA_REG_TRANSPACE);
71 writel(0x61000000, viaparinfo->io_virt + VIA_REG_TRANSPACE);
72 writel(0x62000000, viaparinfo->io_virt + VIA_REG_TRANSPACE);
73 writel(0x63000000, viaparinfo->io_virt + VIA_REG_TRANSPACE);
74 writel(0x64000000, viaparinfo->io_virt + VIA_REG_TRANSPACE);
75 writel(0x7D000000, viaparinfo->io_virt + VIA_REG_TRANSPACE);
76
77 writel(0xFE020000, viaparinfo->io_virt + VIA_REG_TRANSET);
78 writel(0x00000000, viaparinfo->io_virt + VIA_REG_TRANSPACE);
79 break;
80 }
81 if (viaparinfo->VQ_start != 0) {
82 /* Enable VQ */
83 dwVQStartAddr = viaparinfo->VQ_start;
84 dwVQEndAddr = viaparinfo->VQ_end;
85
86 dwVQStartL = 0x50000000 | (dwVQStartAddr & 0xFFFFFF);
87 dwVQEndL = 0x51000000 | (dwVQEndAddr & 0xFFFFFF);
88 dwVQStartEndH = 0x52000000 |
89 ((dwVQStartAddr & 0xFF000000) >> 24) |
90 ((dwVQEndAddr & 0xFF000000) >> 16);
91 dwVQLen = 0x53000000 | (VQ_SIZE >> 3);
92 switch (viaparinfo->chip_info->gfx_chip_name) {
93 case UNICHROME_K8M890:
94 case UNICHROME_P4M900:
95 dwVQStartL |= 0x20000000;
96 dwVQEndL |= 0x20000000;
97 dwVQStartEndH |= 0x20000000;
98 dwVQLen |= 0x20000000;
99 break;
100 default:
101 break;
102 }
103
104 switch (viaparinfo->chip_info->gfx_chip_name) {
105 case UNICHROME_K8M890:
106 case UNICHROME_P4M900:
107 writel(0x00100000,
108 viaparinfo->io_virt + VIA_REG_CR_TRANSET);
109 writel(dwVQStartEndH,
110 viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
111 writel(dwVQStartL,
112 viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
113 writel(dwVQEndL,
114 viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
115 writel(dwVQLen,
116 viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
117 writel(0x74301001,
118 viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
119 writel(0x00000000,
120 viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
121 break;
122 default:
123 writel(0x00FE0000,
124 viaparinfo->io_virt + VIA_REG_TRANSET);
125 writel(0x080003FE,
126 viaparinfo->io_virt + VIA_REG_TRANSPACE);
127 writel(0x0A00027C,
128 viaparinfo->io_virt + VIA_REG_TRANSPACE);
129 writel(0x0B000260,
130 viaparinfo->io_virt + VIA_REG_TRANSPACE);
131 writel(0x0C000274,
132 viaparinfo->io_virt + VIA_REG_TRANSPACE);
133 writel(0x0D000264,
134 viaparinfo->io_virt + VIA_REG_TRANSPACE);
135 writel(0x0E000000,
136 viaparinfo->io_virt + VIA_REG_TRANSPACE);
137 writel(0x0F000020,
138 viaparinfo->io_virt + VIA_REG_TRANSPACE);
139 writel(0x1000027E,
140 viaparinfo->io_virt + VIA_REG_TRANSPACE);
141 writel(0x110002FE,
142 viaparinfo->io_virt + VIA_REG_TRANSPACE);
143 writel(0x200F0060,
144 viaparinfo->io_virt + VIA_REG_TRANSPACE);
145
146 writel(0x00000006,
147 viaparinfo->io_virt + VIA_REG_TRANSPACE);
148 writel(0x40008C0F,
149 viaparinfo->io_virt + VIA_REG_TRANSPACE);
150 writel(0x44000000,
151 viaparinfo->io_virt + VIA_REG_TRANSPACE);
152 writel(0x45080C04,
153 viaparinfo->io_virt + VIA_REG_TRANSPACE);
154 writel(0x46800408,
155 viaparinfo->io_virt + VIA_REG_TRANSPACE);
156
157 writel(dwVQStartEndH,
158 viaparinfo->io_virt + VIA_REG_TRANSPACE);
159 writel(dwVQStartL,
160 viaparinfo->io_virt + VIA_REG_TRANSPACE);
161 writel(dwVQEndL,
162 viaparinfo->io_virt + VIA_REG_TRANSPACE);
163 writel(dwVQLen,
164 viaparinfo->io_virt + VIA_REG_TRANSPACE);
165 break;
166 }
167 } else {
168 /* Disable VQ */
169 switch (viaparinfo->chip_info->gfx_chip_name) {
170 case UNICHROME_K8M890:
171 case UNICHROME_P4M900:
172 writel(0x00100000,
173 viaparinfo->io_virt + VIA_REG_CR_TRANSET);
174 writel(0x74301000,
175 viaparinfo->io_virt + VIA_REG_CR_TRANSPACE);
176 break;
177 default:
178 writel(0x00FE0000,
179 viaparinfo->io_virt + VIA_REG_TRANSET);
180 writel(0x00000004,
181 viaparinfo->io_virt + VIA_REG_TRANSPACE);
182 writel(0x40008C0F,
183 viaparinfo->io_virt + VIA_REG_TRANSPACE);
184 writel(0x44000000,
185 viaparinfo->io_virt + VIA_REG_TRANSPACE);
186 writel(0x45080C04,
187 viaparinfo->io_virt + VIA_REG_TRANSPACE);
188 writel(0x46800408,
189 viaparinfo->io_virt + VIA_REG_TRANSPACE);
190 break;
191 }
192 }
193
194 viafb_set_2d_color_depth(viaparinfo->bpp);
195
196 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCBASE);
197 writel(0x0, viaparinfo->io_virt + VIA_REG_DSTBASE);
198
199 writel(VIA_PITCH_ENABLE |
200 (((viaparinfo->hres *
201 viaparinfo->bpp >> 3) >> 3) | (((viaparinfo->hres *
202 viaparinfo->
203 bpp >> 3) >> 3) << 16)),
204 viaparinfo->io_virt + VIA_REG_PITCH);
205}
206
207void viafb_set_2d_color_depth(int bpp)
208{
209 u32 dwGEMode;
210
211 dwGEMode = readl(viaparinfo->io_virt + 0x04) & 0xFFFFFCFF;
212
213 switch (bpp) {
214 case 16:
215 dwGEMode |= VIA_GEM_16bpp;
216 break;
217 case 32:
218 dwGEMode |= VIA_GEM_32bpp;
219 break;
220 default:
221 dwGEMode |= VIA_GEM_8bpp;
222 break;
223 }
224
225 /* Set BPP and Pitch */
226 writel(dwGEMode, viaparinfo->io_virt + VIA_REG_GEMODE);
227}
228
229void viafb_hw_cursor_init(void)
230{
231 /* Set Cursor Image Base Address */
232 writel(viaparinfo->cursor_start,
233 viaparinfo->io_virt + VIA_REG_CURSOR_MODE);
234 writel(0x0, viaparinfo->io_virt + VIA_REG_CURSOR_POS);
235 writel(0x0, viaparinfo->io_virt + VIA_REG_CURSOR_ORG);
236 writel(0x0, viaparinfo->io_virt + VIA_REG_CURSOR_BG);
237 writel(0x0, viaparinfo->io_virt + VIA_REG_CURSOR_FG);
238}
239
240void viafb_show_hw_cursor(struct fb_info *info, int Status)
241{
242 u32 temp;
243 u32 iga_path = ((struct viafb_par *)(info->par))->iga_path;
244
245 temp = readl(viaparinfo->io_virt + VIA_REG_CURSOR_MODE);
246 switch (Status) {
247 case HW_Cursor_ON:
248 temp |= 0x1;
249 break;
250 case HW_Cursor_OFF:
251 temp &= 0xFFFFFFFE;
252 break;
253 }
254 switch (iga_path) {
255 case IGA2:
256 temp |= 0x80000000;
257 break;
258 case IGA1:
259 default:
260 temp &= 0x7FFFFFFF;
261 }
262 writel(temp, viaparinfo->io_virt + VIA_REG_CURSOR_MODE);
263}
264
265int viafb_wait_engine_idle(void)
266{
267 int loop = 0;
268
269 while (!(readl(viaparinfo->io_virt + VIA_REG_STATUS) &
270 VIA_VR_QUEUE_BUSY) && (loop++ < MAXLOOP))
271 cpu_relax();
272
273 while ((readl(viaparinfo->io_virt + VIA_REG_STATUS) &
274 (VIA_CMD_RGTR_BUSY | VIA_2D_ENG_BUSY | VIA_3D_ENG_BUSY)) &&
275 (loop++ < MAXLOOP))
276 cpu_relax();
277
278 return loop >= MAXLOOP;
279}
diff --git a/drivers/video/via/accel.h b/drivers/video/via/accel.h
new file mode 100644
index 000000000000..29bf854e8ccf
--- /dev/null
+++ b/drivers/video/via/accel.h
@@ -0,0 +1,169 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#ifndef __ACCEL_H__
23#define __ACCEL_H__
24
25#define FB_ACCEL_VIA_UNICHROME 50
26
27/* MMIO Base Address Definition */
28#define MMIO_VGABASE 0x8000
29#define MMIO_CR_READ (MMIO_VGABASE + 0x3D4)
30#define MMIO_CR_WRITE (MMIO_VGABASE + 0x3D5)
31#define MMIO_SR_READ (MMIO_VGABASE + 0x3C4)
32#define MMIO_SR_WRITE (MMIO_VGABASE + 0x3C5)
33
34/* HW Cursor Status Define */
35#define HW_Cursor_ON 0
36#define HW_Cursor_OFF 1
37
38#define CURSOR_SIZE (8 * 1024)
39#define VQ_SIZE (256 * 1024)
40
41#define VIA_MMIO_BLTBASE 0x200000
42#define VIA_MMIO_BLTSIZE 0x200000
43
44/* Defines for 2D registers */
45#define VIA_REG_GECMD 0x000
46#define VIA_REG_GEMODE 0x004
47#define VIA_REG_SRCPOS 0x008
48#define VIA_REG_DSTPOS 0x00C
49/* width and height */
50#define VIA_REG_DIMENSION 0x010
51#define VIA_REG_PATADDR 0x014
52#define VIA_REG_FGCOLOR 0x018
53#define VIA_REG_BGCOLOR 0x01C
54/* top and left of clipping */
55#define VIA_REG_CLIPTL 0x020
56/* bottom and right of clipping */
57#define VIA_REG_CLIPBR 0x024
58#define VIA_REG_OFFSET 0x028
59/* color key control */
60#define VIA_REG_KEYCONTROL 0x02C
61#define VIA_REG_SRCBASE 0x030
62#define VIA_REG_DSTBASE 0x034
63/* pitch of src and dst */
64#define VIA_REG_PITCH 0x038
65#define VIA_REG_MONOPAT0 0x03C
66#define VIA_REG_MONOPAT1 0x040
67/* from 0x100 to 0x1ff */
68#define VIA_REG_COLORPAT 0x100
69
70/* VIA_REG_PITCH(0x38): Pitch Setting */
71#define VIA_PITCH_ENABLE 0x80000000
72
73/* defines for VIA HW cursor registers */
74#define VIA_REG_CURSOR_MODE 0x2D0
75#define VIA_REG_CURSOR_POS 0x2D4
76#define VIA_REG_CURSOR_ORG 0x2D8
77#define VIA_REG_CURSOR_BG 0x2DC
78#define VIA_REG_CURSOR_FG 0x2E0
79
80/* VIA_REG_GEMODE(0x04): GE mode */
81#define VIA_GEM_8bpp 0x00000000
82#define VIA_GEM_16bpp 0x00000100
83#define VIA_GEM_32bpp 0x00000300
84
85/* VIA_REG_GECMD(0x00): 2D Engine Command */
86#define VIA_GEC_NOOP 0x00000000
87#define VIA_GEC_BLT 0x00000001
88#define VIA_GEC_LINE 0x00000005
89
90/* Rotate Command */
91#define VIA_GEC_ROT 0x00000008
92
93#define VIA_GEC_SRC_XY 0x00000000
94#define VIA_GEC_SRC_LINEAR 0x00000010
95#define VIA_GEC_DST_XY 0x00000000
96#define VIA_GEC_DST_LINRAT 0x00000020
97
98#define VIA_GEC_SRC_FB 0x00000000
99#define VIA_GEC_SRC_SYS 0x00000040
100#define VIA_GEC_DST_FB 0x00000000
101#define VIA_GEC_DST_SYS 0x00000080
102
103/* source is mono */
104#define VIA_GEC_SRC_MONO 0x00000100
105/* pattern is mono */
106#define VIA_GEC_PAT_MONO 0x00000200
107/* mono src is opaque */
108#define VIA_GEC_MSRC_OPAQUE 0x00000000
109/* mono src is transparent */
110#define VIA_GEC_MSRC_TRANS 0x00000400
111/* pattern is in frame buffer */
112#define VIA_GEC_PAT_FB 0x00000000
113/* pattern is from reg setting */
114#define VIA_GEC_PAT_REG 0x00000800
115
116#define VIA_GEC_CLIP_DISABLE 0x00000000
117#define VIA_GEC_CLIP_ENABLE 0x00001000
118
119#define VIA_GEC_FIXCOLOR_PAT 0x00002000
120
121#define VIA_GEC_INCX 0x00000000
122#define VIA_GEC_DECY 0x00004000
123#define VIA_GEC_INCY 0x00000000
124#define VIA_GEC_DECX 0x00008000
125/* mono pattern is opaque */
126#define VIA_GEC_MPAT_OPAQUE 0x00000000
127/* mono pattern is transparent */
128#define VIA_GEC_MPAT_TRANS 0x00010000
129
130#define VIA_GEC_MONO_UNPACK 0x00000000
131#define VIA_GEC_MONO_PACK 0x00020000
132#define VIA_GEC_MONO_DWORD 0x00000000
133#define VIA_GEC_MONO_WORD 0x00040000
134#define VIA_GEC_MONO_BYTE 0x00080000
135
136#define VIA_GEC_LASTPIXEL_ON 0x00000000
137#define VIA_GEC_LASTPIXEL_OFF 0x00100000
138#define VIA_GEC_X_MAJOR 0x00000000
139#define VIA_GEC_Y_MAJOR 0x00200000
140#define VIA_GEC_QUICK_START 0x00800000
141
142/* defines for VIA 3D registers */
143#define VIA_REG_STATUS 0x400
144#define VIA_REG_CR_TRANSET 0x41C
145#define VIA_REG_CR_TRANSPACE 0x420
146#define VIA_REG_TRANSET 0x43C
147#define VIA_REG_TRANSPACE 0x440
148
149/* VIA_REG_STATUS(0x400): Engine Status */
150
151/* Command Regulator is busy */
152#define VIA_CMD_RGTR_BUSY 0x00000080
153/* 2D Engine is busy */
154#define VIA_2D_ENG_BUSY 0x00000002
155/* 3D Engine is busy */
156#define VIA_3D_ENG_BUSY 0x00000001
157/* Virtual Queue is busy */
158#define VIA_VR_QUEUE_BUSY 0x00020000
159
160#define MAXLOOP 0xFFFFFF
161
162void viafb_init_accel(void);
163void viafb_init_2d_engine(void);
164void set_2d_color_depth(int);
165void viafb_hw_cursor_init(void);
166void viafb_show_hw_cursor(struct fb_info *info, int Status); int
167viafb_wait_engine_idle(void); void viafb_set_2d_color_depth(int bpp);
168
169#endif /* __ACCEL_H__ */
diff --git a/drivers/video/via/chip.h b/drivers/video/via/chip.h
new file mode 100644
index 000000000000..dde95edc387a
--- /dev/null
+++ b/drivers/video/via/chip.h
@@ -0,0 +1,190 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21#ifndef __CHIP_H__
22#define __CHIP_H__
23
24#include "global.h"
25
26/***************************************/
27/* Definition Graphic Chip Information */
28/***************************************/
29
30#define PCI_VIA_VENDOR_ID 0x1106
31
32/* Define VIA Graphic Chip Name */
33#define UNICHROME_CLE266 1
34#define UNICHROME_CLE266_DID 0x3122
35#define CLE266_REVISION_AX 0x0A
36#define CLE266_REVISION_CX 0x0C
37
38#define UNICHROME_K400 2
39#define UNICHROME_K400_DID 0x7205
40
41#define UNICHROME_K800 3
42#define UNICHROME_K800_DID 0x3108
43
44#define UNICHROME_PM800 4
45#define UNICHROME_PM800_DID 0x3118
46
47#define UNICHROME_CN700 5
48#define UNICHROME_CN700_DID 0x3344
49
50#define UNICHROME_CX700 6
51#define UNICHROME_CX700_DID 0x3157
52#define CX700_REVISION_700 0x0
53#define CX700_REVISION_700M 0x1
54#define CX700_REVISION_700M2 0x2
55
56#define UNICHROME_CN750 7
57#define UNICHROME_CN750_DID 0x3225
58
59#define UNICHROME_K8M890 8
60#define UNICHROME_K8M890_DID 0x3230
61
62#define UNICHROME_P4M890 9
63#define UNICHROME_P4M890_DID 0x3343
64
65#define UNICHROME_P4M900 10
66#define UNICHROME_P4M900_DID 0x3371
67
68#define UNICHROME_VX800 11
69#define UNICHROME_VX800_DID 0x1122
70
71/**************************************************/
72/* Definition TMDS Trasmitter Information */
73/**************************************************/
74
75/* Definition TMDS Trasmitter Index */
76#define NON_TMDS_TRANSMITTER 0x00
77#define VT1632_TMDS 0x01
78#define INTEGRATED_TMDS 0x42
79
80/* Definition TMDS Trasmitter I2C Slave Address */
81#define VT1632_TMDS_I2C_ADDR 0x10
82
83/**************************************************/
84/* Definition LVDS Trasmitter Information */
85/**************************************************/
86
87/* Definition LVDS Trasmitter Index */
88#define NON_LVDS_TRANSMITTER 0x00
89#define VT1631_LVDS 0x01
90#define VT1636_LVDS 0x0E
91#define INTEGRATED_LVDS 0x41
92
93/* Definition Digital Transmitter Mode */
94#define TX_DATA_12_BITS 0x01
95#define TX_DATA_24_BITS 0x02
96#define TX_DATA_DDR_MODE 0x04
97#define TX_DATA_SDR_MODE 0x08
98
99/* Definition LVDS Trasmitter I2C Slave Address */
100#define VT1631_LVDS_I2C_ADDR 0x70
101#define VT3271_LVDS_I2C_ADDR 0x80
102#define VT1636_LVDS_I2C_ADDR 0x80
103
104struct tmds_chip_information {
105 int tmds_chip_name;
106 int tmds_chip_slave_addr;
107 int dvi_panel_id;
108 int data_mode;
109 int output_interface;
110 int i2c_port;
111 int device_type;
112};
113
114struct lvds_chip_information {
115 int lvds_chip_name;
116 int lvds_chip_slave_addr;
117 int data_mode;
118 int output_interface;
119 int i2c_port;
120};
121
122struct chip_information {
123 int gfx_chip_name;
124 int gfx_chip_revision;
125 int chip_on_slot;
126 struct tmds_chip_information tmds_chip_info;
127 struct lvds_chip_information lvds_chip_info;
128 struct lvds_chip_information lvds_chip_info2;
129};
130
131struct crt_setting_information {
132 int iga_path;
133 int h_active;
134 int v_active;
135 int bpp;
136 int refresh_rate;
137};
138
139struct tmds_setting_information {
140 int iga_path;
141 int h_active;
142 int v_active;
143 int bpp;
144 int refresh_rate;
145 int get_dvi_size_method;
146 int max_pixel_clock;
147 int dvi_panel_size;
148 int dvi_panel_hres;
149 int dvi_panel_vres;
150 int native_size;
151};
152
153struct lvds_setting_information {
154 int iga_path;
155 int h_active;
156 int v_active;
157 int bpp;
158 int refresh_rate;
159 int get_lcd_size_method;
160 int lcd_panel_id;
161 int lcd_panel_size;
162 int lcd_panel_hres;
163 int lcd_panel_vres;
164 int display_method;
165 int device_lcd_dualedge;
166 int LCDDithering;
167 int lcd_mode;
168 u32 vclk; /*panel mode clock value */
169};
170
171struct GFX_DPA_SETTING {
172 int ClkRangeIndex;
173 u8 DVP0; /* CR96[3:0] */
174 u8 DVP0DataDri_S1; /* SR2A[5] */
175 u8 DVP0DataDri_S; /* SR1B[1] */
176 u8 DVP0ClockDri_S1; /* SR2A[4] */
177 u8 DVP0ClockDri_S; /* SR1E[2] */
178 u8 DVP1; /* CR9B[3:0] */
179 u8 DVP1Driving; /* SR65[3:0], Data and Clock driving */
180 u8 DFPHigh; /* CR97[3:0] */
181 u8 DFPLow; /* CR99[3:0] */
182
183};
184
185struct VT1636_DPA_SETTING {
186 int PanelSizeID;
187 u8 CLK_SEL_ST1;
188 u8 CLK_SEL_ST2;
189};
190#endif /* __CHIP_H__ */
diff --git a/drivers/video/via/debug.h b/drivers/video/via/debug.h
new file mode 100644
index 000000000000..86eacc2017f3
--- /dev/null
+++ b/drivers/video/via/debug.h
@@ -0,0 +1,41 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21#ifndef __DEBUG_H__
22#define __DEBUG_H__
23
24#ifndef VIAFB_DEBUG
25#define VIAFB_DEBUG 0
26#endif
27
28#if VIAFB_DEBUG
29#define DEBUG_MSG(f, a...) printk(f, ## a)
30#else
31#define DEBUG_MSG(f, a...)
32#endif
33
34#define VIAFB_WARN 0
35#if VIAFB_WARN
36#define WARN_MSG(f, a...) printk(f, ## a)
37#else
38#define WARN_MSG(f, a...)
39#endif
40
41#endif /* __DEBUG_H__ */
diff --git a/drivers/video/via/dvi.c b/drivers/video/via/dvi.c
new file mode 100644
index 000000000000..d6965447ca69
--- /dev/null
+++ b/drivers/video/via/dvi.c
@@ -0,0 +1,682 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21#include "global.h"
22
23static void tmds_register_write(int index, u8 data);
24static int tmds_register_read(int index);
25static int tmds_register_read_bytes(int index, u8 *buff, int buff_len);
26static int check_reduce_blanking_mode(int mode_index,
27 int refresh_rate);
28static int dvi_get_panel_size_from_DDCv1(void);
29static int dvi_get_panel_size_from_DDCv2(void);
30static unsigned char dvi_get_panel_info(void);
31static int viafb_dvi_query_EDID(void);
32
33static int check_tmds_chip(int device_id_subaddr, int device_id)
34{
35 if (tmds_register_read(device_id_subaddr) == device_id)
36 return OK;
37 else
38 return FAIL;
39}
40
41void viafb_init_dvi_size(void)
42{
43 DEBUG_MSG(KERN_INFO "viafb_init_dvi_size()\n");
44 DEBUG_MSG(KERN_INFO
45 "viaparinfo->tmds_setting_info->get_dvi_size_method %d\n",
46 viaparinfo->tmds_setting_info->get_dvi_size_method);
47
48 switch (viaparinfo->tmds_setting_info->get_dvi_size_method) {
49 case GET_DVI_SIZE_BY_SYSTEM_BIOS:
50 break;
51 case GET_DVI_SZIE_BY_HW_STRAPPING:
52 break;
53 case GET_DVI_SIZE_BY_VGA_BIOS:
54 default:
55 dvi_get_panel_info();
56 break;
57 }
58 return;
59}
60
61int viafb_tmds_trasmitter_identify(void)
62{
63 unsigned char sr2a = 0, sr1e = 0, sr3e = 0;
64
65 /* Turn on ouputting pad */
66 switch (viaparinfo->chip_info->gfx_chip_name) {
67 case UNICHROME_K8M890:
68 /*=* DFP Low Pad on *=*/
69 sr2a = viafb_read_reg(VIASR, SR2A);
70 viafb_write_reg_mask(SR2A, VIASR, 0x03, BIT0 + BIT1);
71 break;
72
73 case UNICHROME_P4M900:
74 case UNICHROME_P4M890:
75 /* DFP Low Pad on */
76 sr2a = viafb_read_reg(VIASR, SR2A);
77 viafb_write_reg_mask(SR2A, VIASR, 0x03, BIT0 + BIT1);
78 /* DVP0 Pad on */
79 sr1e = viafb_read_reg(VIASR, SR1E);
80 viafb_write_reg_mask(SR1E, VIASR, 0xC0, BIT6 + BIT7);
81 break;
82
83 default:
84 /* DVP0/DVP1 Pad on */
85 sr1e = viafb_read_reg(VIASR, SR1E);
86 viafb_write_reg_mask(SR1E, VIASR, 0xF0, BIT4 +
87 BIT5 + BIT6 + BIT7);
88 /* SR3E[1]Multi-function selection:
89 0 = Emulate I2C and DDC bus by GPIO2/3/4. */
90 sr3e = viafb_read_reg(VIASR, SR3E);
91 viafb_write_reg_mask(SR3E, VIASR, 0x0, BIT5);
92 break;
93 }
94
95 /* Check for VT1632: */
96 viaparinfo->chip_info->tmds_chip_info.tmds_chip_name = VT1632_TMDS;
97 viaparinfo->chip_info->
98 tmds_chip_info.tmds_chip_slave_addr = VT1632_TMDS_I2C_ADDR;
99 viaparinfo->chip_info->tmds_chip_info.i2c_port = I2CPORTINDEX;
100 if (check_tmds_chip(VT1632_DEVICE_ID_REG, VT1632_DEVICE_ID) != FAIL) {
101 /*
102 * Currently only support 12bits,dual edge,add 24bits mode later
103 */
104 tmds_register_write(0x08, 0x3b);
105
106 DEBUG_MSG(KERN_INFO "\n VT1632 TMDS ! \n");
107 DEBUG_MSG(KERN_INFO "\n %2d",
108 viaparinfo->chip_info->tmds_chip_info.tmds_chip_name);
109 DEBUG_MSG(KERN_INFO "\n %2d",
110 viaparinfo->chip_info->tmds_chip_info.i2c_port);
111 return OK;
112 } else {
113 viaparinfo->chip_info->tmds_chip_info.i2c_port = GPIOPORTINDEX;
114 if (check_tmds_chip(VT1632_DEVICE_ID_REG, VT1632_DEVICE_ID)
115 != FAIL) {
116 tmds_register_write(0x08, 0x3b);
117 DEBUG_MSG(KERN_INFO "\n VT1632 TMDS ! \n");
118 DEBUG_MSG(KERN_INFO "\n %2d",
119 viaparinfo->chip_info->
120 tmds_chip_info.tmds_chip_name);
121 DEBUG_MSG(KERN_INFO "\n %2d",
122 viaparinfo->chip_info->
123 tmds_chip_info.i2c_port);
124 return OK;
125 }
126 }
127
128 viaparinfo->chip_info->tmds_chip_info.tmds_chip_name = INTEGRATED_TMDS;
129
130 if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700) &&
131 ((viafb_display_hardware_layout == HW_LAYOUT_DVI_ONLY) ||
132 (viafb_display_hardware_layout == HW_LAYOUT_LCD_DVI))) {
133 DEBUG_MSG(KERN_INFO "\n Integrated TMDS ! \n");
134 return OK;
135 }
136
137 switch (viaparinfo->chip_info->gfx_chip_name) {
138 case UNICHROME_K8M890:
139 viafb_write_reg(SR2A, VIASR, sr2a);
140 break;
141
142 case UNICHROME_P4M900:
143 case UNICHROME_P4M890:
144 viafb_write_reg(SR2A, VIASR, sr2a);
145 viafb_write_reg(SR1E, VIASR, sr1e);
146 break;
147
148 default:
149 viafb_write_reg(SR1E, VIASR, sr1e);
150 viafb_write_reg(SR3E, VIASR, sr3e);
151 break;
152 }
153
154 viaparinfo->chip_info->
155 tmds_chip_info.tmds_chip_name = NON_TMDS_TRANSMITTER;
156 viaparinfo->chip_info->tmds_chip_info.
157 tmds_chip_slave_addr = VT1632_TMDS_I2C_ADDR;
158 return FAIL;
159}
160
161static void tmds_register_write(int index, u8 data)
162{
163 viaparinfo->i2c_stuff.i2c_port =
164 viaparinfo->chip_info->tmds_chip_info.i2c_port;
165
166 viafb_i2c_writebyte(viaparinfo->chip_info->tmds_chip_info.
167 tmds_chip_slave_addr, index,
168 data);
169}
170
171static int tmds_register_read(int index)
172{
173 u8 data;
174
175 viaparinfo->i2c_stuff.i2c_port =
176 viaparinfo->chip_info->tmds_chip_info.i2c_port;
177 viafb_i2c_readbyte((u8) viaparinfo->chip_info->
178 tmds_chip_info.tmds_chip_slave_addr,
179 (u8) index, &data);
180 return data;
181}
182
183static int tmds_register_read_bytes(int index, u8 *buff, int buff_len)
184{
185 viaparinfo->i2c_stuff.i2c_port =
186 viaparinfo->chip_info->tmds_chip_info.i2c_port;
187 viafb_i2c_readbytes((u8) viaparinfo->chip_info->tmds_chip_info.
188 tmds_chip_slave_addr, (u8) index, buff, buff_len);
189 return 0;
190}
191
192static int check_reduce_blanking_mode(int mode_index,
193 int refresh_rate)
194{
195 if (refresh_rate != 60)
196 return false;
197
198 switch (mode_index) {
199 /* Following modes have reduce blanking mode. */
200 case VIA_RES_1360X768:
201 case VIA_RES_1400X1050:
202 case VIA_RES_1440X900:
203 case VIA_RES_1600X900:
204 case VIA_RES_1680X1050:
205 case VIA_RES_1920X1080:
206 case VIA_RES_1920X1200:
207 break;
208
209 default:
210 DEBUG_MSG(KERN_INFO
211 "This dvi mode %d have no reduce blanking mode!\n",
212 mode_index);
213 return false;
214 }
215
216 return true;
217}
218
219/* DVI Set Mode */
220void viafb_dvi_set_mode(int video_index, int mode_bpp, int set_iga)
221{
222 struct VideoModeTable *videoMode = NULL;
223 struct crt_mode_table *pDviTiming;
224 unsigned long desirePixelClock, maxPixelClock;
225 int status = 0;
226 videoMode = viafb_get_modetbl_pointer(video_index);
227 pDviTiming = videoMode->crtc;
228 desirePixelClock = pDviTiming->clk / 1000000;
229 maxPixelClock = (unsigned long)viaparinfo->
230 tmds_setting_info->max_pixel_clock;
231
232 DEBUG_MSG(KERN_INFO "\nDVI_set_mode!!\n");
233
234 if ((maxPixelClock != 0) && (desirePixelClock > maxPixelClock)) {
235 /*Check if reduce-blanking mode is exist */
236 status =
237 check_reduce_blanking_mode(video_index,
238 pDviTiming->refresh_rate);
239 if (status) {
240 video_index += 100; /*Use reduce-blanking mode */
241 videoMode = viafb_get_modetbl_pointer(video_index);
242 pDviTiming = videoMode->crtc;
243 DEBUG_MSG(KERN_INFO
244 "DVI use reduce blanking mode %d!!\n",
245 video_index);
246 }
247 }
248 viafb_fill_crtc_timing(pDviTiming, video_index, mode_bpp / 8, set_iga);
249 viafb_set_output_path(DEVICE_DVI, set_iga,
250 viaparinfo->chip_info->tmds_chip_info.output_interface);
251}
252
253/* Sense DVI Connector */
254int viafb_dvi_sense(void)
255{
256 u8 RegSR1E = 0, RegSR3E = 0, RegCR6B = 0, RegCR91 = 0,
257 RegCR93 = 0, RegCR9B = 0, data;
258 int ret = false;
259
260 DEBUG_MSG(KERN_INFO "viafb_dvi_sense!!\n");
261
262 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
263 /* DI1 Pad on */
264 RegSR1E = viafb_read_reg(VIASR, SR1E);
265 viafb_write_reg(SR1E, VIASR, RegSR1E | 0x30);
266
267 /* CR6B[0]VCK Input Selection: 1 = External clock. */
268 RegCR6B = viafb_read_reg(VIACR, CR6B);
269 viafb_write_reg(CR6B, VIACR, RegCR6B | 0x08);
270
271 /* CR91[4] VDD On [3] Data On [2] VEE On [1] Back Light Off
272 [0] Software Control Power Sequence */
273 RegCR91 = viafb_read_reg(VIACR, CR91);
274 viafb_write_reg(CR91, VIACR, 0x1D);
275
276 /* CR93[7] DI1 Data Source Selection: 1 = DSP2.
277 CR93[5] DI1 Clock Source: 1 = internal.
278 CR93[4] DI1 Clock Polarity.
279 CR93[3:1] DI1 Clock Adjust. CR93[0] DI1 enable */
280 RegCR93 = viafb_read_reg(VIACR, CR93);
281 viafb_write_reg(CR93, VIACR, 0x01);
282 } else {
283 /* DVP0/DVP1 Pad on */
284 RegSR1E = viafb_read_reg(VIASR, SR1E);
285 viafb_write_reg(SR1E, VIASR, RegSR1E | 0xF0);
286
287 /* SR3E[1]Multi-function selection:
288 0 = Emulate I2C and DDC bus by GPIO2/3/4. */
289 RegSR3E = viafb_read_reg(VIASR, SR3E);
290 viafb_write_reg(SR3E, VIASR, RegSR3E & (~0x20));
291
292 /* CR91[4] VDD On [3] Data On [2] VEE On [1] Back Light Off
293 [0] Software Control Power Sequence */
294 RegCR91 = viafb_read_reg(VIACR, CR91);
295 viafb_write_reg(CR91, VIACR, 0x1D);
296
297 /*CR9B[4] DVP1 Data Source Selection: 1 = From secondary
298 display.CR9B[2:0] DVP1 Clock Adjust */
299 RegCR9B = viafb_read_reg(VIACR, CR9B);
300 viafb_write_reg(CR9B, VIACR, 0x01);
301 }
302
303 data = (u8) tmds_register_read(0x09);
304 if (data & 0x04)
305 ret = true;
306
307 if (ret == false) {
308 if (viafb_dvi_query_EDID())
309 ret = true;
310 }
311
312 /* Restore status */
313 viafb_write_reg(SR1E, VIASR, RegSR1E);
314 viafb_write_reg(CR91, VIACR, RegCR91);
315 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
316 viafb_write_reg(CR6B, VIACR, RegCR6B);
317 viafb_write_reg(CR93, VIACR, RegCR93);
318 } else {
319 viafb_write_reg(SR3E, VIASR, RegSR3E);
320 viafb_write_reg(CR9B, VIACR, RegCR9B);
321 }
322
323 return ret;
324}
325
326/* Query Flat Panel's EDID Table Version Through DVI Connector */
327static int viafb_dvi_query_EDID(void)
328{
329 u8 data0, data1;
330 int restore;
331
332 DEBUG_MSG(KERN_INFO "viafb_dvi_query_EDID!!\n");
333
334 restore = viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr;
335 viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr = 0xA0;
336
337 data0 = (u8) tmds_register_read(0x00);
338 data1 = (u8) tmds_register_read(0x01);
339 if ((data0 == 0) && (data1 == 0xFF)) {
340 viaparinfo->chip_info->
341 tmds_chip_info.tmds_chip_slave_addr = restore;
342 return EDID_VERSION_1; /* Found EDID1 Table */
343 }
344
345 data0 = (u8) tmds_register_read(0x00);
346 viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr = restore;
347 if (data0 == 0x20)
348 return EDID_VERSION_2; /* Found EDID2 Table */
349 else
350 return false;
351}
352
353/*
354 *
355 * int dvi_get_panel_size_from_DDCv1(void)
356 *
357 * - Get Panel Size Using EDID1 Table
358 *
359 * Return Type: int
360 *
361 */
362static int dvi_get_panel_size_from_DDCv1(void)
363{
364 int i, max_h = 0, max_v = 0, tmp, restore;
365 unsigned char rData;
366 unsigned char EDID_DATA[18];
367
368 DEBUG_MSG(KERN_INFO "\n dvi_get_panel_size_from_DDCv1 \n");
369
370 restore = viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr;
371 viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr = 0xA0;
372
373 rData = tmds_register_read(0x23);
374 if (rData & 0x3C)
375 max_h = 640;
376 if (rData & 0xC0)
377 max_h = 720;
378 if (rData & 0x03)
379 max_h = 800;
380
381 rData = tmds_register_read(0x24);
382 if (rData & 0xC0)
383 max_h = 800;
384 if (rData & 0x1E)
385 max_h = 1024;
386 if (rData & 0x01)
387 max_h = 1280;
388
389 for (i = 0x25; i < 0x6D; i++) {
390 switch (i) {
391 case 0x26:
392 case 0x28:
393 case 0x2A:
394 case 0x2C:
395 case 0x2E:
396 case 0x30:
397 case 0x32:
398 case 0x34:
399 rData = tmds_register_read(i);
400 if (rData == 1)
401 break;
402 /* data = (data + 31) * 8 */
403 tmp = (rData + 31) << 3;
404 if (tmp > max_h)
405 max_h = tmp;
406 break;
407
408 case 0x36:
409 case 0x48:
410 case 0x5A:
411 case 0x6C:
412 tmds_register_read_bytes(i, EDID_DATA, 10);
413 if (!(EDID_DATA[0] || EDID_DATA[1])) {
414 /* The first two byte must be zero. */
415 if (EDID_DATA[3] == 0xFD) {
416 /* To get max pixel clock. */
417 viaparinfo->tmds_setting_info->
418 max_pixel_clock = EDID_DATA[9] * 10;
419 }
420 }
421 break;
422
423 default:
424 break;
425 }
426 }
427
428 switch (max_h) {
429 case 640:
430 viaparinfo->tmds_setting_info->dvi_panel_size =
431 VIA_RES_640X480;
432 break;
433 case 800:
434 viaparinfo->tmds_setting_info->dvi_panel_size =
435 VIA_RES_800X600;
436 break;
437 case 1024:
438 viaparinfo->tmds_setting_info->dvi_panel_size =
439 VIA_RES_1024X768;
440 break;
441 case 1280:
442 viaparinfo->tmds_setting_info->dvi_panel_size =
443 VIA_RES_1280X1024;
444 break;
445 case 1400:
446 viaparinfo->tmds_setting_info->dvi_panel_size =
447 VIA_RES_1400X1050;
448 break;
449 case 1440:
450 viaparinfo->tmds_setting_info->dvi_panel_size =
451 VIA_RES_1440X1050;
452 break;
453 case 1600:
454 viaparinfo->tmds_setting_info->dvi_panel_size =
455 VIA_RES_1600X1200;
456 break;
457 case 1920:
458 if (max_v == 1200) {
459 viaparinfo->tmds_setting_info->dvi_panel_size =
460 VIA_RES_1920X1200;
461 } else {
462 viaparinfo->tmds_setting_info->dvi_panel_size =
463 VIA_RES_1920X1080;
464 }
465
466 break;
467 default:
468 viaparinfo->tmds_setting_info->dvi_panel_size =
469 VIA_RES_1024X768;
470 DEBUG_MSG(KERN_INFO "Unknow panel size max resolution = %d !\
471 set default panel size.\n", max_h);
472 break;
473 }
474
475 DEBUG_MSG(KERN_INFO "DVI max pixelclock = %d\n",
476 viaparinfo->tmds_setting_info->max_pixel_clock);
477 viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr = restore;
478 return viaparinfo->tmds_setting_info->dvi_panel_size;
479}
480
481/*
482 *
483 * int dvi_get_panel_size_from_DDCv2(void)
484 *
485 * - Get Panel Size Using EDID2 Table
486 *
487 * Return Type: int
488 *
489 */
490static int dvi_get_panel_size_from_DDCv2(void)
491{
492 int HSize = 0, restore;
493 unsigned char R_Buffer[2];
494
495 DEBUG_MSG(KERN_INFO "\n dvi_get_panel_size_from_DDCv2 \n");
496
497 restore = viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr;
498 viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr = 0xA2;
499
500 /* Horizontal: 0x76, 0x77 */
501 tmds_register_read_bytes(0x76, R_Buffer, 2);
502 HSize = R_Buffer[0];
503 HSize += R_Buffer[1] << 8;
504
505 switch (HSize) {
506 case 640:
507 viaparinfo->tmds_setting_info->dvi_panel_size =
508 VIA_RES_640X480;
509 break;
510 case 800:
511 viaparinfo->tmds_setting_info->dvi_panel_size =
512 VIA_RES_800X600;
513 break;
514 case 1024:
515 viaparinfo->tmds_setting_info->dvi_panel_size =
516 VIA_RES_1024X768;
517 break;
518 case 1280:
519 viaparinfo->tmds_setting_info->dvi_panel_size =
520 VIA_RES_1280X1024;
521 break;
522 case 1400:
523 viaparinfo->tmds_setting_info->dvi_panel_size =
524 VIA_RES_1400X1050;
525 break;
526 case 1440:
527 viaparinfo->tmds_setting_info->dvi_panel_size =
528 VIA_RES_1440X1050;
529 break;
530 case 1600:
531 viaparinfo->tmds_setting_info->dvi_panel_size =
532 VIA_RES_1600X1200;
533 break;
534 default:
535 viaparinfo->tmds_setting_info->dvi_panel_size =
536 VIA_RES_1024X768;
537 DEBUG_MSG(KERN_INFO "Unknow panel size max resolution = %d!\
538 set default panel size.\n", HSize);
539 break;
540 }
541
542 viaparinfo->chip_info->tmds_chip_info.tmds_chip_slave_addr = restore;
543 return viaparinfo->tmds_setting_info->dvi_panel_size;
544}
545
546/*
547 *
548 * unsigned char dvi_get_panel_info(void)
549 *
550 * - Get Panel Size
551 *
552 * Return Type: unsigned char
553 */
554static unsigned char dvi_get_panel_info(void)
555{
556 unsigned char dvipanelsize;
557 DEBUG_MSG(KERN_INFO "dvi_get_panel_info! \n");
558
559 viafb_dvi_sense();
560 switch (viafb_dvi_query_EDID()) {
561 case 1:
562 dvi_get_panel_size_from_DDCv1();
563 break;
564 case 2:
565 dvi_get_panel_size_from_DDCv2();
566 break;
567 default:
568 break;
569 }
570
571 DEBUG_MSG(KERN_INFO "dvi panel size is %2d \n",
572 viaparinfo->tmds_setting_info->dvi_panel_size);
573 dvipanelsize = (unsigned char)(viaparinfo->
574 tmds_setting_info->dvi_panel_size);
575 return dvipanelsize;
576}
577
578/* If Disable DVI, turn off pad */
579void viafb_dvi_disable(void)
580{
581 if (viaparinfo->chip_info->
582 tmds_chip_info.output_interface == INTERFACE_DVP0)
583 viafb_write_reg(SR1E, VIASR,
584 viafb_read_reg(VIASR, SR1E) & (~0xC0));
585
586 if (viaparinfo->chip_info->
587 tmds_chip_info.output_interface == INTERFACE_DVP1)
588 viafb_write_reg(SR1E, VIASR,
589 viafb_read_reg(VIASR, SR1E) & (~0x30));
590
591 if (viaparinfo->chip_info->
592 tmds_chip_info.output_interface == INTERFACE_DFP_HIGH)
593 viafb_write_reg(SR2A, VIASR,
594 viafb_read_reg(VIASR, SR2A) & (~0x0C));
595
596 if (viaparinfo->chip_info->
597 tmds_chip_info.output_interface == INTERFACE_DFP_LOW)
598 viafb_write_reg(SR2A, VIASR,
599 viafb_read_reg(VIASR, SR2A) & (~0x03));
600
601 if (viaparinfo->chip_info->
602 tmds_chip_info.output_interface == INTERFACE_TMDS)
603 /* Turn off TMDS power. */
604 viafb_write_reg(CRD2, VIACR,
605 viafb_read_reg(VIACR, CRD2) | 0x08);
606}
607
608/* If Enable DVI, turn off pad */
609void viafb_dvi_enable(void)
610{
611 u8 data;
612
613 if (viaparinfo->chip_info->
614 tmds_chip_info.output_interface == INTERFACE_DVP0) {
615 viafb_write_reg(SR1E, VIASR,
616 viafb_read_reg(VIASR, SR1E) | 0xC0);
617 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
618 tmds_register_write(0x88, 0x3b);
619 else
620 /*clear CR91[5] to direct on display period
621 in the secondary diplay path */
622 viafb_write_reg(CR91, VIACR,
623 viafb_read_reg(VIACR, CR91) & 0xDF);
624 }
625
626 if (viaparinfo->chip_info->
627 tmds_chip_info.output_interface == INTERFACE_DVP1) {
628 viafb_write_reg(SR1E, VIASR,
629 viafb_read_reg(VIASR, SR1E) | 0x30);
630
631 /*fix dvi cann't be enabled with MB VT5718C4 - Al Zhang */
632 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
633 tmds_register_write(0x88, 0x3b);
634 } else {
635 /*clear CR91[5] to direct on display period
636 in the secondary diplay path */
637 viafb_write_reg(CR91, VIACR,
638 viafb_read_reg(VIACR, CR91) & 0xDF);
639 }
640
641 /*fix DVI cannot enable on EPIA-M board */
642 if (viafb_platform_epia_dvi == 1) {
643 viafb_write_reg_mask(CR91, VIACR, 0x1f, 0x1f);
644 viafb_write_reg_mask(CR88, VIACR, 0x00, BIT6 + BIT0);
645 if (viafb_bus_width == 24) {
646 if (viafb_device_lcd_dualedge == 1)
647 data = 0x3F;
648 else
649 data = 0x37;
650 viafb_i2c_writebyte(viaparinfo->chip_info->
651 tmds_chip_info.
652 tmds_chip_slave_addr,
653 0x08, data);
654 }
655 }
656 }
657
658 if (viaparinfo->chip_info->
659 tmds_chip_info.output_interface == INTERFACE_DFP_HIGH) {
660 viafb_write_reg(SR2A, VIASR,
661 viafb_read_reg(VIASR, SR2A) | 0x0C);
662 viafb_write_reg(CR91, VIACR,
663 viafb_read_reg(VIACR, CR91) & 0xDF);
664 }
665
666 if (viaparinfo->chip_info->
667 tmds_chip_info.output_interface == INTERFACE_DFP_LOW) {
668 viafb_write_reg(SR2A, VIASR,
669 viafb_read_reg(VIASR, SR2A) | 0x03);
670 viafb_write_reg(CR91, VIACR,
671 viafb_read_reg(VIACR, CR91) & 0xDF);
672 }
673 if (viaparinfo->chip_info->
674 tmds_chip_info.output_interface == INTERFACE_TMDS) {
675 /* Turn on Display period in the panel path. */
676 viafb_write_reg_mask(CR91, VIACR, 0, BIT7);
677
678 /* Turn on TMDS power. */
679 viafb_write_reg_mask(CRD2, VIACR, 0, BIT3);
680 }
681}
682
diff --git a/drivers/video/via/dvi.h b/drivers/video/via/dvi.h
new file mode 100644
index 000000000000..e1ec37fb0dc3
--- /dev/null
+++ b/drivers/video/via/dvi.h
@@ -0,0 +1,64 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#ifndef __DVI_H__
23#define __DVI_H__
24
25/*Definition TMDS Device ID register*/
26#define VT1632_DEVICE_ID_REG 0x02
27#define VT1632_DEVICE_ID 0x92
28
29#define GET_DVI_SIZE_BY_SYSTEM_BIOS 0x01
30#define GET_DVI_SIZE_BY_VGA_BIOS 0x02
31#define GET_DVI_SZIE_BY_HW_STRAPPING 0x03
32
33/* Definition DVI Panel ID*/
34/* Resolution: 640x480, Channel: single, Dithering: Enable */
35#define DVI_PANEL_ID0_640X480 0x00
36/* Resolution: 800x600, Channel: single, Dithering: Enable */
37#define DVI_PANEL_ID1_800x600 0x01
38/* Resolution: 1024x768, Channel: single, Dithering: Enable */
39#define DVI_PANEL_ID1_1024x768 0x02
40/* Resolution: 1280x768, Channel: single, Dithering: Enable */
41#define DVI_PANEL_ID1_1280x768 0x03
42/* Resolution: 1280x1024, Channel: dual, Dithering: Enable */
43#define DVI_PANEL_ID1_1280x1024 0x04
44/* Resolution: 1400x1050, Channel: dual, Dithering: Enable */
45#define DVI_PANEL_ID1_1400x1050 0x05
46/* Resolution: 1600x1200, Channel: dual, Dithering: Enable */
47#define DVI_PANEL_ID1_1600x1200 0x06
48
49/* Define the version of EDID*/
50#define EDID_VERSION_1 1
51#define EDID_VERSION_2 2
52
53#define DEV_CONNECT_DVI 0x01
54#define DEV_CONNECT_HDMI 0x02
55
56struct VideoModeTable *viafb_get_cea_mode_tbl_pointer(int Index);
57int viafb_dvi_sense(void);
58void viafb_dvi_disable(void);
59void viafb_dvi_enable(void);
60int viafb_tmds_trasmitter_identify(void);
61void viafb_init_dvi_size(void);
62void viafb_dvi_set_mode(int video_index, int mode_bpp, int set_iga);
63
64#endif /* __DVI_H__ */
diff --git a/drivers/video/via/global.c b/drivers/video/via/global.c
new file mode 100644
index 000000000000..468be2425af3
--- /dev/null
+++ b/drivers/video/via/global.c
@@ -0,0 +1,60 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21#include "global.h"
22int viafb_platform_epia_dvi = STATE_OFF;
23int viafb_device_lcd_dualedge = STATE_OFF;
24int viafb_bus_width = 12;
25int viafb_display_hardware_layout = HW_LAYOUT_LCD_DVI;
26int viafb_memsize;
27int viafb_DeviceStatus = CRT_Device;
28int viafb_hotplug;
29int viafb_refresh = 60;
30int viafb_refresh1 = 60;
31int viafb_lcd_dsp_method = LCD_EXPANDSION;
32int viafb_lcd_mode = LCD_OPENLDI;
33int viafb_bpp = 32;
34int viafb_bpp1 = 32;
35int viafb_accel = 1;
36int viafb_CRT_ON = 1;
37int viafb_DVI_ON;
38int viafb_LCD_ON ;
39int viafb_LCD2_ON;
40int viafb_SAMM_ON;
41int viafb_dual_fb;
42int viafb_hotplug_Xres = 640;
43int viafb_hotplug_Yres = 480;
44int viafb_hotplug_bpp = 32;
45int viafb_hotplug_refresh = 60;
46unsigned int viafb_second_offset;
47int viafb_second_size;
48int viafb_primary_dev = None_Device;
49void __iomem *viafb_FB_MM;
50unsigned int viafb_second_xres = 640;
51unsigned int viafb_second_yres = 480;
52unsigned int viafb_second_virtual_xres;
53unsigned int viafb_second_virtual_yres;
54int viafb_lcd_panel_id = LCD_PANEL_ID_MAXIMUM + 1;
55struct fb_cursor viacursor;
56struct fb_info *viafbinfo;
57struct fb_info *viafbinfo1;
58struct viafb_par *viaparinfo;
59struct viafb_par *viaparinfo1;
60
diff --git a/drivers/video/via/global.h b/drivers/video/via/global.h
new file mode 100644
index 000000000000..8e5263c5b812
--- /dev/null
+++ b/drivers/video/via/global.h
@@ -0,0 +1,90 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#ifndef __GLOBAL_H__
23#define __GLOBAL_H__
24
25#include <linux/fb.h>
26#include <linux/delay.h>
27#include <linux/ioport.h>
28#include <linux/pci.h>
29#include <linux/io.h>
30#include <linux/uaccess.h>
31#include <linux/init.h>
32#include <linux/proc_fs.h>
33#include <linux/console.h>
34#include <linux/timer.h>
35
36#include "debug.h"
37
38#include "iface.h"
39#include "viafbdev.h"
40#include "chip.h"
41#include "debug.h"
42#include "accel.h"
43#include "share.h"
44#include "dvi.h"
45#include "viamode.h"
46#include "via_i2c.h"
47#include "hw.h"
48
49#include "lcd.h"
50#include "ioctl.h"
51#include "viamode.h"
52#include "via_utility.h"
53#include "vt1636.h"
54#include "tblDPASetting.h"
55#include "tbl1636.h"
56#include "viafbdev.h"
57
58/* External struct*/
59
60extern int viafb_platform_epia_dvi;
61extern int viafb_device_lcd_dualedge;
62extern int viafb_bus_width;
63extern int viafb_display_hardware_layout;
64extern struct offset offset_reg;
65extern struct viafb_par *viaparinfo;
66extern struct viafb_par *viaparinfo1;
67extern struct fb_info *viafbinfo;
68extern struct fb_info *viafbinfo1;
69extern int viafb_DeviceStatus;
70extern int viafb_refresh;
71extern int viafb_refresh1;
72extern int viafb_lcd_dsp_method;
73extern int viafb_lcd_mode;
74extern int viafb_bpp;
75extern int viafb_bpp1;
76
77extern int viafb_CRT_ON;
78extern int viafb_hotplug_Xres;
79extern int viafb_hotplug_Yres;
80extern int viafb_hotplug_bpp;
81extern int viafb_hotplug_refresh;
82extern int viafb_primary_dev;
83extern void __iomem *viafb_FB_MM;
84extern struct fb_cursor viacursor;
85
86extern unsigned int viafb_second_xres;
87extern unsigned int viafb_second_yres;
88extern int viafb_lcd_panel_id;
89
90#endif /* __GLOBAL_H__ */
diff --git a/drivers/video/via/hw.c b/drivers/video/via/hw.c
new file mode 100644
index 000000000000..fcd53ceb88fa
--- /dev/null
+++ b/drivers/video/via/hw.c
@@ -0,0 +1,2865 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#include "global.h"
23
24static const struct pci_device_id_info pciidlist[] = {
25 {PCI_VIA_VENDOR_ID, UNICHROME_CLE266_DID, UNICHROME_CLE266},
26 {PCI_VIA_VENDOR_ID, UNICHROME_PM800_DID, UNICHROME_PM800},
27 {PCI_VIA_VENDOR_ID, UNICHROME_K400_DID, UNICHROME_K400},
28 {PCI_VIA_VENDOR_ID, UNICHROME_K800_DID, UNICHROME_K800},
29 {PCI_VIA_VENDOR_ID, UNICHROME_CN700_DID, UNICHROME_CN700},
30 {PCI_VIA_VENDOR_ID, UNICHROME_P4M890_DID, UNICHROME_P4M890},
31 {PCI_VIA_VENDOR_ID, UNICHROME_K8M890_DID, UNICHROME_K8M890},
32 {PCI_VIA_VENDOR_ID, UNICHROME_CX700_DID, UNICHROME_CX700},
33 {PCI_VIA_VENDOR_ID, UNICHROME_P4M900_DID, UNICHROME_P4M900},
34 {PCI_VIA_VENDOR_ID, UNICHROME_CN750_DID, UNICHROME_CN750},
35 {PCI_VIA_VENDOR_ID, UNICHROME_VX800_DID, UNICHROME_VX800},
36 {0, 0, 0}
37};
38
39struct offset offset_reg = {
40 /* IGA1 Offset Register */
41 {IGA1_OFFSET_REG_NUM, {{CR13, 0, 7}, {CR35, 5, 7} } },
42 /* IGA2 Offset Register */
43 {IGA2_OFFSET_REG_NUM, {{CR66, 0, 7}, {CR67, 0, 1} } }
44};
45
46static struct pll_map pll_value[] = {
47 {CLK_25_175M, CLE266_PLL_25_175M, K800_PLL_25_175M, CX700_25_175M},
48 {CLK_29_581M, CLE266_PLL_29_581M, K800_PLL_29_581M, CX700_29_581M},
49 {CLK_26_880M, CLE266_PLL_26_880M, K800_PLL_26_880M, CX700_26_880M},
50 {CLK_31_490M, CLE266_PLL_31_490M, K800_PLL_31_490M, CX700_31_490M},
51 {CLK_31_500M, CLE266_PLL_31_500M, K800_PLL_31_500M, CX700_31_500M},
52 {CLK_31_728M, CLE266_PLL_31_728M, K800_PLL_31_728M, CX700_31_728M},
53 {CLK_32_668M, CLE266_PLL_32_668M, K800_PLL_32_668M, CX700_32_668M},
54 {CLK_36_000M, CLE266_PLL_36_000M, K800_PLL_36_000M, CX700_36_000M},
55 {CLK_40_000M, CLE266_PLL_40_000M, K800_PLL_40_000M, CX700_40_000M},
56 {CLK_41_291M, CLE266_PLL_41_291M, K800_PLL_41_291M, CX700_41_291M},
57 {CLK_43_163M, CLE266_PLL_43_163M, K800_PLL_43_163M, CX700_43_163M},
58 {CLK_45_250M, CLE266_PLL_45_250M, K800_PLL_45_250M, CX700_45_250M},
59 {CLK_46_000M, CLE266_PLL_46_000M, K800_PLL_46_000M, CX700_46_000M},
60 {CLK_46_996M, CLE266_PLL_46_996M, K800_PLL_46_996M, CX700_46_996M},
61 {CLK_48_000M, CLE266_PLL_48_000M, K800_PLL_48_000M, CX700_48_000M},
62 {CLK_48_875M, CLE266_PLL_48_875M, K800_PLL_48_875M, CX700_48_875M},
63 {CLK_49_500M, CLE266_PLL_49_500M, K800_PLL_49_500M, CX700_49_500M},
64 {CLK_52_406M, CLE266_PLL_52_406M, K800_PLL_52_406M, CX700_52_406M},
65 {CLK_52_977M, CLE266_PLL_52_977M, K800_PLL_52_977M, CX700_52_977M},
66 {CLK_56_250M, CLE266_PLL_56_250M, K800_PLL_56_250M, CX700_56_250M},
67 {CLK_60_466M, CLE266_PLL_60_466M, K800_PLL_60_466M, CX700_60_466M},
68 {CLK_61_500M, CLE266_PLL_61_500M, K800_PLL_61_500M, CX700_61_500M},
69 {CLK_65_000M, CLE266_PLL_65_000M, K800_PLL_65_000M, CX700_65_000M},
70 {CLK_65_178M, CLE266_PLL_65_178M, K800_PLL_65_178M, CX700_65_178M},
71 {CLK_66_750M, CLE266_PLL_66_750M, K800_PLL_66_750M, CX700_66_750M},
72 {CLK_68_179M, CLE266_PLL_68_179M, K800_PLL_68_179M, CX700_68_179M},
73 {CLK_69_924M, CLE266_PLL_69_924M, K800_PLL_69_924M, CX700_69_924M},
74 {CLK_70_159M, CLE266_PLL_70_159M, K800_PLL_70_159M, CX700_70_159M},
75 {CLK_72_000M, CLE266_PLL_72_000M, K800_PLL_72_000M, CX700_72_000M},
76 {CLK_78_750M, CLE266_PLL_78_750M, K800_PLL_78_750M, CX700_78_750M},
77 {CLK_80_136M, CLE266_PLL_80_136M, K800_PLL_80_136M, CX700_80_136M},
78 {CLK_83_375M, CLE266_PLL_83_375M, K800_PLL_83_375M, CX700_83_375M},
79 {CLK_83_950M, CLE266_PLL_83_950M, K800_PLL_83_950M, CX700_83_950M},
80 {CLK_84_750M, CLE266_PLL_84_750M, K800_PLL_84_750M, CX700_84_750M},
81 {CLK_85_860M, CLE266_PLL_85_860M, K800_PLL_85_860M, CX700_85_860M},
82 {CLK_88_750M, CLE266_PLL_88_750M, K800_PLL_88_750M, CX700_88_750M},
83 {CLK_94_500M, CLE266_PLL_94_500M, K800_PLL_94_500M, CX700_94_500M},
84 {CLK_97_750M, CLE266_PLL_97_750M, K800_PLL_97_750M, CX700_97_750M},
85 {CLK_101_000M, CLE266_PLL_101_000M, K800_PLL_101_000M,
86 CX700_101_000M},
87 {CLK_106_500M, CLE266_PLL_106_500M, K800_PLL_106_500M,
88 CX700_106_500M},
89 {CLK_108_000M, CLE266_PLL_108_000M, K800_PLL_108_000M,
90 CX700_108_000M},
91 {CLK_113_309M, CLE266_PLL_113_309M, K800_PLL_113_309M,
92 CX700_113_309M},
93 {CLK_118_840M, CLE266_PLL_118_840M, K800_PLL_118_840M,
94 CX700_118_840M},
95 {CLK_119_000M, CLE266_PLL_119_000M, K800_PLL_119_000M,
96 CX700_119_000M},
97 {CLK_121_750M, CLE266_PLL_121_750M, K800_PLL_121_750M,
98 CX700_121_750M},
99 {CLK_125_104M, CLE266_PLL_125_104M, K800_PLL_125_104M,
100 CX700_125_104M},
101 {CLK_133_308M, CLE266_PLL_133_308M, K800_PLL_133_308M,
102 CX700_133_308M},
103 {CLK_135_000M, CLE266_PLL_135_000M, K800_PLL_135_000M,
104 CX700_135_000M},
105 {CLK_136_700M, CLE266_PLL_136_700M, K800_PLL_136_700M,
106 CX700_136_700M},
107 {CLK_138_400M, CLE266_PLL_138_400M, K800_PLL_138_400M,
108 CX700_138_400M},
109 {CLK_146_760M, CLE266_PLL_146_760M, K800_PLL_146_760M,
110 CX700_146_760M},
111 {CLK_153_920M, CLE266_PLL_153_920M, K800_PLL_153_920M,
112 CX700_153_920M},
113 {CLK_156_000M, CLE266_PLL_156_000M, K800_PLL_156_000M,
114 CX700_156_000M},
115 {CLK_157_500M, CLE266_PLL_157_500M, K800_PLL_157_500M,
116 CX700_157_500M},
117 {CLK_162_000M, CLE266_PLL_162_000M, K800_PLL_162_000M,
118 CX700_162_000M},
119 {CLK_187_000M, CLE266_PLL_187_000M, K800_PLL_187_000M,
120 CX700_187_000M},
121 {CLK_193_295M, CLE266_PLL_193_295M, K800_PLL_193_295M,
122 CX700_193_295M},
123 {CLK_202_500M, CLE266_PLL_202_500M, K800_PLL_202_500M,
124 CX700_202_500M},
125 {CLK_204_000M, CLE266_PLL_204_000M, K800_PLL_204_000M,
126 CX700_204_000M},
127 {CLK_218_500M, CLE266_PLL_218_500M, K800_PLL_218_500M,
128 CX700_218_500M},
129 {CLK_234_000M, CLE266_PLL_234_000M, K800_PLL_234_000M,
130 CX700_234_000M},
131 {CLK_267_250M, CLE266_PLL_267_250M, K800_PLL_267_250M,
132 CX700_267_250M},
133 {CLK_297_500M, CLE266_PLL_297_500M, K800_PLL_297_500M,
134 CX700_297_500M},
135 {CLK_74_481M, CLE266_PLL_74_481M, K800_PLL_74_481M, CX700_74_481M},
136 {CLK_172_798M, CLE266_PLL_172_798M, K800_PLL_172_798M,
137 CX700_172_798M},
138 {CLK_122_614M, CLE266_PLL_122_614M, K800_PLL_122_614M,
139 CX700_122_614M},
140 {CLK_74_270M, CLE266_PLL_74_270M, K800_PLL_74_270M, CX700_74_270M},
141 {CLK_148_500M, CLE266_PLL_148_500M, K800_PLL_148_500M,
142 CX700_148_500M}
143};
144
145static struct fifo_depth_select display_fifo_depth_reg = {
146 /* IGA1 FIFO Depth_Select */
147 {IGA1_FIFO_DEPTH_SELECT_REG_NUM, {{SR17, 0, 7} } },
148 /* IGA2 FIFO Depth_Select */
149 {IGA2_FIFO_DEPTH_SELECT_REG_NUM,
150 {{CR68, 4, 7}, {CR94, 7, 7}, {CR95, 7, 7} } }
151};
152
153static struct fifo_threshold_select fifo_threshold_select_reg = {
154 /* IGA1 FIFO Threshold Select */
155 {IGA1_FIFO_THRESHOLD_REG_NUM, {{SR16, 0, 5}, {SR16, 7, 7} } },
156 /* IGA2 FIFO Threshold Select */
157 {IGA2_FIFO_THRESHOLD_REG_NUM, {{CR68, 0, 3}, {CR95, 4, 6} } }
158};
159
160static struct fifo_high_threshold_select fifo_high_threshold_select_reg = {
161 /* IGA1 FIFO High Threshold Select */
162 {IGA1_FIFO_HIGH_THRESHOLD_REG_NUM, {{SR18, 0, 5}, {SR18, 7, 7} } },
163 /* IGA2 FIFO High Threshold Select */
164 {IGA2_FIFO_HIGH_THRESHOLD_REG_NUM, {{CR92, 0, 3}, {CR95, 0, 2} } }
165};
166
167static struct display_queue_expire_num display_queue_expire_num_reg = {
168 /* IGA1 Display Queue Expire Num */
169 {IGA1_DISPLAY_QUEUE_EXPIRE_NUM_REG_NUM, {{SR22, 0, 4} } },
170 /* IGA2 Display Queue Expire Num */
171 {IGA2_DISPLAY_QUEUE_EXPIRE_NUM_REG_NUM, {{CR94, 0, 6} } }
172};
173
174/* Definition Fetch Count Registers*/
175static struct fetch_count fetch_count_reg = {
176 /* IGA1 Fetch Count Register */
177 {IGA1_FETCH_COUNT_REG_NUM, {{SR1C, 0, 7}, {SR1D, 0, 1} } },
178 /* IGA2 Fetch Count Register */
179 {IGA2_FETCH_COUNT_REG_NUM, {{CR65, 0, 7}, {CR67, 2, 3} } }
180};
181
182static struct iga1_crtc_timing iga1_crtc_reg = {
183 /* IGA1 Horizontal Total */
184 {IGA1_HOR_TOTAL_REG_NUM, {{CR00, 0, 7}, {CR36, 3, 3} } },
185 /* IGA1 Horizontal Addressable Video */
186 {IGA1_HOR_ADDR_REG_NUM, {{CR01, 0, 7} } },
187 /* IGA1 Horizontal Blank Start */
188 {IGA1_HOR_BLANK_START_REG_NUM, {{CR02, 0, 7} } },
189 /* IGA1 Horizontal Blank End */
190 {IGA1_HOR_BLANK_END_REG_NUM,
191 {{CR03, 0, 4}, {CR05, 7, 7}, {CR33, 5, 5} } },
192 /* IGA1 Horizontal Sync Start */
193 {IGA1_HOR_SYNC_START_REG_NUM, {{CR04, 0, 7}, {CR33, 4, 4} } },
194 /* IGA1 Horizontal Sync End */
195 {IGA1_HOR_SYNC_END_REG_NUM, {{CR05, 0, 4} } },
196 /* IGA1 Vertical Total */
197 {IGA1_VER_TOTAL_REG_NUM,
198 {{CR06, 0, 7}, {CR07, 0, 0}, {CR07, 5, 5}, {CR35, 0, 0} } },
199 /* IGA1 Vertical Addressable Video */
200 {IGA1_VER_ADDR_REG_NUM,
201 {{CR12, 0, 7}, {CR07, 1, 1}, {CR07, 6, 6}, {CR35, 2, 2} } },
202 /* IGA1 Vertical Blank Start */
203 {IGA1_VER_BLANK_START_REG_NUM,
204 {{CR15, 0, 7}, {CR07, 3, 3}, {CR09, 5, 5}, {CR35, 3, 3} } },
205 /* IGA1 Vertical Blank End */
206 {IGA1_VER_BLANK_END_REG_NUM, {{CR16, 0, 7} } },
207 /* IGA1 Vertical Sync Start */
208 {IGA1_VER_SYNC_START_REG_NUM,
209 {{CR10, 0, 7}, {CR07, 2, 2}, {CR07, 7, 7}, {CR35, 1, 1} } },
210 /* IGA1 Vertical Sync End */
211 {IGA1_VER_SYNC_END_REG_NUM, {{CR11, 0, 3} } }
212};
213
214static struct iga2_crtc_timing iga2_crtc_reg = {
215 /* IGA2 Horizontal Total */
216 {IGA2_HOR_TOTAL_REG_NUM, {{CR50, 0, 7}, {CR55, 0, 3} } },
217 /* IGA2 Horizontal Addressable Video */
218 {IGA2_HOR_ADDR_REG_NUM, {{CR51, 0, 7}, {CR55, 4, 6} } },
219 /* IGA2 Horizontal Blank Start */
220 {IGA2_HOR_BLANK_START_REG_NUM, {{CR52, 0, 7}, {CR54, 0, 2} } },
221 /* IGA2 Horizontal Blank End */
222 {IGA2_HOR_BLANK_END_REG_NUM,
223 {{CR53, 0, 7}, {CR54, 3, 5}, {CR5D, 6, 6} } },
224 /* IGA2 Horizontal Sync Start */
225 {IGA2_HOR_SYNC_START_REG_NUM,
226 {{CR56, 0, 7}, {CR54, 6, 7}, {CR5C, 7, 7}, {CR5D, 7, 7} } },
227 /* IGA2 Horizontal Sync End */
228 {IGA2_HOR_SYNC_END_REG_NUM, {{CR57, 0, 7}, {CR5C, 6, 6} } },
229 /* IGA2 Vertical Total */
230 {IGA2_VER_TOTAL_REG_NUM, {{CR58, 0, 7}, {CR5D, 0, 2} } },
231 /* IGA2 Vertical Addressable Video */
232 {IGA2_VER_ADDR_REG_NUM, {{CR59, 0, 7}, {CR5D, 3, 5} } },
233 /* IGA2 Vertical Blank Start */
234 {IGA2_VER_BLANK_START_REG_NUM, {{CR5A, 0, 7}, {CR5C, 0, 2} } },
235 /* IGA2 Vertical Blank End */
236 {IGA2_VER_BLANK_END_REG_NUM, {{CR5B, 0, 7}, {CR5C, 3, 5} } },
237 /* IGA2 Vertical Sync Start */
238 {IGA2_VER_SYNC_START_REG_NUM, {{CR5E, 0, 7}, {CR5F, 5, 7} } },
239 /* IGA2 Vertical Sync End */
240 {IGA2_VER_SYNC_END_REG_NUM, {{CR5F, 0, 4} } }
241};
242
243static struct rgbLUT palLUT_table[] = {
244 /* {R,G,B} */
245 /* Index 0x00~0x03 */
246 {0x00, 0x00, 0x00}, {0x00, 0x00, 0x2A}, {0x00, 0x2A, 0x00}, {0x00,
247 0x2A,
248 0x2A},
249 /* Index 0x04~0x07 */
250 {0x2A, 0x00, 0x00}, {0x2A, 0x00, 0x2A}, {0x2A, 0x15, 0x00}, {0x2A,
251 0x2A,
252 0x2A},
253 /* Index 0x08~0x0B */
254 {0x15, 0x15, 0x15}, {0x15, 0x15, 0x3F}, {0x15, 0x3F, 0x15}, {0x15,
255 0x3F,
256 0x3F},
257 /* Index 0x0C~0x0F */
258 {0x3F, 0x15, 0x15}, {0x3F, 0x15, 0x3F}, {0x3F, 0x3F, 0x15}, {0x3F,
259 0x3F,
260 0x3F},
261 /* Index 0x10~0x13 */
262 {0x00, 0x00, 0x00}, {0x05, 0x05, 0x05}, {0x08, 0x08, 0x08}, {0x0B,
263 0x0B,
264 0x0B},
265 /* Index 0x14~0x17 */
266 {0x0E, 0x0E, 0x0E}, {0x11, 0x11, 0x11}, {0x14, 0x14, 0x14}, {0x18,
267 0x18,
268 0x18},
269 /* Index 0x18~0x1B */
270 {0x1C, 0x1C, 0x1C}, {0x20, 0x20, 0x20}, {0x24, 0x24, 0x24}, {0x28,
271 0x28,
272 0x28},
273 /* Index 0x1C~0x1F */
274 {0x2D, 0x2D, 0x2D}, {0x32, 0x32, 0x32}, {0x38, 0x38, 0x38}, {0x3F,
275 0x3F,
276 0x3F},
277 /* Index 0x20~0x23 */
278 {0x00, 0x00, 0x3F}, {0x10, 0x00, 0x3F}, {0x1F, 0x00, 0x3F}, {0x2F,
279 0x00,
280 0x3F},
281 /* Index 0x24~0x27 */
282 {0x3F, 0x00, 0x3F}, {0x3F, 0x00, 0x2F}, {0x3F, 0x00, 0x1F}, {0x3F,
283 0x00,
284 0x10},
285 /* Index 0x28~0x2B */
286 {0x3F, 0x00, 0x00}, {0x3F, 0x10, 0x00}, {0x3F, 0x1F, 0x00}, {0x3F,
287 0x2F,
288 0x00},
289 /* Index 0x2C~0x2F */
290 {0x3F, 0x3F, 0x00}, {0x2F, 0x3F, 0x00}, {0x1F, 0x3F, 0x00}, {0x10,
291 0x3F,
292 0x00},
293 /* Index 0x30~0x33 */
294 {0x00, 0x3F, 0x00}, {0x00, 0x3F, 0x10}, {0x00, 0x3F, 0x1F}, {0x00,
295 0x3F,
296 0x2F},
297 /* Index 0x34~0x37 */
298 {0x00, 0x3F, 0x3F}, {0x00, 0x2F, 0x3F}, {0x00, 0x1F, 0x3F}, {0x00,
299 0x10,
300 0x3F},
301 /* Index 0x38~0x3B */
302 {0x1F, 0x1F, 0x3F}, {0x27, 0x1F, 0x3F}, {0x2F, 0x1F, 0x3F}, {0x37,
303 0x1F,
304 0x3F},
305 /* Index 0x3C~0x3F */
306 {0x3F, 0x1F, 0x3F}, {0x3F, 0x1F, 0x37}, {0x3F, 0x1F, 0x2F}, {0x3F,
307 0x1F,
308 0x27},
309 /* Index 0x40~0x43 */
310 {0x3F, 0x1F, 0x1F}, {0x3F, 0x27, 0x1F}, {0x3F, 0x2F, 0x1F}, {0x3F,
311 0x3F,
312 0x1F},
313 /* Index 0x44~0x47 */
314 {0x3F, 0x3F, 0x1F}, {0x37, 0x3F, 0x1F}, {0x2F, 0x3F, 0x1F}, {0x27,
315 0x3F,
316 0x1F},
317 /* Index 0x48~0x4B */
318 {0x1F, 0x3F, 0x1F}, {0x1F, 0x3F, 0x27}, {0x1F, 0x3F, 0x2F}, {0x1F,
319 0x3F,
320 0x37},
321 /* Index 0x4C~0x4F */
322 {0x1F, 0x3F, 0x3F}, {0x1F, 0x37, 0x3F}, {0x1F, 0x2F, 0x3F}, {0x1F,
323 0x27,
324 0x3F},
325 /* Index 0x50~0x53 */
326 {0x2D, 0x2D, 0x3F}, {0x31, 0x2D, 0x3F}, {0x36, 0x2D, 0x3F}, {0x3A,
327 0x2D,
328 0x3F},
329 /* Index 0x54~0x57 */
330 {0x3F, 0x2D, 0x3F}, {0x3F, 0x2D, 0x3A}, {0x3F, 0x2D, 0x36}, {0x3F,
331 0x2D,
332 0x31},
333 /* Index 0x58~0x5B */
334 {0x3F, 0x2D, 0x2D}, {0x3F, 0x31, 0x2D}, {0x3F, 0x36, 0x2D}, {0x3F,
335 0x3A,
336 0x2D},
337 /* Index 0x5C~0x5F */
338 {0x3F, 0x3F, 0x2D}, {0x3A, 0x3F, 0x2D}, {0x36, 0x3F, 0x2D}, {0x31,
339 0x3F,
340 0x2D},
341 /* Index 0x60~0x63 */
342 {0x2D, 0x3F, 0x2D}, {0x2D, 0x3F, 0x31}, {0x2D, 0x3F, 0x36}, {0x2D,
343 0x3F,
344 0x3A},
345 /* Index 0x64~0x67 */
346 {0x2D, 0x3F, 0x3F}, {0x2D, 0x3A, 0x3F}, {0x2D, 0x36, 0x3F}, {0x2D,
347 0x31,
348 0x3F},
349 /* Index 0x68~0x6B */
350 {0x00, 0x00, 0x1C}, {0x07, 0x00, 0x1C}, {0x0E, 0x00, 0x1C}, {0x15,
351 0x00,
352 0x1C},
353 /* Index 0x6C~0x6F */
354 {0x1C, 0x00, 0x1C}, {0x1C, 0x00, 0x15}, {0x1C, 0x00, 0x0E}, {0x1C,
355 0x00,
356 0x07},
357 /* Index 0x70~0x73 */
358 {0x1C, 0x00, 0x00}, {0x1C, 0x07, 0x00}, {0x1C, 0x0E, 0x00}, {0x1C,
359 0x15,
360 0x00},
361 /* Index 0x74~0x77 */
362 {0x1C, 0x1C, 0x00}, {0x15, 0x1C, 0x00}, {0x0E, 0x1C, 0x00}, {0x07,
363 0x1C,
364 0x00},
365 /* Index 0x78~0x7B */
366 {0x00, 0x1C, 0x00}, {0x00, 0x1C, 0x07}, {0x00, 0x1C, 0x0E}, {0x00,
367 0x1C,
368 0x15},
369 /* Index 0x7C~0x7F */
370 {0x00, 0x1C, 0x1C}, {0x00, 0x15, 0x1C}, {0x00, 0x0E, 0x1C}, {0x00,
371 0x07,
372 0x1C},
373 /* Index 0x80~0x83 */
374 {0x0E, 0x0E, 0x1C}, {0x11, 0x0E, 0x1C}, {0x15, 0x0E, 0x1C}, {0x18,
375 0x0E,
376 0x1C},
377 /* Index 0x84~0x87 */
378 {0x1C, 0x0E, 0x1C}, {0x1C, 0x0E, 0x18}, {0x1C, 0x0E, 0x15}, {0x1C,
379 0x0E,
380 0x11},
381 /* Index 0x88~0x8B */
382 {0x1C, 0x0E, 0x0E}, {0x1C, 0x11, 0x0E}, {0x1C, 0x15, 0x0E}, {0x1C,
383 0x18,
384 0x0E},
385 /* Index 0x8C~0x8F */
386 {0x1C, 0x1C, 0x0E}, {0x18, 0x1C, 0x0E}, {0x15, 0x1C, 0x0E}, {0x11,
387 0x1C,
388 0x0E},
389 /* Index 0x90~0x93 */
390 {0x0E, 0x1C, 0x0E}, {0x0E, 0x1C, 0x11}, {0x0E, 0x1C, 0x15}, {0x0E,
391 0x1C,
392 0x18},
393 /* Index 0x94~0x97 */
394 {0x0E, 0x1C, 0x1C}, {0x0E, 0x18, 0x1C}, {0x0E, 0x15, 0x1C}, {0x0E,
395 0x11,
396 0x1C},
397 /* Index 0x98~0x9B */
398 {0x14, 0x14, 0x1C}, {0x16, 0x14, 0x1C}, {0x18, 0x14, 0x1C}, {0x1A,
399 0x14,
400 0x1C},
401 /* Index 0x9C~0x9F */
402 {0x1C, 0x14, 0x1C}, {0x1C, 0x14, 0x1A}, {0x1C, 0x14, 0x18}, {0x1C,
403 0x14,
404 0x16},
405 /* Index 0xA0~0xA3 */
406 {0x1C, 0x14, 0x14}, {0x1C, 0x16, 0x14}, {0x1C, 0x18, 0x14}, {0x1C,
407 0x1A,
408 0x14},
409 /* Index 0xA4~0xA7 */
410 {0x1C, 0x1C, 0x14}, {0x1A, 0x1C, 0x14}, {0x18, 0x1C, 0x14}, {0x16,
411 0x1C,
412 0x14},
413 /* Index 0xA8~0xAB */
414 {0x14, 0x1C, 0x14}, {0x14, 0x1C, 0x16}, {0x14, 0x1C, 0x18}, {0x14,
415 0x1C,
416 0x1A},
417 /* Index 0xAC~0xAF */
418 {0x14, 0x1C, 0x1C}, {0x14, 0x1A, 0x1C}, {0x14, 0x18, 0x1C}, {0x14,
419 0x16,
420 0x1C},
421 /* Index 0xB0~0xB3 */
422 {0x00, 0x00, 0x10}, {0x04, 0x00, 0x10}, {0x08, 0x00, 0x10}, {0x0C,
423 0x00,
424 0x10},
425 /* Index 0xB4~0xB7 */
426 {0x10, 0x00, 0x10}, {0x10, 0x00, 0x0C}, {0x10, 0x00, 0x08}, {0x10,
427 0x00,
428 0x04},
429 /* Index 0xB8~0xBB */
430 {0x10, 0x00, 0x00}, {0x10, 0x04, 0x00}, {0x10, 0x08, 0x00}, {0x10,
431 0x0C,
432 0x00},
433 /* Index 0xBC~0xBF */
434 {0x10, 0x10, 0x00}, {0x0C, 0x10, 0x00}, {0x08, 0x10, 0x00}, {0x04,
435 0x10,
436 0x00},
437 /* Index 0xC0~0xC3 */
438 {0x00, 0x10, 0x00}, {0x00, 0x10, 0x04}, {0x00, 0x10, 0x08}, {0x00,
439 0x10,
440 0x0C},
441 /* Index 0xC4~0xC7 */
442 {0x00, 0x10, 0x10}, {0x00, 0x0C, 0x10}, {0x00, 0x08, 0x10}, {0x00,
443 0x04,
444 0x10},
445 /* Index 0xC8~0xCB */
446 {0x08, 0x08, 0x10}, {0x0A, 0x08, 0x10}, {0x0C, 0x08, 0x10}, {0x0E,
447 0x08,
448 0x10},
449 /* Index 0xCC~0xCF */
450 {0x10, 0x08, 0x10}, {0x10, 0x08, 0x0E}, {0x10, 0x08, 0x0C}, {0x10,
451 0x08,
452 0x0A},
453 /* Index 0xD0~0xD3 */
454 {0x10, 0x08, 0x08}, {0x10, 0x0A, 0x08}, {0x10, 0x0C, 0x08}, {0x10,
455 0x0E,
456 0x08},
457 /* Index 0xD4~0xD7 */
458 {0x10, 0x10, 0x08}, {0x0E, 0x10, 0x08}, {0x0C, 0x10, 0x08}, {0x0A,
459 0x10,
460 0x08},
461 /* Index 0xD8~0xDB */
462 {0x08, 0x10, 0x08}, {0x08, 0x10, 0x0A}, {0x08, 0x10, 0x0C}, {0x08,
463 0x10,
464 0x0E},
465 /* Index 0xDC~0xDF */
466 {0x08, 0x10, 0x10}, {0x08, 0x0E, 0x10}, {0x08, 0x0C, 0x10}, {0x08,
467 0x0A,
468 0x10},
469 /* Index 0xE0~0xE3 */
470 {0x0B, 0x0B, 0x10}, {0x0C, 0x0B, 0x10}, {0x0D, 0x0B, 0x10}, {0x0F,
471 0x0B,
472 0x10},
473 /* Index 0xE4~0xE7 */
474 {0x10, 0x0B, 0x10}, {0x10, 0x0B, 0x0F}, {0x10, 0x0B, 0x0D}, {0x10,
475 0x0B,
476 0x0C},
477 /* Index 0xE8~0xEB */
478 {0x10, 0x0B, 0x0B}, {0x10, 0x0C, 0x0B}, {0x10, 0x0D, 0x0B}, {0x10,
479 0x0F,
480 0x0B},
481 /* Index 0xEC~0xEF */
482 {0x10, 0x10, 0x0B}, {0x0F, 0x10, 0x0B}, {0x0D, 0x10, 0x0B}, {0x0C,
483 0x10,
484 0x0B},
485 /* Index 0xF0~0xF3 */
486 {0x0B, 0x10, 0x0B}, {0x0B, 0x10, 0x0C}, {0x0B, 0x10, 0x0D}, {0x0B,
487 0x10,
488 0x0F},
489 /* Index 0xF4~0xF7 */
490 {0x0B, 0x10, 0x10}, {0x0B, 0x0F, 0x10}, {0x0B, 0x0D, 0x10}, {0x0B,
491 0x0C,
492 0x10},
493 /* Index 0xF8~0xFB */
494 {0x00, 0x00, 0x00}, {0x00, 0x00, 0x00}, {0x00, 0x00, 0x00}, {0x00,
495 0x00,
496 0x00},
497 /* Index 0xFC~0xFF */
498 {0x00, 0x00, 0x00}, {0x00, 0x00, 0x00}, {0x00, 0x00, 0x00}, {0x00,
499 0x00,
500 0x00}
501};
502
503static void set_crt_output_path(int set_iga);
504static void dvi_patch_skew_dvp0(void);
505static void dvi_patch_skew_dvp1(void);
506static void dvi_patch_skew_dvp_low(void);
507static void set_dvi_output_path(int set_iga, int output_interface);
508static void set_lcd_output_path(int set_iga, int output_interface);
509static int search_mode_setting(int ModeInfoIndex);
510static void load_fix_bit_crtc_reg(void);
511static void init_gfx_chip_info(void);
512static void init_tmds_chip_info(void);
513static void init_lvds_chip_info(void);
514static void device_screen_off(void);
515static void device_screen_on(void);
516static void set_display_channel(void);
517static void device_off(void);
518static void device_on(void);
519static void enable_second_display_channel(void);
520static void disable_second_display_channel(void);
521static int get_fb_size_from_pci(void);
522
523void viafb_write_reg(u8 index, u16 io_port, u8 data)
524{
525 outb(index, io_port);
526 outb(data, io_port + 1);
527 /*DEBUG_MSG(KERN_INFO "\nIndex=%2d Value=%2d", index, data); */
528}
529u8 viafb_read_reg(int io_port, u8 index)
530{
531 outb(index, io_port);
532 return inb(io_port + 1);
533}
534
535void viafb_lock_crt(void)
536{
537 viafb_write_reg_mask(CR11, VIACR, BIT7, BIT7);
538}
539
540void viafb_unlock_crt(void)
541{
542 viafb_write_reg_mask(CR11, VIACR, 0, BIT7);
543 viafb_write_reg_mask(CR47, VIACR, 0, BIT0);
544}
545
546void viafb_write_reg_mask(u8 index, int io_port, u8 data, u8 mask)
547{
548 u8 tmp;
549
550 outb(index, io_port);
551 tmp = inb(io_port + 1);
552 outb((data & mask) | (tmp & (~mask)), io_port + 1);
553 /*DEBUG_MSG(KERN_INFO "\nIndex=%2d Value=%2d", index, tmp); */
554}
555
556void write_dac_reg(u8 index, u8 r, u8 g, u8 b)
557{
558 outb(index, LUT_INDEX_WRITE);
559 outb(r, LUT_DATA);
560 outb(g, LUT_DATA);
561 outb(b, LUT_DATA);
562}
563
564/*Set IGA path for each device*/
565void viafb_set_iga_path(void)
566{
567
568 if (viafb_SAMM_ON == 1) {
569 if (viafb_CRT_ON) {
570 if (viafb_primary_dev == CRT_Device)
571 viaparinfo->crt_setting_info->iga_path = IGA1;
572 else
573 viaparinfo->crt_setting_info->iga_path = IGA2;
574 }
575
576 if (viafb_DVI_ON) {
577 if (viafb_primary_dev == DVI_Device)
578 viaparinfo->tmds_setting_info->iga_path = IGA1;
579 else
580 viaparinfo->tmds_setting_info->iga_path = IGA2;
581 }
582
583 if (viafb_LCD_ON) {
584 if (viafb_primary_dev == LCD_Device) {
585 if (viafb_dual_fb &&
586 (viaparinfo->chip_info->gfx_chip_name ==
587 UNICHROME_CLE266)) {
588 viaparinfo->
589 lvds_setting_info->iga_path = IGA2;
590 viaparinfo->
591 crt_setting_info->iga_path = IGA1;
592 viaparinfo->
593 tmds_setting_info->iga_path = IGA1;
594 } else
595 viaparinfo->
596 lvds_setting_info->iga_path = IGA1;
597 } else {
598 viaparinfo->lvds_setting_info->iga_path = IGA2;
599 }
600 }
601 if (viafb_LCD2_ON) {
602 if (LCD2_Device == viafb_primary_dev)
603 viaparinfo->lvds_setting_info2->iga_path = IGA1;
604 else
605 viaparinfo->lvds_setting_info2->iga_path = IGA2;
606 }
607 } else {
608 viafb_SAMM_ON = 0;
609
610 if (viafb_CRT_ON && viafb_LCD_ON) {
611 viaparinfo->crt_setting_info->iga_path = IGA1;
612 viaparinfo->lvds_setting_info->iga_path = IGA2;
613 } else if (viafb_CRT_ON && viafb_DVI_ON) {
614 viaparinfo->crt_setting_info->iga_path = IGA1;
615 viaparinfo->tmds_setting_info->iga_path = IGA2;
616 } else if (viafb_LCD_ON && viafb_DVI_ON) {
617 viaparinfo->tmds_setting_info->iga_path = IGA1;
618 viaparinfo->lvds_setting_info->iga_path = IGA2;
619 } else if (viafb_LCD_ON && viafb_LCD2_ON) {
620 viaparinfo->lvds_setting_info->iga_path = IGA2;
621 viaparinfo->lvds_setting_info2->iga_path = IGA2;
622 } else if (viafb_CRT_ON) {
623 viaparinfo->crt_setting_info->iga_path = IGA1;
624 } else if (viafb_LCD_ON) {
625 viaparinfo->lvds_setting_info->iga_path = IGA2;
626 } else if (viafb_DVI_ON) {
627 viaparinfo->tmds_setting_info->iga_path = IGA1;
628 }
629 }
630}
631
632void viafb_set_start_addr(void)
633{
634 unsigned long offset = 0, tmp = 0, size = 0;
635 unsigned long length;
636
637 DEBUG_MSG(KERN_INFO "viafb_set_start_addr!\n");
638 viafb_unlock_crt();
639 /* update starting address of IGA1 */
640 viafb_write_reg(CR0C, VIACR, 0x00); /*initial starting address */
641 viafb_write_reg(CR0D, VIACR, 0x00);
642 viafb_write_reg(CR34, VIACR, 0x00);
643 viafb_write_reg_mask(CR48, VIACR, 0x00, 0x1F);
644
645 if (viafb_dual_fb) {
646 viaparinfo->iga_path = IGA1;
647 viaparinfo1->iga_path = IGA2;
648 }
649
650 if (viafb_SAMM_ON == 1) {
651 if (!viafb_dual_fb) {
652 if (viafb_second_size)
653 size = viafb_second_size * 1024 * 1024;
654 else
655 size = 8 * 1024 * 1024;
656 } else {
657
658 size = viaparinfo1->memsize;
659 }
660 offset = viafb_second_offset;
661 DEBUG_MSG(KERN_INFO
662 "viafb_second_size=%lx, second start_adddress=%lx\n",
663 size, offset);
664 }
665 if (viafb_SAMM_ON == 1) {
666 offset = offset >> 3;
667
668 tmp = viafb_read_reg(VIACR, 0x62) & 0x01;
669 tmp |= (offset & 0x7F) << 1;
670 viafb_write_reg(CR62, VIACR, tmp);
671 viafb_write_reg(CR63, VIACR, ((offset & 0x7F80) >> 7));
672 viafb_write_reg(CR64, VIACR, ((offset & 0x7F8000) >> 15));
673 viafb_write_reg(CRA3, VIACR, ((offset & 0x3800000) >> 23));
674 } else {
675 /* update starting address */
676 viafb_write_reg(CR62, VIACR, 0x00);
677 viafb_write_reg(CR63, VIACR, 0x00);
678 viafb_write_reg(CR64, VIACR, 0x00);
679 viafb_write_reg(CRA3, VIACR, 0x00);
680 }
681
682 if (viafb_SAMM_ON == 1) {
683 if (viafb_accel) {
684 if (!viafb_dual_fb)
685 length = size - viaparinfo->fbmem_used;
686 else
687 length = size - viaparinfo1->fbmem_used;
688 } else
689 length = size;
690 offset = (unsigned long)(void *)viafb_FB_MM +
691 viafb_second_offset;
692 memset((void *)offset, 0, length);
693 }
694
695 viafb_lock_crt();
696}
697
698void viafb_set_output_path(int device, int set_iga, int output_interface)
699{
700 switch (device) {
701 case DEVICE_CRT:
702 set_crt_output_path(set_iga);
703 break;
704 case DEVICE_DVI:
705 set_dvi_output_path(set_iga, output_interface);
706 break;
707 case DEVICE_LCD:
708 set_lcd_output_path(set_iga, output_interface);
709 break;
710 }
711}
712
713static void set_crt_output_path(int set_iga)
714{
715 viafb_write_reg_mask(CR36, VIACR, 0x00, BIT4 + BIT5);
716
717 switch (set_iga) {
718 case IGA1:
719 viafb_write_reg_mask(SR16, VIASR, 0x00, BIT6);
720 break;
721 case IGA2:
722 case IGA1_IGA2:
723 viafb_write_reg_mask(CR6A, VIACR, 0xC0, BIT6 + BIT7);
724 viafb_write_reg_mask(SR16, VIASR, 0x40, BIT6);
725 if (set_iga == IGA1_IGA2)
726 viafb_write_reg_mask(CR6B, VIACR, 0x08, BIT3);
727 break;
728 }
729}
730
731static void dvi_patch_skew_dvp0(void)
732{
733 /* Reset data driving first: */
734 viafb_write_reg_mask(SR1B, VIASR, 0, BIT1);
735 viafb_write_reg_mask(SR2A, VIASR, 0, BIT4);
736
737 switch (viaparinfo->chip_info->gfx_chip_name) {
738 case UNICHROME_P4M890:
739 {
740 if ((viaparinfo->tmds_setting_info->h_active == 1600) &&
741 (viaparinfo->tmds_setting_info->v_active ==
742 1200))
743 viafb_write_reg_mask(CR96, VIACR, 0x03,
744 BIT0 + BIT1 + BIT2);
745 else
746 viafb_write_reg_mask(CR96, VIACR, 0x07,
747 BIT0 + BIT1 + BIT2);
748 break;
749 }
750
751 case UNICHROME_P4M900:
752 {
753 viafb_write_reg_mask(CR96, VIACR, 0x07,
754 BIT0 + BIT1 + BIT2 + BIT3);
755 viafb_write_reg_mask(SR1B, VIASR, 0x02, BIT1);
756 viafb_write_reg_mask(SR2A, VIASR, 0x10, BIT4);
757 break;
758 }
759
760 default:
761 {
762 break;
763 }
764 }
765}
766
767static void dvi_patch_skew_dvp1(void)
768{
769 switch (viaparinfo->chip_info->gfx_chip_name) {
770 case UNICHROME_CX700:
771 {
772 break;
773 }
774
775 default:
776 {
777 break;
778 }
779 }
780}
781
782static void dvi_patch_skew_dvp_low(void)
783{
784 switch (viaparinfo->chip_info->gfx_chip_name) {
785 case UNICHROME_K8M890:
786 {
787 viafb_write_reg_mask(CR99, VIACR, 0x03, BIT0 + BIT1);
788 break;
789 }
790
791 case UNICHROME_P4M900:
792 {
793 viafb_write_reg_mask(CR99, VIACR, 0x08,
794 BIT0 + BIT1 + BIT2 + BIT3);
795 break;
796 }
797
798 case UNICHROME_P4M890:
799 {
800 viafb_write_reg_mask(CR99, VIACR, 0x0F,
801 BIT0 + BIT1 + BIT2 + BIT3);
802 break;
803 }
804
805 default:
806 {
807 break;
808 }
809 }
810}
811
812static void set_dvi_output_path(int set_iga, int output_interface)
813{
814 switch (output_interface) {
815 case INTERFACE_DVP0:
816 viafb_write_reg_mask(CR6B, VIACR, 0x01, BIT0);
817
818 if (set_iga == IGA1) {
819 viafb_write_reg_mask(CR96, VIACR, 0x00, BIT4);
820 viafb_write_reg_mask(CR6C, VIACR, 0x21, BIT0 +
821 BIT5 + BIT7);
822 } else {
823 viafb_write_reg_mask(CR96, VIACR, 0x10, BIT4);
824 viafb_write_reg_mask(CR6C, VIACR, 0xA1, BIT0 +
825 BIT5 + BIT7);
826 }
827
828 viafb_write_reg_mask(SR1E, VIASR, 0xC0, BIT7 + BIT6);
829
830 dvi_patch_skew_dvp0();
831 break;
832
833 case INTERFACE_DVP1:
834 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
835 if (set_iga == IGA1)
836 viafb_write_reg_mask(CR93, VIACR, 0x21,
837 BIT0 + BIT5 + BIT7);
838 else
839 viafb_write_reg_mask(CR93, VIACR, 0xA1,
840 BIT0 + BIT5 + BIT7);
841 } else {
842 if (set_iga == IGA1)
843 viafb_write_reg_mask(CR9B, VIACR, 0x00, BIT4);
844 else
845 viafb_write_reg_mask(CR9B, VIACR, 0x10, BIT4);
846 }
847
848 viafb_write_reg_mask(SR1E, VIASR, 0x30, BIT4 + BIT5);
849 dvi_patch_skew_dvp1();
850 break;
851 case INTERFACE_DFP_HIGH:
852 if (viaparinfo->chip_info->gfx_chip_name != UNICHROME_CLE266) {
853 if (set_iga == IGA1) {
854 viafb_write_reg_mask(CR96, VIACR, 0x00, BIT4);
855 viafb_write_reg_mask(CR97, VIACR, 0x03,
856 BIT0 + BIT1 + BIT4);
857 } else {
858 viafb_write_reg_mask(CR96, VIACR, 0x10, BIT4);
859 viafb_write_reg_mask(CR97, VIACR, 0x13,
860 BIT0 + BIT1 + BIT4);
861 }
862 }
863 viafb_write_reg_mask(SR2A, VIASR, 0x0C, BIT2 + BIT3);
864 break;
865
866 case INTERFACE_DFP_LOW:
867 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
868 break;
869
870 if (set_iga == IGA1) {
871 viafb_write_reg_mask(CR99, VIACR, 0x00, BIT4);
872 viafb_write_reg_mask(CR9B, VIACR, 0x00, BIT4);
873 } else {
874 viafb_write_reg_mask(CR99, VIACR, 0x10, BIT4);
875 viafb_write_reg_mask(CR9B, VIACR, 0x10, BIT4);
876 }
877
878 viafb_write_reg_mask(SR2A, VIASR, 0x03, BIT0 + BIT1);
879 dvi_patch_skew_dvp_low();
880 break;
881
882 case INTERFACE_TMDS:
883 if (set_iga == IGA1)
884 viafb_write_reg_mask(CR99, VIACR, 0x00, BIT4);
885 else
886 viafb_write_reg_mask(CR99, VIACR, 0x10, BIT4);
887 break;
888 }
889
890 if (set_iga == IGA2) {
891 enable_second_display_channel();
892 /* Disable LCD Scaling */
893 viafb_write_reg_mask(CR79, VIACR, 0x00, BIT0);
894 }
895}
896
897static void set_lcd_output_path(int set_iga, int output_interface)
898{
899 DEBUG_MSG(KERN_INFO
900 "set_lcd_output_path, iga:%d,out_interface:%d\n",
901 set_iga, output_interface);
902 switch (set_iga) {
903 case IGA1:
904 viafb_write_reg_mask(CR6B, VIACR, 0x00, BIT3);
905 viafb_write_reg_mask(CR6A, VIACR, 0x08, BIT3);
906
907 disable_second_display_channel();
908 break;
909
910 case IGA2:
911 viafb_write_reg_mask(CR6B, VIACR, 0x00, BIT3);
912 viafb_write_reg_mask(CR6A, VIACR, 0x08, BIT3);
913
914 enable_second_display_channel();
915 break;
916
917 case IGA1_IGA2:
918 viafb_write_reg_mask(CR6B, VIACR, 0x08, BIT3);
919 viafb_write_reg_mask(CR6A, VIACR, 0x08, BIT3);
920
921 disable_second_display_channel();
922 break;
923 }
924
925 switch (output_interface) {
926 case INTERFACE_DVP0:
927 if (set_iga == IGA1) {
928 viafb_write_reg_mask(CR96, VIACR, 0x00, BIT4);
929 } else {
930 viafb_write_reg(CR91, VIACR, 0x00);
931 viafb_write_reg_mask(CR96, VIACR, 0x10, BIT4);
932 }
933 break;
934
935 case INTERFACE_DVP1:
936 if (set_iga == IGA1)
937 viafb_write_reg_mask(CR9B, VIACR, 0x00, BIT4);
938 else {
939 viafb_write_reg(CR91, VIACR, 0x00);
940 viafb_write_reg_mask(CR9B, VIACR, 0x10, BIT4);
941 }
942 break;
943
944 case INTERFACE_DFP_HIGH:
945 if (set_iga == IGA1)
946 viafb_write_reg_mask(CR97, VIACR, 0x00, BIT4);
947 else {
948 viafb_write_reg(CR91, VIACR, 0x00);
949 viafb_write_reg_mask(CR97, VIACR, 0x10, BIT4);
950 viafb_write_reg_mask(CR96, VIACR, 0x10, BIT4);
951 }
952 break;
953
954 case INTERFACE_DFP_LOW:
955 if (set_iga == IGA1)
956 viafb_write_reg_mask(CR99, VIACR, 0x00, BIT4);
957 else {
958 viafb_write_reg(CR91, VIACR, 0x00);
959 viafb_write_reg_mask(CR99, VIACR, 0x10, BIT4);
960 viafb_write_reg_mask(CR9B, VIACR, 0x10, BIT4);
961 }
962
963 break;
964
965 case INTERFACE_DFP:
966 if ((UNICHROME_K8M890 == viaparinfo->chip_info->gfx_chip_name)
967 || (UNICHROME_P4M890 ==
968 viaparinfo->chip_info->gfx_chip_name))
969 viafb_write_reg_mask(CR97, VIACR, 0x84,
970 BIT7 + BIT2 + BIT1 + BIT0);
971 if (set_iga == IGA1) {
972 viafb_write_reg_mask(CR97, VIACR, 0x00, BIT4);
973 viafb_write_reg_mask(CR99, VIACR, 0x00, BIT4);
974 } else {
975 viafb_write_reg(CR91, VIACR, 0x00);
976 viafb_write_reg_mask(CR97, VIACR, 0x10, BIT4);
977 viafb_write_reg_mask(CR99, VIACR, 0x10, BIT4);
978 }
979 break;
980
981 case INTERFACE_LVDS0:
982 case INTERFACE_LVDS0LVDS1:
983 if (set_iga == IGA1)
984 viafb_write_reg_mask(CR99, VIACR, 0x00, BIT4);
985 else
986 viafb_write_reg_mask(CR99, VIACR, 0x10, BIT4);
987
988 break;
989
990 case INTERFACE_LVDS1:
991 if (set_iga == IGA1)
992 viafb_write_reg_mask(CR97, VIACR, 0x00, BIT4);
993 else
994 viafb_write_reg_mask(CR97, VIACR, 0x10, BIT4);
995 break;
996 }
997}
998
999/* Search Mode Index */
1000static int search_mode_setting(int ModeInfoIndex)
1001{
1002 int i = 0;
1003
1004 while ((i < NUM_TOTAL_MODETABLE) &&
1005 (ModeInfoIndex != CLE266Modes[i].ModeIndex))
1006 i++;
1007 if (i >= NUM_TOTAL_MODETABLE)
1008 i = 0;
1009 return i;
1010
1011}
1012
1013struct VideoModeTable *viafb_get_modetbl_pointer(int Index)
1014{
1015 struct VideoModeTable *TmpTbl = NULL;
1016 TmpTbl = &CLE266Modes[search_mode_setting(Index)];
1017 return TmpTbl;
1018}
1019
1020struct VideoModeTable *viafb_get_cea_mode_tbl_pointer(int Index)
1021{
1022 struct VideoModeTable *TmpTbl = NULL;
1023 int i = 0;
1024 while ((i < NUM_TOTAL_CEA_MODES) &&
1025 (Index != CEA_HDMI_Modes[i].ModeIndex))
1026 i++;
1027 if ((i < NUM_TOTAL_CEA_MODES))
1028 TmpTbl = &CEA_HDMI_Modes[i];
1029 else {
1030 /*Still use general timing if don't find CEA timing */
1031 i = 0;
1032 while ((i < NUM_TOTAL_MODETABLE) &&
1033 (Index != CLE266Modes[i].ModeIndex))
1034 i++;
1035 if (i >= NUM_TOTAL_MODETABLE)
1036 i = 0;
1037 TmpTbl = &CLE266Modes[i];
1038 }
1039 return TmpTbl;
1040}
1041
1042static void load_fix_bit_crtc_reg(void)
1043{
1044 /* always set to 1 */
1045 viafb_write_reg_mask(CR03, VIACR, 0x80, BIT7);
1046 /* line compare should set all bits = 1 (extend modes) */
1047 viafb_write_reg(CR18, VIACR, 0xff);
1048 /* line compare should set all bits = 1 (extend modes) */
1049 viafb_write_reg_mask(CR07, VIACR, 0x10, BIT4);
1050 /* line compare should set all bits = 1 (extend modes) */
1051 viafb_write_reg_mask(CR09, VIACR, 0x40, BIT6);
1052 /* line compare should set all bits = 1 (extend modes) */
1053 viafb_write_reg_mask(CR35, VIACR, 0x10, BIT4);
1054 /* line compare should set all bits = 1 (extend modes) */
1055 viafb_write_reg_mask(CR33, VIACR, 0x06, BIT0 + BIT1 + BIT2);
1056 /*viafb_write_reg_mask(CR32, VIACR, 0x01, BIT0); */
1057 /* extend mode always set to e3h */
1058 viafb_write_reg(CR17, VIACR, 0xe3);
1059 /* extend mode always set to 0h */
1060 viafb_write_reg(CR08, VIACR, 0x00);
1061 /* extend mode always set to 0h */
1062 viafb_write_reg(CR14, VIACR, 0x00);
1063
1064 /* If K8M800, enable Prefetch Mode. */
1065 if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_K800)
1066 || (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K8M890))
1067 viafb_write_reg_mask(CR33, VIACR, 0x08, BIT3);
1068 if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
1069 && (viaparinfo->chip_info->gfx_chip_revision == CLE266_REVISION_AX))
1070 viafb_write_reg_mask(SR1A, VIASR, 0x02, BIT1);
1071
1072}
1073
1074void viafb_load_reg(int timing_value, int viafb_load_reg_num,
1075 struct io_register *reg,
1076 int io_type)
1077{
1078 int reg_mask;
1079 int bit_num = 0;
1080 int data;
1081 int i, j;
1082 int shift_next_reg;
1083 int start_index, end_index, cr_index;
1084 u16 get_bit;
1085
1086 for (i = 0; i < viafb_load_reg_num; i++) {
1087 reg_mask = 0;
1088 data = 0;
1089 start_index = reg[i].start_bit;
1090 end_index = reg[i].end_bit;
1091 cr_index = reg[i].io_addr;
1092
1093 shift_next_reg = bit_num;
1094 for (j = start_index; j <= end_index; j++) {
1095 /*if (bit_num==8) timing_value = timing_value >>8; */
1096 reg_mask = reg_mask | (BIT0 << j);
1097 get_bit = (timing_value & (BIT0 << bit_num));
1098 data =
1099 data | ((get_bit >> shift_next_reg) << start_index);
1100 bit_num++;
1101 }
1102 if (io_type == VIACR)
1103 viafb_write_reg_mask(cr_index, VIACR, data, reg_mask);
1104 else
1105 viafb_write_reg_mask(cr_index, VIASR, data, reg_mask);
1106 }
1107
1108}
1109
1110/* Write Registers */
1111void viafb_write_regx(struct io_reg RegTable[], int ItemNum)
1112{
1113 int i;
1114 unsigned char RegTemp;
1115
1116 /*DEBUG_MSG(KERN_INFO "Table Size : %x!!\n",ItemNum ); */
1117
1118 for (i = 0; i < ItemNum; i++) {
1119 outb(RegTable[i].index, RegTable[i].port);
1120 RegTemp = inb(RegTable[i].port + 1);
1121 RegTemp = (RegTemp & (~RegTable[i].mask)) | RegTable[i].value;
1122 outb(RegTemp, RegTable[i].port + 1);
1123 }
1124}
1125
1126void viafb_load_offset_reg(int h_addr, int bpp_byte, int set_iga)
1127{
1128 int reg_value;
1129 int viafb_load_reg_num;
1130 struct io_register *reg;
1131
1132 switch (set_iga) {
1133 case IGA1_IGA2:
1134 case IGA1:
1135 reg_value = IGA1_OFFSET_FORMULA(h_addr, bpp_byte);
1136 viafb_load_reg_num = offset_reg.iga1_offset_reg.reg_num;
1137 reg = offset_reg.iga1_offset_reg.reg;
1138 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
1139 if (set_iga == IGA1)
1140 break;
1141 case IGA2:
1142 reg_value = IGA2_OFFSET_FORMULA(h_addr, bpp_byte);
1143 viafb_load_reg_num = offset_reg.iga2_offset_reg.reg_num;
1144 reg = offset_reg.iga2_offset_reg.reg;
1145 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
1146 break;
1147 }
1148}
1149
1150void viafb_load_fetch_count_reg(int h_addr, int bpp_byte, int set_iga)
1151{
1152 int reg_value;
1153 int viafb_load_reg_num;
1154 struct io_register *reg = NULL;
1155
1156 switch (set_iga) {
1157 case IGA1_IGA2:
1158 case IGA1:
1159 reg_value = IGA1_FETCH_COUNT_FORMULA(h_addr, bpp_byte);
1160 viafb_load_reg_num = fetch_count_reg.
1161 iga1_fetch_count_reg.reg_num;
1162 reg = fetch_count_reg.iga1_fetch_count_reg.reg;
1163 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIASR);
1164 if (set_iga == IGA1)
1165 break;
1166 case IGA2:
1167 reg_value = IGA2_FETCH_COUNT_FORMULA(h_addr, bpp_byte);
1168 viafb_load_reg_num = fetch_count_reg.
1169 iga2_fetch_count_reg.reg_num;
1170 reg = fetch_count_reg.iga2_fetch_count_reg.reg;
1171 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
1172 break;
1173 }
1174
1175}
1176
1177void viafb_load_FIFO_reg(int set_iga, int hor_active, int ver_active)
1178{
1179 int reg_value;
1180 int viafb_load_reg_num;
1181 struct io_register *reg = NULL;
1182 int iga1_fifo_max_depth = 0, iga1_fifo_threshold =
1183 0, iga1_fifo_high_threshold = 0, iga1_display_queue_expire_num = 0;
1184 int iga2_fifo_max_depth = 0, iga2_fifo_threshold =
1185 0, iga2_fifo_high_threshold = 0, iga2_display_queue_expire_num = 0;
1186
1187 if (set_iga == IGA1) {
1188 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K800) {
1189 iga1_fifo_max_depth = K800_IGA1_FIFO_MAX_DEPTH;
1190 iga1_fifo_threshold = K800_IGA1_FIFO_THRESHOLD;
1191 iga1_fifo_high_threshold =
1192 K800_IGA1_FIFO_HIGH_THRESHOLD;
1193 /* If resolution > 1280x1024, expire length = 64, else
1194 expire length = 128 */
1195 if ((hor_active > 1280) && (ver_active > 1024))
1196 iga1_display_queue_expire_num = 16;
1197 else
1198 iga1_display_queue_expire_num =
1199 K800_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1200
1201 }
1202
1203 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_PM800) {
1204 iga1_fifo_max_depth = P880_IGA1_FIFO_MAX_DEPTH;
1205 iga1_fifo_threshold = P880_IGA1_FIFO_THRESHOLD;
1206 iga1_fifo_high_threshold =
1207 P880_IGA1_FIFO_HIGH_THRESHOLD;
1208 iga1_display_queue_expire_num =
1209 P880_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1210
1211 /* If resolution > 1280x1024, expire length = 64, else
1212 expire length = 128 */
1213 if ((hor_active > 1280) && (ver_active > 1024))
1214 iga1_display_queue_expire_num = 16;
1215 else
1216 iga1_display_queue_expire_num =
1217 P880_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1218 }
1219
1220 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CN700) {
1221 iga1_fifo_max_depth = CN700_IGA1_FIFO_MAX_DEPTH;
1222 iga1_fifo_threshold = CN700_IGA1_FIFO_THRESHOLD;
1223 iga1_fifo_high_threshold =
1224 CN700_IGA1_FIFO_HIGH_THRESHOLD;
1225
1226 /* If resolution > 1280x1024, expire length = 64,
1227 else expire length = 128 */
1228 if ((hor_active > 1280) && (ver_active > 1024))
1229 iga1_display_queue_expire_num = 16;
1230 else
1231 iga1_display_queue_expire_num =
1232 CN700_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1233 }
1234
1235 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700) {
1236 iga1_fifo_max_depth = CX700_IGA1_FIFO_MAX_DEPTH;
1237 iga1_fifo_threshold = CX700_IGA1_FIFO_THRESHOLD;
1238 iga1_fifo_high_threshold =
1239 CX700_IGA1_FIFO_HIGH_THRESHOLD;
1240 iga1_display_queue_expire_num =
1241 CX700_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1242 }
1243
1244 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K8M890) {
1245 iga1_fifo_max_depth = K8M890_IGA1_FIFO_MAX_DEPTH;
1246 iga1_fifo_threshold = K8M890_IGA1_FIFO_THRESHOLD;
1247 iga1_fifo_high_threshold =
1248 K8M890_IGA1_FIFO_HIGH_THRESHOLD;
1249 iga1_display_queue_expire_num =
1250 K8M890_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1251 }
1252
1253 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_P4M890) {
1254 iga1_fifo_max_depth = P4M890_IGA1_FIFO_MAX_DEPTH;
1255 iga1_fifo_threshold = P4M890_IGA1_FIFO_THRESHOLD;
1256 iga1_fifo_high_threshold =
1257 P4M890_IGA1_FIFO_HIGH_THRESHOLD;
1258 iga1_display_queue_expire_num =
1259 P4M890_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1260 }
1261
1262 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_P4M900) {
1263 iga1_fifo_max_depth = P4M900_IGA1_FIFO_MAX_DEPTH;
1264 iga1_fifo_threshold = P4M900_IGA1_FIFO_THRESHOLD;
1265 iga1_fifo_high_threshold =
1266 P4M900_IGA1_FIFO_HIGH_THRESHOLD;
1267 iga1_display_queue_expire_num =
1268 P4M900_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1269 }
1270
1271 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_VX800) {
1272 iga1_fifo_max_depth = VX800_IGA1_FIFO_MAX_DEPTH;
1273 iga1_fifo_threshold = VX800_IGA1_FIFO_THRESHOLD;
1274 iga1_fifo_high_threshold =
1275 VX800_IGA1_FIFO_HIGH_THRESHOLD;
1276 iga1_display_queue_expire_num =
1277 VX800_IGA1_DISPLAY_QUEUE_EXPIRE_NUM;
1278 }
1279
1280 /* Set Display FIFO Depath Select */
1281 reg_value = IGA1_FIFO_DEPTH_SELECT_FORMULA(iga1_fifo_max_depth);
1282 viafb_load_reg_num =
1283 display_fifo_depth_reg.iga1_fifo_depth_select_reg.reg_num;
1284 reg = display_fifo_depth_reg.iga1_fifo_depth_select_reg.reg;
1285 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIASR);
1286
1287 /* Set Display FIFO Threshold Select */
1288 reg_value = IGA1_FIFO_THRESHOLD_FORMULA(iga1_fifo_threshold);
1289 viafb_load_reg_num =
1290 fifo_threshold_select_reg.
1291 iga1_fifo_threshold_select_reg.reg_num;
1292 reg =
1293 fifo_threshold_select_reg.
1294 iga1_fifo_threshold_select_reg.reg;
1295 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIASR);
1296
1297 /* Set FIFO High Threshold Select */
1298 reg_value =
1299 IGA1_FIFO_HIGH_THRESHOLD_FORMULA(iga1_fifo_high_threshold);
1300 viafb_load_reg_num =
1301 fifo_high_threshold_select_reg.
1302 iga1_fifo_high_threshold_select_reg.reg_num;
1303 reg =
1304 fifo_high_threshold_select_reg.
1305 iga1_fifo_high_threshold_select_reg.reg;
1306 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIASR);
1307
1308 /* Set Display Queue Expire Num */
1309 reg_value =
1310 IGA1_DISPLAY_QUEUE_EXPIRE_NUM_FORMULA
1311 (iga1_display_queue_expire_num);
1312 viafb_load_reg_num =
1313 display_queue_expire_num_reg.
1314 iga1_display_queue_expire_num_reg.reg_num;
1315 reg =
1316 display_queue_expire_num_reg.
1317 iga1_display_queue_expire_num_reg.reg;
1318 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIASR);
1319
1320 } else {
1321 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K800) {
1322 iga2_fifo_max_depth = K800_IGA2_FIFO_MAX_DEPTH;
1323 iga2_fifo_threshold = K800_IGA2_FIFO_THRESHOLD;
1324 iga2_fifo_high_threshold =
1325 K800_IGA2_FIFO_HIGH_THRESHOLD;
1326
1327 /* If resolution > 1280x1024, expire length = 64,
1328 else expire length = 128 */
1329 if ((hor_active > 1280) && (ver_active > 1024))
1330 iga2_display_queue_expire_num = 16;
1331 else
1332 iga2_display_queue_expire_num =
1333 K800_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1334 }
1335
1336 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_PM800) {
1337 iga2_fifo_max_depth = P880_IGA2_FIFO_MAX_DEPTH;
1338 iga2_fifo_threshold = P880_IGA2_FIFO_THRESHOLD;
1339 iga2_fifo_high_threshold =
1340 P880_IGA2_FIFO_HIGH_THRESHOLD;
1341
1342 /* If resolution > 1280x1024, expire length = 64,
1343 else expire length = 128 */
1344 if ((hor_active > 1280) && (ver_active > 1024))
1345 iga2_display_queue_expire_num = 16;
1346 else
1347 iga2_display_queue_expire_num =
1348 P880_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1349 }
1350
1351 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CN700) {
1352 iga2_fifo_max_depth = CN700_IGA2_FIFO_MAX_DEPTH;
1353 iga2_fifo_threshold = CN700_IGA2_FIFO_THRESHOLD;
1354 iga2_fifo_high_threshold =
1355 CN700_IGA2_FIFO_HIGH_THRESHOLD;
1356
1357 /* If resolution > 1280x1024, expire length = 64,
1358 else expire length = 128 */
1359 if ((hor_active > 1280) && (ver_active > 1024))
1360 iga2_display_queue_expire_num = 16;
1361 else
1362 iga2_display_queue_expire_num =
1363 CN700_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1364 }
1365
1366 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700) {
1367 iga2_fifo_max_depth = CX700_IGA2_FIFO_MAX_DEPTH;
1368 iga2_fifo_threshold = CX700_IGA2_FIFO_THRESHOLD;
1369 iga2_fifo_high_threshold =
1370 CX700_IGA2_FIFO_HIGH_THRESHOLD;
1371 iga2_display_queue_expire_num =
1372 CX700_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1373 }
1374
1375 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K8M890) {
1376 iga2_fifo_max_depth = K8M890_IGA2_FIFO_MAX_DEPTH;
1377 iga2_fifo_threshold = K8M890_IGA2_FIFO_THRESHOLD;
1378 iga2_fifo_high_threshold =
1379 K8M890_IGA2_FIFO_HIGH_THRESHOLD;
1380 iga2_display_queue_expire_num =
1381 K8M890_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1382 }
1383
1384 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_P4M890) {
1385 iga2_fifo_max_depth = P4M890_IGA2_FIFO_MAX_DEPTH;
1386 iga2_fifo_threshold = P4M890_IGA2_FIFO_THRESHOLD;
1387 iga2_fifo_high_threshold =
1388 P4M890_IGA2_FIFO_HIGH_THRESHOLD;
1389 iga2_display_queue_expire_num =
1390 P4M890_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1391 }
1392
1393 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_P4M900) {
1394 iga2_fifo_max_depth = P4M900_IGA2_FIFO_MAX_DEPTH;
1395 iga2_fifo_threshold = P4M900_IGA2_FIFO_THRESHOLD;
1396 iga2_fifo_high_threshold =
1397 P4M900_IGA2_FIFO_HIGH_THRESHOLD;
1398 iga2_display_queue_expire_num =
1399 P4M900_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1400 }
1401
1402 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_VX800) {
1403 iga2_fifo_max_depth = VX800_IGA2_FIFO_MAX_DEPTH;
1404 iga2_fifo_threshold = VX800_IGA2_FIFO_THRESHOLD;
1405 iga2_fifo_high_threshold =
1406 VX800_IGA2_FIFO_HIGH_THRESHOLD;
1407 iga2_display_queue_expire_num =
1408 VX800_IGA2_DISPLAY_QUEUE_EXPIRE_NUM;
1409 }
1410
1411 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K800) {
1412 /* Set Display FIFO Depath Select */
1413 reg_value =
1414 IGA2_FIFO_DEPTH_SELECT_FORMULA(iga2_fifo_max_depth)
1415 - 1;
1416 /* Patch LCD in IGA2 case */
1417 viafb_load_reg_num =
1418 display_fifo_depth_reg.
1419 iga2_fifo_depth_select_reg.reg_num;
1420 reg =
1421 display_fifo_depth_reg.
1422 iga2_fifo_depth_select_reg.reg;
1423 viafb_load_reg(reg_value,
1424 viafb_load_reg_num, reg, VIACR);
1425 } else {
1426
1427 /* Set Display FIFO Depath Select */
1428 reg_value =
1429 IGA2_FIFO_DEPTH_SELECT_FORMULA(iga2_fifo_max_depth);
1430 viafb_load_reg_num =
1431 display_fifo_depth_reg.
1432 iga2_fifo_depth_select_reg.reg_num;
1433 reg =
1434 display_fifo_depth_reg.
1435 iga2_fifo_depth_select_reg.reg;
1436 viafb_load_reg(reg_value,
1437 viafb_load_reg_num, reg, VIACR);
1438 }
1439
1440 /* Set Display FIFO Threshold Select */
1441 reg_value = IGA2_FIFO_THRESHOLD_FORMULA(iga2_fifo_threshold);
1442 viafb_load_reg_num =
1443 fifo_threshold_select_reg.
1444 iga2_fifo_threshold_select_reg.reg_num;
1445 reg =
1446 fifo_threshold_select_reg.
1447 iga2_fifo_threshold_select_reg.reg;
1448 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
1449
1450 /* Set FIFO High Threshold Select */
1451 reg_value =
1452 IGA2_FIFO_HIGH_THRESHOLD_FORMULA(iga2_fifo_high_threshold);
1453 viafb_load_reg_num =
1454 fifo_high_threshold_select_reg.
1455 iga2_fifo_high_threshold_select_reg.reg_num;
1456 reg =
1457 fifo_high_threshold_select_reg.
1458 iga2_fifo_high_threshold_select_reg.reg;
1459 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
1460
1461 /* Set Display Queue Expire Num */
1462 reg_value =
1463 IGA2_DISPLAY_QUEUE_EXPIRE_NUM_FORMULA
1464 (iga2_display_queue_expire_num);
1465 viafb_load_reg_num =
1466 display_queue_expire_num_reg.
1467 iga2_display_queue_expire_num_reg.reg_num;
1468 reg =
1469 display_queue_expire_num_reg.
1470 iga2_display_queue_expire_num_reg.reg;
1471 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
1472
1473 }
1474
1475}
1476
1477u32 viafb_get_clk_value(int clk)
1478{
1479 int i;
1480
1481 for (i = 0; i < NUM_TOTAL_PLL_TABLE; i++) {
1482 if (clk == pll_value[i].clk) {
1483 switch (viaparinfo->chip_info->gfx_chip_name) {
1484 case UNICHROME_CLE266:
1485 case UNICHROME_K400:
1486 return pll_value[i].cle266_pll;
1487
1488 case UNICHROME_K800:
1489 case UNICHROME_PM800:
1490 case UNICHROME_CN700:
1491 return pll_value[i].k800_pll;
1492
1493 case UNICHROME_CX700:
1494 case UNICHROME_K8M890:
1495 case UNICHROME_P4M890:
1496 case UNICHROME_P4M900:
1497 case UNICHROME_VX800:
1498 return pll_value[i].cx700_pll;
1499 }
1500 }
1501 }
1502
1503 DEBUG_MSG(KERN_INFO "Can't find match PLL value\n\n");
1504 return 0;
1505}
1506
1507/* Set VCLK*/
1508void viafb_set_vclock(u32 CLK, int set_iga)
1509{
1510 unsigned char RegTemp;
1511
1512 /* H.W. Reset : ON */
1513 viafb_write_reg_mask(CR17, VIACR, 0x00, BIT7);
1514
1515 if ((set_iga == IGA1) || (set_iga == IGA1_IGA2)) {
1516 /* Change D,N FOR VCLK */
1517 switch (viaparinfo->chip_info->gfx_chip_name) {
1518 case UNICHROME_CLE266:
1519 case UNICHROME_K400:
1520 viafb_write_reg(SR46, VIASR, CLK / 0x100);
1521 viafb_write_reg(SR47, VIASR, CLK % 0x100);
1522 break;
1523
1524 case UNICHROME_K800:
1525 case UNICHROME_PM800:
1526 case UNICHROME_CN700:
1527 case UNICHROME_CX700:
1528 case UNICHROME_K8M890:
1529 case UNICHROME_P4M890:
1530 case UNICHROME_P4M900:
1531 case UNICHROME_VX800:
1532 viafb_write_reg(SR44, VIASR, CLK / 0x10000);
1533 DEBUG_MSG(KERN_INFO "\nSR44=%x", CLK / 0x10000);
1534 viafb_write_reg(SR45, VIASR, (CLK & 0xFFFF) / 0x100);
1535 DEBUG_MSG(KERN_INFO "\nSR45=%x",
1536 (CLK & 0xFFFF) / 0x100);
1537 viafb_write_reg(SR46, VIASR, CLK % 0x100);
1538 DEBUG_MSG(KERN_INFO "\nSR46=%x", CLK % 0x100);
1539 break;
1540 }
1541 }
1542
1543 if ((set_iga == IGA2) || (set_iga == IGA1_IGA2)) {
1544 /* Change D,N FOR LCK */
1545 switch (viaparinfo->chip_info->gfx_chip_name) {
1546 case UNICHROME_CLE266:
1547 case UNICHROME_K400:
1548 viafb_write_reg(SR44, VIASR, CLK / 0x100);
1549 viafb_write_reg(SR45, VIASR, CLK % 0x100);
1550 break;
1551
1552 case UNICHROME_K800:
1553 case UNICHROME_PM800:
1554 case UNICHROME_CN700:
1555 case UNICHROME_CX700:
1556 case UNICHROME_K8M890:
1557 case UNICHROME_P4M890:
1558 case UNICHROME_P4M900:
1559 case UNICHROME_VX800:
1560 viafb_write_reg(SR4A, VIASR, CLK / 0x10000);
1561 viafb_write_reg(SR4B, VIASR, (CLK & 0xFFFF) / 0x100);
1562 viafb_write_reg(SR4C, VIASR, CLK % 0x100);
1563 break;
1564 }
1565 }
1566
1567 /* H.W. Reset : OFF */
1568 viafb_write_reg_mask(CR17, VIACR, 0x80, BIT7);
1569
1570 /* Reset PLL */
1571 if ((set_iga == IGA1) || (set_iga == IGA1_IGA2)) {
1572 viafb_write_reg_mask(SR40, VIASR, 0x02, BIT1);
1573 viafb_write_reg_mask(SR40, VIASR, 0x00, BIT1);
1574 }
1575
1576 if ((set_iga == IGA2) || (set_iga == IGA1_IGA2)) {
1577 viafb_write_reg_mask(SR40, VIASR, 0x01, BIT0);
1578 viafb_write_reg_mask(SR40, VIASR, 0x00, BIT0);
1579 }
1580
1581 /* Fire! */
1582 RegTemp = inb(VIARMisc);
1583 outb(RegTemp | (BIT2 + BIT3), VIAWMisc);
1584}
1585
1586void viafb_load_crtc_timing(struct display_timing device_timing,
1587 int set_iga)
1588{
1589 int i;
1590 int viafb_load_reg_num = 0;
1591 int reg_value = 0;
1592 struct io_register *reg = NULL;
1593
1594 viafb_unlock_crt();
1595
1596 for (i = 0; i < 12; i++) {
1597 if (set_iga == IGA1) {
1598 switch (i) {
1599 case H_TOTAL_INDEX:
1600 reg_value =
1601 IGA1_HOR_TOTAL_FORMULA(device_timing.
1602 hor_total);
1603 viafb_load_reg_num =
1604 iga1_crtc_reg.hor_total.reg_num;
1605 reg = iga1_crtc_reg.hor_total.reg;
1606 break;
1607 case H_ADDR_INDEX:
1608 reg_value =
1609 IGA1_HOR_ADDR_FORMULA(device_timing.
1610 hor_addr);
1611 viafb_load_reg_num =
1612 iga1_crtc_reg.hor_addr.reg_num;
1613 reg = iga1_crtc_reg.hor_addr.reg;
1614 break;
1615 case H_BLANK_START_INDEX:
1616 reg_value =
1617 IGA1_HOR_BLANK_START_FORMULA
1618 (device_timing.hor_blank_start);
1619 viafb_load_reg_num =
1620 iga1_crtc_reg.hor_blank_start.reg_num;
1621 reg = iga1_crtc_reg.hor_blank_start.reg;
1622 break;
1623 case H_BLANK_END_INDEX:
1624 reg_value =
1625 IGA1_HOR_BLANK_END_FORMULA
1626 (device_timing.hor_blank_start,
1627 device_timing.hor_blank_end);
1628 viafb_load_reg_num =
1629 iga1_crtc_reg.hor_blank_end.reg_num;
1630 reg = iga1_crtc_reg.hor_blank_end.reg;
1631 break;
1632 case H_SYNC_START_INDEX:
1633 reg_value =
1634 IGA1_HOR_SYNC_START_FORMULA
1635 (device_timing.hor_sync_start);
1636 viafb_load_reg_num =
1637 iga1_crtc_reg.hor_sync_start.reg_num;
1638 reg = iga1_crtc_reg.hor_sync_start.reg;
1639 break;
1640 case H_SYNC_END_INDEX:
1641 reg_value =
1642 IGA1_HOR_SYNC_END_FORMULA
1643 (device_timing.hor_sync_start,
1644 device_timing.hor_sync_end);
1645 viafb_load_reg_num =
1646 iga1_crtc_reg.hor_sync_end.reg_num;
1647 reg = iga1_crtc_reg.hor_sync_end.reg;
1648 break;
1649 case V_TOTAL_INDEX:
1650 reg_value =
1651 IGA1_VER_TOTAL_FORMULA(device_timing.
1652 ver_total);
1653 viafb_load_reg_num =
1654 iga1_crtc_reg.ver_total.reg_num;
1655 reg = iga1_crtc_reg.ver_total.reg;
1656 break;
1657 case V_ADDR_INDEX:
1658 reg_value =
1659 IGA1_VER_ADDR_FORMULA(device_timing.
1660 ver_addr);
1661 viafb_load_reg_num =
1662 iga1_crtc_reg.ver_addr.reg_num;
1663 reg = iga1_crtc_reg.ver_addr.reg;
1664 break;
1665 case V_BLANK_START_INDEX:
1666 reg_value =
1667 IGA1_VER_BLANK_START_FORMULA
1668 (device_timing.ver_blank_start);
1669 viafb_load_reg_num =
1670 iga1_crtc_reg.ver_blank_start.reg_num;
1671 reg = iga1_crtc_reg.ver_blank_start.reg;
1672 break;
1673 case V_BLANK_END_INDEX:
1674 reg_value =
1675 IGA1_VER_BLANK_END_FORMULA
1676 (device_timing.ver_blank_start,
1677 device_timing.ver_blank_end);
1678 viafb_load_reg_num =
1679 iga1_crtc_reg.ver_blank_end.reg_num;
1680 reg = iga1_crtc_reg.ver_blank_end.reg;
1681 break;
1682 case V_SYNC_START_INDEX:
1683 reg_value =
1684 IGA1_VER_SYNC_START_FORMULA
1685 (device_timing.ver_sync_start);
1686 viafb_load_reg_num =
1687 iga1_crtc_reg.ver_sync_start.reg_num;
1688 reg = iga1_crtc_reg.ver_sync_start.reg;
1689 break;
1690 case V_SYNC_END_INDEX:
1691 reg_value =
1692 IGA1_VER_SYNC_END_FORMULA
1693 (device_timing.ver_sync_start,
1694 device_timing.ver_sync_end);
1695 viafb_load_reg_num =
1696 iga1_crtc_reg.ver_sync_end.reg_num;
1697 reg = iga1_crtc_reg.ver_sync_end.reg;
1698 break;
1699
1700 }
1701 }
1702
1703 if (set_iga == IGA2) {
1704 switch (i) {
1705 case H_TOTAL_INDEX:
1706 reg_value =
1707 IGA2_HOR_TOTAL_FORMULA(device_timing.
1708 hor_total);
1709 viafb_load_reg_num =
1710 iga2_crtc_reg.hor_total.reg_num;
1711 reg = iga2_crtc_reg.hor_total.reg;
1712 break;
1713 case H_ADDR_INDEX:
1714 reg_value =
1715 IGA2_HOR_ADDR_FORMULA(device_timing.
1716 hor_addr);
1717 viafb_load_reg_num =
1718 iga2_crtc_reg.hor_addr.reg_num;
1719 reg = iga2_crtc_reg.hor_addr.reg;
1720 break;
1721 case H_BLANK_START_INDEX:
1722 reg_value =
1723 IGA2_HOR_BLANK_START_FORMULA
1724 (device_timing.hor_blank_start);
1725 viafb_load_reg_num =
1726 iga2_crtc_reg.hor_blank_start.reg_num;
1727 reg = iga2_crtc_reg.hor_blank_start.reg;
1728 break;
1729 case H_BLANK_END_INDEX:
1730 reg_value =
1731 IGA2_HOR_BLANK_END_FORMULA
1732 (device_timing.hor_blank_start,
1733 device_timing.hor_blank_end);
1734 viafb_load_reg_num =
1735 iga2_crtc_reg.hor_blank_end.reg_num;
1736 reg = iga2_crtc_reg.hor_blank_end.reg;
1737 break;
1738 case H_SYNC_START_INDEX:
1739 reg_value =
1740 IGA2_HOR_SYNC_START_FORMULA
1741 (device_timing.hor_sync_start);
1742 if (UNICHROME_CN700 <=
1743 viaparinfo->chip_info->gfx_chip_name)
1744 viafb_load_reg_num =
1745 iga2_crtc_reg.hor_sync_start.
1746 reg_num;
1747 else
1748 viafb_load_reg_num = 3;
1749 reg = iga2_crtc_reg.hor_sync_start.reg;
1750 break;
1751 case H_SYNC_END_INDEX:
1752 reg_value =
1753 IGA2_HOR_SYNC_END_FORMULA
1754 (device_timing.hor_sync_start,
1755 device_timing.hor_sync_end);
1756 viafb_load_reg_num =
1757 iga2_crtc_reg.hor_sync_end.reg_num;
1758 reg = iga2_crtc_reg.hor_sync_end.reg;
1759 break;
1760 case V_TOTAL_INDEX:
1761 reg_value =
1762 IGA2_VER_TOTAL_FORMULA(device_timing.
1763 ver_total);
1764 viafb_load_reg_num =
1765 iga2_crtc_reg.ver_total.reg_num;
1766 reg = iga2_crtc_reg.ver_total.reg;
1767 break;
1768 case V_ADDR_INDEX:
1769 reg_value =
1770 IGA2_VER_ADDR_FORMULA(device_timing.
1771 ver_addr);
1772 viafb_load_reg_num =
1773 iga2_crtc_reg.ver_addr.reg_num;
1774 reg = iga2_crtc_reg.ver_addr.reg;
1775 break;
1776 case V_BLANK_START_INDEX:
1777 reg_value =
1778 IGA2_VER_BLANK_START_FORMULA
1779 (device_timing.ver_blank_start);
1780 viafb_load_reg_num =
1781 iga2_crtc_reg.ver_blank_start.reg_num;
1782 reg = iga2_crtc_reg.ver_blank_start.reg;
1783 break;
1784 case V_BLANK_END_INDEX:
1785 reg_value =
1786 IGA2_VER_BLANK_END_FORMULA
1787 (device_timing.ver_blank_start,
1788 device_timing.ver_blank_end);
1789 viafb_load_reg_num =
1790 iga2_crtc_reg.ver_blank_end.reg_num;
1791 reg = iga2_crtc_reg.ver_blank_end.reg;
1792 break;
1793 case V_SYNC_START_INDEX:
1794 reg_value =
1795 IGA2_VER_SYNC_START_FORMULA
1796 (device_timing.ver_sync_start);
1797 viafb_load_reg_num =
1798 iga2_crtc_reg.ver_sync_start.reg_num;
1799 reg = iga2_crtc_reg.ver_sync_start.reg;
1800 break;
1801 case V_SYNC_END_INDEX:
1802 reg_value =
1803 IGA2_VER_SYNC_END_FORMULA
1804 (device_timing.ver_sync_start,
1805 device_timing.ver_sync_end);
1806 viafb_load_reg_num =
1807 iga2_crtc_reg.ver_sync_end.reg_num;
1808 reg = iga2_crtc_reg.ver_sync_end.reg;
1809 break;
1810
1811 }
1812 }
1813 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
1814 }
1815
1816 viafb_lock_crt();
1817}
1818
1819void viafb_set_color_depth(int bpp_byte, int set_iga)
1820{
1821 if (set_iga == IGA1) {
1822 switch (bpp_byte) {
1823 case MODE_8BPP:
1824 viafb_write_reg_mask(SR15, VIASR, 0x22, 0x7E);
1825 break;
1826 case MODE_16BPP:
1827 viafb_write_reg_mask(SR15, VIASR, 0xB6, 0xFE);
1828 break;
1829 case MODE_32BPP:
1830 viafb_write_reg_mask(SR15, VIASR, 0xAE, 0xFE);
1831 break;
1832 }
1833 } else {
1834 switch (bpp_byte) {
1835 case MODE_8BPP:
1836 viafb_write_reg_mask(CR67, VIACR, 0x00, BIT6 + BIT7);
1837 break;
1838 case MODE_16BPP:
1839 viafb_write_reg_mask(CR67, VIACR, 0x40, BIT6 + BIT7);
1840 break;
1841 case MODE_32BPP:
1842 viafb_write_reg_mask(CR67, VIACR, 0xC0, BIT6 + BIT7);
1843 break;
1844 }
1845 }
1846}
1847
1848void viafb_fill_crtc_timing(struct crt_mode_table *crt_table,
1849 int mode_index, int bpp_byte, int set_iga)
1850{
1851 struct VideoModeTable *video_mode;
1852 struct display_timing crt_reg;
1853 int i;
1854 int index = 0;
1855 int h_addr, v_addr;
1856 u32 pll_D_N;
1857
1858 video_mode = &CLE266Modes[search_mode_setting(mode_index)];
1859
1860 for (i = 0; i < video_mode->mode_array; i++) {
1861 index = i;
1862
1863 if (crt_table[i].refresh_rate == viaparinfo->
1864 crt_setting_info->refresh_rate)
1865 break;
1866 }
1867
1868 crt_reg = crt_table[index].crtc;
1869
1870 /* Mode 640x480 has border, but LCD/DFP didn't have border. */
1871 /* So we would delete border. */
1872 if ((viafb_LCD_ON | viafb_DVI_ON) && (mode_index == VIA_RES_640X480)
1873 && (viaparinfo->crt_setting_info->refresh_rate == 60)) {
1874 /* The border is 8 pixels. */
1875 crt_reg.hor_blank_start = crt_reg.hor_blank_start - 8;
1876
1877 /* Blanking time should add left and right borders. */
1878 crt_reg.hor_blank_end = crt_reg.hor_blank_end + 16;
1879 }
1880
1881 h_addr = crt_reg.hor_addr;
1882 v_addr = crt_reg.ver_addr;
1883
1884 /* update polarity for CRT timing */
1885 if (crt_table[index].h_sync_polarity == NEGATIVE) {
1886 if (crt_table[index].v_sync_polarity == NEGATIVE)
1887 outb((inb(VIARMisc) & (~(BIT6 + BIT7))) |
1888 (BIT6 + BIT7), VIAWMisc);
1889 else
1890 outb((inb(VIARMisc) & (~(BIT6 + BIT7))) | (BIT6),
1891 VIAWMisc);
1892 } else {
1893 if (crt_table[index].v_sync_polarity == NEGATIVE)
1894 outb((inb(VIARMisc) & (~(BIT6 + BIT7))) | (BIT7),
1895 VIAWMisc);
1896 else
1897 outb((inb(VIARMisc) & (~(BIT6 + BIT7))), VIAWMisc);
1898 }
1899
1900 if (set_iga == IGA1) {
1901 viafb_unlock_crt();
1902 viafb_write_reg(CR09, VIACR, 0x00); /*initial CR09=0 */
1903 viafb_write_reg_mask(CR11, VIACR, 0x00, BIT4 + BIT5 + BIT6);
1904 viafb_write_reg_mask(CR17, VIACR, 0x00, BIT7);
1905 }
1906
1907 switch (set_iga) {
1908 case IGA1:
1909 viafb_load_crtc_timing(crt_reg, IGA1);
1910 break;
1911 case IGA2:
1912 viafb_load_crtc_timing(crt_reg, IGA2);
1913 break;
1914 }
1915
1916 load_fix_bit_crtc_reg();
1917 viafb_lock_crt();
1918 viafb_write_reg_mask(CR17, VIACR, 0x80, BIT7);
1919 viafb_load_offset_reg(h_addr, bpp_byte, set_iga);
1920 viafb_load_fetch_count_reg(h_addr, bpp_byte, set_iga);
1921
1922 /* load FIFO */
1923 if ((viaparinfo->chip_info->gfx_chip_name != UNICHROME_CLE266)
1924 && (viaparinfo->chip_info->gfx_chip_name != UNICHROME_K400))
1925 viafb_load_FIFO_reg(set_iga, h_addr, v_addr);
1926
1927 /* load SR Register About Memory and Color part */
1928 viafb_set_color_depth(bpp_byte, set_iga);
1929
1930 pll_D_N = viafb_get_clk_value(crt_table[index].clk);
1931 DEBUG_MSG(KERN_INFO "PLL=%x", pll_D_N);
1932 viafb_set_vclock(pll_D_N, set_iga);
1933
1934}
1935
1936void viafb_init_chip_info(void)
1937{
1938 init_gfx_chip_info();
1939 init_tmds_chip_info();
1940 init_lvds_chip_info();
1941
1942 viaparinfo->crt_setting_info->iga_path = IGA1;
1943 viaparinfo->crt_setting_info->refresh_rate = viafb_refresh;
1944
1945 /*Set IGA path for each device */
1946 viafb_set_iga_path();
1947
1948 viaparinfo->lvds_setting_info->display_method = viafb_lcd_dsp_method;
1949 viaparinfo->lvds_setting_info->get_lcd_size_method =
1950 GET_LCD_SIZE_BY_USER_SETTING;
1951 viaparinfo->lvds_setting_info->lcd_mode = viafb_lcd_mode;
1952 viaparinfo->lvds_setting_info2->display_method =
1953 viaparinfo->lvds_setting_info->display_method;
1954 viaparinfo->lvds_setting_info2->lcd_mode =
1955 viaparinfo->lvds_setting_info->lcd_mode;
1956}
1957
1958void viafb_update_device_setting(int hres, int vres,
1959 int bpp, int vmode_refresh, int flag)
1960{
1961 if (flag == 0) {
1962 viaparinfo->crt_setting_info->h_active = hres;
1963 viaparinfo->crt_setting_info->v_active = vres;
1964 viaparinfo->crt_setting_info->bpp = bpp;
1965 viaparinfo->crt_setting_info->refresh_rate =
1966 vmode_refresh;
1967
1968 viaparinfo->tmds_setting_info->h_active = hres;
1969 viaparinfo->tmds_setting_info->v_active = vres;
1970 viaparinfo->tmds_setting_info->bpp = bpp;
1971 viaparinfo->tmds_setting_info->refresh_rate =
1972 vmode_refresh;
1973
1974 viaparinfo->lvds_setting_info->h_active = hres;
1975 viaparinfo->lvds_setting_info->v_active = vres;
1976 viaparinfo->lvds_setting_info->bpp = bpp;
1977 viaparinfo->lvds_setting_info->refresh_rate =
1978 vmode_refresh;
1979 viaparinfo->lvds_setting_info2->h_active = hres;
1980 viaparinfo->lvds_setting_info2->v_active = vres;
1981 viaparinfo->lvds_setting_info2->bpp = bpp;
1982 viaparinfo->lvds_setting_info2->refresh_rate =
1983 vmode_refresh;
1984 } else {
1985
1986 if (viaparinfo->tmds_setting_info->iga_path == IGA2) {
1987 viaparinfo->tmds_setting_info->h_active = hres;
1988 viaparinfo->tmds_setting_info->v_active = vres;
1989 viaparinfo->tmds_setting_info->bpp = bpp;
1990 viaparinfo->tmds_setting_info->refresh_rate =
1991 vmode_refresh;
1992 }
1993
1994 if (viaparinfo->lvds_setting_info->iga_path == IGA2) {
1995 viaparinfo->lvds_setting_info->h_active = hres;
1996 viaparinfo->lvds_setting_info->v_active = vres;
1997 viaparinfo->lvds_setting_info->bpp = bpp;
1998 viaparinfo->lvds_setting_info->refresh_rate =
1999 vmode_refresh;
2000 }
2001 if (IGA2 == viaparinfo->lvds_setting_info2->iga_path) {
2002 viaparinfo->lvds_setting_info2->h_active = hres;
2003 viaparinfo->lvds_setting_info2->v_active = vres;
2004 viaparinfo->lvds_setting_info2->bpp = bpp;
2005 viaparinfo->lvds_setting_info2->refresh_rate =
2006 vmode_refresh;
2007 }
2008 }
2009}
2010
2011static void init_gfx_chip_info(void)
2012{
2013 struct pci_dev *pdev = NULL;
2014 u32 i;
2015 u8 tmp;
2016
2017 /* Indentify GFX Chip Name */
2018 for (i = 0; pciidlist[i].vendor != 0; i++) {
2019 pdev = pci_get_device(pciidlist[i].vendor,
2020 pciidlist[i].device, 0);
2021 if (pdev)
2022 break;
2023 }
2024
2025 if (!pciidlist[i].vendor)
2026 return ;
2027
2028 viaparinfo->chip_info->gfx_chip_name = pciidlist[i].chip_index;
2029
2030 /* Check revision of CLE266 Chip */
2031 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
2032 /* CR4F only define in CLE266.CX chip */
2033 tmp = viafb_read_reg(VIACR, CR4F);
2034 viafb_write_reg(CR4F, VIACR, 0x55);
2035 if (viafb_read_reg(VIACR, CR4F) != 0x55)
2036 viaparinfo->chip_info->gfx_chip_revision =
2037 CLE266_REVISION_AX;
2038 else
2039 viaparinfo->chip_info->gfx_chip_revision =
2040 CLE266_REVISION_CX;
2041 /* restore orignal CR4F value */
2042 viafb_write_reg(CR4F, VIACR, tmp);
2043 }
2044
2045 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700) {
2046 tmp = viafb_read_reg(VIASR, SR43);
2047 DEBUG_MSG(KERN_INFO "SR43:%X\n", tmp);
2048 if (tmp & 0x02) {
2049 viaparinfo->chip_info->gfx_chip_revision =
2050 CX700_REVISION_700M2;
2051 } else if (tmp & 0x40) {
2052 viaparinfo->chip_info->gfx_chip_revision =
2053 CX700_REVISION_700M;
2054 } else {
2055 viaparinfo->chip_info->gfx_chip_revision =
2056 CX700_REVISION_700;
2057 }
2058 }
2059
2060 pci_dev_put(pdev);
2061}
2062
2063static void init_tmds_chip_info(void)
2064{
2065 viafb_tmds_trasmitter_identify();
2066
2067 if (INTERFACE_NONE == viaparinfo->chip_info->tmds_chip_info.
2068 output_interface) {
2069 switch (viaparinfo->chip_info->gfx_chip_name) {
2070 case UNICHROME_CX700:
2071 {
2072 /* we should check support by hardware layout.*/
2073 if ((viafb_display_hardware_layout ==
2074 HW_LAYOUT_DVI_ONLY)
2075 || (viafb_display_hardware_layout ==
2076 HW_LAYOUT_LCD_DVI)) {
2077 viaparinfo->chip_info->tmds_chip_info.
2078 output_interface = INTERFACE_TMDS;
2079 } else {
2080 viaparinfo->chip_info->tmds_chip_info.
2081 output_interface =
2082 INTERFACE_NONE;
2083 }
2084 break;
2085 }
2086 case UNICHROME_K8M890:
2087 case UNICHROME_P4M900:
2088 case UNICHROME_P4M890:
2089 /* TMDS on PCIE, we set DFPLOW as default. */
2090 viaparinfo->chip_info->tmds_chip_info.output_interface =
2091 INTERFACE_DFP_LOW;
2092 break;
2093 default:
2094 {
2095 /* set DVP1 default for DVI */
2096 viaparinfo->chip_info->tmds_chip_info
2097 .output_interface = INTERFACE_DVP1;
2098 }
2099 }
2100 }
2101
2102 DEBUG_MSG(KERN_INFO "TMDS Chip = %d\n",
2103 viaparinfo->chip_info->tmds_chip_info.tmds_chip_name);
2104 viaparinfo->tmds_setting_info->get_dvi_size_method =
2105 GET_DVI_SIZE_BY_VGA_BIOS;
2106 viafb_init_dvi_size();
2107}
2108
2109static void init_lvds_chip_info(void)
2110{
2111 if (viafb_lcd_panel_id > LCD_PANEL_ID_MAXIMUM)
2112 viaparinfo->lvds_setting_info->get_lcd_size_method =
2113 GET_LCD_SIZE_BY_VGA_BIOS;
2114 else
2115 viaparinfo->lvds_setting_info->get_lcd_size_method =
2116 GET_LCD_SIZE_BY_USER_SETTING;
2117
2118 viafb_lvds_trasmitter_identify();
2119 viafb_init_lcd_size();
2120 viafb_init_lvds_output_interface(&viaparinfo->chip_info->lvds_chip_info,
2121 viaparinfo->lvds_setting_info);
2122 if (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
2123 viafb_init_lvds_output_interface(&viaparinfo->chip_info->
2124 lvds_chip_info2, viaparinfo->lvds_setting_info2);
2125 }
2126 /*If CX700,two singel LCD, we need to reassign
2127 LCD interface to different LVDS port */
2128 if ((UNICHROME_CX700 == viaparinfo->chip_info->gfx_chip_name)
2129 && (HW_LAYOUT_LCD1_LCD2 == viafb_display_hardware_layout)) {
2130 if ((INTEGRATED_LVDS == viaparinfo->chip_info->lvds_chip_info.
2131 lvds_chip_name) && (INTEGRATED_LVDS ==
2132 viaparinfo->chip_info->
2133 lvds_chip_info2.lvds_chip_name)) {
2134 viaparinfo->chip_info->lvds_chip_info.output_interface =
2135 INTERFACE_LVDS0;
2136 viaparinfo->chip_info->lvds_chip_info2.
2137 output_interface =
2138 INTERFACE_LVDS1;
2139 }
2140 }
2141
2142 DEBUG_MSG(KERN_INFO "LVDS Chip = %d\n",
2143 viaparinfo->chip_info->lvds_chip_info.lvds_chip_name);
2144 DEBUG_MSG(KERN_INFO "LVDS1 output_interface = %d\n",
2145 viaparinfo->chip_info->lvds_chip_info.output_interface);
2146 DEBUG_MSG(KERN_INFO "LVDS2 output_interface = %d\n",
2147 viaparinfo->chip_info->lvds_chip_info.output_interface);
2148}
2149
2150void viafb_init_dac(int set_iga)
2151{
2152 int i;
2153 u8 tmp;
2154
2155 if (set_iga == IGA1) {
2156 /* access Primary Display's LUT */
2157 viafb_write_reg_mask(SR1A, VIASR, 0x00, BIT0);
2158 /* turn off LCK */
2159 viafb_write_reg_mask(SR1B, VIASR, 0x00, BIT7 + BIT6);
2160 for (i = 0; i < 256; i++) {
2161 write_dac_reg(i, palLUT_table[i].red,
2162 palLUT_table[i].green,
2163 palLUT_table[i].blue);
2164 }
2165 /* turn on LCK */
2166 viafb_write_reg_mask(SR1B, VIASR, 0xC0, BIT7 + BIT6);
2167 } else {
2168 tmp = viafb_read_reg(VIACR, CR6A);
2169 /* access Secondary Display's LUT */
2170 viafb_write_reg_mask(CR6A, VIACR, 0x40, BIT6);
2171 viafb_write_reg_mask(SR1A, VIASR, 0x01, BIT0);
2172 for (i = 0; i < 256; i++) {
2173 write_dac_reg(i, palLUT_table[i].red,
2174 palLUT_table[i].green,
2175 palLUT_table[i].blue);
2176 }
2177 /* set IGA1 DAC for default */
2178 viafb_write_reg_mask(SR1A, VIASR, 0x00, BIT0);
2179 viafb_write_reg(CR6A, VIACR, tmp);
2180 }
2181}
2182
2183static void device_screen_off(void)
2184{
2185 /* turn off CRT screen (IGA1) */
2186 viafb_write_reg_mask(SR01, VIASR, 0x20, BIT5);
2187}
2188
2189static void device_screen_on(void)
2190{
2191 /* turn on CRT screen (IGA1) */
2192 viafb_write_reg_mask(SR01, VIASR, 0x00, BIT5);
2193}
2194
2195static void set_display_channel(void)
2196{
2197 /*If viafb_LCD2_ON, on cx700, internal lvds's information
2198 is keeped on lvds_setting_info2 */
2199 if (viafb_LCD2_ON &&
2200 viaparinfo->lvds_setting_info2->device_lcd_dualedge) {
2201 /* For dual channel LCD: */
2202 /* Set to Dual LVDS channel. */
2203 viafb_write_reg_mask(CRD2, VIACR, 0x20, BIT4 + BIT5);
2204 } else if (viafb_LCD_ON && viafb_DVI_ON) {
2205 /* For LCD+DFP: */
2206 /* Set to LVDS1 + TMDS channel. */
2207 viafb_write_reg_mask(CRD2, VIACR, 0x10, BIT4 + BIT5);
2208 } else if (viafb_DVI_ON) {
2209 /* Set to single TMDS channel. */
2210 viafb_write_reg_mask(CRD2, VIACR, 0x30, BIT4 + BIT5);
2211 } else if (viafb_LCD_ON) {
2212 if (viaparinfo->lvds_setting_info->device_lcd_dualedge) {
2213 /* For dual channel LCD: */
2214 /* Set to Dual LVDS channel. */
2215 viafb_write_reg_mask(CRD2, VIACR, 0x20, BIT4 + BIT5);
2216 } else {
2217 /* Set to LVDS0 + LVDS1 channel. */
2218 viafb_write_reg_mask(CRD2, VIACR, 0x00, BIT4 + BIT5);
2219 }
2220 }
2221}
2222
2223int viafb_setmode(int vmode_index, int hor_res, int ver_res, int video_bpp,
2224 int vmode_index1, int hor_res1, int ver_res1, int video_bpp1)
2225{
2226 int i, j;
2227 int port;
2228 u8 value, index, mask;
2229 struct VideoModeTable *vmode_tbl;
2230 struct crt_mode_table *crt_timing;
2231 struct VideoModeTable *vmode_tbl1 = NULL;
2232 struct crt_mode_table *crt_timing1 = NULL;
2233
2234 DEBUG_MSG(KERN_INFO "Set Mode!!\n");
2235 DEBUG_MSG(KERN_INFO
2236 "vmode_index=%d hor_res=%d ver_res=%d video_bpp=%d\n",
2237 vmode_index, hor_res, ver_res, video_bpp);
2238
2239 device_screen_off();
2240 vmode_tbl = &CLE266Modes[search_mode_setting(vmode_index)];
2241 crt_timing = vmode_tbl->crtc;
2242
2243 if (viafb_SAMM_ON == 1) {
2244 vmode_tbl1 = &CLE266Modes[search_mode_setting(vmode_index1)];
2245 crt_timing1 = vmode_tbl1->crtc;
2246 }
2247
2248 inb(VIAStatus);
2249 outb(0x00, VIAAR);
2250
2251 /* Write Common Setting for Video Mode */
2252 switch (viaparinfo->chip_info->gfx_chip_name) {
2253 case UNICHROME_CLE266:
2254 viafb_write_regx(CLE266_ModeXregs, NUM_TOTAL_CLE266_ModeXregs);
2255 break;
2256
2257 case UNICHROME_K400:
2258 viafb_write_regx(KM400_ModeXregs, NUM_TOTAL_KM400_ModeXregs);
2259 break;
2260
2261 case UNICHROME_K800:
2262 case UNICHROME_PM800:
2263 viafb_write_regx(CN400_ModeXregs, NUM_TOTAL_CN400_ModeXregs);
2264 break;
2265
2266 case UNICHROME_CN700:
2267 case UNICHROME_K8M890:
2268 case UNICHROME_P4M890:
2269 case UNICHROME_P4M900:
2270 viafb_write_regx(CN700_ModeXregs, NUM_TOTAL_CN700_ModeXregs);
2271 break;
2272
2273 case UNICHROME_CX700:
2274 viafb_write_regx(CX700_ModeXregs, NUM_TOTAL_CX700_ModeXregs);
2275
2276 case UNICHROME_VX800:
2277 viafb_write_regx(VX800_ModeXregs, NUM_TOTAL_VX800_ModeXregs);
2278
2279 break;
2280 }
2281
2282 device_off();
2283
2284 /* Fill VPIT Parameters */
2285 /* Write Misc Register */
2286 outb(VPIT.Misc, VIAWMisc);
2287
2288 /* Write Sequencer */
2289 for (i = 1; i <= StdSR; i++) {
2290 outb(i, VIASR);
2291 outb(VPIT.SR[i - 1], VIASR + 1);
2292 }
2293
2294 viafb_set_start_addr();
2295 viafb_set_iga_path();
2296
2297 /* Write CRTC */
2298 viafb_fill_crtc_timing(crt_timing, vmode_index, video_bpp / 8, IGA1);
2299
2300 /* Write Graphic Controller */
2301 for (i = 0; i < StdGR; i++) {
2302 outb(i, VIAGR);
2303 outb(VPIT.GR[i], VIAGR + 1);
2304 }
2305
2306 /* Write Attribute Controller */
2307 for (i = 0; i < StdAR; i++) {
2308 inb(VIAStatus);
2309 outb(i, VIAAR);
2310 outb(VPIT.AR[i], VIAAR);
2311 }
2312
2313 inb(VIAStatus);
2314 outb(0x20, VIAAR);
2315
2316 /* Update Patch Register */
2317
2318 if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
2319 || (viaparinfo->chip_info->gfx_chip_name == UNICHROME_K400)) {
2320 for (i = 0; i < NUM_TOTAL_PATCH_MODE; i++) {
2321 if (res_patch_table[i].mode_index == vmode_index) {
2322 for (j = 0;
2323 j < res_patch_table[i].table_length; j++) {
2324 index =
2325 res_patch_table[i].
2326 io_reg_table[j].index;
2327 port =
2328 res_patch_table[i].
2329 io_reg_table[j].port;
2330 value =
2331 res_patch_table[i].
2332 io_reg_table[j].value;
2333 mask =
2334 res_patch_table[i].
2335 io_reg_table[j].mask;
2336 viafb_write_reg_mask(index, port, value,
2337 mask);
2338 }
2339 }
2340 }
2341 }
2342
2343 if (viafb_SAMM_ON == 1) {
2344 if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)
2345 || (viaparinfo->chip_info->gfx_chip_name ==
2346 UNICHROME_K400)) {
2347 for (i = 0; i < NUM_TOTAL_PATCH_MODE; i++) {
2348 if (res_patch_table[i].mode_index ==
2349 vmode_index1) {
2350 for (j = 0;
2351 j <
2352 res_patch_table[i].
2353 table_length; j++) {
2354 index =
2355 res_patch_table[i].
2356 io_reg_table[j].index;
2357 port =
2358 res_patch_table[i].
2359 io_reg_table[j].port;
2360 value =
2361 res_patch_table[i].
2362 io_reg_table[j].value;
2363 mask =
2364 res_patch_table[i].
2365 io_reg_table[j].mask;
2366 viafb_write_reg_mask(index,
2367 port, value, mask);
2368 }
2369 }
2370 }
2371 }
2372 }
2373
2374 /* Update Refresh Rate Setting */
2375
2376 /* Clear On Screen */
2377
2378 /* CRT set mode */
2379 if (viafb_CRT_ON) {
2380 if (viafb_SAMM_ON && (viaparinfo->crt_setting_info->iga_path ==
2381 IGA2)) {
2382 viafb_fill_crtc_timing(crt_timing1, vmode_index1,
2383 video_bpp1 / 8,
2384 viaparinfo->crt_setting_info->iga_path);
2385 } else {
2386 viafb_fill_crtc_timing(crt_timing, vmode_index,
2387 video_bpp / 8,
2388 viaparinfo->crt_setting_info->iga_path);
2389 }
2390
2391 set_crt_output_path(viaparinfo->crt_setting_info->iga_path);
2392
2393 /* Patch if set_hres is not 8 alignment (1366) to viafb_setmode
2394 to 8 alignment (1368),there is several pixels (2 pixels)
2395 on right side of screen. */
2396 if (hor_res % 8) {
2397 viafb_unlock_crt();
2398 viafb_write_reg(CR02, VIACR,
2399 viafb_read_reg(VIACR, CR02) - 1);
2400 viafb_lock_crt();
2401 }
2402 }
2403
2404 if (viafb_DVI_ON) {
2405 if (viafb_SAMM_ON &&
2406 (viaparinfo->tmds_setting_info->iga_path == IGA2)) {
2407 viafb_dvi_set_mode(viafb_get_mode_index
2408 (viaparinfo->tmds_setting_info->h_active,
2409 viaparinfo->tmds_setting_info->
2410 v_active, 1),
2411 video_bpp1, viaparinfo->
2412 tmds_setting_info->iga_path);
2413 } else {
2414 viafb_dvi_set_mode(viafb_get_mode_index
2415 (viaparinfo->tmds_setting_info->h_active,
2416 viaparinfo->
2417 tmds_setting_info->v_active, 0),
2418 video_bpp, viaparinfo->
2419 tmds_setting_info->iga_path);
2420 }
2421 }
2422
2423 if (viafb_LCD_ON) {
2424 if (viafb_SAMM_ON &&
2425 (viaparinfo->lvds_setting_info->iga_path == IGA2)) {
2426 viaparinfo->lvds_setting_info->bpp = video_bpp1;
2427 viafb_lcd_set_mode(crt_timing1, viaparinfo->
2428 lvds_setting_info,
2429 &viaparinfo->chip_info->lvds_chip_info);
2430 } else {
2431 /* IGA1 doesn't have LCD scaling, so set it center. */
2432 if (viaparinfo->lvds_setting_info->iga_path == IGA1) {
2433 viaparinfo->lvds_setting_info->display_method =
2434 LCD_CENTERING;
2435 }
2436 viaparinfo->lvds_setting_info->bpp = video_bpp;
2437 viafb_lcd_set_mode(crt_timing, viaparinfo->
2438 lvds_setting_info,
2439 &viaparinfo->chip_info->lvds_chip_info);
2440 }
2441 }
2442 if (viafb_LCD2_ON) {
2443 if (viafb_SAMM_ON &&
2444 (viaparinfo->lvds_setting_info2->iga_path == IGA2)) {
2445 viaparinfo->lvds_setting_info2->bpp = video_bpp1;
2446 viafb_lcd_set_mode(crt_timing1, viaparinfo->
2447 lvds_setting_info2,
2448 &viaparinfo->chip_info->lvds_chip_info2);
2449 } else {
2450 /* IGA1 doesn't have LCD scaling, so set it center. */
2451 if (viaparinfo->lvds_setting_info2->iga_path == IGA1) {
2452 viaparinfo->lvds_setting_info2->display_method =
2453 LCD_CENTERING;
2454 }
2455 viaparinfo->lvds_setting_info2->bpp = video_bpp;
2456 viafb_lcd_set_mode(crt_timing, viaparinfo->
2457 lvds_setting_info2,
2458 &viaparinfo->chip_info->lvds_chip_info2);
2459 }
2460 }
2461
2462 if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700)
2463 && (viafb_LCD_ON || viafb_DVI_ON))
2464 set_display_channel();
2465
2466 /* If set mode normally, save resolution information for hot-plug . */
2467 if (!viafb_hotplug) {
2468 viafb_hotplug_Xres = hor_res;
2469 viafb_hotplug_Yres = ver_res;
2470 viafb_hotplug_bpp = video_bpp;
2471 viafb_hotplug_refresh = viafb_refresh;
2472
2473 if (viafb_DVI_ON)
2474 viafb_DeviceStatus = DVI_Device;
2475 else
2476 viafb_DeviceStatus = CRT_Device;
2477 }
2478 device_on();
2479
2480 if (viafb_SAMM_ON == 1)
2481 viafb_write_reg_mask(CR6A, VIACR, 0xC0, BIT6 + BIT7);
2482
2483 device_screen_on();
2484 return 1;
2485}
2486
2487int viafb_get_pixclock(int hres, int vres, int vmode_refresh)
2488{
2489 int i;
2490
2491 for (i = 0; i < NUM_TOTAL_RES_MAP_REFRESH; i++) {
2492 if ((hres == res_map_refresh_tbl[i].hres)
2493 && (vres == res_map_refresh_tbl[i].vres)
2494 && (vmode_refresh == res_map_refresh_tbl[i].vmode_refresh))
2495 return res_map_refresh_tbl[i].pixclock;
2496 }
2497 return RES_640X480_60HZ_PIXCLOCK;
2498
2499}
2500
2501int viafb_get_refresh(int hres, int vres, u32 long_refresh)
2502{
2503#define REFRESH_TOLERANCE 3
2504 int i, nearest = -1, diff = REFRESH_TOLERANCE;
2505 for (i = 0; i < NUM_TOTAL_RES_MAP_REFRESH; i++) {
2506 if ((hres == res_map_refresh_tbl[i].hres)
2507 && (vres == res_map_refresh_tbl[i].vres)
2508 && (diff > (abs(long_refresh -
2509 res_map_refresh_tbl[i].vmode_refresh)))) {
2510 diff = abs(long_refresh - res_map_refresh_tbl[i].
2511 vmode_refresh);
2512 nearest = i;
2513 }
2514 }
2515#undef REFRESH_TOLERANCE
2516 if (nearest > 0)
2517 return res_map_refresh_tbl[nearest].vmode_refresh;
2518 return 60;
2519}
2520
2521static void device_off(void)
2522{
2523 viafb_crt_disable();
2524 viafb_dvi_disable();
2525 viafb_lcd_disable();
2526}
2527
2528static void device_on(void)
2529{
2530 if (viafb_CRT_ON == 1)
2531 viafb_crt_enable();
2532 if (viafb_DVI_ON == 1)
2533 viafb_dvi_enable();
2534 if (viafb_LCD_ON == 1)
2535 viafb_lcd_enable();
2536}
2537
2538void viafb_crt_disable(void)
2539{
2540 viafb_write_reg_mask(CR36, VIACR, BIT5 + BIT4, BIT5 + BIT4);
2541}
2542
2543void viafb_crt_enable(void)
2544{
2545 viafb_write_reg_mask(CR36, VIACR, 0x0, BIT5 + BIT4);
2546}
2547
2548void viafb_get_mmio_info(unsigned long *mmio_base,
2549 unsigned long *mmio_len)
2550{
2551 struct pci_dev *pdev = NULL;
2552 u32 vendor, device;
2553 u32 i;
2554
2555 for (i = 0; pciidlist[i].vendor != 0; i++)
2556 if (viaparinfo->chip_info->gfx_chip_name ==
2557 pciidlist[i].chip_index)
2558 break;
2559
2560 if (!pciidlist[i].vendor)
2561 return ;
2562
2563 vendor = pciidlist[i].vendor;
2564 device = pciidlist[i].device;
2565
2566 pdev = pci_get_device(vendor, device, NULL);
2567
2568 if (!pdev) {
2569 *mmio_base = 0;
2570 *mmio_len = 0;
2571 return ;
2572 }
2573
2574 *mmio_base = pci_resource_start(pdev, 1);
2575 *mmio_len = pci_resource_len(pdev, 1);
2576
2577 pci_dev_put(pdev);
2578}
2579
2580static void enable_second_display_channel(void)
2581{
2582 /* to enable second display channel. */
2583 viafb_write_reg_mask(CR6A, VIACR, 0x00, BIT6);
2584 viafb_write_reg_mask(CR6A, VIACR, BIT7, BIT7);
2585 viafb_write_reg_mask(CR6A, VIACR, BIT6, BIT6);
2586}
2587
2588static void disable_second_display_channel(void)
2589{
2590 /* to disable second display channel. */
2591 viafb_write_reg_mask(CR6A, VIACR, 0x00, BIT6);
2592 viafb_write_reg_mask(CR6A, VIACR, 0x00, BIT7);
2593 viafb_write_reg_mask(CR6A, VIACR, BIT6, BIT6);
2594}
2595
2596void viafb_get_fb_info(unsigned int *fb_base, unsigned int *fb_len)
2597{
2598 struct pci_dev *pdev = NULL;
2599 u32 vendor, device;
2600 u32 i;
2601
2602 for (i = 0; pciidlist[i].vendor != 0; i++)
2603 if (viaparinfo->chip_info->gfx_chip_name ==
2604 pciidlist[i].chip_index)
2605 break;
2606
2607 if (!pciidlist[i].vendor)
2608 return ;
2609
2610 vendor = pciidlist[i].vendor;
2611 device = pciidlist[i].device;
2612
2613 pdev = pci_get_device(vendor, device, NULL);
2614
2615 if (!pdev) {
2616 *fb_base = viafb_read_reg(VIASR, SR30) << 24;
2617 *fb_len = viafb_get_memsize();
2618 DEBUG_MSG(KERN_INFO "Get FB info from SR30!\n");
2619 DEBUG_MSG(KERN_INFO "fb_base = %08x\n", *fb_base);
2620 DEBUG_MSG(KERN_INFO "fb_len = %08x\n", *fb_len);
2621 return ;
2622 }
2623
2624 *fb_base = (unsigned int)pci_resource_start(pdev, 0);
2625 *fb_len = get_fb_size_from_pci();
2626 DEBUG_MSG(KERN_INFO "Get FB info from PCI system!\n");
2627 DEBUG_MSG(KERN_INFO "fb_base = %08x\n", *fb_base);
2628 DEBUG_MSG(KERN_INFO "fb_len = %08x\n", *fb_len);
2629
2630 pci_dev_put(pdev);
2631}
2632
2633static int get_fb_size_from_pci(void)
2634{
2635 unsigned long configid, deviceid, FBSize = 0;
2636 int VideoMemSize;
2637 int DeviceFound = false;
2638
2639 for (configid = 0x80000000; configid < 0x80010800; configid += 0x100) {
2640 outl(configid, (unsigned long)0xCF8);
2641 deviceid = (inl((unsigned long)0xCFC) >> 16) & 0xffff;
2642
2643 switch (deviceid) {
2644 case CLE266:
2645 case KM400:
2646 outl(configid + 0xE0, (unsigned long)0xCF8);
2647 FBSize = inl((unsigned long)0xCFC);
2648 DeviceFound = true; /* Found device id */
2649 break;
2650
2651 case CN400_FUNCTION3:
2652 case CN700_FUNCTION3:
2653 case CX700_FUNCTION3:
2654 case KM800_FUNCTION3:
2655 case KM890_FUNCTION3:
2656 case P4M890_FUNCTION3:
2657 case P4M900_FUNCTION3:
2658 case VX800_FUNCTION3:
2659 /*case CN750_FUNCTION3: */
2660 outl(configid + 0xA0, (unsigned long)0xCF8);
2661 FBSize = inl((unsigned long)0xCFC);
2662 DeviceFound = true; /* Found device id */
2663 break;
2664
2665 default:
2666 break;
2667 }
2668
2669 if (DeviceFound)
2670 break;
2671 }
2672
2673 DEBUG_MSG(KERN_INFO "Device ID = %lx\n", deviceid);
2674
2675 FBSize = FBSize & 0x00007000;
2676 DEBUG_MSG(KERN_INFO "FB Size = %x\n", FBSize);
2677
2678 if (viaparinfo->chip_info->gfx_chip_name < UNICHROME_CX700) {
2679 switch (FBSize) {
2680 case 0x00004000:
2681 VideoMemSize = (16 << 20); /*16M */
2682 break;
2683
2684 case 0x00005000:
2685 VideoMemSize = (32 << 20); /*32M */
2686 break;
2687
2688 case 0x00006000:
2689 VideoMemSize = (64 << 20); /*64M */
2690 break;
2691
2692 default:
2693 VideoMemSize = (32 << 20); /*32M */
2694 break;
2695 }
2696 } else {
2697 switch (FBSize) {
2698 case 0x00001000:
2699 VideoMemSize = (8 << 20); /*8M */
2700 break;
2701
2702 case 0x00002000:
2703 VideoMemSize = (16 << 20); /*16M */
2704 break;
2705
2706 case 0x00003000:
2707 VideoMemSize = (32 << 20); /*32M */
2708 break;
2709
2710 case 0x00004000:
2711 VideoMemSize = (64 << 20); /*64M */
2712 break;
2713
2714 case 0x00005000:
2715 VideoMemSize = (128 << 20); /*128M */
2716 break;
2717
2718 case 0x00006000:
2719 VideoMemSize = (256 << 20); /*256M */
2720 break;
2721
2722 default:
2723 VideoMemSize = (32 << 20); /*32M */
2724 break;
2725 }
2726 }
2727
2728 return VideoMemSize;
2729}
2730
2731void viafb_set_dpa_gfx(int output_interface, struct GFX_DPA_SETTING\
2732 *p_gfx_dpa_setting)
2733{
2734 switch (output_interface) {
2735 case INTERFACE_DVP0:
2736 {
2737 /* DVP0 Clock Polarity and Adjust: */
2738 viafb_write_reg_mask(CR96, VIACR,
2739 p_gfx_dpa_setting->DVP0, 0x0F);
2740
2741 /* DVP0 Clock and Data Pads Driving: */
2742 viafb_write_reg_mask(SR1E, VIASR,
2743 p_gfx_dpa_setting->DVP0ClockDri_S, BIT2);
2744 viafb_write_reg_mask(SR2A, VIASR,
2745 p_gfx_dpa_setting->DVP0ClockDri_S1,
2746 BIT4);
2747 viafb_write_reg_mask(SR1B, VIASR,
2748 p_gfx_dpa_setting->DVP0DataDri_S, BIT1);
2749 viafb_write_reg_mask(SR2A, VIASR,
2750 p_gfx_dpa_setting->DVP0DataDri_S1, BIT5);
2751 break;
2752 }
2753
2754 case INTERFACE_DVP1:
2755 {
2756 /* DVP1 Clock Polarity and Adjust: */
2757 viafb_write_reg_mask(CR9B, VIACR,
2758 p_gfx_dpa_setting->DVP1, 0x0F);
2759
2760 /* DVP1 Clock and Data Pads Driving: */
2761 viafb_write_reg_mask(SR65, VIASR,
2762 p_gfx_dpa_setting->DVP1Driving, 0x0F);
2763 break;
2764 }
2765
2766 case INTERFACE_DFP_HIGH:
2767 {
2768 viafb_write_reg_mask(CR97, VIACR,
2769 p_gfx_dpa_setting->DFPHigh, 0x0F);
2770 break;
2771 }
2772
2773 case INTERFACE_DFP_LOW:
2774 {
2775 viafb_write_reg_mask(CR99, VIACR,
2776 p_gfx_dpa_setting->DFPLow, 0x0F);
2777 break;
2778 }
2779
2780 case INTERFACE_DFP:
2781 {
2782 viafb_write_reg_mask(CR97, VIACR,
2783 p_gfx_dpa_setting->DFPHigh, 0x0F);
2784 viafb_write_reg_mask(CR99, VIACR,
2785 p_gfx_dpa_setting->DFPLow, 0x0F);
2786 break;
2787 }
2788 }
2789}
2790
2791void viafb_memory_pitch_patch(struct fb_info *info)
2792{
2793 if (info->var.xres != info->var.xres_virtual) {
2794 viafb_load_offset_reg(info->var.xres_virtual,
2795 info->var.bits_per_pixel >> 3, IGA1);
2796
2797 if (viafb_SAMM_ON) {
2798 viafb_load_offset_reg(viafb_second_virtual_xres,
2799 viafb_bpp1 >> 3,
2800 IGA2);
2801 } else {
2802 viafb_load_offset_reg(info->var.xres_virtual,
2803 info->var.bits_per_pixel >> 3, IGA2);
2804 }
2805
2806 }
2807}
2808
2809/*According var's xres, yres fill var's other timing information*/
2810void viafb_fill_var_timing_info(struct fb_var_screeninfo *var, int refresh,
2811 int mode_index)
2812{
2813 struct VideoModeTable *vmode_tbl = NULL;
2814 struct crt_mode_table *crt_timing = NULL;
2815 struct display_timing crt_reg;
2816 int i = 0, index = 0;
2817 vmode_tbl = &CLE266Modes[search_mode_setting(mode_index)];
2818 crt_timing = vmode_tbl->crtc;
2819 for (i = 0; i < vmode_tbl->mode_array; i++) {
2820 index = i;
2821 if (crt_timing[i].refresh_rate == refresh)
2822 break;
2823 }
2824
2825 crt_reg = crt_timing[index].crtc;
2826 switch (var->bits_per_pixel) {
2827 case 8:
2828 var->red.offset = 0;
2829 var->green.offset = 0;
2830 var->blue.offset = 0;
2831 var->red.length = 6;
2832 var->green.length = 6;
2833 var->blue.length = 6;
2834 break;
2835 case 16:
2836 var->red.offset = 11;
2837 var->green.offset = 5;
2838 var->blue.offset = 0;
2839 var->red.length = 5;
2840 var->green.length = 6;
2841 var->blue.length = 5;
2842 break;
2843 case 32:
2844 var->red.offset = 16;
2845 var->green.offset = 8;
2846 var->blue.offset = 0;
2847 var->red.length = 8;
2848 var->green.length = 8;
2849 var->blue.length = 8;
2850 break;
2851 default:
2852 /* never happed, put here to keep consistent */
2853 break;
2854 }
2855
2856 var->pixclock = viafb_get_pixclock(var->xres, var->yres, refresh);
2857 var->left_margin =
2858 crt_reg.hor_total - (crt_reg.hor_sync_start + crt_reg.hor_sync_end);
2859 var->right_margin = crt_reg.hor_sync_start - crt_reg.hor_addr;
2860 var->hsync_len = crt_reg.hor_sync_end;
2861 var->upper_margin =
2862 crt_reg.ver_total - (crt_reg.ver_sync_start + crt_reg.ver_sync_end);
2863 var->lower_margin = crt_reg.ver_sync_start - crt_reg.ver_addr;
2864 var->vsync_len = crt_reg.ver_sync_end;
2865}
diff --git a/drivers/video/via/hw.h b/drivers/video/via/hw.h
new file mode 100644
index 000000000000..6ff38fa8569a
--- /dev/null
+++ b/drivers/video/via/hw.h
@@ -0,0 +1,933 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#ifndef __HW_H__
23#define __HW_H__
24
25#include "global.h"
26
27/***************************************************
28* Definition IGA1 Design Method of CRTC Registers *
29****************************************************/
30#define IGA1_HOR_TOTAL_FORMULA(x) (((x)/8)-5)
31#define IGA1_HOR_ADDR_FORMULA(x) (((x)/8)-1)
32#define IGA1_HOR_BLANK_START_FORMULA(x) (((x)/8)-1)
33#define IGA1_HOR_BLANK_END_FORMULA(x, y) (((x+y)/8)-1)
34#define IGA1_HOR_SYNC_START_FORMULA(x) ((x)/8)
35#define IGA1_HOR_SYNC_END_FORMULA(x, y) ((x+y)/8)
36
37#define IGA1_VER_TOTAL_FORMULA(x) ((x)-2)
38#define IGA1_VER_ADDR_FORMULA(x) ((x)-1)
39#define IGA1_VER_BLANK_START_FORMULA(x) ((x)-1)
40#define IGA1_VER_BLANK_END_FORMULA(x, y) ((x+y)-1)
41#define IGA1_VER_SYNC_START_FORMULA(x) ((x)-1)
42#define IGA1_VER_SYNC_END_FORMULA(x, y) ((x+y)-1)
43
44/***************************************************
45** Definition IGA2 Design Method of CRTC Registers *
46****************************************************/
47#define IGA2_HOR_TOTAL_FORMULA(x) ((x)-1)
48#define IGA2_HOR_ADDR_FORMULA(x) ((x)-1)
49#define IGA2_HOR_BLANK_START_FORMULA(x) ((x)-1)
50#define IGA2_HOR_BLANK_END_FORMULA(x, y) ((x+y)-1)
51#define IGA2_HOR_SYNC_START_FORMULA(x) ((x)-1)
52#define IGA2_HOR_SYNC_END_FORMULA(x, y) ((x+y)-1)
53
54#define IGA2_VER_TOTAL_FORMULA(x) ((x)-1)
55#define IGA2_VER_ADDR_FORMULA(x) ((x)-1)
56#define IGA2_VER_BLANK_START_FORMULA(x) ((x)-1)
57#define IGA2_VER_BLANK_END_FORMULA(x, y) ((x+y)-1)
58#define IGA2_VER_SYNC_START_FORMULA(x) ((x)-1)
59#define IGA2_VER_SYNC_END_FORMULA(x, y) ((x+y)-1)
60
61/**********************************************************/
62/* Definition IGA2 Design Method of CRTC Shadow Registers */
63/**********************************************************/
64#define IGA2_HOR_TOTAL_SHADOW_FORMULA(x) ((x/8)-5)
65#define IGA2_HOR_BLANK_END_SHADOW_FORMULA(x, y) (((x+y)/8)-1)
66#define IGA2_VER_TOTAL_SHADOW_FORMULA(x) ((x)-2)
67#define IGA2_VER_ADDR_SHADOW_FORMULA(x) ((x)-1)
68#define IGA2_VER_BLANK_START_SHADOW_FORMULA(x) ((x)-1)
69#define IGA2_VER_BLANK_END_SHADOW_FORMULA(x, y) ((x+y)-1)
70#define IGA2_VER_SYNC_START_SHADOW_FORMULA(x) (x)
71#define IGA2_VER_SYNC_END_SHADOW_FORMULA(x, y) (x+y)
72
73/* Define Register Number for IGA1 CRTC Timing */
74
75/* location: {CR00,0,7},{CR36,3,3} */
76#define IGA1_HOR_TOTAL_REG_NUM 2
77/* location: {CR01,0,7} */
78#define IGA1_HOR_ADDR_REG_NUM 1
79/* location: {CR02,0,7} */
80#define IGA1_HOR_BLANK_START_REG_NUM 1
81/* location: {CR03,0,4},{CR05,7,7},{CR33,5,5} */
82#define IGA1_HOR_BLANK_END_REG_NUM 3
83/* location: {CR04,0,7},{CR33,4,4} */
84#define IGA1_HOR_SYNC_START_REG_NUM 2
85/* location: {CR05,0,4} */
86#define IGA1_HOR_SYNC_END_REG_NUM 1
87/* location: {CR06,0,7},{CR07,0,0},{CR07,5,5},{CR35,0,0} */
88#define IGA1_VER_TOTAL_REG_NUM 4
89/* location: {CR12,0,7},{CR07,1,1},{CR07,6,6},{CR35,2,2} */
90#define IGA1_VER_ADDR_REG_NUM 4
91/* location: {CR15,0,7},{CR07,3,3},{CR09,5,5},{CR35,3,3} */
92#define IGA1_VER_BLANK_START_REG_NUM 4
93/* location: {CR16,0,7} */
94#define IGA1_VER_BLANK_END_REG_NUM 1
95/* location: {CR10,0,7},{CR07,2,2},{CR07,7,7},{CR35,1,1} */
96#define IGA1_VER_SYNC_START_REG_NUM 4
97/* location: {CR11,0,3} */
98#define IGA1_VER_SYNC_END_REG_NUM 1
99
100/* Define Register Number for IGA2 Shadow CRTC Timing */
101
102/* location: {CR6D,0,7},{CR71,3,3} */
103#define IGA2_SHADOW_HOR_TOTAL_REG_NUM 2
104/* location: {CR6E,0,7} */
105#define IGA2_SHADOW_HOR_BLANK_END_REG_NUM 1
106/* location: {CR6F,0,7},{CR71,0,2} */
107#define IGA2_SHADOW_VER_TOTAL_REG_NUM 2
108/* location: {CR70,0,7},{CR71,4,6} */
109#define IGA2_SHADOW_VER_ADDR_REG_NUM 2
110/* location: {CR72,0,7},{CR74,4,6} */
111#define IGA2_SHADOW_VER_BLANK_START_REG_NUM 2
112/* location: {CR73,0,7},{CR74,0,2} */
113#define IGA2_SHADOW_VER_BLANK_END_REG_NUM 2
114/* location: {CR75,0,7},{CR76,4,6} */
115#define IGA2_SHADOW_VER_SYNC_START_REG_NUM 2
116/* location: {CR76,0,3} */
117#define IGA2_SHADOW_VER_SYNC_END_REG_NUM 1
118
119/* Define Register Number for IGA2 CRTC Timing */
120
121/* location: {CR50,0,7},{CR55,0,3} */
122#define IGA2_HOR_TOTAL_REG_NUM 2
123/* location: {CR51,0,7},{CR55,4,6} */
124#define IGA2_HOR_ADDR_REG_NUM 2
125/* location: {CR52,0,7},{CR54,0,2} */
126#define IGA2_HOR_BLANK_START_REG_NUM 2
127/* location: CLE266: {CR53,0,7},{CR54,3,5} => CLE266's CR5D[6]
128is reserved, so it may have problem to set 1600x1200 on IGA2. */
129/* Others: {CR53,0,7},{CR54,3,5},{CR5D,6,6} */
130#define IGA2_HOR_BLANK_END_REG_NUM 3
131/* location: {CR56,0,7},{CR54,6,7},{CR5C,7,7} */
132/* VT3314 and Later: {CR56,0,7},{CR54,6,7},{CR5C,7,7}, {CR5D,7,7} */
133#define IGA2_HOR_SYNC_START_REG_NUM 4
134
135/* location: {CR57,0,7},{CR5C,6,6} */
136#define IGA2_HOR_SYNC_END_REG_NUM 2
137/* location: {CR58,0,7},{CR5D,0,2} */
138#define IGA2_VER_TOTAL_REG_NUM 2
139/* location: {CR59,0,7},{CR5D,3,5} */
140#define IGA2_VER_ADDR_REG_NUM 2
141/* location: {CR5A,0,7},{CR5C,0,2} */
142#define IGA2_VER_BLANK_START_REG_NUM 2
143/* location: {CR5E,0,7},{CR5C,3,5} */
144#define IGA2_VER_BLANK_END_REG_NUM 2
145/* location: {CR5E,0,7},{CR5F,5,7} */
146#define IGA2_VER_SYNC_START_REG_NUM 2
147/* location: {CR5F,0,4} */
148#define IGA2_VER_SYNC_END_REG_NUM 1
149
150/* Define Offset and Fetch Count Register*/
151
152/* location: {CR13,0,7},{CR35,5,7} */
153#define IGA1_OFFSET_REG_NUM 2
154/* 8 bytes alignment. */
155#define IGA1_OFFSER_ALIGN_BYTE 8
156/* x: H resolution, y: color depth */
157#define IGA1_OFFSET_FORMULA(x, y) ((x*y)/IGA1_OFFSER_ALIGN_BYTE)
158/* location: {SR1C,0,7},{SR1D,0,1} */
159#define IGA1_FETCH_COUNT_REG_NUM 2
160/* 16 bytes alignment. */
161#define IGA1_FETCH_COUNT_ALIGN_BYTE 16
162/* x: H resolution, y: color depth */
163#define IGA1_FETCH_COUNT_PATCH_VALUE 4
164#define IGA1_FETCH_COUNT_FORMULA(x, y) \
165 (((x*y)/IGA1_FETCH_COUNT_ALIGN_BYTE) + IGA1_FETCH_COUNT_PATCH_VALUE)
166
167/* location: {CR66,0,7},{CR67,0,1} */
168#define IGA2_OFFSET_REG_NUM 2
169#define IGA2_OFFSET_ALIGN_BYTE 8
170/* x: H resolution, y: color depth */
171#define IGA2_OFFSET_FORMULA(x, y) ((x*y)/IGA2_OFFSET_ALIGN_BYTE)
172/* location: {CR65,0,7},{CR67,2,3} */
173#define IGA2_FETCH_COUNT_REG_NUM 2
174#define IGA2_FETCH_COUNT_ALIGN_BYTE 16
175#define IGA2_FETCH_COUNT_PATCH_VALUE 0
176#define IGA2_FETCH_COUNT_FORMULA(x, y) \
177 (((x*y)/IGA2_FETCH_COUNT_ALIGN_BYTE) + IGA2_FETCH_COUNT_PATCH_VALUE)
178
179/* Staring Address*/
180
181/* location: {CR0C,0,7},{CR0D,0,7},{CR34,0,7},{CR48,0,1} */
182#define IGA1_STARTING_ADDR_REG_NUM 4
183/* location: {CR62,1,7},{CR63,0,7},{CR64,0,7} */
184#define IGA2_STARTING_ADDR_REG_NUM 3
185
186/* Define Display OFFSET*/
187/* These value are by HW suggested value*/
188/* location: {SR17,0,7} */
189#define K800_IGA1_FIFO_MAX_DEPTH 384
190/* location: {SR16,0,5},{SR16,7,7} */
191#define K800_IGA1_FIFO_THRESHOLD 328
192/* location: {SR18,0,5},{SR18,7,7} */
193#define K800_IGA1_FIFO_HIGH_THRESHOLD 296
194/* location: {SR22,0,4}. (128/4) =64, K800 must be set zero, */
195 /* because HW only 5 bits */
196#define K800_IGA1_DISPLAY_QUEUE_EXPIRE_NUM 0
197
198/* location: {CR68,4,7},{CR94,7,7},{CR95,7,7} */
199#define K800_IGA2_FIFO_MAX_DEPTH 384
200/* location: {CR68,0,3},{CR95,4,6} */
201#define K800_IGA2_FIFO_THRESHOLD 328
202/* location: {CR92,0,3},{CR95,0,2} */
203#define K800_IGA2_FIFO_HIGH_THRESHOLD 296
204/* location: {CR94,0,6} */
205#define K800_IGA2_DISPLAY_QUEUE_EXPIRE_NUM 128
206
207/* location: {SR17,0,7} */
208#define P880_IGA1_FIFO_MAX_DEPTH 192
209/* location: {SR16,0,5},{SR16,7,7} */
210#define P880_IGA1_FIFO_THRESHOLD 128
211/* location: {SR18,0,5},{SR18,7,7} */
212#define P880_IGA1_FIFO_HIGH_THRESHOLD 64
213/* location: {SR22,0,4}. (128/4) =64, K800 must be set zero, */
214 /* because HW only 5 bits */
215#define P880_IGA1_DISPLAY_QUEUE_EXPIRE_NUM 0
216
217/* location: {CR68,4,7},{CR94,7,7},{CR95,7,7} */
218#define P880_IGA2_FIFO_MAX_DEPTH 96
219/* location: {CR68,0,3},{CR95,4,6} */
220#define P880_IGA2_FIFO_THRESHOLD 64
221/* location: {CR92,0,3},{CR95,0,2} */
222#define P880_IGA2_FIFO_HIGH_THRESHOLD 32
223/* location: {CR94,0,6} */
224#define P880_IGA2_DISPLAY_QUEUE_EXPIRE_NUM 128
225
226/* VT3314 chipset*/
227
228/* location: {SR17,0,7} */
229#define CN700_IGA1_FIFO_MAX_DEPTH 96
230/* location: {SR16,0,5},{SR16,7,7} */
231#define CN700_IGA1_FIFO_THRESHOLD 80
232/* location: {SR18,0,5},{SR18,7,7} */
233#define CN700_IGA1_FIFO_HIGH_THRESHOLD 64
234/* location: {SR22,0,4}. (128/4) =64, P800 must be set zero,
235 because HW only 5 bits */
236#define CN700_IGA1_DISPLAY_QUEUE_EXPIRE_NUM 0
237/* location: {CR68,4,7},{CR94,7,7},{CR95,7,7} */
238#define CN700_IGA2_FIFO_MAX_DEPTH 96
239/* location: {CR68,0,3},{CR95,4,6} */
240#define CN700_IGA2_FIFO_THRESHOLD 80
241/* location: {CR92,0,3},{CR95,0,2} */
242#define CN700_IGA2_FIFO_HIGH_THRESHOLD 32
243/* location: {CR94,0,6} */
244#define CN700_IGA2_DISPLAY_QUEUE_EXPIRE_NUM 128
245
246/* For VT3324, these values are suggested by HW */
247/* location: {SR17,0,7} */
248#define CX700_IGA1_FIFO_MAX_DEPTH 192
249/* location: {SR16,0,5},{SR16,7,7} */
250#define CX700_IGA1_FIFO_THRESHOLD 128
251/* location: {SR18,0,5},{SR18,7,7} */
252#define CX700_IGA1_FIFO_HIGH_THRESHOLD 128
253/* location: {SR22,0,4} */
254#define CX700_IGA1_DISPLAY_QUEUE_EXPIRE_NUM 124
255
256/* location: {CR68,4,7},{CR94,7,7},{CR95,7,7} */
257#define CX700_IGA2_FIFO_MAX_DEPTH 96
258/* location: {CR68,0,3},{CR95,4,6} */
259#define CX700_IGA2_FIFO_THRESHOLD 64
260/* location: {CR92,0,3},{CR95,0,2} */
261#define CX700_IGA2_FIFO_HIGH_THRESHOLD 32
262/* location: {CR94,0,6} */
263#define CX700_IGA2_DISPLAY_QUEUE_EXPIRE_NUM 128
264
265/* VT3336 chipset*/
266/* location: {SR17,0,7} */
267#define K8M890_IGA1_FIFO_MAX_DEPTH 360
268/* location: {SR16,0,5},{SR16,7,7} */
269#define K8M890_IGA1_FIFO_THRESHOLD 328
270/* location: {SR18,0,5},{SR18,7,7} */
271#define K8M890_IGA1_FIFO_HIGH_THRESHOLD 296
272/* location: {SR22,0,4}. */
273#define K8M890_IGA1_DISPLAY_QUEUE_EXPIRE_NUM 124
274
275/* location: {CR68,4,7},{CR94,7,7},{CR95,7,7} */
276#define K8M890_IGA2_FIFO_MAX_DEPTH 360
277/* location: {CR68,0,3},{CR95,4,6} */
278#define K8M890_IGA2_FIFO_THRESHOLD 328
279/* location: {CR92,0,3},{CR95,0,2} */
280#define K8M890_IGA2_FIFO_HIGH_THRESHOLD 296
281/* location: {CR94,0,6} */
282#define K8M890_IGA2_DISPLAY_QUEUE_EXPIRE_NUM 124
283
284/* VT3327 chipset*/
285/* location: {SR17,0,7} */
286#define P4M890_IGA1_FIFO_MAX_DEPTH 96
287/* location: {SR16,0,5},{SR16,7,7} */
288#define P4M890_IGA1_FIFO_THRESHOLD 76
289/* location: {SR18,0,5},{SR18,7,7} */
290#define P4M890_IGA1_FIFO_HIGH_THRESHOLD 64
291/* location: {SR22,0,4}. (32/4) =8 */
292#define P4M890_IGA1_DISPLAY_QUEUE_EXPIRE_NUM 32
293/* location: {CR68,4,7},{CR94,7,7},{CR95,7,7} */
294#define P4M890_IGA2_FIFO_MAX_DEPTH 96
295/* location: {CR68,0,3},{CR95,4,6} */
296#define P4M890_IGA2_FIFO_THRESHOLD 76
297/* location: {CR92,0,3},{CR95,0,2} */
298#define P4M890_IGA2_FIFO_HIGH_THRESHOLD 64
299/* location: {CR94,0,6} */
300#define P4M890_IGA2_DISPLAY_QUEUE_EXPIRE_NUM 32
301
302/* VT3364 chipset*/
303/* location: {SR17,0,7} */
304#define P4M900_IGA1_FIFO_MAX_DEPTH 96
305/* location: {SR16,0,5},{SR16,7,7} */
306#define P4M900_IGA1_FIFO_THRESHOLD 76
307/* location: {SR18,0,5},{SR18,7,7} */
308#define P4M900_IGA1_FIFO_HIGH_THRESHOLD 76
309/* location: {SR22,0,4}. */
310#define P4M900_IGA1_DISPLAY_QUEUE_EXPIRE_NUM 32
311/* location: {CR68,4,7},{CR94,7,7},{CR95,7,7} */
312#define P4M900_IGA2_FIFO_MAX_DEPTH 96
313/* location: {CR68,0,3},{CR95,4,6} */
314#define P4M900_IGA2_FIFO_THRESHOLD 76
315/* location: {CR92,0,3},{CR95,0,2} */
316#define P4M900_IGA2_FIFO_HIGH_THRESHOLD 76
317/* location: {CR94,0,6} */
318#define P4M900_IGA2_DISPLAY_QUEUE_EXPIRE_NUM 32
319
320/* For VT3353, these values are suggested by HW */
321/* location: {SR17,0,7} */
322#define VX800_IGA1_FIFO_MAX_DEPTH 192
323/* location: {SR16,0,5},{SR16,7,7} */
324#define VX800_IGA1_FIFO_THRESHOLD 152
325/* location: {SR18,0,5},{SR18,7,7} */
326#define VX800_IGA1_FIFO_HIGH_THRESHOLD 152
327/* location: {SR22,0,4} */
328#define VX800_IGA1_DISPLAY_QUEUE_EXPIRE_NUM 64
329/* location: {CR68,4,7},{CR94,7,7},{CR95,7,7} */
330#define VX800_IGA2_FIFO_MAX_DEPTH 96
331/* location: {CR68,0,3},{CR95,4,6} */
332#define VX800_IGA2_FIFO_THRESHOLD 64
333/* location: {CR92,0,3},{CR95,0,2} */
334#define VX800_IGA2_FIFO_HIGH_THRESHOLD 32
335/* location: {CR94,0,6} */
336#define VX800_IGA2_DISPLAY_QUEUE_EXPIRE_NUM 128
337
338#define IGA1_FIFO_DEPTH_SELECT_REG_NUM 1
339#define IGA1_FIFO_THRESHOLD_REG_NUM 2
340#define IGA1_FIFO_HIGH_THRESHOLD_REG_NUM 2
341#define IGA1_DISPLAY_QUEUE_EXPIRE_NUM_REG_NUM 1
342
343#define IGA2_FIFO_DEPTH_SELECT_REG_NUM 3
344#define IGA2_FIFO_THRESHOLD_REG_NUM 2
345#define IGA2_FIFO_HIGH_THRESHOLD_REG_NUM 2
346#define IGA2_DISPLAY_QUEUE_EXPIRE_NUM_REG_NUM 1
347
348#define IGA1_FIFO_DEPTH_SELECT_FORMULA(x) ((x/2)-1)
349#define IGA1_FIFO_THRESHOLD_FORMULA(x) (x/4)
350#define IGA1_DISPLAY_QUEUE_EXPIRE_NUM_FORMULA(x) (x/4)
351#define IGA1_FIFO_HIGH_THRESHOLD_FORMULA(x) (x/4)
352#define IGA2_FIFO_DEPTH_SELECT_FORMULA(x) (((x/2)/4)-1)
353#define IGA2_FIFO_THRESHOLD_FORMULA(x) (x/4)
354#define IGA2_DISPLAY_QUEUE_EXPIRE_NUM_FORMULA(x) (x/4)
355#define IGA2_FIFO_HIGH_THRESHOLD_FORMULA(x) (x/4)
356
357/************************************************************************/
358/* LCD Timing */
359/************************************************************************/
360
361/* 500 ms = 500000 us */
362#define LCD_POWER_SEQ_TD0 500000
363/* 50 ms = 50000 us */
364#define LCD_POWER_SEQ_TD1 50000
365/* 0 us */
366#define LCD_POWER_SEQ_TD2 0
367/* 210 ms = 210000 us */
368#define LCD_POWER_SEQ_TD3 210000
369/* 2^10 * (1/14.31818M) = 71.475 us (K400.revA) */
370#define CLE266_POWER_SEQ_UNIT 71
371/* 2^11 * (1/14.31818M) = 142.95 us (K400.revB) */
372#define K800_POWER_SEQ_UNIT 142
373/* 2^13 * (1/14.31818M) = 572.1 us */
374#define P880_POWER_SEQ_UNIT 572
375
376#define CLE266_POWER_SEQ_FORMULA(x) ((x)/CLE266_POWER_SEQ_UNIT)
377#define K800_POWER_SEQ_FORMULA(x) ((x)/K800_POWER_SEQ_UNIT)
378#define P880_POWER_SEQ_FORMULA(x) ((x)/P880_POWER_SEQ_UNIT)
379
380/* location: {CR8B,0,7},{CR8F,0,3} */
381#define LCD_POWER_SEQ_TD0_REG_NUM 2
382/* location: {CR8C,0,7},{CR8F,4,7} */
383#define LCD_POWER_SEQ_TD1_REG_NUM 2
384/* location: {CR8D,0,7},{CR90,0,3} */
385#define LCD_POWER_SEQ_TD2_REG_NUM 2
386/* location: {CR8E,0,7},{CR90,4,7} */
387#define LCD_POWER_SEQ_TD3_REG_NUM 2
388
389/* LCD Scaling factor*/
390/* x: indicate setting horizontal size*/
391/* y: indicate panel horizontal size*/
392
393/* Horizontal scaling factor 10 bits (2^10) */
394#define CLE266_LCD_HOR_SCF_FORMULA(x, y) (((x-1)*1024)/(y-1))
395/* Vertical scaling factor 10 bits (2^10) */
396#define CLE266_LCD_VER_SCF_FORMULA(x, y) (((x-1)*1024)/(y-1))
397/* Horizontal scaling factor 10 bits (2^12) */
398#define K800_LCD_HOR_SCF_FORMULA(x, y) (((x-1)*4096)/(y-1))
399/* Vertical scaling factor 10 bits (2^11) */
400#define K800_LCD_VER_SCF_FORMULA(x, y) (((x-1)*2048)/(y-1))
401
402/* location: {CR9F,0,1},{CR77,0,7},{CR79,4,5} */
403#define LCD_HOR_SCALING_FACTOR_REG_NUM 3
404/* location: {CR79,3,3},{CR78,0,7},{CR79,6,7} */
405#define LCD_VER_SCALING_FACTOR_REG_NUM 3
406/* location: {CR77,0,7},{CR79,4,5} */
407#define LCD_HOR_SCALING_FACTOR_REG_NUM_CLE 2
408/* location: {CR78,0,7},{CR79,6,7} */
409#define LCD_VER_SCALING_FACTOR_REG_NUM_CLE 2
410
411/************************************************
412 ***** Define IGA1 Display Timing *****
413 ************************************************/
414struct io_register {
415 u8 io_addr;
416 u8 start_bit;
417 u8 end_bit;
418};
419
420/* IGA1 Horizontal Total */
421struct iga1_hor_total {
422 int reg_num;
423 struct io_register reg[IGA1_HOR_TOTAL_REG_NUM];
424};
425
426/* IGA1 Horizontal Addressable Video */
427struct iga1_hor_addr {
428 int reg_num;
429 struct io_register reg[IGA1_HOR_ADDR_REG_NUM];
430};
431
432/* IGA1 Horizontal Blank Start */
433struct iga1_hor_blank_start {
434 int reg_num;
435 struct io_register reg[IGA1_HOR_BLANK_START_REG_NUM];
436};
437
438/* IGA1 Horizontal Blank End */
439struct iga1_hor_blank_end {
440 int reg_num;
441 struct io_register reg[IGA1_HOR_BLANK_END_REG_NUM];
442};
443
444/* IGA1 Horizontal Sync Start */
445struct iga1_hor_sync_start {
446 int reg_num;
447 struct io_register reg[IGA1_HOR_SYNC_START_REG_NUM];
448};
449
450/* IGA1 Horizontal Sync End */
451struct iga1_hor_sync_end {
452 int reg_num;
453 struct io_register reg[IGA1_HOR_SYNC_END_REG_NUM];
454};
455
456/* IGA1 Vertical Total */
457struct iga1_ver_total {
458 int reg_num;
459 struct io_register reg[IGA1_VER_TOTAL_REG_NUM];
460};
461
462/* IGA1 Vertical Addressable Video */
463struct iga1_ver_addr {
464 int reg_num;
465 struct io_register reg[IGA1_VER_ADDR_REG_NUM];
466};
467
468/* IGA1 Vertical Blank Start */
469struct iga1_ver_blank_start {
470 int reg_num;
471 struct io_register reg[IGA1_VER_BLANK_START_REG_NUM];
472};
473
474/* IGA1 Vertical Blank End */
475struct iga1_ver_blank_end {
476 int reg_num;
477 struct io_register reg[IGA1_VER_BLANK_END_REG_NUM];
478};
479
480/* IGA1 Vertical Sync Start */
481struct iga1_ver_sync_start {
482 int reg_num;
483 struct io_register reg[IGA1_VER_SYNC_START_REG_NUM];
484};
485
486/* IGA1 Vertical Sync End */
487struct iga1_ver_sync_end {
488 int reg_num;
489 struct io_register reg[IGA1_VER_SYNC_END_REG_NUM];
490};
491
492/*****************************************************
493** Define IGA2 Shadow Display Timing ****
494*****************************************************/
495
496/* IGA2 Shadow Horizontal Total */
497struct iga2_shadow_hor_total {
498 int reg_num;
499 struct io_register reg[IGA2_SHADOW_HOR_TOTAL_REG_NUM];
500};
501
502/* IGA2 Shadow Horizontal Blank End */
503struct iga2_shadow_hor_blank_end {
504 int reg_num;
505 struct io_register reg[IGA2_SHADOW_HOR_BLANK_END_REG_NUM];
506};
507
508/* IGA2 Shadow Vertical Total */
509struct iga2_shadow_ver_total {
510 int reg_num;
511 struct io_register reg[IGA2_SHADOW_VER_TOTAL_REG_NUM];
512};
513
514/* IGA2 Shadow Vertical Addressable Video */
515struct iga2_shadow_ver_addr {
516 int reg_num;
517 struct io_register reg[IGA2_SHADOW_VER_ADDR_REG_NUM];
518};
519
520/* IGA2 Shadow Vertical Blank Start */
521struct iga2_shadow_ver_blank_start {
522 int reg_num;
523 struct io_register reg[IGA2_SHADOW_VER_BLANK_START_REG_NUM];
524};
525
526/* IGA2 Shadow Vertical Blank End */
527struct iga2_shadow_ver_blank_end {
528 int reg_num;
529 struct io_register reg[IGA2_SHADOW_VER_BLANK_END_REG_NUM];
530};
531
532/* IGA2 Shadow Vertical Sync Start */
533struct iga2_shadow_ver_sync_start {
534 int reg_num;
535 struct io_register reg[IGA2_SHADOW_VER_SYNC_START_REG_NUM];
536};
537
538/* IGA2 Shadow Vertical Sync End */
539struct iga2_shadow_ver_sync_end {
540 int reg_num;
541 struct io_register reg[IGA2_SHADOW_VER_SYNC_END_REG_NUM];
542};
543
544/*****************************************************
545** Define IGA2 Display Timing ****
546******************************************************/
547
548/* IGA2 Horizontal Total */
549struct iga2_hor_total {
550 int reg_num;
551 struct io_register reg[IGA2_HOR_TOTAL_REG_NUM];
552};
553
554/* IGA2 Horizontal Addressable Video */
555struct iga2_hor_addr {
556 int reg_num;
557 struct io_register reg[IGA2_HOR_ADDR_REG_NUM];
558};
559
560/* IGA2 Horizontal Blank Start */
561struct iga2_hor_blank_start {
562 int reg_num;
563 struct io_register reg[IGA2_HOR_BLANK_START_REG_NUM];
564};
565
566/* IGA2 Horizontal Blank End */
567struct iga2_hor_blank_end {
568 int reg_num;
569 struct io_register reg[IGA2_HOR_BLANK_END_REG_NUM];
570};
571
572/* IGA2 Horizontal Sync Start */
573struct iga2_hor_sync_start {
574 int reg_num;
575 struct io_register reg[IGA2_HOR_SYNC_START_REG_NUM];
576};
577
578/* IGA2 Horizontal Sync End */
579struct iga2_hor_sync_end {
580 int reg_num;
581 struct io_register reg[IGA2_HOR_SYNC_END_REG_NUM];
582};
583
584/* IGA2 Vertical Total */
585struct iga2_ver_total {
586 int reg_num;
587 struct io_register reg[IGA2_VER_TOTAL_REG_NUM];
588};
589
590/* IGA2 Vertical Addressable Video */
591struct iga2_ver_addr {
592 int reg_num;
593 struct io_register reg[IGA2_VER_ADDR_REG_NUM];
594};
595
596/* IGA2 Vertical Blank Start */
597struct iga2_ver_blank_start {
598 int reg_num;
599 struct io_register reg[IGA2_VER_BLANK_START_REG_NUM];
600};
601
602/* IGA2 Vertical Blank End */
603struct iga2_ver_blank_end {
604 int reg_num;
605 struct io_register reg[IGA2_VER_BLANK_END_REG_NUM];
606};
607
608/* IGA2 Vertical Sync Start */
609struct iga2_ver_sync_start {
610 int reg_num;
611 struct io_register reg[IGA2_VER_SYNC_START_REG_NUM];
612};
613
614/* IGA2 Vertical Sync End */
615struct iga2_ver_sync_end {
616 int reg_num;
617 struct io_register reg[IGA2_VER_SYNC_END_REG_NUM];
618};
619
620/* IGA1 Offset Register */
621struct iga1_offset {
622 int reg_num;
623 struct io_register reg[IGA1_OFFSET_REG_NUM];
624};
625
626/* IGA2 Offset Register */
627struct iga2_offset {
628 int reg_num;
629 struct io_register reg[IGA2_OFFSET_REG_NUM];
630};
631
632struct offset {
633 struct iga1_offset iga1_offset_reg;
634 struct iga2_offset iga2_offset_reg;
635};
636
637/* IGA1 Fetch Count Register */
638struct iga1_fetch_count {
639 int reg_num;
640 struct io_register reg[IGA1_FETCH_COUNT_REG_NUM];
641};
642
643/* IGA2 Fetch Count Register */
644struct iga2_fetch_count {
645 int reg_num;
646 struct io_register reg[IGA2_FETCH_COUNT_REG_NUM];
647};
648
649struct fetch_count {
650 struct iga1_fetch_count iga1_fetch_count_reg;
651 struct iga2_fetch_count iga2_fetch_count_reg;
652};
653
654/* Starting Address Register */
655struct iga1_starting_addr {
656 int reg_num;
657 struct io_register reg[IGA1_STARTING_ADDR_REG_NUM];
658};
659
660struct iga2_starting_addr {
661 int reg_num;
662 struct io_register reg[IGA2_STARTING_ADDR_REG_NUM];
663};
664
665struct starting_addr {
666 struct iga1_starting_addr iga1_starting_addr_reg;
667 struct iga2_starting_addr iga2_starting_addr_reg;
668};
669
670/* LCD Power Sequence Timer */
671struct lcd_pwd_seq_td0 {
672 int reg_num;
673 struct io_register reg[LCD_POWER_SEQ_TD0_REG_NUM];
674};
675
676struct lcd_pwd_seq_td1 {
677 int reg_num;
678 struct io_register reg[LCD_POWER_SEQ_TD1_REG_NUM];
679};
680
681struct lcd_pwd_seq_td2 {
682 int reg_num;
683 struct io_register reg[LCD_POWER_SEQ_TD2_REG_NUM];
684};
685
686struct lcd_pwd_seq_td3 {
687 int reg_num;
688 struct io_register reg[LCD_POWER_SEQ_TD3_REG_NUM];
689};
690
691struct _lcd_pwd_seq_timer {
692 struct lcd_pwd_seq_td0 td0;
693 struct lcd_pwd_seq_td1 td1;
694 struct lcd_pwd_seq_td2 td2;
695 struct lcd_pwd_seq_td3 td3;
696};
697
698/* LCD Scaling Factor */
699struct _lcd_hor_scaling_factor {
700 int reg_num;
701 struct io_register reg[LCD_HOR_SCALING_FACTOR_REG_NUM];
702};
703
704struct _lcd_ver_scaling_factor {
705 int reg_num;
706 struct io_register reg[LCD_VER_SCALING_FACTOR_REG_NUM];
707};
708
709struct _lcd_scaling_factor {
710 struct _lcd_hor_scaling_factor lcd_hor_scaling_factor;
711 struct _lcd_ver_scaling_factor lcd_ver_scaling_factor;
712};
713
714struct pll_map {
715 u32 clk;
716 u32 cle266_pll;
717 u32 k800_pll;
718 u32 cx700_pll;
719};
720
721struct rgbLUT {
722 u8 red;
723 u8 green;
724 u8 blue;
725};
726
727struct lcd_pwd_seq_timer {
728 u16 td0;
729 u16 td1;
730 u16 td2;
731 u16 td3;
732};
733
734/* Display FIFO Relation Registers*/
735struct iga1_fifo_depth_select {
736 int reg_num;
737 struct io_register reg[IGA1_FIFO_DEPTH_SELECT_REG_NUM];
738};
739
740struct iga1_fifo_threshold_select {
741 int reg_num;
742 struct io_register reg[IGA1_FIFO_THRESHOLD_REG_NUM];
743};
744
745struct iga1_fifo_high_threshold_select {
746 int reg_num;
747 struct io_register reg[IGA1_FIFO_HIGH_THRESHOLD_REG_NUM];
748};
749
750struct iga1_display_queue_expire_num {
751 int reg_num;
752 struct io_register reg[IGA1_DISPLAY_QUEUE_EXPIRE_NUM_REG_NUM];
753};
754
755struct iga2_fifo_depth_select {
756 int reg_num;
757 struct io_register reg[IGA2_FIFO_DEPTH_SELECT_REG_NUM];
758};
759
760struct iga2_fifo_threshold_select {
761 int reg_num;
762 struct io_register reg[IGA2_FIFO_THRESHOLD_REG_NUM];
763};
764
765struct iga2_fifo_high_threshold_select {
766 int reg_num;
767 struct io_register reg[IGA2_FIFO_HIGH_THRESHOLD_REG_NUM];
768};
769
770struct iga2_display_queue_expire_num {
771 int reg_num;
772 struct io_register reg[IGA2_DISPLAY_QUEUE_EXPIRE_NUM_REG_NUM];
773};
774
775struct fifo_depth_select {
776 struct iga1_fifo_depth_select iga1_fifo_depth_select_reg;
777 struct iga2_fifo_depth_select iga2_fifo_depth_select_reg;
778};
779
780struct fifo_threshold_select {
781 struct iga1_fifo_threshold_select iga1_fifo_threshold_select_reg;
782 struct iga2_fifo_threshold_select iga2_fifo_threshold_select_reg;
783};
784
785struct fifo_high_threshold_select {
786 struct iga1_fifo_high_threshold_select
787 iga1_fifo_high_threshold_select_reg;
788 struct iga2_fifo_high_threshold_select
789 iga2_fifo_high_threshold_select_reg;
790};
791
792struct display_queue_expire_num {
793 struct iga1_display_queue_expire_num
794 iga1_display_queue_expire_num_reg;
795 struct iga2_display_queue_expire_num
796 iga2_display_queue_expire_num_reg;
797};
798
799struct iga1_crtc_timing {
800 struct iga1_hor_total hor_total;
801 struct iga1_hor_addr hor_addr;
802 struct iga1_hor_blank_start hor_blank_start;
803 struct iga1_hor_blank_end hor_blank_end;
804 struct iga1_hor_sync_start hor_sync_start;
805 struct iga1_hor_sync_end hor_sync_end;
806 struct iga1_ver_total ver_total;
807 struct iga1_ver_addr ver_addr;
808 struct iga1_ver_blank_start ver_blank_start;
809 struct iga1_ver_blank_end ver_blank_end;
810 struct iga1_ver_sync_start ver_sync_start;
811 struct iga1_ver_sync_end ver_sync_end;
812};
813
814struct iga2_shadow_crtc_timing {
815 struct iga2_shadow_hor_total hor_total_shadow;
816 struct iga2_shadow_hor_blank_end hor_blank_end_shadow;
817 struct iga2_shadow_ver_total ver_total_shadow;
818 struct iga2_shadow_ver_addr ver_addr_shadow;
819 struct iga2_shadow_ver_blank_start ver_blank_start_shadow;
820 struct iga2_shadow_ver_blank_end ver_blank_end_shadow;
821 struct iga2_shadow_ver_sync_start ver_sync_start_shadow;
822 struct iga2_shadow_ver_sync_end ver_sync_end_shadow;
823};
824
825struct iga2_crtc_timing {
826 struct iga2_hor_total hor_total;
827 struct iga2_hor_addr hor_addr;
828 struct iga2_hor_blank_start hor_blank_start;
829 struct iga2_hor_blank_end hor_blank_end;
830 struct iga2_hor_sync_start hor_sync_start;
831 struct iga2_hor_sync_end hor_sync_end;
832 struct iga2_ver_total ver_total;
833 struct iga2_ver_addr ver_addr;
834 struct iga2_ver_blank_start ver_blank_start;
835 struct iga2_ver_blank_end ver_blank_end;
836 struct iga2_ver_sync_start ver_sync_start;
837 struct iga2_ver_sync_end ver_sync_end;
838};
839
840/* device ID */
841#define CLE266 0x3123
842#define KM400 0x3205
843#define CN400_FUNCTION2 0x2259
844#define CN400_FUNCTION3 0x3259
845/* support VT3314 chipset */
846#define CN700_FUNCTION2 0x2314
847#define CN700_FUNCTION3 0x3208
848/* VT3324 chipset */
849#define CX700_FUNCTION2 0x2324
850#define CX700_FUNCTION3 0x3324
851/* VT3204 chipset*/
852#define KM800_FUNCTION3 0x3204
853/* VT3336 chipset*/
854#define KM890_FUNCTION3 0x3336
855/* VT3327 chipset*/
856#define P4M890_FUNCTION3 0x3327
857/* VT3293 chipset*/
858#define CN750_FUNCTION3 0x3208
859/* VT3364 chipset*/
860#define P4M900_FUNCTION3 0x3364
861/* VT3353 chipset*/
862#define VX800_FUNCTION3 0x3353
863
864#define NUM_TOTAL_PLL_TABLE ARRAY_SIZE(pll_value)
865
866struct IODATA {
867 u8 Index;
868 u8 Mask;
869 u8 Data;
870};
871
872struct pci_device_id_info {
873 u32 vendor;
874 u32 device;
875 u32 chip_index;
876};
877
878extern unsigned int viafb_second_virtual_xres;
879extern unsigned int viafb_second_offset;
880extern int viafb_second_size;
881extern int viafb_SAMM_ON;
882extern int viafb_dual_fb;
883extern int viafb_LCD2_ON;
884extern int viafb_LCD_ON;
885extern int viafb_DVI_ON;
886extern int viafb_accel;
887extern int viafb_hotplug;
888
889void viafb_write_reg_mask(u8 index, int io_port, u8 data, u8 mask);
890void viafb_set_output_path(int device, int set_iga,
891 int output_interface);
892void viafb_fill_crtc_timing(struct crt_mode_table *crt_table,
893 int mode_index, int bpp_byte, int set_iga);
894
895void viafb_set_vclock(u32 CLK, int set_iga);
896void viafb_load_reg(int timing_value, int viafb_load_reg_num,
897 struct io_register *reg,
898 int io_type);
899void viafb_crt_disable(void);
900void viafb_crt_enable(void);
901void init_ad9389(void);
902/* Access I/O Function */
903void viafb_write_reg(u8 index, u16 io_port, u8 data);
904u8 viafb_read_reg(int io_port, u8 index);
905void viafb_lock_crt(void);
906void viafb_unlock_crt(void);
907void viafb_load_offset_reg(int h_addr, int bpp_byte, int set_iga);
908void viafb_load_fetch_count_reg(int h_addr, int bpp_byte, int set_iga);
909void viafb_write_regx(struct io_reg RegTable[], int ItemNum);
910struct VideoModeTable *viafb_get_modetbl_pointer(int Index);
911u32 viafb_get_clk_value(int clk);
912void viafb_load_FIFO_reg(int set_iga, int hor_active, int ver_active);
913void viafb_set_color_depth(int bpp_byte, int set_iga);
914void viafb_set_dpa_gfx(int output_interface, struct GFX_DPA_SETTING\
915 *p_gfx_dpa_setting);
916
917int viafb_setmode(int vmode_index, int hor_res, int ver_res,
918 int video_bpp, int vmode_index1, int hor_res1,
919 int ver_res1, int video_bpp1);
920void viafb_init_chip_info(void);
921void viafb_init_dac(int set_iga);
922int viafb_get_pixclock(int hres, int vres, int vmode_refresh);
923int viafb_get_refresh(int hres, int vres, u32 float_refresh);
924void viafb_update_device_setting(int hres, int vres, int bpp,
925 int vmode_refresh, int flag);
926void viafb_get_mmio_info(unsigned long *mmio_base,
927 unsigned long *mmio_len);
928
929void viafb_set_iga_path(void);
930void viafb_set_start_addr(void);
931void viafb_get_fb_info(unsigned int *fb_base, unsigned int *fb_len);
932
933#endif /* __HW_H__ */
diff --git a/drivers/video/via/iface.c b/drivers/video/via/iface.c
new file mode 100644
index 000000000000..1570636c8d51
--- /dev/null
+++ b/drivers/video/via/iface.c
@@ -0,0 +1,78 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#include "global.h"
23
24/* Get frame buffer size from VGA BIOS */
25
26unsigned int viafb_get_memsize(void)
27{
28 unsigned int m;
29
30 /* If memory size provided by user */
31 if (viafb_memsize)
32 m = viafb_memsize * Mb;
33 else {
34 m = (unsigned int)viafb_read_reg(VIASR, SR39);
35 m = m * (4 * Mb);
36
37 if ((m < (16 * Mb)) || (m > (64 * Mb)))
38 m = 16 * Mb;
39 }
40 DEBUG_MSG(KERN_INFO "framebuffer size = %d Mb\n", m / Mb);
41 return m;
42}
43
44/* Get Video Buffer Starting Physical Address(back door)*/
45
46unsigned long viafb_get_videobuf_addr(void)
47{
48 struct pci_dev *pdev = NULL;
49 unsigned char sys_mem;
50 unsigned char video_mem;
51 unsigned long sys_mem_size;
52 unsigned long video_mem_size;
53 /*system memory = 256 MB, video memory 64 MB */
54 unsigned long vmem_starting_adr = 0x0C000000;
55
56 pdev =
57 (struct pci_dev *)pci_get_device(VIA_K800_BRIDGE_VID,
58 VIA_K800_BRIDGE_DID, NULL);
59 if (pdev != NULL) {
60 pci_read_config_byte(pdev, VIA_K800_SYSTEM_MEMORY_REG,
61 &sys_mem);
62 pci_read_config_byte(pdev, VIA_K800_VIDEO_MEMORY_REG,
63 &video_mem);
64 video_mem = (video_mem & 0x70) >> 4;
65 sys_mem_size = ((unsigned long)sys_mem) << 24;
66 if (video_mem != 0)
67 video_mem_size = (1 << (video_mem)) * 1024 * 1024;
68 else
69 video_mem_size = 0;
70
71 vmem_starting_adr = sys_mem_size - video_mem_size;
72 pci_dev_put(pdev);
73 }
74
75 DEBUG_MSG(KERN_INFO "Video Memory Starting Address = %lx \n",
76 vmem_starting_adr);
77 return vmem_starting_adr;
78}
diff --git a/drivers/video/via/iface.h b/drivers/video/via/iface.h
new file mode 100644
index 000000000000..790ec3e3aea2
--- /dev/null
+++ b/drivers/video/via/iface.h
@@ -0,0 +1,38 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#ifndef __IFACE_H__
23#define __IFACE_H__
24
25#define Kb (1024)
26#define Mb (Kb*Kb)
27
28#define VIA_K800_BRIDGE_VID 0x1106
29#define VIA_K800_BRIDGE_DID 0x3204
30
31#define VIA_K800_SYSTEM_MEMORY_REG 0x47
32#define VIA_K800_VIDEO_MEMORY_REG 0xA1
33
34extern int viafb_memsize;
35unsigned int viafb_get_memsize(void);
36unsigned long viafb_get_videobuf_addr(void);
37
38#endif /* __IFACE_H__ */
diff --git a/drivers/video/via/ioctl.c b/drivers/video/via/ioctl.c
new file mode 100644
index 000000000000..da03c074e32a
--- /dev/null
+++ b/drivers/video/via/ioctl.c
@@ -0,0 +1,112 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#include "global.h"
23
24int viafb_ioctl_get_viafb_info(u_long arg)
25{
26 struct viafb_ioctl_info viainfo;
27
28 viainfo.viafb_id = VIAID;
29 viainfo.vendor_id = PCI_VIA_VENDOR_ID;
30
31 switch (viaparinfo->chip_info->gfx_chip_name) {
32 case UNICHROME_CLE266:
33 viainfo.device_id = UNICHROME_CLE266_DID;
34 break;
35
36 case UNICHROME_K400:
37 viainfo.device_id = UNICHROME_K400_DID;
38 break;
39
40 case UNICHROME_K800:
41 viainfo.device_id = UNICHROME_K800_DID;
42 break;
43
44 case UNICHROME_PM800:
45 viainfo.device_id = UNICHROME_PM800_DID;
46 break;
47
48 case UNICHROME_CN700:
49 viainfo.device_id = UNICHROME_CN700_DID;
50 break;
51
52 case UNICHROME_CX700:
53 viainfo.device_id = UNICHROME_CX700_DID;
54 break;
55
56 case UNICHROME_K8M890:
57 viainfo.device_id = UNICHROME_K8M890_DID;
58 break;
59
60 case UNICHROME_P4M890:
61 viainfo.device_id = UNICHROME_P4M890_DID;
62 break;
63
64 case UNICHROME_P4M900:
65 viainfo.device_id = UNICHROME_P4M900_DID;
66 break;
67 }
68
69 viainfo.version = VERSION_MAJOR;
70 viainfo.revision = VERSION_MINOR;
71
72 if (copy_to_user((void __user *)arg, &viainfo, sizeof(viainfo)))
73 return -EFAULT;
74
75 return 0;
76}
77
78/* Hot-Plug Priority: DVI > CRT*/
79int viafb_ioctl_hotplug(int hres, int vres, int bpp)
80{
81 int DVIsense, status = 0;
82 DEBUG_MSG(KERN_INFO "viafb_ioctl_hotplug!!\n");
83
84 if (viaparinfo->chip_info->tmds_chip_info.tmds_chip_name !=
85 NON_TMDS_TRANSMITTER) {
86 DVIsense = viafb_dvi_sense();
87
88 if (DVIsense) {
89 DEBUG_MSG(KERN_INFO "DVI Attached...\n");
90 if (viafb_DeviceStatus != DVI_Device) {
91 viafb_DVI_ON = 1;
92 viafb_CRT_ON = 0;
93 viafb_LCD_ON = 0;
94 viafb_DeviceStatus = DVI_Device;
95 return viafb_DeviceStatus;
96 }
97 status = 1;
98 } else
99 DEBUG_MSG(KERN_INFO "DVI De-attached...\n");
100 }
101
102 if ((viafb_DeviceStatus != CRT_Device) && (status == 0)) {
103 viafb_CRT_ON = 1;
104 viafb_DVI_ON = 0;
105 viafb_LCD_ON = 0;
106
107 viafb_DeviceStatus = CRT_Device;
108 return viafb_DeviceStatus;
109 }
110
111 return 0;
112}
diff --git a/drivers/video/via/ioctl.h b/drivers/video/via/ioctl.h
new file mode 100644
index 000000000000..842fe30b9868
--- /dev/null
+++ b/drivers/video/via/ioctl.h
@@ -0,0 +1,210 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#ifndef __IOCTL_H__
23#define __IOCTL_H__
24
25#ifndef __user
26#define __user
27#endif
28
29/* VIAFB IOCTL definition */
30#define VIAFB_GET_INFO_SIZE 0x56494101 /* 'VIA\01' */
31#define VIAFB_GET_INFO 0x56494102 /* 'VIA\02' */
32#define VIAFB_HOTPLUG 0x56494103 /* 'VIA\03' */
33#define VIAFB_SET_HOTPLUG_FLAG 0x56494104 /* 'VIA\04' */
34#define VIAFB_GET_RESOLUTION 0x56494105 /* 'VIA\05' */
35#define VIAFB_GET_SAMM_INFO 0x56494107 /* 'VIA\07' */
36#define VIAFB_TURN_ON_OUTPUT_DEVICE 0x56494108 /* 'VIA\08' */
37#define VIAFB_TURN_OFF_OUTPUT_DEVICE 0x56494109 /* 'VIA\09' */
38#define VIAFB_SET_DEVICE 0x5649410A
39#define VIAFB_GET_DEVICE 0x5649410B
40#define VIAFB_GET_DRIVER_VERSION 0x56494112 /* 'VIA\12' */
41#define VIAFB_GET_CHIP_INFO 0x56494113 /* 'VIA\13' */
42#define VIAFB_SET_DEVICE_INFO 0x56494114
43#define VIAFB_GET_DEVICE_INFO 0x56494115
44
45#define VIAFB_GET_DEVICE_SUPPORT 0x56494118
46#define VIAFB_GET_DEVICE_CONNECT 0x56494119
47#define VIAFB_GET_PANEL_SUPPORT_EXPAND 0x5649411A
48#define VIAFB_GET_DRIVER_NAME 0x56494122
49#define VIAFB_GET_DEVICE_SUPPORT_STATE 0x56494123
50#define VIAFB_GET_GAMMA_LUT 0x56494124
51#define VIAFB_SET_GAMMA_LUT 0x56494125
52#define VIAFB_GET_GAMMA_SUPPORT_STATE 0x56494126
53#define VIAFB_SET_VIDEO_DEVICE 0x56494127
54#define VIAFB_GET_VIDEO_DEVICE 0x56494128
55#define VIAFB_SET_SECOND_MODE 0x56494129
56#define VIAFB_SYNC_SURFACE 0x56494130
57#define VIAFB_GET_DRIVER_CAPS 0x56494131
58#define VIAFB_GET_IGA_SCALING_INFO 0x56494132
59#define VIAFB_GET_PANEL_MAX_SIZE 0x56494133
60#define VIAFB_GET_PANEL_MAX_POSITION 0x56494134
61#define VIAFB_SET_PANEL_SIZE 0x56494135
62#define VIAFB_SET_PANEL_POSITION 0x56494136
63#define VIAFB_GET_PANEL_POSITION 0x56494137
64#define VIAFB_GET_PANEL_SIZE 0x56494138
65
66#define None_Device 0x00
67#define CRT_Device 0x01
68#define LCD_Device 0x02
69#define DVI_Device 0x08
70#define CRT2_Device 0x10
71#define LCD2_Device 0x40
72
73#define OP_LCD_CENTERING 0x01
74#define OP_LCD_PANEL_ID 0x02
75#define OP_LCD_MODE 0x03
76
77/*SAMM operation flag*/
78#define OP_SAMM 0x80
79
80#define LCD_PANEL_ID_MAXIMUM 22
81
82#define STATE_ON 0x1
83#define STATE_OFF 0x0
84#define STATE_DEFAULT 0xFFFF
85
86#define MAX_ACTIVE_DEV_NUM 2
87
88struct device_t {
89 unsigned short crt:1;
90 unsigned short dvi:1;
91 unsigned short lcd:1;
92 unsigned short samm:1;
93 unsigned short lcd_dsp_cent:1;
94 unsigned char lcd_mode:1;
95 unsigned short epia_dvi:1;
96 unsigned short lcd_dual_edge:1;
97 unsigned short lcd2:1;
98
99 unsigned short primary_dev;
100 unsigned char lcd_panel_id;
101 unsigned short xres, yres;
102 unsigned short xres1, yres1;
103 unsigned short refresh;
104 unsigned short bpp;
105 unsigned short refresh1;
106 unsigned short bpp1;
107 unsigned short sequence;
108 unsigned short bus_width;
109};
110
111struct viafb_ioctl_info {
112 u32 viafb_id; /* for identifying viafb */
113#define VIAID 0x56494146 /* Identify myself with 'VIAF' */
114 u16 vendor_id;
115 u16 device_id;
116 u8 version;
117 u8 revision;
118 u8 reserved[246]; /* for future use */
119};
120
121struct viafb_ioctl_mode {
122 u32 xres;
123 u32 yres;
124 u32 refresh;
125 u32 bpp;
126 u32 xres_sec;
127 u32 yres_sec;
128 u32 virtual_xres_sec;
129 u32 virtual_yres_sec;
130 u32 refresh_sec;
131 u32 bpp_sec;
132};
133struct viafb_ioctl_samm {
134 u32 samm_status;
135 u32 size_prim;
136 u32 size_sec;
137 u32 mem_base;
138 u32 offset_sec;
139};
140
141struct viafb_driver_version {
142 int iMajorNum;
143 int iKernelNum;
144 int iOSNum;
145 int iMinorNum;
146};
147
148struct viafb_ioctl_lcd_attribute {
149 unsigned int panel_id;
150 unsigned int display_center;
151 unsigned int lcd_mode;
152};
153
154struct viafb_ioctl_setting {
155 /* Enable or disable active devices */
156 unsigned short device_flag;
157 /* Indicate which device should be turn on or turn off. */
158 unsigned short device_status;
159 unsigned int reserved;
160 /* Indicate which LCD's attribute can be changed. */
161 unsigned short lcd_operation_flag;
162 /* 1: SAMM ON 0: SAMM OFF */
163 unsigned short samm_status;
164 /* horizontal resolution of first device */
165 unsigned short first_dev_hor_res;
166 /* vertical resolution of first device */
167 unsigned short first_dev_ver_res;
168 /* horizontal resolution of second device */
169 unsigned short second_dev_hor_res;
170 /* vertical resolution of second device */
171 unsigned short second_dev_ver_res;
172 /* refresh rate of first device */
173 unsigned short first_dev_refresh;
174 /* bpp of first device */
175 unsigned short first_dev_bpp;
176 /* refresh rate of second device */
177 unsigned short second_dev_refresh;
178 /* bpp of second device */
179 unsigned short second_dev_bpp;
180 /* Indicate which device are primary display device. */
181 unsigned int primary_device;
182 /* Indicate which device will show video. only valid in duoview mode */
183 unsigned int video_device_status;
184 unsigned int struct_reserved[34];
185 struct viafb_ioctl_lcd_attribute lcd_attributes;
186};
187
188struct _UTFunctionCaps {
189 unsigned int dw3DScalingState;
190 unsigned int reserved[31];
191};
192
193struct _POSITIONVALUE {
194 unsigned int dwX;
195 unsigned int dwY;
196};
197
198struct _panel_size_pos_info {
199 unsigned int device_type;
200 int x;
201 int y;
202};
203
204extern int viafb_LCD_ON;
205extern int viafb_DVI_ON;
206
207int viafb_ioctl_get_viafb_info(u_long arg);
208int viafb_ioctl_hotplug(int hres, int vres, int bpp);
209
210#endif /* __IOCTL_H__ */
diff --git a/drivers/video/via/lcd.c b/drivers/video/via/lcd.c
new file mode 100644
index 000000000000..6c7290a6a447
--- /dev/null
+++ b/drivers/video/via/lcd.c
@@ -0,0 +1,1821 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#include "global.h"
23#include "lcdtbl.h"
24
25static struct iga2_shadow_crtc_timing iga2_shadow_crtc_reg = {
26 /* IGA2 Shadow Horizontal Total */
27 {IGA2_SHADOW_HOR_TOTAL_REG_NUM, {{CR6D, 0, 7}, {CR71, 3, 3} } },
28 /* IGA2 Shadow Horizontal Blank End */
29 {IGA2_SHADOW_HOR_BLANK_END_REG_NUM, {{CR6E, 0, 7} } },
30 /* IGA2 Shadow Vertical Total */
31 {IGA2_SHADOW_VER_TOTAL_REG_NUM, {{CR6F, 0, 7}, {CR71, 0, 2} } },
32 /* IGA2 Shadow Vertical Addressable Video */
33 {IGA2_SHADOW_VER_ADDR_REG_NUM, {{CR70, 0, 7}, {CR71, 4, 6} } },
34 /* IGA2 Shadow Vertical Blank Start */
35 {IGA2_SHADOW_VER_BLANK_START_REG_NUM,
36 {{CR72, 0, 7}, {CR74, 4, 6} } },
37 /* IGA2 Shadow Vertical Blank End */
38 {IGA2_SHADOW_VER_BLANK_END_REG_NUM, {{CR73, 0, 7}, {CR74, 0, 2} } },
39 /* IGA2 Shadow Vertical Sync Start */
40 {IGA2_SHADOW_VER_SYNC_START_REG_NUM, {{CR75, 0, 7}, {CR76, 4, 6} } },
41 /* IGA2 Shadow Vertical Sync End */
42 {IGA2_SHADOW_VER_SYNC_END_REG_NUM, {{CR76, 0, 3} } }
43};
44
45static struct _lcd_scaling_factor lcd_scaling_factor = {
46 /* LCD Horizontal Scaling Factor Register */
47 {LCD_HOR_SCALING_FACTOR_REG_NUM,
48 {{CR9F, 0, 1}, {CR77, 0, 7}, {CR79, 4, 5} } },
49 /* LCD Vertical Scaling Factor Register */
50 {LCD_VER_SCALING_FACTOR_REG_NUM,
51 {{CR79, 3, 3}, {CR78, 0, 7}, {CR79, 6, 7} } }
52};
53static struct _lcd_scaling_factor lcd_scaling_factor_CLE = {
54 /* LCD Horizontal Scaling Factor Register */
55 {LCD_HOR_SCALING_FACTOR_REG_NUM_CLE, {{CR77, 0, 7}, {CR79, 4, 5} } },
56 /* LCD Vertical Scaling Factor Register */
57 {LCD_VER_SCALING_FACTOR_REG_NUM_CLE, {{CR78, 0, 7}, {CR79, 6, 7} } }
58};
59
60static int check_lvds_chip(int device_id_subaddr, int device_id);
61static bool lvds_identify_integratedlvds(void);
62static int fp_id_to_vindex(int panel_id);
63static int lvds_register_read(int index);
64static void load_lcd_scaling(int set_hres, int set_vres, int panel_hres,
65 int panel_vres);
66static void load_lcd_k400_patch_tbl(int set_hres, int set_vres,
67 int panel_id);
68static void load_lcd_p880_patch_tbl(int set_hres, int set_vres,
69 int panel_id);
70static void load_lcd_patch_regs(int set_hres, int set_vres,
71 int panel_id, int set_iga);
72static void via_pitch_alignment_patch_lcd(
73 struct lvds_setting_information *plvds_setting_info,
74 struct lvds_chip_information
75 *plvds_chip_info);
76static void lcd_patch_skew_dvp0(struct lvds_setting_information
77 *plvds_setting_info,
78 struct lvds_chip_information *plvds_chip_info);
79static void lcd_patch_skew_dvp1(struct lvds_setting_information
80 *plvds_setting_info,
81 struct lvds_chip_information *plvds_chip_info);
82static void lcd_patch_skew(struct lvds_setting_information
83 *plvds_setting_info, struct lvds_chip_information *plvds_chip_info);
84
85static void integrated_lvds_disable(struct lvds_setting_information
86 *plvds_setting_info,
87 struct lvds_chip_information *plvds_chip_info);
88static void integrated_lvds_enable(struct lvds_setting_information
89 *plvds_setting_info,
90 struct lvds_chip_information *plvds_chip_info);
91static void lcd_powersequence_off(void);
92static void lcd_powersequence_on(void);
93static void fill_lcd_format(void);
94static void check_diport_of_integrated_lvds(
95 struct lvds_chip_information *plvds_chip_info,
96 struct lvds_setting_information
97 *plvds_setting_info);
98static struct display_timing lcd_centering_timging(struct display_timing
99 mode_crt_reg,
100 struct display_timing panel_crt_reg);
101static void load_crtc_shadow_timing(struct display_timing mode_timing,
102 struct display_timing panel_timing);
103static void viafb_load_scaling_factor_for_p4m900(int set_hres,
104 int set_vres, int panel_hres, int panel_vres);
105
106static int check_lvds_chip(int device_id_subaddr, int device_id)
107{
108 if (lvds_register_read(device_id_subaddr) == device_id)
109 return OK;
110 else
111 return FAIL;
112}
113
114void viafb_init_lcd_size(void)
115{
116 DEBUG_MSG(KERN_INFO "viafb_init_lcd_size()\n");
117 DEBUG_MSG(KERN_INFO
118 "viaparinfo->lvds_setting_info->get_lcd_size_method %d\n",
119 viaparinfo->lvds_setting_info->get_lcd_size_method);
120
121 switch (viaparinfo->lvds_setting_info->get_lcd_size_method) {
122 case GET_LCD_SIZE_BY_SYSTEM_BIOS:
123 break;
124 case GET_LCD_SZIE_BY_HW_STRAPPING:
125 break;
126 case GET_LCD_SIZE_BY_VGA_BIOS:
127 DEBUG_MSG(KERN_INFO "Get LCD Size method by VGA BIOS !!\n");
128 viaparinfo->lvds_setting_info->lcd_panel_size =
129 fp_id_to_vindex(viafb_lcd_panel_id);
130 DEBUG_MSG(KERN_INFO "LCD Panel_ID = %d\n",
131 viaparinfo->lvds_setting_info->lcd_panel_id);
132 DEBUG_MSG(KERN_INFO "LCD Panel Size = %d\n",
133 viaparinfo->lvds_setting_info->lcd_panel_size);
134 break;
135 case GET_LCD_SIZE_BY_USER_SETTING:
136 DEBUG_MSG(KERN_INFO "Get LCD Size method by user setting !!\n");
137 viaparinfo->lvds_setting_info->lcd_panel_size =
138 fp_id_to_vindex(viafb_lcd_panel_id);
139 DEBUG_MSG(KERN_INFO "LCD Panel_ID = %d\n",
140 viaparinfo->lvds_setting_info->lcd_panel_id);
141 DEBUG_MSG(KERN_INFO "LCD Panel Size = %d\n",
142 viaparinfo->lvds_setting_info->lcd_panel_size);
143 break;
144 default:
145 DEBUG_MSG(KERN_INFO "viafb_init_lcd_size fail\n");
146 viaparinfo->lvds_setting_info->lcd_panel_id =
147 LCD_PANEL_ID1_800X600;
148 viaparinfo->lvds_setting_info->lcd_panel_size =
149 fp_id_to_vindex(LCD_PANEL_ID1_800X600);
150 }
151 viaparinfo->lvds_setting_info2->lcd_panel_id =
152 viaparinfo->lvds_setting_info->lcd_panel_id;
153 viaparinfo->lvds_setting_info2->lcd_panel_size =
154 viaparinfo->lvds_setting_info->lcd_panel_size;
155 viaparinfo->lvds_setting_info2->lcd_panel_hres =
156 viaparinfo->lvds_setting_info->lcd_panel_hres;
157 viaparinfo->lvds_setting_info2->lcd_panel_vres =
158 viaparinfo->lvds_setting_info->lcd_panel_vres;
159 viaparinfo->lvds_setting_info2->device_lcd_dualedge =
160 viaparinfo->lvds_setting_info->device_lcd_dualedge;
161 viaparinfo->lvds_setting_info2->LCDDithering =
162 viaparinfo->lvds_setting_info->LCDDithering;
163}
164
165static bool lvds_identify_integratedlvds(void)
166{
167 if (viafb_display_hardware_layout == HW_LAYOUT_LCD_EXTERNAL_LCD2) {
168 /* Two dual channel LCD (Internal LVDS + External LVDS): */
169 /* If we have an external LVDS, such as VT1636, we should
170 have its chip ID already. */
171 if (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
172 viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name =
173 INTEGRATED_LVDS;
174 DEBUG_MSG(KERN_INFO "Support two dual channel LVDS!\
175 (Internal LVDS + External LVDS)\n");
176 } else {
177 viaparinfo->chip_info->lvds_chip_info.lvds_chip_name =
178 INTEGRATED_LVDS;
179 DEBUG_MSG(KERN_INFO "Not found external LVDS,\
180 so can't support two dual channel LVDS!\n");
181 }
182 } else if (viafb_display_hardware_layout == HW_LAYOUT_LCD1_LCD2) {
183 /* Two single channel LCD (Internal LVDS + Internal LVDS): */
184 viaparinfo->chip_info->lvds_chip_info.lvds_chip_name =
185 INTEGRATED_LVDS;
186 viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name =
187 INTEGRATED_LVDS;
188 DEBUG_MSG(KERN_INFO "Support two single channel LVDS!\
189 (Internal LVDS + Internal LVDS)\n");
190 } else if (viafb_display_hardware_layout != HW_LAYOUT_DVI_ONLY) {
191 /* If we have found external LVDS, just use it,
192 otherwise, we will use internal LVDS as default. */
193 if (!viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
194 viaparinfo->chip_info->lvds_chip_info.lvds_chip_name =
195 INTEGRATED_LVDS;
196 DEBUG_MSG(KERN_INFO "Found Integrated LVDS!\n");
197 }
198 } else {
199 viaparinfo->chip_info->lvds_chip_info.lvds_chip_name =
200 NON_LVDS_TRANSMITTER;
201 DEBUG_MSG(KERN_INFO "Do not support LVDS!\n");
202 return false;
203 }
204
205 return true;
206}
207
208int viafb_lvds_trasmitter_identify(void)
209{
210 viaparinfo->i2c_stuff.i2c_port = I2CPORTINDEX;
211 if (viafb_lvds_identify_vt1636()) {
212 viaparinfo->chip_info->lvds_chip_info.i2c_port = I2CPORTINDEX;
213 DEBUG_MSG(KERN_INFO
214 "Found VIA VT1636 LVDS on port i2c 0x31 \n");
215 } else {
216 viaparinfo->i2c_stuff.i2c_port = GPIOPORTINDEX;
217 if (viafb_lvds_identify_vt1636()) {
218 viaparinfo->chip_info->lvds_chip_info.i2c_port =
219 GPIOPORTINDEX;
220 DEBUG_MSG(KERN_INFO
221 "Found VIA VT1636 LVDS on port gpio 0x2c \n");
222 }
223 }
224
225 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700)
226 lvds_identify_integratedlvds();
227
228 if (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name)
229 return true;
230 /* Check for VT1631: */
231 viaparinfo->chip_info->lvds_chip_info.lvds_chip_name = VT1631_LVDS;
232 viaparinfo->chip_info->lvds_chip_info.lvds_chip_slave_addr =
233 VT1631_LVDS_I2C_ADDR;
234
235 if (check_lvds_chip(VT1631_DEVICE_ID_REG, VT1631_DEVICE_ID) != FAIL) {
236 DEBUG_MSG(KERN_INFO "\n VT1631 LVDS ! \n");
237 DEBUG_MSG(KERN_INFO "\n %2d",
238 viaparinfo->chip_info->lvds_chip_info.lvds_chip_name);
239 DEBUG_MSG(KERN_INFO "\n %2d",
240 viaparinfo->chip_info->lvds_chip_info.lvds_chip_name);
241 return OK;
242 }
243
244 viaparinfo->chip_info->lvds_chip_info.lvds_chip_name =
245 NON_LVDS_TRANSMITTER;
246 viaparinfo->chip_info->lvds_chip_info.lvds_chip_slave_addr =
247 VT1631_LVDS_I2C_ADDR;
248 return FAIL;
249}
250
251static int fp_id_to_vindex(int panel_id)
252{
253 DEBUG_MSG(KERN_INFO "fp_get_panel_id()\n");
254
255 if (panel_id > LCD_PANEL_ID_MAXIMUM)
256 viafb_lcd_panel_id = panel_id =
257 viafb_read_reg(VIACR, CR3F) & 0x0F;
258
259 switch (panel_id) {
260 case 0x0:
261 viaparinfo->lvds_setting_info->lcd_panel_hres = 640;
262 viaparinfo->lvds_setting_info->lcd_panel_vres = 480;
263 viaparinfo->lvds_setting_info->lcd_panel_id =
264 LCD_PANEL_ID0_640X480;
265 viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
266 viaparinfo->lvds_setting_info->LCDDithering = 1;
267 return VIA_RES_640X480;
268 break;
269 case 0x1:
270 viaparinfo->lvds_setting_info->lcd_panel_hres = 800;
271 viaparinfo->lvds_setting_info->lcd_panel_vres = 600;
272 viaparinfo->lvds_setting_info->lcd_panel_id =
273 LCD_PANEL_ID1_800X600;
274 viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
275 viaparinfo->lvds_setting_info->LCDDithering = 1;
276 return VIA_RES_800X600;
277 break;
278 case 0x2:
279 viaparinfo->lvds_setting_info->lcd_panel_hres = 1024;
280 viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
281 viaparinfo->lvds_setting_info->lcd_panel_id =
282 LCD_PANEL_ID2_1024X768;
283 viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
284 viaparinfo->lvds_setting_info->LCDDithering = 1;
285 return VIA_RES_1024X768;
286 break;
287 case 0x3:
288 viaparinfo->lvds_setting_info->lcd_panel_hres = 1280;
289 viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
290 viaparinfo->lvds_setting_info->lcd_panel_id =
291 LCD_PANEL_ID3_1280X768;
292 viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
293 viaparinfo->lvds_setting_info->LCDDithering = 1;
294 return VIA_RES_1280X768;
295 break;
296 case 0x4:
297 viaparinfo->lvds_setting_info->lcd_panel_hres = 1280;
298 viaparinfo->lvds_setting_info->lcd_panel_vres = 1024;
299 viaparinfo->lvds_setting_info->lcd_panel_id =
300 LCD_PANEL_ID4_1280X1024;
301 viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
302 viaparinfo->lvds_setting_info->LCDDithering = 1;
303 return VIA_RES_1280X1024;
304 break;
305 case 0x5:
306 viaparinfo->lvds_setting_info->lcd_panel_hres = 1400;
307 viaparinfo->lvds_setting_info->lcd_panel_vres = 1050;
308 viaparinfo->lvds_setting_info->lcd_panel_id =
309 LCD_PANEL_ID5_1400X1050;
310 viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
311 viaparinfo->lvds_setting_info->LCDDithering = 1;
312 return VIA_RES_1400X1050;
313 break;
314 case 0x6:
315 viaparinfo->lvds_setting_info->lcd_panel_hres = 1600;
316 viaparinfo->lvds_setting_info->lcd_panel_vres = 1200;
317 viaparinfo->lvds_setting_info->lcd_panel_id =
318 LCD_PANEL_ID6_1600X1200;
319 viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
320 viaparinfo->lvds_setting_info->LCDDithering = 1;
321 return VIA_RES_1600X1200;
322 break;
323 case 0x8:
324 viaparinfo->lvds_setting_info->lcd_panel_hres = 800;
325 viaparinfo->lvds_setting_info->lcd_panel_vres = 480;
326 viaparinfo->lvds_setting_info->lcd_panel_id =
327 LCD_PANEL_IDA_800X480;
328 viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
329 viaparinfo->lvds_setting_info->LCDDithering = 1;
330 return VIA_RES_800X480;
331 break;
332 case 0x9:
333 viaparinfo->lvds_setting_info->lcd_panel_hres = 1024;
334 viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
335 viaparinfo->lvds_setting_info->lcd_panel_id =
336 LCD_PANEL_ID2_1024X768;
337 viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
338 viaparinfo->lvds_setting_info->LCDDithering = 1;
339 return VIA_RES_1024X768;
340 break;
341 case 0xA:
342 viaparinfo->lvds_setting_info->lcd_panel_hres = 1024;
343 viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
344 viaparinfo->lvds_setting_info->lcd_panel_id =
345 LCD_PANEL_ID2_1024X768;
346 viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
347 viaparinfo->lvds_setting_info->LCDDithering = 0;
348 return VIA_RES_1024X768;
349 break;
350 case 0xB:
351 viaparinfo->lvds_setting_info->lcd_panel_hres = 1024;
352 viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
353 viaparinfo->lvds_setting_info->lcd_panel_id =
354 LCD_PANEL_ID2_1024X768;
355 viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
356 viaparinfo->lvds_setting_info->LCDDithering = 0;
357 return VIA_RES_1024X768;
358 break;
359 case 0xC:
360 viaparinfo->lvds_setting_info->lcd_panel_hres = 1280;
361 viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
362 viaparinfo->lvds_setting_info->lcd_panel_id =
363 LCD_PANEL_ID3_1280X768;
364 viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
365 viaparinfo->lvds_setting_info->LCDDithering = 0;
366 return VIA_RES_1280X768;
367 break;
368 case 0xD:
369 viaparinfo->lvds_setting_info->lcd_panel_hres = 1280;
370 viaparinfo->lvds_setting_info->lcd_panel_vres = 1024;
371 viaparinfo->lvds_setting_info->lcd_panel_id =
372 LCD_PANEL_ID4_1280X1024;
373 viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
374 viaparinfo->lvds_setting_info->LCDDithering = 0;
375 return VIA_RES_1280X1024;
376 break;
377 case 0xE:
378 viaparinfo->lvds_setting_info->lcd_panel_hres = 1400;
379 viaparinfo->lvds_setting_info->lcd_panel_vres = 1050;
380 viaparinfo->lvds_setting_info->lcd_panel_id =
381 LCD_PANEL_ID5_1400X1050;
382 viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
383 viaparinfo->lvds_setting_info->LCDDithering = 0;
384 return VIA_RES_1400X1050;
385 break;
386 case 0xF:
387 viaparinfo->lvds_setting_info->lcd_panel_hres = 1600;
388 viaparinfo->lvds_setting_info->lcd_panel_vres = 1200;
389 viaparinfo->lvds_setting_info->lcd_panel_id =
390 LCD_PANEL_ID6_1600X1200;
391 viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
392 viaparinfo->lvds_setting_info->LCDDithering = 0;
393 return VIA_RES_1600X1200;
394 break;
395 case 0x10:
396 viaparinfo->lvds_setting_info->lcd_panel_hres = 1366;
397 viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
398 viaparinfo->lvds_setting_info->lcd_panel_id =
399 LCD_PANEL_ID7_1366X768;
400 viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
401 viaparinfo->lvds_setting_info->LCDDithering = 0;
402 return VIA_RES_1368X768;
403 break;
404 case 0x11:
405 viaparinfo->lvds_setting_info->lcd_panel_hres = 1024;
406 viaparinfo->lvds_setting_info->lcd_panel_vres = 600;
407 viaparinfo->lvds_setting_info->lcd_panel_id =
408 LCD_PANEL_ID8_1024X600;
409 viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
410 viaparinfo->lvds_setting_info->LCDDithering = 1;
411 return VIA_RES_1024X600;
412 break;
413 case 0x12:
414 viaparinfo->lvds_setting_info->lcd_panel_hres = 1280;
415 viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
416 viaparinfo->lvds_setting_info->lcd_panel_id =
417 LCD_PANEL_ID3_1280X768;
418 viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
419 viaparinfo->lvds_setting_info->LCDDithering = 1;
420 return VIA_RES_1280X768;
421 break;
422 case 0x13:
423 viaparinfo->lvds_setting_info->lcd_panel_hres = 1280;
424 viaparinfo->lvds_setting_info->lcd_panel_vres = 800;
425 viaparinfo->lvds_setting_info->lcd_panel_id =
426 LCD_PANEL_ID9_1280X800;
427 viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
428 viaparinfo->lvds_setting_info->LCDDithering = 1;
429 return VIA_RES_1280X800;
430 break;
431 case 0x14:
432 viaparinfo->lvds_setting_info->lcd_panel_hres = 1360;
433 viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
434 viaparinfo->lvds_setting_info->lcd_panel_id =
435 LCD_PANEL_IDB_1360X768;
436 viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
437 viaparinfo->lvds_setting_info->LCDDithering = 0;
438 return VIA_RES_1360X768;
439 break;
440 case 0x15:
441 viaparinfo->lvds_setting_info->lcd_panel_hres = 1280;
442 viaparinfo->lvds_setting_info->lcd_panel_vres = 768;
443 viaparinfo->lvds_setting_info->lcd_panel_id =
444 LCD_PANEL_ID3_1280X768;
445 viaparinfo->lvds_setting_info->device_lcd_dualedge = 1;
446 viaparinfo->lvds_setting_info->LCDDithering = 0;
447 return VIA_RES_1280X768;
448 break;
449 case 0x16:
450 viaparinfo->lvds_setting_info->lcd_panel_hres = 480;
451 viaparinfo->lvds_setting_info->lcd_panel_vres = 640;
452 viaparinfo->lvds_setting_info->lcd_panel_id =
453 LCD_PANEL_IDC_480X640;
454 viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
455 viaparinfo->lvds_setting_info->LCDDithering = 1;
456 return VIA_RES_480X640;
457 break;
458 default:
459 viaparinfo->lvds_setting_info->lcd_panel_hres = 800;
460 viaparinfo->lvds_setting_info->lcd_panel_vres = 600;
461 viaparinfo->lvds_setting_info->lcd_panel_id =
462 LCD_PANEL_ID1_800X600;
463 viaparinfo->lvds_setting_info->device_lcd_dualedge = 0;
464 viaparinfo->lvds_setting_info->LCDDithering = 1;
465 return VIA_RES_800X600;
466 }
467}
468
469static int lvds_register_read(int index)
470{
471 u8 data;
472
473 viaparinfo->i2c_stuff.i2c_port = GPIOPORTINDEX;
474 viafb_i2c_readbyte((u8) viaparinfo->chip_info->
475 lvds_chip_info.lvds_chip_slave_addr,
476 (u8) index, &data);
477 return data;
478}
479
480static void load_lcd_scaling(int set_hres, int set_vres, int panel_hres,
481 int panel_vres)
482{
483 int reg_value = 0;
484 int viafb_load_reg_num;
485 struct io_register *reg = NULL;
486
487 DEBUG_MSG(KERN_INFO "load_lcd_scaling()!!\n");
488
489 /* LCD Scaling Enable */
490 viafb_write_reg_mask(CR79, VIACR, 0x07, BIT0 + BIT1 + BIT2);
491 if (UNICHROME_P4M900 == viaparinfo->chip_info->gfx_chip_name) {
492 viafb_load_scaling_factor_for_p4m900(set_hres, set_vres,
493 panel_hres, panel_vres);
494 return;
495 }
496
497 /* Check if expansion for horizontal */
498 if (set_hres != panel_hres) {
499 /* Load Horizontal Scaling Factor */
500 switch (viaparinfo->chip_info->gfx_chip_name) {
501 case UNICHROME_CLE266:
502 case UNICHROME_K400:
503 reg_value =
504 CLE266_LCD_HOR_SCF_FORMULA(set_hres, panel_hres);
505 viafb_load_reg_num =
506 lcd_scaling_factor_CLE.lcd_hor_scaling_factor.
507 reg_num;
508 reg = lcd_scaling_factor_CLE.lcd_hor_scaling_factor.reg;
509 viafb_load_reg(reg_value,
510 viafb_load_reg_num, reg, VIACR);
511 break;
512 case UNICHROME_K800:
513 case UNICHROME_PM800:
514 case UNICHROME_CN700:
515 case UNICHROME_CX700:
516 case UNICHROME_K8M890:
517 case UNICHROME_P4M890:
518 reg_value =
519 K800_LCD_HOR_SCF_FORMULA(set_hres, panel_hres);
520 /* Horizontal scaling enabled */
521 viafb_write_reg_mask(CRA2, VIACR, 0xC0, BIT7 + BIT6);
522 viafb_load_reg_num =
523 lcd_scaling_factor.lcd_hor_scaling_factor.reg_num;
524 reg = lcd_scaling_factor.lcd_hor_scaling_factor.reg;
525 viafb_load_reg(reg_value,
526 viafb_load_reg_num, reg, VIACR);
527 break;
528 }
529
530 DEBUG_MSG(KERN_INFO "Horizontal Scaling value = %d", reg_value);
531 } else {
532 /* Horizontal scaling disabled */
533 viafb_write_reg_mask(CRA2, VIACR, 0x00, BIT7);
534 }
535
536 /* Check if expansion for vertical */
537 if (set_vres != panel_vres) {
538 /* Load Vertical Scaling Factor */
539 switch (viaparinfo->chip_info->gfx_chip_name) {
540 case UNICHROME_CLE266:
541 case UNICHROME_K400:
542 reg_value =
543 CLE266_LCD_VER_SCF_FORMULA(set_vres, panel_vres);
544 viafb_load_reg_num =
545 lcd_scaling_factor_CLE.lcd_ver_scaling_factor.
546 reg_num;
547 reg = lcd_scaling_factor_CLE.lcd_ver_scaling_factor.reg;
548 viafb_load_reg(reg_value,
549 viafb_load_reg_num, reg, VIACR);
550 break;
551 case UNICHROME_K800:
552 case UNICHROME_PM800:
553 case UNICHROME_CN700:
554 case UNICHROME_CX700:
555 case UNICHROME_K8M890:
556 case UNICHROME_P4M890:
557 reg_value =
558 K800_LCD_VER_SCF_FORMULA(set_vres, panel_vres);
559 /* Vertical scaling enabled */
560 viafb_write_reg_mask(CRA2, VIACR, 0x08, BIT3);
561 viafb_load_reg_num =
562 lcd_scaling_factor.lcd_ver_scaling_factor.reg_num;
563 reg = lcd_scaling_factor.lcd_ver_scaling_factor.reg;
564 viafb_load_reg(reg_value,
565 viafb_load_reg_num, reg, VIACR);
566 break;
567 }
568
569 DEBUG_MSG(KERN_INFO "Vertical Scaling value = %d", reg_value);
570 } else {
571 /* Vertical scaling disabled */
572 viafb_write_reg_mask(CRA2, VIACR, 0x00, BIT3);
573 }
574}
575
576static void load_lcd_k400_patch_tbl(int set_hres, int set_vres,
577 int panel_id)
578{
579 int vmode_index;
580 int reg_num = 0;
581 struct io_reg *lcd_patch_reg = NULL;
582
583 if (viaparinfo->lvds_setting_info->iga_path == IGA2)
584 vmode_index = viafb_get_mode_index(set_hres, set_vres, 1);
585 else
586 vmode_index = viafb_get_mode_index(set_hres, set_vres, 0);
587 switch (panel_id) {
588 /* LCD 800x600 */
589 case LCD_PANEL_ID1_800X600:
590 switch (vmode_index) {
591 case VIA_RES_640X400:
592 case VIA_RES_640X480:
593 reg_num = NUM_TOTAL_K400_LCD_RES_6X4_8X6;
594 lcd_patch_reg = K400_LCD_RES_6X4_8X6;
595 break;
596 case VIA_RES_720X480:
597 case VIA_RES_720X576:
598 reg_num = NUM_TOTAL_K400_LCD_RES_7X4_8X6;
599 lcd_patch_reg = K400_LCD_RES_7X4_8X6;
600 break;
601 }
602 break;
603
604 /* LCD 1024x768 */
605 case LCD_PANEL_ID2_1024X768:
606 switch (vmode_index) {
607 case VIA_RES_640X400:
608 case VIA_RES_640X480:
609 reg_num = NUM_TOTAL_K400_LCD_RES_6X4_10X7;
610 lcd_patch_reg = K400_LCD_RES_6X4_10X7;
611 break;
612 case VIA_RES_720X480:
613 case VIA_RES_720X576:
614 reg_num = NUM_TOTAL_K400_LCD_RES_7X4_10X7;
615 lcd_patch_reg = K400_LCD_RES_7X4_10X7;
616 break;
617 case VIA_RES_800X600:
618 reg_num = NUM_TOTAL_K400_LCD_RES_8X6_10X7;
619 lcd_patch_reg = K400_LCD_RES_8X6_10X7;
620 break;
621 }
622 break;
623
624 /* LCD 1280x1024 */
625 case LCD_PANEL_ID4_1280X1024:
626 switch (vmode_index) {
627 case VIA_RES_640X400:
628 case VIA_RES_640X480:
629 reg_num = NUM_TOTAL_K400_LCD_RES_6X4_12X10;
630 lcd_patch_reg = K400_LCD_RES_6X4_12X10;
631 break;
632 case VIA_RES_720X480:
633 case VIA_RES_720X576:
634 reg_num = NUM_TOTAL_K400_LCD_RES_7X4_12X10;
635 lcd_patch_reg = K400_LCD_RES_7X4_12X10;
636 break;
637 case VIA_RES_800X600:
638 reg_num = NUM_TOTAL_K400_LCD_RES_8X6_12X10;
639 lcd_patch_reg = K400_LCD_RES_8X6_12X10;
640 break;
641 case VIA_RES_1024X768:
642 reg_num = NUM_TOTAL_K400_LCD_RES_10X7_12X10;
643 lcd_patch_reg = K400_LCD_RES_10X7_12X10;
644 break;
645
646 }
647 break;
648
649 /* LCD 1400x1050 */
650 case LCD_PANEL_ID5_1400X1050:
651 switch (vmode_index) {
652 case VIA_RES_640X480:
653 reg_num = NUM_TOTAL_K400_LCD_RES_6X4_14X10;
654 lcd_patch_reg = K400_LCD_RES_6X4_14X10;
655 break;
656 case VIA_RES_800X600:
657 reg_num = NUM_TOTAL_K400_LCD_RES_8X6_14X10;
658 lcd_patch_reg = K400_LCD_RES_8X6_14X10;
659 break;
660 case VIA_RES_1024X768:
661 reg_num = NUM_TOTAL_K400_LCD_RES_10X7_14X10;
662 lcd_patch_reg = K400_LCD_RES_10X7_14X10;
663 break;
664 case VIA_RES_1280X768:
665 case VIA_RES_1280X800:
666 case VIA_RES_1280X960:
667 case VIA_RES_1280X1024:
668 reg_num = NUM_TOTAL_K400_LCD_RES_12X10_14X10;
669 lcd_patch_reg = K400_LCD_RES_12X10_14X10;
670 break;
671 }
672 break;
673
674 /* LCD 1600x1200 */
675 case LCD_PANEL_ID6_1600X1200:
676 switch (vmode_index) {
677 case VIA_RES_640X400:
678 case VIA_RES_640X480:
679 reg_num = NUM_TOTAL_K400_LCD_RES_6X4_16X12;
680 lcd_patch_reg = K400_LCD_RES_6X4_16X12;
681 break;
682 case VIA_RES_720X480:
683 case VIA_RES_720X576:
684 reg_num = NUM_TOTAL_K400_LCD_RES_7X4_16X12;
685 lcd_patch_reg = K400_LCD_RES_7X4_16X12;
686 break;
687 case VIA_RES_800X600:
688 reg_num = NUM_TOTAL_K400_LCD_RES_8X6_16X12;
689 lcd_patch_reg = K400_LCD_RES_8X6_16X12;
690 break;
691 case VIA_RES_1024X768:
692 reg_num = NUM_TOTAL_K400_LCD_RES_10X7_16X12;
693 lcd_patch_reg = K400_LCD_RES_10X7_16X12;
694 break;
695 case VIA_RES_1280X768:
696 case VIA_RES_1280X800:
697 case VIA_RES_1280X960:
698 case VIA_RES_1280X1024:
699 reg_num = NUM_TOTAL_K400_LCD_RES_12X10_16X12;
700 lcd_patch_reg = K400_LCD_RES_12X10_16X12;
701 break;
702 }
703 break;
704
705 /* LCD 1366x768 */
706 case LCD_PANEL_ID7_1366X768:
707 switch (vmode_index) {
708 case VIA_RES_640X480:
709 reg_num = NUM_TOTAL_K400_LCD_RES_6X4_1366X7;
710 lcd_patch_reg = K400_LCD_RES_6X4_1366X7;
711 break;
712 case VIA_RES_720X480:
713 case VIA_RES_720X576:
714 reg_num = NUM_TOTAL_K400_LCD_RES_7X4_1366X7;
715 lcd_patch_reg = K400_LCD_RES_7X4_1366X7;
716 break;
717 case VIA_RES_800X600:
718 reg_num = NUM_TOTAL_K400_LCD_RES_8X6_1366X7;
719 lcd_patch_reg = K400_LCD_RES_8X6_1366X7;
720 break;
721 case VIA_RES_1024X768:
722 reg_num = NUM_TOTAL_K400_LCD_RES_10X7_1366X7;
723 lcd_patch_reg = K400_LCD_RES_10X7_1366X7;
724 break;
725 case VIA_RES_1280X768:
726 case VIA_RES_1280X800:
727 case VIA_RES_1280X960:
728 case VIA_RES_1280X1024:
729 reg_num = NUM_TOTAL_K400_LCD_RES_12X10_1366X7;
730 lcd_patch_reg = K400_LCD_RES_12X10_1366X7;
731 break;
732 }
733 break;
734
735 /* LCD 1360x768 */
736 case LCD_PANEL_IDB_1360X768:
737 break;
738 }
739 if (reg_num != 0) {
740 /* H.W. Reset : ON */
741 viafb_write_reg_mask(CR17, VIACR, 0x00, BIT7);
742
743 viafb_write_regx(lcd_patch_reg, reg_num);
744
745 /* H.W. Reset : OFF */
746 viafb_write_reg_mask(CR17, VIACR, 0x80, BIT7);
747
748 /* Reset PLL */
749 viafb_write_reg_mask(SR40, VIASR, 0x02, BIT1);
750 viafb_write_reg_mask(SR40, VIASR, 0x00, BIT1);
751
752 /* Fire! */
753 outb(inb(VIARMisc) | (BIT2 + BIT3), VIAWMisc);
754 }
755}
756
757static void load_lcd_p880_patch_tbl(int set_hres, int set_vres,
758 int panel_id)
759{
760 int vmode_index;
761 int reg_num = 0;
762 struct io_reg *lcd_patch_reg = NULL;
763
764 if (viaparinfo->lvds_setting_info->iga_path == IGA2)
765 vmode_index = viafb_get_mode_index(set_hres, set_vres, 1);
766 else
767 vmode_index = viafb_get_mode_index(set_hres, set_vres, 0);
768
769 switch (panel_id) {
770 case LCD_PANEL_ID5_1400X1050:
771 switch (vmode_index) {
772 case VIA_RES_640X480:
773 reg_num = NUM_TOTAL_P880_LCD_RES_6X4_14X10;
774 lcd_patch_reg = P880_LCD_RES_6X4_14X10;
775 break;
776 case VIA_RES_800X600:
777 reg_num = NUM_TOTAL_P880_LCD_RES_8X6_14X10;
778 lcd_patch_reg = P880_LCD_RES_8X6_14X10;
779 break;
780 }
781 break;
782 case LCD_PANEL_ID6_1600X1200:
783 switch (vmode_index) {
784 case VIA_RES_640X400:
785 case VIA_RES_640X480:
786 reg_num = NUM_TOTAL_P880_LCD_RES_6X4_16X12;
787 lcd_patch_reg = P880_LCD_RES_6X4_16X12;
788 break;
789 case VIA_RES_720X480:
790 case VIA_RES_720X576:
791 reg_num = NUM_TOTAL_P880_LCD_RES_7X4_16X12;
792 lcd_patch_reg = P880_LCD_RES_7X4_16X12;
793 break;
794 case VIA_RES_800X600:
795 reg_num = NUM_TOTAL_P880_LCD_RES_8X6_16X12;
796 lcd_patch_reg = P880_LCD_RES_8X6_16X12;
797 break;
798 case VIA_RES_1024X768:
799 reg_num = NUM_TOTAL_P880_LCD_RES_10X7_16X12;
800 lcd_patch_reg = P880_LCD_RES_10X7_16X12;
801 break;
802 case VIA_RES_1280X768:
803 case VIA_RES_1280X960:
804 case VIA_RES_1280X1024:
805 reg_num = NUM_TOTAL_P880_LCD_RES_12X10_16X12;
806 lcd_patch_reg = P880_LCD_RES_12X10_16X12;
807 break;
808 }
809 break;
810
811 }
812 if (reg_num != 0) {
813 /* H.W. Reset : ON */
814 viafb_write_reg_mask(CR17, VIACR, 0x00, BIT7);
815
816 viafb_write_regx(lcd_patch_reg, reg_num);
817
818 /* H.W. Reset : OFF */
819 viafb_write_reg_mask(CR17, VIACR, 0x80, BIT7);
820
821 /* Reset PLL */
822 viafb_write_reg_mask(SR40, VIASR, 0x02, BIT1);
823 viafb_write_reg_mask(SR40, VIASR, 0x00, BIT1);
824
825 /* Fire! */
826 outb(inb(VIARMisc) | (BIT2 + BIT3), VIAWMisc);
827 }
828}
829
830static void load_lcd_patch_regs(int set_hres, int set_vres,
831 int panel_id, int set_iga)
832{
833 int vmode_index;
834
835 if (viaparinfo->lvds_setting_info->iga_path == IGA2)
836 vmode_index = viafb_get_mode_index(set_hres, set_vres, 1);
837 else
838 vmode_index = viafb_get_mode_index(set_hres, set_vres, 0);
839
840 viafb_unlock_crt();
841
842 /* Patch for simultaneous & Expansion */
843 if ((set_iga == IGA1_IGA2) &&
844 (viaparinfo->lvds_setting_info->display_method ==
845 LCD_EXPANDSION)) {
846 switch (viaparinfo->chip_info->gfx_chip_name) {
847 case UNICHROME_CLE266:
848 case UNICHROME_K400:
849 load_lcd_k400_patch_tbl(set_hres, set_vres, panel_id);
850 break;
851 case UNICHROME_K800:
852 break;
853 case UNICHROME_PM800:
854 case UNICHROME_CN700:
855 case UNICHROME_CX700:
856 load_lcd_p880_patch_tbl(set_hres, set_vres, panel_id);
857 }
858 }
859
860 viafb_lock_crt();
861}
862
863static void via_pitch_alignment_patch_lcd(
864 struct lvds_setting_information *plvds_setting_info,
865 struct lvds_chip_information
866 *plvds_chip_info)
867{
868 unsigned char cr13, cr35, cr65, cr66, cr67;
869 unsigned long dwScreenPitch = 0;
870 unsigned long dwPitch;
871
872 dwPitch = plvds_setting_info->h_active * (plvds_setting_info->bpp >> 3);
873 if (dwPitch & 0x1F) {
874 dwScreenPitch = ((dwPitch + 31) & ~31) >> 3;
875 if (plvds_setting_info->iga_path == IGA2) {
876 if (plvds_setting_info->bpp > 8) {
877 cr66 = (unsigned char)(dwScreenPitch & 0xFF);
878 viafb_write_reg(CR66, VIACR, cr66);
879 cr67 = viafb_read_reg(VIACR, CR67) & 0xFC;
880 cr67 |=
881 (unsigned
882 char)((dwScreenPitch & 0x300) >> 8);
883 viafb_write_reg(CR67, VIACR, cr67);
884 }
885
886 /* Fetch Count */
887 cr67 = viafb_read_reg(VIACR, CR67) & 0xF3;
888 cr67 |= (unsigned char)((dwScreenPitch & 0x600) >> 7);
889 viafb_write_reg(CR67, VIACR, cr67);
890 cr65 = (unsigned char)((dwScreenPitch >> 1) & 0xFF);
891 cr65 += 2;
892 viafb_write_reg(CR65, VIACR, cr65);
893 } else {
894 if (plvds_setting_info->bpp > 8) {
895 cr13 = (unsigned char)(dwScreenPitch & 0xFF);
896 viafb_write_reg(CR13, VIACR, cr13);
897 cr35 = viafb_read_reg(VIACR, CR35) & 0x1F;
898 cr35 |=
899 (unsigned
900 char)((dwScreenPitch & 0x700) >> 3);
901 viafb_write_reg(CR35, VIACR, cr35);
902 }
903 }
904 }
905}
906static void lcd_patch_skew_dvp0(struct lvds_setting_information
907 *plvds_setting_info,
908 struct lvds_chip_information *plvds_chip_info)
909{
910 if (VT1636_LVDS == plvds_chip_info->lvds_chip_name) {
911 switch (viaparinfo->chip_info->gfx_chip_name) {
912 case UNICHROME_P4M900:
913 viafb_vt1636_patch_skew_on_vt3364(plvds_setting_info,
914 plvds_chip_info);
915 break;
916 case UNICHROME_P4M890:
917 viafb_vt1636_patch_skew_on_vt3327(plvds_setting_info,
918 plvds_chip_info);
919 break;
920 }
921 }
922}
923static void lcd_patch_skew_dvp1(struct lvds_setting_information
924 *plvds_setting_info,
925 struct lvds_chip_information *plvds_chip_info)
926{
927 if (VT1636_LVDS == plvds_chip_info->lvds_chip_name) {
928 switch (viaparinfo->chip_info->gfx_chip_name) {
929 case UNICHROME_CX700:
930 viafb_vt1636_patch_skew_on_vt3324(plvds_setting_info,
931 plvds_chip_info);
932 break;
933 }
934 }
935}
936static void lcd_patch_skew(struct lvds_setting_information
937 *plvds_setting_info, struct lvds_chip_information *plvds_chip_info)
938{
939 DEBUG_MSG(KERN_INFO "lcd_patch_skew\n");
940 switch (plvds_chip_info->output_interface) {
941 case INTERFACE_DVP0:
942 lcd_patch_skew_dvp0(plvds_setting_info, plvds_chip_info);
943 break;
944 case INTERFACE_DVP1:
945 lcd_patch_skew_dvp1(plvds_setting_info, plvds_chip_info);
946 break;
947 case INTERFACE_DFP_LOW:
948 if (UNICHROME_P4M900 == viaparinfo->chip_info->gfx_chip_name) {
949 viafb_write_reg_mask(CR99, VIACR, 0x08,
950 BIT0 + BIT1 + BIT2 + BIT3);
951 }
952 break;
953 }
954}
955
956/* LCD Set Mode */
957void viafb_lcd_set_mode(struct crt_mode_table *mode_crt_table,
958 struct lvds_setting_information *plvds_setting_info,
959 struct lvds_chip_information *plvds_chip_info)
960{
961 int video_index = plvds_setting_info->lcd_panel_size;
962 int set_iga = plvds_setting_info->iga_path;
963 int mode_bpp = plvds_setting_info->bpp;
964 int viafb_load_reg_num = 0;
965 int reg_value = 0;
966 int set_hres, set_vres;
967 int panel_hres, panel_vres;
968 u32 pll_D_N;
969 int offset;
970 struct io_register *reg = NULL;
971 struct display_timing mode_crt_reg, panel_crt_reg;
972 struct crt_mode_table *panel_crt_table = NULL;
973 struct VideoModeTable *vmode_tbl = NULL;
974
975 DEBUG_MSG(KERN_INFO "viafb_lcd_set_mode!!\n");
976 /* Get mode table */
977 mode_crt_reg = mode_crt_table->crtc;
978 /* Get panel table Pointer */
979 vmode_tbl = viafb_get_modetbl_pointer(video_index);
980 panel_crt_table = vmode_tbl->crtc;
981 panel_crt_reg = panel_crt_table->crtc;
982 DEBUG_MSG(KERN_INFO "bellow viafb_lcd_set_mode!!\n");
983 set_hres = plvds_setting_info->h_active;
984 set_vres = plvds_setting_info->v_active;
985 panel_hres = plvds_setting_info->lcd_panel_hres;
986 panel_vres = plvds_setting_info->lcd_panel_vres;
987 if (VT1636_LVDS == plvds_chip_info->lvds_chip_name)
988 viafb_init_lvds_vt1636(plvds_setting_info, plvds_chip_info);
989 plvds_setting_info->vclk = panel_crt_table->clk;
990 if (set_iga == IGA1) {
991 /* IGA1 doesn't have LCD scaling, so set it as centering. */
992 viafb_load_crtc_timing(lcd_centering_timging
993 (mode_crt_reg, panel_crt_reg), IGA1);
994 } else {
995 /* Expansion */
996 if ((plvds_setting_info->display_method ==
997 LCD_EXPANDSION) & ((set_hres != panel_hres)
998 || (set_vres != panel_vres))) {
999 /* expansion timing IGA2 loaded panel set timing*/
1000 viafb_load_crtc_timing(panel_crt_reg, IGA2);
1001 DEBUG_MSG(KERN_INFO "viafb_load_crtc_timing!!\n");
1002 load_lcd_scaling(set_hres, set_vres, panel_hres,
1003 panel_vres);
1004 DEBUG_MSG(KERN_INFO "load_lcd_scaling!!\n");
1005 } else { /* Centering */
1006 /* centering timing IGA2 always loaded panel
1007 and mode releative timing */
1008 viafb_load_crtc_timing(lcd_centering_timging
1009 (mode_crt_reg, panel_crt_reg), IGA2);
1010 viafb_write_reg_mask(CR79, VIACR, 0x00,
1011 BIT0 + BIT1 + BIT2);
1012 /* LCD scaling disabled */
1013 }
1014 }
1015
1016 if (set_iga == IGA1_IGA2) {
1017 load_crtc_shadow_timing(mode_crt_reg, panel_crt_reg);
1018 /* Fill shadow registers */
1019
1020 switch (plvds_setting_info->lcd_panel_id) {
1021 case LCD_PANEL_ID0_640X480:
1022 offset = 80;
1023 break;
1024 case LCD_PANEL_ID1_800X600:
1025 case LCD_PANEL_IDA_800X480:
1026 offset = 110;
1027 break;
1028 case LCD_PANEL_ID2_1024X768:
1029 offset = 150;
1030 break;
1031 case LCD_PANEL_ID3_1280X768:
1032 case LCD_PANEL_ID4_1280X1024:
1033 case LCD_PANEL_ID5_1400X1050:
1034 case LCD_PANEL_ID9_1280X800:
1035 offset = 190;
1036 break;
1037 case LCD_PANEL_ID6_1600X1200:
1038 offset = 250;
1039 break;
1040 case LCD_PANEL_ID7_1366X768:
1041 case LCD_PANEL_IDB_1360X768:
1042 offset = 212;
1043 break;
1044 default:
1045 offset = 140;
1046 break;
1047 }
1048
1049 /* Offset for simultaneous */
1050 reg_value = offset;
1051 viafb_load_reg_num = offset_reg.iga2_offset_reg.reg_num;
1052 reg = offset_reg.iga2_offset_reg.reg;
1053 viafb_load_reg(reg_value, viafb_load_reg_num, reg, VIACR);
1054 DEBUG_MSG(KERN_INFO "viafb_load_reg!!\n");
1055 viafb_load_fetch_count_reg(set_hres, 4, IGA2);
1056 /* Fetch count for simultaneous */
1057 } else { /* SAMM */
1058 /* Offset for IGA2 only */
1059 viafb_load_offset_reg(set_hres, mode_bpp / 8, set_iga);
1060 /* Fetch count for IGA2 only */
1061 viafb_load_fetch_count_reg(set_hres, mode_bpp / 8, set_iga);
1062
1063 if ((viaparinfo->chip_info->gfx_chip_name != UNICHROME_CLE266)
1064 && (viaparinfo->chip_info->gfx_chip_name != UNICHROME_K400))
1065 viafb_load_FIFO_reg(set_iga, set_hres, set_vres);
1066
1067 viafb_set_color_depth(mode_bpp / 8, set_iga);
1068 }
1069
1070 fill_lcd_format();
1071
1072 pll_D_N = viafb_get_clk_value(panel_crt_table[0].clk);
1073 DEBUG_MSG(KERN_INFO "PLL=0x%x", pll_D_N);
1074 viafb_set_vclock(pll_D_N, set_iga);
1075
1076 viafb_set_output_path(DEVICE_LCD, set_iga,
1077 plvds_chip_info->output_interface);
1078 lcd_patch_skew(plvds_setting_info, plvds_chip_info);
1079
1080 /* If K8M800, enable LCD Prefetch Mode. */
1081 if ((viaparinfo->chip_info->gfx_chip_name == UNICHROME_K800)
1082 || (UNICHROME_K8M890 == viaparinfo->chip_info->gfx_chip_name))
1083 viafb_write_reg_mask(CR6A, VIACR, 0x01, BIT0);
1084
1085 load_lcd_patch_regs(set_hres, set_vres,
1086 plvds_setting_info->lcd_panel_id, set_iga);
1087
1088 DEBUG_MSG(KERN_INFO "load_lcd_patch_regs!!\n");
1089
1090 /* Patch for non 32bit alignment mode */
1091 via_pitch_alignment_patch_lcd(plvds_setting_info, plvds_chip_info);
1092}
1093
1094static void integrated_lvds_disable(struct lvds_setting_information
1095 *plvds_setting_info,
1096 struct lvds_chip_information *plvds_chip_info)
1097{
1098 bool turn_off_first_powersequence = false;
1099 bool turn_off_second_powersequence = false;
1100 if (INTERFACE_LVDS0LVDS1 == plvds_chip_info->output_interface)
1101 turn_off_first_powersequence = true;
1102 if (INTERFACE_LVDS0 == plvds_chip_info->output_interface)
1103 turn_off_first_powersequence = true;
1104 if (INTERFACE_LVDS1 == plvds_chip_info->output_interface)
1105 turn_off_second_powersequence = true;
1106 if (turn_off_second_powersequence) {
1107 /* Use second power sequence control: */
1108
1109 /* Turn off power sequence. */
1110 viafb_write_reg_mask(CRD4, VIACR, 0, BIT1);
1111
1112 /* Turn off back light. */
1113 viafb_write_reg_mask(CRD3, VIACR, 0xC0, BIT6 + BIT7);
1114 }
1115 if (turn_off_first_powersequence) {
1116 /* Use first power sequence control: */
1117
1118 /* Turn off power sequence. */
1119 viafb_write_reg_mask(CR6A, VIACR, 0, BIT3);
1120
1121 /* Turn off back light. */
1122 viafb_write_reg_mask(CR91, VIACR, 0xC0, BIT6 + BIT7);
1123 }
1124
1125 /* Turn DFP High/Low Pad off. */
1126 viafb_write_reg_mask(SR2A, VIASR, 0, BIT0 + BIT1 + BIT2 + BIT3);
1127
1128 /* Power off LVDS channel. */
1129 switch (plvds_chip_info->output_interface) {
1130 case INTERFACE_LVDS0:
1131 {
1132 viafb_write_reg_mask(CRD2, VIACR, 0x80, BIT7);
1133 break;
1134 }
1135
1136 case INTERFACE_LVDS1:
1137 {
1138 viafb_write_reg_mask(CRD2, VIACR, 0x40, BIT6);
1139 break;
1140 }
1141
1142 case INTERFACE_LVDS0LVDS1:
1143 {
1144 viafb_write_reg_mask(CRD2, VIACR, 0xC0, BIT6 + BIT7);
1145 break;
1146 }
1147 }
1148}
1149
1150static void integrated_lvds_enable(struct lvds_setting_information
1151 *plvds_setting_info,
1152 struct lvds_chip_information *plvds_chip_info)
1153{
1154 bool turn_on_first_powersequence = false;
1155 bool turn_on_second_powersequence = false;
1156
1157 DEBUG_MSG(KERN_INFO "integrated_lvds_enable, out_interface:%d\n",
1158 plvds_chip_info->output_interface);
1159 if (plvds_setting_info->lcd_mode == LCD_SPWG)
1160 viafb_write_reg_mask(CRD2, VIACR, 0x00, BIT0 + BIT1);
1161 else
1162 viafb_write_reg_mask(CRD2, VIACR, 0x03, BIT0 + BIT1);
1163 if (INTERFACE_LVDS0LVDS1 == plvds_chip_info->output_interface)
1164 turn_on_first_powersequence = true;
1165 if (INTERFACE_LVDS0 == plvds_chip_info->output_interface)
1166 turn_on_first_powersequence = true;
1167 if (INTERFACE_LVDS1 == plvds_chip_info->output_interface)
1168 turn_on_second_powersequence = true;
1169
1170 if (turn_on_second_powersequence) {
1171 /* Use second power sequence control: */
1172
1173 /* Use hardware control power sequence. */
1174 viafb_write_reg_mask(CRD3, VIACR, 0, BIT0);
1175
1176 /* Turn on back light. */
1177 viafb_write_reg_mask(CRD3, VIACR, 0, BIT6 + BIT7);
1178
1179 /* Turn on hardware power sequence. */
1180 viafb_write_reg_mask(CRD4, VIACR, 0x02, BIT1);
1181 }
1182 if (turn_on_first_powersequence) {
1183 /* Use first power sequence control: */
1184
1185 /* Use hardware control power sequence. */
1186 viafb_write_reg_mask(CR91, VIACR, 0, BIT0);
1187
1188 /* Turn on back light. */
1189 viafb_write_reg_mask(CR91, VIACR, 0, BIT6 + BIT7);
1190
1191 /* Turn on hardware power sequence. */
1192 viafb_write_reg_mask(CR6A, VIACR, 0x08, BIT3);
1193 }
1194
1195 /* Turn DFP High/Low pad on. */
1196 viafb_write_reg_mask(SR2A, VIASR, 0x0F, BIT0 + BIT1 + BIT2 + BIT3);
1197
1198 /* Power on LVDS channel. */
1199 switch (plvds_chip_info->output_interface) {
1200 case INTERFACE_LVDS0:
1201 {
1202 viafb_write_reg_mask(CRD2, VIACR, 0, BIT7);
1203 break;
1204 }
1205
1206 case INTERFACE_LVDS1:
1207 {
1208 viafb_write_reg_mask(CRD2, VIACR, 0, BIT6);
1209 break;
1210 }
1211
1212 case INTERFACE_LVDS0LVDS1:
1213 {
1214 viafb_write_reg_mask(CRD2, VIACR, 0, BIT6 + BIT7);
1215 break;
1216 }
1217 }
1218}
1219
1220void viafb_lcd_disable(void)
1221{
1222
1223 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
1224 lcd_powersequence_off();
1225 /* DI1 pad off */
1226 viafb_write_reg_mask(SR1E, VIASR, 0x00, 0x30);
1227 } else if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700) {
1228 if (viafb_LCD2_ON
1229 && (INTEGRATED_LVDS ==
1230 viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name))
1231 integrated_lvds_disable(viaparinfo->lvds_setting_info,
1232 &viaparinfo->chip_info->lvds_chip_info2);
1233 if (INTEGRATED_LVDS ==
1234 viaparinfo->chip_info->lvds_chip_info.lvds_chip_name)
1235 integrated_lvds_disable(viaparinfo->lvds_setting_info,
1236 &viaparinfo->chip_info->lvds_chip_info);
1237 if (VT1636_LVDS == viaparinfo->chip_info->
1238 lvds_chip_info.lvds_chip_name)
1239 viafb_disable_lvds_vt1636(viaparinfo->lvds_setting_info,
1240 &viaparinfo->chip_info->lvds_chip_info);
1241 } else if (VT1636_LVDS ==
1242 viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
1243 viafb_disable_lvds_vt1636(viaparinfo->lvds_setting_info,
1244 &viaparinfo->chip_info->lvds_chip_info);
1245 } else {
1246 /* DFP-HL pad off */
1247 viafb_write_reg_mask(SR2A, VIASR, 0x00, 0x0F);
1248 /* Backlight off */
1249 viafb_write_reg_mask(SR3D, VIASR, 0x00, 0x20);
1250 /* 24 bit DI data paht off */
1251 viafb_write_reg_mask(CR91, VIACR, 0x80, 0x80);
1252 /* Simultaneout disabled */
1253 viafb_write_reg_mask(CR6B, VIACR, 0x00, 0x08);
1254 }
1255
1256 /* Disable expansion bit */
1257 viafb_write_reg_mask(CR79, VIACR, 0x00, 0x01);
1258 /* CRT path set to IGA1 */
1259 viafb_write_reg_mask(SR16, VIASR, 0x00, 0x40);
1260 /* Simultaneout disabled */
1261 viafb_write_reg_mask(CR6B, VIACR, 0x00, 0x08);
1262 /* IGA2 path disabled */
1263 viafb_write_reg_mask(CR6A, VIACR, 0x00, 0x80);
1264
1265}
1266
1267void viafb_lcd_enable(void)
1268{
1269 if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266) {
1270 /* DI1 pad on */
1271 viafb_write_reg_mask(SR1E, VIASR, 0x30, 0x30);
1272 lcd_powersequence_on();
1273 } else if (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CX700) {
1274 if (viafb_LCD2_ON && (INTEGRATED_LVDS ==
1275 viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name))
1276 integrated_lvds_enable(viaparinfo->lvds_setting_info2, \
1277 &viaparinfo->chip_info->lvds_chip_info2);
1278 if (INTEGRATED_LVDS ==
1279 viaparinfo->chip_info->lvds_chip_info.lvds_chip_name)
1280 integrated_lvds_enable(viaparinfo->lvds_setting_info,
1281 &viaparinfo->chip_info->lvds_chip_info);
1282 if (VT1636_LVDS == viaparinfo->chip_info->
1283 lvds_chip_info.lvds_chip_name)
1284 viafb_enable_lvds_vt1636(viaparinfo->
1285 lvds_setting_info, &viaparinfo->chip_info->
1286 lvds_chip_info);
1287 } else if (VT1636_LVDS ==
1288 viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
1289 viafb_enable_lvds_vt1636(viaparinfo->lvds_setting_info,
1290 &viaparinfo->chip_info->lvds_chip_info);
1291 } else {
1292 /* DFP-HL pad on */
1293 viafb_write_reg_mask(SR2A, VIASR, 0x0F, 0x0F);
1294 /* Backlight on */
1295 viafb_write_reg_mask(SR3D, VIASR, 0x20, 0x20);
1296 /* 24 bit DI data paht on */
1297 viafb_write_reg_mask(CR91, VIACR, 0x00, 0x80);
1298
1299 /* Set data source selection bit by iga path */
1300 if (viaparinfo->lvds_setting_info->iga_path == IGA1) {
1301 /* DFP-H set to IGA1 */
1302 viafb_write_reg_mask(CR97, VIACR, 0x00, 0x10);
1303 /* DFP-L set to IGA1 */
1304 viafb_write_reg_mask(CR99, VIACR, 0x00, 0x10);
1305 } else {
1306 /* DFP-H set to IGA2 */
1307 viafb_write_reg_mask(CR97, VIACR, 0x10, 0x10);
1308 /* DFP-L set to IGA2 */
1309 viafb_write_reg_mask(CR99, VIACR, 0x10, 0x10);
1310 }
1311 /* LCD enabled */
1312 viafb_write_reg_mask(CR6A, VIACR, 0x48, 0x48);
1313 }
1314
1315 if ((viaparinfo->lvds_setting_info->iga_path == IGA1)
1316 || (viaparinfo->lvds_setting_info->iga_path == IGA1_IGA2)) {
1317 /* CRT path set to IGA2 */
1318 viafb_write_reg_mask(SR16, VIASR, 0x40, 0x40);
1319 /* IGA2 path disabled */
1320 viafb_write_reg_mask(CR6A, VIACR, 0x00, 0x80);
1321 /* IGA2 path enabled */
1322 } else { /* IGA2 */
1323 viafb_write_reg_mask(CR6A, VIACR, 0x80, 0x80);
1324 }
1325
1326}
1327
1328static void lcd_powersequence_off(void)
1329{
1330 int i, mask, data;
1331
1332 /* Software control power sequence */
1333 viafb_write_reg_mask(CR91, VIACR, 0x11, 0x11);
1334
1335 for (i = 0; i < 3; i++) {
1336 mask = PowerSequenceOff[0][i];
1337 data = PowerSequenceOff[1][i] & mask;
1338 viafb_write_reg_mask(CR91, VIACR, (u8) data, (u8) mask);
1339 udelay(PowerSequenceOff[2][i]);
1340 }
1341
1342 /* Disable LCD */
1343 viafb_write_reg_mask(CR6A, VIACR, 0x00, 0x08);
1344}
1345
1346static void lcd_powersequence_on(void)
1347{
1348 int i, mask, data;
1349
1350 /* Software control power sequence */
1351 viafb_write_reg_mask(CR91, VIACR, 0x11, 0x11);
1352
1353 /* Enable LCD */
1354 viafb_write_reg_mask(CR6A, VIACR, 0x08, 0x08);
1355
1356 for (i = 0; i < 3; i++) {
1357 mask = PowerSequenceOn[0][i];
1358 data = PowerSequenceOn[1][i] & mask;
1359 viafb_write_reg_mask(CR91, VIACR, (u8) data, (u8) mask);
1360 udelay(PowerSequenceOn[2][i]);
1361 }
1362
1363 udelay(1);
1364}
1365
1366static void fill_lcd_format(void)
1367{
1368 u8 bdithering = 0, bdual = 0;
1369
1370 if (viaparinfo->lvds_setting_info->device_lcd_dualedge)
1371 bdual = BIT4;
1372 if (viaparinfo->lvds_setting_info->LCDDithering)
1373 bdithering = BIT0;
1374 /* Dual & Dithering */
1375 viafb_write_reg_mask(CR88, VIACR, (bdithering | bdual), BIT4 + BIT0);
1376}
1377
1378static void check_diport_of_integrated_lvds(
1379 struct lvds_chip_information *plvds_chip_info,
1380 struct lvds_setting_information
1381 *plvds_setting_info)
1382{
1383 /* Determine LCD DI Port by hardware layout. */
1384 switch (viafb_display_hardware_layout) {
1385 case HW_LAYOUT_LCD_ONLY:
1386 {
1387 if (plvds_setting_info->device_lcd_dualedge) {
1388 plvds_chip_info->output_interface =
1389 INTERFACE_LVDS0LVDS1;
1390 } else {
1391 plvds_chip_info->output_interface =
1392 INTERFACE_LVDS0;
1393 }
1394
1395 break;
1396 }
1397
1398 case HW_LAYOUT_DVI_ONLY:
1399 {
1400 plvds_chip_info->output_interface = INTERFACE_NONE;
1401 break;
1402 }
1403
1404 case HW_LAYOUT_LCD1_LCD2:
1405 case HW_LAYOUT_LCD_EXTERNAL_LCD2:
1406 {
1407 plvds_chip_info->output_interface =
1408 INTERFACE_LVDS0LVDS1;
1409 break;
1410 }
1411
1412 case HW_LAYOUT_LCD_DVI:
1413 {
1414 plvds_chip_info->output_interface = INTERFACE_LVDS1;
1415 break;
1416 }
1417
1418 default:
1419 {
1420 plvds_chip_info->output_interface = INTERFACE_LVDS1;
1421 break;
1422 }
1423 }
1424
1425 DEBUG_MSG(KERN_INFO
1426 "Display Hardware Layout: 0x%x, LCD DI Port: 0x%x\n",
1427 viafb_display_hardware_layout,
1428 plvds_chip_info->output_interface);
1429}
1430
1431void viafb_init_lvds_output_interface(struct lvds_chip_information
1432 *plvds_chip_info,
1433 struct lvds_setting_information
1434 *plvds_setting_info)
1435{
1436 if (INTERFACE_NONE != plvds_chip_info->output_interface) {
1437 /*Do nothing, lcd port is specified by module parameter */
1438 return;
1439 }
1440
1441 switch (plvds_chip_info->lvds_chip_name) {
1442
1443 case VT1636_LVDS:
1444 switch (viaparinfo->chip_info->gfx_chip_name) {
1445 case UNICHROME_CX700:
1446 plvds_chip_info->output_interface = INTERFACE_DVP1;
1447 break;
1448 case UNICHROME_CN700:
1449 plvds_chip_info->output_interface = INTERFACE_DFP_LOW;
1450 break;
1451 default:
1452 plvds_chip_info->output_interface = INTERFACE_DVP0;
1453 break;
1454 }
1455 break;
1456
1457 case INTEGRATED_LVDS:
1458 check_diport_of_integrated_lvds(plvds_chip_info,
1459 plvds_setting_info);
1460 break;
1461
1462 default:
1463 switch (viaparinfo->chip_info->gfx_chip_name) {
1464 case UNICHROME_K8M890:
1465 case UNICHROME_P4M900:
1466 case UNICHROME_P4M890:
1467 plvds_chip_info->output_interface = INTERFACE_DFP_LOW;
1468 break;
1469 default:
1470 plvds_chip_info->output_interface = INTERFACE_DFP;
1471 break;
1472 }
1473 break;
1474 }
1475}
1476
1477static struct display_timing lcd_centering_timging(struct display_timing
1478 mode_crt_reg,
1479 struct display_timing panel_crt_reg)
1480{
1481 struct display_timing crt_reg;
1482
1483 crt_reg.hor_total = panel_crt_reg.hor_total;
1484 crt_reg.hor_addr = mode_crt_reg.hor_addr;
1485 crt_reg.hor_blank_start =
1486 (panel_crt_reg.hor_addr - mode_crt_reg.hor_addr) / 2 +
1487 crt_reg.hor_addr;
1488 crt_reg.hor_blank_end = panel_crt_reg.hor_blank_end;
1489 crt_reg.hor_sync_start =
1490 (panel_crt_reg.hor_sync_start -
1491 panel_crt_reg.hor_blank_start) + crt_reg.hor_blank_start;
1492 crt_reg.hor_sync_end = panel_crt_reg.hor_sync_end;
1493
1494 crt_reg.ver_total = panel_crt_reg.ver_total;
1495 crt_reg.ver_addr = mode_crt_reg.ver_addr;
1496 crt_reg.ver_blank_start =
1497 (panel_crt_reg.ver_addr - mode_crt_reg.ver_addr) / 2 +
1498 crt_reg.ver_addr;
1499 crt_reg.ver_blank_end = panel_crt_reg.ver_blank_end;
1500 crt_reg.ver_sync_start =
1501 (panel_crt_reg.ver_sync_start -
1502 panel_crt_reg.ver_blank_start) + crt_reg.ver_blank_start;
1503 crt_reg.ver_sync_end = panel_crt_reg.ver_sync_end;
1504
1505 return crt_reg;
1506}
1507
1508static void load_crtc_shadow_timing(struct display_timing mode_timing,
1509 struct display_timing panel_timing)
1510{
1511 struct io_register *reg = NULL;
1512 int i;
1513 int viafb_load_reg_Num = 0;
1514 int reg_value = 0;
1515
1516 if (viaparinfo->lvds_setting_info->display_method == LCD_EXPANDSION) {
1517 /* Expansion */
1518 for (i = 12; i < 20; i++) {
1519 switch (i) {
1520 case H_TOTAL_SHADOW_INDEX:
1521 reg_value =
1522 IGA2_HOR_TOTAL_SHADOW_FORMULA
1523 (panel_timing.hor_total);
1524 viafb_load_reg_Num =
1525 iga2_shadow_crtc_reg.hor_total_shadow.
1526 reg_num;
1527 reg = iga2_shadow_crtc_reg.hor_total_shadow.reg;
1528 break;
1529 case H_BLANK_END_SHADOW_INDEX:
1530 reg_value =
1531 IGA2_HOR_BLANK_END_SHADOW_FORMULA
1532 (panel_timing.hor_blank_start,
1533 panel_timing.hor_blank_end);
1534 viafb_load_reg_Num =
1535 iga2_shadow_crtc_reg.
1536 hor_blank_end_shadow.reg_num;
1537 reg =
1538 iga2_shadow_crtc_reg.
1539 hor_blank_end_shadow.reg;
1540 break;
1541 case V_TOTAL_SHADOW_INDEX:
1542 reg_value =
1543 IGA2_VER_TOTAL_SHADOW_FORMULA
1544 (panel_timing.ver_total);
1545 viafb_load_reg_Num =
1546 iga2_shadow_crtc_reg.ver_total_shadow.
1547 reg_num;
1548 reg = iga2_shadow_crtc_reg.ver_total_shadow.reg;
1549 break;
1550 case V_ADDR_SHADOW_INDEX:
1551 reg_value =
1552 IGA2_VER_ADDR_SHADOW_FORMULA
1553 (panel_timing.ver_addr);
1554 viafb_load_reg_Num =
1555 iga2_shadow_crtc_reg.ver_addr_shadow.
1556 reg_num;
1557 reg = iga2_shadow_crtc_reg.ver_addr_shadow.reg;
1558 break;
1559 case V_BLANK_SATRT_SHADOW_INDEX:
1560 reg_value =
1561 IGA2_VER_BLANK_START_SHADOW_FORMULA
1562 (panel_timing.ver_blank_start);
1563 viafb_load_reg_Num =
1564 iga2_shadow_crtc_reg.
1565 ver_blank_start_shadow.reg_num;
1566 reg =
1567 iga2_shadow_crtc_reg.
1568 ver_blank_start_shadow.reg;
1569 break;
1570 case V_BLANK_END_SHADOW_INDEX:
1571 reg_value =
1572 IGA2_VER_BLANK_END_SHADOW_FORMULA
1573 (panel_timing.ver_blank_start,
1574 panel_timing.ver_blank_end);
1575 viafb_load_reg_Num =
1576 iga2_shadow_crtc_reg.
1577 ver_blank_end_shadow.reg_num;
1578 reg =
1579 iga2_shadow_crtc_reg.
1580 ver_blank_end_shadow.reg;
1581 break;
1582 case V_SYNC_SATRT_SHADOW_INDEX:
1583 reg_value =
1584 IGA2_VER_SYNC_START_SHADOW_FORMULA
1585 (panel_timing.ver_sync_start);
1586 viafb_load_reg_Num =
1587 iga2_shadow_crtc_reg.
1588 ver_sync_start_shadow.reg_num;
1589 reg =
1590 iga2_shadow_crtc_reg.
1591 ver_sync_start_shadow.reg;
1592 break;
1593 case V_SYNC_END_SHADOW_INDEX:
1594 reg_value =
1595 IGA2_VER_SYNC_END_SHADOW_FORMULA
1596 (panel_timing.ver_sync_start,
1597 panel_timing.ver_sync_end);
1598 viafb_load_reg_Num =
1599 iga2_shadow_crtc_reg.
1600 ver_sync_end_shadow.reg_num;
1601 reg =
1602 iga2_shadow_crtc_reg.
1603 ver_sync_end_shadow.reg;
1604 break;
1605 }
1606 viafb_load_reg(reg_value,
1607 viafb_load_reg_Num, reg, VIACR);
1608 }
1609 } else { /* Centering */
1610 for (i = 12; i < 20; i++) {
1611 switch (i) {
1612 case H_TOTAL_SHADOW_INDEX:
1613 reg_value =
1614 IGA2_HOR_TOTAL_SHADOW_FORMULA
1615 (panel_timing.hor_total);
1616 viafb_load_reg_Num =
1617 iga2_shadow_crtc_reg.hor_total_shadow.
1618 reg_num;
1619 reg = iga2_shadow_crtc_reg.hor_total_shadow.reg;
1620 break;
1621 case H_BLANK_END_SHADOW_INDEX:
1622 reg_value =
1623 IGA2_HOR_BLANK_END_SHADOW_FORMULA
1624 (panel_timing.hor_blank_start,
1625 panel_timing.hor_blank_end);
1626 viafb_load_reg_Num =
1627 iga2_shadow_crtc_reg.
1628 hor_blank_end_shadow.reg_num;
1629 reg =
1630 iga2_shadow_crtc_reg.
1631 hor_blank_end_shadow.reg;
1632 break;
1633 case V_TOTAL_SHADOW_INDEX:
1634 reg_value =
1635 IGA2_VER_TOTAL_SHADOW_FORMULA
1636 (panel_timing.ver_total);
1637 viafb_load_reg_Num =
1638 iga2_shadow_crtc_reg.ver_total_shadow.
1639 reg_num;
1640 reg = iga2_shadow_crtc_reg.ver_total_shadow.reg;
1641 break;
1642 case V_ADDR_SHADOW_INDEX:
1643 reg_value =
1644 IGA2_VER_ADDR_SHADOW_FORMULA
1645 (mode_timing.ver_addr);
1646 viafb_load_reg_Num =
1647 iga2_shadow_crtc_reg.ver_addr_shadow.
1648 reg_num;
1649 reg = iga2_shadow_crtc_reg.ver_addr_shadow.reg;
1650 break;
1651 case V_BLANK_SATRT_SHADOW_INDEX:
1652 reg_value =
1653 IGA2_VER_BLANK_START_SHADOW_FORMULA
1654 (mode_timing.ver_blank_start);
1655 viafb_load_reg_Num =
1656 iga2_shadow_crtc_reg.
1657 ver_blank_start_shadow.reg_num;
1658 reg =
1659 iga2_shadow_crtc_reg.
1660 ver_blank_start_shadow.reg;
1661 break;
1662 case V_BLANK_END_SHADOW_INDEX:
1663 reg_value =
1664 IGA2_VER_BLANK_END_SHADOW_FORMULA
1665 (panel_timing.ver_blank_start,
1666 panel_timing.ver_blank_end);
1667 viafb_load_reg_Num =
1668 iga2_shadow_crtc_reg.
1669 ver_blank_end_shadow.reg_num;
1670 reg =
1671 iga2_shadow_crtc_reg.
1672 ver_blank_end_shadow.reg;
1673 break;
1674 case V_SYNC_SATRT_SHADOW_INDEX:
1675 reg_value =
1676 IGA2_VER_SYNC_START_SHADOW_FORMULA(
1677 (panel_timing.ver_sync_start -
1678 panel_timing.ver_blank_start) +
1679 (panel_timing.ver_addr -
1680 mode_timing.ver_addr) / 2 +
1681 mode_timing.ver_addr);
1682 viafb_load_reg_Num =
1683 iga2_shadow_crtc_reg.ver_sync_start_shadow.
1684 reg_num;
1685 reg =
1686 iga2_shadow_crtc_reg.ver_sync_start_shadow.
1687 reg;
1688 break;
1689 case V_SYNC_END_SHADOW_INDEX:
1690 reg_value =
1691 IGA2_VER_SYNC_END_SHADOW_FORMULA(
1692 (panel_timing.ver_sync_start -
1693 panel_timing.ver_blank_start) +
1694 (panel_timing.ver_addr -
1695 mode_timing.ver_addr) / 2 +
1696 mode_timing.ver_addr,
1697 panel_timing.ver_sync_end);
1698 viafb_load_reg_Num =
1699 iga2_shadow_crtc_reg.ver_sync_end_shadow.
1700 reg_num;
1701 reg =
1702 iga2_shadow_crtc_reg.ver_sync_end_shadow.
1703 reg;
1704 break;
1705 }
1706 viafb_load_reg(reg_value,
1707 viafb_load_reg_Num, reg, VIACR);
1708 }
1709 }
1710}
1711
1712bool viafb_lcd_get_mobile_state(bool *mobile)
1713{
1714 unsigned char *romptr, *tableptr;
1715 u8 core_base;
1716 unsigned char *biosptr;
1717 /* Rom address */
1718 u32 romaddr = 0x000C0000;
1719 u16 start_pattern = 0;
1720
1721 biosptr = ioremap(romaddr, 0x10000);
1722
1723 memcpy(&start_pattern, biosptr, 2);
1724 /* Compare pattern */
1725 if (start_pattern == 0xAA55) {
1726 /* Get the start of Table */
1727 /* 0x1B means BIOS offset position */
1728 romptr = biosptr + 0x1B;
1729 tableptr = biosptr + *((u16 *) romptr);
1730
1731 /* Get the start of biosver structure */
1732 /* 18 means BIOS version position. */
1733 romptr = tableptr + 18;
1734 romptr = biosptr + *((u16 *) romptr);
1735
1736 /* The offset should be 44, but the
1737 actual image is less three char. */
1738 /* pRom += 44; */
1739 romptr += 41;
1740
1741 core_base = *romptr++;
1742
1743 if (core_base & 0x8)
1744 *mobile = false;
1745 else
1746 *mobile = true;
1747 /* release memory */
1748 iounmap(biosptr);
1749
1750 return true;
1751 } else {
1752 iounmap(biosptr);
1753 return false;
1754 }
1755}
1756
1757static void viafb_load_scaling_factor_for_p4m900(int set_hres,
1758 int set_vres, int panel_hres, int panel_vres)
1759{
1760 int h_scaling_factor;
1761 int v_scaling_factor;
1762 u8 cra2 = 0;
1763 u8 cr77 = 0;
1764 u8 cr78 = 0;
1765 u8 cr79 = 0;
1766 u8 cr9f = 0;
1767 /* Check if expansion for horizontal */
1768 if (set_hres < panel_hres) {
1769 /* Load Horizontal Scaling Factor */
1770
1771 /* For VIA_K8M800 or later chipsets. */
1772 h_scaling_factor =
1773 K800_LCD_HOR_SCF_FORMULA(set_hres, panel_hres);
1774 /* HSCaleFactor[1:0] at CR9F[1:0] */
1775 cr9f = h_scaling_factor & 0x0003;
1776 /* HSCaleFactor[9:2] at CR77[7:0] */
1777 cr77 = (h_scaling_factor & 0x03FC) >> 2;
1778 /* HSCaleFactor[11:10] at CR79[5:4] */
1779 cr79 = (h_scaling_factor & 0x0C00) >> 10;
1780 cr79 <<= 4;
1781
1782 /* Horizontal scaling enabled */
1783 cra2 = 0xC0;
1784
1785 DEBUG_MSG(KERN_INFO "Horizontal Scaling value = %d\n",
1786 h_scaling_factor);
1787 } else {
1788 /* Horizontal scaling disabled */
1789 cra2 = 0x00;
1790 }
1791
1792 /* Check if expansion for vertical */
1793 if (set_vres < panel_vres) {
1794 /* Load Vertical Scaling Factor */
1795
1796 /* For VIA_K8M800 or later chipsets. */
1797 v_scaling_factor =
1798 K800_LCD_VER_SCF_FORMULA(set_vres, panel_vres);
1799
1800 /* Vertical scaling enabled */
1801 cra2 |= 0x08;
1802 /* VSCaleFactor[0] at CR79[3] */
1803 cr79 |= ((v_scaling_factor & 0x0001) << 3);
1804 /* VSCaleFactor[8:1] at CR78[7:0] */
1805 cr78 |= (v_scaling_factor & 0x01FE) >> 1;
1806 /* VSCaleFactor[10:9] at CR79[7:6] */
1807 cr79 |= ((v_scaling_factor & 0x0600) >> 9) << 6;
1808
1809 DEBUG_MSG(KERN_INFO "Vertical Scaling value = %d\n",
1810 v_scaling_factor);
1811 } else {
1812 /* Vertical scaling disabled */
1813 cra2 |= 0x00;
1814 }
1815
1816 viafb_write_reg_mask(CRA2, VIACR, cra2, BIT3 + BIT6 + BIT7);
1817 viafb_write_reg_mask(CR77, VIACR, cr77, 0xFF);
1818 viafb_write_reg_mask(CR78, VIACR, cr78, 0xFF);
1819 viafb_write_reg_mask(CR79, VIACR, cr79, 0xF8);
1820 viafb_write_reg_mask(CR9F, VIACR, cr9f, BIT0 + BIT1);
1821}
diff --git a/drivers/video/via/lcd.h b/drivers/video/via/lcd.h
new file mode 100644
index 000000000000..071f47cf5be1
--- /dev/null
+++ b/drivers/video/via/lcd.h
@@ -0,0 +1,94 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21#ifndef __LCD_H__
22#define __LCD_H__
23
24/*Definition TMDS Device ID register*/
25#define VT1631_DEVICE_ID_REG 0x02
26#define VT1631_DEVICE_ID 0x92
27
28#define VT3271_DEVICE_ID_REG 0x02
29#define VT3271_DEVICE_ID 0x71
30
31#define GET_LCD_SIZE_BY_SYSTEM_BIOS 0x01
32#define GET_LCD_SIZE_BY_VGA_BIOS 0x02
33#define GET_LCD_SZIE_BY_HW_STRAPPING 0x03
34#define GET_LCD_SIZE_BY_USER_SETTING 0x04
35
36/* Definition DVI Panel ID*/
37/* Resolution: 640x480, Channel: single, Dithering: Enable */
38#define LCD_PANEL_ID0_640X480 0x00
39/* Resolution: 800x600, Channel: single, Dithering: Enable */
40#define LCD_PANEL_ID1_800X600 0x01
41/* Resolution: 1024x768, Channel: single, Dithering: Enable */
42#define LCD_PANEL_ID2_1024X768 0x02
43/* Resolution: 1280x768, Channel: single, Dithering: Enable */
44#define LCD_PANEL_ID3_1280X768 0x03
45/* Resolution: 1280x1024, Channel: dual, Dithering: Enable */
46#define LCD_PANEL_ID4_1280X1024 0x04
47/* Resolution: 1400x1050, Channel: dual, Dithering: Enable */
48#define LCD_PANEL_ID5_1400X1050 0x05
49/* Resolution: 1600x1200, Channel: dual, Dithering: Enable */
50#define LCD_PANEL_ID6_1600X1200 0x06
51/* Resolution: 1366x768, Channel: single, Dithering: Disable */
52#define LCD_PANEL_ID7_1366X768 0x07
53/* Resolution: 1024x600, Channel: single, Dithering: Enable*/
54#define LCD_PANEL_ID8_1024X600 0x08
55/* Resolution: 1280x800, Channel: single, Dithering: Enable*/
56#define LCD_PANEL_ID9_1280X800 0x09
57/* Resolution: 800x480, Channel: single, Dithering: Enable*/
58#define LCD_PANEL_IDA_800X480 0x0A
59/* Resolution: 1360x768, Channel: single, Dithering: Disable*/
60#define LCD_PANEL_IDB_1360X768 0x0B
61/* Resolution: 480x640, Channel: single, Dithering: Enable */
62#define LCD_PANEL_IDC_480X640 0x0C
63
64
65extern int viafb_LCD2_ON;
66extern int viafb_LCD_ON;
67extern int viafb_DVI_ON;
68
69void viafb_disable_lvds_vt1636(struct lvds_setting_information
70 *plvds_setting_info,
71 struct lvds_chip_information *plvds_chip_info);
72void viafb_enable_lvds_vt1636(struct lvds_setting_information
73 *plvds_setting_info,
74 struct lvds_chip_information *plvds_chip_info);
75void viafb_lcd_disable(void);
76void viafb_lcd_enable(void);
77void viafb_init_lcd_size(void);
78void viafb_init_lvds_output_interface(struct lvds_chip_information
79 *plvds_chip_info,
80 struct lvds_setting_information
81 *plvds_setting_info);
82void viafb_lcd_set_mode(struct crt_mode_table *mode_crt_table,
83 struct lvds_setting_information *plvds_setting_info,
84 struct lvds_chip_information *plvds_chip_info);
85int viafb_lvds_trasmitter_identify(void);
86void viafb_init_lvds_output_interface(struct lvds_chip_information
87 *plvds_chip_info,
88 struct lvds_setting_information
89 *plvds_setting_info);
90bool viafb_lcd_get_mobile_state(bool *mobile);
91void viafb_load_crtc_timing(struct display_timing device_timing,
92 int set_iga);
93
94#endif /* __LCD_H__ */
diff --git a/drivers/video/via/lcdtbl.h b/drivers/video/via/lcdtbl.h
new file mode 100644
index 000000000000..6f3dd800be59
--- /dev/null
+++ b/drivers/video/via/lcdtbl.h
@@ -0,0 +1,591 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21#ifndef __LCDTBL_H__
22#define __LCDTBL_H__
23
24#include "share.h"
25
26/* CLE266 Software Power Sequence */
27/* {Mask}, {Data}, {Delay} */
28int PowerSequenceOn[3][3] =
29 { {0x10, 0x08, 0x06}, {0x10, 0x08, 0x06}, {0x19, 0x1FE, 0x01} };
30int PowerSequenceOff[3][3] =
31 { {0x06, 0x08, 0x10}, {0x00, 0x00, 0x00}, {0xD2, 0x19, 0x01} };
32
33/* ++++++ P880 ++++++ */
34/* Panel 1600x1200 */
35struct io_reg P880_LCD_RES_6X4_16X12[] = {
36 /*IGA2 Horizontal Total */
37 {VIACR, CR50, 0xFF, 0x73}, {VIACR, CR55, 0x0F, 0x08},
38 /*IGA2 Horizontal Blank End */
39 {VIACR, CR53, 0xFF, 0x73}, {VIACR, CR54, 0x38, 0x00},
40 {VIACR, CR5D, 0x40, 0x40},
41 /*IGA2 Horizontal Total Shadow */
42 {VIACR, CR6D, 0xFF, 0x5A}, {VIACR, CR71, 0x08, 0x00},
43 /*IGA2 Horizontal Blank End Shadow */
44 {VIACR, CR6E, 0xFF, 0x5E},
45 /*IGA2 Offset */
46 {VIACR, CR66, 0xFF, 0xD6}, {VIACR, CR67, 0x03, 0x00},
47 /*VCLK*/ {VIASR, SR44, 0xFF, 0x7D}, {VIASR, SR45, 0xFF, 0x8C},
48 {VIASR, SR46, 0xFF, 0x02}
49
50};
51
52#define NUM_TOTAL_P880_LCD_RES_6X4_16X12 ARRAY_SIZE(P880_LCD_RES_6X4_16X12)
53
54struct io_reg P880_LCD_RES_7X4_16X12[] = {
55 /*IGA2 Horizontal Total */
56 {VIACR, CR50, 0xFF, 0x67}, {VIACR, CR55, 0x0F, 0x08},
57 /*IGA2 Horizontal Blank End */
58 {VIACR, CR53, 0xFF, 0x67}, {VIACR, CR54, 0x38, 0x00},
59 {VIACR, CR5D, 0x40, 0x40},
60 /*IGA2 Horizontal Total Shadow */
61 {VIACR, CR6D, 0xFF, 0x74}, {VIACR, CR71, 0x08, 0x00},
62 /*IGA2 Horizontal Blank End Shadow */
63 {VIACR, CR6E, 0xFF, 0x78},
64 /*IGA2 Offset */
65 {VIACR, CR66, 0xFF, 0xF5}, {VIACR, CR67, 0x03, 0x00},
66 /*VCLK*/ {VIASR, SR44, 0xFF, 0x78}, {VIASR, SR45, 0xFF, 0x8C},
67 {VIASR, SR46, 0xFF, 0x01}
68
69};
70
71#define NUM_TOTAL_P880_LCD_RES_7X4_16X12 ARRAY_SIZE(P880_LCD_RES_7X4_16X12)
72
73struct io_reg P880_LCD_RES_8X6_16X12[] = {
74 /*IGA2 Horizontal Total */
75 {VIACR, CR50, 0xFF, 0x65}, {VIACR, CR55, 0x0F, 0x08},
76 /*IGA2 Horizontal Blank End */
77 {VIACR, CR53, 0xFF, 0x65}, {VIACR, CR54, 0x38, 0x00},
78 {VIACR, CR5D, 0x40, 0x40},
79 /*IGA2 Horizontal Total Shadow */
80 {VIACR, CR6D, 0xFF, 0x7F}, {VIACR, CR71, 0x08, 0x00},
81 /*IGA2 Horizontal Blank End Shadow */
82 {VIACR, CR6E, 0xFF, 0x83},
83 /*IGA2 Offset */
84 {VIACR, CR66, 0xFF, 0xE1}, {VIACR, CR67, 0x03, 0x00},
85 /*VCLK*/ {VIASR, SR44, 0xFF, 0x6D}, {VIASR, SR45, 0xFF, 0x88},
86 {VIASR, SR46, 0xFF, 0x03}
87
88};
89
90#define NUM_TOTAL_P880_LCD_RES_8X6_16X12 ARRAY_SIZE(P880_LCD_RES_8X6_16X12)
91
92struct io_reg P880_LCD_RES_10X7_16X12[] = {
93 /*IGA2 Horizontal Total */
94 {VIACR, CR50, 0xFF, 0x65}, {VIACR, CR55, 0x0F, 0x08},
95 /*IGA2 Horizontal Blank End */
96 {VIACR, CR53, 0xFF, 0x65}, {VIACR, CR54, 0x38, 0x00},
97 {VIACR, CR5D, 0x40, 0x40},
98 /*IGA2 Horizontal Total Shadow */
99 {VIACR, CR6D, 0xFF, 0xAB}, {VIACR, CR71, 0x08, 0x00},
100 /*IGA2 Horizontal Blank End Shadow */
101 {VIACR, CR6E, 0xFF, 0xAF},
102 /*IGA2 Offset */
103 {VIACR, CR66, 0xFF, 0xF0}, {VIACR, CR67, 0x03, 0x00},
104 /*VCLK*/ {VIASR, SR44, 0xFF, 0x92}, {VIASR, SR45, 0xFF, 0x88},
105 {VIASR, SR46, 0xFF, 0x03}
106
107};
108
109#define NUM_TOTAL_P880_LCD_RES_10X7_16X12 ARRAY_SIZE(P880_LCD_RES_10X7_16X12)
110
111struct io_reg P880_LCD_RES_12X10_16X12[] = {
112 /*IGA2 Horizontal Total */
113 {VIACR, CR50, 0xFF, 0x7D}, {VIACR, CR55, 0x0F, 0x08},
114 /*IGA2 Horizontal Blank End */
115 {VIACR, CR53, 0xFF, 0x7D}, {VIACR, CR54, 0x38, 0x00},
116 {VIACR, CR5D, 0x40, 0x40},
117 /*IGA2 Horizontal Total Shadow */
118 {VIACR, CR6D, 0xFF, 0xD0}, {VIACR, CR71, 0x08, 0x00},
119 /*IGA2 Horizontal Blank End Shadow */
120 {VIACR, CR6E, 0xFF, 0xD4},
121 /*IGA2 Offset */
122 {VIACR, CR66, 0xFF, 0xFA}, {VIACR, CR67, 0x03, 0x00},
123 /*VCLK*/ {VIASR, SR44, 0xFF, 0xF6}, {VIASR, SR45, 0xFF, 0x88},
124 {VIASR, SR46, 0xFF, 0x05}
125
126};
127
128#define NUM_TOTAL_P880_LCD_RES_12X10_16X12 ARRAY_SIZE(P880_LCD_RES_12X10_16X12)
129
130/* Panel 1400x1050 */
131struct io_reg P880_LCD_RES_6X4_14X10[] = {
132 /* 640x480 */
133 /* IGA2 Horizontal Total */
134 {VIACR, CR50, 0xFF, 0x9D}, {VIACR, CR55, 0x0F, 0x56},
135 /* IGA2 Horizontal Blank End */
136 {VIACR, CR53, 0xFF, 0x9D}, {VIACR, CR54, 0x38, 0x75},
137 {VIACR, CR5D, 0x40, 0x24},
138 /* IGA2 Horizontal Total Shadow */
139 {VIACR, CR6D, 0xFF, 0x5F}, {VIACR, CR71, 0x08, 0x44},
140 /* IGA2 Horizontal Blank End Shadow */
141 {VIACR, CR6E, 0xFF, 0x63},
142 /* IGA2 Offset */
143 {VIACR, CR66, 0xFF, 0xB4}, {VIACR, CR67, 0x03, 0x00},
144 /* VCLK */
145 {VIASR, SR44, 0xFF, 0xC6}, {VIASR, SR45, 0xFF, 0x8C},
146 {VIASR, SR46, 0xFF, 0x05}
147};
148
149#define NUM_TOTAL_P880_LCD_RES_6X4_14X10 ARRAY_SIZE(P880_LCD_RES_6X4_14X10)
150
151struct io_reg P880_LCD_RES_8X6_14X10[] = {
152 /* 800x600 */
153 /* IGA2 Horizontal Total */
154 {VIACR, CR50, 0xFF, 0x9D}, {VIACR, CR55, 0x0F, 0x56},
155 /* IGA2 Horizontal Blank End */
156 {VIACR, CR53, 0xFF, 0x9D}, {VIACR, CR54, 0x38, 0x75},
157 {VIACR, CR5D, 0x40, 0x24},
158 /* IGA2 Horizontal Total Shadow */
159 {VIACR, CR6D, 0xFF, 0x7F}, {VIACR, CR71, 0x08, 0x44},
160 /* IGA2 Horizontal Blank End Shadow */
161 {VIACR, CR6E, 0xFF, 0x83},
162 /* IGA2 Offset */
163 {VIACR, CR66, 0xFF, 0xBE}, {VIACR, CR67, 0x03, 0x00},
164 /* VCLK */
165 {VIASR, SR44, 0xFF, 0x06}, {VIASR, SR45, 0xFF, 0x8D},
166 {VIASR, SR46, 0xFF, 0x05}
167};
168
169#define NUM_TOTAL_P880_LCD_RES_8X6_14X10 ARRAY_SIZE(P880_LCD_RES_8X6_14X10)
170
171/* ++++++ K400 ++++++ */
172/* Panel 1600x1200 */
173struct io_reg K400_LCD_RES_6X4_16X12[] = {
174 /*IGA2 Horizontal Total */
175 {VIACR, CR50, 0xFF, 0x73}, {VIACR, CR55, 0x0F, 0x08},
176 /*IGA2 Horizontal Blank End */
177 {VIACR, CR53, 0xFF, 0x73}, {VIACR, CR54, 0x38, 0x00},
178 {VIACR, CR5D, 0x40, 0x40},
179 /*IGA2 Horizontal Total Shadow */
180 {VIACR, CR6D, 0xFF, 0x5A}, {VIACR, CR71, 0x08, 0x00},
181 /*IGA2 Horizontal Blank End Shadow */
182 {VIACR, CR6E, 0xFF, 0x5E},
183 /*IGA2 Offset */
184 {VIACR, CR66, 0xFF, 0xDA}, {VIACR, CR67, 0x03, 0x00},
185 /*VCLK*/ {VIASR, SR46, 0xFF, 0xC4}, {VIASR, SR47, 0xFF, 0x7F}
186};
187
188#define NUM_TOTAL_K400_LCD_RES_6X4_16X12 ARRAY_SIZE(K400_LCD_RES_6X4_16X12)
189
190struct io_reg K400_LCD_RES_7X4_16X12[] = {
191 /*IGA2 Horizontal Total */
192 {VIACR, CR50, 0xFF, 0x67}, {VIACR, CR55, 0x0F, 0x08},
193 /*IGA2 Horizontal Blank End */
194 {VIACR, CR53, 0xFF, 0x67}, {VIACR, CR54, 0x38, 0x00},
195 {VIACR, CR5D, 0x40, 0x40},
196 /*IGA2 Horizontal Total Shadow */
197 {VIACR, CR6D, 0xFF, 0x74}, {VIACR, CR71, 0x08, 0x00},
198 /*IGA2 Horizontal Blank End Shadow */
199 {VIACR, CR6E, 0xFF, 0x78},
200 /*IGA2 Offset */
201 {VIACR, CR66, 0xFF, 0xF5}, {VIACR, CR67, 0x03, 0x00},
202 /*VCLK*/ {VIASR, SR46, 0xFF, 0x46}, {VIASR, SR47, 0xFF, 0x3D}
203};
204
205#define NUM_TOTAL_K400_LCD_RES_7X4_16X12 ARRAY_SIZE(K400_LCD_RES_7X4_16X12)
206
207struct io_reg K400_LCD_RES_8X6_16X12[] = {
208 /*IGA2 Horizontal Total */
209 {VIACR, CR50, 0xFF, 0x65}, {VIACR, CR55, 0x0F, 0x08},
210 /*IGA2 Horizontal Blank End */
211 {VIACR, CR53, 0xFF, 0x65}, {VIACR, CR54, 0x38, 0x00},
212 {VIACR, CR5D, 0x40, 0x40},
213 /*IGA2 Horizontal Total Shadow */
214 {VIACR, CR6D, 0xFF, 0x7F}, {VIACR, CR71, 0x08, 0x00},
215 /*IGA2 Horizontal Blank End Shadow */
216 {VIACR, CR6E, 0xFF, 0x83},
217 /*IGA2 Offset */
218 {VIACR, CR66, 0xFF, 0xE1}, {VIACR, CR67, 0x03, 0x00},
219 /*VCLK*/ {VIASR, SR46, 0xFF, 0x85}, {VIASR, SR47, 0xFF, 0x6F}
220};
221
222#define NUM_TOTAL_K400_LCD_RES_8X6_16X12 ARRAY_SIZE(K400_LCD_RES_8X6_16X12)
223
224struct io_reg K400_LCD_RES_10X7_16X12[] = {
225 /*IGA2 Horizontal Total */
226 {VIACR, CR50, 0xFF, 0x65}, {VIACR, CR55, 0x0F, 0x08},
227 /*IGA2 Horizontal Blank End */
228 {VIACR, CR53, 0xFF, 0x65}, {VIACR, CR54, 0x38, 0x00},
229 {VIACR, CR5D, 0x40, 0x40},
230 /*IGA2 Horizontal Total Shadow */
231 {VIACR, CR6D, 0xFF, 0xAB}, {VIACR, CR71, 0x08, 0x00},
232 /*IGA2 Horizontal Blank End Shadow */
233 {VIACR, CR6E, 0xFF, 0xAF},
234 /*IGA2 Offset */
235 {VIACR, CR66, 0xFF, 0xF0}, {VIACR, CR67, 0x03, 0x00},
236 /*VCLK*/ {VIASR, SR46, 0xFF, 0x45}, {VIASR, SR47, 0xFF, 0x4A}
237};
238
239#define NUM_TOTAL_K400_LCD_RES_10X7_16X12 ARRAY_SIZE(K400_LCD_RES_10X7_16X12)
240
241struct io_reg K400_LCD_RES_12X10_16X12[] = {
242 /*IGA2 Horizontal Total */
243 {VIACR, CR50, 0xFF, 0x7D}, {VIACR, CR55, 0x0F, 0x08},
244 /*IGA2 Horizontal Blank End */
245 {VIACR, CR53, 0xFF, 0x7D}, {VIACR, CR54, 0x38, 0x00},
246 {VIACR, CR5D, 0x40, 0x40},
247 /*IGA2 Horizontal Total Shadow */
248 {VIACR, CR6D, 0xFF, 0xD0}, {VIACR, CR71, 0x08, 0x00},
249 /*IGA2 Horizontal Blank End Shadow */
250 {VIACR, CR6E, 0xFF, 0xD4},
251 /*IGA2 Offset */
252 {VIACR, CR66, 0xFF, 0xFA}, {VIACR, CR67, 0x03, 0x00},
253 /*VCLK*/ {VIASR, SR46, 0xFF, 0x47}, {VIASR, SR47, 0xFF, 0x7C}
254};
255
256#define NUM_TOTAL_K400_LCD_RES_12X10_16X12 ARRAY_SIZE(K400_LCD_RES_12X10_16X12)
257
258/* Panel 1400x1050 */
259struct io_reg K400_LCD_RES_6X4_14X10[] = {
260 /* 640x400 */
261 /* IGA2 Horizontal Total */
262 {VIACR, CR50, 0xFF, 0x9D}, {VIACR, CR55, 0x0F, 0x56},
263 /* IGA2 Horizontal Blank End */
264 {VIACR, CR53, 0xFF, 0x9D}, {VIACR, CR54, 0x38, 0x75},
265 {VIACR, CR5D, 0x40, 0x24},
266 /* IGA2 Horizontal Total Shadow */
267 {VIACR, CR6D, 0xFF, 0x5F}, {VIACR, CR71, 0x08, 0x44},
268 /* IGA2 Horizontal Blank End Shadow */
269 {VIACR, CR6E, 0xFF, 0x63},
270 /* IGA2 Offset */
271 {VIACR, CR66, 0xFF, 0xB4}, {VIACR, CR67, 0x03, 0x00},
272 /* VCLK */
273 {VIASR, SR46, 0xFF, 0x07}, {VIASR, SR47, 0xFF, 0x19}
274};
275
276#define NUM_TOTAL_K400_LCD_RES_6X4_14X10 ARRAY_SIZE(K400_LCD_RES_6X4_14X10)
277
278struct io_reg K400_LCD_RES_8X6_14X10[] = {
279 /* 800x600 */
280 /* IGA2 Horizontal Total */
281 {VIACR, CR50, 0xFF, 0x9D}, {VIACR, CR55, 0x0F, 0x56},
282 /* IGA2 Horizontal Blank End */
283 {VIACR, CR53, 0xFF, 0x9D}, {VIACR, CR54, 0x38, 0x75},
284 {VIACR, CR5D, 0x40, 0x24},
285 /* IGA2 Horizontal Total Shadow */
286 {VIACR, CR6D, 0xFF, 0x7F}, {VIACR, CR71, 0x08, 0x44},
287 /* IGA2 Horizontal Blank End Shadow */
288 {VIACR, CR6E, 0xFF, 0x83},
289 /* IGA2 Offset */
290 {VIACR, CR66, 0xFF, 0xBE}, {VIACR, CR67, 0x03, 0x00},
291 /* VCLK */
292 {VIASR, SR46, 0xFF, 0x07}, {VIASR, SR47, 0xFF, 0x21}
293};
294
295#define NUM_TOTAL_K400_LCD_RES_8X6_14X10 ARRAY_SIZE(K400_LCD_RES_8X6_14X10)
296
297struct io_reg K400_LCD_RES_10X7_14X10[] = {
298 /* 1024x768 */
299 /* IGA2 Horizontal Total */
300 {VIACR, CR50, 0xFF, 0x9D}, {VIACR, CR55, 0x0F, 0x56},
301 /* IGA2 Horizontal Blank End */
302 {VIACR, CR53, 0xFF, 0x9D}, {VIACR, CR54, 0x38, 0x75},
303 {VIACR, CR5D, 0x40, 0x24},
304 /* IGA2 Horizontal Total Shadow */
305 {VIACR, CR6D, 0xFF, 0xA3}, {VIACR, CR71, 0x08, 0x44},
306 /* IGA2 Horizontal Blank End Shadow */
307 {VIACR, CR6E, 0xFF, 0xA7},
308 /* IGA2 Offset */
309 {VIACR, CR66, 0xFF, 0xC3}, {VIACR, CR67, 0x03, 0x04},
310 /* VCLK */
311 {VIASR, SR46, 0xFF, 0x05}, {VIASR, SR47, 0xFF, 0x1E}
312};
313
314#define NUM_TOTAL_K400_LCD_RES_10X7_14X10 ARRAY_SIZE(K400_LCD_RES_10X7_14X10)
315
316struct io_reg K400_LCD_RES_12X10_14X10[] = {
317 /* 1280x768, 1280x960, 1280x1024 */
318 /* IGA2 Horizontal Total */
319 {VIACR, CR50, 0xFF, 0x97}, {VIACR, CR55, 0x0F, 0x56},
320 /* IGA2 Horizontal Blank End */
321 {VIACR, CR53, 0xFF, 0x97}, {VIACR, CR54, 0x38, 0x75},
322 {VIACR, CR5D, 0x40, 0x24},
323 /* IGA2 Horizontal Total Shadow */
324 {VIACR, CR6D, 0xFF, 0xCE}, {VIACR, CR71, 0x08, 0x44},
325 /* IGA2 Horizontal Blank End Shadow */
326 {VIACR, CR6E, 0xFF, 0xD2},
327 /* IGA2 Offset */
328 {VIACR, CR66, 0xFF, 0xC9}, {VIACR, CR67, 0x03, 0x04},
329 /* VCLK */
330 {VIASR, SR46, 0xFF, 0x84}, {VIASR, SR47, 0xFF, 0x79}
331};
332
333#define NUM_TOTAL_K400_LCD_RES_12X10_14X10 ARRAY_SIZE(K400_LCD_RES_12X10_14X10)
334
335/* ++++++ K400 ++++++ */
336/* Panel 1366x768 */
337struct io_reg K400_LCD_RES_6X4_1366X7[] = {
338 /* 640x400 */
339 /* IGA2 Horizontal Total */
340 {VIACR, CR50, 0xFF, 0x47}, {VIACR, CR55, 0x0F, 0x35},
341 /* IGA2 Horizontal Blank End */
342 {VIACR, CR53, 0xFF, 0x47}, {VIACR, CR54, 0x38, 0x2B},
343 {VIACR, CR5D, 0x40, 0x13},
344 /* IGA2 Horizontal Total Shadow */
345 {VIACR, CR6D, 0xFF, 0x60}, {VIACR, CR71, 0x08, 0x23},
346 /* IGA2 Horizontal Blank End Shadow */
347 {VIACR, CR6E, 0xFF, 0x64},
348 /* IGA2 Offset */
349 {VIACR, CR66, 0xFF, 0x8C}, {VIACR, CR67, 0x03, 0x00},
350 /* VCLK */
351 {VIASR, SR46, 0xFF, 0x87}, {VIASR, SR47, 0xFF, 0x4C}
352};
353
354#define NUM_TOTAL_K400_LCD_RES_6X4_1366X7 ARRAY_SIZE(K400_LCD_RES_6X4_1366X7)
355
356struct io_reg K400_LCD_RES_7X4_1366X7[] = {
357 /* IGA2 Horizontal Total */
358 {VIACR, CR50, 0xFF, 0x3B}, {VIACR, CR55, 0x0F, 0x35},
359 /* IGA2 Horizontal Blank End */
360 {VIACR, CR53, 0xFF, 0x3B}, {VIACR, CR54, 0x38, 0x2B},
361 {VIACR, CR5D, 0x40, 0x13},
362 /* IGA2 Horizontal Total Shadow */
363 {VIACR, CR6D, 0xFF, 0x71}, {VIACR, CR71, 0x08, 0x23},
364 /* IGA2 Horizontal Blank End Shadow */
365 {VIACR, CR6E, 0xFF, 0x75},
366 /* IGA2 Offset */
367 {VIACR, CR66, 0xFF, 0x96}, {VIACR, CR67, 0x03, 0x00},
368 /* VCLK */
369 {VIASR, SR46, 0xFF, 0x05}, {VIASR, SR47, 0xFF, 0x10}
370};
371
372#define NUM_TOTAL_K400_LCD_RES_7X4_1366X7 ARRAY_SIZE(K400_LCD_RES_7X4_1366X7)
373
374struct io_reg K400_LCD_RES_8X6_1366X7[] = {
375 /* 800x600 */
376 /* IGA2 Horizontal Total */
377 {VIACR, CR50, 0xFF, 0x37}, {VIACR, CR55, 0x0F, 0x35},
378 /* IGA2 Horizontal Blank End */
379 {VIACR, CR53, 0xFF, 0x37}, {VIACR, CR54, 0x38, 0x2B},
380 {VIACR, CR5D, 0x40, 0x13},
381 /* IGA2 Horizontal Total Shadow */
382 {VIACR, CR6D, 0xFF, 0x7E}, {VIACR, CR71, 0x08, 0x23},
383 /* IGA2 Horizontal Blank End Shadow */
384 {VIACR, CR6E, 0xFF, 0x82},
385 /* IGA2 Offset */
386 {VIACR, CR66, 0xFF, 0x8C}, {VIACR, CR67, 0x03, 0x00},
387 /* VCLK */
388 {VIASR, SR46, 0xFF, 0x84}, {VIASR, SR47, 0xFF, 0xB9}
389};
390
391#define NUM_TOTAL_K400_LCD_RES_8X6_1366X7 ARRAY_SIZE(K400_LCD_RES_8X6_1366X7)
392
393struct io_reg K400_LCD_RES_10X7_1366X7[] = {
394 /* 1024x768 */
395 /* IGA2 Horizontal Total */
396 {VIACR, CR50, 0xFF, 0x9D}, {VIACR, CR55, 0x0F, 0x56},
397 /* IGA2 Horizontal Blank End */
398 {VIACR, CR53, 0xFF, 0x9D}, {VIACR, CR54, 0x38, 0x75},
399 {VIACR, CR5D, 0x40, 0x24},
400 /* IGA2 Horizontal Total Shadow */
401 {VIACR, CR6D, 0xFF, 0xA3}, {VIACR, CR71, 0x08, 0x44},
402 /* IGA2 Horizontal Blank End Shadow */
403 {VIACR, CR6E, 0xFF, 0xA7},
404 /* IGA2 Offset */
405 {VIACR, CR66, 0xFF, 0xC3}, {VIACR, CR67, 0x03, 0x04},
406 /* VCLK */
407 {VIASR, SR46, 0xFF, 0x05}, {VIASR, SR47, 0xFF, 0x1E}
408};
409
410#define NUM_TOTAL_K400_LCD_RES_10X7_1366X7 ARRAY_SIZE(K400_LCD_RES_10X7_1366X7)
411
412struct io_reg K400_LCD_RES_12X10_1366X7[] = {
413 /* 1280x768, 1280x960, 1280x1024 */
414 /* IGA2 Horizontal Total */
415 {VIACR, CR50, 0xFF, 0x97}, {VIACR, CR55, 0x0F, 0x56},
416 /* IGA2 Horizontal Blank End */
417 {VIACR, CR53, 0xFF, 0x97}, {VIACR, CR54, 0x38, 0x75},
418 {VIACR, CR5D, 0x40, 0x24},
419 /* IGA2 Horizontal Total Shadow */
420 {VIACR, CR6D, 0xFF, 0xCE}, {VIACR, CR71, 0x08, 0x44},
421 /* IGA2 Horizontal Blank End Shadow */
422 {VIACR, CR6E, 0xFF, 0xD2},
423 /* IGA2 Offset */
424 {VIACR, CR66, 0xFF, 0xC9}, {VIACR, CR67, 0x03, 0x04},
425 /* VCLK */
426 {VIASR, SR46, 0xFF, 0x84}, {VIASR, SR47, 0xFF, 0x79}
427};
428
429#define NUM_TOTAL_K400_LCD_RES_12X10_1366X7\
430 ARRAY_SIZE(K400_LCD_RES_12X10_1366X7)
431
432/* ++++++ K400 ++++++ */
433/* Panel 1280x1024 */
434struct io_reg K400_LCD_RES_6X4_12X10[] = {
435 /*IGA2 Horizontal Total */
436 {VIACR, CR50, 0xFF, 0x9D}, {VIACR, CR55, 0x0F, 0x46},
437 /*IGA2 Horizontal Blank End */
438 {VIACR, CR53, 0xFF, 0x9D}, {VIACR, CR54, 0x38, 0x74},
439 {VIACR, CR5D, 0x40, 0x1C},
440 /*IGA2 Horizontal Total Shadow */
441 {VIACR, CR6D, 0xFF, 0x5F}, {VIACR, CR71, 0x08, 0x34},
442 /*IGA2 Horizontal Blank End Shadow */
443 {VIACR, CR6E, 0xFF, 0x63},
444 /*IGA2 Offset */
445 {VIACR, CR66, 0xFF, 0xAA}, {VIACR, CR67, 0x03, 0x00},
446 /*VCLK*/ {VIASR, SR46, 0xFF, 0x07}, {VIASR, SR47, 0xFF, 0x19}
447};
448
449#define NUM_TOTAL_K400_LCD_RES_6X4_12X10 ARRAY_SIZE(K400_LCD_RES_6X4_12X10)
450
451struct io_reg K400_LCD_RES_7X4_12X10[] = {
452 /*IGA2 Horizontal Total */
453 {VIACR, CR50, 0xFF, 0x9D}, {VIACR, CR55, 0x0F, 0x46},
454 /*IGA2 Horizontal Blank End */
455 {VIACR, CR53, 0xFF, 0x9D}, {VIACR, CR54, 0x38, 0x74},
456 {VIACR, CR5D, 0x40, 0x1C},
457 /*IGA2 Horizontal Total Shadow */
458 {VIACR, CR6D, 0xFF, 0x68}, {VIACR, CR71, 0x08, 0x34},
459 /*IGA2 Horizontal Blank End Shadow */
460 {VIACR, CR6E, 0xFF, 0x6C},
461 /*IGA2 Offset */
462 {VIACR, CR66, 0xFF, 0xA8}, {VIACR, CR67, 0x03, 0x00},
463 /*VCLK*/ {VIASR, SR46, 0xFF, 0x87}, {VIASR, SR47, 0xFF, 0xED}
464};
465
466#define NUM_TOTAL_K400_LCD_RES_7X4_12X10 ARRAY_SIZE(K400_LCD_RES_7X4_12X10)
467
468struct io_reg K400_LCD_RES_8X6_12X10[] = {
469 /*IGA2 Horizontal Total */
470 {VIACR, CR50, 0xFF, 0x9D}, {VIACR, CR55, 0x0F, 0x46},
471 /*IGA2 Horizontal Blank End */
472 {VIACR, CR53, 0xFF, 0x9D}, {VIACR, CR54, 0x38, 0x74},
473 {VIACR, CR5D, 0x40, 0x1C},
474 /*IGA2 Horizontal Total Shadow */
475 {VIACR, CR6D, 0xFF, 0x7F}, {VIACR, CR71, 0x08, 0x34},
476 /*IGA2 Horizontal Blank End Shadow */
477 {VIACR, CR6E, 0xFF, 0x83},
478 /*IGA2 Offset */
479 {VIACR, CR66, 0xFF, 0xBE}, {VIACR, CR67, 0x03, 0x00},
480 /*VCLK*/ {VIASR, SR46, 0xFF, 0x07}, {VIASR, SR47, 0xFF, 0x21}
481};
482
483#define NUM_TOTAL_K400_LCD_RES_8X6_12X10 ARRAY_SIZE(K400_LCD_RES_8X6_12X10)
484
485struct io_reg K400_LCD_RES_10X7_12X10[] = {
486 /*IGA2 Horizontal Total */
487 {VIACR, CR50, 0xFF, 0x9D}, {VIACR, CR55, 0x0F, 0x46},
488 /*IGA2 Horizontal Blank End */
489 {VIACR, CR53, 0xFF, 0x9D}, {VIACR, CR54, 0x38, 0x74},
490 {VIACR, CR5D, 0x40, 0x1C},
491 /*IGA2 Horizontal Total Shadow */
492 {VIACR, CR6D, 0xFF, 0xA3}, {VIACR, CR71, 0x08, 0x34},
493 /*IGA2 Horizontal Blank End Shadow */
494 {VIACR, CR6E, 0xFF, 0xA7},
495 /*IGA2 Offset */
496 {VIACR, CR66, 0xFF, 0xBE}, {VIACR, CR67, 0x03, 0x04},
497 /*VCLK*/ {VIASR, SR46, 0xFF, 0x05}, {VIASR, SR47, 0xFF, 0x1E}
498};
499
500#define NUM_TOTAL_K400_LCD_RES_10X7_12X10 ARRAY_SIZE(K400_LCD_RES_10X7_12X10)
501
502/* ++++++ K400 ++++++ */
503/* Panel 1024x768 */
504struct io_reg K400_LCD_RES_6X4_10X7[] = {
505 /*IGA2 Horizontal Total */
506 {VIACR, CR50, 0xFF, 0x47}, {VIACR, CR55, 0x0F, 0x35},
507 /*IGA2 Horizontal Blank End */
508 {VIACR, CR53, 0xFF, 0x47}, {VIACR, CR54, 0x38, 0x2B},
509 {VIACR, CR5D, 0x40, 0x13},
510 /*IGA2 Horizontal Total Shadow */
511 {VIACR, CR6D, 0xFF, 0x60}, {VIACR, CR71, 0x08, 0x23},
512 /*IGA2 Horizontal Blank End Shadow */
513 {VIACR, CR6E, 0xFF, 0x64},
514 /*IGA2 Offset */
515 {VIACR, CR66, 0xFF, 0x8C}, {VIACR, CR67, 0x03, 0x00},
516 /*VCLK*/ {VIASR, SR46, 0xFF, 0x87}, {VIASR, SR47, 0xFF, 0x4C}
517};
518
519#define NUM_TOTAL_K400_LCD_RES_6X4_10X7 ARRAY_SIZE(K400_LCD_RES_6X4_10X7)
520
521struct io_reg K400_LCD_RES_7X4_10X7[] = {
522 /*IGA2 Horizontal Total */
523 {VIACR, CR50, 0xFF, 0x3B}, {VIACR, CR55, 0x0F, 0x35},
524 /*IGA2 Horizontal Blank End */
525 {VIACR, CR53, 0xFF, 0x3B}, {VIACR, CR54, 0x38, 0x2B},
526 {VIACR, CR5D, 0x40, 0x13},
527 /*IGA2 Horizontal Total Shadow */
528 {VIACR, CR6D, 0xFF, 0x71}, {VIACR, CR71, 0x08, 0x23},
529 /*IGA2 Horizontal Blank End Shadow */
530 {VIACR, CR6E, 0xFF, 0x75},
531 /*IGA2 Offset */
532 {VIACR, CR66, 0xFF, 0x96}, {VIACR, CR67, 0x03, 0x00},
533 /*VCLK*/ {VIASR, SR46, 0xFF, 0x05}, {VIASR, SR47, 0xFF, 0x10}
534};
535
536#define NUM_TOTAL_K400_LCD_RES_7X4_10X7 ARRAY_SIZE(K400_LCD_RES_7X4_10X7)
537
538struct io_reg K400_LCD_RES_8X6_10X7[] = {
539 /*IGA2 Horizontal Total */
540 {VIACR, CR50, 0xFF, 0x37}, {VIACR, CR55, 0x0F, 0x35},
541 /*IGA2 Horizontal Blank End */
542 {VIACR, CR53, 0xFF, 0x37}, {VIACR, CR54, 0x38, 0x2B},
543 {VIACR, CR5D, 0x40, 0x13},
544 /*IGA2 Horizontal Total Shadow */
545 {VIACR, CR6D, 0xFF, 0x7E}, {VIACR, CR71, 0x08, 0x23},
546 /*IGA2 Horizontal Blank End Shadow */
547 {VIACR, CR6E, 0xFF, 0x82},
548 /*IGA2 Offset */
549 {VIACR, CR66, 0xFF, 0x8C}, {VIACR, CR67, 0x03, 0x00},
550 /*VCLK*/ {VIASR, SR46, 0xFF, 0x84}, {VIASR, SR47, 0xFF, 0xB9}
551};
552
553#define NUM_TOTAL_K400_LCD_RES_8X6_10X7 ARRAY_SIZE(K400_LCD_RES_8X6_10X7)
554
555/* ++++++ K400 ++++++ */
556/* Panel 800x600 */
557struct io_reg K400_LCD_RES_6X4_8X6[] = {
558 /*IGA2 Horizontal Total */
559 {VIACR, CR50, 0xFF, 0x1A}, {VIACR, CR55, 0x0F, 0x34},
560 /*IGA2 Horizontal Blank End */
561 {VIACR, CR53, 0xFF, 0x1A}, {VIACR, CR54, 0x38, 0xE3},
562 {VIACR, CR5D, 0x40, 0x12},
563 /*IGA2 Horizontal Total Shadow */
564 {VIACR, CR6D, 0xFF, 0x5F}, {VIACR, CR71, 0x08, 0x22},
565 /*IGA2 Horizontal Blank End Shadow */
566 {VIACR, CR6E, 0xFF, 0x63},
567 /*IGA2 Offset */
568 {VIACR, CR66, 0xFF, 0x6E}, {VIACR, CR67, 0x03, 0x00},
569 /*VCLK*/ {VIASR, SR46, 0xFF, 0x86}, {VIASR, SR47, 0xFF, 0xB3}
570};
571
572#define NUM_TOTAL_K400_LCD_RES_6X4_8X6 ARRAY_SIZE(K400_LCD_RES_6X4_8X6)
573
574struct io_reg K400_LCD_RES_7X4_8X6[] = {
575 /*IGA2 Horizontal Total */
576 {VIACR, CR50, 0xFF, 0x1F}, {VIACR, CR55, 0x0F, 0x34},
577 /*IGA2 Horizontal Blank End */
578 {VIACR, CR53, 0xFF, 0x1F}, {VIACR, CR54, 0x38, 0xE3},
579 {VIACR, CR5D, 0x40, 0x12},
580 /*IGA2 Horizontal Total Shadow */
581 {VIACR, CR6D, 0xFF, 0x7F}, {VIACR, CR71, 0x08, 0x22},
582 /*IGA2 Horizontal Blank End Shadow */
583 {VIACR, CR6E, 0xFF, 0x83},
584 /*IGA2 Offset */
585 {VIACR, CR66, 0xFF, 0x78}, {VIACR, CR67, 0x03, 0x00},
586 /*VCLK*/ {VIASR, SR46, 0xFF, 0xC4}, {VIASR, SR47, 0xFF, 0x59}
587};
588
589#define NUM_TOTAL_K400_LCD_RES_7X4_8X6 ARRAY_SIZE(K400_LCD_RES_7X4_8X6)
590
591#endif /* __LCDTBL_H__ */
diff --git a/drivers/video/via/share.h b/drivers/video/via/share.h
new file mode 100644
index 000000000000..2e1254da9c8c
--- /dev/null
+++ b/drivers/video/via/share.h
@@ -0,0 +1,1105 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#ifndef __SHARE_H__
23#define __SHARE_H__
24
25/* Define Return Value */
26#define FAIL -1
27#define OK 1
28
29#ifndef NULL
30#define NULL 0
31#endif
32
33/* Define Bit Field */
34#define BIT0 0x01
35#define BIT1 0x02
36#define BIT2 0x04
37#define BIT3 0x08
38#define BIT4 0x10
39#define BIT5 0x20
40#define BIT6 0x40
41#define BIT7 0x80
42
43/* Video Memory Size */
44#define VIDEO_MEMORY_SIZE_16M 0x1000000
45
46/* Definition Mode Index
47*/
48#define VIA_RES_640X480 0
49#define VIA_RES_800X600 1
50#define VIA_RES_1024X768 2
51#define VIA_RES_1152X864 3
52#define VIA_RES_1280X1024 4
53#define VIA_RES_1600X1200 5
54#define VIA_RES_1440X1050 6
55#define VIA_RES_1280X768 7
56#define VIA_RES_1280X960 8
57#define VIA_RES_1920X1440 9
58#define VIA_RES_848X480 10
59#define VIA_RES_1400X1050 11
60#define VIA_RES_720X480 12
61#define VIA_RES_720X576 13
62#define VIA_RES_1024X512 14
63#define VIA_RES_856X480 15
64#define VIA_RES_1024X576 16
65#define VIA_RES_640X400 17
66#define VIA_RES_1280X720 18
67#define VIA_RES_1920X1080 19
68#define VIA_RES_800X480 20
69#define VIA_RES_1368X768 21
70#define VIA_RES_1024X600 22
71#define VIA_RES_1280X800 23
72#define VIA_RES_1680X1050 24
73#define VIA_RES_960X600 25
74#define VIA_RES_1000X600 26
75#define VIA_RES_1088X612 27
76#define VIA_RES_1152X720 28
77#define VIA_RES_1200X720 29
78#define VIA_RES_1280X600 30
79#define VIA_RES_1360X768 31
80#define VIA_RES_1366X768 32
81#define VIA_RES_1440X900 33
82#define VIA_RES_1600X900 34
83#define VIA_RES_1600X1024 35
84#define VIA_RES_1792X1344 36
85#define VIA_RES_1856X1392 37
86#define VIA_RES_1920X1200 38
87#define VIA_RES_2048X1536 39
88#define VIA_RES_480X640 40
89
90/*Reduce Blanking*/
91#define VIA_RES_1360X768_RB 131
92#define VIA_RES_1440X900_RB 133
93#define VIA_RES_1400X1050_RB 111
94#define VIA_RES_1600X900_RB 134
95#define VIA_RES_1680X1050_RB 124
96#define VIA_RES_1920X1080_RB 119
97#define VIA_RES_1920X1200_RB 138
98
99#define VIA_RES_INVALID 255
100
101/* standard VGA IO port
102*/
103#define VIARMisc 0x3CC
104#define VIAWMisc 0x3C2
105#define VIAStatus 0x3DA
106#define VIACR 0x3D4
107#define VIASR 0x3C4
108#define VIAGR 0x3CE
109#define VIAAR 0x3C0
110
111#define StdCR 0x19
112#define StdSR 0x04
113#define StdGR 0x09
114#define StdAR 0x14
115
116#define PatchCR 11
117
118/* Display path */
119#define IGA1 1
120#define IGA2 2
121#define IGA1_IGA2 3
122
123/* Define Color Depth */
124#define MODE_8BPP 1
125#define MODE_16BPP 2
126#define MODE_32BPP 4
127
128#define GR20 0x20
129#define GR21 0x21
130#define GR22 0x22
131
132/* Sequencer Registers */
133#define SR01 0x01
134#define SR10 0x10
135#define SR12 0x12
136#define SR15 0x15
137#define SR16 0x16
138#define SR17 0x17
139#define SR18 0x18
140#define SR1B 0x1B
141#define SR1A 0x1A
142#define SR1C 0x1C
143#define SR1D 0x1D
144#define SR1E 0x1E
145#define SR1F 0x1F
146#define SR20 0x20
147#define SR21 0x21
148#define SR22 0x22
149#define SR2A 0x2A
150#define SR2D 0x2D
151#define SR2E 0x2E
152
153#define SR30 0x30
154#define SR39 0x39
155#define SR3D 0x3D
156#define SR3E 0x3E
157#define SR3F 0x3F
158#define SR40 0x40
159#define SR43 0x43
160#define SR44 0x44
161#define SR45 0x45
162#define SR46 0x46
163#define SR47 0x47
164#define SR48 0x48
165#define SR49 0x49
166#define SR4A 0x4A
167#define SR4B 0x4B
168#define SR4C 0x4C
169#define SR52 0x52
170#define SR5E 0x5E
171#define SR65 0x65
172
173/* CRT Controller Registers */
174#define CR00 0x00
175#define CR01 0x01
176#define CR02 0x02
177#define CR03 0x03
178#define CR04 0x04
179#define CR05 0x05
180#define CR06 0x06
181#define CR07 0x07
182#define CR08 0x08
183#define CR09 0x09
184#define CR0A 0x0A
185#define CR0B 0x0B
186#define CR0C 0x0C
187#define CR0D 0x0D
188#define CR0E 0x0E
189#define CR0F 0x0F
190#define CR10 0x10
191#define CR11 0x11
192#define CR12 0x12
193#define CR13 0x13
194#define CR14 0x14
195#define CR15 0x15
196#define CR16 0x16
197#define CR17 0x17
198#define CR18 0x18
199
200/* Extend CRT Controller Registers */
201#define CR30 0x30
202#define CR31 0x31
203#define CR32 0x32
204#define CR33 0x33
205#define CR34 0x34
206#define CR35 0x35
207#define CR36 0x36
208#define CR37 0x37
209#define CR38 0x38
210#define CR39 0x39
211#define CR3A 0x3A
212#define CR3B 0x3B
213#define CR3C 0x3C
214#define CR3D 0x3D
215#define CR3E 0x3E
216#define CR3F 0x3F
217#define CR40 0x40
218#define CR41 0x41
219#define CR42 0x42
220#define CR43 0x43
221#define CR44 0x44
222#define CR45 0x45
223#define CR46 0x46
224#define CR47 0x47
225#define CR48 0x48
226#define CR49 0x49
227#define CR4A 0x4A
228#define CR4B 0x4B
229#define CR4C 0x4C
230#define CR4D 0x4D
231#define CR4E 0x4E
232#define CR4F 0x4F
233#define CR50 0x50
234#define CR51 0x51
235#define CR52 0x52
236#define CR53 0x53
237#define CR54 0x54
238#define CR55 0x55
239#define CR56 0x56
240#define CR57 0x57
241#define CR58 0x58
242#define CR59 0x59
243#define CR5A 0x5A
244#define CR5B 0x5B
245#define CR5C 0x5C
246#define CR5D 0x5D
247#define CR5E 0x5E
248#define CR5F 0x5F
249#define CR60 0x60
250#define CR61 0x61
251#define CR62 0x62
252#define CR63 0x63
253#define CR64 0x64
254#define CR65 0x65
255#define CR66 0x66
256#define CR67 0x67
257#define CR68 0x68
258#define CR69 0x69
259#define CR6A 0x6A
260#define CR6B 0x6B
261#define CR6C 0x6C
262#define CR6D 0x6D
263#define CR6E 0x6E
264#define CR6F 0x6F
265#define CR70 0x70
266#define CR71 0x71
267#define CR72 0x72
268#define CR73 0x73
269#define CR74 0x74
270#define CR75 0x75
271#define CR76 0x76
272#define CR77 0x77
273#define CR78 0x78
274#define CR79 0x79
275#define CR7A 0x7A
276#define CR7B 0x7B
277#define CR7C 0x7C
278#define CR7D 0x7D
279#define CR7E 0x7E
280#define CR7F 0x7F
281#define CR80 0x80
282#define CR81 0x81
283#define CR82 0x82
284#define CR83 0x83
285#define CR84 0x84
286#define CR85 0x85
287#define CR86 0x86
288#define CR87 0x87
289#define CR88 0x88
290#define CR89 0x89
291#define CR8A 0x8A
292#define CR8B 0x8B
293#define CR8C 0x8C
294#define CR8D 0x8D
295#define CR8E 0x8E
296#define CR8F 0x8F
297#define CR90 0x90
298#define CR91 0x91
299#define CR92 0x92
300#define CR93 0x93
301#define CR94 0x94
302#define CR95 0x95
303#define CR96 0x96
304#define CR97 0x97
305#define CR98 0x98
306#define CR99 0x99
307#define CR9A 0x9A
308#define CR9B 0x9B
309#define CR9C 0x9C
310#define CR9D 0x9D
311#define CR9E 0x9E
312#define CR9F 0x9F
313#define CRA0 0xA0
314#define CRA1 0xA1
315#define CRA2 0xA2
316#define CRA3 0xA3
317#define CRD2 0xD2
318#define CRD3 0xD3
319#define CRD4 0xD4
320
321/* LUT Table*/
322#define LUT_DATA 0x3C9 /* DACDATA */
323#define LUT_INDEX_READ 0x3C7 /* DACRX */
324#define LUT_INDEX_WRITE 0x3C8 /* DACWX */
325#define DACMASK 0x3C6
326
327/* Definition Device */
328#define DEVICE_CRT 0x01
329#define DEVICE_DVI 0x03
330#define DEVICE_LCD 0x04
331
332/* Device output interface */
333#define INTERFACE_NONE 0x00
334#define INTERFACE_ANALOG_RGB 0x01
335#define INTERFACE_DVP0 0x02
336#define INTERFACE_DVP1 0x03
337#define INTERFACE_DFP_HIGH 0x04
338#define INTERFACE_DFP_LOW 0x05
339#define INTERFACE_DFP 0x06
340#define INTERFACE_LVDS0 0x07
341#define INTERFACE_LVDS1 0x08
342#define INTERFACE_LVDS0LVDS1 0x09
343#define INTERFACE_TMDS 0x0A
344
345#define HW_LAYOUT_LCD_ONLY 0x01
346#define HW_LAYOUT_DVI_ONLY 0x02
347#define HW_LAYOUT_LCD_DVI 0x03
348#define HW_LAYOUT_LCD1_LCD2 0x04
349#define HW_LAYOUT_LCD_EXTERNAL_LCD2 0x10
350
351/* Definition Refresh Rate */
352#define REFRESH_50 50
353#define REFRESH_60 60
354#define REFRESH_75 75
355#define REFRESH_85 85
356#define REFRESH_100 100
357#define REFRESH_120 120
358
359/* Definition Sync Polarity*/
360#define NEGATIVE 1
361#define POSITIVE 0
362
363/*480x640@60 Sync Polarity (GTF)
364*/
365#define M480X640_R60_HSP NEGATIVE
366#define M480X640_R60_VSP POSITIVE
367
368/*640x480@60 Sync Polarity (VESA Mode)
369*/
370#define M640X480_R60_HSP NEGATIVE
371#define M640X480_R60_VSP NEGATIVE
372
373/*640x480@75 Sync Polarity (VESA Mode)
374*/
375#define M640X480_R75_HSP NEGATIVE
376#define M640X480_R75_VSP NEGATIVE
377
378/*640x480@85 Sync Polarity (VESA Mode)
379*/
380#define M640X480_R85_HSP NEGATIVE
381#define M640X480_R85_VSP NEGATIVE
382
383/*640x480@100 Sync Polarity (GTF Mode)
384*/
385#define M640X480_R100_HSP NEGATIVE
386#define M640X480_R100_VSP POSITIVE
387
388/*640x480@120 Sync Polarity (GTF Mode)
389*/
390#define M640X480_R120_HSP NEGATIVE
391#define M640X480_R120_VSP POSITIVE
392
393/*720x480@60 Sync Polarity (GTF Mode)
394*/
395#define M720X480_R60_HSP NEGATIVE
396#define M720X480_R60_VSP POSITIVE
397
398/*720x576@60 Sync Polarity (GTF Mode)
399*/
400#define M720X576_R60_HSP NEGATIVE
401#define M720X576_R60_VSP POSITIVE
402
403/*800x600@60 Sync Polarity (VESA Mode)
404*/
405#define M800X600_R60_HSP POSITIVE
406#define M800X600_R60_VSP POSITIVE
407
408/*800x600@75 Sync Polarity (VESA Mode)
409*/
410#define M800X600_R75_HSP POSITIVE
411#define M800X600_R75_VSP POSITIVE
412
413/*800x600@85 Sync Polarity (VESA Mode)
414*/
415#define M800X600_R85_HSP POSITIVE
416#define M800X600_R85_VSP POSITIVE
417
418/*800x600@100 Sync Polarity (GTF Mode)
419*/
420#define M800X600_R100_HSP NEGATIVE
421#define M800X600_R100_VSP POSITIVE
422
423/*800x600@120 Sync Polarity (GTF Mode)
424*/
425#define M800X600_R120_HSP NEGATIVE
426#define M800X600_R120_VSP POSITIVE
427
428/*800x480@60 Sync Polarity (CVT Mode)
429*/
430#define M800X480_R60_HSP NEGATIVE
431#define M800X480_R60_VSP POSITIVE
432
433/*848x480@60 Sync Polarity (CVT Mode)
434*/
435#define M848X480_R60_HSP NEGATIVE
436#define M848X480_R60_VSP POSITIVE
437
438/*852x480@60 Sync Polarity (GTF Mode)
439*/
440#define M852X480_R60_HSP NEGATIVE
441#define M852X480_R60_VSP POSITIVE
442
443/*1024x512@60 Sync Polarity (GTF Mode)
444*/
445#define M1024X512_R60_HSP NEGATIVE
446#define M1024X512_R60_VSP POSITIVE
447
448/*1024x600@60 Sync Polarity (GTF Mode)
449*/
450#define M1024X600_R60_HSP NEGATIVE
451#define M1024X600_R60_VSP POSITIVE
452
453/*1024x768@60 Sync Polarity (VESA Mode)
454*/
455#define M1024X768_R60_HSP NEGATIVE
456#define M1024X768_R60_VSP NEGATIVE
457
458/*1024x768@75 Sync Polarity (VESA Mode)
459*/
460#define M1024X768_R75_HSP POSITIVE
461#define M1024X768_R75_VSP POSITIVE
462
463/*1024x768@85 Sync Polarity (VESA Mode)
464*/
465#define M1024X768_R85_HSP POSITIVE
466#define M1024X768_R85_VSP POSITIVE
467
468/*1024x768@100 Sync Polarity (GTF Mode)
469*/
470#define M1024X768_R100_HSP NEGATIVE
471#define M1024X768_R100_VSP POSITIVE
472
473/*1152x864@75 Sync Polarity (VESA Mode)
474*/
475#define M1152X864_R75_HSP POSITIVE
476#define M1152X864_R75_VSP POSITIVE
477
478/*1280x720@60 Sync Polarity (GTF Mode)
479*/
480#define M1280X720_R60_HSP NEGATIVE
481#define M1280X720_R60_VSP POSITIVE
482
483/* 1280x768@50 Sync Polarity (GTF Mode) */
484#define M1280X768_R50_HSP NEGATIVE
485#define M1280X768_R50_VSP POSITIVE
486
487/*1280x768@60 Sync Polarity (GTF Mode)
488*/
489#define M1280X768_R60_HSP NEGATIVE
490#define M1280X768_R60_VSP POSITIVE
491
492/*1280x800@60 Sync Polarity (CVT Mode)
493*/
494#define M1280X800_R60_HSP NEGATIVE
495#define M1280X800_R60_VSP POSITIVE
496
497/*1280x960@60 Sync Polarity (VESA Mode)
498*/
499#define M1280X960_R60_HSP POSITIVE
500#define M1280X960_R60_VSP POSITIVE
501
502/*1280x1024@60 Sync Polarity (VESA Mode)
503*/
504#define M1280X1024_R60_HSP POSITIVE
505#define M1280X1024_R60_VSP POSITIVE
506
507/* 1360x768@60 Sync Polarity (CVT Mode) */
508#define M1360X768_R60_HSP POSITIVE
509#define M1360X768_R60_VSP POSITIVE
510
511/* 1360x768@60 Sync Polarity (CVT Reduce Blanking Mode) */
512#define M1360X768_RB_R60_HSP POSITIVE
513#define M1360X768_RB_R60_VSP NEGATIVE
514
515/* 1368x768@50 Sync Polarity (GTF Mode) */
516#define M1368X768_R50_HSP NEGATIVE
517#define M1368X768_R50_VSP POSITIVE
518
519/* 1368x768@60 Sync Polarity (VESA Mode) */
520#define M1368X768_R60_HSP NEGATIVE
521#define M1368X768_R60_VSP POSITIVE
522
523/*1280x1024@75 Sync Polarity (VESA Mode)
524*/
525#define M1280X1024_R75_HSP POSITIVE
526#define M1280X1024_R75_VSP POSITIVE
527
528/*1280x1024@85 Sync Polarity (VESA Mode)
529*/
530#define M1280X1024_R85_HSP POSITIVE
531#define M1280X1024_R85_VSP POSITIVE
532
533/*1440x1050@60 Sync Polarity (GTF Mode)
534*/
535#define M1440X1050_R60_HSP NEGATIVE
536#define M1440X1050_R60_VSP POSITIVE
537
538/*1600x1200@60 Sync Polarity (VESA Mode)
539*/
540#define M1600X1200_R60_HSP POSITIVE
541#define M1600X1200_R60_VSP POSITIVE
542
543/*1600x1200@75 Sync Polarity (VESA Mode)
544*/
545#define M1600X1200_R75_HSP POSITIVE
546#define M1600X1200_R75_VSP POSITIVE
547
548/* 1680x1050@60 Sync Polarity (CVT Mode) */
549#define M1680x1050_R60_HSP NEGATIVE
550#define M1680x1050_R60_VSP NEGATIVE
551
552/* 1680x1050@60 Sync Polarity (CVT Reduce Blanking Mode) */
553#define M1680x1050_RB_R60_HSP POSITIVE
554#define M1680x1050_RB_R60_VSP NEGATIVE
555
556/* 1680x1050@75 Sync Polarity (CVT Mode) */
557#define M1680x1050_R75_HSP NEGATIVE
558#define M1680x1050_R75_VSP POSITIVE
559
560/*1920x1080@60 Sync Polarity (CVT Mode)
561*/
562#define M1920X1080_R60_HSP NEGATIVE
563#define M1920X1080_R60_VSP POSITIVE
564
565/* 1920x1080@60 Sync Polarity (CVT Reduce Blanking Mode) */
566#define M1920X1080_RB_R60_HSP POSITIVE
567#define M1920X1080_RB_R60_VSP NEGATIVE
568
569/*1920x1440@60 Sync Polarity (VESA Mode)
570*/
571#define M1920X1440_R60_HSP NEGATIVE
572#define M1920X1440_R60_VSP POSITIVE
573
574/*1920x1440@75 Sync Polarity (VESA Mode)
575*/
576#define M1920X1440_R75_HSP NEGATIVE
577#define M1920X1440_R75_VSP POSITIVE
578
579#if 0
580/* 1400x1050@60 Sync Polarity (VESA Mode) */
581#define M1400X1050_R60_HSP NEGATIVE
582#define M1400X1050_R60_VSP NEGATIVE
583#endif
584
585/* 1400x1050@60 Sync Polarity (CVT Mode) */
586#define M1400X1050_R60_HSP NEGATIVE
587#define M1400X1050_R60_VSP POSITIVE
588
589/* 1400x1050@60 Sync Polarity (CVT Reduce Blanking Mode) */
590#define M1400X1050_RB_R60_HSP POSITIVE
591#define M1400X1050_RB_R60_VSP NEGATIVE
592
593/* 1400x1050@75 Sync Polarity (CVT Mode) */
594#define M1400X1050_R75_HSP NEGATIVE
595#define M1400X1050_R75_VSP POSITIVE
596
597/* 960x600@60 Sync Polarity (CVT Mode) */
598#define M960X600_R60_HSP NEGATIVE
599#define M960X600_R60_VSP POSITIVE
600
601/* 1000x600@60 Sync Polarity (GTF Mode) */
602#define M1000X600_R60_HSP NEGATIVE
603#define M1000X600_R60_VSP POSITIVE
604
605/* 1024x576@60 Sync Polarity (GTF Mode) */
606#define M1024X576_R60_HSP NEGATIVE
607#define M1024X576_R60_VSP POSITIVE
608
609/*1024x600@60 Sync Polarity (GTF Mode)*/
610#define M1024X600_R60_HSP NEGATIVE
611#define M1024X600_R60_VSP POSITIVE
612
613/* 1088x612@60 Sync Polarity (CVT Mode) */
614#define M1088X612_R60_HSP NEGATIVE
615#define M1088X612_R60_VSP POSITIVE
616
617/* 1152x720@60 Sync Polarity (CVT Mode) */
618#define M1152X720_R60_HSP NEGATIVE
619#define M1152X720_R60_VSP POSITIVE
620
621/* 1200x720@60 Sync Polarity (GTF Mode) */
622#define M1200X720_R60_HSP NEGATIVE
623#define M1200X720_R60_VSP POSITIVE
624
625/* 1280x600@60 Sync Polarity (GTF Mode) */
626#define M1280x600_R60_HSP NEGATIVE
627#define M1280x600_R60_VSP POSITIVE
628
629/* 1280x720@50 Sync Polarity (GTF Mode) */
630#define M1280X720_R50_HSP NEGATIVE
631#define M1280X720_R50_VSP POSITIVE
632
633/* 1280x720@60 Sync Polarity (CEA Mode) */
634#define M1280X720_CEA_R60_HSP POSITIVE
635#define M1280X720_CEA_R60_VSP POSITIVE
636
637/* 1440x900@60 Sync Polarity (CVT Mode) */
638#define M1440X900_R60_HSP NEGATIVE
639#define M1440X900_R60_VSP POSITIVE
640
641/* 1440x900@75 Sync Polarity (CVT Mode) */
642#define M1440X900_R75_HSP NEGATIVE
643#define M1440X900_R75_VSP POSITIVE
644
645/* 1440x900@60 Sync Polarity (CVT Reduce Blanking Mode) */
646#define M1440X900_RB_R60_HSP POSITIVE
647#define M1440X900_RB_R60_VSP NEGATIVE
648
649/* 1600x900@60 Sync Polarity (CVT Mode) */
650#define M1600X900_R60_HSP NEGATIVE
651#define M1600X900_R60_VSP POSITIVE
652
653/* 1600x900@60 Sync Polarity (CVT Reduce Blanking Mode) */
654#define M1600X900_RB_R60_HSP POSITIVE
655#define M1600X900_RB_R60_VSP NEGATIVE
656
657/* 1600x1024@60 Sync Polarity (GTF Mode) */
658#define M1600X1024_R60_HSP NEGATIVE
659#define M1600X1024_R60_VSP POSITIVE
660
661/* 1792x1344@60 Sync Polarity (DMT Mode) */
662#define M1792x1344_R60_HSP NEGATIVE
663#define M1792x1344_R60_VSP POSITIVE
664
665/* 1856x1392@60 Sync Polarity (DMT Mode) */
666#define M1856x1392_R60_HSP NEGATIVE
667#define M1856x1392_R60_VSP POSITIVE
668
669/* 1920x1200@60 Sync Polarity (CVT Mode) */
670#define M1920X1200_R60_HSP NEGATIVE
671#define M1920X1200_R60_VSP POSITIVE
672
673/* 1920x1200@60 Sync Polarity (CVT Reduce Blanking Mode) */
674#define M1920X1200_RB_R60_HSP POSITIVE
675#define M1920X1200_RB_R60_VSP NEGATIVE
676
677/* 1920x1080@60 Sync Polarity (CEA Mode) */
678#define M1920X1080_CEA_R60_HSP POSITIVE
679#define M1920X1080_CEA_R60_VSP POSITIVE
680
681/* 2048x1536@60 Sync Polarity (CVT Mode) */
682#define M2048x1536_R60_HSP NEGATIVE
683#define M2048x1536_R60_VSP POSITIVE
684
685/* define PLL index: */
686#define CLK_25_175M 25175000
687#define CLK_26_880M 26880000
688#define CLK_29_581M 29581000
689#define CLK_31_490M 31490000
690#define CLK_31_500M 31500000
691#define CLK_31_728M 31728000
692#define CLK_32_668M 32688000
693#define CLK_36_000M 36000000
694#define CLK_40_000M 40000000
695#define CLK_41_291M 41291000
696#define CLK_43_163M 43163000
697#define CLK_45_250M 45250000 /* 45.46MHz */
698#define CLK_46_000M 46000000
699#define CLK_46_996M 46996000
700#define CLK_48_000M 48000000
701#define CLK_48_875M 48875000
702#define CLK_49_500M 49500000
703#define CLK_52_406M 52406000
704#define CLK_52_977M 52977000
705#define CLK_56_250M 56250000
706#define CLK_60_466M 60466000
707#define CLK_61_500M 61500000
708#define CLK_65_000M 65000000
709#define CLK_65_178M 65178000
710#define CLK_66_750M 66750000 /* 67.116MHz */
711#define CLK_68_179M 68179000
712#define CLK_69_924M 69924000
713#define CLK_70_159M 70159000
714#define CLK_72_000M 72000000
715#define CLK_74_270M 74270000
716#define CLK_78_750M 78750000
717#define CLK_80_136M 80136000
718#define CLK_83_375M 83375000
719#define CLK_83_950M 83950000
720#define CLK_84_750M 84750000 /* 84.537Mhz */
721#define CLK_85_860M 85860000
722#define CLK_88_750M 88750000
723#define CLK_94_500M 94500000
724#define CLK_97_750M 97750000
725#define CLK_101_000M 101000000
726#define CLK_106_500M 106500000
727#define CLK_108_000M 108000000
728#define CLK_113_309M 113309000
729#define CLK_118_840M 118840000
730#define CLK_119_000M 119000000
731#define CLK_121_750M 121750000 /* 121.704MHz */
732#define CLK_125_104M 125104000
733#define CLK_133_308M 133308000
734#define CLK_135_000M 135000000
735#define CLK_136_700M 136700000
736#define CLK_138_400M 138400000
737#define CLK_146_760M 146760000
738#define CLK_148_500M 148500000
739
740#define CLK_153_920M 153920000
741#define CLK_156_000M 156000000
742#define CLK_157_500M 157500000
743#define CLK_162_000M 162000000
744#define CLK_187_000M 187000000
745#define CLK_193_295M 193295000
746#define CLK_202_500M 202500000
747#define CLK_204_000M 204000000
748#define CLK_218_500M 218500000
749#define CLK_234_000M 234000000
750#define CLK_267_250M 267250000
751#define CLK_297_500M 297500000
752#define CLK_74_481M 74481000
753#define CLK_172_798M 172798000
754#define CLK_122_614M 122614000
755
756/* CLE266 PLL value
757*/
758#define CLE266_PLL_25_175M 0x0000C763
759#define CLE266_PLL_26_880M 0x0000440F
760#define CLE266_PLL_29_581M 0x00008421
761#define CLE266_PLL_31_490M 0x00004721
762#define CLE266_PLL_31_500M 0x0000C3B5
763#define CLE266_PLL_31_728M 0x0000471F
764#define CLE266_PLL_32_668M 0x0000C449
765#define CLE266_PLL_36_000M 0x0000C5E5
766#define CLE266_PLL_40_000M 0x0000C459
767#define CLE266_PLL_41_291M 0x00004417
768#define CLE266_PLL_43_163M 0x0000C579
769#define CLE266_PLL_45_250M 0x0000C57F /* 45.46MHz */
770#define CLE266_PLL_46_000M 0x0000875A
771#define CLE266_PLL_46_996M 0x0000C4E9
772#define CLE266_PLL_48_000M 0x00001443
773#define CLE266_PLL_48_875M 0x00001D63
774#define CLE266_PLL_49_500M 0x00008653
775#define CLE266_PLL_52_406M 0x0000C475
776#define CLE266_PLL_52_977M 0x00004525
777#define CLE266_PLL_56_250M 0x000047B7
778#define CLE266_PLL_60_466M 0x0000494C
779#define CLE266_PLL_61_500M 0x00001456
780#define CLE266_PLL_65_000M 0x000086ED
781#define CLE266_PLL_65_178M 0x0000855B
782#define CLE266_PLL_66_750M 0x0000844B /* 67.116MHz */
783#define CLE266_PLL_68_179M 0x00000413
784#define CLE266_PLL_69_924M 0x00001153
785#define CLE266_PLL_70_159M 0x00001462
786#define CLE266_PLL_72_000M 0x00001879
787#define CLE266_PLL_74_270M 0x00004853
788#define CLE266_PLL_78_750M 0x00004321
789#define CLE266_PLL_80_136M 0x0000051C
790#define CLE266_PLL_83_375M 0x0000C25D
791#define CLE266_PLL_83_950M 0x00000729
792#define CLE266_PLL_84_750M 0x00008576 /* 84.537MHz */
793#define CLE266_PLL_85_860M 0x00004754
794#define CLE266_PLL_88_750M 0x0000051F
795#define CLE266_PLL_94_500M 0x00000521
796#define CLE266_PLL_97_750M 0x00004652
797#define CLE266_PLL_101_000M 0x0000497F
798#define CLE266_PLL_106_500M 0x00008477 /* 106.491463 MHz */
799#define CLE266_PLL_108_000M 0x00008479
800#define CLE266_PLL_113_309M 0x00000C5F
801#define CLE266_PLL_118_840M 0x00004553
802#define CLE266_PLL_119_000M 0x00000D6C
803#define CLE266_PLL_121_750M 0x00004555 /* 121.704MHz */
804#define CLE266_PLL_125_104M 0x000006B5
805#define CLE266_PLL_133_308M 0x0000465F
806#define CLE266_PLL_135_000M 0x0000455E
807#define CLE266_PLL_136_700M 0x00000C73
808#define CLE266_PLL_138_400M 0x00000957
809#define CLE266_PLL_146_760M 0x00004567
810#define CLE266_PLL_148_500M 0x00000853
811#define CLE266_PLL_153_920M 0x00000856
812#define CLE266_PLL_156_000M 0x0000456D
813#define CLE266_PLL_157_500M 0x000005B7
814#define CLE266_PLL_162_000M 0x00004571
815#define CLE266_PLL_187_000M 0x00000976
816#define CLE266_PLL_193_295M 0x0000086C
817#define CLE266_PLL_202_500M 0x00000763
818#define CLE266_PLL_204_000M 0x00000764
819#define CLE266_PLL_218_500M 0x0000065C
820#define CLE266_PLL_234_000M 0x00000662
821#define CLE266_PLL_267_250M 0x00000670
822#define CLE266_PLL_297_500M 0x000005E6
823#define CLE266_PLL_74_481M 0x0000051A
824#define CLE266_PLL_172_798M 0x00004579
825#define CLE266_PLL_122_614M 0x0000073C
826
827/* K800 PLL value
828*/
829#define K800_PLL_25_175M 0x00539001
830#define K800_PLL_26_880M 0x001C8C80
831#define K800_PLL_29_581M 0x00409080
832#define K800_PLL_31_490M 0x006F9001
833#define K800_PLL_31_500M 0x008B9002
834#define K800_PLL_31_728M 0x00AF9003
835#define K800_PLL_32_668M 0x00909002
836#define K800_PLL_36_000M 0x009F9002
837#define K800_PLL_40_000M 0x00578C02
838#define K800_PLL_41_291M 0x00438C01
839#define K800_PLL_43_163M 0x00778C03
840#define K800_PLL_45_250M 0x007D8C83 /* 45.46MHz */
841#define K800_PLL_46_000M 0x00658C02
842#define K800_PLL_46_996M 0x00818C83
843#define K800_PLL_48_000M 0x00848C83
844#define K800_PLL_48_875M 0x00508C81
845#define K800_PLL_49_500M 0x00518C01
846#define K800_PLL_52_406M 0x00738C02
847#define K800_PLL_52_977M 0x00928C83
848#define K800_PLL_56_250M 0x007C8C02
849#define K800_PLL_60_466M 0x00A78C83
850#define K800_PLL_61_500M 0x00AA8C83
851#define K800_PLL_65_000M 0x006B8C01
852#define K800_PLL_65_178M 0x00B48C83
853#define K800_PLL_66_750M 0x00948C82 /* 67.116MHz */
854#define K800_PLL_68_179M 0x00708C01
855#define K800_PLL_69_924M 0x00C18C83
856#define K800_PLL_70_159M 0x00C28C83
857#define K800_PLL_72_000M 0x009F8C82
858#define K800_PLL_74_270M 0x00ce0c03
859#define K800_PLL_78_750M 0x00408801
860#define K800_PLL_80_136M 0x00428801
861#define K800_PLL_83_375M 0x005B0882
862#define K800_PLL_83_950M 0x00738803
863#define K800_PLL_84_750M 0x00748883 /* 84.477MHz */
864#define K800_PLL_85_860M 0x00768883
865#define K800_PLL_88_750M 0x007A8883
866#define K800_PLL_94_500M 0x00828803
867#define K800_PLL_97_750M 0x00878883
868#define K800_PLL_101_000M 0x008B8883
869#define K800_PLL_106_500M 0x00758882 /* 106.491463 MHz */
870#define K800_PLL_108_000M 0x00778882
871#define K800_PLL_113_309M 0x005D8881
872#define K800_PLL_118_840M 0x00A48883
873#define K800_PLL_119_000M 0x00838882
874#define K800_PLL_121_750M 0x00A88883 /* 121.704MHz */
875#define K800_PLL_125_104M 0x00688801
876#define K800_PLL_133_308M 0x005D8801
877#define K800_PLL_135_000M 0x001A4081
878#define K800_PLL_136_700M 0x00BD8883
879#define K800_PLL_138_400M 0x00728881
880#define K800_PLL_146_760M 0x00CC8883
881#define K800_PLL_148_500M 0x00ce0803
882#define K800_PLL_153_920M 0x00548482
883#define K800_PLL_156_000M 0x006B8483
884#define K800_PLL_157_500M 0x00142080
885#define K800_PLL_162_000M 0x006F8483
886#define K800_PLL_187_000M 0x00818483
887#define K800_PLL_193_295M 0x004F8481
888#define K800_PLL_202_500M 0x00538481
889#define K800_PLL_204_000M 0x008D8483
890#define K800_PLL_218_500M 0x00978483
891#define K800_PLL_234_000M 0x00608401
892#define K800_PLL_267_250M 0x006E8481
893#define K800_PLL_297_500M 0x00A48402
894#define K800_PLL_74_481M 0x007B8C81
895#define K800_PLL_172_798M 0x00778483
896#define K800_PLL_122_614M 0x00878882
897
898/* PLL for VT3324 */
899#define CX700_25_175M 0x008B1003
900#define CX700_26_719M 0x00931003
901#define CX700_26_880M 0x00941003
902#define CX700_29_581M 0x00A49003
903#define CX700_31_490M 0x00AE1003
904#define CX700_31_500M 0x00AE1003
905#define CX700_31_728M 0x00AF1003
906#define CX700_32_668M 0x00B51003
907#define CX700_36_000M 0x00C81003
908#define CX700_40_000M 0x006E0C03
909#define CX700_41_291M 0x00710C03
910#define CX700_43_163M 0x00770C03
911#define CX700_45_250M 0x007D0C03 /* 45.46MHz */
912#define CX700_46_000M 0x007F0C03
913#define CX700_46_996M 0x00818C83
914#define CX700_48_000M 0x00840C03
915#define CX700_48_875M 0x00508C81
916#define CX700_49_500M 0x00880C03
917#define CX700_52_406M 0x00730C02
918#define CX700_52_977M 0x00920C03
919#define CX700_56_250M 0x009B0C03
920#define CX700_60_466M 0x00460C00
921#define CX700_61_500M 0x00AA0C03
922#define CX700_65_000M 0x006B0C01
923#define CX700_65_178M 0x006B0C01
924#define CX700_66_750M 0x00940C02 /*67.116MHz */
925#define CX700_68_179M 0x00BC0C03
926#define CX700_69_924M 0x00C10C03
927#define CX700_70_159M 0x00C20C03
928#define CX700_72_000M 0x009F0C02
929#define CX700_74_270M 0x00CE0C03
930#define CX700_74_481M 0x00CE0C03
931#define CX700_78_750M 0x006C0803
932#define CX700_80_136M 0x006E0803
933#define CX700_83_375M 0x005B0882
934#define CX700_83_950M 0x00730803
935#define CX700_84_750M 0x00740803 /* 84.537Mhz */
936#define CX700_85_860M 0x00760803
937#define CX700_88_750M 0x00AC8885
938#define CX700_94_500M 0x00820803
939#define CX700_97_750M 0x00870803
940#define CX700_101_000M 0x008B0803
941#define CX700_106_500M 0x00750802
942#define CX700_108_000M 0x00950803
943#define CX700_113_309M 0x005D0801
944#define CX700_118_840M 0x00A40803
945#define CX700_119_000M 0x00830802
946#define CX700_121_750M 0x00420800 /* 121.704MHz */
947#define CX700_125_104M 0x00AD0803
948#define CX700_133_308M 0x00930802
949#define CX700_135_000M 0x00950802
950#define CX700_136_700M 0x00BD0803
951#define CX700_138_400M 0x00720801
952#define CX700_146_760M 0x00CC0803
953#define CX700_148_500M 0x00a40802
954#define CX700_153_920M 0x00540402
955#define CX700_156_000M 0x006B0403
956#define CX700_157_500M 0x006C0403
957#define CX700_162_000M 0x006F0403
958#define CX700_172_798M 0x00770403
959#define CX700_187_000M 0x00810403
960#define CX700_193_295M 0x00850403
961#define CX700_202_500M 0x008C0403
962#define CX700_204_000M 0x008D0403
963#define CX700_218_500M 0x00970403
964#define CX700_234_000M 0x00600401
965#define CX700_267_250M 0x00B90403
966#define CX700_297_500M 0x00CE0403
967#define CX700_122_614M 0x00870802
968
969/* Definition CRTC Timing Index */
970#define H_TOTAL_INDEX 0
971#define H_ADDR_INDEX 1
972#define H_BLANK_START_INDEX 2
973#define H_BLANK_END_INDEX 3
974#define H_SYNC_START_INDEX 4
975#define H_SYNC_END_INDEX 5
976#define V_TOTAL_INDEX 6
977#define V_ADDR_INDEX 7
978#define V_BLANK_START_INDEX 8
979#define V_BLANK_END_INDEX 9
980#define V_SYNC_START_INDEX 10
981#define V_SYNC_END_INDEX 11
982#define H_TOTAL_SHADOW_INDEX 12
983#define H_BLANK_END_SHADOW_INDEX 13
984#define V_TOTAL_SHADOW_INDEX 14
985#define V_ADDR_SHADOW_INDEX 15
986#define V_BLANK_SATRT_SHADOW_INDEX 16
987#define V_BLANK_END_SHADOW_INDEX 17
988#define V_SYNC_SATRT_SHADOW_INDEX 18
989#define V_SYNC_END_SHADOW_INDEX 19
990
991/* Definition Video Mode Pixel Clock (picoseconds)
992*/
993#define RES_480X640_60HZ_PIXCLOCK 39722
994#define RES_640X480_60HZ_PIXCLOCK 39722
995#define RES_640X480_75HZ_PIXCLOCK 31747
996#define RES_640X480_85HZ_PIXCLOCK 27777
997#define RES_640X480_100HZ_PIXCLOCK 23168
998#define RES_640X480_120HZ_PIXCLOCK 19081
999#define RES_720X480_60HZ_PIXCLOCK 37020
1000#define RES_720X576_60HZ_PIXCLOCK 30611
1001#define RES_800X600_60HZ_PIXCLOCK 25000
1002#define RES_800X600_75HZ_PIXCLOCK 20203
1003#define RES_800X600_85HZ_PIXCLOCK 17777
1004#define RES_800X600_100HZ_PIXCLOCK 14667
1005#define RES_800X600_120HZ_PIXCLOCK 11912
1006#define RES_800X480_60HZ_PIXCLOCK 33805
1007#define RES_848X480_60HZ_PIXCLOCK 31756
1008#define RES_856X480_60HZ_PIXCLOCK 31518
1009#define RES_1024X512_60HZ_PIXCLOCK 24218
1010#define RES_1024X600_60HZ_PIXCLOCK 20460
1011#define RES_1024X768_60HZ_PIXCLOCK 15385
1012#define RES_1024X768_75HZ_PIXCLOCK 12699
1013#define RES_1024X768_85HZ_PIXCLOCK 10582
1014#define RES_1024X768_100HZ_PIXCLOCK 8825
1015#define RES_1152X864_75HZ_PIXCLOCK 9259
1016#define RES_1280X768_60HZ_PIXCLOCK 12480
1017#define RES_1280X800_60HZ_PIXCLOCK 11994
1018#define RES_1280X960_60HZ_PIXCLOCK 9259
1019#define RES_1280X1024_60HZ_PIXCLOCK 9260
1020#define RES_1280X1024_75HZ_PIXCLOCK 7408
1021#define RES_1280X768_85HZ_PIXCLOCK 6349
1022#define RES_1440X1050_60HZ_PIXCLOCK 7993
1023#define RES_1600X1200_60HZ_PIXCLOCK 6172
1024#define RES_1600X1200_75HZ_PIXCLOCK 4938
1025#define RES_1280X720_60HZ_PIXCLOCK 13426
1026#define RES_1920X1080_60HZ_PIXCLOCK 5787
1027#define RES_1400X1050_60HZ_PIXCLOCK 8214
1028#define RES_1400X1050_75HZ_PIXCLOCK 6410
1029#define RES_1368X768_60HZ_PIXCLOCK 11647
1030#define RES_960X600_60HZ_PIXCLOCK 22099
1031#define RES_1000X600_60HZ_PIXCLOCK 20834
1032#define RES_1024X576_60HZ_PIXCLOCK 21278
1033#define RES_1088X612_60HZ_PIXCLOCK 18877
1034#define RES_1152X720_60HZ_PIXCLOCK 14981
1035#define RES_1200X720_60HZ_PIXCLOCK 14253
1036#define RES_1280X600_60HZ_PIXCLOCK 16260
1037#define RES_1280X720_50HZ_PIXCLOCK 16538
1038#define RES_1280X768_50HZ_PIXCLOCK 15342
1039#define RES_1366X768_50HZ_PIXCLOCK 14301
1040#define RES_1366X768_60HZ_PIXCLOCK 11646
1041#define RES_1360X768_60HZ_PIXCLOCK 11799
1042#define RES_1440X900_60HZ_PIXCLOCK 9390
1043#define RES_1440X900_75HZ_PIXCLOCK 7315
1044#define RES_1600X900_60HZ_PIXCLOCK 8415
1045#define RES_1600X1024_60HZ_PIXCLOCK 7315
1046#define RES_1680X1050_60HZ_PIXCLOCK 6814
1047#define RES_1680X1050_75HZ_PIXCLOCK 5348
1048#define RES_1792X1344_60HZ_PIXCLOCK 4902
1049#define RES_1856X1392_60HZ_PIXCLOCK 4577
1050#define RES_1920X1200_60HZ_PIXCLOCK 5173
1051#define RES_1920X1440_60HZ_PIXCLOCK 4274
1052#define RES_1920X1440_75HZ_PIXCLOCK 3367
1053#define RES_2048X1536_60HZ_PIXCLOCK 3742
1054
1055#define RES_1360X768_RB_60HZ_PIXCLOCK 13889
1056#define RES_1400X1050_RB_60HZ_PIXCLOCK 9901
1057#define RES_1440X900_RB_60HZ_PIXCLOCK 11268
1058#define RES_1600X900_RB_60HZ_PIXCLOCK 10230
1059#define RES_1680X1050_RB_60HZ_PIXCLOCK 8403
1060#define RES_1920X1080_RB_60HZ_PIXCLOCK 7225
1061#define RES_1920X1200_RB_60HZ_PIXCLOCK 6497
1062
1063/* LCD display method
1064*/
1065#define LCD_EXPANDSION 0x00
1066#define LCD_CENTERING 0x01
1067
1068/* LCD mode
1069*/
1070#define LCD_OPENLDI 0x00
1071#define LCD_SPWG 0x01
1072
1073/* Define display timing
1074*/
1075struct display_timing {
1076 u16 hor_total;
1077 u16 hor_addr;
1078 u16 hor_blank_start;
1079 u16 hor_blank_end;
1080 u16 hor_sync_start;
1081 u16 hor_sync_end;
1082 u16 ver_total;
1083 u16 ver_addr;
1084 u16 ver_blank_start;
1085 u16 ver_blank_end;
1086 u16 ver_sync_start;
1087 u16 ver_sync_end;
1088};
1089
1090struct crt_mode_table {
1091 int refresh_rate;
1092 unsigned long clk;
1093 int h_sync_polarity;
1094 int v_sync_polarity;
1095 struct display_timing crtc;
1096};
1097
1098struct io_reg {
1099 int port;
1100 u8 index;
1101 u8 mask;
1102 u8 value;
1103};
1104
1105#endif /* __SHARE_H__ */
diff --git a/drivers/video/via/tbl1636.c b/drivers/video/via/tbl1636.c
new file mode 100644
index 000000000000..2d8453429d4a
--- /dev/null
+++ b/drivers/video/via/tbl1636.c
@@ -0,0 +1,71 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#include "global.h"
23struct IODATA COMMON_INIT_TBL_VT1636[] = {
24/* Index, Mask, Value */
25 /* Set panel power sequence timing */
26 {0x10, 0xC0, 0x00},
27 /* T1: VDD on - Data on. Each increment is 1 ms. (50ms = 031h) */
28 {0x0B, 0xFF, 0x40},
29 /* T2: Data on - Backlight on. Each increment is 2 ms. (210ms = 068h) */
30 {0x0C, 0xFF, 0x31},
31 /* T3: Backlight off -Data off. Each increment is 2 ms. (210ms = 068h)*/
32 {0x0D, 0xFF, 0x31},
33 /* T4: Data off - VDD off. Each increment is 1 ms. (50ms = 031h) */
34 {0x0E, 0xFF, 0x68},
35 /* T5: VDD off - VDD on. Each increment is 100 ms. (500ms = 04h) */
36 {0x0F, 0xFF, 0x68},
37 /* LVDS output power up */
38 {0x09, 0xA0, 0xA0},
39 /* turn on back light */
40 {0x10, 0x33, 0x13}
41};
42
43struct IODATA DUAL_CHANNEL_ENABLE_TBL_VT1636[] = {
44/* Index, Mask, Value */
45 {0x08, 0xF0, 0xE0} /* Input Data Mode Select */
46};
47
48struct IODATA SINGLE_CHANNEL_ENABLE_TBL_VT1636[] = {
49/* Index, Mask, Value */
50 {0x08, 0xF0, 0x00} /* Input Data Mode Select */
51};
52
53struct IODATA DITHERING_ENABLE_TBL_VT1636[] = {
54/* Index, Mask, Value */
55 {0x0A, 0x70, 0x50}
56};
57
58struct IODATA DITHERING_DISABLE_TBL_VT1636[] = {
59/* Index, Mask, Value */
60 {0x0A, 0x70, 0x00}
61};
62
63struct IODATA VDD_ON_TBL_VT1636[] = {
64/* Index, Mask, Value */
65 {0x10, 0x20, 0x20}
66};
67
68struct IODATA VDD_OFF_TBL_VT1636[] = {
69/* Index, Mask, Value */
70 {0x10, 0x20, 0x00}
71};
diff --git a/drivers/video/via/tbl1636.h b/drivers/video/via/tbl1636.h
new file mode 100644
index 000000000000..d906055f1511
--- /dev/null
+++ b/drivers/video/via/tbl1636.h
@@ -0,0 +1,34 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#ifndef _TBL1636_H_
23#define _TBL1636_H_
24#include "hw.h"
25
26extern struct IODATA COMMON_INIT_TBL_VT1636[8];
27extern struct IODATA DUAL_CHANNEL_ENABLE_TBL_VT1636[1];
28extern struct IODATA SINGLE_CHANNEL_ENABLE_TBL_VT1636[1];
29extern struct IODATA DITHERING_ENABLE_TBL_VT1636[1];
30extern struct IODATA DITHERING_DISABLE_TBL_VT1636[1];
31extern struct IODATA VDD_ON_TBL_VT1636[1];
32extern struct IODATA VDD_OFF_TBL_VT1636[1];
33
34#endif /* _VIA_TBL1636_H_ */
diff --git a/drivers/video/via/tblDPASetting.c b/drivers/video/via/tblDPASetting.c
new file mode 100644
index 000000000000..0c4c8cc712f4
--- /dev/null
+++ b/drivers/video/via/tblDPASetting.c
@@ -0,0 +1,109 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#include "global.h"
23/* For VT3324: */
24struct VT1636_DPA_SETTING VT1636_DPA_SETTING_TBL_VT3324[] = {
25 /* Panel ID, CLK_SEL_ST1[09], CLK_SEL_ST2[08] */
26 {LCD_PANEL_ID0_640X480, 0x00, 0x00}, /* For 640x480 */
27 {LCD_PANEL_ID1_800X600, 0x00, 0x00}, /* For 800x600 */
28 {LCD_PANEL_ID2_1024X768, 0x00, 0x00}, /* For 1024x768 */
29 {LCD_PANEL_ID3_1280X768, 0x00, 0x00}, /* For 1280x768 */
30 {LCD_PANEL_ID4_1280X1024, 0x00, 0x00}, /* For 1280x1024 */
31 {LCD_PANEL_ID5_1400X1050, 0x00, 0x00}, /* For 1400x1050 */
32 {LCD_PANEL_ID6_1600X1200, 0x0B, 0x03} /* For 1600x1200 */
33};
34
35struct GFX_DPA_SETTING GFX_DPA_SETTING_TBL_VT3324[] = {
36/* ClkRange, DVP0, DVP0DataDriving, DVP0ClockDriving, DVP1,
37 DVP1Driving, DFPHigh, DFPLow */
38/* CR96, SR2A[5], SR1B[1], SR2A[4], SR1E[2], CR9B,
39 SR65, CR97, CR99 */
40 /* LCK/VCK < 30000000 will use this value */
41 {DPA_CLK_RANGE_30M, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
42 0x00},
43 /* 30000000 < LCK/VCK < 50000000 will use this value */
44 {DPA_CLK_RANGE_30_50M, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00,
45 0x00},
46 /* 50000000 < LCK/VCK < 70000000 will use this value */
47 {DPA_CLK_RANGE_50_70M, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
48 0x00},
49 /* 70000000 < LCK/VCK < 100000000 will use this value */
50 {DPA_CLK_RANGE_70_100M, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
51 0x00},
52 /* 100000000 < LCK/VCK < 15000000 will use this value */
53 {DPA_CLK_RANGE_100_150M, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00,
54 0x00},
55 /* 15000000 < LCK/VCK will use this value */
56 {DPA_CLK_RANGE_150M, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x0E, 0x00,
57 0x00},
58};
59
60/* For VT3327: */
61struct VT1636_DPA_SETTING VT1636_DPA_SETTING_TBL_VT3327[] = {
62 /* Panel ID, CLK_SEL_ST1[09], CLK_SEL_ST2[08] */
63 {LCD_PANEL_ID0_640X480, 0x00, 0x00}, /* For 640x480 */
64 {LCD_PANEL_ID1_800X600, 0x00, 0x00}, /* For 800x600 */
65 {LCD_PANEL_ID2_1024X768, 0x00, 0x00}, /* For 1024x768 */
66 {LCD_PANEL_ID3_1280X768, 0x00, 0x00}, /* For 1280x768 */
67 {LCD_PANEL_ID4_1280X1024, 0x00, 0x00}, /* For 1280x1024 */
68 {LCD_PANEL_ID5_1400X1050, 0x00, 0x00}, /* For 1400x1050 */
69 {LCD_PANEL_ID6_1600X1200, 0x00, 0x00} /* For 1600x1200 */
70};
71
72struct GFX_DPA_SETTING GFX_DPA_SETTING_TBL_VT3327[] = {
73/* ClkRange,DVP0, DVP0DataDriving, DVP0ClockDriving, DVP1,
74 DVP1Driving, DFPHigh, DFPLow */
75/* CR96, SR2A[5], SR1B[1], SR2A[4], SR1E[2], CR9B,
76 SR65, CR97, CR99 */
77/* LCK/VCK < 30000000 will use this value */
78{DPA_CLK_RANGE_30M, 0x07, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 0x01},
79/* 30000000 < LCK/VCK < 50000000 will use this value */
80{DPA_CLK_RANGE_30_50M, 0x07, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 0x01},
81/* 50000000 < LCK/VCK < 70000000 will use this value */
82{DPA_CLK_RANGE_50_70M, 0x06, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 0x01},
83/* 70000000 < LCK/VCK < 100000000 will use this value */
84{DPA_CLK_RANGE_70_100M, 0x03, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x08, 0x03},
85/* 100000000 < LCK/VCK < 15000000 will use this value */
86{DPA_CLK_RANGE_100_150M, 0x03, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x01, 0x02},
87/* 15000000 < LCK/VCK will use this value */
88{DPA_CLK_RANGE_150M, 0x00, 0x20, 0x00, 0x10, 0x00, 0x03, 0x00, 0x0D, 0x03},
89};
90
91/* For VT3364: */
92struct GFX_DPA_SETTING GFX_DPA_SETTING_TBL_VT3364[] = {
93/* ClkRange,DVP0, DVP0DataDriving, DVP0ClockDriving, DVP1,
94 DVP1Driving, DFPHigh, DFPLow */
95/* CR96, SR2A[5], SR1B[1], SR2A[4], SR1E[2], CR9B,
96 SR65, CR97, CR99 */
97/* LCK/VCK < 30000000 will use this value */
98{DPA_CLK_RANGE_30M, 0x07, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x08},
99/* 30000000 < LCK/VCK < 50000000 will use this value */
100{DPA_CLK_RANGE_30_50M, 0x07, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x08},
101/* 50000000 < LCK/VCK < 70000000 will use this value */
102{DPA_CLK_RANGE_50_70M, 0x07, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x08},
103/* 70000000 < LCK/VCK < 100000000 will use this value */
104{DPA_CLK_RANGE_70_100M, 0x07, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x08},
105/* 100000000 < LCK/VCK < 15000000 will use this value */
106{DPA_CLK_RANGE_100_150M, 0x03, 0x00, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x08},
107/* 15000000 < LCK/VCK will use this value */
108{DPA_CLK_RANGE_150M, 0x01, 0x00, 0x02, 0x10, 0x00, 0x03, 0x00, 0x00, 0x08},
109};
diff --git a/drivers/video/via/tblDPASetting.h b/drivers/video/via/tblDPASetting.h
new file mode 100644
index 000000000000..b065a83481d3
--- /dev/null
+++ b/drivers/video/via/tblDPASetting.h
@@ -0,0 +1,47 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#ifndef _TBLDPASETTING_H_
23#define _TBLDPASETTING_H_
24#include "global.h"
25
26#define DPA_CLK_30M 30000000
27#define DPA_CLK_50M 50000000
28#define DPA_CLK_70M 70000000
29#define DPA_CLK_100M 100000000
30#define DPA_CLK_150M 150000000
31
32enum DPA_RANGE {
33 DPA_CLK_RANGE_30M,
34 DPA_CLK_RANGE_30_50M,
35 DPA_CLK_RANGE_50_70M,
36 DPA_CLK_RANGE_70_100M,
37 DPA_CLK_RANGE_100_150M,
38 DPA_CLK_RANGE_150M
39};
40
41extern struct VT1636_DPA_SETTING VT1636_DPA_SETTING_TBL_VT3324[7];
42extern struct GFX_DPA_SETTING GFX_DPA_SETTING_TBL_VT3324[6];
43extern struct VT1636_DPA_SETTING VT1636_DPA_SETTING_TBL_VT3327[7];
44extern struct GFX_DPA_SETTING GFX_DPA_SETTING_TBL_VT3327[];
45extern struct GFX_DPA_SETTING GFX_DPA_SETTING_TBL_VT3364[6];
46
47#endif
diff --git a/drivers/video/via/via_i2c.c b/drivers/video/via/via_i2c.c
new file mode 100644
index 000000000000..0f3ed4eb236d
--- /dev/null
+++ b/drivers/video/via/via_i2c.c
@@ -0,0 +1,177 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#include "global.h"
23
24static void via_i2c_setscl(void *data, int state)
25{
26 u8 val;
27 struct via_i2c_stuff *via_i2c_chan = (struct via_i2c_stuff *)data;
28
29 val = viafb_read_reg(VIASR, via_i2c_chan->i2c_port) & 0xF0;
30 if (state)
31 val |= 0x20;
32 else
33 val &= ~0x20;
34 switch (via_i2c_chan->i2c_port) {
35 case I2CPORTINDEX:
36 val |= 0x01;
37 break;
38 case GPIOPORTINDEX:
39 val |= 0x80;
40 break;
41 default:
42 DEBUG_MSG("via_i2c: specify wrong i2c port.\n");
43 }
44 viafb_write_reg(via_i2c_chan->i2c_port, VIASR, val);
45}
46
47static int via_i2c_getscl(void *data)
48{
49 struct via_i2c_stuff *via_i2c_chan = (struct via_i2c_stuff *)data;
50
51 if (viafb_read_reg(VIASR, via_i2c_chan->i2c_port) & 0x08)
52 return 1;
53 return 0;
54}
55
56static int via_i2c_getsda(void *data)
57{
58 struct via_i2c_stuff *via_i2c_chan = (struct via_i2c_stuff *)data;
59
60 if (viafb_read_reg(VIASR, via_i2c_chan->i2c_port) & 0x04)
61 return 1;
62 return 0;
63}
64
65static void via_i2c_setsda(void *data, int state)
66{
67 u8 val;
68 struct via_i2c_stuff *via_i2c_chan = (struct via_i2c_stuff *)data;
69
70 val = viafb_read_reg(VIASR, via_i2c_chan->i2c_port) & 0xF0;
71 if (state)
72 val |= 0x10;
73 else
74 val &= ~0x10;
75 switch (via_i2c_chan->i2c_port) {
76 case I2CPORTINDEX:
77 val |= 0x01;
78 break;
79 case GPIOPORTINDEX:
80 val |= 0x40;
81 break;
82 default:
83 DEBUG_MSG("via_i2c: specify wrong i2c port.\n");
84 }
85 viafb_write_reg(via_i2c_chan->i2c_port, VIASR, val);
86}
87
88int viafb_i2c_readbyte(u8 slave_addr, u8 index, u8 *pdata)
89{
90 u8 mm1[] = {0x00};
91 struct i2c_msg msgs[2];
92
93 *pdata = 0;
94 msgs[0].flags = 0;
95 msgs[1].flags = I2C_M_RD;
96 msgs[0].addr = msgs[1].addr = slave_addr / 2;
97 mm1[0] = index;
98 msgs[0].len = 1; msgs[1].len = 1;
99 msgs[0].buf = mm1; msgs[1].buf = pdata;
100 i2c_transfer(&viaparinfo->i2c_stuff.adapter, msgs, 2);
101
102 return 0;
103}
104
105int viafb_i2c_writebyte(u8 slave_addr, u8 index, u8 data)
106{
107 u8 msg[2] = { index, data };
108 struct i2c_msg msgs;
109
110 msgs.flags = 0;
111 msgs.addr = slave_addr / 2;
112 msgs.len = 2;
113 msgs.buf = msg;
114 return i2c_transfer(&viaparinfo->i2c_stuff.adapter, &msgs, 1);
115}
116
117int viafb_i2c_readbytes(u8 slave_addr, u8 index, u8 *buff, int buff_len)
118{
119 u8 mm1[] = {0x00};
120 struct i2c_msg msgs[2];
121
122 msgs[0].flags = 0;
123 msgs[1].flags = I2C_M_RD;
124 msgs[0].addr = msgs[1].addr = slave_addr / 2;
125 mm1[0] = index;
126 msgs[0].len = 1; msgs[1].len = buff_len;
127 msgs[0].buf = mm1; msgs[1].buf = buff;
128 i2c_transfer(&viaparinfo->i2c_stuff.adapter, msgs, 2);
129 return 0;
130}
131
132int viafb_create_i2c_bus(void *viapar)
133{
134 int ret;
135 struct viafb_par *par = (struct viafb_par *)viapar;
136
137 strcpy(par->i2c_stuff.adapter.name, "via_i2c");
138 par->i2c_stuff.i2c_port = 0x0;
139 par->i2c_stuff.adapter.owner = THIS_MODULE;
140 par->i2c_stuff.adapter.id = 0x01FFFF;
141 par->i2c_stuff.adapter.class = 0;
142 par->i2c_stuff.adapter.algo_data = &par->i2c_stuff.algo;
143 par->i2c_stuff.adapter.dev.parent = NULL;
144 par->i2c_stuff.algo.setsda = via_i2c_setsda;
145 par->i2c_stuff.algo.setscl = via_i2c_setscl;
146 par->i2c_stuff.algo.getsda = via_i2c_getsda;
147 par->i2c_stuff.algo.getscl = via_i2c_getscl;
148 par->i2c_stuff.algo.udelay = 40;
149 par->i2c_stuff.algo.timeout = 20;
150 par->i2c_stuff.algo.data = &par->i2c_stuff;
151
152 i2c_set_adapdata(&par->i2c_stuff.adapter, &par->i2c_stuff);
153
154 /* Raise SCL and SDA */
155 par->i2c_stuff.i2c_port = I2CPORTINDEX;
156 via_i2c_setsda(&par->i2c_stuff, 1);
157 via_i2c_setscl(&par->i2c_stuff, 1);
158
159 par->i2c_stuff.i2c_port = GPIOPORTINDEX;
160 via_i2c_setsda(&par->i2c_stuff, 1);
161 via_i2c_setscl(&par->i2c_stuff, 1);
162 udelay(20);
163
164 ret = i2c_bit_add_bus(&par->i2c_stuff.adapter);
165 if (ret == 0)
166 DEBUG_MSG("I2C bus %s registered.\n",
167 par->i2c_stuff.adapter.name);
168 else
169 DEBUG_MSG("Failed to register I2C bus %s.\n",
170 par->i2c_stuff.adapter.name);
171 return ret;
172}
173
174void viafb_delete_i2c_buss(void *par)
175{
176 i2c_del_adapter(&((struct viafb_par *)par)->i2c_stuff.adapter);
177}
diff --git a/drivers/video/via/via_i2c.h b/drivers/video/via/via_i2c.h
new file mode 100644
index 000000000000..3a13242a3152
--- /dev/null
+++ b/drivers/video/via/via_i2c.h
@@ -0,0 +1,46 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21#ifndef __VIA_I2C_H__
22#define __VIA_I2C_H__
23
24#include <linux/i2c.h>
25#include <linux/i2c-algo-bit.h>
26
27struct via_i2c_stuff {
28 u16 i2c_port; /* GPIO or I2C port */
29 struct i2c_adapter adapter;
30 struct i2c_algo_bit_data algo;
31};
32
33#define I2CPORT 0x3c4
34#define I2CPORTINDEX 0x31
35#define GPIOPORT 0x3C4
36#define GPIOPORTINDEX 0x2C
37#define I2C_BUS 1
38#define GPIO_BUS 2
39#define DELAYPORT 0x3C3
40
41int viafb_i2c_readbyte(u8 slave_addr, u8 index, u8 *pdata);
42int viafb_i2c_writebyte(u8 slave_addr, u8 index, u8 data);
43int viafb_i2c_readbytes(u8 slave_addr, u8 index, u8 *buff, int buff_len);
44int viafb_create_i2c_bus(void *par);
45void viafb_delete_i2c_buss(void *par);
46#endif /* __VIA_I2C_H__ */
diff --git a/drivers/video/via/via_utility.c b/drivers/video/via/via_utility.c
new file mode 100644
index 000000000000..d53c3d54ed8e
--- /dev/null
+++ b/drivers/video/via/via_utility.c
@@ -0,0 +1,253 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#include "global.h"
23
24void viafb_get_device_support_state(u32 *support_state)
25{
26 *support_state = CRT_Device;
27
28 if (viaparinfo->chip_info->tmds_chip_info.tmds_chip_name == VT1632_TMDS)
29 *support_state |= DVI_Device;
30
31 if (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name == VT1631_LVDS)
32 *support_state |= LCD_Device;
33}
34
35void viafb_get_device_connect_state(u32 *connect_state)
36{
37 bool mobile = false;
38
39 *connect_state = CRT_Device;
40
41 if (viafb_dvi_sense())
42 *connect_state |= DVI_Device;
43
44 viafb_lcd_get_mobile_state(&mobile);
45 if (mobile)
46 *connect_state |= LCD_Device;
47}
48
49bool viafb_lcd_get_support_expand_state(u32 xres, u32 yres)
50{
51 unsigned int support_state = 0;
52
53 switch (viafb_lcd_panel_id) {
54 case LCD_PANEL_ID0_640X480:
55 if ((xres < 640) && (yres < 480))
56 support_state = true;
57 break;
58
59 case LCD_PANEL_ID1_800X600:
60 if ((xres < 800) && (yres < 600))
61 support_state = true;
62 break;
63
64 case LCD_PANEL_ID2_1024X768:
65 if ((xres < 1024) && (yres < 768))
66 support_state = true;
67 break;
68
69 case LCD_PANEL_ID3_1280X768:
70 if ((xres < 1280) && (yres < 768))
71 support_state = true;
72 break;
73
74 case LCD_PANEL_ID4_1280X1024:
75 if ((xres < 1280) && (yres < 1024))
76 support_state = true;
77 break;
78
79 case LCD_PANEL_ID5_1400X1050:
80 if ((xres < 1400) && (yres < 1050))
81 support_state = true;
82 break;
83
84 case LCD_PANEL_ID6_1600X1200:
85 if ((xres < 1600) && (yres < 1200))
86 support_state = true;
87 break;
88
89 case LCD_PANEL_ID7_1366X768:
90 if ((xres < 1366) && (yres < 768))
91 support_state = true;
92 break;
93
94 case LCD_PANEL_ID8_1024X600:
95 if ((xres < 1024) && (yres < 600))
96 support_state = true;
97 break;
98
99 case LCD_PANEL_ID9_1280X800:
100 if ((xres < 1280) && (yres < 800))
101 support_state = true;
102 break;
103
104 case LCD_PANEL_IDA_800X480:
105 if ((xres < 800) && (yres < 480))
106 support_state = true;
107 break;
108
109 case LCD_PANEL_IDB_1360X768:
110 if ((xres < 1360) && (yres < 768))
111 support_state = true;
112 break;
113
114 case LCD_PANEL_IDC_480X640:
115 if ((xres < 480) && (yres < 640))
116 support_state = true;
117 break;
118
119 default:
120 support_state = false;
121 break;
122 }
123
124 return support_state;
125}
126
127/*====================================================================*/
128/* Gamma Function Implementation*/
129/*====================================================================*/
130
131void viafb_set_gamma_table(int bpp, unsigned int *gamma_table)
132{
133 int i, sr1a;
134 int active_device_amount = 0;
135 int device_status = viafb_DeviceStatus;
136
137 for (i = 0; i < sizeof(viafb_DeviceStatus) * 8; i++) {
138 if (device_status & 1)
139 active_device_amount++;
140 device_status >>= 1;
141 }
142
143 /* 8 bpp mode can't adjust gamma */
144 if (bpp == 8)
145 return ;
146
147 /* Enable Gamma */
148 switch (viaparinfo->chip_info->gfx_chip_name) {
149 case UNICHROME_CLE266:
150 case UNICHROME_K400:
151 viafb_write_reg_mask(SR16, VIASR, 0x80, BIT7);
152 break;
153
154 case UNICHROME_K800:
155 case UNICHROME_PM800:
156 case UNICHROME_CN700:
157 case UNICHROME_CX700:
158 case UNICHROME_K8M890:
159 case UNICHROME_P4M890:
160 case UNICHROME_P4M900:
161 viafb_write_reg_mask(CR33, VIACR, 0x80, BIT7);
162 break;
163 }
164 sr1a = (unsigned int)viafb_read_reg(VIASR, SR1A);
165 viafb_write_reg_mask(SR1A, VIASR, 0x0, BIT0);
166
167 /* Fill IGA1 Gamma Table */
168 outb(0, LUT_INDEX_WRITE);
169 for (i = 0; i < 256; i++) {
170 outb(gamma_table[i] >> 16, LUT_DATA);
171 outb(gamma_table[i] >> 8 & 0xFF, LUT_DATA);
172 outb(gamma_table[i] & 0xFF, LUT_DATA);
173 }
174
175 /* If adjust Gamma value in SAMM, fill IGA1,
176 IGA2 Gamma table simultanous. */
177 /* Switch to IGA2 Gamma Table */
178 if ((active_device_amount > 1) &&
179 !((viaparinfo->chip_info->gfx_chip_name ==
180 UNICHROME_CLE266) &&
181 (viaparinfo->chip_info->gfx_chip_revision < 15))) {
182 viafb_write_reg_mask(SR1A, VIASR, 0x01, BIT0);
183 viafb_write_reg_mask(CR6A, VIACR, 0x02, BIT1);
184
185 /* Fill IGA2 Gamma Table */
186 outb(0, LUT_INDEX_WRITE);
187 for (i = 0; i < 256; i++) {
188 outb(gamma_table[i] >> 16, LUT_DATA);
189 outb(gamma_table[i] >> 8 & 0xFF, LUT_DATA);
190 outb(gamma_table[i] & 0xFF, LUT_DATA);
191 }
192 }
193 viafb_write_reg(SR1A, VIASR, sr1a);
194}
195
196void viafb_get_gamma_table(unsigned int *gamma_table)
197{
198 unsigned char color_r, color_g, color_b;
199 unsigned char sr1a = 0;
200 int i;
201
202 /* Enable Gamma */
203 switch (viaparinfo->chip_info->gfx_chip_name) {
204 case UNICHROME_CLE266:
205 case UNICHROME_K400:
206 viafb_write_reg_mask(SR16, VIASR, 0x80, BIT7);
207 break;
208
209 case UNICHROME_K800:
210 case UNICHROME_PM800:
211 case UNICHROME_CN700:
212 case UNICHROME_CX700:
213 case UNICHROME_K8M890:
214 case UNICHROME_P4M890:
215 case UNICHROME_P4M900:
216 viafb_write_reg_mask(CR33, VIACR, 0x80, BIT7);
217 break;
218 }
219 sr1a = viafb_read_reg(VIASR, SR1A);
220 viafb_write_reg_mask(SR1A, VIASR, 0x0, BIT0);
221
222 /* Reading gamma table to get color value */
223 outb(0, LUT_INDEX_READ);
224 for (i = 0; i < 256; i++) {
225 color_r = inb(LUT_DATA);
226 color_g = inb(LUT_DATA);
227 color_b = inb(LUT_DATA);
228 gamma_table[i] =
229 ((((u32) color_r) << 16) |
230 (((u16) color_g) << 8)) | color_b;
231 }
232 viafb_write_reg(SR1A, VIASR, sr1a);
233}
234
235void viafb_get_gamma_support_state(int bpp, unsigned int *support_state)
236{
237 if (bpp == 8)
238 *support_state = None_Device;
239 else
240 *support_state = CRT_Device | DVI_Device | LCD_Device;
241}
242
243int viafb_input_parameter_converter(int parameter_value)
244{
245 int result;
246
247 if (parameter_value >= 1 && parameter_value <= 9)
248 result = 1 << (parameter_value - 1);
249 else
250 result = 1;
251
252 return result;
253}
diff --git a/drivers/video/via/via_utility.h b/drivers/video/via/via_utility.h
new file mode 100644
index 000000000000..2fd455202ebd
--- /dev/null
+++ b/drivers/video/via/via_utility.h
@@ -0,0 +1,35 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21#ifndef __VIAUTILITY_H__
22#define __VIAUTILITY_H__
23
24/* These functions are used to get infomation about device's state */
25void viafb_get_device_support_state(u32 *support_state);
26void viafb_get_device_connect_state(u32 *connect_state);
27bool viafb_lcd_get_support_expand_state(u32 xres, u32 yres);
28
29/* These function are used to access gamma table */
30void viafb_set_gamma_table(int bpp, unsigned int *gamma_table);
31void viafb_get_gamma_table(unsigned int *gamma_table);
32void viafb_get_gamma_support_state(int bpp, unsigned int *support_state);
33int viafb_input_parameter_converter(int parameter_value);
34
35#endif /* __VIAUTILITY_H__ */
diff --git a/drivers/video/via/viafbdev.c b/drivers/video/via/viafbdev.c
new file mode 100644
index 000000000000..0132eae06f55
--- /dev/null
+++ b/drivers/video/via/viafbdev.c
@@ -0,0 +1,2571 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#include <linux/module.h>
23#define _MASTER_FILE
24
25#include "global.h"
26
27static int MAX_CURS = 32;
28static struct fb_var_screeninfo default_var;
29static char *viafb_name = "Via";
30static u32 pseudo_pal[17];
31
32/* video mode */
33static char *viafb_mode = "640x480";
34static char *viafb_mode1 = "640x480";
35static int viafb_resMode = VIA_RES_640X480;
36
37/* Added for specifying active devices.*/
38char *viafb_active_dev = "";
39
40/* Added for specifying video on devices.*/
41char *viafb_video_dev = "";
42
43/*Added for specify lcd output port*/
44char *viafb_lcd_port = "";
45char *viafb_dvi_port = "";
46
47static void viafb_set_device(struct device_t active_dev);
48static int apply_device_setting(struct viafb_ioctl_setting setting_info,
49 struct fb_info *info);
50static void apply_second_mode_setting(struct fb_var_screeninfo
51 *sec_var);
52static void retrieve_device_setting(struct viafb_ioctl_setting
53 *setting_info);
54static void viafb_set_video_device(u32 video_dev_info);
55static void viafb_get_video_device(u32 *video_dev_info);
56
57/* Mode information */
58static const struct viafb_modeinfo viafb_modentry[] = {
59 {480, 640, VIA_RES_480X640, "480x640"},
60 {640, 480, VIA_RES_640X480, "640x480"},
61 {800, 480, VIA_RES_800X480, "800x480"},
62 {800, 600, VIA_RES_800X600, "800x600"},
63 {1024, 768, VIA_RES_1024X768, "1024x768"},
64 {1152, 864, VIA_RES_1152X864, "1152x864"},
65 {1280, 1024, VIA_RES_1280X1024, "1280x1024"},
66 {1600, 1200, VIA_RES_1600X1200, "1600x1200"},
67 {1440, 1050, VIA_RES_1440X1050, "1440x1050"},
68 {1280, 768, VIA_RES_1280X768, "1280x768"},
69 {1280, 800, VIA_RES_1280X800, "1280x800"},
70 {1280, 960, VIA_RES_1280X960, "1280x960"},
71 {1920, 1440, VIA_RES_1920X1440, "1920x1440"},
72 {848, 480, VIA_RES_848X480, "848x480"},
73 {1400, 1050, VIA_RES_1400X1050, "1400x1050"},
74 {720, 480, VIA_RES_720X480, "720x480"},
75 {720, 576, VIA_RES_720X576, "720x576"},
76 {1024, 512, VIA_RES_1024X512, "1024x512"},
77 {1024, 576, VIA_RES_1024X576, "1024x576"},
78 {1024, 600, VIA_RES_1024X600, "1024x600"},
79 {1280, 720, VIA_RES_1280X720, "1280x720"},
80 {1920, 1080, VIA_RES_1920X1080, "1920x1080"},
81 {1366, 768, VIA_RES_1368X768, "1368x768"},
82 {1680, 1050, VIA_RES_1680X1050, "1680x1050"},
83 {960, 600, VIA_RES_960X600, "960x600"},
84 {1000, 600, VIA_RES_1000X600, "1000x600"},
85 {1024, 576, VIA_RES_1024X576, "1024x576"},
86 {1024, 600, VIA_RES_1024X600, "1024x600"},
87 {1088, 612, VIA_RES_1088X612, "1088x612"},
88 {1152, 720, VIA_RES_1152X720, "1152x720"},
89 {1200, 720, VIA_RES_1200X720, "1200x720"},
90 {1280, 600, VIA_RES_1280X600, "1280x600"},
91 {1360, 768, VIA_RES_1360X768, "1360x768"},
92 {1440, 900, VIA_RES_1440X900, "1440x900"},
93 {1600, 900, VIA_RES_1600X900, "1600x900"},
94 {1600, 1024, VIA_RES_1600X1024, "1600x1024"},
95 {1792, 1344, VIA_RES_1792X1344, "1792x1344"},
96 {1856, 1392, VIA_RES_1856X1392, "1856x1392"},
97 {1920, 1200, VIA_RES_1920X1200, "1920x1200"},
98 {2048, 1536, VIA_RES_2048X1536, "2048x1536"},
99 {0, 0, VIA_RES_INVALID, "640x480"}
100};
101
102static struct fb_ops viafb_ops;
103
104static int viafb_update_fix(struct fb_fix_screeninfo *fix, struct fb_info *info)
105{
106 struct viafb_par *ppar;
107 ppar = info->par;
108
109 DEBUG_MSG(KERN_INFO "viafb_update_fix!\n");
110
111 fix->visual =
112 ppar->bpp == 8 ? FB_VISUAL_PSEUDOCOLOR : FB_VISUAL_TRUECOLOR;
113 fix->line_length = ppar->linelength;
114
115 return 0;
116}
117
118
119static void viafb_setup_fixinfo(struct fb_fix_screeninfo *fix,
120 struct viafb_par *viaparinfo)
121{
122 memset(fix, 0, sizeof(struct fb_fix_screeninfo));
123 strcpy(fix->id, viafb_name);
124
125 fix->smem_start = viaparinfo->fbmem;
126 fix->smem_len = viaparinfo->fbmem_free;
127 fix->mmio_start = viaparinfo->mmio_base;
128 fix->mmio_len = viaparinfo->mmio_len;
129
130 fix->type = FB_TYPE_PACKED_PIXELS;
131 fix->type_aux = 0;
132
133 fix->xpanstep = fix->ywrapstep = 0;
134 fix->ypanstep = 1;
135
136 /* Just tell the accel name */
137 viafbinfo->fix.accel = FB_ACCEL_VIA_UNICHROME;
138}
139static int viafb_open(struct fb_info *info, int user)
140{
141 DEBUG_MSG(KERN_INFO "viafb_open!\n");
142 return 0;
143}
144
145static int viafb_release(struct fb_info *info, int user)
146{
147 DEBUG_MSG(KERN_INFO "viafb_release!\n");
148 return 0;
149}
150
151static void viafb_update_viafb_par(struct fb_info *info)
152{
153 struct viafb_par *ppar;
154
155 ppar = info->par;
156 ppar->bpp = info->var.bits_per_pixel;
157 ppar->linelength = ((info->var.xres_virtual + 7) & ~7) * ppar->bpp / 8;
158 ppar->hres = info->var.xres;
159 ppar->vres = info->var.yres;
160 ppar->xoffset = info->var.xoffset;
161 ppar->yoffset = info->var.yoffset;
162}
163
164static int viafb_check_var(struct fb_var_screeninfo *var,
165 struct fb_info *info)
166{
167 int vmode_index, htotal, vtotal;
168 struct viafb_par *ppar;
169 u32 long_refresh;
170 struct viafb_par *p_viafb_par;
171 ppar = info->par;
172
173
174 DEBUG_MSG(KERN_INFO "viafb_check_var!\n");
175 /* Sanity check */
176 /* HW neither support interlacte nor double-scaned mode */
177 if (var->vmode & FB_VMODE_INTERLACED || var->vmode & FB_VMODE_DOUBLE)
178 return -EINVAL;
179
180 vmode_index = viafb_get_mode_index(var->xres, var->yres, 0);
181 if (vmode_index == VIA_RES_INVALID) {
182 DEBUG_MSG(KERN_INFO
183 "viafb: Mode %dx%dx%d not supported!!\n",
184 var->xres, var->yres, var->bits_per_pixel);
185 return -EINVAL;
186 }
187
188 if (24 == var->bits_per_pixel)
189 var->bits_per_pixel = 32;
190
191 if (var->bits_per_pixel != 8 && var->bits_per_pixel != 16 &&
192 var->bits_per_pixel != 32)
193 return -EINVAL;
194
195 if ((var->xres_virtual * (var->bits_per_pixel >> 3)) & 0x1F)
196 /*32 pixel alignment */
197 var->xres_virtual = (var->xres_virtual + 31) & ~31;
198 if (var->xres_virtual * var->yres_virtual * var->bits_per_pixel / 8 >
199 ppar->memsize)
200 return -EINVAL;
201
202 /* Based on var passed in to calculate the refresh,
203 * because our driver use some modes special.
204 */
205 htotal = var->xres + var->left_margin +
206 var->right_margin + var->hsync_len;
207 vtotal = var->yres + var->upper_margin +
208 var->lower_margin + var->vsync_len;
209 long_refresh = 1000000000UL / var->pixclock * 1000;
210 long_refresh /= (htotal * vtotal);
211
212 viafb_refresh = viafb_get_refresh(var->xres, var->yres, long_refresh);
213
214 /* Adjust var according to our driver's own table */
215 viafb_fill_var_timing_info(var, viafb_refresh, vmode_index);
216
217 /* This is indeed a patch for VT3353 */
218 if (!info->par)
219 return -1;
220 p_viafb_par = (struct viafb_par *)info->par;
221 if (p_viafb_par->chip_info->gfx_chip_name == UNICHROME_VX800)
222 var->accel_flags = 0;
223
224 return 0;
225}
226
227static int viafb_set_par(struct fb_info *info)
228{
229 int vmode_index;
230 int vmode_index1 = 0;
231 DEBUG_MSG(KERN_INFO "viafb_set_par!\n");
232
233 viafb_update_device_setting(info->var.xres, info->var.yres,
234 info->var.bits_per_pixel, viafb_refresh, 0);
235
236 vmode_index = viafb_get_mode_index(info->var.xres, info->var.yres, 0);
237
238 if (viafb_SAMM_ON == 1) {
239 DEBUG_MSG(KERN_INFO
240 "viafb_second_xres = %d, viafb_second_yres = %d, bpp = %d\n",
241 viafb_second_xres, viafb_second_yres, viafb_bpp1);
242 vmode_index1 = viafb_get_mode_index(viafb_second_xres,
243 viafb_second_yres, 1);
244 DEBUG_MSG(KERN_INFO "->viafb_SAMM_ON: index=%d\n",
245 vmode_index1);
246
247 viafb_update_device_setting(viafb_second_xres,
248 viafb_second_yres, viafb_bpp1, viafb_refresh1, 1);
249 }
250
251 if (vmode_index != VIA_RES_INVALID) {
252 viafb_setmode(vmode_index, info->var.xres, info->var.yres,
253 info->var.bits_per_pixel, vmode_index1,
254 viafb_second_xres, viafb_second_yres, viafb_bpp1);
255
256 /*We should set memory offset according virtual_x */
257 /*Fix me:put this function into viafb_setmode */
258 viafb_memory_pitch_patch(info);
259
260 /* Update ***fb_par information */
261 viafb_update_viafb_par(info);
262
263 /* Update other fixed information */
264 viafb_update_fix(&info->fix, info);
265 viafb_bpp = info->var.bits_per_pixel;
266 /* Update viafb_accel, it is necessary to our 2D accelerate */
267 viafb_accel = info->var.accel_flags;
268
269 if (viafb_accel)
270 viafb_set_2d_color_depth(info->var.bits_per_pixel);
271 }
272
273 return 0;
274}
275
276/* Set one color register */
277static int viafb_setcolreg(unsigned regno, unsigned red, unsigned green,
278unsigned blue, unsigned transp, struct fb_info *info)
279{
280 u8 sr1a, sr1b, cr67, cr6a, rev = 0, shift = 10;
281 unsigned cmap_entries = (info->var.bits_per_pixel == 8) ? 256 : 16;
282 DEBUG_MSG(KERN_INFO "viafb_setcolreg!\n");
283 if (regno >= cmap_entries)
284 return 1;
285 if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name) {
286 /*
287 * Read PCI bus 0,dev 0,function 0,index 0xF6 to get chip rev.
288 */
289 outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8);
290 rev = (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff;
291 }
292 switch (info->var.bits_per_pixel) {
293 case 8:
294 outb(0x1A, 0x3C4);
295 sr1a = inb(0x3C5);
296 outb(0x1B, 0x3C4);
297 sr1b = inb(0x3C5);
298 outb(0x67, 0x3D4);
299 cr67 = inb(0x3D5);
300 outb(0x6A, 0x3D4);
301 cr6a = inb(0x3D5);
302
303 /* Map the 3C6/7/8/9 to the IGA2 */
304 outb(0x1A, 0x3C4);
305 outb(sr1a | 0x01, 0x3C5);
306 /* Second Display Engine colck always on */
307 outb(0x1B, 0x3C4);
308 outb(sr1b | 0x80, 0x3C5);
309 /* Second Display Color Depth 8 */
310 outb(0x67, 0x3D4);
311 outb(cr67 & 0x3F, 0x3D5);
312 outb(0x6A, 0x3D4);
313 /* Second Display Channel Reset CR6A[6]) */
314 outb(cr6a & 0xBF, 0x3D5);
315 /* Second Display Channel Enable CR6A[7] */
316 outb(cr6a | 0x80, 0x3D5);
317 /* Second Display Channel stop reset) */
318 outb(cr6a | 0x40, 0x3D5);
319
320 /* Bit mask of palette */
321 outb(0xFF, 0x3c6);
322 /* Write one register of IGA2 */
323 outb(regno, 0x3C8);
324 if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name &&
325 rev >= 15) {
326 shift = 8;
327 viafb_write_reg_mask(CR6A, VIACR, BIT5, BIT5);
328 viafb_write_reg_mask(SR15, VIASR, BIT7, BIT7);
329 } else {
330 shift = 10;
331 viafb_write_reg_mask(CR6A, VIACR, 0, BIT5);
332 viafb_write_reg_mask(SR15, VIASR, 0, BIT7);
333 }
334 outb(red >> shift, 0x3C9);
335 outb(green >> shift, 0x3C9);
336 outb(blue >> shift, 0x3C9);
337
338 /* Map the 3C6/7/8/9 to the IGA1 */
339 outb(0x1A, 0x3C4);
340 outb(sr1a & 0xFE, 0x3C5);
341 /* Bit mask of palette */
342 outb(0xFF, 0x3c6);
343 /* Write one register of IGA1 */
344 outb(regno, 0x3C8);
345 outb(red >> shift, 0x3C9);
346 outb(green >> shift, 0x3C9);
347 outb(blue >> shift, 0x3C9);
348
349 outb(0x1A, 0x3C4);
350 outb(sr1a, 0x3C5);
351 outb(0x1B, 0x3C4);
352 outb(sr1b, 0x3C5);
353 outb(0x67, 0x3D4);
354 outb(cr67, 0x3D5);
355 outb(0x6A, 0x3D4);
356 outb(cr6a, 0x3D5);
357 break;
358 case 16:
359 ((u32 *) info->pseudo_palette)[regno] = (red & 0xF800) |
360 ((green & 0xFC00) >> 5) | ((blue & 0xF800) >> 11);
361 break;
362 case 32:
363 ((u32 *) info->pseudo_palette)[regno] =
364 ((transp & 0xFF00) << 16) |
365 ((red & 0xFF00) << 8) |
366 ((green & 0xFF00)) | ((blue & 0xFF00) >> 8);
367 break;
368 }
369
370 return 0;
371
372}
373
374/*CALLED BY: fb_set_cmap */
375/* fb_set_var, pass 256 colors */
376/*CALLED BY: fb_set_cmap */
377/* fbcon_set_palette, pass 16 colors */
378static int viafb_setcmap(struct fb_cmap *cmap, struct fb_info *info)
379{
380 u32 len = cmap->len;
381 u32 i;
382 u16 *pred = cmap->red;
383 u16 *pgreen = cmap->green;
384 u16 *pblue = cmap->blue;
385 u16 *ptransp = cmap->transp;
386 u8 sr1a, sr1b, cr67, cr6a, rev = 0, shift = 10;
387 if (len > 256)
388 return 1;
389 if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name) {
390 /*
391 * Read PCI bus 0, dev 0, function 0, index 0xF6 to get chip
392 * rev.
393 */
394 outl(0x80000000 | (0xf6 & ~3), (unsigned long)0xCF8);
395 rev = (inl((unsigned long)0xCFC) >> ((0xf6 & 3) * 8)) & 0xff;
396 }
397 switch (info->var.bits_per_pixel) {
398 case 8:
399 outb(0x1A, 0x3C4);
400 sr1a = inb(0x3C5);
401 outb(0x1B, 0x3C4);
402 sr1b = inb(0x3C5);
403 outb(0x67, 0x3D4);
404 cr67 = inb(0x3D5);
405 outb(0x6A, 0x3D4);
406 cr6a = inb(0x3D5);
407 /* Map the 3C6/7/8/9 to the IGA2 */
408 outb(0x1A, 0x3C4);
409 outb(sr1a | 0x01, 0x3C5);
410 outb(0x1B, 0x3C4);
411 /* Second Display Engine colck always on */
412 outb(sr1b | 0x80, 0x3C5);
413 outb(0x67, 0x3D4);
414 /* Second Display Color Depth 8 */
415 outb(cr67 & 0x3F, 0x3D5);
416 outb(0x6A, 0x3D4);
417 /* Second Display Channel Reset CR6A[6]) */
418 outb(cr6a & 0xBF, 0x3D5);
419 /* Second Display Channel Enable CR6A[7] */
420 outb(cr6a | 0x80, 0x3D5);
421 /* Second Display Channel stop reset) */
422 outb(cr6a | 0xC0, 0x3D5);
423
424 /* Bit mask of palette */
425 outb(0xFF, 0x3c6);
426 outb(0x00, 0x3C8);
427 if (UNICHROME_CLE266 == viaparinfo->chip_info->gfx_chip_name &&
428 rev >= 15) {
429 shift = 8;
430 viafb_write_reg_mask(CR6A, VIACR, BIT5, BIT5);
431 viafb_write_reg_mask(SR15, VIASR, BIT7, BIT7);
432 } else {
433 shift = 10;
434 viafb_write_reg_mask(CR6A, VIACR, 0, BIT5);
435 viafb_write_reg_mask(SR15, VIASR, 0, BIT7);
436 }
437 for (i = 0; i < len; i++) {
438 outb((*(pred + i)) >> shift, 0x3C9);
439 outb((*(pgreen + i)) >> shift, 0x3C9);
440 outb((*(pblue + i)) >> shift, 0x3C9);
441 }
442
443 outb(0x1A, 0x3C4);
444 /* Map the 3C6/7/8/9 to the IGA1 */
445 outb(sr1a & 0xFE, 0x3C5);
446 /* Bit mask of palette */
447 outb(0xFF, 0x3c6);
448 outb(0x00, 0x3C8);
449 for (i = 0; i < len; i++) {
450 outb((*(pred + i)) >> shift, 0x3C9);
451 outb((*(pgreen + i)) >> shift, 0x3C9);
452 outb((*(pblue + i)) >> shift, 0x3C9);
453 }
454
455 outb(0x1A, 0x3C4);
456 outb(sr1a, 0x3C5);
457 outb(0x1B, 0x3C4);
458 outb(sr1b, 0x3C5);
459 outb(0x67, 0x3D4);
460 outb(cr67, 0x3D5);
461 outb(0x6A, 0x3D4);
462 outb(cr6a, 0x3D5);
463 break;
464 case 16:
465 if (len > 17)
466 return 0; /* Because static u32 pseudo_pal[17]; */
467 for (i = 0; i < len; i++)
468 ((u32 *) info->pseudo_palette)[i] =
469 (*(pred + i) & 0xF800) |
470 ((*(pgreen + i) & 0xFC00) >> 5) |
471 ((*(pblue + i) & 0xF800) >> 11);
472 break;
473 case 32:
474 if (len > 17)
475 return 0;
476 if (ptransp) {
477 for (i = 0; i < len; i++)
478 ((u32 *) info->pseudo_palette)[i] =
479 ((*(ptransp + i) & 0xFF00) << 16) |
480 ((*(pred + i) & 0xFF00) << 8) |
481 ((*(pgreen + i) & 0xFF00)) |
482 ((*(pblue + i) & 0xFF00) >> 8);
483 } else {
484 for (i = 0; i < len; i++)
485 ((u32 *) info->pseudo_palette)[i] =
486 0x00000000 |
487 ((*(pred + i) & 0xFF00) << 8) |
488 ((*(pgreen + i) & 0xFF00)) |
489 ((*(pblue + i) & 0xFF00) >> 8);
490 }
491 break;
492 }
493 return 0;
494}
495
496static int viafb_pan_display(struct fb_var_screeninfo *var,
497 struct fb_info *info)
498{
499 unsigned int offset;
500
501 DEBUG_MSG(KERN_INFO "viafb_pan_display!\n");
502
503 offset = (var->xoffset + (var->yoffset * var->xres_virtual)) *
504 var->bits_per_pixel / 16;
505
506 DEBUG_MSG(KERN_INFO "\nviafb_pan_display,offset =%d ", offset);
507
508 viafb_write_reg_mask(0x48, 0x3d4, ((offset >> 24) & 0x3), 0x3);
509 viafb_write_reg_mask(0x34, 0x3d4, ((offset >> 16) & 0xff), 0xff);
510 viafb_write_reg_mask(0x0c, 0x3d4, ((offset >> 8) & 0xff), 0xff);
511 viafb_write_reg_mask(0x0d, 0x3d4, (offset & 0xff), 0xff);
512
513 return 0;
514}
515
516static int viafb_blank(int blank_mode, struct fb_info *info)
517{
518 DEBUG_MSG(KERN_INFO "viafb_blank!\n");
519 /* clear DPMS setting */
520
521 switch (blank_mode) {
522 case FB_BLANK_UNBLANK:
523 /* Screen: On, HSync: On, VSync: On */
524 /* control CRT monitor power management */
525 viafb_write_reg_mask(CR36, VIACR, 0x00, BIT4 + BIT5);
526 break;
527 case FB_BLANK_HSYNC_SUSPEND:
528 /* Screen: Off, HSync: Off, VSync: On */
529 /* control CRT monitor power management */
530 viafb_write_reg_mask(CR36, VIACR, 0x10, BIT4 + BIT5);
531 break;
532 case FB_BLANK_VSYNC_SUSPEND:
533 /* Screen: Off, HSync: On, VSync: Off */
534 /* control CRT monitor power management */
535 viafb_write_reg_mask(CR36, VIACR, 0x20, BIT4 + BIT5);
536 break;
537 case FB_BLANK_POWERDOWN:
538 /* Screen: Off, HSync: Off, VSync: Off */
539 /* control CRT monitor power management */
540 viafb_write_reg_mask(CR36, VIACR, 0x30, BIT4 + BIT5);
541 break;
542 }
543
544 return 0;
545}
546
547static int viafb_ioctl(struct fb_info *info, u_int cmd, u_long arg)
548{
549 struct viafb_ioctl_mode viamode;
550 struct viafb_ioctl_samm viasamm;
551 struct viafb_driver_version driver_version;
552 struct fb_var_screeninfo sec_var;
553 struct _panel_size_pos_info panel_pos_size_para;
554 u32 state_info = 0;
555 u32 viainfo_size = sizeof(struct viafb_ioctl_info);
556 u32 *viafb_gamma_table;
557 char driver_name[] = "viafb";
558
559 u32 __user *argp = (u32 __user *) arg;
560 u32 gpu32;
561 u32 video_dev_info = 0;
562 struct viafb_ioctl_setting viafb_setting = {};
563 struct device_t active_dev = {};
564
565 DEBUG_MSG(KERN_INFO "viafb_ioctl: 0x%X !!\n", cmd);
566
567 switch (cmd) {
568 case VIAFB_GET_CHIP_INFO:
569 if (copy_to_user(argp, viaparinfo->chip_info,
570 sizeof(struct chip_information)))
571 return -EFAULT;
572 break;
573 case VIAFB_GET_INFO_SIZE:
574 return put_user(viainfo_size, argp);
575 case VIAFB_GET_INFO:
576 return viafb_ioctl_get_viafb_info(arg);
577 case VIAFB_HOTPLUG:
578 return put_user(viafb_ioctl_hotplug(info->var.xres,
579 info->var.yres,
580 info->var.bits_per_pixel), argp);
581 case VIAFB_SET_HOTPLUG_FLAG:
582 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
583 return -EFAULT;
584 viafb_hotplug = (gpu32) ? 1 : 0;
585 break;
586 case VIAFB_GET_RESOLUTION:
587 viamode.xres = (u32) viafb_hotplug_Xres;
588 viamode.yres = (u32) viafb_hotplug_Yres;
589 viamode.refresh = (u32) viafb_hotplug_refresh;
590 viamode.bpp = (u32) viafb_hotplug_bpp;
591 if (viafb_SAMM_ON == 1) {
592 viamode.xres_sec = viafb_second_xres;
593 viamode.yres_sec = viafb_second_yres;
594 viamode.virtual_xres_sec = viafb_second_virtual_xres;
595 viamode.virtual_yres_sec = viafb_second_virtual_yres;
596 viamode.refresh_sec = viafb_refresh1;
597 viamode.bpp_sec = viafb_bpp1;
598 } else {
599 viamode.xres_sec = 0;
600 viamode.yres_sec = 0;
601 viamode.virtual_xres_sec = 0;
602 viamode.virtual_yres_sec = 0;
603 viamode.refresh_sec = 0;
604 viamode.bpp_sec = 0;
605 }
606 if (copy_to_user(argp, &viamode, sizeof(viamode)))
607 return -EFAULT;
608 break;
609 case VIAFB_GET_SAMM_INFO:
610 viasamm.samm_status = viafb_SAMM_ON;
611
612 if (viafb_SAMM_ON == 1) {
613 if (viafb_dual_fb) {
614 viasamm.size_prim = viaparinfo->fbmem_free;
615 viasamm.size_sec = viaparinfo1->fbmem_free;
616 } else {
617 if (viafb_second_size) {
618 viasamm.size_prim =
619 viaparinfo->fbmem_free -
620 viafb_second_size * 1024 * 1024;
621 viasamm.size_sec =
622 viafb_second_size * 1024 * 1024;
623 } else {
624 viasamm.size_prim =
625 viaparinfo->fbmem_free >> 1;
626 viasamm.size_sec =
627 (viaparinfo->fbmem_free >> 1);
628 }
629 }
630 viasamm.mem_base = viaparinfo->fbmem;
631 viasamm.offset_sec = viafb_second_offset;
632 } else {
633 viasamm.size_prim =
634 viaparinfo->memsize - viaparinfo->fbmem_used;
635 viasamm.size_sec = 0;
636 viasamm.mem_base = viaparinfo->fbmem;
637 viasamm.offset_sec = 0;
638 }
639
640 if (copy_to_user(argp, &viasamm, sizeof(viasamm)))
641 return -EFAULT;
642
643 break;
644 case VIAFB_TURN_ON_OUTPUT_DEVICE:
645 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
646 return -EFAULT;
647 if (gpu32 & CRT_Device)
648 viafb_crt_enable();
649 if (gpu32 & DVI_Device)
650 viafb_dvi_enable();
651 if (gpu32 & LCD_Device)
652 viafb_lcd_enable();
653 break;
654 case VIAFB_TURN_OFF_OUTPUT_DEVICE:
655 if (copy_from_user(&gpu32, argp, sizeof(gpu32)))
656 return -EFAULT;
657 if (gpu32 & CRT_Device)
658 viafb_crt_disable();
659 if (gpu32 & DVI_Device)
660 viafb_dvi_disable();
661 if (gpu32 & LCD_Device)
662 viafb_lcd_disable();
663 break;
664 case VIAFB_SET_DEVICE:
665 if (copy_from_user(&active_dev, (void *)argp,
666 sizeof(active_dev)))
667 return -EFAULT;
668 viafb_set_device(active_dev);
669 viafb_set_par(info);
670 break;
671 case VIAFB_GET_DEVICE:
672 active_dev.crt = viafb_CRT_ON;
673 active_dev.dvi = viafb_DVI_ON;
674 active_dev.lcd = viafb_LCD_ON;
675 active_dev.samm = viafb_SAMM_ON;
676 active_dev.primary_dev = viafb_primary_dev;
677
678 active_dev.lcd_dsp_cent = viafb_lcd_dsp_method;
679 active_dev.lcd_panel_id = viafb_lcd_panel_id;
680 active_dev.lcd_mode = viafb_lcd_mode;
681
682 active_dev.xres = viafb_hotplug_Xres;
683 active_dev.yres = viafb_hotplug_Yres;
684
685 active_dev.xres1 = viafb_second_xres;
686 active_dev.yres1 = viafb_second_yres;
687
688 active_dev.bpp = viafb_bpp;
689 active_dev.bpp1 = viafb_bpp1;
690 active_dev.refresh = viafb_refresh;
691 active_dev.refresh1 = viafb_refresh1;
692
693 active_dev.epia_dvi = viafb_platform_epia_dvi;
694 active_dev.lcd_dual_edge = viafb_device_lcd_dualedge;
695 active_dev.bus_width = viafb_bus_width;
696
697 if (copy_to_user(argp, &active_dev, sizeof(active_dev)))
698 return -EFAULT;
699 break;
700
701 case VIAFB_GET_DRIVER_VERSION:
702 driver_version.iMajorNum = VERSION_MAJOR;
703 driver_version.iKernelNum = VERSION_KERNEL;
704 driver_version.iOSNum = VERSION_OS;
705 driver_version.iMinorNum = VERSION_MINOR;
706
707 if (copy_to_user(argp, &driver_version,
708 sizeof(driver_version)))
709 return -EFAULT;
710
711 break;
712
713 case VIAFB_SET_DEVICE_INFO:
714 if (copy_from_user(&viafb_setting,
715 argp, sizeof(viafb_setting)))
716 return -EFAULT;
717 if (apply_device_setting(viafb_setting, info) < 0)
718 return -EINVAL;
719
720 break;
721
722 case VIAFB_SET_SECOND_MODE:
723 if (copy_from_user(&sec_var, argp, sizeof(sec_var)))
724 return -EFAULT;
725 apply_second_mode_setting(&sec_var);
726 break;
727
728 case VIAFB_GET_DEVICE_INFO:
729
730 retrieve_device_setting(&viafb_setting);
731
732 if (copy_to_user(argp, &viafb_setting, sizeof(viafb_setting)))
733 return -EFAULT;
734
735 break;
736
737 case VIAFB_GET_DEVICE_SUPPORT:
738 viafb_get_device_support_state(&state_info);
739 if (put_user(state_info, argp))
740 return -EFAULT;
741 break;
742
743 case VIAFB_GET_DEVICE_CONNECT:
744 viafb_get_device_connect_state(&state_info);
745 if (put_user(state_info, argp))
746 return -EFAULT;
747 break;
748
749 case VIAFB_GET_PANEL_SUPPORT_EXPAND:
750 state_info =
751 viafb_lcd_get_support_expand_state(info->var.xres,
752 info->var.yres);
753 if (put_user(state_info, argp))
754 return -EFAULT;
755 break;
756
757 case VIAFB_GET_DRIVER_NAME:
758 if (copy_to_user(argp, driver_name, sizeof(driver_name)))
759 return -EFAULT;
760 break;
761
762 case VIAFB_SET_GAMMA_LUT:
763 viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL);
764 if (!viafb_gamma_table)
765 return -ENOMEM;
766 if (copy_from_user(viafb_gamma_table, argp,
767 sizeof(viafb_gamma_table))) {
768 kfree(viafb_gamma_table);
769 return -EFAULT;
770 }
771 viafb_set_gamma_table(viafb_bpp, viafb_gamma_table);
772 kfree(viafb_gamma_table);
773 break;
774
775 case VIAFB_GET_GAMMA_LUT:
776 viafb_gamma_table = kmalloc(256 * sizeof(u32), GFP_KERNEL);
777 if (!viafb_gamma_table)
778 return -ENOMEM;
779 viafb_get_gamma_table(viafb_gamma_table);
780 if (copy_to_user(argp, viafb_gamma_table,
781 sizeof(viafb_gamma_table))) {
782 kfree(viafb_gamma_table);
783 return -EFAULT;
784 }
785 kfree(viafb_gamma_table);
786 break;
787
788 case VIAFB_GET_GAMMA_SUPPORT_STATE:
789 viafb_get_gamma_support_state(viafb_bpp, &state_info);
790 if (put_user(state_info, argp))
791 return -EFAULT;
792 break;
793 case VIAFB_SET_VIDEO_DEVICE:
794 get_user(video_dev_info, argp);
795 viafb_set_video_device(video_dev_info);
796 break;
797 case VIAFB_GET_VIDEO_DEVICE:
798 viafb_get_video_device(&video_dev_info);
799 if (put_user(video_dev_info, argp))
800 return -EFAULT;
801 break;
802 case VIAFB_SYNC_SURFACE:
803 DEBUG_MSG(KERN_INFO "lobo VIAFB_SYNC_SURFACE\n");
804 break;
805 case VIAFB_GET_DRIVER_CAPS:
806 break;
807
808 case VIAFB_GET_PANEL_MAX_SIZE:
809 if (copy_from_user
810 (&panel_pos_size_para, argp, sizeof(panel_pos_size_para)))
811 return -EFAULT;
812 panel_pos_size_para.x = panel_pos_size_para.y = 0;
813 if (copy_to_user(argp, &panel_pos_size_para,
814 sizeof(panel_pos_size_para)))
815 return -EFAULT;
816 break;
817 case VIAFB_GET_PANEL_MAX_POSITION:
818 if (copy_from_user
819 (&panel_pos_size_para, argp, sizeof(panel_pos_size_para)))
820 return -EFAULT;
821 panel_pos_size_para.x = panel_pos_size_para.y = 0;
822 if (copy_to_user(argp, &panel_pos_size_para,
823 sizeof(panel_pos_size_para)))
824 return -EFAULT;
825 break;
826
827 case VIAFB_GET_PANEL_POSITION:
828 if (copy_from_user
829 (&panel_pos_size_para, argp, sizeof(panel_pos_size_para)))
830 return -EFAULT;
831 panel_pos_size_para.x = panel_pos_size_para.y = 0;
832 if (copy_to_user(argp, &panel_pos_size_para,
833 sizeof(panel_pos_size_para)))
834 return -EFAULT;
835 break;
836 case VIAFB_GET_PANEL_SIZE:
837 if (copy_from_user
838 (&panel_pos_size_para, argp, sizeof(panel_pos_size_para)))
839 return -EFAULT;
840 panel_pos_size_para.x = panel_pos_size_para.y = 0;
841 if (copy_to_user(argp, &panel_pos_size_para,
842 sizeof(panel_pos_size_para)))
843 return -EFAULT;
844 break;
845
846 case VIAFB_SET_PANEL_POSITION:
847 if (copy_from_user
848 (&panel_pos_size_para, argp, sizeof(panel_pos_size_para)))
849 return -EFAULT;
850 break;
851 case VIAFB_SET_PANEL_SIZE:
852 if (copy_from_user
853 (&panel_pos_size_para, argp, sizeof(panel_pos_size_para)))
854 return -EFAULT;
855 break;
856
857 default:
858 return -EINVAL;
859 }
860
861 return 0;
862}
863
864static void viafb_fillrect(struct fb_info *info,
865 const struct fb_fillrect *rect)
866{
867 u32 col = 0, rop = 0;
868 int pitch;
869
870 if (!viafb_accel)
871 return cfb_fillrect(info, rect);
872
873 if (!rect->width || !rect->height)
874 return;
875
876 switch (rect->rop) {
877 case ROP_XOR:
878 rop = 0x5A;
879 break;
880 case ROP_COPY:
881 default:
882 rop = 0xF0;
883 break;
884 }
885
886 switch (info->var.bits_per_pixel) {
887 case 8:
888 col = rect->color;
889 break;
890 case 16:
891 col = ((u32 *) (info->pseudo_palette))[rect->color];
892 break;
893 case 32:
894 col = ((u32 *) (info->pseudo_palette))[rect->color];
895 break;
896 }
897
898 /* BitBlt Source Address */
899 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCPOS);
900 /* Source Base Address */
901 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCBASE);
902 /* Destination Base Address */
903 writel(((unsigned long) (info->screen_base) -
904 (unsigned long) viafb_FB_MM) >> 3,
905 viaparinfo->io_virt + VIA_REG_DSTBASE);
906 /* Pitch */
907 pitch = (info->var.xres_virtual + 7) & ~7;
908 writel(VIA_PITCH_ENABLE |
909 (((pitch *
910 info->var.bits_per_pixel >> 3) >> 3) |
911 (((pitch * info->
912 var.bits_per_pixel >> 3) >> 3) << 16)),
913 viaparinfo->io_virt + VIA_REG_PITCH);
914 /* BitBlt Destination Address */
915 writel(((rect->dy << 16) | rect->dx),
916 viaparinfo->io_virt + VIA_REG_DSTPOS);
917 /* Dimension: width & height */
918 writel((((rect->height - 1) << 16) | (rect->width - 1)),
919 viaparinfo->io_virt + VIA_REG_DIMENSION);
920 /* Forground color or Destination color */
921 writel(col, viaparinfo->io_virt + VIA_REG_FGCOLOR);
922 /* GE Command */
923 writel((0x01 | 0x2000 | (rop << 24)),
924 viaparinfo->io_virt + VIA_REG_GECMD);
925
926}
927
928static void viafb_copyarea(struct fb_info *info,
929 const struct fb_copyarea *area)
930{
931 u32 dy = area->dy, sy = area->sy, direction = 0x0;
932 u32 sx = area->sx, dx = area->dx, width = area->width;
933 int pitch;
934
935 DEBUG_MSG(KERN_INFO "viafb_copyarea!!\n");
936
937 if (!viafb_accel)
938 return cfb_copyarea(info, area);
939
940 if (!area->width || !area->height)
941 return;
942
943 if (sy < dy) {
944 dy += area->height - 1;
945 sy += area->height - 1;
946 direction |= 0x4000;
947 }
948
949 if (sx < dx) {
950 dx += width - 1;
951 sx += width - 1;
952 direction |= 0x8000;
953 }
954
955 /* Source Base Address */
956 writel(((unsigned long) (info->screen_base) -
957 (unsigned long) viafb_FB_MM) >> 3,
958 viaparinfo->io_virt + VIA_REG_SRCBASE);
959 /* Destination Base Address */
960 writel(((unsigned long) (info->screen_base) -
961 (unsigned long) viafb_FB_MM) >> 3,
962 viaparinfo->io_virt + VIA_REG_DSTBASE);
963 /* Pitch */
964 pitch = (info->var.xres_virtual + 7) & ~7;
965 /* VIA_PITCH_ENABLE can be omitted now. */
966 writel(VIA_PITCH_ENABLE |
967 (((pitch *
968 info->var.bits_per_pixel >> 3) >> 3) | (((pitch *
969 info->var.
970 bits_per_pixel
971 >> 3) >> 3)
972 << 16)),
973 viaparinfo->io_virt + VIA_REG_PITCH);
974 /* BitBlt Source Address */
975 writel(((sy << 16) | sx), viaparinfo->io_virt + VIA_REG_SRCPOS);
976 /* BitBlt Destination Address */
977 writel(((dy << 16) | dx), viaparinfo->io_virt + VIA_REG_DSTPOS);
978 /* Dimension: width & height */
979 writel((((area->height - 1) << 16) | (area->width - 1)),
980 viaparinfo->io_virt + VIA_REG_DIMENSION);
981 /* GE Command */
982 writel((0x01 | direction | (0xCC << 24)),
983 viaparinfo->io_virt + VIA_REG_GECMD);
984
985}
986
987static void viafb_imageblit(struct fb_info *info,
988 const struct fb_image *image)
989{
990 u32 size, bg_col = 0, fg_col = 0, *udata;
991 int i;
992 int pitch;
993
994 if (!viafb_accel)
995 return cfb_imageblit(info, image);
996
997 udata = (u32 *) image->data;
998
999 switch (info->var.bits_per_pixel) {
1000 case 8:
1001 bg_col = image->bg_color;
1002 fg_col = image->fg_color;
1003 break;
1004 case 16:
1005 bg_col = ((u32 *) (info->pseudo_palette))[image->bg_color];
1006 fg_col = ((u32 *) (info->pseudo_palette))[image->fg_color];
1007 break;
1008 case 32:
1009 bg_col = ((u32 *) (info->pseudo_palette))[image->bg_color];
1010 fg_col = ((u32 *) (info->pseudo_palette))[image->fg_color];
1011 break;
1012 }
1013 size = image->width * image->height;
1014
1015 /* Source Base Address */
1016 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCBASE);
1017 /* Destination Base Address */
1018 writel(((unsigned long) (info->screen_base) -
1019 (unsigned long) viafb_FB_MM) >> 3,
1020 viaparinfo->io_virt + VIA_REG_DSTBASE);
1021 /* Pitch */
1022 pitch = (info->var.xres_virtual + 7) & ~7;
1023 writel(VIA_PITCH_ENABLE |
1024 (((pitch *
1025 info->var.bits_per_pixel >> 3) >> 3) | (((pitch *
1026 info->var.
1027 bits_per_pixel
1028 >> 3) >> 3)
1029 << 16)),
1030 viaparinfo->io_virt + VIA_REG_PITCH);
1031 /* BitBlt Source Address */
1032 writel(0x0, viaparinfo->io_virt + VIA_REG_SRCPOS);
1033 /* BitBlt Destination Address */
1034 writel(((image->dy << 16) | image->dx),
1035 viaparinfo->io_virt + VIA_REG_DSTPOS);
1036 /* Dimension: width & height */
1037 writel((((image->height - 1) << 16) | (image->width - 1)),
1038 viaparinfo->io_virt + VIA_REG_DIMENSION);
1039 /* fb color */
1040 writel(fg_col, viaparinfo->io_virt + VIA_REG_FGCOLOR);
1041 /* bg color */
1042 writel(bg_col, viaparinfo->io_virt + VIA_REG_BGCOLOR);
1043 /* GE Command */
1044 writel(0xCC020142, viaparinfo->io_virt + VIA_REG_GECMD);
1045
1046 for (i = 0; i < size / 4; i++) {
1047 writel(*udata, viaparinfo->io_virt + VIA_MMIO_BLTBASE);
1048 udata++;
1049 }
1050
1051}
1052
1053static int viafb_cursor(struct fb_info *info, struct fb_cursor *cursor)
1054{
1055 u8 data[CURSOR_SIZE / 8];
1056 u32 data_bak[CURSOR_SIZE / 32];
1057 u32 temp, xx, yy, bg_col = 0, fg_col = 0;
1058 int size, i, j = 0;
1059 static int hw_cursor;
1060 struct viafb_par *p_viafb_par;
1061
1062 if (viafb_accel)
1063 hw_cursor = 1;
1064
1065 if (!viafb_accel) {
1066 if (hw_cursor) {
1067 viafb_show_hw_cursor(info, HW_Cursor_OFF);
1068 hw_cursor = 0;
1069 }
1070 return -ENODEV;
1071 }
1072
1073 if ((((struct viafb_par *)(info->par))->iga_path == IGA2)
1074 && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266))
1075 return -ENODEV;
1076
1077 /* When duoview and using lcd , use soft cursor */
1078 if (viafb_LCD_ON || ((struct viafb_par *)(info->par))->duoview)
1079 return -ENODEV;
1080
1081 viafb_show_hw_cursor(info, HW_Cursor_OFF);
1082 viacursor = *cursor;
1083
1084 if (cursor->set & FB_CUR_SETHOT) {
1085 viacursor.hot = cursor->hot;
1086 temp = ((viacursor.hot.x) << 16) + viacursor.hot.y;
1087 writel(temp, viaparinfo->io_virt + VIA_REG_CURSOR_ORG);
1088 }
1089
1090 if (cursor->set & FB_CUR_SETPOS) {
1091 viacursor.image.dx = cursor->image.dx;
1092 viacursor.image.dy = cursor->image.dy;
1093 yy = cursor->image.dy - info->var.yoffset;
1094 xx = cursor->image.dx - info->var.xoffset;
1095 temp = yy & 0xFFFF;
1096 temp |= (xx << 16);
1097 writel(temp, viaparinfo->io_virt + VIA_REG_CURSOR_POS);
1098 }
1099
1100 if (cursor->set & FB_CUR_SETSIZE) {
1101 temp = readl(viaparinfo->io_virt + VIA_REG_CURSOR_MODE);
1102
1103 if ((cursor->image.width <= 32)
1104 && (cursor->image.height <= 32)) {
1105 MAX_CURS = 32;
1106 temp |= 0x2;
1107 } else if ((cursor->image.width <= 64)
1108 && (cursor->image.height <= 64)) {
1109 MAX_CURS = 64;
1110 temp &= 0xFFFFFFFD;
1111 } else {
1112 DEBUG_MSG(KERN_INFO
1113 "The cursor image is biger than 64x64 bits...\n");
1114 return -ENXIO;
1115 }
1116 writel(temp, viaparinfo->io_virt + VIA_REG_CURSOR_MODE);
1117
1118 viacursor.image.height = cursor->image.height;
1119 viacursor.image.width = cursor->image.width;
1120 }
1121
1122 if (cursor->set & FB_CUR_SETCMAP) {
1123 viacursor.image.fg_color = cursor->image.fg_color;
1124 viacursor.image.bg_color = cursor->image.bg_color;
1125
1126 switch (info->var.bits_per_pixel) {
1127 case 8:
1128 case 16:
1129 case 32:
1130 bg_col =
1131 (0xFF << 24) |
1132 (((info->cmap.red)[viacursor.image.bg_color] &
1133 0xFF00) << 8) |
1134 ((info->cmap.green)[viacursor.image.bg_color] &
1135 0xFF00) |
1136 (((info->cmap.blue)[viacursor.image.bg_color] &
1137 0xFF00) >> 8);
1138 fg_col =
1139 (0xFF << 24) |
1140 (((info->cmap.red)[viacursor.image.fg_color] &
1141 0xFF00) << 8) |
1142 ((info->cmap.green)[viacursor.image.fg_color] &
1143 0xFF00) |
1144 (((info->cmap.blue)[viacursor.image.fg_color] &
1145 0xFF00) >> 8);
1146 break;
1147 default:
1148 return 0;
1149 }
1150
1151 /* This is indeed a patch for VT3324/VT3353 */
1152 if (!info->par)
1153 return 0;
1154 p_viafb_par = (struct viafb_par *)info->par;
1155
1156 if ((p_viafb_par->chip_info->gfx_chip_name ==
1157 UNICHROME_CX700) ||
1158 ((p_viafb_par->chip_info->gfx_chip_name ==
1159 UNICHROME_VX800))) {
1160 bg_col =
1161 (((info->cmap.red)[viacursor.image.bg_color] &
1162 0xFFC0) << 14) |
1163 (((info->cmap.green)[viacursor.image.bg_color] &
1164 0xFFC0) << 4) |
1165 (((info->cmap.blue)[viacursor.image.bg_color] &
1166 0xFFC0) >> 6);
1167 fg_col =
1168 (((info->cmap.red)[viacursor.image.fg_color] &
1169 0xFFC0) << 14) |
1170 (((info->cmap.green)[viacursor.image.fg_color] &
1171 0xFFC0) << 4) |
1172 (((info->cmap.blue)[viacursor.image.fg_color] &
1173 0xFFC0) >> 6);
1174 }
1175
1176 writel(bg_col, viaparinfo->io_virt + VIA_REG_CURSOR_BG);
1177 writel(fg_col, viaparinfo->io_virt + VIA_REG_CURSOR_FG);
1178 }
1179
1180 if (cursor->set & FB_CUR_SETSHAPE) {
1181 size =
1182 ((viacursor.image.width + 7) >> 3) *
1183 viacursor.image.height;
1184
1185 if (MAX_CURS == 32) {
1186 for (i = 0; i < (CURSOR_SIZE / 32); i++) {
1187 data_bak[i] = 0x0;
1188 data_bak[i + 1] = 0xFFFFFFFF;
1189 i += 1;
1190 }
1191 } else if (MAX_CURS == 64) {
1192 for (i = 0; i < (CURSOR_SIZE / 32); i++) {
1193 data_bak[i] = 0x0;
1194 data_bak[i + 1] = 0x0;
1195 data_bak[i + 2] = 0xFFFFFFFF;
1196 data_bak[i + 3] = 0xFFFFFFFF;
1197 i += 3;
1198 }
1199 }
1200
1201 switch (viacursor.rop) {
1202 case ROP_XOR:
1203 for (i = 0; i < size; i++)
1204 data[i] = viacursor.mask[i];
1205 break;
1206 case ROP_COPY:
1207
1208 for (i = 0; i < size; i++)
1209 data[i] = viacursor.mask[i];
1210 break;
1211 default:
1212 break;
1213 }
1214
1215 if (MAX_CURS == 32) {
1216 for (i = 0; i < size; i++) {
1217 data_bak[j] = (u32) data[i];
1218 data_bak[j + 1] = ~data_bak[j];
1219 j += 2;
1220 }
1221 } else if (MAX_CURS == 64) {
1222 for (i = 0; i < size; i++) {
1223 data_bak[j] = (u32) data[i];
1224 data_bak[j + 1] = 0x0;
1225 data_bak[j + 2] = ~data_bak[j];
1226 data_bak[j + 3] = ~data_bak[j + 1];
1227 j += 4;
1228 }
1229 }
1230
1231 memcpy(((struct viafb_par *)(info->par))->fbmem_virt +
1232 ((struct viafb_par *)(info->par))->cursor_start,
1233 data_bak, CURSOR_SIZE);
1234 }
1235
1236 if (viacursor.enable)
1237 viafb_show_hw_cursor(info, HW_Cursor_ON);
1238
1239 return 0;
1240}
1241
1242static int viafb_sync(struct fb_info *info)
1243{
1244 if (viafb_accel)
1245 viafb_wait_engine_idle();
1246 return 0;
1247}
1248
1249int viafb_get_mode_index(int hres, int vres, int flag)
1250{
1251 u32 i;
1252 DEBUG_MSG(KERN_INFO "viafb_get_mode_index!\n");
1253
1254 for (i = 0; viafb_modentry[i].mode_index != VIA_RES_INVALID; i++)
1255 if (viafb_modentry[i].xres == hres &&
1256 viafb_modentry[i].yres == vres)
1257 break;
1258
1259 viafb_resMode = viafb_modentry[i].mode_index;
1260 if (flag)
1261 viafb_mode1 = viafb_modentry[i].mode_res;
1262 else
1263 viafb_mode = viafb_modentry[i].mode_res;
1264
1265 return viafb_resMode;
1266}
1267
1268static void check_available_device_to_enable(int device_id)
1269{
1270 int device_num = 0;
1271
1272 /* Initialize: */
1273 viafb_CRT_ON = STATE_OFF;
1274 viafb_DVI_ON = STATE_OFF;
1275 viafb_LCD_ON = STATE_OFF;
1276 viafb_LCD2_ON = STATE_OFF;
1277 viafb_DeviceStatus = None_Device;
1278
1279 if ((device_id & CRT_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
1280 viafb_CRT_ON = STATE_ON;
1281 device_num++;
1282 viafb_DeviceStatus |= CRT_Device;
1283 }
1284
1285 if ((device_id & DVI_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
1286 viafb_DVI_ON = STATE_ON;
1287 device_num++;
1288 viafb_DeviceStatus |= DVI_Device;
1289 }
1290
1291 if ((device_id & LCD_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
1292 viafb_LCD_ON = STATE_ON;
1293 device_num++;
1294 viafb_DeviceStatus |= LCD_Device;
1295 }
1296
1297 if ((device_id & LCD2_Device) && (device_num < MAX_ACTIVE_DEV_NUM)) {
1298 viafb_LCD2_ON = STATE_ON;
1299 device_num++;
1300 viafb_DeviceStatus |= LCD2_Device;
1301 }
1302
1303 if (viafb_DeviceStatus == None_Device) {
1304 /* Use CRT as default active device: */
1305 viafb_CRT_ON = STATE_ON;
1306 viafb_DeviceStatus = CRT_Device;
1307 }
1308 DEBUG_MSG(KERN_INFO "Device Status:%x", viafb_DeviceStatus);
1309}
1310
1311static void viafb_set_device(struct device_t active_dev)
1312{
1313 /* Check available device to enable: */
1314 int device_id = None_Device;
1315 if (active_dev.crt)
1316 device_id |= CRT_Device;
1317 if (active_dev.dvi)
1318 device_id |= DVI_Device;
1319 if (active_dev.lcd)
1320 device_id |= LCD_Device;
1321
1322 check_available_device_to_enable(device_id);
1323
1324 /* Check property of LCD: */
1325 if (viafb_LCD_ON) {
1326 if (active_dev.lcd_dsp_cent) {
1327 viaparinfo->lvds_setting_info->display_method =
1328 viafb_lcd_dsp_method = LCD_CENTERING;
1329 } else {
1330 viaparinfo->lvds_setting_info->display_method =
1331 viafb_lcd_dsp_method = LCD_EXPANDSION;
1332 }
1333
1334 if (active_dev.lcd_mode == LCD_SPWG) {
1335 viaparinfo->lvds_setting_info->lcd_mode =
1336 viafb_lcd_mode = LCD_SPWG;
1337 } else {
1338 viaparinfo->lvds_setting_info->lcd_mode =
1339 viafb_lcd_mode = LCD_OPENLDI;
1340 }
1341
1342 if (active_dev.lcd_panel_id <= LCD_PANEL_ID_MAXIMUM) {
1343 viafb_lcd_panel_id = active_dev.lcd_panel_id;
1344 viafb_init_lcd_size();
1345 }
1346 }
1347
1348 /* Check property of mode: */
1349 if (!active_dev.xres1)
1350 viafb_second_xres = 640;
1351 else
1352 viafb_second_xres = active_dev.xres1;
1353 if (!active_dev.yres1)
1354 viafb_second_yres = 480;
1355 else
1356 viafb_second_yres = active_dev.yres1;
1357 if (active_dev.bpp != 0)
1358 viafb_bpp = active_dev.bpp;
1359 if (active_dev.bpp1 != 0)
1360 viafb_bpp1 = active_dev.bpp1;
1361 if (active_dev.refresh != 0)
1362 viafb_refresh = active_dev.refresh;
1363 if (active_dev.refresh1 != 0)
1364 viafb_refresh1 = active_dev.refresh1;
1365 if ((active_dev.samm == STATE_OFF) || (active_dev.samm == STATE_ON))
1366 viafb_SAMM_ON = active_dev.samm;
1367 viafb_primary_dev = active_dev.primary_dev;
1368
1369 viafb_set_start_addr();
1370 viafb_set_iga_path();
1371}
1372
1373static void viafb_set_video_device(u32 video_dev_info)
1374{
1375 viaparinfo->video_on_crt = STATE_OFF;
1376 viaparinfo->video_on_dvi = STATE_OFF;
1377 viaparinfo->video_on_lcd = STATE_OFF;
1378
1379 /* Check available device to enable: */
1380 if ((video_dev_info & CRT_Device) == CRT_Device)
1381 viaparinfo->video_on_crt = STATE_ON;
1382 else if ((video_dev_info & DVI_Device) == DVI_Device)
1383 viaparinfo->video_on_dvi = STATE_ON;
1384 else if ((video_dev_info & LCD_Device) == LCD_Device)
1385 viaparinfo->video_on_lcd = STATE_ON;
1386}
1387
1388static void viafb_get_video_device(u32 *video_dev_info)
1389{
1390 *video_dev_info = None_Device;
1391 if (viaparinfo->video_on_crt == STATE_ON)
1392 *video_dev_info |= CRT_Device;
1393 else if (viaparinfo->video_on_dvi == STATE_ON)
1394 *video_dev_info |= DVI_Device;
1395 else if (viaparinfo->video_on_lcd == STATE_ON)
1396 *video_dev_info |= LCD_Device;
1397}
1398
1399static int get_primary_device(void)
1400{
1401 int primary_device = 0;
1402 /* Rule: device on iga1 path are the primary device. */
1403 if (viafb_SAMM_ON) {
1404 if (viafb_CRT_ON) {
1405 if (viaparinfo->crt_setting_info->iga_path == IGA1) {
1406 DEBUG_MSG(KERN_INFO "CRT IGA Path:%d\n",
1407 viaparinfo->
1408 crt_setting_info->iga_path);
1409 primary_device = CRT_Device;
1410 }
1411 }
1412 if (viafb_DVI_ON) {
1413 if (viaparinfo->tmds_setting_info->iga_path == IGA1) {
1414 DEBUG_MSG(KERN_INFO "DVI IGA Path:%d\n",
1415 viaparinfo->
1416 tmds_setting_info->iga_path);
1417 primary_device = DVI_Device;
1418 }
1419 }
1420 if (viafb_LCD_ON) {
1421 if (viaparinfo->lvds_setting_info->iga_path == IGA1) {
1422 DEBUG_MSG(KERN_INFO "LCD IGA Path:%d\n",
1423 viaparinfo->
1424 lvds_setting_info->iga_path);
1425 primary_device = LCD_Device;
1426 }
1427 }
1428 if (viafb_LCD2_ON) {
1429 if (viaparinfo->lvds_setting_info2->iga_path == IGA1) {
1430 DEBUG_MSG(KERN_INFO "LCD2 IGA Path:%d\n",
1431 viaparinfo->
1432 lvds_setting_info2->iga_path);
1433 primary_device = LCD2_Device;
1434 }
1435 }
1436 }
1437 return primary_device;
1438}
1439
1440static u8 is_duoview(void)
1441{
1442 if (0 == viafb_SAMM_ON) {
1443 if (viafb_LCD_ON + viafb_LCD2_ON +
1444 viafb_DVI_ON + viafb_CRT_ON == 2)
1445 return true;
1446 return false;
1447 } else {
1448 return false;
1449 }
1450}
1451
1452static void apply_second_mode_setting(struct fb_var_screeninfo
1453 *sec_var)
1454{
1455 u32 htotal, vtotal, long_refresh;
1456
1457 htotal = sec_var->xres + sec_var->left_margin +
1458 sec_var->right_margin + sec_var->hsync_len;
1459 vtotal = sec_var->yres + sec_var->upper_margin +
1460 sec_var->lower_margin + sec_var->vsync_len;
1461 if ((sec_var->xres_virtual * (sec_var->bits_per_pixel >> 3)) & 0x1F) {
1462 /*Is 32 bytes alignment? */
1463 /*32 pixel alignment */
1464 sec_var->xres_virtual = (sec_var->xres_virtual + 31) & ~31;
1465 }
1466
1467 htotal = sec_var->xres + sec_var->left_margin +
1468 sec_var->right_margin + sec_var->hsync_len;
1469 vtotal = sec_var->yres + sec_var->upper_margin +
1470 sec_var->lower_margin + sec_var->vsync_len;
1471 long_refresh = 1000000000UL / sec_var->pixclock * 1000;
1472 long_refresh /= (htotal * vtotal);
1473
1474 viafb_second_xres = sec_var->xres;
1475 viafb_second_yres = sec_var->yres;
1476 viafb_second_virtual_xres = sec_var->xres_virtual;
1477 viafb_second_virtual_yres = sec_var->yres_virtual;
1478 viafb_bpp1 = sec_var->bits_per_pixel;
1479 viafb_refresh1 = viafb_get_refresh(sec_var->xres, sec_var->yres,
1480 long_refresh);
1481}
1482
1483static int apply_device_setting(struct viafb_ioctl_setting setting_info,
1484 struct fb_info *info)
1485{
1486 int need_set_mode = 0;
1487 DEBUG_MSG(KERN_INFO "apply_device_setting\n");
1488
1489 if (setting_info.device_flag) {
1490 need_set_mode = 1;
1491 check_available_device_to_enable(setting_info.device_status);
1492 }
1493
1494 /* Unlock LCD's operation according to LCD flag
1495 and check if the setting value is valid. */
1496 /* If the value is valid, apply the new setting value to the device. */
1497 if (viafb_LCD_ON) {
1498 if (setting_info.lcd_operation_flag & OP_LCD_CENTERING) {
1499 need_set_mode = 1;
1500 if (setting_info.lcd_attributes.display_center) {
1501 /* Centering */
1502 viaparinfo->lvds_setting_info->display_method =
1503 LCD_CENTERING;
1504 viafb_lcd_dsp_method = LCD_CENTERING;
1505 viaparinfo->lvds_setting_info2->display_method =
1506 viafb_lcd_dsp_method = LCD_CENTERING;
1507 } else {
1508 /* expandsion */
1509 viaparinfo->lvds_setting_info->display_method =
1510 LCD_EXPANDSION;
1511 viafb_lcd_dsp_method = LCD_EXPANDSION;
1512 viaparinfo->lvds_setting_info2->display_method =
1513 LCD_EXPANDSION;
1514 viafb_lcd_dsp_method = LCD_EXPANDSION;
1515 }
1516 }
1517
1518 if (setting_info.lcd_operation_flag & OP_LCD_MODE) {
1519 need_set_mode = 1;
1520 if (setting_info.lcd_attributes.lcd_mode ==
1521 LCD_SPWG) {
1522 viaparinfo->lvds_setting_info->lcd_mode =
1523 viafb_lcd_mode = LCD_SPWG;
1524 } else {
1525 viaparinfo->lvds_setting_info->lcd_mode =
1526 viafb_lcd_mode = LCD_OPENLDI;
1527 }
1528 viaparinfo->lvds_setting_info2->lcd_mode =
1529 viaparinfo->lvds_setting_info->lcd_mode;
1530 }
1531
1532 if (setting_info.lcd_operation_flag & OP_LCD_PANEL_ID) {
1533 need_set_mode = 1;
1534 if (setting_info.lcd_attributes.panel_id <=
1535 LCD_PANEL_ID_MAXIMUM) {
1536 viafb_lcd_panel_id =
1537 setting_info.lcd_attributes.panel_id;
1538 viafb_init_lcd_size();
1539 }
1540 }
1541 }
1542
1543 if (0 != (setting_info.samm_status & OP_SAMM)) {
1544 setting_info.samm_status =
1545 setting_info.samm_status & (~OP_SAMM);
1546 if (setting_info.samm_status == 0
1547 || setting_info.samm_status == 1) {
1548 viafb_SAMM_ON = setting_info.samm_status;
1549
1550 if (viafb_SAMM_ON)
1551 viafb_primary_dev = setting_info.primary_device;
1552
1553 viafb_set_start_addr();
1554 viafb_set_iga_path();
1555 }
1556 need_set_mode = 1;
1557 }
1558
1559 viaparinfo->duoview = is_duoview();
1560
1561 if (!need_set_mode) {
1562 ;
1563 } else {
1564 viafb_set_iga_path();
1565 viafb_set_par(info);
1566 }
1567 return true;
1568}
1569
1570static void retrieve_device_setting(struct viafb_ioctl_setting
1571 *setting_info)
1572{
1573
1574 /* get device status */
1575 if (viafb_CRT_ON == 1)
1576 setting_info->device_status = CRT_Device;
1577 if (viafb_DVI_ON == 1)
1578 setting_info->device_status |= DVI_Device;
1579 if (viafb_LCD_ON == 1)
1580 setting_info->device_status |= LCD_Device;
1581 if (viafb_LCD2_ON == 1)
1582 setting_info->device_status |= LCD2_Device;
1583 if ((viaparinfo->video_on_crt == 1) && (viafb_CRT_ON == 1)) {
1584 setting_info->video_device_status =
1585 viaparinfo->crt_setting_info->iga_path;
1586 } else if ((viaparinfo->video_on_dvi == 1) && (viafb_DVI_ON == 1)) {
1587 setting_info->video_device_status =
1588 viaparinfo->tmds_setting_info->iga_path;
1589 } else if ((viaparinfo->video_on_lcd == 1) && (viafb_LCD_ON == 1)) {
1590 setting_info->video_device_status =
1591 viaparinfo->lvds_setting_info->iga_path;
1592 } else {
1593 setting_info->video_device_status = 0;
1594 }
1595
1596 setting_info->samm_status = viafb_SAMM_ON;
1597 setting_info->primary_device = get_primary_device();
1598
1599 setting_info->first_dev_bpp = viafb_bpp;
1600 setting_info->second_dev_bpp = viafb_bpp1;
1601
1602 setting_info->first_dev_refresh = viafb_refresh;
1603 setting_info->second_dev_refresh = viafb_refresh1;
1604
1605 setting_info->first_dev_hor_res = viafb_hotplug_Xres;
1606 setting_info->first_dev_ver_res = viafb_hotplug_Yres;
1607 setting_info->second_dev_hor_res = viafb_second_xres;
1608 setting_info->second_dev_ver_res = viafb_second_yres;
1609
1610 /* Get lcd attributes */
1611 setting_info->lcd_attributes.display_center = viafb_lcd_dsp_method;
1612 setting_info->lcd_attributes.panel_id = viafb_lcd_panel_id;
1613 setting_info->lcd_attributes.lcd_mode = viafb_lcd_mode;
1614}
1615
1616static void parse_active_dev(void)
1617{
1618 viafb_CRT_ON = STATE_OFF;
1619 viafb_DVI_ON = STATE_OFF;
1620 viafb_LCD_ON = STATE_OFF;
1621 viafb_LCD2_ON = STATE_OFF;
1622 /* 1. Modify the active status of devices. */
1623 /* 2. Keep the order of devices, so we can set corresponding
1624 IGA path to devices in SAMM case. */
1625 /* Note: The previous of active_dev is primary device,
1626 and the following is secondary device. */
1627 if (!strncmp(viafb_active_dev, "CRT+DVI", 7)) {
1628 /* CRT+DVI */
1629 viafb_CRT_ON = STATE_ON;
1630 viafb_DVI_ON = STATE_ON;
1631 viafb_primary_dev = CRT_Device;
1632 } else if (!strncmp(viafb_active_dev, "DVI+CRT", 7)) {
1633 /* DVI+CRT */
1634 viafb_CRT_ON = STATE_ON;
1635 viafb_DVI_ON = STATE_ON;
1636 viafb_primary_dev = DVI_Device;
1637 } else if (!strncmp(viafb_active_dev, "CRT+LCD", 7)) {
1638 /* CRT+LCD */
1639 viafb_CRT_ON = STATE_ON;
1640 viafb_LCD_ON = STATE_ON;
1641 viafb_primary_dev = CRT_Device;
1642 } else if (!strncmp(viafb_active_dev, "LCD+CRT", 7)) {
1643 /* LCD+CRT */
1644 viafb_CRT_ON = STATE_ON;
1645 viafb_LCD_ON = STATE_ON;
1646 viafb_primary_dev = LCD_Device;
1647 } else if (!strncmp(viafb_active_dev, "DVI+LCD", 7)) {
1648 /* DVI+LCD */
1649 viafb_DVI_ON = STATE_ON;
1650 viafb_LCD_ON = STATE_ON;
1651 viafb_primary_dev = DVI_Device;
1652 } else if (!strncmp(viafb_active_dev, "LCD+DVI", 7)) {
1653 /* LCD+DVI */
1654 viafb_DVI_ON = STATE_ON;
1655 viafb_LCD_ON = STATE_ON;
1656 viafb_primary_dev = LCD_Device;
1657 } else if (!strncmp(viafb_active_dev, "LCD+LCD2", 8)) {
1658 viafb_LCD_ON = STATE_ON;
1659 viafb_LCD2_ON = STATE_ON;
1660 viafb_primary_dev = LCD_Device;
1661 } else if (!strncmp(viafb_active_dev, "LCD2+LCD", 8)) {
1662 viafb_LCD_ON = STATE_ON;
1663 viafb_LCD2_ON = STATE_ON;
1664 viafb_primary_dev = LCD2_Device;
1665 } else if (!strncmp(viafb_active_dev, "CRT", 3)) {
1666 /* CRT only */
1667 viafb_CRT_ON = STATE_ON;
1668 viafb_SAMM_ON = STATE_OFF;
1669 } else if (!strncmp(viafb_active_dev, "DVI", 3)) {
1670 /* DVI only */
1671 viafb_DVI_ON = STATE_ON;
1672 viafb_SAMM_ON = STATE_OFF;
1673 } else if (!strncmp(viafb_active_dev, "LCD", 3)) {
1674 /* LCD only */
1675 viafb_LCD_ON = STATE_ON;
1676 viafb_SAMM_ON = STATE_OFF;
1677 } else {
1678 viafb_CRT_ON = STATE_ON;
1679 viafb_SAMM_ON = STATE_OFF;
1680 }
1681 viaparinfo->duoview = is_duoview();
1682}
1683
1684static void parse_video_dev(void)
1685{
1686 viaparinfo->video_on_crt = STATE_OFF;
1687 viaparinfo->video_on_dvi = STATE_OFF;
1688 viaparinfo->video_on_lcd = STATE_OFF;
1689
1690 if (!strncmp(viafb_video_dev, "CRT", 3)) {
1691 /* Video on CRT */
1692 viaparinfo->video_on_crt = STATE_ON;
1693 } else if (!strncmp(viafb_video_dev, "DVI", 3)) {
1694 /* Video on DVI */
1695 viaparinfo->video_on_dvi = STATE_ON;
1696 } else if (!strncmp(viafb_video_dev, "LCD", 3)) {
1697 /* Video on LCD */
1698 viaparinfo->video_on_lcd = STATE_ON;
1699 }
1700}
1701
1702static int parse_port(char *opt_str, int *output_interface)
1703{
1704 if (!strncmp(opt_str, "DVP0", 4))
1705 *output_interface = INTERFACE_DVP0;
1706 else if (!strncmp(opt_str, "DVP1", 4))
1707 *output_interface = INTERFACE_DVP1;
1708 else if (!strncmp(opt_str, "DFP_HIGHLOW", 11))
1709 *output_interface = INTERFACE_DFP;
1710 else if (!strncmp(opt_str, "DFP_HIGH", 8))
1711 *output_interface = INTERFACE_DFP_HIGH;
1712 else if (!strncmp(opt_str, "DFP_LOW", 7))
1713 *output_interface = INTERFACE_DFP_LOW;
1714 else
1715 *output_interface = INTERFACE_NONE;
1716 return 0;
1717}
1718
1719static void parse_lcd_port(void)
1720{
1721 parse_port(viafb_lcd_port, &viaparinfo->chip_info->lvds_chip_info.
1722 output_interface);
1723 /*Initialize to avoid unexpected behavior */
1724 viaparinfo->chip_info->lvds_chip_info2.output_interface =
1725 INTERFACE_NONE;
1726
1727 DEBUG_MSG(KERN_INFO "parse_lcd_port: viafb_lcd_port:%s,interface:%d\n",
1728 viafb_lcd_port, viaparinfo->chip_info->lvds_chip_info.
1729 output_interface);
1730}
1731
1732static void parse_dvi_port(void)
1733{
1734 parse_port(viafb_dvi_port, &viaparinfo->chip_info->tmds_chip_info.
1735 output_interface);
1736
1737 DEBUG_MSG(KERN_INFO "parse_dvi_port: viafb_dvi_port:%s,interface:%d\n",
1738 viafb_dvi_port, viaparinfo->chip_info->tmds_chip_info.
1739 output_interface);
1740}
1741
1742/*
1743 * The proc filesystem read/write function, a simple proc implement to
1744 * get/set the value of DPA DVP0, DVP0DataDriving, DVP0ClockDriving, DVP1,
1745 * DVP1Driving, DFPHigh, DFPLow CR96, SR2A[5], SR1B[1], SR2A[4], SR1E[2],
1746 * CR9B, SR65, CR97, CR99
1747 */
1748static int viafb_dvp0_proc_read(char *buf, char **start, off_t offset,
1749int count, int *eof, void *data)
1750{
1751 int len = 0;
1752 u8 dvp0_data_dri = 0, dvp0_clk_dri = 0, dvp0 = 0;
1753 dvp0_data_dri =
1754 (viafb_read_reg(VIASR, SR2A) & BIT5) >> 4 |
1755 (viafb_read_reg(VIASR, SR1B) & BIT1) >> 1;
1756 dvp0_clk_dri =
1757 (viafb_read_reg(VIASR, SR2A) & BIT4) >> 3 |
1758 (viafb_read_reg(VIASR, SR1E) & BIT2) >> 2;
1759 dvp0 = viafb_read_reg(VIACR, CR96) & 0x0f;
1760 len +=
1761 sprintf(buf + len, "%x %x %x\n", dvp0, dvp0_data_dri, dvp0_clk_dri);
1762 *eof = 1; /*Inform kernel end of data */
1763 return len;
1764}
1765static int viafb_dvp0_proc_write(struct file *file,
1766 const char __user *buffer, unsigned long count, void *data)
1767{
1768 char buf[20], *value, *pbuf;
1769 u8 reg_val = 0;
1770 unsigned long length, i;
1771 if (count < 1)
1772 return -EINVAL;
1773 length = count > 20 ? 20 : count;
1774 if (copy_from_user(&buf[0], buffer, length))
1775 return -EFAULT;
1776 buf[length - 1] = '\0'; /*Ensure end string */
1777 pbuf = &buf[0];
1778 for (i = 0; i < 3; i++) {
1779 value = strsep(&pbuf, " ");
1780 if (value != NULL) {
1781 strict_strtoul(value, 0, (unsigned long *)&reg_val);
1782 DEBUG_MSG(KERN_INFO "DVP0:reg_val[%l]=:%x\n", i,
1783 reg_val);
1784 switch (i) {
1785 case 0:
1786 viafb_write_reg_mask(CR96, VIACR,
1787 reg_val, 0x0f);
1788 break;
1789 case 1:
1790 viafb_write_reg_mask(SR2A, VIASR,
1791 reg_val << 4, BIT5);
1792 viafb_write_reg_mask(SR1B, VIASR,
1793 reg_val << 1, BIT1);
1794 break;
1795 case 2:
1796 viafb_write_reg_mask(SR2A, VIASR,
1797 reg_val << 3, BIT4);
1798 viafb_write_reg_mask(SR1E, VIASR,
1799 reg_val << 2, BIT2);
1800 break;
1801 default:
1802 break;
1803 }
1804 } else {
1805 break;
1806 }
1807 }
1808 return count;
1809}
1810static int viafb_dvp1_proc_read(char *buf, char **start, off_t offset,
1811 int count, int *eof, void *data)
1812{
1813 int len = 0;
1814 u8 dvp1 = 0, dvp1_data_dri = 0, dvp1_clk_dri = 0;
1815 dvp1 = viafb_read_reg(VIACR, CR9B) & 0x0f;
1816 dvp1_data_dri = (viafb_read_reg(VIASR, SR65) & 0x0c) >> 2;
1817 dvp1_clk_dri = viafb_read_reg(VIASR, SR65) & 0x03;
1818 len +=
1819 sprintf(buf + len, "%x %x %x\n", dvp1, dvp1_data_dri, dvp1_clk_dri);
1820 *eof = 1; /*Inform kernel end of data */
1821 return len;
1822}
1823static int viafb_dvp1_proc_write(struct file *file,
1824 const char __user *buffer, unsigned long count, void *data)
1825{
1826 char buf[20], *value, *pbuf;
1827 u8 reg_val = 0;
1828 unsigned long length, i;
1829 if (count < 1)
1830 return -EINVAL;
1831 length = count > 20 ? 20 : count;
1832 if (copy_from_user(&buf[0], buffer, length))
1833 return -EFAULT;
1834 buf[length - 1] = '\0'; /*Ensure end string */
1835 pbuf = &buf[0];
1836 for (i = 0; i < 3; i++) {
1837 value = strsep(&pbuf, " ");
1838 if (value != NULL) {
1839 strict_strtoul(value, 0, (unsigned long *)&reg_val);
1840 switch (i) {
1841 case 0:
1842 viafb_write_reg_mask(CR9B, VIACR,
1843 reg_val, 0x0f);
1844 break;
1845 case 1:
1846 viafb_write_reg_mask(SR65, VIASR,
1847 reg_val << 2, 0x0c);
1848 break;
1849 case 2:
1850 viafb_write_reg_mask(SR65, VIASR,
1851 reg_val, 0x03);
1852 break;
1853 default:
1854 break;
1855 }
1856 } else {
1857 break;
1858 }
1859 }
1860 return count;
1861}
1862
1863static int viafb_dfph_proc_read(char *buf, char **start, off_t offset,
1864 int count, int *eof, void *data)
1865{
1866 int len = 0;
1867 u8 dfp_high = 0;
1868 dfp_high = viafb_read_reg(VIACR, CR97) & 0x0f;
1869 len += sprintf(buf + len, "%x\n", dfp_high);
1870 *eof = 1; /*Inform kernel end of data */
1871 return len;
1872}
1873static int viafb_dfph_proc_write(struct file *file,
1874 const char __user *buffer, unsigned long count, void *data)
1875{
1876 char buf[20];
1877 u8 reg_val = 0;
1878 unsigned long length;
1879 if (count < 1)
1880 return -EINVAL;
1881 length = count > 20 ? 20 : count;
1882 if (copy_from_user(&buf[0], buffer, length))
1883 return -EFAULT;
1884 buf[length - 1] = '\0'; /*Ensure end string */
1885 strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
1886 viafb_write_reg_mask(CR97, VIACR, reg_val, 0x0f);
1887 return count;
1888}
1889static int viafb_dfpl_proc_read(char *buf, char **start, off_t offset,
1890 int count, int *eof, void *data)
1891{
1892 int len = 0;
1893 u8 dfp_low = 0;
1894 dfp_low = viafb_read_reg(VIACR, CR99) & 0x0f;
1895 len += sprintf(buf + len, "%x\n", dfp_low);
1896 *eof = 1; /*Inform kernel end of data */
1897 return len;
1898}
1899static int viafb_dfpl_proc_write(struct file *file,
1900 const char __user *buffer, unsigned long count, void *data)
1901{
1902 char buf[20];
1903 u8 reg_val = 0;
1904 unsigned long length;
1905 if (count < 1)
1906 return -EINVAL;
1907 length = count > 20 ? 20 : count;
1908 if (copy_from_user(&buf[0], buffer, length))
1909 return -EFAULT;
1910 buf[length - 1] = '\0'; /*Ensure end string */
1911 strict_strtoul(&buf[0], 0, (unsigned long *)&reg_val);
1912 viafb_write_reg_mask(CR99, VIACR, reg_val, 0x0f);
1913 return count;
1914}
1915static int viafb_vt1636_proc_read(char *buf, char **start,
1916 off_t offset, int count, int *eof, void *data)
1917{
1918 int len = 0;
1919 u8 vt1636_08 = 0, vt1636_09 = 0;
1920 switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
1921 case VT1636_LVDS:
1922 vt1636_08 =
1923 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
1924 &viaparinfo->chip_info->lvds_chip_info, 0x08) & 0x0f;
1925 vt1636_09 =
1926 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info,
1927 &viaparinfo->chip_info->lvds_chip_info, 0x09) & 0x1f;
1928 len += sprintf(buf + len, "%x %x\n", vt1636_08, vt1636_09);
1929 break;
1930 default:
1931 break;
1932 }
1933 switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
1934 case VT1636_LVDS:
1935 vt1636_08 =
1936 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
1937 &viaparinfo->chip_info->lvds_chip_info2, 0x08) & 0x0f;
1938 vt1636_09 =
1939 viafb_gpio_i2c_read_lvds(viaparinfo->lvds_setting_info2,
1940 &viaparinfo->chip_info->lvds_chip_info2, 0x09) & 0x1f;
1941 len += sprintf(buf + len, " %x %x\n", vt1636_08, vt1636_09);
1942 break;
1943 default:
1944 break;
1945 }
1946 *eof = 1; /*Inform kernel end of data */
1947 return len;
1948}
1949static int viafb_vt1636_proc_write(struct file *file,
1950 const char __user *buffer, unsigned long count, void *data)
1951{
1952 char buf[30], *value, *pbuf;
1953 struct IODATA reg_val;
1954 unsigned long length, i;
1955 if (count < 1)
1956 return -EINVAL;
1957 length = count > 30 ? 30 : count;
1958 if (copy_from_user(&buf[0], buffer, length))
1959 return -EFAULT;
1960 buf[length - 1] = '\0'; /*Ensure end string */
1961 pbuf = &buf[0];
1962 switch (viaparinfo->chip_info->lvds_chip_info.lvds_chip_name) {
1963 case VT1636_LVDS:
1964 for (i = 0; i < 2; i++) {
1965 value = strsep(&pbuf, " ");
1966 if (value != NULL) {
1967 strict_strtoul(value, 0,
1968 (unsigned long *)&reg_val.Data);
1969 switch (i) {
1970 case 0:
1971 reg_val.Index = 0x08;
1972 reg_val.Mask = 0x0f;
1973 viafb_gpio_i2c_write_mask_lvds
1974 (viaparinfo->lvds_setting_info,
1975 &viaparinfo->
1976 chip_info->lvds_chip_info,
1977 reg_val);
1978 break;
1979 case 1:
1980 reg_val.Index = 0x09;
1981 reg_val.Mask = 0x1f;
1982 viafb_gpio_i2c_write_mask_lvds
1983 (viaparinfo->lvds_setting_info,
1984 &viaparinfo->
1985 chip_info->lvds_chip_info,
1986 reg_val);
1987 break;
1988 default:
1989 break;
1990 }
1991 } else {
1992 break;
1993 }
1994 }
1995 break;
1996 default:
1997 break;
1998 }
1999 switch (viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
2000 case VT1636_LVDS:
2001 for (i = 0; i < 2; i++) {
2002 value = strsep(&pbuf, " ");
2003 if (value != NULL) {
2004 strict_strtoul(value, 0,
2005 (unsigned long *)&reg_val.Data);
2006 switch (i) {
2007 case 0:
2008 reg_val.Index = 0x08;
2009 reg_val.Mask = 0x0f;
2010 viafb_gpio_i2c_write_mask_lvds
2011 (viaparinfo->lvds_setting_info2,
2012 &viaparinfo->
2013 chip_info->lvds_chip_info2,
2014 reg_val);
2015 break;
2016 case 1:
2017 reg_val.Index = 0x09;
2018 reg_val.Mask = 0x1f;
2019 viafb_gpio_i2c_write_mask_lvds
2020 (viaparinfo->lvds_setting_info2,
2021 &viaparinfo->
2022 chip_info->lvds_chip_info2,
2023 reg_val);
2024 break;
2025 default:
2026 break;
2027 }
2028 } else {
2029 break;
2030 }
2031 }
2032 break;
2033 default:
2034 break;
2035 }
2036 return count;
2037}
2038
2039static void viafb_init_proc(struct proc_dir_entry *viafb_entry)
2040{
2041 struct proc_dir_entry *entry;
2042 viafb_entry = proc_mkdir("viafb", NULL);
2043 if (viafb_entry) {
2044 entry = create_proc_entry("dvp0", 0, viafb_entry);
2045 if (entry) {
2046 entry->owner = THIS_MODULE;
2047 entry->read_proc = viafb_dvp0_proc_read;
2048 entry->write_proc = viafb_dvp0_proc_write;
2049 }
2050 entry = create_proc_entry("dvp1", 0, viafb_entry);
2051 if (entry) {
2052 entry->owner = THIS_MODULE;
2053 entry->read_proc = viafb_dvp1_proc_read;
2054 entry->write_proc = viafb_dvp1_proc_write;
2055 }
2056 entry = create_proc_entry("dfph", 0, viafb_entry);
2057 if (entry) {
2058 entry->owner = THIS_MODULE;
2059 entry->read_proc = viafb_dfph_proc_read;
2060 entry->write_proc = viafb_dfph_proc_write;
2061 }
2062 entry = create_proc_entry("dfpl", 0, viafb_entry);
2063 if (entry) {
2064 entry->owner = THIS_MODULE;
2065 entry->read_proc = viafb_dfpl_proc_read;
2066 entry->write_proc = viafb_dfpl_proc_write;
2067 }
2068 if (VT1636_LVDS == viaparinfo->chip_info->lvds_chip_info.
2069 lvds_chip_name || VT1636_LVDS ==
2070 viaparinfo->chip_info->lvds_chip_info2.lvds_chip_name) {
2071 entry = create_proc_entry("vt1636", 0, viafb_entry);
2072 if (entry) {
2073 entry->owner = THIS_MODULE;
2074 entry->read_proc = viafb_vt1636_proc_read;
2075 entry->write_proc = viafb_vt1636_proc_write;
2076 }
2077 }
2078
2079 }
2080}
2081static void viafb_remove_proc(struct proc_dir_entry *viafb_entry)
2082{
2083 /* no problem if it was not registered */
2084 remove_proc_entry("dvp0", viafb_entry);/* parent dir */
2085 remove_proc_entry("dvp1", viafb_entry);
2086 remove_proc_entry("dfph", viafb_entry);
2087 remove_proc_entry("dfpl", viafb_entry);
2088 remove_proc_entry("vt1636", viafb_entry);
2089 remove_proc_entry("vt1625", viafb_entry);
2090}
2091
2092static int __devinit via_pci_probe(void)
2093{
2094 unsigned int default_xres, default_yres;
2095 char *tmpc, *tmpm;
2096 char *tmpc_sec, *tmpm_sec;
2097 int vmode_index;
2098 u32 tmds_length, lvds_length, crt_length, chip_length, viafb_par_length;
2099
2100 DEBUG_MSG(KERN_INFO "VIAFB PCI Probe!!\n");
2101
2102 viafb_par_length = ALIGN(sizeof(struct viafb_par), BITS_PER_LONG/8);
2103 tmds_length = ALIGN(sizeof(struct tmds_setting_information),
2104 BITS_PER_LONG/8);
2105 lvds_length = ALIGN(sizeof(struct lvds_setting_information),
2106 BITS_PER_LONG/8);
2107 crt_length = ALIGN(sizeof(struct lvds_setting_information),
2108 BITS_PER_LONG/8);
2109 chip_length = ALIGN(sizeof(struct chip_information), BITS_PER_LONG/8);
2110
2111 /* Allocate fb_info and ***_par here, also including some other needed
2112 * variables
2113 */
2114 viafbinfo = framebuffer_alloc(viafb_par_length + 2 * lvds_length +
2115 tmds_length + crt_length + chip_length, NULL);
2116 if (!viafbinfo) {
2117 printk(KERN_ERR"Could not allocate memory for viafb_info.\n");
2118 return -ENODEV;
2119 }
2120
2121 viaparinfo = (struct viafb_par *)viafbinfo->par;
2122 viaparinfo->tmds_setting_info = (struct tmds_setting_information *)
2123 ((unsigned long)viaparinfo + viafb_par_length);
2124 viaparinfo->lvds_setting_info = (struct lvds_setting_information *)
2125 ((unsigned long)viaparinfo->tmds_setting_info + tmds_length);
2126 viaparinfo->lvds_setting_info2 = (struct lvds_setting_information *)
2127 ((unsigned long)viaparinfo->lvds_setting_info + lvds_length);
2128 viaparinfo->crt_setting_info = (struct crt_setting_information *)
2129 ((unsigned long)viaparinfo->lvds_setting_info2 + lvds_length);
2130 viaparinfo->chip_info = (struct chip_information *)
2131 ((unsigned long)viaparinfo->crt_setting_info + crt_length);
2132
2133 if (viafb_dual_fb)
2134 viafb_SAMM_ON = 1;
2135 parse_active_dev();
2136 parse_video_dev();
2137 parse_lcd_port();
2138 parse_dvi_port();
2139
2140 /* for dual-fb must viafb_SAMM_ON=1 and viafb_dual_fb=1 */
2141 if (!viafb_SAMM_ON)
2142 viafb_dual_fb = 0;
2143
2144 /* Set up I2C bus stuff */
2145 viafb_create_i2c_bus(viaparinfo);
2146
2147 viafb_init_chip_info();
2148 viafb_get_fb_info(&viaparinfo->fbmem, &viaparinfo->memsize);
2149 viaparinfo->fbmem_free = viaparinfo->memsize;
2150 viaparinfo->fbmem_used = 0;
2151 viaparinfo->fbmem_virt = ioremap_nocache(viaparinfo->fbmem,
2152 viaparinfo->memsize);
2153 viafbinfo->screen_base = (char *)viaparinfo->fbmem_virt;
2154
2155 if (!viaparinfo->fbmem_virt) {
2156 printk(KERN_INFO "ioremap failed\n");
2157 return -1;
2158 }
2159
2160 viafb_get_mmio_info(&viaparinfo->mmio_base, &viaparinfo->mmio_len);
2161 viaparinfo->io_virt = ioremap_nocache(viaparinfo->mmio_base,
2162 viaparinfo->mmio_len);
2163
2164 viafbinfo->node = 0;
2165 viafbinfo->fbops = &viafb_ops;
2166 viafbinfo->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN;
2167
2168 viafbinfo->pseudo_palette = pseudo_pal;
2169 if (viafb_accel) {
2170 viafb_init_accel();
2171 viafb_init_2d_engine();
2172 viafb_hw_cursor_init();
2173 }
2174
2175 if (viafb_second_size && (viafb_second_size < 8)) {
2176 viafb_second_offset = viaparinfo->fbmem_free -
2177 viafb_second_size * 1024 * 1024;
2178 } else {
2179 viafb_second_size = 8;
2180 viafb_second_offset = viaparinfo->fbmem_free -
2181 viafb_second_size * 1024 * 1024;
2182 }
2183
2184 viafb_FB_MM = viaparinfo->fbmem_virt;
2185 tmpm = viafb_mode;
2186 tmpc = strsep(&tmpm, "x");
2187 strict_strtoul(tmpc, 0, (unsigned long *)&default_xres);
2188 strict_strtoul(tmpm, 0, (unsigned long *)&default_yres);
2189
2190 vmode_index = viafb_get_mode_index(default_xres, default_yres, 0);
2191 DEBUG_MSG(KERN_INFO "0->index=%d\n", vmode_index);
2192
2193 if (viafb_SAMM_ON == 1) {
2194 if (strcmp(viafb_mode, viafb_mode1)) {
2195 tmpm_sec = viafb_mode1;
2196 tmpc_sec = strsep(&tmpm_sec, "x");
2197 strict_strtoul(tmpc_sec, 0,
2198 (unsigned long *)&viafb_second_xres);
2199 strict_strtoul(tmpm_sec, 0,
2200 (unsigned long *)&viafb_second_yres);
2201 } else {
2202 viafb_second_xres = default_xres;
2203 viafb_second_yres = default_yres;
2204 }
2205 if (0 == viafb_second_virtual_xres) {
2206 switch (viafb_second_xres) {
2207 case 1400:
2208 viafb_second_virtual_xres = 1408;
2209 break;
2210 default:
2211 viafb_second_virtual_xres = viafb_second_xres;
2212 break;
2213 }
2214 }
2215 if (0 == viafb_second_virtual_yres)
2216 viafb_second_virtual_yres = viafb_second_yres;
2217 }
2218
2219 switch (viafb_bpp) {
2220 case 0 ... 8:
2221 viafb_bpp = 8;
2222 break;
2223 case 9 ... 16:
2224 viafb_bpp = 16;
2225 break;
2226 case 17 ... 32:
2227 viafb_bpp = 32;
2228 break;
2229 default:
2230 viafb_bpp = 8;
2231 }
2232 default_var.xres = default_xres;
2233 default_var.yres = default_yres;
2234 switch (default_xres) {
2235 case 1400:
2236 default_var.xres_virtual = 1408;
2237 break;
2238 default:
2239 default_var.xres_virtual = default_xres;
2240 break;
2241 }
2242 default_var.yres_virtual = default_yres;
2243 default_var.bits_per_pixel = viafb_bpp;
2244 if (default_var.bits_per_pixel == 15)
2245 default_var.bits_per_pixel = 16;
2246 default_var.pixclock =
2247 viafb_get_pixclock(default_xres, default_yres, viafb_refresh);
2248 default_var.left_margin = (default_xres >> 3) & 0xf8;
2249 default_var.right_margin = 32;
2250 default_var.upper_margin = 16;
2251 default_var.lower_margin = 4;
2252 default_var.hsync_len = default_var.left_margin;
2253 default_var.vsync_len = 4;
2254 default_var.accel_flags = 0;
2255
2256 if (viafb_accel) {
2257 viafbinfo->flags |=
2258 (FBINFO_HWACCEL_COPYAREA | FBINFO_HWACCEL_FILLRECT |
2259 FBINFO_HWACCEL_IMAGEBLIT);
2260 default_var.accel_flags |= FB_ACCELF_TEXT;
2261 } else
2262 viafbinfo->flags |= FBINFO_HWACCEL_DISABLED;
2263
2264 if (viafb_dual_fb) {
2265 viafbinfo1 = framebuffer_alloc(viafb_par_length, NULL);
2266 if (!viafbinfo1) {
2267 printk(KERN_ERR
2268 "allocate the second framebuffer struct error\n");
2269 framebuffer_release(viafbinfo);
2270 return -ENOMEM;
2271 }
2272 viaparinfo1 = viafbinfo1->par;
2273 memcpy(viaparinfo1, viaparinfo, viafb_par_length);
2274 viaparinfo1->memsize = viaparinfo->memsize -
2275 viafb_second_offset;
2276 viaparinfo->memsize = viafb_second_offset;
2277 viaparinfo1->fbmem_virt = viaparinfo->fbmem_virt +
2278 viafb_second_offset;
2279 viaparinfo1->fbmem = viaparinfo->fbmem + viafb_second_offset;
2280
2281 viaparinfo1->fbmem_used = viaparinfo->fbmem_used;
2282 viaparinfo1->fbmem_free = viaparinfo1->memsize -
2283 viaparinfo1->fbmem_used;
2284 viaparinfo->fbmem_free = viaparinfo->memsize;
2285 viaparinfo->fbmem_used = 0;
2286 if (viafb_accel) {
2287 viaparinfo1->cursor_start =
2288 viaparinfo->cursor_start - viafb_second_offset;
2289 viaparinfo1->VQ_start = viaparinfo->VQ_start -
2290 viafb_second_offset;
2291 viaparinfo1->VQ_end = viaparinfo->VQ_end -
2292 viafb_second_offset;
2293 }
2294
2295 memcpy(viafbinfo1, viafbinfo, sizeof(struct fb_info));
2296 viafbinfo1->screen_base = viafbinfo->screen_base +
2297 viafb_second_offset;
2298 viafbinfo1->fix.smem_start = viaparinfo1->fbmem;
2299 viafbinfo1->fix.smem_len = viaparinfo1->fbmem_free;
2300
2301 default_var.xres = viafb_second_xres;
2302 default_var.yres = viafb_second_yres;
2303 default_var.xres_virtual = viafb_second_virtual_xres;
2304 default_var.yres_virtual = viafb_second_virtual_yres;
2305 if (viafb_bpp1 != viafb_bpp)
2306 viafb_bpp1 = viafb_bpp;
2307 default_var.bits_per_pixel = viafb_bpp1;
2308 default_var.pixclock =
2309 viafb_get_pixclock(viafb_second_xres, viafb_second_yres,
2310 viafb_refresh);
2311 default_var.left_margin = (viafb_second_xres >> 3) & 0xf8;
2312 default_var.right_margin = 32;
2313 default_var.upper_margin = 16;
2314 default_var.lower_margin = 4;
2315 default_var.hsync_len = default_var.left_margin;
2316 default_var.vsync_len = 4;
2317
2318 viafb_setup_fixinfo(&viafbinfo1->fix, viaparinfo1);
2319 viafb_check_var(&default_var, viafbinfo1);
2320 viafbinfo1->var = default_var;
2321 viafb_update_viafb_par(viafbinfo);
2322 viafb_update_fix(&viafbinfo1->fix, viafbinfo1);
2323 }
2324
2325 viafb_setup_fixinfo(&viafbinfo->fix, viaparinfo);
2326 viafb_check_var(&default_var, viafbinfo);
2327 viafbinfo->var = default_var;
2328 viafb_update_viafb_par(viafbinfo);
2329 viafb_update_fix(&viafbinfo->fix, viafbinfo);
2330 default_var.activate = FB_ACTIVATE_NOW;
2331 fb_alloc_cmap(&viafbinfo->cmap, 256, 0);
2332
2333 if (viafb_dual_fb && (viafb_primary_dev == LCD_Device)
2334 && (viaparinfo->chip_info->gfx_chip_name == UNICHROME_CLE266)) {
2335 if (register_framebuffer(viafbinfo1) < 0)
2336 return -EINVAL;
2337 }
2338 if (register_framebuffer(viafbinfo) < 0)
2339 return -EINVAL;
2340
2341 if (viafb_dual_fb && ((viafb_primary_dev != LCD_Device)
2342 || (viaparinfo->chip_info->gfx_chip_name !=
2343 UNICHROME_CLE266))) {
2344 if (register_framebuffer(viafbinfo1) < 0)
2345 return -EINVAL;
2346 }
2347 DEBUG_MSG(KERN_INFO "fb%d: %s frame buffer device %dx%d-%dbpp\n",
2348 viafbinfo->node, viafbinfo->fix.id, default_var.xres,
2349 default_var.yres, default_var.bits_per_pixel);
2350
2351 viafb_init_proc(viaparinfo->proc_entry);
2352 viafb_init_dac(IGA2);
2353 return 0;
2354}
2355
2356static void __devexit via_pci_remove(void)
2357{
2358 DEBUG_MSG(KERN_INFO "via_pci_remove!\n");
2359 fb_dealloc_cmap(&viafbinfo->cmap);
2360 unregister_framebuffer(viafbinfo);
2361 if (viafb_dual_fb)
2362 unregister_framebuffer(viafbinfo1);
2363 iounmap((void *)viaparinfo->fbmem_virt);
2364 iounmap(viaparinfo->io_virt);
2365
2366 viafb_delete_i2c_buss(viaparinfo);
2367
2368 framebuffer_release(viafbinfo);
2369 if (viafb_dual_fb)
2370 framebuffer_release(viafbinfo1);
2371
2372 viafb_remove_proc(viaparinfo->proc_entry);
2373}
2374
2375#ifndef MODULE
2376static int __init viafb_setup(char *options)
2377{
2378 char *this_opt;
2379 DEBUG_MSG(KERN_INFO "viafb_setup!\n");
2380
2381 if (!options || !*options)
2382 return 0;
2383
2384 while ((this_opt = strsep(&options, ",")) != NULL) {
2385 if (!*this_opt)
2386 continue;
2387
2388 if (!strncmp(this_opt, "viafb_mode1=", 12))
2389 viafb_mode1 = kstrdup(this_opt + 12, GFP_KERNEL);
2390 else if (!strncmp(this_opt, "viafb_mode=", 11))
2391 viafb_mode = kstrdup(this_opt + 11, GFP_KERNEL);
2392 else if (!strncmp(this_opt, "viafb_bpp1=", 11))
2393 strict_strtoul(this_opt + 11, 0,
2394 (unsigned long *)&viafb_bpp1);
2395 else if (!strncmp(this_opt, "viafb_bpp=", 10))
2396 strict_strtoul(this_opt + 10, 0,
2397 (unsigned long *)&viafb_bpp);
2398 else if (!strncmp(this_opt, "viafb_refresh1=", 15))
2399 strict_strtoul(this_opt + 15, 0,
2400 (unsigned long *)&viafb_refresh1);
2401 else if (!strncmp(this_opt, "viafb_refresh=", 14))
2402 strict_strtoul(this_opt + 14, 0,
2403 (unsigned long *)&viafb_refresh);
2404 else if (!strncmp(this_opt, "viafb_lcd_dsp_method=", 21))
2405 strict_strtoul(this_opt + 21, 0,
2406 (unsigned long *)&viafb_lcd_dsp_method);
2407 else if (!strncmp(this_opt, "viafb_lcd_panel_id=", 19))
2408 strict_strtoul(this_opt + 19, 0,
2409 (unsigned long *)&viafb_lcd_panel_id);
2410 else if (!strncmp(this_opt, "viafb_accel=", 12))
2411 strict_strtoul(this_opt + 12, 0,
2412 (unsigned long *)&viafb_accel);
2413 else if (!strncmp(this_opt, "viafb_SAMM_ON=", 14))
2414 strict_strtoul(this_opt + 14, 0,
2415 (unsigned long *)&viafb_SAMM_ON);
2416 else if (!strncmp(this_opt, "viafb_active_dev=", 17))
2417 viafb_active_dev = kstrdup(this_opt + 17, GFP_KERNEL);
2418 else if (!strncmp(this_opt,
2419 "viafb_display_hardware_layout=", 30))
2420 strict_strtoul(this_opt + 30, 0,
2421 (unsigned long *)&viafb_display_hardware_layout);
2422 else if (!strncmp(this_opt, "viafb_second_size=", 18))
2423 strict_strtoul(this_opt + 18, 0,
2424 (unsigned long *)&viafb_second_size);
2425 else if (!strncmp(this_opt,
2426 "viafb_platform_epia_dvi=", 24))
2427 strict_strtoul(this_opt + 24, 0,
2428 (unsigned long *)&viafb_platform_epia_dvi);
2429 else if (!strncmp(this_opt,
2430 "viafb_device_lcd_dualedge=", 26))
2431 strict_strtoul(this_opt + 26, 0,
2432 (unsigned long *)&viafb_device_lcd_dualedge);
2433 else if (!strncmp(this_opt, "viafb_bus_width=", 16))
2434 strict_strtoul(this_opt + 16, 0,
2435 (unsigned long *)&viafb_bus_width);
2436 else if (!strncmp(this_opt, "viafb_lcd_mode=", 15))
2437 strict_strtoul(this_opt + 15, 0,
2438 (unsigned long *)&viafb_lcd_mode);
2439 else if (!strncmp(this_opt, "viafb_video_dev=", 16))
2440 viafb_video_dev = kstrdup(this_opt + 16, GFP_KERNEL);
2441 else if (!strncmp(this_opt, "viafb_lcd_port=", 15))
2442 viafb_lcd_port = kstrdup(this_opt + 15, GFP_KERNEL);
2443 else if (!strncmp(this_opt, "viafb_dvi_port=", 15))
2444 viafb_dvi_port = kstrdup(this_opt + 15, GFP_KERNEL);
2445 }
2446 return 0;
2447}
2448#endif
2449
2450static int __init viafb_init(void)
2451{
2452#ifndef MODULE
2453 char *option = NULL;
2454 if (fb_get_options("viafb", &option))
2455 return -ENODEV;
2456 viafb_setup(option);
2457#endif
2458 printk(KERN_INFO
2459 "VIA Graphics Intergration Chipset framebuffer %d.%d initializing\n",
2460 VERSION_MAJOR, VERSION_MINOR);
2461 return via_pci_probe();
2462}
2463
2464static void __exit viafb_exit(void)
2465{
2466 DEBUG_MSG(KERN_INFO "viafb_exit!\n");
2467 via_pci_remove();
2468}
2469
2470static struct fb_ops viafb_ops = {
2471 .owner = THIS_MODULE,
2472 .fb_open = viafb_open,
2473 .fb_release = viafb_release,
2474 .fb_check_var = viafb_check_var,
2475 .fb_set_par = viafb_set_par,
2476 .fb_setcolreg = viafb_setcolreg,
2477 .fb_pan_display = viafb_pan_display,
2478 .fb_blank = viafb_blank,
2479 .fb_fillrect = viafb_fillrect,
2480 .fb_copyarea = viafb_copyarea,
2481 .fb_imageblit = viafb_imageblit,
2482 .fb_cursor = viafb_cursor,
2483 .fb_ioctl = viafb_ioctl,
2484 .fb_sync = viafb_sync,
2485 .fb_setcmap = viafb_setcmap,
2486};
2487
2488module_init(viafb_init);
2489module_exit(viafb_exit);
2490
2491#ifdef MODULE
2492module_param(viafb_memsize, int, 0);
2493
2494module_param(viafb_mode, charp, 0);
2495MODULE_PARM_DESC(viafb_mode, "Set resolution (default=640x480)");
2496
2497module_param(viafb_mode1, charp, 0);
2498MODULE_PARM_DESC(viafb_mode1, "Set resolution (default=640x480)");
2499
2500module_param(viafb_bpp, int, 0);
2501MODULE_PARM_DESC(viafb_bpp, "Set color depth (default=32bpp)");
2502
2503module_param(viafb_bpp1, int, 0);
2504MODULE_PARM_DESC(viafb_bpp1, "Set color depth (default=32bpp)");
2505
2506module_param(viafb_refresh, int, 0);
2507MODULE_PARM_DESC(viafb_refresh,
2508 "Set CRT viafb_refresh rate (default = 60)");
2509
2510module_param(viafb_refresh1, int, 0);
2511MODULE_PARM_DESC(viafb_refresh1,
2512 "Set CRT refresh rate (default = 60)");
2513
2514module_param(viafb_lcd_panel_id, int, 0);
2515MODULE_PARM_DESC(viafb_lcd_panel_id,
2516 "Set Flat Panel type(Default=1024x768)");
2517
2518module_param(viafb_lcd_dsp_method, int, 0);
2519MODULE_PARM_DESC(viafb_lcd_dsp_method,
2520 "Set Flat Panel display scaling method.(Default=Expandsion)");
2521
2522module_param(viafb_SAMM_ON, int, 0);
2523MODULE_PARM_DESC(viafb_SAMM_ON,
2524 "Turn on/off flag of SAMM(Default=OFF)");
2525
2526module_param(viafb_accel, int, 0);
2527MODULE_PARM_DESC(viafb_accel,
2528 "Set 2D Hardware Acceleration.(Default = OFF)");
2529
2530module_param(viafb_active_dev, charp, 0);
2531MODULE_PARM_DESC(viafb_active_dev, "Specify active devices.");
2532
2533module_param(viafb_display_hardware_layout, int, 0);
2534MODULE_PARM_DESC(viafb_display_hardware_layout,
2535 "Display Hardware Layout (LCD Only, DVI Only...,etc)");
2536
2537module_param(viafb_second_size, int, 0);
2538MODULE_PARM_DESC(viafb_second_size,
2539 "Set secondary device memory size");
2540
2541module_param(viafb_dual_fb, int, 0);
2542MODULE_PARM_DESC(viafb_dual_fb,
2543 "Turn on/off flag of dual framebuffer devices.(Default = OFF)");
2544
2545module_param(viafb_platform_epia_dvi, int, 0);
2546MODULE_PARM_DESC(viafb_platform_epia_dvi,
2547 "Turn on/off flag of DVI devices on EPIA board.(Default = OFF)");
2548
2549module_param(viafb_device_lcd_dualedge, int, 0);
2550MODULE_PARM_DESC(viafb_device_lcd_dualedge,
2551 "Turn on/off flag of dual edge panel.(Default = OFF)");
2552
2553module_param(viafb_bus_width, int, 0);
2554MODULE_PARM_DESC(viafb_bus_width,
2555 "Set bus width of panel.(Default = 12)");
2556
2557module_param(viafb_lcd_mode, int, 0);
2558MODULE_PARM_DESC(viafb_lcd_mode,
2559 "Set Flat Panel mode(Default=OPENLDI)");
2560
2561module_param(viafb_video_dev, charp, 0);
2562MODULE_PARM_DESC(viafb_video_dev, "Specify video devices.");
2563
2564module_param(viafb_lcd_port, charp, 0);
2565MODULE_PARM_DESC(viafb_lcd_port, "Specify LCD output port.");
2566
2567module_param(viafb_dvi_port, charp, 0);
2568MODULE_PARM_DESC(viafb_dvi_port, "Specify DVI output port.");
2569
2570MODULE_LICENSE("GPL");
2571#endif
diff --git a/drivers/video/via/viafbdev.h b/drivers/video/via/viafbdev.h
new file mode 100644
index 000000000000..a4158e872878
--- /dev/null
+++ b/drivers/video/via/viafbdev.h
@@ -0,0 +1,112 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#ifndef __VIAFBDEV_H__
23#define __VIAFBDEV_H__
24
25#include <linux/proc_fs.h>
26#include <linux/fb.h>
27
28#include "ioctl.h"
29#include "share.h"
30#include "chip.h"
31#include "hw.h"
32#include "via_i2c.h"
33
34#define VERSION_MAJOR 2
35#define VERSION_KERNEL 6 /* For kernel 2.6 */
36
37#define VERSION_OS 0 /* 0: for 32 bits OS, 1: for 64 bits OS */
38#define VERSION_MINOR 4
39
40struct viafb_par {
41 int bpp;
42 int hres;
43 int vres;
44 int linelength;
45 u32 xoffset;
46 u32 yoffset;
47
48 void __iomem *fbmem_virt; /*framebuffer virtual memory address */
49 void __iomem *io_virt; /*iospace virtual memory address */
50 unsigned int fbmem; /*framebuffer physical memory address */
51 unsigned int memsize; /*size of fbmem */
52 unsigned int io; /*io space address */
53 unsigned long mmio_base; /*mmio base address */
54 unsigned long mmio_len; /*mmio base length */
55 u32 fbmem_free; /* Free FB memory */
56 u32 fbmem_used; /* Use FB memory size */
57 u32 cursor_start; /* Cursor Start Address */
58 u32 VQ_start; /* Virtual Queue Start Address */
59 u32 VQ_end; /* Virtual Queue End Address */
60 u32 iga_path;
61 struct proc_dir_entry *proc_entry; /*viafb proc entry */
62 u8 duoview; /*Is working in duoview mode? */
63
64 /* I2C stuff */
65 struct via_i2c_stuff i2c_stuff;
66
67 /* All the information will be needed to set engine */
68 struct tmds_setting_information *tmds_setting_info;
69 struct crt_setting_information *crt_setting_info;
70 struct lvds_setting_information *lvds_setting_info;
71 struct lvds_setting_information *lvds_setting_info2;
72 struct chip_information *chip_info;
73
74 /* some information related to video playing */
75 int video_on_crt;
76 int video_on_dvi;
77 int video_on_lcd;
78
79};
80struct viafb_modeinfo {
81 u32 xres;
82 u32 yres;
83 int mode_index;
84 char *mode_res;
85};
86extern unsigned int viafb_second_virtual_yres;
87extern unsigned int viafb_second_virtual_xres;
88extern unsigned int viafb_second_offset;
89extern int viafb_second_size;
90extern int viafb_SAMM_ON;
91extern int viafb_dual_fb;
92extern int viafb_LCD2_ON;
93extern int viafb_LCD_ON;
94extern int viafb_DVI_ON;
95extern int viafb_accel;
96extern int viafb_hotplug;
97extern int viafb_memsize;
98
99extern int strict_strtoul(const char *cp, unsigned int base,
100 unsigned long *res);
101
102void viafb_memory_pitch_patch(struct fb_info *info);
103void viafb_fill_var_timing_info(struct fb_var_screeninfo *var, int refresh,
104 int mode_index);
105int viafb_get_mode_index(int hres, int vres, int flag);
106u8 viafb_gpio_i2c_read_lvds(struct lvds_setting_information
107 *plvds_setting_info, struct lvds_chip_information
108 *plvds_chip_info, u8 index);
109void viafb_gpio_i2c_write_mask_lvds(struct lvds_setting_information
110 *plvds_setting_info, struct lvds_chip_information
111 *plvds_chip_info, struct IODATA io_data);
112#endif /* __VIAFBDEV_H__ */
diff --git a/drivers/video/via/viamode.c b/drivers/video/via/viamode.c
new file mode 100644
index 000000000000..6dcf583a837d
--- /dev/null
+++ b/drivers/video/via/viamode.c
@@ -0,0 +1,1086 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#include "global.h"
23struct res_map_refresh res_map_refresh_tbl[] = {
24/*hres, vres, vclock, vmode_refresh*/
25 {480, 640, RES_480X640_60HZ_PIXCLOCK, 60},
26 {640, 480, RES_640X480_60HZ_PIXCLOCK, 60},
27 {640, 480, RES_640X480_75HZ_PIXCLOCK, 75},
28 {640, 480, RES_640X480_85HZ_PIXCLOCK, 85},
29 {640, 480, RES_640X480_100HZ_PIXCLOCK, 100},
30 {640, 480, RES_640X480_120HZ_PIXCLOCK, 120},
31 {720, 480, RES_720X480_60HZ_PIXCLOCK, 60},
32 {720, 576, RES_720X576_60HZ_PIXCLOCK, 60},
33 {800, 480, RES_800X480_60HZ_PIXCLOCK, 60},
34 {800, 600, RES_800X600_60HZ_PIXCLOCK, 60},
35 {800, 600, RES_800X600_75HZ_PIXCLOCK, 75},
36 {800, 600, RES_800X600_85HZ_PIXCLOCK, 85},
37 {800, 600, RES_800X600_100HZ_PIXCLOCK, 100},
38 {800, 600, RES_800X600_120HZ_PIXCLOCK, 120},
39 {848, 480, RES_848X480_60HZ_PIXCLOCK, 60},
40 {856, 480, RES_856X480_60HZ_PIXCLOCK, 60},
41 {1024, 512, RES_1024X512_60HZ_PIXCLOCK, 60},
42 {1024, 600, RES_1024X600_60HZ_PIXCLOCK, 60},
43 {1024, 768, RES_1024X768_60HZ_PIXCLOCK, 60},
44 {1024, 768, RES_1024X768_75HZ_PIXCLOCK, 75},
45 {1024, 768, RES_1024X768_85HZ_PIXCLOCK, 85},
46 {1024, 768, RES_1024X768_100HZ_PIXCLOCK, 100},
47/* {1152,864, RES_1152X864_70HZ_PIXCLOCK, 70},*/
48 {1152, 864, RES_1152X864_75HZ_PIXCLOCK, 75},
49 {1280, 768, RES_1280X768_60HZ_PIXCLOCK, 60},
50 {1280, 800, RES_1280X800_60HZ_PIXCLOCK, 60},
51 {1280, 960, RES_1280X960_60HZ_PIXCLOCK, 60},
52 {1280, 1024, RES_1280X1024_60HZ_PIXCLOCK, 60},
53 {1280, 1024, RES_1280X1024_75HZ_PIXCLOCK, 75},
54 {1280, 1024, RES_1280X768_85HZ_PIXCLOCK, 85},
55 {1440, 1050, RES_1440X1050_60HZ_PIXCLOCK, 60},
56 {1600, 1200, RES_1600X1200_60HZ_PIXCLOCK, 60},
57 {1600, 1200, RES_1600X1200_75HZ_PIXCLOCK, 75},
58 {1280, 720, RES_1280X720_60HZ_PIXCLOCK, 60},
59 {1920, 1080, RES_1920X1080_60HZ_PIXCLOCK, 60},
60 {1400, 1050, RES_1400X1050_60HZ_PIXCLOCK, 60},
61 {1400, 1050, RES_1400X1050_75HZ_PIXCLOCK, 75},
62 {1368, 768, RES_1368X768_60HZ_PIXCLOCK, 60},
63 {960, 600, RES_960X600_60HZ_PIXCLOCK, 60},
64 {1000, 600, RES_1000X600_60HZ_PIXCLOCK, 60},
65 {1024, 576, RES_1024X576_60HZ_PIXCLOCK, 60},
66 {1088, 612, RES_1088X612_60HZ_PIXCLOCK, 60},
67 {1152, 720, RES_1152X720_60HZ_PIXCLOCK, 60},
68 {1200, 720, RES_1200X720_60HZ_PIXCLOCK, 60},
69 {1280, 600, RES_1280X600_60HZ_PIXCLOCK, 60},
70 {1280, 720, RES_1280X720_50HZ_PIXCLOCK, 50},
71 {1280, 768, RES_1280X768_50HZ_PIXCLOCK, 50},
72 {1360, 768, RES_1360X768_60HZ_PIXCLOCK, 60},
73 {1366, 768, RES_1366X768_50HZ_PIXCLOCK, 50},
74 {1366, 768, RES_1366X768_60HZ_PIXCLOCK, 60},
75 {1440, 900, RES_1440X900_60HZ_PIXCLOCK, 60},
76 {1440, 900, RES_1440X900_75HZ_PIXCLOCK, 75},
77 {1600, 900, RES_1600X900_60HZ_PIXCLOCK, 60},
78 {1600, 1024, RES_1600X1024_60HZ_PIXCLOCK, 60},
79 {1680, 1050, RES_1680X1050_60HZ_PIXCLOCK, 60},
80 {1680, 1050, RES_1680X1050_75HZ_PIXCLOCK, 75},
81 {1792, 1344, RES_1792X1344_60HZ_PIXCLOCK, 60},
82 {1856, 1392, RES_1856X1392_60HZ_PIXCLOCK, 60},
83 {1920, 1200, RES_1920X1200_60HZ_PIXCLOCK, 60},
84 {1920, 1440, RES_1920X1440_60HZ_PIXCLOCK, 60},
85 {1920, 1440, RES_1920X1440_75HZ_PIXCLOCK, 75},
86 {2048, 1536, RES_2048X1536_60HZ_PIXCLOCK, 60}
87};
88
89struct io_reg CN400_ModeXregs[] = { {VIASR, SR10, 0xFF, 0x01},
90{VIASR, SR15, 0x02, 0x02},
91{VIASR, SR16, 0xBF, 0x08},
92{VIASR, SR17, 0xFF, 0x1F},
93{VIASR, SR18, 0xFF, 0x4E},
94{VIASR, SR1A, 0xFB, 0x08},
95{VIASR, SR1E, 0x0F, 0x01},
96{VIASR, SR2A, 0xFF, 0x00},
97{VIACR, CR0A, 0xFF, 0x1E}, /* Cursor Start */
98{VIACR, CR0B, 0xFF, 0x00}, /* Cursor End */
99{VIACR, CR0E, 0xFF, 0x00}, /* Cursor Location High */
100{VIACR, CR0F, 0xFF, 0x00}, /* Cursor Localtion Low */
101{VIACR, CR32, 0xFF, 0x00},
102{VIACR, CR33, 0xFF, 0x00},
103{VIACR, CR34, 0xFF, 0x00},
104{VIACR, CR35, 0xFF, 0x00},
105{VIACR, CR36, 0x08, 0x00},
106{VIACR, CR62, 0xFF, 0x00}, /* Secondary Display Starting Address */
107{VIACR, CR63, 0xFF, 0x00}, /* Secondary Display Starting Address */
108{VIACR, CR64, 0xFF, 0x00}, /* Secondary Display Starting Address */
109{VIACR, CR69, 0xFF, 0x00},
110{VIACR, CR6A, 0xFF, 0x40},
111{VIACR, CR6B, 0xFF, 0x00},
112{VIACR, CR6C, 0xFF, 0x00},
113{VIACR, CR7A, 0xFF, 0x01}, /* LCD Scaling Parameter 1 */
114{VIACR, CR7B, 0xFF, 0x02}, /* LCD Scaling Parameter 2 */
115{VIACR, CR7C, 0xFF, 0x03}, /* LCD Scaling Parameter 3 */
116{VIACR, CR7D, 0xFF, 0x04}, /* LCD Scaling Parameter 4 */
117{VIACR, CR7E, 0xFF, 0x07}, /* LCD Scaling Parameter 5 */
118{VIACR, CR7F, 0xFF, 0x0A}, /* LCD Scaling Parameter 6 */
119{VIACR, CR80, 0xFF, 0x0D}, /* LCD Scaling Parameter 7 */
120{VIACR, CR81, 0xFF, 0x13}, /* LCD Scaling Parameter 8 */
121{VIACR, CR82, 0xFF, 0x16}, /* LCD Scaling Parameter 9 */
122{VIACR, CR83, 0xFF, 0x19}, /* LCD Scaling Parameter 10 */
123{VIACR, CR84, 0xFF, 0x1C}, /* LCD Scaling Parameter 11 */
124{VIACR, CR85, 0xFF, 0x1D}, /* LCD Scaling Parameter 12 */
125{VIACR, CR86, 0xFF, 0x1E}, /* LCD Scaling Parameter 13 */
126{VIACR, CR87, 0xFF, 0x1F}, /* LCD Scaling Parameter 14 */
127{VIACR, CR88, 0xFF, 0x40}, /* LCD Panel Type */
128{VIACR, CR89, 0xFF, 0x00}, /* LCD Timing Control 0 */
129{VIACR, CR8A, 0xFF, 0x88}, /* LCD Timing Control 1 */
130{VIACR, CR8B, 0xFF, 0x69}, /* LCD Power Sequence Control 0 */
131{VIACR, CR8C, 0xFF, 0x57}, /* LCD Power Sequence Control 1 */
132{VIACR, CR8D, 0xFF, 0x00}, /* LCD Power Sequence Control 2 */
133{VIACR, CR8E, 0xFF, 0x7B}, /* LCD Power Sequence Control 3 */
134{VIACR, CR8F, 0xFF, 0x03}, /* LCD Power Sequence Control 4 */
135{VIACR, CR90, 0xFF, 0x30}, /* LCD Power Sequence Control 5 */
136{VIACR, CR91, 0xFF, 0xA0}, /* 24/12 bit LVDS Data off */
137{VIACR, CR96, 0xFF, 0x00},
138{VIACR, CR97, 0xFF, 0x00},
139{VIACR, CR99, 0xFF, 0x00},
140{VIACR, CR9B, 0xFF, 0x00}
141};
142
143/* Video Mode Table for VT3314 chipset*/
144/* Common Setting for Video Mode */
145struct io_reg CN700_ModeXregs[] = { {VIASR, SR10, 0xFF, 0x01},
146{VIASR, SR15, 0x02, 0x02},
147{VIASR, SR16, 0xBF, 0x08},
148{VIASR, SR17, 0xFF, 0x1F},
149{VIASR, SR18, 0xFF, 0x4E},
150{VIASR, SR1A, 0xFB, 0x82},
151{VIASR, SR1B, 0xFF, 0xF0},
152{VIASR, SR1F, 0xFF, 0x00},
153{VIASR, SR1E, 0xFF, 0x01},
154{VIASR, SR22, 0xFF, 0x1F},
155{VIASR, SR2A, 0x0F, 0x00},
156{VIASR, SR2E, 0xFF, 0xFF},
157{VIASR, SR3F, 0xFF, 0xFF},
158{VIASR, SR40, 0xF7, 0x00},
159{VIASR, CR30, 0xFF, 0x04},
160{VIACR, CR32, 0xFF, 0x00},
161{VIACR, CR33, 0x7F, 0x00},
162{VIACR, CR34, 0xFF, 0x00},
163{VIACR, CR35, 0xFF, 0x00},
164{VIACR, CR36, 0xFF, 0x31},
165{VIACR, CR41, 0xFF, 0x80},
166{VIACR, CR42, 0xFF, 0x00},
167{VIACR, CR55, 0x80, 0x00},
168{VIACR, CR5D, 0x80, 0x00}, /*Horizontal Retrace Start bit[11] should be 0*/
169{VIACR, CR62, 0xFF, 0x00}, /* Secondary Display Starting Address */
170{VIACR, CR63, 0xFF, 0x00}, /* Secondary Display Starting Address */
171{VIACR, CR64, 0xFF, 0x00}, /* Secondary Display Starting Address */
172{VIACR, CR68, 0xFF, 0x67}, /* Default FIFO For IGA2 */
173{VIACR, CR69, 0xFF, 0x00},
174{VIACR, CR6A, 0xFD, 0x40},
175{VIACR, CR6B, 0xFF, 0x00},
176{VIACR, CR6C, 0xFF, 0x00},
177{VIACR, CR77, 0xFF, 0x00}, /* LCD scaling Factor */
178{VIACR, CR78, 0xFF, 0x00}, /* LCD scaling Factor */
179{VIACR, CR79, 0xFF, 0x00}, /* LCD scaling Factor */
180{VIACR, CR9F, 0x03, 0x00}, /* LCD scaling Factor */
181{VIACR, CR7A, 0xFF, 0x01}, /* LCD Scaling Parameter 1 */
182{VIACR, CR7B, 0xFF, 0x02}, /* LCD Scaling Parameter 2 */
183{VIACR, CR7C, 0xFF, 0x03}, /* LCD Scaling Parameter 3 */
184{VIACR, CR7D, 0xFF, 0x04}, /* LCD Scaling Parameter 4 */
185{VIACR, CR7E, 0xFF, 0x07}, /* LCD Scaling Parameter 5 */
186{VIACR, CR7F, 0xFF, 0x0A}, /* LCD Scaling Parameter 6 */
187{VIACR, CR80, 0xFF, 0x0D}, /* LCD Scaling Parameter 7 */
188{VIACR, CR81, 0xFF, 0x13}, /* LCD Scaling Parameter 8 */
189{VIACR, CR82, 0xFF, 0x16}, /* LCD Scaling Parameter 9 */
190{VIACR, CR83, 0xFF, 0x19}, /* LCD Scaling Parameter 10 */
191{VIACR, CR84, 0xFF, 0x1C}, /* LCD Scaling Parameter 11 */
192{VIACR, CR85, 0xFF, 0x1D}, /* LCD Scaling Parameter 12 */
193{VIACR, CR86, 0xFF, 0x1E}, /* LCD Scaling Parameter 13 */
194{VIACR, CR87, 0xFF, 0x1F}, /* LCD Scaling Parameter 14 */
195{VIACR, CR88, 0xFF, 0x40}, /* LCD Panel Type */
196{VIACR, CR89, 0xFF, 0x00}, /* LCD Timing Control 0 */
197{VIACR, CR8A, 0xFF, 0x88}, /* LCD Timing Control 1 */
198{VIACR, CR8B, 0xFF, 0x5D}, /* LCD Power Sequence Control 0 */
199{VIACR, CR8C, 0xFF, 0x2B}, /* LCD Power Sequence Control 1 */
200{VIACR, CR8D, 0xFF, 0x6F}, /* LCD Power Sequence Control 2 */
201{VIACR, CR8E, 0xFF, 0x2B}, /* LCD Power Sequence Control 3 */
202{VIACR, CR8F, 0xFF, 0x01}, /* LCD Power Sequence Control 4 */
203{VIACR, CR90, 0xFF, 0x01}, /* LCD Power Sequence Control 5 */
204{VIACR, CR91, 0xFF, 0xA0}, /* 24/12 bit LVDS Data off */
205{VIACR, CR96, 0xFF, 0x00},
206{VIACR, CR97, 0xFF, 0x00},
207{VIACR, CR99, 0xFF, 0x00},
208{VIACR, CR9B, 0xFF, 0x00},
209{VIACR, CR9D, 0xFF, 0x80},
210{VIACR, CR9E, 0xFF, 0x80}
211};
212
213struct io_reg KM400_ModeXregs[] = {
214 {VIASR, SR10, 0xFF, 0x01}, /* Unlock Register */
215 {VIASR, SR16, 0xFF, 0x08}, /* Display FIFO threshold Control */
216 {VIASR, SR17, 0xFF, 0x1F}, /* Display FIFO Control */
217 {VIASR, SR18, 0xFF, 0x4E}, /* GFX PREQ threshold */
218 {VIASR, SR1A, 0xFF, 0x0a}, /* GFX PREQ threshold */
219 {VIASR, SR1F, 0xFF, 0x00}, /* Memory Control 0 */
220 {VIASR, SR1B, 0xFF, 0xF0}, /* Power Management Control 0 */
221 {VIASR, SR1E, 0xFF, 0x01}, /* Power Management Control */
222 {VIASR, SR20, 0xFF, 0x00}, /* Sequencer Arbiter Control 0 */
223 {VIASR, SR21, 0xFF, 0x00}, /* Sequencer Arbiter Control 1 */
224 {VIASR, SR22, 0xFF, 0x1F}, /* Display Arbiter Control 1 */
225 {VIASR, SR2A, 0xFF, 0x00}, /* Power Management Control 5 */
226 {VIASR, SR2D, 0xFF, 0xFF}, /* Power Management Control 1 */
227 {VIASR, SR2E, 0xFF, 0xFF}, /* Power Management Control 2 */
228 {VIACR, CR0A, 0xFF, 0x1E}, /* Cursor Start */
229 {VIACR, CR0B, 0xFF, 0x00}, /* Cursor End */
230 {VIACR, CR0E, 0xFF, 0x00}, /* Cursor Location High */
231 {VIACR, CR0F, 0xFF, 0x00}, /* Cursor Localtion Low */
232 {VIACR, CR33, 0xFF, 0x00},
233 {VIACR, CR55, 0x80, 0x00},
234 {VIACR, CR5D, 0x80, 0x00},
235 {VIACR, CR36, 0xFF, 0x01}, /* Power Mangement 3 */
236 {VIACR, CR62, 0xFF, 0x00}, /* Secondary Display Starting Address */
237 {VIACR, CR63, 0xFF, 0x00}, /* Secondary Display Starting Address */
238 {VIACR, CR64, 0xFF, 0x00}, /* Secondary Display Starting Address */
239 {VIACR, CR68, 0xFF, 0x67}, /* Default FIFO For IGA2 */
240 {VIACR, CR6A, 0x20, 0x20}, /* Extended FIFO On */
241 {VIACR, CR7A, 0xFF, 0x01}, /* LCD Scaling Parameter 1 */
242 {VIACR, CR7B, 0xFF, 0x02}, /* LCD Scaling Parameter 2 */
243 {VIACR, CR7C, 0xFF, 0x03}, /* LCD Scaling Parameter 3 */
244 {VIACR, CR7D, 0xFF, 0x04}, /* LCD Scaling Parameter 4 */
245 {VIACR, CR7E, 0xFF, 0x07}, /* LCD Scaling Parameter 5 */
246 {VIACR, CR7F, 0xFF, 0x0A}, /* LCD Scaling Parameter 6 */
247 {VIACR, CR80, 0xFF, 0x0D}, /* LCD Scaling Parameter 7 */
248 {VIACR, CR81, 0xFF, 0x13}, /* LCD Scaling Parameter 8 */
249 {VIACR, CR82, 0xFF, 0x16}, /* LCD Scaling Parameter 9 */
250 {VIACR, CR83, 0xFF, 0x19}, /* LCD Scaling Parameter 10 */
251 {VIACR, CR84, 0xFF, 0x1C}, /* LCD Scaling Parameter 11 */
252 {VIACR, CR85, 0xFF, 0x1D}, /* LCD Scaling Parameter 12 */
253 {VIACR, CR86, 0xFF, 0x1E}, /* LCD Scaling Parameter 13 */
254 {VIACR, CR87, 0xFF, 0x1F}, /* LCD Scaling Parameter 14 */
255 {VIACR, CR88, 0xFF, 0x40}, /* LCD Panel Type */
256 {VIACR, CR89, 0xFF, 0x00}, /* LCD Timing Control 0 */
257 {VIACR, CR8A, 0xFF, 0x88}, /* LCD Timing Control 1 */
258 {VIACR, CR8B, 0xFF, 0x2D}, /* LCD Power Sequence Control 0 */
259 {VIACR, CR8C, 0xFF, 0x2D}, /* LCD Power Sequence Control 1 */
260 {VIACR, CR8D, 0xFF, 0xC8}, /* LCD Power Sequence Control 2 */
261 {VIACR, CR8E, 0xFF, 0x36}, /* LCD Power Sequence Control 3 */
262 {VIACR, CR8F, 0xFF, 0x00}, /* LCD Power Sequence Control 4 */
263 {VIACR, CR90, 0xFF, 0x10}, /* LCD Power Sequence Control 5 */
264 {VIACR, CR91, 0xFF, 0xA0}, /* 24/12 bit LVDS Data off */
265 {VIACR, CR96, 0xFF, 0x03}, /* DVP0 ; DVP0 Clock Skew */
266 {VIACR, CR97, 0xFF, 0x03}, /* DFP high ; DFPH Clock Skew */
267 {VIACR, CR99, 0xFF, 0x03}, /* DFP low ; DFPL Clock Skew*/
268 {VIACR, CR9B, 0xFF, 0x07} /* DVI on DVP1 ; DVP1 Clock Skew*/
269};
270
271/* For VT3324: Common Setting for Video Mode */
272struct io_reg CX700_ModeXregs[] = { {VIASR, SR10, 0xFF, 0x01},
273{VIASR, SR15, 0x02, 0x02},
274{VIASR, SR16, 0xBF, 0x08},
275{VIASR, SR17, 0xFF, 0x1F},
276{VIASR, SR18, 0xFF, 0x4E},
277{VIASR, SR1A, 0xFB, 0x08},
278{VIASR, SR1B, 0xFF, 0xF0},
279{VIASR, SR1E, 0xFF, 0x01},
280{VIASR, SR2A, 0xFF, 0x00},
281{VIASR, SR2D, 0xFF, 0xFF}, /* VCK and LCK PLL power on. */
282{VIACR, CR0A, 0xFF, 0x1E}, /* Cursor Start */
283{VIACR, CR0B, 0xFF, 0x00}, /* Cursor End */
284{VIACR, CR0E, 0xFF, 0x00}, /* Cursor Location High */
285{VIACR, CR0F, 0xFF, 0x00}, /* Cursor Localtion Low */
286{VIACR, CR32, 0xFF, 0x00},
287{VIACR, CR33, 0xFF, 0x00},
288{VIACR, CR34, 0xFF, 0x00},
289{VIACR, CR35, 0xFF, 0x00},
290{VIACR, CR36, 0x08, 0x00},
291{VIACR, CR47, 0xC8, 0x00}, /* Clear VCK Plus. */
292{VIACR, CR62, 0xFF, 0x00}, /* Secondary Display Starting Address */
293{VIACR, CR63, 0xFF, 0x00}, /* Secondary Display Starting Address */
294{VIACR, CR64, 0xFF, 0x00}, /* Secondary Display Starting Address */
295{VIACR, CRA3, 0xFF, 0x00}, /* Secondary Display Starting Address */
296{VIACR, CR69, 0xFF, 0x00},
297{VIACR, CR6A, 0xFF, 0x40},
298{VIACR, CR6B, 0xFF, 0x00},
299{VIACR, CR6C, 0xFF, 0x00},
300{VIACR, CR7A, 0xFF, 0x01}, /* LCD Scaling Parameter 1 */
301{VIACR, CR7B, 0xFF, 0x02}, /* LCD Scaling Parameter 2 */
302{VIACR, CR7C, 0xFF, 0x03}, /* LCD Scaling Parameter 3 */
303{VIACR, CR7D, 0xFF, 0x04}, /* LCD Scaling Parameter 4 */
304{VIACR, CR7E, 0xFF, 0x07}, /* LCD Scaling Parameter 5 */
305{VIACR, CR7F, 0xFF, 0x0A}, /* LCD Scaling Parameter 6 */
306{VIACR, CR80, 0xFF, 0x0D}, /* LCD Scaling Parameter 7 */
307{VIACR, CR81, 0xFF, 0x13}, /* LCD Scaling Parameter 8 */
308{VIACR, CR82, 0xFF, 0x16}, /* LCD Scaling Parameter 9 */
309{VIACR, CR83, 0xFF, 0x19}, /* LCD Scaling Parameter 10 */
310{VIACR, CR84, 0xFF, 0x1C}, /* LCD Scaling Parameter 11 */
311{VIACR, CR85, 0xFF, 0x1D}, /* LCD Scaling Parameter 12 */
312{VIACR, CR86, 0xFF, 0x1E}, /* LCD Scaling Parameter 13 */
313{VIACR, CR87, 0xFF, 0x1F}, /* LCD Scaling Parameter 14 */
314{VIACR, CR88, 0xFF, 0x40}, /* LCD Panel Type */
315{VIACR, CR89, 0xFF, 0x00}, /* LCD Timing Control 0 */
316{VIACR, CR8A, 0xFF, 0x88}, /* LCD Timing Control 1 */
317{VIACR, CRD4, 0xFF, 0x81}, /* Second power sequence control */
318{VIACR, CR8B, 0xFF, 0x5D}, /* LCD Power Sequence Control 0 */
319{VIACR, CR8C, 0xFF, 0x2B}, /* LCD Power Sequence Control 1 */
320{VIACR, CR8D, 0xFF, 0x6F}, /* LCD Power Sequence Control 2 */
321{VIACR, CR8E, 0xFF, 0x2B}, /* LCD Power Sequence Control 3 */
322{VIACR, CR8F, 0xFF, 0x01}, /* LCD Power Sequence Control 4 */
323{VIACR, CR90, 0xFF, 0x01}, /* LCD Power Sequence Control 5 */
324{VIACR, CR91, 0xFF, 0x80}, /* 24/12 bit LVDS Data off */
325{VIACR, CR96, 0xFF, 0x00},
326{VIACR, CR97, 0xFF, 0x00},
327{VIACR, CR99, 0xFF, 0x00},
328{VIACR, CR9B, 0xFF, 0x00},
329{VIACR, CRD2, 0xFF, 0xFF} /* TMDS/LVDS control register. */
330};
331
332/* For VT3353: Common Setting for Video Mode */
333struct io_reg VX800_ModeXregs[] = { {VIASR, SR10, 0xFF, 0x01},
334{VIASR, SR15, 0x02, 0x02},
335{VIASR, SR16, 0xBF, 0x08},
336{VIASR, SR17, 0xFF, 0x1F},
337{VIASR, SR18, 0xFF, 0x4E},
338{VIASR, SR1A, 0xFB, 0x08},
339{VIASR, SR1B, 0xFF, 0xF0},
340{VIASR, SR1E, 0xFF, 0x01},
341{VIASR, SR2A, 0xFF, 0x00},
342{VIASR, SR2D, 0xFF, 0xFF}, /* VCK and LCK PLL power on. */
343{VIACR, CR0A, 0xFF, 0x1E}, /* Cursor Start */
344{VIACR, CR0B, 0xFF, 0x00}, /* Cursor End */
345{VIACR, CR0E, 0xFF, 0x00}, /* Cursor Location High */
346{VIACR, CR0F, 0xFF, 0x00}, /* Cursor Localtion Low */
347{VIACR, CR32, 0xFF, 0x00},
348{VIACR, CR33, 0xFF, 0x00},
349{VIACR, CR34, 0xFF, 0x00},
350{VIACR, CR35, 0xFF, 0x00},
351{VIACR, CR36, 0x08, 0x00},
352{VIACR, CR47, 0xC8, 0x00}, /* Clear VCK Plus. */
353{VIACR, CR62, 0xFF, 0x00}, /* Secondary Display Starting Address */
354{VIACR, CR63, 0xFF, 0x00}, /* Secondary Display Starting Address */
355{VIACR, CR64, 0xFF, 0x00}, /* Secondary Display Starting Address */
356{VIACR, CRA3, 0xFF, 0x00}, /* Secondary Display Starting Address */
357{VIACR, CR69, 0xFF, 0x00},
358{VIACR, CR6A, 0xFF, 0x40},
359{VIACR, CR6B, 0xFF, 0x00},
360{VIACR, CR6C, 0xFF, 0x00},
361{VIACR, CR7A, 0xFF, 0x01}, /* LCD Scaling Parameter 1 */
362{VIACR, CR7B, 0xFF, 0x02}, /* LCD Scaling Parameter 2 */
363{VIACR, CR7C, 0xFF, 0x03}, /* LCD Scaling Parameter 3 */
364{VIACR, CR7D, 0xFF, 0x04}, /* LCD Scaling Parameter 4 */
365{VIACR, CR7E, 0xFF, 0x07}, /* LCD Scaling Parameter 5 */
366{VIACR, CR7F, 0xFF, 0x0A}, /* LCD Scaling Parameter 6 */
367{VIACR, CR80, 0xFF, 0x0D}, /* LCD Scaling Parameter 7 */
368{VIACR, CR81, 0xFF, 0x13}, /* LCD Scaling Parameter 8 */
369{VIACR, CR82, 0xFF, 0x16}, /* LCD Scaling Parameter 9 */
370{VIACR, CR83, 0xFF, 0x19}, /* LCD Scaling Parameter 10 */
371{VIACR, CR84, 0xFF, 0x1C}, /* LCD Scaling Parameter 11 */
372{VIACR, CR85, 0xFF, 0x1D}, /* LCD Scaling Parameter 12 */
373{VIACR, CR86, 0xFF, 0x1E}, /* LCD Scaling Parameter 13 */
374{VIACR, CR87, 0xFF, 0x1F}, /* LCD Scaling Parameter 14 */
375{VIACR, CR88, 0xFF, 0x40}, /* LCD Panel Type */
376{VIACR, CR89, 0xFF, 0x00}, /* LCD Timing Control 0 */
377{VIACR, CR8A, 0xFF, 0x88}, /* LCD Timing Control 1 */
378{VIACR, CRD4, 0xFF, 0x81}, /* Second power sequence control */
379{VIACR, CR8B, 0xFF, 0x5D}, /* LCD Power Sequence Control 0 */
380{VIACR, CR8C, 0xFF, 0x2B}, /* LCD Power Sequence Control 1 */
381{VIACR, CR8D, 0xFF, 0x6F}, /* LCD Power Sequence Control 2 */
382{VIACR, CR8E, 0xFF, 0x2B}, /* LCD Power Sequence Control 3 */
383{VIACR, CR8F, 0xFF, 0x01}, /* LCD Power Sequence Control 4 */
384{VIACR, CR90, 0xFF, 0x01}, /* LCD Power Sequence Control 5 */
385{VIACR, CR91, 0xFF, 0x80}, /* 24/12 bit LVDS Data off */
386{VIACR, CR96, 0xFF, 0x00},
387{VIACR, CR97, 0xFF, 0x00},
388{VIACR, CR99, 0xFF, 0x00},
389{VIACR, CR9B, 0xFF, 0x00},
390{VIACR, CRD2, 0xFF, 0xFF} /* TMDS/LVDS control register. */
391};
392
393/* Video Mode Table */
394/* Common Setting for Video Mode */
395struct io_reg CLE266_ModeXregs[] = { {VIASR, SR1E, 0xF0, 0x00},
396{VIASR, SR2A, 0x0F, 0x00},
397{VIASR, SR15, 0x02, 0x02},
398{VIASR, SR16, 0xBF, 0x08},
399{VIASR, SR17, 0xFF, 0x1F},
400{VIASR, SR18, 0xFF, 0x4E},
401{VIASR, SR1A, 0xFB, 0x08},
402
403{VIACR, CR32, 0xFF, 0x00},
404{VIACR, CR34, 0xFF, 0x00},
405{VIACR, CR35, 0xFF, 0x00},
406{VIACR, CR36, 0x08, 0x00},
407{VIACR, CR6A, 0xFF, 0x80},
408{VIACR, CR6A, 0xFF, 0xC0},
409
410{VIACR, CR55, 0x80, 0x00},
411{VIACR, CR5D, 0x80, 0x00},
412
413{VIAGR, GR20, 0xFF, 0x00},
414{VIAGR, GR21, 0xFF, 0x00},
415{VIAGR, GR22, 0xFF, 0x00},
416 /* LCD Parameters */
417{VIACR, CR7A, 0xFF, 0x01}, /* LCD Parameter 1 */
418{VIACR, CR7B, 0xFF, 0x02}, /* LCD Parameter 2 */
419{VIACR, CR7C, 0xFF, 0x03}, /* LCD Parameter 3 */
420{VIACR, CR7D, 0xFF, 0x04}, /* LCD Parameter 4 */
421{VIACR, CR7E, 0xFF, 0x07}, /* LCD Parameter 5 */
422{VIACR, CR7F, 0xFF, 0x0A}, /* LCD Parameter 6 */
423{VIACR, CR80, 0xFF, 0x0D}, /* LCD Parameter 7 */
424{VIACR, CR81, 0xFF, 0x13}, /* LCD Parameter 8 */
425{VIACR, CR82, 0xFF, 0x16}, /* LCD Parameter 9 */
426{VIACR, CR83, 0xFF, 0x19}, /* LCD Parameter 10 */
427{VIACR, CR84, 0xFF, 0x1C}, /* LCD Parameter 11 */
428{VIACR, CR85, 0xFF, 0x1D}, /* LCD Parameter 12 */
429{VIACR, CR86, 0xFF, 0x1E}, /* LCD Parameter 13 */
430{VIACR, CR87, 0xFF, 0x1F}, /* LCD Parameter 14 */
431
432};
433
434/* Mode:1024X768 */
435struct io_reg PM1024x768[] = { {VIASR, 0x16, 0xBF, 0x0C},
436{VIASR, 0x18, 0xFF, 0x4C}
437};
438
439struct patch_table res_patch_table[] = {
440 {VIA_RES_1024X768, ARRAY_SIZE(PM1024x768), PM1024x768}
441};
442
443/* struct VPITTable {
444 unsigned char Misc;
445 unsigned char SR[StdSR];
446 unsigned char CR[StdCR];
447 unsigned char GR[StdGR];
448 unsigned char AR[StdAR];
449 };*/
450
451struct VPITTable VPIT = {
452 /* Msic */
453 0xC7,
454 /* Sequencer */
455 {0x01, 0x0F, 0x00, 0x0E},
456 /* Graphic Controller */
457 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0F, 0xFF},
458 /* Attribute Controller */
459 {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
460 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
461 0x01, 0x00, 0x0F, 0x00}
462};
463
464/********************/
465/* Mode Table */
466/********************/
467
468/* 480x640 */
469struct crt_mode_table CRTM480x640[] = {
470 /* r_rate, vclk, hsp, vsp */
471 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
472 {REFRESH_60, CLK_25_175M, M480X640_R60_HSP, M480X640_R60_VSP,
473 {624, 480, 480, 144, 504, 48, 663, 640, 640, 23, 641, 3} } /* GTF*/
474};
475
476/* 640x480*/
477struct crt_mode_table CRTM640x480[] = {
478 /*r_rate,vclk,hsp,vsp */
479 /*HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
480 {REFRESH_60, CLK_25_175M, M640X480_R60_HSP, M640X480_R60_VSP,
481 {800, 640, 648, 144, 656, 96, 525, 480, 480, 45, 490, 2} },
482 {REFRESH_75, CLK_31_500M, M640X480_R75_HSP, M640X480_R75_VSP,
483 {840, 640, 640, 200, 656, 64, 500, 480, 480, 20, 481, 3} },
484 {REFRESH_85, CLK_36_000M, M640X480_R85_HSP, M640X480_R85_VSP,
485 {832, 640, 640, 192, 696, 56, 509, 480, 480, 29, 481, 3} },
486 {REFRESH_100, CLK_43_163M, M640X480_R100_HSP, M640X480_R100_VSP,
487 {848, 640, 640, 208, 680, 64, 509, 480, 480, 29, 481, 3} }, /*GTF*/
488 {REFRESH_120, CLK_52_406M, M640X480_R120_HSP,
489 M640X480_R120_VSP,
490 {848, 640, 640, 208, 680, 64, 515, 480, 480, 35, 481,
491 3} } /*GTF*/
492};
493
494/*720x480 (GTF)*/
495struct crt_mode_table CRTM720x480[] = {
496 /*r_rate,vclk,hsp,vsp */
497 /*HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
498 {REFRESH_60, CLK_26_880M, M720X480_R60_HSP, M720X480_R60_VSP,
499 {896, 720, 720, 176, 736, 72, 497, 480, 480, 17, 481, 3} }
500
501};
502
503/*720x576 (GTF)*/
504struct crt_mode_table CRTM720x576[] = {
505 /*r_rate,vclk,hsp,vsp */
506 /*HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
507 {REFRESH_60, CLK_32_668M, M720X576_R60_HSP, M720X576_R60_VSP,
508 {912, 720, 720, 192, 744, 72, 597, 576, 576, 21, 577, 3} }
509};
510
511/* 800x480 (CVT) */
512struct crt_mode_table CRTM800x480[] = {
513 /* r_rate, vclk, hsp, vsp */
514 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
515 {REFRESH_60, CLK_29_581M, M800X480_R60_HSP, M800X480_R60_VSP,
516 {992, 800, 800, 192, 824, 72, 500, 480, 480, 20, 483, 7} }
517};
518
519/* 800x600*/
520struct crt_mode_table CRTM800x600[] = {
521 /*r_rate,vclk,hsp,vsp */
522 /*HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
523 {REFRESH_60, CLK_40_000M, M800X600_R60_HSP, M800X600_R60_VSP,
524 {1056, 800, 800, 256, 840, 128, 628, 600, 600, 28, 601, 4} },
525 {REFRESH_75, CLK_49_500M, M800X600_R75_HSP, M800X600_R75_VSP,
526 {1056, 800, 800, 256, 816, 80, 625, 600, 600, 25, 601, 3} },
527 {REFRESH_85, CLK_56_250M, M800X600_R85_HSP, M800X600_R85_VSP,
528 {1048, 800, 800, 248, 832, 64, 631, 600, 600, 31, 601, 3} },
529 {REFRESH_100, CLK_68_179M, M800X600_R100_HSP, M800X600_R100_VSP,
530 {1072, 800, 800, 272, 848, 88, 636, 600, 600, 36, 601, 3} },
531 {REFRESH_120, CLK_83_950M, M800X600_R120_HSP,
532 M800X600_R120_VSP,
533 {1088, 800, 800, 288, 856, 88, 643, 600, 600, 43, 601,
534 3} }
535};
536
537/* 848x480 (CVT) */
538struct crt_mode_table CRTM848x480[] = {
539 /* r_rate, vclk, hsp, vsp */
540 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
541 {REFRESH_60, CLK_31_500M, M848X480_R60_HSP, M848X480_R60_VSP,
542 {1056, 848, 848, 208, 872, 80, 500, 480, 480, 20, 483, 5} }
543};
544
545/*856x480 (GTF) convert to 852x480*/
546struct crt_mode_table CRTM852x480[] = {
547 /*r_rate,vclk,hsp,vsp */
548 /*HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
549 {REFRESH_60, CLK_31_728M, M852X480_R60_HSP, M852X480_R60_VSP,
550 {1064, 856, 856, 208, 872, 88, 497, 480, 480, 17, 481, 3} }
551};
552
553/*1024x512 (GTF)*/
554struct crt_mode_table CRTM1024x512[] = {
555 /*r_rate,vclk,hsp,vsp */
556 /*HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
557 {REFRESH_60, CLK_41_291M, M1024X512_R60_HSP, M1024X512_R60_VSP,
558 {1296, 1024, 1024, 272, 1056, 104, 531, 512, 512, 19, 513, 3} }
559
560};
561
562/* 1024x600*/
563struct crt_mode_table CRTM1024x600[] = {
564 /*r_rate,vclk,hsp,vsp */
565 /*HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
566 {REFRESH_60, CLK_48_875M, M1024X600_R60_HSP, M1024X600_R60_VSP,
567 {1312, 1024, 1024, 288, 1064, 104, 622, 600, 600, 22, 601, 3} },
568};
569
570/* 1024x768*/
571struct crt_mode_table CRTM1024x768[] = {
572 /*r_rate,vclk,hsp,vsp */
573 /*HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
574 {REFRESH_60, CLK_65_000M, M1024X768_R60_HSP, M1024X768_R60_VSP,
575 {1344, 1024, 1024, 320, 1048, 136, 806, 768, 768, 38, 771, 6} },
576 {REFRESH_75, CLK_78_750M, M1024X768_R75_HSP, M1024X768_R75_VSP,
577 {1312, 1024, 1024, 288, 1040, 96, 800, 768, 768, 32, 769, 3} },
578 {REFRESH_85, CLK_94_500M, M1024X768_R85_HSP, M1024X768_R85_VSP,
579 {1376, 1024, 1024, 352, 1072, 96, 808, 768, 768, 40, 769, 3} },
580 {REFRESH_100, CLK_113_309M, M1024X768_R100_HSP, M1024X768_R100_VSP,
581 {1392, 1024, 1024, 368, 1096, 112, 814, 768, 768, 46, 769, 3} }
582};
583
584/* 1152x864*/
585struct crt_mode_table CRTM1152x864[] = {
586 /*r_rate,vclk,hsp,vsp */
587 /*HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
588 {REFRESH_75, CLK_108_000M, M1152X864_R75_HSP, M1152X864_R75_VSP,
589 {1600, 1152, 1152, 448, 1216, 128, 900, 864, 864, 36, 865, 3} }
590
591};
592
593/* 1280x720 (HDMI 720P)*/
594struct crt_mode_table CRTM1280x720[] = {
595 /*r_rate,vclk,hsp,vsp */
596 /*HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
597 {REFRESH_60, CLK_74_481M, M1280X720_R60_HSP, M1280X720_R60_VSP,
598 {1648, 1280, 1280, 368, 1392, 40, 750, 720, 720, 30, 725, 5} },
599 {REFRESH_50, CLK_60_466M, M1280X720_R50_HSP, M1280X720_R50_VSP,
600 {1632, 1280, 1280, 352, 1328, 128, 741, 720, 720, 21, 721, 3} }
601};
602
603/*1280x768 (GTF)*/
604struct crt_mode_table CRTM1280x768[] = {
605 /*r_rate,vclk,hsp,vsp */
606 /*HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
607 {REFRESH_60, CLK_80_136M, M1280X768_R60_HSP, M1280X768_R60_VSP,
608 {1680, 1280, 1280, 400, 1344, 136, 795, 768, 768, 27, 769, 3} },
609 {REFRESH_50, CLK_65_178M, M1280X768_R50_HSP, M1280X768_R50_VSP,
610 {1648, 1280, 1280, 368, 1336, 128, 791, 768, 768, 23, 769, 3} }
611};
612
613/* 1280x800 (CVT) */
614struct crt_mode_table CRTM1280x800[] = {
615 /* r_rate, vclk, hsp, vsp */
616 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
617 {REFRESH_60, CLK_83_375M, M1280X800_R60_HSP, M1280X800_R60_VSP,
618 {1680, 1280, 1280, 400, 1352, 128, 831, 800, 800, 31, 803, 6} }
619};
620
621/*1280x960*/
622struct crt_mode_table CRTM1280x960[] = {
623 /*r_rate,vclk,hsp,vsp */
624 /*HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
625 {REFRESH_60, CLK_108_000M, M1280X960_R60_HSP, M1280X960_R60_VSP,
626 {1800, 1280, 1280, 520, 1376, 112, 1000, 960, 960, 40, 961, 3} }
627};
628
629/* 1280x1024*/
630struct crt_mode_table CRTM1280x1024[] = {
631 /*r_rate,vclk,,hsp,vsp */
632 /*HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
633 {REFRESH_60, CLK_108_000M, M1280X1024_R60_HSP, M1280X1024_R60_VSP,
634 {1688, 1280, 1280, 408, 1328, 112, 1066, 1024, 1024, 42, 1025,
635 3} },
636 {REFRESH_75, CLK_135_000M, M1280X1024_R75_HSP, M1280X1024_R75_VSP,
637 {1688, 1280, 1280, 408, 1296, 144, 1066, 1024, 1024, 42, 1025,
638 3} },
639 {REFRESH_85, CLK_157_500M, M1280X1024_R85_HSP, M1280X1024_R85_VSP,
640 {1728, 1280, 1280, 448, 1344, 160, 1072, 1024, 1024, 48, 1025, 3} }
641};
642
643/* 1368x768 (GTF) */
644struct crt_mode_table CRTM1368x768[] = {
645 /* r_rate, vclk, hsp, vsp */
646 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
647 {REFRESH_60, CLK_85_860M, M1368X768_R60_HSP, M1368X768_R60_VSP,
648 {1800, 1368, 1368, 432, 1440, 144, 795, 768, 768, 27, 769, 3} }
649};
650
651/*1440x1050 (GTF)*/
652struct crt_mode_table CRTM1440x1050[] = {
653 /*r_rate,vclk,hsp,vsp */
654 /*HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
655 {REFRESH_60, CLK_125_104M, M1440X1050_R60_HSP, M1440X1050_R60_VSP,
656 {1936, 1440, 1440, 496, 1536, 152, 1077, 1040, 1040, 37, 1041, 3} }
657};
658
659/* 1600x1200*/
660struct crt_mode_table CRTM1600x1200[] = {
661 /*r_rate,vclk,hsp,vsp */
662 /*HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
663 {REFRESH_60, CLK_162_000M, M1600X1200_R60_HSP, M1600X1200_R60_VSP,
664 {2160, 1600, 1600, 560, 1664, 192, 1250, 1200, 1200, 50, 1201,
665 3} },
666 {REFRESH_75, CLK_202_500M, M1600X1200_R75_HSP, M1600X1200_R75_VSP,
667 {2160, 1600, 1600, 560, 1664, 192, 1250, 1200, 1200, 50, 1201, 3} }
668
669};
670
671/* 1680x1050 (CVT) */
672struct crt_mode_table CRTM1680x1050[] = {
673 /* r_rate, vclk, hsp, vsp */
674 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
675 {REFRESH_60, CLK_146_760M, M1680x1050_R60_HSP, M1680x1050_R60_VSP,
676 {2240, 1680, 1680, 560, 1784, 176, 1089, 1050, 1050, 39, 1053,
677 6} },
678 {REFRESH_75, CLK_187_000M, M1680x1050_R75_HSP, M1680x1050_R75_VSP,
679 {2272, 1680, 1680, 592, 1800, 176, 1099, 1050, 1050, 49, 1053, 6} }
680};
681
682/* 1680x1050 (CVT Reduce Blanking) */
683struct crt_mode_table CRTM1680x1050_RB[] = {
684 /* r_rate, vclk, hsp, vsp */
685 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
686 {REFRESH_60, CLK_119_000M, M1680x1050_RB_R60_HSP,
687 M1680x1050_RB_R60_VSP,
688 {1840, 1680, 1680, 160, 1728, 32, 1080, 1050, 1050, 30, 1053, 6} }
689};
690
691/* 1920x1080 (CVT)*/
692struct crt_mode_table CRTM1920x1080[] = {
693 /*r_rate,vclk,hsp,vsp */
694 /*HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
695 {REFRESH_60, CLK_172_798M, M1920X1080_R60_HSP, M1920X1080_R60_VSP,
696 {2576, 1920, 1920, 656, 2048, 200, 1120, 1080, 1080, 40, 1083, 5} }
697};
698
699/* 1920x1080 (CVT with Reduce Blanking) */
700struct crt_mode_table CRTM1920x1080_RB[] = {
701 /* r_rate, vclk, hsp, vsp */
702 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
703 {REFRESH_60, CLK_138_400M, M1920X1080_RB_R60_HSP,
704 M1920X1080_RB_R60_VSP,
705 {2080, 1920, 1920, 160, 1968, 32, 1111, 1080, 1080, 31, 1083, 5} }
706};
707
708/* 1920x1440*/
709struct crt_mode_table CRTM1920x1440[] = {
710 /*r_rate,vclk,hsp,vsp */
711 /*HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
712 {REFRESH_60, CLK_234_000M, M1920X1440_R60_HSP, M1920X1440_R60_VSP,
713 {2600, 1920, 1920, 680, 2048, 208, 1500, 1440, 1440, 60, 1441,
714 3} },
715 {REFRESH_75, CLK_297_500M, M1920X1440_R75_HSP, M1920X1440_R75_VSP,
716 {2640, 1920, 1920, 720, 2064, 224, 1500, 1440, 1440, 60, 1441, 3} }
717};
718
719/* 1400x1050 (CVT) */
720struct crt_mode_table CRTM1400x1050[] = {
721 /* r_rate, vclk, hsp, vsp */
722 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
723 {REFRESH_60, CLK_121_750M, M1400X1050_R60_HSP, M1400X1050_R60_VSP,
724 {1864, 1400, 1400, 464, 1488, 144, 1089, 1050, 1050, 39, 1053,
725 4} },
726 {REFRESH_75, CLK_156_000M, M1400X1050_R75_HSP, M1400X1050_R75_VSP,
727 {1896, 1400, 1400, 496, 1504, 144, 1099, 1050, 1050, 49, 1053, 4} }
728};
729
730/* 1400x1050 (CVT Reduce Blanking) */
731struct crt_mode_table CRTM1400x1050_RB[] = {
732 /* r_rate, vclk, hsp, vsp */
733 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
734 {REFRESH_60, CLK_101_000M, M1400X1050_RB_R60_HSP,
735 M1400X1050_RB_R60_VSP,
736 {1560, 1400, 1400, 160, 1448, 32, 1080, 1050, 1050, 30, 1053, 4} }
737};
738
739/* 960x600 (CVT) */
740struct crt_mode_table CRTM960x600[] = {
741 /* r_rate, vclk, hsp, vsp */
742 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
743 {REFRESH_60, CLK_45_250M, M960X600_R60_HSP, M960X600_R60_VSP,
744 {1216, 960, 960, 256, 992, 96, 624, 600, 600, 24, 603, 6} }
745};
746
747/* 1000x600 (GTF) */
748struct crt_mode_table CRTM1000x600[] = {
749 /* r_rate, vclk, hsp, vsp */
750 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
751 {REFRESH_60, CLK_48_000M, M1000X600_R60_HSP, M1000X600_R60_VSP,
752 {1288, 1000, 1000, 288, 1040, 104, 622, 600, 600, 22, 601, 3} }
753};
754
755/* 1024x576 (GTF) */
756struct crt_mode_table CRTM1024x576[] = {
757 /* r_rate, vclk, hsp, vsp */
758 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
759 {REFRESH_60, CLK_46_996M, M1024X576_R60_HSP, M1024X576_R60_VSP,
760 {1312, 1024, 1024, 288, 1064, 104, 597, 576, 576, 21, 577, 3} }
761};
762
763/* 1088x612 (CVT) */
764struct crt_mode_table CRTM1088x612[] = {
765 /* r_rate, vclk, hsp, vsp */
766 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
767 {REFRESH_60, CLK_52_977M, M1088X612_R60_HSP, M1088X612_R60_VSP,
768 {1392, 1088, 1088, 304, 1136, 104, 636, 612, 612, 24, 615, 5} }
769};
770
771/* 1152x720 (CVT) */
772struct crt_mode_table CRTM1152x720[] = {
773 /* r_rate, vclk, hsp, vsp */
774 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
775 {REFRESH_60, CLK_66_750M, M1152X720_R60_HSP, M1152X720_R60_VSP,
776 {1488, 1152, 1152, 336, 1208, 112, 748, 720, 720, 28, 723, 6} }
777};
778
779/* 1200x720 (GTF) */
780struct crt_mode_table CRTM1200x720[] = {
781 /* r_rate, vclk, hsp, vsp */
782 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
783 {REFRESH_60, CLK_70_159M, M1200X720_R60_HSP, M1200X720_R60_VSP,
784 {1568, 1200, 1200, 368, 1256, 128, 746, 720, 720, 26, 721, 3} }
785};
786
787/* 1280x600 (GTF) */
788struct crt_mode_table CRTM1280x600[] = {
789 /* r_rate, vclk, hsp, vsp */
790 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
791 {REFRESH_60, CLK_61_500M, M1280x600_R60_HSP, M1280x600_R60_VSP,
792 {1648, 1280, 1280, 368, 1336, 128, 622, 600, 600, 22, 601, 3} }
793};
794
795/* 1360x768 (CVT) */
796struct crt_mode_table CRTM1360x768[] = {
797 /* r_rate, vclk, hsp, vsp */
798 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
799 {REFRESH_60, CLK_84_750M, M1360X768_R60_HSP, M1360X768_R60_VSP,
800 {1776, 1360, 1360, 416, 1432, 136, 798, 768, 768, 30, 771, 5} }
801};
802
803/* 1360x768 (CVT Reduce Blanking) */
804struct crt_mode_table CRTM1360x768_RB[] = {
805 /* r_rate, vclk, hsp, vsp */
806 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
807 {REFRESH_60, CLK_72_000M, M1360X768_RB_R60_HSP,
808 M1360X768_RB_R60_VSP,
809 {1520, 1360, 1360, 160, 1408, 32, 790, 768, 768, 22, 771, 5} }
810};
811
812/* 1366x768 (GTF) */
813struct crt_mode_table CRTM1366x768[] = {
814 /* r_rate, vclk, hsp, vsp */
815 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
816 {REFRESH_60, CLK_85_860M, M1368X768_R60_HSP, M1368X768_R60_VSP,
817 {1800, 1368, 1368, 432, 1440, 144, 795, 768, 768, 27, 769, 3} },
818 {REFRESH_50, CLK_69_924M, M1368X768_R50_HSP, M1368X768_R50_VSP,
819 {1768, 1368, 1368, 400, 1424, 144, 791, 768, 768, 23, 769, 3} }
820};
821
822/* 1440x900 (CVT) */
823struct crt_mode_table CRTM1440x900[] = {
824 /* r_rate, vclk, hsp, vsp */
825 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
826 {REFRESH_60, CLK_106_500M, M1440X900_R60_HSP, M1440X900_R60_VSP,
827 {1904, 1440, 1440, 464, 1520, 152, 934, 900, 900, 34, 903, 6} },
828 {REFRESH_75, CLK_136_700M, M1440X900_R75_HSP, M1440X900_R75_VSP,
829 {1936, 1440, 1440, 496, 1536, 152, 942, 900, 900, 42, 903, 6} }
830};
831
832/* 1440x900 (CVT Reduce Blanking) */
833struct crt_mode_table CRTM1440x900_RB[] = {
834 /* r_rate, vclk, hsp, vsp */
835 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
836 {REFRESH_60, CLK_88_750M, M1440X900_RB_R60_HSP,
837 M1440X900_RB_R60_VSP,
838 {1600, 1440, 1440, 160, 1488, 32, 926, 900, 900, 26, 903, 6} }
839};
840
841/* 1600x900 (CVT) */
842struct crt_mode_table CRTM1600x900[] = {
843 /* r_rate, vclk, hsp, vsp */
844 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
845 {REFRESH_60, CLK_118_840M, M1600X900_R60_HSP, M1600X900_R60_VSP,
846 {2112, 1600, 1600, 512, 1688, 168, 934, 900, 900, 34, 903, 5} }
847};
848
849/* 1600x900 (CVT Reduce Blanking) */
850struct crt_mode_table CRTM1600x900_RB[] = {
851 /* r_rate, vclk, hsp, vsp */
852 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
853 {REFRESH_60, CLK_97_750M, M1600X900_RB_R60_HSP,
854 M1600X900_RB_R60_VSP,
855 {1760, 1600, 1600, 160, 1648, 32, 926, 900, 900, 26, 903, 5} }
856};
857
858/* 1600x1024 (GTF) */
859struct crt_mode_table CRTM1600x1024[] = {
860 /* r_rate, vclk, hsp, vsp */
861 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
862 {REFRESH_60, CLK_136_700M, M1600X1024_R60_HSP, M1600X1024_R60_VSP,
863 {2144, 1600, 1600, 544, 1704, 168, 1060, 1024, 1024, 36, 1025, 3} }
864};
865
866/* 1792x1344 (DMT) */
867struct crt_mode_table CRTM1792x1344[] = {
868 /* r_rate, vclk, hsp, vsp */
869 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
870 {REFRESH_60, CLK_204_000M, M1792x1344_R60_HSP, M1792x1344_R60_VSP,
871 {2448, 1792, 1792, 656, 1920, 200, 1394, 1344, 1344, 50, 1345, 3} }
872};
873
874/* 1856x1392 (DMT) */
875struct crt_mode_table CRTM1856x1392[] = {
876 /* r_rate, vclk, hsp, vsp */
877 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
878 {REFRESH_60, CLK_218_500M, M1856x1392_R60_HSP, M1856x1392_R60_VSP,
879 {2528, 1856, 1856, 672, 1952, 224, 1439, 1392, 1392, 47, 1393, 3} }
880};
881
882/* 1920x1200 (CVT) */
883struct crt_mode_table CRTM1920x1200[] = {
884 /* r_rate, vclk, hsp, vsp */
885 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
886 {REFRESH_60, CLK_193_295M, M1920X1200_R60_HSP, M1920X1200_R60_VSP,
887 {2592, 1920, 1920, 672, 2056, 200, 1245, 1200, 1200, 45, 1203, 6} }
888};
889
890/* 1920x1200 (CVT with Reduce Blanking) */
891struct crt_mode_table CRTM1920x1200_RB[] = {
892 /* r_rate, vclk, hsp, vsp */
893 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
894 {REFRESH_60, CLK_153_920M, M1920X1200_RB_R60_HSP,
895 M1920X1200_RB_R60_VSP,
896 {2080, 1920, 1920, 160, 1968, 32, 1235, 1200, 1200, 35, 1203, 6} }
897};
898
899/* 2048x1536 (CVT) */
900struct crt_mode_table CRTM2048x1536[] = {
901 /* r_rate, vclk, hsp, vsp */
902 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
903 {REFRESH_60, CLK_267_250M, M2048x1536_R60_HSP, M2048x1536_R60_VSP,
904 {2800, 2048, 2048, 752, 2200, 224, 1592, 1536, 1536, 56, 1539, 4} }
905};
906
907/* Video Mode Table */
908/* struct VideoModeTable {*/
909/* int ModeIndex;*/
910/* struct crt_mode_table *crtc;*/
911/* int mode_array;*/
912/* };*/
913struct VideoModeTable CLE266Modes[] = {
914 /* Display : 480x640 (GTF) */
915 {VIA_RES_480X640, CRTM480x640, ARRAY_SIZE(CRTM480x640)},
916
917 /* Display : 640x480 */
918 {VIA_RES_640X480, CRTM640x480, ARRAY_SIZE(CRTM640x480)},
919
920 /* Display : 720x480 (GTF) */
921 {VIA_RES_720X480, CRTM720x480, ARRAY_SIZE(CRTM720x480)},
922
923 /* Display : 720x576 (GTF) */
924 {VIA_RES_720X576, CRTM720x576, ARRAY_SIZE(CRTM720x576)},
925
926 /* Display : 800x600 */
927 {VIA_RES_800X600, CRTM800x600, ARRAY_SIZE(CRTM800x600)},
928
929 /* Display : 800x480 (CVT) */
930 {VIA_RES_800X480, CRTM800x480, ARRAY_SIZE(CRTM800x480)},
931
932 /* Display : 848x480 (CVT) */
933 {VIA_RES_848X480, CRTM848x480, ARRAY_SIZE(CRTM848x480)},
934
935 /* Display : 852x480 (GTF) */
936 {VIA_RES_856X480, CRTM852x480, ARRAY_SIZE(CRTM852x480)},
937
938 /* Display : 1024x512 (GTF) */
939 {VIA_RES_1024X512, CRTM1024x512, ARRAY_SIZE(CRTM1024x512)},
940
941 /* Display : 1024x600 */
942 {VIA_RES_1024X600, CRTM1024x600, ARRAY_SIZE(CRTM1024x600)},
943
944 /* Display : 1024x576 (GTF) */
945 /*{ VIA_RES_1024X576, CRTM1024x576, ARRAY_SIZE(CRTM1024x576)}, */
946
947 /* Display : 1024x768 */
948 {VIA_RES_1024X768, CRTM1024x768, ARRAY_SIZE(CRTM1024x768)},
949
950 /* Display : 1152x864 */
951 {VIA_RES_1152X864, CRTM1152x864, ARRAY_SIZE(CRTM1152x864)},
952
953 /* Display : 1280x768 (GTF) */
954 {VIA_RES_1280X768, CRTM1280x768, ARRAY_SIZE(CRTM1280x768)},
955
956 /* Display : 960x600 (CVT) */
957 {VIA_RES_960X600, CRTM960x600, ARRAY_SIZE(CRTM960x600)},
958
959 /* Display : 1000x600 (GTF) */
960 {VIA_RES_1000X600, CRTM1000x600, ARRAY_SIZE(CRTM1000x600)},
961
962 /* Display : 1024x576 (GTF) */
963 {VIA_RES_1024X576, CRTM1024x576, ARRAY_SIZE(CRTM1024x576)},
964
965 /* Display : 1088x612 (GTF) */
966 {VIA_RES_1088X612, CRTM1088x612, ARRAY_SIZE(CRTM1088x612)},
967
968 /* Display : 1152x720 (CVT) */
969 {VIA_RES_1152X720, CRTM1152x720, ARRAY_SIZE(CRTM1152x720)},
970
971 /* Display : 1200x720 (GTF) */
972 {VIA_RES_1200X720, CRTM1200x720, ARRAY_SIZE(CRTM1200x720)},
973
974 /* Display : 1280x600 (GTF) */
975 {VIA_RES_1280X600, CRTM1280x600, ARRAY_SIZE(CRTM1280x600)},
976
977 /* Display : 1280x800 (CVT) */
978 {VIA_RES_1280X800, CRTM1280x800, ARRAY_SIZE(CRTM1280x800)},
979
980 /* Display : 1280x800 (GTF) */
981 /*{ M1280x800, CRTM1280x800, ARRAY_SIZE(CRTM1280x800)}, */
982
983 /* Display : 1280x960 */
984 {VIA_RES_1280X960, CRTM1280x960, ARRAY_SIZE(CRTM1280x960)},
985
986 /* Display : 1280x1024 */
987 {VIA_RES_1280X1024, CRTM1280x1024, ARRAY_SIZE(CRTM1280x1024)},
988
989 /* Display : 1360x768 (CVT) */
990 {VIA_RES_1360X768, CRTM1360x768, ARRAY_SIZE(CRTM1360x768)},
991
992 /* Display : 1360x768 (CVT Reduce Blanking) */
993 {VIA_RES_1360X768_RB, CRTM1360x768_RB,
994 ARRAY_SIZE(CRTM1360x768_RB)},
995
996 /* Display : 1366x768 */
997 {VIA_RES_1366X768, CRTM1366x768, ARRAY_SIZE(CRTM1366x768)},
998
999 /* Display : 1368x768 (GTF) */
1000 /*{ M1368x768,CRTM1368x768,ARRAY_SIZE(CRTM1368x768)}, */
1001 /* Display : 1368x768 (GTF) */
1002 {VIA_RES_1368X768, CRTM1368x768, ARRAY_SIZE(CRTM1368x768)},
1003
1004 /* Display : 1440x900 (CVT) */
1005 {VIA_RES_1440X900, CRTM1440x900, ARRAY_SIZE(CRTM1440x900)},
1006
1007 /* Display : 1440x900 (CVT Reduce Blanking) */
1008 {VIA_RES_1440X900_RB, CRTM1440x900_RB,
1009 ARRAY_SIZE(CRTM1440x900_RB)},
1010
1011 /* Display : 1440x1050 (GTF) */
1012 {VIA_RES_1440X1050, CRTM1440x1050, ARRAY_SIZE(CRTM1440x1050)},
1013
1014 /* Display : 1400x1050 (CVT Reduce Blanking) */
1015 {VIA_RES_1400X1050_RB, CRTM1400x1050_RB,
1016 ARRAY_SIZE(CRTM1400x1050_RB)},
1017
1018 /* Display : 1600x900 (CVT) */
1019 {VIA_RES_1600X900, CRTM1600x900, ARRAY_SIZE(CRTM1600x900)},
1020
1021 /* Display : 1600x900 (CVT Reduce Blanking) */
1022 {VIA_RES_1600X900_RB, CRTM1600x900_RB,
1023 ARRAY_SIZE(CRTM1600x900_RB)},
1024
1025 /* Display : 1600x1024 (GTF) */
1026 {VIA_RES_1600X1024, CRTM1600x1024, ARRAY_SIZE(CRTM1600x1024)},
1027
1028 /* Display : 1600x1200 */
1029 {VIA_RES_1600X1200, CRTM1600x1200, ARRAY_SIZE(CRTM1600x1200)},
1030
1031 /* Display : 1680x1050 (CVT) */
1032 {VIA_RES_1680X1050, CRTM1680x1050, ARRAY_SIZE(CRTM1680x1050)},
1033
1034 /* Display : 1680x1050 (CVT Reduce Blanking) */
1035 {VIA_RES_1680X1050_RB, CRTM1680x1050_RB,
1036 ARRAY_SIZE(CRTM1680x1050_RB)},
1037
1038 /* Display : 1792x1344 (DMT) */
1039 {VIA_RES_1792X1344, CRTM1792x1344, ARRAY_SIZE(CRTM1792x1344)},
1040
1041 /* Display : 1856x1392 (DMT) */
1042 {VIA_RES_1856X1392, CRTM1856x1392, ARRAY_SIZE(CRTM1856x1392)},
1043
1044 /* Display : 1920x1440 */
1045 {VIA_RES_1920X1440, CRTM1920x1440, ARRAY_SIZE(CRTM1920x1440)},
1046
1047 /* Display : 2048x1536 */
1048 {VIA_RES_2048X1536, CRTM2048x1536, ARRAY_SIZE(CRTM2048x1536)},
1049
1050 /* Display : 1280x720 */
1051 {VIA_RES_1280X720, CRTM1280x720, ARRAY_SIZE(CRTM1280x720)},
1052
1053 /* Display : 1920x1080 (CVT) */
1054 {VIA_RES_1920X1080, CRTM1920x1080, ARRAY_SIZE(CRTM1920x1080)},
1055
1056 /* Display : 1920x1080 (CVT Reduce Blanking) */
1057 {VIA_RES_1920X1080_RB, CRTM1920x1080_RB,
1058 ARRAY_SIZE(CRTM1920x1080_RB)},
1059
1060 /* Display : 1920x1200 (CVT) */
1061 {VIA_RES_1920X1200, CRTM1920x1200, ARRAY_SIZE(CRTM1920x1200)},
1062
1063 /* Display : 1920x1200 (CVT Reduce Blanking) */
1064 {VIA_RES_1920X1200_RB, CRTM1920x1200_RB,
1065 ARRAY_SIZE(CRTM1920x1200_RB)},
1066
1067 /* Display : 1400x1050 (CVT) */
1068 {VIA_RES_1400X1050, CRTM1400x1050, ARRAY_SIZE(CRTM1400x1050)}
1069};
1070struct crt_mode_table CEAM1280x720[] = {
1071 {REFRESH_60, CLK_74_270M, M1280X720_CEA_R60_HSP,
1072 M1280X720_CEA_R60_VSP,
1073 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
1074 {1650, 1280, 1280, 370, 1390, 40, 750, 720, 720, 30, 725, 5} }
1075};
1076struct crt_mode_table CEAM1920x1080[] = {
1077 {REFRESH_60, CLK_148_500M, M1920X1080_CEA_R60_HSP,
1078 M1920X1080_CEA_R60_VSP,
1079 /* HT, HA, HBS, HBE, HSS, HSE, VT, VA, VBS, VBE, VSS, VSE */
1080 {2200, 1920, 1920, 300, 2008, 44, 1125, 1080, 1080, 45, 1084, 5} }
1081};
1082struct VideoModeTable CEA_HDMI_Modes[] = {
1083 /* Display : 1280x720 */
1084 {VIA_RES_1280X720, CEAM1280x720, ARRAY_SIZE(CEAM1280x720)},
1085 {VIA_RES_1920X1080, CEAM1920x1080, ARRAY_SIZE(CEAM1920x1080)}
1086};
diff --git a/drivers/video/via/viamode.h b/drivers/video/via/viamode.h
new file mode 100644
index 000000000000..1a5de50a23a2
--- /dev/null
+++ b/drivers/video/via/viamode.h
@@ -0,0 +1,177 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#ifndef __VIAMODE_H__
23#define __VIAMODE_H__
24
25#include "global.h"
26
27struct VPITTable {
28 unsigned char Misc;
29 unsigned char SR[StdSR];
30 unsigned char GR[StdGR];
31 unsigned char AR[StdAR];
32};
33
34struct VideoModeTable {
35 int ModeIndex;
36 struct crt_mode_table *crtc;
37 int mode_array;
38};
39
40struct patch_table {
41 int mode_index;
42 int table_length;
43 struct io_reg *io_reg_table;
44};
45
46struct res_map_refresh {
47 int hres;
48 int vres;
49 int pixclock;
50 int vmode_refresh;
51};
52
53#define NUM_TOTAL_RES_MAP_REFRESH ARRAY_SIZE(res_map_refresh_tbl)
54#define NUM_TOTAL_CEA_MODES ARRAY_SIZE(CEA_HDMI_Modes)
55#define NUM_TOTAL_CN400_ModeXregs ARRAY_SIZE(CN400_ModeXregs)
56#define NUM_TOTAL_CN700_ModeXregs ARRAY_SIZE(CN700_ModeXregs)
57#define NUM_TOTAL_KM400_ModeXregs ARRAY_SIZE(KM400_ModeXregs)
58#define NUM_TOTAL_CX700_ModeXregs ARRAY_SIZE(CX700_ModeXregs)
59#define NUM_TOTAL_VX800_ModeXregs ARRAY_SIZE(VX800_ModeXregs)
60#define NUM_TOTAL_CLE266_ModeXregs ARRAY_SIZE(CLE266_ModeXregs)
61#define NUM_TOTAL_PATCH_MODE ARRAY_SIZE(res_patch_table)
62#define NUM_TOTAL_MODETABLE ARRAY_SIZE(CLE266Modes)
63
64/********************/
65/* Mode Table */
66/********************/
67
68/* 480x640 */
69extern struct crt_mode_table CRTM480x640[1];
70/* 640x480*/
71extern struct crt_mode_table CRTM640x480[5];
72/*720x480 (GTF)*/
73extern struct crt_mode_table CRTM720x480[1];
74/*720x576 (GTF)*/
75extern struct crt_mode_table CRTM720x576[1];
76/* 800x480 (CVT) */
77extern struct crt_mode_table CRTM800x480[1];
78/* 800x600*/
79extern struct crt_mode_table CRTM800x600[5];
80/* 848x480 (CVT) */
81extern struct crt_mode_table CRTM848x480[1];
82/*856x480 (GTF) convert to 852x480*/
83extern struct crt_mode_table CRTM852x480[1];
84/*1024x512 (GTF)*/
85extern struct crt_mode_table CRTM1024x512[1];
86/* 1024x600*/
87extern struct crt_mode_table CRTM1024x600[1];
88/* 1024x768*/
89extern struct crt_mode_table CRTM1024x768[4];
90/* 1152x864*/
91extern struct crt_mode_table CRTM1152x864[1];
92/* 1280x720 (HDMI 720P)*/
93extern struct crt_mode_table CRTM1280x720[2];
94/*1280x768 (GTF)*/
95extern struct crt_mode_table CRTM1280x768[2];
96/* 1280x800 (CVT) */
97extern struct crt_mode_table CRTM1280x800[1];
98/*1280x960*/
99extern struct crt_mode_table CRTM1280x960[1];
100/* 1280x1024*/
101extern struct crt_mode_table CRTM1280x1024[3];
102/* 1368x768 (GTF) */
103extern struct crt_mode_table CRTM1368x768[1];
104/*1440x1050 (GTF)*/
105extern struct crt_mode_table CRTM1440x1050[1];
106/* 1600x1200*/
107extern struct crt_mode_table CRTM1600x1200[2];
108/* 1680x1050 (CVT) */
109extern struct crt_mode_table CRTM1680x1050[2];
110/* 1680x1050 (CVT Reduce Blanking) */
111extern struct crt_mode_table CRTM1680x1050_RB[1];
112/* 1920x1080 (CVT)*/
113extern struct crt_mode_table CRTM1920x1080[1];
114/* 1920x1080 (CVT with Reduce Blanking) */
115extern struct crt_mode_table CRTM1920x1080_RB[1];
116/* 1920x1440*/
117extern struct crt_mode_table CRTM1920x1440[2];
118/* 1400x1050 (CVT) */
119extern struct crt_mode_table CRTM1400x1050[2];
120/* 1400x1050 (CVT Reduce Blanking) */
121extern struct crt_mode_table CRTM1400x1050_RB[1];
122/* 960x600 (CVT) */
123extern struct crt_mode_table CRTM960x600[1];
124/* 1000x600 (GTF) */
125extern struct crt_mode_table CRTM1000x600[1];
126/* 1024x576 (GTF) */
127extern struct crt_mode_table CRTM1024x576[1];
128/* 1088x612 (CVT) */
129extern struct crt_mode_table CRTM1088x612[1];
130/* 1152x720 (CVT) */
131extern struct crt_mode_table CRTM1152x720[1];
132/* 1200x720 (GTF) */
133extern struct crt_mode_table CRTM1200x720[1];
134/* 1280x600 (GTF) */
135extern struct crt_mode_table CRTM1280x600[1];
136/* 1360x768 (CVT) */
137extern struct crt_mode_table CRTM1360x768[1];
138/* 1360x768 (CVT Reduce Blanking) */
139extern struct crt_mode_table CRTM1360x768_RB[1];
140/* 1366x768 (GTF) */
141extern struct crt_mode_table CRTM1366x768[2];
142/* 1440x900 (CVT) */
143extern struct crt_mode_table CRTM1440x900[2];
144/* 1440x900 (CVT Reduce Blanking) */
145extern struct crt_mode_table CRTM1440x900_RB[1];
146/* 1600x900 (CVT) */
147extern struct crt_mode_table CRTM1600x900[1];
148/* 1600x900 (CVT Reduce Blanking) */
149extern struct crt_mode_table CRTM1600x900_RB[1];
150/* 1600x1024 (GTF) */
151extern struct crt_mode_table CRTM1600x1024[1];
152/* 1792x1344 (DMT) */
153extern struct crt_mode_table CRTM1792x1344[1];
154/* 1856x1392 (DMT) */
155extern struct crt_mode_table CRTM1856x1392[1];
156/* 1920x1200 (CVT) */
157extern struct crt_mode_table CRTM1920x1200[1];
158/* 1920x1200 (CVT with Reduce Blanking) */
159extern struct crt_mode_table CRTM1920x1200_RB[1];
160/* 2048x1536 (CVT) */
161extern struct crt_mode_table CRTM2048x1536[1];
162extern struct VideoModeTable CLE266Modes[47];
163extern struct crt_mode_table CEAM1280x720[1];
164extern struct crt_mode_table CEAM1920x1080[1];
165extern struct VideoModeTable CEA_HDMI_Modes[2];
166
167extern struct res_map_refresh res_map_refresh_tbl[61];
168extern struct io_reg CN400_ModeXregs[52];
169extern struct io_reg CN700_ModeXregs[66];
170extern struct io_reg KM400_ModeXregs[55];
171extern struct io_reg CX700_ModeXregs[58];
172extern struct io_reg VX800_ModeXregs[58];
173extern struct io_reg CLE266_ModeXregs[32];
174extern struct io_reg PM1024x768[2];
175extern struct patch_table res_patch_table[1];
176extern struct VPITTable VPIT;
177#endif /* __VIAMODE_H__ */
diff --git a/drivers/video/via/vt1636.c b/drivers/video/via/vt1636.c
new file mode 100644
index 000000000000..322a9f993550
--- /dev/null
+++ b/drivers/video/via/vt1636.c
@@ -0,0 +1,306 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#include "global.h"
23
24u8 viafb_gpio_i2c_read_lvds(struct lvds_setting_information
25 *plvds_setting_info, struct lvds_chip_information *plvds_chip_info,
26 u8 index)
27{
28 u8 data;
29
30 viaparinfo->i2c_stuff.i2c_port = plvds_chip_info->i2c_port;
31 viafb_i2c_readbyte(plvds_chip_info->lvds_chip_slave_addr, index, &data);
32
33 return data;
34}
35
36void viafb_gpio_i2c_write_mask_lvds(struct lvds_setting_information
37 *plvds_setting_info, struct lvds_chip_information
38 *plvds_chip_info, struct IODATA io_data)
39{
40 int index, data;
41
42 viaparinfo->i2c_stuff.i2c_port = plvds_chip_info->i2c_port;
43
44 index = io_data.Index;
45 data = viafb_gpio_i2c_read_lvds(plvds_setting_info, plvds_chip_info,
46 index);
47 data = (data & (~io_data.Mask)) | io_data.Data;
48
49 viafb_i2c_writebyte(plvds_chip_info->lvds_chip_slave_addr, index, data);
50}
51
52void viafb_init_lvds_vt1636(struct lvds_setting_information
53 *plvds_setting_info, struct lvds_chip_information *plvds_chip_info)
54{
55 int reg_num, i;
56
57 /* Common settings: */
58 reg_num = ARRAY_SIZE(COMMON_INIT_TBL_VT1636);
59
60 for (i = 0; i < reg_num; i++) {
61 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
62 plvds_chip_info,
63 COMMON_INIT_TBL_VT1636[i]);
64 }
65
66 /* Input Data Mode Select */
67 if (plvds_setting_info->device_lcd_dualedge) {
68 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
69 plvds_chip_info,
70 DUAL_CHANNEL_ENABLE_TBL_VT1636[0]);
71 } else {
72 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
73 plvds_chip_info,
74 SINGLE_CHANNEL_ENABLE_TBL_VT1636[0]);
75 }
76
77 if (plvds_setting_info->LCDDithering) {
78 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
79 plvds_chip_info,
80 DITHERING_ENABLE_TBL_VT1636[0]);
81 } else {
82 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
83 plvds_chip_info,
84 DITHERING_DISABLE_TBL_VT1636[0]);
85 }
86}
87
88void viafb_enable_lvds_vt1636(struct lvds_setting_information
89 *plvds_setting_info,
90 struct lvds_chip_information *plvds_chip_info)
91{
92
93 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info, plvds_chip_info,
94 VDD_ON_TBL_VT1636[0]);
95
96 /* Pad on: */
97 switch (plvds_chip_info->output_interface) {
98 case INTERFACE_DVP0:
99 {
100 viafb_write_reg_mask(SR1E, VIASR, 0xC0, 0xC0);
101 break;
102 }
103
104 case INTERFACE_DVP1:
105 {
106 viafb_write_reg_mask(SR1E, VIASR, 0x30, 0x30);
107 break;
108 }
109
110 case INTERFACE_DFP_LOW:
111 {
112 viafb_write_reg_mask(SR2A, VIASR, 0x03, 0x03);
113 break;
114 }
115
116 case INTERFACE_DFP_HIGH:
117 {
118 viafb_write_reg_mask(SR2A, VIASR, 0x03, 0x0C);
119 break;
120 }
121
122 }
123}
124
125void viafb_disable_lvds_vt1636(struct lvds_setting_information
126 *plvds_setting_info,
127 struct lvds_chip_information *plvds_chip_info)
128{
129
130 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info, plvds_chip_info,
131 VDD_OFF_TBL_VT1636[0]);
132
133 /* Pad off: */
134 switch (plvds_chip_info->output_interface) {
135 case INTERFACE_DVP0:
136 {
137 viafb_write_reg_mask(SR1E, VIASR, 0x00, 0xC0);
138 break;
139 }
140
141 case INTERFACE_DVP1:
142 {
143 viafb_write_reg_mask(SR1E, VIASR, 0x00, 0x30);
144 break;
145 }
146
147 case INTERFACE_DFP_LOW:
148 {
149 viafb_write_reg_mask(SR2A, VIASR, 0x00, 0x03);
150 break;
151 }
152
153 case INTERFACE_DFP_HIGH:
154 {
155 viafb_write_reg_mask(SR2A, VIASR, 0x00, 0x0C);
156 break;
157 }
158
159 }
160}
161
162bool viafb_lvds_identify_vt1636(void)
163{
164 u8 Buffer[2];
165
166 DEBUG_MSG(KERN_INFO "viafb_lvds_identify_vt1636.\n");
167
168 /* Sense VT1636 LVDS Transmiter */
169 viaparinfo->chip_info->lvds_chip_info.lvds_chip_slave_addr =
170 VT1636_LVDS_I2C_ADDR;
171
172 /* Check vendor ID first: */
173 viafb_i2c_readbyte((u8) viaparinfo->chip_info->lvds_chip_info.
174 lvds_chip_slave_addr,
175 0x00, &Buffer[0]);
176 viafb_i2c_readbyte((u8) viaparinfo->chip_info->lvds_chip_info.
177 lvds_chip_slave_addr,
178 0x01, &Buffer[1]);
179
180 if (!((Buffer[0] == 0x06) && (Buffer[1] == 0x11)))
181 return false;
182
183 /* Check Chip ID: */
184 viafb_i2c_readbyte((u8) viaparinfo->chip_info->lvds_chip_info.
185 lvds_chip_slave_addr,
186 0x02, &Buffer[0]);
187 viafb_i2c_readbyte((u8) viaparinfo->chip_info->lvds_chip_info.
188 lvds_chip_slave_addr,
189 0x03, &Buffer[1]);
190 if ((Buffer[0] == 0x45) && (Buffer[1] == 0x33)) {
191 viaparinfo->chip_info->lvds_chip_info.lvds_chip_name =
192 VT1636_LVDS;
193 return true;
194 }
195
196 return false;
197}
198
199static int get_clk_range_index(u32 Clk)
200{
201 if (Clk < DPA_CLK_30M)
202 return DPA_CLK_RANGE_30M;
203 else if (Clk < DPA_CLK_50M)
204 return DPA_CLK_RANGE_30_50M;
205 else if (Clk < DPA_CLK_70M)
206 return DPA_CLK_RANGE_50_70M;
207 else if (Clk < DPA_CLK_100M)
208 return DPA_CLK_RANGE_70_100M;
209 else if (Clk < DPA_CLK_150M)
210 return DPA_CLK_RANGE_100_150M;
211 else
212 return DPA_CLK_RANGE_150M;
213}
214
215static int get_lvds_dpa_setting_index(int panel_size_id,
216 struct VT1636_DPA_SETTING *p_vt1636_dpasetting_tbl,
217 int tbl_size)
218{
219 int i;
220
221 for (i = 0; i < tbl_size; i++) {
222 if (panel_size_id == p_vt1636_dpasetting_tbl->PanelSizeID)
223 return i;
224
225 p_vt1636_dpasetting_tbl++;
226 }
227
228 return 0;
229}
230
231static void set_dpa_vt1636(struct lvds_setting_information
232 *plvds_setting_info, struct lvds_chip_information *plvds_chip_info,
233 struct VT1636_DPA_SETTING *p_vt1636_dpa_setting)
234{
235 struct IODATA io_data;
236
237 io_data.Index = 0x09;
238 io_data.Mask = 0x1F;
239 io_data.Data = p_vt1636_dpa_setting->CLK_SEL_ST1;
240 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info,
241 plvds_chip_info, io_data);
242
243 io_data.Index = 0x08;
244 io_data.Mask = 0x0F;
245 io_data.Data = p_vt1636_dpa_setting->CLK_SEL_ST2;
246 viafb_gpio_i2c_write_mask_lvds(plvds_setting_info, plvds_chip_info,
247 io_data);
248}
249
250void viafb_vt1636_patch_skew_on_vt3324(
251 struct lvds_setting_information *plvds_setting_info,
252 struct lvds_chip_information *plvds_chip_info)
253{
254 int index, size;
255
256 DEBUG_MSG(KERN_INFO "viafb_vt1636_patch_skew_on_vt3324.\n");
257
258 /* Graphics DPA settings: */
259 index = get_clk_range_index(plvds_setting_info->vclk);
260 viafb_set_dpa_gfx(plvds_chip_info->output_interface,
261 &GFX_DPA_SETTING_TBL_VT3324[index]);
262
263 /* LVDS Transmitter DPA settings: */
264 size = ARRAY_SIZE(VT1636_DPA_SETTING_TBL_VT3324);
265 index =
266 get_lvds_dpa_setting_index(plvds_setting_info->lcd_panel_id,
267 VT1636_DPA_SETTING_TBL_VT3324, size);
268 set_dpa_vt1636(plvds_setting_info, plvds_chip_info,
269 &VT1636_DPA_SETTING_TBL_VT3324[index]);
270}
271
272void viafb_vt1636_patch_skew_on_vt3327(
273 struct lvds_setting_information *plvds_setting_info,
274 struct lvds_chip_information *plvds_chip_info)
275{
276 int index, size;
277
278 DEBUG_MSG(KERN_INFO "viafb_vt1636_patch_skew_on_vt3327.\n");
279
280 /* Graphics DPA settings: */
281 index = get_clk_range_index(plvds_setting_info->vclk);
282 viafb_set_dpa_gfx(plvds_chip_info->output_interface,
283 &GFX_DPA_SETTING_TBL_VT3327[index]);
284
285 /* LVDS Transmitter DPA settings: */
286 size = ARRAY_SIZE(VT1636_DPA_SETTING_TBL_VT3327);
287 index =
288 get_lvds_dpa_setting_index(plvds_setting_info->lcd_panel_id,
289 VT1636_DPA_SETTING_TBL_VT3327, size);
290 set_dpa_vt1636(plvds_setting_info, plvds_chip_info,
291 &VT1636_DPA_SETTING_TBL_VT3327[index]);
292}
293
294void viafb_vt1636_patch_skew_on_vt3364(
295 struct lvds_setting_information *plvds_setting_info,
296 struct lvds_chip_information *plvds_chip_info)
297{
298 int index;
299
300 DEBUG_MSG(KERN_INFO "viafb_vt1636_patch_skew_on_vt3364.\n");
301
302 /* Graphics DPA settings: */
303 index = get_clk_range_index(plvds_setting_info->vclk);
304 viafb_set_dpa_gfx(plvds_chip_info->output_interface,
305 &GFX_DPA_SETTING_TBL_VT3364[index]);
306}
diff --git a/drivers/video/via/vt1636.h b/drivers/video/via/vt1636.h
new file mode 100644
index 000000000000..2a150c58c7ed
--- /dev/null
+++ b/drivers/video/via/vt1636.h
@@ -0,0 +1,44 @@
1/*
2 * Copyright 1998-2008 VIA Technologies, Inc. All Rights Reserved.
3 * Copyright 2001-2008 S3 Graphics, Inc. All Rights Reserved.
4
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License as published by the Free Software Foundation;
8 * either version 2, or (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTIES OR REPRESENTATIONS; without even
12 * the implied warranty of MERCHANTABILITY or FITNESS FOR
13 * A PARTICULAR PURPOSE.See the GNU General Public License
14 * for more details.
15
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc.,
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#ifndef _VT1636_H_
23#define _VT1636_H_
24#include "chip.h"
25bool viafb_lvds_identify_vt1636(void);
26void viafb_init_lvds_vt1636(struct lvds_setting_information
27 *plvds_setting_info, struct lvds_chip_information *plvds_chip_info);
28void viafb_enable_lvds_vt1636(struct lvds_setting_information
29 *plvds_setting_info,
30 struct lvds_chip_information *plvds_chip_info);
31void viafb_disable_lvds_vt1636(struct lvds_setting_information
32 *plvds_setting_info,
33 struct lvds_chip_information *plvds_chip_info);
34void viafb_vt1636_patch_skew_on_vt3324(
35 struct lvds_setting_information *plvds_setting_info,
36 struct lvds_chip_information *plvds_chip_info);
37void viafb_vt1636_patch_skew_on_vt3327(
38 struct lvds_setting_information *plvds_setting_info,
39 struct lvds_chip_information *plvds_chip_info);
40void viafb_vt1636_patch_skew_on_vt3364(
41 struct lvds_setting_information *plvds_setting_info,
42 struct lvds_chip_information *plvds_chip_info);
43
44#endif
diff --git a/drivers/w1/masters/ds1wm.c b/drivers/w1/masters/ds1wm.c
index 10211e493001..29e144f81cbe 100644
--- a/drivers/w1/masters/ds1wm.c
+++ b/drivers/w1/masters/ds1wm.c
@@ -160,8 +160,10 @@ static int ds1wm_reset(struct ds1wm_data *ds1wm_data)
160 * 625 us - 60 us - 240 us - 100 ns = 324.9 us 160 * 625 us - 60 us - 240 us - 100 ns = 324.9 us
161 * 161 *
162 * We'll wait a bit longer just to be sure. 162 * We'll wait a bit longer just to be sure.
163 * Was udelay(500), but if it is going to busywait the cpu that long,
164 * might as well come back later.
163 */ 165 */
164 udelay(500); 166 msleep(1);
165 167
166 ds1wm_write_register(ds1wm_data, DS1WM_INT_EN, 168 ds1wm_write_register(ds1wm_data, DS1WM_INT_EN,
167 DS1WM_INTEN_ERBF | DS1WM_INTEN_ETMT | DS1WM_INTEN_EPD | 169 DS1WM_INTEN_ERBF | DS1WM_INTEN_ETMT | DS1WM_INTEN_EPD |
@@ -274,8 +276,8 @@ static u8 ds1wm_reset_bus(void *data)
274 return 0; 276 return 0;
275} 277}
276 278
277static void ds1wm_search(void *data, u8 search_type, 279static void ds1wm_search(void *data, struct w1_master *master_dev,
278 w1_slave_found_callback slave_found) 280 u8 search_type, w1_slave_found_callback slave_found)
279{ 281{
280 struct ds1wm_data *ds1wm_data = data; 282 struct ds1wm_data *ds1wm_data = data;
281 int i; 283 int i;
@@ -313,7 +315,7 @@ static void ds1wm_search(void *data, u8 search_type,
313 ds1wm_write_register(ds1wm_data, DS1WM_CMD, ~DS1WM_CMD_SRA); 315 ds1wm_write_register(ds1wm_data, DS1WM_CMD, ~DS1WM_CMD_SRA);
314 ds1wm_reset(ds1wm_data); 316 ds1wm_reset(ds1wm_data);
315 317
316 slave_found(ds1wm_data, rom_id); 318 slave_found(master_dev, rom_id);
317} 319}
318 320
319/* --------------------------------------------------------------------- */ 321/* --------------------------------------------------------------------- */
diff --git a/drivers/w1/masters/ds2490.c b/drivers/w1/masters/ds2490.c
index b63b5e044a4c..59ad6e95af8f 100644
--- a/drivers/w1/masters/ds2490.c
+++ b/drivers/w1/masters/ds2490.c
@@ -88,7 +88,7 @@
88#define COMM_DT 0x2000 88#define COMM_DT 0x2000
89#define COMM_SPU 0x1000 89#define COMM_SPU 0x1000
90#define COMM_F 0x0800 90#define COMM_F 0x0800
91#define COMM_NTP 0x0400 91#define COMM_NTF 0x0400
92#define COMM_ICP 0x0200 92#define COMM_ICP 0x0200
93#define COMM_RST 0x0100 93#define COMM_RST 0x0100
94 94
@@ -98,11 +98,6 @@
98#define BRANCH_MAIN 0xCC 98#define BRANCH_MAIN 0xCC
99#define BRANCH_AUX 0x33 99#define BRANCH_AUX 0x33
100 100
101/*
102 * Duration of the strong pull-up pulse in milliseconds.
103 */
104#define PULLUP_PULSE_DURATION 750
105
106/* Status flags */ 101/* Status flags */
107#define ST_SPUA 0x01 /* Strong Pull-up is active */ 102#define ST_SPUA 0x01 /* Strong Pull-up is active */
108#define ST_PRGA 0x02 /* 12V programming pulse is being generated */ 103#define ST_PRGA 0x02 /* 12V programming pulse is being generated */
@@ -112,6 +107,17 @@
112#define ST_IDLE 0x20 /* DS2490 is currently idle */ 107#define ST_IDLE 0x20 /* DS2490 is currently idle */
113#define ST_EPOF 0x80 108#define ST_EPOF 0x80
114 109
110/* Result Register flags */
111#define RR_DETECT 0xA5 /* New device detected */
112#define RR_NRS 0x01 /* Reset no presence or ... */
113#define RR_SH 0x02 /* short on reset or set path */
114#define RR_APP 0x04 /* alarming presence on reset */
115#define RR_VPP 0x08 /* 12V expected not seen */
116#define RR_CMP 0x10 /* compare error */
117#define RR_CRC 0x20 /* CRC error detected */
118#define RR_RDP 0x40 /* redirected page */
119#define RR_EOS 0x80 /* end of search error */
120
115#define SPEED_NORMAL 0x00 121#define SPEED_NORMAL 0x00
116#define SPEED_FLEXIBLE 0x01 122#define SPEED_FLEXIBLE 0x01
117#define SPEED_OVERDRIVE 0x02 123#define SPEED_OVERDRIVE 0x02
@@ -131,6 +137,15 @@ struct ds_device
131 137
132 int ep[NUM_EP]; 138 int ep[NUM_EP];
133 139
140 /* Strong PullUp
141 * 0: pullup not active, else duration in milliseconds
142 */
143 int spu_sleep;
144 /* spu_bit contains COMM_SPU or 0 depending on if the strong pullup
145 * should be active or not for writes.
146 */
147 u16 spu_bit;
148
134 struct w1_bus_master master; 149 struct w1_bus_master master;
135}; 150};
136 151
@@ -164,7 +179,6 @@ MODULE_DEVICE_TABLE(usb, ds_id_table);
164static int ds_probe(struct usb_interface *, const struct usb_device_id *); 179static int ds_probe(struct usb_interface *, const struct usb_device_id *);
165static void ds_disconnect(struct usb_interface *); 180static void ds_disconnect(struct usb_interface *);
166 181
167static inline void ds_dump_status(unsigned char *, unsigned char *, int);
168static int ds_send_control(struct ds_device *, u16, u16); 182static int ds_send_control(struct ds_device *, u16, u16);
169static int ds_send_control_cmd(struct ds_device *, u16, u16); 183static int ds_send_control_cmd(struct ds_device *, u16, u16);
170 184
@@ -192,7 +206,7 @@ static int ds_send_control_cmd(struct ds_device *dev, u16 value, u16 index)
192 206
193 return err; 207 return err;
194} 208}
195#if 0 209
196static int ds_send_control_mode(struct ds_device *dev, u16 value, u16 index) 210static int ds_send_control_mode(struct ds_device *dev, u16 value, u16 index)
197{ 211{
198 int err; 212 int err;
@@ -207,7 +221,7 @@ static int ds_send_control_mode(struct ds_device *dev, u16 value, u16 index)
207 221
208 return err; 222 return err;
209} 223}
210#endif 224
211static int ds_send_control(struct ds_device *dev, u16 value, u16 index) 225static int ds_send_control(struct ds_device *dev, u16 value, u16 index)
212{ 226{
213 int err; 227 int err;
@@ -223,11 +237,6 @@ static int ds_send_control(struct ds_device *dev, u16 value, u16 index)
223 return err; 237 return err;
224} 238}
225 239
226static inline void ds_dump_status(unsigned char *buf, unsigned char *str, int off)
227{
228 printk("%45s: %8x\n", str, buf[off]);
229}
230
231static int ds_recv_status_nodump(struct ds_device *dev, struct ds_status *st, 240static int ds_recv_status_nodump(struct ds_device *dev, struct ds_status *st,
232 unsigned char *buf, int size) 241 unsigned char *buf, int size)
233{ 242{
@@ -248,62 +257,81 @@ static int ds_recv_status_nodump(struct ds_device *dev, struct ds_status *st,
248 return count; 257 return count;
249} 258}
250 259
251static int ds_recv_status(struct ds_device *dev, struct ds_status *st) 260static inline void ds_print_msg(unsigned char *buf, unsigned char *str, int off)
252{ 261{
253 unsigned char buf[64]; 262 printk(KERN_INFO "%45s: %8x\n", str, buf[off]);
254 int count, err = 0, i; 263}
255
256 memcpy(st, buf, sizeof(*st));
257 264
258 count = ds_recv_status_nodump(dev, st, buf, sizeof(buf)); 265static void ds_dump_status(struct ds_device *dev, unsigned char *buf, int count)
259 if (count < 0) 266{
260 return err; 267 int i;
261 268
262 printk("0x%x: count=%d, status: ", dev->ep[EP_STATUS], count); 269 printk(KERN_INFO "0x%x: count=%d, status: ", dev->ep[EP_STATUS], count);
263 for (i=0; i<count; ++i) 270 for (i=0; i<count; ++i)
264 printk("%02x ", buf[i]); 271 printk("%02x ", buf[i]);
265 printk("\n"); 272 printk(KERN_INFO "\n");
266 273
267 if (count >= 16) { 274 if (count >= 16) {
268 ds_dump_status(buf, "enable flag", 0); 275 ds_print_msg(buf, "enable flag", 0);
269 ds_dump_status(buf, "1-wire speed", 1); 276 ds_print_msg(buf, "1-wire speed", 1);
270 ds_dump_status(buf, "strong pullup duration", 2); 277 ds_print_msg(buf, "strong pullup duration", 2);
271 ds_dump_status(buf, "programming pulse duration", 3); 278 ds_print_msg(buf, "programming pulse duration", 3);
272 ds_dump_status(buf, "pulldown slew rate control", 4); 279 ds_print_msg(buf, "pulldown slew rate control", 4);
273 ds_dump_status(buf, "write-1 low time", 5); 280 ds_print_msg(buf, "write-1 low time", 5);
274 ds_dump_status(buf, "data sample offset/write-0 recovery time", 6); 281 ds_print_msg(buf, "data sample offset/write-0 recovery time",
275 ds_dump_status(buf, "reserved (test register)", 7); 282 6);
276 ds_dump_status(buf, "device status flags", 8); 283 ds_print_msg(buf, "reserved (test register)", 7);
277 ds_dump_status(buf, "communication command byte 1", 9); 284 ds_print_msg(buf, "device status flags", 8);
278 ds_dump_status(buf, "communication command byte 2", 10); 285 ds_print_msg(buf, "communication command byte 1", 9);
279 ds_dump_status(buf, "communication command buffer status", 11); 286 ds_print_msg(buf, "communication command byte 2", 10);
280 ds_dump_status(buf, "1-wire data output buffer status", 12); 287 ds_print_msg(buf, "communication command buffer status", 11);
281 ds_dump_status(buf, "1-wire data input buffer status", 13); 288 ds_print_msg(buf, "1-wire data output buffer status", 12);
282 ds_dump_status(buf, "reserved", 14); 289 ds_print_msg(buf, "1-wire data input buffer status", 13);
283 ds_dump_status(buf, "reserved", 15); 290 ds_print_msg(buf, "reserved", 14);
291 ds_print_msg(buf, "reserved", 15);
284 } 292 }
285 293 for (i = 16; i < count; ++i) {
286 memcpy(st, buf, sizeof(*st)); 294 if (buf[i] == RR_DETECT) {
287 295 ds_print_msg(buf, "new device detect", i);
288 if (st->status & ST_EPOF) { 296 continue;
289 printk(KERN_INFO "Resetting device after ST_EPOF.\n"); 297 }
290 err = ds_send_control_cmd(dev, CTL_RESET_DEVICE, 0); 298 ds_print_msg(buf, "Result Register Value: ", i);
291 if (err) 299 if (buf[i] & RR_NRS)
292 return err; 300 printk(KERN_INFO "NRS: Reset no presence or ...\n");
293 count = ds_recv_status_nodump(dev, st, buf, sizeof(buf)); 301 if (buf[i] & RR_SH)
294 if (count < 0) 302 printk(KERN_INFO "SH: short on reset or set path\n");
295 return err; 303 if (buf[i] & RR_APP)
296 } 304 printk(KERN_INFO "APP: alarming presence on reset\n");
297#if 0 305 if (buf[i] & RR_VPP)
298 if (st->status & ST_IDLE) { 306 printk(KERN_INFO "VPP: 12V expected not seen\n");
299 printk(KERN_INFO "Resetting pulse after ST_IDLE.\n"); 307 if (buf[i] & RR_CMP)
300 err = ds_start_pulse(dev, PULLUP_PULSE_DURATION); 308 printk(KERN_INFO "CMP: compare error\n");
301 if (err) 309 if (buf[i] & RR_CRC)
302 return err; 310 printk(KERN_INFO "CRC: CRC error detected\n");
311 if (buf[i] & RR_RDP)
312 printk(KERN_INFO "RDP: redirected page\n");
313 if (buf[i] & RR_EOS)
314 printk(KERN_INFO "EOS: end of search error\n");
303 } 315 }
304#endif 316}
305 317
306 return err; 318static void ds_reset_device(struct ds_device *dev)
319{
320 ds_send_control_cmd(dev, CTL_RESET_DEVICE, 0);
321 /* Always allow strong pullup which allow individual writes to use
322 * the strong pullup.
323 */
324 if (ds_send_control_mode(dev, MOD_PULSE_EN, PULSE_SPUE))
325 printk(KERN_ERR "ds_reset_device: "
326 "Error allowing strong pullup\n");
327 /* Chip strong pullup time was cleared. */
328 if (dev->spu_sleep) {
329 /* lower 4 bits are 0, see ds_set_pullup */
330 u8 del = dev->spu_sleep>>4;
331 if (ds_send_control(dev, COMM_SET_DURATION | COMM_IM, del))
332 printk(KERN_ERR "ds_reset_device: "
333 "Error setting duration\n");
334 }
307} 335}
308 336
309static int ds_recv_data(struct ds_device *dev, unsigned char *buf, int size) 337static int ds_recv_data(struct ds_device *dev, unsigned char *buf, int size)
@@ -311,13 +339,27 @@ static int ds_recv_data(struct ds_device *dev, unsigned char *buf, int size)
311 int count, err; 339 int count, err;
312 struct ds_status st; 340 struct ds_status st;
313 341
342 /* Careful on size. If size is less than what is available in
343 * the input buffer, the device fails the bulk transfer and
344 * clears the input buffer. It could read the maximum size of
345 * the data buffer, but then do you return the first, last, or
346 * some set of the middle size bytes? As long as the rest of
347 * the code is correct there will be size bytes waiting. A
348 * call to ds_wait_status will wait until the device is idle
349 * and any data to be received would have been available.
350 */
314 count = 0; 351 count = 0;
315 err = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_DATA_IN]), 352 err = usb_bulk_msg(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_DATA_IN]),
316 buf, size, &count, 1000); 353 buf, size, &count, 1000);
317 if (err < 0) { 354 if (err < 0) {
355 u8 buf[0x20];
356 int count;
357
318 printk(KERN_INFO "Clearing ep0x%x.\n", dev->ep[EP_DATA_IN]); 358 printk(KERN_INFO "Clearing ep0x%x.\n", dev->ep[EP_DATA_IN]);
319 usb_clear_halt(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_DATA_IN])); 359 usb_clear_halt(dev->udev, usb_rcvbulkpipe(dev->udev, dev->ep[EP_DATA_IN]));
320 ds_recv_status(dev, &st); 360
361 count = ds_recv_status_nodump(dev, &st, buf, sizeof(buf));
362 ds_dump_status(dev, buf, count);
321 return err; 363 return err;
322 } 364 }
323 365
@@ -341,7 +383,8 @@ static int ds_send_data(struct ds_device *dev, unsigned char *buf, int len)
341 count = 0; 383 count = 0;
342 err = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, dev->ep[EP_DATA_OUT]), buf, len, &count, 1000); 384 err = usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, dev->ep[EP_DATA_OUT]), buf, len, &count, 1000);
343 if (err < 0) { 385 if (err < 0) {
344 printk(KERN_ERR "Failed to read 1-wire data from 0x02: err=%d.\n", err); 386 printk(KERN_ERR "Failed to write 1-wire data to ep0x%x: "
387 "err=%d.\n", dev->ep[EP_DATA_OUT], err);
345 return err; 388 return err;
346 } 389 }
347 390
@@ -397,7 +440,7 @@ int ds_detect(struct ds_device *dev, struct ds_status *st)
397 if (err) 440 if (err)
398 return err; 441 return err;
399 442
400 err = ds_recv_status(dev, st); 443 err = ds_dump_status(dev, st);
401 444
402 return err; 445 return err;
403} 446}
@@ -420,33 +463,49 @@ static int ds_wait_status(struct ds_device *dev, struct ds_status *st)
420 printk("\n"); 463 printk("\n");
421 } 464 }
422#endif 465#endif
423 } while(!(buf[0x08] & 0x20) && !(err < 0) && ++count < 100); 466 } while (!(buf[0x08] & ST_IDLE) && !(err < 0) && ++count < 100);
467
468 if (err >= 16 && st->status & ST_EPOF) {
469 printk(KERN_INFO "Resetting device after ST_EPOF.\n");
470 ds_reset_device(dev);
471 /* Always dump the device status. */
472 count = 101;
473 }
424 474
475 /* Dump the status for errors or if there is extended return data.
476 * The extended status includes new device detection (maybe someone
477 * can do something with it).
478 */
479 if (err > 16 || count >= 100 || err < 0)
480 ds_dump_status(dev, buf, err);
425 481
426 if (((err > 16) && (buf[0x10] & 0x01)) || count >= 100 || err < 0) { 482 /* Extended data isn't an error. Well, a short is, but the dump
427 ds_recv_status(dev, st); 483 * would have already told the user that and we can't do anything
484 * about it in software anyway.
485 */
486 if (count >= 100 || err < 0)
428 return -1; 487 return -1;
429 } else 488 else
430 return 0; 489 return 0;
431} 490}
432 491
433static int ds_reset(struct ds_device *dev, struct ds_status *st) 492static int ds_reset(struct ds_device *dev)
434{ 493{
435 int err; 494 int err;
436 495
437 //err = ds_send_control(dev, COMM_1_WIRE_RESET | COMM_F | COMM_IM | COMM_SE, SPEED_FLEXIBLE); 496 /* Other potentionally interesting flags for reset.
438 err = ds_send_control(dev, 0x43, SPEED_NORMAL); 497 *
498 * COMM_NTF: Return result register feedback. This could be used to
499 * detect some conditions such as short, alarming presence, or
500 * detect if a new device was detected.
501 *
502 * COMM_SE which allows SPEED_NORMAL, SPEED_FLEXIBLE, SPEED_OVERDRIVE:
503 * Select the data transfer rate.
504 */
505 err = ds_send_control(dev, COMM_1_WIRE_RESET | COMM_IM, SPEED_NORMAL);
439 if (err) 506 if (err)
440 return err; 507 return err;
441 508
442 ds_wait_status(dev, st);
443#if 0
444 if (st->command_buffer_status) {
445 printk(KERN_INFO "Short circuit.\n");
446 return -EIO;
447 }
448#endif
449
450 return 0; 509 return 0;
451} 510}
452 511
@@ -471,60 +530,43 @@ static int ds_set_speed(struct ds_device *dev, int speed)
471} 530}
472#endif /* 0 */ 531#endif /* 0 */
473 532
474static int ds_start_pulse(struct ds_device *dev, int delay) 533static int ds_set_pullup(struct ds_device *dev, int delay)
475{ 534{
476 int err; 535 int err = 0;
477 u8 del = 1 + (u8)(delay >> 4); 536 u8 del = 1 + (u8)(delay >> 4);
478 struct ds_status st; 537 /* Just storing delay would not get the trunication and roundup. */
479 538 int ms = del<<4;
480#if 0 539
481 err = ds_stop_pulse(dev, 10); 540 /* Enable spu_bit if a delay is set. */
482 if (err) 541 dev->spu_bit = delay ? COMM_SPU : 0;
542 /* If delay is zero, it has already been disabled, if the time is
543 * the same as the hardware was last programmed to, there is also
544 * nothing more to do. Compare with the recalculated value ms
545 * rather than del or delay which can have a different value.
546 */
547 if (delay == 0 || ms == dev->spu_sleep)
483 return err; 548 return err;
484 549
485 err = ds_send_control_mode(dev, MOD_PULSE_EN, PULSE_SPUE);
486 if (err)
487 return err;
488#endif
489 err = ds_send_control(dev, COMM_SET_DURATION | COMM_IM, del); 550 err = ds_send_control(dev, COMM_SET_DURATION | COMM_IM, del);
490 if (err) 551 if (err)
491 return err; 552 return err;
492 553
493 err = ds_send_control(dev, COMM_PULSE | COMM_IM | COMM_F, 0); 554 dev->spu_sleep = ms;
494 if (err)
495 return err;
496
497 mdelay(delay);
498
499 ds_wait_status(dev, &st);
500 555
501 return err; 556 return err;
502} 557}
503 558
504static int ds_touch_bit(struct ds_device *dev, u8 bit, u8 *tbit) 559static int ds_touch_bit(struct ds_device *dev, u8 bit, u8 *tbit)
505{ 560{
506 int err, count; 561 int err;
507 struct ds_status st; 562 struct ds_status st;
508 u16 value = (COMM_BIT_IO | COMM_IM) | ((bit) ? COMM_D : 0);
509 u16 cmd;
510 563
511 err = ds_send_control(dev, value, 0); 564 err = ds_send_control(dev, COMM_BIT_IO | COMM_IM | (bit ? COMM_D : 0),
565 0);
512 if (err) 566 if (err)
513 return err; 567 return err;
514 568
515 count = 0; 569 ds_wait_status(dev, &st);
516 do {
517 err = ds_wait_status(dev, &st);
518 if (err)
519 return err;
520
521 cmd = st.command0 | (st.command1 << 8);
522 } while (cmd != value && ++count < 10);
523
524 if (err < 0 || count >= 10) {
525 printk(KERN_ERR "Failed to obtain status.\n");
526 return -EINVAL;
527 }
528 570
529 err = ds_recv_data(dev, tbit, sizeof(*tbit)); 571 err = ds_recv_data(dev, tbit, sizeof(*tbit));
530 if (err < 0) 572 if (err < 0)
@@ -533,12 +575,18 @@ static int ds_touch_bit(struct ds_device *dev, u8 bit, u8 *tbit)
533 return 0; 575 return 0;
534} 576}
535 577
578#if 0
536static int ds_write_bit(struct ds_device *dev, u8 bit) 579static int ds_write_bit(struct ds_device *dev, u8 bit)
537{ 580{
538 int err; 581 int err;
539 struct ds_status st; 582 struct ds_status st;
540 583
541 err = ds_send_control(dev, COMM_BIT_IO | COMM_IM | (bit) ? COMM_D : 0, 0); 584 /* Set COMM_ICP to write without a readback. Note, this will
585 * produce one time slot, a down followed by an up with COMM_D
586 * only determing the timing.
587 */
588 err = ds_send_control(dev, COMM_BIT_IO | COMM_IM | COMM_ICP |
589 (bit ? COMM_D : 0), 0);
542 if (err) 590 if (err)
543 return err; 591 return err;
544 592
@@ -546,6 +594,7 @@ static int ds_write_bit(struct ds_device *dev, u8 bit)
546 594
547 return 0; 595 return 0;
548} 596}
597#endif
549 598
550static int ds_write_byte(struct ds_device *dev, u8 byte) 599static int ds_write_byte(struct ds_device *dev, u8 byte)
551{ 600{
@@ -553,10 +602,13 @@ static int ds_write_byte(struct ds_device *dev, u8 byte)
553 struct ds_status st; 602 struct ds_status st;
554 u8 rbyte; 603 u8 rbyte;
555 604
556 err = ds_send_control(dev, COMM_BYTE_IO | COMM_IM | COMM_SPU, byte); 605 err = ds_send_control(dev, COMM_BYTE_IO | COMM_IM | dev->spu_bit, byte);
557 if (err) 606 if (err)
558 return err; 607 return err;
559 608
609 if (dev->spu_bit)
610 msleep(dev->spu_sleep);
611
560 err = ds_wait_status(dev, &st); 612 err = ds_wait_status(dev, &st);
561 if (err) 613 if (err)
562 return err; 614 return err;
@@ -565,8 +617,6 @@ static int ds_write_byte(struct ds_device *dev, u8 byte)
565 if (err < 0) 617 if (err < 0)
566 return err; 618 return err;
567 619
568 ds_start_pulse(dev, PULLUP_PULSE_DURATION);
569
570 return !(byte == rbyte); 620 return !(byte == rbyte);
571} 621}
572 622
@@ -602,7 +652,7 @@ static int ds_read_block(struct ds_device *dev, u8 *buf, int len)
602 if (err < 0) 652 if (err < 0)
603 return err; 653 return err;
604 654
605 err = ds_send_control(dev, COMM_BLOCK_IO | COMM_IM | COMM_SPU, len); 655 err = ds_send_control(dev, COMM_BLOCK_IO | COMM_IM, len);
606 if (err) 656 if (err)
607 return err; 657 return err;
608 658
@@ -623,20 +673,19 @@ static int ds_write_block(struct ds_device *dev, u8 *buf, int len)
623 if (err < 0) 673 if (err < 0)
624 return err; 674 return err;
625 675
626 ds_wait_status(dev, &st); 676 err = ds_send_control(dev, COMM_BLOCK_IO | COMM_IM | dev->spu_bit, len);
627
628 err = ds_send_control(dev, COMM_BLOCK_IO | COMM_IM | COMM_SPU, len);
629 if (err) 677 if (err)
630 return err; 678 return err;
631 679
680 if (dev->spu_bit)
681 msleep(dev->spu_sleep);
682
632 ds_wait_status(dev, &st); 683 ds_wait_status(dev, &st);
633 684
634 err = ds_recv_data(dev, buf, len); 685 err = ds_recv_data(dev, buf, len);
635 if (err < 0) 686 if (err < 0)
636 return err; 687 return err;
637 688
638 ds_start_pulse(dev, PULLUP_PULSE_DURATION);
639
640 return !(err == len); 689 return !(err == len);
641} 690}
642 691
@@ -728,6 +777,7 @@ static u8 ds9490r_touch_bit(void *data, u8 bit)
728 return ret; 777 return ret;
729} 778}
730 779
780#if 0
731static void ds9490r_write_bit(void *data, u8 bit) 781static void ds9490r_write_bit(void *data, u8 bit)
732{ 782{
733 struct ds_device *dev = data; 783 struct ds_device *dev = data;
@@ -735,13 +785,6 @@ static void ds9490r_write_bit(void *data, u8 bit)
735 ds_write_bit(dev, bit); 785 ds_write_bit(dev, bit);
736} 786}
737 787
738static void ds9490r_write_byte(void *data, u8 byte)
739{
740 struct ds_device *dev = data;
741
742 ds_write_byte(dev, byte);
743}
744
745static u8 ds9490r_read_bit(void *data) 788static u8 ds9490r_read_bit(void *data)
746{ 789{
747 struct ds_device *dev = data; 790 struct ds_device *dev = data;
@@ -754,6 +797,14 @@ static u8 ds9490r_read_bit(void *data)
754 797
755 return bit & 1; 798 return bit & 1;
756} 799}
800#endif
801
802static void ds9490r_write_byte(void *data, u8 byte)
803{
804 struct ds_device *dev = data;
805
806 ds_write_byte(dev, byte);
807}
757 808
758static u8 ds9490r_read_byte(void *data) 809static u8 ds9490r_read_byte(void *data)
759{ 810{
@@ -790,31 +841,58 @@ static u8 ds9490r_read_block(void *data, u8 *buf, int len)
790static u8 ds9490r_reset(void *data) 841static u8 ds9490r_reset(void *data)
791{ 842{
792 struct ds_device *dev = data; 843 struct ds_device *dev = data;
793 struct ds_status st;
794 int err; 844 int err;
795 845
796 memset(&st, 0, sizeof(st)); 846 err = ds_reset(dev);
797
798 err = ds_reset(dev, &st);
799 if (err) 847 if (err)
800 return 1; 848 return 1;
801 849
802 return 0; 850 return 0;
803} 851}
804 852
853static u8 ds9490r_set_pullup(void *data, int delay)
854{
855 struct ds_device *dev = data;
856
857 if (ds_set_pullup(dev, delay))
858 return 1;
859
860 return 0;
861}
862
805static int ds_w1_init(struct ds_device *dev) 863static int ds_w1_init(struct ds_device *dev)
806{ 864{
807 memset(&dev->master, 0, sizeof(struct w1_bus_master)); 865 memset(&dev->master, 0, sizeof(struct w1_bus_master));
808 866
867 /* Reset the device as it can be in a bad state.
868 * This is necessary because a block write will wait for data
869 * to be placed in the output buffer and block any later
870 * commands which will keep accumulating and the device will
871 * not be idle. Another case is removing the ds2490 module
872 * while a bus search is in progress, somehow a few commands
873 * get through, but the input transfers fail leaving data in
874 * the input buffer. This will cause the next read to fail
875 * see the note in ds_recv_data.
876 */
877 ds_reset_device(dev);
878
809 dev->master.data = dev; 879 dev->master.data = dev;
810 dev->master.touch_bit = &ds9490r_touch_bit; 880 dev->master.touch_bit = &ds9490r_touch_bit;
881 /* read_bit and write_bit in w1_bus_master are expected to set and
882 * sample the line level. For write_bit that means it is expected to
883 * set it to that value and leave it there. ds2490 only supports an
884 * individual time slot at the lowest level. The requirement from
885 * pulling the bus state down to reading the state is 15us, something
886 * that isn't realistic on the USB bus anyway.
811 dev->master.read_bit = &ds9490r_read_bit; 887 dev->master.read_bit = &ds9490r_read_bit;
812 dev->master.write_bit = &ds9490r_write_bit; 888 dev->master.write_bit = &ds9490r_write_bit;
889 */
813 dev->master.read_byte = &ds9490r_read_byte; 890 dev->master.read_byte = &ds9490r_read_byte;
814 dev->master.write_byte = &ds9490r_write_byte; 891 dev->master.write_byte = &ds9490r_write_byte;
815 dev->master.read_block = &ds9490r_read_block; 892 dev->master.read_block = &ds9490r_read_block;
816 dev->master.write_block = &ds9490r_write_block; 893 dev->master.write_block = &ds9490r_write_block;
817 dev->master.reset_bus = &ds9490r_reset; 894 dev->master.reset_bus = &ds9490r_reset;
895 dev->master.set_pullup = &ds9490r_set_pullup;
818 896
819 return w1_add_master_device(&dev->master); 897 return w1_add_master_device(&dev->master);
820} 898}
@@ -838,6 +916,8 @@ static int ds_probe(struct usb_interface *intf,
838 printk(KERN_INFO "Failed to allocate new DS9490R structure.\n"); 916 printk(KERN_INFO "Failed to allocate new DS9490R structure.\n");
839 return -ENOMEM; 917 return -ENOMEM;
840 } 918 }
919 dev->spu_sleep = 0;
920 dev->spu_bit = 0;
841 dev->udev = usb_get_dev(udev); 921 dev->udev = usb_get_dev(udev);
842 if (!dev->udev) { 922 if (!dev->udev) {
843 err = -ENOMEM; 923 err = -ENOMEM;
diff --git a/drivers/w1/slaves/w1_ds2431.c b/drivers/w1/slaves/w1_ds2431.c
new file mode 100644
index 000000000000..2c6c0cf6a20f
--- /dev/null
+++ b/drivers/w1/slaves/w1_ds2431.c
@@ -0,0 +1,312 @@
1/*
2 * w1_ds2431.c - w1 family 2d (DS2431) driver
3 *
4 * Copyright (c) 2008 Bernhard Weirich <bernhard.weirich@riedel.net>
5 *
6 * Heavily inspired by w1_DS2433 driver from Ben Gardner <bgardner@wabtec.com>
7 *
8 * This source code is licensed under the GNU General Public License,
9 * Version 2. See the file COPYING for more details.
10 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/moduleparam.h>
15#include <linux/device.h>
16#include <linux/types.h>
17#include <linux/delay.h>
18
19#include "../w1.h"
20#include "../w1_int.h"
21#include "../w1_family.h"
22
23#define W1_F2D_EEPROM_SIZE 128
24#define W1_F2D_PAGE_COUNT 4
25#define W1_F2D_PAGE_BITS 5
26#define W1_F2D_PAGE_SIZE (1<<W1_F2D_PAGE_BITS)
27#define W1_F2D_PAGE_MASK 0x1F
28
29#define W1_F2D_SCRATCH_BITS 3
30#define W1_F2D_SCRATCH_SIZE (1<<W1_F2D_SCRATCH_BITS)
31#define W1_F2D_SCRATCH_MASK (W1_F2D_SCRATCH_SIZE-1)
32
33#define W1_F2D_READ_EEPROM 0xF0
34#define W1_F2D_WRITE_SCRATCH 0x0F
35#define W1_F2D_READ_SCRATCH 0xAA
36#define W1_F2D_COPY_SCRATCH 0x55
37
38
39#define W1_F2D_TPROG_MS 11
40
41#define W1_F2D_READ_RETRIES 10
42#define W1_F2D_READ_MAXLEN 8
43
44/*
45 * Check the file size bounds and adjusts count as needed.
46 * This would not be needed if the file size didn't reset to 0 after a write.
47 */
48static inline size_t w1_f2d_fix_count(loff_t off, size_t count, size_t size)
49{
50 if (off > size)
51 return 0;
52
53 if ((off + count) > size)
54 return size - off;
55
56 return count;
57}
58
59/*
60 * Read a block from W1 ROM two times and compares the results.
61 * If they are equal they are returned, otherwise the read
62 * is repeated W1_F2D_READ_RETRIES times.
63 *
64 * count must not exceed W1_F2D_READ_MAXLEN.
65 */
66static int w1_f2d_readblock(struct w1_slave *sl, int off, int count, char *buf)
67{
68 u8 wrbuf[3];
69 u8 cmp[W1_F2D_READ_MAXLEN];
70 int tries = W1_F2D_READ_RETRIES;
71
72 do {
73 wrbuf[0] = W1_F2D_READ_EEPROM;
74 wrbuf[1] = off & 0xff;
75 wrbuf[2] = off >> 8;
76
77 if (w1_reset_select_slave(sl))
78 return -1;
79
80 w1_write_block(sl->master, wrbuf, 3);
81 w1_read_block(sl->master, buf, count);
82
83 if (w1_reset_select_slave(sl))
84 return -1;
85
86 w1_write_block(sl->master, wrbuf, 3);
87 w1_read_block(sl->master, cmp, count);
88
89 if (!memcmp(cmp, buf, count))
90 return 0;
91 } while (--tries);
92
93 dev_err(&sl->dev, "proof reading failed %d times\n",
94 W1_F2D_READ_RETRIES);
95
96 return -1;
97}
98
99static ssize_t w1_f2d_read_bin(struct kobject *kobj,
100 struct bin_attribute *bin_attr,
101 char *buf, loff_t off, size_t count)
102{
103 struct w1_slave *sl = kobj_to_w1_slave(kobj);
104 int todo = count;
105
106 count = w1_f2d_fix_count(off, count, W1_F2D_EEPROM_SIZE);
107 if (count == 0)
108 return 0;
109
110 mutex_lock(&sl->master->mutex);
111
112 /* read directly from the EEPROM in chunks of W1_F2D_READ_MAXLEN */
113 while (todo > 0) {
114 int block_read;
115
116 if (todo >= W1_F2D_READ_MAXLEN)
117 block_read = W1_F2D_READ_MAXLEN;
118 else
119 block_read = todo;
120
121 if (w1_f2d_readblock(sl, off, block_read, buf) < 0)
122 count = -EIO;
123
124 todo -= W1_F2D_READ_MAXLEN;
125 buf += W1_F2D_READ_MAXLEN;
126 off += W1_F2D_READ_MAXLEN;
127 }
128
129 mutex_unlock(&sl->master->mutex);
130
131 return count;
132}
133
134/*
135 * Writes to the scratchpad and reads it back for verification.
136 * Then copies the scratchpad to EEPROM.
137 * The data must be aligned at W1_F2D_SCRATCH_SIZE bytes and
138 * must be W1_F2D_SCRATCH_SIZE bytes long.
139 * The master must be locked.
140 *
141 * @param sl The slave structure
142 * @param addr Address for the write
143 * @param len length must be <= (W1_F2D_PAGE_SIZE - (addr & W1_F2D_PAGE_MASK))
144 * @param data The data to write
145 * @return 0=Success -1=failure
146 */
147static int w1_f2d_write(struct w1_slave *sl, int addr, int len, const u8 *data)
148{
149 int tries = W1_F2D_READ_RETRIES;
150 u8 wrbuf[4];
151 u8 rdbuf[W1_F2D_SCRATCH_SIZE + 3];
152 u8 es = (addr + len - 1) % W1_F2D_SCRATCH_SIZE;
153
154retry:
155
156 /* Write the data to the scratchpad */
157 if (w1_reset_select_slave(sl))
158 return -1;
159
160 wrbuf[0] = W1_F2D_WRITE_SCRATCH;
161 wrbuf[1] = addr & 0xff;
162 wrbuf[2] = addr >> 8;
163
164 w1_write_block(sl->master, wrbuf, 3);
165 w1_write_block(sl->master, data, len);
166
167 /* Read the scratchpad and verify */
168 if (w1_reset_select_slave(sl))
169 return -1;
170
171 w1_write_8(sl->master, W1_F2D_READ_SCRATCH);
172 w1_read_block(sl->master, rdbuf, len + 3);
173
174 /* Compare what was read against the data written */
175 if ((rdbuf[0] != wrbuf[1]) || (rdbuf[1] != wrbuf[2]) ||
176 (rdbuf[2] != es) || (memcmp(data, &rdbuf[3], len) != 0)) {
177
178 if (--tries)
179 goto retry;
180
181 dev_err(&sl->dev,
182 "could not write to eeprom, scratchpad compare failed %d times\n",
183 W1_F2D_READ_RETRIES);
184
185 return -1;
186 }
187
188 /* Copy the scratchpad to EEPROM */
189 if (w1_reset_select_slave(sl))
190 return -1;
191
192 wrbuf[0] = W1_F2D_COPY_SCRATCH;
193 wrbuf[3] = es;
194 w1_write_block(sl->master, wrbuf, 4);
195
196 /* Sleep for tprog ms to wait for the write to complete */
197 msleep(W1_F2D_TPROG_MS);
198
199 /* Reset the bus to wake up the EEPROM */
200 w1_reset_bus(sl->master);
201
202 return 0;
203}
204
205static ssize_t w1_f2d_write_bin(struct kobject *kobj,
206 struct bin_attribute *bin_attr,
207 char *buf, loff_t off, size_t count)
208{
209 struct w1_slave *sl = kobj_to_w1_slave(kobj);
210 int addr, len;
211 int copy;
212
213 count = w1_f2d_fix_count(off, count, W1_F2D_EEPROM_SIZE);
214 if (count == 0)
215 return 0;
216
217 mutex_lock(&sl->master->mutex);
218
219 /* Can only write data in blocks of the size of the scratchpad */
220 addr = off;
221 len = count;
222 while (len > 0) {
223
224 /* if len too short or addr not aligned */
225 if (len < W1_F2D_SCRATCH_SIZE || addr & W1_F2D_SCRATCH_MASK) {
226 char tmp[W1_F2D_SCRATCH_SIZE];
227
228 /* read the block and update the parts to be written */
229 if (w1_f2d_readblock(sl, addr & ~W1_F2D_SCRATCH_MASK,
230 W1_F2D_SCRATCH_SIZE, tmp)) {
231 count = -EIO;
232 goto out_up;
233 }
234
235 /* copy at most to the boundary of the PAGE or len */
236 copy = W1_F2D_SCRATCH_SIZE -
237 (addr & W1_F2D_SCRATCH_MASK);
238
239 if (copy > len)
240 copy = len;
241
242 memcpy(&tmp[addr & W1_F2D_SCRATCH_MASK], buf, copy);
243 if (w1_f2d_write(sl, addr & ~W1_F2D_SCRATCH_MASK,
244 W1_F2D_SCRATCH_SIZE, tmp) < 0) {
245 count = -EIO;
246 goto out_up;
247 }
248 } else {
249
250 copy = W1_F2D_SCRATCH_SIZE;
251 if (w1_f2d_write(sl, addr, copy, buf) < 0) {
252 count = -EIO;
253 goto out_up;
254 }
255 }
256 buf += copy;
257 addr += copy;
258 len -= copy;
259 }
260
261out_up:
262 mutex_unlock(&sl->master->mutex);
263
264 return count;
265}
266
267static struct bin_attribute w1_f2d_bin_attr = {
268 .attr = {
269 .name = "eeprom",
270 .mode = S_IRUGO | S_IWUSR,
271 },
272 .size = W1_F2D_EEPROM_SIZE,
273 .read = w1_f2d_read_bin,
274 .write = w1_f2d_write_bin,
275};
276
277static int w1_f2d_add_slave(struct w1_slave *sl)
278{
279 return sysfs_create_bin_file(&sl->dev.kobj, &w1_f2d_bin_attr);
280}
281
282static void w1_f2d_remove_slave(struct w1_slave *sl)
283{
284 sysfs_remove_bin_file(&sl->dev.kobj, &w1_f2d_bin_attr);
285}
286
287static struct w1_family_ops w1_f2d_fops = {
288 .add_slave = w1_f2d_add_slave,
289 .remove_slave = w1_f2d_remove_slave,
290};
291
292static struct w1_family w1_family_2d = {
293 .fid = W1_EEPROM_DS2431,
294 .fops = &w1_f2d_fops,
295};
296
297static int __init w1_f2d_init(void)
298{
299 return w1_register_family(&w1_family_2d);
300}
301
302static void __exit w1_f2d_fini(void)
303{
304 w1_unregister_family(&w1_family_2d);
305}
306
307module_init(w1_f2d_init);
308module_exit(w1_f2d_fini);
309
310MODULE_LICENSE("GPL");
311MODULE_AUTHOR("Bernhard Weirich <bernhard.weirich@riedel.net>");
312MODULE_DESCRIPTION("w1 family 2d driver for DS2431, 1kb EEPROM");
diff --git a/drivers/w1/slaves/w1_therm.c b/drivers/w1/slaves/w1_therm.c
index fb28acaeed6c..2c8dff9f77da 100644
--- a/drivers/w1/slaves/w1_therm.c
+++ b/drivers/w1/slaves/w1_therm.c
@@ -37,31 +37,33 @@ MODULE_LICENSE("GPL");
37MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>"); 37MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
38MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol, temperature family."); 38MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol, temperature family.");
39 39
40/* Allow the strong pullup to be disabled, but default to enabled.
41 * If it was disabled a parasite powered device might not get the require
42 * current to do a temperature conversion. If it is enabled parasite powered
43 * devices have a better chance of getting the current required.
44 */
45static int w1_strong_pullup = 1;
46module_param_named(strong_pullup, w1_strong_pullup, int, 0);
47
40static u8 bad_roms[][9] = { 48static u8 bad_roms[][9] = {
41 {0xaa, 0x00, 0x4b, 0x46, 0xff, 0xff, 0x0c, 0x10, 0x87}, 49 {0xaa, 0x00, 0x4b, 0x46, 0xff, 0xff, 0x0c, 0x10, 0x87},
42 {} 50 {}
43 }; 51 };
44 52
45static ssize_t w1_therm_read_bin(struct kobject *, struct bin_attribute *, 53static ssize_t w1_therm_read(struct device *device,
46 char *, loff_t, size_t); 54 struct device_attribute *attr, char *buf);
47 55
48static struct bin_attribute w1_therm_bin_attr = { 56static struct device_attribute w1_therm_attr =
49 .attr = { 57 __ATTR(w1_slave, S_IRUGO, w1_therm_read, NULL);
50 .name = "w1_slave",
51 .mode = S_IRUGO,
52 },
53 .size = W1_SLAVE_DATA_SIZE,
54 .read = w1_therm_read_bin,
55};
56 58
57static int w1_therm_add_slave(struct w1_slave *sl) 59static int w1_therm_add_slave(struct w1_slave *sl)
58{ 60{
59 return sysfs_create_bin_file(&sl->dev.kobj, &w1_therm_bin_attr); 61 return device_create_file(&sl->dev, &w1_therm_attr);
60} 62}
61 63
62static void w1_therm_remove_slave(struct w1_slave *sl) 64static void w1_therm_remove_slave(struct w1_slave *sl)
63{ 65{
64 sysfs_remove_bin_file(&sl->dev.kobj, &w1_therm_bin_attr); 66 device_remove_file(&sl->dev, &w1_therm_attr);
65} 67}
66 68
67static struct w1_family_ops w1_therm_fops = { 69static struct w1_family_ops w1_therm_fops = {
@@ -160,30 +162,19 @@ static int w1_therm_check_rom(u8 rom[9])
160 return 0; 162 return 0;
161} 163}
162 164
163static ssize_t w1_therm_read_bin(struct kobject *kobj, 165static ssize_t w1_therm_read(struct device *device,
164 struct bin_attribute *bin_attr, 166 struct device_attribute *attr, char *buf)
165 char *buf, loff_t off, size_t count)
166{ 167{
167 struct w1_slave *sl = kobj_to_w1_slave(kobj); 168 struct w1_slave *sl = dev_to_w1_slave(device);
168 struct w1_master *dev = sl->master; 169 struct w1_master *dev = sl->master;
169 u8 rom[9], crc, verdict; 170 u8 rom[9], crc, verdict;
170 int i, max_trying = 10; 171 int i, max_trying = 10;
172 ssize_t c = PAGE_SIZE;
171 173
172 mutex_lock(&sl->master->mutex); 174 mutex_lock(&dev->mutex);
173 175
174 if (off > W1_SLAVE_DATA_SIZE) {
175 count = 0;
176 goto out;
177 }
178 if (off + count > W1_SLAVE_DATA_SIZE) {
179 count = 0;
180 goto out;
181 }
182
183 memset(buf, 0, count);
184 memset(rom, 0, sizeof(rom)); 176 memset(rom, 0, sizeof(rom));
185 177
186 count = 0;
187 verdict = 0; 178 verdict = 0;
188 crc = 0; 179 crc = 0;
189 180
@@ -192,15 +183,20 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj,
192 int count = 0; 183 int count = 0;
193 unsigned int tm = 750; 184 unsigned int tm = 750;
194 185
186 /* 750ms strong pullup (or delay) after the convert */
187 if (w1_strong_pullup)
188 w1_next_pullup(dev, tm);
195 w1_write_8(dev, W1_CONVERT_TEMP); 189 w1_write_8(dev, W1_CONVERT_TEMP);
196 190 if (!w1_strong_pullup)
197 msleep(tm); 191 msleep(tm);
198 192
199 if (!w1_reset_select_slave(sl)) { 193 if (!w1_reset_select_slave(sl)) {
200 194
201 w1_write_8(dev, W1_READ_SCRATCHPAD); 195 w1_write_8(dev, W1_READ_SCRATCHPAD);
202 if ((count = w1_read_block(dev, rom, 9)) != 9) { 196 if ((count = w1_read_block(dev, rom, 9)) != 9) {
203 dev_warn(&dev->dev, "w1_read_block() returned %d instead of 9.\n", count); 197 dev_warn(device, "w1_read_block() "
198 "returned %u instead of 9.\n",
199 count);
204 } 200 }
205 201
206 crc = w1_calc_crc8(rom, 8); 202 crc = w1_calc_crc8(rom, 8);
@@ -215,22 +211,22 @@ static ssize_t w1_therm_read_bin(struct kobject *kobj,
215 } 211 }
216 212
217 for (i = 0; i < 9; ++i) 213 for (i = 0; i < 9; ++i)
218 count += sprintf(buf + count, "%02x ", rom[i]); 214 c -= snprintf(buf + PAGE_SIZE - c, c, "%02x ", rom[i]);
219 count += sprintf(buf + count, ": crc=%02x %s\n", 215 c -= snprintf(buf + PAGE_SIZE - c, c, ": crc=%02x %s\n",
220 crc, (verdict) ? "YES" : "NO"); 216 crc, (verdict) ? "YES" : "NO");
221 if (verdict) 217 if (verdict)
222 memcpy(sl->rom, rom, sizeof(sl->rom)); 218 memcpy(sl->rom, rom, sizeof(sl->rom));
223 else 219 else
224 dev_warn(&dev->dev, "18S20 doesn't respond to CONVERT_TEMP.\n"); 220 dev_warn(device, "18S20 doesn't respond to CONVERT_TEMP.\n");
225 221
226 for (i = 0; i < 9; ++i) 222 for (i = 0; i < 9; ++i)
227 count += sprintf(buf + count, "%02x ", sl->rom[i]); 223 c -= snprintf(buf + PAGE_SIZE - c, c, "%02x ", sl->rom[i]);
228 224
229 count += sprintf(buf + count, "t=%d\n", w1_convert_temp(rom, sl->family->fid)); 225 c -= snprintf(buf + PAGE_SIZE - c, c, "t=%d\n",
230out: 226 w1_convert_temp(rom, sl->family->fid));
231 mutex_unlock(&dev->mutex); 227 mutex_unlock(&dev->mutex);
232 228
233 return count; 229 return PAGE_SIZE - c;
234} 230}
235 231
236static int __init w1_therm_init(void) 232static int __init w1_therm_init(void)
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 7293c9b11f91..3b615d4022ee 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -46,19 +46,17 @@ MODULE_AUTHOR("Evgeniy Polyakov <johnpol@2ka.mipt.ru>");
46MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol."); 46MODULE_DESCRIPTION("Driver for 1-wire Dallas network protocol.");
47 47
48static int w1_timeout = 10; 48static int w1_timeout = 10;
49static int w1_control_timeout = 1;
50int w1_max_slave_count = 10; 49int w1_max_slave_count = 10;
51int w1_max_slave_ttl = 10; 50int w1_max_slave_ttl = 10;
52 51
53module_param_named(timeout, w1_timeout, int, 0); 52module_param_named(timeout, w1_timeout, int, 0);
54module_param_named(control_timeout, w1_control_timeout, int, 0);
55module_param_named(max_slave_count, w1_max_slave_count, int, 0); 53module_param_named(max_slave_count, w1_max_slave_count, int, 0);
56module_param_named(slave_ttl, w1_max_slave_ttl, int, 0); 54module_param_named(slave_ttl, w1_max_slave_ttl, int, 0);
57 55
58DEFINE_MUTEX(w1_mlock); 56DEFINE_MUTEX(w1_mlock);
59LIST_HEAD(w1_masters); 57LIST_HEAD(w1_masters);
60 58
61static struct task_struct *w1_control_thread; 59static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn);
62 60
63static int w1_master_match(struct device *dev, struct device_driver *drv) 61static int w1_master_match(struct device *dev, struct device_driver *drv)
64{ 62{
@@ -83,10 +81,10 @@ static void w1_slave_release(struct device *dev)
83{ 81{
84 struct w1_slave *sl = dev_to_w1_slave(dev); 82 struct w1_slave *sl = dev_to_w1_slave(dev);
85 83
86 printk("%s: Releasing %s.\n", __func__, sl->name); 84 dev_dbg(dev, "%s: Releasing %s.\n", __func__, sl->name);
87 85
88 while (atomic_read(&sl->refcnt)) { 86 while (atomic_read(&sl->refcnt)) {
89 printk("Waiting for %s to become free: refcnt=%d.\n", 87 dev_dbg(dev, "Waiting for %s to become free: refcnt=%d.\n",
90 sl->name, atomic_read(&sl->refcnt)); 88 sl->name, atomic_read(&sl->refcnt));
91 if (msleep_interruptible(1000)) 89 if (msleep_interruptible(1000))
92 flush_signals(current); 90 flush_signals(current);
@@ -105,35 +103,20 @@ static ssize_t w1_slave_read_name(struct device *dev, struct device_attribute *a
105 return sprintf(buf, "%s\n", sl->name); 103 return sprintf(buf, "%s\n", sl->name);
106} 104}
107 105
108static ssize_t w1_slave_read_id(struct kobject *kobj, 106static ssize_t w1_slave_read_id(struct device *dev,
109 struct bin_attribute *bin_attr, 107 struct device_attribute *attr, char *buf)
110 char *buf, loff_t off, size_t count)
111{ 108{
112 struct w1_slave *sl = kobj_to_w1_slave(kobj); 109 struct w1_slave *sl = dev_to_w1_slave(dev);
113 110 ssize_t count = sizeof(sl->reg_num);
114 if (off > 8) {
115 count = 0;
116 } else {
117 if (off + count > 8)
118 count = 8 - off;
119
120 memcpy(buf, (u8 *)&sl->reg_num, count);
121 }
122 111
112 memcpy(buf, (u8 *)&sl->reg_num, count);
123 return count; 113 return count;
124} 114}
125 115
126static struct device_attribute w1_slave_attr_name = 116static struct device_attribute w1_slave_attr_name =
127 __ATTR(name, S_IRUGO, w1_slave_read_name, NULL); 117 __ATTR(name, S_IRUGO, w1_slave_read_name, NULL);
128 118static struct device_attribute w1_slave_attr_id =
129static struct bin_attribute w1_slave_attr_bin_id = { 119 __ATTR(id, S_IRUGO, w1_slave_read_id, NULL);
130 .attr = {
131 .name = "id",
132 .mode = S_IRUGO,
133 },
134 .size = 8,
135 .read = w1_slave_read_id,
136};
137 120
138/* Default family */ 121/* Default family */
139 122
@@ -250,11 +233,16 @@ static ssize_t w1_master_attribute_store_search(struct device * dev,
250 struct device_attribute *attr, 233 struct device_attribute *attr,
251 const char * buf, size_t count) 234 const char * buf, size_t count)
252{ 235{
236 long tmp;
253 struct w1_master *md = dev_to_w1_master(dev); 237 struct w1_master *md = dev_to_w1_master(dev);
254 238
239 if (strict_strtol(buf, 0, &tmp) == -EINVAL)
240 return -EINVAL;
241
255 mutex_lock(&md->mutex); 242 mutex_lock(&md->mutex);
256 md->search_count = simple_strtol(buf, NULL, 0); 243 md->search_count = tmp;
257 mutex_unlock(&md->mutex); 244 mutex_unlock(&md->mutex);
245 wake_up_process(md->thread);
258 246
259 return count; 247 return count;
260} 248}
@@ -273,6 +261,38 @@ static ssize_t w1_master_attribute_show_search(struct device *dev,
273 return count; 261 return count;
274} 262}
275 263
264static ssize_t w1_master_attribute_store_pullup(struct device *dev,
265 struct device_attribute *attr,
266 const char *buf, size_t count)
267{
268 long tmp;
269 struct w1_master *md = dev_to_w1_master(dev);
270
271 if (strict_strtol(buf, 0, &tmp) == -EINVAL)
272 return -EINVAL;
273
274 mutex_lock(&md->mutex);
275 md->enable_pullup = tmp;
276 mutex_unlock(&md->mutex);
277 wake_up_process(md->thread);
278
279 return count;
280}
281
282static ssize_t w1_master_attribute_show_pullup(struct device *dev,
283 struct device_attribute *attr,
284 char *buf)
285{
286 struct w1_master *md = dev_to_w1_master(dev);
287 ssize_t count;
288
289 mutex_lock(&md->mutex);
290 count = sprintf(buf, "%d\n", md->enable_pullup);
291 mutex_unlock(&md->mutex);
292
293 return count;
294}
295
276static ssize_t w1_master_attribute_show_pointer(struct device *dev, struct device_attribute *attr, char *buf) 296static ssize_t w1_master_attribute_show_pointer(struct device *dev, struct device_attribute *attr, char *buf)
277{ 297{
278 struct w1_master *md = dev_to_w1_master(dev); 298 struct w1_master *md = dev_to_w1_master(dev);
@@ -324,7 +344,8 @@ static ssize_t w1_master_attribute_show_slave_count(struct device *dev, struct d
324 return count; 344 return count;
325} 345}
326 346
327static ssize_t w1_master_attribute_show_slaves(struct device *dev, struct device_attribute *attr, char *buf) 347static ssize_t w1_master_attribute_show_slaves(struct device *dev,
348 struct device_attribute *attr, char *buf)
328{ 349{
329 struct w1_master *md = dev_to_w1_master(dev); 350 struct w1_master *md = dev_to_w1_master(dev);
330 int c = PAGE_SIZE; 351 int c = PAGE_SIZE;
@@ -349,6 +370,135 @@ static ssize_t w1_master_attribute_show_slaves(struct device *dev, struct device
349 return PAGE_SIZE - c; 370 return PAGE_SIZE - c;
350} 371}
351 372
373static ssize_t w1_master_attribute_show_add(struct device *dev,
374 struct device_attribute *attr, char *buf)
375{
376 int c = PAGE_SIZE;
377 c -= snprintf(buf+PAGE_SIZE - c, c,
378 "write device id xx-xxxxxxxxxxxx to add slave\n");
379 return PAGE_SIZE - c;
380}
381
382static int w1_atoreg_num(struct device *dev, const char *buf, size_t count,
383 struct w1_reg_num *rn)
384{
385 unsigned int family;
386 unsigned long long id;
387 int i;
388 u64 rn64_le;
389
390 /* The CRC value isn't read from the user because the sysfs directory
391 * doesn't include it and most messages from the bus search don't
392 * print it either. It would be unreasonable for the user to then
393 * provide it.
394 */
395 const char *error_msg = "bad slave string format, expecting "
396 "ff-dddddddddddd\n";
397
398 if (buf[2] != '-') {
399 dev_err(dev, "%s", error_msg);
400 return -EINVAL;
401 }
402 i = sscanf(buf, "%02x-%012llx", &family, &id);
403 if (i != 2) {
404 dev_err(dev, "%s", error_msg);
405 return -EINVAL;
406 }
407 rn->family = family;
408 rn->id = id;
409
410 rn64_le = cpu_to_le64(*(u64 *)rn);
411 rn->crc = w1_calc_crc8((u8 *)&rn64_le, 7);
412
413#if 0
414 dev_info(dev, "With CRC device is %02x.%012llx.%02x.\n",
415 rn->family, (unsigned long long)rn->id, rn->crc);
416#endif
417
418 return 0;
419}
420
421/* Searches the slaves in the w1_master and returns a pointer or NULL.
422 * Note: must hold the mutex
423 */
424static struct w1_slave *w1_slave_search_device(struct w1_master *dev,
425 struct w1_reg_num *rn)
426{
427 struct w1_slave *sl;
428 list_for_each_entry(sl, &dev->slist, w1_slave_entry) {
429 if (sl->reg_num.family == rn->family &&
430 sl->reg_num.id == rn->id &&
431 sl->reg_num.crc == rn->crc) {
432 return sl;
433 }
434 }
435 return NULL;
436}
437
438static ssize_t w1_master_attribute_store_add(struct device *dev,
439 struct device_attribute *attr,
440 const char *buf, size_t count)
441{
442 struct w1_master *md = dev_to_w1_master(dev);
443 struct w1_reg_num rn;
444 struct w1_slave *sl;
445 ssize_t result = count;
446
447 if (w1_atoreg_num(dev, buf, count, &rn))
448 return -EINVAL;
449
450 mutex_lock(&md->mutex);
451 sl = w1_slave_search_device(md, &rn);
452 /* It would be nice to do a targeted search one the one-wire bus
453 * for the new device to see if it is out there or not. But the
454 * current search doesn't support that.
455 */
456 if (sl) {
457 dev_info(dev, "Device %s already exists\n", sl->name);
458 result = -EINVAL;
459 } else {
460 w1_attach_slave_device(md, &rn);
461 }
462 mutex_unlock(&md->mutex);
463
464 return result;
465}
466
467static ssize_t w1_master_attribute_show_remove(struct device *dev,
468 struct device_attribute *attr, char *buf)
469{
470 int c = PAGE_SIZE;
471 c -= snprintf(buf+PAGE_SIZE - c, c,
472 "write device id xx-xxxxxxxxxxxx to remove slave\n");
473 return PAGE_SIZE - c;
474}
475
476static ssize_t w1_master_attribute_store_remove(struct device *dev,
477 struct device_attribute *attr,
478 const char *buf, size_t count)
479{
480 struct w1_master *md = dev_to_w1_master(dev);
481 struct w1_reg_num rn;
482 struct w1_slave *sl;
483 ssize_t result = count;
484
485 if (w1_atoreg_num(dev, buf, count, &rn))
486 return -EINVAL;
487
488 mutex_lock(&md->mutex);
489 sl = w1_slave_search_device(md, &rn);
490 if (sl) {
491 w1_slave_detach(sl);
492 } else {
493 dev_info(dev, "Device %02x-%012llx doesn't exists\n", rn.family,
494 (unsigned long long)rn.id);
495 result = -EINVAL;
496 }
497 mutex_unlock(&md->mutex);
498
499 return result;
500}
501
352#define W1_MASTER_ATTR_RO(_name, _mode) \ 502#define W1_MASTER_ATTR_RO(_name, _mode) \
353 struct device_attribute w1_master_attribute_##_name = \ 503 struct device_attribute w1_master_attribute_##_name = \
354 __ATTR(w1_master_##_name, _mode, \ 504 __ATTR(w1_master_##_name, _mode, \
@@ -368,6 +518,9 @@ static W1_MASTER_ATTR_RO(attempts, S_IRUGO);
368static W1_MASTER_ATTR_RO(timeout, S_IRUGO); 518static W1_MASTER_ATTR_RO(timeout, S_IRUGO);
369static W1_MASTER_ATTR_RO(pointer, S_IRUGO); 519static W1_MASTER_ATTR_RO(pointer, S_IRUGO);
370static W1_MASTER_ATTR_RW(search, S_IRUGO | S_IWUGO); 520static W1_MASTER_ATTR_RW(search, S_IRUGO | S_IWUGO);
521static W1_MASTER_ATTR_RW(pullup, S_IRUGO | S_IWUGO);
522static W1_MASTER_ATTR_RW(add, S_IRUGO | S_IWUGO);
523static W1_MASTER_ATTR_RW(remove, S_IRUGO | S_IWUGO);
371 524
372static struct attribute *w1_master_default_attrs[] = { 525static struct attribute *w1_master_default_attrs[] = {
373 &w1_master_attribute_name.attr, 526 &w1_master_attribute_name.attr,
@@ -378,6 +531,9 @@ static struct attribute *w1_master_default_attrs[] = {
378 &w1_master_attribute_timeout.attr, 531 &w1_master_attribute_timeout.attr,
379 &w1_master_attribute_pointer.attr, 532 &w1_master_attribute_pointer.attr,
380 &w1_master_attribute_search.attr, 533 &w1_master_attribute_search.attr,
534 &w1_master_attribute_pullup.attr,
535 &w1_master_attribute_add.attr,
536 &w1_master_attribute_remove.attr,
381 NULL 537 NULL
382}; 538};
383 539
@@ -390,7 +546,7 @@ int w1_create_master_attributes(struct w1_master *master)
390 return sysfs_create_group(&master->dev.kobj, &w1_master_defattr_group); 546 return sysfs_create_group(&master->dev.kobj, &w1_master_defattr_group);
391} 547}
392 548
393static void w1_destroy_master_attributes(struct w1_master *master) 549void w1_destroy_master_attributes(struct w1_master *master)
394{ 550{
395 sysfs_remove_group(&master->dev.kobj, &w1_master_defattr_group); 551 sysfs_remove_group(&master->dev.kobj, &w1_master_defattr_group);
396} 552}
@@ -479,7 +635,7 @@ static int __w1_attach_slave_device(struct w1_slave *sl)
479 } 635 }
480 636
481 /* Create "id" entry */ 637 /* Create "id" entry */
482 err = sysfs_create_bin_file(&sl->dev.kobj, &w1_slave_attr_bin_id); 638 err = device_create_file(&sl->dev, &w1_slave_attr_id);
483 if (err < 0) { 639 if (err < 0) {
484 dev_err(&sl->dev, 640 dev_err(&sl->dev,
485 "sysfs file creation for [%s] failed. err=%d\n", 641 "sysfs file creation for [%s] failed. err=%d\n",
@@ -501,7 +657,7 @@ static int __w1_attach_slave_device(struct w1_slave *sl)
501 return 0; 657 return 0;
502 658
503out_rem2: 659out_rem2:
504 sysfs_remove_bin_file(&sl->dev.kobj, &w1_slave_attr_bin_id); 660 device_remove_file(&sl->dev, &w1_slave_attr_id);
505out_rem1: 661out_rem1:
506 device_remove_file(&sl->dev, &w1_slave_attr_name); 662 device_remove_file(&sl->dev, &w1_slave_attr_name);
507out_unreg: 663out_unreg:
@@ -567,7 +723,7 @@ static int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn)
567 return 0; 723 return 0;
568} 724}
569 725
570static void w1_slave_detach(struct w1_slave *sl) 726void w1_slave_detach(struct w1_slave *sl)
571{ 727{
572 struct w1_netlink_msg msg; 728 struct w1_netlink_msg msg;
573 729
@@ -583,7 +739,7 @@ static void w1_slave_detach(struct w1_slave *sl)
583 msg.type = W1_SLAVE_REMOVE; 739 msg.type = W1_SLAVE_REMOVE;
584 w1_netlink_send(sl->master, &msg); 740 w1_netlink_send(sl->master, &msg);
585 741
586 sysfs_remove_bin_file(&sl->dev.kobj, &w1_slave_attr_bin_id); 742 device_remove_file(&sl->dev, &w1_slave_attr_id);
587 device_remove_file(&sl->dev, &w1_slave_attr_name); 743 device_remove_file(&sl->dev, &w1_slave_attr_name);
588 device_unregister(&sl->dev); 744 device_unregister(&sl->dev);
589 745
@@ -591,24 +747,6 @@ static void w1_slave_detach(struct w1_slave *sl)
591 kfree(sl); 747 kfree(sl);
592} 748}
593 749
594static struct w1_master *w1_search_master(void *data)
595{
596 struct w1_master *dev;
597 int found = 0;
598
599 mutex_lock(&w1_mlock);
600 list_for_each_entry(dev, &w1_masters, w1_master_entry) {
601 if (dev->bus_master->data == data) {
602 found = 1;
603 atomic_inc(&dev->refcnt);
604 break;
605 }
606 }
607 mutex_unlock(&w1_mlock);
608
609 return (found)?dev:NULL;
610}
611
612struct w1_master *w1_search_master_id(u32 id) 750struct w1_master *w1_search_master_id(u32 id)
613{ 751{
614 struct w1_master *dev; 752 struct w1_master *dev;
@@ -656,55 +794,56 @@ struct w1_slave *w1_search_slave(struct w1_reg_num *id)
656 return (found)?sl:NULL; 794 return (found)?sl:NULL;
657} 795}
658 796
659void w1_reconnect_slaves(struct w1_family *f) 797void w1_reconnect_slaves(struct w1_family *f, int attach)
660{ 798{
799 struct w1_slave *sl, *sln;
661 struct w1_master *dev; 800 struct w1_master *dev;
662 801
663 mutex_lock(&w1_mlock); 802 mutex_lock(&w1_mlock);
664 list_for_each_entry(dev, &w1_masters, w1_master_entry) { 803 list_for_each_entry(dev, &w1_masters, w1_master_entry) {
665 dev_dbg(&dev->dev, "Reconnecting slaves in %s into new family %02x.\n", 804 dev_dbg(&dev->dev, "Reconnecting slaves in device %s "
666 dev->name, f->fid); 805 "for family %02x.\n", dev->name, f->fid);
667 set_bit(W1_MASTER_NEED_RECONNECT, &dev->flags); 806 mutex_lock(&dev->mutex);
807 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) {
808 /* If it is a new family, slaves with the default
809 * family driver and are that family will be
810 * connected. If the family is going away, devices
811 * matching that family are reconneced.
812 */
813 if ((attach && sl->family->fid == W1_FAMILY_DEFAULT
814 && sl->reg_num.family == f->fid) ||
815 (!attach && sl->family->fid == f->fid)) {
816 struct w1_reg_num rn;
817
818 memcpy(&rn, &sl->reg_num, sizeof(rn));
819 w1_slave_detach(sl);
820
821 w1_attach_slave_device(dev, &rn);
822 }
823 }
824 dev_dbg(&dev->dev, "Reconnecting slaves in device %s "
825 "has been finished.\n", dev->name);
826 mutex_unlock(&dev->mutex);
668 } 827 }
669 mutex_unlock(&w1_mlock); 828 mutex_unlock(&w1_mlock);
670} 829}
671 830
672static void w1_slave_found(void *data, u64 rn) 831static void w1_slave_found(struct w1_master *dev, u64 rn)
673{ 832{
674 int slave_count;
675 struct w1_slave *sl; 833 struct w1_slave *sl;
676 struct list_head *ent;
677 struct w1_reg_num *tmp; 834 struct w1_reg_num *tmp;
678 struct w1_master *dev;
679 u64 rn_le = cpu_to_le64(rn); 835 u64 rn_le = cpu_to_le64(rn);
680 836
681 dev = w1_search_master(data); 837 atomic_inc(&dev->refcnt);
682 if (!dev) {
683 printk(KERN_ERR "Failed to find w1 master device for data %p, "
684 "it is impossible.\n", data);
685 return;
686 }
687 838
688 tmp = (struct w1_reg_num *) &rn; 839 tmp = (struct w1_reg_num *) &rn;
689 840
690 slave_count = 0; 841 sl = w1_slave_search_device(dev, tmp);
691 list_for_each(ent, &dev->slist) { 842 if (sl) {
692 843 set_bit(W1_SLAVE_ACTIVE, (long *)&sl->flags);
693 sl = list_entry(ent, struct w1_slave, w1_slave_entry); 844 } else {
694 845 if (rn && tmp->crc == w1_calc_crc8((u8 *)&rn_le, 7))
695 if (sl->reg_num.family == tmp->family && 846 w1_attach_slave_device(dev, tmp);
696 sl->reg_num.id == tmp->id &&
697 sl->reg_num.crc == tmp->crc) {
698 set_bit(W1_SLAVE_ACTIVE, (long *)&sl->flags);
699 break;
700 }
701
702 slave_count++;
703 }
704
705 if (slave_count == dev->slave_count &&
706 rn && ((rn >> 56) & 0xff) == w1_calc_crc8((u8 *)&rn_le, 7)) {
707 w1_attach_slave_device(dev, tmp);
708 } 847 }
709 848
710 atomic_dec(&dev->refcnt); 849 atomic_dec(&dev->refcnt);
@@ -779,80 +918,20 @@ void w1_search(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb
779 /* extract the direction taken & update the device number */ 918 /* extract the direction taken & update the device number */
780 tmp64 = (triplet_ret >> 2); 919 tmp64 = (triplet_ret >> 2);
781 rn |= (tmp64 << i); 920 rn |= (tmp64 << i);
921
922 if (kthread_should_stop()) {
923 dev_dbg(&dev->dev, "Abort w1_search\n");
924 return;
925 }
782 } 926 }
783 927
784 if ( (triplet_ret & 0x03) != 0x03 ) { 928 if ( (triplet_ret & 0x03) != 0x03 ) {
785 if ( (desc_bit == last_zero) || (last_zero < 0)) 929 if ( (desc_bit == last_zero) || (last_zero < 0))
786 last_device = 1; 930 last_device = 1;
787 desc_bit = last_zero; 931 desc_bit = last_zero;
788 cb(dev->bus_master->data, rn); 932 cb(dev, rn);
789 }
790 }
791}
792
793static int w1_control(void *data)
794{
795 struct w1_slave *sl, *sln;
796 struct w1_master *dev, *n;
797 int have_to_wait = 0;
798
799 set_freezable();
800 while (!kthread_should_stop() || have_to_wait) {
801 have_to_wait = 0;
802
803 try_to_freeze();
804 msleep_interruptible(w1_control_timeout * 1000);
805
806 list_for_each_entry_safe(dev, n, &w1_masters, w1_master_entry) {
807 if (!kthread_should_stop() && !dev->flags)
808 continue;
809 /*
810 * Little race: we can create thread but not set the flag.
811 * Get a chance for external process to set flag up.
812 */
813 if (!dev->initialized) {
814 have_to_wait = 1;
815 continue;
816 }
817
818 if (kthread_should_stop() || test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) {
819 set_bit(W1_MASTER_NEED_EXIT, &dev->flags);
820
821 mutex_lock(&w1_mlock);
822 list_del(&dev->w1_master_entry);
823 mutex_unlock(&w1_mlock);
824
825 mutex_lock(&dev->mutex);
826 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) {
827 w1_slave_detach(sl);
828 }
829 w1_destroy_master_attributes(dev);
830 mutex_unlock(&dev->mutex);
831 atomic_dec(&dev->refcnt);
832 continue;
833 }
834
835 if (test_bit(W1_MASTER_NEED_RECONNECT, &dev->flags)) {
836 dev_dbg(&dev->dev, "Reconnecting slaves in device %s.\n", dev->name);
837 mutex_lock(&dev->mutex);
838 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry) {
839 if (sl->family->fid == W1_FAMILY_DEFAULT) {
840 struct w1_reg_num rn;
841
842 memcpy(&rn, &sl->reg_num, sizeof(rn));
843 w1_slave_detach(sl);
844
845 w1_attach_slave_device(dev, &rn);
846 }
847 }
848 dev_dbg(&dev->dev, "Reconnecting slaves in device %s has been finished.\n", dev->name);
849 clear_bit(W1_MASTER_NEED_RECONNECT, &dev->flags);
850 mutex_unlock(&dev->mutex);
851 }
852 } 933 }
853 } 934 }
854
855 return 0;
856} 935}
857 936
858void w1_search_process(struct w1_master *dev, u8 search_type) 937void w1_search_process(struct w1_master *dev, u8 search_type)
@@ -878,23 +957,29 @@ void w1_search_process(struct w1_master *dev, u8 search_type)
878int w1_process(void *data) 957int w1_process(void *data)
879{ 958{
880 struct w1_master *dev = (struct w1_master *) data; 959 struct w1_master *dev = (struct w1_master *) data;
960 /* As long as w1_timeout is only set by a module parameter the sleep
961 * time can be calculated in jiffies once.
962 */
963 const unsigned long jtime = msecs_to_jiffies(w1_timeout * 1000);
964
965 while (!kthread_should_stop()) {
966 if (dev->search_count) {
967 mutex_lock(&dev->mutex);
968 w1_search_process(dev, W1_SEARCH);
969 mutex_unlock(&dev->mutex);
970 }
881 971
882 while (!kthread_should_stop() && !test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) {
883 try_to_freeze(); 972 try_to_freeze();
884 msleep_interruptible(w1_timeout * 1000); 973 __set_current_state(TASK_INTERRUPTIBLE);
885 974
886 if (kthread_should_stop() || test_bit(W1_MASTER_NEED_EXIT, &dev->flags)) 975 if (kthread_should_stop())
887 break; 976 break;
888 977
889 if (!dev->initialized) 978 /* Only sleep when the search is active. */
890 continue; 979 if (dev->search_count)
891 980 schedule_timeout(jtime);
892 if (dev->search_count == 0) 981 else
893 continue; 982 schedule();
894
895 mutex_lock(&dev->mutex);
896 w1_search_process(dev, W1_SEARCH);
897 mutex_unlock(&dev->mutex);
898 } 983 }
899 984
900 atomic_dec(&dev->refcnt); 985 atomic_dec(&dev->refcnt);
@@ -932,18 +1017,13 @@ static int w1_init(void)
932 goto err_out_master_unregister; 1017 goto err_out_master_unregister;
933 } 1018 }
934 1019
935 w1_control_thread = kthread_run(w1_control, NULL, "w1_control");
936 if (IS_ERR(w1_control_thread)) {
937 retval = PTR_ERR(w1_control_thread);
938 printk(KERN_ERR "Failed to create control thread. err=%d\n",
939 retval);
940 goto err_out_slave_unregister;
941 }
942
943 return 0; 1020 return 0;
944 1021
1022#if 0
1023/* For undoing the slave register if there was a step after it. */
945err_out_slave_unregister: 1024err_out_slave_unregister:
946 driver_unregister(&w1_slave_driver); 1025 driver_unregister(&w1_slave_driver);
1026#endif
947 1027
948err_out_master_unregister: 1028err_out_master_unregister:
949 driver_unregister(&w1_master_driver); 1029 driver_unregister(&w1_master_driver);
@@ -959,13 +1039,12 @@ static void w1_fini(void)
959{ 1039{
960 struct w1_master *dev; 1040 struct w1_master *dev;
961 1041
1042 /* Set netlink removal messages and some cleanup */
962 list_for_each_entry(dev, &w1_masters, w1_master_entry) 1043 list_for_each_entry(dev, &w1_masters, w1_master_entry)
963 __w1_remove_master_device(dev); 1044 __w1_remove_master_device(dev);
964 1045
965 w1_fini_netlink(); 1046 w1_fini_netlink();
966 1047
967 kthread_stop(w1_control_thread);
968
969 driver_unregister(&w1_slave_driver); 1048 driver_unregister(&w1_slave_driver);
970 driver_unregister(&w1_master_driver); 1049 driver_unregister(&w1_master_driver);
971 bus_unregister(&w1_bus_type); 1050 bus_unregister(&w1_bus_type);
diff --git a/drivers/w1/w1.h b/drivers/w1/w1.h
index f1df5343f4ad..cdaa6fffbfc7 100644
--- a/drivers/w1/w1.h
+++ b/drivers/w1/w1.h
@@ -46,7 +46,6 @@ struct w1_reg_num
46#include "w1_family.h" 46#include "w1_family.h"
47 47
48#define W1_MAXNAMELEN 32 48#define W1_MAXNAMELEN 32
49#define W1_SLAVE_DATA_SIZE 128
50 49
51#define W1_SEARCH 0xF0 50#define W1_SEARCH 0xF0
52#define W1_ALARM_SEARCH 0xEC 51#define W1_ALARM_SEARCH 0xEC
@@ -77,7 +76,7 @@ struct w1_slave
77 struct completion released; 76 struct completion released;
78}; 77};
79 78
80typedef void (* w1_slave_found_callback)(void *, u64); 79typedef void (*w1_slave_found_callback)(struct w1_master *, u64);
81 80
82 81
83/** 82/**
@@ -142,12 +141,18 @@ struct w1_bus_master
142 */ 141 */
143 u8 (*reset_bus)(void *); 142 u8 (*reset_bus)(void *);
144 143
145 /** Really nice hardware can handles the different types of ROM search */ 144 /**
146 void (*search)(void *, u8, w1_slave_found_callback); 145 * Put out a strong pull-up pulse of the specified duration.
147}; 146 * @return -1=Error, 0=completed
147 */
148 u8 (*set_pullup)(void *, int);
148 149
149#define W1_MASTER_NEED_EXIT 0 150 /** Really nice hardware can handles the different types of ROM search
150#define W1_MASTER_NEED_RECONNECT 1 151 * w1_master* is passed to the slave found callback.
152 */
153 void (*search)(void *, struct w1_master *,
154 u8, w1_slave_found_callback);
155};
151 156
152struct w1_master 157struct w1_master
153{ 158{
@@ -167,7 +172,10 @@ struct w1_master
167 void *priv; 172 void *priv;
168 int priv_size; 173 int priv_size;
169 174
170 long flags; 175 /** 5V strong pullup enabled flag, 1 enabled, zero disabled. */
176 int enable_pullup;
177 /** 5V strong pullup duration in milliseconds, zero disabled. */
178 int pullup_duration;
171 179
172 struct task_struct *thread; 180 struct task_struct *thread;
173 struct mutex mutex; 181 struct mutex mutex;
@@ -181,12 +189,21 @@ struct w1_master
181}; 189};
182 190
183int w1_create_master_attributes(struct w1_master *); 191int w1_create_master_attributes(struct w1_master *);
192void w1_destroy_master_attributes(struct w1_master *master);
184void w1_search(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb); 193void w1_search(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb);
185void w1_search_devices(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb); 194void w1_search_devices(struct w1_master *dev, u8 search_type, w1_slave_found_callback cb);
186struct w1_slave *w1_search_slave(struct w1_reg_num *id); 195struct w1_slave *w1_search_slave(struct w1_reg_num *id);
187void w1_search_process(struct w1_master *dev, u8 search_type); 196void w1_search_process(struct w1_master *dev, u8 search_type);
188struct w1_master *w1_search_master_id(u32 id); 197struct w1_master *w1_search_master_id(u32 id);
189 198
199/* Disconnect and reconnect devices in the given family. Used for finding
200 * unclaimed devices after a family has been registered or releasing devices
201 * after a family has been unregistered. Set attach to 1 when a new family
202 * has just been registered, to 0 when it has been unregistered.
203 */
204void w1_reconnect_slaves(struct w1_family *f, int attach);
205void w1_slave_detach(struct w1_slave *sl);
206
190u8 w1_triplet(struct w1_master *dev, int bdir); 207u8 w1_triplet(struct w1_master *dev, int bdir);
191void w1_write_8(struct w1_master *, u8); 208void w1_write_8(struct w1_master *, u8);
192int w1_reset_bus(struct w1_master *); 209int w1_reset_bus(struct w1_master *);
@@ -194,6 +211,7 @@ u8 w1_calc_crc8(u8 *, int);
194void w1_write_block(struct w1_master *, const u8 *, int); 211void w1_write_block(struct w1_master *, const u8 *, int);
195u8 w1_read_block(struct w1_master *, u8 *, int); 212u8 w1_read_block(struct w1_master *, u8 *, int);
196int w1_reset_select_slave(struct w1_slave *sl); 213int w1_reset_select_slave(struct w1_slave *sl);
214void w1_next_pullup(struct w1_master *, int);
197 215
198static inline struct w1_slave* dev_to_w1_slave(struct device *dev) 216static inline struct w1_slave* dev_to_w1_slave(struct device *dev)
199{ 217{
diff --git a/drivers/w1/w1_family.c b/drivers/w1/w1_family.c
index a3c95bd6890a..4a099041f28a 100644
--- a/drivers/w1/w1_family.c
+++ b/drivers/w1/w1_family.c
@@ -48,12 +48,12 @@ int w1_register_family(struct w1_family *newf)
48 48
49 if (!ret) { 49 if (!ret) {
50 atomic_set(&newf->refcnt, 0); 50 atomic_set(&newf->refcnt, 0);
51 newf->need_exit = 0;
52 list_add_tail(&newf->family_entry, &w1_families); 51 list_add_tail(&newf->family_entry, &w1_families);
53 } 52 }
54 spin_unlock(&w1_flock); 53 spin_unlock(&w1_flock);
55 54
56 w1_reconnect_slaves(newf); 55 /* check default devices against the new set of drivers */
56 w1_reconnect_slaves(newf, 1);
57 57
58 return ret; 58 return ret;
59} 59}
@@ -72,11 +72,11 @@ void w1_unregister_family(struct w1_family *fent)
72 break; 72 break;
73 } 73 }
74 } 74 }
75
76 fent->need_exit = 1;
77
78 spin_unlock(&w1_flock); 75 spin_unlock(&w1_flock);
79 76
77 /* deatch devices using this family code */
78 w1_reconnect_slaves(fent, 0);
79
80 while (atomic_read(&fent->refcnt)) { 80 while (atomic_read(&fent->refcnt)) {
81 printk(KERN_INFO "Waiting for family %u to become free: refcnt=%d.\n", 81 printk(KERN_INFO "Waiting for family %u to become free: refcnt=%d.\n",
82 fent->fid, atomic_read(&fent->refcnt)); 82 fent->fid, atomic_read(&fent->refcnt));
@@ -109,8 +109,7 @@ struct w1_family * w1_family_registered(u8 fid)
109 109
110static void __w1_family_put(struct w1_family *f) 110static void __w1_family_put(struct w1_family *f)
111{ 111{
112 if (atomic_dec_and_test(&f->refcnt)) 112 atomic_dec(&f->refcnt);
113 f->need_exit = 1;
114} 113}
115 114
116void w1_family_put(struct w1_family *f) 115void w1_family_put(struct w1_family *f)
diff --git a/drivers/w1/w1_family.h b/drivers/w1/w1_family.h
index ef1e1dafa19a..3ca1b9298f21 100644
--- a/drivers/w1/w1_family.h
+++ b/drivers/w1/w1_family.h
@@ -33,6 +33,7 @@
33#define W1_THERM_DS1822 0x22 33#define W1_THERM_DS1822 0x22
34#define W1_EEPROM_DS2433 0x23 34#define W1_EEPROM_DS2433 0x23
35#define W1_THERM_DS18B20 0x28 35#define W1_THERM_DS18B20 0x28
36#define W1_EEPROM_DS2431 0x2D
36#define W1_FAMILY_DS2760 0x30 37#define W1_FAMILY_DS2760 0x30
37 38
38#define MAXNAMELEN 32 39#define MAXNAMELEN 32
@@ -53,7 +54,6 @@ struct w1_family
53 struct w1_family_ops *fops; 54 struct w1_family_ops *fops;
54 55
55 atomic_t refcnt; 56 atomic_t refcnt;
56 u8 need_exit;
57}; 57};
58 58
59extern spinlock_t w1_flock; 59extern spinlock_t w1_flock;
@@ -63,6 +63,5 @@ void __w1_family_get(struct w1_family *);
63struct w1_family * w1_family_registered(u8); 63struct w1_family * w1_family_registered(u8);
64void w1_unregister_family(struct w1_family *); 64void w1_unregister_family(struct w1_family *);
65int w1_register_family(struct w1_family *); 65int w1_register_family(struct w1_family *);
66void w1_reconnect_slaves(struct w1_family *f);
67 66
68#endif /* __W1_FAMILY_H */ 67#endif /* __W1_FAMILY_H */
diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
index 6840dfebe4d4..a3a54567bfba 100644
--- a/drivers/w1/w1_int.c
+++ b/drivers/w1/w1_int.c
@@ -29,7 +29,11 @@
29#include "w1_netlink.h" 29#include "w1_netlink.h"
30#include "w1_int.h" 30#include "w1_int.h"
31 31
32static u32 w1_ids = 1; 32static int w1_search_count = -1; /* Default is continual scan */
33module_param_named(search_count, w1_search_count, int, 0);
34
35static int w1_enable_pullup = 1;
36module_param_named(enable_pullup, w1_enable_pullup, int, 0);
33 37
34static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl, 38static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
35 struct device_driver *driver, 39 struct device_driver *driver,
@@ -59,8 +63,12 @@ static struct w1_master * w1_alloc_dev(u32 id, int slave_count, int slave_ttl,
59 dev->initialized = 0; 63 dev->initialized = 0;
60 dev->id = id; 64 dev->id = id;
61 dev->slave_ttl = slave_ttl; 65 dev->slave_ttl = slave_ttl;
62 dev->search_count = -1; /* continual scan */ 66 dev->search_count = w1_search_count;
67 dev->enable_pullup = w1_enable_pullup;
63 68
69 /* 1 for w1_process to decrement
70 * 1 for __w1_remove_master_device to decrement
71 */
64 atomic_set(&dev->refcnt, 2); 72 atomic_set(&dev->refcnt, 2);
65 73
66 INIT_LIST_HEAD(&dev->slist); 74 INIT_LIST_HEAD(&dev->slist);
@@ -93,9 +101,10 @@ static void w1_free_dev(struct w1_master *dev)
93 101
94int w1_add_master_device(struct w1_bus_master *master) 102int w1_add_master_device(struct w1_bus_master *master)
95{ 103{
96 struct w1_master *dev; 104 struct w1_master *dev, *entry;
97 int retval = 0; 105 int retval = 0;
98 struct w1_netlink_msg msg; 106 struct w1_netlink_msg msg;
107 int id, found;
99 108
100 /* validate minimum functionality */ 109 /* validate minimum functionality */
101 if (!(master->touch_bit && master->reset_bus) && 110 if (!(master->touch_bit && master->reset_bus) &&
@@ -104,10 +113,50 @@ int w1_add_master_device(struct w1_bus_master *master)
104 printk(KERN_ERR "w1_add_master_device: invalid function set\n"); 113 printk(KERN_ERR "w1_add_master_device: invalid function set\n");
105 return(-EINVAL); 114 return(-EINVAL);
106 } 115 }
116 /* While it would be electrically possible to make a device that
117 * generated a strong pullup in bit bang mode, only hardare that
118 * controls 1-wire time frames are even expected to support a strong
119 * pullup. w1_io.c would need to support calling set_pullup before
120 * the last write_bit operation of a w1_write_8 which it currently
121 * doesn't.
122 */
123 if (!master->write_byte && !master->touch_bit && master->set_pullup) {
124 printk(KERN_ERR "w1_add_master_device: set_pullup requires "
125 "write_byte or touch_bit, disabling\n");
126 master->set_pullup = NULL;
127 }
128
129 /* Lock until the device is added (or not) to w1_masters. */
130 mutex_lock(&w1_mlock);
131 /* Search for the first available id (starting at 1). */
132 id = 0;
133 do {
134 ++id;
135 found = 0;
136 list_for_each_entry(entry, &w1_masters, w1_master_entry) {
137 if (entry->id == id) {
138 found = 1;
139 break;
140 }
141 }
142 } while (found);
107 143
108 dev = w1_alloc_dev(w1_ids++, w1_max_slave_count, w1_max_slave_ttl, &w1_master_driver, &w1_master_device); 144 dev = w1_alloc_dev(id, w1_max_slave_count, w1_max_slave_ttl,
109 if (!dev) 145 &w1_master_driver, &w1_master_device);
146 if (!dev) {
147 mutex_unlock(&w1_mlock);
110 return -ENOMEM; 148 return -ENOMEM;
149 }
150
151 retval = w1_create_master_attributes(dev);
152 if (retval) {
153 mutex_unlock(&w1_mlock);
154 goto err_out_free_dev;
155 }
156
157 memcpy(dev->bus_master, master, sizeof(struct w1_bus_master));
158
159 dev->initialized = 1;
111 160
112 dev->thread = kthread_run(&w1_process, dev, "%s", dev->name); 161 dev->thread = kthread_run(&w1_process, dev, "%s", dev->name);
113 if (IS_ERR(dev->thread)) { 162 if (IS_ERR(dev->thread)) {
@@ -115,18 +164,10 @@ int w1_add_master_device(struct w1_bus_master *master)
115 dev_err(&dev->dev, 164 dev_err(&dev->dev,
116 "Failed to create new kernel thread. err=%d\n", 165 "Failed to create new kernel thread. err=%d\n",
117 retval); 166 retval);
118 goto err_out_free_dev; 167 mutex_unlock(&w1_mlock);
168 goto err_out_rm_attr;
119 } 169 }
120 170
121 retval = w1_create_master_attributes(dev);
122 if (retval)
123 goto err_out_kill_thread;
124
125 memcpy(dev->bus_master, master, sizeof(struct w1_bus_master));
126
127 dev->initialized = 1;
128
129 mutex_lock(&w1_mlock);
130 list_add(&dev->w1_master_entry, &w1_masters); 171 list_add(&dev->w1_master_entry, &w1_masters);
131 mutex_unlock(&w1_mlock); 172 mutex_unlock(&w1_mlock);
132 173
@@ -137,8 +178,12 @@ int w1_add_master_device(struct w1_bus_master *master)
137 178
138 return 0; 179 return 0;
139 180
181#if 0 /* Thread cleanup code, not required currently. */
140err_out_kill_thread: 182err_out_kill_thread:
141 kthread_stop(dev->thread); 183 kthread_stop(dev->thread);
184#endif
185err_out_rm_attr:
186 w1_destroy_master_attributes(dev);
142err_out_free_dev: 187err_out_free_dev:
143 w1_free_dev(dev); 188 w1_free_dev(dev);
144 189
@@ -148,10 +193,21 @@ err_out_free_dev:
148void __w1_remove_master_device(struct w1_master *dev) 193void __w1_remove_master_device(struct w1_master *dev)
149{ 194{
150 struct w1_netlink_msg msg; 195 struct w1_netlink_msg msg;
196 struct w1_slave *sl, *sln;
151 197
152 set_bit(W1_MASTER_NEED_EXIT, &dev->flags);
153 kthread_stop(dev->thread); 198 kthread_stop(dev->thread);
154 199
200 mutex_lock(&w1_mlock);
201 list_del(&dev->w1_master_entry);
202 mutex_unlock(&w1_mlock);
203
204 mutex_lock(&dev->mutex);
205 list_for_each_entry_safe(sl, sln, &dev->slist, w1_slave_entry)
206 w1_slave_detach(sl);
207 w1_destroy_master_attributes(dev);
208 mutex_unlock(&dev->mutex);
209 atomic_dec(&dev->refcnt);
210
155 while (atomic_read(&dev->refcnt)) { 211 while (atomic_read(&dev->refcnt)) {
156 dev_info(&dev->dev, "Waiting for %s to become free: refcnt=%d.\n", 212 dev_info(&dev->dev, "Waiting for %s to become free: refcnt=%d.\n",
157 dev->name, atomic_read(&dev->refcnt)); 213 dev->name, atomic_read(&dev->refcnt));
diff --git a/drivers/w1/w1_io.c b/drivers/w1/w1_io.c
index 30b6fbf83bd4..f4f82f1f486e 100644
--- a/drivers/w1/w1_io.c
+++ b/drivers/w1/w1_io.c
@@ -93,6 +93,40 @@ static void w1_write_bit(struct w1_master *dev, int bit)
93} 93}
94 94
95/** 95/**
96 * Pre-write operation, currently only supporting strong pullups.
97 * Program the hardware for a strong pullup, if one has been requested and
98 * the hardware supports it.
99 *
100 * @param dev the master device
101 */
102static void w1_pre_write(struct w1_master *dev)
103{
104 if (dev->pullup_duration &&
105 dev->enable_pullup && dev->bus_master->set_pullup) {
106 dev->bus_master->set_pullup(dev->bus_master->data,
107 dev->pullup_duration);
108 }
109}
110
111/**
112 * Post-write operation, currently only supporting strong pullups.
113 * If a strong pullup was requested, clear it if the hardware supports
114 * them, or execute the delay otherwise, in either case clear the request.
115 *
116 * @param dev the master device
117 */
118static void w1_post_write(struct w1_master *dev)
119{
120 if (dev->pullup_duration) {
121 if (dev->enable_pullup && dev->bus_master->set_pullup)
122 dev->bus_master->set_pullup(dev->bus_master->data, 0);
123 else
124 msleep(dev->pullup_duration);
125 dev->pullup_duration = 0;
126 }
127}
128
129/**
96 * Writes 8 bits. 130 * Writes 8 bits.
97 * 131 *
98 * @param dev the master device 132 * @param dev the master device
@@ -102,11 +136,17 @@ void w1_write_8(struct w1_master *dev, u8 byte)
102{ 136{
103 int i; 137 int i;
104 138
105 if (dev->bus_master->write_byte) 139 if (dev->bus_master->write_byte) {
140 w1_pre_write(dev);
106 dev->bus_master->write_byte(dev->bus_master->data, byte); 141 dev->bus_master->write_byte(dev->bus_master->data, byte);
142 }
107 else 143 else
108 for (i = 0; i < 8; ++i) 144 for (i = 0; i < 8; ++i) {
145 if (i == 7)
146 w1_pre_write(dev);
109 w1_touch_bit(dev, (byte >> i) & 0x1); 147 w1_touch_bit(dev, (byte >> i) & 0x1);
148 }
149 w1_post_write(dev);
110} 150}
111EXPORT_SYMBOL_GPL(w1_write_8); 151EXPORT_SYMBOL_GPL(w1_write_8);
112 152
@@ -203,11 +243,14 @@ void w1_write_block(struct w1_master *dev, const u8 *buf, int len)
203{ 243{
204 int i; 244 int i;
205 245
206 if (dev->bus_master->write_block) 246 if (dev->bus_master->write_block) {
247 w1_pre_write(dev);
207 dev->bus_master->write_block(dev->bus_master->data, buf, len); 248 dev->bus_master->write_block(dev->bus_master->data, buf, len);
249 }
208 else 250 else
209 for (i = 0; i < len; ++i) 251 for (i = 0; i < len; ++i)
210 w1_write_8(dev, buf[i]); 252 w1_write_8(dev, buf[i]); /* calls w1_pre_write */
253 w1_post_write(dev);
211} 254}
212EXPORT_SYMBOL_GPL(w1_write_block); 255EXPORT_SYMBOL_GPL(w1_write_block);
213 256
@@ -250,12 +293,24 @@ int w1_reset_bus(struct w1_master *dev)
250 result = dev->bus_master->reset_bus(dev->bus_master->data) & 0x1; 293 result = dev->bus_master->reset_bus(dev->bus_master->data) & 0x1;
251 else { 294 else {
252 dev->bus_master->write_bit(dev->bus_master->data, 0); 295 dev->bus_master->write_bit(dev->bus_master->data, 0);
296 /* minimum 480, max ? us
297 * be nice and sleep, except 18b20 spec lists 960us maximum,
298 * so until we can sleep with microsecond accuracy, spin.
299 * Feel free to come up with some other way to give up the
300 * cpu for such a short amount of time AND get it back in
301 * the maximum amount of time.
302 */
253 w1_delay(480); 303 w1_delay(480);
254 dev->bus_master->write_bit(dev->bus_master->data, 1); 304 dev->bus_master->write_bit(dev->bus_master->data, 1);
255 w1_delay(70); 305 w1_delay(70);
256 306
257 result = dev->bus_master->read_bit(dev->bus_master->data) & 0x1; 307 result = dev->bus_master->read_bit(dev->bus_master->data) & 0x1;
258 w1_delay(410); 308 /* minmum 70 (above) + 410 = 480 us
309 * There aren't any timing requirements between a reset and
310 * the following transactions. Sleeping is safe here.
311 */
312 /* w1_delay(410); min required time */
313 msleep(1);
259 } 314 }
260 315
261 return result; 316 return result;
@@ -277,7 +332,8 @@ void w1_search_devices(struct w1_master *dev, u8 search_type, w1_slave_found_cal
277{ 332{
278 dev->attempts++; 333 dev->attempts++;
279 if (dev->bus_master->search) 334 if (dev->bus_master->search)
280 dev->bus_master->search(dev->bus_master->data, search_type, cb); 335 dev->bus_master->search(dev->bus_master->data, dev,
336 search_type, cb);
281 else 337 else
282 w1_search(dev, search_type, cb); 338 w1_search(dev, search_type, cb);
283} 339}
@@ -305,3 +361,20 @@ int w1_reset_select_slave(struct w1_slave *sl)
305 return 0; 361 return 0;
306} 362}
307EXPORT_SYMBOL_GPL(w1_reset_select_slave); 363EXPORT_SYMBOL_GPL(w1_reset_select_slave);
364
365/**
366 * Put out a strong pull-up of the specified duration after the next write
367 * operation. Not all hardware supports strong pullups. Hardware that
368 * doesn't support strong pullups will sleep for the given time after the
369 * write operation without a strong pullup. This is a one shot request for
370 * the next write, specifying zero will clear a previous request.
371 * The w1 master lock must be held.
372 *
373 * @param delay time in milliseconds
374 * @return 0=success, anything else=error
375 */
376void w1_next_pullup(struct w1_master *dev, int delay)
377{
378 dev->pullup_duration = delay;
379}
380EXPORT_SYMBOL_GPL(w1_next_pullup);